Feature to add drug-drug interaction checking for the
[openemr.git] / interface / billing / sl_eob_invoice.php
blobc6c5f2a2fb408cd0b109359df14f68466d5fdf59
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");
34 require_once("$srcdir/formdata.inc.php");
36 $debug = 0; // set to 1 for debugging mode
39 // If we permit deletion of transactions. Might change this later.
40 $ALLOW_DELETE = true;
42 $info_msg = "";
44 // Format money for display.
46 function bucks($amount) {
47 if ($amount)
48 printf("%.2f", $amount);
51 // Delete rows, with logging, for the specified table using the
52 // specified WHERE clause. Borrowed from deleter.php.
54 function row_delete($table, $where) {
55 $tres = sqlStatement("SELECT * FROM $table WHERE $where");
56 $count = 0;
57 while ($trow = sqlFetchArray($tres)) {
58 $logstring = "";
59 foreach ($trow as $key => $value) {
60 if (! $value || $value == '0000-00-00 00:00:00') continue;
61 if ($logstring) $logstring .= " ";
62 $logstring .= $key . "='" . addslashes($value) . "'";
64 newEvent("delete", $_SESSION['authUser'], $_SESSION['authProvider'], 1, "$table: $logstring");
65 ++$count;
67 if ($count) {
68 $query = "DELETE FROM $table WHERE $where";
69 echo $query . "<br>\n";
70 sqlStatement($query);
74 <html>
75 <head>
76 <?php html_header_show(); ?>
77 <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
78 <title><?php xl('EOB Posting - Invoice','e')?></title>
79 <script language="JavaScript">
81 // An insurance radio button is selected.
82 function setins(istr) {
83 return true;
86 // Compute an adjustment that writes off the balance:
87 function writeoff(code) {
88 var f = document.forms[0];
89 var belement = f['form_line[' + code + '][bal]'];
90 var pelement = f['form_line[' + code + '][pay]'];
91 var aelement = f['form_line[' + code + '][adj]'];
92 var relement = f['form_line[' + code + '][reason]'];
93 var tmp = belement.value - pelement.value;
94 aelement.value = Number(tmp).toFixed(2);
95 if (aelement.value && ! relement.value) relement.selectedIndex = 1;
96 return false;
99 // Onsubmit handler. A good excuse to write some JavaScript.
100 function validate(f) {
101 var delcount = 0;
102 for (var i = 0; i < f.elements.length; ++i) {
103 var ename = f.elements[i].name;
104 // Count deletes.
105 if (ename.substring(0, 9) == 'form_del[') {
106 if (f.elements[i].checked) ++delcount;
107 continue;
109 var pfxlen = ename.indexOf('[pay]');
110 if (pfxlen < 0) continue;
111 var pfx = ename.substring(0, pfxlen);
112 var code = pfx.substring(pfx.indexOf('[')+1, pfxlen-1);
113 if (f[pfx+'[pay]'].value || f[pfx+'[adj]'].value) {
114 if (! f[pfx+'[date]'].value) {
115 alert('<?php xl('Date is missing for code ','e')?>' + code);
116 return false;
119 if (f[pfx+'[pay]'].value && isNaN(parseFloat(f[pfx+'[pay]'].value))) {
120 alert('<?php xl('Payment value for code ','e') ?>' + code + '<?php xl(' is not a number','e') ?>');
121 return false;
123 if (f[pfx+'[adj]'].value && isNaN(parseFloat(f[pfx+'[adj]'].value))) {
124 alert('<?php xl('Adjustment value for code ','e') ?>' + code + '<?php xl(' is not a number','e') ?>');
125 return false;
127 if (f[pfx+'[adj]'].value && ! f[pfx+'[reason]'].value) {
128 alert('<?php xl('Please select an adjustment reason for code ','e') ?>' + code);
129 return false;
131 // TBD: validate the date format
133 // Demand confirmation if deleting anything.
134 if (delcount > 0) {
135 if (!confirm('<?php echo xl('Really delete'); ?> ' + delcount +
136 ' <?php echo xl('transactions'); ?>?' +
137 ' <?php echo xl('This action will be logged'); ?>!')
138 ) return false;
140 return true;
143 <!-- Get current date -->
145 function getFormattedToday()
147 var today = new Date();
148 var dd = today.getDate();
149 var mm = today.getMonth()+1; //January is 0!
150 var yyyy = today.getFullYear();
151 if(dd<10){dd='0'+dd}
152 if(mm<10){mm='0'+mm}
154 return (yyyy + '-' + mm + '-' + dd);
157 <!-- Update Payment Fields -->
159 function updateFields(payField, adjField, balField, coPayField, isFirstProcCode)
161 var payAmount = 0.0;
162 var adjAmount = 0.0;
163 var balAmount = 0.0;
164 var coPayAmount = 0.0;
166 // coPayFiled will be null if there is no co-pay entry in the fee sheet
167 if (coPayField)
168 coPayAmount = coPayField.value;
170 // if balance field is 0.00, its value comes back as null, so check for nul-ness first
171 if (balField)
172 balAmount = (balField.value) ? balField.value : 0;
173 if (payField)
174 payAmount = (payField.value) ? payField.value : 0;
176 //alert('balance = >' + balAmount +'< payAmount = ' + payAmount + ' copay = ' + coPayAmount + ' isFirstProcCode = ' + isFirstProcCode);
178 // subtract the co-pay only from the first procedure code
179 if (isFirstProcCode == 1)
180 balAmount = parseFloat(balAmount) + parseFloat(coPayAmount);
182 adjAmount = balAmount - payAmount;
184 // Assign rounded adjustment value back to TextField
185 adjField.value = adjAmount = Math.round(adjAmount*100)/100;
188 </script>
189 </head>
190 <body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>
191 <?php
192 $trans_id = 0 + $_GET['id'];
193 if (! $trans_id) die(xl("You cannot access this page directly."));
195 // A/R case, $trans_id matches form_encounter.id.
196 $ferow = sqlQuery("SELECT e.*, p.fname, p.mname, p.lname " .
197 "FROM form_encounter AS e, patient_data AS p WHERE " .
198 "e.id = '$trans_id' AND p.pid = e.pid");
199 if (empty($ferow)) die("There is no encounter with form_encounter.id = '$trans_id'.");
200 $patient_id = 0 + $ferow['pid'];
201 $encounter_id = 0 + $ferow['encounter'];
202 $svcdate = substr($ferow['date'], 0, 10);
203 $form_payer_id = 0 + $_POST['form_payer_id'];
204 $form_reference = $_POST['form_reference'];
205 $form_check_date = fixDate($_POST['form_check_date'], date('Y-m-d'));
206 $form_deposit_date = fixDate($_POST['form_deposit_date'], $form_check_date);
207 $form_pay_total = 0 + $_POST['form_pay_total'];
209 $payer_type = 0;
210 if (preg_match('/^Ins(\d)/i', $_POST['form_insurance'], $matches)) {
211 $payer_type = $matches[1];
214 if ($_POST['form_save'] || $_POST['form_cancel']) {
215 if ($_POST['form_save']) {
216 if ($debug) {
217 echo xl("This module is in test mode. The database will not be changed.",'','<p><b>',"</b><p>\n");
220 $session_id = arGetSession($form_payer_id, $form_reference,
221 $form_check_date, $form_deposit_date, $form_pay_total);
222 // The sl_eob_search page needs its invoice links modified to invoke
223 // javascript to load form parms for all the above and submit.
224 // At the same time that page would be modified to work off the
225 // openemr database exclusively.
226 // And back to the sl_eob_invoice page, I think we may want to move
227 // the source input fields from row level to header level.
229 // Handle deletes. row_delete() is borrowed from deleter.php.
230 if ($ALLOW_DELETE && !$debug) {
231 foreach ($_POST['form_del'] as $arseq => $dummy) {
232 row_delete("ar_activity", "pid = '$patient_id' AND " .
233 "encounter = '$encounter_id' AND sequence_no = '$arseq'");
237 $paytotal = 0;
238 foreach ($_POST['form_line'] as $code => $cdata) {
239 $thispay = trim($cdata['pay']);
240 $thisadj = trim($cdata['adj']);
241 $thisins = trim($cdata['ins']);
242 $thiscodetype = trim($cdata['code_type']);
243 $reason = strip_escape_custom($cdata['reason']);
245 // Get the adjustment reason type. Possible values are:
246 // 1 = Charge adjustment
247 // 2 = Coinsurance
248 // 3 = Deductible
249 // 4 = Other pt resp
250 // 5 = Comment
251 $reason_type = '1';
252 if ($reason) {
253 $tmp = sqlQuery("SELECT option_value FROM list_options WHERE " .
254 "list_id = 'adjreason' AND activity = 1 AND " .
255 "option_id = '" . add_escape_custom($reason) . "'");
256 if (empty($tmp['option_value'])) {
257 // This should not happen but if it does, apply old logic.
258 if (preg_match("/To copay/", $reason)) {
259 $reason_type = 2;
261 else if (preg_match("/To ded'ble/", $reason)) {
262 $reason_type = 3;
264 $info_msg .= xl("No adjustment reason type found for") . " \"$reason\". ";
266 else {
267 $reason_type = $tmp['option_value'];
271 if (! $thisins) $thisins = 0;
273 if ($thispay) {
274 arPostPayment($patient_id, $encounter_id, $session_id,
275 $thispay, $code, $payer_type, '', $debug, '', $thiscodetype);
276 $paytotal += $thispay;
279 // Be sure to record adjustment reasons, even for zero adjustments if
280 // they happen to be comments.
281 if ($thisadj || ($reason && $reason_type == 5)) {
282 // "To copay" and "To ded'ble" need to become a comment in a zero
283 // adjustment, formatted just like sl_eob_process.php.
284 if ($reason_type == '2') {
285 $reason = $_POST['form_insurance'] . " coins: $thisadj";
286 $thisadj = 0;
288 else if ($reason_type == '3') {
289 $reason = $_POST['form_insurance'] . " dedbl: $thisadj";
290 $thisadj = 0;
292 else if ($reason_type == '4') {
293 $reason = $_POST['form_insurance'] . " ptresp: $thisadj $reason";
294 $thisadj = 0;
296 else if ($reason_type == '5') {
297 $reason = $_POST['form_insurance'] . " note: $thisadj $reason";
298 $thisadj = 0;
300 else {
301 // An adjustment reason including "Ins" is assumed to be assigned by
302 // insurance, and in that case we identify which one by appending
303 // Ins1, Ins2 or Ins3.
304 if (strpos(strtolower($reason), 'ins') !== false)
305 $reason .= ' ' . $_POST['form_insurance'];
307 arPostAdjustment($patient_id, $encounter_id, $session_id,
308 $thisadj, $code, $payer_type, $reason, $debug, '', $thiscodetype);
312 // Maintain which insurances are marked as finished.
314 $form_done = 0 + $_POST['form_done'];
315 $form_stmt_count = 0 + $_POST['form_stmt_count'];
316 sqlStatement("UPDATE form_encounter " .
317 "SET last_level_closed = $form_done, " .
318 "stmt_count = $form_stmt_count WHERE " .
319 "pid = '$patient_id' AND encounter = '$encounter_id'");
321 if ($_POST['form_secondary']) {
322 arSetupSecondary($patient_id, $encounter_id, $debug);
325 echo "<script language='JavaScript'>\n";
326 echo " if (opener.document.forms[0].form_amount) {\n";
327 echo " var tmp = opener.document.forms[0].form_amount.value - $paytotal;\n";
328 echo " opener.document.forms[0].form_amount.value = Number(tmp).toFixed(2);\n";
329 echo " }\n";
330 } else {
331 echo "<script language='JavaScript'>\n";
333 if ($info_msg) echo " alert('" . addslashes($info_msg) . "');\n";
334 if (! $debug) echo " window.close();\n";
335 echo "</script></body></html>\n";
336 exit();
339 // Get invoice charge details.
340 $codes = ar_get_invoice_summary($patient_id, $encounter_id, true);
342 $pdrow = sqlQuery("select billing_note " .
343 "from patient_data where pid = '$patient_id' limit 1");
345 <center>
347 <form method='post' action='sl_eob_invoice.php?id=<?php echo $trans_id ?>'
348 onsubmit='return validate(this)'>
350 <table border='0' cellpadding='3'>
351 <tr>
352 <td>
353 <?php xl('Patient:','e')?>
354 </td>
355 <td>
356 <?php
357 echo $ferow['fname'] . ' ' . $ferow['mname'] . ' ' . $ferow['lname'];
359 </td>
360 <td colspan="2" rowspan="3">
361 <?php
362 for ($i = 1; $i <= 3; ++$i) {
363 $payerid = arGetPayerID($patient_id, $svcdate, $i);
364 if ($payerid) {
365 $tmp = sqlQuery("SELECT name FROM insurance_companies WHERE id = $payerid");
366 echo "Ins$i: " . $tmp['name'] . "<br />";
370 </td>
371 <?php
372 echo "<td rowspan='3' valign='bottom'>\n";
373 echo xl('Statements Sent:');
374 echo "</td>\n";
375 echo "<td rowspan='3' valign='bottom'>\n";
376 echo "<input type='text' name='form_stmt_count' size='10' value='" .
377 (0 + $ferow['stmt_count']) . "' />\n";
378 echo "</td>\n";
380 </tr>
381 <tr>
382 <td>
383 <?php xl('Provider:','e')?>
384 </td>
385 <td>
386 <?php
387 $tmp = sqlQuery("SELECT fname, mname, lname " .
388 "FROM users WHERE id = " . $ferow['provider_id']);
389 echo text($tmp['fname']) . ' ' . text($tmp['mname']) . ' ' . text($tmp['lname']);
390 $tmp = sqlQuery("SELECT bill_date FROM billing WHERE " .
391 "pid = '$patient_id' AND encounter = '$encounter_id' AND " .
392 "activity = 1 ORDER BY fee DESC, id ASC LIMIT 1");
393 $billdate = substr(($tmp['bill_date'] . "Not Billed"), 0, 10);
395 </td>
396 </tr>
397 <tr>
398 <td>
399 <?php xl('Invoice:','e')?>
400 </td>
401 <td>
402 <?php
403 echo "$patient_id.$encounter_id";
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 $last_level_closed = 0 + $ferow['last_level_closed'];
423 foreach (array(0 => 'None', 1 => 'Ins1', 2 => 'Ins2', 3 => 'Ins3') as $key => $value) {
424 if ($key && !arGetPayerID($patient_id, $svcdate, $key)) continue;
425 $checked = ($last_level_closed == $key) ? " checked" : "";
426 echo " <input type='radio' name='form_done' value='$key'$checked />$value&nbsp;\n";
429 </td>
430 <?php
431 echo "<td>\n";
432 echo xl('Check/EOB No.:');
433 echo "</td>\n";
434 echo "<td>\n";
435 echo "<input type='text' name='form_reference' size='10' value='' />\n";
436 echo "</td>\n";
438 </tr>
440 <tr>
441 <td>
442 <?php xl('Last Bill Date:','e') ?>
443 </td>
444 <td>
445 <?php
446 echo $billdate;
448 </td>
449 <td colspan="2">
450 <?php xl('Now posting for:','e','',"&nbsp")?>;
452 <?php
453 // TBD: check the first not-done-with insurance, not always Ins1!
455 <input type='radio' name='form_insurance' value='Ins1' onclick='setins("Ins1")' checked /><?php xl('Ins1','e')?>&nbsp;
456 <input type='radio' name='form_insurance' value='Ins2' onclick='setins("Ins2")' /><?php xl('Ins2','e')?>&nbsp;
457 <input type='radio' name='form_insurance' value='Ins3' onclick='setins("Ins3")' /><?php xl('Ins3','e')?>&nbsp;
458 <input type='radio' name='form_insurance' value='Pt' onclick='setins("Pt")' /><?php xl('Patient','e')?>
460 <?php
461 // TBD: I think the following is unused and can be removed.
463 <input type='hidden' name='form_eobs' value='<?php echo addslashes($arrow['shipvia']) ?>' />
465 </td>
466 <?php
467 echo "<td>\n";
468 echo xl('Check/EOB Date:');
469 echo "</td>\n";
470 echo "<td>\n";
471 echo "<input type='text' name='form_check_date' size='10' value='' />\n";
472 echo "</td>\n";
474 </tr>
475 <tr>
476 <td>
477 </td>
478 <td>
479 </td>
480 <td colspan="2">
481 <input type="checkbox" name="form_secondary" value="1"> <?php xl('Needs secondary billing','e')?>
482 &nbsp;&nbsp;
483 <input type='submit' name='form_save' value='<?php xl('Save','e')?>'>
484 &nbsp;
485 <input type='button' value='<?php xl('Cancel','e')?>' onclick='window.close()'>
486 </td>
487 <?php
488 echo "<td>\n";
489 echo xl('Deposit Date:');
490 echo "</td>\n";
491 echo "<td>\n";
492 echo "<input type='text' name='form_deposit_date' size='10' value='' />\n";
493 echo "<input type='hidden' name='form_payer_id' value='' />\n";
494 echo "<input type='hidden' name='form_orig_reference' value='' />\n";
495 echo "<input type='hidden' name='form_orig_check_date' value='' />\n";
496 echo "<input type='hidden' name='form_orig_deposit_date' value='' />\n";
497 echo "<input type='hidden' name='form_pay_total' value='' />\n";
498 echo "</td>\n";
500 </tr>
501 <?php if (!empty($pdrow['billing_note'])) { ?>
502 <tr>
503 <td>
504 <?php xl('Billing Note:','e')?>
505 </td>
506 <td colspan='3' style='color:red'>
507 <?php echo $pdrow['billing_note'] ?>
508 </td>
509 </tr>
510 <?php } ?>
511 <tr>
512 <td height="1">
513 </td>
514 </tr>
515 </table>
517 <table border='0' cellpadding='2' cellspacing='0' width='98%'>
519 <tr bgcolor="#cccccc">
520 <td class="dehead">
521 <?php xl('Code','e')?>
522 </td>
523 <td class="dehead" align="right">
524 <?php xl('Charge','e')?>
525 </td>
526 <td class="dehead" align="right">
527 <?php xl('Balance','e')?>&nbsp;
528 </td>
529 <td class="dehead">
530 <?php xl('By/Source','e')?>
531 </td>
532 <td class="dehead">
533 <?php xl('Date','e')?>
534 </td>
535 <td class="dehead">
536 <?php xl('Pay','e')?>
537 </td>
538 <td class="dehead">
539 <?php xl('Adjust','e')?>
540 </td>
541 <td class="dehead">
542 <?php xl('Reason','e')?>
543 </td>
544 <?php if ($ALLOW_DELETE) { ?>
545 <td class="dehead">
546 <?php xl('Del','e')?>
547 </td>
548 <?php } ?>
549 </tr>
550 <?php
551 $firstProcCodeIndex = -1;
552 $encount = 0;
553 foreach ($codes as $code => $cdata) {
554 ++$encount;
555 $bgcolor = "#" . (($encount & 1) ? "ddddff" : "ffdddd");
556 $dispcode = $code;
558 // remember the index of the first entry whose code is not "CO-PAY", i.e. it's a legitimate proc code
559 if ($firstProcCodeIndex == -1 && strcmp($code, "CO-PAY") !=0)
560 $firstProcCodeIndex = $encount;
562 // this sorts the details more or less chronologically:
563 ksort($cdata['dtl']);
564 foreach ($cdata['dtl'] as $dkey => $ddata) {
565 $ddate = substr($dkey, 0, 10);
566 if (preg_match('/^(\d\d\d\d)(\d\d)(\d\d)\s*$/', $ddate, $matches)) {
567 $ddate = $matches[1] . '-' . $matches[2] . '-' . $matches[3];
569 $tmpchg = "";
570 $tmpadj = "";
571 /*****************************************************************
572 if ($ddata['chg'] > 0)
573 $tmpchg = $ddata['chg'];
574 else if ($ddata['chg'] < 0)
575 $tmpadj = 0 - $ddata['chg'];
576 *****************************************************************/
577 if ($ddata['chg'] != 0) {
578 if (isset($ddata['rsn'])) $tmpadj = 0 - $ddata['chg'];
579 else $tmpchg = $ddata['chg'];
582 <tr bgcolor='<?php echo $bgcolor ?>'>
583 <td class="detail">
584 <?php echo $dispcode; $dispcode = "" ?>
585 </td>
586 <td class="detail" align="right">
587 <?php bucks($tmpchg) ?>
588 </td>
589 <td class="detail" align="right">
590 &nbsp;
591 </td>
592 <td class="detail">
593 <?php
594 if (isset($ddata['plv'])) {
595 if (!$ddata['plv']) echo 'Pt/';
596 else echo 'Ins' . $ddata['plv'] . '/';
598 echo $ddata['src'];
600 </td>
601 <td class="detail">
602 <?php echo $ddate ?>
603 </td>
604 <td class="detail">
605 <?php bucks($ddata['pmt']) ?>
606 </td>
607 <td class="detail">
608 <?php bucks($tmpadj) ?>
609 </td>
610 <td class="detail">
611 <?php echo $ddata['rsn'] ?>
612 </td>
613 <?php if ($ALLOW_DELETE) { ?>
614 <td class="detail">
615 <?php if (!empty($ddata['arseq'])) { ?>
616 <input type="checkbox" name="form_del[<?php echo $ddata['arseq']; ?>]" />
617 <?php } else { ?>
618 &nbsp;
619 <?php } ?>
620 </td>
621 <?php } ?>
622 </tr>
623 <?php
624 } // end of prior detail line
626 <tr bgcolor='<?php echo $bgcolor ?>'>
627 <td class="detail">
628 <?php echo $dispcode; $dispcode = "" ?>
629 </td>
630 <td class="detail" align="right">
631 &nbsp;
632 </td>
633 <td class="detail" align="right">
634 <input type="hidden" name="form_line[<?php echo $code ?>][bal]" value="<?php bucks($cdata['bal']) ?>">
635 <input type="hidden" name="form_line[<?php echo $code ?>][ins]" value="<?php echo $cdata['ins'] ?>">
636 <input type="hidden" name="form_line[<?php echo $code ?>][code_type]" value="<?php echo $cdata['code_type'] ?>">
637 <?php printf("%.2f", $cdata['bal']) ?>&nbsp;
638 </td>
639 <td class="detail">
642 </td>
643 <td class="detail">
646 </td>
647 <td class="detail">
648 <input type="text" name="form_line[<?php echo $code ?>][pay]" size="10"
649 style="background-color:<?php echo $bgcolor ?>"
650 onKeyUp="updateFields(document.forms[0]['form_line[<?php echo $code ?>][pay]'],
651 document.forms[0]['form_line[<?php echo $code ?>][adj]'],
652 document.forms[0]['form_line[<?php echo $code ?>][bal]'],
653 document.forms[0]['form_line[CO-PAY][bal]'],
654 <?php echo ($firstProcCodeIndex == $encount) ? 1 : 0 ?>)"/>
655 </td>
656 <td class="detail">
657 <input type="text" name="form_line[<?php echo $code ?>][adj]" size="10"
658 value='<?php echo $totalAdjAmount ?>'
659 style="background-color:<?php echo $bgcolor ?>" />
660 &nbsp; <a href="" onclick="return writeoff('<?php echo $code ?>')">W</a>
661 </td>
662 <td class="detail">
663 <select name="form_line[<?php echo $code ?>][reason]"
664 style="background-color:<?php echo $bgcolor ?>">
665 <?php
666 // Adjustment reasons are now taken from the list_options table.
667 echo " <option value=''></option>\n";
668 $ores = sqlStatement("SELECT option_id, title, is_default FROM list_options " .
669 "WHERE list_id = 'adjreason' AND activity = 1 ORDER BY seq, title");
670 while ($orow = sqlFetchArray($ores)) {
671 echo " <option value='" . htmlspecialchars($orow['option_id'], ENT_QUOTES) . "'";
672 if ($orow['is_default']) echo " selected";
673 echo ">" . htmlspecialchars($orow['title']) . "</option>\n";
677 </select>
678 <?php
679 // TBD: Maybe a comment field would be good here, for appending
680 // to the reason.
682 </td>
684 <?php if ($ALLOW_DELETE) { ?>
685 <td class="detail">
686 &nbsp;
687 </td>
688 <?php } ?>
690 </tr>
691 <?php
692 } // end of code
695 </table>
696 </form>
697 </center>
698 <script language="JavaScript">
699 var f1 = opener.document.forms[0];
700 var f2 = document.forms[0];
701 if (f1.form_source) {
702 <?php
703 // These support creation and lookup of ar_session table entries:
704 echo " f2.form_reference.value = f1.form_source.value;\n";
705 echo " f2.form_check_date.value = f1.form_paydate.value;\n";
706 echo " //f2.form_deposit_date.value = f1.form_deposit_date.value;\n";
707 echo " if (f1.form_deposit_date.value != '')\n";
708 echo " f2.form_deposit_date.value = f1.form_deposit_date.value;\n";
709 echo " else\n";
710 echo " f2.form_deposit_date.value = getFormattedToday();\n";
711 echo " f2.form_payer_id.value = f1.form_payer_id.value;\n";
712 echo " f2.form_pay_total.value = f1.form_amount.value;\n";
713 echo " f2.form_orig_reference.value = f1.form_source.value;\n";
714 echo " f2.form_orig_check_date.value = f1.form_paydate.value;\n";
715 echo " f2.form_orig_deposit_date.value = f1.form_deposit_date.value;\n";
717 // While I'm thinking about it, some notes about eob sessions.
718 // If they do not have all of the session key fields in the search
719 // page, then show a warning at the top of the invoice page.
720 // Also when they go to save the invoice page and a session key
721 // field has changed, alert them to that and allow a cancel.
723 // Another point... when posting EOBs, the incoming payer ID might
724 // not match the payer ID for the patient's insurance. This is
725 // because the same payer might be entered more than once into the
726 // insurance_companies table. I don't think it matters much.
729 setins("Ins1");
730 </script>
731 </body>
732 </html>