fix Row size too large error, change varchar(255) to TEXT
[openemr.git] / interface / billing / sl_eob_process.php
blobe887c722d857ae7e9a9cd2719b98c02bec9e7bed
1 <?php
2 // Copyright (C) 2006-2010 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 processes X12 835 remittances and produces a report.
11 // Buffer all output so we can archive it to a file.
12 ob_start();
14 require_once("../globals.php");
15 require_once("$srcdir/invoice_summary.inc.php");
16 require_once("$srcdir/sl_eob.inc.php");
17 require_once("$srcdir/parse_era.inc.php");
18 require_once("claim_status_codes.php");
19 require_once("adjustment_reason_codes.php");
20 require_once("remark_codes.php");
21 require_once("$srcdir/formatting.inc.php");
22 require_once("$srcdir/billing.inc");
24 $debug = $_GET['debug'] ? 1 : 0; // set to 1 for debugging mode
25 $paydate = parse_date($_GET['paydate']);
26 $encount = 0;
28 $last_ptname = '';
29 $last_invnumber = '';
30 $last_code = '';
31 $invoice_total = 0.00;
32 $InsertionId;//last inserted ID of
33 $INTEGRATED_AR = $GLOBALS['oer_config']['ws_accounting']['enabled'] === 2;
35 ///////////////////////// Assorted Functions /////////////////////////
37 function parse_date($date) {
38 $date = substr(trim($date), 0, 10);
39 if (preg_match('/^(\d\d\d\d)\D*(\d\d)\D*(\d\d)$/', $date, $matches)) {
40 return $matches[1] . '-' . $matches[2] . '-' . $matches[3];
42 return '';
45 function writeMessageLine($bgcolor, $class, $description) {
46 $dline =
47 " <tr bgcolor='$bgcolor'>\n" .
48 " <td class='$class' colspan='4'>&nbsp;</td>\n" .
49 " <td class='$class'>$description</td>\n" .
50 " <td class='$class' colspan='2'>&nbsp;</td>\n" .
51 " </tr>\n";
52 echo $dline;
55 function writeDetailLine($bgcolor, $class, $ptname, $invnumber,
56 $code, $date, $description, $amount, $balance)
58 global $last_ptname, $last_invnumber, $last_code;
59 if ($ptname == $last_ptname) $ptname = '&nbsp;';
60 else $last_ptname = $ptname;
61 if ($invnumber == $last_invnumber) $invnumber = '&nbsp;';
62 else $last_invnumber = $invnumber;
63 if ($code == $last_code) $code = '&nbsp;';
64 else $last_code = $code;
65 if ($amount ) $amount = sprintf("%.2f", $amount );
66 if ($balance) $balance = sprintf("%.2f", $balance);
67 $dline =
68 " <tr bgcolor='$bgcolor'>\n" .
69 " <td class='$class'>$ptname</td>\n" .
70 " <td class='$class'>$invnumber</td>\n" .
71 " <td class='$class'>$code</td>\n" .
72 " <td class='$class'>" . oeFormatShortDate($date) . "</td>\n" .
73 " <td class='$class'>$description</td>\n" .
74 " <td class='$class' align='right'>" . oeFormatMoney($amount) . "</td>\n" .
75 " <td class='$class' align='right'>" . oeFormatMoney($balance) . "</td>\n" .
76 " </tr>\n";
77 echo $dline;
80 // This writes detail lines that were already in SQL-Ledger for a given
81 // charge item.
83 function writeOldDetail(&$prev, $ptname, $invnumber, $dos, $code, $bgcolor) {
84 global $invoice_total;
85 // $prev['total'] = 0.00; // to accumulate total charges
86 ksort($prev['dtl']);
87 foreach ($prev['dtl'] as $dkey => $ddata) {
88 $ddate = substr($dkey, 0, 10);
89 $description = $ddata['src'] . $ddata['rsn'];
90 if ($ddate == ' ') { // this is the service item
91 $ddate = $dos;
92 $description = 'Service Item';
94 $amount = sprintf("%.2f", $ddata['chg'] - $ddata['pmt']);
95 $invoice_total = sprintf("%.2f", $invoice_total + $amount);
96 writeDetailLine($bgcolor, 'olddetail', $ptname, $invnumber,
97 $code, $ddate, $description, $amount, $invoice_total);
101 // This is called back by parse_era() once per claim.
103 function era_callback_check(&$out)
106 global $InsertionId;//last inserted ID of
107 global $StringToEcho,$debug;
109 if($_GET['original']=='original')
111 $StringToEcho="<br/><br/><br/><br/><br/><br/>";
112 $StringToEcho.="<table border='1' cellpadding='0' cellspacing='0' width='750'>";
113 $StringToEcho.="<tr bgcolor='#cccccc'><td width='50'></td><td class='dehead' width='150' align='center'>".htmlspecialchars( xl('Check Number'), ENT_QUOTES)."</td><td class='dehead' width='400' align='center'>".htmlspecialchars( xl('Payee Name'), ENT_QUOTES)."</td><td class='dehead' width='150' align='center'>".htmlspecialchars( xl('Check Amount'), ENT_QUOTES)."</td></tr>";
114 $WarningFlag=false;
115 for ($check_count=1;$check_count<=$out['check_count'];$check_count++)
117 if($check_count%2==1)
119 $bgcolor='#ddddff';
121 else
123 $bgcolor='#ffdddd';
125 $rs=sqlQ("select reference from ar_session where reference='".$out['check_number'.$check_count]."'");
126 if(sqlNumRows($rs)>0)
128 $bgcolor='#ff0000';
129 $WarningFlag=true;
131 $StringToEcho.="<tr bgcolor='$bgcolor'>";
132 $StringToEcho.="<td><input type='checkbox' name='chk".$out['check_number'.$check_count]."' value='".$out['check_number'.$check_count]."'/></td>";
133 $StringToEcho.="<td>".htmlspecialchars($out['check_number'.$check_count])."</td>";
134 $StringToEcho.="<td>".htmlspecialchars($out['payee_name'.$check_count])."</td>";
135 $StringToEcho.="<td align='right'>".htmlspecialchars(number_format($out['check_amount'.$check_count],2))."</td>";
136 $StringToEcho.="</tr>";
138 $StringToEcho.="<tr bgcolor='#cccccc'><td colspan='4' align='center'><input type='submit' name='CheckSubmit' value='Submit'/></td></tr>";
139 if($WarningFlag==true)
140 $StringToEcho.="<tr bgcolor='#ff0000'><td colspan='4' align='center'>".htmlspecialchars( xl('Warning, Check Number already exist in the database'), ENT_QUOTES)."</td></tr>";
141 $StringToEcho.="</table>";
143 else
145 for ($check_count=1;$check_count<=$out['check_count'];$check_count++)
147 $chk_num=$out['check_number'.$check_count];
148 $chk_num=str_replace(' ','_',$chk_num);
149 if(isset($_REQUEST['chk'.$chk_num]))
151 $check_date=$out['check_date'.$check_count]?$out['check_date'.$check_count]:$_REQUEST['paydate'];
152 $post_to_date=$_REQUEST['post_to_date']!=''?$_REQUEST['post_to_date']:date('Y-m-d');
153 $deposit_date=$_REQUEST['deposit_date']!=''?$_REQUEST['deposit_date']:date('Y-m-d');
154 $InsertionId[$out['check_number'.$check_count]]=arPostSession($_REQUEST['InsId'],$out['check_number'.$check_count],$out['check_date'.$check_count],$out['check_amount'.$check_count],$post_to_date,$deposit_date,$debug);
161 function era_callback(&$out) {
162 global $encount, $debug, $claim_status_codes, $adjustment_reasons, $remark_codes;
163 global $invoice_total, $last_code, $paydate, $INTEGRATED_AR;
164 global $InsertionId;//last inserted ID of
167 // Some heading information.
168 $chk_123=$out['check_number'];
169 $chk_123=str_replace(' ','_',$chk_123);
170 if(isset($_REQUEST['chk'.$chk_123])){
171 if ($encount == 0) {
172 writeMessageLine('#ffffff', 'infdetail',
173 "Payer: " . htmlspecialchars($out['payer_name'], ENT_QUOTES));
174 if ($debug) {
175 writeMessageLine('#ffffff', 'infdetail',
176 "WITHOUT UPDATE is selected; no changes will be applied.");
180 $last_code = '';
181 $invoice_total = 0.00;
182 $bgcolor = (++$encount & 1) ? "#ddddff" : "#ffdddd";
183 list($pid, $encounter, $invnumber) = slInvoiceNumber($out);
185 // Get details, if we have them, for the invoice.
186 $inverror = true;
187 $codes = array();
188 if ($pid && $encounter) {
189 // Get invoice data into $arrow or $ferow.
190 if ($INTEGRATED_AR) {
191 $ferow = sqlQuery("SELECT e.*, p.fname, p.mname, p.lname " .
192 "FROM form_encounter AS e, patient_data AS p WHERE " .
193 "e.pid = '$pid' AND e.encounter = '$encounter' AND ".
194 "p.pid = e.pid");
195 if (empty($ferow)) {
196 $pid = $encounter = 0;
197 $invnumber = $out['our_claim_id'];
198 } else {
199 $inverror = false;
200 $codes = ar_get_invoice_summary($pid, $encounter, true);
201 // $svcdate = substr($ferow['date'], 0, 10);
203 } // end internal a/r
204 else {
205 $arres = SLQuery("SELECT ar.id, ar.notes, ar.shipvia, customer.name " .
206 "FROM ar, customer WHERE ar.invnumber = '$invnumber' AND " .
207 "customer.id = ar.customer_id");
208 if ($sl_err) die($sl_err);
209 $arrow = SLGetRow($arres, 0);
210 if ($arrow) {
211 $inverror = false;
212 $codes = get_invoice_summary($arrow['id'], true);
213 } else { // oops, no such invoice
214 $pid = $encounter = 0;
215 $invnumber = $out['our_claim_id'];
217 } // end not internal a/r
220 // Show the claim status.
221 $csc = $out['claim_status_code'];
222 $inslabel = 'Ins1';
223 if ($csc == '1' || $csc == '19') $inslabel = 'Ins1';
224 if ($csc == '2' || $csc == '20') $inslabel = 'Ins2';
225 if ($csc == '3' || $csc == '21') $inslabel = 'Ins3';
226 $primary = ($inslabel == 'Ins1');
227 writeMessageLine($bgcolor, 'infdetail',
228 "Claim status $csc: " . $claim_status_codes[$csc]);
230 // Show an error message if the claim is missing or already posted.
231 if ($inverror) {
232 writeMessageLine($bgcolor, 'errdetail',
233 "The following claim is not in our database");
235 else {
236 // Skip this test. Claims can get multiple CLPs from the same payer!
238 // $insdone = strtolower($arrow['shipvia']);
239 // if (strpos($insdone, 'ins1') !== false) {
240 // $inverror = true;
241 // writeMessageLine($bgcolor, 'errdetail',
242 // "Primary insurance EOB was already posted for the following claim");
243 // }
246 if ($csc == '4') {//Denial case, code is stored in the claims table for display in the billing manager screen with reason explained.
247 $inverror = true;
248 if (!$debug) {
249 if ($pid && $encounter) {
250 $code_value = '';
251 foreach ($out['svc'] as $svc) {
252 foreach ($svc['adj'] as $adj) {//Per code and modifier the reason will be showed in the billing manager.
253 $code_value .= $svc['code'].'_'.$svc['mod'].'_'.$adj['group_code'].'_'.$adj['reason_code'].',';
256 $code_value = substr($code_value,0,-1);
257 //We store the reason code to display it with description in the billing manager screen.
258 //process_file is used as for the denial case file name will not be there, and extra field(to store reason) can be avoided.
259 updateClaim(true, $pid, $encounter, $_REQUEST['InsId'], substr($inslabel,3),7,0,$code_value);
262 writeMessageLine($bgcolor, 'errdetail',
263 "Not posting adjustments for denied claims, please follow up manually!");
265 else if ($csc == '22') {
266 $inverror = true;
267 writeMessageLine($bgcolor, 'errdetail',
268 "Payment reversals are not automated, please enter manually!");
271 if ($out['warnings']) {
272 writeMessageLine($bgcolor, 'infdetail', nl2br(rtrim($out['warnings'])));
275 // Simplify some claim attributes for cleaner code.
276 $service_date = parse_date($out['dos']);
277 $check_date = $paydate ? $paydate : parse_date($out['check_date']);
278 $production_date = $paydate ? $paydate : parse_date($out['production_date']);
280 if ($INTEGRATED_AR) {
281 $insurance_id = arGetPayerID($pid, $service_date, substr($inslabel, 3));
282 if (empty($ferow['lname'])) {
283 $patient_name = $out['patient_fname'] . ' ' . $out['patient_lname'];
284 } else {
285 $patient_name = $ferow['fname'] . ' ' . $ferow['lname'];
287 } else {
288 $insurance_id = 0;
289 foreach ($codes as $cdata) {
290 if ($cdata['ins']) {
291 $insurance_id = $cdata['ins'];
292 break;
295 $patient_name = $arrow['name'] ? $arrow['name'] :
296 ($out['patient_fname'] . ' ' . $out['patient_lname']);
299 $error = $inverror;
301 // This loops once for each service item in this claim.
302 foreach ($out['svc'] as $svc) {
304 // Treat a modifier in the remit data as part of the procedure key.
305 // This key will then make its way into SQL-Ledger.
306 $codekey = $svc['code'];
307 if ($svc['mod']) $codekey .= ':' . $svc['mod'];
308 $prev = $codes[$codekey];
310 // This reports detail lines already on file for this service item.
311 if ($prev) {
312 writeOldDetail($prev, $patient_name, $invnumber, $service_date, $codekey, $bgcolor);
313 // Check for sanity in amount charged.
314 $prevchg = sprintf("%.2f", $prev['chg'] + $prev['adj']);
315 if ($prevchg != abs($svc['chg'])) {
316 writeMessageLine($bgcolor, 'errdetail',
317 "EOB charge amount " . $svc['chg'] . " for this code does not match our invoice");
318 $error = true;
321 // Check for already-existing primary remittance activity.
322 // Removed this check because it was not allowing for copays manually
323 // entered into the invoice under a non-copay billing code.
324 /****
325 if ((sprintf("%.2f",$prev['chg']) != sprintf("%.2f",$prev['bal']) ||
326 $prev['adj'] != 0) && $primary)
328 writeMessageLine($bgcolor, 'errdetail',
329 "This service item already has primary payments and/or adjustments!");
330 $error = true;
332 ****/
334 unset($codes[$codekey]);
337 // If the service item is not in our database...
338 else {
340 // This is not an error. If we are not in error mode and not debugging,
341 // insert the service item into SL. Then display it (in green if it
342 // was inserted, or in red if we are in error mode).
343 $description = "CPT4:$codekey Added by $inslabel $production_date";
344 if (!$error && !$debug) {
345 if ($INTEGRATED_AR) {
346 arPostCharge($pid, $encounter, 0, $svc['chg'], 1, $service_date,
347 $codekey, $description, $debug);
348 } else {
349 slPostCharge($arrow['id'], $svc['chg'], 1, $service_date, $codekey,
350 $insurance_id, $description, $debug);
352 $invoice_total += $svc['chg'];
354 $class = $error ? 'errdetail' : 'newdetail';
355 writeDetailLine($bgcolor, $class, $patient_name, $invnumber,
356 $codekey, $production_date, $description,
357 $svc['chg'], ($error ? '' : $invoice_total));
361 $class = $error ? 'errdetail' : 'newdetail';
363 // Report Allowed Amount.
364 if ($svc['allowed']) {
365 // A problem here is that some payers will include an adjustment
366 // reflecting the allowed amount, others not. So here we need to
367 // check if the adjustment exists, and if not then create it. We
368 // assume that any nonzero CO (Contractual Obligation) or PI
369 // (Payer Initiated) adjustment is good enough.
370 $contract_adj = sprintf("%.2f", $svc['chg'] - $svc['allowed']);
371 foreach ($svc['adj'] as $adj) {
372 if (($adj['group_code'] == 'CO' || $adj['group_code'] == 'PI') && $adj['amount'] != 0)
373 $contract_adj = 0;
375 if ($contract_adj > 0) {
376 $svc['adj'][] = array('group_code' => 'CO', 'reason_code' => 'A2',
377 'amount' => $contract_adj);
379 writeMessageLine($bgcolor, 'infdetail',
380 'Allowed amount is ' . sprintf("%.2f", $svc['allowed']));
383 // Report miscellaneous remarks.
384 if ($svc['remark']) {
385 $rmk = $svc['remark'];
386 writeMessageLine($bgcolor, 'infdetail', "$rmk: " . $remark_codes[$rmk]);
389 // Post and report the payment for this service item from the ERA.
390 // By the way a 'Claim' level payment is probably going to be negative,
391 // i.e. a payment reversal.
392 if ($svc['paid']) {
393 if (!$error && !$debug) {
394 if ($INTEGRATED_AR) {
395 arPostPayment($pid, $encounter,$InsertionId[$out['check_number']], $svc['paid'],//$InsertionId[$out['check_number']] gives the session id
396 $codekey, substr($inslabel,3), $out['check_number'], $debug);
397 } else {
398 slPostPayment($arrow['id'], $svc['paid'], $check_date,
399 "$inslabel/" . $out['check_number'], $codekey, $insurance_id, $debug);
401 $invoice_total -= $svc['paid'];
403 $description = "$inslabel/" . $out['check_number'] . ' payment';
404 if ($svc['paid'] < 0) $description .= ' reversal';
405 writeDetailLine($bgcolor, $class, $patient_name, $invnumber,
406 $codekey, $check_date, $description,
407 0 - $svc['paid'], ($error ? '' : $invoice_total));
410 // Post and report adjustments from this ERA. Posted adjustment reasons
411 // must be 25 characters or less in order to fit on patient statements.
412 foreach ($svc['adj'] as $adj) {
413 $description = $adj['reason_code'] . ': ' . $adjustment_reasons[$adj['reason_code']];
414 if ($adj['group_code'] == 'PR' || !$primary) {
415 // Group code PR is Patient Responsibility. Enter these as zero
416 // adjustments to retain the note without crediting the claim.
417 if ($primary) {
418 /****
419 $reason = 'Pt resp: '; // Reasons should be 25 chars or less.
420 if ($adj['reason_code'] == '1') $reason = 'To deductible: ';
421 else if ($adj['reason_code'] == '2') $reason = 'Coinsurance: ';
422 else if ($adj['reason_code'] == '3') $reason = 'Co-pay: ';
423 ****/
424 $reason = "$inslabel ptresp: "; // Reasons should be 25 chars or less.
425 if ($adj['reason_code'] == '1') $reason = "$inslabel dedbl: ";
426 else if ($adj['reason_code'] == '2') $reason = "$inslabel coins: ";
427 else if ($adj['reason_code'] == '3') $reason = "$inslabel copay: ";
429 // Non-primary insurance adjustments are garbage, either repeating
430 // the primary or are not adjustments at all. Report them as notes
431 // but do not post any amounts.
432 else {
433 $reason = "$inslabel note " . $adj['reason_code'] . ': ';
434 /****
435 $reason .= sprintf("%.2f", $adj['amount']);
436 ****/
438 $reason .= sprintf("%.2f", $adj['amount']);
439 // Post a zero-dollar adjustment just to save it as a comment.
440 if (!$error && !$debug) {
441 if ($INTEGRATED_AR) {
442 arPostAdjustment($pid, $encounter, $InsertionId[$out['check_number']], 0, $codekey,//$InsertionId[$out['check_number']] gives the session id
443 substr($inslabel,3), $reason, $debug);
444 } else {
445 slPostAdjustment($arrow['id'], 0, $production_date,
446 $out['check_number'], $codekey, $insurance_id,
447 $reason, $debug);
450 writeMessageLine($bgcolor, $class, $description . ' ' .
451 sprintf("%.2f", $adj['amount']));
453 // Other group codes for primary insurance are real adjustments.
454 else {
455 if (!$error && !$debug) {
456 if ($INTEGRATED_AR) {
457 arPostAdjustment($pid, $encounter, $InsertionId[$out['check_number']], $adj['amount'],//$InsertionId[$out['check_number']] gives the session id
458 $codekey, substr($inslabel,3),
459 "Adjust code " . $adj['reason_code'], $debug);
460 } else {
461 slPostAdjustment($arrow['id'], $adj['amount'], $production_date,
462 $out['check_number'], $codekey, $insurance_id,
463 "$inslabel adjust code " . $adj['reason_code'], $debug);
465 $invoice_total -= $adj['amount'];
467 writeDetailLine($bgcolor, $class, $patient_name, $invnumber,
468 $codekey, $production_date, $description,
469 0 - $adj['amount'], ($error ? '' : $invoice_total));
473 } // End of service item
475 // Report any existing service items not mentioned in the ERA, and
476 // determine if any of them are still missing an insurance response
477 // (if so, then insurance is not yet done with the claim).
478 $insurance_done = true;
479 foreach ($codes as $code => $prev) {
480 // writeOldDetail($prev, $arrow['name'], $invnumber, $service_date, $code, $bgcolor);
481 writeOldDetail($prev, $patient_name, $invnumber, $service_date, $code, $bgcolor);
482 $got_response = false;
483 foreach ($prev['dtl'] as $ddata) {
484 if ($ddata['pmt'] || $ddata['rsn']) $got_response = true;
486 if (!$got_response) $insurance_done = false;
489 // Cleanup: If all is well, mark Ins<x> done and check for secondary billing.
490 if (!$error && !$debug && $insurance_done) {
491 if ($INTEGRATED_AR) {
492 $level_done = 0 + substr($inslabel, 3);
494 if($out['crossover']==1)
495 {//Automatic forward case.So need not again bill from the billing manager screen.
496 sqlStatement("UPDATE form_encounter " .
497 "SET last_level_closed = $level_done,last_level_billed=".$level_done." WHERE " .
498 "pid = '$pid' AND encounter = '$encounter'");
499 writeMessageLine($bgcolor, 'infdetail',
500 'This claim is processed by Insurance '.$level_done.' and automatically forwarded to Insurance '.($level_done+1) .' for processing. ');
502 else
504 "UPDATE form_encounter " .
505 "SET last_level_closed = $level_done WHERE " .
506 "pid = '$pid' AND encounter = '$encounter'";
508 // Check for secondary insurance.
509 if ($primary && arGetPayerID($pid, $service_date, 2)) {
510 arSetupSecondary($pid, $encounter, $debug,$out['crossover']);
512 if($out['crossover']<>1)
514 writeMessageLine($bgcolor, 'infdetail',
515 'This claim is now re-queued for secondary paper billing');
518 } else {
519 $shipvia = 'Done: Ins1';
520 if ($inslabel != 'Ins1') $shipvia .= ',Ins2';
521 if ($inslabel == 'Ins3') $shipvia .= ',Ins3';
522 $query = "UPDATE ar SET shipvia = '$shipvia' WHERE id = " . $arrow['id'];
523 SLQuery($query);
524 if ($sl_err) die($sl_err);
525 // Check for secondary insurance.
526 $insgot = strtolower($arrow['notes']);
527 if ($primary && strpos($insgot, 'ins2') !== false) {
528 slSetupSecondary($arrow['id'], $debug);
529 if($out['crossover']<>1)
531 writeMessageLine($bgcolor, 'infdetail',
532 'This claim is now re-queued for secondary paper billing');
540 /////////////////////////// End Functions ////////////////////////////
542 $info_msg = "";
544 $eraname = $_GET['eraname'];
545 if (! $eraname) die(xl("You cannot access this page directly."));
547 // Open the output file early so that in case it fails, we do not post a
548 // bunch of stuff without saving the report. Also be sure to retain any old
549 // report files. Do not save the report if this is a no-update situation.
551 if (!$debug) {
552 $nameprefix = $GLOBALS['OE_SITE_DIR'] . "/era/$eraname";
553 $namesuffix = '';
554 for ($i = 1; is_file("$nameprefix$namesuffix.html"); ++$i) {
555 $namesuffix = "_$i";
557 $fnreport = "$nameprefix$namesuffix.html";
558 $fhreport = fopen($fnreport, 'w');
559 if (!$fhreport) die(xl("Cannot create") . " '$fnreport'");
562 if (!$INTEGRATED_AR) slInitialize();
564 <html>
565 <head>
566 <?php html_header_show();?>
567 <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
568 <style type="text/css">
569 body { font-family:sans-serif; font-size:8pt; font-weight:normal }
570 .dehead { color:#000000; font-family:sans-serif; font-size:9pt; font-weight:bold }
571 .olddetail { color:#000000; font-family:sans-serif; font-size:9pt; font-weight:normal }
572 .newdetail { color:#00dd00; font-family:sans-serif; font-size:9pt; font-weight:normal }
573 .errdetail { color:#dd0000; font-family:sans-serif; font-size:9pt; font-weight:normal }
574 .infdetail { color:#0000ff; font-family:sans-serif; font-size:9pt; font-weight:normal }
575 </style>
576 <title><?php xl('EOB Posting - Electronic Remittances','e')?></title>
577 <script language="JavaScript">
578 </script>
579 </head>
580 <body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>
581 <form action="sl_eob_process.php" method="get" >
582 <center>
583 <?php
584 if($_GET['original']=='original')
586 $alertmsg = parse_era_for_check($GLOBALS['OE_SITE_DIR'] . "/era/$eraname.edi", 'era_callback');
587 echo $StringToEcho;
589 else
592 <table border='0' cellpadding='2' cellspacing='0' width='100%'>
594 <tr bgcolor="#cccccc">
595 <td class="dehead">
596 <?php echo htmlspecialchars( xl('Patient'), ENT_QUOTES) ?>
597 </td>
598 <td class="dehead">
599 <?php echo htmlspecialchars( xl('Invoice'), ENT_QUOTES) ?>
600 </td>
601 <td class="dehead">
602 <?php echo htmlspecialchars( xl('Code'), ENT_QUOTES) ?>
603 </td>
604 <td class="dehead">
605 <?php echo htmlspecialchars( xl('Date'), ENT_QUOTES) ?>
606 </td>
607 <td class="dehead">
608 <?php echo htmlspecialchars( xl('Description'), ENT_QUOTES) ?>
609 </td>
610 <td class="dehead" align="right">
611 <?php echo htmlspecialchars( xl('Amount'), ENT_QUOTES) ?>&nbsp;
612 </td>
613 <td class="dehead" align="right">
614 <?php echo htmlspecialchars( xl('Balance'), ENT_QUOTES) ?>&nbsp;
615 </td>
616 </tr>
618 <?php
619 global $InsertionId;
621 $eraname=$_REQUEST['eraname'];
622 $alertmsg = parse_era_for_check($GLOBALS['OE_SITE_DIR'] . "/era/$eraname.edi");
623 $alertmsg = parse_era($GLOBALS['OE_SITE_DIR'] . "/era/$eraname.edi", 'era_callback');
624 if(!$debug)
626 $StringIssue=htmlspecialchars( xl("Total Distribution for following check number is not full"), ENT_QUOTES).': ';
627 $StringPrint='No';
628 foreach($InsertionId as $key => $value)
630 $rs= sqlQ("select pay_total from ar_session where session_id='$value'");
631 $row=sqlFetchArray($rs);
632 $pay_total=$row['pay_total'];
633 $rs= sqlQ("select sum(pay_amount) sum_pay_amount from ar_activity where session_id='$value'");
634 $row=sqlFetchArray($rs);
635 $pay_amount=$row['sum_pay_amount'];
637 if(($pay_total-$pay_amount)<>0)
639 $StringIssue.=$key.' ';
640 $StringPrint='Yes';
643 if($StringPrint=='Yes')
644 echo "<script>alert('$StringIssue')</script>";
647 if (!$INTEGRATED_AR) slTerminate();
650 </table>
651 <?php
654 </center>
655 <script language="JavaScript">
656 <?php
657 if ($alertmsg) echo " alert('" . htmlspecialchars($alertmsg, ENT_QUOTES) . "');\n";
659 </script>
660 <input type="hidden" name="paydate" value="<?php echo DateToYYYYMMDD($_REQUEST['paydate']);?>" />
661 <input type="hidden" name="post_to_date" value="<?php echo DateToYYYYMMDD($_REQUEST['post_to_date']);?>" />
662 <input type="hidden" name="deposit_date" value="<?php echo DateToYYYYMMDD($_REQUEST['deposit_date']);?>" />
663 <input type="hidden" name="debug" value="<?php echo $_REQUEST['debug'];?>" />
664 <input type="hidden" name="InsId" value="<?php echo $_REQUEST['InsId'];?>" />
665 <input type="hidden" name="eraname" value="<?php echo $eraname?>" />
666 </form>
667 </body>
668 </html>
669 <?php
670 // Save all of this script's output to a report file.
671 if (!$debug) {
672 fwrite($fhreport, ob_get_contents());
673 fclose($fhreport);
675 ob_end_flush();