CAMOS bug fix, which substitutes values for placeholders before submission of
[openemr.git] / interface / billing / sl_eob_process.php
blobe0a8bd1f3047e5f717d0955a6079e0e68dcabaaa
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");
23 $debug = $_GET['debug'] ? 1 : 0; // set to 1 for debugging mode
24 $paydate = parse_date($_GET['paydate']);
25 $encount = 0;
27 $last_ptname = '';
28 $last_invnumber = '';
29 $last_code = '';
30 $invoice_total = 0.00;
31 $InsertionId;//last inserted ID of
32 $INTEGRATED_AR = $GLOBALS['oer_config']['ws_accounting']['enabled'] === 2;
34 ///////////////////////// Assorted Functions /////////////////////////
36 function parse_date($date) {
37 $date = substr(trim($date), 0, 10);
38 if (preg_match('/^(\d\d\d\d)\D*(\d\d)\D*(\d\d)$/', $date, $matches)) {
39 return $matches[1] . '-' . $matches[2] . '-' . $matches[3];
41 return '';
44 function writeMessageLine($bgcolor, $class, $description) {
45 $dline =
46 " <tr bgcolor='$bgcolor'>\n" .
47 " <td class='$class' colspan='4'>&nbsp;</td>\n" .
48 " <td class='$class'>$description</td>\n" .
49 " <td class='$class' colspan='2'>&nbsp;</td>\n" .
50 " </tr>\n";
51 echo $dline;
54 function writeDetailLine($bgcolor, $class, $ptname, $invnumber,
55 $code, $date, $description, $amount, $balance)
57 global $last_ptname, $last_invnumber, $last_code;
58 if ($ptname == $last_ptname) $ptname = '&nbsp;';
59 else $last_ptname = $ptname;
60 if ($invnumber == $last_invnumber) $invnumber = '&nbsp;';
61 else $last_invnumber = $invnumber;
62 if ($code == $last_code) $code = '&nbsp;';
63 else $last_code = $code;
64 if ($amount ) $amount = sprintf("%.2f", $amount );
65 if ($balance) $balance = sprintf("%.2f", $balance);
66 $dline =
67 " <tr bgcolor='$bgcolor'>\n" .
68 " <td class='$class'>$ptname</td>\n" .
69 " <td class='$class'>$invnumber</td>\n" .
70 " <td class='$class'>$code</td>\n" .
71 " <td class='$class'>" . oeFormatShortDate($date) . "</td>\n" .
72 " <td class='$class'>$description</td>\n" .
73 " <td class='$class' align='right'>" . oeFormatMoney($amount) . "</td>\n" .
74 " <td class='$class' align='right'>" . oeFormatMoney($balance) . "</td>\n" .
75 " </tr>\n";
76 echo $dline;
79 // This writes detail lines that were already in SQL-Ledger for a given
80 // charge item.
82 function writeOldDetail(&$prev, $ptname, $invnumber, $dos, $code, $bgcolor) {
83 global $invoice_total;
84 // $prev['total'] = 0.00; // to accumulate total charges
85 ksort($prev['dtl']);
86 foreach ($prev['dtl'] as $dkey => $ddata) {
87 $ddate = substr($dkey, 0, 10);
88 $description = $ddata['src'] . $ddata['rsn'];
89 if ($ddate == ' ') { // this is the service item
90 $ddate = $dos;
91 $description = 'Service Item';
93 $amount = sprintf("%.2f", $ddata['chg'] - $ddata['pmt']);
94 $invoice_total = sprintf("%.2f", $invoice_total + $amount);
95 writeDetailLine($bgcolor, 'olddetail', $ptname, $invnumber,
96 $code, $ddate, $description, $amount, $invoice_total);
100 // This is called back by parse_era() once per claim.
102 function era_callback_check(&$out)
105 global $InsertionId;//last inserted ID of
106 global $StringToEcho,$debug;
108 if($_GET['original']=='original')
110 $StringToEcho="<br/><br/><br/><br/><br/><br/>";
111 $StringToEcho.="<table border='1' cellpadding='0' cellspacing='0' width='750'>";
112 $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>";
113 $WarningFlag=false;
114 for ($check_count=1;$check_count<=$out['check_count'];$check_count++)
116 if($check_count%2==1)
118 $bgcolor='#ddddff';
120 else
122 $bgcolor='#ffdddd';
124 $rs=sqlQ("select reference from ar_session where reference='".$out['check_number'.$check_count]."'");
125 if(sqlNumRows($rs)>0)
127 $bgcolor='#ff0000';
128 $WarningFlag=true;
130 $StringToEcho.="<tr bgcolor='$bgcolor'>";
131 $StringToEcho.="<td><input type='checkbox' name='chk".$out['check_number'.$check_count]."' value='".$out['check_number'.$check_count]."'/></td>";
132 $StringToEcho.="<td>".htmlspecialchars($out['check_number'.$check_count])."</td>";
133 $StringToEcho.="<td>".htmlspecialchars($out['payee_name'.$check_count])."</td>";
134 $StringToEcho.="<td align='right'>".htmlspecialchars(number_format($out['check_amount'.$check_count],2))."</td>";
135 $StringToEcho.="</tr>";
137 $StringToEcho.="<tr bgcolor='#cccccc'><td colspan='4' align='center'><input type='submit' name='CheckSubmit' value='Submit'/></td></tr>";
138 if($WarningFlag==true)
139 $StringToEcho.="<tr bgcolor='#ff0000'><td colspan='4' align='center'>".htmlspecialchars( xl('Warning Cheque Number already exist in the database'), ENT_QUOTES)."</td></tr>";
140 $StringToEcho.="</table>";
142 else
144 for ($check_count=1;$check_count<=$out['check_count'];$check_count++)
147 if(isset($_REQUEST['chk'.$out['check_number'.$check_count]]))
149 $check_date=$out['check_date'.$check_count]?$out['check_date'.$check_count]:$_REQUEST['paydate'];
150 $post_to_date=$_REQUEST['post_to_date']!=''?$_REQUEST['post_to_date']:date('Y-m-d');
151 $deposit_date=$_REQUEST['deposit_date']!=''?$_REQUEST['deposit_date']:date('Y-m-d');
152 $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);
159 function era_callback(&$out) {
160 global $encount, $debug, $claim_status_codes, $adjustment_reasons, $remark_codes;
161 global $invoice_total, $last_code, $paydate, $INTEGRATED_AR;
162 global $InsertionId;//last inserted ID of
165 // Some heading information.
166 if(isset($_REQUEST['chk'.$out['check_number']])){
167 if ($encount == 0) {
168 writeMessageLine('#ffffff', 'infdetail',
169 "Payer: " . htmlspecialchars($out['payer_name'], ENT_QUOTES));
170 if ($debug) {
171 writeMessageLine('#ffffff', 'infdetail',
172 "WITHOUT UPDATE is selected; no changes will be applied.");
176 $last_code = '';
177 $invoice_total = 0.00;
178 $bgcolor = (++$encount & 1) ? "#ddddff" : "#ffdddd";
179 list($pid, $encounter, $invnumber) = slInvoiceNumber($out);
181 // Get details, if we have them, for the invoice.
182 $inverror = true;
183 $codes = array();
184 if ($pid && $encounter) {
185 // Get invoice data into $arrow or $ferow.
186 if ($INTEGRATED_AR) {
187 $ferow = sqlQuery("SELECT e.*, p.fname, p.mname, p.lname " .
188 "FROM form_encounter AS e, patient_data AS p WHERE " .
189 "e.pid = '$pid' AND e.encounter = '$encounter' AND ".
190 "p.pid = e.pid");
191 if (empty($ferow)) {
192 $pid = $encounter = 0;
193 $invnumber = $out['our_claim_id'];
194 } else {
195 $inverror = false;
196 $codes = ar_get_invoice_summary($pid, $encounter, true);
197 // $svcdate = substr($ferow['date'], 0, 10);
199 } // end internal a/r
200 else {
201 $arres = SLQuery("SELECT ar.id, ar.notes, ar.shipvia, customer.name " .
202 "FROM ar, customer WHERE ar.invnumber = '$invnumber' AND " .
203 "customer.id = ar.customer_id");
204 if ($sl_err) die($sl_err);
205 $arrow = SLGetRow($arres, 0);
206 if ($arrow) {
207 $inverror = false;
208 $codes = get_invoice_summary($arrow['id'], true);
209 } else { // oops, no such invoice
210 $pid = $encounter = 0;
211 $invnumber = $out['our_claim_id'];
213 } // end not internal a/r
216 // Show the claim status.
217 $csc = $out['claim_status_code'];
218 $inslabel = 'Ins1';
219 if ($csc == '1' || $csc == '19') $inslabel = 'Ins1';
220 if ($csc == '2' || $csc == '20') $inslabel = 'Ins2';
221 if ($csc == '3' || $csc == '21') $inslabel = 'Ins3';
222 $primary = ($inslabel == 'Ins1');
223 writeMessageLine($bgcolor, 'infdetail',
224 "Claim status $csc: " . $claim_status_codes[$csc]);
226 // Show an error message if the claim is missing or already posted.
227 if ($inverror) {
228 writeMessageLine($bgcolor, 'errdetail',
229 "The following claim is not in our database");
231 else {
232 // Skip this test. Claims can get multiple CLPs from the same payer!
234 // $insdone = strtolower($arrow['shipvia']);
235 // if (strpos($insdone, 'ins1') !== false) {
236 // $inverror = true;
237 // writeMessageLine($bgcolor, 'errdetail',
238 // "Primary insurance EOB was already posted for the following claim");
239 // }
242 if ($csc == '4') {
243 $inverror = true;
244 writeMessageLine($bgcolor, 'errdetail',
245 "Not posting adjustments for denied claims, please follow up manually!");
247 else if ($csc == '22') {
248 $inverror = true;
249 writeMessageLine($bgcolor, 'errdetail',
250 "Payment reversals are not automated, please enter manually!");
253 if ($out['warnings']) {
254 writeMessageLine($bgcolor, 'infdetail', nl2br(rtrim($out['warnings'])));
257 // Simplify some claim attributes for cleaner code.
258 $service_date = parse_date($out['dos']);
259 $check_date = $paydate ? $paydate : parse_date($out['check_date']);
260 $production_date = $paydate ? $paydate : parse_date($out['production_date']);
262 if ($INTEGRATED_AR) {
263 $insurance_id = arGetPayerID($pid, $service_date, substr($inslabel, 3));
264 if (empty($ferow['lname'])) {
265 $patient_name = $out['patient_fname'] . ' ' . $out['patient_lname'];
266 } else {
267 $patient_name = $ferow['fname'] . ' ' . $ferow['lname'];
269 } else {
270 $insurance_id = 0;
271 foreach ($codes as $cdata) {
272 if ($cdata['ins']) {
273 $insurance_id = $cdata['ins'];
274 break;
277 $patient_name = $arrow['name'] ? $arrow['name'] :
278 ($out['patient_fname'] . ' ' . $out['patient_lname']);
281 $error = $inverror;
283 // This loops once for each service item in this claim.
284 foreach ($out['svc'] as $svc) {
286 // Treat a modifier in the remit data as part of the procedure key.
287 // This key will then make its way into SQL-Ledger.
288 $codekey = $svc['code'];
289 if ($svc['mod']) $codekey .= ':' . $svc['mod'];
290 $prev = $codes[$codekey];
292 // This reports detail lines already on file for this service item.
293 if ($prev) {
294 writeOldDetail($prev, $patient_name, $invnumber, $service_date, $codekey, $bgcolor);
295 // Check for sanity in amount charged.
296 $prevchg = sprintf("%.2f", $prev['chg'] + $prev['adj']);
297 if ($prevchg != abs($svc['chg'])) {
298 writeMessageLine($bgcolor, 'errdetail',
299 "EOB charge amount " . $svc['chg'] . " for this code does not match our invoice");
300 $error = true;
303 // Check for already-existing primary remittance activity.
304 // Removed this check because it was not allowing for copays manually
305 // entered into the invoice under a non-copay billing code.
306 /****
307 if ((sprintf("%.2f",$prev['chg']) != sprintf("%.2f",$prev['bal']) ||
308 $prev['adj'] != 0) && $primary)
310 writeMessageLine($bgcolor, 'errdetail',
311 "This service item already has primary payments and/or adjustments!");
312 $error = true;
314 ****/
316 unset($codes[$codekey]);
319 // If the service item is not in our database...
320 else {
322 // This is not an error. If we are not in error mode and not debugging,
323 // insert the service item into SL. Then display it (in green if it
324 // was inserted, or in red if we are in error mode).
325 $description = "CPT4:$codekey Added by $inslabel $production_date";
326 if (!$error && !$debug) {
327 if ($INTEGRATED_AR) {
328 arPostCharge($pid, $encounter, 0, $svc['chg'], 1, $service_date,
329 $codekey, $description, $debug);
330 } else {
331 slPostCharge($arrow['id'], $svc['chg'], 1, $service_date, $codekey,
332 $insurance_id, $description, $debug);
334 $invoice_total += $svc['chg'];
336 $class = $error ? 'errdetail' : 'newdetail';
337 writeDetailLine($bgcolor, $class, $patient_name, $invnumber,
338 $codekey, $production_date, $description,
339 $svc['chg'], ($error ? '' : $invoice_total));
343 $class = $error ? 'errdetail' : 'newdetail';
345 // Report Allowed Amount.
346 if ($svc['allowed']) {
347 // A problem here is that some payers will include an adjustment
348 // reflecting the allowed amount, others not. So here we need to
349 // check if the adjustment exists, and if not then create it. We
350 // assume that any nonzero CO (Contractual Obligation) or PI
351 // (Payer Initiated) adjustment is good enough.
352 $contract_adj = sprintf("%.2f", $svc['chg'] - $svc['allowed']);
353 foreach ($svc['adj'] as $adj) {
354 if (($adj['group_code'] == 'CO' || $adj['group_code'] == 'PI') && $adj['amount'] != 0)
355 $contract_adj = 0;
357 if ($contract_adj > 0) {
358 $svc['adj'][] = array('group_code' => 'CO', 'reason_code' => 'A2',
359 'amount' => $contract_adj);
361 writeMessageLine($bgcolor, 'infdetail',
362 'Allowed amount is ' . sprintf("%.2f", $svc['allowed']));
365 // Report miscellaneous remarks.
366 if ($svc['remark']) {
367 $rmk = $svc['remark'];
368 writeMessageLine($bgcolor, 'infdetail', "$rmk: " . $remark_codes[$rmk]);
371 // Post and report the payment for this service item from the ERA.
372 // By the way a 'Claim' level payment is probably going to be negative,
373 // i.e. a payment reversal.
374 if ($svc['paid']) {
375 if (!$error && !$debug) {
376 if ($INTEGRATED_AR) {
377 arPostPayment($pid, $encounter,$InsertionId[$out['check_number']], $svc['paid'],//$InsertionId[$out['check_number']] gives the session id
378 $codekey, substr($inslabel,3), $out['check_number'], $debug);
379 } else {
380 slPostPayment($arrow['id'], $svc['paid'], $check_date,
381 "$inslabel/" . $out['check_number'], $codekey, $insurance_id, $debug);
383 $invoice_total -= $svc['paid'];
385 $description = "$inslabel/" . $out['check_number'] . ' payment';
386 if ($svc['paid'] < 0) $description .= ' reversal';
387 writeDetailLine($bgcolor, $class, $patient_name, $invnumber,
388 $codekey, $check_date, $description,
389 0 - $svc['paid'], ($error ? '' : $invoice_total));
392 // Post and report adjustments from this ERA. Posted adjustment reasons
393 // must be 25 characters or less in order to fit on patient statements.
394 foreach ($svc['adj'] as $adj) {
395 $description = $adj['reason_code'] . ': ' . $adjustment_reasons[$adj['reason_code']];
396 if ($adj['group_code'] == 'PR' || !$primary) {
397 // Group code PR is Patient Responsibility. Enter these as zero
398 // adjustments to retain the note without crediting the claim.
399 if ($primary) {
400 /****
401 $reason = 'Pt resp: '; // Reasons should be 25 chars or less.
402 if ($adj['reason_code'] == '1') $reason = 'To deductible: ';
403 else if ($adj['reason_code'] == '2') $reason = 'Coinsurance: ';
404 else if ($adj['reason_code'] == '3') $reason = 'Co-pay: ';
405 ****/
406 $reason = "$inslabel ptresp: "; // Reasons should be 25 chars or less.
407 if ($adj['reason_code'] == '1') $reason = "$inslabel dedbl: ";
408 else if ($adj['reason_code'] == '2') $reason = "$inslabel coins: ";
409 else if ($adj['reason_code'] == '3') $reason = "$inslabel copay: ";
411 // Non-primary insurance adjustments are garbage, either repeating
412 // the primary or are not adjustments at all. Report them as notes
413 // but do not post any amounts.
414 else {
415 $reason = "$inslabel note " . $adj['reason_code'] . ': ';
416 /****
417 $reason .= sprintf("%.2f", $adj['amount']);
418 ****/
420 $reason .= sprintf("%.2f", $adj['amount']);
421 // Post a zero-dollar adjustment just to save it as a comment.
422 if (!$error && !$debug) {
423 if ($INTEGRATED_AR) {
424 arPostAdjustment($pid, $encounter, $InsertionId[$out['check_number']], 0, $codekey,//$InsertionId[$out['check_number']] gives the session id
425 substr($inslabel,3), $reason, $debug);
426 } else {
427 slPostAdjustment($arrow['id'], 0, $production_date,
428 $out['check_number'], $codekey, $insurance_id,
429 $reason, $debug);
432 writeMessageLine($bgcolor, $class, $description . ' ' .
433 sprintf("%.2f", $adj['amount']));
435 // Other group codes for primary insurance are real adjustments.
436 else {
437 if (!$error && !$debug) {
438 if ($INTEGRATED_AR) {
439 arPostAdjustment($pid, $encounter, $InsertionId[$out['check_number']], $adj['amount'],//$InsertionId[$out['check_number']] gives the session id
440 $codekey, substr($inslabel,3),
441 "Adjust code " . $adj['reason_code'], $debug);
442 } else {
443 slPostAdjustment($arrow['id'], $adj['amount'], $production_date,
444 $out['check_number'], $codekey, $insurance_id,
445 "$inslabel adjust code " . $adj['reason_code'], $debug);
447 $invoice_total -= $adj['amount'];
449 writeDetailLine($bgcolor, $class, $patient_name, $invnumber,
450 $codekey, $production_date, $description,
451 0 - $adj['amount'], ($error ? '' : $invoice_total));
455 } // End of service item
457 // Report any existing service items not mentioned in the ERA, and
458 // determine if any of them are still missing an insurance response
459 // (if so, then insurance is not yet done with the claim).
460 $insurance_done = true;
461 foreach ($codes as $code => $prev) {
462 // writeOldDetail($prev, $arrow['name'], $invnumber, $service_date, $code, $bgcolor);
463 writeOldDetail($prev, $patient_name, $invnumber, $service_date, $code, $bgcolor);
464 $got_response = false;
465 foreach ($prev['dtl'] as $ddata) {
466 if ($ddata['pmt'] || $ddata['rsn']) $got_response = true;
468 if (!$got_response) $insurance_done = false;
471 // Cleanup: If all is well, mark Ins<x> done and check for secondary billing.
472 if (!$error && !$debug && $insurance_done) {
473 if ($INTEGRATED_AR) {
474 $level_done = 0 + substr($inslabel, 3);
475 sqlStatement("UPDATE form_encounter " .
476 "SET last_level_closed = $level_done WHERE " .
477 "pid = '$pid' AND encounter = '$encounter'");
478 // Check for secondary insurance.
479 if ($primary && arGetPayerID($pid, $service_date, 2)) {
480 arSetupSecondary($pid, $encounter, $debug);
481 writeMessageLine($bgcolor, 'infdetail',
482 'This claim is now re-queued for secondary paper billing');
484 } else {
485 $shipvia = 'Done: Ins1';
486 if ($inslabel != 'Ins1') $shipvia .= ',Ins2';
487 if ($inslabel == 'Ins3') $shipvia .= ',Ins3';
488 $query = "UPDATE ar SET shipvia = '$shipvia' WHERE id = " . $arrow['id'];
489 SLQuery($query);
490 if ($sl_err) die($sl_err);
491 // Check for secondary insurance.
492 $insgot = strtolower($arrow['notes']);
493 if ($primary && strpos($insgot, 'ins2') !== false) {
494 slSetupSecondary($arrow['id'], $debug);
495 writeMessageLine($bgcolor, 'infdetail',
496 'This claim is now re-queued for secondary paper billing');
503 /////////////////////////// End Functions ////////////////////////////
505 $info_msg = "";
507 $eraname = $_GET['eraname'];
508 if (! $eraname) die(xl("You cannot access this page directly."));
510 // Open the output file early so that in case it fails, we do not post a
511 // bunch of stuff without saving the report. Also be sure to retain any old
512 // report files. Do not save the report if this is a no-update situation.
514 if (!$debug) {
515 $nameprefix = $GLOBALS['OE_SITE_DIR'] . "/era/$eraname";
516 $namesuffix = '';
517 for ($i = 1; is_file("$nameprefix$namesuffix.html"); ++$i) {
518 $namesuffix = "_$i";
520 $fnreport = "$nameprefix$namesuffix.html";
521 $fhreport = fopen($fnreport, 'w');
522 if (!$fhreport) die(xl("Cannot create") . " '$fnreport'");
525 if (!$INTEGRATED_AR) slInitialize();
527 <html>
528 <head>
529 <? html_header_show();?>
530 <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
531 <style type="text/css">
532 body { font-family:sans-serif; font-size:8pt; font-weight:normal }
533 .dehead { color:#000000; font-family:sans-serif; font-size:9pt; font-weight:bold }
534 .olddetail { color:#000000; font-family:sans-serif; font-size:9pt; font-weight:normal }
535 .newdetail { color:#00dd00; font-family:sans-serif; font-size:9pt; font-weight:normal }
536 .errdetail { color:#dd0000; font-family:sans-serif; font-size:9pt; font-weight:normal }
537 .infdetail { color:#0000ff; font-family:sans-serif; font-size:9pt; font-weight:normal }
538 </style>
539 <title><?php xl('EOB Posting - Electronic Remittances','e')?></title>
540 <script language="JavaScript">
541 </script>
542 </head>
543 <body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>
544 <form action="sl_eob_process.php" method="get" >
545 <center>
546 <?php
547 if($_GET['original']=='original')
549 $alertmsg = parse_era_for_check($GLOBALS['OE_SITE_DIR'] . "/era/$eraname.edi", 'era_callback');
550 echo $StringToEcho;
552 else
555 <table border='0' cellpadding='2' cellspacing='0' width='100%'>
557 <tr bgcolor="#cccccc">
558 <td class="dehead">
559 <?php echo htmlspecialchars( xl('Patient'), ENT_QUOTES) ?>
560 </td>
561 <td class="dehead">
562 <?php echo htmlspecialchars( xl('Invoice'), ENT_QUOTES) ?>
563 </td>
564 <td class="dehead">
565 <?php echo htmlspecialchars( xl('Code'), ENT_QUOTES) ?>
566 </td>
567 <td class="dehead">
568 <?php echo htmlspecialchars( xl('Date'), ENT_QUOTES) ?>
569 </td>
570 <td class="dehead">
571 <?php echo htmlspecialchars( xl('Description'), ENT_QUOTES) ?>
572 </td>
573 <td class="dehead" align="right">
574 <?php echo htmlspecialchars( xl('Amount'), ENT_QUOTES) ?>&nbsp;
575 </td>
576 <td class="dehead" align="right">
577 <?php echo htmlspecialchars( xl('Balance'), ENT_QUOTES) ?>&nbsp;
578 </td>
579 </tr>
581 <?php
582 global $InsertionId;
584 $eraname=$_REQUEST['eraname'];
585 $alertmsg = parse_era_for_check($GLOBALS['OE_SITE_DIR'] . "/era/$eraname.edi");
586 $alertmsg = parse_era($GLOBALS['OE_SITE_DIR'] . "/era/$eraname.edi", 'era_callback');
587 if(!$debug)
589 $StringIssue=htmlspecialchars( xl("Total Distribution for following check number is not full"), ENT_QUOTES).': ';
590 $StringPrint='No';
591 foreach($InsertionId as $key => $value)
593 $rs= sqlQ("select pay_total from ar_session where session_id='$value'");
594 $row=sqlFetchArray($rs);
595 $pay_total=$row['pay_total'];
596 $rs= sqlQ("select sum(pay_amount) sum_pay_amount from ar_activity where session_id='$value'");
597 $row=sqlFetchArray($rs);
598 $pay_amount=$row['sum_pay_amount'];
600 if(($pay_total-$pay_amount)<>0)
602 $StringIssue.=$key.' ';
603 $StringPrint='Yes';
606 if($StringPrint=='Yes')
607 echo "<script>alert('$StringIssue')</script>";
610 if (!$INTEGRATED_AR) slTerminate();
613 </table>
614 <?php
617 </center>
618 <script language="JavaScript">
619 <?php
620 if ($alertmsg) echo " alert('" . htmlspecialchars($alertmsg, ENT_QUOTES) . "');\n";
622 </script>
623 <input type="hidden" name="paydate" value="<?php echo DateToYYYYMMDD($_REQUEST['paydate']);?>" />
624 <input type="hidden" name="post_to_date" value="<?php echo DateToYYYYMMDD($_REQUEST['post_to_date']);?>" />
625 <input type="hidden" name="deposit_date" value="<?php echo DateToYYYYMMDD($_REQUEST['deposit_date']);?>" />
626 <input type="hidden" name="debug" value="<?php echo $_REQUEST['debug'];?>" />
627 <input type="hidden" name="InsId" value="<?php echo $_REQUEST['InsId'];?>" />
628 <input type="hidden" name="eraname" value="<?php echo $eraname?>" />
629 </form>
630 </body>
631 </html>
632 <?php
633 // Save all of this script's output to a report file.
634 if (!$debug) {
635 fwrite($fhreport, ob_get_contents());
636 fclose($fhreport);
638 ob_end_flush();