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