minor improvement to tabs style
[openemr.git] / portal / portal_payment.php
blobe98e70cc0cdf873a6062d65b5e5316c846ff3ef2
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 require_once ( dirname( __FILE__ ) . "/../interface/globals.php" );
32 } else{
33 session_destroy();
34 $ignoreAuth = false;
35 require_once ( dirname( __FILE__ ) . "/../interface/globals.php" );
36 if( ! isset( $_SESSION['authUserID'] ) ){
37 $landingpage = "index.php";
38 header( 'Location: ' . $landingpage );
39 exit();
42 require_once ( dirname( __FILE__ ) . "/lib/appsql.class.php" );
43 require_once ( "$srcdir/acl.inc" );
44 require_once ( "$srcdir/patient.inc" );
45 require_once ( "$srcdir/billing.inc" );
46 require_once ( "$srcdir/payment.inc.php" );
47 require_once ( "$srcdir/forms.inc" );
48 require_once ( "$srcdir/sl_eob.inc.php" );
49 require_once ( "$srcdir/invoice_summary.inc.php" );
50 require_once ( "../custom/code_types.inc.php" );
51 require_once ( "$srcdir/formatting.inc.php" );
52 require_once ( "$srcdir/options.inc.php" );
53 require_once ( "$srcdir/encounter_events.inc.php" );
55 $appsql = new ApplicationTable();
57 $pid = $_REQUEST['hidden_patient_code'] > 0 ? $_REQUEST['hidden_patient_code'] : $pid;
59 $edata = $appsql->getPortalAudit( $pid, 'review', 'payment' );
60 $ccdata = array();
61 $invdata = array();
63 if( $edata ){
64 $ccdata = json_decode(aes256Decrypt($edata['checksum']),true);
65 $invdata = json_decode($edata['table_args'],true);
66 echo "<script type='text/javascript'>var jsondata='" . $edata['table_args'] . "';var ccdata='" . $edata['checksum'] . "'</script>";
68 function bucks( $amount ){
69 if( $amount ){
70 $amount = oeFormatMoney( $amount );
71 return $amount;
73 return '';
75 function rawbucks( $amount ){
76 if( $amount ){
77 $amount = sprintf( "%.2f", $amount );
78 return $amount;
80 return '';
83 // Display a row of data for an encounter.
85 $var_index = 0;
86 function echoLine( $iname, $date, $charges, $ptpaid, $inspaid, $duept, $encounter = 0, $copay = 0, $patcopay = 0 ){
87 global $var_index;
88 $var_index ++;
89 $balance = bucks( $charges - $ptpaid - $inspaid );
90 $balance = ( round( $duept, 2 ) != 0 ) ? 0 : $balance; // if balance is due from patient, then insurance balance is displayed as zero
91 $encounter = $encounter ? $encounter : '';
92 echo " <tr id='tr_" . attr( $var_index ) . "' >\n";
93 echo " <td class='detail'>" . text( oeFormatShortDate( $date ) ) . "</td>\n";
94 echo " <td class='detail' id='" . attr( $date ) . "' align='left'>" . htmlspecialchars( $encounter, ENT_QUOTES ) . "</td>\n";
95 echo " <td class='detail' align='center' id='td_charges_$var_index' >" . htmlspecialchars( bucks( $charges ), ENT_QUOTES ) . "</td>\n";
96 echo " <td class='detail' align='center' id='td_inspaid_$var_index' >" . htmlspecialchars( bucks( $inspaid * - 1 ), ENT_QUOTES ) . "</td>\n";
97 echo " <td class='detail' align='center' id='td_ptpaid_$var_index' >" . htmlspecialchars( bucks( $ptpaid * - 1 ), ENT_QUOTES ) . "</td>\n";
98 echo " <td class='detail' align='center' id='td_patient_copay_$var_index' >" . htmlspecialchars( bucks( $patcopay ), ENT_QUOTES ) . "</td>\n";
99 echo " <td class='detail' align='center' id='td_copay_$var_index' >" . htmlspecialchars( bucks( $copay ), ENT_QUOTES ) . "</td>\n";
100 echo " <td class='detail' align='center' id='balance_$var_index'>" . htmlspecialchars( bucks( $balance ), ENT_QUOTES ) . "</td>\n";
101 echo " <td class='detail' align='center' id='duept_$var_index'>" . htmlspecialchars( bucks( round( $duept, 2 ) * 1 ), ENT_QUOTES ) . "</td>\n";
102 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";
103 echo " </tr>\n";
106 // We use this to put dashes, colons, etc. back into a timestamp.
108 function decorateString( $fmt, $str ){
109 $res = '';
110 while( $fmt ){
111 $fc = substr( $fmt, 0, 1 );
112 $fmt = substr( $fmt, 1 );
113 if( $fc == '.' ){
114 $res .= substr( $str, 0, 1 );
115 $str = substr( $str, 1 );
116 } else{
117 $res .= $fc;
120 return $res;
123 // Compute taxes from a tax rate string and a possibly taxable amount.
125 function calcTaxes( $row, $amount ){
126 $total = 0;
127 if( empty( $row['taxrates'] ) ) return $total;
128 $arates = explode( ':', $row['taxrates'] );
129 if( empty( $arates ) ) return $total;
130 foreach( $arates as $value ){
131 if( empty( $value ) ) continue;
132 $trow = sqlQuery( "SELECT option_value FROM list_options WHERE " . "list_id = 'taxrate' AND option_id = ? LIMIT 1", array ($value
133 ) );
134 if( empty( $trow['option_value'] ) ){
135 echo "<!-- Missing tax rate '" . text( $value ) . "'! -->\n";
136 continue;
138 $tax = sprintf( "%01.2f", $amount * $trow['option_value'] );
139 // echo "<!-- Rate = '$value', amount = '$amount', tax = '$tax' -->\n";
140 $total += $tax;
142 return $total;
145 $now = time();
146 $today = date( 'Y-m-d', $now );
147 $timestamp = date( 'Y-m-d H:i:s', $now );
150 // $patdata = getPatientData($pid, 'fname,lname,pubpid');
152 $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
153 ) );
155 $alertmsg = ''; // anything here pops up in an alert box
157 // If the Save button was clicked...
158 if( $_POST['form_save'] ){
159 // $extra = json_decode($_POST['ajax_mode'], true);
160 $form_pid = $_POST['form_pid'];
161 $form_method = trim( $_POST['form_method'] );
162 $form_source = trim( $_POST['form_source'] );
163 $patdata = getPatientData( $form_pid, 'fname,mname,lname,pubpid' );
164 $NameNew = $patdata['fname'] . " " . $patdata['lname'] . " " . $patdata['mname'];
166 if( $_REQUEST['radio_type_of_payment'] == 'pre_payment' ){
167 $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 (
168 0,$form_pid,$_SESSION['authUserID'],0,$form_source,$_REQUEST['form_prepayment'],$NameNew,$form_method
169 ) );
171 frontPayment( $form_pid, 0, $form_method, $form_source, $_REQUEST['form_prepayment'], 0, $timestamp ); // insertion to 'payments' table.
174 if( $_POST['form_upay'] && $_REQUEST['radio_type_of_payment'] != 'pre_payment' ){
175 foreach( $_POST['form_upay'] as $enc => $payment ){
176 if( $amount = 0 + $payment ){
177 $zero_enc = $enc;
178 if( $_REQUEST['radio_type_of_payment'] == 'invoice_balance' ){
180 } else{
181 if( ! $enc ){
182 $enc = calendar_arrived( $form_pid );
185 // ----------------------------------------------------------------------------------------------------
186 // Fetching the existing code and modifier
187 $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
188 ) );
189 if( $RowSearch = sqlFetchArray( $ResultSearchNew ) ){
190 $Codetype = $RowSearch['code_type'];
191 $Code = $RowSearch['code'];
192 $Modifier = $RowSearch['modifier'];
193 } else{
194 $Codetype = '';
195 $Code = '';
196 $Modifier = '';
198 // ----------------------------------------------------------------------------------------------------
199 if( $_REQUEST['radio_type_of_payment'] == 'copay' ) // copay saving to ar_session and ar_activity tables
201 $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 (
202 $_SESSION['authId'],$form_source,$amount,$form_pid,$form_method
203 ) );
205 $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
206 ) );
208 frontPayment( $form_pid, $enc, $form_method, $form_source, $amount, 0, $timestamp ); // insertion to 'payments' table.
210 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.
211 if( $_REQUEST['radio_type_of_payment'] == 'cash' ){
212 sqlStatement( "update form_encounter set last_level_closed=? where encounter=? and pid=? ", array (4,$enc,$form_pid
213 ) );
214 sqlStatement( "update billing set billed=? where encounter=? and pid=?", array (1,$enc,$form_pid
215 ) );
217 $adjustment_code = 'patient_payment';
218 $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 (
219 0,$form_pid,$_SESSION['authUserID'],0,$form_source,$amount,$NameNew,$adjustment_code,$form_method
220 ) );
222 // --------------------------------------------------------------------------------------------------------------------
224 frontPayment( $form_pid, $enc, $form_method, $form_source, 0, $amount, $timestamp ); // insertion to 'payments' table.
226 // --------------------------------------------------------------------------------------------------------------------
228 $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
229 ) ); // new fees screen copay gives account_code='PCP'
230 $rowMoneyGot = sqlFetchArray( $resMoneyGot );
231 $Copay = $rowMoneyGot['PatientPay'];
233 // --------------------------------------------------------------------------------------------------------------------
235 // Looping the existing code and modifier
236 $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
237 ) );
238 while( $RowSearch = sqlFetchArray( $ResultSearchNew ) ){
239 $Codetype = $RowSearch['code_type'];
240 $Code = $RowSearch['code'];
241 $Modifier = $RowSearch['modifier'];
242 $Fee = $RowSearch['fee'];
244 $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
245 ) );
246 // new fees screen copay gives account_code='PCP'
247 $rowMoneyGot = sqlFetchArray( $resMoneyGot );
248 $MoneyGot = $rowMoneyGot['MoneyGot'];
250 $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
251 ) );
252 $rowMoneyAdjusted = sqlFetchArray( $resMoneyAdjusted );
253 $MoneyAdjusted = $rowMoneyAdjusted['MoneyAdjusted'];
255 $Remainder = $Fee - $Copay - $MoneyGot - $MoneyAdjusted;
256 $Copay = 0;
257 if( round( $Remainder, 2 ) != 0 && $amount != 0 ){
258 if( $amount - $Remainder >= 0 ){
259 $insert_value = $Remainder;
260 $amount = $amount - $Remainder;
261 } else{
262 $insert_value = $amount;
263 $amount = 0;
265 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 (
266 $form_pid,$enc,$Codetype,$Code,$Modifier,0,3,$payment_id,$insert_value,0
267 ) );
268 } // if
269 } // while
270 if( $amount != 0 ){ // if any excess is there.
271 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 (
272 $form_pid,$enc,$Codetype,$Code,$Modifier,0,3,$payment_id,$amount,0
273 ) );
275 // --------------------------------------------------------------------------------------------------------------------
276 } // invoice_balance
277 } // if ($amount = 0 + $payment)
278 } // foreach
279 } // if ($_POST['form_upay'])
280 } // if ($_POST['form_save'])
282 if( $_POST['form_save'] || $_REQUEST['receipt']){
284 if( $_REQUEST['receipt'] ){
285 $form_pid = $_GET['patient'];
286 $timestamp = decorateString( '....-..-.. ..:..:..', $_GET['time'] );
289 // Get details for what we guess is the primary facility.
290 $frow = sqlQuery( "SELECT * FROM facility " . "ORDER BY billing_location DESC, accepts_assignment DESC, id LIMIT 1" );
292 // Get the patient's name and chart number.
293 $patdata = getPatientData( $form_pid, 'fname,mname,lname,pubpid' );
295 // Re-fetch payment info.
296 $payrow = sqlQuery( "SELECT " . "SUM(amount1) AS amount1, " . "SUM(amount2) AS amount2, " . "MAX(method) AS method, " . "MAX(source) AS source, " . "MAX(dtime) AS dtime, " .
297 // "MAX(user) AS user " .
298 "MAX(user) AS user, " . "MAX(encounter) as encounter " . "FROM payments WHERE " . "pid = ? AND dtime = ?", array ($form_pid,$timestamp
299 ) );
301 // Create key for deleting, just in case.
302 $ref_id = ( $_REQUEST['radio_type_of_payment'] == 'copay' ) ? $session_id : $payment_id;
303 $payment_key = $form_pid . '.' . preg_replace( '/[^0-9]/', '', $timestamp ) . '.' . $ref_id;
305 // get facility from encounter
306 $tmprow = sqlQuery( "
307 SELECT facility_id
308 FROM form_encounter
309 WHERE encounter = ?", array ($payrow['encounter']
310 ) );
311 $frow = sqlQuery( "SELECT * FROM facility " . " WHERE id = ?", array ($tmprow['facility_id']
312 ) );
314 // Now proceed with printing the receipt.
317 <title><?php echo xlt('Receipt for Payment'); ?></title>
319 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-11-3/index.js"></script>
320 <script type="text/javascript">
321 $( document ).ready();
322 function goHome(){
323 window.location.replace("./patient/onsiteactivityviews");
325 function notifyPatient(){
326 var pid = <?php echo attr($pid);?>;
327 var note = $('#pop_receipt').text();
328 var formURL = './messaging/handle_note.php';
329 $.ajax({
330 url: formURL,
331 type: "POST",
332 data: {'task':'add', 'pid':pid, 'inputBody':note, 'title':'Bill/Collect', 'sendto':'-patient-','noteid':'0'},
333 success: function(data, textStatus, jqXHR) {
334 alert('Receipt sent to patient via Messages.')
336 error: function(jqXHR, status, error) {
337 console.log(status + ": " + error);
341 </script>
342 <?php
343 ob_start();
344 echo '<htlm><head></head><body style="text-align: center; margin: auto;">';
347 <div id='pop_receipt' style='display: block'>
349 <h2><?php echo xlt('Receipt for Payment'); ?></h2>
350 <p><?php echo text($frow['name'])?>
351 <br><?php echo text($frow['street'])?>
352 <br><?php echo text( $frow['city'] . ', ' . $frow['state'] ) . ' ' . text( $frow['postal_code'] )?>
353 <br><?php echo htmlentities($frow['phone'])?>
355 <div style="text-align: center; margin: auto;">
356 <table border='0' cellspacing='8'
357 style="text-align: center; margin: auto;">
358 <tr>
359 <td><?php echo xlt('Date'); ?>:</td>
360 <td><?php echo text(oeFormatSDFT(strtotime($payrow['dtime']))) ?></td>
361 </tr>
362 <tr>
363 <td><?php echo xlt('Patient'); ?>:</td>
364 <td><?php echo text( $patdata['fname'] ) . " " . text( $patdata['mname'] ) . " " . text( $patdata['lname'] ) . " (" . text( $patdata['pubpid'] ) . ")"?></td>
365 </tr>
366 <tr>
367 <td><?php echo xlt('Paid Via'); ?>:</td>
368 <td><?php echo generate_display_field(array('data_type'=>'1','list_id'=>'payment_method'),$payrow['method']); ?></td>
369 </tr>
370 <tr>
371 <td><?php echo xlt('Authorized Id'); ?>:</td>
372 <td><?php echo text($payrow['source']) ?></td>
373 </tr>
374 <tr>
375 <td><?php echo xlt('Amount for This Visit'); ?>:</td>
376 <td><?php echo text(oeFormatMoney($payrow['amount1'])) ?></td>
377 </tr>
378 <tr>
379 <td><?php echo xlt('Amount for Past Balance'); ?>:</td>
380 <td><?php echo text(oeFormatMoney($payrow['amount2'])) ?></td>
381 </tr>
382 <tr>
383 <td><?php echo xlt('Received By'); ?>:</td>
384 <td><?php echo text($payrow['user']) ?></td>
385 </tr>
386 </table>
387 </div>
388 </div>
389 <button class='btn btn-sm' type='button' onclick='goHome()' id='returnhome'><?php echo xla('Return Home'); ?></button>
390 <button class='btn btn-sm' type='button' onclick="notifyPatient()"><?php echo xla('Notify Patient'); ?></button>
391 </body></html>
392 <?php
393 ob_end_flush();
394 } else{
396 // Here we display the form for data entry.
399 <title><?php echo xlt('Record Payment'); ?></title>
400 <style type="text/css">
401 body {
402 /* font-family:sans-serif; font-size:10pt; font-weight:normal */
405 .dehead {
406 color: #000000; /*font-family:sans-serif; font-size:10pt;*/
407 font-weight: bold
410 .detail {
411 padding: 1px 1px;
412 /* width: 65px; */
413 color: #000000; /*font-family:sans-serif; font-size:10pt; */
414 font-weight: normal
416 </style>
417 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-creditcardvalidator-1-1-0/jquery.creditCardValidator.js"></script>
418 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/textformat.js?v=<?php echo $v_js_includes; ?>"></script>
420 <script type="text/javascript">
421 var mypcc = '1';
422 function calctotal() {
423 var flag=0;
424 var f = document.forms["payfrm"];
425 var total = 0;
426 for (var i = 0; i < f.elements.length; ++i) {
427 var elem = f.elements[i];
428 var ename = elem.name;
429 if (ename.indexOf('form_upay[') == 0 || ename.indexOf('form_bpay[') == 0) {
430 if (elem.value.length > 0){
431 total += Number(elem.value);
432 if(total < 0) flag=1;
436 f.form_paytotal.value = Number(total).toFixed(2);
437 if(flag){
438 $('#payfrm')[0].reset();
439 alert("<?php echo addslashes( xl('Negative payments not accepted')) ?>")
441 return true;
443 function coloring()
445 for (var i = 1; ; ++i)
447 if(document.getElementById('paying_'+i))
449 paying=document.getElementById('paying_'+i).value*1;
450 patient_balance=document.getElementById('duept_'+i).innerHTML*1;
451 //balance=document.getElementById('balance_'+i).innerHTML*1;
452 if(patient_balance>0 && paying>0)
454 if(paying>patient_balance)
456 document.getElementById('paying_'+i).style.background='#FF0000';
458 else if(paying<patient_balance)
460 document.getElementById('paying_'+i).style.background='#99CC00';
462 else if(paying==patient_balance)
464 document.getElementById('paying_'+i).style.background='#ffffff';
467 else
469 document.getElementById('paying_'+i).style.background='#ffffff';
472 else
474 break;
478 function CheckVisible(MakeBlank)
479 {//Displays and hides the check number text box.
480 if(document.getElementById('form_method').options[document.getElementById('form_method').selectedIndex].value=='check_payment' ||
481 document.getElementById('form_method').options[document.getElementById('form_method').selectedIndex].value=='bank_draft' )
483 document.getElementById('check_number').disabled=false;
485 else
487 document.getElementById('check_number').disabled=true;
490 function validate()
492 var f = document.forms["payfrm"];
493 ok=-1;
494 //no checks taken here....
495 issue='no';
496 /*if(((document.getElementById('form_method').options[document.getElementById('form_method').selectedIndex].value=='check_payment' ||
497 document.getElementById('form_method').options[document.getElementById('form_method').selectedIndex].value=='bank_draft') &&
498 document.getElementById('check_number').value=='' ))
500 alert("<?php //echo addslashes( xl('Please Fill the Check/Ref Number')) ?>");
501 document.getElementById('check_number').focus();
502 return false;
505 if(document.getElementById('radio_type_of_payment_self1').checked==false &&
506 document.getElementById('radio_type_of_payment1').checked==false
507 && document.getElementById('radio_type_of_payment2').checked==false
508 && document.getElementById('radio_type_of_payment4').checked==false)
510 alert("<?php //echo addslashes( xl('Please Select Type Of Payment.')) ?>");
511 return false;
513 if(document.getElementById('radio_type_of_payment_self1').checked==true || document.getElementById('radio_type_of_payment1').checked==true)
515 for (var i = 0; i < f.elements.length; ++i)
517 var elem = f.elements[i];
518 var ename = elem.name;
519 if (ename.indexOf('form_upay[0') == 0) //Today is this text box.
521 if(elem.value*1>0)
522 {//A warning message, if the amount is posted with out encounter.
523 if(confirm("<?php echo addslashes( xl('Are you sure to post for today?')) ?>"))
525 ok=1;
527 else
529 elem.focus();
530 return false;
533 break;
537 //CO-PAY
538 /* if(document.getElementById('radio_type_of_payment1').checked==true)
540 var total = 0;
541 for (var i = 0; i < f.elements.length; ++i)
543 var elem = f.elements[i];
544 var ename = elem.name;
545 if (ename.indexOf('form_upay[') == 0) //Today is this text box.
547 if(f.form_paytotal.value*1!=elem.value*1)//Total CO-PAY is not posted against today
548 {//A warning message, if the amount is posted against an old encounter.
549 if(confirm("<?php //echo addslashes( xl('You are posting against an old encounter?')) ?>"))
551 ok=1;
553 // else
555 elem.focus();
556 return false;
559 break;
562 }*///Co Pay
563 else if( document.getElementsByName('form_paytotal')[0].value <= 0 )//total 0
565 alert("<?php echo addslashes( xl('Invalid Total!')) ?>")
566 return false;
568 if(ok==-1)
570 //return true;
571 if(confirm("<?php echo addslashes( xl('Payment Validated: Save?')) ?>"))
573 return true;
575 else
577 return false;
581 function cursor_pointer()
582 {//Point the cursor to the latest encounter(Today)
583 var f = document.forms["payfrm"];
584 var total = 0;
585 for (var i = 0; i < f.elements.length; ++i)
587 var elem = f.elements[i];
588 var ename = elem.name;
589 if (ename.indexOf('form_upay[') == 0)
591 elem.focus();
592 break;
596 //=====================================================
597 function make_it_hide_enc_pay()
599 document.getElementById('td_head_insurance_payment').style.display="none";
600 document.getElementById('td_head_patient_co_pay').style.display="none";
601 document.getElementById('td_head_co_pay').style.display="none";
602 document.getElementById('td_head_insurance_balance').style.display="none";
603 for (var i = 1; ; ++i)
605 var td_inspaid_elem = document.getElementById('td_inspaid_'+i)
606 var td_patient_copay_elem = document.getElementById('td_patient_copay_'+i)
607 var td_copay_elem = document.getElementById('td_copay_'+i)
608 var balance_elem = document.getElementById('balance_'+i)
609 if (td_inspaid_elem)
611 td_inspaid_elem.style.display="none";
612 td_patient_copay_elem.style.display="none";
613 td_copay_elem.style.display="none";
614 balance_elem.style.display="none";
616 else
618 break;
621 document.getElementById('td_total_4').style.display="none";
622 document.getElementById('td_total_7').style.display="none";
623 document.getElementById('td_total_8').style.display="none";
624 document.getElementById('td_total_6').style.display="none";
626 document.getElementById('table_display').width="420px";
629 //=====================================================
630 function make_visible()
632 document.getElementById('td_head_rep_doc').style.display="";
633 document.getElementById('td_head_description').style.display="";
634 document.getElementById('td_head_total_charge').style.display="none";
635 document.getElementById('td_head_insurance_payment').style.display="none";
636 document.getElementById('td_head_patient_payment').style.display="none";
637 document.getElementById('td_head_patient_co_pay').style.display="none";
638 document.getElementById('td_head_co_pay').style.display="none";
639 document.getElementById('td_head_insurance_balance').style.display="none";
640 document.getElementById('td_head_patient_balance').style.display="none";
641 for (var i = 1; ; ++i)
643 var td_charges_elem = document.getElementById('td_charges_'+i)
644 var td_inspaid_elem = document.getElementById('td_inspaid_'+i)
645 var td_ptpaid_elem = document.getElementById('td_ptpaid_'+i)
646 var td_patient_copay_elem = document.getElementById('td_patient_copay_'+i)
647 var td_copay_elem = document.getElementById('td_copay_'+i)
648 var balance_elem = document.getElementById('balance_'+i)
649 var duept_elem = document.getElementById('duept_'+i)
650 if (td_charges_elem)
652 td_charges_elem.style.display="none";
653 td_inspaid_elem.style.display="none";
654 td_ptpaid_elem.style.display="none";
655 td_patient_copay_elem.style.display="none";
656 td_copay_elem.style.display="none";
657 balance_elem.style.display="none";
658 duept_elem.style.display="none";
660 else
662 break;
665 document.getElementById('td_total_7').style.display="";
666 document.getElementById('td_total_8').style.display="";
667 document.getElementById('td_total_1').style.display="none";
668 document.getElementById('td_total_2').style.display="none";
669 document.getElementById('td_total_3').style.display="none";
670 document.getElementById('td_total_4').style.display="none";
671 document.getElementById('td_total_5').style.display="none";
672 document.getElementById('td_total_6').style.display="none";
674 document.getElementById('table_display').width="505px";
676 function make_it_hide()
678 document.getElementById('td_head_rep_doc').style.display="none";
679 document.getElementById('td_head_description').style.display="none";
680 document.getElementById('td_head_total_charge').style.display="";
681 document.getElementById('td_head_insurance_payment').style.display="";
682 document.getElementById('td_head_patient_payment').style.display="";
683 document.getElementById('td_head_patient_co_pay').style.display="";
684 document.getElementById('td_head_co_pay').style.display="";
685 document.getElementById('td_head_insurance_balance').style.display="";
686 document.getElementById('td_head_patient_balance').style.display="";
687 for (var i = 1; ; ++i)
689 var td_charges_elem = document.getElementById('td_charges_'+i)
690 var td_inspaid_elem = document.getElementById('td_inspaid_'+i)
691 var td_ptpaid_elem = document.getElementById('td_ptpaid_'+i)
692 var td_patient_copay_elem = document.getElementById('td_patient_copay_'+i)
693 var td_copay_elem = document.getElementById('td_copay_'+i)
694 var balance_elem = document.getElementById('balance_'+i)
695 var duept_elem = document.getElementById('duept_'+i)
696 if (td_charges_elem)
698 td_charges_elem.style.display="";
699 td_inspaid_elem.style.display="";
700 td_ptpaid_elem.style.display="";
701 td_patient_copay_elem.style.display="";
702 td_copay_elem.style.display="";
703 balance_elem.style.display="";
704 duept_elem.style.display="";
706 else
708 break;
711 document.getElementById('td_total_1').style.display="";
712 document.getElementById('td_total_2').style.display="";
713 document.getElementById('td_total_3').style.display="";
714 document.getElementById('td_total_4').style.display="";
715 document.getElementById('td_total_5').style.display="";
716 document.getElementById('td_total_6').style.display="";
717 document.getElementById('td_total_7').style.display="";
718 document.getElementById('td_total_8').style.display="";
720 document.getElementById('table_display').width="100%";
722 function make_visible_radio()
724 document.getElementById('tr_radio1').style.display="";
725 document.getElementById('tr_radio2').style.display="none";
727 function make_hide_radio()
729 document.getElementById('tr_radio1').style.display="none";
730 document.getElementById('tr_radio2').style.display="";
732 function make_visible_row()
734 document.getElementById('table_display').style.display="";
735 document.getElementById('table_display_prepayment').style.display="none";
737 function make_hide_row()
739 document.getElementById('table_display').style.display="none";
740 document.getElementById('table_display_prepayment').style.display="";
742 function make_self()
744 make_visible_row();
745 make_it_hide();
746 make_it_hide_enc_pay();
747 document.getElementById('radio_type_of_payment_self1').checked=true;
748 cursor_pointer();
750 function make_insurance()
752 make_visible_row();
753 make_it_hide();
754 cursor_pointer();
755 document.getElementById('radio_type_of_payment1').checked=true;
757 //--------------------------------------------------------------------------------------------------//
758 $('#paySubmit').click( function(e) {
759 e.preventDefault()
760 $("#mode").val( "portal-save" );
761 var inv_values= JSON.stringify(getFormObj('payfrm'));
762 var extra_values=JSON.stringify(getFormObj('paycredit'));
763 var extra = "&inv_values="+inv_values+"&extra_values="+extra_values;
765 var flag = 0
766 var liburl = './lib/paylib.php';
767 $.ajax({
768 type: "POST",
769 url: liburl,
770 data: $("#payfrm").serialize()+extra,
771 beforeSend: function(xhr){
772 if( validateCC() !== true) return false;
773 if( $('#pin').val() == "" || $('#ccname').val() == "" || $('#ccyear').val() == "" || $('#ccmonth').val() == ""){
774 alert("<?php echo addslashes( xl('Invalid Credit Card Values: Please correct')) ?>")
775 return false;
777 if( validate() != true){
778 flag = 1;
779 alert("<?php echo addslashes( xl('Validation error: Fix and resubmit. This popup info is preserved!')) ?>")
780 return false;
782 $("#openPayModal .close").click()
784 error: function(qXHR, textStatus, errorThrow){
785 console.log("There was an error:"+errorThrow);
787 success: function(templateHtml, textStatus, jqXHR){
788 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')) ?>")
789 window.location.reload(false);
792 if(flag)
793 $("#openPayModal .close").click();
795 //---------------------------------------------------------------------------------------//
796 $("#payfrm").on('submit', function(e){
797 e.preventDefault();
798 var thisform = this;
799 $("#mode").val( "review-save" );
800 var inv_values= JSON.stringify(getFormObj('payfrm'));
801 var extra_values=JSON.stringify(getFormObj('paycredit'));
802 var extra = "&inv_values="+inv_values+"&extra_values="+extra_values;
804 var flag = 0
805 var liburl ='<?php echo $GLOBALS["webroot"] ?>/portal/lib/paylib.php';
806 $.ajax({
807 type: "POST",
808 url: liburl,
809 data: $("#payfrm").serialize()+extra,
810 beforeSend: function(xhr){
811 if( validate() != true){
812 flag = 1;
813 alert("<?php echo addslashes( xl('Validation error: Fix and resubmit. Payment values are preserved!')) ?>")
814 return false;
817 error: function(xhr, textStatus, error){
818 alert("<?php echo addslashes( xl('There is a Post error')) ?>")
819 console.log("There was an error:"+textStatus);
820 return false;
822 success: function(templateHtml, textStatus, jqXHR){
823 thisform.submit();
827 function getFormObj(formId) {
828 var formObj = {};
829 var inputs = $('#'+formId).serializeArray();
830 $.each(inputs, function (i, input) {
831 formObj[input.name] = input.value;
833 return formObj;
835 function formRepopulate(jsondata){
836 data = $.parseJSON(jsondata);
837 $.each(data, function(name, val){
838 var $el = $('[name="'+name+'"]'),
839 type = $el.attr('type');
840 switch(type){
841 case 'checkbox':
842 $el.prop('checked',true);
843 break;
844 case 'radio':
845 $el.filter('[value="'+val+'"]').prop('checked', true);
846 break;
847 default:
848 $el.val(val);
852 function getAuth(){
853 var authnum = prompt("<?php echo xlt('Please enter card comfirmation authorization') ?>", "");
854 if (authnum != null) {
855 $('#check_number').val(authnum);
858 </script>
860 <body class="body_top" onunload='imclosing()' onLoad="cursor_pointer();"
861 style="text-align: center; margin: auto;">
863 <form id="payfrm" method='post'
864 action='<?php echo $GLOBALS["webroot"] ?>/portal/portal_payment.php'>
865 <input type='hidden' name='form_pid' value='<?php echo attr($pid) ?>' />
866 <input type='hidden' name='form_save'
867 value='<?php echo xlt('Invoice');?>' />
869 <table>
870 <tr height="10">
871 <td colspan="3">&nbsp;</td>
872 </tr>
874 <tr>
875 <td colspan='3' align='center' class='text'><b><?php echo xlt('Accept Payment for'); ?>&nbsp;:&nbsp;&nbsp;<?php
877 echo htmlspecialchars( $patdata['fname'], ENT_QUOTES ) . " " . htmlspecialchars( $patdata['lname'], ENT_QUOTES ) . " " . htmlspecialchars( $patdata['mname'], ENT_QUOTES ) . " (" . htmlspecialchars( $patdata['pid'], ENT_QUOTES ) . ")"?></b>
878 <?php $NameNew=$patdata['fname'] . " " .$patdata['lname']. " " .$patdata['mname'];?>
879 </td>
880 </tr>
881 <tr height="15">
882 <td colspan='3'></td>
883 </tr>
884 <tr>
885 <td class='text'>
886 <?php echo xlt('Payment Method'); ?>:
887 </td>
888 <td colspan='2'><select name="form_method" id="form_method"
889 class="text" onChange='CheckVisible("yes")'>
890 <?php
891 $query1112 = "SELECT * FROM list_options where list_id=? ORDER BY seq, title ";
892 $bres1112 = sqlStatement( $query1112, array ('payment_method') );
893 while( $brow1112 = sqlFetchArray( $bres1112 ) ){
894 if( $brow1112['option_id'] != 'credit_card' || $brow1112['option_id'] == 'electronic' || $brow1112['option_id'] == 'bank_draft' ) continue;
895 echo "<option value='" . htmlspecialchars( $brow1112['option_id'], ENT_QUOTES ) . "'>" . htmlspecialchars( xl_list_label( $brow1112['title'] ), ENT_QUOTES ) . "</option>";
898 </select></td>
899 </tr>
901 <tr height="5">
902 <td colspan='3'></td>
903 </tr>
905 <tr>
906 <td class='text'>
907 <?php echo xla('Authorized'); ?>:
908 </td>
909 <td colspan='2'>
910 <?php
911 if( isset( $_SESSION['authUserID'] ) )
912 echo "<input type='text' id='check_number' name='form_source' style='width:120px;' value='" . htmlspecialchars( $payrow['source'], ENT_QUOTES ) . "'>";
914 </td>
915 </tr>
916 <tr height="5">
917 <td colspan='3'></td>
918 </tr>
919 <tr>
920 <td class='text' valign="middle">
921 <?php echo xlt('Patient Coverage'); ?>:
922 </td>
923 <td class='text' colspan="2">
924 <input type="radio" name="radio_type_of_coverage" id="radio_type_of_coverage1"
925 value="self" onClick="make_visible_radio();make_self();" />
926 <?php echo xlt('Self'); ?>
927 <input type="radio" name="radio_type_of_coverage" id="radio_type_of_coverag2" value="insurance" checked="checked"
928 onClick="make_hide_radio();make_insurance();" />
929 <?php echo xlt('Insurance'); ?>
930 </td>
931 </tr>
932 <tr height="5">
933 <td colspan='3'></td>
934 </tr>
935 <tr id="tr_radio1" style="display: none">
936 <!-- For radio Insurance -->
937 <td class='text' valign="top">
938 <?php echo xlt('Payment against'); ?>:
939 </td>
940 <td class='text' colspan="2">
941 <input type="radio" name="radio_type_of_payment" id="radio_type_of_payment_self1"
942 value="cash" onClick="make_visible_row();make_it_hide_enc_pay();cursor_pointer();" />
943 <?php echo xlt('Encounter Payment'); ?>
944 </td>
945 </tr>
946 <tr id="tr_radio2">
947 <!-- For radio self -->
948 <td class='text' valign="top"><?php echo xlt('Payment against'); ?>:
949 </td>
950 <td class='text' colspan="2"><input type="radio" name="radio_type_of_payment" id="radio_type_of_payment1" checked="checked"
951 value="copay" onClick="make_visible_row();cursor_pointer();" /><?php echo xlt('Co Pay'); ?>
952 <input type="radio" name="radio_type_of_payment" id="radio_type_of_payment2"
953 value="invoice_balance" onClick="make_visible_row();" /><?php echo xlt('Invoice Balance'); ?><br />
954 <input type="radio" name="radio_type_of_payment" id="radio_type_of_payment4" value="pre_payment"
955 onClick="make_hide_row();" /><?php echo xlt('Pre Pay'); ?></td>
956 </tr>
957 <tr height="15">
958 <td colspan='3'></td>
959 </tr>
960 </table>
961 <table width="35%" border="0" cellspacing="0" cellpadding="0" id="table_display_prepayment" style="display: none">
962 <tr>
963 <td class='detail'><?php echo xlt('Pre Payment'); ?></td>
964 <td><input class="form-control" type='text' name='form_prepayment' style='width: 100px' /></td>
965 </tr>
966 </table>
967 <table id="table_display" style="width: 100%; background: #eee;" class="table table-striped table-responsive">
968 <thead>
969 </thead>
970 <tbody>
971 <!-- <table border='0' id="table_display" cellpadding='0' cellspacing='0' width='100%'> -->
972 <tr bgcolor="#cccccc" id="tr_head">
973 <td class="dehead" width="60">
974 <?php echo xlt('DOS')?>
975 </td>
976 <td class="dehead" width="120">
977 <?php echo xlt('Visit Reason')?>
978 </td>
979 <td class="dehead" align="center" width="70" id="td_head_total_charge">
980 <?php echo xlt('Total Charge')?>
981 </td>
982 <td class="dehead" align="center" width="70" id="td_head_rep_doc" style='display: none'>
983 <?php echo xlt('Report/ Form')?>
984 </td>
985 <td class="dehead" align="center" width="200" id="td_head_description" style='display: none'>
986 <?php echo xlt('Description')?>
987 </td>
988 <td class="dehead" align="center" width="70" id="td_head_insurance_payment">
989 <?php echo xlt('Insurance Payment')?>
990 </td>
991 <td class="dehead" align="center" width="70" id="td_head_patient_payment">
992 <?php echo xlt('Patient Payment')?>
993 </td>
994 <td class="dehead" align="center" width="55" id="td_head_patient_co_pay">
995 <?php echo xlt('Co Pay Paid')?>
996 </td>
997 <td class="dehead" align="center" width="55" id="td_head_co_pay">
998 <?php echo xlt('Required Co Pay')?>
999 </td>
1000 <td class="dehead" align="center" width="70" id="td_head_insurance_balance">
1001 <?php echo xlt('Insurance Balance')?>
1002 </td>
1003 <td class="dehead" align="center" width="70" id="td_head_patient_balance">
1004 <?php echo xlt('Patient Balance')?>
1005 </td>
1006 <td class="dehead" align="center" width="50">
1007 <?php echo xlt('Paying')?>
1008 </td>
1009 </tr>
1010 <?php
1011 $encs = array ();
1012 // Get the unbilled service charges and payments by encounter for this patient.
1014 $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
1015 "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";
1016 $bres = sqlStatement( $query, array ($pid,$pid) );
1018 while( $brow = sqlFetchArray( $bres ) ){
1019 $key = 0 + $brow['encounter'];
1020 if( empty( $encs[$key] ) ){
1021 $encs[$key] = array ('encounter' => $brow['encounter'],'date' => $brow['encdate'],'last_level_closed' => $brow['last_level_closed'],'charges' => 0,'payments' => 0,'reason'=>$brow['reason']
1024 if( $brow['code_type'] === 'COPAY' ){
1025 // $encs[$key]['payments'] -= $brow['fee'];
1026 } else{
1027 $encs[$key]['charges'] += $brow['fee'];
1028 // Add taxes.
1029 $sql_array = array ();
1030 $query = "SELECT taxrates FROM codes WHERE " . "code_type = ? AND " . "code = ? AND ";
1031 array_push( $sql_array, $code_types[$brow['code_type']]['id'], $brow['code'] );
1032 if( $brow['modifier'] ){
1033 $query .= "modifier = ?";
1034 array_push( $sql_array, $brow['modifier'] );
1035 } else{
1036 $query .= "(modifier IS NULL OR modifier = '')";
1038 $query .= " LIMIT 1";
1039 $trow = sqlQuery( $query, $sql_array );
1040 $encs[$key]['charges'] += calcTaxes( $trow, $brow['fee'] );
1043 // Do the same for unbilled product sales.
1045 $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
1046 "AND fe.pid = s.pid AND fe.encounter = s.encounter " . "where fe.pid = ? " . "ORDER BY s.encounter";
1048 $dres = sqlStatement( $query, array ($pid,$pid) );
1050 while( $drow = sqlFetchArray( $dres ) ){
1051 $key = 0 + $drow['encounter'];
1052 if( empty( $encs[$key] ) ){
1053 $encs[$key] = array ('encounter' => $drow['encounter'],'date' => $drow['encdate'],'last_level_closed' => $drow['last_level_closed'],'charges' => 0,'payments' => 0
1056 $encs[$key]['charges'] += $drow['fee'];
1057 // Add taxes.
1058 $trow = sqlQuery( "SELECT taxrates FROM drug_templates WHERE drug_id = ? " . "ORDER BY selector LIMIT 1", array ($drow['drug_id']
1059 ) );
1060 $encs[$key]['charges'] += calcTaxes( $trow, $drow['fee'] );
1063 ksort( $encs, SORT_NUMERIC );
1064 $gottoday = false;
1065 // Bringing on top the Today always
1066 foreach( $encs as $key => $value ){
1067 $dispdate = $value['date'];
1068 if( strcmp( $dispdate, $today ) == 0 && ! $gottoday ){
1069 $gottoday = true;
1070 break;
1074 // If no billing was entered yet for today, then generate a line for
1075 // entering today's co-pay.
1077 if( ! $gottoday ){
1078 // echoLine("form_upay[0]", date("Y-m-d"), 0, 0, 0, 0 /*$duept*/);//No encounter yet defined.
1080 $gottoday = false;
1081 foreach( $encs as $key => $value ){
1082 $enc = $value['encounter'];
1083 $reason = $value['reason'];
1084 $dispdate = $value['date'];
1085 if( strcmp( $dispdate, $today ) == 0 && ! $gottoday ){
1086 $dispdate = date( "Y-m-d" );
1087 $gottoday = true;
1089 // ------------------------------------------------------------------------------------
1090 $inscopay = getCopay( $pid, $dispdate );
1091 $patcopay = getPatientCopay( $pid, $enc );
1092 // Insurance Payment
1093 // -----------------
1094 $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
1095 ) );
1096 $dpayment = $drow['payments'];
1097 $dadjustment = $drow['adjustments'];
1098 // Patient Payment
1099 // ---------------
1100 $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
1101 ) );
1102 $dpayment_pat = $drow['payments'];
1104 // ------------------------------------------------------------------------------------
1105 // NumberOfInsurance
1106 $ResultNumberOfInsurance = sqlStatement( "SELECT COUNT( DISTINCT TYPE ) NumberOfInsurance FROM insurance_data
1107 where pid = ? and provider>0 ", array ($pid
1108 ) );
1109 $RowNumberOfInsurance = sqlFetchArray( $ResultNumberOfInsurance );
1110 $NumberOfInsurance = $RowNumberOfInsurance['NumberOfInsurance'] * 1;
1111 // ------------------------------------------------------------------------------------
1112 $duept = 0;
1113 if( ( ( $NumberOfInsurance == 0 || $value['last_level_closed'] == 4 || $NumberOfInsurance == $value['last_level_closed'] ) ) ){ // Patient balance
1114 $brow = sqlQuery( "SELECT SUM(fee) AS amount FROM billing WHERE " . "pid = ? and encounter = ? AND activity = 1", array ($pid,$enc
1115 ) );
1116 $srow = sqlQuery( "SELECT SUM(fee) AS amount FROM drug_sales WHERE " . "pid = ? and encounter = ? ", array ($pid,$enc
1117 ) );
1118 $drow = sqlQuery( "SELECT SUM(pay_amount) AS payments, " . "SUM(adj_amount) AS adjustments FROM ar_activity WHERE " . "pid = ? and encounter = ? ", array ($pid,$enc
1119 ) );
1120 $duept = $brow['amount'] + $srow['amount'] - $drow['payments'] - $drow['adjustments'];
1122 echoLine( "form_upay[$enc]", $dispdate, $value['charges'], $dpayment_pat, ( $dpayment + $dadjustment ), $duept, ($enc.':'.$reason), $inscopay, $patcopay );
1125 // Continue with display of the data entry form.
1127 <tr>
1128 <td class="dehead" id='td_total_1'></td>
1129 <td class="dehead" id='td_total_2'></td>
1130 <td class="dehead" id='td_total_3'></td>
1131 <td class="dehead" id='td_total_4'></td>
1132 <td class="dehead" id='td_total_5'></td>
1133 <td class="dehead" id='td_total_6'></td>
1134 <td class="dehead" id='td_total_7'></td>
1135 <td class="dehead" id='td_total_8'></td>
1136 <td class="dehead" align="right"><?php echo xlt('Total');?></td>
1137 <td class="dehead" align="right"><input class="form-control" type='text' name='form_paytotal'
1138 value='' style='color: #00aa00; width: 65px; padding: 1px 1px;' readonly />
1139 </td>
1140 </tr>
1141 </table>
1142 <?php
1143 if( isset( $ccdata["name"] ) ){
1144 echo '<div class="col-xs-12 col-md-4 col-lg-4">
1145 <div class="panel panel-default height">';
1146 if( ! isset( $_SESSION['authUserID'] ) )
1147 echo '<div class="panel-heading">'.xlt("Payment Information").'<span style="color:#cc0000"><em> '.xlt("Pending Auth since").': </em>'.text($edata["date"]).'</span></div>';
1148 else
1149 echo '<div class="panel-heading">'.xlt("Payment Information").' <button type="button" class="btn btn-danger btn-sm" onclick="getAuth()">'.xlt("Authorize").'</button></div>';
1151 else{
1152 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>';
1155 <div class="panel-body">
1156 <strong><?php echo xlt('Card Name');?>: </strong><span id="cn"><?php echo attr($ccdata["cc_type"])?></span><br>
1157 <strong><?php echo xlt('Name On Card');?>: </strong><span id="nc"><?php echo attr($ccdata["name"])?></span><br>
1158 <strong><?php echo xlt('Card Number');?>: </strong><span id="ccn"><?php
1159 if( isset( $_SESSION['authUserID'] ) )
1160 echo $ccdata["cc_number"] . "</span><br>";
1161 else
1162 echo "********** ".substr($ccdata["cc_number"],-4) . "</span><br>";
1164 <strong><?php echo xlt('Exp Date');?>: </strong><span id="ed"><?php echo attr($ccdata["month"])."/".attr($ccdata["year"])?></span><br>
1165 <strong><?php echo xlt('Charge Total');?>: </strong><span id="ct"><?php echo attr($invdata["form_paytotal"])?></span><br>
1166 </div>
1167 </div>
1168 </div>
1170 <?php
1171 if( ! isset( $_SESSION['authUserID'] ) )
1172 echo '<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#openPayModal">' . xlt("Pay Invoice") . '</button>';
1173 else
1174 echo "<button type='submit' class='btn btn-danger' form='payfrm'>" . xlt('Post Payment') . "</button>";
1176 &nbsp;
1177 </p>
1178 <input type="hidden" name="hidden_patient_code" id="hidden_patient_code" value="<?php echo attr($pid);?>" />
1179 <input type='hidden' name='mode' id='mode' value='' />
1180 </form>
1182 <script type="text/javascript">
1183 if (typeof jsondata !== 'undefined') {
1184 formRepopulate(jsondata);
1186 calctotal();
1187 </script>
1188 <!-- credit payment modal -->
1189 <div id="openPayModal" class="modal fade" role="dialog">
1190 <div class="modal-dialog">
1191 <div class="modal-content">
1192 <div class="modal-header">
1193 <h3><?php echo xlt('Submit Payment for Authorization');?></h3>
1194 <button type="button" class="close" data-dismiss="modal">&times;</button>
1195 </div>
1196 <div class="modal-body container">
1197 <form id='paycredit' class="form-horizontal col-xs-12 col-sm-6 col-md-6">
1198 <fieldset>
1199 <div class="control-group">
1200 <label label-default="label-default" class="control-label"><?php echo xlt('Name on Card');?></label>
1201 <div class="controls">
1202 <input name="name" id="ccname" type="text" class="form-control"
1203 pattern="\w+ \w+.*" title="<?php echo xla('Fill your first and last name'); ?>"
1204 required value="" />
1205 </div>
1206 </div>
1207 <div class="control-group">
1208 <label class="control-label"><?php echo xlt('Card Number');?></label>
1209 <div class="controls">
1210 <div class="row">
1211 <div class="col-sm-12">
1212 <input name="cc_number" id="cc_number" type="text" class="form-control inline col-sm-3"
1213 autocomplete="off" maxlength="19" pattern="\d" onchange="validateCC()"
1214 title="<?php echo xla('Card Number'); ?>" required value="" />
1215 <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="" />
1216 </div>
1217 </div>
1218 </div>
1219 </div>
1220 <div class="control-group">
1221 <label label-default="label-default" class="control-label"><?php echo xlt('Card Expiry Date');?></label>
1222 <div class="controls">
1223 <div class="row">
1224 <div class="col-md-4">
1225 <select name="month" id="ccmonth" class="form-control">
1226 <option value=""><?php echo xlt('Select Month'); ?></option>
1227 <option value="01"><?php echo xlt('January'); ?></option>
1228 <option value="02"><?php echo xlt('February'); ?></option>
1229 <option value="03"><?php echo xlt('March'); ?></option>
1230 <option value="04"><?php echo xlt('April'); ?></option>
1231 <option value="05"><?php echo xlt('May'); ?></option>
1232 <option value="06"><?php echo xlt('June'); ?></option>
1233 <option value="07"><?php echo xlt('July'); ?></option>
1234 <option value="08"><?php echo xlt('August'); ?></option>
1235 <option value="09"><?php echo xlt('September'); ?></option>
1236 <option value="10"><?php echo xlt('October'); ?></option>
1237 <option value="11"><?php echo xlt('November'); ?></option>
1238 <option value="12"><?php echo xlt('December'); ?></option>
1239 </select>
1240 </div>
1241 <div class="col-md-3">
1242 <select name="year" id="ccyear" class="form-control">
1243 <option value=""><?php echo xlt('Select Year'); ?></option>
1244 <option value="2017">2017</option>
1245 <option value="2018">2018</option>
1246 <option value="2019">2019</option>
1247 <option value="2020">2020</option>
1248 <option value="2021">2021</option>
1249 <option value="2022">2022</option>
1250 <option value="2023">2023</option>
1251 <option value="2024">2024</option>
1252 </select>
1253 </div>
1254 </div>
1255 </div>
1256 </div>
1257 <div class="control-group">
1258 <label label-default="label-default" class="control-label"><?php echo xlt('Card CVV');?></label>
1259 <div class="controls">
1260 <div class="row">
1261 <div class="col-md-3">
1262 <input name="pin" id="pin" type="text" class="form-control"
1263 autocomplete="off" maxlength="4" pattern="\d{3}" onfocus="validateCC()"
1264 title="<?php echo xlt('Three or four digits at back of your card'); ?>" required value="" />
1265 </div>
1266 <div class="col-md-3">
1267 <img src='./images/img_cvc.png' style='height: 58px; width: auto'>
1268 </div>
1269 </div>
1270 </div>
1271 </div>
1272 <div class="form-actions">
1273 <button id="paySubmit" class="btn btn-danger"><?php echo xlt('Submit');?></button>
1274 <button type="button" class="btn btn-default" data-dismiss="modal"><?php echo xlt('Cancel');?></button>
1275 </div>
1276 </fieldset>
1277 <input type='hidden' name='cc_type' id='cc_type' value='' />
1278 </form>
1279 </div>
1280 <!-- Body -->
1281 <div class="modal-footer">
1282 <button type="button" class="btn btn-default" data-dismiss="modal"><?php echo xlt('Close');?></button>
1283 </div>
1284 </div>
1285 </div>
1286 </div>
1287 <?php echo "<script>var ccerr='". xlt('Invalid Credit Card Number') . "';</script>";?>
1288 <script type="text/javascript">
1289 $('#cc_number').validateCreditCard(function(result){
1290 var r = (result.card_type == null ? '' : result.card_type.name.toUpperCase())
1291 var v = (result.valid== true ? ' Valid #' : ' Invalid #')
1292 $('#cardtype').val(r+v);
1294 function validateCC() {
1295 var result = $('#cc_number').validateCreditCard();
1296 var r = (result.card_type == null ? '' : result.card_type.name.toUpperCase())
1297 var v = (result.valid == true ? ' Okay' : ' Invalid #')
1298 $('#cardtype').val(r+v);
1299 $('#cc_type').val(r);
1300 if(!result.valid){
1301 alert(ccerr)
1302 return false;
1304 else{
1305 return true;
1308 </script>
1309 </body>
1310 <?php