2 // Copyright (C) 2006-2016 Rod Roark <rod@sunsetsystems.com>
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
12 require_once("../globals.php");
13 require_once("$srcdir/acl.inc");
14 require_once("$srcdir/patient.inc");
15 require_once("$srcdir/billing.inc");
16 require_once("$srcdir/payment.inc.php");
17 require_once("$srcdir/forms.inc");
18 require_once("$srcdir/sl_eob.inc.php");
19 require_once("$srcdir/invoice_summary.inc.php");
20 require_once("../../custom/code_types.inc.php");
21 require_once("$srcdir/options.inc.php");
22 require_once("$srcdir/encounter_events.inc.php");
23 $pid = $_REQUEST['hidden_patient_code'] > 0 ?
$_REQUEST['hidden_patient_code'] : $pid;
25 $facilityService = new \services\
FacilityService();
30 <?php
html_header_show();?
>
31 <script type
="text/javascript" src
="<?php echo $webroot ?>/interface/main/tabs/js/include_opener.js"></script
>
32 <link rel
='stylesheet' href
='<?php echo $css_header ?>' type
='text/css'>
34 // Format dollars for display.
36 function bucks($amount)
39 $amount = oeFormatMoney($amount);
46 function rawbucks($amount)
49 $amount = sprintf("%.2f", $amount);
56 // Display a row of data for an encounter.
59 function echoLine($iname, $date, $charges, $ptpaid, $inspaid, $duept, $encounter = 0, $copay = 0, $patcopay = 0)
63 $balance = bucks($charges - $ptpaid - $inspaid);
64 $balance = (round($duept, 2) != 0) ?
0 : $balance;//if balance is due from patient, then insurance balance is displayed as zero
65 $encounter = $encounter ?
$encounter : '';
66 echo " <tr id='tr_".attr($var_index)."' >\n";
67 echo " <td class='detail'>" . text(oeFormatShortDate($date)) . "</td>\n";
68 echo " <td class='detail' id='".attr($date)."' align='center'>" . htmlspecialchars($encounter, ENT_QUOTES
) . "</td>\n";
69 echo " <td class='detail' align='center' id='td_charges_$var_index' >" . htmlspecialchars(bucks($charges), ENT_QUOTES
) . "</td>\n";
70 echo " <td class='detail' align='center' id='td_inspaid_$var_index' >" . htmlspecialchars(bucks($inspaid*-1), ENT_QUOTES
) . "</td>\n";
71 echo " <td class='detail' align='center' id='td_ptpaid_$var_index' >" . htmlspecialchars(bucks($ptpaid*-1), ENT_QUOTES
) . "</td>\n";
72 echo " <td class='detail' align='center' id='td_patient_copay_$var_index' >" . htmlspecialchars(bucks($patcopay), ENT_QUOTES
) . "</td>\n";
73 echo " <td class='detail' align='center' id='td_copay_$var_index' >" . htmlspecialchars(bucks($copay), ENT_QUOTES
) . "</td>\n";
74 echo " <td class='detail' align='center' id='balance_$var_index'>" . htmlspecialchars(bucks($balance), ENT_QUOTES
) . "</td>\n";
75 echo " <td class='detail' align='center' id='duept_$var_index'>" . htmlspecialchars(bucks(round($duept, 2)*1), ENT_QUOTES
) . "</td>\n";
76 echo " <td class='detail' align='right'><input type='text' name='".attr($iname)."' id='paying_".attr($var_index)."' " .
77 " value='" . '' . "' onchange='coloring();calctotal()' autocomplete='off' " .
78 "onkeyup='calctotal()' style='width:50px'/></td>\n";
82 // We use this to put dashes, colons, etc. back into a timestamp.
84 function decorateString($fmt, $str)
88 $fc = substr($fmt, 0, 1);
89 $fmt = substr($fmt, 1);
91 $res .= substr($str, 0, 1);
92 $str = substr($str, 1);
101 // Compute taxes from a tax rate string and a possibly taxable amount.
103 function calcTaxes($row, $amount)
106 if (empty($row['taxrates'])) {
110 $arates = explode(':', $row['taxrates']);
111 if (empty($arates)) {
115 foreach ($arates as $value) {
120 $trow = sqlQuery("SELECT option_value FROM list_options WHERE " .
121 "list_id = 'taxrate' AND option_id = ? AND activity = 1 LIMIT 1", array($value));
122 if (empty($trow['option_value'])) {
123 echo "<!-- Missing tax rate '".text($value)."'! -->\n";
127 $tax = sprintf("%01.2f", $amount * $trow['option_value']);
128 // echo "<!-- Rate = '$value', amount = '$amount', tax = '$tax' -->\n";
136 $today = date('Y-m-d', $now);
137 $timestamp = date('Y-m-d H:i:s', $now);
140 // $patdata = getPatientData($pid, 'fname,lname,pubpid');
142 $patdata = sqlQuery("SELECT " .
143 "p.fname, p.mname, p.lname, p.pubpid,p.pid, i.copay " .
144 "FROM patient_data AS p " .
145 "LEFT OUTER JOIN insurance_data AS i ON " .
146 "i.pid = p.pid AND i.type = 'primary' " .
147 "WHERE p.pid = ? ORDER BY i.date DESC LIMIT 1", array($pid));
149 $alertmsg = ''; // anything here pops up in an alert box
151 // If the Save button was clicked...
152 if ($_POST['form_save']) {
153 $form_pid = $_POST['form_pid'];
154 $form_method = trim($_POST['form_method']);
155 $form_source = trim($_POST['form_source']);
156 $patdata = getPatientData($form_pid, 'fname,mname,lname,pubpid');
157 $NameNew=$patdata['fname'] . " " .$patdata['lname']. " " .$patdata['mname'];
159 if ($_REQUEST['radio_type_of_payment']=='pre_payment') {
160 $payment_id = idSqlStatement(
161 "insert into ar_session set " .
167 ", check_date = now() , deposit_date = now() " .
169 ", payment_type = 'patient'" .
170 ", description = ?" .
171 ", adjustment_code = 'pre_payment'" .
172 ", post_to_date = now() " .
173 ", payment_method = ?",
174 array(0,$form_pid,$_SESSION['authUserID'],0,$form_source,$_REQUEST['form_prepayment'],$NameNew,$form_method)
177 frontPayment($form_pid, 0, $form_method, $form_source, $_REQUEST['form_prepayment'], 0, $timestamp);//insertion to 'payments' table.
180 if ($_POST['form_upay'] && $_REQUEST['radio_type_of_payment']!='pre_payment') {
181 foreach ($_POST['form_upay'] as $enc => $payment) {
182 if ($amount = 0 +
$payment) {
184 if ($_REQUEST['radio_type_of_payment']=='invoice_balance') {
188 $enc = calendar_arrived($form_pid);
192 //----------------------------------------------------------------------------------------------------
193 //Fetching the existing code and modifier
194 $ResultSearchNew = sqlStatement(
195 "SELECT * FROM billing LEFT JOIN code_types ON billing.code_type=code_types.ct_key ".
196 "WHERE code_types.ct_fee=1 AND billing.activity!=0 AND billing.pid =? AND encounter=? ORDER BY billing.code,billing.modifier",
197 array($form_pid,$enc)
199 if ($RowSearch = sqlFetchArray($ResultSearchNew)) {
200 $Codetype=$RowSearch['code_type'];
201 $Code=$RowSearch['code'];
202 $Modifier=$RowSearch['modifier'];
209 //----------------------------------------------------------------------------------------------------
210 if ($_REQUEST['radio_type_of_payment']=='copay') {//copay saving to ar_session and ar_activity tables
211 $session_id=sqlInsert(
212 "INSERT INTO ar_session (payer_id,user_id,reference,check_date,deposit_date,pay_total,".
213 " global_amount,payment_type,description,patient_id,payment_method,adjustment_code,post_to_date) ".
214 " VALUES ('0',?,?,now(),now(),?,'','patient','COPAY',?,?,'patient_payment',now())",
215 array($_SESSION['authId'],$form_source,$amount,$form_pid,$form_method)
219 $sequence_no = sqlQuery("SELECT IFNULL(MAX(sequence_no),0) + 1 AS increment FROM ar_activity WHERE pid = ? AND encounter = ?", array($form_pid, $enc));
221 "INSERT INTO ar_activity (pid,encounter,sequence_no,code_type,code,modifier,payer_type,post_time,post_user,session_id,pay_amount,account_code)".
222 " VALUES (?,?,?,?,?,?,0,now(),?,?,?,'PCP')",
223 array($form_pid,$enc,$sequence_no['increment'],$Codetype,$Code,$Modifier,$_SESSION['authId'],$session_id,$amount)
227 frontPayment($form_pid, $enc, $form_method, $form_source, $amount, 0, $timestamp);//insertion to 'payments' table.
230 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.
231 if ($_REQUEST['radio_type_of_payment']=='cash') {
233 "update form_encounter set last_level_closed=? where encounter=? and pid=? ",
234 array(4,$enc,$form_pid)
237 "update billing set billed=? where encounter=? and pid=?",
238 array(1,$enc,$form_pid)
242 $adjustment_code='patient_payment';
243 $payment_id = idSqlStatement(
244 "insert into ar_session set " .
250 ", check_date = now() , deposit_date = now() " .
252 ", payment_type = 'patient'" .
253 ", description = ?" .
254 ", adjustment_code = ?" .
255 ", post_to_date = now() " .
256 ", payment_method = ?",
257 array(0,$form_pid,$_SESSION['authUserID'],0,$form_source,$amount,$NameNew,$adjustment_code,$form_method)
260 //--------------------------------------------------------------------------------------------------------------------
262 frontPayment($form_pid, $enc, $form_method, $form_source, 0, $amount, $timestamp);//insertion to 'payments' table.
264 //--------------------------------------------------------------------------------------------------------------------
266 $resMoneyGot = sqlStatement(
267 "SELECT sum(pay_amount) as PatientPay FROM ar_activity where pid =? and ".
268 "encounter =? and payer_type=0 and account_code='PCP'",
269 array($form_pid,$enc)
270 );//new fees screen copay gives account_code='PCP'
271 $rowMoneyGot = sqlFetchArray($resMoneyGot);
272 $Copay=$rowMoneyGot['PatientPay'];
274 //--------------------------------------------------------------------------------------------------------------------
276 //Looping the existing code and modifier
277 $ResultSearchNew = sqlStatement(
278 "SELECT * FROM billing LEFT JOIN code_types ON billing.code_type=code_types.ct_key WHERE code_types.ct_fee=1 ".
279 "AND billing.activity!=0 AND billing.pid =? AND encounter=? ORDER BY billing.code,billing.modifier",
280 array($form_pid,$enc)
282 while ($RowSearch = sqlFetchArray($ResultSearchNew)) {
283 $Codetype=$RowSearch['code_type'];
284 $Code=$RowSearch['code'];
285 $Modifier =$RowSearch['modifier'];
286 $Fee =$RowSearch['fee'];
288 $resMoneyGot = sqlStatement(
289 "SELECT sum(pay_amount) as MoneyGot FROM ar_activity where pid =? ".
290 "and code_type=? and code=? and modifier=? and encounter =? and !(payer_type=0 and account_code='PCP')",
291 array($form_pid,$Codetype,$Code,$Modifier,$enc)
293 //new fees screen copay gives account_code='PCP'
294 $rowMoneyGot = sqlFetchArray($resMoneyGot);
295 $MoneyGot=$rowMoneyGot['MoneyGot'];
297 $resMoneyAdjusted = sqlStatement(
298 "SELECT sum(adj_amount) as MoneyAdjusted FROM ar_activity where ".
299 "pid =? and code_type=? and code=? and modifier=? and encounter =?",
300 array($form_pid,$Codetype,$Code,$Modifier,$enc)
302 $rowMoneyAdjusted = sqlFetchArray($resMoneyAdjusted);
303 $MoneyAdjusted=$rowMoneyAdjusted['MoneyAdjusted'];
305 $Remainder=$Fee-$Copay-$MoneyGot-$MoneyAdjusted;
307 if (round($Remainder, 2)!=0 && $amount!=0) {
308 if ($amount-$Remainder >= 0) {
309 $insert_value=$Remainder;
310 $amount=$amount-$Remainder;
312 $insert_value=$amount;
317 $sequence_no = sqlQuery("SELECT IFNULL(MAX(sequence_no),0) + 1 AS increment FROM ar_activity WHERE pid = ? AND encounter = ?", array($form_pid, $enc));
319 "insert into ar_activity set " .
322 ", sequence_no = ?" .
327 ", post_time = now() " .
332 ", account_code = 'PP'",
333 array($form_pid,$enc,$sequence_no['increment'],$Codetype,$Code,$Modifier,0,$_SESSION['authUserID'],$payment_id,$insert_value,0)
338 if ($amount!=0) {//if any excess is there.
340 $sequence_no = sqlQuery("SELECT IFNULL(MAX(sequence_no),0) + 1 AS increment FROM ar_activity WHERE pid = ? AND encounter = ?", array($form_pid, $enc));
342 "insert into ar_activity set " .
345 ", sequence_no = ?" .
350 ", post_time = now() " .
355 ", account_code = 'PP'",
356 array($form_pid,$enc,$sequence_no['increment'],$Codetype,$Code,$Modifier,0,$_SESSION['authUserID'],$payment_id,$amount,0)
361 //--------------------------------------------------------------------------------------------------------------------
363 }//if ($amount = 0 + $payment)
365 }//if ($_POST['form_upay'])
366 }//if ($_POST['form_save'])
368 if ($_POST['form_save'] ||
$_REQUEST['receipt']) {
369 if ($_REQUEST['receipt']) {
370 $form_pid = $_GET['patient'];
371 $timestamp = decorateString('....-..-.. ..:..:..', $_GET['time']);
374 // Get details for what we guess is the primary facility.
375 $frow = $facilityService->getPrimaryBusinessEntity(array("useLegacyImplementation" => true));
377 // Get the patient's name and chart number.
378 $patdata = getPatientData($form_pid, 'fname,mname,lname,pubpid');
380 // Re-fetch payment info.
381 $payrow = sqlQuery("SELECT " .
382 "SUM(amount1) AS amount1, " .
383 "SUM(amount2) AS amount2, " .
384 "MAX(method) AS method, " .
385 "MAX(source) AS source, " .
386 "MAX(dtime) AS dtime, " .
387 // "MAX(user) AS user " .
388 "MAX(user) AS user, " .
389 "MAX(encounter) as encounter ".
390 "FROM payments WHERE " .
391 "pid = ? AND dtime = ?", array($form_pid,$timestamp));
393 // Create key for deleting, just in case.
394 $ref_id = ($_REQUEST['radio_type_of_payment']=='copay') ?
$session_id : $payment_id ;
395 $payment_key = $form_pid . '.' . preg_replace('/[^0-9]/', '', $timestamp).'.'.$ref_id;
397 // get facility from encounter
401 WHERE encounter = ?", array($payrow['encounter']));
402 $frow = $facilityService->getById($tmprow['facility_id']);
404 // Now proceed with printing the receipt.
407 <title
><?php
echo xlt('Receipt for Payment'); ?
></title
>
408 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-2-2/index.js"></script
>
409 <script type
="text/javascript" src
="../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script
>
410 <script language
="JavaScript">
412 <?php
require($GLOBALS['srcdir'] . "/restoreSession.php"); ?
>
414 $
(document
).ready(function() {
415 var win
= top
.printLogSetup ? top
: opener
.top
;
416 win
.printLogSetup(document
.getElementById('printbutton'));
419 // This is action to take before printing and is called from restoreSession.php.
420 function printlog_before_print() {
421 var divstyle
= document
.getElementById('hideonprint').style
;
422 divstyle
.display
= 'none';
425 // Process click on Delete button.
426 function deleteme() {
427 dlgopen('deleter.php?payment=<?php echo $payment_key ?>', '_blank', 500, 450);
430 // Called by the deleteme.php window on a successful delete.
431 function imdeleted() {
435 // Called to switch to the specified encounter having the specified DOS.
436 // This also closes the popup window.
437 function toencounter(enc
, datestr
, topframe
) {
438 topframe
.restoreSession();
439 // Hard-coding of RBot for this purpose is awkward, but since this is a
440 // pop-up and our openemr is left_nav, we have no good clue as to whether
441 // the top frame is more appropriate.
442 topframe
.left_nav
.forceDual();
443 topframe
.left_nav
.setEncounter(datestr
, enc
, '');
444 topframe
.left_nav
.loadFrame('enc2', 'RBot', 'patient_file/encounter/encounter_top.php?set_encounter=' + enc
);
450 <body bgcolor
='#ffffff'>
453 <p
><h2
><?php
echo xlt('Receipt for Payment'); ?
></h2
>
455 <p
><?php
echo text($frow['name']) ?
>
456 <br
><?php
echo text($frow['street']) ?
>
457 <br
><?php
echo text($frow['city'] . ', ' . $frow['state']) . ' ' .
458 text($frow['postal_code']) ?
>
459 <br
><?php
echo htmlentities($frow['phone']) ?
>
462 <table border
='0' cellspacing
='8'>
464 <td
><?php
echo xlt('Date'); ?
>:</td
>
465 <td
><?php
echo text(oeFormatSDFT(strtotime($payrow['dtime']))) ?
></td
>
468 <td
><?php
echo xlt('Patient'); ?
>:</td
>
469 <td
><?php
echo text($patdata['fname']) . " " . text($patdata['mname']) . " " .
470 text($patdata['lname']) . " (" . text($patdata['pubpid']) . ")" ?
></td
>
473 <td
><?php
echo xlt('Paid Via'); ?
>:</td
>
474 <td
><?php
echo generate_display_field(array('data_type'=>'1','list_id'=>'payment_method'), $payrow['method']); ?
></td
>
477 <td
><?php
echo xlt('Check/Ref Number'); ?
>:</td
>
478 <td
><?php
echo text($payrow['source']) ?
></td
>
481 <td
><?php
echo xlt('Amount for This Visit'); ?
>:</td
>
482 <td
><?php
echo text(oeFormatMoney($payrow['amount1'])) ?
></td
>
485 <td
><?php
echo xlt('Amount for Past Balance'); ?
>:</td
>
486 <td
><?php
echo text(oeFormatMoney($payrow['amount2'])) ?
></td
>
489 <td
><?php
echo xlt('Received By'); ?
>:</td
>
490 <td
><?php
echo text($payrow['user']) ?
></td
>
494 <div id
='hideonprint'>
496 <input type
='button' value
='<?php echo xla('Print'); ?>' id
='printbutton' />
499 $todaysenc = todaysEncounterIf($pid);
500 if ($todaysenc && $todaysenc != $encounter) {
501 echo " <input type='button' " .
502 "value='" . xla('Open Today`s Visit') . "' " .
503 "onclick='toencounter($todaysenc,\"$today\",opener.top)' />\n";
507 <?php
if (acl_check('admin', 'super')) { ?
>
509 <input type
='button' value
='<?php xl('Delete
', 'e
'); ?>' style
='color:red' onclick
='deleteme()' />
518 // End of receipt printing logic.
522 // Here we display the form for data entry.
525 <title
><?php
echo xlt('Record Payment'); ?
></title
>
527 <style type
="text/css">
528 body
{ font
-family
:sans
-serif
; font
-size
:10pt
; font
-weight
:normal
}
529 .dehead
{ color
:#000000; font-family:sans-serif; font-size:10pt; font-weight:bold }
530 .detail
{ color
:#000000; font-family:sans-serif; font-size:10pt; font-weight:normal }
534 background
-color
: #FBFDD0;
535 border
: 1px solid
#ccc;
540 <link rel
="stylesheet" href
="<?php echo $css_header;?>" type
="text/css">
542 <!-- supporting javascript code
-->
543 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-2-2/index.js"></script
>
545 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js?v=<?php echo $v_js_includes; ?>"></script
>
549 <link rel
="stylesheet" href
="<?php echo $css_header;?>" type
="text/css">
550 <link rel
="stylesheet" type
="text/css" href
="../../library/js/fancybox/jquery.fancybox-1.2.6.css" media
="screen" />
551 <style type
="text/css">@import
url(../../library
/dynarch_calendar
.css
);</style
>
552 <script type
="text/javascript" src
="../../library/textformat.js"></script
>
553 <script type
="text/javascript" src
="../../library/dynarch_calendar.js"></script
>
554 <?php
include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?
>
555 <script type
="text/javascript" src
="../../library/dynarch_calendar_setup.js"></script
>
556 <script type
="text/javascript" src
="../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script
>
557 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-3-2/index.js"></script
>
558 <script type
="text/javascript" src
="../../library/js/common.js"></script
>
559 <script type
="text/javascript" src
="../../library/js/fancybox/jquery.fancybox-1.2.6.js"></script
>
560 <script type
="text/javascript" src
="../../library/js/jquery.easydrag.handler.beta2.js"></script
>
561 <script language
='JavaScript'>
564 <?php
include_once("{$GLOBALS['srcdir']}/ajax/payment_ajax_jav.inc.php"); ?
>
565 <script language
="javascript" type
="text/javascript">
566 document
.onclick
=HideTheAjaxDivs
;
569 <script type
="text/javascript" src
="../../library/topdialog.js"></script
>
571 <script language
="JavaScript">
572 <?php
require($GLOBALS['srcdir'] . "/restoreSession.php"); ?
>
574 function calctotal() {
575 var f
= document
.forms
[0];
577 for (var i
= 0; i
< f
.elements
.length
; ++i
) {
578 var elem
= f
.elements
[i
];
579 var ename
= elem
.name
;
580 if (ename
.indexOf('form_upay[') == 0 || ename
.indexOf('form_bpay[') == 0) {
581 if (elem
.value
.length
> 0) total +
= Number(elem
.value
);
584 f
.form_paytotal
.value
= Number(total
).toFixed(2);
589 for (var i
= 1; ; ++i
)
591 if(document
.getElementById('paying_'+i
))
593 paying
=document
.getElementById('paying_'+i
).value
*1;
594 patient_balance
=document
.getElementById('duept_'+i
).innerHTML
*1;
595 //balance=document.getElementById('balance_'+i).innerHTML*1;
596 if(patient_balance
>0 && paying
>0)
598 if(paying
>patient_balance
)
600 document
.getElementById('paying_'+i
).style
.background
='#FF0000';
602 else if(paying
<patient_balance
)
604 document
.getElementById('paying_'+i
).style
.background
='#99CC00';
606 else if(paying
==patient_balance
)
608 document
.getElementById('paying_'+i
).style
.background
='#ffffff';
613 document
.getElementById('paying_'+i
).style
.background
='#ffffff';
622 function CheckVisible(MakeBlank
)
623 {//Displays and hides the check number text box.
624 if(document
.getElementById('form_method').options
[document
.getElementById('form_method').selectedIndex
].value
=='check_payment' ||
625 document
.getElementById('form_method').options
[document
.getElementById('form_method').selectedIndex
].value
=='bank_draft' )
627 document
.getElementById('check_number').disabled
=false;
631 document
.getElementById('check_number').disabled
=true;
636 var f
= document
.forms
[0];
638 top
.restoreSession();
640 if(((document
.getElementById('form_method').options
[document
.getElementById('form_method').selectedIndex
].value
=='check_payment' ||
641 document
.getElementById('form_method').options
[document
.getElementById('form_method').selectedIndex
].value
=='bank_draft') &&
642 document
.getElementById('check_number').value
=='' ))
644 alert("<?php echo addslashes(xl('Please Fill the Check/Ref Number')) ?>");
645 document
.getElementById('check_number').focus();
649 if(document
.getElementById('radio_type_of_payment_self1').checked
==false && document
.getElementById('radio_type_of_payment_self2').checked
==false && document
.getElementById('radio_type_of_payment1').checked
==false && document
.getElementById('radio_type_of_payment2').checked
==false && document
.getElementById('radio_type_of_payment5').checked
==false && document
.getElementById('radio_type_of_payment4').checked
==false)
651 alert("<?php echo addslashes(xl('Please Select Type Of Payment.')) ?>");
654 if(document
.getElementById('radio_type_of_payment_self1').checked
==true || document
.getElementById('radio_type_of_payment_self2').checked
==true || document
.getElementById('radio_type_of_payment1').checked
==true || document
.getElementById('radio_type_of_payment5').checked
==true)
656 for (var i
= 0; i
< f
.elements
.length
; ++i
)
658 var elem
= f
.elements
[i
];
659 var ename
= elem
.name
;
660 if (ename
.indexOf('form_upay[0') == 0) //Today is this text box.
663 {//A warning message, if the amount is posted with out encounter.
664 if(confirm("<?php echo addslashes(xl('Are you sure to post for today?')) ?>"))
679 if(document
.getElementById('radio_type_of_payment1').checked
==true)//CO-PAY
682 for (var i
= 0; i
< f
.elements
.length
; ++i
)
684 var elem
= f
.elements
[i
];
685 var ename
= elem
.name
;
686 if (ename
.indexOf('form_upay[') == 0) //Today is this text box.
688 if(f
.form_paytotal
.value
*1!=elem
.value
*1)//Total CO-PAY is not posted against today
689 {//A warning message, if the amount is posted against an old encounter.
690 if(confirm("<?php echo addslashes(xl('You are posting against an old encounter?')) ?>"))
704 else if(document
.getElementById('radio_type_of_payment2').checked
==true)//Invoice Balance
706 if(document
.getElementById('Today').innerHTML
=='')
708 for (var i
= 0; i
< f
.elements
.length
; ++i
)
710 var elem
= f
.elements
[i
];
711 var ename
= elem
.name
;
712 if (ename
.indexOf('form_upay[') == 0)
714 if (elem
.value
*1 > 0)
716 alert("<?php echo addslashes(xl('Invoice Balance cannot be posted. No Encounter is created.')) ?>");
726 if(confirm("<?php echo addslashes(xl('Would you like to save?')) ?>"))
736 function cursor_pointer()
737 {//Point the cursor to the latest encounter(Today)
738 var f
= document
.forms
[0];
740 for (var i
= 0; i
< f
.elements
.length
; ++i
)
742 var elem
= f
.elements
[i
];
743 var ename
= elem
.name
;
744 if (ename
.indexOf('form_upay[') == 0)
751 //=====================================================
752 function make_it_hide_enc_pay()
754 document
.getElementById('td_head_insurance_payment').style
.display
="none";
755 document
.getElementById('td_head_patient_co_pay').style
.display
="none";
756 document
.getElementById('td_head_co_pay').style
.display
="none";
757 document
.getElementById('td_head_insurance_balance').style
.display
="none";
758 for (var i
= 1; ; ++i
)
760 var td_inspaid_elem
= document
.getElementById('td_inspaid_'+i
)
761 var td_patient_copay_elem
= document
.getElementById('td_patient_copay_'+i
)
762 var td_copay_elem
= document
.getElementById('td_copay_'+i
)
763 var balance_elem
= document
.getElementById('balance_'+i
)
766 td_inspaid_elem
.style
.display
="none";
767 td_patient_copay_elem
.style
.display
="none";
768 td_copay_elem
.style
.display
="none";
769 balance_elem
.style
.display
="none";
776 document
.getElementById('td_total_4').style
.display
="none";
777 document
.getElementById('td_total_7').style
.display
="none";
778 document
.getElementById('td_total_8').style
.display
="none";
779 document
.getElementById('td_total_6').style
.display
="none";
781 document
.getElementById('table_display').width
="420px";
784 //=====================================================
785 function make_visible()
787 document
.getElementById('td_head_rep_doc').style
.display
="";
788 document
.getElementById('td_head_description').style
.display
="";
789 document
.getElementById('td_head_total_charge').style
.display
="none";
790 document
.getElementById('td_head_insurance_payment').style
.display
="none";
791 document
.getElementById('td_head_patient_payment').style
.display
="none";
792 document
.getElementById('td_head_patient_co_pay').style
.display
="none";
793 document
.getElementById('td_head_co_pay').style
.display
="none";
794 document
.getElementById('td_head_insurance_balance').style
.display
="none";
795 document
.getElementById('td_head_patient_balance').style
.display
="none";
796 for (var i
= 1; ; ++i
)
798 var td_charges_elem
= document
.getElementById('td_charges_'+i
)
799 var td_inspaid_elem
= document
.getElementById('td_inspaid_'+i
)
800 var td_ptpaid_elem
= document
.getElementById('td_ptpaid_'+i
)
801 var td_patient_copay_elem
= document
.getElementById('td_patient_copay_'+i
)
802 var td_copay_elem
= document
.getElementById('td_copay_'+i
)
803 var balance_elem
= document
.getElementById('balance_'+i
)
804 var duept_elem
= document
.getElementById('duept_'+i
)
807 td_charges_elem
.style
.display
="none";
808 td_inspaid_elem
.style
.display
="none";
809 td_ptpaid_elem
.style
.display
="none";
810 td_patient_copay_elem
.style
.display
="none";
811 td_copay_elem
.style
.display
="none";
812 balance_elem
.style
.display
="none";
813 duept_elem
.style
.display
="none";
820 document
.getElementById('td_total_7').style
.display
="";
821 document
.getElementById('td_total_8').style
.display
="";
822 document
.getElementById('td_total_1').style
.display
="none";
823 document
.getElementById('td_total_2').style
.display
="none";
824 document
.getElementById('td_total_3').style
.display
="none";
825 document
.getElementById('td_total_4').style
.display
="none";
826 document
.getElementById('td_total_5').style
.display
="none";
827 document
.getElementById('td_total_6').style
.display
="none";
829 document
.getElementById('table_display').width
="505px";
831 function make_it_hide()
833 document
.getElementById('td_head_rep_doc').style
.display
="none";
834 document
.getElementById('td_head_description').style
.display
="none";
835 document
.getElementById('td_head_total_charge').style
.display
="";
836 document
.getElementById('td_head_insurance_payment').style
.display
="";
837 document
.getElementById('td_head_patient_payment').style
.display
="";
838 document
.getElementById('td_head_patient_co_pay').style
.display
="";
839 document
.getElementById('td_head_co_pay').style
.display
="";
840 document
.getElementById('td_head_insurance_balance').style
.display
="";
841 document
.getElementById('td_head_patient_balance').style
.display
="";
842 for (var i
= 1; ; ++i
)
844 var td_charges_elem
= document
.getElementById('td_charges_'+i
)
845 var td_inspaid_elem
= document
.getElementById('td_inspaid_'+i
)
846 var td_ptpaid_elem
= document
.getElementById('td_ptpaid_'+i
)
847 var td_patient_copay_elem
= document
.getElementById('td_patient_copay_'+i
)
848 var td_copay_elem
= document
.getElementById('td_copay_'+i
)
849 var balance_elem
= document
.getElementById('balance_'+i
)
850 var duept_elem
= document
.getElementById('duept_'+i
)
853 td_charges_elem
.style
.display
="";
854 td_inspaid_elem
.style
.display
="";
855 td_ptpaid_elem
.style
.display
="";
856 td_patient_copay_elem
.style
.display
="";
857 td_copay_elem
.style
.display
="";
858 balance_elem
.style
.display
="";
859 duept_elem
.style
.display
="";
866 document
.getElementById('td_total_1').style
.display
="";
867 document
.getElementById('td_total_2').style
.display
="";
868 document
.getElementById('td_total_3').style
.display
="";
869 document
.getElementById('td_total_4').style
.display
="";
870 document
.getElementById('td_total_5').style
.display
="";
871 document
.getElementById('td_total_6').style
.display
="";
872 document
.getElementById('td_total_7').style
.display
="";
873 document
.getElementById('td_total_8').style
.display
="";
875 document
.getElementById('table_display').width
="635px";
877 function make_visible_radio()
879 document
.getElementById('tr_radio1').style
.display
="";
880 document
.getElementById('tr_radio2').style
.display
="none";
882 function make_hide_radio()
884 document
.getElementById('tr_radio1').style
.display
="none";
885 document
.getElementById('tr_radio2').style
.display
="";
887 function make_visible_row()
889 document
.getElementById('table_display').style
.display
="";
890 document
.getElementById('table_display_prepayment').style
.display
="none";
892 function make_hide_row()
894 document
.getElementById('table_display').style
.display
="none";
895 document
.getElementById('table_display_prepayment').style
.display
="";
901 make_it_hide_enc_pay();
902 document
.getElementById('radio_type_of_payment_self1').checked
=true;
905 function make_insurance()
910 document
.getElementById('radio_type_of_payment1').checked
=true;
916 <body
class="body_top" onunload
='imclosing()' onLoad
="cursor_pointer();">
919 <form method
='post' action
='front_payment.php<?php if ($payid) {
920 echo "?payid=$payid";
922 onsubmit
='return validate();'>
923 <input type
='hidden' name
='form_pid' value
='<?php echo attr($pid) ?>' />
926 <table border
='0' cellspacing
='0' cellpadding
="0">
929 <td colspan
="3"> 
;</td
>
933 <td colspan
='3' align
='center' class='text' >
934 <b
><?php
echo htmlspecialchars(xl('Accept Payment for'), ENT_QUOTES
); ?
> 
;: 
; 
;<?php
echo htmlspecialchars($patdata['fname'], ENT_QUOTES
) . " " .
935 htmlspecialchars($patdata['lname'], ENT_QUOTES
) . " " .htmlspecialchars($patdata['mname'], ENT_QUOTES
). " (" . htmlspecialchars($patdata['pid'], ENT_QUOTES
) . ")" ?
></b
>
936 <?php
$NameNew=$patdata['fname'] . " " .$patdata['lname']. " " .$patdata['mname'];?
>
940 <tr height
="15"><td colspan
='3'></td
></tr
>
945 <?php
echo xlt('Payment Method'); ?
>:
948 <select name
="form_method" id
="form_method" class="text" onChange
='CheckVisible("yes")'>
950 $query1112 = "SELECT * FROM list_options where list_id=? ORDER BY seq, title ";
951 $bres1112 = sqlStatement($query1112, array('payment_method'));
952 while ($brow1112 = sqlFetchArray($bres1112)) {
953 if ($brow1112['option_id']=='electronic' ||
$brow1112['option_id']=='bank_draft') {
957 echo "<option value='".htmlspecialchars($brow1112['option_id'], ENT_QUOTES
)."'>".htmlspecialchars(xl_list_label($brow1112['title']), ENT_QUOTES
)."</option>";
964 <tr height
="5"><td colspan
='3'></td
></tr
>
968 <?php
echo xla('Check/Ref Number'); ?
>:
970 <td colspan
='2' ><div id
="ajax_div_patient" style
="display:none;"></div
>
971 <input type
='text' id
="check_number" name
='form_source' style
="width:120px" value
='<?php echo htmlspecialchars($payrow['source
'], ENT_QUOTES); ?>'>
974 <tr height
="5"><td colspan
='3'></td
></tr
>
977 <td
class='text' valign
="middle" >
978 <?php
echo htmlspecialchars(xl('Patient Coverage'), ENT_QUOTES
); ?
>:
980 <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
>
983 <tr height
="5"><td colspan
='3'></td
></tr
>
985 <tr id
="tr_radio1" style
="display:none"><!-- For radio Insurance
-->
986 <td
class='text' valign
="top" >
987 <?php
echo htmlspecialchars(xl('Payment against'), ENT_QUOTES
); ?
>:
989 <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
>
991 <tr id
="tr_radio2"><!-- For radio self
-->
992 <td
class='text' valign
="top" >
993 <?php
echo htmlspecialchars(xl('Payment against'), ENT_QUOTES
); ?
>:
995 <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
>
998 <tr height
="15"><td colspan
='3'></td
></tr
>
1001 <table width
="200" border
="0" cellspacing
="0" cellpadding
="0" id
="table_display_prepayment" style
="display:none">
1003 <td
class='detail'><?php
echo htmlspecialchars(xl('Pre Payment'), ENT_QUOTES
); ?
></td
>
1004 <td
><input type
='text' name
='form_prepayment' style
='width:100px' /></td
>
1008 <table border
='0' id
="table_display" cellpadding
='0' cellspacing
='0' width
='635'>
1009 <tr bgcolor
="#cccccc" id
="tr_head">
1010 <td
class="dehead" width
="70">
1011 <?php
echo htmlspecialchars(xl('DOS'), ENT_QUOTES
) ?
>
1013 <td
class="dehead" width
="65">
1014 <?php
echo htmlspecialchars(xl('Encounter'), ENT_QUOTES
) ?
>
1016 <td
class="dehead" align
="center" width
="80" id
="td_head_total_charge" >
1017 <?php
echo htmlspecialchars(xl('Total Charge'), ENT_QUOTES
) ?
>
1019 <td
class="dehead" align
="center" width
="70" id
="td_head_rep_doc" style
='display:none'>
1020 <?php
echo htmlspecialchars(xl('Report/ Form'), ENT_QUOTES
) ?
>
1022 <td
class="dehead" align
="center" width
="200" id
="td_head_description" style
='display:none'>
1023 <?php
echo htmlspecialchars(xl('Description'), ENT_QUOTES
) ?
>
1025 <td
class="dehead" align
="center" width
="80" id
="td_head_insurance_payment" >
1026 <?php
echo htmlspecialchars(xl('Insurance Payment'), ENT_QUOTES
) ?
>
1028 <td
class="dehead" align
="center" width
="80" id
="td_head_patient_payment" >
1029 <?php
echo htmlspecialchars(xl('Patient Payment'), ENT_QUOTES
) ?
>
1031 <td
class="dehead" align
="center" width
="55" id
="td_head_patient_co_pay" >
1032 <?php
echo htmlspecialchars(xl('Co Pay Paid'), ENT_QUOTES
) ?
>
1034 <td
class="dehead" align
="center" width
="55" id
="td_head_co_pay" >
1035 <?php
echo htmlspecialchars(xl('Required Co Pay'), ENT_QUOTES
) ?
>
1037 <td
class="dehead" align
="center" width
="80" id
="td_head_insurance_balance" >
1038 <?php
echo htmlspecialchars(xl('Insurance Balance'), ENT_QUOTES
) ?
>
1040 <td
class="dehead" align
="center" width
="80" id
="td_head_patient_balance" >
1041 <?php
echo htmlspecialchars(xl('Patient Balance'), ENT_QUOTES
) ?
>
1043 <td
class="dehead" align
="center" width
="50">
1044 <?php
echo htmlspecialchars(xl('Paying'), ENT_QUOTES
) ?
>
1051 // Get the unbilled service charges and payments by encounter for this patient.
1053 $query = "SELECT fe.encounter, b.code_type, b.code, b.modifier, b.fee, " .
1054 "LEFT(fe.date, 10) AS encdate ,fe.last_level_closed " .
1055 "FROM form_encounter AS fe left join billing AS b on " .
1056 "b.pid = ? AND b.activity = 1 AND " .//AND b.billed = 0
1057 "b.code_type != 'TAX' AND b.fee != 0 " .
1058 "AND fe.pid = b.pid AND fe.encounter = b.encounter " .
1059 "where fe.pid = ? " .
1060 "ORDER BY b.encounter";
1061 $bres = sqlStatement($query, array($pid,$pid));
1063 while ($brow = sqlFetchArray($bres)) {
1064 $key = 0 - $brow['encounter'];
1065 if (empty($encs[$key])) {
1066 $encs[$key] = array(
1067 'encounter' => $brow['encounter'],
1068 'date' => $brow['encdate'],
1069 'last_level_closed' => $brow['last_level_closed'],
1074 if ($brow['code_type'] === 'COPAY') {
1075 //$encs[$key]['payments'] -= $brow['fee'];
1077 $encs[$key]['charges'] +
= $brow['fee'];
1080 $query = "SELECT taxrates FROM codes WHERE " .
1081 "code_type = ? AND " .
1083 array_push($sql_array, $code_types[$brow['code_type']]['id'], $brow['code']);
1084 if ($brow['modifier']) {
1085 $query .= "modifier = ?";
1086 array_push($sql_array, $brow['modifier']);
1088 $query .= "(modifier IS NULL OR modifier = '')";
1091 $query .= " LIMIT 1";
1092 $trow = sqlQuery($query, $sql_array);
1093 $encs[$key]['charges'] +
= calcTaxes($trow, $brow['fee']);
1097 // Do the same for unbilled product sales.
1099 $query = "SELECT fe.encounter, s.drug_id, s.fee, " .
1100 "LEFT(fe.date, 10) AS encdate,fe.last_level_closed " .
1101 "FROM form_encounter AS fe left join drug_sales AS s " .
1102 "on s.pid = ? AND s.fee != 0 " .//AND s.billed = 0
1103 "AND fe.pid = s.pid AND fe.encounter = s.encounter " .
1104 "where fe.pid = ? " .
1105 "ORDER BY s.encounter";
1107 $dres = sqlStatement($query, array($pid,$pid));
1109 while ($drow = sqlFetchArray($dres)) {
1110 $key = 0 - $drow['encounter'];
1111 if (empty($encs[$key])) {
1112 $encs[$key] = array(
1113 'encounter' => $drow['encounter'],
1114 'date' => $drow['encdate'],
1115 'last_level_closed' => $drow['last_level_closed'],
1120 $encs[$key]['charges'] +
= $drow['fee'];
1122 $trow = sqlQuery("SELECT taxrates FROM drug_templates WHERE drug_id = ? " .
1123 "ORDER BY selector LIMIT 1", array($drow['drug_id']));
1124 $encs[$key]['charges'] +
= calcTaxes($trow, $drow['fee']);
1127 ksort($encs, SORT_NUMERIC
);
1129 //Bringing on top the Today always
1130 foreach ($encs as $key => $value) {
1131 $dispdate = $value['date'];
1132 if (strcmp($dispdate, $today) == 0 && !$gottoday) {
1138 // If no billing was entered yet for today, then generate a line for
1139 // entering today's co-pay.
1142 echoLine("form_upay[0]", date("Y-m-d"), 0, 0, 0, 0 /*$duept*/);//No encounter yet defined.
1146 foreach ($encs as $key => $value) {
1147 $enc = $value['encounter'];
1148 $dispdate = $value['date'];
1149 if (strcmp($dispdate, $today) == 0 && !$gottoday) {
1150 $dispdate = date("Y-m-d");
1154 //------------------------------------------------------------------------------------
1155 $inscopay = getCopay($pid, $dispdate);
1156 $patcopay = getPatientCopay($pid, $enc);
1160 "SELECT SUM(pay_amount) AS payments, " .
1161 "SUM(adj_amount) AS adjustments FROM ar_activity WHERE " .
1162 "pid = ? and encounter = ? and " .
1163 "payer_type != 0 and account_code!='PCP' ",
1166 $dpayment=$drow['payments'];
1167 $dadjustment=$drow['adjustments'];
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_pat=$drow['payments'];
1179 //------------------------------------------------------------------------------------
1181 $ResultNumberOfInsurance = sqlStatement("SELECT COUNT( DISTINCT TYPE ) NumberOfInsurance FROM insurance_data
1182 where pid = ? and provider>0 ", array($pid));
1183 $RowNumberOfInsurance = sqlFetchArray($ResultNumberOfInsurance);
1184 $NumberOfInsurance=$RowNumberOfInsurance['NumberOfInsurance']*1;
1185 //------------------------------------------------------------------------------------
1187 if ((($NumberOfInsurance==0 ||
$value['last_level_closed']==4 ||
$NumberOfInsurance== $value['last_level_closed']))) {//Patient balance
1188 $brow = sqlQuery("SELECT SUM(fee) AS amount FROM billing WHERE " .
1189 "pid = ? and encounter = ? AND activity = 1", array($pid,$enc));
1190 $srow = sqlQuery("SELECT SUM(fee) AS amount FROM drug_sales WHERE " .
1191 "pid = ? and encounter = ? ", array($pid,$enc));
1192 $drow = sqlQuery("SELECT SUM(pay_amount) AS payments, " .
1193 "SUM(adj_amount) AS adjustments FROM ar_activity WHERE " .
1194 "pid = ? and encounter = ? ", array($pid,$enc));
1195 $duept= $brow['amount'] +
$srow['amount'] - $drow['payments'] - $drow['adjustments'];
1203 ($dpayment +
$dadjustment),
1213 // Continue with display of the data entry form.
1216 <tr bgcolor
="#cccccc">
1217 <td
class="dehead" id
='td_total_1'></td
>
1218 <td
class="dehead" id
='td_total_2'></td
>
1219 <td
class="dehead" id
='td_total_3'></td
>
1220 <td
class="dehead" id
='td_total_4'></td
>
1221 <td
class="dehead" id
='td_total_5'></td
>
1222 <td
class="dehead" id
='td_total_6'></td
>
1223 <td
class="dehead" id
='td_total_7'></td
>
1224 <td
class="dehead" id
='td_total_8'></td
>
1225 <td
class="dehead" align
="right">
1226 <?php
echo htmlspecialchars(xl('Total'), ENT_QUOTES
);?
>
1228 <td
class="dehead" align
="right">
1229 <input type
='text' name
='form_paytotal' value
=''
1230 style
='color:#00aa00;width:50px' readonly
/>
1237 <input type
='submit' name
='form_save' value
='<?php echo htmlspecialchars(xl('Generate Invoice
'), ENT_QUOTES);?>' />  
;
1238 <input type
='button' value
='<?php echo xla('Cancel
'); ?>' onclick
='window.close()' />
1240 <input type
="hidden" name
="hidden_patient_code" id
="hidden_patient_code" value
="<?php echo attr($pid);?>"/>
1241 <input type
='hidden' name
='ajax_mode' id
='ajax_mode' value
='' />
1242 <input type
='hidden' name
='mode' id
='mode' value
='' />
1244 <script language
="JavaScript">