minor cosmetic fixes
[openemr.git] / interface / billing / sl_receipts_report.php
blob37a4ea5adf447eca625e004ac28ace96c5892663
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");
20 // This determines if a particular procedure code corresponds to receipts
21 // for the "Clinic" column as opposed to receipts for the practitioner. Each
22 // practice will have its own policies in this regard, so you'll probably
23 // have to customize this function. If you use the "fee sheet" encounter
24 // form then the code below may work for you.
26 include_once("../forms/fee_sheet/codes.php");
27 function is_clinic($code) {
28 global $bcodes;
29 $i = strpos($code, ':');
30 if ($i) $code = substr($code, 0, $i);
31 return ($bcodes['CPT4'][xl('Lab')][$code] ||
32 $bcodes['CPT4'][xl('Immunizations')][$code] ||
33 $bcodes['HCPCS'][xl('Therapeutic Injections')][$code]);
36 function bucks($amount) {
37 if ($amount) echo oeFormatMoney($amount);
40 if (! acl_check('acct', 'rep')) die(xl("Unauthorized access."));
42 $INTEGRATED_AR = $GLOBALS['oer_config']['ws_accounting']['enabled'] === 2;
44 if (!$INTEGRATED_AR) {
45 SLConnect();
46 $chart_id_cash = SLQueryValue("select id from chart where accno = '$sl_cash_acc'");
47 if ($sl_err) die($sl_err);
50 $form_use_edate = $_POST['form_use_edate'];
51 $form_cptcode = trim($_POST['form_cptcode']);
52 $form_icdcode = trim($_POST['form_icdcode']);
53 $form_procedures = empty($_POST['form_procedures']) ? 0 : 1;
54 $form_from_date = fixDate($_POST['form_from_date'], date('Y-m-01'));
55 $form_to_date = fixDate($_POST['form_to_date'], date('Y-m-d'));
56 $form_facility = $_POST['form_facility'];
58 <html>
59 <head>
60 <?php if (function_exists('html_header_show')) html_header_show(); ?>
61 <style type="text/css">
62 /* specifically include & exclude from printing */
63 @media print {
64 #report_parameters {
65 visibility: hidden;
66 display: none;
68 #report_parameters_daterange {
69 visibility: visible;
70 display: inline;
72 #report_results {
73 margin-top: 30px;
77 /* specifically exclude some from the screen */
78 @media screen { N
79 #report_parameters_daterange {
80 visibility: hidden;
81 display: none;
84 </style>
85 <title><?xl('Cash Receipts by Provider','e')?></title>
86 </head>
88 <body class="body_top">
90 <span class='title'><?php xl('Report','e'); ?> - <?php xl('Cash Receipts by Provider','e'); ?></span>
92 <form method='post' action='sl_receipts_report.php' id='theform'>
94 <div id="report_parameters">
96 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
98 <table>
99 <tr>
100 <td width='660px'>
101 <div style='float:left'>
103 <table class='text'>
104 <tr>
105 <td class='label'>
106 <?php xl('Facility','e'); ?>:
107 </td>
108 <td>
109 <?php
110 // Build a drop-down list of facilities.
112 $query = "SELECT id, name FROM facility ORDER BY name";
113 $fres = sqlStatement($query);
114 echo " <select name='form_facility'>\n";
115 echo " <option value=''>-- " . xl('All Facilities') . " --\n";
116 while ($frow = sqlFetchArray($fres)) {
117 $facid = $frow['id'];
118 echo " <option value='$facid'";
119 if ($facid == $form_facility) echo " selected";
120 echo ">" . $frow['name'] . "\n";
122 echo " <option value='0'";
123 if ($form_facility === '0') echo " selected";
124 echo ">-- " . xl('Unspecified', 'e') . " --\n";
125 echo " </select>\n";
127 </td>
128 <td class='label'>
129 <?php xl('Provider','e'); ?>:
130 </td>
131 <td>
132 <?php
133 if (acl_check('acct', 'rep_a')) {
134 // Build a drop-down list of providers.
136 $query = "select id, lname, fname from users where " .
137 "authorized = 1 order by lname, fname";
138 $res = sqlStatement($query);
139 echo " &nbsp;<select name='form_doctor'>\n";
140 echo " <option value=''>-- " . xl('All Providers', 'e') . " --\n";
141 while ($row = sqlFetchArray($res)) {
142 $provid = $row['id'];
143 echo " <option value='$provid'";
144 if ($provid == $_POST['form_doctor']) echo " selected";
145 echo ">" . $row['lname'] . ", " . $row['fname'] . "\n";
147 echo " </select>\n";
148 } else {
149 echo "<input type='hidden' name='form_doctor' value='" . $_SESSION['authUserID'] . "'>";
152 </td>
153 <td>
154 <select name='form_use_edate'>
155 <option value='0'><?php xl('Payment Date','e'); ?></option>
156 <option value='1'<?php if ($form_use_edate) echo ' selected' ?>><?php xl('Invoice Date','e'); ?></option>
157 </select>
158 </td>
159 </tr>
160 <tr>
161 <td class='label'>
162 <?php xl('From','e'); ?>:
163 </td>
164 <td>
165 <input type='text' name='form_from_date' id="form_from_date" size='10' value='<?php echo $form_from_date; ?>'
166 title='Date of appointments mm/dd/yyyy' >
167 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
168 id='img_from_date' border='0' alt='[?]' style='cursor:pointer'
169 title='<?php xl('Click here to choose a date','e'); ?>'>
170 </td>
171 <td class='label'>
172 <?php xl('To','e'); ?>:
173 </td>
174 <td>
175 <input type='text' name='form_to_date' id="form_to_date" size='10' value='<?php echo $form_to_date; ?>'
176 title='Optional end date mm/dd/yyyy' >
177 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
178 id='img_to_date' border='0' alt='[?]' style='cursor:pointer'
179 title='<?php xl('Click here to choose a date','e'); ?>'>
180 </td>
181 <td>&nbsp;</td>
182 </tr>
183 <tr>
184 <td>
185 <?php if (!$GLOBALS['simplified_demographics']) echo '&nbsp;' . xl('CPT', 'e') . ':'; ?>
186 </td>
187 <td>
188 <input type='text' name='form_cptcode' size='5' value='<? echo $form_cptcode; ?>'
189 title='<?php xl('Optional procedure code','e'); ?>'
190 <?php if ($GLOBALS['simplified_demographics']) echo "style='display:none'"; ?>>
191 </td>
193 <td>
194 <?php if (!$GLOBALS['simplified_demographics']) echo '&nbsp;' . xl('ICD', 'e') . ':'; ?>
195 </td>
196 <td>
197 <input type='text' name='form_icdcode' size='5' value='<? echo $form_icdcode; ?>'
198 title='<?php xl('Enter a diagnosis code to exclude all invoices not containing it','e'); ?>'
199 <?php if ($GLOBALS['simplified_demographics']) echo "style='display:none'"; ?>>
200 </td>
202 <td>
203 <input type='checkbox' name='form_details' value='1'<? if ($_POST['form_details']) echo " checked"; ?>><?xl('Details','e')?>
204 <input type='checkbox' name='form_procedures' value='1'<? if ($form_procedures) echo " checked"; ?>><?xl('Procedures','e')?>
205 </td>
206 </tr>
207 </table>
209 </div>
211 </td>
212 <td align='left' valign='middle' height="100%">
213 <table style='border-left:1px solid; width:100%; height:100%' >
214 <tr>
215 <td>
216 <div style='margin-left:15px'>
217 <a href='#' class='css_button' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
218 <span>
219 <?php xl('Submit','e'); ?>
220 </span>
221 </a>
223 <?php if ($_POST['form_refresh']) { ?>
224 <a href='#' class='css_button' onclick='window.print()'>
225 <span>
226 <?php xl('Print','e'); ?>
227 </span>
228 </a>
229 <?php } ?>
230 </div>
231 </td>
232 </tr>
233 </table>
234 </td>
235 </tr>
236 </table>
237 </div>
239 <?php
240 if ($_POST['form_refresh']) {
242 <div id="report_results">
243 <table border='0' cellpadding='1' cellspacing='2' width='98%'>
244 <thead>
245 <th>
246 <?php xl('Practitioner','e') ?>
247 </th>
248 <th>
249 <?php xl('Date','e') ?>
250 </th>
251 <?php if ($form_procedures) { ?>
252 <th>
253 <?php xl('Invoice','e') ?>
254 </th>
255 <?php } ?>
256 <?php if ($form_cptcode) { ?>
257 <th align='right'>
258 <?php xl('InvAmt','e') ?>
259 </th>
260 <?php } ?>
261 <?php if ($form_cptcode) { ?>
262 <th>
263 <?php xl('Insurance','e') ?>
264 </th>
265 <?php } ?>
266 <?php if ($form_procedures) { ?>
267 <th>
268 <?php xl('Procedure','e') ?>
269 </th>
270 <th align="right">
271 <?php xl('Prof.','e') ?>
272 </th>
273 <th align="right">
274 <?php xl('Clinic','e') ?>
275 </th>
276 <?php } else { ?>
277 <th align="right">
278 <?php xl('Received','e') ?>
279 </th>
280 <?php } ?>
281 </thead>
282 <?php
283 if ($_POST['form_refresh']) {
284 $form_doctor = $_POST['form_doctor'];
285 $arows = array();
287 if ($INTEGRATED_AR) {
288 $ids_to_skip = array();
289 $irow = 0;
291 // Get copays. These will be ignored if a CPT code was specified.
293 if (!$form_cptcode) {
294 /*************************************************************
295 $query = "SELECT b.fee, b.pid, b.encounter, b.code_type, b.code, b.modifier, " .
296 "fe.date, fe.id AS trans_id, u.id AS docid " .
297 "FROM billing AS b " .
298 "JOIN form_encounter AS fe ON fe.pid = b.pid AND fe.encounter = b.encounter " .
299 "JOIN forms AS f ON f.pid = b.pid AND f.encounter = b.encounter AND f.formdir = 'newpatient' " .
300 "LEFT OUTER JOIN users AS u ON u.username = f.user " .
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 u.id = '$form_doctor'";
311 *************************************************************/
312 $query = "SELECT b.fee, b.pid, b.encounter, b.code_type, b.code, b.modifier, " .
313 "fe.date, fe.id AS trans_id, fe.provider_id AS docid " .
314 "FROM billing AS b " .
315 "JOIN form_encounter AS fe ON fe.pid = b.pid AND fe.encounter = b.encounter " .
316 "WHERE b.code_type = 'COPAY' AND b.activity = 1 AND " .
317 "fe.date >= '$form_from_date 00:00:00' AND fe.date <= '$form_to_date 23:59:59'";
318 // If a facility was specified.
319 if ($form_facility) {
320 $query .= " AND fe.facility_id = '$form_facility'";
322 // If a doctor was specified.
323 if ($form_doctor) {
324 $query .= " AND fe.provider_id = '$form_doctor'";
326 /************************************************************/
328 $res = sqlStatement($query);
329 while ($row = sqlFetchArray($res)) {
330 $trans_id = $row['trans_id'];
331 $thedate = substr($row['date'], 0, 10);
332 $patient_id = $row['pid'];
333 $encounter_id = $row['encounter'];
335 if (!empty($ids_to_skip[$trans_id])) continue;
337 // If a diagnosis code was given then skip any invoices without
338 // that diagnosis.
339 if ($form_icdcode) {
340 $tmp = sqlQuery("SELECT count(*) AS count FROM billing WHERE " .
341 "pid = '$patient_id' AND encounter = '$encounter_id' AND " .
342 "code_type = 'ICD9' AND code LIKE '$form_icdcode' AND " .
343 "activity = 1");
344 if (empty($tmp['count'])) {
345 $ids_to_skip[$trans_id] = 1;
346 continue;
350 $key = sprintf("%08u%s%08u%08u%06u", $row['docid'], $thedate,
351 $patient_id, $encounter_id, ++$irow);
352 $arows[$key] = array();
353 $arows[$key]['transdate'] = $thedate;
354 $arows[$key]['amount'] = $row['fee'];
355 $arows[$key]['docid'] = $row['docid'];
356 $arows[$key]['project_id'] = 0;
357 $arows[$key]['memo'] = '';
358 $arows[$key]['invnumber'] = "$patient_id.$encounter_id";
359 } // end while
360 } // end copays (not $form_cptcode)
362 // Get ar_activity (having payments), form_encounter, forms, users, optional ar_session
363 /***************************************************************
364 $query = "SELECT a.pid, a.encounter, a.post_time, a.code, a.modifier, a.pay_amount, " .
365 "fe.date, fe.id AS trans_id, u.id AS docid, s.deposit_date, s.payer_id " .
366 "FROM ar_activity AS a " .
367 "JOIN form_encounter AS fe ON fe.pid = a.pid AND fe.encounter = a.encounter " .
368 "JOIN forms AS f ON f.pid = a.pid AND f.encounter = a.encounter AND f.formdir = 'newpatient' " .
369 "LEFT OUTER JOIN users AS u ON u.username = f.user " .
370 "LEFT OUTER JOIN ar_session AS s ON s.session_id = a.session_id " .
371 "WHERE a.pay_amount != 0 AND ( " .
372 "a.post_time >= '$form_from_date 00:00:00' AND a.post_time <= '$form_to_date 23:59:59' " .
373 "OR fe.date >= '$form_from_date 00:00:00' AND fe.date <= '$form_to_date 23:59:59' " .
374 "OR s.deposit_date >= '$form_from_date' AND s.deposit_date <= '$form_to_date' )";
375 // If a procedure code was specified.
376 if ($form_cptcode) $query .= " AND a.code = '$form_cptcode'";
377 // If a facility was specified.
378 if ($form_facility) $query .= " AND fe.facility_id = '$form_facility'";
379 // If a doctor was specified.
380 if ($form_doctor) $query .= " AND u.id = '$form_doctor'";
381 ***************************************************************/
382 $query = "SELECT a.pid, a.encounter, a.post_time, a.code, a.modifier, a.pay_amount, " .
383 "fe.date, fe.id AS trans_id, fe.provider_id AS docid, s.deposit_date, s.payer_id, " .
384 "b.provider_id " .
385 "FROM ar_activity AS a " .
386 "JOIN form_encounter AS fe ON fe.pid = a.pid AND fe.encounter = a.encounter " .
387 "LEFT OUTER JOIN ar_session AS s ON s.session_id = a.session_id " .
388 "LEFT OUTER JOIN billing AS b ON b.pid = a.pid AND b.encounter = a.encounter AND " .
389 "b.code = a.code AND b.modifier = a.modifier AND b.activity = 1 AND " .
390 "b.code_type != 'COPAY' AND b.code_type != 'TAX' " .
391 "WHERE a.pay_amount != 0 AND ( " .
392 "a.post_time >= '$form_from_date 00:00:00' AND a.post_time <= '$form_to_date 23:59:59' " .
393 "OR fe.date >= '$form_from_date 00:00:00' AND fe.date <= '$form_to_date 23:59:59' " .
394 "OR s.deposit_date >= '$form_from_date' AND s.deposit_date <= '$form_to_date' )";
395 // If a procedure code was specified.
396 if ($form_cptcode) $query .= " AND a.code = '$form_cptcode'";
397 // If a facility was specified.
398 if ($form_facility) $query .= " AND fe.facility_id = '$form_facility'";
399 // If a doctor was specified.
400 if ($form_doctor) {
401 $query .= " AND ( b.provider_id = '$form_doctor' OR " .
402 "( ( b.provider_id IS NULL OR b.provider_id = 0 ) AND " .
403 "fe.provider_id = '$form_doctor' ) )";
405 /**************************************************************/
407 $res = sqlStatement($query);
408 while ($row = sqlFetchArray($res)) {
409 $trans_id = $row['trans_id'];
410 $patient_id = $row['pid'];
411 $encounter_id = $row['encounter'];
413 if (!empty($ids_to_skip[$trans_id])) continue;
415 if ($form_use_edate) {
416 $thedate = substr($row['date'], 0, 10);
417 } else {
418 if (!empty($row['deposit_date']))
419 $thedate = $row['deposit_date'];
420 else
421 $thedate = substr($row['post_time'], 0, 10);
423 if (strcmp($thedate, $form_from_date) < 0 || strcmp($thedate, $form_to_date) > 0) continue;
425 // If a diagnosis code was given then skip any invoices without
426 // that diagnosis.
427 if ($form_icdcode) {
428 $tmp = sqlQuery("SELECT count(*) AS count FROM billing WHERE " .
429 "pid = '$patient_id' AND encounter = '$encounter_id' AND " .
430 "code_type = 'ICD9' AND code LIKE '$form_icdcode' AND " .
431 "activity = 1");
432 if (empty($tmp['count'])) {
433 $ids_to_skip[$trans_id] = 1;
434 continue;
438 $docid = empty($row['encounter_id']) ? $row['docid'] : $row['encounter_id'];
439 $key = sprintf("%08u%s%08u%08u%06u", $docid, $thedate,
440 $patient_id, $encounter_id, ++$irow);
441 $arows[$key] = array();
442 $arows[$key]['transdate'] = $thedate;
443 $arows[$key]['amount'] = 0 - $row['pay_amount'];
444 $arows[$key]['docid'] = $docid;
445 $arows[$key]['project_id'] = empty($row['payer_id']) ? 0 : $row['payer_id'];
446 $arows[$key]['memo'] = $row['code'];
447 $arows[$key]['invnumber'] = "$patient_id.$encounter_id";
448 } // end while
449 } // end $INTEGRATED_AR
451 else {
452 if ($form_cptcode) {
453 $query = "SELECT acc_trans.amount, acc_trans.transdate, " .
454 "acc_trans.memo, acc_trans.project_id, acc_trans.trans_id, " .
455 "ar.invnumber, ar.employee_id, invoice.sellprice, invoice.qty " .
456 "FROM acc_trans, ar, invoice WHERE " .
457 "acc_trans.chart_id = $chart_id_cash AND " .
458 "acc_trans.memo ILIKE '$form_cptcode' AND " .
459 "ar.id = acc_trans.trans_id AND " .
460 "invoice.trans_id = acc_trans.trans_id AND " .
461 "invoice.serialnumber ILIKE acc_trans.memo AND " .
462 "invoice.sellprice >= 0.00 AND " .
463 "( invoice.description ILIKE 'CPT%' OR invoice.description ILIKE 'Proc%' ) AND ";
465 else {
466 $query = "select acc_trans.amount, acc_trans.transdate, " .
467 "acc_trans.memo, acc_trans.trans_id, " .
468 "ar.invnumber, ar.employee_id from acc_trans, ar where " .
469 "acc_trans.chart_id = $chart_id_cash and " .
470 "ar.id = acc_trans.trans_id and ";
473 if ($form_use_edate) {
474 $query .= "ar.transdate >= '$form_from_date' and " .
475 "ar.transdate <= '$form_to_date'";
476 } else {
477 $query .= "acc_trans.transdate >= '$form_from_date' and " .
478 "acc_trans.transdate <= '$form_to_date'";
481 $query .= " order by ar.invnumber";
483 // echo "<!-- $query -->\n"; // debugging
485 $t_res = SLQuery($query);
486 if ($sl_err) die($sl_err);
488 $docname = "";
489 $docnameleft = "";
490 $main_docid = 0;
491 $doctotal1 = 0;
492 $grandtotal1 = 0;
493 $doctotal2 = 0;
494 $grandtotal2 = 0;
495 $last_trans_id = 0;
496 $skipping = false;
498 for ($irow = 0; $irow < SLRowCount($t_res); ++$irow) {
499 $row = SLGetRow($t_res, $irow);
501 list($patient_id, $encounter_id) = explode(".", $row['invnumber']);
503 // Under some conditions we may skip invoices that matched the SQL query.
505 if ($row['trans_id'] == $last_trans_id) {
506 if ($skipping) continue;
507 // same invoice and not skipping, do nothing.
508 } else { // new invoice
509 $skipping = false;
510 // If a diagnosis code was given then skip any invoices without
511 // that diagnosis.
512 if ($form_icdcode) {
513 if (!SLQueryValue("SELECT count(*) FROM invoice WHERE " .
514 "invoice.trans_id = '" . $row['trans_id'] . "' AND " .
515 "( invoice.description ILIKE 'ICD9:$form_icdcode %' OR " .
516 "invoice.serialnumber ILIKE 'ICD9:$form_icdcode' )"))
518 $skipping = true;
519 continue;
522 // If a facility was specified then skip invoices whose encounters
523 // do not indicate that facility.
524 if ($form_facility) {
525 $tmp = sqlQuery("SELECT count(*) AS count FROM form_encounter WHERE " .
526 "pid = '$patient_id' AND encounter = '$encounter_id' AND " .
527 "facility_id = '$form_facility'");
528 if (empty($tmp['count'])) {
529 $skipping = true;
530 continue;
533 // Find out who the practitioner is.
534 /***********************************************************
535 $tmp = sqlQuery("SELECT users.id, users.authorized FROM forms, users WHERE " .
536 "forms.pid = '$patient_id' AND forms.encounter = '$encounter_id' AND " .
537 "forms.formdir = 'newpatient' AND users.username = forms.user");
538 $main_docid = empty($tmp['id']) ? 0 : $tmp['id'];
539 if (empty($tmp['authorized'])) {
540 $tmp = sqlQuery("SELECT users.id FROM billing, users WHERE " .
541 "billing.pid = '$patient_id' AND billing.encounter = '$encounter_id' AND " .
542 "billing.activity = 1 AND billing.fee > 0 AND " .
543 "users.id = billing.provider_id AND users.authorized = 1 " .
544 "ORDER BY billing.fee DESC, billing.id ASC LIMIT 1");
545 if (!empty($tmp['id'])) $main_docid = $tmp['id'];
547 ***********************************************************/
548 $tmp = sqlQuery("SELECT provider_id FROM form_encounter WHERE " .
549 "pid = '$patient_id' AND encounter = '$encounter_id' " .
550 "ORDER BY id DESC LIMIT 1");
551 $main_docid = $tmp['provider_id'] + 0;
553 // If a practitioner was specified then skip other practitioners.
554 if ($form_doctor) {
555 if ($form_doctor != $main_docid) {
556 $skipping = true;
557 continue;
560 } // end new invoice
562 $row['docid'] = $main_docid;
563 $key = sprintf("%08u%s%08u%08u%06u", $main_docid, $row['transdate'],
564 $patient_id, $encounter_id, $irow);
565 $arows[$key] = $row;
568 } // end not $INTEGRATED_AR
570 ksort($arows);
571 $docid = 0;
573 foreach ($arows as $row) {
575 // Get insurance company name
576 $insconame = '';
577 if ($form_cptcode && $row['project_id']) {
578 $tmp = sqlQuery("SELECT name FROM insurance_companies WHERE " .
579 "id = '" . $row['project_id'] . "'");
580 $insconame = $tmp['name'];
583 $amount1 = 0;
584 $amount2 = 0;
585 if ($form_procedures && is_clinic($row['memo']))
586 $amount2 -= $row['amount'];
587 else
588 $amount1 -= $row['amount'];
590 // if ($docid != $row['employee_id']) {
591 if ($docid != $row['docid']) {
592 if ($docid) {
593 // Print doc totals.
596 <tr bgcolor="#ddddff">
597 <td class="detail" colspan="<?php echo ($form_cptcode ? 4 : 2) + ($form_procedures ? 2 : 0); ?>">
598 <? echo xl('Totals for ') . $docname ?>
599 </td>
600 <td align="right">
601 <?php bucks($doctotal1) ?>
602 </td>
603 <?php if ($form_procedures) { ?>
604 <td align="right">
605 <?php bucks($doctotal2) ?>
606 </td>
607 <?php } ?>
608 </tr>
609 <?php
611 $doctotal1 = 0;
612 $doctotal2 = 0;
614 $docid = $row['docid'];
615 $tmp = sqlQuery("SELECT lname, fname FROM users WHERE id = '$docid'");
616 $docname = empty($tmp) ? 'Unknown' : $tmp['fname'] . ' ' . $tmp['lname'];
618 $docnameleft = $docname;
621 if ($_POST['form_details']) {
624 <tr>
625 <td class="detail">
626 <?php echo $docnameleft; $docnameleft = "&nbsp;" ?>
627 </td>
628 <td class="detail">
629 <?php echo oeFormatShortDate($row['transdate']) ?>
630 </td>
631 <?php if ($form_procedures) { ?>
632 <td class="detail">
633 <?php echo $row['invnumber'] ?>
634 </td>
635 <?php } ?>
636 <?php
637 if ($form_cptcode) {
638 echo " <td class='detail' align='right'>";
639 if ($INTEGRATED_AR) {
640 list($patient_id, $encounter_id) = explode(".", $row['invnumber']);
641 $tmp = sqlQuery("SELECT SUM(fee) AS sum FROM billing WHERE " .
642 "pid = '$patient_id' AND encounter = '$encounter_id' AND " .
643 "code = '$form_cptcode' AND activity = 1");
644 bucks($tmp['sum']);
646 else {
647 bucks($row['sellprice'] * $row['qty']);
649 echo " </td>\n";
652 <?php if ($form_cptcode) { ?>
653 <td class="detail">
654 <?php echo $insconame ?>
655 </td>
656 <?php } ?>
657 <?php if ($form_procedures) { ?>
658 <td class="detail">
659 <?php echo $row['memo'] ?>
660 </td>
661 <?php } ?>
662 <td class="detail" align="right">
663 <?php bucks($amount1) ?>
664 </td>
665 <?php if ($form_procedures) { ?>
666 <td class="detail" align="right">
667 <?php bucks($amount2) ?>
668 </td>
669 <?php } ?>
670 </tr>
671 <?php
672 } // end details
673 $doctotal1 += $amount1;
674 $doctotal2 += $amount2;
675 $grandtotal1 += $amount1;
676 $grandtotal2 += $amount2;
680 <tr bgcolor="#ddddff">
681 <td class="detail" colspan="<?php echo ($form_cptcode ? 4 : 2) + ($form_procedures ? 2 : 0); ?>">
682 <?echo xl('Totals for ') . $docname ?>
683 </td>
684 <td align="right">
685 <?php bucks($doctotal1) ?>
686 </td>
687 <?php if ($form_procedures) { ?>
688 <td align="right">
689 <?php bucks($doctotal2) ?>
690 </td>
691 <?php } ?>
692 </tr>
694 <tr bgcolor="#ffdddd">
695 <td class="detail" colspan="<?php echo ($form_cptcode ? 4 : 2) + ($form_procedures ? 2 : 0); ?>">
696 <?php xl('Grand Totals','e') ?>
697 </td>
698 <td align="right">
699 <?php bucks($grandtotal1) ?>
700 </td>
701 <?php if ($form_procedures) { ?>
702 <td align="right">
703 <?php bucks($grandtotal2) ?>
704 </td>
705 <?php } ?>
706 </tr>
708 <?php
710 if (!$INTEGRATED_AR) SLClose();
713 </table>
714 </div>
715 <?php } else { ?>
716 <div class='text'>
717 <?php echo xl('Please input search criteria above, and click Submit to view results.', 'e' ); ?>
718 </div>
719 <?php } ?>
721 </form>
722 </body>
724 <!-- stuff for the popup calendar -->
725 <link rel='stylesheet' href='<?php echo $css_header ?>' type='text/css'>
726 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
727 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
728 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
729 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
730 <script type="text/javascript" src="../../library/js/jquery.1.3.2.js"></script>
732 <script language="Javascript">
733 Calendar.setup({inputField:"form_from_date", ifFormat:"%Y-%m-%d", button:"img_from_date"});
734 Calendar.setup({inputField:"form_to_date", ifFormat:"%Y-%m-%d", button:"img_to_date"});
735 </script>
737 </html>