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