the last of the legacy date pickers (#990)
[openemr.git] / portal / portal_payment.php
blob8ceaaf6f1fe62aec261406fecaa1cc32dd38bf1b
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();
43 require_once(dirname(__FILE__) . "/lib/appsql.class.php");
44 require_once("$srcdir/acl.inc");
45 require_once("$srcdir/patient.inc");
46 require_once("$srcdir/billing.inc");
47 require_once("$srcdir/payment.inc.php");
48 require_once("$srcdir/forms.inc");
49 require_once("$srcdir/sl_eob.inc.php");
50 require_once("$srcdir/invoice_summary.inc.php");
51 require_once("../custom/code_types.inc.php");
52 require_once("$srcdir/formatting.inc.php");
53 require_once("$srcdir/options.inc.php");
54 require_once("$srcdir/encounter_events.inc.php");
56 $appsql = new ApplicationTable();
58 $pid = $_REQUEST['hidden_patient_code'] > 0 ? $_REQUEST['hidden_patient_code'] : $pid;
60 $edata = $appsql->getPortalAudit($pid, 'review', 'payment');
61 $ccdata = array();
62 $invdata = array();
64 if ($edata) {
65 $ccdata = json_decode(aes256Decrypt($edata['checksum']), true);
66 $invdata = json_decode($edata['table_args'], true);
67 echo "<script type='text/javascript'>var jsondata='" . $edata['table_args'] . "';var ccdata='" . $edata['checksum'] . "'</script>";
70 function bucks($amount)
72 if ($amount) {
73 $amount = oeFormatMoney($amount);
74 return $amount;
77 return '';
79 function rawbucks($amount)
81 if ($amount) {
82 $amount = sprintf("%.2f", $amount);
83 return $amount;
86 return '';
89 // Display a row of data for an encounter.
91 $var_index = 0;
92 function echoLine($iname, $date, $charges, $ptpaid, $inspaid, $duept, $encounter = 0, $copay = 0, $patcopay = 0)
94 global $var_index;
95 $var_index ++;
96 $balance = bucks($charges - $ptpaid - $inspaid);
97 $balance = ( round($duept, 2) != 0 ) ? 0 : $balance; // if balance is due from patient, then insurance balance is displayed as zero
98 $encounter = $encounter ? $encounter : '';
99 echo " <tr id='tr_" . attr($var_index) . "' >\n";
100 echo " <td class='detail'>" . text(oeFormatShortDate($date)) . "</td>\n";
101 echo " <td class='detail' id='" . attr($date) . "' align='left'>" . htmlspecialchars($encounter, ENT_QUOTES) . "</td>\n";
102 echo " <td class='detail' align='center' id='td_charges_$var_index' >" . htmlspecialchars(bucks($charges), ENT_QUOTES) . "</td>\n";
103 echo " <td class='detail' align='center' id='td_inspaid_$var_index' >" . htmlspecialchars(bucks($inspaid * - 1), ENT_QUOTES) . "</td>\n";
104 echo " <td class='detail' align='center' id='td_ptpaid_$var_index' >" . htmlspecialchars(bucks($ptpaid * - 1), ENT_QUOTES) . "</td>\n";
105 echo " <td class='detail' align='center' id='td_patient_copay_$var_index' >" . htmlspecialchars(bucks($patcopay), ENT_QUOTES) . "</td>\n";
106 echo " <td class='detail' align='center' id='td_copay_$var_index' >" . htmlspecialchars(bucks($copay), ENT_QUOTES) . "</td>\n";
107 echo " <td class='detail' align='center' id='balance_$var_index'>" . htmlspecialchars(bucks($balance), ENT_QUOTES) . "</td>\n";
108 echo " <td class='detail' align='center' id='duept_$var_index'>" . htmlspecialchars(bucks(round($duept, 2) * 1), ENT_QUOTES) . "</td>\n";
109 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";
110 echo " </tr>\n";
113 // We use this to put dashes, colons, etc. back into a timestamp.
115 function decorateString($fmt, $str)
117 $res = '';
118 while ($fmt) {
119 $fc = substr($fmt, 0, 1);
120 $fmt = substr($fmt, 1);
121 if ($fc == '.') {
122 $res .= substr($str, 0, 1);
123 $str = substr($str, 1);
124 } else {
125 $res .= $fc;
129 return $res;
132 // Compute taxes from a tax rate string and a possibly taxable amount.
134 function calcTaxes($row, $amount)
136 $total = 0;
137 if (empty($row['taxrates'])) {
138 return $total;
141 $arates = explode(':', $row['taxrates']);
142 if (empty($arates)) {
143 return $total;
146 foreach ($arates as $value) {
147 if (empty($value)) {
148 continue;
151 $trow = sqlQuery("SELECT option_value FROM list_options WHERE " . "list_id = 'taxrate' AND option_id = ? LIMIT 1", array ($value
153 if (empty($trow['option_value'])) {
154 echo "<!-- Missing tax rate '" . text($value) . "'! -->\n";
155 continue;
158 $tax = sprintf("%01.2f", $amount * $trow['option_value']);
159 // echo "<!-- Rate = '$value', amount = '$amount', tax = '$tax' -->\n";
160 $total += $tax;
163 return $total;
166 $now = time();
167 $today = date('Y-m-d', $now);
168 $timestamp = date('Y-m-d H:i:s', $now);
171 // $patdata = getPatientData($pid, 'fname,lname,pubpid');
173 $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
176 $alertmsg = ''; // anything here pops up in an alert box
178 // If the Save button was clicked...
179 if ($_POST['form_save']) {
180 // $extra = json_decode($_POST['ajax_mode'], true);
181 $form_pid = $_POST['form_pid'];
182 $form_method = trim($_POST['form_method']);
183 $form_source = trim($_POST['form_source']);
184 $patdata = getPatientData($form_pid, 'fname,mname,lname,pubpid');
185 $NameNew = $patdata['fname'] . " " . $patdata['lname'] . " " . $patdata['mname'];
187 if ($_REQUEST['radio_type_of_payment'] == 'pre_payment') {
188 $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 (
189 0,$form_pid,$_SESSION['authUserID'],0,$form_source,$_REQUEST['form_prepayment'],$NameNew,$form_method
192 frontPayment($form_pid, 0, $form_method, $form_source, $_REQUEST['form_prepayment'], 0, $timestamp); // insertion to 'payments' table.
195 if ($_POST['form_upay'] && $_REQUEST['radio_type_of_payment'] != 'pre_payment') {
196 foreach ($_POST['form_upay'] as $enc => $payment) {
197 if ($amount = 0 + $payment) {
198 $zero_enc = $enc;
199 if ($_REQUEST['radio_type_of_payment'] == 'invoice_balance') {
201 } else {
202 if (! $enc) {
203 $enc = calendar_arrived($form_pid);
207 // ----------------------------------------------------------------------------------------------------
208 // Fetching the existing code and modifier
209 $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
211 if ($RowSearch = sqlFetchArray($ResultSearchNew)) {
212 $Codetype = $RowSearch['code_type'];
213 $Code = $RowSearch['code'];
214 $Modifier = $RowSearch['modifier'];
215 } else {
216 $Codetype = '';
217 $Code = '';
218 $Modifier = '';
221 // ----------------------------------------------------------------------------------------------------
222 if ($_REQUEST['radio_type_of_payment'] == 'copay') { // copay saving to ar_session and ar_activity tables
223 $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 (
224 $_SESSION['authId'],$form_source,$amount,$form_pid,$form_method
227 $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
230 frontPayment($form_pid, $enc, $form_method, $form_source, $amount, 0, $timestamp); // insertion to 'payments' table.
233 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.
234 if ($_REQUEST['radio_type_of_payment'] == 'cash') {
235 sqlStatement("update form_encounter set last_level_closed=? where encounter=? and pid=? ", array (4,$enc,$form_pid
237 sqlStatement("update billing set billed=? where encounter=? and pid=?", array (1,$enc,$form_pid
241 $adjustment_code = 'patient_payment';
242 $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 (
243 0,$form_pid,$_SESSION['authUserID'],0,$form_source,$amount,$NameNew,$adjustment_code,$form_method
246 // --------------------------------------------------------------------------------------------------------------------
248 frontPayment($form_pid, $enc, $form_method, $form_source, 0, $amount, $timestamp); // insertion to 'payments' table.
250 // --------------------------------------------------------------------------------------------------------------------
252 $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
253 )); // new fees screen copay gives account_code='PCP'
254 $rowMoneyGot = sqlFetchArray($resMoneyGot);
255 $Copay = $rowMoneyGot['PatientPay'];
257 // --------------------------------------------------------------------------------------------------------------------
259 // Looping the existing code and modifier
260 $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
262 while ($RowSearch = sqlFetchArray($ResultSearchNew)) {
263 $Codetype = $RowSearch['code_type'];
264 $Code = $RowSearch['code'];
265 $Modifier = $RowSearch['modifier'];
266 $Fee = $RowSearch['fee'];
268 $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
270 // new fees screen copay gives account_code='PCP'
271 $rowMoneyGot = sqlFetchArray($resMoneyGot);
272 $MoneyGot = $rowMoneyGot['MoneyGot'];
274 $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
276 $rowMoneyAdjusted = sqlFetchArray($resMoneyAdjusted);
277 $MoneyAdjusted = $rowMoneyAdjusted['MoneyAdjusted'];
279 $Remainder = $Fee - $Copay - $MoneyGot - $MoneyAdjusted;
280 $Copay = 0;
281 if (round($Remainder, 2) != 0 && $amount != 0) {
282 if ($amount - $Remainder >= 0) {
283 $insert_value = $Remainder;
284 $amount = $amount - $Remainder;
285 } else {
286 $insert_value = $amount;
287 $amount = 0;
290 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 (
291 $form_pid,$enc,$Codetype,$Code,$Modifier,0,3,$payment_id,$insert_value,0
293 } // if
294 } // while
295 if ($amount != 0) { // if any excess is there.
296 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 (
297 $form_pid,$enc,$Codetype,$Code,$Modifier,0,3,$payment_id,$amount,0
301 // --------------------------------------------------------------------------------------------------------------------
302 } // invoice_balance
303 } // if ($amount = 0 + $payment)
304 } // foreach
305 } // if ($_POST['form_upay'])
306 } // if ($_POST['form_save'])
308 if ($_POST['form_save'] || $_REQUEST['receipt']) {
309 if ($_REQUEST['receipt']) {
310 $form_pid = $_GET['patient'];
311 $timestamp = decorateString('....-..-.. ..:..:..', $_GET['time']);
314 // Get details for what we guess is the primary facility.
315 $frow = sqlQuery("SELECT * FROM facility " . "ORDER BY billing_location DESC, accepts_assignment DESC, id LIMIT 1");
317 // Get the patient's name and chart number.
318 $patdata = getPatientData($form_pid, 'fname,mname,lname,pubpid');
320 // Re-fetch payment info.
321 $payrow = sqlQuery("SELECT " . "SUM(amount1) AS amount1, " . "SUM(amount2) AS amount2, " . "MAX(method) AS method, " . "MAX(source) AS source, " . "MAX(dtime) AS dtime, " .
322 // "MAX(user) AS user " .
323 "MAX(user) AS user, " . "MAX(encounter) as encounter " . "FROM payments WHERE " . "pid = ? AND dtime = ?", array ($form_pid,$timestamp
326 // Create key for deleting, just in case.
327 $ref_id = ( $_REQUEST['radio_type_of_payment'] == 'copay' ) ? $session_id : $payment_id;
328 $payment_key = $form_pid . '.' . preg_replace('/[^0-9]/', '', $timestamp) . '.' . $ref_id;
330 // get facility from encounter
331 $tmprow = sqlQuery("
332 SELECT facility_id
333 FROM form_encounter
334 WHERE encounter = ?", array ($payrow['encounter']
336 $frow = sqlQuery("SELECT * FROM facility " . " WHERE id = ?", array ($tmprow['facility_id']
339 // Now proceed with printing the receipt.
342 <title><?php echo xlt('Receipt for Payment'); ?></title>
344 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-11-3/index.js"></script>
345 <script type="text/javascript">
346 $( document ).ready();
347 function goHome(){
348 window.location.replace("./patient/onsiteactivityviews");
350 function notifyPatient(){
351 var pid = <?php echo attr($pid);?>;
352 var note = $('#pop_receipt').text();
353 var formURL = './messaging/handle_note.php';
354 $.ajax({
355 url: formURL,
356 type: "POST",
357 data: {'task':'add', 'pid':pid, 'inputBody':note, 'title':'Bill/Collect', 'sendto':'-patient-','noteid':'0'},
358 success: function(data, textStatus, jqXHR) {
359 alert('Receipt sent to patient via Messages.')
361 error: function(jqXHR, status, error) {
362 console.log(status + ": " + error);
366 </script>
367 <?php
368 ob_start();
369 echo '<htlm><head></head><body style="text-align: center; margin: auto;">';
372 <div id='pop_receipt' style='display: block'>
374 <h2><?php echo xlt('Receipt for Payment'); ?></h2>
375 <p><?php echo text($frow['name'])?>
376 <br><?php echo text($frow['street'])?>
377 <br><?php echo text($frow['city'] . ', ' . $frow['state']) . ' ' . text($frow['postal_code'])?>
378 <br><?php echo htmlentities($frow['phone'])?>
380 <div style="text-align: center; margin: auto;">
381 <table border='0' cellspacing='8'
382 style="text-align: center; margin: auto;">
383 <tr>
384 <td><?php echo xlt('Date'); ?>:</td>
385 <td><?php echo text(oeFormatSDFT(strtotime($payrow['dtime']))) ?></td>
386 </tr>
387 <tr>
388 <td><?php echo xlt('Patient'); ?>:</td>
389 <td><?php echo text($patdata['fname']) . " " . text($patdata['mname']) . " " . text($patdata['lname']) . " (" . text($patdata['pubpid']) . ")"?></td>
390 </tr>
391 <tr>
392 <td><?php echo xlt('Paid Via'); ?>:</td>
393 <td><?php echo generate_display_field(array('data_type'=>'1','list_id'=>'payment_method'), $payrow['method']); ?></td>
394 </tr>
395 <tr>
396 <td><?php echo xlt('Authorized Id'); ?>:</td>
397 <td><?php echo text($payrow['source']) ?></td>
398 </tr>
399 <tr>
400 <td><?php echo xlt('Amount for This Visit'); ?>:</td>
401 <td><?php echo text(oeFormatMoney($payrow['amount1'])) ?></td>
402 </tr>
403 <tr>
404 <td><?php echo xlt('Amount for Past Balance'); ?>:</td>
405 <td><?php echo text(oeFormatMoney($payrow['amount2'])) ?></td>
406 </tr>
407 <tr>
408 <td><?php echo xlt('Received By'); ?>:</td>
409 <td><?php echo text($payrow['user']) ?></td>
410 </tr>
411 </table>
412 </div>
413 </div>
414 <button class='btn btn-sm' type='button' onclick='goHome()' id='returnhome'><?php echo xla('Return Home'); ?></button>
415 <button class='btn btn-sm' type='button' onclick="notifyPatient()"><?php echo xla('Notify Patient'); ?></button>
416 </body></html>
417 <?php
418 ob_end_flush();
419 } else {
421 // Here we display the form for data entry.
424 <title><?php echo xlt('Record Payment'); ?></title>
425 <style type="text/css">
426 body {
427 /* font-family:sans-serif; font-size:10pt; font-weight:normal */
430 .dehead {
431 color: #000000; /*font-family:sans-serif; font-size:10pt;*/
432 font-weight: bold
435 .detail {
436 padding: 1px 1px;
437 /* width: 65px; */
438 color: #000000; /*font-family:sans-serif; font-size:10pt; */
439 font-weight: normal
441 </style>
442 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-creditcardvalidator-1-1-0/jquery.creditCardValidator.js"></script>
443 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/textformat.js?v=<?php echo $v_js_includes; ?>"></script>
445 <script type="text/javascript">
446 var mypcc = '1';
447 function calctotal() {
448 var flag=0;
449 var f = document.forms["payfrm"];
450 var total = 0;
451 for (var i = 0; i < f.elements.length; ++i) {
452 var elem = f.elements[i];
453 var ename = elem.name;
454 if (ename.indexOf('form_upay[') == 0 || ename.indexOf('form_bpay[') == 0) {
455 if (elem.value.length > 0){
456 total += Number(elem.value);
457 if(total < 0) flag=1;
461 f.form_paytotal.value = Number(total).toFixed(2);
462 if(flag){
463 $('#payfrm')[0].reset();
464 alert("<?php echo addslashes(xl('Negative payments not accepted')) ?>")
466 return true;
468 function coloring()
470 for (var i = 1; ; ++i)
472 if(document.getElementById('paying_'+i))
474 paying=document.getElementById('paying_'+i).value*1;
475 patient_balance=document.getElementById('duept_'+i).innerHTML*1;
476 //balance=document.getElementById('balance_'+i).innerHTML*1;
477 if(patient_balance>0 && paying>0)
479 if(paying>patient_balance)
481 document.getElementById('paying_'+i).style.background='#FF0000';
483 else if(paying<patient_balance)
485 document.getElementById('paying_'+i).style.background='#99CC00';
487 else if(paying==patient_balance)
489 document.getElementById('paying_'+i).style.background='#ffffff';
492 else
494 document.getElementById('paying_'+i).style.background='#ffffff';
497 else
499 break;
503 function CheckVisible(MakeBlank)
504 {//Displays and hides the check number text box.
505 if(document.getElementById('form_method').options[document.getElementById('form_method').selectedIndex].value=='check_payment' ||
506 document.getElementById('form_method').options[document.getElementById('form_method').selectedIndex].value=='bank_draft' )
508 document.getElementById('check_number').disabled=false;
510 else
512 document.getElementById('check_number').disabled=true;
515 function validate()
517 var f = document.forms["payfrm"];
518 ok=-1;
519 //no checks taken here....
520 issue='no';
521 /*if(((document.getElementById('form_method').options[document.getElementById('form_method').selectedIndex].value=='check_payment' ||
522 document.getElementById('form_method').options[document.getElementById('form_method').selectedIndex].value=='bank_draft') &&
523 document.getElementById('check_number').value=='' ))
525 alert("<?php //echo addslashes( xl('Please Fill the Check/Ref Number')) ?>");
526 document.getElementById('check_number').focus();
527 return false;
530 if(document.getElementById('radio_type_of_payment_self1').checked==false &&
531 document.getElementById('radio_type_of_payment1').checked==false
532 && document.getElementById('radio_type_of_payment2').checked==false
533 && document.getElementById('radio_type_of_payment4').checked==false)
535 alert("<?php //echo addslashes( xl('Please Select Type Of Payment.')) ?>");
536 return false;
538 if(document.getElementById('radio_type_of_payment_self1').checked==true || document.getElementById('radio_type_of_payment1').checked==true)
540 for (var i = 0; i < f.elements.length; ++i)
542 var elem = f.elements[i];
543 var ename = elem.name;
544 if (ename.indexOf('form_upay[0') == 0) //Today is this text box.
546 if(elem.value*1>0)
547 {//A warning message, if the amount is posted with out encounter.
548 if(confirm("<?php echo addslashes(xl('Are you sure to post for today?')) ?>"))
550 ok=1;
552 else
554 elem.focus();
555 return false;
558 break;
562 //CO-PAY
563 /* if(document.getElementById('radio_type_of_payment1').checked==true)
565 var total = 0;
566 for (var i = 0; i < f.elements.length; ++i)
568 var elem = f.elements[i];
569 var ename = elem.name;
570 if (ename.indexOf('form_upay[') == 0) //Today is this text box.
572 if(f.form_paytotal.value*1!=elem.value*1)//Total CO-PAY is not posted against today
573 {//A warning message, if the amount is posted against an old encounter.
574 if(confirm("<?php //echo addslashes( xl('You are posting against an old encounter?')) ?>"))
576 ok=1;
578 // else
580 elem.focus();
581 return false;
584 break;
587 }*///Co Pay
588 else if( document.getElementsByName('form_paytotal')[0].value <= 0 )//total 0
590 alert("<?php echo addslashes(xl('Invalid Total!')) ?>")
591 return false;
593 if(ok==-1)
595 //return true;
596 if(confirm("<?php echo addslashes(xl('Payment Validated: Save?')) ?>"))
598 return true;
600 else
602 return false;
606 function cursor_pointer()
607 {//Point the cursor to the latest encounter(Today)
608 var f = document.forms["payfrm"];
609 var total = 0;
610 for (var i = 0; i < f.elements.length; ++i)
612 var elem = f.elements[i];
613 var ename = elem.name;
614 if (ename.indexOf('form_upay[') == 0)
616 elem.focus();
617 break;
621 //=====================================================
622 function make_it_hide_enc_pay()
624 document.getElementById('td_head_insurance_payment').style.display="none";
625 document.getElementById('td_head_patient_co_pay').style.display="none";
626 document.getElementById('td_head_co_pay').style.display="none";
627 document.getElementById('td_head_insurance_balance').style.display="none";
628 for (var i = 1; ; ++i)
630 var td_inspaid_elem = document.getElementById('td_inspaid_'+i)
631 var td_patient_copay_elem = document.getElementById('td_patient_copay_'+i)
632 var td_copay_elem = document.getElementById('td_copay_'+i)
633 var balance_elem = document.getElementById('balance_'+i)
634 if (td_inspaid_elem)
636 td_inspaid_elem.style.display="none";
637 td_patient_copay_elem.style.display="none";
638 td_copay_elem.style.display="none";
639 balance_elem.style.display="none";
641 else
643 break;
646 document.getElementById('td_total_4').style.display="none";
647 document.getElementById('td_total_7').style.display="none";
648 document.getElementById('td_total_8').style.display="none";
649 document.getElementById('td_total_6').style.display="none";
651 document.getElementById('table_display').width="420px";
654 //=====================================================
655 function make_visible()
657 document.getElementById('td_head_rep_doc').style.display="";
658 document.getElementById('td_head_description').style.display="";
659 document.getElementById('td_head_total_charge').style.display="none";
660 document.getElementById('td_head_insurance_payment').style.display="none";
661 document.getElementById('td_head_patient_payment').style.display="none";
662 document.getElementById('td_head_patient_co_pay').style.display="none";
663 document.getElementById('td_head_co_pay').style.display="none";
664 document.getElementById('td_head_insurance_balance').style.display="none";
665 document.getElementById('td_head_patient_balance').style.display="none";
666 for (var i = 1; ; ++i)
668 var td_charges_elem = document.getElementById('td_charges_'+i)
669 var td_inspaid_elem = document.getElementById('td_inspaid_'+i)
670 var td_ptpaid_elem = document.getElementById('td_ptpaid_'+i)
671 var td_patient_copay_elem = document.getElementById('td_patient_copay_'+i)
672 var td_copay_elem = document.getElementById('td_copay_'+i)
673 var balance_elem = document.getElementById('balance_'+i)
674 var duept_elem = document.getElementById('duept_'+i)
675 if (td_charges_elem)
677 td_charges_elem.style.display="none";
678 td_inspaid_elem.style.display="none";
679 td_ptpaid_elem.style.display="none";
680 td_patient_copay_elem.style.display="none";
681 td_copay_elem.style.display="none";
682 balance_elem.style.display="none";
683 duept_elem.style.display="none";
685 else
687 break;
690 document.getElementById('td_total_7').style.display="";
691 document.getElementById('td_total_8').style.display="";
692 document.getElementById('td_total_1').style.display="none";
693 document.getElementById('td_total_2').style.display="none";
694 document.getElementById('td_total_3').style.display="none";
695 document.getElementById('td_total_4').style.display="none";
696 document.getElementById('td_total_5').style.display="none";
697 document.getElementById('td_total_6').style.display="none";
699 document.getElementById('table_display').width="505px";
701 function make_it_hide()
703 document.getElementById('td_head_rep_doc').style.display="none";
704 document.getElementById('td_head_description').style.display="none";
705 document.getElementById('td_head_total_charge').style.display="";
706 document.getElementById('td_head_insurance_payment').style.display="";
707 document.getElementById('td_head_patient_payment').style.display="";
708 document.getElementById('td_head_patient_co_pay').style.display="";
709 document.getElementById('td_head_co_pay').style.display="";
710 document.getElementById('td_head_insurance_balance').style.display="";
711 document.getElementById('td_head_patient_balance').style.display="";
712 for (var i = 1; ; ++i)
714 var td_charges_elem = document.getElementById('td_charges_'+i)
715 var td_inspaid_elem = document.getElementById('td_inspaid_'+i)
716 var td_ptpaid_elem = document.getElementById('td_ptpaid_'+i)
717 var td_patient_copay_elem = document.getElementById('td_patient_copay_'+i)
718 var td_copay_elem = document.getElementById('td_copay_'+i)
719 var balance_elem = document.getElementById('balance_'+i)
720 var duept_elem = document.getElementById('duept_'+i)
721 if (td_charges_elem)
723 td_charges_elem.style.display="";
724 td_inspaid_elem.style.display="";
725 td_ptpaid_elem.style.display="";
726 td_patient_copay_elem.style.display="";
727 td_copay_elem.style.display="";
728 balance_elem.style.display="";
729 duept_elem.style.display="";
731 else
733 break;
736 document.getElementById('td_total_1').style.display="";
737 document.getElementById('td_total_2').style.display="";
738 document.getElementById('td_total_3').style.display="";
739 document.getElementById('td_total_4').style.display="";
740 document.getElementById('td_total_5').style.display="";
741 document.getElementById('td_total_6').style.display="";
742 document.getElementById('td_total_7').style.display="";
743 document.getElementById('td_total_8').style.display="";
745 document.getElementById('table_display').width="100%";
747 function make_visible_radio()
749 document.getElementById('tr_radio1').style.display="";
750 document.getElementById('tr_radio2').style.display="none";
752 function make_hide_radio()
754 document.getElementById('tr_radio1').style.display="none";
755 document.getElementById('tr_radio2').style.display="";
757 function make_visible_row()
759 document.getElementById('table_display').style.display="";
760 document.getElementById('table_display_prepayment').style.display="none";
762 function make_hide_row()
764 document.getElementById('table_display').style.display="none";
765 document.getElementById('table_display_prepayment').style.display="";
767 function make_self()
769 make_visible_row();
770 make_it_hide();
771 make_it_hide_enc_pay();
772 document.getElementById('radio_type_of_payment_self1').checked=true;
773 cursor_pointer();
775 function make_insurance()
777 make_visible_row();
778 make_it_hide();
779 cursor_pointer();
780 document.getElementById('radio_type_of_payment1').checked=true;
782 //--------------------------------------------------------------------------------------------------//
783 $('#paySubmit').click( function(e) {
784 e.preventDefault()
785 $("#mode").val( "portal-save" );
786 var inv_values= JSON.stringify(getFormObj('payfrm'));
787 var extra_values=JSON.stringify(getFormObj('paycredit'));
788 var extra = "&inv_values="+inv_values+"&extra_values="+extra_values;
790 var flag = 0
791 var liburl = './lib/paylib.php';
792 $.ajax({
793 type: "POST",
794 url: liburl,
795 data: $("#payfrm").serialize()+extra,
796 beforeSend: function(xhr){
797 if( validateCC() !== true) return false;
798 if( $('#pin').val() == "" || $('#ccname').val() == "" || $('#ccyear').val() == "" || $('#ccmonth').val() == ""){
799 alert("<?php echo addslashes(xl('Invalid Credit Card Values: Please correct')) ?>")
800 return false;
802 if( validate() != true){
803 flag = 1;
804 alert("<?php echo addslashes(xl('Validation error: Fix and resubmit. This popup info is preserved!')) ?>")
805 return false;
807 $("#openPayModal .close").click()
809 error: function(qXHR, textStatus, errorThrow){
810 console.log("There was an error:"+errorThrow);
812 success: function(templateHtml, textStatus, jqXHR){
813 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')) ?>")
814 window.location.reload(false);
817 if(flag)
818 $("#openPayModal .close").click();
820 //---------------------------------------------------------------------------------------//
821 $("#payfrm").on('submit', function(e){
822 e.preventDefault();
823 var thisform = this;
824 $("#mode").val( "review-save" );
825 var inv_values= JSON.stringify(getFormObj('payfrm'));
826 var extra_values=JSON.stringify(getFormObj('paycredit'));
827 var extra = "&inv_values="+inv_values+"&extra_values="+extra_values;
829 var flag = 0
830 var liburl ='<?php echo $GLOBALS["webroot"] ?>/portal/lib/paylib.php';
831 $.ajax({
832 type: "POST",
833 url: liburl,
834 data: $("#payfrm").serialize()+extra,
835 beforeSend: function(xhr){
836 if( validate() != true){
837 flag = 1;
838 alert("<?php echo addslashes(xl('Validation error: Fix and resubmit. Payment values are preserved!')) ?>")
839 return false;
842 error: function(xhr, textStatus, error){
843 alert("<?php echo addslashes(xl('There is a Post error')) ?>")
844 console.log("There was an error:"+textStatus);
845 return false;
847 success: function(templateHtml, textStatus, jqXHR){
848 thisform.submit();
852 function getFormObj(formId) {
853 var formObj = {};
854 var inputs = $('#'+formId).serializeArray();
855 $.each(inputs, function (i, input) {
856 formObj[input.name] = input.value;
858 return formObj;
860 function formRepopulate(jsondata){
861 data = $.parseJSON(jsondata);
862 $.each(data, function(name, val){
863 var $el = $('[name="'+name+'"]'),
864 type = $el.attr('type');
865 switch(type){
866 case 'checkbox':
867 $el.prop('checked',true);
868 break;
869 case 'radio':
870 $el.filter('[value="'+val+'"]').prop('checked', true);
871 break;
872 default:
873 $el.val(val);
877 function getAuth(){
878 var authnum = prompt("<?php echo xlt('Please enter card comfirmation authorization') ?>", "");
879 if (authnum != null) {
880 $('#check_number').val(authnum);
883 </script>
885 <body class="body_top" onunload='imclosing()' onLoad="cursor_pointer();"
886 style="text-align: center; margin: auto;">
888 <form id="payfrm" method='post'
889 action='<?php echo $GLOBALS["webroot"] ?>/portal/portal_payment.php'>
890 <input type='hidden' name='form_pid' value='<?php echo attr($pid) ?>' />
891 <input type='hidden' name='form_save'
892 value='<?php echo xlt('Invoice');?>' />
894 <table>
895 <tr height="10">
896 <td colspan="3">&nbsp;</td>
897 </tr>
899 <tr>
900 <td colspan='3' align='center' class='text'><b><?php echo xlt('Accept Payment for'); ?>&nbsp;:&nbsp;&nbsp;<?php
902 echo htmlspecialchars($patdata['fname'], ENT_QUOTES) . " " . htmlspecialchars($patdata['lname'], ENT_QUOTES) . " " . htmlspecialchars($patdata['mname'], ENT_QUOTES) . " (" . htmlspecialchars($patdata['pid'], ENT_QUOTES) . ")"?></b>
903 <?php $NameNew=$patdata['fname'] . " " .$patdata['lname']. " " .$patdata['mname'];?>
904 </td>
905 </tr>
906 <tr height="15">
907 <td colspan='3'></td>
908 </tr>
909 <tr>
910 <td class='text'>
911 <?php echo xlt('Payment Method'); ?>:
912 </td>
913 <td colspan='2'><select name="form_method" id="form_method"
914 class="text" onChange='CheckVisible("yes")'>
915 <?php
916 $query1112 = "SELECT * FROM list_options where list_id=? ORDER BY seq, title ";
917 $bres1112 = sqlStatement($query1112, array ('payment_method'));
918 while ($brow1112 = sqlFetchArray($bres1112)) {
919 if ($brow1112['option_id'] != 'credit_card' || $brow1112['option_id'] == 'electronic' || $brow1112['option_id'] == 'bank_draft') {
920 continue;
923 echo "<option value='" . htmlspecialchars($brow1112['option_id'], ENT_QUOTES) . "'>" . htmlspecialchars(xl_list_label($brow1112['title']), ENT_QUOTES) . "</option>";
926 </select></td>
927 </tr>
929 <tr height="5">
930 <td colspan='3'></td>
931 </tr>
933 <tr>
934 <td class='text'>
935 <?php echo xla('Authorized'); ?>:
936 </td>
937 <td colspan='2'>
938 <?php
939 if (isset($_SESSION['authUserID'])) {
940 echo "<input type='text' id='check_number' name='form_source' style='width:120px;' value='" . htmlspecialchars($payrow['source'], ENT_QUOTES) . "'>";
943 </td>
944 </tr>
945 <tr height="5">
946 <td colspan='3'></td>
947 </tr>
948 <tr>
949 <td class='text' valign="middle">
950 <?php echo xlt('Patient Coverage'); ?>:
951 </td>
952 <td class='text' colspan="2">
953 <input type="radio" name="radio_type_of_coverage" id="radio_type_of_coverage1"
954 value="self" onClick="make_visible_radio();make_self();" />
955 <?php echo xlt('Self'); ?>
956 <input type="radio" name="radio_type_of_coverage" id="radio_type_of_coverag2" value="insurance" checked="checked"
957 onClick="make_hide_radio();make_insurance();" />
958 <?php echo xlt('Insurance'); ?>
959 </td>
960 </tr>
961 <tr height="5">
962 <td colspan='3'></td>
963 </tr>
964 <tr id="tr_radio1" style="display: none">
965 <!-- For radio Insurance -->
966 <td class='text' valign="top">
967 <?php echo xlt('Payment against'); ?>:
968 </td>
969 <td class='text' colspan="2">
970 <input type="radio" name="radio_type_of_payment" id="radio_type_of_payment_self1"
971 value="cash" onClick="make_visible_row();make_it_hide_enc_pay();cursor_pointer();" />
972 <?php echo xlt('Encounter Payment'); ?>
973 </td>
974 </tr>
975 <tr id="tr_radio2">
976 <!-- For radio self -->
977 <td class='text' valign="top"><?php echo xlt('Payment against'); ?>:
978 </td>
979 <td class='text' colspan="2"><input type="radio" name="radio_type_of_payment" id="radio_type_of_payment1" checked="checked"
980 value="copay" onClick="make_visible_row();cursor_pointer();" /><?php echo xlt('Co Pay'); ?>
981 <input type="radio" name="radio_type_of_payment" id="radio_type_of_payment2"
982 value="invoice_balance" onClick="make_visible_row();" /><?php echo xlt('Invoice Balance'); ?><br />
983 <input type="radio" name="radio_type_of_payment" id="radio_type_of_payment4" value="pre_payment"
984 onClick="make_hide_row();" /><?php echo xlt('Pre Pay'); ?></td>
985 </tr>
986 <tr height="15">
987 <td colspan='3'></td>
988 </tr>
989 </table>
990 <table width="35%" border="0" cellspacing="0" cellpadding="0" id="table_display_prepayment" style="display: none">
991 <tr>
992 <td class='detail'><?php echo xlt('Pre Payment'); ?></td>
993 <td><input class="form-control" type='text' name='form_prepayment' style='width: 100px' /></td>
994 </tr>
995 </table>
996 <table id="table_display" style="width: 100%; background: #eee;" class="table table-striped table-responsive">
997 <thead>
998 </thead>
999 <tbody>
1000 <!-- <table border='0' id="table_display" cellpadding='0' cellspacing='0' width='100%'> -->
1001 <tr bgcolor="#cccccc" id="tr_head">
1002 <td class="dehead" width="60">
1003 <?php echo xlt('DOS')?>
1004 </td>
1005 <td class="dehead" width="120">
1006 <?php echo xlt('Visit Reason')?>
1007 </td>
1008 <td class="dehead" align="center" width="70" id="td_head_total_charge">
1009 <?php echo xlt('Total Charge')?>
1010 </td>
1011 <td class="dehead" align="center" width="70" id="td_head_rep_doc" style='display: none'>
1012 <?php echo xlt('Report/ Form')?>
1013 </td>
1014 <td class="dehead" align="center" width="200" id="td_head_description" style='display: none'>
1015 <?php echo xlt('Description')?>
1016 </td>
1017 <td class="dehead" align="center" width="70" id="td_head_insurance_payment">
1018 <?php echo xlt('Insurance Payment')?>
1019 </td>
1020 <td class="dehead" align="center" width="70" id="td_head_patient_payment">
1021 <?php echo xlt('Patient Payment')?>
1022 </td>
1023 <td class="dehead" align="center" width="55" id="td_head_patient_co_pay">
1024 <?php echo xlt('Co Pay Paid')?>
1025 </td>
1026 <td class="dehead" align="center" width="55" id="td_head_co_pay">
1027 <?php echo xlt('Required Co Pay')?>
1028 </td>
1029 <td class="dehead" align="center" width="70" id="td_head_insurance_balance">
1030 <?php echo xlt('Insurance Balance')?>
1031 </td>
1032 <td class="dehead" align="center" width="70" id="td_head_patient_balance">
1033 <?php echo xlt('Patient Balance')?>
1034 </td>
1035 <td class="dehead" align="center" width="50">
1036 <?php echo xlt('Paying')?>
1037 </td>
1038 </tr>
1039 <?php
1040 $encs = array ();
1041 // Get the unbilled service charges and payments by encounter for this patient.
1043 $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
1044 "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";
1045 $bres = sqlStatement($query, array ($pid,$pid));
1047 while ($brow = sqlFetchArray($bres)) {
1048 $key = 0 + $brow['encounter'];
1049 if (empty($encs[$key])) {
1050 $encs[$key] = array ('encounter' => $brow['encounter'],'date' => $brow['encdate'],'last_level_closed' => $brow['last_level_closed'],'charges' => 0,'payments' => 0,'reason'=>$brow['reason']
1054 if ($brow['code_type'] === 'COPAY') {
1055 // $encs[$key]['payments'] -= $brow['fee'];
1056 } else {
1057 $encs[$key]['charges'] += $brow['fee'];
1058 // Add taxes.
1059 $sql_array = array ();
1060 $query = "SELECT taxrates FROM codes WHERE " . "code_type = ? AND " . "code = ? AND ";
1061 array_push($sql_array, $code_types[$brow['code_type']]['id'], $brow['code']);
1062 if ($brow['modifier']) {
1063 $query .= "modifier = ?";
1064 array_push($sql_array, $brow['modifier']);
1065 } else {
1066 $query .= "(modifier IS NULL OR modifier = '')";
1069 $query .= " LIMIT 1";
1070 $trow = sqlQuery($query, $sql_array);
1071 $encs[$key]['charges'] += calcTaxes($trow, $brow['fee']);
1075 // Do the same for unbilled product sales.
1077 $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
1078 "AND fe.pid = s.pid AND fe.encounter = s.encounter " . "where fe.pid = ? " . "ORDER BY s.encounter";
1080 $dres = sqlStatement($query, array ($pid,$pid));
1082 while ($drow = sqlFetchArray($dres)) {
1083 $key = 0 + $drow['encounter'];
1084 if (empty($encs[$key])) {
1085 $encs[$key] = array ('encounter' => $drow['encounter'],'date' => $drow['encdate'],'last_level_closed' => $drow['last_level_closed'],'charges' => 0,'payments' => 0
1089 $encs[$key]['charges'] += $drow['fee'];
1090 // Add taxes.
1091 $trow = sqlQuery("SELECT taxrates FROM drug_templates WHERE drug_id = ? " . "ORDER BY selector LIMIT 1", array ($drow['drug_id']
1093 $encs[$key]['charges'] += calcTaxes($trow, $drow['fee']);
1096 ksort($encs, SORT_NUMERIC);
1097 $gottoday = false;
1098 // Bringing on top the Today always
1099 foreach ($encs as $key => $value) {
1100 $dispdate = $value['date'];
1101 if (strcmp($dispdate, $today) == 0 && ! $gottoday) {
1102 $gottoday = true;
1103 break;
1107 // If no billing was entered yet for today, then generate a line for
1108 // entering today's co-pay.
1110 if (! $gottoday) {
1111 // echoLine("form_upay[0]", date("Y-m-d"), 0, 0, 0, 0 /*$duept*/);//No encounter yet defined.
1114 $gottoday = false;
1115 foreach ($encs as $key => $value) {
1116 $enc = $value['encounter'];
1117 $reason = $value['reason'];
1118 $dispdate = $value['date'];
1119 if (strcmp($dispdate, $today) == 0 && ! $gottoday) {
1120 $dispdate = date("Y-m-d");
1121 $gottoday = true;
1124 // ------------------------------------------------------------------------------------
1125 $inscopay = getCopay($pid, $dispdate);
1126 $patcopay = getPatientCopay($pid, $enc);
1127 // Insurance Payment
1128 // -----------------
1129 $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
1131 $dpayment = $drow['payments'];
1132 $dadjustment = $drow['adjustments'];
1133 // Patient Payment
1134 // ---------------
1135 $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
1137 $dpayment_pat = $drow['payments'];
1139 // ------------------------------------------------------------------------------------
1140 // NumberOfInsurance
1141 $ResultNumberOfInsurance = sqlStatement("SELECT COUNT( DISTINCT TYPE ) NumberOfInsurance FROM insurance_data
1142 where pid = ? and provider>0 ", array ($pid
1144 $RowNumberOfInsurance = sqlFetchArray($ResultNumberOfInsurance);
1145 $NumberOfInsurance = $RowNumberOfInsurance['NumberOfInsurance'] * 1;
1146 // ------------------------------------------------------------------------------------
1147 $duept = 0;
1148 if (( ( $NumberOfInsurance == 0 || $value['last_level_closed'] == 4 || $NumberOfInsurance == $value['last_level_closed'] ) )) { // Patient balance
1149 $brow = sqlQuery("SELECT SUM(fee) AS amount FROM billing WHERE " . "pid = ? and encounter = ? AND activity = 1", array ($pid,$enc
1151 $srow = sqlQuery("SELECT SUM(fee) AS amount FROM drug_sales WHERE " . "pid = ? and encounter = ? ", array ($pid,$enc
1153 $drow = sqlQuery("SELECT SUM(pay_amount) AS payments, " . "SUM(adj_amount) AS adjustments FROM ar_activity WHERE " . "pid = ? and encounter = ? ", array ($pid,$enc
1155 $duept = $brow['amount'] + $srow['amount'] - $drow['payments'] - $drow['adjustments'];
1158 echoLine("form_upay[$enc]", $dispdate, $value['charges'], $dpayment_pat, ( $dpayment + $dadjustment ), $duept, ($enc.':'.$reason), $inscopay, $patcopay);
1161 // Continue with display of the data entry form.
1163 <tr>
1164 <td class="dehead" id='td_total_1'></td>
1165 <td class="dehead" id='td_total_2'></td>
1166 <td class="dehead" id='td_total_3'></td>
1167 <td class="dehead" id='td_total_4'></td>
1168 <td class="dehead" id='td_total_5'></td>
1169 <td class="dehead" id='td_total_6'></td>
1170 <td class="dehead" id='td_total_7'></td>
1171 <td class="dehead" id='td_total_8'></td>
1172 <td class="dehead" align="right"><?php echo xlt('Total');?></td>
1173 <td class="dehead" align="right"><input class="form-control" type='text' name='form_paytotal'
1174 value='' style='color: #00aa00; width: 65px; padding: 1px 1px;' readonly />
1175 </td>
1176 </tr>
1177 </table>
1178 <?php
1179 if (isset($ccdata["name"])) {
1180 echo '<div class="col-xs-12 col-md-4 col-lg-4">
1181 <div class="panel panel-default height">';
1182 if (! isset($_SESSION['authUserID'])) {
1183 echo '<div class="panel-heading">'.xlt("Payment Information").'<span style="color:#cc0000"><em> '.xlt("Pending Auth since").': </em>'.text($edata["date"]).'</span></div>';
1184 } else {
1185 echo '<div class="panel-heading">'.xlt("Payment Information").' <button type="button" class="btn btn-danger btn-sm" onclick="getAuth()">'.xlt("Authorize").'</button></div>';
1187 } else {
1188 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>';
1191 <div class="panel-body">
1192 <strong><?php echo xlt('Card Name');?>: </strong><span id="cn"><?php echo attr($ccdata["cc_type"])?></span><br>
1193 <strong><?php echo xlt('Name On Card');?>: </strong><span id="nc"><?php echo attr($ccdata["name"])?></span><br>
1194 <strong><?php echo xlt('Card Number');?>: </strong><span id="ccn"><?php
1195 if (isset($_SESSION['authUserID'])) {
1196 echo $ccdata["cc_number"] . "</span><br>";
1197 } else {
1198 echo "********** ".substr($ccdata["cc_number"], -4) . "</span><br>";
1201 <strong><?php echo xlt('Exp Date');?>: </strong><span id="ed"><?php echo attr($ccdata["month"])."/".attr($ccdata["year"])?></span><br>
1202 <strong><?php echo xlt('Charge Total');?>: </strong><span id="ct"><?php echo attr($invdata["form_paytotal"])?></span><br>
1203 </div>
1204 </div>
1205 </div>
1207 <?php
1208 if (! isset($_SESSION['authUserID'])) {
1209 echo '<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#openPayModal">' . xlt("Pay Invoice") . '</button>';
1210 } else {
1211 echo "<button type='submit' class='btn btn-danger' form='payfrm'>" . xlt('Post Payment') . "</button>";
1214 &nbsp;
1215 </p>
1216 <input type="hidden" name="hidden_patient_code" id="hidden_patient_code" value="<?php echo attr($pid);?>" />
1217 <input type='hidden' name='mode' id='mode' value='' />
1218 </form>
1220 <script type="text/javascript">
1221 if (typeof jsondata !== 'undefined') {
1222 formRepopulate(jsondata);
1224 calctotal();
1225 </script>
1226 <!-- credit payment modal -->
1227 <div id="openPayModal" class="modal fade" role="dialog">
1228 <div class="modal-dialog">
1229 <div class="modal-content">
1230 <div class="modal-header">
1231 <h3><?php echo xlt('Submit Payment for Authorization');?></h3>
1232 <button type="button" class="close" data-dismiss="modal">&times;</button>
1233 </div>
1234 <div class="modal-body container">
1235 <form id='paycredit' class="form-horizontal col-xs-12 col-sm-6 col-md-6">
1236 <fieldset>
1237 <div class="control-group">
1238 <label label-default="label-default" class="control-label"><?php echo xlt('Name on Card');?></label>
1239 <div class="controls">
1240 <input name="name" id="ccname" type="text" class="form-control"
1241 pattern="\w+ \w+.*" title="<?php echo xla('Fill your first and last name'); ?>"
1242 required value="" />
1243 </div>
1244 </div>
1245 <div class="control-group">
1246 <label class="control-label"><?php echo xlt('Card Number');?></label>
1247 <div class="controls">
1248 <div class="row">
1249 <div class="col-sm-12">
1250 <input name="cc_number" id="cc_number" type="text" class="form-control inline col-sm-3"
1251 autocomplete="off" maxlength="19" pattern="\d" onchange="validateCC()"
1252 title="<?php echo xla('Card Number'); ?>" required value="" />
1253 <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="" />
1254 </div>
1255 </div>
1256 </div>
1257 </div>
1258 <div class="control-group">
1259 <label label-default="label-default" class="control-label"><?php echo xlt('Card Expiry Date');?></label>
1260 <div class="controls">
1261 <div class="row">
1262 <div class="col-md-4">
1263 <select name="month" id="ccmonth" class="form-control">
1264 <option value=""><?php echo xlt('Select Month'); ?></option>
1265 <option value="01"><?php echo xlt('January'); ?></option>
1266 <option value="02"><?php echo xlt('February'); ?></option>
1267 <option value="03"><?php echo xlt('March'); ?></option>
1268 <option value="04"><?php echo xlt('April'); ?></option>
1269 <option value="05"><?php echo xlt('May'); ?></option>
1270 <option value="06"><?php echo xlt('June'); ?></option>
1271 <option value="07"><?php echo xlt('July'); ?></option>
1272 <option value="08"><?php echo xlt('August'); ?></option>
1273 <option value="09"><?php echo xlt('September'); ?></option>
1274 <option value="10"><?php echo xlt('October'); ?></option>
1275 <option value="11"><?php echo xlt('November'); ?></option>
1276 <option value="12"><?php echo xlt('December'); ?></option>
1277 </select>
1278 </div>
1279 <div class="col-md-3">
1280 <select name="year" id="ccyear" class="form-control">
1281 <option value=""><?php echo xlt('Select Year'); ?></option>
1282 <option value="2017">2017</option>
1283 <option value="2018">2018</option>
1284 <option value="2019">2019</option>
1285 <option value="2020">2020</option>
1286 <option value="2021">2021</option>
1287 <option value="2022">2022</option>
1288 <option value="2023">2023</option>
1289 <option value="2024">2024</option>
1290 </select>
1291 </div>
1292 </div>
1293 </div>
1294 </div>
1295 <div class="control-group">
1296 <label label-default="label-default" class="control-label"><?php echo xlt('Card CVV');?></label>
1297 <div class="controls">
1298 <div class="row">
1299 <div class="col-md-3">
1300 <input name="pin" id="pin" type="text" class="form-control"
1301 autocomplete="off" maxlength="4" pattern="\d{3}" onfocus="validateCC()"
1302 title="<?php echo xlt('Three or four digits at back of your card'); ?>" required value="" />
1303 </div>
1304 <div class="col-md-3">
1305 <img src='./images/img_cvc.png' style='height: 58px; width: auto'>
1306 </div>
1307 </div>
1308 </div>
1309 </div>
1310 <div class="form-actions">
1311 <button id="paySubmit" class="btn btn-danger"><?php echo xlt('Submit');?></button>
1312 <button type="button" class="btn btn-default" data-dismiss="modal"><?php echo xlt('Cancel');?></button>
1313 </div>
1314 </fieldset>
1315 <input type='hidden' name='cc_type' id='cc_type' value='' />
1316 </form>
1317 </div>
1318 <!-- Body -->
1319 <div class="modal-footer">
1320 <button type="button" class="btn btn-default" data-dismiss="modal"><?php echo xlt('Close');?></button>
1321 </div>
1322 </div>
1323 </div>
1324 </div>
1325 <?php echo "<script>var ccerr='". xlt('Invalid Credit Card Number') . "';</script>";?>
1326 <script type="text/javascript">
1327 $('#cc_number').validateCreditCard(function(result){
1328 var r = (result.card_type == null ? '' : result.card_type.name.toUpperCase())
1329 var v = (result.valid== true ? ' Valid #' : ' Invalid #')
1330 $('#cardtype').val(r+v);
1332 function validateCC() {
1333 var result = $('#cc_number').validateCreditCard();
1334 var r = (result.card_type == null ? '' : result.card_type.name.toUpperCase())
1335 var v = (result.valid == true ? ' Okay' : ' Invalid #')
1336 $('#cardtype').val(r+v);
1337 $('#cc_type').val(r);
1338 if(!result.valid){
1339 alert(ccerr)
1340 return false;
1342 else{
1343 return true;
1346 </script>
1347 </body>
1348 <?php