minor cosmetic fixes
[openemr.git] / interface / billing / sl_eob_invoice.php
blob685e7fc0bd5e1caa895e1119c585ef83e8ee4ca9
1 <?php
2 // Copyright (C) 2005-2009 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 $info_msg = "";
26 // Format money for display.
28 function bucks($amount) {
29 if ($amount)
30 printf("%.2f", $amount);
33 <html>
34 <head>
35 <? html_header_show();?>
36 <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
37 <title><?php xl('EOB Posting - Invoice','e')?></title>
38 <script language="JavaScript">
40 // An insurance radio button is selected.
41 function setins(istr) {
42 <?php if (!$INTEGRATED_AR) { ?>
43 var f = document.forms[0];
44 for (var i = 0; i < f.elements.length; ++i) {
45 var ename = f.elements[i].name;
46 if (ename.indexOf('[src]') < 0) continue;
47 var evalue = f.elements[i].value;
48 var tmp = evalue.substring(0, 4).toLowerCase();
49 if (tmp >= 'ins1' && tmp <= 'ins3')
50 evalue = evalue.substring(4);
51 else if (evalue.substring(0, 2).toLowerCase() == 'pt')
52 evalue = evalue.substring(2);
53 while (evalue.substring(0, 1) == '/')
54 evalue = evalue.substring(1);
55 f.elements[i].value = istr + '/' + evalue;
57 <?php } ?>
58 return true;
61 // Compute an adjustment that writes off the balance:
62 function writeoff(code) {
63 var f = document.forms[0];
64 var belement = f['form_line[' + code + '][bal]'];
65 var pelement = f['form_line[' + code + '][pay]'];
66 var aelement = f['form_line[' + code + '][adj]'];
67 var relement = f['form_line[' + code + '][reason]'];
68 var tmp = belement.value - pelement.value;
69 aelement.value = Number(tmp).toFixed(2);
70 if (aelement.value && ! relement.value) relement.selectedIndex = 1;
71 return false;
74 // Onsubmit handler. A good excuse to write some JavaScript.
75 function validate(f) {
76 for (var i = 0; i < f.elements.length; ++i) {
77 var ename = f.elements[i].name;
78 var pfxlen = ename.indexOf('[pay]');
79 if (pfxlen < 0) continue;
80 var pfx = ename.substring(0, pfxlen);
81 var code = pfx.substring(pfx.indexOf('[')+1, pfxlen-1);
82 if (f[pfx+'[pay]'].value || f[pfx+'[adj]'].value) {
83 <?php if (!$INTEGRATED_AR) { // source validation not appropriate ?>
84 var srcobj = f[pfx+'[src]'];
85 while (srcobj.value.length) {
86 var tmp = srcobj.value.substring(srcobj.value.length - 1);
87 if (tmp > ' ' && tmp != '/') break;
88 srcobj.value = srcobj.value.substring(0, srcobj.value.length - 1);
90 var svalue = srcobj.value;
91 if (! svalue) {
92 alert('<?php xl('Source is missing for code ','e') ?>' + code);
93 return false;
94 } else {
95 var tmp = svalue.substring(0, 4).toLowerCase();
96 if (tmp >= 'ins1' && tmp <= 'ins3') {
97 svalue = svalue.substring(4);
98 } else if (svalue.substring(0, 2).toLowerCase() == 'pt') {
99 svalue = svalue.substring(2);
100 } else {
101 alert('<?php xl('Invalid or missing payer in source for code ','e')?>' + code);
102 return false;
104 if (svalue) {
105 if (svalue.substring(0, 1) != '/') {
106 alert('<?php xl('Missing slash after payer in source for code ','e')?>' + code);
107 return false;
109 if (false) { // Please keep this, Oakland Clinic wants it. -- Rod
110 tmp = svalue.substring(1, 3).toLowerCase();
111 if (tmp != 'nm' && tmp != 'ci' && tmp != 'cp' && tmp != 'ne' &&
112 tmp != 'it' && tmp != 'pf' && tmp != 'pp' && tmp != 'ok')
114 alert('<?php xl('Invalid source designation "','e') ?>' + tmp + '<?php xl('" for code ','e') ?>' + code);
115 return false;
117 } // End of OC code
120 <?php } ?>
121 if (! f[pfx+'[date]'].value) {
122 alert('<?php xl('Date is missing for code ','e')?>' + code);
123 return false;
126 if (f[pfx+'[pay]'].value && isNaN(parseFloat(f[pfx+'[pay]'].value))) {
127 alert('<?php xl('Payment value for code ','e') ?>' + code + '<?php xl(' is not a number','e') ?>');
128 return false;
130 if (f[pfx+'[adj]'].value && isNaN(parseFloat(f[pfx+'[adj]'].value))) {
131 alert('<?php xl('Adjustment value for code ','e') ?>' + code + '<?php xl(' is not a number','e') ?>');
132 return false;
134 if (f[pfx+'[adj]'].value && ! f[pfx+'[reason]'].value) {
135 alert('<?php xl('Please select an adjustment reason for code ','e') ?>' + code);
136 return false;
138 // TBD: validate the date format
140 return true;
143 </script>
144 </head>
145 <body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>
146 <?php
147 $trans_id = 0 + $_GET['id'];
148 if (! $trans_id) die(xl("You cannot access this page directly."));
150 if ($INTEGRATED_AR) {
151 // In the Integrated A/R case, $trans_id matches form_encounter.id.
152 $ferow = sqlQuery("SELECT e.*, p.fname, p.mname, p.lname " .
153 "FROM form_encounter AS e, patient_data AS p WHERE " .
154 "e.id = '$trans_id' AND p.pid = e.pid");
155 if (empty($ferow)) die("There is no encounter with form_encounter.id = '$trans_id'.");
156 $patient_id = 0 + $ferow['pid'];
157 $encounter_id = 0 + $ferow['encounter'];
158 $svcdate = substr($ferow['date'], 0, 10);
159 $form_payer_id = 0 + $_POST['form_payer_id'];
160 $form_reference = $_POST['form_reference'];
161 $form_check_date = fixDate($_POST['form_check_date'], date('Y-m-d'));
162 $form_deposit_date = fixDate($_POST['form_deposit_date'], $form_check_date);
163 $form_pay_total = 0 + $_POST['form_pay_total'];
165 else {
166 slInitialize();
169 $payer_type = 0;
170 if (preg_match('/^Ins(\d)/i', $_POST['form_insurance'], $matches)) {
171 $payer_type = $matches[1];
174 if ($_POST['form_save'] || $_POST['form_cancel']) {
175 if ($_POST['form_save']) {
176 if ($debug) {
177 echo xl("This module is in test mode. The database will not be changed.",'','<p><b>',"</b><p>\n");
180 if ($INTEGRATED_AR) {
181 $session_id = arGetSession($form_payer_id, $form_reference,
182 $form_check_date, $form_deposit_date, $form_pay_total);
183 // The sl_eob_search page needs its invoice links modified to invoke
184 // javascript to load form parms for all the above and submit.
185 // At the same time that page would be modified to work off the
186 // openemr database exclusively.
187 // And back to the sl_eob_invoice page, I think we may want to move
188 // the source input fields from row level to header level.
191 $paytotal = 0;
192 foreach ($_POST['form_line'] as $code => $cdata) {
193 if (!$INTEGRATED_AR) {
194 $thissrc = trim($cdata['src']);
195 $thisdate = trim($cdata['date']);
197 $thispay = trim($cdata['pay']);
198 $thisadj = trim($cdata['adj']);
199 $thisins = trim($cdata['ins']);
200 $reason = trim($cdata['reason']);
201 if (strpos(strtolower($reason), 'ins') !== false)
202 $reason .= ' ' . $_POST['form_insurance'];
203 if (! $thisins) $thisins = 0;
205 if ($thispay) {
206 if ($INTEGRATED_AR) {
207 arPostPayment($patient_id, $encounter_id, $session_id,
208 $thispay, $code, $payer_type, $reason, $debug);
209 } else {
210 slPostPayment($trans_id, $thispay, $thisdate, $thissrc, $code, $thisins, $debug);
212 $paytotal += $thispay;
215 // Be sure to record adjustment reasons even for zero adjustments.
216 if ($thisadj || $reason) {
217 // "To copay" and "To ded'ble" need to become a comment in a zero
218 // adjustment, formatted just like sl_eob_process.php.
219 if (preg_match("/To copay/", $reason)) {
220 $reason = $_POST['form_insurance'] . " coins: $thisadj";
221 $thisadj = 0;
223 else if (preg_match("/To ded'ble/", $reason)) {
224 $reason = $_POST['form_insurance'] . " dedbl: $thisadj";
225 $thisadj = 0;
227 if ($INTEGRATED_AR) {
228 arPostAdjustment($patient_id, $encounter_id, $session_id,
229 $thisadj, $code, $payer_type, $reason, $debug);
230 } else {
231 slPostAdjustment($trans_id, $thisadj, $thisdate, $thissrc, $code, $thisins, $reason, $debug);
236 // Maintain which insurances are marked as finished.
238 if ($INTEGRATED_AR) {
239 $form_done = 0 + $_POST['form_done'];
240 sqlStatement("UPDATE form_encounter " .
241 "SET last_level_closed = $form_done WHERE " .
242 "pid = '$patient_id' AND encounter = '$encounter_id'");
244 else {
245 $form_duedate = fixDate($_POST['form_duedate']);
246 $form_notes = trim($_POST['form_notes']);
247 // We use the "Ship Via" field of the invoice to hold these.
248 $form_eobs = "";
249 foreach (array('Ins1', 'Ins2', 'Ins3') as $value) {
250 if ($_POST["form_done_$value"]) {
251 if ($form_eobs) $form_eobs .= ","; else $form_eobs = "Done: ";
252 $form_eobs .= $value;
255 $query = "UPDATE ar SET duedate = '$form_duedate', notes = '$form_notes', " .
256 "shipvia = '$form_eobs' WHERE id = $trans_id";
257 if ($debug) {
258 echo $query . "<br>\n";
259 } else {
260 SLQuery($query);
261 if ($sl_err) die($sl_err);
265 if ($_POST['form_secondary']) {
266 if ($INTEGRATED_AR) {
267 arSetupSecondary($patient_id, $encounter_id, $debug);
268 } else {
269 slSetupSecondary($trans_id, $debug);
273 echo "<script language='JavaScript'>\n";
274 echo " if (opener.document.forms[0].form_amount) {\n";
275 echo " var tmp = opener.document.forms[0].form_amount.value - $paytotal;\n";
276 echo " opener.document.forms[0].form_amount.value = Number(tmp).toFixed(2);\n";
277 echo " }\n";
278 } else {
279 echo "<script language='JavaScript'>\n";
281 if ($info_msg) echo " alert('$info_msg');\n";
282 if (! $debug) echo " window.close();\n";
283 echo "</script></body></html>\n";
284 if (!$INTEGRATED_AR) SLClose();
285 exit();
288 if ($INTEGRATED_AR) {
289 /*****************************************************************
290 $ferow = sqlQuery("SELECT e.*, p.fname, p.mname, p.lname " .
291 "FROM form_encounter AS e, patient_data AS p WHERE " .
292 "e.pid = '$patient_id' AND e.encounter = '$encounter_id' AND ".
293 "p.pid = e.pid");
294 if (empty($ferow)) die("There is no encounter $patient_id.$encounter_id.");
295 $svcdate = substr($ferow['date'], 0, 10);
296 *****************************************************************/
297 // Get invoice charge details.
298 $codes = ar_get_invoice_summary($patient_id, $encounter_id, true);
300 else {
301 // Get invoice data into $arrow.
302 $arres = SLQuery("select ar.*, customer.name, employee.name as doctor " .
303 "from ar, customer, employee where ar.id = $trans_id and " .
304 "customer.id = ar.customer_id and employee.id = ar.employee_id");
305 if ($sl_err) die($sl_err);
306 $arrow = SLGetRow($arres, 0);
307 if (! $arrow) die(xl("There is no match for invoice id = ") . $trans_id);
309 // Determine the date of service. An 8-digit encounter number is
310 // presumed to be a date of service imported during conversion.
311 // Otherwise look it up in the form_encounter table.
313 $svcdate = "";
314 list($patient_id, $encounter) = explode(".", $arrow['invnumber']);
315 if (strlen($encounter) == 8) {
316 $svcdate = substr($encounter, 0, 4) . "-" . substr($encounter, 4, 2) .
317 "-" . substr($encounter, 6, 2);
319 else if ($encounter) {
320 $tmp = sqlQuery("SELECT date FROM form_encounter WHERE " .
321 "encounter = $encounter");
322 $svcdate = substr($tmp['date'], 0, 10);
325 // Get invoice charge details.
326 $codes = get_invoice_summary($trans_id, true);
329 $pdrow = sqlQuery("select genericname2, genericval2 " .
330 "from patient_data where pid = '$patient_id' limit 1");
332 <center>
334 <form method='post' action='sl_eob_invoice.php?id=<?php echo $trans_id ?>'
335 onsubmit='return validate(this)'>
337 <table border='0' cellpadding='3'>
338 <tr>
339 <td>
340 <?php xl('Patient:','e')?>
341 </td>
342 <td>
343 <?php
344 if ($INTEGRATED_AR) {
345 echo $ferow['fname'] . ' ' . $ferow['mname'] . ' ' . $ferow['lname'];
347 else {
348 echo $arrow['name'];
351 </td>
352 <td colspan="2" rowspan="3">
353 <?php
354 if ($INTEGRATED_AR) {
355 for ($i = 1; $i <= 3; ++$i) {
356 $payerid = arGetPayerID($patient_id, $svcdate, $i);
357 if ($payerid) {
358 $tmp = sqlQuery("SELECT name FROM insurance_companies WHERE id = $payerid");
359 echo "Ins$i: " . $tmp['name'] . "<br />";
363 else {
364 echo " <textarea name='form_notes' cols='50' style='height:100%'>";
365 echo $arrow['notes'];
366 echo "</textarea>\n";
369 </td>
370 </tr>
371 <tr>
372 <td>
373 <?php xl('Provider:','e')?>
374 </td>
375 <td>
376 <?php
377 if ($INTEGRATED_AR) {
378 $tmp = sqlQuery("SELECT fname, mname, lname " .
379 "FROM users WHERE id = " . $ferow['provider_id']);
380 echo $tmp['fname'] . ' ' . $tmp['mname'] . ' ' . $tmp['lname'];
381 $tmp = sqlQuery("SELECT bill_date FROM billing WHERE " .
382 "pid = '$patient_id' AND encounter = '$encounter_id' AND " .
383 "activity = 1 ORDER BY fee DESC, id ASC LIMIT 1");
384 $billdate = substr(($tmp['bill_date'] . "Not Billed"), 0, 10);
386 else {
387 echo $arrow['doctor'];
390 </td>
391 </tr>
392 <tr>
393 <td>
394 <?php xl('Invoice:','e')?>
395 </td>
396 <td>
397 <?php
398 if ($INTEGRATED_AR) {
399 echo "$patient_id.$encounter_id";
401 else {
402 echo $arrow['invnumber'];
405 </td>
406 </tr>
408 <tr>
409 <td>
410 <?php xl('Svc Date:','e'); ?>
411 </td>
412 <td>
413 <?php
414 echo $svcdate;
416 </td>
417 <td colspan="2">
418 <?php xl('Done with:','e','',"&nbsp")?>;
419 <?php
420 // Write a checkbox for each insurance. It is to be checked when
421 // we no longer expect any payments from that company for the claim.
422 if ($INTEGRATED_AR) {
423 $last_level_closed = 0 + $ferow['last_level_closed'];
424 foreach (array(0 => 'None', 1 => 'Ins1', 2 => 'Ins2', 3 => 'Ins3') as $key => $value) {
425 if ($key && !arGetPayerID($patient_id, $svcdate, $key)) continue;
426 $checked = ($last_level_closed == $key) ? " checked" : "";
427 echo " <input type='radio' name='form_done' value='$key'$checked />$value&nbsp;\n";
430 else {
431 // The information is stored in the 'shipvia' field of the invoice.
432 $insgot = strtolower($arrow['notes']);
433 $insdone = strtolower($arrow['shipvia']);
434 foreach (array('Ins1', 'Ins2', 'Ins3') as $value) {
435 $lcvalue = strtolower($value);
436 $checked = (strpos($insdone, $lcvalue) === false) ? "" : " checked";
437 if (strpos($insgot, $lcvalue) !== false) {
438 echo " <input type='checkbox' name='form_done_$value' value='1'$checked />$value&nbsp;\n";
443 </td>
444 <?php
445 if ($INTEGRATED_AR) {
446 echo "<td>\n";
447 echo xl('Check/EOB No.:');
448 echo "</td>\n";
449 echo "<td>\n";
450 echo "<input type='text' name='form_reference' size='10' value='' />\n";
451 echo "</td>\n";
454 </tr>
456 <tr>
457 <td>
458 <?php xl('Last Bill Date:','e') ?>
459 </td>
460 <td>
461 <?php
462 if ($INTEGRATED_AR) {
463 echo $billdate;
465 else {
466 echo $arrow['transdate'];
469 </td>
470 <td colspan="2">
471 <?php xl('Now posting for:','e','',"&nbsp")?>;
473 <?php
474 // TBD: check the first not-done-with insurance, not always Ins1!
476 <input type='radio' name='form_insurance' value='Ins1' onclick='setins("Ins1")' checked /><?php xl('Ins1','e')?>&nbsp;
477 <input type='radio' name='form_insurance' value='Ins2' onclick='setins("Ins2")' /><?php xl('Ins2','e')?>&nbsp;
478 <input type='radio' name='form_insurance' value='Ins3' onclick='setins("Ins3")' /><?php xl('Ins3','e')?>&nbsp;
479 <input type='radio' name='form_insurance' value='Pt' onclick='setins("Pt")' /><?php xl('Patient','e')?>
481 <?php
482 // TBD: I think the following is unused and can be removed.
484 <input type='hidden' name='form_eobs' value='<?php echo addslashes($arrow['shipvia']) ?>' />
486 </td>
487 <?php
488 if ($INTEGRATED_AR) {
489 echo "<td>\n";
490 echo xl('Check/EOB Date:');
491 echo "</td>\n";
492 echo "<td>\n";
493 echo "<input type='text' name='form_check_date' size='10' value='' />\n";
494 echo "</td>\n";
497 </tr>
498 <tr>
499 <td>
500 <?php
501 if (!$INTEGRATED_AR) xl('Due Date:','e');
503 </td>
504 <td>
506 <?php if (!$INTEGRATED_AR) { ?>
507 <input type='text' name='form_duedate' size='10' value='<?php echo $arrow['duedate'] ?>'
508 title='<?php xl('Due date mm/dd/yyyy or yyyy-mm-dd','e')?>'>
509 <?php } ?>
510 </td>
511 <td colspan="2">
512 <input type="checkbox" name="form_secondary" value="1"> <?php xl('Needs secondary billing','e')?>
513 &nbsp;&nbsp;
514 <input type='submit' name='form_save' value='<?php xl('Save','e')?>'>
515 &nbsp;
516 <input type='button' value='<?php xl('Cancel','e')?>' onclick='window.close()'>
517 </td>
518 <?php
519 if ($INTEGRATED_AR) {
520 echo "<td>\n";
521 echo xl('Deposit Date:');
522 echo "</td>\n";
523 echo "<td>\n";
524 echo "<input type='text' name='form_deposit_date' size='10' value='' />\n";
525 echo "<input type='hidden' name='form_payer_id' value='' />\n";
526 echo "<input type='hidden' name='form_orig_reference' value='' />\n";
527 echo "<input type='hidden' name='form_orig_check_date' value='' />\n";
528 echo "<input type='hidden' name='form_orig_deposit_date' value='' />\n";
529 echo "<input type='hidden' name='form_pay_total' value='' />\n";
530 echo "</td>\n";
533 </tr>
534 <?php if ($pdrow['genericname2'] == 'Billing') { ?>
535 <tr>
536 <td>
537 <?php xl('Billing Note:','e')?>
538 </td>
539 <td colspan='3' style='color:red'>
540 <?php echo $pdrow['genericval2'] ?>
541 </td>
542 </tr>
543 <?php } ?>
544 <tr>
545 <td height="1">
546 </td>
547 </tr>
548 </table>
550 <table border='0' cellpadding='2' cellspacing='0' width='98%'>
552 <tr bgcolor="#cccccc">
553 <td class="dehead">
554 <?php xl('Code','e')?>
555 </td>
556 <td class="dehead" align="right">
557 <?php xl('Charge','e')?>
558 </td>
559 <td class="dehead" align="right">
560 <?php xl('Balance','e')?>&nbsp;
561 </td>
562 <td class="dehead">
563 <?php xl('By/Source','e')?>
564 </td>
565 <td class="dehead">
566 <?php xl('Date','e')?>
567 </td>
568 <td class="dehead">
569 <?php xl('Pay','e')?>
570 </td>
571 <td class="dehead">
572 <?php xl('Adjust','e')?>
573 </td>
574 <td class="dehead">
575 <?php xl('Reason','e')?>
576 </td>
577 </tr>
578 <?php
579 $encount = 0;
580 foreach ($codes as $code => $cdata) {
581 ++$encount;
582 $bgcolor = "#" . (($encount & 1) ? "ddddff" : "ffdddd");
583 $dispcode = $code;
584 // this sorts the details more or less chronologically:
585 ksort($cdata['dtl']);
586 foreach ($cdata['dtl'] as $dkey => $ddata) {
587 $ddate = substr($dkey, 0, 10);
588 if (preg_match('/^(\d\d\d\d)(\d\d)(\d\d)\s*$/', $ddate, $matches)) {
589 $ddate = $matches[1] . '-' . $matches[2] . '-' . $matches[3];
591 $tmpchg = "";
592 $tmpadj = "";
593 /*****************************************************************
594 if ($ddata['chg'] > 0)
595 $tmpchg = $ddata['chg'];
596 else if ($ddata['chg'] < 0)
597 $tmpadj = 0 - $ddata['chg'];
598 *****************************************************************/
599 if ($ddata['chg'] != 0) {
600 if (isset($ddata['rsn'])) $tmpadj = 0 - $ddata['chg'];
601 else $tmpchg = $ddata['chg'];
604 <tr bgcolor='<?php echo $bgcolor ?>'>
605 <td class="detail">
606 <?php echo $dispcode; $dispcode = "" ?>
607 </td>
608 <td class="detail" align="right">
609 <?php bucks($tmpchg) ?>
610 </td>
611 <td class="detail" align="right">
612 &nbsp;
613 </td>
614 <td class="detail">
615 <?php
616 if (isset($ddata['plv'])) {
617 if (!$ddata['plv']) echo 'Pt/';
618 else echo 'Ins' . $ddata['plv'] . '/';
620 echo $ddata['src'];
622 </td>
623 <td class="detail">
624 <?php echo $ddate ?>
625 </td>
626 <td class="detail">
627 <?php bucks($ddata['pmt']) ?>
628 </td>
629 <td class="detail">
630 <?php bucks($tmpadj) ?>
631 </td>
632 <td class="detail">
633 <?php echo $ddata['rsn'] ?>
634 </td>
635 </tr>
636 <?php
637 } // end of prior detail line
639 <tr bgcolor='<?php echo $bgcolor ?>'>
640 <td class="detail">
641 <?php echo $dispcode; $dispcode = "" ?>
642 </td>
643 <td class="detail" align="right">
644 &nbsp;
645 </td>
646 <td class="detail" align="right">
647 <input type="hidden" name="form_line[<?php echo $code ?>][bal]" value="<?php bucks($cdata['bal']) ?>">
648 <input type="hidden" name="form_line[<?php echo $code ?>][ins]" value="<?php echo $cdata['ins'] ?>">
649 <?php printf("%.2f", $cdata['bal']) ?>&nbsp;
650 </td>
651 <td class="detail">
653 <?php if (!$INTEGRATED_AR) { ?>
654 <input type="text" name="form_line[<?php echo $code ?>][src]" size="10"
655 style="background-color:<?php echo $bgcolor ?>" />
656 <!-- title="NM=notmet, CI=coins, CP=copay, NE=notelig, IT=insterm, PF=ptfull, PP=ptpart" -->
657 <?php } ?>
659 </td>
660 <td class="detail">
662 <?php if (!$INTEGRATED_AR) { ?>
663 <input type="text" name="form_line[<?php echo $code ?>][date]" size="10"
664 style="background-color:<?php echo $bgcolor ?>" />
665 <?php } ?>
667 </td>
668 <td class="detail">
669 <input type="text" name="form_line[<?php echo $code ?>][pay]" size="10"
670 style="background-color:<?php echo $bgcolor ?>" />
671 </td>
672 <td class="detail">
673 <input type="text" name="form_line[<?php echo $code ?>][adj]" size="10"
674 style="background-color:<?php echo $bgcolor ?>" />
675 &nbsp; <a href="" onclick="return writeoff('<?php echo $code ?>')">W</a>
676 </td>
677 <td class="detail">
678 <select name="form_line[<?php echo $code ?>][reason]"
679 style="background-color:<?php echo $bgcolor ?>">
680 <?php
681 // Adjustment reasons are now taken from the list_options table.
682 echo " <option value=''></option>\n";
683 $ores = sqlStatement("SELECT option_id, title FROM list_options " .
684 "WHERE list_id = 'adjreason' ORDER BY seq, title");
685 while ($orow = sqlFetchArray($ores)) {
686 echo " <option value='" . addslashes($orow['option_id']) . "'";
687 echo ">" . $orow['title'] . "</option>\n";
690 </select>
691 <?php
692 // TBD: Maybe a comment field would be good here, for appending
693 // to the reason.
695 </td>
696 </tr>
697 <?php
698 } // end of code
699 if (!$INTEGRATED_AR) SLClose();
702 </table>
703 </form>
704 </center>
705 <script language="JavaScript">
706 var f1 = opener.document.forms[0];
707 var f2 = document.forms[0];
708 if (f1.form_source) {
709 <?php
710 if ($INTEGRATED_AR) {
711 // These support creation and lookup of ar_session table entries:
712 echo " f2.form_reference.value = f1.form_source.value;\n";
713 echo " f2.form_check_date.value = f1.form_paydate.value;\n";
714 echo " f2.form_deposit_date.value = f1.form_deposit_date.value;\n";
715 echo " f2.form_payer_id.value = f1.form_payer_id.value;\n";
716 echo " f2.form_pay_total.value = f1.form_amount.value;\n";
717 echo " f2.form_orig_reference.value = f1.form_source.value;\n";
718 echo " f2.form_orig_check_date.value = f1.form_paydate.value;\n";
719 echo " f2.form_orig_deposit_date.value = f1.form_deposit_date.value;\n";
721 // While I'm thinking about it, some notes about eob sessions.
722 // If they do not have all of the session key fields in the search
723 // page, then show a warning at the top of the invoice page.
724 // Also when they go to save the invoice page and a session key
725 // field has changed, alert them to that and allow a cancel.
727 // Another point... when posting EOBs, the incoming payer ID might
728 // not match the payer ID for the patient's insurance. This is
729 // because the same payer might be entered more than once into the
730 // insurance_companies table. I don't think it matters much.
732 else {
733 foreach ($codes as $code => $cdata) {
734 echo " f2['form_line[$code][src]'].value = f1.form_source.value;\n";
735 echo " f2['form_line[$code][date]'].value = f1.form_paydate.value;\n";
740 setins("Ins1");
741 </script>
742 </body>
743 </html>