2 // Copyright (C) 2006 Rod Roark <rod@sunsetsystems.com>
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 // This is a report of sales by item description. It's driven from
10 // SQL-Ledger so as to include all types of invoice items.
12 include_once("../globals.php");
13 include_once("../../library/patient.inc");
14 include_once("../../library/sql-ledger.inc");
15 include_once("../../library/acl.inc");
17 function bucks($amount) {
19 printf("%.2f", $amount);
22 if (! acl_check('acct', 'rep')) die(xl("Unauthorized access."));
26 $form_from_date = fixDate($_POST['form_from_date'], date('Y-m-d'));
27 $form_to_date = fixDate($_POST['form_to_date'] , date('Y-m-d'));
31 <?
html_header_show();?
>
32 <title
><?
xl('Sales by Item','e')?
></title
>
35 <body leftmargin
='0' topmargin
='0' marginwidth
='0' marginheight
='0'>
38 <h2
><?
xl('Sales by Item','e')?
></h2
>
40 <form method
='post' action
='sales_by_item.php'>
42 <table border
='0' cellpadding
='3'>
46  
;<?
xl('From:','e')?
>
47 <input type
='text' name
='form_from_date' id
="form_from_date" size
='10' value
='<?php echo $form_from_date ?>'
48 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' title
='yyyy-mm-dd'>
49 <img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
50 id
='img_from_date' border
='0' alt
='[?]' style
='cursor:pointer'
51 title
='<?php xl('Click here to choose a date
','e
'); ?>'>
53 <input type
='text' name
='form_to_date' id
="form_to_date" size
='10' value
='<?php echo $form_to_date ?>'
54 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' title
='yyyy-mm-dd'>
55 <img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
56 id
='img_to_date' border
='0' alt
='[?]' style
='cursor:pointer'
57 title
='<?php xl('Click here to choose a date
','e
'); ?>'>
59 <input type
='checkbox' name
='form_details' value
='1'<?
if ($_POST['form_details']) echo " checked"; ?
>><?
xl('Details','e')?
>
61 <input type
='submit' name
='form_refresh' value
="<?xl('Refresh','e')?>">
63 <input type
='button' value
='<?php xl('Print','e
'); ?>' onclick
='window.print()' />
74 <table border
='0' cellpadding
='1' cellspacing
='2' width
='98%'>
76 <tr bgcolor
="#dddddd">
86 <td
class="dehead" align
="right">
89 <td
class="dehead" align
="right">
94 if ($_POST['form_refresh']) {
95 $from_date = $form_from_date;
96 $to_date = $form_to_date;
98 $query = "SELECT ar.invnumber, ar.transdate, " .
99 "invoice.description, invoice.qty, invoice.sellprice " .
100 "FROM ar, invoice WHERE " .
101 "ar.transdate >= '$from_date' AND ar.transdate <= '$to_date' " .
102 "AND invoice.trans_id = ar.id " .
103 "ORDER BY invoice.description, ar.transdate, ar.id";
105 // echo "<!-- $query -->\n"; // debugging
107 $t_res = SLQuery($query);
108 if ($sl_err) die($sl_err);
117 for ($irow = 0; $irow < SLRowCount($t_res); ++
$irow) {
118 $row = SLGetRow($t_res, $irow);
119 // $rowamount = $row['fxsellprice'];
120 $rowamount = sprintf('%01.2f', $row['sellprice'] * $row['qty']);
122 // Extract only the first word as the payment method because any following
123 // text will be some petty detail like a check number.
124 $rowproduct = $row['description'];
125 if (! $rowproduct) $rowproduct = 'Unknown';
127 if ($product != $rowproduct) {
129 // Print product total.
132 <tr bgcolor
="#ddddff">
133 <td
class="detail" colspan
="3">
134 <?
echo xl('Total for ') . $product ?
>
136 <td
class="dehead" align
="right">
137 <?php
echo $productqty; ?
>
139 <td
class="dehead" align
="right">
140 <?php
bucks($producttotal); ?
>
147 $product = $rowproduct;
148 $productleft = $product;
151 if ($_POST['form_details']) {
156 <?php
echo $productleft; $productleft = " "; ?
>
159 <?php
echo $row['transdate']; ?
>
162 <?php
echo $row['invnumber']; ?
>
164 <td
class="dehead" align
="right">
165 <?php
echo $row['qty']; ?
>
167 <td
class="dehead" align
="right">
168 <?php
bucks($rowamount); ?
>
173 $producttotal +
= $rowamount;
174 $grandtotal +
= $rowamount;
175 $productqty +
= $row['qty'];
176 $grandqty +
= $row['qty'];
180 <tr bgcolor
="#ddddff">
181 <td
class="detail" colspan
="3">
182 <?
echo xl('Total for ') . $product ?
>
184 <td
class="dehead" align
="right">
185 <?php
echo $productqty; ?
>
187 <td
class="dehead" align
="right">
188 <?php
bucks($producttotal); ?
>
192 <tr bgcolor
="#ffdddd">
193 <td
class="detail" colspan
="3">
194 <?php
xl('Grand Total','e'); ?
>
196 <td
class="dehead" align
="right">
197 <?php
echo $grandqty; ?
>
199 <td
class="dehead" align
="right">
200 <?php
bucks($grandtotal); ?
>
214 <!-- stuff
for the popup calendar
-->
215 <style type
="text/css">@import
url(../../library
/dynarch_calendar
.css
);</style
>
216 <script type
="text/javascript" src
="../../library/dynarch_calendar.js"></script
>
217 <script type
="text/javascript" src
="../../library/dynarch_calendar_en.js"></script
>
218 <script type
="text/javascript" src
="../../library/dynarch_calendar_setup.js"></script
>
219 <script language
="Javascript">
220 Calendar
.setup({inputField
:"form_from_date", ifFormat
:"%Y-%m-%d", button
:"img_from_date"});
221 Calendar
.setup({inputField
:"form_to_date", ifFormat
:"%Y-%m-%d", button
:"img_to_date"});