migrated ubiquitous libraries to composer autoloader (#421)
[openemr.git] / interface / billing / sl_eob_invoice.php
blob57855a00c5067186e0f544cca4b94a6111abff30
1 <?php
2 /**
3 * This provides for manual posting of EOBs. It is invoked from
4 * sl_eob_search.php. For automated (X12 835) remittance posting
5 * see sl_eob_process.php.
7 * Copyright (C) 2005-2016 Rod Roark <rod@sunsetsystems.com>
8 *
9 * LICENSE: This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
20 * @package OpenEMR
21 * @author Rod Roark <rod@sunsetsystems.com>
22 * @author Roberto Vasquez <robertogagliotta@gmail.com>
23 * @author Terry Hill <terry@lillysystems.com>
24 * @link http://www.open-emr.org
27 require_once("../globals.php");
28 require_once("$srcdir/log.inc");
29 require_once("$srcdir/patient.inc");
30 require_once("$srcdir/forms.inc");
31 require_once("$srcdir/sl_eob.inc.php");
32 require_once("$srcdir/invoice_summary.inc.php");
33 require_once("../../custom/code_types.inc.php");
35 $debug = 0; // set to 1 for debugging mode
38 // If we permit deletion of transactions. Might change this later.
39 $ALLOW_DELETE = true;
41 $info_msg = "";
43 // Format money for display.
45 function bucks($amount) {
46 if ($amount)
47 printf("%.2f", $amount);
50 // Delete rows, with logging, for the specified table using the
51 // specified WHERE clause. Borrowed from deleter.php.
53 function row_delete($table, $where) {
54 $tres = sqlStatement("SELECT * FROM $table WHERE $where");
55 $count = 0;
56 while ($trow = sqlFetchArray($tres)) {
57 $logstring = "";
58 foreach ($trow as $key => $value) {
59 if (! $value || $value == '0000-00-00 00:00:00') continue;
60 if ($logstring) $logstring .= " ";
61 $logstring .= $key . "='" . addslashes($value) . "'";
63 newEvent("delete", $_SESSION['authUser'], $_SESSION['authProvider'], 1, "$table: $logstring");
64 ++$count;
66 if ($count) {
67 $query = "DELETE FROM $table WHERE $where";
68 echo $query . "<br>\n";
69 sqlStatement($query);
73 <html>
74 <head>
75 <?php html_header_show(); ?>
76 <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
77 <title><?php xl('EOB Posting - Invoice','e')?></title>
78 <script language="JavaScript">
80 // An insurance radio button is selected.
81 function setins(istr) {
82 return true;
85 // Compute an adjustment that writes off the balance:
86 function writeoff(code) {
87 var f = document.forms[0];
88 var belement = f['form_line[' + code + '][bal]'];
89 var pelement = f['form_line[' + code + '][pay]'];
90 var aelement = f['form_line[' + code + '][adj]'];
91 var relement = f['form_line[' + code + '][reason]'];
92 var tmp = belement.value - pelement.value;
93 aelement.value = Number(tmp).toFixed(2);
94 if (aelement.value && ! relement.value) relement.selectedIndex = 1;
95 return false;
98 // Onsubmit handler. A good excuse to write some JavaScript.
99 function validate(f) {
100 var delcount = 0;
101 for (var i = 0; i < f.elements.length; ++i) {
102 var ename = f.elements[i].name;
103 // Count deletes.
104 if (ename.substring(0, 9) == 'form_del[') {
105 if (f.elements[i].checked) ++delcount;
106 continue;
108 var pfxlen = ename.indexOf('[pay]');
109 if (pfxlen < 0) continue;
110 var pfx = ename.substring(0, pfxlen);
111 var code = pfx.substring(pfx.indexOf('[')+1, pfxlen-1);
112 if (f[pfx+'[pay]'].value || f[pfx+'[adj]'].value) {
113 if (! f[pfx+'[date]'].value) {
114 alert('<?php xl('Date is missing for code ','e')?>' + code);
115 return false;
118 if (f[pfx+'[pay]'].value && isNaN(parseFloat(f[pfx+'[pay]'].value))) {
119 alert('<?php xl('Payment value for code ','e') ?>' + code + '<?php xl(' is not a number','e') ?>');
120 return false;
122 if (f[pfx+'[adj]'].value && isNaN(parseFloat(f[pfx+'[adj]'].value))) {
123 alert('<?php xl('Adjustment value for code ','e') ?>' + code + '<?php xl(' is not a number','e') ?>');
124 return false;
126 if (f[pfx+'[adj]'].value && ! f[pfx+'[reason]'].value) {
127 alert('<?php xl('Please select an adjustment reason for code ','e') ?>' + code);
128 return false;
130 // TBD: validate the date format
132 // Demand confirmation if deleting anything.
133 if (delcount > 0) {
134 if (!confirm('<?php echo xl('Really delete'); ?> ' + delcount +
135 ' <?php echo xl('transactions'); ?>?' +
136 ' <?php echo xl('This action will be logged'); ?>!')
137 ) return false;
139 return true;
142 <!-- Get current date -->
144 function getFormattedToday()
146 var today = new Date();
147 var dd = today.getDate();
148 var mm = today.getMonth()+1; //January is 0!
149 var yyyy = today.getFullYear();
150 if(dd<10){dd='0'+dd}
151 if(mm<10){mm='0'+mm}
153 return (yyyy + '-' + mm + '-' + dd);
156 <!-- Update Payment Fields -->
158 function updateFields(payField, adjField, balField, coPayField, isFirstProcCode)
160 var payAmount = 0.0;
161 var adjAmount = 0.0;
162 var balAmount = 0.0;
163 var coPayAmount = 0.0;
165 // coPayFiled will be null if there is no co-pay entry in the fee sheet
166 if (coPayField)
167 coPayAmount = coPayField.value;
169 // if balance field is 0.00, its value comes back as null, so check for nul-ness first
170 if (balField)
171 balAmount = (balField.value) ? balField.value : 0;
172 if (payField)
173 payAmount = (payField.value) ? payField.value : 0;
175 //alert('balance = >' + balAmount +'< payAmount = ' + payAmount + ' copay = ' + coPayAmount + ' isFirstProcCode = ' + isFirstProcCode);
177 // subtract the co-pay only from the first procedure code
178 if (isFirstProcCode == 1)
179 balAmount = parseFloat(balAmount) + parseFloat(coPayAmount);
181 adjAmount = balAmount - payAmount;
183 // Assign rounded adjustment value back to TextField
184 adjField.value = adjAmount = Math.round(adjAmount*100)/100;
187 </script>
188 </head>
189 <body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>
190 <?php
191 $trans_id = 0 + $_GET['id'];
192 if (! $trans_id) die(xl("You cannot access this page directly."));
194 // A/R case, $trans_id matches form_encounter.id.
195 $ferow = sqlQuery("SELECT e.*, p.fname, p.mname, p.lname " .
196 "FROM form_encounter AS e, patient_data AS p WHERE " .
197 "e.id = '$trans_id' AND p.pid = e.pid");
198 if (empty($ferow)) die("There is no encounter with form_encounter.id = '$trans_id'.");
199 $patient_id = 0 + $ferow['pid'];
200 $encounter_id = 0 + $ferow['encounter'];
201 $svcdate = substr($ferow['date'], 0, 10);
202 $form_payer_id = 0 + $_POST['form_payer_id'];
203 $form_reference = $_POST['form_reference'];
204 $form_check_date = fixDate($_POST['form_check_date'], date('Y-m-d'));
205 $form_deposit_date = fixDate($_POST['form_deposit_date'], $form_check_date);
206 $form_pay_total = 0 + $_POST['form_pay_total'];
208 $payer_type = 0;
209 if (preg_match('/^Ins(\d)/i', $_POST['form_insurance'], $matches)) {
210 $payer_type = $matches[1];
213 if ($_POST['form_save'] || $_POST['form_cancel']) {
214 if ($_POST['form_save']) {
215 if ($debug) {
216 echo xl("This module is in test mode. The database will not be changed.",'','<p><b>',"</b><p>\n");
219 $session_id = arGetSession($form_payer_id, $form_reference,
220 $form_check_date, $form_deposit_date, $form_pay_total);
221 // The sl_eob_search page needs its invoice links modified to invoke
222 // javascript to load form parms for all the above and submit.
223 // At the same time that page would be modified to work off the
224 // openemr database exclusively.
225 // And back to the sl_eob_invoice page, I think we may want to move
226 // the source input fields from row level to header level.
228 // Handle deletes. row_delete() is borrowed from deleter.php.
229 if ($ALLOW_DELETE && !$debug) {
230 foreach ($_POST['form_del'] as $arseq => $dummy) {
231 row_delete("ar_activity", "pid = '$patient_id' AND " .
232 "encounter = '$encounter_id' AND sequence_no = '$arseq'");
236 $paytotal = 0;
237 foreach ($_POST['form_line'] as $code => $cdata) {
238 $thispay = trim($cdata['pay']);
239 $thisadj = trim($cdata['adj']);
240 $thisins = trim($cdata['ins']);
241 $thiscodetype = trim($cdata['code_type']);
242 $reason = strip_escape_custom($cdata['reason']);
244 // Get the adjustment reason type. Possible values are:
245 // 1 = Charge adjustment
246 // 2 = Coinsurance
247 // 3 = Deductible
248 // 4 = Other pt resp
249 // 5 = Comment
250 $reason_type = '1';
251 if ($reason) {
252 $tmp = sqlQuery("SELECT option_value FROM list_options WHERE " .
253 "list_id = 'adjreason' AND activity = 1 AND " .
254 "option_id = '" . add_escape_custom($reason) . "'");
255 if (empty($tmp['option_value'])) {
256 // This should not happen but if it does, apply old logic.
257 if (preg_match("/To copay/", $reason)) {
258 $reason_type = 2;
260 else if (preg_match("/To ded'ble/", $reason)) {
261 $reason_type = 3;
263 $info_msg .= xl("No adjustment reason type found for") . " \"$reason\". ";
265 else {
266 $reason_type = $tmp['option_value'];
270 if (! $thisins) $thisins = 0;
272 if ($thispay) {
273 arPostPayment($patient_id, $encounter_id, $session_id,
274 $thispay, $code, $payer_type, '', $debug, '', $thiscodetype);
275 $paytotal += $thispay;
278 // Be sure to record adjustment reasons, even for zero adjustments if
279 // they happen to be comments.
280 if ($thisadj || ($reason && $reason_type == 5)) {
281 // "To copay" and "To ded'ble" need to become a comment in a zero
282 // adjustment, formatted just like sl_eob_process.php.
283 if ($reason_type == '2') {
284 $reason = $_POST['form_insurance'] . " coins: $thisadj";
285 $thisadj = 0;
287 else if ($reason_type == '3') {
288 $reason = $_POST['form_insurance'] . " dedbl: $thisadj";
289 $thisadj = 0;
291 else if ($reason_type == '4') {
292 $reason = $_POST['form_insurance'] . " ptresp: $thisadj $reason";
293 $thisadj = 0;
295 else if ($reason_type == '5') {
296 $reason = $_POST['form_insurance'] . " note: $thisadj $reason";
297 $thisadj = 0;
299 else {
300 // An adjustment reason including "Ins" is assumed to be assigned by
301 // insurance, and in that case we identify which one by appending
302 // Ins1, Ins2 or Ins3.
303 if (strpos(strtolower($reason), 'ins') !== false)
304 $reason .= ' ' . $_POST['form_insurance'];
306 arPostAdjustment($patient_id, $encounter_id, $session_id,
307 $thisadj, $code, $payer_type, $reason, $debug, '', $thiscodetype);
311 // Maintain which insurances are marked as finished.
313 $form_done = 0 + $_POST['form_done'];
314 $form_stmt_count = 0 + $_POST['form_stmt_count'];
315 sqlStatement("UPDATE form_encounter " .
316 "SET last_level_closed = $form_done, " .
317 "stmt_count = $form_stmt_count WHERE " .
318 "pid = '$patient_id' AND encounter = '$encounter_id'");
320 if ($_POST['form_secondary']) {
321 arSetupSecondary($patient_id, $encounter_id, $debug);
324 echo "<script language='JavaScript'>\n";
325 echo " if (opener.document.forms[0].form_amount) {\n";
326 echo " var tmp = opener.document.forms[0].form_amount.value - $paytotal;\n";
327 echo " opener.document.forms[0].form_amount.value = Number(tmp).toFixed(2);\n";
328 echo " }\n";
329 } else {
330 echo "<script language='JavaScript'>\n";
332 if ($info_msg) echo " alert('" . addslashes($info_msg) . "');\n";
333 if (! $debug) echo " window.close();\n";
334 echo "</script></body></html>\n";
335 exit();
338 // Get invoice charge details.
339 $codes = ar_get_invoice_summary($patient_id, $encounter_id, true);
341 $pdrow = sqlQuery("select billing_note " .
342 "from patient_data where pid = '$patient_id' limit 1");
344 <center>
346 <form method='post' action='sl_eob_invoice.php?id=<?php echo $trans_id ?>'
347 onsubmit='return validate(this)'>
349 <table border='0' cellpadding='3'>
350 <tr>
351 <td>
352 <?php xl('Patient:','e')?>
353 </td>
354 <td>
355 <?php
356 echo $ferow['fname'] . ' ' . $ferow['mname'] . ' ' . $ferow['lname'];
358 </td>
359 <td colspan="2" rowspan="3">
360 <?php
361 for ($i = 1; $i <= 3; ++$i) {
362 $payerid = arGetPayerID($patient_id, $svcdate, $i);
363 if ($payerid) {
364 $tmp = sqlQuery("SELECT name FROM insurance_companies WHERE id = $payerid");
365 echo "Ins$i: " . $tmp['name'] . "<br />";
369 </td>
370 <?php
371 echo "<td rowspan='3' valign='bottom'>\n";
372 echo xl('Statements Sent:');
373 echo "</td>\n";
374 echo "<td rowspan='3' valign='bottom'>\n";
375 echo "<input type='text' name='form_stmt_count' size='10' value='" .
376 (0 + $ferow['stmt_count']) . "' />\n";
377 echo "</td>\n";
379 </tr>
380 <tr>
381 <td>
382 <?php xl('Provider:','e')?>
383 </td>
384 <td>
385 <?php
386 $tmp = sqlQuery("SELECT fname, mname, lname " .
387 "FROM users WHERE id = " . $ferow['provider_id']);
388 echo text($tmp['fname']) . ' ' . text($tmp['mname']) . ' ' . text($tmp['lname']);
389 $tmp = sqlQuery("SELECT bill_date FROM billing WHERE " .
390 "pid = '$patient_id' AND encounter = '$encounter_id' AND " .
391 "activity = 1 ORDER BY fee DESC, id ASC LIMIT 1");
392 $billdate = substr(($tmp['bill_date'] . "Not Billed"), 0, 10);
394 </td>
395 </tr>
396 <tr>
397 <td>
398 <?php xl('Invoice:','e')?>
399 </td>
400 <td>
401 <?php
402 echo "$patient_id.$encounter_id";
404 </td>
405 </tr>
407 <tr>
408 <td>
409 <?php xl('Svc Date:','e'); ?>
410 </td>
411 <td>
412 <?php
413 echo $svcdate;
415 </td>
416 <td colspan="2">
417 <?php xl('Done with:','e','',"&nbsp")?>;
418 <?php
419 // Write a checkbox for each insurance. It is to be checked when
420 // we no longer expect any payments from that company for the claim.
421 $last_level_closed = 0 + $ferow['last_level_closed'];
422 foreach (array(0 => 'None', 1 => 'Ins1', 2 => 'Ins2', 3 => 'Ins3') as $key => $value) {
423 if ($key && !arGetPayerID($patient_id, $svcdate, $key)) continue;
424 $checked = ($last_level_closed == $key) ? " checked" : "";
425 echo " <input type='radio' name='form_done' value='$key'$checked />$value&nbsp;\n";
428 </td>
429 <?php
430 echo "<td>\n";
431 echo xl('Check/EOB No.:');
432 echo "</td>\n";
433 echo "<td>\n";
434 echo "<input type='text' name='form_reference' size='10' value='' />\n";
435 echo "</td>\n";
437 </tr>
439 <tr>
440 <td>
441 <?php xl('Last Bill Date:','e') ?>
442 </td>
443 <td>
444 <?php
445 echo $billdate;
447 </td>
448 <td colspan="2">
449 <?php xl('Now posting for:','e','',"&nbsp")?>;
451 <?php
452 // TBD: check the first not-done-with insurance, not always Ins1!
454 <input type='radio' name='form_insurance' value='Ins1' onclick='setins("Ins1")' checked /><?php xl('Ins1','e')?>&nbsp;
455 <input type='radio' name='form_insurance' value='Ins2' onclick='setins("Ins2")' /><?php xl('Ins2','e')?>&nbsp;
456 <input type='radio' name='form_insurance' value='Ins3' onclick='setins("Ins3")' /><?php xl('Ins3','e')?>&nbsp;
457 <input type='radio' name='form_insurance' value='Pt' onclick='setins("Pt")' /><?php xl('Patient','e')?>
459 <?php
460 // TBD: I think the following is unused and can be removed.
462 <input type='hidden' name='form_eobs' value='<?php echo addslashes($arrow['shipvia']) ?>' />
464 </td>
465 <?php
466 echo "<td>\n";
467 echo xl('Check/EOB Date:');
468 echo "</td>\n";
469 echo "<td>\n";
470 echo "<input type='text' name='form_check_date' size='10' value='' />\n";
471 echo "</td>\n";
473 </tr>
474 <tr>
475 <td>
476 </td>
477 <td>
478 </td>
479 <td colspan="2">
480 <input type="checkbox" name="form_secondary" value="1"> <?php xl('Needs secondary billing','e')?>
481 &nbsp;&nbsp;
482 <input type='submit' name='form_save' value='<?php xl('Save','e')?>'>
483 &nbsp;
484 <input type='button' value='<?php xl('Cancel','e')?>' onclick='window.close()'>
485 </td>
486 <?php
487 echo "<td>\n";
488 echo xl('Deposit Date:');
489 echo "</td>\n";
490 echo "<td>\n";
491 echo "<input type='text' name='form_deposit_date' size='10' value='' />\n";
492 echo "<input type='hidden' name='form_payer_id' value='' />\n";
493 echo "<input type='hidden' name='form_orig_reference' value='' />\n";
494 echo "<input type='hidden' name='form_orig_check_date' value='' />\n";
495 echo "<input type='hidden' name='form_orig_deposit_date' value='' />\n";
496 echo "<input type='hidden' name='form_pay_total' value='' />\n";
497 echo "</td>\n";
499 </tr>
500 <?php if (!empty($pdrow['billing_note'])) { ?>
501 <tr>
502 <td>
503 <?php xl('Billing Note:','e')?>
504 </td>
505 <td colspan='3' style='color:red'>
506 <?php echo $pdrow['billing_note'] ?>
507 </td>
508 </tr>
509 <?php } ?>
510 <tr>
511 <td height="1">
512 </td>
513 </tr>
514 </table>
516 <table border='0' cellpadding='2' cellspacing='0' width='98%'>
518 <tr bgcolor="#cccccc">
519 <td class="dehead">
520 <?php xl('Code','e')?>
521 </td>
522 <td class="dehead" align="right">
523 <?php xl('Charge','e')?>
524 </td>
525 <td class="dehead" align="right">
526 <?php xl('Balance','e')?>&nbsp;
527 </td>
528 <td class="dehead">
529 <?php xl('By/Source','e')?>
530 </td>
531 <td class="dehead">
532 <?php xl('Date','e')?>
533 </td>
534 <td class="dehead">
535 <?php xl('Pay','e')?>
536 </td>
537 <td class="dehead">
538 <?php xl('Adjust','e')?>
539 </td>
540 <td class="dehead">
541 <?php xl('Reason','e')?>
542 </td>
543 <?php if ($ALLOW_DELETE) { ?>
544 <td class="dehead">
545 <?php xl('Del','e')?>
546 </td>
547 <?php } ?>
548 </tr>
549 <?php
550 $firstProcCodeIndex = -1;
551 $encount = 0;
552 foreach ($codes as $code => $cdata) {
553 ++$encount;
554 $bgcolor = "#" . (($encount & 1) ? "ddddff" : "ffdddd");
555 $dispcode = $code;
557 // remember the index of the first entry whose code is not "CO-PAY", i.e. it's a legitimate proc code
558 if ($firstProcCodeIndex == -1 && strcmp($code, "CO-PAY") !=0)
559 $firstProcCodeIndex = $encount;
561 // this sorts the details more or less chronologically:
562 ksort($cdata['dtl']);
563 foreach ($cdata['dtl'] as $dkey => $ddata) {
564 $ddate = substr($dkey, 0, 10);
565 if (preg_match('/^(\d\d\d\d)(\d\d)(\d\d)\s*$/', $ddate, $matches)) {
566 $ddate = $matches[1] . '-' . $matches[2] . '-' . $matches[3];
568 $tmpchg = "";
569 $tmpadj = "";
570 /*****************************************************************
571 if ($ddata['chg'] > 0)
572 $tmpchg = $ddata['chg'];
573 else if ($ddata['chg'] < 0)
574 $tmpadj = 0 - $ddata['chg'];
575 *****************************************************************/
576 if ($ddata['chg'] != 0) {
577 if (isset($ddata['rsn'])) $tmpadj = 0 - $ddata['chg'];
578 else $tmpchg = $ddata['chg'];
581 <tr bgcolor='<?php echo $bgcolor ?>'>
582 <td class="detail">
583 <?php echo $dispcode; $dispcode = "" ?>
584 </td>
585 <td class="detail" align="right">
586 <?php bucks($tmpchg) ?>
587 </td>
588 <td class="detail" align="right">
589 &nbsp;
590 </td>
591 <td class="detail">
592 <?php
593 if (isset($ddata['plv'])) {
594 if (!$ddata['plv']) echo 'Pt/';
595 else echo 'Ins' . $ddata['plv'] . '/';
597 echo $ddata['src'];
599 </td>
600 <td class="detail">
601 <?php echo $ddate ?>
602 </td>
603 <td class="detail">
604 <?php bucks($ddata['pmt']) ?>
605 </td>
606 <td class="detail">
607 <?php bucks($tmpadj) ?>
608 </td>
609 <td class="detail">
610 <?php echo $ddata['rsn'] ?>
611 </td>
612 <?php if ($ALLOW_DELETE) { ?>
613 <td class="detail">
614 <?php if (!empty($ddata['arseq'])) { ?>
615 <input type="checkbox" name="form_del[<?php echo $ddata['arseq']; ?>]" />
616 <?php } else { ?>
617 &nbsp;
618 <?php } ?>
619 </td>
620 <?php } ?>
621 </tr>
622 <?php
623 } // end of prior detail line
625 <tr bgcolor='<?php echo $bgcolor ?>'>
626 <td class="detail">
627 <?php echo $dispcode; $dispcode = "" ?>
628 </td>
629 <td class="detail" align="right">
630 &nbsp;
631 </td>
632 <td class="detail" align="right">
633 <input type="hidden" name="form_line[<?php echo $code ?>][bal]" value="<?php bucks($cdata['bal']) ?>">
634 <input type="hidden" name="form_line[<?php echo $code ?>][ins]" value="<?php echo $cdata['ins'] ?>">
635 <input type="hidden" name="form_line[<?php echo $code ?>][code_type]" value="<?php echo $cdata['code_type'] ?>">
636 <?php printf("%.2f", $cdata['bal']) ?>&nbsp;
637 </td>
638 <td class="detail">
641 </td>
642 <td class="detail">
645 </td>
646 <td class="detail">
647 <input type="text" name="form_line[<?php echo $code ?>][pay]" size="10"
648 style="background-color:<?php echo $bgcolor ?>"
649 onKeyUp="updateFields(document.forms[0]['form_line[<?php echo $code ?>][pay]'],
650 document.forms[0]['form_line[<?php echo $code ?>][adj]'],
651 document.forms[0]['form_line[<?php echo $code ?>][bal]'],
652 document.forms[0]['form_line[CO-PAY][bal]'],
653 <?php echo ($firstProcCodeIndex == $encount) ? 1 : 0 ?>)"/>
654 </td>
655 <td class="detail">
656 <input type="text" name="form_line[<?php echo $code ?>][adj]" size="10"
657 value='<?php echo $totalAdjAmount ?>'
658 style="background-color:<?php echo $bgcolor ?>" />
659 &nbsp; <a href="" onclick="return writeoff('<?php echo $code ?>')">W</a>
660 </td>
661 <td class="detail">
662 <select name="form_line[<?php echo $code ?>][reason]"
663 style="background-color:<?php echo $bgcolor ?>">
664 <?php
665 // Adjustment reasons are now taken from the list_options table.
666 echo " <option value=''></option>\n";
667 $ores = sqlStatement("SELECT option_id, title, is_default FROM list_options " .
668 "WHERE list_id = 'adjreason' AND activity = 1 ORDER BY seq, title");
669 while ($orow = sqlFetchArray($ores)) {
670 echo " <option value='" . htmlspecialchars($orow['option_id'], ENT_QUOTES) . "'";
671 if ($orow['is_default']) echo " selected";
672 echo ">" . htmlspecialchars($orow['title']) . "</option>\n";
676 </select>
677 <?php
678 // TBD: Maybe a comment field would be good here, for appending
679 // to the reason.
681 </td>
683 <?php if ($ALLOW_DELETE) { ?>
684 <td class="detail">
685 &nbsp;
686 </td>
687 <?php } ?>
689 </tr>
690 <?php
691 } // end of code
694 </table>
695 </form>
696 </center>
697 <script language="JavaScript">
698 var f1 = opener.document.forms[0];
699 var f2 = document.forms[0];
700 if (f1.form_source) {
701 <?php
702 // These support creation and lookup of ar_session table entries:
703 echo " f2.form_reference.value = f1.form_source.value;\n";
704 echo " f2.form_check_date.value = f1.form_paydate.value;\n";
705 echo " //f2.form_deposit_date.value = f1.form_deposit_date.value;\n";
706 echo " if (f1.form_deposit_date.value != '')\n";
707 echo " f2.form_deposit_date.value = f1.form_deposit_date.value;\n";
708 echo " else\n";
709 echo " f2.form_deposit_date.value = getFormattedToday();\n";
710 echo " f2.form_payer_id.value = f1.form_payer_id.value;\n";
711 echo " f2.form_pay_total.value = f1.form_amount.value;\n";
712 echo " f2.form_orig_reference.value = f1.form_source.value;\n";
713 echo " f2.form_orig_check_date.value = f1.form_paydate.value;\n";
714 echo " f2.form_orig_deposit_date.value = f1.form_deposit_date.value;\n";
716 // While I'm thinking about it, some notes about eob sessions.
717 // If they do not have all of the session key fields in the search
718 // page, then show a warning at the top of the invoice page.
719 // Also when they go to save the invoice page and a session key
720 // field has changed, alert them to that and allow a cancel.
722 // Another point... when posting EOBs, the incoming payer ID might
723 // not match the payer ID for the patient's insurance. This is
724 // because the same payer might be entered more than once into the
725 // insurance_companies table. I don't think it matters much.
728 setins("Ins1");
729 </script>
730 </body>
731 </html>