Initial import.
[openemr.git] / interface / billing / sl_receipts_report.php
blob4b9ef65bea019faa982316b9e528c4e05b42e4b1
1 <?
2 // This module was written for one of my clients to report on cash
3 // receipts by practitioner. It is not as complete as it should be
4 // but I wanted to make the code available to the project because
5 // many other practices have this same need. - rod@sunsetsystems.com
7 include_once("../globals.php");
8 include_once("../../library/patient.inc");
9 include_once("../../library/sql-ledger.inc");
10 include_once("../../library/acl.inc");
12 // This determines if a particular procedure code corresponds to receipts
13 // for the "Clinic" column as opposed to receipts for the practitioner. Each
14 // practice will have its own policies in this regard, so you'll probably
15 // have to customize this function. If you use the "fee sheet" encounter
16 // form then the code below may work for you.
18 include_once("../forms/fee_sheet/codes.php");
19 function is_clinic($code) {
20 global $cpt, $hcpcs;
21 return ($cpt['Lab'][$code] || $cpt['Immunizations'][$code] ||
22 $hcpcs['Therapeutic Injections'][$code]);
25 function bucks($amount) {
26 if ($amount)
27 printf("%.2f", $amount);
30 if (! acl_check('acct', 'rep')) die("Unauthorized access.");
32 SLConnect();
34 <html>
35 <head>
36 <title>Receipts for Medical Services</title>
37 </head>
39 <body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>
40 <center>
42 <h2>Cash Receipts</h2>
44 <form method='post' action='sl_receipts_report.php'>
46 <table border='0' cellpadding='3'>
48 <tr>
49 <td>
51 if (acl_check('acct', 'rep_a')) {
52 // Build a drop-down list of providers.
54 $query = "select id, lname, fname from users where " .
55 "authorized = 1 order by lname, fname";
56 $res = sqlStatement($query);
57 echo " <select name='form_doctor'>\n";
58 echo " <option value=''>All Providers\n";
59 while ($row = sqlFetchArray($res)) {
60 $provid = $row['id'];
61 echo " <option value='$provid'";
62 if ($provid == $_POST['form_doctor']) echo " selected";
63 echo ">" . $row['lname'] . ", " . $row['fname'] . "\n";
65 echo " </select>\n";
66 } else {
67 echo "<input type='hidden' name='form_doctor' value='" . $_SESSION['authUserID'] . "'>";
70 &nbsp;From:
71 <input type='text' name='form_from_date' size='10' value='<? echo $_POST['form_from_date']; ?>' title='MM/DD/YYYY'>
72 &nbsp;To:
73 <input type='text' name='form_to_date' size='10' value='<? echo $_POST['form_to_date']; ?>' title='MM/DD/YYYY'>
74 &nbsp;
75 <input type='checkbox' name='form_details' value='1'<? if ($_POST['form_details']) echo " checked"; ?>>Details
76 &nbsp;
77 <input type='submit' name='form_refresh' value='Refresh'>
78 </td>
79 </tr>
81 <tr>
82 <td height="1">
83 </td>
84 </tr>
86 </table>
88 <table border='0' cellpadding='1' cellspacing='2' width='98%'>
90 <tr bgcolor="#dddddd">
91 <td class="dehead">
92 Practitioner
93 </td>
94 <td class="dehead">
95 Date
96 </td>
97 <td class="dehead">
98 Invoice
99 </td>
100 <td class="dehead">
101 Procedure
102 </td>
103 <td class="dehead" align="right">
104 Prof.
105 </td>
106 <td class="dehead" align="right">
107 Clinic
108 </td>
109 </tr>
111 $chart_id_cash = SLQueryValue("select id from chart where accno = '$sl_cash_acc'");
112 if ($sl_err) die($sl_err);
114 if ($_POST['form_refresh']) {
115 $form_doctor = $_POST['form_doctor'];
116 $from_date = fixDate($_POST['form_from_date']);
117 $to_date = fixDate($_POST['form_to_date']);
119 $query = "select acc_trans.amount, acc_trans.transdate, acc_trans.memo, " .
120 "ar.invnumber, ar.employee_id from acc_trans, ar where " .
121 "acc_trans.chart_id = $chart_id_cash and " .
122 "acc_trans.transdate >= '$from_date' and " .
123 "acc_trans.transdate <= '$to_date' and " .
124 "ar.id = acc_trans.trans_id";
126 if ($form_doctor) {
127 $tmp = sqlQuery("select foreign_id from integration_mapping where " .
128 "foreign_table = 'salesman' and local_id = $form_doctor");
129 // $emplid = SLQueryValue("select id from employee where employeenumber = " .
130 // $tmp['foreign_id']);
131 $emplid = $tmp['foreign_id'];
132 $query .= " and ar.employee_id = $emplid";
135 $query .= " order by ar.employee_id, acc_trans.transdate, ar.invnumber, acc_trans.memo";
137 echo "<!-- $query -->\n";
139 $t_res = SLQuery($query);
140 if ($sl_err) die($sl_err);
142 $docname = "";
143 $docnameleft = "";
144 $docid = 0;
145 $doctotal1 = 0;
146 $grandtotal1 = 0;
147 $doctotal2 = 0;
148 $grandtotal2 = 0;
150 for ($irow = 0; $irow < SLRowCount($t_res); ++$irow) {
151 $row = SLGetRow($t_res, $irow);
152 $amount1 = 0;
153 $amount2 = 0;
154 if (is_clinic($row['memo']))
155 $amount2 -= $row['amount'];
156 else
157 $amount1 -= $row['amount'];
159 if ($docid != $row['employee_id']) {
160 if ($docid) {
161 // Print doc totals.
164 <tr bgcolor="#ddddff">
165 <td class="detail" colspan="4">
166 Totals for <? echo $docname ?>
167 </td>
168 <td class="dehead" align="right">
169 <? bucks($doctotal1) ?>
170 </td>
171 <td class="dehead" align="right">
172 <? bucks($doctotal2) ?>
173 </td>
174 </tr>
177 $doctotal1 = 0;
178 $doctotal2 = 0;
179 $docid = $row['employee_id'];
180 $docname = SLQueryValue("select name from employee where id = $docid");
181 $docnameleft = $docname;
184 if ($_POST['form_details']) {
187 <tr>
188 <td class="detail">
189 <? echo $docnameleft; $docnameleft = "&nbsp;" ?>
190 </td>
191 <td class="dehead">
192 <? echo $row['transdate'] ?>
193 </td>
194 <td class="detail">
195 <? echo $row['invnumber'] ?>
196 </td>
197 <td class="dehead">
198 <? echo $row['memo'] ?>
199 </td>
200 <td class="dehead" align="right">
201 <? bucks($amount1) ?>
202 </td>
203 <td class="dehead" align="right">
204 <? bucks($amount2) ?>
205 </td>
206 </tr>
209 $doctotal1 += $amount1;
210 $doctotal2 += $amount2;
211 $grandtotal1 += $amount1;
212 $grandtotal2 += $amount2;
216 <tr bgcolor="#ddddff">
217 <td class="detail" colspan="4">
218 Totals for <? echo $docname ?>
219 </td>
220 <td class="dehead" align="right">
221 <? bucks($doctotal1) ?>
222 </td>
223 <td class="dehead" align="right">
224 <? bucks($doctotal2) ?>
225 </td>
226 </tr>
228 <tr bgcolor="#ffdddd">
229 <td class="detail" colspan="4">
230 Grand Totals
231 </td>
232 <td class="dehead" align="right">
233 <? bucks($grandtotal1) ?>
234 </td>
235 <td class="dehead" align="right">
236 <? bucks($grandtotal2) ?>
237 </td>
238 </tr>
242 SLClose();
245 </table>
246 </form>
247 </center>
248 </body>
249 </html>