| 40 | | if(!isset($fromProduct)) { |
| 41 | | require_once("../../../include/session.php"); |
| 42 | | } |
| 43 | | |
| 44 | | class salesHistoryReport{ |
| | 40 | if(!class_exists("phpbmsReport")) |
| | 41 | include("../../../report/report_class.php"); |
| | 42 | |
| | 43 | class salesHistoryReport extends phpbmsReport{ |
| | 44 | |
| | 45 | var $fromDate; |
| | 46 | var $toDate; |
| | 47 | var $view; |
| | 48 | var $productQueryresult; |
| | 49 | var $dataPrint; |
| | 50 | |
| | 51 | function salesHistoryReport($db, $reportUUID, $tabledefUUID){ |
| | 52 | |
| | 53 | parent::phpbmsReport($db, $reportUUID, $tabledefUUID); |
| | 54 | |
| | 55 | //$this->checkForDefaultSettings(); |
| | 56 | |
| | 57 | }//end function init |
| | 58 | |
| | 59 | |
| | 60 | function initialize($variables){ |
| | 61 | |
| | 62 | if(!isset($variables["fromdate"]) || !isset($variables["todate"]) || !isset($variables["status"])) |
| | 63 | $error = new appError(300, "Missing Passed Parameters"); |
| | 64 | |
| | 65 | $this->fromDate = $variables["fromdate"]; |
| | 66 | $this->toDate = $variables["todate"]; |
| | 67 | $this->view = $variables["status"]; |
| | 68 | |
| | 69 | $this->dataPrint = $_SESSION["printing"]["dataprint"]; |
| | 70 | |
| | 71 | if(!$this->sortOrder) |
| | 72 | $this->sortOrder = " ORDER BY products.partnumber "; |
| | 73 | |
| | 74 | if(!$this->whereClause) |
| | 75 | $this->whereClause = "products.id!=-1"; |
| | 76 | |
| | 77 | $this->whereClause = " WHERE (".$this->whereClause.") "; |
| | 78 | |
| | 79 | $querystatement = " |
| | 80 | SELECT |
| | 81 | products.uuid, |
| | 82 | products.partnumber, |
| | 83 | products.partname |
| | 84 | FROM |
| | 85 | products |
| | 86 | ".$this->whereClause.$this->sortOrder; |
| | 87 | |
| | 88 | $this->productQueryresult = $this->db->query($querystatement); |
| | 89 | |
| | 90 | }//end function initialize |
| | 91 | |
| | 92 | |
| | 93 | function generateSingleHistory($productUUID){ |
| | 94 | |
| | 95 | $theStatus = "(invoices.type = '"; |
| | 96 | |
| | 97 | switch($this->view){ |
| | 98 | |
| | 99 | case "Orders and Invoices": |
| | 100 | $theStatus .= "Order' OR invoices.type ='Invoice')"; |
| | 101 | $searchDate = "orderdate"; |
| | 102 | break; |
| | 103 | |
| | 104 | case "Invoices": |
| | 105 | $theStatus .= "Invoice')"; |
| | 106 | $searchDate = "invoicedate"; |
| | 107 | break; |
| | 108 | |
| | 109 | case "Orders": |
| | 110 | $theStatus .= "Order')"; |
| | 111 | $searchDate = "orderdate"; |
| | 112 | break; |
| | 113 | |
| | 114 | }//endswitch |
| | 115 | |
| | 116 | $mysqlFromDate = sqlDateFromString($this->fromDate); |
| | 117 | $mysqlToDate = sqlDateFromString($this->toDate); |
| | 118 | |
| | 119 | $querystatement = " |
| | 120 | SELECT |
| | 121 | `invoices`.`id`, |
| | 122 | `invoices`.`orderdate`, |
| | 123 | `invoices`.`invoicedate`, |
| | 124 | IF(clients.lastname!=\"\",concat(clients.lastname,\", \",clients.firstname,if(clients.company!=\"\",concat(\" (\",clients.company,\")\"),\"\")),clients.company) AS `client`, |
| | 125 | `lineitems`.`quantity` AS `qty`, |
| | 126 | `lineitems`.`unitprice`*`lineitems`.`quantity` AS `extended`, |
| | 127 | `lineitems`.`unitprice` AS `price`, |
| | 128 | `lineitems`.`unitcost` AS `cost`, |
| | 129 | `lineitems`.`unitcost`*`lineitems`.`quantity` AS extendedcost |
| | 130 | FROM |
| | 131 | ((products INNER JOIN lineitems on products.uuid=lineitems.productid) |
| | 132 | INNER JOIN `invoices` ON lineitems.invoiceid=invoices.id) |
| | 133 | INNER JOIN `clients` on `invoices`.`clientid`=`clients`.`uuid` |
| | 134 | WHERE |
| | 135 | `products`.`uuid`='".$productUUID."' |
| | 136 | AND |
| | 137 | `invoices`.".$searchDate.">='".$mysqlFromDate."' |
| | 138 | AND |
| | 139 | `invoices`.".$searchDate."<='".$mysqlToDate."' |
| | 140 | AND |
| | 141 | ".$theStatus." |
| | 142 | ORDER BY |
| | 143 | `invoices`.`invoicedate`, |
| | 144 | `invoices`.`orderdate` |
| | 145 | "; |
| | 146 | |
| | 147 | $queryresult = $this->db->query($querystatement); |
| | 148 | |
| | 149 | ob_start(); |
| | 150 | |
| | 151 | ?> |
| | 152 | <table border="0" cellpadding="3" cellspacing="0"> |
| | 153 | <thead> |
| | 154 | <tr> |
| | 155 | <th align="center" nowrap="nowrap" >ID</th> |
| | 156 | <th align="center" nowrap="nowrap" >Order Date</th> |
| | 157 | <th align="center" nowrap="nowrap" >Invoice. Date</th> |
| | 158 | <th nowrap="nowrap" width="100%" align="left">Client</th> |
| | 159 | <th align="center" nowrap="nowrap" >Qty.</th> |
| | 160 | <th align="right" nowrap="nowrap" >Unit Cost</th> |
| | 161 | <th align="right" nowrap="nowrap" >Cost Ext.</th> |
| | 162 | <th align="right" nowrap="nowrap" >Unit Price</th> |
| | 163 | <th align="right" nowrap="nowrap">Price Ext.</th> |
| | 164 | </tr> |
| | 165 | </thead> |
| | 166 | <?php |
| | 167 | |
| | 168 | $totalextended = 0; |
| | 169 | $totalcostextended = 0; |
| | 170 | $totalquantity = 0; |
| | 171 | $avgprice = 0; |
| | 172 | $avgcost = 0; |
| | 173 | |
| | 174 | $numrows = $this->db->numRows($queryresult); |
| | 175 | |
| | 176 | while ($therecord = $this->db->fetchArray($queryresult)){ |
| | 177 | |
| | 178 | $avgcost += $therecord["cost"]; |
| | 179 | $avgprice += $therecord["price"]; |
| | 180 | $totalquantity += $therecord["qty"]; |
| | 181 | $totalextended += $therecord["extended"]; |
| | 182 | $totalcostextended += $therecord["extendedcost"]; |
| | 183 | ?> |
| | 184 | <tr> |
| | 185 | <td align="center" nowrap="nowrap"><?php echo $therecord["id"]?></td> |
| | 186 | <td align="center" nowrap="nowrap"><?php echo $therecord["orderdate"]?formatFromSQLDate($therecord["orderdate"]):" " ?></td> |
| | 187 | <td align="center" nowrap="nowrap"><?php echo $therecord["invoicedate"]?formatFromSQLDate($therecord["invoicedate"]):" " ?></td> |
| | 188 | <td nowrap="nowrap"><?php echo $therecord["client"]?></td> |
| | 189 | <td align="center" nowrap="nowrap"><?php echo number_format($therecord["qty"],2)?></td> |
| | 190 | <td align="right" nowrap="nowrap"><?php echo numberToCurrency($therecord["cost"])?></td> |
| | 191 | <td align="right" nowrap="nowrap"><?php echo numberToCurrency($therecord["extendedcost"])?></td> |
| | 192 | <td align="right" nowrap="nowrap"><?php echo numberToCurrency($therecord["price"])?></td> |
| | 193 | <td align="right" nowrap="nowrap"><?php echo numberToCurrency($therecord["extended"])?></td> |
| | 194 | </tr> |
| | 195 | <?php }//endwhile ?> |
| | 196 | <tr> |
| | 197 | <td align="center" class="grandtotals"> </td> |
| | 198 | <td align="center" class="grandtotals"> </td> |
| | 199 | <td class="grandtotals"> </td> |
| | 200 | <td class="grandtotals"> </td> |
| | 201 | <td align="center" class="grandtotals"><?php echo number_format($totalquantity,2)?></td> |
| | 202 | <td align="right" nowrap="nowrap"class="grandtotals">avg. = <?php $numrows?$avgcost=$avgcost/$numrows:$avgcost=0; echo numberToCurrency($avgcost)?></td> |
| | 203 | <td align="right" class="grandtotals"><?php echo numberToCurrency($totalcostextended)?></td> |
| | 204 | <td align="right" nowrap="nowrap" class="grandtotals">avg. = <?php $numrows?$avgprice=$avgprice/$numrows:$avgprice=0; echo numberToCurrency($avgprice)?></td> |
| | 205 | <td align="right" class="grandtotals"><?php echo numberToCurrency($totalextended)?></td> |
| | 206 | </tr> |
| | 207 | </table> |
| | 208 | <?php |
| | 209 | |
| | 210 | $output = ob_get_contents(); |
| | 211 | ob_end_clean(); |
| | 212 | |
| | 213 | return $output; |
| | 214 | |
| | 215 | }//end function generateSingleHistory |
| | 216 | |
| | 217 | |
| | 218 | |
| | 219 | function generate(){ |
| | 220 | |
| | 221 | |
| | 222 | ob_start(); |
| | 223 | ?> |
| | 224 | |
| | 225 | <h1>Product Sales History</h1> |
| | 226 | |
| | 227 | <ul> |
| | 228 | <li> |
| | 229 | source:<br /> |
| | 230 | <?php echo formatVariable($this->dataPrint); ?> |
| | 231 | </li> |
| | 232 | <li> |
| | 233 | date generated:<br /> |
| | 234 | <?php echo dateToString(mktime())." ".timeToString(mktime()); ?> |
| | 235 | </li> |
| | 236 | <li> |
| | 237 | view:<br /> |
| | 238 | <?php echo $this->view; ?> |
| | 239 | </li> |
| | 240 | <li> |
| | 241 | from:<br /> |
| | 242 | <?php echo $this->fromDate; ?> |
| | 243 | </li> |
| | 244 | <li> |
| | 245 | to:<br /> |
| | 246 | <?php echo $this->toDate; ?> |
| | 247 | </li> |
| | 248 | </ul> |
| | 249 | |
| | 250 | <?php |
| | 251 | |
| | 252 | $this->reportOutput = ob_get_contents(); |
| | 253 | ob_end_clean(); |
| | 254 | |
| | 255 | while($therecord = $this->db->fetchArray($this->productQueryresult)){ |
| | 256 | |
| | 257 | $this->reportOutput .= '<h2>'.$therecord["partnumber"].'<br />'.$therecord["partname"].'</h2>'; |
| | 258 | |
| | 259 | $this->reportOutput .= $this->generateSingleHistory($therecord["uuid"]); |
| | 260 | |
| | 261 | }//endwhile |
| | 262 | |
| | 263 | }//end function generate |
| | 264 | |
| | 265 | |
| | 266 | function output(){ |
| | 267 | |
| | 268 | global $phpbms; |
| | 269 | $db = &$this->db; |
| | 270 | |
| | 271 | $phpbms->cssIncludes[] = "reports.css"; |
| | 272 | $phpbms->cssIncludes[] = "pages/bms/clienthistoryreport.css"; |
| | 273 | |
| | 274 | $phpbms->showMenu = false; |
| | 275 | $phpbms->showFooter = false; |
| | 276 | |
| | 277 | include("header.php"); |
| | 278 | |
| | 279 | echo $this->reportOutput; |
| | 280 | |
| | 281 | include("footer.php"); |
| | 282 | |
| | 283 | }//end function output |
| | 284 | |
| | 285 | |
| | 286 | function displayOptions(){ |
| | 287 | |
| | 288 | global $phpbms; |
| | 289 | $db = &$this->db; |
| | 290 | |
| | 291 | require("include/fields.php"); |
| | 292 | |
| | 293 | $pageTitle = "Product Sales History"; |
| | 294 | $phpbms->cssIncludes[] = "pages/historyreports.css"; |
| | 295 | $phpbms->showMenu = false; |
| | 296 | |
| | 297 | //Form Elements |
| | 298 | //============================================================== |
| | 299 | $theform = new phpbmsForm(); |
| | 300 | |
| | 301 | $thedate = dateToString( mktime(0,0,0,date("m"),1),"SQL" ); |
| | 302 | $theinput = new inputDatePicker("fromdate", $thedate, "from",true); |
| | 303 | $theform->addField($theinput); |
| | 304 | |
| | 305 | $thedate = dateToString( mktime(0,0,0,date("m")+1,0,date("Y")), "SQL" ); |
| | 306 | $theinput = new inputDatePicker("todate", $thedate, "to",true); |
| | 307 | $theform->addField($theinput); |
| | 308 | |
| | 309 | $theform->jsMerge(); |
| | 310 | //============================================================== |
| | 311 | //End Form Elements |
| | 312 | |
| | 313 | include("header.php"); |
| | 314 | ?> |
| | 315 | <form action="<?php echo str_replace("&", "&", $_SERVER["REQUEST_URI"]); ?>" method="post" name="totals" onsubmit="return validateForm(this)"> |
| | 316 | |
| | 317 | <div class="bodyline" id="reportOptions"> |
| | 318 | |
| | 319 | <h1 id="topTitle"><span>Product Sales History Options</span></h1> |
| | 320 | |
| | 321 | <fieldset> |
| | 322 | <legend>time frame</legend> |
| | 323 | |
| | 324 | <p id="fromP"><?php $theform->showField("fromdate");?></p> |
| | 325 | |
| | 326 | <p><?php $theform->showField("todate");?></p> |
| | 327 | </fieldset> |
| | 328 | |
| | 329 | <p> |
| | 330 | <label for="status">include products from...<br /></label> |
| | 331 | <select id="status" name="status"> |
| | 332 | <option value="Orders and Invoices" selected="selected">Orders and Invoices</option> |
| | 333 | <option value="Invoices">Invoices</option> |
| | 334 | <option value="Orders">Orders</option> |
| | 335 | </select> |
| | 336 | </p> |
| | 337 | |
| | 338 | <div align="right"> |
| | 339 | <input name="command" type="submit" class="Buttons" id="print" value="print" /> |
| | 340 | <input name="cancel" type="button" class="Buttons" id="cancel" value="cancel" onclick="window.close();" /> |
| | 341 | </div> |
| | 342 | </div> |
| | 343 | </form> |
| | 344 | |
| | 345 | <?php |
| | 346 | include("footer.php"); |
| | 347 | |
| | 348 | }//end function displayOptions |
| | 349 | |
| | 350 | }//end class salesHistoryReport |
| | 351 | |
| | 352 | |
| | 353 | /** |
| | 354 | * PROCESSING |
| | 355 | * ============================================================================= |
| | 356 | */ |
| | 357 | if(!isset($noOutput)){ |
| | 358 | |
| | 359 | //IE needs caching to be set to private in order to display PDFS |
| | 360 | session_cache_limiter('private'); |
| | 361 | |
| | 362 | require_once("../../../include/session.php"); |
| | 363 | |
| | 364 | checkForReportArguments(); |
| | 365 | |
| | 366 | $report = new salesHistoryReport($db, $_GET["rid"], $_GET["tid"]); |
| | 367 | |
| | 368 | if(!isset($_POST["command"]) && !isset($_GET["status"])) |
| | 369 | $report->displayOptions(); |
| | 370 | else{ |
| | 371 | |
| | 372 | if(isset($_GET["status"])){ |
| | 373 | |
| | 374 | $_POST["status"] = $_GET["status"]; |
| | 375 | $_POST["fromdate"] = $_GET["fromdate"]; |
| | 376 | $_POST["todate"] = $_GET["todate"]; |
| | 377 | |
| | 378 | }//endif |
| | 379 | |
| | 380 | //need to set post variables here |
| | 381 | |
| | 382 | $report->setupFromPrintScreen(); |
| | 383 | $report->initialize($_POST); |
| | 384 | $report->generate(); |
| | 385 | $report->output(); |
| | 386 | |
| | 387 | }//endif |
| | 388 | |
| | 389 | |
| | 390 | }//end if |
| | 391 | |
| | 392 | /** |
| | 393 | * When adding a new report record, the add/edit needs to know what the class |
| | 394 | * name is so that it can instantiate it, and grab it's default settings. |
| | 395 | */ |
| | 396 | if(isset($addingReportRecord)) |
| | 397 | $reportClass ="salesHistoryReport"; |
| | 398 | |
| | 399 | |
| | 400 | |
| | 401 | |
| | 402 | |
| | 403 | |
| | 404 | |
| | 405 | |
| | 406 | |
| | 407 | class s_salesHistoryReport{ |