changes to prior commit for coding standards compliance
[openemr.git] / portal / portal_payment.php
blob648c0fa3b13d9438baafa1c7ccdd26ae8d7719f3
1 <?php
2 /**
4 * namespace OnsitePortal
6 * Copyright (C) 2006-2015 Rod Roark <rod@sunsetsystems.com>
7 * Copyright (C) 2016-2017 Jerry Padgett <sjpadgett@gmail.com>
9 * LICENSE: This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 3
12 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
20 * @package OpenEMR
21 * @author Rod Roark <rod@sunsetsystems.com>
22 * @author Jerry Padgett <sjpadgett@gmail.com>
23 * @link http://www.open-emr.org
26 session_start();
28 if( isset( $_SESSION['pid'] ) && isset( $_SESSION['patient_portal_onsite_two'] ) ){
29 $pid = $_SESSION['pid'];
30 $ignoreAuth = true;
31 $fake_register_globals=false;
32 $sanitize_all_escapes=true;
33 require_once ( dirname( __FILE__ ) . "/../interface/globals.php" );
34 } else{
35 session_destroy();
36 $ignoreAuth = false;
37 $sanitize_all_escapes = true;
38 $fake_register_globals = false;
39 require_once ( dirname( __FILE__ ) . "/../interface/globals.php" );
40 if( ! isset( $_SESSION['authUserID'] ) ){
41 $landingpage = "index.php";
42 header( 'Location: ' . $landingpage );
43 exit();
46 require_once ( dirname( __FILE__ ) . "/lib/appsql.class.php" );
47 require_once ( "$srcdir/acl.inc" );
48 require_once ( "$srcdir/patient.inc" );
49 require_once ( "$srcdir/billing.inc" );
50 require_once ( "$srcdir/payment.inc.php" );
51 require_once ( "$srcdir/forms.inc" );
52 require_once ( "$srcdir/sl_eob.inc.php" );
53 require_once ( "$srcdir/invoice_summary.inc.php" );
54 require_once ( "../custom/code_types.inc.php" );
55 require_once ( "$srcdir/formatting.inc.php" );
56 require_once ( "$srcdir/options.inc.php" );
57 require_once ( "$srcdir/encounter_events.inc.php" );
59 $appsql = new ApplicationTable();
61 $pid = $_REQUEST['hidden_patient_code'] > 0 ? $_REQUEST['hidden_patient_code'] : $pid;
63 $edata = $appsql->getPortalAudit( $pid, 'review', 'payment' );
64 $ccdata = array();
65 $invdata = array();
67 if( $edata ){
68 $ccdata = json_decode(aes256Decrypt($edata['checksum']),true);
69 $invdata = json_decode($edata['table_args'],true);
70 echo "<script type='text/javascript'>var jsondata='" . $edata['table_args'] . "';var ccdata='" . $edata['checksum'] . "'</script>";
72 function bucks( $amount ){
73 if( $amount ){
74 $amount = oeFormatMoney( $amount );
75 return $amount;
77 return '';
79 function rawbucks( $amount ){
80 if( $amount ){
81 $amount = sprintf( "%.2f", $amount );
82 return $amount;
84 return '';
87 // Display a row of data for an encounter.
89 $var_index = 0;
90 function echoLine( $iname, $date, $charges, $ptpaid, $inspaid, $duept, $encounter = 0, $copay = 0, $patcopay = 0 ){
91 global $var_index;
92 $var_index ++;
93 $balance = bucks( $charges - $ptpaid - $inspaid );
94 $balance = ( round( $duept, 2 ) != 0 ) ? 0 : $balance; // if balance is due from patient, then insurance balance is displayed as zero
95 $encounter = $encounter ? $encounter : '';
96 echo " <tr id='tr_" . attr( $var_index ) . "' >\n";
97 echo " <td class='detail'>" . text( oeFormatShortDate( $date ) ) . "</td>\n";
98 echo " <td class='detail' id='" . attr( $date ) . "' align='left'>" . htmlspecialchars( $encounter, ENT_QUOTES ) . "</td>\n";
99 echo " <td class='detail' align='center' id='td_charges_$var_index' >" . htmlspecialchars( bucks( $charges ), ENT_QUOTES ) . "</td>\n";
100 echo " <td class='detail' align='center' id='td_inspaid_$var_index' >" . htmlspecialchars( bucks( $inspaid * - 1 ), ENT_QUOTES ) . "</td>\n";
101 echo " <td class='detail' align='center' id='td_ptpaid_$var_index' >" . htmlspecialchars( bucks( $ptpaid * - 1 ), ENT_QUOTES ) . "</td>\n";
102 echo " <td class='detail' align='center' id='td_patient_copay_$var_index' >" . htmlspecialchars( bucks( $patcopay ), ENT_QUOTES ) . "</td>\n";
103 echo " <td class='detail' align='center' id='td_copay_$var_index' >" . htmlspecialchars( bucks( $copay ), ENT_QUOTES ) . "</td>\n";
104 echo " <td class='detail' align='center' id='balance_$var_index'>" . htmlspecialchars( bucks( $balance ), ENT_QUOTES ) . "</td>\n";
105 echo " <td class='detail' align='center' id='duept_$var_index'>" . htmlspecialchars( bucks( round( $duept, 2 ) * 1 ), ENT_QUOTES ) . "</td>\n";
106 echo " <td class='detail' align='right'><input class='form-control' style='width:60px;padding:2px 2px;' type='text' name='" . attr( $iname ) . "' id='paying_" . attr( $var_index ) . "' " . " value='" . '' . "' onchange='coloring();calctotal()' autocomplete='off' " . "onkeyup='calctotal()'/></td>\n";
107 echo " </tr>\n";
110 // We use this to put dashes, colons, etc. back into a timestamp.
112 function decorateString( $fmt, $str ){
113 $res = '';
114 while( $fmt ){
115 $fc = substr( $fmt, 0, 1 );
116 $fmt = substr( $fmt, 1 );
117 if( $fc == '.' ){
118 $res .= substr( $str, 0, 1 );
119 $str = substr( $str, 1 );
120 } else{
121 $res .= $fc;
124 return $res;
127 // Compute taxes from a tax rate string and a possibly taxable amount.
129 function calcTaxes( $row, $amount ){
130 $total = 0;
131 if( empty( $row['taxrates'] ) ) return $total;
132 $arates = explode( ':', $row['taxrates'] );
133 if( empty( $arates ) ) return $total;
134 foreach( $arates as $value ){
135 if( empty( $value ) ) continue;
136 $trow = sqlQuery( "SELECT option_value FROM list_options WHERE " . "list_id = 'taxrate' AND option_id = ? LIMIT 1", array ($value
137 ) );
138 if( empty( $trow['option_value'] ) ){
139 echo "<!-- Missing tax rate '" . text( $value ) . "'! -->\n";
140 continue;
142 $tax = sprintf( "%01.2f", $amount * $trow['option_value'] );
143 // echo "<!-- Rate = '$value', amount = '$amount', tax = '$tax' -->\n";
144 $total += $tax;
146 return $total;
149 $now = time();
150 $today = date( 'Y-m-d', $now );
151 $timestamp = date( 'Y-m-d H:i:s', $now );
154 // $patdata = getPatientData($pid, 'fname,lname,pubpid');
156 $patdata = sqlQuery( "SELECT " . "p.fname, p.mname, p.lname, p.pubpid,p.pid, i.copay " . "FROM patient_data AS p " . "LEFT OUTER JOIN insurance_data AS i ON " . "i.pid = p.pid AND i.type = 'primary' " . "WHERE p.pid = ? ORDER BY i.date DESC LIMIT 1", array ($pid
157 ) );
159 $alertmsg = ''; // anything here pops up in an alert box
161 // If the Save button was clicked...
162 if( $_POST['form_save'] ){
163 // $extra = json_decode($_POST['ajax_mode'], true);
164 $form_pid = $_POST['form_pid'];
165 $form_method = trim( $_POST['form_method'] );
166 $form_source = trim( $_POST['form_source'] );
167 $patdata = getPatientData( $form_pid, 'fname,mname,lname,pubpid' );
168 $NameNew = $patdata['fname'] . " " . $patdata['lname'] . " " . $patdata['mname'];
170 if( $_REQUEST['radio_type_of_payment'] == 'pre_payment' ){
171 $payment_id = idSqlStatement( "insert into ar_session set " . "payer_id = ?" . ", patient_id = ?" . ", user_id = ?" . ", closed = ?" . ", reference = ?" . ", check_date = now() , deposit_date = now() " . ", pay_total = ?" . ", payment_type = 'patient'" . ", description = ?" . ", adjustment_code = 'pre_payment'" . ", post_to_date = now() " . ", payment_method = ?", array (
172 0,$form_pid,$_SESSION['authUserID'],0,$form_source,$_REQUEST['form_prepayment'],$NameNew,$form_method
173 ) );
175 frontPayment( $form_pid, 0, $form_method, $form_source, $_REQUEST['form_prepayment'], 0, $timestamp ); // insertion to 'payments' table.
178 if( $_POST['form_upay'] && $_REQUEST['radio_type_of_payment'] != 'pre_payment' ){
179 foreach( $_POST['form_upay'] as $enc => $payment ){
180 if( $amount = 0 + $payment ){
181 $zero_enc = $enc;
182 if( $_REQUEST['radio_type_of_payment'] == 'invoice_balance' ){
184 } else{
185 if( ! $enc ){
186 $enc = calendar_arrived( $form_pid );
189 // ----------------------------------------------------------------------------------------------------
190 // Fetching the existing code and modifier
191 $ResultSearchNew = sqlStatement( "SELECT * FROM billing LEFT JOIN code_types ON billing.code_type=code_types.ct_key " . "WHERE code_types.ct_fee=1 AND billing.activity!=0 AND billing.pid =? AND encounter=? ORDER BY billing.code,billing.modifier", array ($form_pid,$enc
192 ) );
193 if( $RowSearch = sqlFetchArray( $ResultSearchNew ) ){
194 $Codetype = $RowSearch['code_type'];
195 $Code = $RowSearch['code'];
196 $Modifier = $RowSearch['modifier'];
197 } else{
198 $Codetype = '';
199 $Code = '';
200 $Modifier = '';
202 // ----------------------------------------------------------------------------------------------------
203 if( $_REQUEST['radio_type_of_payment'] == 'copay' ) // copay saving to ar_session and ar_activity tables
205 $session_id = idSqlStatement( "INSERT INTO ar_session (payer_id,user_id,reference,check_date,deposit_date,pay_total," . " global_amount,payment_type,description,patient_id,payment_method,adjustment_code,post_to_date) " . " VALUES ('0',?,?,now(),now(),?,'','patient','COPAY',?,?,'patient_payment',now())", array (
206 $_SESSION['authId'],$form_source,$amount,$form_pid,$form_method
207 ) );
209 $insrt_id = idSqlStatement( "INSERT INTO ar_activity (pid,encounter,code_type,code,modifier,payer_type,post_time,post_user,session_id,pay_amount,account_code)" . " VALUES (?,?,?,?,?,0,now(),?,?,?,'PCP')", array ($form_pid,$enc,$Codetype,$Code,$Modifier,'3',$session_id,$amount
210 ) );
212 frontPayment( $form_pid, $enc, $form_method, $form_source, $amount, 0, $timestamp ); // insertion to 'payments' table.
214 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.
215 if( $_REQUEST['radio_type_of_payment'] == 'cash' ){
216 sqlStatement( "update form_encounter set last_level_closed=? where encounter=? and pid=? ", array (4,$enc,$form_pid
217 ) );
218 sqlStatement( "update billing set billed=? where encounter=? and pid=?", array (1,$enc,$form_pid
219 ) );
221 $adjustment_code = 'patient_payment';
222 $payment_id = idSqlStatement( "insert into ar_session set " . "payer_id = ?" . ", patient_id = ?" . ", user_id = ?" . ", closed = ?" . ", reference = ?" . ", check_date = now() , deposit_date = now() " . ", pay_total = ?" . ", payment_type = 'patient'" . ", description = ?" . ", adjustment_code = ?" . ", post_to_date = now() " . ", payment_method = ?", array (
223 0,$form_pid,$_SESSION['authUserID'],0,$form_source,$amount,$NameNew,$adjustment_code,$form_method
224 ) );
226 // --------------------------------------------------------------------------------------------------------------------
228 frontPayment( $form_pid, $enc, $form_method, $form_source, 0, $amount, $timestamp ); // insertion to 'payments' table.
230 // --------------------------------------------------------------------------------------------------------------------
232 $resMoneyGot = sqlStatement( "SELECT sum(pay_amount) as PatientPay FROM ar_activity where pid =? and " . "encounter =? and payer_type=0 and account_code='PCP'", array ($form_pid,$enc
233 ) ); // new fees screen copay gives account_code='PCP'
234 $rowMoneyGot = sqlFetchArray( $resMoneyGot );
235 $Copay = $rowMoneyGot['PatientPay'];
237 // --------------------------------------------------------------------------------------------------------------------
239 // Looping the existing code and modifier
240 $ResultSearchNew = sqlStatement( "SELECT * FROM billing LEFT JOIN code_types ON billing.code_type=code_types.ct_key WHERE code_types.ct_fee=1 " . "AND billing.activity!=0 AND billing.pid =? AND encounter=? ORDER BY billing.code,billing.modifier", array ($form_pid,$enc
241 ) );
242 while( $RowSearch = sqlFetchArray( $ResultSearchNew ) ){
243 $Codetype = $RowSearch['code_type'];
244 $Code = $RowSearch['code'];
245 $Modifier = $RowSearch['modifier'];
246 $Fee = $RowSearch['fee'];
248 $resMoneyGot = sqlStatement( "SELECT sum(pay_amount) as MoneyGot FROM ar_activity where pid =? " . "and code_type=? and code=? and modifier=? and encounter =? and !(payer_type=0 and account_code='PCP')", array ($form_pid,$Codetype,$Code,$Modifier,$enc
249 ) );
250 // new fees screen copay gives account_code='PCP'
251 $rowMoneyGot = sqlFetchArray( $resMoneyGot );
252 $MoneyGot = $rowMoneyGot['MoneyGot'];
254 $resMoneyAdjusted = sqlStatement( "SELECT sum(adj_amount) as MoneyAdjusted FROM ar_activity where " . "pid =? and code_type=? and code=? and modifier=? and encounter =?", array ($form_pid,$Codetype,$Code,$Modifier,$enc
255 ) );
256 $rowMoneyAdjusted = sqlFetchArray( $resMoneyAdjusted );
257 $MoneyAdjusted = $rowMoneyAdjusted['MoneyAdjusted'];
259 $Remainder = $Fee - $Copay - $MoneyGot - $MoneyAdjusted;
260 $Copay = 0;
261 if( round( $Remainder, 2 ) != 0 && $amount != 0 ){
262 if( $amount - $Remainder >= 0 ){
263 $insert_value = $Remainder;
264 $amount = $amount - $Remainder;
265 } else{
266 $insert_value = $amount;
267 $amount = 0;
269 sqlStatement( "insert into ar_activity set " . "pid = ?" . ", encounter = ?" . ", code_type = ?" . ", code = ?" . ", modifier = ?" . ", payer_type = ?" . ", post_time = now() " . ", post_user = ?" . ", session_id = ?" . ", pay_amount = ?" . ", adj_amount = ?" . ", account_code = 'PP'", array (
270 $form_pid,$enc,$Codetype,$Code,$Modifier,0,3,$payment_id,$insert_value,0
271 ) );
272 } // if
273 } // while
274 if( $amount != 0 ){ // if any excess is there.
275 sqlStatement( "insert into ar_activity set " . "pid = ?" . ", encounter = ?" . ", code_type = ?" . ", code = ?" . ", modifier = ?" . ", payer_type = ?" . ", post_time = now() " . ", post_user = ?" . ", session_id = ?" . ", pay_amount = ?" . ", adj_amount = ?" . ", account_code = 'PP'", array (
276 $form_pid,$enc,$Codetype,$Code,$Modifier,0,3,$payment_id,$amount,0
277 ) );
279 // --------------------------------------------------------------------------------------------------------------------
280 } // invoice_balance
281 } // if ($amount = 0 + $payment)
282 } // foreach
283 } // if ($_POST['form_upay'])
284 } // if ($_POST['form_save'])
286 if( $_POST['form_save'] || $_REQUEST['receipt']){
288 if( $_REQUEST['receipt'] ){
289 $form_pid = $_GET['patient'];
290 $timestamp = decorateString( '....-..-.. ..:..:..', $_GET['time'] );
293 // Get details for what we guess is the primary facility.
294 $frow = sqlQuery( "SELECT * FROM facility " . "ORDER BY billing_location DESC, accepts_assignment DESC, id LIMIT 1" );
296 // Get the patient's name and chart number.
297 $patdata = getPatientData( $form_pid, 'fname,mname,lname,pubpid' );
299 // Re-fetch payment info.
300 $payrow = sqlQuery( "SELECT " . "SUM(amount1) AS amount1, " . "SUM(amount2) AS amount2, " . "MAX(method) AS method, " . "MAX(source) AS source, " . "MAX(dtime) AS dtime, " .
301 // "MAX(user) AS user " .
302 "MAX(user) AS user, " . "MAX(encounter) as encounter " . "FROM payments WHERE " . "pid = ? AND dtime = ?", array ($form_pid,$timestamp
303 ) );
305 // Create key for deleting, just in case.
306 $ref_id = ( $_REQUEST['radio_type_of_payment'] == 'copay' ) ? $session_id : $payment_id;
307 $payment_key = $form_pid . '.' . preg_replace( '/[^0-9]/', '', $timestamp ) . '.' . $ref_id;
309 // get facility from encounter
310 $tmprow = sqlQuery( "
311 SELECT facility_id
312 FROM form_encounter
313 WHERE encounter = ?", array ($payrow['encounter']
314 ) );
315 $frow = sqlQuery( "SELECT * FROM facility " . " WHERE id = ?", array ($tmprow['facility_id']
316 ) );
318 // Now proceed with printing the receipt.
321 <title><?php echo xlt('Receipt for Payment'); ?></title>
323 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-11-3/index.js"></script>
324 <script type="text/javascript">
325 $( document ).ready();
326 function goHome(){
327 window.location.replace("./patient/onsiteactivityviews");
329 function notifyPatient(){
330 var pid = <?php echo attr($pid);?>;
331 var note = $('#pop_receipt').text();
332 var formURL = './messaging/handle_note.php';
333 $.ajax({
334 url: formURL,
335 type: "POST",
336 data: {'task':'add', 'pid':pid, 'inputBody':note, 'title':'Bill/Collect', 'sendto':'-patient-','noteid':'0'},
337 success: function(data, textStatus, jqXHR) {
338 alert('Receipt sent to patient via Messages.')
340 error: function(jqXHR, status, error) {
341 console.log(status + ": " + error);
345 </script>
346 <?php
347 ob_start();
348 echo '<htlm><head></head><body style="text-align: center; margin: auto;">';
351 <div id='pop_receipt' style='display: block'>
353 <h2><?php echo xlt('Receipt for Payment'); ?></h2>
354 <p><?php echo text($frow['name'])?>
355 <br><?php echo text($frow['street'])?>
356 <br><?php echo text( $frow['city'] . ', ' . $frow['state'] ) . ' ' . text( $frow['postal_code'] )?>
357 <br><?php echo htmlentities($frow['phone'])?>
359 <div style="text-align: center; margin: auto;">
360 <table border='0' cellspacing='8'
361 style="text-align: center; margin: auto;">
362 <tr>
363 <td><?php echo xlt('Date'); ?>:</td>
364 <td><?php echo text(oeFormatSDFT(strtotime($payrow['dtime']))) ?></td>
365 </tr>
366 <tr>
367 <td><?php echo xlt('Patient'); ?>:</td>
368 <td><?php echo text( $patdata['fname'] ) . " " . text( $patdata['mname'] ) . " " . text( $patdata['lname'] ) . " (" . text( $patdata['pubpid'] ) . ")"?></td>
369 </tr>
370 <tr>
371 <td><?php echo xlt('Paid Via'); ?>:</td>
372 <td><?php echo generate_display_field(array('data_type'=>'1','list_id'=>'payment_method'),$payrow['method']); ?></td>
373 </tr>
374 <tr>
375 <td><?php echo xlt('Authorized Id'); ?>:</td>
376 <td><?php echo text($payrow['source']) ?></td>
377 </tr>
378 <tr>
379 <td><?php echo xlt('Amount for This Visit'); ?>:</td>
380 <td><?php echo text(oeFormatMoney($payrow['amount1'])) ?></td>
381 </tr>
382 <tr>
383 <td><?php echo xlt('Amount for Past Balance'); ?>:</td>
384 <td><?php echo text(oeFormatMoney($payrow['amount2'])) ?></td>
385 </tr>
386 <tr>
387 <td><?php echo xlt('Received By'); ?>:</td>
388 <td><?php echo text($payrow['user']) ?></td>
389 </tr>
390 </table>
391 </div>
392 </div>
393 <button class='btn btn-sm' type='button' onclick='goHome()' id='returnhome'><?php echo xla('Return Home'); ?></button>
394 <button class='btn btn-sm' type='button' onclick="notifyPatient()"><?php echo xla('Notify Patient'); ?></button>
395 </body></html>
396 <?php
397 ob_end_flush();
398 } else{
400 // Here we display the form for data entry.
403 <title><?php echo xlt('Record Payment'); ?></title>
404 <style type="text/css">
405 body {
406 /* font-family:sans-serif; font-size:10pt; font-weight:normal */
409 .dehead {
410 color: #000000; /*font-family:sans-serif; font-size:10pt;*/
411 font-weight: bold
414 .detail {
415 padding: 1px 1px;
416 /* width: 65px; */
417 color: #000000; /*font-family:sans-serif; font-size:10pt; */
418 font-weight: normal
420 </style>
421 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-creditcardvalidator-1-1-0/jquery.creditCardValidator.js"></script>
422 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/textformat.js?v=<?php echo $v_js_includes; ?>"></script>
424 <script type="text/javascript">
425 var mypcc = '1';
426 function calctotal() {
427 var flag=0;
428 var f = document.forms["payfrm"];
429 var total = 0;
430 for (var i = 0; i < f.elements.length; ++i) {
431 var elem = f.elements[i];
432 var ename = elem.name;
433 if (ename.indexOf('form_upay[') == 0 || ename.indexOf('form_bpay[') == 0) {
434 if (elem.value.length > 0){
435 total += Number(elem.value);
436 if(total < 0) flag=1;
440 f.form_paytotal.value = Number(total).toFixed(2);
441 if(flag){
442 $('#payfrm')[0].reset();
443 alert("<?php echo addslashes( xl('Negative payments not accepted')) ?>")
445 return true;
447 function coloring()
449 for (var i = 1; ; ++i)
451 if(document.getElementById('paying_'+i))
453 paying=document.getElementById('paying_'+i).value*1;
454 patient_balance=document.getElementById('duept_'+i).innerHTML*1;
455 //balance=document.getElementById('balance_'+i).innerHTML*1;
456 if(patient_balance>0 && paying>0)
458 if(paying>patient_balance)
460 document.getElementById('paying_'+i).style.background='#FF0000';
462 else if(paying<patient_balance)
464 document.getElementById('paying_'+i).style.background='#99CC00';
466 else if(paying==patient_balance)
468 document.getElementById('paying_'+i).style.background='#ffffff';
471 else
473 document.getElementById('paying_'+i).style.background='#ffffff';
476 else
478 break;
482 function CheckVisible(MakeBlank)
483 {//Displays and hides the check number text box.
484 if(document.getElementById('form_method').options[document.getElementById('form_method').selectedIndex].value=='check_payment' ||
485 document.getElementById('form_method').options[document.getElementById('form_method').selectedIndex].value=='bank_draft' )
487 document.getElementById('check_number').disabled=false;
489 else
491 document.getElementById('check_number').disabled=true;
494 function validate()
496 var f = document.forms["payfrm"];
497 ok=-1;
498 //no checks taken here....
499 issue='no';
500 /*if(((document.getElementById('form_method').options[document.getElementById('form_method').selectedIndex].value=='check_payment' ||
501 document.getElementById('form_method').options[document.getElementById('form_method').selectedIndex].value=='bank_draft') &&
502 document.getElementById('check_number').value=='' ))
504 alert("<?php //echo addslashes( xl('Please Fill the Check/Ref Number')) ?>");
505 document.getElementById('check_number').focus();
506 return false;
509 if(document.getElementById('radio_type_of_payment_self1').checked==false &&
510 document.getElementById('radio_type_of_payment1').checked==false
511 && document.getElementById('radio_type_of_payment2').checked==false
512 && document.getElementById('radio_type_of_payment4').checked==false)
514 alert("<?php //echo addslashes( xl('Please Select Type Of Payment.')) ?>");
515 return false;
517 if(document.getElementById('radio_type_of_payment_self1').checked==true || document.getElementById('radio_type_of_payment1').checked==true)
519 for (var i = 0; i < f.elements.length; ++i)
521 var elem = f.elements[i];
522 var ename = elem.name;
523 if (ename.indexOf('form_upay[0') == 0) //Today is this text box.
525 if(elem.value*1>0)
526 {//A warning message, if the amount is posted with out encounter.
527 if(confirm("<?php echo addslashes( xl('Are you sure to post for today?')) ?>"))
529 ok=1;
531 else
533 elem.focus();
534 return false;
537 break;
541 //CO-PAY
542 /* if(document.getElementById('radio_type_of_payment1').checked==true)
544 var total = 0;
545 for (var i = 0; i < f.elements.length; ++i)
547 var elem = f.elements[i];
548 var ename = elem.name;
549 if (ename.indexOf('form_upay[') == 0) //Today is this text box.
551 if(f.form_paytotal.value*1!=elem.value*1)//Total CO-PAY is not posted against today
552 {//A warning message, if the amount is posted against an old encounter.
553 if(confirm("<?php //echo addslashes( xl('You are posting against an old encounter?')) ?>"))
555 ok=1;
557 // else
559 elem.focus();
560 return false;
563 break;
566 }*///Co Pay
567 else if( document.getElementsByName('form_paytotal')[0].value <= 0 )//total 0
569 alert("<?php echo addslashes( xl('Invalid Total!')) ?>")
570 return false;
572 if(ok==-1)
574 //return true;
575 if(confirm("<?php echo addslashes( xl('Payment Validated: Save?')) ?>"))
577 return true;
579 else
581 return false;
585 function cursor_pointer()
586 {//Point the cursor to the latest encounter(Today)
587 var f = document.forms["payfrm"];
588 var total = 0;
589 for (var i = 0; i < f.elements.length; ++i)
591 var elem = f.elements[i];
592 var ename = elem.name;
593 if (ename.indexOf('form_upay[') == 0)
595 elem.focus();
596 break;
600 //=====================================================
601 function make_it_hide_enc_pay()
603 document.getElementById('td_head_insurance_payment').style.display="none";
604 document.getElementById('td_head_patient_co_pay').style.display="none";
605 document.getElementById('td_head_co_pay').style.display="none";
606 document.getElementById('td_head_insurance_balance').style.display="none";
607 for (var i = 1; ; ++i)
609 var td_inspaid_elem = document.getElementById('td_inspaid_'+i)
610 var td_patient_copay_elem = document.getElementById('td_patient_copay_'+i)
611 var td_copay_elem = document.getElementById('td_copay_'+i)
612 var balance_elem = document.getElementById('balance_'+i)
613 if (td_inspaid_elem)
615 td_inspaid_elem.style.display="none";
616 td_patient_copay_elem.style.display="none";
617 td_copay_elem.style.display="none";
618 balance_elem.style.display="none";
620 else
622 break;
625 document.getElementById('td_total_4').style.display="none";
626 document.getElementById('td_total_7').style.display="none";
627 document.getElementById('td_total_8').style.display="none";
628 document.getElementById('td_total_6').style.display="none";
630 document.getElementById('table_display').width="420px";
633 //=====================================================
634 function make_visible()
636 document.getElementById('td_head_rep_doc').style.display="";
637 document.getElementById('td_head_description').style.display="";
638 document.getElementById('td_head_total_charge').style.display="none";
639 document.getElementById('td_head_insurance_payment').style.display="none";
640 document.getElementById('td_head_patient_payment').style.display="none";
641 document.getElementById('td_head_patient_co_pay').style.display="none";
642 document.getElementById('td_head_co_pay').style.display="none";
643 document.getElementById('td_head_insurance_balance').style.display="none";
644 document.getElementById('td_head_patient_balance').style.display="none";
645 for (var i = 1; ; ++i)
647 var td_charges_elem = document.getElementById('td_charges_'+i)
648 var td_inspaid_elem = document.getElementById('td_inspaid_'+i)
649 var td_ptpaid_elem = document.getElementById('td_ptpaid_'+i)
650 var td_patient_copay_elem = document.getElementById('td_patient_copay_'+i)
651 var td_copay_elem = document.getElementById('td_copay_'+i)
652 var balance_elem = document.getElementById('balance_'+i)
653 var duept_elem = document.getElementById('duept_'+i)
654 if (td_charges_elem)
656 td_charges_elem.style.display="none";
657 td_inspaid_elem.style.display="none";
658 td_ptpaid_elem.style.display="none";
659 td_patient_copay_elem.style.display="none";
660 td_copay_elem.style.display="none";
661 balance_elem.style.display="none";
662 duept_elem.style.display="none";
664 else
666 break;
669 document.getElementById('td_total_7').style.display="";
670 document.getElementById('td_total_8').style.display="";
671 document.getElementById('td_total_1').style.display="none";
672 document.getElementById('td_total_2').style.display="none";
673 document.getElementById('td_total_3').style.display="none";
674 document.getElementById('td_total_4').style.display="none";
675 document.getElementById('td_total_5').style.display="none";
676 document.getElementById('td_total_6').style.display="none";
678 document.getElementById('table_display').width="505px";
680 function make_it_hide()
682 document.getElementById('td_head_rep_doc').style.display="none";
683 document.getElementById('td_head_description').style.display="none";
684 document.getElementById('td_head_total_charge').style.display="";
685 document.getElementById('td_head_insurance_payment').style.display="";
686 document.getElementById('td_head_patient_payment').style.display="";
687 document.getElementById('td_head_patient_co_pay').style.display="";
688 document.getElementById('td_head_co_pay').style.display="";
689 document.getElementById('td_head_insurance_balance').style.display="";
690 document.getElementById('td_head_patient_balance').style.display="";
691 for (var i = 1; ; ++i)
693 var td_charges_elem = document.getElementById('td_charges_'+i)
694 var td_inspaid_elem = document.getElementById('td_inspaid_'+i)
695 var td_ptpaid_elem = document.getElementById('td_ptpaid_'+i)
696 var td_patient_copay_elem = document.getElementById('td_patient_copay_'+i)
697 var td_copay_elem = document.getElementById('td_copay_'+i)
698 var balance_elem = document.getElementById('balance_'+i)
699 var duept_elem = document.getElementById('duept_'+i)
700 if (td_charges_elem)
702 td_charges_elem.style.display="";
703 td_inspaid_elem.style.display="";
704 td_ptpaid_elem.style.display="";
705 td_patient_copay_elem.style.display="";
706 td_copay_elem.style.display="";
707 balance_elem.style.display="";
708 duept_elem.style.display="";
710 else
712 break;
715 document.getElementById('td_total_1').style.display="";
716 document.getElementById('td_total_2').style.display="";
717 document.getElementById('td_total_3').style.display="";
718 document.getElementById('td_total_4').style.display="";
719 document.getElementById('td_total_5').style.display="";
720 document.getElementById('td_total_6').style.display="";
721 document.getElementById('td_total_7').style.display="";
722 document.getElementById('td_total_8').style.display="";
724 document.getElementById('table_display').width="100%";
726 function make_visible_radio()
728 document.getElementById('tr_radio1').style.display="";
729 document.getElementById('tr_radio2').style.display="none";
731 function make_hide_radio()
733 document.getElementById('tr_radio1').style.display="none";
734 document.getElementById('tr_radio2').style.display="";
736 function make_visible_row()
738 document.getElementById('table_display').style.display="";
739 document.getElementById('table_display_prepayment').style.display="none";
741 function make_hide_row()
743 document.getElementById('table_display').style.display="none";
744 document.getElementById('table_display_prepayment').style.display="";
746 function make_self()
748 make_visible_row();
749 make_it_hide();
750 make_it_hide_enc_pay();
751 document.getElementById('radio_type_of_payment_self1').checked=true;
752 cursor_pointer();
754 function make_insurance()
756 make_visible_row();
757 make_it_hide();
758 cursor_pointer();
759 document.getElementById('radio_type_of_payment1').checked=true;
761 //--------------------------------------------------------------------------------------------------//
762 $('#paySubmit').click( function(e) {
763 e.preventDefault()
764 $("#mode").val( "portal-save" );
765 var inv_values= JSON.stringify(getFormObj('payfrm'));
766 var extra_values=JSON.stringify(getFormObj('paycredit'));
767 var extra = "&inv_values="+inv_values+"&extra_values="+extra_values;
769 var flag = 0
770 var liburl = './lib/paylib.php';
771 $.ajax({
772 type: "POST",
773 url: liburl,
774 data: $("#payfrm").serialize()+extra,
775 beforeSend: function(xhr){
776 if( validateCC() !== true) return false;
777 if( $('#pin').val() == "" || $('#ccname').val() == "" || $('#ccyear').val() == "" || $('#ccmonth').val() == ""){
778 alert("<?php echo addslashes( xl('Invalid Credit Card Values: Please correct')) ?>")
779 return false;
781 if( validate() != true){
782 flag = 1;
783 alert("<?php echo addslashes( xl('Validation error: Fix and resubmit. This popup info is preserved!')) ?>")
784 return false;
786 $("#openPayModal .close").click()
788 error: function(qXHR, textStatus, errorThrow){
789 console.log("There was an error:"+errorThrow);
791 success: function(templateHtml, textStatus, jqXHR){
792 alert("<?php echo addslashes( xl('Payment successfully sent for authorization. You will be notified when payment is posted. Until payment is accepted and you are notified, you may resubmit this payment at anytime with new amounts or different credit card. Thank you')) ?>")
793 window.location.reload(false);
796 if(flag)
797 $("#openPayModal .close").click();
799 //---------------------------------------------------------------------------------------//
800 $("#payfrm").on('submit', function(e){
801 e.preventDefault();
802 var thisform = this;
803 $("#mode").val( "review-save" );
804 var inv_values= JSON.stringify(getFormObj('payfrm'));
805 var extra_values=JSON.stringify(getFormObj('paycredit'));
806 var extra = "&inv_values="+inv_values+"&extra_values="+extra_values;
808 var flag = 0
809 var liburl ='<?php echo $GLOBALS["webroot"] ?>/portal/lib/paylib.php';
810 $.ajax({
811 type: "POST",
812 url: liburl,
813 data: $("#payfrm").serialize()+extra,
814 beforeSend: function(xhr){
815 if( validate() != true){
816 flag = 1;
817 alert("<?php echo addslashes( xl('Validation error: Fix and resubmit. Payment values are preserved!')) ?>")
818 return false;
821 error: function(xhr, textStatus, error){
822 alert("<?php echo addslashes( xl('There is a Post error')) ?>")
823 console.log("There was an error:"+textStatus);
824 return false;
826 success: function(templateHtml, textStatus, jqXHR){
827 thisform.submit();
831 function getFormObj(formId) {
832 var formObj = {};
833 var inputs = $('#'+formId).serializeArray();
834 $.each(inputs, function (i, input) {
835 formObj[input.name] = input.value;
837 return formObj;
839 function formRepopulate(jsondata){
840 data = $.parseJSON(jsondata);
841 $.each(data, function(name, val){
842 var $el = $('[name="'+name+'"]'),
843 type = $el.attr('type');
844 switch(type){
845 case 'checkbox':
846 $el.prop('checked',true);
847 break;
848 case 'radio':
849 $el.filter('[value="'+val+'"]').prop('checked', true);
850 break;
851 default:
852 $el.val(val);
856 function getAuth(){
857 var authnum = prompt("<?php echo xlt('Please enter card comfirmation authorization') ?>", "");
858 if (authnum != null) {
859 $('#check_number').val(authnum);
862 </script>
864 <body class="body_top" onunload='imclosing()' onLoad="cursor_pointer();"
865 style="text-align: center; margin: auto;">
867 <form id="payfrm" method='post'
868 action='<?php echo $GLOBALS["webroot"] ?>/portal/portal_payment.php'>
869 <input type='hidden' name='form_pid' value='<?php echo attr($pid) ?>' />
870 <input type='hidden' name='form_save'
871 value='<?php echo xlt('Invoice');?>' />
873 <table>
874 <tr height="10">
875 <td colspan="3">&nbsp;</td>
876 </tr>
878 <tr>
879 <td colspan='3' align='center' class='text'><b><?php echo xlt('Accept Payment for'); ?>&nbsp;:&nbsp;&nbsp;<?php
881 echo htmlspecialchars( $patdata['fname'], ENT_QUOTES ) . " " . htmlspecialchars( $patdata['lname'], ENT_QUOTES ) . " " . htmlspecialchars( $patdata['mname'], ENT_QUOTES ) . " (" . htmlspecialchars( $patdata['pid'], ENT_QUOTES ) . ")"?></b>
882 <?php $NameNew=$patdata['fname'] . " " .$patdata['lname']. " " .$patdata['mname'];?>
883 </td>
884 </tr>
885 <tr height="15">
886 <td colspan='3'></td>
887 </tr>
888 <tr>
889 <td class='text'>
890 <?php echo xlt('Payment Method'); ?>:
891 </td>
892 <td colspan='2'><select name="form_method" id="form_method"
893 class="text" onChange='CheckVisible("yes")'>
894 <?php
895 $query1112 = "SELECT * FROM list_options where list_id=? ORDER BY seq, title ";
896 $bres1112 = sqlStatement( $query1112, array ('payment_method') );
897 while( $brow1112 = sqlFetchArray( $bres1112 ) ){
898 if( $brow1112['option_id'] != 'credit_card' || $brow1112['option_id'] == 'electronic' || $brow1112['option_id'] == 'bank_draft' ) continue;
899 echo "<option value='" . htmlspecialchars( $brow1112['option_id'], ENT_QUOTES ) . "'>" . htmlspecialchars( xl_list_label( $brow1112['title'] ), ENT_QUOTES ) . "</option>";
902 </select></td>
903 </tr>
905 <tr height="5">
906 <td colspan='3'></td>
907 </tr>
909 <tr>
910 <td class='text'>
911 <?php echo xla('Authorized'); ?>:
912 </td>
913 <td colspan='2'>
914 <?php
915 if( isset( $_SESSION['authUserID'] ) )
916 echo "<input type='text' id='check_number' name='form_source' style='width:120px;' value='" . htmlspecialchars( $payrow['source'], ENT_QUOTES ) . "'>";
918 </td>
919 </tr>
920 <tr height="5">
921 <td colspan='3'></td>
922 </tr>
923 <tr>
924 <td class='text' valign="middle">
925 <?php echo xlt('Patient Coverage'); ?>:
926 </td>
927 <td class='text' colspan="2">
928 <input type="radio" name="radio_type_of_coverage" id="radio_type_of_coverage1"
929 value="self" onClick="make_visible_radio();make_self();" />
930 <?php echo xlt('Self'); ?>
931 <input type="radio" name="radio_type_of_coverage" id="radio_type_of_coverag2" value="insurance" checked="checked"
932 onClick="make_hide_radio();make_insurance();" />
933 <?php echo xlt('Insurance'); ?>
934 </td>
935 </tr>
936 <tr height="5">
937 <td colspan='3'></td>
938 </tr>
939 <tr id="tr_radio1" style="display: none">
940 <!-- For radio Insurance -->
941 <td class='text' valign="top">
942 <?php echo xlt('Payment against'); ?>:
943 </td>
944 <td class='text' colspan="2">
945 <input type="radio" name="radio_type_of_payment" id="radio_type_of_payment_self1"
946 value="cash" onClick="make_visible_row();make_it_hide_enc_pay();cursor_pointer();" />
947 <?php echo xlt('Encounter Payment'); ?>
948 </td>
949 </tr>
950 <tr id="tr_radio2">
951 <!-- For radio self -->
952 <td class='text' valign="top"><?php echo xlt('Payment against'); ?>:
953 </td>
954 <td class='text' colspan="2"><input type="radio" name="radio_type_of_payment" id="radio_type_of_payment1" checked="checked"
955 value="copay" onClick="make_visible_row();cursor_pointer();" /><?php echo xlt('Co Pay'); ?>
956 <input type="radio" name="radio_type_of_payment" id="radio_type_of_payment2"
957 value="invoice_balance" onClick="make_visible_row();" /><?php echo xlt('Invoice Balance'); ?><br />
958 <input type="radio" name="radio_type_of_payment" id="radio_type_of_payment4" value="pre_payment"
959 onClick="make_hide_row();" /><?php echo xlt('Pre Pay'); ?></td>
960 </tr>
961 <tr height="15">
962 <td colspan='3'></td>
963 </tr>
964 </table>
965 <table width="35%" border="0" cellspacing="0" cellpadding="0" id="table_display_prepayment" style="display: none">
966 <tr>
967 <td class='detail'><?php echo xlt('Pre Payment'); ?></td>
968 <td><input class="form-control" type='text' name='form_prepayment' style='width: 100px' /></td>
969 </tr>
970 </table>
971 <table id="table_display" style="width: 100%; background: #eee;" class="table table-striped table-responsive">
972 <thead>
973 </thead>
974 <tbody>
975 <!-- <table border='0' id="table_display" cellpadding='0' cellspacing='0' width='100%'> -->
976 <tr bgcolor="#cccccc" id="tr_head">
977 <td class="dehead" width="60">
978 <?php echo xlt('DOS')?>
979 </td>
980 <td class="dehead" width="120">
981 <?php echo xlt('Visit Reason')?>
982 </td>
983 <td class="dehead" align="center" width="70" id="td_head_total_charge">
984 <?php echo xlt('Total Charge')?>
985 </td>
986 <td class="dehead" align="center" width="70" id="td_head_rep_doc" style='display: none'>
987 <?php echo xlt('Report/ Form')?>
988 </td>
989 <td class="dehead" align="center" width="200" id="td_head_description" style='display: none'>
990 <?php echo xlt('Description')?>
991 </td>
992 <td class="dehead" align="center" width="70" id="td_head_insurance_payment">
993 <?php echo xlt('Insurance Payment')?>
994 </td>
995 <td class="dehead" align="center" width="70" id="td_head_patient_payment">
996 <?php echo xlt('Patient Payment')?>
997 </td>
998 <td class="dehead" align="center" width="55" id="td_head_patient_co_pay">
999 <?php echo xlt('Co Pay Paid')?>
1000 </td>
1001 <td class="dehead" align="center" width="55" id="td_head_co_pay">
1002 <?php echo xlt('Required Co Pay')?>
1003 </td>
1004 <td class="dehead" align="center" width="70" id="td_head_insurance_balance">
1005 <?php echo xlt('Insurance Balance')?>
1006 </td>
1007 <td class="dehead" align="center" width="70" id="td_head_patient_balance">
1008 <?php echo xlt('Patient Balance')?>
1009 </td>
1010 <td class="dehead" align="center" width="50">
1011 <?php echo xlt('Paying')?>
1012 </td>
1013 </tr>
1014 <?php
1015 $encs = array ();
1016 // Get the unbilled service charges and payments by encounter for this patient.
1018 $query = "SELECT fe.encounter, fe.reason, b.code_type, b.code, b.modifier, b.fee, " . "LEFT(fe.date, 10) AS encdate ,fe.last_level_closed " . "FROM form_encounter AS fe left join billing AS b on " . "b.pid = ? AND b.activity = 1 AND " . // AND b.billed = 0
1019 "b.code_type != 'TAX' AND b.fee != 0 " . "AND fe.pid = b.pid AND fe.encounter = b.encounter " . "where fe.pid = ? " . "ORDER BY b.encounter";
1020 $bres = sqlStatement( $query, array ($pid,$pid) );
1022 while( $brow = sqlFetchArray( $bres ) ){
1023 $key = 0 + $brow['encounter'];
1024 if( empty( $encs[$key] ) ){
1025 $encs[$key] = array ('encounter' => $brow['encounter'],'date' => $brow['encdate'],'last_level_closed' => $brow['last_level_closed'],'charges' => 0,'payments' => 0,'reason'=>$brow['reason']
1028 if( $brow['code_type'] === 'COPAY' ){
1029 // $encs[$key]['payments'] -= $brow['fee'];
1030 } else{
1031 $encs[$key]['charges'] += $brow['fee'];
1032 // Add taxes.
1033 $sql_array = array ();
1034 $query = "SELECT taxrates FROM codes WHERE " . "code_type = ? AND " . "code = ? AND ";
1035 array_push( $sql_array, $code_types[$brow['code_type']]['id'], $brow['code'] );
1036 if( $brow['modifier'] ){
1037 $query .= "modifier = ?";
1038 array_push( $sql_array, $brow['modifier'] );
1039 } else{
1040 $query .= "(modifier IS NULL OR modifier = '')";
1042 $query .= " LIMIT 1";
1043 $trow = sqlQuery( $query, $sql_array );
1044 $encs[$key]['charges'] += calcTaxes( $trow, $brow['fee'] );
1047 // Do the same for unbilled product sales.
1049 $query = "SELECT fe.encounter, fe.reason, s.drug_id, s.fee, " . "LEFT(fe.date, 10) AS encdate,fe.last_level_closed " . "FROM form_encounter AS fe left join drug_sales AS s " . "on s.pid = ? AND s.fee != 0 " . // AND s.billed = 0
1050 "AND fe.pid = s.pid AND fe.encounter = s.encounter " . "where fe.pid = ? " . "ORDER BY s.encounter";
1052 $dres = sqlStatement( $query, array ($pid,$pid) );
1054 while( $drow = sqlFetchArray( $dres ) ){
1055 $key = 0 + $drow['encounter'];
1056 if( empty( $encs[$key] ) ){
1057 $encs[$key] = array ('encounter' => $drow['encounter'],'date' => $drow['encdate'],'last_level_closed' => $drow['last_level_closed'],'charges' => 0,'payments' => 0
1060 $encs[$key]['charges'] += $drow['fee'];
1061 // Add taxes.
1062 $trow = sqlQuery( "SELECT taxrates FROM drug_templates WHERE drug_id = ? " . "ORDER BY selector LIMIT 1", array ($drow['drug_id']
1063 ) );
1064 $encs[$key]['charges'] += calcTaxes( $trow, $drow['fee'] );
1067 ksort( $encs, SORT_NUMERIC );
1068 $gottoday = false;
1069 // Bringing on top the Today always
1070 foreach( $encs as $key => $value ){
1071 $dispdate = $value['date'];
1072 if( strcmp( $dispdate, $today ) == 0 && ! $gottoday ){
1073 $gottoday = true;
1074 break;
1078 // If no billing was entered yet for today, then generate a line for
1079 // entering today's co-pay.
1081 if( ! $gottoday ){
1082 // echoLine("form_upay[0]", date("Y-m-d"), 0, 0, 0, 0 /*$duept*/);//No encounter yet defined.
1084 $gottoday = false;
1085 foreach( $encs as $key => $value ){
1086 $enc = $value['encounter'];
1087 $reason = $value['reason'];
1088 $dispdate = $value['date'];
1089 if( strcmp( $dispdate, $today ) == 0 && ! $gottoday ){
1090 $dispdate = date( "Y-m-d" );
1091 $gottoday = true;
1093 // ------------------------------------------------------------------------------------
1094 $inscopay = getCopay( $pid, $dispdate );
1095 $patcopay = getPatientCopay( $pid, $enc );
1096 // Insurance Payment
1097 // -----------------
1098 $drow = sqlQuery( "SELECT SUM(pay_amount) AS payments, " . "SUM(adj_amount) AS adjustments FROM ar_activity WHERE " . "pid = ? and encounter = ? and " . "payer_type != 0 and account_code!='PCP' ", array ($pid,$enc
1099 ) );
1100 $dpayment = $drow['payments'];
1101 $dadjustment = $drow['adjustments'];
1102 // Patient Payment
1103 // ---------------
1104 $drow = sqlQuery( "SELECT SUM(pay_amount) AS payments, " . "SUM(adj_amount) AS adjustments FROM ar_activity WHERE " . "pid = ? and encounter = ? and " . "payer_type = 0 and account_code!='PCP' ", array ($pid,$enc
1105 ) );
1106 $dpayment_pat = $drow['payments'];
1108 // ------------------------------------------------------------------------------------
1109 // NumberOfInsurance
1110 $ResultNumberOfInsurance = sqlStatement( "SELECT COUNT( DISTINCT TYPE ) NumberOfInsurance FROM insurance_data
1111 where pid = ? and provider>0 ", array ($pid
1112 ) );
1113 $RowNumberOfInsurance = sqlFetchArray( $ResultNumberOfInsurance );
1114 $NumberOfInsurance = $RowNumberOfInsurance['NumberOfInsurance'] * 1;
1115 // ------------------------------------------------------------------------------------
1116 $duept = 0;
1117 if( ( ( $NumberOfInsurance == 0 || $value['last_level_closed'] == 4 || $NumberOfInsurance == $value['last_level_closed'] ) ) ){ // Patient balance
1118 $brow = sqlQuery( "SELECT SUM(fee) AS amount FROM billing WHERE " . "pid = ? and encounter = ? AND activity = 1", array ($pid,$enc
1119 ) );
1120 $srow = sqlQuery( "SELECT SUM(fee) AS amount FROM drug_sales WHERE " . "pid = ? and encounter = ? ", array ($pid,$enc
1121 ) );
1122 $drow = sqlQuery( "SELECT SUM(pay_amount) AS payments, " . "SUM(adj_amount) AS adjustments FROM ar_activity WHERE " . "pid = ? and encounter = ? ", array ($pid,$enc
1123 ) );
1124 $duept = $brow['amount'] + $srow['amount'] - $drow['payments'] - $drow['adjustments'];
1126 echoLine( "form_upay[$enc]", $dispdate, $value['charges'], $dpayment_pat, ( $dpayment + $dadjustment ), $duept, ($enc.':'.$reason), $inscopay, $patcopay );
1129 // Continue with display of the data entry form.
1131 <tr>
1132 <td class="dehead" id='td_total_1'></td>
1133 <td class="dehead" id='td_total_2'></td>
1134 <td class="dehead" id='td_total_3'></td>
1135 <td class="dehead" id='td_total_4'></td>
1136 <td class="dehead" id='td_total_5'></td>
1137 <td class="dehead" id='td_total_6'></td>
1138 <td class="dehead" id='td_total_7'></td>
1139 <td class="dehead" id='td_total_8'></td>
1140 <td class="dehead" align="right"><?php echo xlt('Total');?></td>
1141 <td class="dehead" align="right"><input class="form-control" type='text' name='form_paytotal'
1142 value='' style='color: #00aa00; width: 65px; padding: 1px 1px;' readonly />
1143 </td>
1144 </tr>
1145 </table>
1146 <?php
1147 if( isset( $ccdata["name"] ) ){
1148 echo '<div class="col-xs-12 col-md-4 col-lg-4">
1149 <div class="panel panel-default height">';
1150 if( ! isset( $_SESSION['authUserID'] ) )
1151 echo '<div class="panel-heading">'.xlt("Payment Information").'<span style="color:#cc0000"><em> '.xlt("Pending Auth since").': </em>'.text($edata["date"]).'</span></div>';
1152 else
1153 echo '<div class="panel-heading">'.xlt("Payment Information").' <button type="button" class="btn btn-danger btn-sm" onclick="getAuth()">'.xlt("Authorize").'</button></div>';
1155 else{
1156 echo '<div style="display:none" class="col-xs-12 col-md-6 col-lg-6"><div class="panel panel-default height"><div class="panel-heading">'.xlt("Payment Information").' </div>';
1159 <div class="panel-body">
1160 <strong><?php echo xlt('Card Name');?>: </strong><span id="cn"><?php echo attr($ccdata["cc_type"])?></span><br>
1161 <strong><?php echo xlt('Name On Card');?>: </strong><span id="nc"><?php echo attr($ccdata["name"])?></span><br>
1162 <strong><?php echo xlt('Card Number');?>: </strong><span id="ccn"><?php
1163 if( isset( $_SESSION['authUserID'] ) )
1164 echo $ccdata["cc_number"] . "</span><br>";
1165 else
1166 echo "********** ".substr($ccdata["cc_number"],-4) . "</span><br>";
1168 <strong><?php echo xlt('Exp Date');?>: </strong><span id="ed"><?php echo attr($ccdata["month"])."/".attr($ccdata["year"])?></span><br>
1169 <strong><?php echo xlt('Charge Total');?>: </strong><span id="ct"><?php echo attr($invdata["form_paytotal"])?></span><br>
1170 </div>
1171 </div>
1172 </div>
1174 <?php
1175 if( ! isset( $_SESSION['authUserID'] ) )
1176 echo '<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#openPayModal">' . xlt("Pay Invoice") . '</button>';
1177 else
1178 echo "<button type='submit' class='btn btn-danger' form='payfrm'>" . xlt('Post Payment') . "</button>";
1180 &nbsp;
1181 </p>
1182 <input type="hidden" name="hidden_patient_code" id="hidden_patient_code" value="<?php echo attr($pid);?>" />
1183 <input type='hidden' name='mode' id='mode' value='' />
1184 </form>
1186 <script type="text/javascript">
1187 if (typeof jsondata !== 'undefined') {
1188 formRepopulate(jsondata);
1190 calctotal();
1191 </script>
1192 <!-- credit payment modal -->
1193 <div id="openPayModal" class="modal fade" role="dialog">
1194 <div class="modal-dialog">
1195 <div class="modal-content">
1196 <div class="modal-header">
1197 <h3><?php echo xlt('Submit Payment for Authorization');?></h3>
1198 <button type="button" class="close" data-dismiss="modal">&times;</button>
1199 </div>
1200 <div class="modal-body container">
1201 <form id='paycredit' class="form-horizontal col-xs-12 col-sm-6 col-md-6">
1202 <fieldset>
1203 <div class="control-group">
1204 <label label-default="label-default" class="control-label"><?php echo xlt('Name on Card');?></label>
1205 <div class="controls">
1206 <input name="name" id="ccname" type="text" class="form-control"
1207 pattern="\w+ \w+.*" title="<?php echo xla('Fill your first and last name'); ?>"
1208 required value="" />
1209 </div>
1210 </div>
1211 <div class="control-group">
1212 <label class="control-label"><?php echo xlt('Card Number');?></label>
1213 <div class="controls">
1214 <div class="row">
1215 <div class="col-sm-12">
1216 <input name="cc_number" id="cc_number" type="text" class="form-control inline col-sm-3"
1217 autocomplete="off" maxlength="19" pattern="\d" onchange="validateCC()"
1218 title="<?php echo xla('Card Number'); ?>" required value="" />
1219 <input disabled name="cardtype" id="cardtype" type="text" class="form-control inline" title="<?php echo xla('Card Type'); ?>" style="max-width:160px;font-weight:bold;color:red;" value="" />
1220 </div>
1221 </div>
1222 </div>
1223 </div>
1224 <div class="control-group">
1225 <label label-default="label-default" class="control-label"><?php echo xlt('Card Expiry Date');?></label>
1226 <div class="controls">
1227 <div class="row">
1228 <div class="col-md-4">
1229 <select name="month" id="ccmonth" class="form-control">
1230 <option value=""><?php echo xlt('Select Month'); ?></option>
1231 <option value="01"><?php echo xlt('January'); ?></option>
1232 <option value="02"><?php echo xlt('February'); ?></option>
1233 <option value="03"><?php echo xlt('March'); ?></option>
1234 <option value="04"><?php echo xlt('April'); ?></option>
1235 <option value="05"><?php echo xlt('May'); ?></option>
1236 <option value="06"><?php echo xlt('June'); ?></option>
1237 <option value="07"><?php echo xlt('July'); ?></option>
1238 <option value="08"><?php echo xlt('August'); ?></option>
1239 <option value="09"><?php echo xlt('September'); ?></option>
1240 <option value="10"><?php echo xlt('October'); ?></option>
1241 <option value="11"><?php echo xlt('November'); ?></option>
1242 <option value="12"><?php echo xlt('December'); ?></option>
1243 </select>
1244 </div>
1245 <div class="col-md-3">
1246 <select name="year" id="ccyear" class="form-control">
1247 <option value=""><?php echo xlt('Select Year'); ?></option>
1248 <option value="2017">2017</option>
1249 <option value="2018">2018</option>
1250 <option value="2019">2019</option>
1251 <option value="2020">2020</option>
1252 <option value="2021">2021</option>
1253 <option value="2022">2022</option>
1254 <option value="2023">2023</option>
1255 <option value="2024">2024</option>
1256 </select>
1257 </div>
1258 </div>
1259 </div>
1260 </div>
1261 <div class="control-group">
1262 <label label-default="label-default" class="control-label"><?php echo xlt('Card CVV');?></label>
1263 <div class="controls">
1264 <div class="row">
1265 <div class="col-md-3">
1266 <input name="pin" id="pin" type="text" class="form-control"
1267 autocomplete="off" maxlength="4" pattern="\d{3}" onfocus="validateCC()"
1268 title="<?php echo xlt('Three or four digits at back of your card'); ?>" required value="" />
1269 </div>
1270 <div class="col-md-3">
1271 <img src='./images/img_cvc.png' style='height: 58px; width: auto'>
1272 </div>
1273 </div>
1274 </div>
1275 </div>
1276 <div class="form-actions">
1277 <button id="paySubmit" class="btn btn-danger"><?php echo xlt('Submit');?></button>
1278 <button type="button" class="btn btn-default" data-dismiss="modal"><?php echo xlt('Cancel');?></button>
1279 </div>
1280 </fieldset>
1281 <input type='hidden' name='cc_type' id='cc_type' value='' />
1282 </form>
1283 </div>
1284 <!-- Body -->
1285 <div class="modal-footer">
1286 <button type="button" class="btn btn-default" data-dismiss="modal"><?php echo xlt('Close');?></button>
1287 </div>
1288 </div>
1289 </div>
1290 </div>
1291 <?php echo "<script>var ccerr='". xlt('Invalid Credit Card Number') . "';</script>";?>
1292 <script type="text/javascript">
1293 $('#cc_number').validateCreditCard(function(result){
1294 var r = (result.card_type == null ? '' : result.card_type.name.toUpperCase())
1295 var v = (result.valid== true ? ' Valid #' : ' Invalid #')
1296 $('#cardtype').val(r+v);
1298 function validateCC() {
1299 var result = $('#cc_number').validateCreditCard();
1300 var r = (result.card_type == null ? '' : result.card_type.name.toUpperCase())
1301 var v = (result.valid == true ? ' Okay' : ' Invalid #')
1302 $('#cardtype').val(r+v);
1303 $('#cc_type').val(r);
1304 if(!result.valid){
1305 alert(ccerr)
1306 return false;
1308 else{
1309 return true;
1312 </script>
1313 </body>
1314 <?php