Feature to add drug-drug interaction checking for the
[openemr.git] / interface / billing / sl_eob_search.php
blobc212d4689b7c00a84c1d79bd359dfb6428800506
1 <?php
2 /**
3 * This the first of two pages to support posting of EOBs.
4 * The second is sl_eob_invoice.php.
5 * Windows compatibility and statement downloading:
6 * 2009 Bill Cernansky and Tony McCormick [mi-squared.com]
8 * Copyright (C) 2005-2010 Rod Roark <rod@sunsetsystems.com>
10 * LICENSE: This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
21 * @package OpenEMR
22 * @author Rod Roark <rod@sunsetsystems.com>
23 * @author Roberto Vasquez <robertogagliotta@gmail.com>
24 * @link http://www.open-emr.org
27 require_once("../globals.php");
28 require_once("$srcdir/patient.inc");
29 require_once("$srcdir/invoice_summary.inc.php");
30 require_once("$srcdir/appointments.inc.php");
31 require_once($GLOBALS['OE_SITE_DIR'] . "/statement.inc.php");
32 require_once("$srcdir/parse_era.inc.php");
33 require_once("$srcdir/sl_eob.inc.php");
34 require_once("$srcdir/formatting.inc.php");
36 $DEBUG = 0; // set to 0 for production, 1 to test
39 $alertmsg = '';
40 $where = '';
41 $eraname = '';
42 $eracount = 0;
44 // This is called back by parse_era() if we are processing X12 835's.
46 function era_callback(&$out) {
47 global $where, $eracount, $eraname;
48 // print_r($out); // debugging
49 ++$eracount;
50 // $eraname = $out['isa_control_number'];
51 $eraname = $out['gs_date'] . '_' . ltrim($out['isa_control_number'], '0') .
52 '_' . ltrim($out['payer_id'], '0');
53 list($pid, $encounter, $invnumber) = slInvoiceNumber($out);
55 if ($pid && $encounter) {
56 if ($where) $where .= ' OR ';
57 $where .= "( f.pid = '$pid' AND f.encounter = '$encounter' )";
61 function bucks($amount) {
62 if ($amount) echo oeFormatMoney($amount);
65 // Upload a file to the client's browser
67 function upload_file_to_client($file_to_send) {
68 header("Pragma: public");
69 header("Expires: 0");
70 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
71 header("Content-Type: application/force-download");
72 header("Content-Length: " . filesize($file_to_send));
73 header("Content-Disposition: attachment; filename=" . basename($file_to_send));
74 header("Content-Description: File Transfer");
75 readfile($file_to_send);
76 // flush the content to the browser. If you don't do this, the text from the subsequent
77 // output from this script will be in the file instead of sent to the browser.
78 flush();
79 exit(); //added to exit from process properly in order to stop bad html code -ehrlive
80 // sleep one second to ensure there's no follow-on.
81 sleep(1);
83 function upload_file_to_client_pdf($file_to_send) {
84 //Function reads a text file and converts to pdf.
86 global $STMT_TEMP_FILE_PDF;
87 $pdf = new Cezpdf('LETTER');//pdf creation starts
88 $pdf->ezSetMargins(36,0,36,0);
89 $pdf->selectFont('Courier');
90 $pdf->ezSetY($pdf->ez['pageHeight'] - $pdf->ez['topMargin']);
91 $countline=1;
92 $file = fopen($file_to_send, "r");//this file contains the text to be converted to pdf.
93 while(!feof($file))
95 $OneLine=fgets($file);//one line is read
96 if(stristr($OneLine, "\014") == true && !feof($file))//form feed means we should start a new page.
98 $pdf->ezNewPage();
99 $pdf->ezSetY($pdf->ez['pageHeight'] - $pdf->ez['topMargin']);
100 str_replace("\014", "", $OneLine);
103 if(stristr($OneLine, 'REMIT TO') == true || stristr($OneLine, 'Visit Date') == true || stristr($OneLine, 'Future Appointments') == true || stristr($OneLine, 'Current') == true)//lines are made bold when 'REMIT TO' or 'Visit Date' is there.
104 $pdf->ezText('<b>'.$OneLine.'</b>', 12, array('justification' => 'left', 'leading' => 6));
105 else
106 $pdf->ezText($OneLine, 12, array('justification' => 'left', 'leading' => 6));
108 $countline++;
111 $fh = @fopen($STMT_TEMP_FILE_PDF, 'w');//stored to a pdf file
112 if ($fh) {
113 fwrite($fh, $pdf->ezOutput());
114 fclose($fh);
116 header("Pragma: public");//this section outputs the pdf file to browser
117 header("Expires: 0");
118 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
119 header("Content-Type: application/force-download");
120 header("Content-Length: " . filesize($STMT_TEMP_FILE_PDF));
121 header("Content-Disposition: attachment; filename=" . basename($STMT_TEMP_FILE_PDF));
122 header("Content-Description: File Transfer");
123 readfile($STMT_TEMP_FILE_PDF);
124 // flush the content to the browser. If you don't do this, the text from the subsequent
125 // output from this script will be in the file instead of sent to the browser.
126 flush();
127 exit(); //added to exit from process properly in order to stop bad html code -ehrlive
128 // sleep one second to ensure there's no follow-on.
129 sleep(1);
133 $today = date("Y-m-d");
136 // Print or download statements if requested.
138 if (($_POST['form_print'] || $_POST['form_download'] || $_POST['form_pdf']) && $_POST['form_cb']) {
140 $fhprint = fopen($STMT_TEMP_FILE, 'w');
141 $sqlBindArray = array();
142 $where = "";
143 foreach ($_POST['form_cb'] as $key => $value) {
144 $where .= " OR f.id = ?";
145 array_push($sqlBindArray, $key);
147 $where = substr($where, 4);
149 $res = sqlStatement("SELECT " .
150 "f.id, f.date, f.pid, f.encounter, f.stmt_count, f.last_stmt_date, f.last_level_closed, f.last_level_billed, f.billing_note as enc_billing_note, " .
151 "p.fname, p.mname, p.lname, p.street, p.city, p.state, p.postal_code, p.billing_note as pat_billing_note " .
152 "FROM form_encounter AS f, patient_data AS p " .
153 "WHERE ( $where ) AND " .
154 "p.pid = f.pid " .
155 "ORDER BY p.lname, p.fname, f.pid, f.date, f.encounter", $sqlBindArray);
157 $stmt = array();
158 $stmt_count = 0;
160 // This loops once for each invoice/encounter.
162 while ($row = sqlFetchArray($res)) {
163 $svcdate = substr($row['date'], 0, 10);
164 $duedate = $svcdate; // TBD?
165 $duncount = $row['stmt_count'];
166 $enc_note = $row['enc_billing_note'];
168 // If this is a new patient then print the pending statement
169 // and start a new one. This is an associative array:
171 // cid = same as pid
172 // pid = OpenEMR patient ID
173 // patient = patient name
174 // amount = total amount due
175 // adjust = adjustments (already applied to amount)
176 // duedate = due date of the oldest included invoice
177 // age = number of days from duedate to today
178 // to = array of addressee name/address lines
179 // lines = array of:
180 // dos = date of service "yyyy-mm-dd"
181 // desc = description
182 // amount = charge less adjustments
183 // paid = amount paid
184 // notice = 1 for first notice, 2 for second, etc.
185 // detail = array of details, see invoice_summary.inc.php
187 if ($stmt['cid'] != $row['pid']) {
188 if (!empty($stmt)) ++$stmt_count;
189 fwrite($fhprint, create_statement($stmt));
190 $stmt['cid'] = $row['pid'];
191 $stmt['pid'] = $row['pid'];
192 $stmt['dun_count'] = $row['stmt_count'];
193 $stmt['bill_note'] = $row['pat_billing_note'];
194 $stmt['enc_bill_note'] = $row['enc_billing_note'];
195 $stmt['bill_level'] = $row['last_level_billed'];
196 $stmt['level_closed'] = $row['last_level_closed'];
197 $stmt['patient'] = $row['fname'] . ' ' . $row['lname'];
198 #If you use the field in demographics layout called
199 #guardiansname this will allow you to send statements to the parent
200 #of a child or a guardian etc
201 if(strlen($row['guardiansname']) == 0) {
202 $stmt['to'] = array($row['fname'] . ' ' . $row['lname']);
204 else
206 $stmt['to'] = array($row['guardiansname']);
208 if ($row['street']) $stmt['to'][] = $row['street'];
209 $stmt['to'][] = $row['city'] . ", " . $row['state'] . " " . $row['postal_code'];
210 $stmt['lines'] = array();
211 $stmt['amount'] = '0.00';
212 $stmt['ins_paid'] = 0;
213 $stmt['today'] = $today;
214 $stmt['duedate'] = $duedate;
215 } else {
216 // Report the oldest due date.
217 if ($duedate < $stmt['duedate']) {
218 $stmt['duedate'] = $duedate;
222 // Recompute age at each invoice.
223 $stmt['age'] = round((strtotime($today) - strtotime($stmt['duedate'])) /
224 (24 * 60 * 60));
226 $invlines = ar_get_invoice_summary($row['pid'], $row['encounter'], true);
227 foreach ($invlines as $key => $value) {
228 $line = array();
229 $line['dos'] = $svcdate;
230 if ($GLOBALS['use_custom_statement']) {
231 $line['desc'] = ($key == 'CO-PAY') ? "Patient Payment" : $value['code_text'];
233 else
235 $line['desc'] = ($key == 'CO-PAY') ? "Patient Payment" : "Procedure $key";
237 $line['amount'] = sprintf("%.2f", $value['chg']);
238 $line['adjust'] = sprintf("%.2f", $value['adj']);
239 $line['paid'] = sprintf("%.2f", $value['chg'] - $value['bal']);
240 $line['notice'] = $duncount + 1;
241 $line['detail'] = $value['dtl'];
242 $stmt['lines'][] = $line;
243 $stmt['amount'] = sprintf("%.2f", $stmt['amount'] + $value['bal']);
244 $stmt['ins_paid'] = $stmt['ins_paid'] + $value['ins'];
247 // Record that this statement was run.
248 if (! $DEBUG && ! $_POST['form_without']) {
249 sqlStatement("UPDATE form_encounter SET " .
250 "last_stmt_date = '$today', stmt_count = stmt_count + 1 " .
251 "WHERE id = " . $row['id']);
253 } // end for
255 if (!empty($stmt)) ++$stmt_count;
256 fwrite($fhprint, create_statement($stmt));
257 fclose($fhprint);
258 sleep(1);
260 // Download or print the file, as selected
261 if ($_POST['form_download']) {
262 upload_file_to_client($STMT_TEMP_FILE);
263 } elseif ($_POST['form_pdf']) {
264 upload_file_to_client_pdf($STMT_TEMP_FILE);
265 } else { // Must be print!
266 if ($DEBUG) {
267 $alertmsg = xl("Printing skipped; see test output in") .' '. $STMT_TEMP_FILE;
268 } else {
269 exec("$STMT_PRINT_CMD $STMT_TEMP_FILE");
270 if ($_POST['form_without']) {
271 $alertmsg = xl('Now printing') .' '. $stmt_count .' '. xl('statements; invoices will not be updated.');
272 } else {
273 $alertmsg = xl('Now printing') .' '. $stmt_count .' '. xl('statements and updating invoices.');
275 } // end not debug
276 } // end not form_download
277 } // end statements requested
279 <html>
280 <head>
281 <?php html_header_show(); ?>
282 <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
283 <title><?php xl('EOB Posting - Search','e'); ?></title>
284 <script type="text/javascript" src="../../library/textformat.js"></script>
286 <script language="JavaScript">
288 var mypcc = '1';
290 function checkAll(checked) {
291 var f = document.forms[0];
292 for (var i = 0; i < f.elements.length; ++i) {
293 var ename = f.elements[i].name;
294 if (ename.indexOf('form_cb[') == 0)
295 f.elements[i].checked = checked;
299 function npopup(pid) {
300 window.open('sl_eob_patient_note.php?patient_id=' + pid, '_blank', 'width=500,height=250,resizable=1');
301 return false;
304 </script>
306 </head>
308 <body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>
309 <center>
311 <form method='post' action='sl_eob_search.php' enctype='multipart/form-data'>
313 <table border='0' cellpadding='5' cellspacing='0'>
314 <tr>
316 <?php
317 // Identify the payer to support resumable posting sessions.
318 echo " <td>\n";
319 echo " " . xl('Payer') . ":\n";
320 echo " </td>\n";
321 echo " <td>\n";
322 $insurancei = getInsuranceProviders();
323 echo " <select name='form_payer_id'>\n";
324 echo " <option value='0'>-- " . xl('Patient') . " --</option>\n";
325 foreach ($insurancei as $iid => $iname) {
326 echo "<option value='$iid'";
327 if ($iid == $_POST['form_payer_id']) echo " selected";
328 echo ">" . $iname . "</option>\n";
330 echo " </select>\n";
331 echo " </td>\n";
334 <td>
335 <?php xl('Source:','e'); ?>
336 </td>
337 <td>
338 <input type='text' name='form_source' size='10' value='<?php echo $_POST['form_source']; ?>'
339 title='<?php xl("A check number or claim number to identify the payment","e"); ?>'>
340 </td>
341 <td>
342 <?php xl('Pay Date:','e'); ?>
343 </td>
344 <td>
345 <input type='text' name='form_paydate' size='10' value='<?php echo $_POST['form_paydate']; ?>'
346 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)'
347 title='<?php xl("Date of payment yyyy-mm-dd","e"); ?>'>
348 </td>
350 <td>
351 <?php xl('Deposit Date:','e'); ?>
352 </td>
353 <td>
354 <input type='text' name='form_deposit_date' size='10' value='<?php echo $_POST['form_deposit_date']; ?>'
355 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)'
356 title='<?php xl("Date of bank deposit yyyy-mm-dd","e"); ?>'>
357 </td>
359 <td>
360 <?php xl('Amount:','e'); ?>
361 </td>
362 <td>
363 <input type='text' name='form_amount' size='10' value='<?php echo $_POST['form_amount']; ?>'
364 title='<?php xl("Paid amount that you will allocate","e"); ?>'>
365 </td>
366 <td align='right'>
367 <a href='sl_eob_help.php' target='_blank'><?php xl('Help','e'); ?></a>
368 </td>
370 </tr>
371 </table>
373 <table border='0' cellpadding='5' cellspacing='0'>
375 <tr bgcolor='#ddddff'>
376 <td>
377 <?php xl('Name:','e'); ?>
378 </td>
379 <td>
380 <input type='text' name='form_name' size='10' value='<?php echo $_POST['form_name']; ?>'
381 title='<?php xl("Any part of the patient name, or \"last,first\", or \"X-Y\"","e"); ?>'>
382 </td>
383 <td>
384 <?php xl('Chart ID:','e'); ?>
385 </td>
386 <td>
387 <input type='text' name='form_pid' size='10' value='<?php echo $_POST['form_pid']; ?>'
388 title='<?php xl("Patient chart ID","e"); ?>'>
389 </td>
390 <td>
391 <?php xl('Encounter:','e'); ?>
392 </td>
393 <td>
394 <input type='text' name='form_encounter' size='10' value='<?php echo $_POST['form_encounter']; ?>'
395 title='<?php xl("Encounter number","e"); ?>'>
396 </td>
397 <td>
398 <?php xl('Svc Date:','e'); ?>
399 </td>
400 <td>
401 <input type='text' name='form_date' size='10' value='<?php echo $_POST['form_date']; ?>'
402 title='<?php xl("Date of service mm/dd/yyyy","e"); ?>'>
403 </td>
404 <td>
405 <?php xl('To:','e'); ?>
406 </td>
407 <td>
408 <input type='text' name='form_to_date' size='10' value='<?php echo $_POST['form_to_date']; ?>'
409 title='<?php xl("Ending DOS mm/dd/yyyy if you wish to enter a range","e"); ?>'>
410 </td>
411 <td>
412 <select name='form_category'>
413 <?php
414 foreach (array(xl('Open'), xl('All'), xl('Due Pt'), xl('Due Ins')) as $value) {
415 echo " <option value='$value'";
416 if ($_POST['form_category'] == $value) echo " selected";
417 echo ">$value</option>\n";
420 </select>
421 </td>
422 <td>
423 <input type='submit' name='form_search' value='<?php xl("Search","e"); ?>'>
424 </td>
425 </tr>
427 <!-- Support for X12 835 upload -->
428 <tr bgcolor='#ddddff'>
429 <td colspan='12'>
430 <?php xl('Or upload ERA file:','e'); ?>
431 <input type="hidden" name="MAX_FILE_SIZE" value="5000000" />
432 <input name="form_erafile" type="file" />
433 </td>
434 </tr>
436 <tr>
437 <td height="1" colspan="10">
438 </td>
439 </tr>
441 </table>
443 <?php
444 if ($_POST['form_search'] || $_POST['form_print']) {
445 $form_name = trim($_POST['form_name']);
446 $form_pid = trim($_POST['form_pid']);
447 $form_encounter = trim($_POST['form_encounter']);
448 $form_date = fixDate($_POST['form_date'], "");
449 $form_to_date = fixDate($_POST['form_to_date'], "");
451 $where = "";
453 // Handle X12 835 file upload.
455 if ($_FILES['form_erafile']['size']) {
456 $tmp_name = $_FILES['form_erafile']['tmp_name'];
458 // Handle .zip extension if present. Probably won't work on Windows.
459 if (strtolower(substr($_FILES['form_erafile']['name'], -4)) == '.zip') {
460 rename($tmp_name, "$tmp_name.zip");
461 exec("unzip -p $tmp_name.zip > $tmp_name");
462 unlink("$tmp_name.zip");
465 echo "<!-- Notes from ERA upload processing:\n";
466 $alertmsg .= parse_era($tmp_name, 'era_callback');
467 echo "-->\n";
468 $erafullname = $GLOBALS['OE_SITE_DIR'] . "/era/$eraname.edi";
470 if (is_file($erafullname)) {
471 $alertmsg .= "Warning: Set $eraname was already uploaded ";
472 if (is_file($GLOBALS['OE_SITE_DIR'] . "/era/$eraname.html"))
473 $alertmsg .= "and processed. ";
474 else
475 $alertmsg .= "but not yet processed. ";
477 rename($tmp_name, $erafullname);
478 } // End 835 upload
480 if ($eracount) {
481 // Note that parse_era() modified $eracount and $where.
482 if (! $where) $where = '1 = 2';
484 else {
485 if ($form_name) {
486 if ($where) $where .= " AND ";
487 // Allow the last name to be followed by a comma and some part of a first name.
488 if (preg_match('/^(.*\S)\s*,\s*(.*)/', $form_name, $matches)) {
489 $where .= "p.lname LIKE '" . $matches[1] . "%' AND p.fname LIKE '" . $matches[2] . "%'";
490 // Allow a filter like "A-C" on the first character of the last name.
491 } else if (preg_match('/^(\S)\s*-\s*(\S)$/', $form_name, $matches)) {
492 $tmp = '1 = 2';
493 while (ord($matches[1]) <= ord($matches[2])) {
494 $tmp .= " OR p.lname LIKE '" . $matches[1] . "%'";
495 $matches[1] = chr(ord($matches[1]) + 1);
497 $where .= "( $tmp ) ";
498 } else {
499 $where .= "p.lname LIKE '%$form_name%'";
502 if ($form_pid) {
503 if ($where) $where .= " AND ";
504 $where .= "f.pid = '$form_pid'";
506 if ($form_encounter) {
507 if ($where) $where .= " AND ";
508 $where .= "f.encounter = '$form_encounter'";
510 if ($form_date) {
511 if ($where) $where .= " AND ";
512 if ($form_to_date) {
513 $where .= "f.date >= '$form_date' AND f.date <= '$form_to_date'";
515 else {
516 $where .= "f.date = '$form_date'";
519 if (! $where) {
520 if ($_POST['form_category'] == 'All') {
521 die(xl("At least one search parameter is required if you select All."));
522 } else {
523 $where = "1 = 1";
528 // Notes that as of release 4.1.1 the copays are stored
529 // in the ar_activity table marked with a PCP in the account_code column.
530 $query = "SELECT f.id, f.pid, f.encounter, f.date, " .
531 "f.last_level_billed, f.last_level_closed, f.last_stmt_date, f.stmt_count, " .
532 "p.fname, p.mname, p.lname, p.pubpid, p.billing_note, " .
533 "( SELECT SUM(b.fee) FROM billing AS b WHERE " .
534 "b.pid = f.pid AND b.encounter = f.encounter AND " .
535 "b.activity = 1 AND b.code_type != 'COPAY' ) AS charges, " .
536 "( SELECT SUM(a.pay_amount) FROM ar_activity AS a WHERE " .
537 "a.pid = f.pid AND a.encounter = f.encounter AND a.payer_type = 0 AND a.account_code = 'PCP')*-1 AS copays, " .
538 "( SELECT SUM(a.pay_amount) FROM ar_activity AS a WHERE " .
539 "a.pid = f.pid AND a.encounter = f.encounter AND a.account_code != 'PCP') AS payments, " .
540 "( SELECT SUM(a.adj_amount) FROM ar_activity AS a WHERE " .
541 "a.pid = f.pid AND a.encounter = f.encounter ) AS adjustments " .
542 "FROM form_encounter AS f " .
543 "JOIN patient_data AS p ON p.pid = f.pid " .
544 "WHERE $where " .
545 "ORDER BY p.lname, p.fname, p.mname, f.pid, f.encounter";
547 // Note that unlike the SQL-Ledger case, this query does not weed
548 // out encounters that are paid up. Also the use of sub-selects
549 // will require MySQL 4.1 or greater.
551 // echo "<!-- $query -->\n"; // debugging
553 $t_res = sqlStatement($query);
555 $num_invoices = sqlNumRows($t_res);
556 if ($eracount && $num_invoices != $eracount) {
557 $alertmsg .= "Of $eracount remittances, there are $num_invoices " .
558 "matching encounters in OpenEMR. ";
562 <table border='0' cellpadding='1' cellspacing='2' width='98%'>
564 <tr bgcolor="#dddddd">
565 <td class="dehead">
566 &nbsp;<?php xl('Patient','e'); ?>
567 </td>
568 <td class="dehead">
569 &nbsp;<?php xl('Invoice','e'); ?>
570 </td>
571 <td class="dehead">
572 &nbsp;<?php xl('Svc Date','e'); ?>
573 </td>
574 <td class="dehead">
575 &nbsp;<?php xl('Last Stmt','e'); ?>
576 </td>
577 <td class="dehead" align="right">
578 <?php xl('Charge','e'); ?>&nbsp;
579 </td>
580 <td class="dehead" align="right">
581 <?php xl('Adjust','e'); ?>&nbsp;
582 </td>
583 <td class="dehead" align="right">
584 <?php xl('Paid','e'); ?>&nbsp;
585 </td>
586 <td class="dehead" align="right">
587 <?php xl('Balance','e'); ?>&nbsp;
588 </td>
589 <td class="dehead" align="center">
590 <?php xl('Prv','e'); ?>
591 </td>
592 <?php if (!$eracount) { ?>
593 <td class="dehead" align="left">
594 <?php xl('Sel','e'); ?>
595 </td>
596 <?php } ?>
597 </tr>
599 <?php
600 $orow = -1;
602 while ($row = sqlFetchArray($t_res)) {
603 $balance = sprintf("%.2f", $row['charges'] + $row['copays'] - $row['payments'] - $row['adjustments']);
605 if ($_POST['form_category'] != 'All' && $eracount == 0 && $balance == 0) continue;
607 // $duncount was originally supposed to be the number of times that
608 // the patient was sent a statement for this invoice.
610 $duncount = $row['stmt_count'];
612 // But if we have not yet billed the patient, then compute $duncount as a
613 // negative count of the number of insurance plans for which we have not
614 // yet closed out insurance.
616 if (! $duncount) {
617 for ($i = 1; $i <= 3 && arGetPayerID($row['pid'], $row['date'], $i); ++$i) ;
618 $duncount = $row['last_level_closed'] + 1 - $i;
621 $isdueany = ($balance > 0);
623 // An invoice is now due from the patient if money is owed and we are
624 // not waiting for insurance to pay.
626 $isduept = ($duncount >= 0 && $isdueany) ? " checked" : "";
628 // Skip invoices not in the desired "Due..." category.
630 if (substr($_POST['form_category'], 0, 3) == 'Due' && !$isdueany) continue;
631 if ($_POST['form_category'] == 'Due Ins' && ($duncount >= 0 || !$isdueany)) continue;
632 if ($_POST['form_category'] == 'Due Pt' && ($duncount < 0 || !$isdueany)) continue;
634 $bgcolor = ((++$orow & 1) ? "#ffdddd" : "#ddddff");
636 $svcdate = substr($row['date'], 0, 10);
637 $last_stmt_date = empty($row['last_stmt_date']) ? '' : $row['last_stmt_date'];
639 // Determine if customer is in collections.
641 $billnote = $row['billing_note'];
642 $in_collections = stristr($billnote, 'IN COLLECTIONS') !== false;
644 <tr bgcolor='<?php echo $bgcolor ?>'>
645 <td class="detail">
646 &nbsp;<a href="" onclick="return npopup(<?php echo $row['pid'] ?>)"
647 ><?php echo $row['lname'] . ', ' . $row['fname']; ?></a>
648 </td>
649 <td class="detail">
650 &nbsp;<a href="sl_eob_invoice.php?id=<?php echo $row['id'] ?>"
651 target="_blank"><?php echo $row['pid'] . '.' . $row['encounter']; ?></a>
652 </td>
653 <td class="detail">
654 &nbsp;<?php echo oeFormatShortDate($svcdate) ?>
655 </td>
656 <td class="detail">
657 &nbsp;<?php echo oeFormatShortDate($last_stmt_date) ?>
658 </td>
659 <td class="detail" align="right">
660 <?php bucks($row['charges']) ?>&nbsp;
661 </td>
662 <td class="detail" align="right">
663 <?php bucks($row['adjustments']) ?>&nbsp;
664 </td>
665 <td class="detail" align="right">
666 <?php bucks($row['payments'] - $row['copays']); ?>&nbsp;
667 </td>
668 <td class="detail" align="right">
669 <?php bucks($balance); ?>&nbsp;
670 </td>
671 <td class="detail" align="center">
672 <?php echo $duncount ? $duncount : "&nbsp;" ?>
673 </td>
674 <?php if (!$eracount) { ?>
675 <td class="detail" align="left">
676 <input type='checkbox' name='form_cb[<?php echo($row['id']) ?>]'<?php echo $isduept ?> />
677 <?php if ($in_collections) echo "<b><font color='red'>IC</font></b>"; ?>
678 </td>
679 <?php } ?>
680 </tr>
681 <?php
682 } // end while
683 } // end search/print logic
687 </table>
690 <?php if ($eracount) { ?>
691 <input type='button' value='<?php xl('Process ERA File','e')?>' onclick='processERA()' /> &nbsp;
692 <?php } else { ?>
693 <input type='button' value='<?php xl('Select All','e')?>' onclick='checkAll(true)' /> &nbsp;
694 <input type='button' value='<?php xl('Clear All','e')?>' onclick='checkAll(false)' /> &nbsp;
695 <input type='submit' name='form_print' value='<?php xl('Print Selected Statements','e'); ?>' /> &nbsp;
696 <input type='submit' name='form_download' value='<?php xl('Download Selected Statements','e'); ?>' /> &nbsp;
697 <input type='submit' name='form_pdf' value='<?php xl('PDF Download Selected Statements','e'); ?>' /> &nbsp;
698 <?php } ?>
699 <input type='checkbox' name='form_without' value='1' /> <?php xl('Without Update','e'); ?>
700 </p>
702 </form>
703 </center>
704 <script language="JavaScript">
705 function processERA() {
706 var f = document.forms[0];
707 var debug = f.form_without.checked ? '1' : '0';
708 var paydate = f.form_paydate.value;
709 window.open('sl_eob_process.php?eraname=<?php echo $eraname ?>&debug=' + debug + '&paydate=' + paydate + '&original=original', '_blank');
710 return false;
712 <?php
713 if ($alertmsg) {
714 echo "alert('" . htmlentities($alertmsg) . "');\n";
718 </script>
719 </body>
720 </html>