Left menu navigations bug fixes:
[openemr.git] / interface / billing / sl_receipts_report.php
blob8ab8b0f80a4dfd6fe29649129c8a0e16429befd1
1 <?php
2 // Copyright (C) 2006-2010 Rod Roark <rod@sunsetsystems.com>
3 //
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 module was written for one of my clients to report on cash
10 // receipts by practitioner. It is not as complete as it should be
11 // but I wanted to make the code available to the project because
12 // many other practices have this same need. - rod@sunsetsystems.com
14 require_once("../globals.php");
15 require_once("$srcdir/patient.inc");
16 require_once("$srcdir/sql-ledger.inc");
17 require_once("$srcdir/acl.inc");
18 require_once("$srcdir/formatting.inc.php");
19 require_once "$srcdir/options.inc.php";
20 require_once "$srcdir/formdata.inc.php";
22 // This determines if a particular procedure code corresponds to receipts
23 // for the "Clinic" column as opposed to receipts for the practitioner. Each
24 // practice will have its own policies in this regard, so you'll probably
25 // have to customize this function. If you use the "fee sheet" encounter
26 // form then the code below may work for you.
28 include_once("../forms/fee_sheet/codes.php");
29 function is_clinic($code) {
30 global $bcodes;
31 $i = strpos($code, ':');
32 if ($i) $code = substr($code, 0, $i);
33 return ($bcodes['CPT4'][xl('Lab')][$code] ||
34 $bcodes['CPT4'][xl('Immunizations')][$code] ||
35 $bcodes['HCPCS'][xl('Therapeutic Injections')][$code]);
38 function bucks($amount) {
39 if ($amount) echo oeFormatMoney($amount);
42 if (! acl_check('acct', 'rep')) die(xl("Unauthorized access."));
44 $INTEGRATED_AR = $GLOBALS['oer_config']['ws_accounting']['enabled'] === 2;
46 if (!$INTEGRATED_AR) {
47 SLConnect();
48 $chart_id_cash = SLQueryValue("select id from chart where accno = '$sl_cash_acc'");
49 if ($sl_err) die($sl_err);
52 $form_use_edate = $_POST['form_use_edate'];
53 $form_cptcode = trim($_POST['form_cptcode']);
54 $form_icdcode = trim($_POST['form_icdcode']);
55 $form_procedures = empty($_POST['form_procedures']) ? 0 : 1;
56 $form_from_date = fixDate($_POST['form_from_date'], date('Y-m-01'));
57 $form_to_date = fixDate($_POST['form_to_date'], date('Y-m-d'));
58 $form_facility = $_POST['form_facility'];
60 <html>
61 <head>
62 <?php if (function_exists('html_header_show')) html_header_show(); ?>
63 <style type="text/css">
64 /* specifically include & exclude from printing */
65 @media print {
66 #report_parameters {
67 visibility: hidden;
68 display: none;
70 #report_parameters_daterange {
71 visibility: visible;
72 display: inline;
74 #report_results {
75 margin-top: 30px;
79 /* specifically exclude some from the screen */
80 @media screen { N
81 #report_parameters_daterange {
82 visibility: hidden;
83 display: none;
86 </style>
87 <title><?xl('Cash Receipts by Provider','e')?></title>
88 </head>
90 <body class="body_top">
92 <span class='title'><?php xl('Report','e'); ?> - <?php xl('Cash Receipts by Provider','e'); ?></span>
94 <form method='post' action='sl_receipts_report.php' id='theform'>
96 <div id="report_parameters">
98 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
100 <table>
101 <tr>
102 <td width='660px'>
103 <div style='float:left'>
105 <table class='text'>
106 <tr>
107 <td class='label'>
108 <?php xl('Facility','e'); ?>:
109 </td>
110 <td>
111 <?php dropdown_facility(strip_escape_custom($form_facility), 'form_facility'); ?>
112 </td>
113 <td class='label'>
114 <?php xl('Provider','e'); ?>:
115 </td>
116 <td>
117 <?php
118 if (acl_check('acct', 'rep_a')) {
119 // Build a drop-down list of providers.
121 $query = "select id, lname, fname from users where " .
122 "authorized = 1 order by lname, fname";
123 $res = sqlStatement($query);
124 echo " &nbsp;<select name='form_doctor'>\n";
125 echo " <option value=''>-- " . xl('All Providers', 'e') . " --\n";
126 while ($row = sqlFetchArray($res)) {
127 $provid = $row['id'];
128 echo " <option value='$provid'";
129 if ($provid == $_POST['form_doctor']) echo " selected";
130 echo ">" . $row['lname'] . ", " . $row['fname'] . "\n";
132 echo " </select>\n";
133 } else {
134 echo "<input type='hidden' name='form_doctor' value='" . $_SESSION['authUserID'] . "'>";
137 </td>
138 <td>
139 <select name='form_use_edate'>
140 <option value='0'><?php xl('Payment Date','e'); ?></option>
141 <option value='1'<?php if ($form_use_edate) echo ' selected' ?>><?php xl('Invoice Date','e'); ?></option>
142 </select>
143 </td>
144 </tr>
145 <tr>
146 <td class='label'>
147 <?php xl('From','e'); ?>:
148 </td>
149 <td>
150 <input type='text' name='form_from_date' id="form_from_date" size='10' value='<?php echo $form_from_date; ?>'
151 title='Date of appointments mm/dd/yyyy' >
152 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
153 id='img_from_date' border='0' alt='[?]' style='cursor:pointer'
154 title='<?php xl('Click here to choose a date','e'); ?>'>
155 </td>
156 <td class='label'>
157 <?php xl('To','e'); ?>:
158 </td>
159 <td>
160 <input type='text' name='form_to_date' id="form_to_date" size='10' value='<?php echo $form_to_date; ?>'
161 title='Optional end date mm/dd/yyyy' >
162 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
163 id='img_to_date' border='0' alt='[?]' style='cursor:pointer'
164 title='<?php xl('Click here to choose a date','e'); ?>'>
165 </td>
166 <td>&nbsp;</td>
167 </tr>
168 <tr>
169 <td>
170 <?php if (!$GLOBALS['simplified_demographics']) echo '&nbsp;' . xl('CPT', 'e') . ':'; ?>
171 </td>
172 <td>
173 <input type='text' name='form_cptcode' size='5' value='<? echo $form_cptcode; ?>'
174 title='<?php xl('Optional procedure code','e'); ?>'
175 <?php if ($GLOBALS['simplified_demographics']) echo "style='display:none'"; ?>>
176 </td>
178 <td>
179 <?php if (!$GLOBALS['simplified_demographics']) echo '&nbsp;' . xl('ICD', 'e') . ':'; ?>
180 </td>
181 <td>
182 <input type='text' name='form_icdcode' size='5' value='<? echo $form_icdcode; ?>'
183 title='<?php xl('Enter a diagnosis code to exclude all invoices not containing it','e'); ?>'
184 <?php if ($GLOBALS['simplified_demographics']) echo "style='display:none'"; ?>>
185 </td>
187 <td>
188 <input type='checkbox' name='form_details' value='1'<? if ($_POST['form_details']) echo " checked"; ?>><?xl('Details','e')?>
189 <input type='checkbox' name='form_procedures' value='1'<? if ($form_procedures) echo " checked"; ?>><?xl('Procedures','e')?>
190 </td>
191 </tr>
192 </table>
194 </div>
196 </td>
197 <td align='left' valign='middle' height="100%">
198 <table style='border-left:1px solid; width:100%; height:100%' >
199 <tr>
200 <td>
201 <div style='margin-left:15px'>
202 <a href='#' class='css_button' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
203 <span>
204 <?php xl('Submit','e'); ?>
205 </span>
206 </a>
208 <?php if ($_POST['form_refresh']) { ?>
209 <a href='#' class='css_button' onclick='window.print()'>
210 <span>
211 <?php xl('Print','e'); ?>
212 </span>
213 </a>
214 <?php } ?>
215 </div>
216 </td>
217 </tr>
218 </table>
219 </td>
220 </tr>
221 </table>
222 </div>
224 <?php
225 if ($_POST['form_refresh']) {
227 <div id="report_results">
228 <table border='0' cellpadding='1' cellspacing='2' width='98%'>
229 <thead>
230 <th>
231 <?php xl('Practitioner','e') ?>
232 </th>
233 <th>
234 <?php xl('Date','e') ?>
235 </th>
236 <?php if ($form_procedures) { ?>
237 <th>
238 <?php xl('Invoice','e') ?>
239 </th>
240 <?php } ?>
241 <?php if ($form_cptcode) { ?>
242 <th align='right'>
243 <?php xl('InvAmt','e') ?>
244 </th>
245 <?php } ?>
246 <?php if ($form_cptcode) { ?>
247 <th>
248 <?php xl('Insurance','e') ?>
249 </th>
250 <?php } ?>
251 <?php if ($form_procedures) { ?>
252 <th>
253 <?php xl('Procedure','e') ?>
254 </th>
255 <th align="right">
256 <?php xl('Prof.','e') ?>
257 </th>
258 <th align="right">
259 <?php xl('Clinic','e') ?>
260 </th>
261 <?php } else { ?>
262 <th align="right">
263 <?php xl('Received','e') ?>
264 </th>
265 <?php } ?>
266 </thead>
267 <?php
268 if ($_POST['form_refresh']) {
269 $form_doctor = $_POST['form_doctor'];
270 $arows = array();
272 if ($INTEGRATED_AR) {
273 $ids_to_skip = array();
274 $irow = 0;
276 // Get copays. These will be ignored if a CPT code was specified.
278 if (!$form_cptcode) {
279 /*************************************************************
280 $query = "SELECT b.fee, b.pid, b.encounter, b.code_type, b.code, b.modifier, " .
281 "fe.date, fe.id AS trans_id, u.id AS docid " .
282 "FROM billing AS b " .
283 "JOIN form_encounter AS fe ON fe.pid = b.pid AND fe.encounter = b.encounter " .
284 "JOIN forms AS f ON f.pid = b.pid AND f.encounter = b.encounter AND f.formdir = 'newpatient' " .
285 "LEFT OUTER JOIN users AS u ON u.username = f.user " .
286 "WHERE b.code_type = 'COPAY' AND b.activity = 1 AND " .
287 "fe.date >= '$form_from_date 00:00:00' AND fe.date <= '$form_to_date 23:59:59'";
288 // If a facility was specified.
289 if ($form_facility) {
290 $query .= " AND fe.facility_id = '$form_facility'";
292 // If a doctor was specified.
293 if ($form_doctor) {
294 $query .= " AND u.id = '$form_doctor'";
296 *************************************************************/
297 $query = "SELECT b.fee, b.pid, b.encounter, b.code_type, b.code, b.modifier, " .
298 "fe.date, fe.id AS trans_id, fe.provider_id AS docid, fe.invoice_refno " .
299 "FROM billing AS b " .
300 "JOIN form_encounter AS fe ON fe.pid = b.pid AND fe.encounter = b.encounter " .
301 "WHERE b.code_type = 'COPAY' AND b.activity = 1 AND " .
302 "fe.date >= '$form_from_date 00:00:00' AND fe.date <= '$form_to_date 23:59:59'";
303 // If a facility was specified.
304 if ($form_facility) {
305 $query .= " AND fe.facility_id = '$form_facility'";
307 // If a doctor was specified.
308 if ($form_doctor) {
309 $query .= " AND fe.provider_id = '$form_doctor'";
311 /************************************************************/
313 $res = sqlStatement($query);
314 while ($row = sqlFetchArray($res)) {
315 $trans_id = $row['trans_id'];
316 $thedate = substr($row['date'], 0, 10);
317 $patient_id = $row['pid'];
318 $encounter_id = $row['encounter'];
320 if (!empty($ids_to_skip[$trans_id])) continue;
322 // If a diagnosis code was given then skip any invoices without
323 // that diagnosis.
324 if ($form_icdcode) {
325 $tmp = sqlQuery("SELECT count(*) AS count FROM billing WHERE " .
326 "pid = '$patient_id' AND encounter = '$encounter_id' AND " .
327 "code_type = 'ICD9' AND code LIKE '$form_icdcode' AND " .
328 "activity = 1");
329 if (empty($tmp['count'])) {
330 $ids_to_skip[$trans_id] = 1;
331 continue;
335 $key = sprintf("%08u%s%08u%08u%06u", $row['docid'], $thedate,
336 $patient_id, $encounter_id, ++$irow);
337 $arows[$key] = array();
338 $arows[$key]['transdate'] = $thedate;
339 $arows[$key]['amount'] = $row['fee'];
340 $arows[$key]['docid'] = $row['docid'];
341 $arows[$key]['project_id'] = 0;
342 $arows[$key]['memo'] = '';
343 $arows[$key]['invnumber'] = "$patient_id.$encounter_id";
344 $arows[$key]['irnumber'] = $row['invoice_refno'];
345 } // end while
346 } // end copays (not $form_cptcode)
348 // Get ar_activity (having payments), form_encounter, forms, users, optional ar_session
349 /***************************************************************
350 $query = "SELECT a.pid, a.encounter, a.post_time, a.code, a.modifier, a.pay_amount, " .
351 "fe.date, fe.id AS trans_id, u.id AS docid, s.deposit_date, s.payer_id " .
352 "FROM ar_activity AS a " .
353 "JOIN form_encounter AS fe ON fe.pid = a.pid AND fe.encounter = a.encounter " .
354 "JOIN forms AS f ON f.pid = a.pid AND f.encounter = a.encounter AND f.formdir = 'newpatient' " .
355 "LEFT OUTER JOIN users AS u ON u.username = f.user " .
356 "LEFT OUTER JOIN ar_session AS s ON s.session_id = a.session_id " .
357 "WHERE a.pay_amount != 0 AND ( " .
358 "a.post_time >= '$form_from_date 00:00:00' AND a.post_time <= '$form_to_date 23:59:59' " .
359 "OR fe.date >= '$form_from_date 00:00:00' AND fe.date <= '$form_to_date 23:59:59' " .
360 "OR s.deposit_date >= '$form_from_date' AND s.deposit_date <= '$form_to_date' )";
361 // If a procedure code was specified.
362 if ($form_cptcode) $query .= " AND a.code = '$form_cptcode'";
363 // If a facility was specified.
364 if ($form_facility) $query .= " AND fe.facility_id = '$form_facility'";
365 // If a doctor was specified.
366 if ($form_doctor) $query .= " AND u.id = '$form_doctor'";
367 ***************************************************************/
368 $query = "SELECT a.pid, a.encounter, a.post_time, a.code, a.modifier, a.pay_amount, " .
369 "fe.date, fe.id AS trans_id, fe.provider_id AS docid, fe.invoice_refno, s.deposit_date, s.payer_id, " .
370 "b.provider_id " .
371 "FROM ar_activity AS a " .
372 "JOIN form_encounter AS fe ON fe.pid = a.pid AND fe.encounter = a.encounter " .
373 "LEFT OUTER JOIN ar_session AS s ON s.session_id = a.session_id " .
374 "LEFT OUTER JOIN billing AS b ON b.pid = a.pid AND b.encounter = a.encounter AND " .
375 "b.code = a.code AND b.modifier = a.modifier AND b.activity = 1 AND " .
376 "b.code_type != 'COPAY' AND b.code_type != 'TAX' " .
377 "WHERE a.pay_amount != 0 AND ( " .
378 "a.post_time >= '$form_from_date 00:00:00' AND a.post_time <= '$form_to_date 23:59:59' " .
379 "OR fe.date >= '$form_from_date 00:00:00' AND fe.date <= '$form_to_date 23:59:59' " .
380 "OR s.deposit_date >= '$form_from_date' AND s.deposit_date <= '$form_to_date' )";
381 // If a procedure code was specified.
382 if ($form_cptcode) $query .= " AND a.code = '$form_cptcode'";
383 // If a facility was specified.
384 if ($form_facility) $query .= " AND fe.facility_id = '$form_facility'";
385 // If a doctor was specified.
386 if ($form_doctor) {
387 $query .= " AND ( b.provider_id = '$form_doctor' OR " .
388 "( ( b.provider_id IS NULL OR b.provider_id = 0 ) AND " .
389 "fe.provider_id = '$form_doctor' ) )";
391 /**************************************************************/
393 $res = sqlStatement($query);
394 while ($row = sqlFetchArray($res)) {
395 $trans_id = $row['trans_id'];
396 $patient_id = $row['pid'];
397 $encounter_id = $row['encounter'];
399 if (!empty($ids_to_skip[$trans_id])) continue;
401 if ($form_use_edate) {
402 $thedate = substr($row['date'], 0, 10);
403 } else {
404 if (!empty($row['deposit_date']))
405 $thedate = $row['deposit_date'];
406 else
407 $thedate = substr($row['post_time'], 0, 10);
409 if (strcmp($thedate, $form_from_date) < 0 || strcmp($thedate, $form_to_date) > 0) continue;
411 // If a diagnosis code was given then skip any invoices without
412 // that diagnosis.
413 if ($form_icdcode) {
414 $tmp = sqlQuery("SELECT count(*) AS count FROM billing WHERE " .
415 "pid = '$patient_id' AND encounter = '$encounter_id' AND " .
416 "code_type = 'ICD9' AND code LIKE '$form_icdcode' AND " .
417 "activity = 1");
418 if (empty($tmp['count'])) {
419 $ids_to_skip[$trans_id] = 1;
420 continue;
424 $docid = empty($row['encounter_id']) ? $row['docid'] : $row['encounter_id'];
425 $key = sprintf("%08u%s%08u%08u%06u", $docid, $thedate,
426 $patient_id, $encounter_id, ++$irow);
427 $arows[$key] = array();
428 $arows[$key]['transdate'] = $thedate;
429 $arows[$key]['amount'] = 0 - $row['pay_amount'];
430 $arows[$key]['docid'] = $docid;
431 $arows[$key]['project_id'] = empty($row['payer_id']) ? 0 : $row['payer_id'];
432 $arows[$key]['memo'] = $row['code'];
433 $arows[$key]['invnumber'] = "$patient_id.$encounter_id";
434 $arows[$key]['irnumber'] = $row['invoice_refno'];
435 } // end while
436 } // end $INTEGRATED_AR
438 else {
439 if ($form_cptcode) {
440 $query = "SELECT acc_trans.amount, acc_trans.transdate, " .
441 "acc_trans.memo, acc_trans.project_id, acc_trans.trans_id, " .
442 "ar.invnumber, ar.employee_id, invoice.sellprice, invoice.qty " .
443 "FROM acc_trans, ar, invoice WHERE " .
444 "acc_trans.chart_id = $chart_id_cash AND " .
445 "acc_trans.memo ILIKE '$form_cptcode' AND " .
446 "ar.id = acc_trans.trans_id AND " .
447 "invoice.trans_id = acc_trans.trans_id AND " .
448 "invoice.serialnumber ILIKE acc_trans.memo AND " .
449 "invoice.sellprice >= 0.00 AND " .
450 "( invoice.description ILIKE 'CPT%' OR invoice.description ILIKE 'Proc%' ) AND ";
452 else {
453 $query = "select acc_trans.amount, acc_trans.transdate, " .
454 "acc_trans.memo, acc_trans.trans_id, " .
455 "ar.invnumber, ar.employee_id from acc_trans, ar where " .
456 "acc_trans.chart_id = $chart_id_cash and " .
457 "ar.id = acc_trans.trans_id and ";
460 if ($form_use_edate) {
461 $query .= "ar.transdate >= '$form_from_date' and " .
462 "ar.transdate <= '$form_to_date'";
463 } else {
464 $query .= "acc_trans.transdate >= '$form_from_date' and " .
465 "acc_trans.transdate <= '$form_to_date'";
468 $query .= " order by ar.invnumber";
470 // echo "<!-- $query -->\n"; // debugging
472 $t_res = SLQuery($query);
473 if ($sl_err) die($sl_err);
475 $docname = "";
476 $docnameleft = "";
477 $main_docid = 0;
478 $doctotal1 = 0;
479 $grandtotal1 = 0;
480 $doctotal2 = 0;
481 $grandtotal2 = 0;
482 $last_trans_id = 0;
483 $skipping = false;
485 for ($irow = 0; $irow < SLRowCount($t_res); ++$irow) {
486 $row = SLGetRow($t_res, $irow);
488 list($patient_id, $encounter_id) = explode(".", $row['invnumber']);
490 // Under some conditions we may skip invoices that matched the SQL query.
492 if ($row['trans_id'] == $last_trans_id) {
493 if ($skipping) continue;
494 // same invoice and not skipping, do nothing.
495 } else { // new invoice
496 $skipping = false;
497 // If a diagnosis code was given then skip any invoices without
498 // that diagnosis.
499 if ($form_icdcode) {
500 if (!SLQueryValue("SELECT count(*) FROM invoice WHERE " .
501 "invoice.trans_id = '" . $row['trans_id'] . "' AND " .
502 "( invoice.description ILIKE 'ICD9:$form_icdcode %' OR " .
503 "invoice.serialnumber ILIKE 'ICD9:$form_icdcode' )"))
505 $skipping = true;
506 continue;
509 // If a facility was specified then skip invoices whose encounters
510 // do not indicate that facility.
511 if ($form_facility) {
512 $tmp = sqlQuery("SELECT count(*) AS count FROM form_encounter WHERE " .
513 "pid = '$patient_id' AND encounter = '$encounter_id' AND " .
514 "facility_id = '$form_facility'");
515 if (empty($tmp['count'])) {
516 $skipping = true;
517 continue;
520 // Find out who the practitioner is.
521 /***********************************************************
522 $tmp = sqlQuery("SELECT users.id, users.authorized FROM forms, users WHERE " .
523 "forms.pid = '$patient_id' AND forms.encounter = '$encounter_id' AND " .
524 "forms.formdir = 'newpatient' AND users.username = forms.user");
525 $main_docid = empty($tmp['id']) ? 0 : $tmp['id'];
526 if (empty($tmp['authorized'])) {
527 $tmp = sqlQuery("SELECT users.id FROM billing, users WHERE " .
528 "billing.pid = '$patient_id' AND billing.encounter = '$encounter_id' AND " .
529 "billing.activity = 1 AND billing.fee > 0 AND " .
530 "users.id = billing.provider_id AND users.authorized = 1 " .
531 "ORDER BY billing.fee DESC, billing.id ASC LIMIT 1");
532 if (!empty($tmp['id'])) $main_docid = $tmp['id'];
534 ***********************************************************/
535 $tmp = sqlQuery("SELECT provider_id FROM form_encounter WHERE " .
536 "pid = '$patient_id' AND encounter = '$encounter_id' " .
537 "ORDER BY id DESC LIMIT 1");
538 $main_docid = $tmp['provider_id'] + 0;
540 // If a practitioner was specified then skip other practitioners.
541 if ($form_doctor) {
542 if ($form_doctor != $main_docid) {
543 $skipping = true;
544 continue;
547 } // end new invoice
549 $row['docid'] = $main_docid;
550 $key = sprintf("%08u%s%08u%08u%06u", $main_docid, $row['transdate'],
551 $patient_id, $encounter_id, $irow);
552 $arows[$key] = $row;
555 } // end not $INTEGRATED_AR
557 ksort($arows);
558 $docid = 0;
560 foreach ($arows as $row) {
562 // Get insurance company name
563 $insconame = '';
564 if ($form_cptcode && $row['project_id']) {
565 $tmp = sqlQuery("SELECT name FROM insurance_companies WHERE " .
566 "id = '" . $row['project_id'] . "'");
567 $insconame = $tmp['name'];
570 $amount1 = 0;
571 $amount2 = 0;
572 if ($form_procedures && is_clinic($row['memo']))
573 $amount2 -= $row['amount'];
574 else
575 $amount1 -= $row['amount'];
577 // if ($docid != $row['employee_id']) {
578 if ($docid != $row['docid']) {
579 if ($docid) {
580 // Print doc totals.
583 <tr bgcolor="#ddddff">
584 <td class="detail" colspan="<?php echo ($form_cptcode ? 4 : 2) + ($form_procedures ? 2 : 0); ?>">
585 <? echo xl('Totals for ') . $docname ?>
586 </td>
587 <td align="right">
588 <?php bucks($doctotal1) ?>
589 </td>
590 <?php if ($form_procedures) { ?>
591 <td align="right">
592 <?php bucks($doctotal2) ?>
593 </td>
594 <?php } ?>
595 </tr>
596 <?php
598 $doctotal1 = 0;
599 $doctotal2 = 0;
601 $docid = $row['docid'];
602 $tmp = sqlQuery("SELECT lname, fname FROM users WHERE id = '$docid'");
603 $docname = empty($tmp) ? 'Unknown' : $tmp['fname'] . ' ' . $tmp['lname'];
605 $docnameleft = $docname;
608 if ($_POST['form_details']) {
611 <tr>
612 <td class="detail">
613 <?php echo $docnameleft; $docnameleft = "&nbsp;" ?>
614 </td>
615 <td class="detail">
616 <?php echo oeFormatShortDate($row['transdate']) ?>
617 </td>
618 <?php if ($form_procedures) { ?>
619 <td class="detail">
620 <?php echo empty($row['irnumber']) ? $row['invnumber'] : $row['irnumber']; ?>
621 </td>
622 <?php } ?>
623 <?php
624 if ($form_cptcode) {
625 echo " <td class='detail' align='right'>";
626 if ($INTEGRATED_AR) {
627 list($patient_id, $encounter_id) = explode(".", $row['invnumber']);
628 $tmp = sqlQuery("SELECT SUM(fee) AS sum FROM billing WHERE " .
629 "pid = '$patient_id' AND encounter = '$encounter_id' AND " .
630 "code = '$form_cptcode' AND activity = 1");
631 bucks($tmp['sum']);
633 else {
634 bucks($row['sellprice'] * $row['qty']);
636 echo " </td>\n";
639 <?php if ($form_cptcode) { ?>
640 <td class="detail">
641 <?php echo $insconame ?>
642 </td>
643 <?php } ?>
644 <?php if ($form_procedures) { ?>
645 <td class="detail">
646 <?php echo $row['memo'] ?>
647 </td>
648 <?php } ?>
649 <td class="detail" align="right">
650 <?php bucks($amount1) ?>
651 </td>
652 <?php if ($form_procedures) { ?>
653 <td class="detail" align="right">
654 <?php bucks($amount2) ?>
655 </td>
656 <?php } ?>
657 </tr>
658 <?php
659 } // end details
660 $doctotal1 += $amount1;
661 $doctotal2 += $amount2;
662 $grandtotal1 += $amount1;
663 $grandtotal2 += $amount2;
667 <tr bgcolor="#ddddff">
668 <td class="detail" colspan="<?php echo ($form_cptcode ? 4 : 2) + ($form_procedures ? 2 : 0); ?>">
669 <?echo xl('Totals for ') . $docname ?>
670 </td>
671 <td align="right">
672 <?php bucks($doctotal1) ?>
673 </td>
674 <?php if ($form_procedures) { ?>
675 <td align="right">
676 <?php bucks($doctotal2) ?>
677 </td>
678 <?php } ?>
679 </tr>
681 <tr bgcolor="#ffdddd">
682 <td class="detail" colspan="<?php echo ($form_cptcode ? 4 : 2) + ($form_procedures ? 2 : 0); ?>">
683 <?php xl('Grand Totals','e') ?>
684 </td>
685 <td align="right">
686 <?php bucks($grandtotal1) ?>
687 </td>
688 <?php if ($form_procedures) { ?>
689 <td align="right">
690 <?php bucks($grandtotal2) ?>
691 </td>
692 <?php } ?>
693 </tr>
695 <?php
697 if (!$INTEGRATED_AR) SLClose();
700 </table>
701 </div>
702 <?php } else { ?>
703 <div class='text'>
704 <?php echo xl('Please input search criteria above, and click Submit to view results.', 'e' ); ?>
705 </div>
706 <?php } ?>
708 </form>
709 </body>
711 <!-- stuff for the popup calendar -->
712 <link rel='stylesheet' href='<?php echo $css_header ?>' type='text/css'>
713 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
714 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
715 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
716 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
717 <script type="text/javascript" src="../../library/js/jquery.1.3.2.js"></script>
719 <script language="Javascript">
720 Calendar.setup({inputField:"form_from_date", ifFormat:"%Y-%m-%d", button:"img_from_date"});
721 Calendar.setup({inputField:"form_to_date", ifFormat:"%Y-%m-%d", button:"img_to_date"});
722 </script>
724 </html>