Collection report bug fix and an internationalization issue fix
[openemr.git] / interface / reports / collections_report.php
blob2a157bc43462a87d8d82d6b15d530aadfcc37842
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 require_once("../globals.php");
10 require_once("../../library/patient.inc");
11 require_once("../../library/sql-ledger.inc");
12 require_once("../../library/invoice_summary.inc.php");
13 require_once("../../library/sl_eob.inc.php");
14 require_once("../../library/formatting.inc.php");
15 require_once "$srcdir/options.inc.php";
16 require_once "$srcdir/formdata.inc.php";
18 $INTEGRATED_AR = $GLOBALS['oer_config']['ws_accounting']['enabled'] === 2;
20 $alertmsg = '';
21 $bgcolor = "#aaaaaa";
22 $export_patient_count = 0;
23 $export_dollars = 0;
25 $today = date("Y-m-d");
27 $form_date = fixDate($_POST['form_date'], "");
28 $form_to_date = fixDate($_POST['form_to_date'], "");
29 $is_ins_summary = $_POST['form_category'] == 'Ins Summary';
30 $is_due_ins = ($_POST['form_category'] == 'Due Ins') || $is_ins_summary;
31 $is_due_pt = $_POST['form_category'] == 'Due Pt';
32 $is_all = $_POST['form_category'] == 'All';
33 $is_ageby_lad = strpos($_POST['form_ageby'], 'Last') !== false;
34 $form_facility = $_POST['form_facility'];
36 if ($_POST['form_refresh'] || $_POST['form_export'] || $_POST['form_csvexport']) {
37 if ($is_ins_summary) {
38 $form_cb_ssn = false;
39 $form_cb_dob = false;
40 $form_cb_pubpid = false;
41 $form_cb_adate = false;
42 $form_cb_policy = false;
43 $form_cb_phone = false;
44 $form_cb_city = false;
45 $form_cb_ins1 = false;
46 $form_cb_referrer = false;
47 $form_cb_idays = false;
48 $form_cb_err = false;
49 } else {
50 $form_cb_ssn = $_POST['form_cb_ssn'] ? true : false;
51 $form_cb_dob = $_POST['form_cb_dob'] ? true : false;
52 $form_cb_pubpid = $_POST['form_cb_pubpid'] ? true : false;
53 $form_cb_adate = $_POST['form_cb_adate'] ? true : false;
54 $form_cb_policy = $_POST['form_cb_policy'] ? true : false;
55 $form_cb_phone = $_POST['form_cb_phone'] ? true : false;
56 $form_cb_city = $_POST['form_cb_city'] ? true : false;
57 $form_cb_ins1 = $_POST['form_cb_ins1'] ? true : false;
58 $form_cb_referrer = $_POST['form_cb_referrer'] ? true : false;
59 $form_cb_idays = $_POST['form_cb_idays'] ? true : false;
60 $form_cb_err = $_POST['form_cb_err'] ? true : false;
62 } else {
63 $form_cb_ssn = true;
64 $form_cb_dob = false;
65 $form_cb_pubpid = false;
66 $form_cb_adate = false;
67 $form_cb_policy = false;
68 $form_cb_phone = true;
69 $form_cb_city = false;
70 $form_cb_ins1 = false;
71 $form_cb_referrer = false;
72 $form_cb_idays = false;
73 $form_cb_err = false;
75 $form_age_cols = (int) $_POST['form_age_cols'];
76 $form_age_inc = (int) $_POST['form_age_inc'];
77 if ($form_age_cols > 0 && $form_age_cols < 50) {
78 if ($form_age_inc <= 0) $form_age_inc = 30;
79 } else {
80 $form_age_cols = 0;
81 $form_age_inc = 0;
84 $initial_colspan = 1;
85 if ($is_due_ins ) ++$initial_colspan;
86 if ($form_cb_ssn ) ++$initial_colspan;
87 if ($form_cb_dob ) ++$initial_colspan;
88 if ($form_cb_pubpid ) ++$initial_colspan;
89 if ($form_cb_policy ) ++$initial_colspan;
90 if ($form_cb_phone ) ++$initial_colspan;
91 if ($form_cb_city ) ++$initial_colspan;
92 if ($form_cb_ins1 ) ++$initial_colspan;
93 if ($form_cb_referrer) ++$initial_colspan;
95 $final_colspan = $form_cb_adate ? 6 : 5;
97 $grand_total_charges = 0;
98 $grand_total_adjustments = 0;
99 $grand_total_paid = 0;
100 $grand_total_agedbal = array();
101 for ($c = 0; $c < $form_age_cols; ++$c) $grand_total_agedbal[$c] = 0;
103 if (!$INTEGRATED_AR) SLConnect();
105 function bucks($amount) {
106 if ($amount)
107 echo oeFormatMoney($amount); // was printf("%.2f", $amount);
110 function endPatient($ptrow) {
111 global $export_patient_count, $export_dollars, $bgcolor;
112 global $grand_total_charges, $grand_total_adjustments, $grand_total_paid;
113 global $grand_total_agedbal, $is_due_ins, $form_age_cols;
114 global $initial_colspan, $final_colspan, $form_cb_idays, $form_cb_err;
116 if (!$ptrow['pid']) return;
118 $pt_balance = $ptrow['amount'] - $ptrow['paid'];
120 if ($_POST['form_export']) {
121 // This is a fixed-length format used by Transworld Systems. Your
122 // needs will surely be different, so consider this just an example.
124 echo "1896H"; // client number goes here
125 echo "000"; // filler
126 echo sprintf("%-30s", substr($ptrow['ptname'], 0, 30));
127 echo sprintf("%-30s", " ");
128 echo sprintf("%-30s", substr($ptrow['address1'], 0, 30));
129 echo sprintf("%-15s", substr($ptrow['city'], 0, 15));
130 echo sprintf("%-2s", substr($ptrow['state'], 0, 2));
131 echo sprintf("%-5s", $ptrow['zipcode'] ? substr($ptrow['zipcode'], 0, 5) : '00000');
132 echo "1"; // service code
133 echo sprintf("%010.0f", $ptrow['pid']); // transmittal number = patient id
134 echo " "; // filler
135 echo sprintf("%-15s", substr($ptrow['ss'], 0, 15));
136 echo substr($ptrow['dos'], 5, 2) . substr($ptrow['dos'], 8, 2) . substr($ptrow['dos'], 2, 2);
137 echo sprintf("%08.0f", $pt_balance * 100);
138 echo sprintf("%-9s\n", " ");
140 if (!$_POST['form_without']) {
141 sqlStatement("UPDATE patient_data SET " .
142 "genericname2 = 'Billing', " .
143 "genericval2 = CONCAT('IN COLLECTIONS " . date("Y-m-d") . "', genericval2) " .
144 "WHERE pid = '" . $ptrow['pid'] . "'");
146 $export_patient_count += 1;
147 $export_dollars += $pt_balance;
149 else if ($_POST['form_csvexport']) {
150 $export_patient_count += 1;
151 $export_dollars += $pt_balance;
153 else {
154 if ($ptrow['count'] > 1) {
155 echo " <tr bgcolor='$bgcolor'>\n";
156 /***************************************************************
157 echo " <td class='detail' colspan='$initial_colspan'>";
158 echo "&nbsp;</td>\n";
159 echo " <td class='detotal' colspan='$final_colspan'>&nbsp;Total Patient Balance:</td>\n";
160 ***************************************************************/
161 echo " <td class='detotal' colspan='" . ($initial_colspan + $final_colspan) .
162 "'>&nbsp;" . xl('Total Patient Balance') . ":</td>\n";
163 /**************************************************************/
164 if ($form_age_cols) {
165 for ($c = 0; $c < $form_age_cols; ++$c) {
166 echo " <td class='detotal' align='right'>&nbsp;" .
167 oeFormatMoney($ptrow['agedbal'][$c]) . "&nbsp;</td>\n";
170 else {
171 echo " <td class='detotal' align='right'>&nbsp;" .
172 oeFormatMoney($pt_balance) . "&nbsp;</td>\n";
174 if ($form_cb_idays) echo " <td class='detail'>&nbsp;</td>\n";
175 echo " <td class='detail' colspan='2'>&nbsp;</td>\n";
176 if ($form_cb_err) echo " <td class='detail'>&nbsp;</td>\n";
177 echo " </tr>\n";
180 $grand_total_charges += $ptrow['charges'];
181 $grand_total_adjustments += $ptrow['adjustments'];
182 $grand_total_paid += $ptrow['paid'];
183 for ($c = 0; $c < $form_age_cols; ++$c) {
184 $grand_total_agedbal[$c] += $ptrow['agedbal'][$c];
188 function endInsurance($insrow) {
189 global $export_patient_count, $export_dollars, $bgcolor;
190 global $grand_total_charges, $grand_total_adjustments, $grand_total_paid;
191 global $grand_total_agedbal, $is_due_ins, $form_age_cols;
192 global $initial_colspan, $form_cb_idays, $form_cb_err;
193 if (!$insrow['pid']) return;
194 $ins_balance = $insrow['amount'] - $insrow['paid'];
195 if ($_POST['form_export'] || $_POST['form_csvexport']) {
196 // No exporting of insurance summaries.
197 $export_patient_count += 1;
198 $export_dollars += $ins_balance;
200 else {
201 echo " <tr bgcolor='$bgcolor'>\n";
202 echo " <td class='detail'>" . $insrow['insname'] . "</td>\n";
203 echo " <td class='detotal' align='right'>&nbsp;" .
204 oeFormatMoney($insrow['charges']) . "&nbsp;</td>\n";
205 echo " <td class='detotal' align='right'>&nbsp;" .
206 oeFormatMoney($insrow['adjustments']) . "&nbsp;</td>\n";
207 echo " <td class='detotal' align='right'>&nbsp;" .
208 oeFormatMoney($insrow['paid']) . "&nbsp;</td>\n";
209 if ($form_age_cols) {
210 for ($c = 0; $c < $form_age_cols; ++$c) {
211 echo " <td class='detotal' align='right'>&nbsp;" .
212 oeFormatMoney($insrow['agedbal'][$c]) . "&nbsp;</td>\n";
215 else {
216 echo " <td class='detotal' align='right'>&nbsp;" .
217 oeFormatMoney($ins_balance) . "&nbsp;</td>\n";
219 echo " </tr>\n";
221 $grand_total_charges += $insrow['charges'];
222 $grand_total_adjustments += $insrow['adjustments'];
223 $grand_total_paid += $insrow['paid'];
224 for ($c = 0; $c < $form_age_cols; ++$c) {
225 $grand_total_agedbal[$c] += $insrow['agedbal'][$c];
229 function getInsName($payerid) {
230 $tmp = sqlQuery("SELECT name FROM insurance_companies WHERE id = '$payerid'");
231 return $tmp['name'];
234 // In the case of CSV export only, a download will be forced.
235 if ($_POST['form_csvexport']) {
236 header("Pragma: public");
237 header("Expires: 0");
238 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
239 header("Content-Type: application/force-download");
240 header("Content-Disposition: attachment; filename=collections_report.csv");
241 header("Content-Description: File Transfer");
243 else {
245 <html>
246 <head>
247 <?php if (function_exists('html_header_show')) html_header_show(); ?>
248 <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
249 <title><?php xl('Collections Report','e')?></title>
250 <style type="text/css">
252 @media print {
253 #report_parameters {
254 visibility: hidden;
255 display: none;
257 #report_parameters_daterange {
258 visibility: visible;
259 display: inline;
261 #report_results {
262 margin-top: 30px;
266 /* specifically exclude some from the screen */
267 @media screen {
268 #report_parameters_daterange {
269 visibility: hidden;
270 display: none;
274 </style>
276 <script language="JavaScript">
278 function checkAll(checked) {
279 var f = document.forms[0];
280 for (var i = 0; i < f.elements.length; ++i) {
281 var ename = f.elements[i].name;
282 if (ename.indexOf('form_cb[') == 0)
283 f.elements[i].checked = checked;
287 </script>
289 </head>
291 <body class="body_top">
293 <span class='title'><?php xl('Report','e'); ?> - <?php xl('Collections','e'); ?></span>
295 <form method='post' action='collections_report.php' enctype='multipart/form-data' id='theform'>
297 <div id="report_parameters">
299 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
300 <input type='hidden' name='form_export' id='form_export' value=''/>
301 <input type='hidden' name='form_csvexport' id='form_csvexport' value=''/>
303 <table>
304 <tr>
305 <td width='610px'>
306 <div style='float:left'>
308 <table class='text'>
309 <tr>
310 <td class='label'>
311 <table>
312 <tr>
313 <td><?php xl('Displayed Columns','e') ?>:</td>
314 </tr>
315 <tr>
316 <td>
317 <input type='checkbox' name='form_cb_ssn'<?php if ($form_cb_ssn) echo ' checked'; ?>>
318 <?php xl('SSN','e') ?>&nbsp;
319 </td>
320 <td>
321 <input type='checkbox' name='form_cb_dob'<?php if ($form_cb_dob) echo ' checked'; ?>>
322 <?php xl('DOB','e') ?>&nbsp;
323 </td>
324 <td>
325 <input type='checkbox' name='form_cb_pubpid'<?php if ($form_cb_pubpid) echo ' checked'; ?>>
326 <?php xl('ID','e') ?>&nbsp;
327 </td>
328 <td>
329 <input type='checkbox' name='form_cb_policy'<?php if ($form_cb_policy) echo ' checked'; ?>>
330 <?php xl('Policy','e') ?>&nbsp;
331 </td>
332 <td>
333 <input type='checkbox' name='form_cb_phone'<?php if ($form_cb_phone) echo ' checked'; ?>>
334 <?php xl('Phone','e') ?>&nbsp;
335 </td>
336 <td>
337 <input type='checkbox' name='form_cb_city'<?php if ($form_cb_city) echo ' checked'; ?>>
338 <?php xl('City','e') ?>&nbsp;
339 </td>
340 </tr>
341 <tr>
342 <td>
343 <input type='checkbox' name='form_cb_ins1'<?php if ($form_cb_ins1) echo ' checked'; ?>>
344 <?php xl('Primary Ins','e') ?>&nbsp;
345 </td>
346 <td>
347 <input type='checkbox' name='form_cb_referrer'<?php if ($form_cb_referrer) echo ' checked'; ?>>
348 <?php xl('Referrer','e') ?>&nbsp;
349 </td>
350 <td>
351 <input type='checkbox' name='form_cb_adate'<?php if ($form_cb_adate) echo ' checked'; ?>>
352 <?php xl('Act Date','e') ?>&nbsp;
353 </td>
354 <td>
355 <input type='checkbox' name='form_cb_idays'<?php if ($form_cb_idays) echo ' checked'; ?>>
356 <?php xl('Inactive Days','e') ?>&nbsp;
357 </td>
358 <td>
359 <input type='checkbox' name='form_cb_err'<?php if ($form_cb_err) echo ' checked'; ?>>
360 <?php xl('Errors','e') ?>
361 </td>
362 </tr>
363 </table>
364 </td>
365 </tr>
366 </tr>
367 <td>
368 <table>
370 <tr>
371 <td class='label'>
372 <?php xl('Service Date','e'); ?>:
373 </td>
374 <td>
375 <input type='text' name='form_date' id="form_date" size='10' value='<?php echo $form_date ?>'
376 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
377 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
378 id='img_from_date' border='0' alt='[?]' style='cursor:pointer'
379 title='<?php xl('Click here to choose a date','e'); ?>'>
380 </td>
381 <td class='label'>
382 <?php xl('To','e'); ?>:
383 </td>
384 <td>
385 <input type='text' name='form_to_date' id="form_to_date" size='10' value='<?php echo $form_to_date ?>'
386 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
387 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
388 id='img_to_date' border='0' alt='[?]' style='cursor:pointer'
389 title='<?php xl('Click here to choose a date','e'); ?>'>
390 </td>
391 <td>
392 <select name='form_category'>
393 <?php
394 foreach (array('Open' => xl('Open'),'Due Pt' => xl('Due Pt'),'Due Ins' => xl('Due Ins'),'Ins Summary' => xl('Ins Summary'),'Credits' => xl('Credits'),'All' => xl('All')) as $key => $value) {
395 echo " <option value='$key'";
396 if ($_POST['form_category'] == $key) echo " selected";
397 echo ">$value</option>\n";
400 </select>
401 </td>
403 </tr>
406 <tr>
407 <td class='label'>
408 <?php xl('Facility','e'); ?>:
409 </td>
410 <td>
411 <?php dropdown_facility(strip_escape_custom($form_facility), 'form_facility', false); ?>
412 </td>
413 </tr>
415 <tr>
416 <td class='label'>
417 <?php xl('Age By','e') ?>:
418 </td>
419 <td>
420 <select name='form_ageby'>
421 <?php
422 foreach (array('Service Date', 'Last Activity Date') as $value) {
423 echo " <option value='$value'";
424 if ($_POST['form_ageby'] == $value) echo " selected";
425 echo ">" . xl($value) . "</option>\n";
428 </select>
429 </td>
430 </tr>
431 </tr>
432 <td class='label'>
433 <?php xl('Aging Columns:','e') ?>
434 </td>
435 <td>
436 <input type='text' name='form_age_cols' size='2' value='<?php echo $form_age_cols; ?>' />
437 </td>
438 <td class='label'>
439 <?php xl('Days/Col:','e') ?>
440 </td>
441 <td>
442 <input type='text' name='form_age_inc' size='3' value='<?php echo $form_age_inc; ?>' />
443 </td>
444 </tr>
447 </table>
448 </td>
449 </tr>
450 </table>
452 </div>
454 </td>
455 <td align='left' valign='middle' height="100%">
456 <table style='border-left:1px solid; width:100%; height:100%' >
457 <tr>
458 <td>
459 <div style='margin-left:15px'>
460 <a href='#' class='css_button' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
461 <span>
462 <?php xl('Submit','e'); ?>
463 </span>
464 </a>
466 <?php if ($_POST['form_refresh']) { ?>
467 <a href='#' class='css_button' onclick='window.print()'>
468 <span>
469 <?php xl('Print','e'); ?>
470 </span>
471 </a>
472 <?php } ?>
473 </div>
474 </td>
475 </tr>
476 </table>
477 </td>
478 </tr>
479 </table>
480 </div>
483 <?php
485 } // end not form_csvexport
487 if ($_POST['form_refresh'] || $_POST['form_export'] || $_POST['form_csvexport']) {
488 $rows = array();
489 $where = "";
491 if ($INTEGRATED_AR) {
492 if ($_POST['form_export'] || $_POST['form_csvexport']) {
493 $where = "( 1 = 2";
494 foreach ($_POST['form_cb'] as $key => $value) $where .= " OR f.pid = $key";
495 $where .= ' )';
497 if ($form_date) {
498 if ($where) $where .= " AND ";
499 if ($form_to_date) {
500 $where .= "f.date >= '$form_date 00:00:00' AND f.date <= '$form_to_date 23:59:59'";
502 else {
503 $where .= "f.date >= '$form_date 00:00:00' AND f.date <= '$form_date 23:59:59'";
506 if ($form_facility) {
507 if ($where) $where .= " AND ";
508 $where .= "f.facility_id = '$form_facility'";
510 if (! $where) {
511 $where = "1 = 1";
514 $query = "SELECT f.id, f.date, f.pid, f.encounter, f.last_level_billed, " .
515 "f.last_level_closed, f.last_stmt_date, f.stmt_count, f.invoice_refno, " .
516 "p.fname, p.mname, p.lname, p.street, p.city, p.state, " .
517 "p.postal_code, p.phone_home, p.ss, p.genericname2, p.genericval2, " .
518 "p.pubpid, p.DOB, CONCAT(u.lname, ', ', u.fname) AS referrer, " .
519 "( SELECT SUM(b.fee) FROM billing AS b WHERE " .
520 "b.pid = f.pid AND b.encounter = f.encounter AND " .
521 "b.activity = 1 AND b.code_type != 'COPAY' ) AS charges, " .
522 "( SELECT SUM(b.fee) FROM billing AS b WHERE " .
523 "b.pid = f.pid AND b.encounter = f.encounter AND " .
524 "b.activity = 1 AND b.code_type = 'COPAY' ) AS copays, " .
525 "( SELECT SUM(s.fee) FROM drug_sales AS s WHERE " .
526 "s.pid = f.pid AND s.encounter = f.encounter ) AS sales, " .
527 "( SELECT SUM(a.pay_amount) FROM ar_activity AS a WHERE " .
528 "a.pid = f.pid AND a.encounter = f.encounter ) AS payments, " .
529 "( SELECT SUM(a.adj_amount) FROM ar_activity AS a WHERE " .
530 "a.pid = f.pid AND a.encounter = f.encounter ) AS adjustments " .
531 "FROM form_encounter AS f " .
532 "JOIN patient_data AS p ON p.pid = f.pid " .
533 "LEFT OUTER JOIN users AS u ON u.id = p.providerID " .
534 "WHERE $where " .
535 "ORDER BY f.pid, f.encounter";
536 $eres = sqlStatement($query);
538 while ($erow = sqlFetchArray($eres)) {
539 $patient_id = $erow['pid'];
540 $encounter_id = $erow['encounter'];
541 $pt_balance = $erow['charges'] + $erow['sales'] + $erow['copays'] - $erow['payments'] - $erow['adjustments'];
542 $pt_balance = 0 + sprintf("%.2f", $pt_balance); // yes this seems to be necessary
543 $svcdate = substr($erow['date'], 0, 10);
545 if ($_POST['form_refresh'] && ! $is_all) {
546 if ($pt_balance == 0) continue;
548 if ($_POST['form_category'] == 'Credits') {
549 if ($pt_balance > 0) continue;
552 // If we have not yet billed the patient, then compute $duncount as a
553 // negative count of the number of insurance plans for which we have not
554 // yet closed out insurance. Here we also compute $insname as the name of
555 // the insurance plan from which we are awaiting payment, and its sequence
556 // number $insposition (1-3).
557 $last_level_closed = $erow['last_level_closed'];
558 $duncount = $erow['stmt_count'];
559 $payerids = array();
560 $insposition = 0;
561 $insname = '';
562 if (! $duncount) {
563 for ($i = 1; $i <= 3; ++$i) {
564 $tmp = arGetPayerID($patient_id, $svcdate, $i);
565 if (empty($tmp)) break;
566 $payerids[] = $tmp;
568 $duncount = $last_level_closed - count($payerids);
569 if ($duncount < 0) {
570 if (!empty($payerids[$last_level_closed])) {
571 $insname = getInsName($payerids[$last_level_closed]);
572 $insposition = $last_level_closed + 1;
577 // Skip invoices not in the desired "Due..." category.
579 if ($is_due_ins && $duncount >= 0) continue;
580 if ($is_due_pt && $duncount < 0) continue;
582 // echo "<!-- " . $erow['encounter'] . ': ' . $erow['charges'] . ' + ' . $erow['sales'] . ' + ' . $erow['copays'] . ' - ' . $erow['payments'] . ' - ' . $erow['adjustments'] . " -->\n"; // debugging
584 // An invoice is due from the patient if money is owed and we are
585 // not waiting for insurance to pay.
586 $isduept = ($duncount >= 0) ? " checked" : "";
588 $row = array();
590 $row['id'] = $erow['id'];
591 $row['invnumber'] = "$patient_id.$encounter_id";
592 $row['custid'] = $patient_id;
593 $row['name'] = $erow['fname'] . ' ' . $erow['lname'];
594 $row['address1'] = $erow['street'];
595 $row['city'] = $erow['city'];
596 $row['state'] = $erow['state'];
597 $row['zipcode'] = $erow['postal_code'];
598 $row['phone'] = $erow['phone_home'];
599 $row['duncount'] = $duncount;
600 $row['dos'] = $svcdate;
601 $row['ss'] = $erow['ss'];
602 $row['DOB'] = $erow['DOB'];
603 $row['pubpid'] = $erow['pubpid'];
604 $row['billnote'] = ($erow['genericname2'] == 'Billing') ? $erow['genericval2'] : '';
605 $row['referrer'] = $erow['referrer'];
606 $row['irnumber'] = $erow['invoice_refno'];
608 // Also get the primary insurance company name whenever there is one.
609 $row['ins1'] = '';
610 if ($insposition == 1) {
611 $row['ins1'] = $insname;
612 } else {
613 if (empty($payerids)) {
614 $tmp = arGetPayerID($patient_id, $svcdate, 1);
615 if (!empty($tmp)) $payerids[] = $tmp;
617 if (!empty($payerids)) {
618 $row['ins1'] = getInsName($payerids[0]);
622 // This computes the invoice's total original charges and adjustments,
623 // date of last activity, and determines if insurance has responded to
624 // all billing items.
625 $invlines = ar_get_invoice_summary($patient_id, $encounter_id, true);
627 // if ($encounter_id == 185) { // debugging
628 // echo "\n<!--\n";
629 // print_r($invlines);
630 // echo "\n-->\n";
631 // }
633 $row['charges'] = 0;
634 $row['adjustments'] = 0;
635 $row['paid'] = 0;
636 $ins_seems_done = true;
637 $ladate = $svcdate;
638 foreach ($invlines as $key => $value) {
639 $row['charges'] += $value['chg'] + $value['adj'];
640 $row['adjustments'] += 0 - $value['adj'];
641 $row['paid'] += $value['chg'] - $value['bal'];
642 foreach ($value['dtl'] as $dkey => $dvalue) {
643 $dtldate = trim(substr($dkey, 0, 10));
644 if ($dtldate && $dtldate > $ladate) $ladate = $dtldate;
646 $lckey = strtolower($key);
647 if ($lckey == 'co-pay' || $lckey == 'claim') continue;
648 if (count($value['dtl']) <= 1) $ins_seems_done = false;
651 // Simulating ar.amount in SQL-Ledger which is charges with adjustments:
652 $row['amount'] = $row['charges'] + $row['adjustments'];
654 $row['billing_errmsg'] = '';
655 if ($is_due_ins && $last_level_closed < 1 && $ins_seems_done)
656 $row['billing_errmsg'] = 'Ins1 seems done';
657 else if ($last_level_closed >= 1 && !$ins_seems_done)
658 $row['billing_errmsg'] = 'Ins1 seems not done';
660 $row['ladate'] = $ladate;
662 // Compute number of days since last activity.
663 $latime = mktime(0, 0, 0, substr($ladate, 5, 2),
664 substr($ladate, 8, 2), substr($ladate, 0, 4));
665 $row['inactive_days'] = floor((time() - $latime) / (60 * 60 * 24));
667 // Look up insurance policy number if we need it.
668 if ($form_cb_policy) {
669 $instype = ($insposition == 2) ? 'secondary' : (($insposition == 3) ? 'tertiary' : 'primary');
670 $insrow = sqlQuery("SELECT policy_number FROM insurance_data WHERE " .
671 "pid = '$patient_id' AND type = '$instype' AND date <= '$svcdate' " .
672 "ORDER BY date DESC LIMIT 1");
673 $row['policy'] = $insrow['policy_number'];
676 $ptname = $erow['lname'] . ", " . $erow['fname'];
677 if ($erow['mname']) $ptname .= " " . substr($erow['mname'], 0, 1);
679 if (!$is_due_ins ) $insname = '';
680 $rows[$insname . '|' . $ptname . '|' . $encounter_id] = $row;
681 } // end while
682 } // end $INTEGRATED_AR
683 else {
684 if ($_POST['form_export'] || $_POST['form_csvexport']) {
685 $where = "( 1 = 2";
686 foreach ($_POST['form_cb'] as $key => $value) $where .= " OR ar.customer_id = $key";
687 $where .= ' )';
690 if ($form_date) {
691 if ($where) $where .= " AND ";
692 $date1 = substr($form_date, 0, 4) . substr($form_date, 5, 2) .
693 substr($form_date, 8, 2);
694 if ($form_to_date) {
695 $date2 = substr($form_to_date, 0, 4) . substr($form_to_date, 5, 2) .
696 substr($form_to_date, 8, 2);
697 $where .= "((CAST (substring(ar.invnumber from position('.' in ar.invnumber) + 1 for 8) AS integer) " .
698 "BETWEEN '$date1' AND '$date2')";
699 $tmp = "date >= '$form_date' AND date <= '$form_to_date'";
701 else {
702 // This catches old converted invoices where we have no encounters:
703 $where .= "(ar.invnumber LIKE '%.$date1'";
704 $tmp = "date = '$form_date'";
706 // Pick out the encounters from MySQL with the desired DOS:
707 $rez = sqlStatement("SELECT pid, encounter FROM form_encounter WHERE $tmp");
708 while ($row = sqlFetchArray($rez)) {
709 $where .= " OR ar.invnumber = '" . $row['pid'] . "." . $row['encounter'] . "'";
711 $where .= ")";
714 if (! $where) {
715 $where = "1 = 1";
718 // Instead of the subselects in the following query, we will call
719 // get_invoice_summary() in order to get data at the procedure level and
720 // thus decide if insurance appears to be done with each invoice.
722 $query = "SELECT ar.id, ar.invnumber, ar.duedate, ar.amount, ar.paid, " .
723 "ar.intnotes, ar.notes, ar.shipvia, " .
724 "customer.id AS custid, customer.name, customer.address1, " .
725 "customer.city, customer.state, customer.zipcode, customer.phone " .
726 // ", (SELECT SUM(invoice.fxsellprice) FROM invoice WHERE " .
727 // "invoice.trans_id = ar.id AND invoice.fxsellprice > 0) AS charges, " .
728 // "(SELECT SUM(invoice.fxsellprice) FROM invoice WHERE " .
729 // "invoice.trans_id = ar.id AND invoice.fxsellprice < 0) AS adjustments " .
730 "FROM ar JOIN customer ON customer.id = ar.customer_id " .
731 "WHERE ( $where ) ";
732 if ($_POST['form_refresh'] && ! $is_all) {
733 $query .= "AND ar.amount != ar.paid ";
735 $query .= "ORDER BY ar.invnumber";
737 // echo "<!-- $query -->\n"; // debugging
739 $t_res = SLQuery($query);
740 if ($sl_err) die($sl_err);
741 $num_invoices = SLRowCount($t_res);
743 //////////////////////////////////////////////////////////////////
745 for ($irow = 0; $irow < $num_invoices; ++$irow) {
746 $row = SLGetRow($t_res, $irow);
748 // If a facility was specified then skip invoices whose encounters
749 // do not indicate that facility.
750 if ($form_facility) {
751 list($patient_id, $encounter_id) = explode(".", $row['invnumber']);
752 $tmp = sqlQuery("SELECT count(*) AS count FROM form_encounter WHERE " .
753 "pid = '$patient_id' AND encounter = '$encounter_id' AND " .
754 "facility_id = '$form_facility'");
755 if (empty($tmp['count'])) continue;
758 $pt_balance = sprintf("%.2f",$row['amount']) - sprintf("%.2f",$row['paid']);
760 if ($_POST['form_category'] == 'Credits') {
761 if ($pt_balance > 0) continue;
764 // $duncount was originally supposed to be the number of times that
765 // the patient was sent a statement for this invoice.
767 $duncount = substr_count(strtolower($row['intnotes']), "statement sent");
769 // But if we have not yet billed the patient, then compute $duncount as a
770 // negative count of the number of insurance plans for which we have not
771 // yet closed out insurance. Here we also compute $insname as the name of
772 // the insurance plan from which we are awaiting payment, and its sequence
773 // number $insposition (1-3).
775 $insname = '';
776 $insposition = 0;
777 $inseobs = strtolower($row['shipvia']);
778 $insgot = strtolower($row['notes']);
779 if (! $duncount) {
780 foreach (array('ins1', 'ins2', 'ins3') as $value) {
781 $i = strpos($insgot, $value);
782 if ($i !== false && strpos($inseobs, $value) === false) {
783 --$duncount;
784 if (!$insname && $is_due_ins) {
785 $j = strpos($insgot, "\n", $i);
786 if (!$j) $j = strlen($insgot);
787 $insname = trim(substr($row['notes'], $i + 5, $j - $i - 5));
788 $insposition = substr($value, 3); // 1, 2 or 3
793 $row['insname'] = $insname;
795 // Also get the primary insurance company name whenever there is one.
796 $row['ins1'] = '';
797 $i = strpos($insgot, 'ins1');
798 if ($i !== false) {
799 $j = strpos($insgot, "\n", $i);
800 if (!$j) $j = strlen($insgot);
801 $row['ins1'] = trim(substr($row['notes'], $i + 5, $j - $i - 5));
804 // An invoice is now due from the patient if money is owed and we are
805 // not waiting for insurance to pay. We no longer look at the due date
806 // for this.
808 $isduept = ($duncount >= 0) ? " checked" : "";
810 // Skip invoices not in the desired "Due..." category.
812 if ($is_due_ins && $duncount >= 0) continue;
813 if ($is_due_pt && $duncount < 0) continue;
815 $row['duncount'] = $duncount;
817 // Determine the date of service. An 8-digit encounter number is
818 // presumed to be a date of service imported during conversion.
819 // Otherwise look it up in the form_encounter table.
821 $svcdate = "";
822 list($pid, $encounter) = explode(".", $row['invnumber']);
823 if (strlen($encounter) == 8) {
824 $svcdate = substr($encounter, 0, 4) . "-" . substr($encounter, 4, 2) .
825 "-" . substr($encounter, 6, 2);
827 else if ($encounter) {
828 $tmp = sqlQuery("SELECT date FROM form_encounter WHERE " .
829 "encounter = $encounter");
830 $svcdate = substr($tmp['date'], 0, 10);
833 $row['dos'] = $svcdate;
835 // This computes the invoice's total original charges and adjustments,
836 // date of last activity, and determines if insurance has responded to
837 // all billing items.
839 $invlines = get_invoice_summary($row['id'], true);
840 $row['charges'] = 0;
841 $row['adjustments'] = 0;
842 $ins_seems_done = true;
843 $ladate = $svcdate;
844 foreach ($invlines as $key => $value) {
845 $row['charges'] += $value['chg'] + $value['adj'];
846 $row['adjustments'] += 0 - $value['adj'];
847 foreach ($value['dtl'] as $dkey => $dvalue) {
848 $dtldate = trim(substr($dkey, 0, 10));
849 if ($dtldate && $dtldate > $ladate) $ladate = $dtldate;
851 $lckey = strtolower($key);
852 if ($lckey == 'co-pay' || $lckey == 'claim') continue;
853 if (count($value['dtl']) <= 1) $ins_seems_done = false;
855 $row['billing_errmsg'] = '';
856 if ($is_due_ins && strpos($inseobs, 'ins1') === false && $ins_seems_done)
857 $row['billing_errmsg'] = 'Ins1 seems done';
858 else if (strpos($inseobs, 'ins1') !== false && !$ins_seems_done)
859 $row['billing_errmsg'] = 'Ins1 seems not done';
861 $row['ladate'] = $ladate;
863 // Compute number of days since last activity.
864 $latime = mktime(0, 0, 0, substr($ladate, 5, 2),
865 substr($ladate, 8, 2), substr($ladate, 0, 4));
866 $row['inactive_days'] = floor((time() - $latime) / (60 * 60 * 24));
868 $pdrow = sqlQuery("SELECT pd.fname, pd.lname, pd.mname, pd.ss, " .
869 "pd.genericname2, pd.genericval2, pd.pid, pd.pubpid, pd.DOB, " .
870 "CONCAT(u.lname, ', ', u.fname) AS referrer FROM " .
871 "integration_mapping AS im, patient_data AS pd " .
872 "LEFT OUTER JOIN users AS u ON u.id = pd.providerID " .
873 "WHERE im.foreign_id = " . $row['custid'] . " AND " .
874 "im.foreign_table = 'customer' AND " .
875 "pd.id = im.local_id");
877 $row['ss'] = $pdrow['ss'];
878 $row['DOB'] = $pdrow['DOB'];
879 $row['pubpid'] = $pdrow['pubpid'];
880 $row['billnote'] = ($pdrow['genericname2'] == 'Billing') ? $pdrow['genericval2'] : '';
881 $row['referrer'] = $pdrow['referrer'];
883 $ptname = $pdrow['lname'] . ", " . $pdrow['fname'];
884 if ($pdrow['mname']) $ptname .= " " . substr($pdrow['mname'], 0, 1);
886 // Look up insurance policy number if we need it.
887 if ($form_cb_policy) {
888 $patient_id = $pdrow['pid'];
889 $instype = ($insposition == 2) ? 'secondary' : (($insposition == 3) ? 'tertiary' : 'primary');
890 $insrow = sqlQuery("SELECT policy_number FROM insurance_data WHERE " .
891 "pid = '$patient_id' AND type = '$instype' AND date <= '$svcdate' " .
892 "ORDER BY date DESC LIMIT 1");
893 $row['policy'] = $insrow['policy_number'];
896 $rows[$insname . '|' . $ptname . '|' . $encounter] = $row;
897 } // end for
898 } // end not $INTEGRATED_AR
900 ksort($rows);
902 if ($_POST['form_export']) {
903 echo "<textarea rows='35' cols='100' readonly>";
905 else if ($_POST['form_csvexport']) {
906 // CSV headers:
907 if (true) {
908 echo '"Insurance",';
909 echo '"Name",';
910 echo '"Invoice",';
911 echo '"DOS",';
912 echo '"Referrer",';
913 echo '"Charge",';
914 echo '"Adjust",';
915 echo '"Paid",';
916 echo '"Balance",';
917 echo '"IDays",';
918 echo '"LADate"' . "\n";
921 else {
924 <div id="report_results">
925 <table>
927 <thead>
928 <?php if ($is_due_ins) { ?>
929 <th>&nbsp;<?php xl('Insurance','e')?></th>
930 <?php } ?>
931 <?php if (!$is_ins_summary) { ?>
932 <th>&nbsp;<?php xl('Name','e')?></th>
933 <?php } ?>
934 <?php if ($form_cb_ssn) { ?>
935 <th>&nbsp;<?php xl('SSN','e')?></th>
936 <?php } ?>
937 <?php if ($form_cb_dob) { ?>
938 <th>&nbsp;<?php xl('DOB','e')?></th>
939 <?php } ?>
940 <?php if ($form_cb_pubpid) { ?>
941 <th>&nbsp;<?php xl('ID','e')?></th>
942 <?php } ?>
943 <?php if ($form_cb_policy) { ?>
944 <th>&nbsp;<?php xl('Policy','e')?></th>
945 <?php } ?>
946 <?php if ($form_cb_phone) { ?>
947 <th>&nbsp;<?php xl('Phone','e')?></th>
948 <?php } ?>
949 <?php if ($form_cb_city) { ?>
950 <th>&nbsp;<?php xl('City','e')?></th>
951 <?php } ?>
952 <?php if ($form_cb_ins1) { ?>
953 <th>&nbsp;<?php xl('Primary Ins','e')?></th>
954 <?php } ?>
955 <?php if ($form_cb_referrer) { ?>
956 <th>&nbsp;<?php xl('Referrer','e')?></th>
957 <?php } ?>
958 <?php if (!$is_ins_summary) { ?>
959 <th>&nbsp;<?php xl('Invoice','e') ?></th>
960 <th>&nbsp;<?php xl('Svc Date','e') ?></th>
961 <?php if ($form_cb_adate) { ?>
962 <th>&nbsp;<?php xl('Act Date','e')?></th>
963 <?php } ?>
964 <?php } ?>
965 <th align="right"><?php xl('Charge','e') ?>&nbsp;</th>
966 <th align="right"><?php xl('Adjust','e') ?>&nbsp;</th>
967 <th align="right"><?php xl('Paid','e') ?>&nbsp;</th>
968 <?php
969 // Generate aging headers if appropriate, else balance header.
970 if ($form_age_cols) {
971 for ($c = 0; $c < $form_age_cols;) {
972 echo " <th class='dehead' align='right'>";
973 echo $form_age_inc * $c;
974 if (++$c < $form_age_cols) {
975 echo "-" . ($form_age_inc * $c - 1);
976 } else {
977 echo "+";
979 echo "</th>\n";
982 else {
984 <th align="right"><?php xl('Balance','e') ?>&nbsp;</th>
985 <?php
988 <?php if ($form_cb_idays) { ?>
989 <th align="right"><?php xl('IDays','e')?>&nbsp;</th>
990 <?php } ?>
991 <?php if (!$is_ins_summary) { ?>
992 <th align="center"><?php xl('Prv','e') ?></th>
993 <th align="center"><?php xl('Sel','e') ?></th>
994 <?php } ?>
995 <?php if ($form_cb_err) { ?>
996 <th>&nbsp;<?php xl('Error','e')?></th>
997 <?php } ?>
998 </thead>
1000 <?php
1001 } // end not export
1003 $ptrow = array('insname' => '', 'pid' => 0);
1004 $orow = -1;
1006 foreach ($rows as $key => $row) {
1007 list($insname, $ptname, $trash) = explode('|', $key);
1008 list($pid, $encounter) = explode(".", $row['invnumber']);
1010 if ($is_ins_summary && $insname != $ptrow['insname']) {
1011 endInsurance($ptrow);
1012 $bgcolor = ((++$orow & 1) ? "#ffdddd" : "#ddddff");
1013 $ptrow = array('insname' => $insname, 'ptname' => $ptname, 'pid' => $pid, 'count' => 1);
1014 foreach ($row as $key => $value) $ptrow[$key] = $value;
1015 $ptrow['agedbal'] = array();
1017 else if (!$is_ins_summary && ($insname != $ptrow['insname'] || $pid != $ptrow['pid'])) {
1018 // For the report, this will write the patient totals. For the
1019 // collections export this writes everything for the patient:
1020 endPatient($ptrow);
1021 $bgcolor = ((++$orow & 1) ? "#ffdddd" : "#ddddff");
1022 $ptrow = array('insname' => $insname, 'ptname' => $ptname, 'pid' => $pid, 'count' => 1);
1023 foreach ($row as $key => $value) $ptrow[$key] = $value;
1024 $ptrow['agedbal'] = array();
1025 } else {
1026 $ptrow['amount'] += $row['amount'];
1027 $ptrow['paid'] += $row['paid'];
1028 $ptrow['charges'] += $row['charges'];
1029 $ptrow['adjustments'] += $row['adjustments'];
1030 ++$ptrow['count'];
1033 // Compute invoice balance and aging column number, and accumulate aging.
1034 $balance = $row['charges'] + $row['adjustments'] - $row['paid'];
1035 if ($form_age_cols) {
1036 $agedate = $is_ageby_lad ? $row['ladate'] : $row['dos'];
1037 $agetime = mktime(0, 0, 0, substr($agedate, 5, 2),
1038 substr($agedate, 8, 2), substr($agedate, 0, 4));
1039 $days = floor((time() - $agetime) / (60 * 60 * 24));
1040 $agecolno = min($form_age_cols - 1, max(0, floor($days / $form_age_inc)));
1041 $ptrow['agedbal'][$agecolno] += $balance;
1044 if (!$is_ins_summary && !$_POST['form_export'] && !$_POST['form_csvexport']) {
1045 $in_collections = stristr($row['billnote'], 'IN COLLECTIONS') !== false;
1047 <tr bgcolor='<?php echo $bgcolor ?>'>
1048 <?php
1049 if ($ptrow['count'] == 1) {
1050 if ($is_due_ins) {
1051 echo " <td class='detail'>&nbsp;$insname</td>\n";
1053 echo " <td class='detail'>&nbsp;$ptname</td>\n";
1054 if ($form_cb_ssn) {
1055 echo " <td class='detail'>&nbsp;" . $row['ss'] . "</td>\n";
1057 if ($form_cb_dob) {
1058 echo " <td class='detail'>&nbsp;" . oeFormatShortDate($row['DOB']) . "</td>\n";
1060 if ($form_cb_pubpid) {
1061 echo " <td class='detail'>&nbsp;" . $row['pubpid'] . "</td>\n";
1063 if ($form_cb_policy) {
1064 echo " <td class='detail'>&nbsp;" . $row['policy'] . "</td>\n";
1066 if ($form_cb_phone) {
1067 echo " <td class='detail'>&nbsp;" . $row['phone'] . "</td>\n";
1069 if ($form_cb_city) {
1070 echo " <td class='detail'>&nbsp;" . $row['city'] . "</td>\n";
1072 if ($form_cb_ins1) {
1073 echo " <td class='detail'>&nbsp;" . $row['ins1'] . "</td>\n";
1075 if ($form_cb_referrer) {
1076 echo " <td class='detail'>&nbsp;" . $row['referrer'] . "</td>\n";
1078 } else {
1079 echo " <td class='detail' colspan='$initial_colspan'>";
1080 echo "&nbsp;</td>\n";
1083 <td class="detail">
1084 &nbsp;<a href="../billing/sl_eob_invoice.php?id=<?php echo $row['id'] ?>"
1085 target="_blank"><?php echo empty($row['irnumber']) ? $row['invnumber'] : $row['irnumber']; ?></a>
1086 </td>
1087 <td class="detail">
1088 &nbsp;<?php echo oeFormatShortDate($row['dos']); ?>
1089 </td>
1090 <?php if ($form_cb_adate) { ?>
1091 <td class='detail'>
1092 &nbsp;<?php echo oeFormatShortDate($row['ladate']); ?>
1093 </td>
1094 <?php } ?>
1095 <td class="detail" align="right">
1096 <?php bucks($row['charges']) ?>&nbsp;
1097 </td>
1098 <td class="detail" align="right">
1099 <?php bucks($row['adjustments']) ?>&nbsp;
1100 </td>
1101 <td class="detail" align="right">
1102 <?php bucks($row['paid']) ?>&nbsp;
1103 </td>
1104 <?php
1105 if ($form_age_cols) {
1106 for ($c = 0; $c < $form_age_cols; ++$c) {
1107 echo " <td class='detail' align='right'>";
1108 if ($c == $agecolno) {
1109 bucks($balance);
1111 echo "&nbsp;</td>\n";
1114 else {
1116 <td class="detail" align="right"><?php bucks($balance) ?>&nbsp;</td>
1117 <?php
1118 } // end else
1120 <?php
1121 if ($form_cb_idays) {
1122 echo " <td class='detail' align='right'>";
1123 echo $row['inactive_days'] . "&nbsp;</td>\n";
1126 <td class="detail" align="center">
1127 <?php echo $row['duncount'] ? $row['duncount'] : "&nbsp;" ?>
1128 </td>
1129 <td class="detail" align="center">
1130 <?php
1131 if ($ptrow['count'] == 1) {
1132 if ($in_collections) {
1133 echo " <b><font color='red'>IC</font></b>\n";
1134 } else {
1135 echo " <input type='checkbox' name='form_cb[" . $row['custid'] . "]' />\n";
1137 } else {
1138 echo " &nbsp;\n";
1141 </td>
1142 <?php
1143 if ($form_cb_err) {
1144 echo " <td class='detail'>&nbsp;";
1145 echo $row['billing_errmsg'] . "</td>\n";
1148 </tr>
1149 <?php
1150 } // end not export and not insurance summary
1152 else if ($_POST['form_csvexport']) {
1153 // The CSV detail line is written here.
1154 $balance = $row['charges'] + $row['adjustments'] - $row['paid'];
1155 // echo '"' . $insname . '",';
1156 echo '"' . $row['ins1'] . '",';
1157 echo '"' . $ptname . '",';
1158 echo '"' . (empty($row['irnumber']) ? $row['invnumber'] : $row['irnumber']) . '",';
1159 echo '"' . oeFormatShortDate($row['dos']) . '",';
1160 echo '"' . $row['referrer'] . '",';
1161 echo '"' . oeFormatMoney($row['charges']) . '",';
1162 echo '"' . oeFormatMoney($row['adjustments']) . '",';
1163 echo '"' . oeFormatMoney($row['paid']) . '",';
1164 echo '"' . oeFormatMoney($balance) . '",';
1165 echo '"' . $row['inactive_days'] . '",';
1166 echo '"' . oeFormatShortDate($row['ladate']) . '"' . "\n";
1167 } // end $form_csvexport
1169 } // end loop
1171 if ($is_ins_summary)
1172 endInsurance($ptrow);
1173 else
1174 endPatient($ptrow);
1176 if ($_POST['form_export']) {
1177 echo "</textarea>\n";
1178 $alertmsg .= "$export_patient_count patients with total of " .
1179 oeFormatMoney($export_dollars) . " have been exported ";
1180 if ($_POST['form_without']) {
1181 $alertmsg .= "but NOT flagged as in collections.";
1182 } else {
1183 $alertmsg .= "AND flagged as in collections.";
1186 else if ($_POST['form_csvexport']) {
1187 // echo "</textarea>\n";
1188 // $alertmsg .= "$export_patient_count patients representing $" .
1189 // sprintf("%.2f", $export_dollars) . " have been exported.";
1191 else {
1192 echo " <tr bgcolor='#ffffff'>\n";
1193 if ($is_ins_summary) {
1194 echo " <td class='dehead'>&nbsp;" . xl('Report Totals') . ":</td>\n";
1195 } else {
1196 echo " <td class='detail' colspan='$initial_colspan'>\n";
1197 echo " &nbsp;</td>\n";
1198 echo " <td class='dehead' colspan='" . ($final_colspan - 3) .
1199 "'>&nbsp;" . xl('Report Totals') . ":</td>\n";
1201 echo " <td class='dehead' align='right'>&nbsp;" .
1202 oeFormatMoney($grand_total_charges) . "&nbsp;</td>\n";
1203 echo " <td class='dehead' align='right'>&nbsp;" .
1204 oeFormatMoney($grand_total_adjustments) . "&nbsp;</td>\n";
1205 echo " <td class='dehead' align='right'>&nbsp;" .
1206 oeFormatMoney($grand_total_paid) . "&nbsp;</td>\n";
1207 if ($form_age_cols) {
1208 for ($c = 0; $c < $form_age_cols; ++$c) {
1209 echo " <td class='dehead' align='right'>" .
1210 oeFormatMoney($grand_total_agedbal[$c]) . "&nbsp;</td>\n";
1213 else {
1214 echo " <td class='dehead' align='right'>" .
1215 oeFormatMoney($grand_total_charges +
1216 $grand_total_adjustments - $grand_total_paid) . "&nbsp;</td>\n";
1218 if ($form_cb_idays) echo " <td class='detail'>&nbsp;</td>\n";
1219 if (!$is_ins_summary) echo " <td class='detail' colspan='2'>&nbsp;</td>\n";
1220 if ($form_cb_err) echo " <td class='detail'>&nbsp;</td>\n";
1221 echo " </tr>\n";
1222 echo "</table>\n";
1223 echo "</div>\n";
1225 } // end if form_refresh
1227 if (!$INTEGRATED_AR) SLClose();
1229 if (!$_POST['form_csvexport']) {
1230 if (!$_POST['form_export']) {
1233 <div style='float;margin-top:5px'>
1235 <a href='javascript:;' class='css_button' onclick='checkAll(true)'><span><?php xl('Select All','e'); ?></span></a>
1236 <a href='javascript:;' class='css_button' onclick='checkAll(false)'><span><?php xl('Clear All','e'); ?></span></a>
1237 <a href='javascript:;' class='css_button' onclick='$("#form_csvexport").attr("value","true"); $("#theform").submit();'>
1238 <span><?php xl('Export Selected as CSV','e'); ?></span>
1239 </a>
1240 <a href='javascript:;' class='css_button' onclick='$("#form_export").attr("value","true"); $("#theform").submit();'>
1241 <span><?php xl('Export Selected to Collections','e'); ?></span>
1242 </a>
1243 </div>
1245 <div style='float:left'>
1246 <input type='checkbox' name='form_without' value='1' /> <?php xl('Without Update','e') ?>
1247 </div>
1249 <?php
1250 } // end not export
1252 </form>
1253 </center>
1254 <script language="JavaScript">
1255 <?php
1256 if ($alertmsg) {
1257 echo "alert('" . htmlentities($alertmsg) . "');\n";
1260 </script>
1261 </body>
1262 <!-- stuff for the popup calendar -->
1263 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
1264 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
1265 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
1266 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
1267 <script type="text/javascript" src="../../library/js/jquery.1.3.2.js"></script>
1268 <script language="Javascript">
1269 Calendar.setup({inputField:"form_date", ifFormat:"%Y-%m-%d", button:"img_from_date"});
1270 Calendar.setup({inputField:"form_to_date", ifFormat:"%Y-%m-%d", button:"img_to_date"});
1271 </script>
1272 </html>
1273 <?php
1274 } // end not form_csvexport