2 // Copyright (C) 2006-2008 Rod Roark <rod@sunsetsystems.com>
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 include_once("../globals.php");
10 include_once("../../library/patient.inc");
11 include_once("../../library/sql-ledger.inc");
12 include_once("../../library/invoice_summary.inc.php");
13 // include_once("../../custom/statement.inc.php");
14 // include_once("../../library/sl_eob.inc.php");
18 $export_patient_count = 0;
21 $today = date("Y-m-d");
23 $form_date = fixDate($_POST['form_date'], "");
24 $form_to_date = fixDate($_POST['form_to_date'], "");
25 $is_due_ins = $_POST['form_category'] == xl('Due Ins');
26 $is_due_pt = $_POST['form_category'] == xl('Due Pt');
27 $is_all = $_POST['form_category'] == xl('All');
29 if ($_POST['form_search'] ||
$_POST['form_export'] ||
$_POST['form_csvexport']) {
30 $form_cb_ssn = $_POST['form_cb_ssn'] ?
true : false;
31 $form_cb_dob = $_POST['form_cb_dob'] ?
true : false;
32 $form_cb_policy = $_POST['form_cb_policy'] ?
true : false;
33 $form_cb_phone = $_POST['form_cb_phone'] ?
true : false;
34 $form_cb_city = $_POST['form_cb_city'] ?
true : false;
35 $form_cb_ins1 = $_POST['form_cb_ins1'] ?
true : false;
36 $form_cb_referrer = $_POST['form_cb_referrer'] ?
true : false;
37 $form_cb_idays = $_POST['form_cb_idays'] ?
true : false;
38 $form_cb_err = $_POST['form_cb_err'] ?
true : false;
42 $form_cb_policy = false;
43 $form_cb_phone = true;
44 $form_cb_city = false;
45 $form_cb_ins1 = false;
46 $form_cb_referrer = false;
47 $form_cb_idays = false;
50 $form_age_cols = (int) $_POST['form_age_cols'];
51 $form_age_inc = (int) $_POST['form_age_inc'];
52 if ($form_age_cols > 0 && $form_age_cols < 50) {
53 if ($form_age_inc <= 0) $form_age_inc = 30;
60 if ($is_due_ins ) ++
$initial_colspan;
61 if ($form_cb_ssn ) ++
$initial_colspan;
62 if ($form_cb_dob ) ++
$initial_colspan;
63 if ($form_cb_policy ) ++
$initial_colspan;
64 if ($form_cb_phone ) ++
$initial_colspan;
65 if ($form_cb_city ) ++
$initial_colspan;
66 if ($form_cb_ins1 ) ++
$initial_colspan;
67 if ($form_cb_referrer) ++
$initial_colspan;
69 $grand_total_charges = 0;
70 $grand_total_adjustments = 0;
71 $grand_total_paid = 0;
72 $grand_total_agedbal = array();
73 for ($c = 0; $c < $form_age_cols; ++
$c) $grand_total_agedbal[$c] = 0;
77 function bucks($amount) {
79 printf("%.2f", $amount);
82 function endPatient($ptrow) {
83 global $export_patient_count, $export_dollars, $bgcolor;
84 global $grand_total_charges, $grand_total_adjustments, $grand_total_paid;
85 global $grand_total_agedbal, $is_due_ins, $form_age_cols;
86 global $initial_colspan, $form_cb_idays, $form_cb_err;
88 if (!$ptrow['pid']) return;
90 $pt_balance = $ptrow['amount'] - $ptrow['paid'];
92 if ($_POST['form_export']) {
93 // This is a fixed-length format used by Transworld Systems. Your
94 // needs will surely be different, so consider this just an example.
96 echo "1896H"; // client number goes here
98 echo sprintf("%-30s", substr($ptrow['ptname'], 0, 30));
99 echo sprintf("%-30s", " ");
100 echo sprintf("%-30s", substr($ptrow['address1'], 0, 30));
101 echo sprintf("%-15s", substr($ptrow['city'], 0, 15));
102 echo sprintf("%-2s", substr($ptrow['state'], 0, 2));
103 echo sprintf("%-5s", $ptrow['zipcode'] ?
substr($ptrow['zipcode'], 0, 5) : '00000');
104 echo "1"; // service code
105 echo sprintf("%010.0f", $ptrow['pid']); // transmittal number = patient id
107 echo sprintf("%-15s", substr($ptrow['ss'], 0, 15));
108 echo substr($ptrow['dos'], 5, 2) . substr($ptrow['dos'], 8, 2) . substr($ptrow['dos'], 2, 2);
109 echo sprintf("%08.0f", $pt_balance * 100);
110 echo sprintf("%-9s\n", " ");
112 if (!$_POST['form_without']) {
113 sqlStatement("UPDATE patient_data SET " .
114 "genericname2 = 'Billing', " .
115 "genericval2 = CONCAT('IN COLLECTIONS " . date("Y-m-d") . "', genericval2) " .
116 "WHERE pid = '" . $ptrow['pid'] . "'");
118 $export_patient_count +
= 1;
119 $export_dollars +
= $pt_balance;
121 else if ($_POST['form_csvexport']) {
122 $export_patient_count +
= 1;
123 $export_dollars +
= $pt_balance;
126 if ($ptrow['count'] > 1) {
127 echo " <tr bgcolor='$bgcolor'>\n";
128 echo " <td class='detail' colspan='$initial_colspan'>";
129 echo " </td>\n";
130 echo " <td class='detotal' colspan='5'> Total Patient Balance:</td>\n";
131 if ($form_age_cols) {
132 for ($c = 0; $c < $form_age_cols; ++
$c) {
133 echo " <td class='detotal' align='right'> " .
134 sprintf("%.2f", $ptrow['agedbal'][$c]) . " </td>\n";
138 echo " <td class='detotal' align='right'> " .
139 sprintf("%.2f", $pt_balance) . " </td>\n";
141 if ($form_cb_idays) echo " <td class='detail'> </td>\n";
142 echo " <td class='detail' colspan='2'> </td>\n";
143 if ($form_cb_err) echo " <td class='detail'> </td>\n";
147 $grand_total_charges +
= $ptrow['charges'];
148 $grand_total_adjustments +
= $ptrow['adjustments'];
149 $grand_total_paid +
= $ptrow['paid'];
150 for ($c = 0; $c < $form_age_cols; ++
$c) {
151 $grand_total_agedbal[$c] +
= $ptrow['agedbal'][$c];
155 // In the case of CSV export only, a download will be forced.
156 if ($_POST['form_csvexport']) {
157 header("Pragma: public");
158 header("Expires: 0");
159 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
160 header("Content-Type: application/force-download");
161 header("Content-Disposition: attachment; filename=collections_report.csv");
162 header("Content-Description: File Transfer");
168 <link rel
=stylesheet href
="<?echo $css_header;?>" type
="text/css">
169 <title
><?
xl('Collections Report','e')?
></title
>
170 <style type
="text/css">
171 body
{ font
-family
:sans
-serif
; font
-size
:10pt
; font
-weight
:normal
}
172 .dehead
{ color
:#000000; font-family:sans-serif; font-size:10pt; font-weight:bold }
173 .detail
{ color
:#000000; font-family:sans-serif; font-size:10pt; font-weight:normal }
174 .detotal
{ color
:#996600; font-family:sans-serif; font-size:10pt; font-weight:normal }
177 <script language
="JavaScript">
179 function checkAll(checked
) {
180 var f
= document
.forms
[0];
181 for (var i
= 0; i
< f
.elements
.length
; ++i
) {
182 var ename
= f
.elements
[i
].name
;
183 if (ename
.indexOf('form_cb[') == 0)
184 f
.elements
[i
].checked
= checked
;
192 <body leftmargin
='0' topmargin
='0' marginwidth
='0' marginheight
='0'>
195 <form method
='post' action
='collections_report.php' enctype
='multipart/form-data'>
197 <table border
='0' cellpadding
='5' cellspacing
='0' width
='98%'>
204 <tr bgcolor
='#ddddff'>
206 <input type
='checkbox' name
='form_cb_ssn'<?php
if ($form_cb_ssn) echo ' checked'; ?
>>
207 <?php
xl('SSN','e') ?
> 
;
208 <input type
='checkbox' name
='form_cb_dob'<?php
if ($form_cb_dob) echo ' checked'; ?
>>
209 <?php
xl('DOB','e') ?
> 
;
210 <input type
='checkbox' name
='form_cb_policy'<?php
if ($form_cb_policy) echo ' checked'; ?
>>
211 <?php
xl('Policy','e') ?
> 
;
212 <input type
='checkbox' name
='form_cb_phone'<?php
if ($form_cb_phone) echo ' checked'; ?
>>
213 <?php
xl('Phone','e') ?
> 
;
214 <input type
='checkbox' name
='form_cb_city'<?php
if ($form_cb_city) echo ' checked'; ?
>>
215 <?php
xl('City','e') ?
> 
;
216 <input type
='checkbox' name
='form_cb_ins1'<?php
if ($form_cb_ins1) echo ' checked'; ?
>>
217 <?php
xl('Primary Ins','e') ?
> 
;
218 <input type
='checkbox' name
='form_cb_referrer'<?php
if ($form_cb_referrer) echo ' checked'; ?
>>
219 <?php
xl('Referrer','e') ?
> 
;
220 <input type
='checkbox' name
='form_cb_idays'<?php
if ($form_cb_idays) echo ' checked'; ?
>>
221 <?php
xl('Inactive Days','e') ?
> 
;
222 <input type
='checkbox' name
='form_cb_err'<?php
if ($form_cb_err) echo ' checked'; ?
>>
223 <?php
xl('Errors','e') ?
>
227 <tr bgcolor
='#ddddff'>
229 <?php
xl('Age Cols:','e') ?
>
230 <input type
='text' name
='form_age_cols' size
='2' value
='<?php echo $form_age_cols; ?>'>
232 <?php
xl('Age Increment:','e') ?
>
233 <input type
='text' name
='form_age_inc' size
='3' value
='<?php echo $form_age_inc; ?>'>
235 <?
xl('Svc Date:','e')?
>
236 <input type
='text' name
='form_date' size
='10' value
='<?php echo $_POST['form_date
']; ?>'
237 title
='<?xl("Date of service mm/dd/yyyy","e")?>'>
240 <input type
='text' name
='form_to_date' size
='10' value
='<?php echo $_POST['form_to_date
']; ?>'
241 title
='<?xl("Ending DOS mm/dd/yyyy if you wish to enter a range","e")?>'>
243 <select name
='form_category'>
245 foreach (array(xl('Open'), xl('Due Pt'), xl('Due Ins'), xl('Credits'), xl('All')) as $value) {
246 echo " <option value='$value'";
247 if ($_POST['form_category'] == $value) echo " selected";
248 echo ">$value</option>\n";
253 <input type
='submit' name
='form_search' value
='<?xl("Search","e")?>'>
266 } // end not form_csvexport
268 if ($_POST['form_search'] ||
$_POST['form_export'] ||
$_POST['form_csvexport']) {
271 if ($_POST['form_export'] ||
$_POST['form_csvexport']) {
273 foreach ($_POST['form_cb'] as $key => $value) $where .= " OR ar.customer_id = $key";
278 if ($where) $where .= " AND ";
279 $date1 = substr($form_date, 0, 4) . substr($form_date, 5, 2) .
280 substr($form_date, 8, 2);
282 $date2 = substr($form_to_date, 0, 4) . substr($form_to_date, 5, 2) .
283 substr($form_to_date, 8, 2);
284 $where .= "((CAST (substring(ar.invnumber from position('.' in ar.invnumber) + 1 for 8) AS integer) " .
285 "BETWEEN '$date1' AND '$date2')";
286 $tmp = "date >= '$form_date' AND date <= '$form_to_date'";
289 // This catches old converted invoices where we have no encounters:
290 $where .= "(ar.invnumber LIKE '%.$date1'";
291 $tmp = "date = '$form_date'";
293 // Pick out the encounters from MySQL with the desired DOS:
294 $rez = sqlStatement("SELECT pid, encounter FROM form_encounter WHERE $tmp");
295 while ($row = sqlFetchArray($rez)) {
296 $where .= " OR ar.invnumber = '" . $row['pid'] . "." . $row['encounter'] . "'";
305 // TBD: Instead of the subselects in the following query, we will call
306 // get_invoice_summary() in order to get data at the procedure level and
307 // thus decide if insurance appears to be done with each invoice.
309 $query = "SELECT ar.id, ar.invnumber, ar.duedate, ar.amount, ar.paid, " .
310 "ar.intnotes, ar.notes, ar.shipvia, " .
311 "customer.id AS custid, customer.name, customer.address1, " .
312 "customer.city, customer.state, customer.zipcode, customer.phone " .
313 // ", (SELECT SUM(invoice.fxsellprice) FROM invoice WHERE " .
314 // "invoice.trans_id = ar.id AND invoice.fxsellprice > 0) AS charges, " .
315 // "(SELECT SUM(invoice.fxsellprice) FROM invoice WHERE " .
316 // "invoice.trans_id = ar.id AND invoice.fxsellprice < 0) AS adjustments " .
317 "FROM ar JOIN customer ON customer.id = ar.customer_id " .
319 if ($_POST['form_search'] && ! $is_all) {
320 $query .= "AND ar.amount != ar.paid ";
322 $query .= "ORDER BY ar.invnumber";
324 // echo "<!-- $query -->\n"; // debugging
326 $t_res = SLQuery($query);
327 if ($sl_err) die($sl_err);
328 $num_invoices = SLRowCount($t_res);
330 //////////////////////////////////////////////////////////////////
333 for ($irow = 0; $irow < $num_invoices; ++
$irow) {
334 $row = SLGetRow($t_res, $irow);
335 $pt_balance = sprintf("%.2f",$row['amount']) - sprintf("%.2f",$row['paid']);
337 if ($_POST['form_category'] == 'Credits') {
338 if ($pt_balance > 0) continue;
341 // $duncount was originally supposed to be the number of times that
342 // the patient was sent a statement for this invoice.
344 $duncount = substr_count(strtolower($row['intnotes']), "statement sent");
346 // But if we have not yet billed the patient, then compute $duncount as a
347 // negative count of the number of insurance plans for which we have not
348 // yet closed out insurance. Here we also compute $insname as the name of
349 // the insurance plan from which we are awaiting payment, and its sequence
350 // number $insposition (1-3).
354 $inseobs = strtolower($row['shipvia']);
355 $insgot = strtolower($row['notes']);
357 foreach (array('ins1', 'ins2', 'ins3') as $value) {
358 $i = strpos($insgot, $value);
359 if ($i !== false && strpos($inseobs, $value) === false) {
361 if (!$insname && $is_due_ins) {
362 $j = strpos($insgot, "\n", $i);
363 if (!$j) $j = strlen($insgot);
364 $insname = trim(substr($row['notes'], $i +
5, $j - $i - 5));
365 $insposition = substr($value, 3); // 1, 2 or 3
371 // Also get the primary insurance company name whenever there is one.
373 $i = strpos($insgot, 'ins1');
375 $j = strpos($insgot, "\n", $i);
376 if (!$j) $j = strlen($insgot);
377 $row['ins1'] = trim(substr($row['notes'], $i +
5, $j - $i - 5));
380 // An invoice is now due from the patient if money is owed and we are
381 // not waiting for insurance to pay. We no longer look at the due date
384 $isduept = ($duncount >= 0) ?
" checked" : "";
386 // Skip invoices not in the desired "Due..." category.
388 if ($is_due_ins && $duncount >= 0) continue;
389 if ($is_due_pt && $duncount < 0) continue;
391 $row['duncount'] = $duncount;
393 // Determine the date of service. An 8-digit encounter number is
394 // presumed to be a date of service imported during conversion.
395 // Otherwise look it up in the form_encounter table.
398 list($pid, $encounter) = explode(".", $row['invnumber']);
399 if (strlen($encounter) == 8) {
400 $svcdate = substr($encounter, 0, 4) . "-" . substr($encounter, 4, 2) .
401 "-" . substr($encounter, 6, 2);
403 else if ($encounter) {
404 $tmp = sqlQuery("SELECT date FROM form_encounter WHERE " .
405 "encounter = $encounter");
406 $svcdate = substr($tmp['date'], 0, 10);
409 $row['dos'] = $svcdate;
411 // This computes the invoice's total original charges and adjustments,
412 // date of last activity, and determines if insurance has responded to
413 // all billing items.
415 $invlines = get_invoice_summary($row['id'], true);
417 $row['adjustments'] = 0;
418 $ins_seems_done = true;
420 // echo "\n<!-- $ladate * -->\n"; // debugging
421 foreach ($invlines as $key => $value) {
422 $row['charges'] +
= $value['chg'] +
$value['adj'];
423 $row['adjustments'] +
= 0 - $value['adj'];
424 foreach ($value['dtl'] as $dkey => $dvalue) {
425 $dtldate = trim(substr($dkey, 0, 10));
426 // echo "\n<!-- $dtldate -->\n"; // debugging
427 if ($dtldate && $dtldate > $ladate) $ladate = $dtldate;
429 $lckey = strtolower($key);
430 if ($lckey == 'co-pay' ||
$lckey == 'claim') continue;
431 if (count($value['dtl']) <= 1) $ins_seems_done = false;
433 $row['billing_errmsg'] = '';
434 if ($is_due_ins && strpos($inseobs, 'ins1') === false && $ins_seems_done)
435 $row['billing_errmsg'] = 'Ins1 seems done';
436 else if (strpos($inseobs, 'ins1') !== false && !$ins_seems_done)
437 $row['billing_errmsg'] = 'Ins1 seems not done';
439 // Compute number of days since last activity.
440 $latime = mktime(0, 0, 0, substr($ladate, 5, 2),
441 substr($ladate, 8, 2), substr($ladate, 0, 4));
442 $row['inactive_days'] = floor((time() - $latime) / (60 * 60 * 24));
444 $pdrow = sqlQuery("SELECT pd.fname, pd.lname, pd.mname, pd.ss, " .
445 "pd.genericname2, pd.genericval2, pd.pid, pd.DOB, " .
446 "CONCAT(u.lname, ', ', u.fname) AS referrer FROM " .
447 "integration_mapping AS im, patient_data AS pd " .
448 "LEFT OUTER JOIN users AS u ON u.id = pd.providerID " .
449 "WHERE im.foreign_id = " . $row['custid'] . " AND " .
450 "im.foreign_table = 'customer' AND " .
451 "pd.id = im.local_id");
453 $row['ss'] = $pdrow['ss'];
454 $row['DOB'] = $pdrow['DOB'];
455 $row['billnote'] = ($pdrow['genericname2'] == 'Billing') ?
$pdrow['genericval2'] : '';
456 $row['referrer'] = $pdrow['referrer'];
458 $ptname = $pdrow['lname'] . ", " . $pdrow['fname'];
459 if ($pdrow['mname']) $ptname .= " " . substr($pdrow['mname'], 0, 1);
461 // Look up insurance policy number if we need it.
462 if ($form_cb_policy ||
$_POST['form_csvexport']) {
463 $patient_id = $pdrow['pid'];
464 $instype = ($insposition == 2) ?
'secondary' : (($insposition == 3) ?
'tertiary' : 'primary');
465 $insrow = sqlQuery("SELECT policy_number FROM insurance_data WHERE " .
466 "pid = '$patient_id' AND type = '$instype' AND date <= '$svcdate' " .
467 "ORDER BY date DESC LIMIT 1");
468 $row['policy'] = $insrow['policy_number'];
471 // $rows[$ptname] = $row;
472 $rows[$insname . '|' . $ptname . '|' . $encounter] = $row;
477 if ($_POST['form_export']) {
478 echo "<textarea rows='35' cols='100' readonly>";
480 else if ($_POST['form_csvexport']) {
495 echo '"IDays"' . "\n";
501 <table border
='0' cellpadding
='1' cellspacing
='2' width
='98%'>
503 <tr bgcolor
="#dddddd">
504 <?php
if ($is_due_ins) { ?
>
505 <td
class="dehead"> 
;<?php
xl('Insurance','e')?
></td
>
507 <td
class="dehead"> 
;<?php
xl('Name','e')?
></td
>
508 <?php
if ($form_cb_ssn) { ?
>
509 <td
class="dehead"> 
;<?php
xl('SSN','e')?
></td
>
511 <?php
if ($form_cb_dob) { ?
>
512 <td
class="dehead"> 
;<?php
xl('DOB','e')?
></td
>
514 <?php
if ($form_cb_policy) { ?
>
515 <td
class="dehead"> 
;<?php
xl('Policy','e')?
></td
>
517 <?php
if ($form_cb_phone) { ?
>
518 <td
class="dehead"> 
;<?php
xl('Phone','e')?
></td
>
520 <?php
if ($form_cb_city) { ?
>
521 <td
class="dehead"> 
;<?php
xl('City','e')?
></td
>
523 <?php
if ($form_cb_ins1) { ?
>
524 <td
class="dehead"> 
;<?php
xl('Primary Ins','e')?
></td
>
526 <?php
if ($form_cb_referrer) { ?
>
527 <td
class="dehead"> 
;<?php
xl('Referrer','e')?
></td
>
529 <td
class="dehead"> 
;<?php
xl('Invoice','e') ?
></td
>
530 <td
class="dehead"> 
;<?php
xl('Svc Date','e') ?
></td
>
531 <td
class="dehead" align
="right"><?php
xl('Charge','e') ?
> 
;</td
>
532 <td
class="dehead" align
="right"><?php
xl('Adjust','e') ?
> 
;</td
>
533 <td
class="dehead" align
="right"><?php
xl('Paid','e') ?
> 
;</td
>
535 // Generate aging headers if appropriate, else balance header.
536 if ($form_age_cols) {
537 for ($c = 0; $c < $form_age_cols;) {
538 echo " <td class='dehead' align='right'>";
539 echo $form_age_inc * $c;
540 if (++
$c < $form_age_cols) {
541 echo "-" . ($form_age_inc * $c - 1);
550 <td
class="dehead" align
="right"><?php
xl('Balance','e') ?
> 
;</td
>
554 <?php
if ($form_cb_idays) { ?
>
555 <td
class="dehead" align
="right"><?php
xl('IDays','e')?
> 
;</td
>
557 <td
class="dehead" align
="center"><?php
xl('Prv','e') ?
></td
>
558 <td
class="dehead" align
="center"><?php
xl('Sel','e') ?
></td
>
559 <?php
if ($form_cb_err) { ?
>
560 <td
class="dehead"> 
;<?php
xl('Error','e')?
></td
>
567 $ptrow = array('insname' => '', 'pid' => 0);
570 foreach ($rows as $key => $row) {
571 list($insname, $ptname, $trash) = explode('|', $key);
572 list($pid, $encounter) = explode(".", $row['invnumber']);
574 if ($insname != $ptrow['insname'] ||
$pid != $ptrow['pid']) {
575 // For the report, this will write the patient totals. For the
576 // collections export this writes everything for the patient:
578 $bgcolor = ((++
$orow & 1) ?
"#ffdddd" : "#ddddff");
579 $ptrow = array('insname' => $insname, 'ptname' => $ptname, 'pid' => $pid, 'count' => 1);
580 foreach ($row as $key => $value) $ptrow[$key] = $value;
581 $ptrow['agedbal'] = array();
583 $ptrow['amount'] +
= $row['amount'];
584 $ptrow['paid'] +
= $row['paid'];
585 $ptrow['charges'] +
= $row['charges'];
586 $ptrow['adjustments'] +
= $row['adjustments'];
590 if (!$_POST['form_export'] && !$_POST['form_csvexport']) {
591 $in_collections = stristr($row['billnote'], 'IN COLLECTIONS') !== false;
593 <tr bgcolor
='<?php echo $bgcolor ?>'>
595 if ($ptrow['count'] == 1) {
597 echo " <td class='detail'> $insname</td>\n";
599 echo " <td class='detail'> $ptname</td>\n";
601 echo " <td class='detail'> " . $row['ss'] . "</td>\n";
604 echo " <td class='detail'> " . $row['DOB'] . "</td>\n";
606 if ($form_cb_policy) {
607 echo " <td class='detail'> " . $row['policy'] . "</td>\n";
609 if ($form_cb_phone) {
610 echo " <td class='detail'> " . $row['phone'] . "</td>\n";
613 echo " <td class='detail'> " . $row['city'] . "</td>\n";
616 echo " <td class='detail'> " . $row['ins1'] . "</td>\n";
618 if ($form_cb_referrer) {
619 echo " <td class='detail'> " . $row['referrer'] . "</td>\n";
622 echo " <td class='detail' colspan='$initial_colspan'>";
623 echo " </td>\n";
627  
;<a href
="../billing/sl_eob_invoice.php?id=<?php echo $row['id'] ?>"
628 target
="_blank"><?php
echo $row['invnumber'] ?
></a
>
631  
;<?php
echo $row['dos']; ?
>
633 <td
class="detail" align
="right">
634 <?php
bucks($row['charges']) ?
> 
;
636 <td
class="detail" align
="right">
637 <?php
bucks($row['adjustments']) ?
> 
;
639 <td
class="detail" align
="right">
640 <?php
bucks($row['paid']) ?
> 
;
644 $balance = $row['charges'] +
$row['adjustments'] - $row['paid'];
645 if ($form_age_cols) {
646 $dostime = mktime(0, 0, 0, substr($row['dos'], 5, 2),
647 substr($row['dos'], 8, 2), substr($row['dos'], 0, 4));
648 $days = floor((time() - $dostime) / (60 * 60 * 24));
649 $colno = min($form_age_cols - 1, max(0, floor($days / $form_age_inc)));
650 $ptrow['agedbal'][$colno] +
= $balance;
651 for ($c = 0; $c < $form_age_cols; ++
$c) {
652 echo " <td class='detail' align='right'>";
656 echo " </td>\n";
661 <td
class="detail" align
="right"><?php
bucks($balance) ?
> 
;</td
>
666 if ($form_cb_idays) {
667 echo " <td class='detail' align='right'>";
668 echo $row['inactive_days'] . " </td>\n";
671 <td
class="detail" align
="center">
672 <?php
echo $row['duncount'] ?
$row['duncount'] : " " ?
>
674 <td
class="detail" align
="center">
676 if ($ptrow['count'] == 1) {
677 if ($in_collections) {
678 echo " <b><font color='red'>IC</font></b>\n";
680 echo " <input type='checkbox' name='form_cb[" . $row['custid'] . "]' />\n";
689 echo " <td class='detail'> ";
690 echo $row['billing_errmsg'] . "</td>\n";
697 else if ($_POST['form_csvexport']) {
698 // The CSV detail line is written here.
699 $balance = $row['charges'] +
$row['adjustments'] - $row['paid'];
700 // echo '"' . $insname . '",';
701 echo '"' . $row['ins1'] . '",';
702 echo '"' . $ptname . '",';
703 echo '"' . $row['DOB'] . '",';
704 echo '"' . $row['ss'] . '",';
705 echo '"' . $row['policy'] . '",';
706 echo '"' . $row['invnumber'] . '",';
707 echo '"' . $row['dos'] . '",';
708 echo '"' . $row['referrer'] . '",';
709 echo '"' . sprintf('%.2f', $row['charges']) . '",';
710 echo '"' . sprintf('%.2f', $row['adjustments']) . '",';
711 echo '"' . sprintf('%.2f', $row['paid']) . '",';
712 echo '"' . sprintf('%.2f', $balance) . '",';
713 echo '"' . $row['inactive_days'] . '"' . "\n";
714 } // end $form_csvexport
720 if ($_POST['form_export']) {
721 echo "</textarea>\n";
722 $alertmsg .= "$export_patient_count patients representing $" .
723 sprintf("%.2f", $export_dollars) . " have been exported ";
724 if ($_POST['form_without']) {
725 $alertmsg .= "but NOT flagged as in collections.";
727 $alertmsg .= "AND flagged as in collections.";
730 else if ($_POST['form_csvexport']) {
731 // echo "</textarea>\n";
732 // $alertmsg .= "$export_patient_count patients representing $" .
733 // sprintf("%.2f", $export_dollars) . " have been exported.";
736 echo " <tr bgcolor='#ffffff'>\n";
737 echo " <td class='detail' colspan='$initial_colspan'>\n";
738 echo " </td>\n";
739 echo " <td class='dehead' colspan='2'> Report Totals:</td>\n";
740 echo " <td class='dehead' align='right'> " .
741 sprintf("%.2f", $grand_total_charges) . " </td>\n";
742 echo " <td class='dehead' align='right'> " .
743 sprintf("%.2f", $grand_total_adjustments) . " </td>\n";
744 echo " <td class='dehead' align='right'> " .
745 sprintf("%.2f", $grand_total_paid) . " </td>\n";
746 if ($form_age_cols) {
747 for ($c = 0; $c < $form_age_cols; ++
$c) {
748 echo " <td class='dehead' align='right'>" .
749 sprintf("%.2f", $grand_total_agedbal[$c]) . " </td>\n";
753 echo " <td class='dehead' align='right'>" .
754 sprintf("%.2f", $grand_total_charges +
755 $grand_total_adjustments - $grand_total_paid) . " </td>\n";
757 if ($form_cb_idays) echo " <td class='detail'> </td>\n";
758 echo " <td class='detail' colspan='2'> </td>\n";
760 if ($form_cb_err) echo " <td class='detail'> </td>\n";
763 } // end if form_search
766 if (!$_POST['form_csvexport']) {
767 if (!$_POST['form_export']) {
770 <input type
='button' value
='Select All' onclick
='checkAll(true)' />  
;
771 <input type
='button' value
='Clear All' onclick
='checkAll(false)' />  
;
772 <input type
='submit' name
='form_csvexport' value
='Export Selected as CSV' />  
;  
;
773 <input type
='submit' name
='form_export' value
='Export Selected to Collections' />  
;
774 <input type
='checkbox' name
='form_without' value
='1' /> <?php
xl('Without Update','e') ?
>
781 <script language
="JavaScript">
784 echo "alert('" . htmlentities($alertmsg) . "');\n";
791 } // end not form_csvexport