7 * @link http://www.open-emr.org
8 * @author Rod Roark <rod@sunsetsystems.com>
9 * @author Brady Miller <brady.g.miller@gmail.com>
10 * @copyright Copyright (c) 2006-2020 Rod Roark <rod@sunsetsystems.com>
11 * @copyright Copyright (c) 2017-2018 Brady Miller <brady.g.miller@gmail.com>
12 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
15 require_once("../globals.php");
16 require_once("$srcdir/patient.inc");
17 require_once("$srcdir/payment.inc.php");
18 require_once("$srcdir/forms.inc");
19 require_once("../../custom/code_types.inc.php");
20 require_once("$srcdir/options.inc.php");
21 require_once("$srcdir/encounter_events.inc.php");
23 use OpenEMR\Billing\BillingUtilities
;
24 use OpenEMR\Common\Acl\AclMain
;
25 use OpenEMR\Common\Csrf\CsrfUtils
;
26 use OpenEMR\Core\Header
;
27 use OpenEMR\OeUI\OemrUI
;
28 use OpenEMR\Services\FacilityService
;
30 $pid = $_REQUEST['hidden_patient_code'] > 0 ?
$_REQUEST['hidden_patient_code'] : $pid;
32 $facilityService = new FacilityService();
38 <?php Header
::setupHeader(['opener']);?
>
41 // Format dollars for display.
43 function bucks($amount)
46 $amount = oeFormatMoney($amount);
52 function rawbucks($amount)
55 $amount = sprintf("%.2f", $amount);
61 // Display a row of data for an encounter.
64 function echoLine($iname, $date, $charges, $ptpaid, $inspaid, $duept, $encounter = 0, $copay = 0, $patcopay = 0)
68 $balance = bucks($charges - $ptpaid - $inspaid);
69 $balance = (round($duept, 2) != 0) ?
0 : $balance;//if balance is due from patient, then insurance balance is displayed as zero
70 $encounter = $encounter ?
$encounter : '';
71 echo " <tr id='tr_" . attr($var_index) . "' >\n";
72 echo " <td class='detail'>" . text(oeFormatShortDate($date)) . "</td>\n";
73 echo " <td class='detail' id='" . attr($date) . "' align='center'>" . text($encounter) . "</td>\n";
74 echo " <td class='detail' align='center' id='td_charges_$var_index' >" . text(bucks($charges)) . "</td>\n";
75 echo " <td class='detail' align='center' id='td_inspaid_$var_index' >" . text(bucks($inspaid * -1)) . "</td>\n";
76 echo " <td class='detail' align='center' id='td_ptpaid_$var_index' >" . text(bucks($ptpaid * -1)) . "</td>\n";
77 echo " <td class='detail' align='center' id='td_patient_copay_$var_index' >" . text(bucks($patcopay)) . "</td>\n";
78 echo " <td class='detail' align='center' id='td_copay_$var_index' >" . text(bucks($copay)) . "</td>\n";
79 echo " <td class='detail' align='center' id='balance_$var_index'>" . text(bucks($balance)) . "</td>\n";
80 echo " <td class='detail' align='center' id='duept_$var_index'>" . text(bucks(round($duept, 2) * 1)) . "</td>\n";
81 echo " <td class='detail' align='right'><input type='text' name='" . attr($iname) . "' id='paying_" . attr($var_index) . "' " .
82 " value='' onchange='coloring();calctotal()' autocomplete='off' " .
83 "onkeyup='calctotal()' style='width:50px'/></td>\n";
87 // We use this to put dashes, colons, etc. back into a timestamp.
89 function decorateString($fmt, $str)
93 $fc = substr($fmt, 0, 1);
94 $fmt = substr($fmt, 1);
96 $res .= substr($str, 0, 1);
97 $str = substr($str, 1);
106 // Compute taxes from a tax rate string and a possibly taxable amount.
108 function calcTaxes($row, $amount)
111 if (empty($row['taxrates'])) {
115 $arates = explode(':', $row['taxrates']);
116 if (empty($arates)) {
120 foreach ($arates as $value) {
125 $trow = sqlQuery("SELECT option_value FROM list_options WHERE " .
126 "list_id = 'taxrate' AND option_id = ? AND activity = 1 LIMIT 1", array($value));
127 if (empty($trow['option_value'])) {
128 echo "<!-- Missing tax rate '" . text($value) . "'! -->\n";
132 $tax = sprintf("%01.2f", $amount * $trow['option_value']);
133 // echo "<!-- Rate = '$value', amount = '$amount', tax = '$tax' -->\n";
141 $today = date('Y-m-d', $now);
142 $timestamp = date('Y-m-d H:i:s', $now);
145 // $patdata = getPatientData($pid, 'fname,lname,pubpid');
147 $patdata = sqlQuery("SELECT " .
148 "p.fname, p.mname, p.lname, p.pubpid,p.pid, i.copay " .
149 "FROM patient_data AS p " .
150 "LEFT OUTER JOIN insurance_data AS i ON " .
151 "i.pid = p.pid AND i.type = 'primary' " .
152 "WHERE p.pid = ? ORDER BY i.date DESC LIMIT 1", array($pid));
154 $alertmsg = ''; // anything here pops up in an alert box
156 // If the Save button was clicked...
157 if ($_POST['form_save']) {
158 if (!CsrfUtils
::verifyCsrfToken($_POST["csrf_token_form"])) {
159 CsrfUtils
::csrfNotVerified();
162 $form_pid = $_POST['form_pid'];
163 $form_method = trim($_POST['form_method']);
164 $form_source = trim($_POST['form_source']);
165 $patdata = getPatientData($form_pid, 'fname,mname,lname,pubpid');
166 $NameNew = $patdata['fname'] . " " . $patdata['lname'] . " " . $patdata['mname'];
168 if ($_REQUEST['radio_type_of_payment'] == 'pre_payment') {
169 $payment_id = sqlInsert(
170 "insert into ar_session set " .
176 ", check_date = now() , deposit_date = now() " .
178 ", payment_type = 'patient'" .
179 ", description = ?" .
180 ", adjustment_code = 'pre_payment'" .
181 ", post_to_date = now() " .
182 ", payment_method = ?",
183 array(0, $form_pid, $_SESSION['authUserID'], 0, $form_source, $_REQUEST['form_prepayment'], $NameNew, $form_method)
186 frontPayment($form_pid, 0, $form_method, $form_source, $_REQUEST['form_prepayment'], 0, $timestamp);//insertion to 'payments' table.
189 if ($_POST['form_upay'] && $_REQUEST['radio_type_of_payment'] != 'pre_payment') {
190 foreach ($_POST['form_upay'] as $enc => $payment) {
191 if ($amount = 0 +
$payment) {
193 if ($_REQUEST['radio_type_of_payment'] == 'invoice_balance') {
195 $enc = calendar_arrived($form_pid);
199 $enc = calendar_arrived($form_pid);
203 //----------------------------------------------------------------------------------------------------
204 //Fetching the existing code and modifier
205 $ResultSearchNew = sqlStatement(
206 "SELECT * FROM billing LEFT JOIN code_types ON billing.code_type=code_types.ct_key " .
207 "WHERE code_types.ct_fee=1 AND billing.activity!=0 AND billing.pid =? AND encounter=? ORDER BY billing.code,billing.modifier",
208 array($form_pid, $enc)
210 if ($RowSearch = sqlFetchArray($ResultSearchNew)) {
211 $Codetype = $RowSearch['code_type'];
212 $Code = $RowSearch['code'];
213 $Modifier = $RowSearch['modifier'];
220 //----------------------------------------------------------------------------------------------------
221 if ($_REQUEST['radio_type_of_payment'] == 'copay') {//copay saving to ar_session and ar_activity tables
222 $session_id = sqlInsert(
223 "INSERT INTO ar_session (payer_id,user_id,reference,check_date,deposit_date,pay_total," .
224 " global_amount,payment_type,description,patient_id,payment_method,adjustment_code,post_to_date) " .
225 " VALUES ('0',?,?,now(),now(),?,'','patient','COPAY',?,?,'patient_payment',now())",
226 array($_SESSION['authUserID'], $form_source, $amount, $form_pid, $form_method)
230 $sequence_no = sqlQuery("SELECT IFNULL(MAX(sequence_no),0) + 1 AS increment FROM ar_activity WHERE pid = ? AND encounter = ?", array($form_pid, $enc));
231 $insrt_id = sqlInsert(
232 "INSERT INTO ar_activity (pid,encounter,sequence_no,code_type,code,modifier,payer_type,post_time,post_user,session_id,pay_amount,account_code)" .
233 " VALUES (?,?,?,?,?,?,0,now(),?,?,?,'PCP')",
234 array($form_pid, $enc, $sequence_no['increment'], $Codetype, $Code, $Modifier, $_SESSION['authUserID'], $session_id, $amount)
238 frontPayment($form_pid, $enc, $form_method, $form_source, $amount, 0, $timestamp);//insertion to 'payments' table.
241 if ($_REQUEST['radio_type_of_payment'] == 'invoice_balance' ||
$_REQUEST['radio_type_of_payment'] == 'cash') { //Payment by patient after insurance paid, cash patients similar to do not bill insurance in feesheet.
242 if ($_REQUEST['radio_type_of_payment'] == 'cash') {
244 "update form_encounter set last_level_closed=? where encounter=? and pid=? ",
245 array(4, $enc, $form_pid)
248 "update billing set billed=? where encounter=? and pid=?",
249 array(1, $enc, $form_pid)
253 $adjustment_code = 'patient_payment';
254 $payment_id = sqlInsert(
255 "insert into ar_session set " .
261 ", check_date = now() , deposit_date = now() " .
263 ", payment_type = 'patient'" .
264 ", description = ?" .
265 ", adjustment_code = ?" .
266 ", post_to_date = now() " .
267 ", payment_method = ?",
268 array(0, $form_pid, $_SESSION['authUserID'], 0, $form_source, $amount, $NameNew, $adjustment_code, $form_method)
271 //--------------------------------------------------------------------------------------------------------------------
273 frontPayment($form_pid, $enc, $form_method, $form_source, 0, $amount, $timestamp);//insertion to 'payments' table.
275 //--------------------------------------------------------------------------------------------------------------------
277 $resMoneyGot = sqlStatement(
278 "SELECT sum(pay_amount) as PatientPay FROM ar_activity where pid =? and " .
279 "encounter = ? and payer_type = 0 and account_code = 'PCP' AND deleted IS NULL",
280 array($form_pid, $enc)
281 );//new fees screen copay gives account_code='PCP'
282 $rowMoneyGot = sqlFetchArray($resMoneyGot);
283 $Copay = $rowMoneyGot['PatientPay'];
285 //--------------------------------------------------------------------------------------------------------------------
287 //Looping the existing code and modifier
288 $ResultSearchNew = sqlStatement(
289 "SELECT * FROM billing LEFT JOIN code_types ON billing.code_type=code_types.ct_key WHERE code_types.ct_fee=1 " .
290 "AND billing.activity!=0 AND billing.pid =? AND encounter=? ORDER BY billing.code,billing.modifier",
291 array($form_pid, $enc)
293 while ($RowSearch = sqlFetchArray($ResultSearchNew)) {
294 $Codetype = $RowSearch['code_type'];
295 $Code = $RowSearch['code'];
296 $Modifier = $RowSearch['modifier'];
297 $Fee = $RowSearch['fee'];
299 $resMoneyGot = sqlStatement(
300 "SELECT sum(pay_amount) as MoneyGot FROM ar_activity where pid = ? AND deleted IS NULL " .
301 "and code_type=? and code=? and modifier=? and encounter =? and !(payer_type=0 and account_code='PCP')",
302 array($form_pid, $Codetype, $Code, $Modifier, $enc)
304 //new fees screen copay gives account_code='PCP'
305 $rowMoneyGot = sqlFetchArray($resMoneyGot);
306 $MoneyGot = $rowMoneyGot['MoneyGot'];
308 $resMoneyAdjusted = sqlStatement(
309 "SELECT sum(adj_amount) as MoneyAdjusted FROM ar_activity where " .
310 "pid = ? and code_type = ? and code = ? and modifier = ? and encounter = ? AND deleted IS NULL",
311 array($form_pid, $Codetype, $Code, $Modifier, $enc)
313 $rowMoneyAdjusted = sqlFetchArray($resMoneyAdjusted);
314 $MoneyAdjusted = $rowMoneyAdjusted['MoneyAdjusted'];
316 $Remainder = $Fee - $Copay - $MoneyGot - $MoneyAdjusted;
318 if (round($Remainder, 2) != 0 && $amount != 0) {
319 if ($amount - $Remainder >= 0) {
320 $insert_value = $Remainder;
321 $amount = $amount - $Remainder;
323 $insert_value = $amount;
328 $sequence_no = sqlQuery("SELECT IFNULL(MAX(sequence_no),0) + 1 AS increment FROM ar_activity WHERE pid = ? AND encounter = ?", array($form_pid, $enc));
330 "insert into ar_activity set " .
333 ", sequence_no = ?" .
338 ", post_time = now() " .
343 ", account_code = 'PP'",
344 array($form_pid, $enc, $sequence_no['increment'], $Codetype, $Code, $Modifier, 0, $_SESSION['authUserID'], $payment_id, $insert_value, 0)
349 if ($amount != 0) {//if any excess is there.
351 $sequence_no = sqlQuery("SELECT IFNULL(MAX(sequence_no),0) + 1 AS increment FROM ar_activity WHERE pid = ? AND encounter = ?", array($form_pid, $enc));
353 "insert into ar_activity set " .
356 ", sequence_no = ?" .
361 ", post_time = now() " .
366 ", account_code = 'PP'",
367 array($form_pid, $enc, $sequence_no['increment'], $Codetype, $Code, $Modifier, 0, $_SESSION['authUserID'], $payment_id, $amount, 0)
372 //--------------------------------------------------------------------------------------------------------------------
374 }//if ($amount = 0 + $payment)
376 }//if ($_POST['form_upay'])
377 }//if ($_POST['form_save'])
379 if ($_POST['form_save'] ||
$_REQUEST['receipt']) {
380 if ($_REQUEST['receipt']) {
381 $form_pid = $_GET['patient'];
382 $timestamp = decorateString('....-..-.. ..:..:..', $_GET['time']);
385 // Get details for what we guess is the primary facility.
386 $frow = $facilityService->getPrimaryBusinessEntity(array("useLegacyImplementation" => true));
388 // Get the patient's name and chart number.
389 $patdata = getPatientData($form_pid, 'fname,mname,lname,pubpid');
391 // Re-fetch payment info.
392 $payrow = sqlQuery("SELECT " .
393 "SUM(amount1) AS amount1, " .
394 "SUM(amount2) AS amount2, " .
395 "MAX(method) AS method, " .
396 "MAX(source) AS source, " .
397 "MAX(dtime) AS dtime, " .
398 // "MAX(user) AS user " .
399 "MAX(user) AS user, " .
400 "MAX(encounter) as encounter " .
401 "FROM payments WHERE " .
402 "pid = ? AND dtime = ?", array($form_pid, $timestamp));
404 // Create key for deleting, just in case.
405 $ref_id = ($_REQUEST['radio_type_of_payment'] == 'copay') ?
$session_id : $payment_id;
406 $payment_key = $form_pid . '.' . preg_replace('/[^0-9]/', '', $timestamp) . '.' . $ref_id;
408 if ($_REQUEST['radio_type_of_payment'] != 'pre_payment') {
409 // get facility from encounter
410 $tmprow = sqlQuery("SELECT `facility_id` FROM `form_encounter` WHERE `encounter` = ?", array($payrow['encounter']));
411 $frow = $facilityService->getById($tmprow['facility_id']);
413 // if pre_payment, then no encounter yet, so get main office address
414 $frow = $facilityService->getPrimaryBillingLocation();
417 // Now proceed with printing the receipt.
420 <title
><?php
echo xlt('Receipt for Payment'); ?
></title
>
421 <?php Header
::setupHeader(); ?
>
424 <?php
require($GLOBALS['srcdir'] . "/restoreSession.php"); ?
>
427 var win
= top
.printLogSetup ? top
: opener
.top
;
428 win
.printLogSetup(document
.getElementById('printbutton'));
431 function closeHow(e
) {
436 top
.activateTabByName('pat', true);
437 top
.tabCloseByName(window
.name
);
440 // This is action to take before printing and is called from restoreSession.php.
441 function printlog_before_print() {
442 let divstyle
= document
.getElementById('hideonprint').style
;
443 divstyle
.display
= 'none';
444 // currently exit is not hidden by default in case receipt print is not needed
445 // and left here for future option to force users to print via global etc..
446 // can still print later via reports.
447 divstyle
= document
.getElementById('showonprint').style
;
448 divstyle
.display
= '';
451 // Process click on Delete button.
452 function deleteme() {
453 dlgopen('deleter.php?payment=' +
<?php
echo js_url($payment_key); ?
> +
'&csrf_token_form=' +
<?php
echo js_url(CsrfUtils
::collectCsrfToken()); ?
>, '_blank', 500, 450);
457 // Called by the deleteme.php window on a successful delete.
458 function imdeleted() {
460 dlgclose(); // we're in reports/leftnav and callback reloads.
462 window
.history
.back(); // this is us full screen.
466 // Called to switch to the specified encounter having the specified DOS.
467 // This also closes the popup window.
468 function toencounter(enc
, datestr
, topframe
) {
469 topframe
.restoreSession();
470 top
.goToEncounter(enc
);
471 if (opener
) dlgclose();
475 <body bgcolor
='var(--white)'>
478 <p
><h2
><?php
echo xlt('Receipt for Payment'); ?
></h2
>
480 <p
><?php
echo text($frow['name']) ?
>
481 <br
/><?php
echo text($frow['street']) ?
>
482 <br
/><?php
echo text($frow['city'] . ', ' . $frow['state']) . ' ' .
483 text($frow['postal_code']) ?
>
484 <br
/><?php
echo text($frow['phone']) ?
>
487 <table border
='0' cellspacing
='8'>
489 <td
><?php
echo xlt('Date'); ?
>:</td
>
490 <td
><?php
echo text(oeFormatSDFT(strtotime($payrow['dtime']))) ?
></td
>
493 <td
><?php
echo xlt('Patient'); ?
>:</td
>
494 <td
><?php
echo text($patdata['fname']) . " " . text($patdata['mname']) . " " .
495 text($patdata['lname']) . " (" . text($patdata['pubpid']) . ")" ?
></td
>
498 <td
><?php
echo xlt('Paid Via'); ?
>:</td
>
499 <td
><?php
echo generate_display_field(array('data_type' => '1', 'list_id' => 'payment_method'), $payrow['method']); ?
></td
>
502 <td
><?php
echo xlt('Check/Ref Number'); ?
>:</td
>
503 <td
><?php
echo text($payrow['source']) ?
></td
>
506 <td
><?php
echo xlt('Amount for This Visit'); ?
>:</td
>
507 <td
><?php
echo text(oeFormatMoney($payrow['amount1'])) ?
></td
>
512 if ($_REQUEST['radio_type_of_payment'] == 'pre_payment') {
513 echo xlt('Pre-payment Amount');
515 echo xlt('Amount for Past Balance');
519 <td
><?php
echo text(oeFormatMoney($payrow['amount2'])) ?
></td
>
522 <td
><?php
echo xlt('Received By'); ?
>:</td
>
523 <td
><?php
echo text($payrow['user']) ?
></td
>
527 <div id
='hideonprint'>
529 <input type
='button' value
='<?php echo xla('Print'); ?>' id
='printbutton' />
532 $todaysenc = todaysEncounterIf($pid);
533 if ($todaysenc && $todaysenc != $encounter) {
534 echo " <input type='button' " .
535 "value='" . xla('Open Today`s Visit') . "' " .
536 "onclick='toencounter(" . attr_js($todaysenc) . ", " . attr_js($today) . ", (opener ? opener.top : top))' />\n";
540 <?php
if (AclMain
::aclCheckCore('admin', 'super') || AclMain
::aclCheckCore('acct', 'bill')) {
541 // allowing biller to delete payments ?>
543 <input type
='button' value
='<?php echo xla('Delete
'); ?>' style
='color:red' onclick
='deleteme()' />
547 <div id
='showonprint'>
548 <input type
='button' value
='<?php echo xla('Exit'); ?>' id
='donebutton' onclick
="closeHow(event)"/>
555 // End of receipt printing logic.
559 // Here we display the form for data entry.
562 <title
><?php
echo xlt('Record Payment'); ?
></title
>
565 body
{ font
-family
:sans
-serif
; font
-size
:10pt
; font
-weight
:normal
}
566 .dehead
{ color
:var(--black
); font
-family
:sans
-serif
; font
-size
:10pt
; font
-weight
:bold
}
567 .detail
{ color
:var(--black
); font
-family
:sans
-serif
; font
-size
:10pt
; font
-weight
:normal
}
571 background
-color
: #FBFDD0;
572 border
: 1px solid
#ccc;
576 <!--Removed standard dependencies
12/29/17 as not needed any longer since moved to a tab
/frame not popup
.-->
580 <!-- supporting javascript code
-->
584 <?php
include_once("{$GLOBALS['srcdir']}/ajax/payment_ajax_jav.inc.php"); ?
>
586 document
.onclick
=HideTheAjaxDivs
;
589 <?php Header
::setupAssets('topdialog'); ?
>
592 <?php
require($GLOBALS['srcdir'] . "/restoreSession.php"); ?
>
593 function closeHow(e
) {
598 top
.activateTabByName('pat', true);
599 top
.tabCloseByName(window
.name
);
601 function calctotal() {
602 var f
= document
.forms
[0];
604 for (var i
= 0; i
< f
.elements
.length
; ++i
) {
605 var elem
= f
.elements
[i
];
606 var ename
= elem
.name
;
607 if (ename
.indexOf('form_upay[') == 0 || ename
.indexOf('form_bpay[') == 0) {
608 if (elem
.value
.length
> 0) total +
= Number(elem
.value
);
611 f
.form_paytotal
.value
= Number(total
).toFixed(2);
615 function coloring() {
616 for (var i
= 1; ; ++i
) {
617 if (document
.getElementById('paying_' + i
)) {
618 paying
= document
.getElementById('paying_' + i
).value
* 1;
619 patient_balance
= document
.getElementById('duept_' + i
).innerHTML
* 1;
621 //balance=document.getElementById('balance_'+i).innerHTML*1;
622 if (patient_balance
> 0 && paying
> 0) {
623 if (paying
> patient_balance
) {
624 document
.getElementById('paying_' + i
).style
.background
= '#FF0000';
626 else if (paying
< patient_balance
) {
627 document
.getElementById('paying_' + i
).style
.background
= '#99CC00';
629 else if (paying
== patient_balance
) {
630 document
.getElementById('paying_' + i
).style
.background
= 'var(--white)';
633 document
.getElementById('paying_' + i
).style
.background
= 'var(--white)';
642 function CheckVisible(MakeBlank
) { //Displays and hides the check number text box.
643 if (document
.getElementById('form_method').options
[document
.getElementById(
644 'form_method').selectedIndex
].value
== 'check_payment' || document
.getElementById(
645 'form_method').options
[document
.getElementById('form_method').selectedIndex
]
646 .value
== 'bank_draft') {
647 document
.getElementById('check_number').disabled
= false;
649 document
.getElementById('check_number').disabled
= true;
653 function validate() {
654 var f
= document
.forms
[0];
656 top
.restoreSession();
658 // prevent an empty form submission
660 for (let i
= 0; i
< f
.elements
.length
; ++i
) {
661 let ename
= f
.elements
[i
].name
;
662 if (f
.elements
[i
].value
== 'pre_payment' && f
.elements
[i
].checked
=== true) {
663 if (Number(f
.elements
.namedItem("form_prepayment").value
) !== 0) {
668 if (ename
.indexOf('form_upay[') === 0 || ename
.indexOf('form_bpay[') === 0) {
669 if (Number(f
.elements
[i
].value
) !== 0) flgempty
= false;
673 alert(<?php
echo xlj('A Payment is Required!. Please input a payment line item entry.'); ?
>);
676 // continue validation.
677 if (((document
.getElementById('form_method').options
[document
.getElementById('form_method').selectedIndex
].value
== 'check_payment' ||
678 document
.getElementById('form_method').options
[document
.getElementById('form_method').selectedIndex
].value
== 'bank_draft') &&
679 document
.getElementById('check_number').value
== '')) {
680 alert(<?php
echo xlj('Please Fill the Check/Ref Number'); ?
>);
681 document
.getElementById('check_number').focus();
684 if (document
.getElementById('radio_type_of_payment_self1').checked
== false &&
685 document
.getElementById('radio_type_of_payment1').checked
== false &&
686 document
.getElementById('radio_type_of_payment2').checked
== false &&
687 document
.getElementById('radio_type_of_payment4').checked
== false) {
688 alert(<?php
echo xlj('Please Select Type Of Payment.'); ?
>);
691 if (document
.getElementById('radio_type_of_payment_self1').checked
== true ||
692 document
.getElementById('radio_type_of_payment1').checked
== true) {
693 for (var i
= 0; i
< f
.elements
.length
; ++i
) {
694 var elem
= f
.elements
[i
];
695 var ename
= elem
.name
;
696 if (ename
.indexOf('form_upay[0') == 0) //Today is this text box.
698 if (elem
.value
* 1 > 0) {//A warning message, if the amount is posted with out encounter.
699 if (confirm(<?php
echo xlj('If patient has appointment click OK to create encounter otherwise, cancel this and then create an encounter for today visit.'); ?
>)) {
711 if (document
.getElementById('radio_type_of_payment1').checked
== true){//CO-PAY
713 for (var i
= 0; i
< f
.elements
.length
; ++i
) {
714 var elem
= f
.elements
[i
];
715 var ename
= elem
.name
;
716 if (ename
.indexOf('form_upay[0]') == 0) {//Today is this text box.
717 if (f
.form_paytotal
.value
* 1 != elem
.value
* 1) {//Total CO-PAY is not posted against today
718 //A warning message, if the amount is posted against an old encounter.
719 if (confirm(<?php
echo xlj('You are posting against an old encounter?'); ?
>)) {
730 else if (document
.getElementById('radio_type_of_payment2').checked
== true) {//Invoice Balance
731 for (var i
= 0; i
< f
.elements
.length
; ++i
) {
732 var elem
= f
.elements
[i
];
733 var ename
= elem
.name
;
734 if (ename
.indexOf('form_upay[0') == 0) {
735 if (elem
.value
* 1 > 0) {
736 alert(<?php
echo xlj('Invoice Balance cannot be posted. No Encounter is created.'); ?
>);
744 if (confirm(<?php
echo xlj('Would you like to save?'); ?
>)) {
753 function cursor_pointer() { //Point the cursor to the latest encounter(Today)
754 var f
= document
.forms
[0];
756 for (var i
= 0; i
< f
.elements
.length
; ++i
) {
757 var elem
= f
.elements
[i
];
758 var ename
= elem
.name
;
759 if (ename
.indexOf('form_upay[') == 0) {
765 //=====================================================
766 function make_it_hide_enc_pay() {
767 document
.getElementById('td_head_insurance_payment').style
.display
= "none";
768 document
.getElementById('td_head_patient_co_pay').style
.display
= "none";
769 document
.getElementById('td_head_co_pay').style
.display
= "none";
770 document
.getElementById('td_head_insurance_balance').style
.display
= "none";
771 for (var i
= 1; ; ++i
) {
772 var td_inspaid_elem
= document
.getElementById('td_inspaid_' + i
)
773 var td_patient_copay_elem
= document
.getElementById('td_patient_copay_' + i
)
774 var td_copay_elem
= document
.getElementById('td_copay_' + i
)
775 var balance_elem
= document
.getElementById('balance_' + i
)
776 if (td_inspaid_elem
) {
777 td_inspaid_elem
.style
.display
= "none";
778 td_patient_copay_elem
.style
.display
= "none";
779 td_copay_elem
.style
.display
= "none";
780 balance_elem
.style
.display
= "none";
785 document
.getElementById('td_total_4').style
.display
= "none";
786 document
.getElementById('td_total_7').style
.display
= "none";
787 document
.getElementById('td_total_8').style
.display
= "none";
788 document
.getElementById('td_total_6').style
.display
= "none";
789 document
.getElementById('table_display').width
= "420px";
791 //=====================================================
792 function make_visible() {
793 document
.getElementById('td_head_rep_doc').style
.display
= "";
794 document
.getElementById('td_head_description').style
.display
= "";
795 document
.getElementById('td_head_total_charge').style
.display
= "none";
796 document
.getElementById('td_head_insurance_payment').style
.display
= "none";
797 document
.getElementById('td_head_patient_payment').style
.display
= "none";
798 document
.getElementById('td_head_patient_co_pay').style
.display
= "none";
799 document
.getElementById('td_head_co_pay').style
.display
= "none";
800 document
.getElementById('td_head_insurance_balance').style
.display
= "none";
801 document
.getElementById('td_head_patient_balance').style
.display
= "none";
802 for (var i
= 1; ; ++i
) {
803 var td_charges_elem
= document
.getElementById('td_charges_' + i
)
804 var td_inspaid_elem
= document
.getElementById('td_inspaid_' + i
)
805 var td_ptpaid_elem
= document
.getElementById('td_ptpaid_' + i
)
806 var td_patient_copay_elem
= document
.getElementById('td_patient_copay_' + i
)
808 var td_copay_elem
= document
.getElementById('td_copay_' + i
)
809 var balance_elem
= document
.getElementById('balance_' + i
)
810 var duept_elem
= document
.getElementById('duept_' + i
)
811 if (td_charges_elem
) {
812 td_charges_elem
.style
.display
= "none";
813 td_inspaid_elem
.style
.display
= "none";
814 td_ptpaid_elem
.style
.display
= "none";
815 td_patient_copay_elem
.style
.display
= "none";
816 td_copay_elem
.style
.display
= "none";
817 balance_elem
.style
.display
= "none";
818 duept_elem
.style
.display
= "none";
823 document
.getElementById('td_total_7').style
.display
= "";
824 document
.getElementById('td_total_8').style
.display
= "";
825 document
.getElementById('td_total_1').style
.display
= "none";
826 document
.getElementById('td_total_2').style
.display
= "none";
827 document
.getElementById('td_total_3').style
.display
= "none";
828 document
.getElementById('td_total_4').style
.display
= "none";
829 document
.getElementById('td_total_5').style
.display
= "none";
830 document
.getElementById('td_total_6').style
.display
= "none";
831 document
.getElementById('table_display').width
= "505px";
834 function make_it_hide() {
835 document
.getElementById('td_head_rep_doc').style
.display
= "none";
836 document
.getElementById('td_head_description').style
.display
= "none";
837 document
.getElementById('td_head_total_charge').style
.display
= "";
838 document
.getElementById('td_head_insurance_payment').style
.display
= "";
839 document
.getElementById('td_head_patient_payment').style
.display
= "";
840 document
.getElementById('td_head_patient_co_pay').style
.display
= "";
841 document
.getElementById('td_head_co_pay').style
.display
= "";
842 document
.getElementById('td_head_insurance_balance').style
.display
= "";
843 document
.getElementById('td_head_patient_balance').style
.display
= "";
844 for (var i
= 1; ; ++i
) {
845 var td_charges_elem
= document
.getElementById('td_charges_' + i
)
846 var td_inspaid_elem
= document
.getElementById('td_inspaid_' + i
)
847 var td_ptpaid_elem
= document
.getElementById('td_ptpaid_' + i
)
848 var td_patient_copay_elem
= document
.getElementById('td_patient_copay_' + i
)
850 var td_copay_elem
= document
.getElementById('td_copay_' + i
)
851 var balance_elem
= document
.getElementById('balance_' + i
)
852 var duept_elem
= document
.getElementById('duept_' + i
)
853 if (td_charges_elem
) {
854 td_charges_elem
.style
.display
= "";
855 td_inspaid_elem
.style
.display
= "";
856 td_ptpaid_elem
.style
.display
= "";
857 td_patient_copay_elem
.style
.display
= "";
858 td_copay_elem
.style
.display
= "";
859 balance_elem
.style
.display
= "";
860 duept_elem
.style
.display
= "";
865 document
.getElementById('td_total_1').style
.display
= "";
866 document
.getElementById('td_total_2').style
.display
= "";
867 document
.getElementById('td_total_3').style
.display
= "";
868 document
.getElementById('td_total_4').style
.display
= "";
869 document
.getElementById('td_total_5').style
.display
= "";
870 document
.getElementById('td_total_6').style
.display
= "";
871 document
.getElementById('td_total_7').style
.display
= "";
872 document
.getElementById('td_total_8').style
.display
= "";
873 document
.getElementById('table_display').width
= "635px";
876 function make_visible_radio() {
877 document
.getElementById('tr_radio1').style
.display
= "";
878 document
.getElementById('tr_radio2').style
.display
= "none";
881 function make_hide_radio() {
882 document
.getElementById('tr_radio1').style
.display
= "none";
883 document
.getElementById('tr_radio2').style
.display
= "";
886 function make_visible_row() {
887 document
.getElementById('table_display').style
.display
= "";
888 document
.getElementById('table_display_prepayment').style
.display
= "none";
891 function make_hide_row() {
892 document
.getElementById('table_display').style
.display
= "none";
893 document
.getElementById('table_display_prepayment').style
.display
= "";
896 function make_self() {
899 make_it_hide_enc_pay();
900 document
.getElementById('radio_type_of_payment_self1').checked
= true;
904 function make_insurance() {
908 document
.getElementById('radio_type_of_payment1').checked
= true;
913 @media only screen
and (max
-width
: 768px
) {
916 text
-align
: left
!Important
;
921 width
: 90%
!important
;
923 @media
(min
-width
: 992px
) {
925 width
: 1000px
!Important
;
929 <title
><?php
echo xlt('Record Payment'); ?
></title
>
930 <?php
$NameNew = $patdata['fname'] . " " . $patdata['lname'] . " " . $patdata['mname']; ?
>
932 $arrOeUiSettings = array(
933 'heading_title' => xl('Accept Payment'),
934 'include_patient_name' => true,// use only in appropriate pages
935 'expandable' => false,
936 'expandable_files' => array(),//all file names need suffix _xpd
937 'action' => "",//conceal, reveal, search, reset, link or back
938 'action_title' => "",
939 'action_href' => "",//only for actions - reset, link or back
940 'show_help_icon' => false,
941 'help_file_name' => ""
943 $oemr_ui = new OemrUI($arrOeUiSettings);
947 <div
class="container"><!--begin container div
for form
-->
949 <div
class="col-sm-12">
950 <div
class="page-header">
951 <?php
echo $oemr_ui->pageHeading() . "\r\n"; ?
>
956 <div
class="col-sm-12">
957 <form method
='post' action
='front_payment.php<?php echo ($payid) ? "?payid=" . attr_url($payid) : ""; ?>' onsubmit
='return validate();'>
958 <input type
="hidden" name
="csrf_token_form" value
="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
959 <input name
='form_pid' type
='hidden' value
='<?php echo attr($pid) ?>'>
961 <legend
><?php
echo xlt('Payment'); ?
></legend
>
962 <div
class="col-12 oe-custom-line">
963 <div
class="col-3 offset-lg-3">
964 <label
class="control-label" for="form_method"><?php
echo xlt('Payment Method'); ?
>:</label
>
967 <select
class="form-control" id
="form_method" name
="form_method" onchange
='CheckVisible("yes")'>
969 $query1112 = "SELECT * FROM list_options where list_id=? ORDER BY seq, title ";
970 $bres1112 = sqlStatement($query1112, array('payment_method'));
971 while ($brow1112 = sqlFetchArray($bres1112)) {
972 if ($brow1112['option_id'] == 'electronic' ||
$brow1112['option_id'] == 'bank_draft') {
975 echo "<option value='" . attr($brow1112['option_id']) . "'>" . text(xl_list_label($brow1112['title'])) . "</option>";
981 <div
class="col-12 oe-custom-line">
982 <div
class="col-3 offset-lg-3">
983 <label
class="control-label" for="check_number"><?php
echo xlt('Check/Ref Number'); ?
>:</label
>
986 <div id
="ajax_div_patient" style
="display:none;"></div
>
987 <input type
='text' id
="check_number" name
='form_source' class= 'form-control' value
='<?php echo attr($payrow['source
']); ?>'>
990 <div
class="col-12 oe-custom-line">
991 <div
class="col-3 offset-lg-3">
992 <label
class="control-label" for="form_discount"><?php
echo xla('Patient Coverage'); ?
>:</label
>
995 <div style
="padding-left:15px">
996 <label
class="radio-inline">
997 <input id
="radio_type_of_coverage1" name
="radio_type_of_coverage" onclick
="make_visible_radio();make_self();" type
="radio" value
="self"><?php
echo xlt('Self'); ?
>
999 <label
class="radio-inline">
1000 <input checked
="checked" id
="radio_type_of_coverag2" name
="radio_type_of_coverage" onclick
="make_hide_radio();make_insurance();" type
="radio" value
="insurance"><?php
echo xlt('Insurance'); ?
>
1005 <div
class="col-12 oe-custom-line">
1006 <div
class="col-3 offset-lg-3">
1007 <label
class="control-label" for=""><?php
echo xlt('Payment against'); ?
>:</label
>
1010 <div id
="tr_radio1" style
="padding-left:15px; display:none"><!-- For radio Insurance
-->
1011 <label
class="radio-inline">
1012 <input id
="radio_type_of_payment_self1" name
="radio_type_of_payment" onclick
="make_visible_row();make_it_hide_enc_pay();cursor_pointer();" type
="radio" value
="cash"><?php
echo xlt('Encounter Payment'); ?
>
1015 <div id
="tr_radio2" style
="padding-left:15px"><!-- For radio self
-->
1016 <label
class="radio-inline">
1017 <input checked
="checked" id
="radio_type_of_payment1" name
="radio_type_of_payment" onclick
="make_visible_row();cursor_pointer();" type
="radio" value
="copay"><?php
echo xlt('Co Pay'); ?
>
1019 <label
class="radio-inline">
1020 <input id
="radio_type_of_payment2" name
="radio_type_of_payment" onclick
="make_visible_row();" type
="radio" value
="invoice_balance"><?php
echo xlt('Invoice Balance'); ?
><br
/>
1022 <label
class="radio-inline">
1023 <input id
="radio_type_of_payment4" name
="radio_type_of_payment" onclick
="make_hide_row();" type
="radio" value
="pre_payment"><?php
echo xlt('Pre Pay'); ?
>
1028 <div
class="col-12 oe-custom-line">
1029 <div id
="table_display_prepayment" style
="display:none">
1030 <div
class="col-3 offset-lg-3">
1031 <label
class="control-label" for="form_prepayment"><?php
echo xlt('Pre Payment'); ?
>:</label
>
1034 <input name
='form_prepayment' id
='form_prepayment'class='form-control' type
='text' value
=''>
1040 <legend
><?php
echo xlt('Collect For'); ?
></legend
>
1041 <div
class= "table-responsive">
1042 <table
class = "table" id
="table_display">
1044 <tr bgcolor
="#CCCCCC" id
="tr_head">
1045 <td
class="dehead" width
="70"><?php
echo xlt('DOS'); ?
></td
>
1046 <td
class="dehead" width
="65"><?php
echo xlt('Encounter'); ?
></td
>
1047 <td align
="center" class="dehead" id
="td_head_total_charge" width
="80"><?php
echo xlt('Total Charge'); ?
></td
>
1048 <td align
="center" class="dehead" id
="td_head_rep_doc" style
='display:none' width
="70"><?php
echo xlt('Report/ Form'); ?
></td
>
1049 <td align
="center" class="dehead" id
="td_head_description" style
='display:none' width
="200"><?php
echo xlt('Description'); ?
></td
>
1050 <td align
="center" class="dehead" id
="td_head_insurance_payment" width
="80"><?php
echo xlt('Insurance Payment'); ?
></td
>
1051 <td align
="center" class="dehead" id
="td_head_patient_payment" width
="80"><?php
echo xlt('Patient Payment'); ?
></td
>
1052 <td align
="center" class="dehead" id
="td_head_patient_co_pay" width
="55"><?php
echo xlt('Co Pay Paid'); ?
></td
>
1053 <td align
="center" class="dehead" id
="td_head_co_pay" width
="55"><?php
echo xlt('Required Co Pay'); ?
></td
>
1054 <td align
="center" class="dehead" id
="td_head_insurance_balance" width
="80"><?php
echo xlt('Insurance Balance'); ?
></td
>
1055 <td align
="center" class="dehead" id
="td_head_patient_balance" width
="80"><?php
echo xlt('Patient Balance'); ?
></td
>
1056 <td align
="center" class="dehead" width
="50"><?php
echo xlt('Paying'); ?
></td
>
1062 // Get the unbilled service charges and payments by encounter for this patient.
1064 $query = "SELECT fe.encounter, b.code_type, b.code, b.modifier, b.fee, " .
1065 "LEFT(fe.date, 10) AS encdate ,fe.last_level_closed " .
1066 "FROM form_encounter AS fe left join billing AS b on " .
1067 "b.pid = ? AND b.activity = 1 AND " . //AND b.billed = 0
1068 "b.code_type != 'TAX' AND b.fee != 0 " .
1069 "AND fe.pid = b.pid AND fe.encounter = b.encounter " .
1070 "where fe.pid = ? " .
1071 "ORDER BY b.encounter";
1072 $bres = sqlStatement($query, array($pid, $pid));
1074 while ($brow = sqlFetchArray($bres)) {
1075 $key = 0 - $brow['encounter'];
1076 if (empty($encs[$key])) {
1077 $encs[$key] = array(
1078 'encounter' => $brow['encounter'],
1079 'date' => $brow['encdate'],
1080 'last_level_closed' => $brow['last_level_closed'],
1085 if ($brow['code_type'] === 'COPAY') {
1086 //$encs[$key]['payments'] -= $brow['fee'];
1088 $encs[$key]['charges'] +
= $brow['fee'];
1090 $sql_array = array();
1091 $query = "SELECT taxrates FROM codes WHERE " .
1092 "code_type = ? AND " .
1094 array_push($sql_array, $code_types[$brow['code_type']]['id'], $brow['code']);
1095 if ($brow['modifier']) {
1096 $query .= "modifier = ?";
1097 array_push($sql_array, $brow['modifier']);
1099 $query .= "(modifier IS NULL OR modifier = '')";
1102 $query .= " LIMIT 1";
1103 $trow = sqlQuery($query, $sql_array);
1104 $encs[$key]['charges'] +
= calcTaxes($trow, $brow['fee']);
1108 // Do the same for unbilled product sales.
1110 $query = "SELECT fe.encounter, s.drug_id, s.fee, " .
1111 "LEFT(fe.date, 10) AS encdate,fe.last_level_closed " .
1112 "FROM form_encounter AS fe left join drug_sales AS s " .
1113 "on s.pid = ? AND s.fee != 0 " . //AND s.billed = 0
1114 "AND fe.pid = s.pid AND fe.encounter = s.encounter " .
1115 "where fe.pid = ? " .
1116 "ORDER BY s.encounter";
1118 $dres = sqlStatement($query, array($pid, $pid));
1120 while ($drow = sqlFetchArray($dres)) {
1121 $key = 0 - $drow['encounter'];
1122 if (empty($encs[$key])) {
1123 $encs[$key] = array(
1124 'encounter' => $drow['encounter'],
1125 'date' => $drow['encdate'],
1126 'last_level_closed' => $drow['last_level_closed'],
1131 $encs[$key]['charges'] +
= $drow['fee'];
1133 $trow = sqlQuery("SELECT taxrates FROM drug_templates WHERE drug_id = ? " .
1134 "ORDER BY selector LIMIT 1", array($drow['drug_id']));
1135 $encs[$key]['charges'] +
= calcTaxes($trow, $drow['fee']);
1138 ksort($encs, SORT_NUMERIC
);
1140 //Bringing on top the Today always
1141 foreach ($encs as $key => $value) {
1142 $dispdate = $value['date'];
1143 if (strcmp($dispdate, $today) == 0 && !$gottoday) {
1149 // If no billing was entered yet for today, then generate a line for
1150 // entering today's co-pay.
1153 echoLine("form_upay[0]", date("Y-m-d"), 0, 0, 0, 0 /*$duept*/);//No encounter yet defined.
1157 foreach ($encs as $key => $value) {
1158 $enc = $value['encounter'];
1159 $dispdate = $value['date'];
1160 if (strcmp($dispdate, $today) == 0 && !$gottoday) {
1161 $dispdate = date("Y-m-d");
1164 //------------------------------------------------------------------------------------
1165 $inscopay = BillingUtilities
::getCopay($pid, $dispdate);
1166 $patcopay = BillingUtilities
::getPatientCopay($pid, $enc);
1170 "SELECT SUM(pay_amount) AS payments, " .
1171 "SUM(adj_amount) AS adjustments FROM ar_activity WHERE " .
1172 "deleted IS NULL AND pid = ? and encounter = ? and " .
1173 "payer_type != 0 and account_code!='PCP' ",
1176 $dpayment = $drow['payments'];
1177 $dadjustment = $drow['adjustments'];
1181 "SELECT SUM(pay_amount) AS payments, " .
1182 "SUM(adj_amount) AS adjustments FROM ar_activity WHERE " .
1183 "deleted IS NULL AND pid = ? and encounter = ? and " .
1184 "payer_type = 0 and account_code!='PCP' ",
1187 $dpayment_pat = $drow['payments'];
1189 //------------------------------------------------------------------------------------
1191 $ResultNumberOfInsurance = sqlStatement("SELECT COUNT( DISTINCT TYPE ) NumberOfInsurance FROM insurance_data
1192 where pid = ? and provider>0 ", array($pid));
1193 $RowNumberOfInsurance = sqlFetchArray($ResultNumberOfInsurance);
1194 $NumberOfInsurance = $RowNumberOfInsurance['NumberOfInsurance'] * 1;
1195 //------------------------------------------------------------------------------------
1197 if ((($NumberOfInsurance == 0 ||
$value['last_level_closed'] == 4 ||
$NumberOfInsurance == $value['last_level_closed']))) {//Patient balance
1198 $brow = sqlQuery("SELECT SUM(fee) AS amount FROM billing WHERE " .
1199 "pid = ? and encounter = ? AND activity = 1", array($pid, $enc));
1200 $srow = sqlQuery("SELECT SUM(fee) AS amount FROM drug_sales WHERE " .
1201 "pid = ? and encounter = ? ", array($pid, $enc));
1202 $drow = sqlQuery("SELECT SUM(pay_amount) AS payments, " .
1203 "SUM(adj_amount) AS adjustments FROM ar_activity WHERE " .
1204 "deleted IS NULL AND pid = ? and encounter = ? ", array($pid, $enc));
1205 $duept = $brow['amount'] +
$srow['amount'] - $drow['payments'] - $drow['adjustments'];
1213 ($dpayment +
$dadjustment),
1222 // Continue with display of the data entry form.
1225 <tr bgcolor
="#CCCCCC">
1226 <td
class="dehead" id
='td_total_1'></td
>
1227 <td
class="dehead" id
='td_total_2'></td
>
1228 <td
class="dehead" id
='td_total_3'></td
>
1229 <td
class="dehead" id
='td_total_4'></td
>
1230 <td
class="dehead" id
='td_total_5'></td
>
1231 <td
class="dehead" id
='td_total_6'></td
>
1232 <td
class="dehead" id
='td_total_7'></td
>
1233 <td
class="dehead" id
='td_total_8'></td
>
1234 <td align
="right" class="dehead"><?php
echo xlt('Total');?
></td
>
1235 <td align
="right" class="dehead"><input name
='form_paytotal' readonly style
='color:#00aa00;width:50px' type
='text' value
=''></td
>
1240 <div
class="form-group">
1241 <div
class="col-sm-12 text-left position-override">
1242 <div
class="btn-group btn-group-pinch" role
="group">
1243 <button type
='submit' class="btn btn-secondary btn-save" name
='form_save' value
='<?php echo xla('Generate Invoice
');?>'><?php
echo xlt('Generate Invoice');?
></button
>
1244 <button type
='button' class="btn btn-link btn-cancel btn-separate-left" value
='<?php echo xla('Cancel
'); ?>' onclick
='closeHow(event)'><?php
echo xlt('Cancel'); ?
></button
>
1245 <input type
="hidden" name
="hidden_patient_code" id
="hidden_patient_code" value
="<?php echo attr($pid);?>"/>
1246 <input type
='hidden' name
='ajax_mode' id
='ajax_mode' value
='' />
1247 <input type
='hidden' name
='mode' id
='mode' value
='' />
1257 </div
><!--end of container div of accept payment i
.e the form
-->
1259 $oemr_ui->oeBelowContainerDiv();
1260 } // forms else close