| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | $Rev$ | $LastChangedBy$ |
|---|
| 4 | $LastChangedDate$ |
|---|
| 5 | +-------------------------------------------------------------------------+ |
|---|
| 6 | | Copyright (c) 2004 - 2010, Kreotek LLC | |
|---|
| 7 | | All rights reserved. | |
|---|
| 8 | +-------------------------------------------------------------------------+ |
|---|
| 9 | | | |
|---|
| 10 | | Redistribution and use in source and binary forms, with or without | |
|---|
| 11 | | modification, are permitted provided that the following conditions are | |
|---|
| 12 | | met: | |
|---|
| 13 | | | |
|---|
| 14 | | - Redistributions of source code must retain the above copyright | |
|---|
| 15 | | notice, this list of conditions and the following disclaimer. | |
|---|
| 16 | | | |
|---|
| 17 | | - Redistributions in binary form must reproduce the above copyright | |
|---|
| 18 | | notice, this list of conditions and the following disclaimer in the | |
|---|
| 19 | | documentation and/or other materials provided with the distribution. | |
|---|
| 20 | | | |
|---|
| 21 | | - Neither the name of Kreotek LLC nor the names of its contributore may | |
|---|
| 22 | | be used to endorse or promote products derived from this software | |
|---|
| 23 | | without specific prior written permission. | |
|---|
| 24 | | | |
|---|
| 25 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
|---|
| 26 | | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
|---|
| 27 | | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | |
|---|
| 28 | | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
|---|
| 29 | | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
|---|
| 30 | | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
|---|
| 31 | | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
|---|
| 32 | | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
|---|
| 33 | | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
|---|
| 34 | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
|---|
| 35 | | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
|---|
| 36 | | | |
|---|
| 37 | +-------------------------------------------------------------------------+ |
|---|
| 38 | */ |
|---|
| 39 | |
|---|
| 40 | include("../../include/session.php"); |
|---|
| 41 | |
|---|
| 42 | include("../../include/fields.php"); |
|---|
| 43 | |
|---|
| 44 | if(!isset($_GET["id"])) |
|---|
| 45 | $error = new appError(300,"Passed variable not set (id)"); |
|---|
| 46 | |
|---|
| 47 | $clientquerystatement="SELECT firstname,lastname,company FROM clients WHERE id=".$_GET["id"]; |
|---|
| 48 | $clientqueryresult=$db->query($clientquerystatement); |
|---|
| 49 | |
|---|
| 50 | $clientrecord=$db->fetchArray($clientqueryresult); |
|---|
| 51 | |
|---|
| 52 | if(!isset($_POST["fromdate"])) $_POST["fromdate"]=dateToString(strtotime("-1 year")); |
|---|
| 53 | if(!isset($_POST["todate"])) $_POST["todate"]=dateToString(mktime()); |
|---|
| 54 | if(!isset($_POST["status"])) $_POST["status"]="Orders and Invoices"; |
|---|
| 55 | if(!isset($_POST["command"])) $_POST["command"]="show"; |
|---|
| 56 | |
|---|
| 57 | if($_POST["command"]=="print") { |
|---|
| 58 | |
|---|
| 59 | $_SESSION["printing"]["whereclause"] = "clients.id=".$_GET["id"]; |
|---|
| 60 | $_SESSION["printing"]["dataprint"] = "Single Record"; |
|---|
| 61 | |
|---|
| 62 | goURL("report/clients_purchasehistory.php?rid=".urlencode("rpt:1908b03c-cacc-f03a-6d22-21fdef123f65")."&tid=".urlencode("tbld:6d290174-8b73-e199-fe6c-bcf3d4b61083")."&status=".urlencode($_POST["status"])."&fromdate=".urlencode($_POST["fromdate"])."&todate=".urlencode($_POST["todate"])); |
|---|
| 63 | |
|---|
| 64 | } else { |
|---|
| 65 | |
|---|
| 66 | $pageTitle="Client Purchase History: "; |
|---|
| 67 | if($clientrecord["company"]=="") |
|---|
| 68 | $pageTitle.=$clientrecord["firstname"]." ".$clientrecord["lastname"]; |
|---|
| 69 | else |
|---|
| 70 | $pageTitle.=$clientrecord["company"]; |
|---|
| 71 | |
|---|
| 72 | $thestatus="(invoices.type =\""; |
|---|
| 73 | |
|---|
| 74 | switch($_POST["status"]){ |
|---|
| 75 | case "Orders and Invoices": |
|---|
| 76 | $thestatus.="Order\" or invoices.type=\"Invoice\")"; |
|---|
| 77 | break; |
|---|
| 78 | case "Invoices": |
|---|
| 79 | $thestatus.="Invoice\")"; |
|---|
| 80 | break; |
|---|
| 81 | case "Orders": |
|---|
| 82 | $thestatus.="Order\")"; |
|---|
| 83 | break; |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | $mysqlfromdate=sqlDateFromString($_POST["fromdate"]); |
|---|
| 87 | $mysqltodate=sqlDateFromString($_POST["todate"]); |
|---|
| 88 | |
|---|
| 89 | //get history |
|---|
| 90 | $querystatement=" |
|---|
| 91 | SELECT |
|---|
| 92 | invoices.id, |
|---|
| 93 | IF(invoices.type = 'Invoice', invoices.invoicedate, invoices.orderdate) AS thedate, |
|---|
| 94 | invoices.type, |
|---|
| 95 | products.partname AS partname, |
|---|
| 96 | products.partnumber AS partnumber, |
|---|
| 97 | lineitems.quantity AS qty, |
|---|
| 98 | lineitems.unitprice * lineitems.quantity AS extended, |
|---|
| 99 | lineitems.unitprice AS price |
|---|
| 100 | FROM |
|---|
| 101 | ((clients INNER JOIN invoices ON clients.uuid = invoices.clientid) |
|---|
| 102 | INNER JOIN lineitems ON invoices.id = lineitems.invoiceid) |
|---|
| 103 | LEFT JOIN products ON lineitems.productid = products.uuid |
|---|
| 104 | WHERE |
|---|
| 105 | clients.id=".$_GET["id"]." |
|---|
| 106 | AND ".$thestatus." |
|---|
| 107 | HAVING |
|---|
| 108 | thedate >='".$mysqlfromdate."' |
|---|
| 109 | AND thedate <= '".$mysqltodate."' |
|---|
| 110 | ORDER BY |
|---|
| 111 | thedate, |
|---|
| 112 | invoices.id"; |
|---|
| 113 | |
|---|
| 114 | $queryresult=$db->query($querystatement); |
|---|
| 115 | |
|---|
| 116 | $numrows=$db->numRows($queryresult); |
|---|
| 117 | |
|---|
| 118 | $phpbms->cssIncludes[] = "pages/client.css"; |
|---|
| 119 | |
|---|
| 120 | //Form Elements |
|---|
| 121 | //============================================================== |
|---|
| 122 | $theform = new phpbmsForm(); |
|---|
| 123 | |
|---|
| 124 | $theinput = new inputDatePicker("fromdate",sqlDateFromString($_POST["fromdate"]), "from" ,true); |
|---|
| 125 | $theform->addField($theinput); |
|---|
| 126 | |
|---|
| 127 | $theinput = new inputDatePicker("todate",sqlDateFromString($_POST["todate"]), "to" ,true); |
|---|
| 128 | $theform->addField($theinput); |
|---|
| 129 | |
|---|
| 130 | $theform->jsMerge(); |
|---|
| 131 | //============================================================== |
|---|
| 132 | //End Form Elements |
|---|
| 133 | |
|---|
| 134 | include("header.php"); |
|---|
| 135 | |
|---|
| 136 | $phpbms->showTabs("clients entry", "tab:ef895fc0-bbea-9bf5-47ac-4913c6dace13", ((int) $_GET["id"]));?><div class="bodyline"> |
|---|
| 137 | |
|---|
| 138 | <h1><?php echo $pageTitle ?></h1> |
|---|
| 139 | |
|---|
| 140 | <form action="<?php echo htmlentities($_SERVER["REQUEST_URI"]) ?>" method="post" name="record"> |
|---|
| 141 | <div class="box"> |
|---|
| 142 | <p class="timelineP"> |
|---|
| 143 | <label for="status">type</label><br /> |
|---|
| 144 | <select name="status" id="status"> |
|---|
| 145 | <option value="Orders and Invoices" <?php if($_POST["status"]=="Orders and Invoices") echo "selected=\"selected\""?>>Orders and Invoices</option> |
|---|
| 146 | <option value="Invoices" <?php if($_POST["status"]=="Invoices") echo "selected=\"selected\""?>>Invoices</option> |
|---|
| 147 | <option value="Orders" <?php if($_POST["status"]=="Orders") echo "selected=\"selected\""?>>Orders</option> |
|---|
| 148 | </select> |
|---|
| 149 | </p> |
|---|
| 150 | |
|---|
| 151 | <p class="timelineP"><?php $theform->showField("fromdate")?></p> |
|---|
| 152 | |
|---|
| 153 | <p class="timelineP"><?php $theform->showField("todate")?></p> |
|---|
| 154 | |
|---|
| 155 | <p id="printP"><br /><input id="print" name="command" type="submit" value="print" class="Buttons" /></p> |
|---|
| 156 | <p id="changeTimelineP"><br /><input name="command" type="submit" value="update" class="smallButtons" /></p> |
|---|
| 157 | </div> |
|---|
| 158 | </form> |
|---|
| 159 | <div class="fauxP"> |
|---|
| 160 | <table border="0" cellpadding="0" cellspacing="0" class="querytable"> |
|---|
| 161 | <thead> |
|---|
| 162 | <tr> |
|---|
| 163 | <th align="left" nowrap="nowrap" class="queryheader" colspan="4">invoice</th> |
|---|
| 164 | <th align="left" nowrap="nowrap" class="queryheader" colspan="3">product</th> |
|---|
| 165 | <th align="left" nowrap="nowrap" class="queryheader" colspan="2">line item</th> |
|---|
| 166 | </tr> |
|---|
| 167 | <tr> |
|---|
| 168 | <th align="center" nowrap="nowrap" class="queryheader" colspan="2">id</th> |
|---|
| 169 | <th align="left" nowrap="nowrap" class="queryheader">type</th> |
|---|
| 170 | <th align="left" nowrap="nowrap" class="queryheader">date</th> |
|---|
| 171 | <th nowrap="nowrap" class="queryheader" align="left">part num. </th> |
|---|
| 172 | <th width="100%" class="queryheader" align="left">name</th> |
|---|
| 173 | <th align="right" nowrap="nowrap" class="queryheader">price</th> |
|---|
| 174 | <th align="center" nowrap="nowrap" class="queryheader">qty.</th> |
|---|
| 175 | <th align="right" nowrap="nowrap" class="queryheader">ext.</th> |
|---|
| 176 | </tr> |
|---|
| 177 | </thead> |
|---|
| 178 | |
|---|
| 179 | <?php |
|---|
| 180 | $totalextended=0; |
|---|
| 181 | $row=1; |
|---|
| 182 | ob_start(); |
|---|
| 183 | ?><tbody><?php |
|---|
| 184 | while ($therecord=$db->fetchArray($queryresult)){ |
|---|
| 185 | $row==1? $row++ : $row--; |
|---|
| 186 | $totalextended=$totalextended+$therecord["extended"]; |
|---|
| 187 | ?> |
|---|
| 188 | <tr class="row<?php echo $row?>"> |
|---|
| 189 | <td > |
|---|
| 190 | <button type="button" class="invisibleButtons" onclick="location.href='<?php echo getAddEditFile($db, "tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883") ?>?id=<?php echo $therecord["id"]?>'"><img src="<?php echo APP_PATH ?>common/stylesheet/<?php echo STYLESHEET ?>/image/button-edit.png" align="middle" alt="edit" width="16" height="16" border="0" /></button> |
|---|
| 191 | </td> |
|---|
| 192 | <td align="left" nowrap="nowrap"><?php echo $therecord["id"]?$therecord["id"]:" " ?></td> |
|---|
| 193 | <td align="left" nowrap="nowrap"><?php echo $therecord["type"]?$therecord["type"]:" " ?></td> |
|---|
| 194 | <td align="left" nowrap="nowrap"><?php echo $therecord["thedate"]?formatFromSQLDate($therecord["thedate"]):" " ?></td> |
|---|
| 195 | <td nowrap="nowrap"><?php echo $therecord["partnumber"]?></td> |
|---|
| 196 | <td ><?php echo $therecord["partname"]?></td> |
|---|
| 197 | <td align="right" nowrap="nowrap"><?php echo numberToCurrency($therecord["price"])?></td> |
|---|
| 198 | <td align="center" nowrap="nowrap"><?php echo $therecord["qty"]?></td> |
|---|
| 199 | <td align="right" nowrap="nowrap"><?php echo numberToCurrency($therecord["extended"])?></td> |
|---|
| 200 | </tr> |
|---|
| 201 | <?php }//end while ?> |
|---|
| 202 | <?php if(!$db->numRows($queryresult)) {?> |
|---|
| 203 | <tr class="norecords"><td colspan="9" align="center" >No Sales Data for Given Timeframe</td></tr> |
|---|
| 204 | <?php }?> |
|---|
| 205 | </tbody> |
|---|
| 206 | <?php |
|---|
| 207 | $tbody = ob_get_clean(); |
|---|
| 208 | ?> |
|---|
| 209 | <tfoot> |
|---|
| 210 | <tr class="queryfooter"> |
|---|
| 211 | <td align="center" colspan="2"> </td> |
|---|
| 212 | <td align="center" > </td> |
|---|
| 213 | <td align="center" > </td> |
|---|
| 214 | <td > </td> |
|---|
| 215 | <td > </td> |
|---|
| 216 | <td align="right" > </td> |
|---|
| 217 | <td align="center" > </td> |
|---|
| 218 | <td align="right" ><?php echo numberToCurrency($totalextended)?></td> |
|---|
| 219 | </tr> |
|---|
| 220 | </tfoot> |
|---|
| 221 | <?php echo $tbody; ?> |
|---|
| 222 | </table> |
|---|
| 223 | </div></div><?php include("footer.php"); } //end if?> |
|---|