| 39 | | |
| 40 | | require("../../../include/session.php"); |
| 41 | | |
| 42 | | class totalReport{ |
| 43 | | |
| 44 | | var $selectcolumns; |
| 45 | | var $selecttable; |
| 46 | | var $whereclause=""; |
| 47 | | var $group=""; |
| 48 | | var $showinvoices=false; |
| 49 | | var $showlineitems=false; |
| 50 | | var $padamount=20; |
| 51 | | |
| 52 | | function totalReport($db,$variables = NULL){ |
| 53 | | $this->db = $db; |
| 54 | | |
| 55 | | // first we define the available groups |
| 56 | | $this->addGroup("Invoice Date - Year","YEAR(invoices.invoicedate)"); //0 |
| 57 | | $this->addGroup("Invoice Date - Quarter","QUARTER(invoices.invoicedate)"); //1 |
| 58 | | $this->addGroup("Invoice Date - Month","MONTH(invoices.invoicedate)"); //2 |
| 59 | | $this->addGroup("Invoice Date","invoices.invoicedate","date"); //3 |
| 60 | | |
| 61 | | $this->addGroup("Order Date - Year","YEAR(invoices.orderdate)"); //4 |
| 62 | | $this->addGroup("Order Date - Quarter","QUARTER(invoices.orderdate)");//5 |
| 63 | | $this->addGroup("Order Date - Month","MONTH(invoices.orderdate)");//6 |
| 64 | | $this->addGroup("Order Date","invoices.orderdate","date");//7 |
| 65 | | |
| 66 | | $this->addGroup("Required Date - Year","YEAR(invoices.requireddate)");//8 |
| 67 | | $this->addGroup("Required Date - Quarter","QUARTER(invoices.requireddate)");//9 |
| 68 | | $this->addGroup("Required Date - Month","MONTH(invoices.requireddate)");//10 |
| 69 | | $this->addGroup("Required Date","invoices.requireddate","date");//11 |
| 70 | | |
| 71 | | $this->addGroup("Client","if(clients.lastname!='',concat(clients.lastname,', ',clients.firstname,if(clients.company!='',concat(' (',clients.company,')'),'')),clients.company)");//12 |
| 72 | | |
| 73 | | $this->addGroup("Client Sales Person","concat(salesPerson.firstname,' ',salesPerson.lastname)",NULL, "LEFT JOIN users AS salesPerson ON clients.salesmanagerid = salesPerson.uuid");//13 |
| 74 | | |
| 75 | | $this->addGroup("Client Lead Source","clients.leadsource");//14 |
| 76 | | |
| 77 | | $this->addGroup("Invoice Lead Source","invoices.leadsource");//15 |
| 78 | | |
| 79 | | $this->addGroup("Payment Method","paymentmethods.name");//16 |
| 80 | | |
| 81 | | $this->addGroup("Shipping Method","shippingmethods.name");//17 |
| 82 | | $this->addGroup("Invoice Shipping Country","invoices.shiptocountry");//18 |
| 83 | | $this->addGroup("Invoice Shipping State / Province","invoices.shiptostate");//19 |
| 84 | | $this->addGroup("Invoice Shipping Postal Code","invoices.shiptopostalcode");//20 |
| 85 | | $this->addGroup("Invoice Shipping City","invoices.shiptocity");//21 |
| 86 | | |
| 87 | | $this->addGroup("Web Order","invoices.weborder","boolean");//22 |
| 88 | | |
| 89 | | $this->addGroup("Invoice billing Country","invoices.country");//23 |
| 90 | | $this->addGroup("Invoice Billing State / Province","invoices.state");//24 |
| 91 | | $this->addGroup("Invoice Billing Postal Code","invoices.postalcode");//25 |
| 92 | | $this->addGroup("Invoice Billing City","invoices.city");//26 |
| 93 | | |
| 94 | | |
| 95 | | //next we do the columns |
| 96 | | $this->addColumn("Record Count","count(invoices.id)");//0 |
| 97 | | $this->addColumn("Invoice Total","sum(invoices.totalti)","currency");//1 |
| 98 | | $this->addColumn("Average Invoice Total","avg(invoices.totalti)","currency");//2 |
| 99 | | |
| 100 | | $this->addColumn("Subtotal","sum(invoices.totaltni)","currency");//3 |
| 101 | | $this->addColumn("Average Subtotal","avg(invoices.totaltni)","currency");//4 |
| 102 | | |
| 103 | | $this->addColumn("Tax","sum(invoices.tax)","currency");//5 |
| 104 | | $this->addColumn("Average Tax","avg(invoices.tax)","currency");//6 |
| 105 | | |
| 106 | | $this->addColumn("Shipping","sum(invoices.shipping)","currency");//7 |
| 107 | | $this->addColumn("Average Shipping","avg(invoices.shipping)","currency");//8 |
| 108 | | |
| 109 | | $this->addColumn("Amount Paid","sum(invoices.amountpaid)","currency");//9 |
| 110 | | $this->addColumn("Average Amount Paid","avg(invoices.amountpaid)","currency");//10 |
| 111 | | |
| 112 | | $this->addColumn("Amount Due","sum(invoices.totalti - invoices.amountpaid)","currency");//11 |
| 113 | | $this->addColumn("Average Amount Due","avg(invoices.totalti - invoices.amountpaid)","currency");//12 |
| 114 | | |
| 115 | | $this->addColumn("Cost","sum(invoices.totalcost)","currency");//13 |
| 116 | | $this->addColumn("Average Cost","avg(invoices.totalcost)","currency");//14 |
| 117 | | |
| 118 | | $this->addColumn("Total Weight","sum(invoices.totalweight)","real");//15 |
| 119 | | $this->addColumn("Average Total Weight","avg(invoices.totalweight)","real");//16 |
| 120 | | |
| 121 | | |
| 122 | | if($variables){ |
| 123 | | $tempArray = explode("::", $variables["columns"]); |
| 124 | | |
| 125 | | foreach($tempArray as $id) |
| 126 | | $this->selectcolumns[] = $this->columns[$id]; |
| 127 | | $this->selectcolumns = array_reverse($this->selectcolumns); |
| 128 | | |
| 129 | | $this->selecttable="((`invoices` INNER JOIN `clients` ON `invoices`.`clientid`=`clients`.`uuid`) LEFT JOIN `shippingmethods` ON `shippingmethods`.`uuid` = `invoices`.`shippingmethodid`) LEFT JOIN `paymentmethods` ON `paymentmethods`.`id`=`invoices`.`paymentmethodid`"; |
| 130 | | |
| 131 | | if($variables["groupings"] !== ""){ |
| 132 | | $this->group = explode("::",$variables["groupings"]); |
| 133 | | $this->group = array_reverse($this->group); |
| 134 | | } else |
| 135 | | $this->group = array(); |
| 136 | | |
| 137 | | foreach($this->group as $grp){ |
| 138 | | if($this->groupings[$grp]["table"]) |
| 139 | | $this->selecttable="(".$this->selecttable." ".$this->groupings[$grp]["table"].")"; |
| 140 | | } |
| 141 | | |
| 142 | | $this->whereclause=$_SESSION["printing"]["whereclause"]; |
| 143 | | if($this->whereclause=="") $this->whereclause="WHERE invoices.id!=-1"; |
| 144 | | |
| 145 | | switch($variables["showwhat"]){ |
| 146 | | case "invoices": |
| 147 | | $this->showinvoices = true; |
| 148 | | $this->showlineitems = false; |
| 149 | | break; |
| 150 | | |
| 151 | | case "lineitems": |
| 152 | | $this->showinvoices = true; |
| 153 | | $this->showlineitems = true; |
| 154 | | break; |
| 155 | | |
| 156 | | default: |
| 157 | | $this->showinvoices = false; |
| 158 | | $this->showlineitems = false; |
| 159 | | }// endswitch |
| 160 | | |
| 161 | | if($this->whereclause!="") $this->whereclause=" WHERE (".substr($this->whereclause,6).") "; |
| 162 | | }// endif |
| | 39 | if(!class_exists("phpbmsReport")) |
| | 40 | include("../../../report/report_class.php"); |
| | 41 | |
| | 42 | class totalReport extends phpbmsReport{ |
| | 43 | |
| | 44 | var $selectcolumns; |
| | 45 | var $selecttable; |
| | 46 | var $group = ""; |
| | 47 | var $showinvoices = false; |
| | 48 | var $showlineitems = false; |
| | 49 | var $padamount = 20; |
| | 50 | var $title = "Totals"; |
| | 51 | |
| | 52 | function totalReport($db, $reportUUID, $tabledefUUID, $variables = NULL){ |
| | 53 | |
| | 54 | parent::phpbmsReport($db, $reportUUID, $tabledefUUID); |
| | 55 | |
| | 56 | // first we define the available groups |
| | 57 | $this->addGroup("Invoice Date - Year","YEAR(invoices.invoicedate)"); //0 |
| | 58 | $this->addGroup("Invoice Date - Quarter","QUARTER(invoices.invoicedate)"); //1 |
| | 59 | $this->addGroup("Invoice Date - Month","MONTH(invoices.invoicedate)"); //2 |
| | 60 | $this->addGroup("Invoice Date","invoices.invoicedate","date"); //3 |
| | 61 | |
| | 62 | $this->addGroup("Order Date - Year","YEAR(invoices.orderdate)"); //4 |
| | 63 | $this->addGroup("Order Date - Quarter","QUARTER(invoices.orderdate)");//5 |
| | 64 | $this->addGroup("Order Date - Month","MONTH(invoices.orderdate)");//6 |
| | 65 | $this->addGroup("Order Date","invoices.orderdate","date");//7 |
| | 66 | |
| | 67 | $this->addGroup("Required Date - Year","YEAR(invoices.requireddate)");//8 |
| | 68 | $this->addGroup("Required Date - Quarter","QUARTER(invoices.requireddate)");//9 |
| | 69 | $this->addGroup("Required Date - Month","MONTH(invoices.requireddate)");//10 |
| | 70 | $this->addGroup("Required Date","invoices.requireddate","date");//11 |
| | 71 | |
| | 72 | $this->addGroup("Client","if(clients.lastname!='',concat(clients.lastname,', ',clients.firstname,if(clients.company!='',concat(' (',clients.company,')'),'')),clients.company)");//12 |
| | 73 | |
| | 74 | $this->addGroup("Client Sales Person","concat(salesPerson.firstname,' ',salesPerson.lastname)",NULL, "LEFT JOIN users AS salesPerson ON clients.salesmanagerid = salesPerson.uuid");//13 |
| | 75 | |
| | 76 | $this->addGroup("Client Lead Source","clients.leadsource");//14 |
| | 77 | |
| | 78 | $this->addGroup("Invoice Lead Source","invoices.leadsource");//15 |
| | 79 | |
| | 80 | $this->addGroup("Payment Method","paymentmethods.name");//16 |
| | 81 | |
| | 82 | $this->addGroup("Shipping Method","shippingmethods.name");//17 |
| | 83 | $this->addGroup("Invoice Shipping Country","invoices.shiptocountry");//18 |
| | 84 | $this->addGroup("Invoice Shipping State / Province","invoices.shiptostate");//19 |
| | 85 | $this->addGroup("Invoice Shipping Postal Code","invoices.shiptopostalcode");//20 |
| | 86 | $this->addGroup("Invoice Shipping City","invoices.shiptocity");//21 |
| | 87 | |
| | 88 | $this->addGroup("Web Order","invoices.weborder","boolean");//22 |
| | 89 | |
| | 90 | $this->addGroup("Invoice billing Country","invoices.country");//23 |
| | 91 | $this->addGroup("Invoice Billing State / Province","invoices.state");//24 |
| | 92 | $this->addGroup("Invoice Billing Postal Code","invoices.postalcode");//25 |
| | 93 | $this->addGroup("Invoice Billing City","invoices.city");//26 |
| | 94 | |
| | 95 | |
| | 96 | //next we do the columns |
| | 97 | $this->addColumn("Record Count","count(invoices.id)");//0 |
| | 98 | $this->addColumn("Invoice Total","sum(invoices.totalti)","currency");//1 |
| | 99 | $this->addColumn("Average Invoice Total","avg(invoices.totalti)","currency");//2 |
| | 100 | |
| | 101 | $this->addColumn("Subtotal","sum(invoices.totaltni)","currency");//3 |
| | 102 | $this->addColumn("Average Subtotal","avg(invoices.totaltni)","currency");//4 |
| | 103 | |
| | 104 | $this->addColumn("Tax","sum(invoices.tax)","currency");//5 |
| | 105 | $this->addColumn("Average Tax","avg(invoices.tax)","currency");//6 |
| | 106 | |
| | 107 | $this->addColumn("Shipping","sum(invoices.shipping)","currency");//7 |
| | 108 | $this->addColumn("Average Shipping","avg(invoices.shipping)","currency");//8 |
| | 109 | |
| | 110 | $this->addColumn("Amount Paid","sum(invoices.amountpaid)","currency");//9 |
| | 111 | $this->addColumn("Average Amount Paid","avg(invoices.amountpaid)","currency");//10 |
| | 112 | |
| | 113 | $this->addColumn("Amount Due","sum(invoices.totalti - invoices.amountpaid)","currency");//11 |
| | 114 | $this->addColumn("Average Amount Due","avg(invoices.totalti - invoices.amountpaid)","currency");//12 |
| | 115 | |
| | 116 | $this->addColumn("Cost","sum(invoices.totalcost)","currency");//13 |
| | 117 | $this->addColumn("Average Cost","avg(invoices.totalcost)","currency");//14 |
| | 118 | |
| | 119 | $this->addColumn("Total Weight","sum(invoices.totalweight)","real");//15 |
| | 120 | $this->addColumn("Average Total Weight","avg(invoices.totalweight)","real");//16 |
| | 121 | |
| | 122 | $this->selecttable="((`invoices` INNER JOIN `clients` ON `invoices`.`clientid`=`clients`.`uuid`) |
| | 123 | LEFT JOIN `shippingmethods` ON `shippingmethods`.`uuid` = `invoices`.`shippingmethodid`) |
| | 124 | LEFT JOIN `paymentmethods` ON `paymentmethods`.`id`=`invoices`.`paymentmethodid`"; |
| | 125 | |
| | 129 | function processFromPost($variables){ |
| | 130 | |
| | 131 | $tempArray = explode("::", $variables["columns"]); |
| | 132 | |
| | 133 | foreach($tempArray as $id) |
| | 134 | $this->selectcolumns[] = $this->columns[$id]; |
| | 135 | |
| | 136 | $this->selectcolumns = array_reverse($this->selectcolumns); |
| | 137 | |
| | 138 | if($variables["groupings"] !== ""){ |
| | 139 | |
| | 140 | $this->group = explode("::",$variables["groupings"]); |
| | 141 | $this->group = array_reverse($this->group); |
| | 142 | |
| | 143 | } else |
| | 144 | $this->group = array(); |
| | 145 | |
| | 146 | foreach($this->group as $grp) |
| | 147 | if($this->groupings[$grp]["table"]) |
| | 148 | $this->selecttable="(".$this->selecttable." ".$this->groupings[$grp]["table"].")"; |
| | 149 | |
| | 150 | switch($variables["showwhat"]){ |
| | 151 | |
| | 152 | case "invoices": |
| | 153 | $this->showinvoices = true; |
| | 154 | $this->showlineitems = false; |
| | 155 | break; |
| | 156 | |
| | 157 | case "lineitems": |
| | 158 | $this->showinvoices = true; |
| | 159 | $this->showlineitems = true; |
| | 160 | break; |
| | 161 | |
| | 162 | default: |
| | 163 | $this->showinvoices = false; |
| | 164 | $this->showlineitems = false; |
| | 165 | |
| | 166 | }// endswitch |
| | 167 | |
| | 168 | if($variables["reporttitle"]) |
| | 169 | $this->title = $variables["reporttitle"]; |
| | 170 | |
| | 171 | }//end function processFromPost |
| | 172 | |
| | 173 | |
| | 174 | function processFromSettings(){ |
| | 175 | |
| | 176 | foreach($this->settings as $key=>$value) |
| | 177 | if(strpos($key, "column") === 0) |
| | 178 | $this->selectcolumns[substr($key,6)-1] = $this->columns[$value]; |
| | 179 | |
| | 180 | ksort($this->selectcolumns); |
| | 181 | $this->selectcolumns = array_reverse($this->selectcolumns); |
| | 182 | |
| | 183 | $this->group = array(); |
| | 184 | |
| | 185 | foreach($this->settings as $key=>$value) |
| | 186 | if(strpos($key, "group") === 0) |
| | 187 | $this->group[substr($key,5)-1] = $value; |
| | 188 | |
| | 189 | ksort($this->group); |
| | 190 | $this->group = array_reverse($this->group); |
| | 191 | |
| | 192 | foreach($this->group as $grp) |
| | 193 | if($this->groupings[$grp]["table"]) |
| | 194 | $this->selecttable="(".$this->selecttable." ".$this->groupings[$grp]["table"].")"; |
| | 195 | |
| | 196 | |
| | 197 | if(isset($this->settings["showWhat"])) |
| | 198 | $showWhat = $this->settings["showWhat"]; |
| | 199 | else |
| | 200 | $showWhat = ""; |
| | 201 | |
| | 202 | switch($showWhat){ |
| | 203 | |
| | 204 | case "invoices": |
| | 205 | $this->showinvoices = true; |
| | 206 | $this->showlineitems = false; |
| | 207 | break; |
| | 208 | |
| | 209 | case "lineitems": |
| | 210 | $this->showinvoices = true; |
| | 211 | $this->showlineitems = true; |
| | 212 | break; |
| | 213 | |
| | 214 | default: |
| | 215 | $this->showinvoices = false; |
| | 216 | $this->showlineitems = false; |
| | 217 | |
| | 218 | }// endswitch |
| | 219 | |
| | 220 | if(isset($this->settings["reportTitle"])) |
| | 221 | $this->title = $this->settings["reportTitle"]; |
| | 222 | |
| | 223 | }//end function processFromSettings |
| | 224 | |
| | 225 | |