6 * @link http://www.open-emr.org
7 * @author Rod Roark <rod@sunsetsystems.com>
8 * @author Brady Miller <brady.g.miller@gmail.com>
9 * @copyright Copyright (c) 2006-2016 Rod Roark <rod@sunsetsystems.com>
10 * @copyright Copyright (c) 2017 Brady Miller <brady.g.miller@gmail.com>
11 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
15 require_once("../globals.php");
16 require_once("$srcdir/acl.inc");
17 require_once("$srcdir/patient.inc");
18 require_once("$srcdir/billing.inc");
19 require_once("$srcdir/payment.inc.php");
20 require_once("$srcdir/forms.inc");
21 require_once("$srcdir/sl_eob.inc.php");
22 require_once("$srcdir/invoice_summary.inc.php");
23 require_once("../../custom/code_types.inc.php");
24 require_once("$srcdir/options.inc.php");
25 require_once("$srcdir/encounter_events.inc.php");
27 use OpenEMR\Services\FacilityService
;
29 $pid = $_REQUEST['hidden_patient_code'] > 0 ?
$_REQUEST['hidden_patient_code'] : $pid;
31 $facilityService = new FacilityService();
36 <?php
html_header_show();?
>
37 <script type
="text/javascript" src
="<?php echo $webroot ?>/interface/main/tabs/js/include_opener.js"></script
>
38 <link rel
='stylesheet' href
='<?php echo $css_header ?>' type
='text/css'>
40 // Format dollars for display.
42 function bucks($amount)
45 $amount = oeFormatMoney($amount);
52 function rawbucks($amount)
55 $amount = sprintf("%.2f", $amount);
62 // Display a row of data for an encounter.
65 function echoLine($iname, $date, $charges, $ptpaid, $inspaid, $duept, $encounter = 0, $copay = 0, $patcopay = 0)
69 $balance = bucks($charges - $ptpaid - $inspaid);
70 $balance = (round($duept, 2) != 0) ?
0 : $balance;//if balance is due from patient, then insurance balance is displayed as zero
71 $encounter = $encounter ?
$encounter : '';
72 echo " <tr id='tr_".attr($var_index)."' >\n";
73 echo " <td class='detail'>" . text(oeFormatShortDate($date)) . "</td>\n";
74 echo " <td class='detail' id='".attr($date)."' align='center'>" . htmlspecialchars($encounter, ENT_QUOTES
) . "</td>\n";
75 echo " <td class='detail' align='center' id='td_charges_$var_index' >" . htmlspecialchars(bucks($charges), ENT_QUOTES
) . "</td>\n";
76 echo " <td class='detail' align='center' id='td_inspaid_$var_index' >" . htmlspecialchars(bucks($inspaid*-1), ENT_QUOTES
) . "</td>\n";
77 echo " <td class='detail' align='center' id='td_ptpaid_$var_index' >" . htmlspecialchars(bucks($ptpaid*-1), ENT_QUOTES
) . "</td>\n";
78 echo " <td class='detail' align='center' id='td_patient_copay_$var_index' >" . htmlspecialchars(bucks($patcopay), ENT_QUOTES
) . "</td>\n";
79 echo " <td class='detail' align='center' id='td_copay_$var_index' >" . htmlspecialchars(bucks($copay), ENT_QUOTES
) . "</td>\n";
80 echo " <td class='detail' align='center' id='balance_$var_index'>" . htmlspecialchars(bucks($balance), ENT_QUOTES
) . "</td>\n";
81 echo " <td class='detail' align='center' id='duept_$var_index'>" . htmlspecialchars(bucks(round($duept, 2)*1), ENT_QUOTES
) . "</td>\n";
82 echo " <td class='detail' align='right'><input type='text' name='".attr($iname)."' id='paying_".attr($var_index)."' " .
83 " value='" . '' . "' onchange='coloring();calctotal()' autocomplete='off' " .
84 "onkeyup='calctotal()' style='width:50px'/></td>\n";
88 // We use this to put dashes, colons, etc. back into a timestamp.
90 function decorateString($fmt, $str)
94 $fc = substr($fmt, 0, 1);
95 $fmt = substr($fmt, 1);
97 $res .= substr($str, 0, 1);
98 $str = substr($str, 1);
107 // Compute taxes from a tax rate string and a possibly taxable amount.
109 function calcTaxes($row, $amount)
112 if (empty($row['taxrates'])) {
116 $arates = explode(':', $row['taxrates']);
117 if (empty($arates)) {
121 foreach ($arates as $value) {
126 $trow = sqlQuery("SELECT option_value FROM list_options WHERE " .
127 "list_id = 'taxrate' AND option_id = ? AND activity = 1 LIMIT 1", array($value));
128 if (empty($trow['option_value'])) {
129 echo "<!-- Missing tax rate '".text($value)."'! -->\n";
133 $tax = sprintf("%01.2f", $amount * $trow['option_value']);
134 // echo "<!-- Rate = '$value', amount = '$amount', tax = '$tax' -->\n";
142 $today = date('Y-m-d', $now);
143 $timestamp = date('Y-m-d H:i:s', $now);
146 // $patdata = getPatientData($pid, 'fname,lname,pubpid');
148 $patdata = sqlQuery("SELECT " .
149 "p.fname, p.mname, p.lname, p.pubpid,p.pid, i.copay " .
150 "FROM patient_data AS p " .
151 "LEFT OUTER JOIN insurance_data AS i ON " .
152 "i.pid = p.pid AND i.type = 'primary' " .
153 "WHERE p.pid = ? ORDER BY i.date DESC LIMIT 1", array($pid));
155 $alertmsg = ''; // anything here pops up in an alert box
157 // If the Save button was clicked...
158 if ($_POST['form_save']) {
159 $form_pid = $_POST['form_pid'];
160 $form_method = trim($_POST['form_method']);
161 $form_source = trim($_POST['form_source']);
162 $patdata = getPatientData($form_pid, 'fname,mname,lname,pubpid');
163 $NameNew=$patdata['fname'] . " " .$patdata['lname']. " " .$patdata['mname'];
165 if ($_REQUEST['radio_type_of_payment']=='pre_payment') {
166 $payment_id = idSqlStatement(
167 "insert into ar_session set " .
173 ", check_date = now() , deposit_date = now() " .
175 ", payment_type = 'patient'" .
176 ", description = ?" .
177 ", adjustment_code = 'pre_payment'" .
178 ", post_to_date = now() " .
179 ", payment_method = ?",
180 array(0,$form_pid,$_SESSION['authUserID'],0,$form_source,$_REQUEST['form_prepayment'],$NameNew,$form_method)
183 frontPayment($form_pid, 0, $form_method, $form_source, $_REQUEST['form_prepayment'], 0, $timestamp);//insertion to 'payments' table.
186 if ($_POST['form_upay'] && $_REQUEST['radio_type_of_payment']!='pre_payment') {
187 foreach ($_POST['form_upay'] as $enc => $payment) {
188 if ($amount = 0 +
$payment) {
190 if ($_REQUEST['radio_type_of_payment']=='invoice_balance') {
192 $enc = calendar_arrived($form_pid);
196 $enc = calendar_arrived($form_pid);
200 //----------------------------------------------------------------------------------------------------
201 //Fetching the existing code and modifier
202 $ResultSearchNew = sqlStatement(
203 "SELECT * FROM billing LEFT JOIN code_types ON billing.code_type=code_types.ct_key ".
204 "WHERE code_types.ct_fee=1 AND billing.activity!=0 AND billing.pid =? AND encounter=? ORDER BY billing.code,billing.modifier",
205 array($form_pid,$enc)
207 if ($RowSearch = sqlFetchArray($ResultSearchNew)) {
208 $Codetype=$RowSearch['code_type'];
209 $Code=$RowSearch['code'];
210 $Modifier=$RowSearch['modifier'];
217 //----------------------------------------------------------------------------------------------------
218 if ($_REQUEST['radio_type_of_payment']=='copay') {//copay saving to ar_session and ar_activity tables
219 $session_id=sqlInsert(
220 "INSERT INTO ar_session (payer_id,user_id,reference,check_date,deposit_date,pay_total,".
221 " global_amount,payment_type,description,patient_id,payment_method,adjustment_code,post_to_date) ".
222 " VALUES ('0',?,?,now(),now(),?,'','patient','COPAY',?,?,'patient_payment',now())",
223 array($_SESSION['authId'],$form_source,$amount,$form_pid,$form_method)
227 $sequence_no = sqlQuery("SELECT IFNULL(MAX(sequence_no),0) + 1 AS increment FROM ar_activity WHERE pid = ? AND encounter = ?", array($form_pid, $enc));
229 "INSERT INTO ar_activity (pid,encounter,sequence_no,code_type,code,modifier,payer_type,post_time,post_user,session_id,pay_amount,account_code)".
230 " VALUES (?,?,?,?,?,?,0,now(),?,?,?,'PCP')",
231 array($form_pid,$enc,$sequence_no['increment'],$Codetype,$Code,$Modifier,$_SESSION['authId'],$session_id,$amount)
235 frontPayment($form_pid, $enc, $form_method, $form_source, $amount, 0, $timestamp);//insertion to 'payments' table.
238 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.
239 if ($_REQUEST['radio_type_of_payment']=='cash') {
241 "update form_encounter set last_level_closed=? where encounter=? and pid=? ",
242 array(4,$enc,$form_pid)
245 "update billing set billed=? where encounter=? and pid=?",
246 array(1,$enc,$form_pid)
250 $adjustment_code='patient_payment';
251 $payment_id = idSqlStatement(
252 "insert into ar_session set " .
258 ", check_date = now() , deposit_date = now() " .
260 ", payment_type = 'patient'" .
261 ", description = ?" .
262 ", adjustment_code = ?" .
263 ", post_to_date = now() " .
264 ", payment_method = ?",
265 array(0,$form_pid,$_SESSION['authUserID'],0,$form_source,$amount,$NameNew,$adjustment_code,$form_method)
268 //--------------------------------------------------------------------------------------------------------------------
270 frontPayment($form_pid, $enc, $form_method, $form_source, 0, $amount, $timestamp);//insertion to 'payments' table.
272 //--------------------------------------------------------------------------------------------------------------------
274 $resMoneyGot = sqlStatement(
275 "SELECT sum(pay_amount) as PatientPay FROM ar_activity where pid =? and ".
276 "encounter =? and payer_type=0 and account_code='PCP'",
277 array($form_pid,$enc)
278 );//new fees screen copay gives account_code='PCP'
279 $rowMoneyGot = sqlFetchArray($resMoneyGot);
280 $Copay=$rowMoneyGot['PatientPay'];
282 //--------------------------------------------------------------------------------------------------------------------
284 //Looping the existing code and modifier
285 $ResultSearchNew = sqlStatement(
286 "SELECT * FROM billing LEFT JOIN code_types ON billing.code_type=code_types.ct_key WHERE code_types.ct_fee=1 ".
287 "AND billing.activity!=0 AND billing.pid =? AND encounter=? ORDER BY billing.code,billing.modifier",
288 array($form_pid,$enc)
290 while ($RowSearch = sqlFetchArray($ResultSearchNew)) {
291 $Codetype=$RowSearch['code_type'];
292 $Code=$RowSearch['code'];
293 $Modifier =$RowSearch['modifier'];
294 $Fee =$RowSearch['fee'];
296 $resMoneyGot = sqlStatement(
297 "SELECT sum(pay_amount) as MoneyGot FROM ar_activity where pid =? ".
298 "and code_type=? and code=? and modifier=? and encounter =? and !(payer_type=0 and account_code='PCP')",
299 array($form_pid,$Codetype,$Code,$Modifier,$enc)
301 //new fees screen copay gives account_code='PCP'
302 $rowMoneyGot = sqlFetchArray($resMoneyGot);
303 $MoneyGot=$rowMoneyGot['MoneyGot'];
305 $resMoneyAdjusted = sqlStatement(
306 "SELECT sum(adj_amount) as MoneyAdjusted FROM ar_activity where ".
307 "pid =? and code_type=? and code=? and modifier=? and encounter =?",
308 array($form_pid,$Codetype,$Code,$Modifier,$enc)
310 $rowMoneyAdjusted = sqlFetchArray($resMoneyAdjusted);
311 $MoneyAdjusted=$rowMoneyAdjusted['MoneyAdjusted'];
313 $Remainder=$Fee-$Copay-$MoneyGot-$MoneyAdjusted;
315 if (round($Remainder, 2)!=0 && $amount!=0) {
316 if ($amount-$Remainder >= 0) {
317 $insert_value=$Remainder;
318 $amount=$amount-$Remainder;
320 $insert_value=$amount;
325 $sequence_no = sqlQuery("SELECT IFNULL(MAX(sequence_no),0) + 1 AS increment FROM ar_activity WHERE pid = ? AND encounter = ?", array($form_pid, $enc));
327 "insert into ar_activity set " .
330 ", sequence_no = ?" .
335 ", post_time = now() " .
340 ", account_code = 'PP'",
341 array($form_pid,$enc,$sequence_no['increment'],$Codetype,$Code,$Modifier,0,$_SESSION['authUserID'],$payment_id,$insert_value,0)
346 if ($amount!=0) {//if any excess is there.
348 $sequence_no = sqlQuery("SELECT IFNULL(MAX(sequence_no),0) + 1 AS increment FROM ar_activity WHERE pid = ? AND encounter = ?", array($form_pid, $enc));
350 "insert into ar_activity set " .
353 ", sequence_no = ?" .
358 ", post_time = now() " .
363 ", account_code = 'PP'",
364 array($form_pid,$enc,$sequence_no['increment'],$Codetype,$Code,$Modifier,0,$_SESSION['authUserID'],$payment_id,$amount,0)
369 //--------------------------------------------------------------------------------------------------------------------
371 }//if ($amount = 0 + $payment)
373 }//if ($_POST['form_upay'])
374 }//if ($_POST['form_save'])
376 if ($_POST['form_save'] ||
$_REQUEST['receipt']) {
377 if ($_REQUEST['receipt']) {
378 $form_pid = $_GET['patient'];
379 $timestamp = decorateString('....-..-.. ..:..:..', $_GET['time']);
382 // Get details for what we guess is the primary facility.
383 $frow = $facilityService->getPrimaryBusinessEntity(array("useLegacyImplementation" => true));
385 // Get the patient's name and chart number.
386 $patdata = getPatientData($form_pid, 'fname,mname,lname,pubpid');
388 // Re-fetch payment info.
389 $payrow = sqlQuery("SELECT " .
390 "SUM(amount1) AS amount1, " .
391 "SUM(amount2) AS amount2, " .
392 "MAX(method) AS method, " .
393 "MAX(source) AS source, " .
394 "MAX(dtime) AS dtime, " .
395 // "MAX(user) AS user " .
396 "MAX(user) AS user, " .
397 "MAX(encounter) as encounter ".
398 "FROM payments WHERE " .
399 "pid = ? AND dtime = ?", array($form_pid,$timestamp));
401 // Create key for deleting, just in case.
402 $ref_id = ($_REQUEST['radio_type_of_payment']=='copay') ?
$session_id : $payment_id ;
403 $payment_key = $form_pid . '.' . preg_replace('/[^0-9]/', '', $timestamp).'.'.$ref_id;
405 if ($_REQUEST['radio_type_of_payment'] != 'pre_payment') {
406 // get facility from encounter
407 $tmprow = sqlQuery("SELECT `facility_id` FROM `form_encounter` WHERE `encounter` = ?", array($payrow['encounter']));
408 $frow = $facilityService->getById($tmprow['facility_id']);
410 // if pre_payment, then no encounter yet, so get main office address
411 $frow = $facilityService->getPrimaryBillingLocation();
414 // Now proceed with printing the receipt.
417 <title
><?php
echo xlt('Receipt for Payment'); ?
></title
>
418 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-2-2/index.js"></script
>
419 <script type
="text/javascript" src
="../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script
>
420 <script language
="JavaScript">
422 <?php
require($GLOBALS['srcdir'] . "/restoreSession.php"); ?
>
424 $
(document
).ready(function() {
425 var win
= top
.printLogSetup ? top
: opener
.top
;
426 win
.printLogSetup(document
.getElementById('printbutton'));
429 // This is action to take before printing and is called from restoreSession.php.
430 function printlog_before_print() {
431 var divstyle
= document
.getElementById('hideonprint').style
;
432 divstyle
.display
= 'none';
435 // Process click on Delete button.
436 function deleteme() {
437 dlgopen('deleter.php?payment=<?php echo attr($payment_key); ?>', '_blank', 500, 450);
440 // Called by the deleteme.php window on a successful delete.
441 function imdeleted() {
445 // Called to switch to the specified encounter having the specified DOS.
446 // This also closes the popup window.
447 function toencounter(enc
, datestr
, topframe
) {
448 topframe
.restoreSession();
449 // Hard-coding of RBot for this purpose is awkward, but since this is a
450 // pop-up and our openemr is left_nav, we have no good clue as to whether
451 // the top frame is more appropriate.
452 topframe
.left_nav
.forceDual();
453 topframe
.left_nav
.setEncounter(datestr
, enc
, '');
454 topframe
.left_nav
.loadFrame('enc2', 'RBot', 'patient_file/encounter/encounter_top.php?set_encounter=' + enc
);
460 <body bgcolor
='#ffffff'>
463 <p
><h2
><?php
echo xlt('Receipt for Payment'); ?
></h2
>
465 <p
><?php
echo text($frow['name']) ?
>
466 <br
><?php
echo text($frow['street']) ?
>
467 <br
><?php
echo text($frow['city'] . ', ' . $frow['state']) . ' ' .
468 text($frow['postal_code']) ?
>
469 <br
><?php
echo text($frow['phone']) ?
>
472 <table border
='0' cellspacing
='8'>
474 <td
><?php
echo xlt('Date'); ?
>:</td
>
475 <td
><?php
echo text(oeFormatSDFT(strtotime($payrow['dtime']))) ?
></td
>
478 <td
><?php
echo xlt('Patient'); ?
>:</td
>
479 <td
><?php
echo text($patdata['fname']) . " " . text($patdata['mname']) . " " .
480 text($patdata['lname']) . " (" . text($patdata['pubpid']) . ")" ?
></td
>
483 <td
><?php
echo xlt('Paid Via'); ?
>:</td
>
484 <td
><?php
echo generate_display_field(array('data_type'=>'1','list_id'=>'payment_method'), $payrow['method']); ?
></td
>
487 <td
><?php
echo xlt('Check/Ref Number'); ?
>:</td
>
488 <td
><?php
echo text($payrow['source']) ?
></td
>
491 <td
><?php
echo xlt('Amount for This Visit'); ?
>:</td
>
492 <td
><?php
echo text(oeFormatMoney($payrow['amount1'])) ?
></td
>
497 if ($_REQUEST['radio_type_of_payment']=='pre_payment') {
498 echo xlt('Pre-payment Amount');
500 echo xlt('Amount for Past Balance');
504 <td
><?php
echo text(oeFormatMoney($payrow['amount2'])) ?
></td
>
507 <td
><?php
echo xlt('Received By'); ?
>:</td
>
508 <td
><?php
echo text($payrow['user']) ?
></td
>
512 <div id
='hideonprint'>
514 <input type
='button' value
='<?php echo xla('Print'); ?>' id
='printbutton' />
517 $todaysenc = todaysEncounterIf($pid);
518 if ($todaysenc && $todaysenc != $encounter) {
519 echo " <input type='button' " .
520 "value='" . xla('Open Today`s Visit') . "' " .
521 "onclick='toencounter($todaysenc,\"$today\",opener.top)' />\n";
525 <?php
if (acl_check('admin', 'super')) { ?
>
527 <input type
='button' value
='<?php echo xla('Delete
'); ?>' style
='color:red' onclick
='deleteme()' />
536 // End of receipt printing logic.
540 // Here we display the form for data entry.
543 <title
><?php
echo xlt('Record Payment'); ?
></title
>
545 <style type
="text/css">
546 body
{ font
-family
:sans
-serif
; font
-size
:10pt
; font
-weight
:normal
}
547 .dehead
{ color
:#000000; font-family:sans-serif; font-size:10pt; font-weight:bold }
548 .detail
{ color
:#000000; font-family:sans-serif; font-size:10pt; font-weight:normal }
552 background
-color
: #FBFDD0;
553 border
: 1px solid
#ccc;
558 <link rel
="stylesheet" href
="<?php echo $css_header;?>" type
="text/css">
560 <!-- supporting javascript code
-->
561 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-2-2/index.js"></script
>
563 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js?v=<?php echo $v_js_includes; ?>"></script
>
567 <link rel
="stylesheet" href
="<?php echo $css_header;?>" type
="text/css">
568 <script type
="text/javascript" src
="../../library/textformat.js"></script
>
569 <script type
="text/javascript" src
="../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script
>
570 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-3-2/index.js"></script
>
571 <script type
="text/javascript" src
="../../library/js/common.js"></script
>
572 <script language
='JavaScript'>
575 <?php
include_once("{$GLOBALS['srcdir']}/ajax/payment_ajax_jav.inc.php"); ?
>
576 <script language
="javascript" type
="text/javascript">
577 document
.onclick
=HideTheAjaxDivs
;
580 <script type
="text/javascript" src
="../../library/topdialog.js"></script
>
582 <script language
="JavaScript">
583 <?php
require($GLOBALS['srcdir'] . "/restoreSession.php"); ?
>
585 function calctotal() {
586 var f
= document
.forms
[0];
588 for (var i
= 0; i
< f
.elements
.length
; ++i
) {
589 var elem
= f
.elements
[i
];
590 var ename
= elem
.name
;
591 if (ename
.indexOf('form_upay[') == 0 || ename
.indexOf('form_bpay[') == 0) {
592 if (elem
.value
.length
> 0) total +
= Number(elem
.value
);
595 f
.form_paytotal
.value
= Number(total
).toFixed(2);
600 for (var i
= 1; ; ++i
)
602 if(document
.getElementById('paying_'+i
))
604 paying
=document
.getElementById('paying_'+i
).value
*1;
605 patient_balance
=document
.getElementById('duept_'+i
).innerHTML
*1;
606 //balance=document.getElementById('balance_'+i).innerHTML*1;
607 if(patient_balance
>0 && paying
>0)
609 if(paying
>patient_balance
)
611 document
.getElementById('paying_'+i
).style
.background
='#FF0000';
613 else if(paying
<patient_balance
)
615 document
.getElementById('paying_'+i
).style
.background
='#99CC00';
617 else if(paying
==patient_balance
)
619 document
.getElementById('paying_'+i
).style
.background
='#ffffff';
624 document
.getElementById('paying_'+i
).style
.background
='#ffffff';
633 function CheckVisible(MakeBlank
)
634 {//Displays and hides the check number text box.
635 if(document
.getElementById('form_method').options
[document
.getElementById('form_method').selectedIndex
].value
=='check_payment' ||
636 document
.getElementById('form_method').options
[document
.getElementById('form_method').selectedIndex
].value
=='bank_draft' )
638 document
.getElementById('check_number').disabled
=false;
642 document
.getElementById('check_number').disabled
=true;
647 var f
= document
.forms
[0];
649 top
.restoreSession();
651 if(((document
.getElementById('form_method').options
[document
.getElementById('form_method').selectedIndex
].value
=='check_payment' ||
652 document
.getElementById('form_method').options
[document
.getElementById('form_method').selectedIndex
].value
=='bank_draft') &&
653 document
.getElementById('check_number').value
=='' ))
655 alert("<?php echo addslashes(xl('Please Fill the Check/Ref Number')) ?>");
656 document
.getElementById('check_number').focus();
660 if(document
.getElementById('radio_type_of_payment_self1').checked
==false &&
661 document
.getElementById('radio_type_of_payment1').checked
==false &&
662 document
.getElementById('radio_type_of_payment2').checked
==false &&
663 document
.getElementById('radio_type_of_payment4').checked
==false)
665 alert("<?php echo addslashes(xl('Please Select Type Of Payment.')) ?>");
669 if(document
.getElementById('radio_type_of_payment_self1').checked
==true ||
670 document
.getElementById('radio_type_of_payment1').checked
==true)
672 for (var i
= 0; i
< f
.elements
.length
; ++i
)
674 var elem
= f
.elements
[i
];
675 var ename
= elem
.name
;
676 if (ename
.indexOf('form_upay[0') == 0) //Today is this text box.
679 {//A warning message, if the amount is posted with out encounter.
680 if(confirm("<?php echo addslashes(xlt('If patient has appointment click OK to create encounter otherwise, cancel and create encounter.')) ?>"))
695 if(document
.getElementById('radio_type_of_payment1').checked
==true)//CO-PAY
698 for (var i
= 0; i
< f
.elements
.length
; ++i
)
700 var elem
= f
.elements
[i
];
701 var ename
= elem
.name
;
702 if (ename
.indexOf('form_upay[0') == 0) //Today is this text box.
704 if(f
.form_paytotal
.value
*1!=elem
.value
*1)//Total CO-PAY is not posted against today
705 {//A warning message, if the amount is posted against an old encounter.
706 if(confirm("<?php echo addslashes(xl('You are posting against an old encounter?')) ?>"))
720 else if(document
.getElementById('radio_type_of_payment2').checked
==true)//Invoice Balance
722 for (var i
= 0; i
< f
.elements
.length
; ++i
)
724 var elem
= f
.elements
[i
];
725 var ename
= elem
.name
;
726 if (ename
.indexOf('form_upay[0') == 0)
728 if (elem
.value
*1 > 0)
730 alert("<?php echo addslashes(xl('Invoice Balance cannot be posted. No Encounter is created.')) ?>");
739 if(confirm("<?php echo addslashes(xl('Would you like to save?')) ?>"))
749 function cursor_pointer()
750 {//Point the cursor to the latest encounter(Today)
751 var f
= document
.forms
[0];
753 for (var i
= 0; i
< f
.elements
.length
; ++i
)
755 var elem
= f
.elements
[i
];
756 var ename
= elem
.name
;
757 if (ename
.indexOf('form_upay[') == 0)
764 //=====================================================
765 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
)
773 var td_inspaid_elem
= document
.getElementById('td_inspaid_'+i
)
774 var td_patient_copay_elem
= document
.getElementById('td_patient_copay_'+i
)
775 var td_copay_elem
= document
.getElementById('td_copay_'+i
)
776 var balance_elem
= document
.getElementById('balance_'+i
)
779 td_inspaid_elem
.style
.display
="none";
780 td_patient_copay_elem
.style
.display
="none";
781 td_copay_elem
.style
.display
="none";
782 balance_elem
.style
.display
="none";
789 document
.getElementById('td_total_4').style
.display
="none";
790 document
.getElementById('td_total_7').style
.display
="none";
791 document
.getElementById('td_total_8').style
.display
="none";
792 document
.getElementById('td_total_6').style
.display
="none";
794 document
.getElementById('table_display').width
="420px";
797 //=====================================================
798 function make_visible()
800 document
.getElementById('td_head_rep_doc').style
.display
="";
801 document
.getElementById('td_head_description').style
.display
="";
802 document
.getElementById('td_head_total_charge').style
.display
="none";
803 document
.getElementById('td_head_insurance_payment').style
.display
="none";
804 document
.getElementById('td_head_patient_payment').style
.display
="none";
805 document
.getElementById('td_head_patient_co_pay').style
.display
="none";
806 document
.getElementById('td_head_co_pay').style
.display
="none";
807 document
.getElementById('td_head_insurance_balance').style
.display
="none";
808 document
.getElementById('td_head_patient_balance').style
.display
="none";
809 for (var i
= 1; ; ++i
)
811 var td_charges_elem
= document
.getElementById('td_charges_'+i
)
812 var td_inspaid_elem
= document
.getElementById('td_inspaid_'+i
)
813 var td_ptpaid_elem
= document
.getElementById('td_ptpaid_'+i
)
814 var td_patient_copay_elem
= document
.getElementById('td_patient_copay_'+i
)
815 var td_copay_elem
= document
.getElementById('td_copay_'+i
)
816 var balance_elem
= document
.getElementById('balance_'+i
)
817 var duept_elem
= document
.getElementById('duept_'+i
)
820 td_charges_elem
.style
.display
="none";
821 td_inspaid_elem
.style
.display
="none";
822 td_ptpaid_elem
.style
.display
="none";
823 td_patient_copay_elem
.style
.display
="none";
824 td_copay_elem
.style
.display
="none";
825 balance_elem
.style
.display
="none";
826 duept_elem
.style
.display
="none";
833 document
.getElementById('td_total_7').style
.display
="";
834 document
.getElementById('td_total_8').style
.display
="";
835 document
.getElementById('td_total_1').style
.display
="none";
836 document
.getElementById('td_total_2').style
.display
="none";
837 document
.getElementById('td_total_3').style
.display
="none";
838 document
.getElementById('td_total_4').style
.display
="none";
839 document
.getElementById('td_total_5').style
.display
="none";
840 document
.getElementById('td_total_6').style
.display
="none";
842 document
.getElementById('table_display').width
="505px";
844 function make_it_hide()
846 document
.getElementById('td_head_rep_doc').style
.display
="none";
847 document
.getElementById('td_head_description').style
.display
="none";
848 document
.getElementById('td_head_total_charge').style
.display
="";
849 document
.getElementById('td_head_insurance_payment').style
.display
="";
850 document
.getElementById('td_head_patient_payment').style
.display
="";
851 document
.getElementById('td_head_patient_co_pay').style
.display
="";
852 document
.getElementById('td_head_co_pay').style
.display
="";
853 document
.getElementById('td_head_insurance_balance').style
.display
="";
854 document
.getElementById('td_head_patient_balance').style
.display
="";
855 for (var i
= 1; ; ++i
)
857 var td_charges_elem
= document
.getElementById('td_charges_'+i
)
858 var td_inspaid_elem
= document
.getElementById('td_inspaid_'+i
)
859 var td_ptpaid_elem
= document
.getElementById('td_ptpaid_'+i
)
860 var td_patient_copay_elem
= document
.getElementById('td_patient_copay_'+i
)
861 var td_copay_elem
= document
.getElementById('td_copay_'+i
)
862 var balance_elem
= document
.getElementById('balance_'+i
)
863 var duept_elem
= document
.getElementById('duept_'+i
)
866 td_charges_elem
.style
.display
="";
867 td_inspaid_elem
.style
.display
="";
868 td_ptpaid_elem
.style
.display
="";
869 td_patient_copay_elem
.style
.display
="";
870 td_copay_elem
.style
.display
="";
871 balance_elem
.style
.display
="";
872 duept_elem
.style
.display
="";
879 document
.getElementById('td_total_1').style
.display
="";
880 document
.getElementById('td_total_2').style
.display
="";
881 document
.getElementById('td_total_3').style
.display
="";
882 document
.getElementById('td_total_4').style
.display
="";
883 document
.getElementById('td_total_5').style
.display
="";
884 document
.getElementById('td_total_6').style
.display
="";
885 document
.getElementById('td_total_7').style
.display
="";
886 document
.getElementById('td_total_8').style
.display
="";
888 document
.getElementById('table_display').width
="635px";
890 function make_visible_radio()
892 document
.getElementById('tr_radio1').style
.display
="";
893 document
.getElementById('tr_radio2').style
.display
="none";
895 function make_hide_radio()
897 document
.getElementById('tr_radio1').style
.display
="none";
898 document
.getElementById('tr_radio2').style
.display
="";
900 function make_visible_row()
902 document
.getElementById('table_display').style
.display
="";
903 document
.getElementById('table_display_prepayment').style
.display
="none";
905 function make_hide_row()
907 document
.getElementById('table_display').style
.display
="none";
908 document
.getElementById('table_display_prepayment').style
.display
="";
914 make_it_hide_enc_pay();
915 document
.getElementById('radio_type_of_payment_self1').checked
=true;
918 function make_insurance()
923 document
.getElementById('radio_type_of_payment1').checked
=true;
929 <body
class="body_top" onunload
='imclosing()' onLoad
="cursor_pointer();">
932 <form method
='post' action
='front_payment.php<?php echo ($payid) ? "?payid=".attr($payid) : ""; ?>'
933 onsubmit
='return validate();'>
934 <input type
='hidden' name
='form_pid' value
='<?php echo attr($pid) ?>' />
937 <table border
='0' cellspacing
='0' cellpadding
="0">
940 <td colspan
="3"> 
;</td
>
944 <td colspan
='3' align
='center' class='text' >
945 <b
><?php
echo htmlspecialchars(xl('Accept Payment for'), ENT_QUOTES
); ?
> 
;: 
; 
;<?php
echo htmlspecialchars($patdata['fname'], ENT_QUOTES
) . " " .
946 htmlspecialchars($patdata['lname'], ENT_QUOTES
) . " " .htmlspecialchars($patdata['mname'], ENT_QUOTES
). " (" . htmlspecialchars($patdata['pid'], ENT_QUOTES
) . ")" ?
></b
>
947 <?php
$NameNew=$patdata['fname'] . " " .$patdata['lname']. " " .$patdata['mname'];?
>
951 <tr height
="15"><td colspan
='3'></td
></tr
>
956 <?php
echo xlt('Payment Method'); ?
>:
959 <select name
="form_method" id
="form_method" class="text" onChange
='CheckVisible("yes")'>
961 $query1112 = "SELECT * FROM list_options where list_id=? ORDER BY seq, title ";
962 $bres1112 = sqlStatement($query1112, array('payment_method'));
963 while ($brow1112 = sqlFetchArray($bres1112)) {
964 if ($brow1112['option_id']=='electronic' ||
$brow1112['option_id']=='bank_draft') {
968 echo "<option value='".htmlspecialchars($brow1112['option_id'], ENT_QUOTES
)."'>".htmlspecialchars(xl_list_label($brow1112['title']), ENT_QUOTES
)."</option>";
975 <tr height
="5"><td colspan
='3'></td
></tr
>
979 <?php
echo xla('Check/Ref Number'); ?
>:
981 <td colspan
='2' ><div id
="ajax_div_patient" style
="display:none;"></div
>
982 <input type
='text' id
="check_number" name
='form_source' style
="width:120px" value
='<?php echo htmlspecialchars($payrow['source
'], ENT_QUOTES); ?>'>
985 <tr height
="5"><td colspan
='3'></td
></tr
>
988 <td
class='text' valign
="middle" >
989 <?php
echo htmlspecialchars(xl('Patient Coverage'), ENT_QUOTES
); ?
>:
991 <td
class='text' colspan
="2" ><input type
="radio" name
="radio_type_of_coverage" id
="radio_type_of_coverage1" value
="self" onClick
="make_visible_radio();make_self();"/><?php
echo htmlspecialchars(xl('Self'), ENT_QUOTES
); ?
><input type
="radio" name
="radio_type_of_coverage" id
="radio_type_of_coverag2" value
="insurance" checked
="checked" onClick
="make_hide_radio();make_insurance();"/><?php
echo htmlspecialchars(xl('Insurance'), ENT_QUOTES
); ?
> </td
>
994 <tr height
="5"><td colspan
='3'></td
></tr
>
996 <tr id
="tr_radio1" style
="display:none"><!-- For radio Insurance
-->
997 <td
class='text' valign
="top" >
998 <?php
echo htmlspecialchars(xl('Payment against'), ENT_QUOTES
); ?
>:
1000 <td
class='text' colspan
="2" ><input type
="radio" name
="radio_type_of_payment" id
="radio_type_of_payment_self1" value
="cash" onClick
="make_visible_row();make_it_hide_enc_pay();cursor_pointer();"/><?php
echo htmlspecialchars(xl('Encounter Payment'), ENT_QUOTES
); ?
></td
>
1002 <tr id
="tr_radio2"><!-- For radio self
-->
1003 <td
class='text' valign
="top" >
1004 <?php
echo htmlspecialchars(xl('Payment against'), ENT_QUOTES
); ?
>:
1006 <td
class='text' colspan
="2" ><input type
="radio" name
="radio_type_of_payment" id
="radio_type_of_payment1" value
="copay" checked
="checked" onClick
="make_visible_row();cursor_pointer();"/><?php
echo htmlspecialchars(xl('Co Pay'), ENT_QUOTES
); ?
><input type
="radio" name
="radio_type_of_payment" id
="radio_type_of_payment2" value
="invoice_balance" onClick
="make_visible_row();"/><?php
echo htmlspecialchars(xl('Invoice Balance'), ENT_QUOTES
); ?
><br
/><input type
="radio" name
="radio_type_of_payment" id
="radio_type_of_payment4" value
="pre_payment" onClick
="make_hide_row();"/><?php
echo htmlspecialchars(xl('Pre Pay'), ENT_QUOTES
); ?
></td
>
1009 <tr height
="15"><td colspan
='3'></td
></tr
>
1012 <table width
="200" border
="0" cellspacing
="0" cellpadding
="0" id
="table_display_prepayment" style
="display:none">
1014 <td
class='detail'><?php
echo htmlspecialchars(xl('Pre Payment'), ENT_QUOTES
); ?
></td
>
1015 <td
><input type
='text' name
='form_prepayment' style
='width:100px' /></td
>
1019 <table border
='0' id
="table_display" cellpadding
='0' cellspacing
='0' width
='635'>
1020 <tr bgcolor
="#cccccc" id
="tr_head">
1021 <td
class="dehead" width
="70">
1022 <?php
echo htmlspecialchars(xl('DOS'), ENT_QUOTES
) ?
>
1024 <td
class="dehead" width
="65">
1025 <?php
echo htmlspecialchars(xl('Encounter'), ENT_QUOTES
) ?
>
1027 <td
class="dehead" align
="center" width
="80" id
="td_head_total_charge" >
1028 <?php
echo htmlspecialchars(xl('Total Charge'), ENT_QUOTES
) ?
>
1030 <td
class="dehead" align
="center" width
="70" id
="td_head_rep_doc" style
='display:none'>
1031 <?php
echo htmlspecialchars(xl('Report/ Form'), ENT_QUOTES
) ?
>
1033 <td
class="dehead" align
="center" width
="200" id
="td_head_description" style
='display:none'>
1034 <?php
echo htmlspecialchars(xl('Description'), ENT_QUOTES
) ?
>
1036 <td
class="dehead" align
="center" width
="80" id
="td_head_insurance_payment" >
1037 <?php
echo htmlspecialchars(xl('Insurance Payment'), ENT_QUOTES
) ?
>
1039 <td
class="dehead" align
="center" width
="80" id
="td_head_patient_payment" >
1040 <?php
echo htmlspecialchars(xl('Patient Payment'), ENT_QUOTES
) ?
>
1042 <td
class="dehead" align
="center" width
="55" id
="td_head_patient_co_pay" >
1043 <?php
echo htmlspecialchars(xl('Co Pay Paid'), ENT_QUOTES
) ?
>
1045 <td
class="dehead" align
="center" width
="55" id
="td_head_co_pay" >
1046 <?php
echo htmlspecialchars(xl('Required Co Pay'), ENT_QUOTES
) ?
>
1048 <td
class="dehead" align
="center" width
="80" id
="td_head_insurance_balance" >
1049 <?php
echo htmlspecialchars(xl('Insurance Balance'), ENT_QUOTES
) ?
>
1051 <td
class="dehead" align
="center" width
="80" id
="td_head_patient_balance" >
1052 <?php
echo htmlspecialchars(xl('Patient Balance'), ENT_QUOTES
) ?
>
1054 <td
class="dehead" align
="center" width
="50">
1055 <?php
echo htmlspecialchars(xl('Paying'), ENT_QUOTES
) ?
>
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'];
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");
1165 //------------------------------------------------------------------------------------
1166 $inscopay = getCopay($pid, $dispdate);
1167 $patcopay = getPatientCopay($pid, $enc);
1171 "SELECT SUM(pay_amount) AS payments, " .
1172 "SUM(adj_amount) AS adjustments FROM ar_activity WHERE " .
1173 "pid = ? and encounter = ? and " .
1174 "payer_type != 0 and account_code!='PCP' ",
1177 $dpayment=$drow['payments'];
1178 $dadjustment=$drow['adjustments'];
1182 "SELECT SUM(pay_amount) AS payments, " .
1183 "SUM(adj_amount) AS adjustments FROM ar_activity WHERE " .
1184 "pid = ? and encounter = ? and " .
1185 "payer_type = 0 and account_code!='PCP' ",
1188 $dpayment_pat=$drow['payments'];
1190 //------------------------------------------------------------------------------------
1192 $ResultNumberOfInsurance = sqlStatement("SELECT COUNT( DISTINCT TYPE ) NumberOfInsurance FROM insurance_data
1193 where pid = ? and provider>0 ", array($pid));
1194 $RowNumberOfInsurance = sqlFetchArray($ResultNumberOfInsurance);
1195 $NumberOfInsurance=$RowNumberOfInsurance['NumberOfInsurance']*1;
1196 //------------------------------------------------------------------------------------
1198 if ((($NumberOfInsurance==0 ||
$value['last_level_closed']==4 ||
$NumberOfInsurance== $value['last_level_closed']))) {//Patient balance
1199 $brow = sqlQuery("SELECT SUM(fee) AS amount FROM billing WHERE " .
1200 "pid = ? and encounter = ? AND activity = 1", array($pid,$enc));
1201 $srow = sqlQuery("SELECT SUM(fee) AS amount FROM drug_sales WHERE " .
1202 "pid = ? and encounter = ? ", array($pid,$enc));
1203 $drow = sqlQuery("SELECT SUM(pay_amount) AS payments, " .
1204 "SUM(adj_amount) AS adjustments FROM ar_activity WHERE " .
1205 "pid = ? and encounter = ? ", array($pid,$enc));
1206 $duept= $brow['amount'] +
$srow['amount'] - $drow['payments'] - $drow['adjustments'];
1214 ($dpayment +
$dadjustment),
1224 // Continue with display of the data entry form.
1227 <tr bgcolor
="#cccccc">
1228 <td
class="dehead" id
='td_total_1'></td
>
1229 <td
class="dehead" id
='td_total_2'></td
>
1230 <td
class="dehead" id
='td_total_3'></td
>
1231 <td
class="dehead" id
='td_total_4'></td
>
1232 <td
class="dehead" id
='td_total_5'></td
>
1233 <td
class="dehead" id
='td_total_6'></td
>
1234 <td
class="dehead" id
='td_total_7'></td
>
1235 <td
class="dehead" id
='td_total_8'></td
>
1236 <td
class="dehead" align
="right">
1237 <?php
echo htmlspecialchars(xl('Total'), ENT_QUOTES
);?
>
1239 <td
class="dehead" align
="right">
1240 <input type
='text' name
='form_paytotal' value
=''
1241 style
='color:#00aa00;width:50px' readonly
/>
1248 <input type
='submit' name
='form_save' value
='<?php echo htmlspecialchars(xl('Generate Invoice
'), ENT_QUOTES);?>' />  
;
1249 <input type
='button' value
='<?php echo xla('Cancel
'); ?>' onclick
='dlgclose()' />
1251 <input type
="hidden" name
="hidden_patient_code" id
="hidden_patient_code" value
="<?php echo attr($pid);?>"/>
1252 <input type
='hidden' name
='ajax_mode' id
='ajax_mode' value
='' />
1253 <input type
='hidden' name
='mode' id
='mode' value
='' />
1255 <script language
="JavaScript">