| 53 | | function totalReport($db,$variables = NULL){ |
| 54 | | $this->db = $db; |
| 55 | | |
| 56 | | // first we define the available groups |
| 57 | | $this->addGroup("Year","YEAR(docdate)"); //0 |
| 58 | | $this->addGroup("Quarter","QUARTER(docdate)"); //1 |
| 59 | | $this->addGroup("Month","DATE_FORMAT(docdate, '%m - %b')"); //2 |
| 60 | | $this->addGroup("Week","WEEK(docdate)"); //3 |
| 61 | | $this->addGroup("Payment Method","paymentmethods.name"); //4 |
| 62 | | $this->addGroup("Document Type","doctype"); //5 |
| 63 | | |
| 64 | | |
| 65 | | //next we do the columns |
| 66 | | $this->addColumn("Record Count","COUNT(id)");//0 |
| 67 | | $this->addColumn("Total","SUM(doctotal)","currency");//1 |
| 68 | | |
| 69 | | |
| 70 | | if($variables){ |
| 71 | | |
| 72 | | $this->selectcolumns = $this->columns; |
| 73 | | |
| 74 | | $this->fromDate = $variables["fromdate"]; |
| 75 | | $this->toDate = $variables["todate"]; |
| 76 | | |
| 77 | | $this->tableClause["invoices"] = "(invoices INNER JOIN paymentmethods ON invoices.paymentmethodid = paymentmethods.uuid)"; |
| 78 | | $this->tableClause["receipts"] = "(receipts INNER JOIN paymentmethods ON receipts.paymentmethodid = paymentmethods.uuid)"; |
| 79 | | |
| 80 | | if($variables["groupings"] !== ""){ |
| 81 | | |
| 82 | | $this->group = explode("::",$variables["groupings"]); |
| 83 | | $this->group = array_reverse($this->group); |
| 84 | | |
| 85 | | } else |
| 86 | | $this->group = array(); |
| 87 | | |
| 88 | | foreach($this->group as $grp){ |
| 89 | | |
| 90 | | if($this->groupings[$grp]["table"]){ |
| 91 | | |
| 92 | | foreach($this->tableClause as $key => $value); |
| 93 | | $this->tableClause[$key]="(".$this->tableClause[$key]." ".$this->groupings[$grp]["table"].")"; |
| 94 | | |
| 95 | | }//endif |
| 96 | | |
| 97 | | }//endforeach |
| 98 | | |
| 99 | | // $this->whereclause = $_SESSION["printing"]["whereclause"]; |
| 100 | | // if($this->whereclause=="") $this->whereclause="WHERE invoices.id!=-1"; |
| 101 | | $this->whereClause["invoices"] = " |
| 102 | | WHERE |
| 103 | | (invoices.type = 'Invoice' |
| 104 | | AND paymentmethods.type != 'receivable' |
| 105 | | AND invoicedate >= '".sqlDateFromString($variables["fromdate"])."' |
| 106 | | AND invoicedate <= '".sqlDateFromString($variables["todate"])."') |
| 107 | | "; |
| 108 | | |
| 109 | | $this->whereClause["receipts"] = " |
| 110 | | WHERE |
| 111 | | (receipts.posted = 1 |
| 112 | | AND receiptdate >= '".sqlDateFromString($variables["fromdate"])."' |
| 113 | | AND receiptdate <= '".sqlDateFromString($variables["todate"])."') |
| 114 | | "; |
| 115 | | |
| 116 | | $this->showItems = isset($variables["showitems"]); |
| 117 | | |
| 118 | | }// endif |
| | 54 | |
| | 55 | function totalReport($db, $reportUUID, $tabledefUUID){ |
| | 56 | |
| | 57 | $this->db = $db; |
| | 58 | |
| | 59 | parent::phpbmsReport($db, $reportUUID, $tabledefUUID); |
| | 60 | |
| | 61 | // first we define the available groups |
| | 62 | $this->addGroup("Year","YEAR(docdate)"); //0 |
| | 63 | $this->addGroup("Quarter","QUARTER(docdate)"); //1 |
| | 64 | $this->addGroup("Month","DATE_FORMAT(docdate, '%m - %b')"); //2 |
| | 65 | $this->addGroup("Week","WEEK(docdate)"); //3 |
| | 66 | $this->addGroup("Payment Method","paymentmethods.name"); //4 |
| | 67 | $this->addGroup("Document Type","doctype"); //5 |
| | 68 | |
| | 69 | //next we do the columns |
| | 70 | $this->addColumn("Record Count","COUNT(id)");//0 |
| | 71 | $this->addColumn("Total","SUM(doctotal)","currency");//1 |
| | 72 | |
| | 73 | $this->tableClause["invoices"] = "(invoices INNER JOIN paymentmethods ON invoices.paymentmethodid = paymentmethods.uuid)"; |
| | 74 | $this->tableClause["receipts"] = "(receipts INNER JOIN paymentmethods ON receipts.paymentmethodid = paymentmethods.uuid)"; |
| | 75 | |
| | 77 | |
| | 78 | |
| | 79 | function processFromPost($variables){ |
| | 80 | |
| | 81 | $this->selectcolumns = $this->columns; |
| | 82 | |
| | 83 | $this->fromDate = $variables["fromdate"]; |
| | 84 | $this->toDate = $variables["todate"]; |
| | 85 | |
| | 86 | if($variables["groupings"] !== ""){ |
| | 87 | |
| | 88 | $this->group = explode("::",$variables["groupings"]); |
| | 89 | $this->group = array_reverse($this->group); |
| | 90 | |
| | 91 | } else |
| | 92 | $this->group = array(); |
| | 93 | |
| | 94 | foreach($this->group as $grp){ |
| | 95 | |
| | 96 | if($this->groupings[$grp]["table"]){ |
| | 97 | |
| | 98 | foreach($this->tableClause as $key => $value); |
| | 99 | $this->tableClause[$key] = "(".$this->tableClause[$key]." ".$this->groupings[$grp]["table"].")"; |
| | 100 | |
| | 101 | }//endif |
| | 102 | |
| | 103 | }//endforeach |
| | 104 | |
| | 105 | $this->whereClauses["invoices"] = " |
| | 106 | WHERE |
| | 107 | (invoices.type = 'Invoice' |
| | 108 | AND paymentmethods.type != 'receivable' |
| | 109 | AND invoicedate >= '".sqlDateFromString($variables["fromdate"])."' |
| | 110 | AND invoicedate <= '".sqlDateFromString($variables["todate"])."') |
| | 111 | "; |
| | 112 | |
| | 113 | $this->whereClauses["receipts"] = " |
| | 114 | WHERE |
| | 115 | (receipts.posted = 1 |
| | 116 | AND receiptdate >= '".sqlDateFromString($variables["fromdate"])."' |
| | 117 | AND receiptdate <= '".sqlDateFromString($variables["todate"])."') |
| | 118 | "; |
| | 119 | |
| | 120 | $this->showItems = isset($variables["showitems"]); |
| | 121 | |
| | 122 | }//end function processFromPost |
| | 123 | |
| | 124 | |
| | 125 | function processFromSettings(){ |
| | 126 | |
| | 127 | $variables["fromdate"] = $this->settings["fromDate"]; |
| | 128 | $variables["todate"] = $this->settings["toDate"]; |
| | 129 | |
| | 130 | $variables["groupings"] = ""; |
| | 131 | foreach($this->settings as $key=>$value) |
| | 132 | if(strpos($key, "group") === 0) |
| | 133 | $variables["groupings"] .= "::".$value; |
| | 134 | |
| | 135 | if($variables["groupings"]) |
| | 136 | $variables["groupings"] = substr($variables["groupings"], 2); |
| | 137 | |
| | 138 | $variables["showitems"] = isset($this->settings["showItems"]); |
| | 139 | |
| | 140 | $this->processFromPost($variables); |
| | 141 | |
| | 142 | }//end function processFromSettings |
| 584 | | // Processing =================================================================================================================== |
| 585 | | if(!isset($dontProcess)){ |
| 586 | | if(isset($_POST["fromdate"])){ |
| 587 | | $myreport= new totalReport($db,$_POST); |
| 588 | | $myreport->showReport(); |
| 589 | | } else { |
| 590 | | $myreport = new totalReport($db); |
| 591 | | $myreport->showSelectScreen(); |
| 592 | | } |
| 593 | | }?> |
| | 608 | |
| | 609 | /** |
| | 610 | * PROCESSING |
| | 611 | * ============================================================================= |
| | 612 | */ |
| | 613 | if(!isset($noOutput)){ |
| | 614 | |
| | 615 | //IE needs caching to be set to private in order to display PDFS |
| | 616 | session_cache_limiter('private'); |
| | 617 | |
| | 618 | //set encoding to latin1 (fpdf doesnt like utf8) |
| | 619 | $sqlEncoding = "latin1"; |
| | 620 | require_once("../../../include/session.php"); |
| | 621 | |
| | 622 | checkForReportArguments(); |
| | 623 | |
| | 624 | $report = new totalReport($db, $_GET["rid"], $_GET["tid"]); |
| | 625 | |
| | 626 | if(isset($_POST["fromdate"])){ |
| | 627 | |
| | 628 | $report->processFromPost($_POST); |
| | 629 | $report->showReport(); |
| | 630 | |
| | 631 | } elseif(isset($report->settings["fromdate"]) && isset($report->settings["todate"]) && isset($report->settings["groupings"])){ |
| | 632 | |
| | 633 | $report->processFromSettings(); |
| | 634 | $report->showReport(); |
| | 635 | |
| | 636 | }else |
| | 637 | $report->showSelectScreen(); |
| | 638 | |
| | 639 | }//end if |
| | 640 | |
| | 641 | /** |
| | 642 | * When adding a new report record, the add/edit needs to know what the class |
| | 643 | * name is so that it can instantiate it, and grab it's default settings. |
| | 644 | */ |
| | 645 | if(isset($addingReportRecord)) |
| | 646 | $reportClass ="totalReport"; |
| | 647 | |
| | 648 | ?> |