bug fix march continued (#1921)
[openemr.git] / interface / billing / sl_eob_invoice.php
blobba74c277b2072b84583cf3c2d32028e90f6c6962
1 <?php
2 /**
3 * This provides for manual posting of EOBs. It is invoked from
4 * sl_eob_search.php. For automated (X12 835) remittance posting
5 * see sl_eob_process.php.
7 * Copyright (C) 2005-2016 Rod Roark <rod@sunsetsystems.com>
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 * @author Jerry Padgett <sjpadgett@gmail.com>
25 * @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");
37 use OpenEMR\Core\Header;
39 $debug = 0; // set to 1 for debugging mode
40 $save_stay = $_REQUEST['form_save'] == '1' ? true : false;
42 // If we permit deletion of transactions. Might change this later.
43 $ALLOW_DELETE = true;
45 $info_msg = "";
47 // Format money for display.
49 function bucks($amount)
51 if ($amount) {
52 return sprintf("%.2f", $amount);
56 // Delete rows, with logging, for the specified table using the
57 // specified WHERE clause. Borrowed from deleter.php.
59 function row_delete($table, $where)
61 $tres = sqlStatement("SELECT * FROM $table WHERE $where");
62 $count = 0;
63 while ($trow = sqlFetchArray($tres)) {
64 $logstring = "";
65 foreach ($trow as $key => $value) {
66 if (!$value || $value == '0000-00-00 00:00:00') {
67 continue;
70 if ($logstring) {
71 $logstring .= " ";
74 $logstring .= $key . "='" . addslashes($value) . "'";
77 newEvent("delete", $_SESSION['authUser'], $_SESSION['authProvider'], 1, "$table: $logstring");
78 ++$count;
81 if ($count) { // Lets not echo the query for stay and save
82 $query = "DELETE FROM $table WHERE $where";
83 sqlStatement($query);
88 <html>
89 <head>
90 <?php Header::setupHeader(['datetime-picker']); ?>
91 <title><?php echo xlt('EOB Posting - Invoice') ?></title>
92 <script language="JavaScript">
93 var adjDisable = opener.document.forms[0].posting_adj_disable.checked;
95 // An insurance radio button is selected.
96 function setins(istr) {
97 return true;
100 function goEncounterSummary (pid) {
101 if(pid) {
102 opener.toEncSummary(pid);
104 window.close();
107 // Compute an adjustment that writes off the balance:
108 function writeoff(code) {
109 var f = document.forms[0];
110 var belement = f['form_line[' + code + '][bal]'];
111 var pelement = f['form_line[' + code + '][pay]'];
112 var aelement = f['form_line[' + code + '][adj]'];
113 var relement = f['form_line[' + code + '][reason]'];
114 var tmp = belement.value - pelement.value;
115 aelement.value = Number(tmp).toFixed(2);
116 if (aelement.value && !relement.value) relement.selectedIndex = 1;
117 return false;
120 // Onsubmit handler. A good excuse to write some JavaScript.
121 function validate(f) {
122 let delcount = 0;
123 let allempty = true;
124 adjDisable = opener.document.forms[0].posting_adj_disable.checked;
126 for (var i = 0; i < f.elements.length; ++i) {
127 let ename = f.elements[i].name;
128 // Count deletes.
129 if (ename.substring(0, 9) == 'form_del[') {
130 if (f.elements[i].checked) ++delcount;
131 continue;
133 let pfxlen = ename.indexOf('[pay]');
134 if (pfxlen < 0) continue;
135 let pfx = ename.substring(0, pfxlen);
136 let code = pfx.substring(pfx.indexOf('[') + 1, pfxlen - 1);
137 let cPay = parseFloat(f[pfx + '[pay]'].value).toFixed(2);
138 let cAdjust = parseFloat(f[pfx + '[adj]'].value).toFixed(2);
140 if ((cPay != 0) || cAdjust != 0) {
141 allempty = false;
143 if(adjDisable) {
144 if ((cAdjust == 0 && f[pfx + '[reason]'].value)) {
145 allempty = false;
148 if ((cPay != 0) && isNaN(parseFloat(f[pfx + '[pay]'].value))) {
149 alert('<?php echo xls('Payment value for code ') ?>' + code + '<?php echo xls(' is not a number') ?>');
150 return false;
152 if ((cAdjust != 0) && isNaN(parseFloat(f[pfx + '[adj]'].value))) {
153 alert('<?php echo xls('Adjustment value for code ') ?>' + code + '<?php echo xls(' is not a number') ?>');
154 return false;
156 if ((cAdjust != 0) && !f[pfx + '[reason]'].value) {
157 alert('<?php echo xls('Please select an adjustment reason for code ') ?>' + code);
158 return false;
160 // TBD: validate the date format
162 // Check if save is clicked with nothing to post.
163 if (allempty && delcount === 0) {
164 alert('<?php echo xls('Nothing to Post! Please review entries or use Cancel to exit transaction')?>');
165 return false;
167 // Demand confirmation if deleting anything.
168 if (delcount > 0) {
169 if (!confirm('<?php echo xls('Really delete'); ?> ' + delcount +
170 ' <?php echo xls('transactions'); ?>?' +
171 ' <?php echo xls('This action will be logged'); ?>!')
172 ) return false;
174 return true;
177 <!-- Get current date -->
179 function getFormattedToday() {
180 let today = new Date();
181 let dd = today.getDate();
182 let mm = today.getMonth() + 1; //January is 0!
183 let yyyy = today.getFullYear();
184 if (dd < 10) {
185 dd = '0' + dd
187 if (mm < 10) {
188 mm = '0' + mm
191 return (yyyy + '-' + mm + '-' + dd);
194 <!-- Update Payment Fields -->
196 function updateFields(payField, adjField, balField, coPayField, isFirstProcCode) {
197 let payAmount = 0.0;
198 let adjAmount = 0.0;
199 let balAmount = 0.0;
200 let coPayAmount = 0.0;
202 // coPayFiled will be null if there is no co-pay entry in the fee sheet
203 if (coPayField)
204 coPayAmount = coPayField.value;
206 // if balance field is 0.00, its value comes back as null, so check for nul-ness first
207 if (balField)
208 balAmount = (balField.value) ? balField.value : 0;
209 if (payField)
210 payAmount = (payField.value) ? payField.value : 0;
212 //alert('balance = >' + balAmount +'< payAmount = ' + payAmount + ' copay = ' + coPayAmount + ' isFirstProcCode = ' + isFirstProcCode);
214 // subtract the co-pay only from the first procedure code
215 if (isFirstProcCode == 1)
216 balAmount = parseFloat(balAmount) + parseFloat(coPayAmount);
217 let adjDisable = opener.document.forms[0].posting_adj_disable.checked;
218 if (adjDisable) return;
220 adjAmount = balAmount - payAmount;
221 // Assign rounded adjustment value back to TextField
222 adjField.value = adjAmount = Math.round(adjAmount * 100) / 100;
225 $(document).ready(function () {
226 $('.datepicker').datetimepicker({
227 <?php $datetimepicker_timepicker = false; ?>
228 <?php $datetimepicker_showseconds = false; ?>
229 <?php $datetimepicker_formatInput = false; ?>
230 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
231 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
235 </script>
236 <style>
237 @media only screen and (max-width: 768px) {
238 [class*="col-"] {
239 width: 100%;
240 text-align: left !Important;
244 .table {
245 margin: auto;
246 width: 99%;
249 .table > tbody > tr > td {
250 border-top: none;
253 .last_detail {
254 border-bottom: 1px black solid;
255 margin-top: 2px;
258 @media (min-width: 992px) {
259 .modal-lg {
260 width: 1000px !Important;
264 /*.modalclass {
265 overflow-x: hidden !Important;
267 .oe-ckbox-label{
268 padding-left: 30px;
269 font-weight: 500;
271 </style>
272 </head>
273 <body>
274 <?php
275 $trans_id = 0 + $_GET['id'];
276 if (!$trans_id) {
277 die(xlt("You cannot access this page directly."));
280 // A/R case, $trans_id matches form_encounter.id.
281 $ferow = sqlQuery("SELECT e.*, p.fname, p.mname, p.lname FROM form_encounter AS e, patient_data AS p WHERE e.id = ? AND p.pid = e.pid", array($trans_id));
282 if (empty($ferow)) {
283 die("There is no encounter with form_encounter.id = '" . text($trans_id) . "'.");
285 $patient_id = 0 + $ferow['pid'];
286 $encounter_id = 0 + $ferow['encounter'];
287 $svcdate = substr($ferow['date'], 0, 10);
288 $form_payer_id = 0 + $_POST['form_payer_id'];
289 $form_reference = $_POST['form_reference'];
290 $form_check_date = fixDate($_POST['form_check_date'], date('Y-m-d'));
291 $form_deposit_date = fixDate($_POST['form_deposit_date'], $form_check_date);
292 $form_pay_total = 0 + $_POST['form_pay_total'];
294 $payer_type = 0;
295 if (preg_match('/^Ins(\d)/i', $_POST['form_insurance'], $matches)) {
296 $payer_type = $matches[1];
299 if (($_POST['form_save'] || $_POST['form_cancel'])) {
300 if ($_POST['form_save']) {
301 if (!verifyCsrfToken($_POST["csrf_token_form"])) {
302 csrfNotVerified();
305 if ($debug) {
306 echo "<p><b>" . xlt("This module is in test mode. The database will not be changed.") . "</b><p>\n";
309 $session_id = arGetSession($form_payer_id, $form_reference, $form_check_date, $form_deposit_date, $form_pay_total);
310 // The sl_eob_search page needs its invoice links modified to invoke
311 // javascript to load form parms for all the above and submit.
312 // At the same time that page would be modified to work off the
313 // openemr database exclusively.
314 // And back to the sl_eob_invoice page, I think we may want to move
315 // the source input fields from row level to header level.
317 // Handle deletes. row_delete() is borrowed from deleter.php.
318 if ($ALLOW_DELETE && !$debug) {
319 if (is_array($_POST['form_del'])) {
320 foreach ($_POST['form_del'] as $arseq => $dummy) {
321 row_delete("ar_activity", "pid = '" . add_escape_custom($patient_id) . "' AND " . "encounter = '" . add_escape_custom($encounter_id) . "' AND sequence_no = '" . add_escape_custom($arseq) . "'");
326 $paytotal = 0;
327 foreach ($_POST['form_line'] as $code => $cdata) {
328 $thispay = trim($cdata['pay']);
329 $thisadj = trim($cdata['adj']);
330 $thisins = trim($cdata['ins']);
331 $thiscodetype = trim($cdata['code_type']);
332 $reason = $cdata['reason'];
334 // Get the adjustment reason type. Possible values are:
335 // 1 = Charge adjustment
336 // 2 = Coinsurance
337 // 3 = Deductible
338 // 4 = Other pt resp
339 // 5 = Comment
340 $reason_type = '1';
341 if ($reason) {
342 $tmp = sqlQuery("SELECT option_value FROM list_options WHERE list_id = 'adjreason' AND activity = 1 AND option_id = ?", array($reason));
343 if (empty($tmp['option_value'])) {
344 // This should not happen but if it does, apply old logic.
345 if (preg_match("/To copay/", $reason)) {
346 $reason_type = 2;
347 } elseif (preg_match("/To ded'ble/", $reason)) {
348 $reason_type = 3;
350 $info_msg .= xl("No adjustment reason type found for") . " \"$reason\". ";
351 } else {
352 $reason_type = $tmp['option_value'];
356 if (!$thisins) {
357 $thisins = 0;
360 if (0.0 + $thispay) {
361 arPostPayment($patient_id, $encounter_id, $session_id, $thispay, $code, $payer_type, '', $debug, '', $thiscodetype);
362 $paytotal += $thispay;
365 // Be sure to record adjustment reasons, even for zero adjustments if
366 // they happen to be comments.
367 if ((0.0 + $thisadj) ||
368 ($reason && $reason_type == 5) ||
369 ($reason && ($reason_type > 1 && $reason_type < 6))) {
370 // "To copay" and "To ded'ble" need to become a comment in a zero
371 // adjustment, formatted just like sl_eob_process.php.
372 if ($reason_type == '2') {
373 $reason = $_POST['form_insurance'] . " coins: $thisadj";
374 $thisadj = 0;
375 } elseif ($reason_type == '3') {
376 $reason = $_POST['form_insurance'] . " dedbl: $thisadj";
377 $thisadj = 0;
378 } elseif ($reason_type == '4') {
379 $reason = $_POST['form_insurance'] . " ptresp: $thisadj $reason";
380 $thisadj = 0;
381 } elseif ($reason_type == '5') {
382 $reason = $_POST['form_insurance'] . " note: $thisadj $reason";
383 $thisadj = 0;
384 } else {
385 // An adjustment reason including "Ins" is assumed to be assigned by
386 // insurance, and in that case we identify which one by appending
387 // Ins1, Ins2 or Ins3.
388 if (strpos(strtolower($reason), 'ins') != false) {
389 $reason .= ' ' . $_POST['form_insurance'];
392 arPostAdjustment($patient_id, $encounter_id, $session_id, $thisadj, $code, $payer_type, $reason, $debug, '', $thiscodetype);
396 // Maintain which insurances are marked as finished.
398 $form_done = 0 + $_POST['form_done'];
399 $form_stmt_count = 0 + $_POST['form_stmt_count'];
400 sqlStatement("UPDATE form_encounter SET last_level_closed = ?, stmt_count = ? WHERE pid = ? AND encounter = ?", array($form_done, $form_stmt_count, $patient_id, $encounter_id));
402 if ($_POST['form_secondary']) {
403 arSetupSecondary($patient_id, $encounter_id, $debug);
405 echo "<script language='JavaScript'>\n";
406 echo " if (opener.document.forms[0] != undefined) {\n";
407 echo " if (opener.document.forms[0].form_amount) {\n";
408 echo " var tmp = opener.document.forms[0].form_amount.value - " . attr($paytotal) . ";\n";
409 echo " opener.document.forms[0].form_amount.value = Number(tmp).toFixed(2);\n";
410 echo " }\n";
411 echo " }\n";
412 } else {
413 echo "<script language='JavaScript'>\n";
415 if ($info_msg) {
416 echo " alert('" . addslashes($info_msg) . "');\n";
418 echo "opener.$('#btn-inv-search').click();";
419 if (!$debug && !$save_stay) {
420 echo " window.close();\n";
421 } else {
422 $reload_url = "sl_eob_invoice.php?id=" . attr(urlencode($trans_id));
423 echo "window.location.assign('" . $reload_url . "')";
425 echo "</script></body></html>\n";
426 if (!$save_stay) {
427 exit();
431 // Get invoice charge details.
432 $codes = ar_get_invoice_summary($patient_id, $encounter_id, true);
433 $pdrow = sqlQuery("select billing_note from patient_data where pid = ? limit 1", array($patient_id));
436 <div class="container">
437 <div class="row">
438 <div class="page-header">
439 <h2><?php echo xlt('EOB Invoice'); ?></h2>
440 </div>
441 </div>
442 <div class="row">
443 <form action='sl_eob_invoice.php?id=<?php echo attr(urlencode($trans_id)); ?>' method='post'
444 onsubmit='return validate(this)'>
445 <input type="hidden" name="csrf_token_form" value="<?php echo attr(collectCsrfToken()); ?>"/>
446 <fieldset>
447 <legend><?php echo xlt('Invoice Actions'); ?></legend>
448 <div class="col-xs-12 oe-custom-line">
449 <div class="col-xs-3">
450 <label class="control-label" for="form_name"><?php echo xlt('Patient'); ?>:</label>
451 <input type="text" class="form-control" class="form-control" class="form-control" id='form_name'
452 name='form_name'
453 value="<?php echo attr($ferow['fname']) . ' ' . attr($ferow['mname']) . ' ' . attr($ferow['lname']); ?>"
454 disabled>
455 </div>
456 <div class="col-xs-3">
457 <label class="control-label" for="form_provider"><?php echo xlt('Provider'); ?>:</label>
458 <?php
459 $tmp = sqlQuery("SELECT fname, mname, lname " .
460 "FROM users WHERE id = ?", array($ferow['provider_id']));
461 $provider = text($tmp['fname']) . ' ' . text($tmp['mname']) . ' ' . text($tmp['lname']);
462 $tmp = sqlQuery("SELECT bill_date FROM billing WHERE " .
463 "pid = ? AND encounter = ? AND " .
464 "activity = 1 ORDER BY fee DESC, id ASC LIMIT 1", array($patient_id, $encounter_id));
465 $billdate = substr(($tmp['bill_date'] . "Not Billed"), 0, 10);
467 <input type="text" class="form-control" class="form-control" id='form_provider'
468 name='form_provider' value="<?php echo attr($provider); ?>" disabled>
469 </div>
470 <div class="col-xs-2">
471 <label class="control-label" for="form_invoice"><?php echo xlt('Invoice'); ?>:</label>
472 <input type="text" class="form-control" class="form-control" id='form_provider'
473 name='form_provider' value='<?php echo attr($patient_id) . "." . attr($encounter_id); ?>'
474 disabled>
475 </div>
476 <div class="col-xs-2">
477 <label class="control-label" for="svc_date"><?php echo xlt('Svc Date'); ?>:</label>
478 <input type="text" class="form-control" class="form-control" id='svc_date' name='form_provider'
479 value='<?php echo attr($svcdate); ?>' disabled>
480 </div>
481 <div class="col-xs-2">
482 <label class="control-label" for="insurance_name"><?php echo xlt('Insurance'); ?>:</label>
483 <?php
484 for ($i = 1; $i <= 3; ++$i) {
485 $payerid = arGetPayerID($patient_id, $svcdate, $i);
486 if ($payerid) {
487 $tmp = sqlQuery("SELECT name FROM insurance_companies WHERE id = ?", array($payerid));
488 $insurance .= "$i: " . $tmp['name'] . "\n";
492 <textarea name="insurance_name" id="insurance_name" class="form-control" cols="5" rows="2"
493 readonly><?php echo attr($insurance); ?></textarea>
494 </div>
495 </div>
496 <div class="col-xs-12 oe-custom-line">
497 <div class="col-xs-3">
498 <label class="control-label" for="form_stmt_count"><?php echo xlt('Statements Sent'); ?>
499 :</label>
500 <input type='text' name='form_stmt_count' id='form_stmt_count' class="form-control"
501 value='<?php echo attr((0 + $ferow['stmt_count'])); ?>'/>
502 </div>
503 <div class="col-xs-3">
504 <label class="control-label" for="form_reference"><?php echo xlt('Check/EOB No.'); ?>:</label>
505 <input type='text' name='form_reference' id='form_reference' class="form-control" value=''/>
506 </div>
507 <div class="col-xs-2">
508 <label class="control-label" for="form_check_date"><?php echo xlt('Check/EOB Date'); ?>:</label>
509 <input type='text' name='form_check_date' class='form-control datepicker' value=''/>
510 </div>
511 <div class="col-xs-2">
512 <label class="control-label" for="form_deposit_date"><?php echo xlt('Deposit Date'); ?>:</label>
513 <input type='text' name='form_deposit_date' id='form_deposit_date'
514 class='form-control datepicker' value=''/>
515 <input type='hidden' name='form_payer_id' value=''/>
516 <input type='hidden' name='form_orig_reference' value=''/>
517 <input type='hidden' name='form_orig_check_date' value=''/>
518 <input type='hidden' name='form_orig_deposit_date' value=''/>
519 <input type='hidden' name='form_pay_total' value=''/>
520 </div>
521 </div>
522 <div class="col-xs-12 oe-custom-line">
523 <div class="col-xs-4">
524 <label class="control-label" for="type_code"><?php echo xlt('Now posting for'); ?>:</label>
525 <div style="padding-left:15px">
526 <?php
527 $last_level_closed = 0 + $ferow['last_level_closed'];
529 <label class="radio-inline">
530 <input <?php echo $last_level_closed === 0 ? attr('checked') : ''; ?> name='form_insurance' onclick='setins("Ins1")' type='radio'
531 value='Ins1'><?php echo xlt('Ins1') ?>
532 </label>
533 <label class="radio-inline">
534 <input <?php echo $last_level_closed === 1 ? attr('checked') : ''; ?> name='form_insurance' onclick='setins("Ins2")' type='radio'
535 value='Ins2'><?php echo xlt('Ins2') ?>
536 </label>
537 <label class="radio-inline">
538 <input <?php echo $last_level_closed === 2 ? attr('checked') : ''; ?> name='form_insurance' onclick='setins("Ins3")' type='radio'
539 value='Ins3'><?php echo xlt('Ins3') ?>
540 </label>
541 <label class="radio-inline">
542 <input <?php echo $last_level_closed === 3 ? attr('checked') : ''; ?> name='form_insurance' onclick='setins("Pt")' type='radio'
543 value='Pt'><?php echo xlt('Patient') ?>
544 </label>
545 <?php
546 // TBD: I think the following is unused and can be removed.
548 <input name='form_eobs' type='hidden' value='<?php echo attr($arrow['shipvia']) ?>'/>
549 </div>
550 </div>
551 <div class="col-xs-4">
552 <label class="control-label" for=""><?php echo xlt('Done with'); ?>:</label>
553 <div style="padding-left:15px">
554 <?php
555 // Write a checkbox for each insurance. It is to be checked when
556 // we no longer expect any payments from that company for the claim.
557 $last_level_closed = 0 + $ferow['last_level_closed'];
558 foreach (array(0 => 'None', 1 => 'Ins1', 2 => 'Ins2', 3 => 'Ins3') as $key => $value) {
559 if ($key && !arGetPayerID($patient_id, $svcdate, $key)) {
560 continue;
562 $checked = ($last_level_closed == $key) ? " checked" : "";
563 echo "<label class='radio-inline'>";
564 echo "<input type='radio' name='form_done' value='" . attr($key) . "'$checked />" . text($value);
565 echo "</label>";
568 </div>
569 </div>
570 <div class="col-xs-4">
571 <label class="control-label" for=""><?php echo xlt('Secondary billing'); ?>:</label>
572 <div style="padding-left:15px">
573 <label class="checkbox-inline">
574 <input name="form_secondary" type="checkbox"
575 value="1"><?php echo xlt('Needs secondary billing') ?>
576 </label>
577 </div>
578 </div>
579 </div>
581 </fieldset>
582 <fieldset>
583 <legend><?php echo xlt('Invoice Details'); ?></legend>
584 <div class="table-responsive">
585 <table class="table table-condensed">
586 <thead>
587 <tr>
588 <th><?php echo xlt('Code') ?></th>
589 <th align="right"><?php echo xlt('Charge') ?></th>
590 <th align="right"><?php echo xlt('Balance') ?>&nbsp;</th>
591 <th><?php echo xlt('By/Source') ?></th>
592 <th><?php echo xlt('Date') ?></th>
593 <th><?php echo xlt('Pay') ?></th>
594 <th><?php echo xlt('Adjust') ?></th>
595 <th>&nbsp;</th>
596 <th><?php echo xlt('Reason') ?></th>
597 <?php
598 if ($ALLOW_DELETE) { ?>
599 <th><?php echo xlt('Del') ?></th>
600 <?php
601 } ?>
602 </tr>
603 </thead>
604 <?php
605 $firstProcCodeIndex = -1;
606 $encount = 0;
607 foreach ($codes as $code => $cdata) {
608 ++$encount;
609 $dispcode = $code;
611 // remember the index of the first entry whose code is not "CO-PAY", i.e. it's a legitimate proc code
612 if ($firstProcCodeIndex == -1 && strcmp($code, "CO-PAY") != 0) {
613 $firstProcCodeIndex = $encount;
616 // this sorts the details more or less chronologically:
617 ksort($cdata['dtl']);
618 foreach ($cdata['dtl'] as $dkey => $ddata) {
619 $ddate = substr($dkey, 0, 10);
620 if (preg_match('/^(\d\d\d\d)(\d\d)(\d\d)\s*$/', $ddate, $matches)) {
621 $ddate = $matches[1] . '-' . $matches[2] . '-' . $matches[3];
623 $tmpchg = "";
624 $tmpadj = "";
625 if ($ddata['chg'] != 0) {
626 if (isset($ddata['rsn'])) {
627 $tmpadj = 0 - $ddata['chg'];
628 } else {
629 $tmpchg = $ddata['chg'];
633 <tr>
634 <td class="detail"
635 style="background:<?php echo $dispcode ? 'lightyellow' : ''; ?>"><?php echo text($dispcode);
636 $dispcode = "" ?></td>
637 <td class="detail" class="detail"><?php echo text(bucks($tmpchg)); ?></td>
638 <td class="detail" class="detail">&nbsp;</td>
639 <td class="detail">
640 <?php
641 if (isset($ddata['plv'])) {
642 if (!$ddata['plv']) {
643 echo 'Pt/';
644 } else {
645 echo 'Ins' . text($ddata['plv']) . '/';
648 echo text($ddata['src']);
650 </td>
651 <td class="detail"><?php echo text($ddate); ?></td>
652 <td class="detail"><?php echo text(bucks($ddata['pmt'])); ?></td>
653 <td class="detail"><?php echo text(bucks($tmpadj)); ?></td>
654 <td class="detail">&nbsp;</td>
655 <td class="detail"><?php echo text($ddata['rsn']); ?></td>
656 <?php
657 if ($ALLOW_DELETE) { ?>
658 <td class="detail">
659 <?php
660 if (!empty($ddata['arseq'])) { ?>
661 <input name="form_del[<?php echo attr($ddata['arseq']); ?>]"
662 type="checkbox">
663 <?php
664 } else {
665 ?> &nbsp;
666 <?php
667 } ?>
668 </td>
669 <?php } ?>
670 </tr>
671 <?php } // end of prior detail line ?>
672 <tr>
673 <td class="last_detail"><?php echo text($dispcode);
674 $dispcode = "" ?></td>
675 <td class="last_detail">&nbsp;</td>
676 <td class="last_detail">
677 <input name="form_line[<?php echo attr($code); ?>][bal]" type="hidden"
678 value="<?php echo attr(bucks($cdata['bal'])); ?>">
679 <input name="form_line[<?php echo attr($code); ?>][ins]" type="hidden"
680 value="<?php echo attr($cdata['ins']); ?>">
681 <input name="form_line[<?php echo attr($code); ?>][code_type]" type="hidden"
682 value="<?php echo attr($cdata['code_type']); ?>"> <?php echo text(sprintf("%.2f", $cdata['bal'])); ?>
683 &nbsp;
684 </td>
685 <td class="last_detail"></td>
686 <td class="last_detail"></td>
687 <td class="last_detail">
688 <input name="form_line[<?php echo attr($code); ?>][pay]"
689 onkeyup="updateFields(document.forms[0]['form_line[<?php echo attr(addslashes($code)); ?>][pay]'], document.forms[0]['form_line[<?php echo attr(addslashes($code)); ?>][adj]'], document.forms[0]['form_line[<?php echo attr(addslashes($code)); ?>][bal]'], document.forms[0]['form_line[CO-PAY][bal]'], <?php echo ($firstProcCodeIndex == $encount) ? 1 : 0 ?>)"
690 onclick="this.select()" autofocus size="10" type="text" class="form-control"
691 value="0.00"></td>
692 <td class="last_detail">
693 <input name="form_line[<?php echo attr($code); ?>][adj]" size="10" type="text"
694 class="form-control"
695 value='<?php echo attr($totalAdjAmount ? $totalAdjAmount : '0.00'); ?>'
696 onclick="this.select()">
697 </td>
698 <td class="last_detail" align="center"><a href=""
699 onclick="return writeoff('<?php echo attr(addslashes($code)); ?>')">WO</a>
700 </td>
701 <td class="last_detail">
702 <select class="form-control" name="form_line[<?php echo attr($code); ?>][reason]">
703 <?php
704 // Adjustment reasons are now taken from the list_options table.
705 echo " <option value=''></option>\n";
706 $ores = sqlStatement("SELECT option_id, title, is_default FROM list_options " .
707 "WHERE list_id = 'adjreason' AND activity = 1 ORDER BY seq, title");
708 while ($orow = sqlFetchArray($ores)) {
709 echo " <option value='" . attr($orow['option_id']) . "'";
710 if ($orow['is_default']) {
711 echo " selected";
713 echo ">" . text($orow['title']) . "</option>\n";
716 </select>
717 <?php
718 // TBD: Maybe a comment field would be good here, for appending
719 // to the reason.
721 </td>
722 <?php if ($ALLOW_DELETE) { ?>
723 <td class="last_detail">&nbsp;</td>
724 <?php } ?>
725 </tr>
726 <?php } // end of code ?>
727 </table>
728 </div>
729 </fieldset>
730 <?php //can change position of buttons by creating a class 'position-override' and adding rule text-align:center or right as the case may be in individual stylesheets ?>
731 <div class="form-group clearfix">
732 <div class="col-sm-12 text-left position-override" id="search-btn">
733 <div class="btn-group" role="group">
734 <button type='submit' class="btn btn-default btn-save" name='form_save' id="btn-save-stay"
735 onclick="this.value='1';"><?php echo xlt("Save Current"); ?></button>
736 <button type='submit' class="btn btn-default btn-save" name='form_save' id="btn-save"
737 onclick="this.value='2';"><?php echo xlt("Save & Exit"); ?></button>
738 <button type='button' class="btn btn-link btn-cancel btn-separate-left" name='form_cancel'
739 id="btn-cancel" onclick='window.close()'><?php echo xlt("Close"); ?></button>
740 </div>
741 <?php if ($GLOBALS['new_tabs_layout']) { ?>
742 <button type='button' class="btn btn-default btn-view pull-right" name='form_goto' id="btn-goto"
743 onclick="goEncounterSummary('<?php echo attr($patient_id) ?>')"><?php echo xlt("Encounter View"); ?></button>
744 <?php } ?>
745 </div>
746 </div>
747 </form>
748 </div>
749 </div><!--End of container div-->
750 <script language="JavaScript">
751 var f1 = opener.document.forms[0];
752 var f2 = document.forms[0];
753 if (f1.form_source) {
754 <?php
755 // These support creation and lookup of ar_session table entries:
756 echo " f2.form_reference.value = f1.form_source.value;\n";
757 echo " f2.form_check_date.value = f1.form_paydate.value;\n";
758 echo " //f2.form_deposit_date.value = f1.form_deposit_date.value;\n";
759 echo " if (f1.form_deposit_date.value != '')\n";
760 echo " f2.form_deposit_date.value = f1.form_deposit_date.value;\n";
761 echo " else\n";
762 echo " f2.form_deposit_date.value = getFormattedToday();\n";
763 echo " f2.form_payer_id.value = f1.form_payer_id.value;\n";
764 echo " f2.form_pay_total.value = f1.form_amount.value;\n";
765 echo " f2.form_orig_reference.value = f1.form_source.value;\n";
766 echo " f2.form_orig_check_date.value = f1.form_paydate.value;\n";
767 echo " f2.form_orig_deposit_date.value = f1.form_deposit_date.value;\n";
769 // While I'm thinking about it, some notes about eob sessions.
770 // If they do not have all of the session key fields in the search
771 // page, then show a warning at the top of the invoice page.
772 // Also when they go to save the invoice page and a session key
773 // field has changed, alert them to that and allow a cancel.
775 // Another point... when posting EOBs, the incoming payer ID might
776 // not match the payer ID for the patient's insurance. This is
777 // because the same payer might be entered more than once into the
778 // insurance_companies table. I don't think it matters much.
781 setins("Ins1");
782 </script>
783 </body>
784 </html>