2 // Copyright (C) 2006-2015 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.
9 $fake_register_globals=false;
10 $sanitize_all_escapes=true;
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/formatting.inc.php");
22 require_once("$srcdir/options.inc.php");
23 require_once("$srcdir/encounter_events.inc.php");
24 $pid = $_REQUEST['hidden_patient_code'] > 0 ?
$_REQUEST['hidden_patient_code'] : $pid;
29 <?php
html_header_show();?
>
30 <script type
="text/javascript" src
="<?php echo $webroot ?>/interface/main/tabs/js/include_opener.js"></script
>
31 <link rel
='stylesheet' href
='<?php echo $css_header ?>' type
='text/css'>
33 // Format dollars for display.
35 function bucks($amount) {
37 $amount = oeFormatMoney($amount);
43 function rawbucks($amount) {
45 $amount = sprintf("%.2f", $amount);
51 // Display a row of data for an encounter.
54 function echoLine($iname, $date, $charges, $ptpaid, $inspaid, $duept,$encounter=0,$copay=0,$patcopay=0) {
57 $balance = bucks($charges - $ptpaid - $inspaid);
58 $balance = (round($duept,2) != 0) ?
0 : $balance;//if balance is due from patient, then insurance balance is displayed as zero
59 $encounter = $encounter ?
$encounter : '';
60 echo " <tr id='tr_".attr($var_index)."' >\n";
61 echo " <td class='detail'>" . text(oeFormatShortDate($date)) . "</td>\n";
62 echo " <td class='detail' id='".attr($date)."' align='center'>" . htmlspecialchars($encounter, ENT_QUOTES
) . "</td>\n";
63 echo " <td class='detail' align='center' id='td_charges_$var_index' >" . htmlspecialchars(bucks($charges), ENT_QUOTES
) . "</td>\n";
64 echo " <td class='detail' align='center' id='td_inspaid_$var_index' >" . htmlspecialchars(bucks($inspaid*-1), ENT_QUOTES
) . "</td>\n";
65 echo " <td class='detail' align='center' id='td_ptpaid_$var_index' >" . htmlspecialchars(bucks($ptpaid*-1), ENT_QUOTES
) . "</td>\n";
66 echo " <td class='detail' align='center' id='td_patient_copay_$var_index' >" . htmlspecialchars(bucks($patcopay), ENT_QUOTES
) . "</td>\n";
67 echo " <td class='detail' align='center' id='td_copay_$var_index' >" . htmlspecialchars(bucks($copay), ENT_QUOTES
) . "</td>\n";
68 echo " <td class='detail' align='center' id='balance_$var_index'>" . htmlspecialchars(bucks($balance), ENT_QUOTES
) . "</td>\n";
69 echo " <td class='detail' align='center' id='duept_$var_index'>" . htmlspecialchars(bucks(round($duept,2)*1), ENT_QUOTES
) . "</td>\n";
70 echo " <td class='detail' align='right'><input type='text' name='".attr($iname)."' id='paying_".attr($var_index)."' " .
71 " value='" . '' . "' onchange='coloring();calctotal()' autocomplete='off' " .
72 "onkeyup='calctotal()' style='width:50px'/></td>\n";
76 // We use this to put dashes, colons, etc. back into a timestamp.
78 function decorateString($fmt, $str) {
81 $fc = substr($fmt, 0, 1);
82 $fmt = substr($fmt, 1);
84 $res .= substr($str, 0, 1);
85 $str = substr($str, 1);
93 // Compute taxes from a tax rate string and a possibly taxable amount.
95 function calcTaxes($row, $amount) {
97 if (empty($row['taxrates'])) return $total;
98 $arates = explode(':', $row['taxrates']);
99 if (empty($arates)) return $total;
100 foreach ($arates as $value) {
101 if (empty($value)) continue;
102 $trow = sqlQuery("SELECT option_value FROM list_options WHERE " .
103 "list_id = 'taxrate' AND option_id = ? LIMIT 1", array($value) );
104 if (empty($trow['option_value'])) {
105 echo "<!-- Missing tax rate '".text($value)."'! -->\n";
108 $tax = sprintf("%01.2f", $amount * $trow['option_value']);
109 // echo "<!-- Rate = '$value', amount = '$amount', tax = '$tax' -->\n";
116 $today = date('Y-m-d', $now);
117 $timestamp = date('Y-m-d H:i:s', $now);
120 // $patdata = getPatientData($pid, 'fname,lname,pubpid');
122 $patdata = sqlQuery("SELECT " .
123 "p.fname, p.mname, p.lname, p.pubpid,p.pid, i.copay " .
124 "FROM patient_data AS p " .
125 "LEFT OUTER JOIN insurance_data AS i ON " .
126 "i.pid = p.pid AND i.type = 'primary' " .
127 "WHERE p.pid = ? ORDER BY i.date DESC LIMIT 1", array($pid) );
129 $alertmsg = ''; // anything here pops up in an alert box
131 // If the Save button was clicked...
132 if ($_POST['form_save']) {
133 $form_pid = $_POST['form_pid'];
134 $form_method = trim($_POST['form_method']);
135 $form_source = trim($_POST['form_source']);
136 $patdata = getPatientData($form_pid, 'fname,mname,lname,pubpid');
137 $NameNew=$patdata['fname'] . " " .$patdata['lname']. " " .$patdata['mname'];
139 if($_REQUEST['radio_type_of_payment']=='pre_payment')
141 $payment_id = idSqlStatement("insert into ar_session set " .
147 ", check_date = now() , deposit_date = now() " .
149 ", payment_type = 'patient'" .
150 ", description = ?" .
151 ", adjustment_code = 'pre_payment'" .
152 ", post_to_date = now() " .
153 ", payment_method = ?",
154 array(0,$form_pid,$_SESSION['authUserID'],0,$form_source,$_REQUEST['form_prepayment'],$NameNew,$form_method));
156 frontPayment($form_pid, 0, $form_method, $form_source, $_REQUEST['form_prepayment'], 0, $timestamp);//insertion to 'payments' table.
159 if ($_POST['form_upay'] && $_REQUEST['radio_type_of_payment']!='pre_payment') {
160 foreach ($_POST['form_upay'] as $enc => $payment) {
161 if ($amount = 0 +
$payment) {
163 if($_REQUEST['radio_type_of_payment']=='invoice_balance')
171 $enc = calendar_arrived($form_pid);
174 //----------------------------------------------------------------------------------------------------
175 //Fetching the existing code and modifier
176 $ResultSearchNew = sqlStatement("SELECT * FROM billing LEFT JOIN code_types ON billing.code_type=code_types.ct_key ".
177 "WHERE code_types.ct_fee=1 AND billing.activity!=0 AND billing.pid =? AND encounter=? ORDER BY billing.code,billing.modifier",
178 array($form_pid,$enc));
179 if($RowSearch = sqlFetchArray($ResultSearchNew))
181 $Codetype=$RowSearch['code_type'];
182 $Code=$RowSearch['code'];
183 $Modifier=$RowSearch['modifier'];
191 //----------------------------------------------------------------------------------------------------
192 if($_REQUEST['radio_type_of_payment']=='copay')//copay saving to ar_session and ar_activity tables
194 $session_id=sqlInsert("INSERT INTO ar_session (payer_id,user_id,reference,check_date,deposit_date,pay_total,".
195 " global_amount,payment_type,description,patient_id,payment_method,adjustment_code,post_to_date) ".
196 " VALUES ('0',?,?,now(),now(),?,'','patient','COPAY',?,?,'patient_payment',now())",
197 array($_SESSION['authId'],$form_source,$amount,$form_pid,$form_method));
200 $sequence_no = sqlQuery( "SELECT IFNULL(MAX(sequence_no),0) + 1 AS increment FROM ar_activity WHERE pid = ? AND encounter = ?", array($form_pid, $enc));
201 $insrt_id=sqlInsert("INSERT INTO ar_activity (pid,encounter,sequence_no,code_type,code,modifier,payer_type,post_time,post_user,session_id,pay_amount,account_code)".
202 " VALUES (?,?,?,?,?,?,0,now(),?,?,?,'PCP')",
203 array($form_pid,$enc,$sequence_no['increment'],$Codetype,$Code,$Modifier,$_SESSION['authId'],$session_id,$amount));
206 frontPayment($form_pid, $enc, $form_method, $form_source, $amount, 0, $timestamp);//insertion to 'payments' table.
208 if($_REQUEST['radio_type_of_payment']=='invoice_balance' ||
$_REQUEST['radio_type_of_payment']=='cash')
209 { //Payment by patient after insurance paid, cash patients similar to do not bill insurance in feesheet.
210 if($_REQUEST['radio_type_of_payment']=='cash')
212 sqlStatement("update form_encounter set last_level_closed=? where encounter=? and pid=? ",
213 array(4,$enc,$form_pid));
214 sqlStatement("update billing set billed=? where encounter=? and pid=?",
215 array(1,$enc,$form_pid));
217 $adjustment_code='patient_payment';
218 $payment_id = idSqlStatement("insert into ar_session set " .
224 ", check_date = now() , deposit_date = now() " .
226 ", payment_type = 'patient'" .
227 ", description = ?" .
228 ", adjustment_code = ?" .
229 ", post_to_date = now() " .
230 ", payment_method = ?",
231 array(0,$form_pid,$_SESSION['authUserID'],0,$form_source,$amount,$NameNew,$adjustment_code,$form_method));
233 //--------------------------------------------------------------------------------------------------------------------
235 frontPayment($form_pid, $enc, $form_method, $form_source, 0, $amount, $timestamp);//insertion to 'payments' table.
237 //--------------------------------------------------------------------------------------------------------------------
239 $resMoneyGot = sqlStatement("SELECT sum(pay_amount) as PatientPay FROM ar_activity where pid =? and ".
240 "encounter =? and payer_type=0 and account_code='PCP'",
241 array($form_pid,$enc));//new fees screen copay gives account_code='PCP'
242 $rowMoneyGot = sqlFetchArray($resMoneyGot);
243 $Copay=$rowMoneyGot['PatientPay'];
245 //--------------------------------------------------------------------------------------------------------------------
247 //Looping the existing code and modifier
248 $ResultSearchNew = sqlStatement("SELECT * FROM billing LEFT JOIN code_types ON billing.code_type=code_types.ct_key WHERE code_types.ct_fee=1 ".
249 "AND billing.activity!=0 AND billing.pid =? AND encounter=? ORDER BY billing.code,billing.modifier",
250 array($form_pid,$enc));
251 while($RowSearch = sqlFetchArray($ResultSearchNew))
253 $Codetype=$RowSearch['code_type'];
254 $Code=$RowSearch['code'];
255 $Modifier =$RowSearch['modifier'];
256 $Fee =$RowSearch['fee'];
258 $resMoneyGot = sqlStatement("SELECT sum(pay_amount) as MoneyGot FROM ar_activity where pid =? ".
259 "and code_type=? and code=? and modifier=? and encounter =? and !(payer_type=0 and account_code='PCP')",
260 array($form_pid,$Codetype,$Code,$Modifier,$enc));
261 //new fees screen copay gives account_code='PCP'
262 $rowMoneyGot = sqlFetchArray($resMoneyGot);
263 $MoneyGot=$rowMoneyGot['MoneyGot'];
265 $resMoneyAdjusted = sqlStatement("SELECT sum(adj_amount) as MoneyAdjusted FROM ar_activity where ".
266 "pid =? and code_type=? and code=? and modifier=? and encounter =?",
267 array($form_pid,$Codetype,$Code,$Modifier,$enc));
268 $rowMoneyAdjusted = sqlFetchArray($resMoneyAdjusted);
269 $MoneyAdjusted=$rowMoneyAdjusted['MoneyAdjusted'];
271 $Remainder=$Fee-$Copay-$MoneyGot-$MoneyAdjusted;
273 if(round($Remainder,2)!=0 && $amount!=0)
275 if($amount-$Remainder >= 0)
277 $insert_value=$Remainder;
278 $amount=$amount-$Remainder;
282 $insert_value=$amount;
286 $sequence_no = sqlQuery( "SELECT IFNULL(MAX(sequence_no),0) + 1 AS increment FROM ar_activity WHERE pid = ? AND encounter = ?", array($form_pid, $enc));
287 sqlStatement("insert into ar_activity set " .
290 ", sequence_no = ?" .
295 ", post_time = now() " .
300 ", account_code = 'PP'",
301 array($form_pid,$enc,$sequence_no['increment'],$Codetype,$Code,$Modifier,0,$_SESSION['authUserID'],$payment_id,$insert_value,0));
305 if($amount!=0)//if any excess is there.
308 $sequence_no = sqlQuery( "SELECT IFNULL(MAX(sequence_no),0) + 1 AS increment FROM ar_activity WHERE pid = ? AND encounter = ?", array($form_pid, $enc));
309 sqlStatement("insert into ar_activity set " .
312 ", sequence_no = ?" .
317 ", post_time = now() " .
322 ", account_code = 'PP'",
323 array($form_pid,$enc,$sequence_no['increment'],$Codetype,$Code,$Modifier,0,$_SESSION['authUserID'],$payment_id,$amount,0));
327 //--------------------------------------------------------------------------------------------------------------------
329 }//if ($amount = 0 + $payment)
331 }//if ($_POST['form_upay'])
332 }//if ($_POST['form_save'])
334 if ($_POST['form_save'] ||
$_REQUEST['receipt']) {
336 if ($_REQUEST['receipt']) {
337 $form_pid = $_GET['patient'];
338 $timestamp = decorateString('....-..-.. ..:..:..', $_GET['time']);
341 // Get details for what we guess is the primary facility.
342 $frow = sqlQuery("SELECT * FROM facility " .
343 "ORDER BY billing_location DESC, accepts_assignment DESC, id LIMIT 1");
345 // Get the patient's name and chart number.
346 $patdata = getPatientData($form_pid, 'fname,mname,lname,pubpid');
348 // Re-fetch payment info.
349 $payrow = sqlQuery("SELECT " .
350 "SUM(amount1) AS amount1, " .
351 "SUM(amount2) AS amount2, " .
352 "MAX(method) AS method, " .
353 "MAX(source) AS source, " .
354 "MAX(dtime) AS dtime, " .
355 // "MAX(user) AS user " .
356 "MAX(user) AS user, " .
357 "MAX(encounter) as encounter ".
358 "FROM payments WHERE " .
359 "pid = ? AND dtime = ?", array($form_pid,$timestamp) );
361 // Create key for deleting, just in case.
362 $ref_id = ($_REQUEST['radio_type_of_payment']=='copay') ?
$session_id : $payment_id ;
363 $payment_key = $form_pid . '.' . preg_replace('/[^0-9]/', '', $timestamp).'.'.$ref_id;
365 // get facility from encounter
369 WHERE encounter = ?", array($payrow['encounter']) );
370 $frow = sqlQuery("SELECT * FROM facility " .
371 " WHERE id = ?", array($tmprow['facility_id']) );
373 // Now proceed with printing the receipt.
376 <title
><?php
echo xlt('Receipt for Payment'); ?
></title
>
377 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.js"></script
>
378 <script type
="text/javascript" src
="../../library/dialog.js"></script
>
379 <script language
="JavaScript">
381 <?php
require($GLOBALS['srcdir'] . "/restoreSession.php"); ?
>
383 $
(document
).ready(function() {
384 var win
= top
.printLogSetup ? top
: opener
.top
;
385 win
.printLogSetup(document
.getElementById('printbutton'));
388 // This is action to take before printing and is called from restoreSession.php.
389 function printlog_before_print() {
390 var divstyle
= document
.getElementById('hideonprint').style
;
391 divstyle
.display
= 'none';
394 // Process click on Delete button.
395 function deleteme() {
396 dlgopen('deleter.php?payment=<?php echo $payment_key ?>', '_blank', 500, 450);
399 // Called by the deleteme.php window on a successful delete.
400 function imdeleted() {
404 // Called to switch to the specified encounter having the specified DOS.
405 // This also closes the popup window.
406 function toencounter(enc
, datestr
, topframe
) {
407 topframe
.restoreSession();
408 <?php
if ($GLOBALS['concurrent_layout']) { ?
>
409 // Hard-coding of RBot for this purpose is awkward, but since this is a
410 // pop-up and our openemr is left_nav, we have no good clue as to whether
411 // the top frame is more appropriate.
412 topframe
.left_nav
.forceDual();
413 topframe
.left_nav
.setEncounter(datestr
, enc
, '');
414 topframe
.left_nav
.setRadio('RBot', 'enc');
415 topframe
.left_nav
.loadFrame('enc2', 'RBot', 'patient_file/encounter/encounter_top.php?set_encounter=' + enc
);
417 topframe
.Title
.location
.href
= 'encounter/encounter_title.php?set_encounter=' + enc
;
418 topframe
.Main
.location
.href
= 'encounter/patient_encounter.php?set_encounter=' + enc
;
425 <body bgcolor
='#ffffff'>
428 <p
><h2
><?php
echo xlt('Receipt for Payment'); ?
></h2
>
430 <p
><?php
echo text($frow['name']) ?
>
431 <br
><?php
echo text($frow['street']) ?
>
432 <br
><?php
echo text($frow['city'] . ', ' . $frow['state']) . ' ' .
433 text($frow['postal_code']) ?
>
434 <br
><?php
echo htmlentities($frow['phone']) ?
>
437 <table border
='0' cellspacing
='8'>
439 <td
><?php
echo xlt('Date'); ?
>:</td
>
440 <td
><?php
echo text(oeFormatSDFT(strtotime($payrow['dtime']))) ?
></td
>
443 <td
><?php
echo xlt('Patient'); ?
>:</td
>
444 <td
><?php
echo text($patdata['fname']) . " " . text($patdata['mname']) . " " .
445 text($patdata['lname']) . " (" . text($patdata['pubpid']) . ")" ?
></td
>
448 <td
><?php
echo xlt('Paid Via'); ?
>:</td
>
449 <td
><?php
echo generate_display_field(array('data_type'=>'1','list_id'=>'payment_method'),$payrow['method']); ?
></td
>
452 <td
><?php
echo xlt('Check/Ref Number'); ?
>:</td
>
453 <td
><?php
echo text($payrow['source']) ?
></td
>
456 <td
><?php
echo xlt('Amount for This Visit'); ?
>:</td
>
457 <td
><?php
echo text(oeFormatMoney($payrow['amount1'])) ?
></td
>
460 <td
><?php
echo xlt('Amount for Past Balance'); ?
>:</td
>
461 <td
><?php
echo text(oeFormatMoney($payrow['amount2'])) ?
></td
>
464 <td
><?php
echo xlt('Received By'); ?
>:</td
>
465 <td
><?php
echo text($payrow['user']) ?
></td
>
469 <div id
='hideonprint'>
471 <input type
='button' value
='<?php echo xla('Print'); ?>' id
='printbutton' />
474 $todaysenc = todaysEncounterIf($pid);
475 if ($todaysenc && $todaysenc != $encounter) {
476 echo " <input type='button' " .
477 "value='" . xla('Open Today`s Visit') . "' " .
478 "onclick='toencounter($todaysenc,\"$today\",opener.top)' />\n";
482 <?php
if (acl_check('admin', 'super')) { ?
>
484 <input type
='button' value
='<?php xl('Delete
','e
'); ?>' style
='color:red' onclick
='deleteme()' />
493 // End of receipt printing logic.
497 // Here we display the form for data entry.
500 <title
><?php
echo xlt('Record Payment'); ?
></title
>
502 <style type
="text/css">
503 body
{ font
-family
:sans
-serif
; font
-size
:10pt
; font
-weight
:normal
}
504 .dehead
{ color
:#000000; font-family:sans-serif; font-size:10pt; font-weight:bold }
505 .detail
{ color
:#000000; font-family:sans-serif; font-size:10pt; font-weight:normal }
509 background
-color
: #FBFDD0;
510 border
: 1px solid
#ccc;
515 <link rel
="stylesheet" href
="<?php echo $css_header;?>" type
="text/css">
517 <!-- supporting javascript code
-->
518 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.js"></script
>
520 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js"></script
>
524 <link rel
="stylesheet" href
="<?php echo $css_header;?>" type
="text/css">
525 <link rel
="stylesheet" type
="text/css" href
="../../library/js/fancybox/jquery.fancybox-1.2.6.css" media
="screen" />
526 <style type
="text/css">@import
url(../../library
/dynarch_calendar
.css
);</style
>
527 <script type
="text/javascript" src
="../../library/textformat.js"></script
>
528 <script type
="text/javascript" src
="../../library/dynarch_calendar.js"></script
>
529 <?php
include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?
>
530 <script type
="text/javascript" src
="../../library/dynarch_calendar_setup.js"></script
>
531 <script type
="text/javascript" src
="../../library/dialog.js"></script
>
532 <script type
="text/javascript" src
="../../library/js/jquery.1.3.2.js"></script
>
533 <script type
="text/javascript" src
="../../library/js/common.js"></script
>
534 <script type
="text/javascript" src
="../../library/js/fancybox/jquery.fancybox-1.2.6.js"></script
>
535 <script type
="text/javascript" src
="../../library/js/jquery.easydrag.handler.beta2.js"></script
>
536 <script language
='JavaScript'>
539 <?php
include_once("{$GLOBALS['srcdir']}/ajax/payment_ajax_jav.inc.php"); ?
>
540 <script language
="javascript" type
="text/javascript">
541 document
.onclick
=HideTheAjaxDivs
;
544 <script type
="text/javascript" src
="../../library/topdialog.js"></script
>
546 <script language
="JavaScript">
547 <?php
require($GLOBALS['srcdir'] . "/restoreSession.php"); ?
>
549 function calctotal() {
550 var f
= document
.forms
[0];
552 for (var i
= 0; i
< f
.elements
.length
; ++i
) {
553 var elem
= f
.elements
[i
];
554 var ename
= elem
.name
;
555 if (ename
.indexOf('form_upay[') == 0 || ename
.indexOf('form_bpay[') == 0) {
556 if (elem
.value
.length
> 0) total +
= Number(elem
.value
);
559 f
.form_paytotal
.value
= Number(total
).toFixed(2);
564 for (var i
= 1; ; ++i
)
566 if(document
.getElementById('paying_'+i
))
568 paying
=document
.getElementById('paying_'+i
).value
*1;
569 patient_balance
=document
.getElementById('duept_'+i
).innerHTML
*1;
570 //balance=document.getElementById('balance_'+i).innerHTML*1;
571 if(patient_balance
>0 && paying
>0)
573 if(paying
>patient_balance
)
575 document
.getElementById('paying_'+i
).style
.background
='#FF0000';
577 else if(paying
<patient_balance
)
579 document
.getElementById('paying_'+i
).style
.background
='#99CC00';
581 else if(paying
==patient_balance
)
583 document
.getElementById('paying_'+i
).style
.background
='#ffffff';
588 document
.getElementById('paying_'+i
).style
.background
='#ffffff';
597 function CheckVisible(MakeBlank
)
598 {//Displays and hides the check number text box.
599 if(document
.getElementById('form_method').options
[document
.getElementById('form_method').selectedIndex
].value
=='check_payment' ||
600 document
.getElementById('form_method').options
[document
.getElementById('form_method').selectedIndex
].value
=='bank_draft' )
602 document
.getElementById('check_number').disabled
=false;
606 document
.getElementById('check_number').disabled
=true;
611 var f
= document
.forms
[0];
613 top
.restoreSession();
615 if(((document
.getElementById('form_method').options
[document
.getElementById('form_method').selectedIndex
].value
=='check_payment' ||
616 document
.getElementById('form_method').options
[document
.getElementById('form_method').selectedIndex
].value
=='bank_draft') &&
617 document
.getElementById('check_number').value
=='' ))
619 alert("<?php echo addslashes( xl('Please Fill the Check/Ref Number')) ?>");
620 document
.getElementById('check_number').focus();
624 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)
626 alert("<?php echo addslashes( xl('Please Select Type Of Payment.')) ?>");
629 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)
631 for (var i
= 0; i
< f
.elements
.length
; ++i
)
633 var elem
= f
.elements
[i
];
634 var ename
= elem
.name
;
635 if (ename
.indexOf('form_upay[0') == 0) //Today is this text box.
638 {//A warning message, if the amount is posted with out encounter.
639 if(confirm("<?php echo addslashes( xl('Are you sure to post for today?')) ?>"))
654 if(document
.getElementById('radio_type_of_payment1').checked
==true)//CO-PAY
657 for (var i
= 0; i
< f
.elements
.length
; ++i
)
659 var elem
= f
.elements
[i
];
660 var ename
= elem
.name
;
661 if (ename
.indexOf('form_upay[') == 0) //Today is this text box.
663 if(f
.form_paytotal
.value
*1!=elem
.value
*1)//Total CO-PAY is not posted against today
664 {//A warning message, if the amount is posted against an old encounter.
665 if(confirm("<?php echo addslashes( xl('You are posting against an old encounter?')) ?>"))
679 else if(document
.getElementById('radio_type_of_payment2').checked
==true)//Invoice Balance
681 if(document
.getElementById('Today').innerHTML
=='')
683 for (var i
= 0; i
< f
.elements
.length
; ++i
)
685 var elem
= f
.elements
[i
];
686 var ename
= elem
.name
;
687 if (ename
.indexOf('form_upay[') == 0)
689 if (elem
.value
*1 > 0)
691 alert("<?php echo addslashes( xl('Invoice Balance cannot be posted. No Encounter is created.')) ?>");
701 if(confirm("<?php echo addslashes( xl('Would you like to save?')) ?>"))
711 function cursor_pointer()
712 {//Point the cursor to the latest encounter(Today)
713 var f
= document
.forms
[0];
715 for (var i
= 0; i
< f
.elements
.length
; ++i
)
717 var elem
= f
.elements
[i
];
718 var ename
= elem
.name
;
719 if (ename
.indexOf('form_upay[') == 0)
726 //=====================================================
727 function make_it_hide_enc_pay()
729 document
.getElementById('td_head_insurance_payment').style
.display
="none";
730 document
.getElementById('td_head_patient_co_pay').style
.display
="none";
731 document
.getElementById('td_head_co_pay').style
.display
="none";
732 document
.getElementById('td_head_insurance_balance').style
.display
="none";
733 for (var i
= 1; ; ++i
)
735 var td_inspaid_elem
= document
.getElementById('td_inspaid_'+i
)
736 var td_patient_copay_elem
= document
.getElementById('td_patient_copay_'+i
)
737 var td_copay_elem
= document
.getElementById('td_copay_'+i
)
738 var balance_elem
= document
.getElementById('balance_'+i
)
741 td_inspaid_elem
.style
.display
="none";
742 td_patient_copay_elem
.style
.display
="none";
743 td_copay_elem
.style
.display
="none";
744 balance_elem
.style
.display
="none";
751 document
.getElementById('td_total_4').style
.display
="none";
752 document
.getElementById('td_total_7').style
.display
="none";
753 document
.getElementById('td_total_8').style
.display
="none";
754 document
.getElementById('td_total_6').style
.display
="none";
756 document
.getElementById('table_display').width
="420px";
759 //=====================================================
760 function make_visible()
762 document
.getElementById('td_head_rep_doc').style
.display
="";
763 document
.getElementById('td_head_description').style
.display
="";
764 document
.getElementById('td_head_total_charge').style
.display
="none";
765 document
.getElementById('td_head_insurance_payment').style
.display
="none";
766 document
.getElementById('td_head_patient_payment').style
.display
="none";
767 document
.getElementById('td_head_patient_co_pay').style
.display
="none";
768 document
.getElementById('td_head_co_pay').style
.display
="none";
769 document
.getElementById('td_head_insurance_balance').style
.display
="none";
770 document
.getElementById('td_head_patient_balance').style
.display
="none";
771 for (var i
= 1; ; ++i
)
773 var td_charges_elem
= document
.getElementById('td_charges_'+i
)
774 var td_inspaid_elem
= document
.getElementById('td_inspaid_'+i
)
775 var td_ptpaid_elem
= document
.getElementById('td_ptpaid_'+i
)
776 var td_patient_copay_elem
= document
.getElementById('td_patient_copay_'+i
)
777 var td_copay_elem
= document
.getElementById('td_copay_'+i
)
778 var balance_elem
= document
.getElementById('balance_'+i
)
779 var duept_elem
= document
.getElementById('duept_'+i
)
782 td_charges_elem
.style
.display
="none";
783 td_inspaid_elem
.style
.display
="none";
784 td_ptpaid_elem
.style
.display
="none";
785 td_patient_copay_elem
.style
.display
="none";
786 td_copay_elem
.style
.display
="none";
787 balance_elem
.style
.display
="none";
788 duept_elem
.style
.display
="none";
795 document
.getElementById('td_total_7').style
.display
="";
796 document
.getElementById('td_total_8').style
.display
="";
797 document
.getElementById('td_total_1').style
.display
="none";
798 document
.getElementById('td_total_2').style
.display
="none";
799 document
.getElementById('td_total_3').style
.display
="none";
800 document
.getElementById('td_total_4').style
.display
="none";
801 document
.getElementById('td_total_5').style
.display
="none";
802 document
.getElementById('td_total_6').style
.display
="none";
804 document
.getElementById('table_display').width
="505px";
806 function make_it_hide()
808 document
.getElementById('td_head_rep_doc').style
.display
="none";
809 document
.getElementById('td_head_description').style
.display
="none";
810 document
.getElementById('td_head_total_charge').style
.display
="";
811 document
.getElementById('td_head_insurance_payment').style
.display
="";
812 document
.getElementById('td_head_patient_payment').style
.display
="";
813 document
.getElementById('td_head_patient_co_pay').style
.display
="";
814 document
.getElementById('td_head_co_pay').style
.display
="";
815 document
.getElementById('td_head_insurance_balance').style
.display
="";
816 document
.getElementById('td_head_patient_balance').style
.display
="";
817 for (var i
= 1; ; ++i
)
819 var td_charges_elem
= document
.getElementById('td_charges_'+i
)
820 var td_inspaid_elem
= document
.getElementById('td_inspaid_'+i
)
821 var td_ptpaid_elem
= document
.getElementById('td_ptpaid_'+i
)
822 var td_patient_copay_elem
= document
.getElementById('td_patient_copay_'+i
)
823 var td_copay_elem
= document
.getElementById('td_copay_'+i
)
824 var balance_elem
= document
.getElementById('balance_'+i
)
825 var duept_elem
= document
.getElementById('duept_'+i
)
828 td_charges_elem
.style
.display
="";
829 td_inspaid_elem
.style
.display
="";
830 td_ptpaid_elem
.style
.display
="";
831 td_patient_copay_elem
.style
.display
="";
832 td_copay_elem
.style
.display
="";
833 balance_elem
.style
.display
="";
834 duept_elem
.style
.display
="";
841 document
.getElementById('td_total_1').style
.display
="";
842 document
.getElementById('td_total_2').style
.display
="";
843 document
.getElementById('td_total_3').style
.display
="";
844 document
.getElementById('td_total_4').style
.display
="";
845 document
.getElementById('td_total_5').style
.display
="";
846 document
.getElementById('td_total_6').style
.display
="";
847 document
.getElementById('td_total_7').style
.display
="";
848 document
.getElementById('td_total_8').style
.display
="";
850 document
.getElementById('table_display').width
="635px";
852 function make_visible_radio()
854 document
.getElementById('tr_radio1').style
.display
="";
855 document
.getElementById('tr_radio2').style
.display
="none";
857 function make_hide_radio()
859 document
.getElementById('tr_radio1').style
.display
="none";
860 document
.getElementById('tr_radio2').style
.display
="";
862 function make_visible_row()
864 document
.getElementById('table_display').style
.display
="";
865 document
.getElementById('table_display_prepayment').style
.display
="none";
867 function make_hide_row()
869 document
.getElementById('table_display').style
.display
="none";
870 document
.getElementById('table_display_prepayment').style
.display
="";
876 make_it_hide_enc_pay();
877 document
.getElementById('radio_type_of_payment_self1').checked
=true;
880 function make_insurance()
885 document
.getElementById('radio_type_of_payment1').checked
=true;
891 <body
class="body_top" onunload
='imclosing()' onLoad
="cursor_pointer();">
894 <form method
='post' action
='front_payment.php<?php if ($payid) echo "?payid=$payid"; ?>'
895 onsubmit
='return validate();'>
896 <input type
='hidden' name
='form_pid' value
='<?php echo attr($pid) ?>' />
899 <table border
='0' cellspacing
='0' cellpadding
="0">
902 <td colspan
="3"> 
;</td
>
906 <td colspan
='3' align
='center' class='text' >
907 <b
><?php
echo htmlspecialchars(xl('Accept Payment for'), ENT_QUOTES
); ?
> 
;: 
; 
;<?php
echo htmlspecialchars($patdata['fname'], ENT_QUOTES
) . " " .
908 htmlspecialchars($patdata['lname'], ENT_QUOTES
) . " " .htmlspecialchars($patdata['mname'], ENT_QUOTES
). " (" . htmlspecialchars($patdata['pid'], ENT_QUOTES
) . ")" ?
></b
>
909 <?php
$NameNew=$patdata['fname'] . " " .$patdata['lname']. " " .$patdata['mname'];?
>
913 <tr height
="15"><td colspan
='3'></td
></tr
>
918 <?php
echo xlt('Payment Method'); ?
>:
921 <select name
="form_method" id
="form_method" class="text" onChange
='CheckVisible("yes")'>
923 $query1112 = "SELECT * FROM list_options where list_id=? ORDER BY seq, title ";
924 $bres1112 = sqlStatement($query1112,array('payment_method'));
925 while ($brow1112 = sqlFetchArray($bres1112))
927 if($brow1112['option_id']=='electronic' ||
$brow1112['option_id']=='bank_draft')
929 echo "<option value='".htmlspecialchars($brow1112['option_id'], ENT_QUOTES
)."'>".htmlspecialchars(xl_list_label($brow1112['title']), ENT_QUOTES
)."</option>";
936 <tr height
="5"><td colspan
='3'></td
></tr
>
940 <?php
echo xla('Check/Ref Number'); ?
>:
942 <td colspan
='2' ><div id
="ajax_div_patient" style
="display:none;"></div
>
943 <input type
='text' id
="check_number" name
='form_source' style
="width:120px" value
='<?php echo htmlspecialchars($payrow['source
'], ENT_QUOTES); ?>'>
946 <tr height
="5"><td colspan
='3'></td
></tr
>
949 <td
class='text' valign
="middle" >
950 <?php
echo htmlspecialchars(xl('Patient Coverage'), ENT_QUOTES
); ?
>:
952 <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
>
955 <tr height
="5"><td colspan
='3'></td
></tr
>
957 <tr id
="tr_radio1" style
="display:none"><!-- For radio Insurance
-->
958 <td
class='text' valign
="top" >
959 <?php
echo htmlspecialchars(xl('Payment against'), ENT_QUOTES
); ?
>:
961 <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
>
963 <tr id
="tr_radio2"><!-- For radio self
-->
964 <td
class='text' valign
="top" >
965 <?php
echo htmlspecialchars(xl('Payment against'), ENT_QUOTES
); ?
>:
967 <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
>
970 <tr height
="15"><td colspan
='3'></td
></tr
>
973 <table width
="200" border
="0" cellspacing
="0" cellpadding
="0" id
="table_display_prepayment" style
="display:none">
975 <td
class='detail'><?php
echo htmlspecialchars(xl('Pre Payment'), ENT_QUOTES
); ?
></td
>
976 <td
><input type
='text' name
='form_prepayment' style
='width:100px' /></td
>
980 <table border
='0' id
="table_display" cellpadding
='0' cellspacing
='0' width
='635'>
981 <tr bgcolor
="#cccccc" id
="tr_head">
982 <td
class="dehead" width
="70">
983 <?php
echo htmlspecialchars( xl('DOS'), ENT_QUOTES
) ?
>
985 <td
class="dehead" width
="65">
986 <?php
echo htmlspecialchars( xl('Encounter'), ENT_QUOTES
) ?
>
988 <td
class="dehead" align
="center" width
="80" id
="td_head_total_charge" >
989 <?php
echo htmlspecialchars( xl('Total Charge'), ENT_QUOTES
) ?
>
991 <td
class="dehead" align
="center" width
="70" id
="td_head_rep_doc" style
='display:none'>
992 <?php
echo htmlspecialchars( xl('Report/ Form'), ENT_QUOTES
) ?
>
994 <td
class="dehead" align
="center" width
="200" id
="td_head_description" style
='display:none'>
995 <?php
echo htmlspecialchars( xl('Description'), ENT_QUOTES
) ?
>
997 <td
class="dehead" align
="center" width
="80" id
="td_head_insurance_payment" >
998 <?php
echo htmlspecialchars( xl('Insurance Payment'), ENT_QUOTES
) ?
>
1000 <td
class="dehead" align
="center" width
="80" id
="td_head_patient_payment" >
1001 <?php
echo htmlspecialchars( xl('Patient Payment'), ENT_QUOTES
) ?
>
1003 <td
class="dehead" align
="center" width
="55" id
="td_head_patient_co_pay" >
1004 <?php
echo htmlspecialchars( xl('Co Pay Paid'), ENT_QUOTES
) ?
>
1006 <td
class="dehead" align
="center" width
="55" id
="td_head_co_pay" >
1007 <?php
echo htmlspecialchars( xl('Required Co Pay'), ENT_QUOTES
) ?
>
1009 <td
class="dehead" align
="center" width
="80" id
="td_head_insurance_balance" >
1010 <?php
echo htmlspecialchars( xl('Insurance Balance'), ENT_QUOTES
) ?
>
1012 <td
class="dehead" align
="center" width
="80" id
="td_head_patient_balance" >
1013 <?php
echo htmlspecialchars( xl('Patient Balance'), ENT_QUOTES
) ?
>
1015 <td
class="dehead" align
="center" width
="50">
1016 <?php
echo htmlspecialchars( xl('Paying'), ENT_QUOTES
) ?
>
1023 // Get the unbilled service charges and payments by encounter for this patient.
1025 $query = "SELECT fe.encounter, b.code_type, b.code, b.modifier, b.fee, " .
1026 "LEFT(fe.date, 10) AS encdate ,fe.last_level_closed " .
1027 "FROM form_encounter AS fe left join billing AS b on " .
1028 "b.pid = ? AND b.activity = 1 AND " .//AND b.billed = 0
1029 "b.code_type != 'TAX' AND b.fee != 0 " .
1030 "AND fe.pid = b.pid AND fe.encounter = b.encounter " .
1031 "where fe.pid = ? " .
1032 "ORDER BY b.encounter";
1033 $bres = sqlStatement($query,array($pid,$pid));
1035 while ($brow = sqlFetchArray($bres)) {
1036 $key = 0 - $brow['encounter'];
1037 if (empty($encs[$key])) {
1038 $encs[$key] = array(
1039 'encounter' => $brow['encounter'],
1040 'date' => $brow['encdate'],
1041 'last_level_closed' => $brow['last_level_closed'],
1045 if ($brow['code_type'] === 'COPAY') {
1046 //$encs[$key]['payments'] -= $brow['fee'];
1048 $encs[$key]['charges'] +
= $brow['fee'];
1051 $query = "SELECT taxrates FROM codes WHERE " .
1052 "code_type = ? AND " .
1054 array_push($sql_array,$code_types[$brow['code_type']]['id'],$brow['code']);
1055 if ($brow['modifier']) {
1056 $query .= "modifier = ?";
1057 array_push($sql_array,$brow['modifier']);
1059 $query .= "(modifier IS NULL OR modifier = '')";
1061 $query .= " LIMIT 1";
1062 $trow = sqlQuery($query,$sql_array);
1063 $encs[$key]['charges'] +
= calcTaxes($trow, $brow['fee']);
1067 // Do the same for unbilled product sales.
1069 $query = "SELECT fe.encounter, s.drug_id, s.fee, " .
1070 "LEFT(fe.date, 10) AS encdate,fe.last_level_closed " .
1071 "FROM form_encounter AS fe left join drug_sales AS s " .
1072 "on s.pid = ? AND s.fee != 0 " .//AND s.billed = 0
1073 "AND fe.pid = s.pid AND fe.encounter = s.encounter " .
1074 "where fe.pid = ? " .
1075 "ORDER BY s.encounter";
1077 $dres = sqlStatement($query,array($pid,$pid));
1079 while ($drow = sqlFetchArray($dres)) {
1080 $key = 0 - $drow['encounter'];
1081 if (empty($encs[$key])) {
1082 $encs[$key] = array(
1083 'encounter' => $drow['encounter'],
1084 'date' => $drow['encdate'],
1085 'last_level_closed' => $drow['last_level_closed'],
1089 $encs[$key]['charges'] +
= $drow['fee'];
1091 $trow = sqlQuery("SELECT taxrates FROM drug_templates WHERE drug_id = ? " .
1092 "ORDER BY selector LIMIT 1", array($drow['drug_id']) );
1093 $encs[$key]['charges'] +
= calcTaxes($trow, $drow['fee']);
1096 ksort($encs, SORT_NUMERIC
);
1098 //Bringing on top the Today always
1099 foreach ($encs as $key => $value) {
1100 $dispdate = $value['date'];
1101 if (strcmp($dispdate, $today) == 0 && !$gottoday) {
1107 // If no billing was entered yet for today, then generate a line for
1108 // entering today's co-pay.
1111 echoLine("form_upay[0]", date("Y-m-d"), 0, 0, 0, 0 /*$duept*/);//No encounter yet defined.
1115 foreach ($encs as $key => $value) {
1116 $enc = $value['encounter'];
1117 $dispdate = $value['date'];
1118 if (strcmp($dispdate, $today) == 0 && !$gottoday) {
1119 $dispdate = date("Y-m-d");
1122 //------------------------------------------------------------------------------------
1123 $inscopay = getCopay($pid, $dispdate);
1124 $patcopay = getPatientCopay($pid, $enc);
1127 $drow = sqlQuery("SELECT SUM(pay_amount) AS payments, " .
1128 "SUM(adj_amount) AS adjustments FROM ar_activity WHERE " .
1129 "pid = ? and encounter = ? and " .
1130 "payer_type != 0 and account_code!='PCP' ",
1132 $dpayment=$drow['payments'];
1133 $dadjustment=$drow['adjustments'];
1136 $drow = sqlQuery("SELECT SUM(pay_amount) AS payments, " .
1137 "SUM(adj_amount) AS adjustments FROM ar_activity WHERE " .
1138 "pid = ? and encounter = ? and " .
1139 "payer_type = 0 and account_code!='PCP' ",
1141 $dpayment_pat=$drow['payments'];
1143 //------------------------------------------------------------------------------------
1145 $ResultNumberOfInsurance = sqlStatement("SELECT COUNT( DISTINCT TYPE ) NumberOfInsurance FROM insurance_data
1146 where pid = ? and provider>0 ",array($pid));
1147 $RowNumberOfInsurance = sqlFetchArray($ResultNumberOfInsurance);
1148 $NumberOfInsurance=$RowNumberOfInsurance['NumberOfInsurance']*1;
1149 //------------------------------------------------------------------------------------
1151 if((($NumberOfInsurance==0 ||
$value['last_level_closed']==4 ||
$NumberOfInsurance== $value['last_level_closed'])))
1153 $brow = sqlQuery("SELECT SUM(fee) AS amount FROM billing WHERE " .
1154 "pid = ? and encounter = ? AND activity = 1",array($pid,$enc));
1155 $srow = sqlQuery("SELECT SUM(fee) AS amount FROM drug_sales WHERE " .
1156 "pid = ? and encounter = ? ",array($pid,$enc));
1157 $drow = sqlQuery("SELECT SUM(pay_amount) AS payments, " .
1158 "SUM(adj_amount) AS adjustments FROM ar_activity WHERE " .
1159 "pid = ? and encounter = ? ",array($pid,$enc));
1160 $duept= $brow['amount'] +
$srow['amount'] - $drow['payments'] - $drow['adjustments'];
1162 echoLine("form_upay[$enc]", $dispdate, $value['charges'],
1163 $dpayment_pat, ($dpayment +
$dadjustment), $duept,$enc,$inscopay,$patcopay);
1168 // Continue with display of the data entry form.
1171 <tr bgcolor
="#cccccc">
1172 <td
class="dehead" id
='td_total_1'></td
>
1173 <td
class="dehead" id
='td_total_2'></td
>
1174 <td
class="dehead" id
='td_total_3'></td
>
1175 <td
class="dehead" id
='td_total_4'></td
>
1176 <td
class="dehead" id
='td_total_5'></td
>
1177 <td
class="dehead" id
='td_total_6'></td
>
1178 <td
class="dehead" id
='td_total_7'></td
>
1179 <td
class="dehead" id
='td_total_8'></td
>
1180 <td
class="dehead" align
="right">
1181 <?php
echo htmlspecialchars( xl('Total'), ENT_QUOTES
);?
>
1183 <td
class="dehead" align
="right">
1184 <input type
='text' name
='form_paytotal' value
=''
1185 style
='color:#00aa00;width:50px' readonly
/>
1192 <input type
='submit' name
='form_save' value
='<?php echo htmlspecialchars( xl('Generate Invoice
'), ENT_QUOTES);?>' />  
;
1193 <input type
='button' value
='<?php echo xla('Cancel
'); ?>' onclick
='window.close()' />
1195 <input type
="hidden" name
="hidden_patient_code" id
="hidden_patient_code" value
="<?php echo attr($pid);?>"/>
1196 <input type
='hidden' name
='ajax_mode' id
='ajax_mode' value
='' />
1197 <input type
='hidden' name
='mode' id
='mode' value
='' />
1199 <script language
="JavaScript">