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) {
21 return ($cpt['Lab'][$code] ||
$cpt['Immunizations'][$code] ||
22 $hcpcs['Therapeutic Injections'][$code]);
25 function bucks($amount) {
27 printf("%.2f", $amount);
30 if (! acl_check('acct', 'rep')) die("Unauthorized access.");
36 <title
>Receipts
for Medical Services
</title
>
39 <body leftmargin
='0' topmargin
='0' marginwidth
='0' marginheight
='0'>
42 <h2
>Cash Receipts
</h2
>
44 <form method
='post' action
='sl_receipts_report.php'>
46 <table border
='0' cellpadding
='3'>
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)) {
61 echo " <option value='$provid'";
62 if ($provid == $_POST['form_doctor']) echo " selected";
63 echo ">" . $row['lname'] . ", " . $row['fname'] . "\n";
67 echo "<input type='hidden' name='form_doctor' value='" . $_SESSION['authUserID'] . "'>";
71 <input type
='text' name
='form_from_date' size
='10' value
='<? echo $_POST['form_from_date
']; ?>' title
='MM/DD/YYYY'>
73 <input type
='text' name
='form_to_date' size
='10' value
='<? echo $_POST['form_to_date
']; ?>' title
='MM/DD/YYYY'>
75 <input type
='checkbox' name
='form_details' value
='1'<?
if ($_POST['form_details']) echo " checked"; ?
>>Details
77 <input type
='submit' name
='form_refresh' value
='Refresh'>
88 <table border
='0' cellpadding
='1' cellspacing
='2' width
='98%'>
90 <tr bgcolor
="#dddddd">
103 <td
class="dehead" align
="right">
106 <td
class="dehead" align
="right">
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";
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);
150 for ($irow = 0; $irow < SLRowCount($t_res); ++
$irow) {
151 $row = SLGetRow($t_res, $irow);
154 if (is_clinic($row['memo']))
155 $amount2 -= $row['amount'];
157 $amount1 -= $row['amount'];
159 if ($docid != $row['employee_id']) {
164 <tr bgcolor
="#ddddff">
165 <td
class="detail" colspan
="4">
166 Totals
for <?
echo $docname ?
>
168 <td
class="dehead" align
="right">
169 <?
bucks($doctotal1) ?
>
171 <td
class="dehead" align
="right">
172 <?
bucks($doctotal2) ?
>
179 $docid = $row['employee_id'];
180 $docname = SLQueryValue("select name from employee where id = $docid");
181 $docnameleft = $docname;
184 if ($_POST['form_details']) {
189 <?
echo $docnameleft; $docnameleft = " " ?
>
192 <?
echo $row['transdate'] ?
>
195 <?
echo $row['invnumber'] ?
>
198 <?
echo $row['memo'] ?
>
200 <td
class="dehead" align
="right">
201 <?
bucks($amount1) ?
>
203 <td
class="dehead" align
="right">
204 <?
bucks($amount2) ?
>
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 ?
>
220 <td
class="dehead" align
="right">
221 <?
bucks($doctotal1) ?
>
223 <td
class="dehead" align
="right">
224 <?
bucks($doctotal2) ?
>
228 <tr bgcolor
="#ffdddd">
229 <td
class="detail" colspan
="4">
232 <td
class="dehead" align
="right">
233 <?
bucks($grandtotal1) ?
>
235 <td
class="dehead" align
="right">
236 <?
bucks($grandtotal2) ?
>