Initial import.
[openemr.git] / interface / billing / sl_eob_invoice.php
blob2306829af60bdc6cd76d0ad15105097af76602b4
1 <?
2 // Copyright (C) 2005 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 is the second of two pages to support posting of EOBs.
10 // The first is sl_eob_search.php.
12 include_once("../globals.php");
13 include_once("../../library/patient.inc");
14 include_once("../../library/forms.inc");
15 include_once("../../library/sql-ledger.inc");
16 include_once("../../library/invoice_summary.inc.php");
17 include_once("../../custom/code_types.inc.php");
19 $debug = 0; // set to 1 for debugging mode
21 $reasons = array(
22 "Ins adjust",
23 "Coll w/o",
24 "Pt released",
25 "Sm debt w/o",
26 "To ded'ble",
27 "To copay",
28 "Bad debt",
29 "Discount",
30 "Hardship w/o",
31 "Ins refund",
32 "Pt refund",
33 "Ins overpaid",
34 "Pt overpaid"
37 $info_msg = "";
39 // Format money for display.
41 function bucks($amount) {
42 if ($amount)
43 printf("%.2f", $amount);
46 // Insert a row into the acc_trans table.
48 function addTransaction($invid, $chartid, $amount, $date, $source, $memo, $insplan) {
49 global $sl_err, $debug;
50 $date = fixDate($date);
51 $query = "INSERT INTO acc_trans ( " .
52 "trans_id, " .
53 "chart_id, " .
54 "amount, " .
55 "transdate, " .
56 "source, " .
57 "project_id, " .
58 "memo " .
59 ") VALUES ( " .
60 "$invid, " . // trans_id
61 "$chartid, " . // chart_id
62 "$amount, " . // amount
63 "'$date', " . // transdate
64 "'$source', " . // source
65 "$insplan, " . // project_id
66 "'$memo' " . // memo
67 ")";
68 if ($debug) {
69 echo $query . "<br>\n";
70 } else {
71 SLQuery($query);
72 if ($sl_err) die($sl_err);
76 // Insert a row into the invoice table.
78 function addLineItem($invid, $serialnumber, $amount, $adjdate, $insplan, $reason) {
79 global $sl_err, $services_id, $debug;
80 $adjdate = fixDate($adjdate);
81 $description = "Adjustment $adjdate $reason";
82 $query = "INSERT INTO invoice ( " .
83 "trans_id, " .
84 "parts_id, " .
85 "description, " .
86 "qty, " .
87 "allocated, " .
88 "sellprice, " .
89 "fxsellprice, " .
90 "discount, " .
91 "unit, " .
92 "project_id, " .
93 "serialnumber " .
94 ") VALUES ( " .
95 "$invid, " . // trans_id
96 "$services_id, " . // parts_id
97 "'$description', " . // description
98 "1, " . // qty
99 "0, " . // allocated
100 "$amount, " . // sellprice
101 "$amount, " . // fxsellprice
102 "0, " . // discount
103 "'', " . // unit
104 "$insplan, " . // project_id
105 "'$serialnumber'" . // serialnumber
106 ")";
107 if ($debug) {
108 echo $query . "<br>\n";
109 } else {
110 SLQuery($query);
111 if ($sl_err) die($sl_err);
115 // Update totals and payment date in the invoice header. Dollar amounts are
116 // stored as double precision floats so we have to be careful about rounding.
118 function updateAR($invid, $amount, $paid = 0, $paydate = "") {
119 global $sl_err, $debug;
120 $paydate = fixDate($paydate);
121 $query = "UPDATE ar SET amount = round(CAST (amount AS numeric) + $amount, 2), " .
122 "netamount = round(CAST (netamount AS numeric) + $amount, 2)";
123 if ($paid) $query .= ", paid = round(CAST (paid AS numeric) + $paid, 2), datepaid = '$paydate'";
124 $query .= " WHERE id = $invid";
125 if ($debug) {
126 echo $query . "<br>\n";
127 } else {
128 SLQuery($query);
129 if ($sl_err) die($sl_err);
133 // Do whatever is necessary to make this invoice re-billable.
135 function setupSecondary($invid) {
136 global $sl_err, $debug, $info_msg, $GLOBALS;
138 // Get some needed items from the SQL-Ledger invoice.
139 $arres = SLQuery("select invnumber, transdate, customer_id, employee_id " .
140 "from ar where ar.id = $invid");
141 if ($sl_err) die($sl_err);
142 $arrow = SLGetRow($arres, 0);
143 if (! $arrow) die("There is no match for invoice id = $trans_id.");
144 $customer_id = $arrow['customer_id'];
145 list($trash, $encounter) = explode(".", $arrow['invnumber']);
147 // Get the OpenEMR PID corresponding to the customer.
148 $pdrow = sqlQuery("SELECT patient_data.pid " .
149 "FROM integration_mapping, patient_data WHERE " .
150 "integration_mapping.foreign_id = $customer_id AND " .
151 "integration_mapping.foreign_table = 'customer' AND " .
152 "patient_data.id = integration_mapping.local_id");
153 $pid = $pdrow['pid'];
154 if (! $pid) die("Cannot find patient from SQL-Ledger customer id = $customer_id.");
156 // Find out if the encounter exists.
157 $ferow = sqlQuery("SELECT pid FROM form_encounter WHERE " .
158 "encounter = $encounter");
159 $encounter_pid = $ferow['pid'];
161 // If it exists, just update the billing items.
162 if ($encounter_pid) {
163 if ($encounter_pid != $pid)
164 die("Expected form_encounter.pid to be $pid, but was $encounter_pid");
165 $query = "UPDATE billing SET billed = 0, bill_process = 0, payer_id = -1, " .
166 "bill_date = NULL, process_date = NULL, process_file = NULL " .
167 "WHERE encounter = $encounter AND pid = $pid AND activity = 1";
168 if ($debug) {
169 echo $query . "<br>\n";
170 } else {
171 sqlQuery($query);
173 $info_msg = "Encounter $encounter is ready for re-billing.";
174 return;
177 // It does not exist then it better be a date.
178 if (! preg_match("/^20\d\d\d\d\d\d$/", $encounter))
179 die("Internal error: encounter '$encounter' should exist but does not.");
181 $employee_id = $arrow['employee_id'];
183 // Get the OpenEMR provider info corresponding to the SQL-Ledger salesman.
184 $drrow = sqlQuery("SELECT users.id, users.username, users.facility " .
185 "FROM integration_mapping, users WHERE " .
186 "integration_mapping.foreign_id = $employee_id AND " .
187 "integration_mapping.foreign_table = 'salesman' AND " .
188 "users.id = integration_mapping.local_id");
189 $provider_id = $drrow['id'];
190 if (! $provider_id) die("Cannot find provider from SQL-Ledger employee = $employee_id.");
192 $date_of_service = $arrow['transdate'];
193 if (! $date_of_service) die("Invoice has no date!");
195 // Generate a new encounter number.
196 $conn = $GLOBALS['adodb']['db'];
197 $new_encounter = $conn->GenID("sequences");
199 // Create the "new encounter".
200 $encounter_id = 0;
201 $query = "INSERT INTO form_encounter ( " .
202 "date, reason, facility, pid, encounter, onset_date " .
203 ") VALUES ( " .
204 "'$date_of_service', " .
205 "'Imported from Accounting', " .
206 "'" . addslashes($drrow['facility']) . "', " .
207 "$pid, " .
208 "$new_encounter, " .
209 "'$date_of_service' " .
210 ")";
211 if ($debug) {
212 echo $query . "<br>\n";
213 echo "Call to addForm() goes here.<br>\n";
214 } else {
215 $encounter_id = idSqlStatement($query);
216 if (! $encounter_id) die("Insert failed: $query");
217 addForm($new_encounter, "New Patient Encounter", $encounter_id,
218 "newpatient", $pid, 1, $date_of_service);
219 $info_msg = "Encounter $new_encounter has been created. ";
222 // For each invoice line item with a billing code we will insert
223 // a billing row with payer_id set to -1. Order the line items
224 // chronologically so that each procedure code will be followed by
225 // its associated icd9 code.
227 $inres = SLQuery("SELECT * FROM invoice WHERE trans_id = $invid " .
228 "ORDER BY id");
229 if ($sl_err) die($sl_err);
231 // When nonzero, this will be the ID of a billing row that needs to
232 // have its justify field set.
233 $proc_ins_id = 0;
235 for ($irow = 0; $irow < SLRowCount($inres); ++$irow) {
236 $row = SLGetRow($inres, $irow);
237 $amount = $row['sellprice'];
239 // Extract the billing code.
240 $code = "Unknown";
241 if (preg_match("/([A-Za-z0-9]\d\d\S*)/", $row['serialnumber'], $matches)) {
242 $code = strtoupper($matches[1]);
244 else if (preg_match("/([A-Za-z0-9]\d\d\S*)/", $row['description'], $matches)) {
245 $code = strtoupper($matches[1]);
248 list($code, $modifier) = explode("-", $code);
250 // Set the billing code type and description.
251 $code_type = "";
252 $code_text = "";
254 /****
255 if (preg_match("/CPT/", $row['serialnumber'])) {
256 $code_type = "CPT4";
257 $code_text = "Procedure $code";
259 else if (preg_match("/HCPCS/", $row['serialnumber'])) {
260 $code_type = "HCPCS";
261 $code_text = "Procedure $code";
263 else if (preg_match("/ICD/", $row['serialnumber'])) {
264 $code_type = "ICD9";
265 $code_text = "Diagnosis $code";
266 if ($proc_ins_id) {
267 $query = "UPDATE billing SET justify = '$code' WHERE id = $proc_ins_id";
268 if ($debug) {
269 echo $query . "<br>\n";
270 } else {
271 sqlQuery($query);
273 $proc_ins_id = 0;
276 ****/
278 foreach ($code_types as $key => $value) {
279 if (preg_match("/$key/", $row['serialnumber'])) {
280 $code_type = $key;
281 if ($value['fee']) {
282 $code_text = "Procedure $code";
283 } else {
284 $code_text = "Diagnosis $code";
285 if ($proc_ins_id) {
286 $query = "UPDATE billing SET justify = '$code' WHERE id = $proc_ins_id";
287 if ($debug) {
288 echo $query . "<br>\n";
289 } else {
290 sqlQuery($query);
292 $proc_ins_id = 0;
295 break;
299 // Skip adjustments.
300 if (! $code_type) continue;
302 // Insert the billing item. If this for a procedure code then save
303 // the row ID so that we can update the "justify" field with the ICD9
304 // code, which should come next in the loop.
306 $query = "INSERT INTO billing ( " .
307 "date, code_type, code, pid, provider_id, user, groupname, authorized, " .
308 "encounter, code_text, activity, payer_id, billed, bill_process, " .
309 "modifier, units, fee, justify " .
310 ") VALUES ( " .
311 "NOW(), " .
312 "'$code_type', " .
313 "'$code', " .
314 "$pid, " .
315 "$provider_id, " .
316 "'" . $_SESSION['authId'] . "', " .
317 "'" . $_SESSION['authProvider'] . "', " .
318 "1, " .
319 "$new_encounter, " .
320 "'$code_text', " .
321 "1, " .
322 "-1, " .
323 "0, " .
324 "0, " .
325 "'$modifier', " .
326 "0, " .
327 "$amount, " .
328 "'' " .
329 ")";
330 if ($debug) {
331 echo $query . "<br>\n";
332 } else {
333 $proc_ins_id = idSqlStatement($query);
334 if ($code_type != "CPT4" && $code_type != "HCPCS")
335 $proc_ins_id = 0;
339 // Finally, change this invoice number to contain the new encounter number.
341 $new_invnumber = "$pid.$new_encounter";
342 $query = "UPDATE ar SET invnumber = '$new_invnumber' WHERE id = $invid";
343 if ($debug) {
344 echo $query . "<br>\n";
345 } else {
346 SLQuery($query);
347 if ($sl_err) die($sl_err);
348 $info_msg .= "This invoice number has been changed to $new_invnumber.";
352 <html>
353 <head>
354 <link rel=stylesheet href="<?echo $css_header;?>" type="text/css">
355 <title>EOB Posting - Invoice</title>
356 <script language="JavaScript">
358 // An insurance radio button is selected.
359 function setins(istr) {
360 var f = document.forms[0];
361 for (var i = 0; i < f.elements.length; ++i) {
362 var ename = f.elements[i].name;
363 if (ename.indexOf('[src]') < 0) continue;
364 var evalue = f.elements[i].value;
365 var tmp = evalue.substring(0, 4).toLowerCase();
366 if (tmp >= 'ins1' && tmp <= 'ins3')
367 evalue = evalue.substring(4);
368 else if (evalue.substring(0, 2).toLowerCase() == 'pt')
369 evalue = evalue.substring(2);
370 while (evalue.substring(0, 1) == '/')
371 evalue = evalue.substring(1);
372 f.elements[i].value = istr + '/' + evalue;
374 return true;
377 // Compute an adjustment that writes off the balance:
378 function writeoff(code) {
379 var f = document.forms[0];
380 var tmp =
381 f['form_line[' + code + '][bal]'].value -
382 f['form_line[' + code + '][pay]'].value;
383 f['form_line[' + code + '][adj]'].value = Number(tmp).toFixed(2);
384 return false;
387 // Onsubmit handler. A good excuse to write some JavaScript.
388 function validate(f) {
389 for (var i = 0; i < f.elements.length; ++i) {
390 var ename = f.elements[i].name;
391 var pfxlen = ename.indexOf('[pay]');
392 if (pfxlen < 0) continue;
393 var pfx = ename.substring(0, pfxlen);
394 var code = pfx.substring(pfx.indexOf('[')+1, pfxlen-1);
395 if (f[pfx+'[pay]'].value || f[pfx+'[adj]'].value) {
396 var srcobj = f[pfx+'[src]'];
397 while (srcobj.value.length) {
398 var tmp = srcobj.value.substring(srcobj.value.length - 1);
399 if (tmp > ' ' && tmp != '/') break;
400 srcobj.value = srcobj.value.substring(0, srcobj.value.length - 1);
402 var svalue = srcobj.value;
403 if (! svalue) {
404 alert('Source is missing for code ' + code);
405 return false;
406 } else {
407 var tmp = svalue.substring(0, 4).toLowerCase();
408 if (tmp >= 'ins1' && tmp <= 'ins3') {
409 svalue = svalue.substring(4);
410 } else if (svalue.substring(0, 2).toLowerCase() == 'pt') {
411 svalue = svalue.substring(2);
412 } else {
413 alert('Invalid or missing payer in source for code ' + code);
414 return false;
416 if (svalue) {
417 if (svalue.substring(0, 1) != '/') {
418 alert('Missing slash after payer in source for code ' + code);
419 return false;
421 tmp = svalue.substring(1, 3).toLowerCase();
422 if (tmp != 'nm' && tmp != 'ci' && tmp != 'cp' && tmp != 'ne' &&
423 tmp != 'it' && tmp != 'pf' && tmp != 'pp' && tmp != 'ok')
425 alert('Invalid source designation "' + tmp + '" for code ' + code);
426 return false;
430 if (! f[pfx+'[date]'].value) {
431 alert('Date is missing for code ' + code);
432 return false;
435 if (f[pfx+'[pay]'].value && isNaN(parseFloat(f[pfx+'[pay]'].value))) {
436 alert('Payment value for code ' + code + ' is not a number');
437 return false;
439 if (f[pfx+'[adj]'].value && isNaN(parseFloat(f[pfx+'[adj]'].value))) {
440 alert('Adjustment value for code ' + code + ' is not a number');
441 return false;
443 // TBD: validate the date format
445 return true;
448 </script>
449 </head>
450 <body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>
452 $trans_id = $_GET['id'];
453 if (! $trans_id) die("You cannot access this page directly.");
455 SLConnect();
457 $chart_id_cash = SLQueryValue("select id from chart where accno = '$sl_cash_acc'");
458 if ($sl_err) die($sl_err);
459 if (! $chart_id_cash) die("There is no COA entry for cash account '$sl_cash_acc'");
461 $chart_id_ar = SLQueryValue("select id from chart where accno = '$sl_ar_acc'");
462 if ($sl_err) die($sl_err);
463 if (! $chart_id_ar) die("There is no COA entry for AR account '$sl_ar_acc'");
465 $chart_id_income = SLQueryValue("select id from chart where accno = '$sl_income_acc'");
466 if ($sl_err) die($sl_err);
467 if (! $chart_id_income) die("There is no COA entry for income account '$sl_income_acc'");
469 $services_id = SLQueryValue("select id from parts where partnumber = '$sl_services_id'");
470 if ($sl_err) die($sl_err);
471 if (! $services_id) die("There is no parts entry for services ID '$sl_services_id'");
473 if ($_POST['form_save'] || $_POST['form_cancel']) {
474 if ($_POST['form_save']) {
475 if ($debug) {
476 echo "<p><b>This module is in test mode. The database will not be changed.</b><p>\n";
478 $paytotal = 0;
479 foreach ($_POST['form_line'] as $code => $cdata) {
480 $thissrc = trim($cdata['src']);
481 $thisdate = trim($cdata['date']);
482 $thispay = trim($cdata['pay']);
483 $thisadj = trim($cdata['adj']);
484 $thisins = trim($cdata['ins']);
485 $reason = trim($cdata['reason']);
486 if (strpos(strtolower($reason), 'ins') !== false)
487 $reason .= ' ' . $_POST['form_insurance'];
488 if (! $thisins) $thisins = 0;
489 if ($thispay) {
490 // Post a payment: add to ar, subtract from cash.
491 addTransaction($trans_id, $chart_id_ar, $thispay, $thisdate, $thissrc, $code, $thisins);
492 addTransaction($trans_id, $chart_id_cash, 0 - $thispay, $thisdate, $thissrc, $code, $thisins);
493 updateAR($trans_id, 0, $thispay, $thisdate);
494 $paytotal += $thispay;
496 if ($thisadj) {
497 // Post an adjustment: add negative invoice item, add to ar, subtract from income
498 addLineItem($trans_id, $code, 0 - $thisadj, $thisdate, $thisins, $reason);
499 addTransaction($trans_id, $chart_id_ar, $thisadj, $thisdate, "InvAdj $thissrc", $code, $thisins);
500 addTransaction($trans_id, $chart_id_income, 0 - $thisadj, $thisdate, "InvAdj $thissrc", $code, $thisins);
501 updateAR($trans_id, 0 - $thisadj);
504 $form_duedate = fixDate($_POST['form_duedate']);
505 $form_notes = trim($_POST['form_notes']);
507 // Maintain the list of insurances whose EOBs we have posted.
508 // We use the "Ship Via" field of the invoice to hold these.
510 $form_eobs = trim($_POST['form_eobs']);
511 $form_insurance = trim($_POST['form_insurance']);
512 if (strpos($form_eobs, $form_insurance) === false) {
513 if ($form_eobs) $form_eobs .= ","; else $form_eobs = "EOBs: ";
514 $form_eobs .= $form_insurance;
517 $query = "UPDATE ar SET duedate = '$form_duedate', notes = '$form_notes', " .
518 "shipvia = '$form_eobs' WHERE id = $trans_id";
520 if ($debug) {
521 echo $query . "<br>\n";
522 } else {
523 SLQuery($query);
524 if ($sl_err) die($sl_err);
526 if ($_POST['form_secondary']) {
527 setupSecondary($trans_id);
529 echo "<script language='JavaScript'>\n";
530 echo " var tmp = opener.document.forms[0].form_amount.value - $paytotal;\n";
531 echo " opener.document.forms[0].form_amount.value = Number(tmp).toFixed(2);\n";
532 } else {
533 echo "<script language='JavaScript'>\n";
535 if ($info_msg) echo " alert('$info_msg');\n";
536 if (! $debug) echo " window.close();\n";
537 echo "</script></body></html>\n";
538 SLClose();
539 exit();
542 // Get invoice data into $arrow.
543 $arres = SLQuery("select ar.*, customer.name, employee.name as doctor " .
544 "from ar, customer, employee where ar.id = $trans_id and " .
545 "customer.id = ar.customer_id and employee.id = ar.employee_id");
546 if ($sl_err) die($sl_err);
547 $arrow = SLGetRow($arres, 0);
548 if (! $arrow) die("There is no match for invoice id = $trans_id.");
550 // Determine the date of service. An 8-digit encounter number is
551 // presumed to be a date of service imported during conversion.
552 // Otherwise look it up in the form_encounter table.
554 $svcdate = "";
555 list($trash, $encounter) = explode(".", $arrow['invnumber']);
556 if (strlen($encounter) == 8) {
557 $svcdate = substr($encounter, 0, 4) . "-" . substr($encounter, 4, 2) .
558 "-" . substr($encounter, 6, 2);
560 else if ($encounter) {
561 $tmp = sqlQuery("SELECT date FROM form_encounter WHERE " .
562 "encounter = $encounter");
563 $svcdate = substr($tmp['date'], 0, 10);
566 // Get invoice charge details.
567 $codes = get_invoice_summary($trans_id, true);
569 <center>
571 <form method='post' action='sl_eob_invoice.php?id=<? echo $trans_id ?>'
572 onsubmit='return validate(this)'>
574 <table border='0' cellpadding='3'>
575 <tr>
576 <td>
577 Patient:
578 </td>
579 <td>
580 <?echo $arrow['name'] ?>
581 </td>
582 <td colspan="2" rowspan="3">
583 <textarea name="form_notes" cols="50" style="height:100%"><?echo $arrow['notes'] ?></textarea>
584 </td>
585 </tr>
586 <tr>
587 <td>
588 Provider:
589 </td>
590 <td>
591 <?echo $arrow['doctor'] ?>
592 </td>
593 </tr>
594 <tr>
595 <td>
596 Invoice:
597 </td>
598 <td>
599 <?echo $arrow['invnumber'] ?>
600 </td>
601 </tr>
603 <tr>
604 <td>
605 Svc Date:
606 </td>
607 <td>
608 <?echo $svcdate ?>
609 </td>
610 <td colspan="2">
611 Already posted:&nbsp;
612 <?echo $arrow['shipvia'] ?>
613 </td>
614 </tr>
616 <tr>
617 <td>
618 Bill Date:
619 </td>
620 <td>
621 <?echo $arrow['transdate'] ?>
622 </td>
623 <td colspan="2">
624 Now posting for:&nbsp;
625 <input type='radio' name='form_insurance' value='Ins1' onclick='setins("Ins1")' checked />Ins1&nbsp;
626 <input type='radio' name='form_insurance' value='Ins2' onclick='setins("Ins2")' />Ins2&nbsp;
627 <input type='radio' name='form_insurance' value='Ins3' onclick='setins("Ins3")' />Ins3&nbsp;
628 <input type='radio' name='form_insurance' value='Pt' onclick='setins("Pt")' />Patient
629 <input type='hidden' name='form_eobs' value='<?echo addslashes($arrow['shipvia']) ?>' />
630 </td>
631 </tr>
632 <tr>
633 <td>
634 Due Date:
635 </td>
636 <td>
637 <input type='text' name='form_duedate' size='10' value='<?echo $arrow['duedate'] ?>'
638 title='Due date mm/dd/yyyy or yyyy-mm-dd'>
639 </td>
640 <td colspan="2">
641 <input type="checkbox" name="form_secondary" value="1"> Needs secondary billing
642 &nbsp;&nbsp;
643 <input type='submit' name='form_save' value='Save'>
644 &nbsp;
645 <input type='button' value='Cancel' onclick='window.close()'>
646 </td>
647 </tr>
648 <tr>
649 <td height="1">
650 </td>
651 </tr>
652 </table>
654 <table border='0' cellpadding='2' cellspacing='0' width='98%'>
656 <tr bgcolor="#cccccc">
657 <td class="dehead">
658 Code
659 </td>
660 <td class="dehead" align="right">
661 Charge
662 </td>
663 <td class="dehead" align="right">
664 Balance&nbsp;
665 </td>
666 <td class="dehead">
667 Source
668 </td>
669 <td class="dehead">
670 Date
671 </td>
672 <td class="dehead">
674 </td>
675 <td class="dehead">
676 Adjust
677 </td>
678 <td class="dehead">
679 Reason
680 </td>
681 </tr>
683 $encount = 0;
684 foreach ($codes as $code => $cdata) {
685 ++$encount;
686 $bgcolor = "#" . (($encount & 1) ? "ddddff" : "ffdddd");
687 $dispcode = $code;
688 // this sorts the details more or less chronologically:
689 ksort($cdata['dtl']);
690 foreach ($cdata['dtl'] as $dkey => $ddata) {
691 $ddate = substr($dkey, 0, 10);
692 if (preg_match('/^(\d\d\d\d)(\d\d)(\d\d)\s*$/', $ddate, $matches)) {
693 $ddate = $matches[1] . '-' . $matches[2] . '-' . $matches[3];
695 $tmpchg = "";
696 $tmpadj = "";
697 if ($ddata['chg'] > 0)
698 $tmpchg = $ddata['chg'];
699 else if ($ddata['chg'] < 0)
700 $tmpadj = 0 - $ddata['chg'];
702 <tr bgcolor='<? echo $bgcolor ?>'>
703 <td class="detail">
704 <? echo $dispcode; $dispcode = "" ?>
705 </td>
706 <td class="detail" align="right">
707 <? bucks($tmpchg) ?>
708 </td>
709 <td class="detail" align="right">
710 &nbsp;
711 </td>
712 <td class="detail">
713 <? echo $ddata['src'] ?>
714 </td>
715 <td class="detail">
716 <? echo $ddate ?>
717 </td>
718 <td class="detail">
719 <? bucks($ddata['pmt']) ?>
720 </td>
721 <td class="detail">
722 <? bucks($tmpadj) ?>
723 </td>
724 <td class="detail">
725 <? echo $ddata['rsn'] ?>
726 </td>
727 </tr>
729 } // end of prior detail line
731 <tr bgcolor='<? echo $bgcolor ?>'>
732 <td class="detail">
733 <? echo $dispcode; $dispcode = "" ?>
734 </td>
735 <td class="detail" align="right">
736 &nbsp;
737 </td>
738 <td class="detail" align="right">
739 <input type="hidden" name="form_line[<? echo $code ?>][bal]" value="<? bucks($cdata['bal']) ?>">
740 <input type="hidden" name="form_line[<? echo $code ?>][ins]" value="<? echo $cdata['ins'] ?>">
741 <? printf("%.2f", $cdata['bal']) ?>&nbsp;
742 </td>
743 <td class="detail">
744 <input type="text" name="form_line[<? echo $code ?>][src]" size="10"
745 style="background-color:<? echo $bgcolor ?>"
746 title="NM=notmet, CI=coins, CP=copay, NE=notelig, IT=insterm, PF=ptfull, PP=ptpart" />
747 </td>
748 <td class="detail">
749 <input type="text" name="form_line[<? echo $code ?>][date]" size="10" style="background-color:<? echo $bgcolor ?>" />
750 </td>
751 <td class="detail">
752 <input type="text" name="form_line[<? echo $code ?>][pay]" size="10" style="background-color:<? echo $bgcolor ?>" />
753 </td>
754 <td class="detail">
755 <input type="text" name="form_line[<? echo $code ?>][adj]" size="10" style="background-color:<? echo $bgcolor ?>" />
756 &nbsp; <a href="" onclick="return writeoff('<? echo $code ?>')">W</a>
757 </td>
758 <td class="detail">
759 <select name="form_line[<? echo $code ?>][reason]" style="background-color:<? echo $bgcolor ?>">
761 foreach ($reasons as $value) {
762 echo " <option value=\"$value\">$value</option>\n";
765 </select>
766 </td>
767 </tr>
769 } // end of code
770 SLClose();
773 </table>
774 </form>
775 </center>
776 <script language="JavaScript">
777 var f1 = opener.document.forms[0];
778 var f2 = document.forms[0];
780 foreach ($codes as $code => $cdata) {
781 echo " f2['form_line[$code][src]'].value = f1.form_source.value;\n";
782 echo " f2['form_line[$code][date]'].value = f1.form_paydate.value;\n";
785 setins("Ins1");
786 </script>
787 </body>
788 </html>