Fixed quote escaping problem in view.php.
[openemr.git] / interface / billing / sl_eob_invoice.php
blob900487252e2c8ca428576d62a1ff9ee5bf907535
1 <?php
2 // Copyright (C) 2005-2006 Rod Roark <rod@sunsetsystems.com>
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 // This provides for manual posting of EOBs. It is invoked from
10 // sl_eob_search.php. For automated (X12 835) remittance posting
11 // see sl_eob_process.php.
13 include_once("../globals.php");
14 include_once("../../library/patient.inc");
15 include_once("../../library/forms.inc");
16 include_once("../../library/sl_eob.inc.php");
17 include_once("../../library/invoice_summary.inc.php");
18 include_once("../../custom/code_types.inc.php");
20 $debug = 0; // set to 1 for debugging mode
22 $INTEGRATED_AR = $GLOBALS['oer_config']['ws_accounting']['enabled'] === 2;
24 $reasons = array(
25 "", // not choosing this allows a reason with no adjustment amount
26 xl("Ins adjust"),
27 xl("Coll w/o"),
28 xl("Pt released"),
29 xl("Sm debt w/o"),
30 xl("To ded'ble"),
31 xl("To copay"),
32 xl("Bad check"),
33 xl("Bad debt"),
34 xl("Discount"),
35 xl("Hardship w/o"),
36 xl("Ins refund"),
37 xl("Pt refund"),
38 xl("Ins overpaid"),
39 xl("Pt overpaid"),
40 xl("Adm adjust"),
41 xl("Untimely filing"),
42 xl("Ins bundling"),
43 xl("After hrs calls")
46 $info_msg = "";
48 // Format money for display.
50 function bucks($amount) {
51 if ($amount)
52 printf("%.2f", $amount);
55 <html>
56 <head>
57 <? html_header_show();?>
58 <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
59 <title><?php xl('EOB Posting - Invoice','e')?></title>
60 <script language="JavaScript">
62 // An insurance radio button is selected.
63 function setins(istr) {
64 <?php if (!$INTEGRATED_AR) { ?>
65 var f = document.forms[0];
66 for (var i = 0; i < f.elements.length; ++i) {
67 var ename = f.elements[i].name;
68 if (ename.indexOf('[src]') < 0) continue;
69 var evalue = f.elements[i].value;
70 var tmp = evalue.substring(0, 4).toLowerCase();
71 if (tmp >= 'ins1' && tmp <= 'ins3')
72 evalue = evalue.substring(4);
73 else if (evalue.substring(0, 2).toLowerCase() == 'pt')
74 evalue = evalue.substring(2);
75 while (evalue.substring(0, 1) == '/')
76 evalue = evalue.substring(1);
77 f.elements[i].value = istr + '/' + evalue;
79 <?php } ?>
80 return true;
83 // Compute an adjustment that writes off the balance:
84 function writeoff(code) {
85 var f = document.forms[0];
86 var belement = f['form_line[' + code + '][bal]'];
87 var pelement = f['form_line[' + code + '][pay]'];
88 var aelement = f['form_line[' + code + '][adj]'];
89 var relement = f['form_line[' + code + '][reason]'];
90 var tmp = belement.value - pelement.value;
91 aelement.value = Number(tmp).toFixed(2);
92 if (aelement.value && ! relement.value) relement.selectedIndex = 1;
93 return false;
96 // Onsubmit handler. A good excuse to write some JavaScript.
97 function validate(f) {
98 for (var i = 0; i < f.elements.length; ++i) {
99 var ename = f.elements[i].name;
100 var pfxlen = ename.indexOf('[pay]');
101 if (pfxlen < 0) continue;
102 var pfx = ename.substring(0, pfxlen);
103 var code = pfx.substring(pfx.indexOf('[')+1, pfxlen-1);
104 if (f[pfx+'[pay]'].value || f[pfx+'[adj]'].value) {
105 <?php if (!$INTEGRATED_AR) { // source validation not appropriate ?>
106 var srcobj = f[pfx+'[src]'];
107 while (srcobj.value.length) {
108 var tmp = srcobj.value.substring(srcobj.value.length - 1);
109 if (tmp > ' ' && tmp != '/') break;
110 srcobj.value = srcobj.value.substring(0, srcobj.value.length - 1);
112 var svalue = srcobj.value;
113 if (! svalue) {
114 alert('<?php xl('Source is missing for code ','e') ?>' + code);
115 return false;
116 } else {
117 var tmp = svalue.substring(0, 4).toLowerCase();
118 if (tmp >= 'ins1' && tmp <= 'ins3') {
119 svalue = svalue.substring(4);
120 } else if (svalue.substring(0, 2).toLowerCase() == 'pt') {
121 svalue = svalue.substring(2);
122 } else {
123 alert('<?php xl('Invalid or missing payer in source for code ','e')?>' + code);
124 return false;
126 if (svalue) {
127 if (svalue.substring(0, 1) != '/') {
128 alert('<?php xl('Missing slash after payer in source for code ','e')?>' + code);
129 return false;
131 if (false) { // Please keep this, Oakland Clinic wants it. -- Rod
132 tmp = svalue.substring(1, 3).toLowerCase();
133 if (tmp != 'nm' && tmp != 'ci' && tmp != 'cp' && tmp != 'ne' &&
134 tmp != 'it' && tmp != 'pf' && tmp != 'pp' && tmp != 'ok')
136 alert('<?php xl('Invalid source designation "','e') ?>' + tmp + '<?php xl('" for code ','e') ?>' + code);
137 return false;
139 } // End of OC code
142 <?php } ?>
143 if (! f[pfx+'[date]'].value) {
144 alert('<?php xl('Date is missing for code ','e')?>' + code);
145 return false;
148 if (f[pfx+'[pay]'].value && isNaN(parseFloat(f[pfx+'[pay]'].value))) {
149 alert('<?php xl('Payment value for code ','e') ?>' + code + '<?php xl(' is not a number','e') ?>');
150 return false;
152 if (f[pfx+'[adj]'].value && isNaN(parseFloat(f[pfx+'[adj]'].value))) {
153 alert('<?php xl('Adjustment value for code ','e') ?>' + code + '<?php xl(' is not a number','e') ?>');
154 return false;
156 if (f[pfx+'[adj]'].value && ! f[pfx+'[reason]'].value) {
157 alert('<?php xl('Please select an adjustment reason for code ','e') ?>' + code);
158 return false;
160 // TBD: validate the date format
162 return true;
165 </script>
166 </head>
167 <body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>
168 <?php
169 $trans_id = 0 + $_GET['id'];
170 if (! $trans_id) die(xl("You cannot access this page directly."));
172 if ($INTEGRATED_AR) {
173 // In the Integrated A/R case, $trans_id matches form_encounter.id.
174 $ferow = sqlQuery("SELECT e.*, p.fname, p.mname, p.lname " .
175 "FROM form_encounter AS e, patient_data AS p WHERE " .
176 "e.id = '$trans_id' AND p.pid = e.pid");
177 if (empty($ferow)) die("There is no encounter with form_encounter.id = '$trans_id'.");
178 $patient_id = 0 + $ferow['pid'];
179 $encounter_id = 0 + $ferow['encounter'];
180 $svcdate = substr($ferow['date'], 0, 10);
181 $form_payer_id = 0 + $_POST['form_payer_id'];
182 $form_reference = $_POST['form_reference'];
183 $form_check_date = fixDate($_POST['form_check_date'], date('Y-m-d'));
184 $form_deposit_date = fixDate($_POST['form_deposit_date'], $form_check_date);
185 $form_pay_total = 0 + $_POST['form_pay_total'];
187 else {
188 slInitialize();
191 $payer_type = 0;
192 if (preg_match('/^Ins(\d)/i', $_POST['form_insurance'], $matches)) {
193 $payer_type = $matches[1];
196 if ($_POST['form_save'] || $_POST['form_cancel']) {
197 if ($_POST['form_save']) {
198 if ($debug) {
199 echo xl("This module is in test mode. The database will not be changed.",'','<p><b>',"</b><p>\n");
202 if ($INTEGRATED_AR) {
203 $session_id = arGetSession($form_payer_id, $form_reference,
204 $form_check_date, $form_deposit_date, $form_pay_total);
205 // The sl_eob_search page needs its invoice links modified to invoke
206 // javascript to load form parms for all the above and submit.
207 // At the same time that page would be modified to work off the
208 // openemr database exclusively.
209 // And back to the sl_eob_invoice page, I think we may want to move
210 // the source input fields from row level to header level.
213 $paytotal = 0;
214 foreach ($_POST['form_line'] as $code => $cdata) {
215 if (!$INTEGRATED_AR) {
216 $thissrc = trim($cdata['src']);
217 $thisdate = trim($cdata['date']);
219 $thispay = trim($cdata['pay']);
220 $thisadj = trim($cdata['adj']);
221 $thisins = trim($cdata['ins']);
222 $reason = trim($cdata['reason']);
223 if (strpos(strtolower($reason), 'ins') !== false)
224 $reason .= ' ' . $_POST['form_insurance'];
225 if (! $thisins) $thisins = 0;
227 if ($thispay) {
228 if ($INTEGRATED_AR) {
229 arPostPayment($patient_id, $encounter_id, $session_id,
230 $thispay, $code, $payer_type, $reason, $debug);
231 } else {
232 slPostPayment($trans_id, $thispay, $thisdate, $thissrc, $code, $thisins, $debug);
234 $paytotal += $thispay;
237 // Be sure to record adjustment reasons even for zero adjustments.
238 if ($thisadj || $reason) {
239 // "To copay" and "To ded'ble" need to become a comment in a zero
240 // adjustment, formatted just like sl_eob_process.php.
241 if (preg_match("/To copay/", $reason)) {
242 $reason = $_POST['form_insurance'] . " coins: $thisadj";
243 $thisadj = 0;
245 else if (preg_match("/To ded'ble/", $reason)) {
246 $reason = $_POST['form_insurance'] . " dedbl: $thisadj";
247 $thisadj = 0;
249 if ($INTEGRATED_AR) {
250 arPostAdjustment($patient_id, $encounter_id, $session_id,
251 $thisadj, $code, $payer_type, $reason, $debug);
252 } else {
253 slPostAdjustment($trans_id, $thisadj, $thisdate, $thissrc, $code, $thisins, $reason, $debug);
258 // Maintain which insurances are marked as finished.
260 if ($INTEGRATED_AR) {
261 $form_done = 0 + $_POST['form_done'];
262 sqlStatement("UPDATE form_encounter " .
263 "SET last_level_closed = $form_done WHERE " .
264 "pid = '$patient_id' AND encounter = '$encounter_id'");
266 else {
267 $form_duedate = fixDate($_POST['form_duedate']);
268 $form_notes = trim($_POST['form_notes']);
269 // We use the "Ship Via" field of the invoice to hold these.
270 $form_eobs = "";
271 foreach (array('Ins1', 'Ins2', 'Ins3') as $value) {
272 if ($_POST["form_done_$value"]) {
273 if ($form_eobs) $form_eobs .= ","; else $form_eobs = "Done: ";
274 $form_eobs .= $value;
277 $query = "UPDATE ar SET duedate = '$form_duedate', notes = '$form_notes', " .
278 "shipvia = '$form_eobs' WHERE id = $trans_id";
279 if ($debug) {
280 echo $query . "<br>\n";
281 } else {
282 SLQuery($query);
283 if ($sl_err) die($sl_err);
287 if ($_POST['form_secondary']) {
288 if ($INTEGRATED_AR) {
289 arSetupSecondary($patient_id, $encounter_id, $debug);
290 } else {
291 slSetupSecondary($trans_id, $debug);
295 echo "<script language='JavaScript'>\n";
296 echo " if (opener.document.forms[0].form_amount) {\n";
297 echo " var tmp = opener.document.forms[0].form_amount.value - $paytotal;\n";
298 echo " opener.document.forms[0].form_amount.value = Number(tmp).toFixed(2);\n";
299 echo " }\n";
300 } else {
301 echo "<script language='JavaScript'>\n";
303 if ($info_msg) echo " alert('$info_msg');\n";
304 if (! $debug) echo " window.close();\n";
305 echo "</script></body></html>\n";
306 if (!$INTEGRATED_AR) SLClose();
307 exit();
310 if ($INTEGRATED_AR) {
311 /*****************************************************************
312 $ferow = sqlQuery("SELECT e.*, p.fname, p.mname, p.lname " .
313 "FROM form_encounter AS e, patient_data AS p WHERE " .
314 "e.pid = '$patient_id' AND e.encounter = '$encounter_id' AND ".
315 "p.pid = e.pid");
316 if (empty($ferow)) die("There is no encounter $patient_id.$encounter_id.");
317 $svcdate = substr($ferow['date'], 0, 10);
318 *****************************************************************/
319 // Get invoice charge details.
320 $codes = ar_get_invoice_summary($patient_id, $encounter_id, true);
322 else {
323 // Get invoice data into $arrow.
324 $arres = SLQuery("select ar.*, customer.name, employee.name as doctor " .
325 "from ar, customer, employee where ar.id = $trans_id and " .
326 "customer.id = ar.customer_id and employee.id = ar.employee_id");
327 if ($sl_err) die($sl_err);
328 $arrow = SLGetRow($arres, 0);
329 if (! $arrow) die(xl("There is no match for invoice id = ") . $trans_id);
331 // Determine the date of service. An 8-digit encounter number is
332 // presumed to be a date of service imported during conversion.
333 // Otherwise look it up in the form_encounter table.
335 $svcdate = "";
336 list($patient_id, $encounter) = explode(".", $arrow['invnumber']);
337 if (strlen($encounter) == 8) {
338 $svcdate = substr($encounter, 0, 4) . "-" . substr($encounter, 4, 2) .
339 "-" . substr($encounter, 6, 2);
341 else if ($encounter) {
342 $tmp = sqlQuery("SELECT date FROM form_encounter WHERE " .
343 "encounter = $encounter");
344 $svcdate = substr($tmp['date'], 0, 10);
347 // Get invoice charge details.
348 $codes = get_invoice_summary($trans_id, true);
351 $pdrow = sqlQuery("select genericname2, genericval2 " .
352 "from patient_data where pid = '$patient_id' limit 1");
354 <center>
356 <form method='post' action='sl_eob_invoice.php?id=<?php echo $trans_id ?>'
357 onsubmit='return validate(this)'>
359 <table border='0' cellpadding='3'>
360 <tr>
361 <td>
362 <?php xl('Patient:','e')?>
363 </td>
364 <td>
365 <?php
366 if ($INTEGRATED_AR) {
367 echo $ferow['fname'] . ' ' . $ferow['mname'] . ' ' . $ferow['lname'];
369 else {
370 echo $arrow['name'];
373 </td>
374 <td colspan="2" rowspan="3">
375 <?php
376 if ($INTEGRATED_AR) {
377 for ($i = 1; $i <= 3; ++$i) {
378 $payerid = arGetPayerID($patient_id, $svcdate, $i);
379 if ($payerid) {
380 $tmp = sqlQuery("SELECT name FROM insurance_companies WHERE id = $payerid");
381 echo "Ins$i: " . $tmp['name'] . "<br />";
385 else {
386 echo " <textarea name='form_notes' cols='50' style='height:100%'>";
387 echo $arrow['notes'];
388 echo "</textarea>\n";
391 </td>
392 </tr>
393 <tr>
394 <td>
395 <?php xl('Provider:','e')?>
396 </td>
397 <td>
398 <?php
399 if ($INTEGRATED_AR) {
400 $tmp = sqlQuery("SELECT u.fname, u.mname, u.lname " .
401 "FROM billing AS b, users AS u WHERE " .
402 "b.pid = '$patient_id' AND b.encounter = '$encounter_id' AND " .
403 "b.activity = 1 AND u.id = b.provider_id " .
404 "ORDER BY u.authorized DESC, b.fee DESC, b.id ASC LIMIT 1");
405 echo $tmp['fname'] . ' ' . $tmp['mname'] . ' ' . $tmp['lname'];
407 else {
408 echo $arrow['doctor'];
411 </td>
412 </tr>
413 <tr>
414 <td>
415 <?php xl('Invoice:','e')?>
416 </td>
417 <td>
418 <?php
419 if ($INTEGRATED_AR) {
420 echo "$patient_id.$encounter_id";
422 else {
423 echo $arrow['invnumber'];
426 </td>
427 </tr>
429 <tr>
430 <td>
431 <?php xl('Svc Date:','e'); ?>
432 </td>
433 <td>
434 <?php
435 echo $svcdate;
437 </td>
438 <td colspan="2">
439 <?php xl('Done with:','e','',"&nbsp")?>;
440 <?php
441 // Write a checkbox for each insurance. It is to be checked when
442 // we no longer expect any payments from that company for the claim.
443 if ($INTEGRATED_AR) {
444 $last_level_closed = 0 + $ferow['last_level_closed'];
445 foreach (array(0 => 'None', 1 => 'Ins1', 2 => 'Ins2', 3 => 'Ins3') as $key => $value) {
446 if ($key && !arGetPayerID($patient_id, $svcdate, $key)) continue;
447 $checked = ($last_level_closed == $key) ? " checked" : "";
448 echo " <input type='radio' name='form_done' value='$key'$checked />$value&nbsp;\n";
451 else {
452 // The information is stored in the 'shipvia' field of the invoice.
453 $insgot = strtolower($arrow['notes']);
454 $insdone = strtolower($arrow['shipvia']);
455 foreach (array('Ins1', 'Ins2', 'Ins3') as $value) {
456 $lcvalue = strtolower($value);
457 $checked = (strpos($insdone, $lcvalue) === false) ? "" : " checked";
458 if (strpos($insgot, $lcvalue) !== false) {
459 echo " <input type='checkbox' name='form_done_$value' value='1'$checked />$value&nbsp;\n";
464 </td>
465 <?php
466 if ($INTEGRATED_AR) {
467 echo "<td>\n";
468 echo xl('Check/EOB No.:');
469 echo "</td>\n";
470 echo "<td>\n";
471 echo "<input type='text' name='form_reference' size='10' value='' />\n";
472 echo "</td>\n";
475 </tr>
477 <tr>
478 <td>
479 <?php xl('Bill Date:','e') ?>
480 </td>
481 <td>
482 <?php
483 if ($INTEGRATED_AR) {
484 echo $svcdate;
486 else {
487 echo $arrow['transdate'];
490 </td>
491 <td colspan="2">
492 <?php xl('Now posting for:','e','',"&nbsp")?>;
494 <?php
495 // TBD: check the first not-done-with insurance, not always Ins1!
497 <input type='radio' name='form_insurance' value='Ins1' onclick='setins("Ins1")' checked /><?php xl('Ins1','e')?>&nbsp;
498 <input type='radio' name='form_insurance' value='Ins2' onclick='setins("Ins2")' /><?php xl('Ins2','e')?>&nbsp;
499 <input type='radio' name='form_insurance' value='Ins3' onclick='setins("Ins3")' /><?php xl('Ins3','e')?>&nbsp;
500 <input type='radio' name='form_insurance' value='Pt' onclick='setins("Pt")' /><?php xl('Patient','e')?>
502 <?php
503 // TBD: I think the following is unused and can be removed.
505 <input type='hidden' name='form_eobs' value='<?php echo addslashes($arrow['shipvia']) ?>' />
507 </td>
508 <?php
509 if ($INTEGRATED_AR) {
510 echo "<td>\n";
511 echo xl('Check/EOB Date:');
512 echo "</td>\n";
513 echo "<td>\n";
514 echo "<input type='text' name='form_check_date' size='10' value='' />\n";
515 echo "</td>\n";
518 </tr>
519 <tr>
520 <td>
521 <?php
522 if (!$INTEGRATED_AR) xl('Due Date:','e');
524 </td>
525 <td>
527 <?php if (!$INTEGRATED_AR) { ?>
528 <input type='text' name='form_duedate' size='10' value='<?php echo $arrow['duedate'] ?>'
529 title='<?php xl('Due date mm/dd/yyyy or yyyy-mm-dd','e')?>'>
530 <?php } ?>
531 </td>
532 <td colspan="2">
533 <input type="checkbox" name="form_secondary" value="1"> <?php xl('Needs secondary billing','e')?>
534 &nbsp;&nbsp;
535 <input type='submit' name='form_save' value='<?php xl('Save','e')?>'>
536 &nbsp;
537 <input type='button' value='<?php xl('Cancel','e')?>' onclick='window.close()'>
538 </td>
539 <?php
540 if ($INTEGRATED_AR) {
541 echo "<td>\n";
542 echo xl('Deposit Date:');
543 echo "</td>\n";
544 echo "<td>\n";
545 echo "<input type='text' name='form_deposit_date' size='10' value='' />\n";
546 echo "<input type='hidden' name='form_payer_id' value='' />\n";
547 echo "<input type='hidden' name='form_orig_reference' value='' />\n";
548 echo "<input type='hidden' name='form_orig_check_date' value='' />\n";
549 echo "<input type='hidden' name='form_orig_deposit_date' value='' />\n";
550 echo "<input type='hidden' name='form_pay_total' value='' />\n";
551 echo "</td>\n";
554 </tr>
555 <?php if ($pdrow['genericname2'] == 'Billing') { ?>
556 <tr>
557 <td>
558 <?php xl('Billing Note:','e')?>
559 </td>
560 <td colspan='3' style='color:red'>
561 <?php echo $pdrow['genericval2'] ?>
562 </td>
563 </tr>
564 <?php } ?>
565 <tr>
566 <td height="1">
567 </td>
568 </tr>
569 </table>
571 <table border='0' cellpadding='2' cellspacing='0' width='98%'>
573 <tr bgcolor="#cccccc">
574 <td class="dehead">
575 <?php xl('Code','e')?>
576 </td>
577 <td class="dehead" align="right">
578 <?php xl('Charge','e')?>
579 </td>
580 <td class="dehead" align="right">
581 <?php xl('Balance','e')?>&nbsp;
582 </td>
583 <td class="dehead">
584 <?php xl('By/Source','e')?>
585 </td>
586 <td class="dehead">
587 <?php xl('Date','e')?>
588 </td>
589 <td class="dehead">
590 <?php xl('Pay','e')?>
591 </td>
592 <td class="dehead">
593 <?php xl('Adjust','e')?>
594 </td>
595 <td class="dehead">
596 <?php xl('Reason','e')?>
597 </td>
598 </tr>
599 <?php
600 $encount = 0;
601 foreach ($codes as $code => $cdata) {
602 ++$encount;
603 $bgcolor = "#" . (($encount & 1) ? "ddddff" : "ffdddd");
604 $dispcode = $code;
605 // this sorts the details more or less chronologically:
606 ksort($cdata['dtl']);
607 foreach ($cdata['dtl'] as $dkey => $ddata) {
608 $ddate = substr($dkey, 0, 10);
609 if (preg_match('/^(\d\d\d\d)(\d\d)(\d\d)\s*$/', $ddate, $matches)) {
610 $ddate = $matches[1] . '-' . $matches[2] . '-' . $matches[3];
612 $tmpchg = "";
613 $tmpadj = "";
614 /*****************************************************************
615 if ($ddata['chg'] > 0)
616 $tmpchg = $ddata['chg'];
617 else if ($ddata['chg'] < 0)
618 $tmpadj = 0 - $ddata['chg'];
619 *****************************************************************/
620 if ($ddata['chg'] != 0) {
621 if (isset($ddata['rsn'])) $tmpadj = 0 - $ddata['chg'];
622 else $tmpchg = $ddata['chg'];
625 <tr bgcolor='<?php echo $bgcolor ?>'>
626 <td class="detail">
627 <?php echo $dispcode; $dispcode = "" ?>
628 </td>
629 <td class="detail" align="right">
630 <?php bucks($tmpchg) ?>
631 </td>
632 <td class="detail" align="right">
633 &nbsp;
634 </td>
635 <td class="detail">
636 <?php
637 if (isset($ddata['plv'])) {
638 if (!$ddata['plv']) echo 'Pt/';
639 else echo 'Ins' . $ddata['plv'] . '/';
641 echo $ddata['src'];
643 </td>
644 <td class="detail">
645 <?php echo $ddate ?>
646 </td>
647 <td class="detail">
648 <?php bucks($ddata['pmt']) ?>
649 </td>
650 <td class="detail">
651 <?php bucks($tmpadj) ?>
652 </td>
653 <td class="detail">
654 <?php echo $ddata['rsn'] ?>
655 </td>
656 </tr>
657 <?php
658 } // end of prior detail line
660 <tr bgcolor='<?php echo $bgcolor ?>'>
661 <td class="detail">
662 <?php echo $dispcode; $dispcode = "" ?>
663 </td>
664 <td class="detail" align="right">
665 &nbsp;
666 </td>
667 <td class="detail" align="right">
668 <input type="hidden" name="form_line[<?php echo $code ?>][bal]" value="<?php bucks($cdata['bal']) ?>">
669 <input type="hidden" name="form_line[<?php echo $code ?>][ins]" value="<?php echo $cdata['ins'] ?>">
670 <?php printf("%.2f", $cdata['bal']) ?>&nbsp;
671 </td>
672 <td class="detail">
674 <?php if (!$INTEGRATED_AR) { ?>
675 <input type="text" name="form_line[<?php echo $code ?>][src]" size="10"
676 style="background-color:<?php echo $bgcolor ?>" />
677 <!-- title="NM=notmet, CI=coins, CP=copay, NE=notelig, IT=insterm, PF=ptfull, PP=ptpart" -->
678 <?php } ?>
680 </td>
681 <td class="detail">
683 <?php if (!$INTEGRATED_AR) { ?>
684 <input type="text" name="form_line[<?php echo $code ?>][date]" size="10"
685 style="background-color:<?php echo $bgcolor ?>" />
686 <?php } ?>
688 </td>
689 <td class="detail">
690 <input type="text" name="form_line[<?php echo $code ?>][pay]" size="10"
691 style="background-color:<?php echo $bgcolor ?>" />
692 </td>
693 <td class="detail">
694 <input type="text" name="form_line[<?php echo $code ?>][adj]" size="10"
695 style="background-color:<?php echo $bgcolor ?>" />
696 &nbsp; <a href="" onclick="return writeoff('<?php echo $code ?>')">W</a>
697 </td>
698 <td class="detail">
699 <select name="form_line[<?php echo $code ?>][reason]"
700 style="background-color:<?php echo $bgcolor ?>">
701 <?php
702 foreach ($reasons as $value) {
703 echo " <option value=\"$value\">$value</option>\n";
706 </select>
707 <?php
708 // TBD: Maybe a comment field would be good here, for appending
709 // to the reason.
711 </td>
712 </tr>
713 <?php
714 } // end of code
715 if (!$INTEGRATED_AR) SLClose();
718 </table>
719 </form>
720 </center>
721 <script language="JavaScript">
722 var f1 = opener.document.forms[0];
723 var f2 = document.forms[0];
724 if (f1.form_source) {
725 <?php
726 if ($INTEGRATED_AR) {
727 // These support creation and lookup of ar_session table entries:
728 echo " f2.form_reference.value = f1.form_source.value;\n";
729 echo " f2.form_check_date.value = f1.form_paydate.value;\n";
730 echo " f2.form_deposit_date.value = f1.form_deposit_date.value;\n";
731 echo " f2.form_payer_id.value = f1.form_payer_id.value;\n";
732 echo " f2.form_pay_total.value = f1.form_amount.value;\n";
733 echo " f2.form_orig_reference.value = f1.form_source.value;\n";
734 echo " f2.form_orig_check_date.value = f1.form_paydate.value;\n";
735 echo " f2.form_orig_deposit_date.value = f1.form_deposit_date.value;\n";
737 // While I'm thinking about it, some notes about eob sessions.
738 // If they do not have all of the session key fields in the search
739 // page, then show a warning at the top of the invoice page.
740 // Also when they go to save the invoice page and a session key
741 // field has changed, alert them to that and allow a cancel.
743 // Another point... when posting EOBs, the incoming payer ID might
744 // not match the payer ID for the patient's insurance. This is
745 // because the same payer might be entered more than once into the
746 // insurance_companies table. I don't think it matters much.
748 else {
749 foreach ($codes as $code => $cdata) {
750 echo " f2['form_line[$code][src]'].value = f1.form_source.value;\n";
751 echo " f2['form_line[$code][date]'].value = f1.form_paydate.value;\n";
756 setins("Ins1");
757 </script>
758 </body>
759 </html>