jquery updates
[openemr.git] / portal / portal_payment.php
blob807d30dcec52ca9355f8353dccc74b0cdde84d3c
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");
55 require_once("$srcdir/log.inc");
56 require_once("$srcdir/crypto.php");
58 $appsql = new ApplicationTable();
59 $pid = isset($_REQUEST['pid']) ? $_REQUEST['pid'] : $pid;
60 $pid = $_REQUEST['hidden_patient_code'] > 0 ? $_REQUEST['hidden_patient_code'] : $pid;
61 $adminUser = '';
62 $portalPatient = '';
64 $query = "SELECT pao.portal_username as recip_id, Concat_Ws(' ', patient_data.fname, patient_data.lname) as username FROM patient_data " .
65 "LEFT JOIN patient_access_onsite pao ON pao.pid = patient_data.pid " .
66 "WHERE patient_data.pid = ? AND pao.portal_pwd_status = 1";
67 $portalPatient = sqlQueryNoLog($query, $pid);
68 if ($_SESSION['authUserID']) {
69 $query = "SELECT users.username as recip_id, users.authorized as dash, CONCAT(users.fname,' ',users.lname) as username " .
70 "FROM users WHERE id = ?";
71 $adminUser = sqlQueryNoLog($query, $_SESSION['authUserID']);
73 $edata = $appsql->getPortalAudit($pid, 'review', 'payment');
74 $ccdata = array();
75 $invdata = array();
77 if ($edata) {
78 $ccdata = json_decode(aes256Decrypt($edata['checksum']), true);
79 $invdata = json_decode($edata['table_args'], true);
80 echo "<script type='text/javascript'>var jsondata='" . $edata['table_args'] . "';var ccdata='" . $edata['checksum'] . "'</script>";
83 function bucks($amount)
85 if ($amount) {
86 $amount = oeFormatMoney($amount);
87 return $amount;
90 return '';
93 function rawbucks($amount)
95 if ($amount) {
96 $amount = sprintf("%.2f", $amount);
97 return $amount;
100 return '';
103 // Display a row of data for an encounter.
105 $var_index = 0;
106 function echoLine($iname, $date, $charges, $ptpaid, $inspaid, $duept, $encounter = 0, $copay = 0, $patcopay = 0)
108 global $var_index;
109 $var_index++;
110 $balance = bucks($charges - $ptpaid - $inspaid);
111 $balance = (round($duept, 2) != 0) ? 0 : $balance; // if balance is due from patient, then insurance balance is displayed as zero
112 $encounter = $encounter ? $encounter : '';
113 echo " <tr id='tr_" . attr($var_index) . "' >\n";
114 echo " <td class='detail'>" . text(oeFormatShortDate($date)) . "</td>\n";
115 echo " <td class='detail' id='" . attr($date) . "' align='left'>" . htmlspecialchars($encounter, ENT_QUOTES) . "</td>\n";
116 echo " <td class='detail' align='center' id='td_charges_$var_index' >" . htmlspecialchars(bucks($charges), ENT_QUOTES) . "</td>\n";
117 echo " <td class='detail' align='center' id='td_inspaid_$var_index' >" . htmlspecialchars(bucks($inspaid * -1), ENT_QUOTES) . "</td>\n";
118 echo " <td class='detail' align='center' id='td_ptpaid_$var_index' >" . htmlspecialchars(bucks($ptpaid * -1), ENT_QUOTES) . "</td>\n";
119 echo " <td class='detail' align='center' id='td_patient_copay_$var_index' >" . htmlspecialchars(bucks($patcopay), ENT_QUOTES) . "</td>\n";
120 echo " <td class='detail' align='center' id='td_copay_$var_index' >" . htmlspecialchars(bucks($copay), ENT_QUOTES) . "</td>\n";
121 echo " <td class='detail' align='center' id='balance_$var_index'>" . htmlspecialchars(bucks($balance), ENT_QUOTES) . "</td>\n";
122 echo " <td class='detail' align='center' id='duept_$var_index'>" . htmlspecialchars(bucks(round($duept, 2) * 1), ENT_QUOTES) . "</td>\n";
123 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";
124 echo " </tr>\n";
127 // We use this to put dashes, colons, etc. back into a timestamp.
129 function decorateString($fmt, $str)
131 $res = '';
132 while ($fmt) {
133 $fc = substr($fmt, 0, 1);
134 $fmt = substr($fmt, 1);
135 if ($fc == '.') {
136 $res .= substr($str, 0, 1);
137 $str = substr($str, 1);
138 } else {
139 $res .= $fc;
143 return $res;
146 // Compute taxes from a tax rate string and a possibly taxable amount.
148 function calcTaxes($row, $amount)
150 $total = 0;
151 if (empty($row['taxrates'])) {
152 return $total;
155 $arates = explode(':', $row['taxrates']);
156 if (empty($arates)) {
157 return $total;
160 foreach ($arates as $value) {
161 if (empty($value)) {
162 continue;
165 $trow = sqlQuery("SELECT option_value FROM list_options WHERE " . "list_id = 'taxrate' AND option_id = ? LIMIT 1", array($value
167 if (empty($trow['option_value'])) {
168 echo "<!-- Missing tax rate '" . text($value) . "'! -->\n";
169 continue;
172 $tax = sprintf("%01.2f", $amount * $trow['option_value']);
173 // echo "<!-- Rate = '$value', amount = '$amount', tax = '$tax' -->\n";
174 $total += $tax;
177 return $total;
180 $now = time();
181 $today = date('Y-m-d', $now);
182 $timestamp = date('Y-m-d H:i:s', $now);
185 // $patdata = getPatientData($pid, 'fname,lname,pubpid');
187 $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
190 $alertmsg = ''; // anything here pops up in an alert box
192 // If the Save button was clicked...
193 if ($_POST['form_save']) {
194 // $extra = json_decode($_POST['ajax_mode'], true);
195 $form_pid = $_POST['form_pid'];
196 $form_method = trim($_POST['form_method']);
197 $form_source = trim($_POST['form_source']);
198 $patdata = getPatientData($form_pid, 'fname,mname,lname,pubpid');
199 $NameNew = $patdata['fname'] . " " . $patdata['lname'] . " " . $patdata['mname'];
201 if ($_REQUEST['radio_type_of_payment'] == 'pre_payment') {
202 $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(
203 0, $form_pid, $_SESSION['authUserID'], 0, $form_source, $_REQUEST['form_prepayment'], $NameNew, $form_method
206 frontPayment($form_pid, 0, $form_method, $form_source, $_REQUEST['form_prepayment'], 0, $timestamp); // insertion to 'payments' table.
209 if ($_POST['form_upay'] && $_REQUEST['radio_type_of_payment'] != 'pre_payment') {
210 foreach ($_POST['form_upay'] as $enc => $payment) {
211 if ($amount = 0 + $payment) {
212 $zero_enc = $enc;
213 if ($_REQUEST['radio_type_of_payment'] == 'invoice_balance') {
215 } else {
216 if (!$enc) {
217 $enc = calendar_arrived($form_pid);
221 // ----------------------------------------------------------------------------------------------------
222 // Fetching the existing code and modifier
223 $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
225 if ($RowSearch = sqlFetchArray($ResultSearchNew)) {
226 $Codetype = $RowSearch['code_type'];
227 $Code = $RowSearch['code'];
228 $Modifier = $RowSearch['modifier'];
229 } else {
230 $Codetype = '';
231 $Code = '';
232 $Modifier = '';
235 // ----------------------------------------------------------------------------------------------------
236 if ($_REQUEST['radio_type_of_payment'] == 'copay') { // copay saving to ar_session and ar_activity tables
237 $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(
238 $_SESSION['authId'], $form_source, $amount, $form_pid, $form_method
241 $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
244 frontPayment($form_pid, $enc, $form_method, $form_source, $amount, 0, $timestamp); // insertion to 'payments' table.
247 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.
248 if ($_REQUEST['radio_type_of_payment'] == 'cash') {
249 sqlStatement("update form_encounter set last_level_closed=? where encounter=? and pid=? ", array(4, $enc, $form_pid
251 sqlStatement("update billing set billed=? where encounter=? and pid=?", array(1, $enc, $form_pid
255 $adjustment_code = 'patient_payment';
256 $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(
257 0, $form_pid, $_SESSION['authUserID'], 0, $form_source, $amount, $NameNew, $adjustment_code, $form_method
260 // --------------------------------------------------------------------------------------------------------------------
262 frontPayment($form_pid, $enc, $form_method, $form_source, 0, $amount, $timestamp); // insertion to 'payments' table.
264 // --------------------------------------------------------------------------------------------------------------------
266 $resMoneyGot = sqlStatement("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
267 )); // new fees screen copay gives account_code='PCP'
268 $rowMoneyGot = sqlFetchArray($resMoneyGot);
269 $Copay = $rowMoneyGot['PatientPay'];
271 // --------------------------------------------------------------------------------------------------------------------
273 // Looping the existing code and modifier
274 $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
276 while ($RowSearch = sqlFetchArray($ResultSearchNew)) {
277 $Codetype = $RowSearch['code_type'];
278 $Code = $RowSearch['code'];
279 $Modifier = $RowSearch['modifier'];
280 $Fee = $RowSearch['fee'];
282 $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
284 // new fees screen copay gives account_code='PCP'
285 $rowMoneyGot = sqlFetchArray($resMoneyGot);
286 $MoneyGot = $rowMoneyGot['MoneyGot'];
288 $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
290 $rowMoneyAdjusted = sqlFetchArray($resMoneyAdjusted);
291 $MoneyAdjusted = $rowMoneyAdjusted['MoneyAdjusted'];
293 $Remainder = $Fee - $Copay - $MoneyGot - $MoneyAdjusted;
294 $Copay = 0;
295 if (round($Remainder, 2) != 0 && $amount != 0) {
296 if ($amount - $Remainder >= 0) {
297 $insert_value = $Remainder;
298 $amount = $amount - $Remainder;
299 } else {
300 $insert_value = $amount;
301 $amount = 0;
304 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(
305 $form_pid, $enc, $Codetype, $Code, $Modifier, 0, 3, $payment_id, $insert_value, 0
307 } // if
308 } // while
309 if ($amount != 0) { // if any excess is there.
310 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(
311 $form_pid, $enc, $Codetype, $Code, $Modifier, 0, 3, $payment_id, $amount, 0
315 // --------------------------------------------------------------------------------------------------------------------
316 } // invoice_balance
317 } // if ($amount = 0 + $payment)
318 } // foreach
319 } // if ($_POST['form_upay'])
320 } // if ($_POST['form_save'])
322 if ($_POST['form_save'] || $_REQUEST['receipt']) {
323 if ($_REQUEST['receipt']) {
324 $form_pid = $_GET['patient'];
325 $timestamp = decorateString('....-..-.. ..:..:..', $_GET['time']);
328 // Get details for what we guess is the primary facility.
329 $frow = sqlQuery("SELECT * FROM facility " . "ORDER BY billing_location DESC, accepts_assignment DESC, id LIMIT 1");
331 // Get the patient's name and chart number.
332 $patdata = getPatientData($form_pid, 'fname,mname,lname,pubpid');
334 // Re-fetch payment info.
335 $payrow = sqlQuery("SELECT " . "SUM(amount1) AS amount1, " . "SUM(amount2) AS amount2, " . "MAX(method) AS method, " . "MAX(source) AS source, " . "MAX(dtime) AS dtime, " .
336 // "MAX(user) AS user " .
337 "MAX(user) AS user, " . "MAX(encounter) as encounter " . "FROM payments WHERE " . "pid = ? AND dtime = ?", array($form_pid, $timestamp
340 // Create key for deleting, just in case.
341 $ref_id = ($_REQUEST['radio_type_of_payment'] == 'copay') ? $session_id : $payment_id;
342 $payment_key = $form_pid . '.' . preg_replace('/[^0-9]/', '', $timestamp) . '.' . $ref_id;
344 // get facility from encounter
345 $tmprow = sqlQuery("
346 SELECT facility_id
347 FROM form_encounter
348 WHERE encounter = ?", array($payrow['encounter']
350 $frow = sqlQuery("SELECT * FROM facility " . " WHERE id = ?", array($tmprow['facility_id']
353 // Now proceed with printing the receipt.
356 <title><?php echo xlt('Receipt for Payment'); ?></title>
358 <script type="text/javascript"
359 src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-1-11-3/dist/jquery.js"></script>
360 <script type="text/javascript">
361 $(document).ready();
363 function goHome() {
364 window.location.replace("./patient/onsiteactivityviews");
367 function notifyPatient() {
368 let pid = <?php echo attr($pid);?>;
369 let note = $('#pop_receipt').html();
370 let formURL = './messaging/handle_note.php';
371 let owner = '<?php echo attr($adminUser['recip_id']); ?>';
372 let sn = '<?php echo attr($adminUser['username']); ?>';
373 let rid = '<?php echo attr($portalPatient['recip_id']); ?>';
374 let rn = '<?php echo attr($portalPatient['username']); ?>';
375 $.ajax({
376 url: formURL,
377 type: "POST",
378 data: {
379 'task': 'add',
380 'owner': owner,
381 'pid': pid,
382 'inputBody': note,
383 'title': 'Bill/Collect',
384 'recipient_name': rn,
385 'recipient_id': rid,
386 'sender_id': owner,
387 'sender_name': sn
389 success: function (data, textStatus, jqXHR) {
390 alert('Receipt sent to patient via Messages.')
392 error: function (jqXHR, status, error) {
393 console.log(status + ": " + error);
397 </script>
398 <?php
399 ob_start();
400 echo '<htlm><head></head><body style="text-align: center; margin: auto;">';
403 <div id='pop_receipt' style='display: block'>
405 <h2><?php echo xlt('Receipt for Payment'); ?></h2>
406 <p><?php echo text($frow['name']) ?>
407 <br><?php echo text($frow['street']) ?>
408 <br><?php echo text($frow['city'] . ', ' . $frow['state']) . ' ' . text($frow['postal_code']) ?>
409 <br><?php echo htmlentities($frow['phone']) ?>
411 <div style="text-align: center; margin: auto;">
412 <table border='0' cellspacing='8'
413 style="text-align: center; margin: auto;">
414 <tr>
415 <td><?php echo xlt('Date'); ?>:</td>
416 <td><?php echo text(oeFormatSDFT(strtotime($payrow['dtime']))) ?></td>
417 </tr>
418 <tr>
419 <td><?php echo xlt('Patient'); ?>:</td>
420 <td><?php echo text($patdata['fname']) . " " . text($patdata['mname']) . " " . text($patdata['lname']) . " (" . text($patdata['pubpid']) . ")" ?></td>
421 </tr>
422 <tr>
423 <td><?php echo xlt('Paid Via'); ?>:</td>
424 <td><?php echo generate_display_field(array('data_type' => '1', 'list_id' => 'payment_method'), $payrow['method']); ?></td>
425 </tr>
426 <tr>
427 <td><?php echo xlt('Authorized Id'); ?>:</td>
428 <td><?php echo text($payrow['source']) ?></td>
429 </tr>
430 <tr>
431 <td><?php echo xlt('Amount for This Visit'); ?>:</td>
432 <td><?php echo text(oeFormatMoney($payrow['amount1'])) ?></td>
433 </tr>
434 <tr>
435 <td><?php echo xlt('Amount for Past Balance'); ?>:</td>
436 <td><?php echo text(oeFormatMoney($payrow['amount2'])) ?></td>
437 </tr>
438 <tr>
439 <td><?php echo xlt('Received By'); ?>:</td>
440 <td><?php echo text($payrow['user']) ?></td>
441 </tr>
442 </table>
443 </div>
444 </div>
445 <button class='btn btn-sm' type='button' onclick='goHome()'
446 id='returnhome'><?php echo xla('Return Home'); ?></button>
447 <button class='btn btn-sm' type='button' onclick="notifyPatient()"><?php echo xla('Notify Patient'); ?></button>
448 </body></html>
449 <?php
450 ob_end_flush();
451 } else {
453 // Here we display the form for data entry.
456 <title><?php echo xlt('Record Payment'); ?></title>
457 <style type="text/css">
458 body {
459 /* font-family:sans-serif; font-size:10pt; font-weight:normal */
462 .dehead {
463 color: #000000; /*font-family:sans-serif; font-size:10pt;*/
464 font-weight: bold
467 .detail {
468 padding: 1px 1px;
469 /* width: 65px; */
470 color: #000000; /*font-family:sans-serif; font-size:10pt; */
471 font-weight: normal
473 </style>
474 <script type="text/javascript"
475 src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-creditcardvalidator/jquery.creditCardValidator.js"></script>
476 <script type="text/javascript"
477 src="<?php echo $GLOBALS['webroot'] ?>/library/textformat.js?v=<?php echo $v_js_includes; ?>"></script>
479 <script type="text/javascript">
480 var mypcc = '1';
482 function calctotal() {
483 var flag = 0;
484 var f = document.forms["payfrm"];
485 var total = 0;
486 for (var i = 0; i < f.elements.length; ++i) {
487 var elem = f.elements[i];
488 var ename = elem.name;
489 if (ename.indexOf('form_upay[') == 0 || ename.indexOf('form_bpay[') == 0) {
490 if (elem.value.length > 0) {
491 total += Number(elem.value);
492 if (total < 0) flag = 1;
496 f.form_paytotal.value = Number(total).toFixed(2);
497 if (flag) {
498 $('#payfrm')[0].reset();
499 alert("<?php echo addslashes(xl('Negative payments not accepted')) ?>")
501 return true;
504 function coloring() {
505 for (var i = 1; ; ++i) {
506 if (document.getElementById('paying_' + i)) {
507 paying = document.getElementById('paying_' + i).value * 1;
508 patient_balance = document.getElementById('duept_' + i).innerHTML * 1;
509 //balance=document.getElementById('balance_'+i).innerHTML*1;
510 if (patient_balance > 0 && paying > 0) {
511 if (paying > patient_balance) {
512 document.getElementById('paying_' + i).style.background = '#FF0000';
514 else if (paying < patient_balance) {
515 document.getElementById('paying_' + i).style.background = '#99CC00';
517 else if (paying == patient_balance) {
518 document.getElementById('paying_' + i).style.background = '#ffffff';
521 else {
522 document.getElementById('paying_' + i).style.background = '#ffffff';
525 else {
526 break;
531 function CheckVisible(MakeBlank) {//Displays and hides the check number text box.
532 if (document.getElementById('form_method').options[document.getElementById('form_method').selectedIndex].value == 'check_payment' ||
533 document.getElementById('form_method').options[document.getElementById('form_method').selectedIndex].value == 'bank_draft') {
534 document.getElementById('check_number').disabled = false;
536 else {
537 document.getElementById('check_number').disabled = true;
541 function validate() {
542 var f = document.forms["payfrm"];
543 ok = -1;
544 //no checks taken here....
545 issue = 'no';
546 if (document.getElementById('radio_type_of_payment_self1').checked == false &&
547 document.getElementById('radio_type_of_payment1').checked == false
548 && document.getElementById('radio_type_of_payment2').checked == false
549 && document.getElementById('radio_type_of_payment4').checked == false) {
550 alert("<?php //echo addslashes( xl('Please Select Type Of Payment.')) ?>");
551 return false;
553 if (document.getElementById('radio_type_of_payment_self1').checked == true || document.getElementById('radio_type_of_payment1').checked == true) {
554 for (var i = 0; i < f.elements.length; ++i) {
555 var elem = f.elements[i];
556 var ename = elem.name;
557 if (ename.indexOf('form_upay[0') == 0) //Today is this text box.
559 if (elem.value * 1 > 0) {//A warning message, if the amount is posted with out encounter.
560 if (confirm("<?php echo addslashes(xl('Are you sure to post for today?')) ?>")) {
561 ok = 1;
563 else {
564 elem.focus();
565 return false;
568 break;
572 else if (document.getElementsByName('form_paytotal')[0].value <= 0)//total 0
574 alert("<?php echo addslashes(xl('Invalid Total!')) ?>")
575 return false;
577 if (ok == -1) {
578 //return true;
579 if (confirm("<?php echo addslashes(xl('Payment Validated: Save?')) ?>")) {
580 return true;
582 else {
583 return false;
588 function cursor_pointer() {//Point the cursor to the latest encounter(Today)
589 var f = document.forms["payfrm"];
590 var total = 0;
591 for (var i = 0; i < f.elements.length; ++i) {
592 var elem = f.elements[i];
593 var ename = elem.name;
594 if (ename.indexOf('form_upay[') == 0) {
595 elem.focus();
596 break;
601 //=====================================================
602 function make_it_hide_enc_pay() {
603 document.getElementById('td_head_insurance_payment').style.display = "none";
604 document.getElementById('td_head_patient_co_pay').style.display = "none";
605 document.getElementById('td_head_co_pay').style.display = "none";
606 document.getElementById('td_head_insurance_balance').style.display = "none";
607 for (var i = 1; ; ++i) {
608 var td_inspaid_elem = document.getElementById('td_inspaid_' + i)
609 var td_patient_copay_elem = document.getElementById('td_patient_copay_' + i)
610 var td_copay_elem = document.getElementById('td_copay_' + i)
611 var balance_elem = document.getElementById('balance_' + i)
612 if (td_inspaid_elem) {
613 td_inspaid_elem.style.display = "none";
614 td_patient_copay_elem.style.display = "none";
615 td_copay_elem.style.display = "none";
616 balance_elem.style.display = "none";
618 else {
619 break;
622 document.getElementById('td_total_4').style.display = "none";
623 document.getElementById('td_total_7').style.display = "none";
624 document.getElementById('td_total_8').style.display = "none";
625 document.getElementById('td_total_6').style.display = "none";
627 document.getElementById('table_display').width = "420px";
630 //=====================================================
631 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) {
642 var td_charges_elem = document.getElementById('td_charges_' + i)
643 var td_inspaid_elem = document.getElementById('td_inspaid_' + i)
644 var td_ptpaid_elem = document.getElementById('td_ptpaid_' + i)
645 var td_patient_copay_elem = document.getElementById('td_patient_copay_' + i)
646 var td_copay_elem = document.getElementById('td_copay_' + i)
647 var balance_elem = document.getElementById('balance_' + i)
648 var duept_elem = document.getElementById('duept_' + i)
649 if (td_charges_elem) {
650 td_charges_elem.style.display = "none";
651 td_inspaid_elem.style.display = "none";
652 td_ptpaid_elem.style.display = "none";
653 td_patient_copay_elem.style.display = "none";
654 td_copay_elem.style.display = "none";
655 balance_elem.style.display = "none";
656 duept_elem.style.display = "none";
658 else {
659 break;
662 document.getElementById('td_total_7').style.display = "";
663 document.getElementById('td_total_8').style.display = "";
664 document.getElementById('td_total_1').style.display = "none";
665 document.getElementById('td_total_2').style.display = "none";
666 document.getElementById('td_total_3').style.display = "none";
667 document.getElementById('td_total_4').style.display = "none";
668 document.getElementById('td_total_5').style.display = "none";
669 document.getElementById('td_total_6').style.display = "none";
671 document.getElementById('table_display').width = "505px";
674 function make_it_hide() {
675 document.getElementById('td_head_rep_doc').style.display = "none";
676 document.getElementById('td_head_description').style.display = "none";
677 document.getElementById('td_head_total_charge').style.display = "";
678 document.getElementById('td_head_insurance_payment').style.display = "";
679 document.getElementById('td_head_patient_payment').style.display = "";
680 document.getElementById('td_head_patient_co_pay').style.display = "";
681 document.getElementById('td_head_co_pay').style.display = "";
682 document.getElementById('td_head_insurance_balance').style.display = "";
683 document.getElementById('td_head_patient_balance').style.display = "";
684 for (var i = 1; ; ++i) {
685 var td_charges_elem = document.getElementById('td_charges_' + i)
686 var td_inspaid_elem = document.getElementById('td_inspaid_' + i)
687 var td_ptpaid_elem = document.getElementById('td_ptpaid_' + i)
688 var td_patient_copay_elem = document.getElementById('td_patient_copay_' + i)
689 var td_copay_elem = document.getElementById('td_copay_' + i)
690 var balance_elem = document.getElementById('balance_' + i)
691 var duept_elem = document.getElementById('duept_' + i)
692 if (td_charges_elem) {
693 td_charges_elem.style.display = "";
694 td_inspaid_elem.style.display = "";
695 td_ptpaid_elem.style.display = "";
696 td_patient_copay_elem.style.display = "";
697 td_copay_elem.style.display = "";
698 balance_elem.style.display = "";
699 duept_elem.style.display = "";
701 else {
702 break;
705 document.getElementById('td_total_1').style.display = "";
706 document.getElementById('td_total_2').style.display = "";
707 document.getElementById('td_total_3').style.display = "";
708 document.getElementById('td_total_4').style.display = "";
709 document.getElementById('td_total_5').style.display = "";
710 document.getElementById('td_total_6').style.display = "";
711 document.getElementById('td_total_7').style.display = "";
712 document.getElementById('td_total_8').style.display = "";
714 document.getElementById('table_display').width = "100%";
717 function make_visible_radio() {
718 document.getElementById('tr_radio1').style.display = "";
719 document.getElementById('tr_radio2').style.display = "none";
722 function make_hide_radio() {
723 document.getElementById('tr_radio1').style.display = "none";
724 document.getElementById('tr_radio2').style.display = "";
727 function make_visible_row() {
728 document.getElementById('table_display').style.display = "";
729 document.getElementById('table_display_prepayment').style.display = "none";
732 function make_hide_row() {
733 document.getElementById('table_display').style.display = "none";
734 document.getElementById('table_display_prepayment').style.display = "";
737 function make_self() {
738 make_visible_row();
739 make_it_hide();
740 make_it_hide_enc_pay();
741 document.getElementById('radio_type_of_payment_self1').checked = true;
742 cursor_pointer();
745 function make_insurance() {
746 make_visible_row();
747 make_it_hide();
748 cursor_pointer();
749 document.getElementById('radio_type_of_payment1').checked = true;
752 //--------------------------------------------------------------------------------------------------//
753 $('#paySubmit').click(function (e) {
754 e.preventDefault()
755 $("#mode").val("portal-save");
756 var inv_values = JSON.stringify(getFormObj('payfrm'));
757 var extra_values = JSON.stringify(getFormObj('paycredit'));
758 var extra = "&inv_values=" + inv_values + "&extra_values=" + extra_values;
760 var flag = 0
761 var liburl = './lib/paylib.php';
762 $.ajax({
763 type: "POST",
764 url: liburl,
765 data: $("#payfrm").serialize() + extra,
766 beforeSend: function (xhr) {
767 if (validateCC() !== true) return false;
768 if ($('#pin').val() == "" || $('#ccname').val() == "" || $('#ccyear').val() == "" || $('#ccmonth').val() == "") {
769 alert("<?php echo addslashes(xl('Invalid Credit Card Values: Please correct')) ?>")
770 return false;
772 if (validate() != true) {
773 flag = 1;
774 alert("<?php echo addslashes(xl('Validation error: Fix and resubmit. This popup info is preserved!')) ?>")
775 return false;
777 $("#openPayModal .close").click()
779 error: function (qXHR, textStatus, errorThrow) {
780 console.log("There was an error:" + errorThrow);
782 success: function (templateHtml, textStatus, jqXHR) {
783 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')) ?>")
784 window.location.reload(false);
787 if (flag)
788 $("#openPayModal .close").click();
790 //---------------------------------------------------------------------------------------//
791 $("#payfrm").on('submit', function (e) {
792 e.preventDefault();
793 var thisform = this;
794 $("#mode").val("review-save");
795 var inv_values = JSON.stringify(getFormObj('payfrm'));
796 var extra_values = JSON.stringify(getFormObj('paycredit'));
797 var extra = "&inv_values=" + inv_values + "&extra_values=" + extra_values;
799 var flag = 0
800 var liburl = '<?php echo $GLOBALS["webroot"] ?>/portal/lib/paylib.php';
801 $.ajax({
802 type: "POST",
803 url: liburl,
804 data: $("#payfrm").serialize() + extra,
805 beforeSend: function (xhr) {
806 if (validate() != true) {
807 flag = 1;
808 alert("<?php echo addslashes(xl('Validation error: Fix and resubmit. Payment values are preserved!')) ?>")
809 return false;
812 error: function (xhr, textStatus, error) {
813 alert("<?php echo addslashes(xl('There is a Post error')) ?>")
814 console.log("There was an error:" + textStatus);
815 return false;
817 success: function (templateHtml, textStatus, jqXHR) {
818 thisform.submit();
823 function getFormObj(formId) {
824 var formObj = {};
825 var inputs = $('#' + formId).serializeArray();
826 $.each(inputs, function (i, input) {
827 formObj[input.name] = input.value;
829 return formObj;
832 function formRepopulate(jsondata) {
833 data = $.parseJSON(jsondata);
834 $.each(data, function (name, val) {
835 var $el = $('[name="' + name + '"]'),
836 type = $el.attr('type');
837 switch (type) {
838 case 'checkbox':
839 $el.prop('checked', true);
840 break;
841 case 'radio':
842 $el.filter('[value="' + val + '"]').prop('checked', true);
843 break;
844 default:
845 $el.val(val);
850 function getAuth() {
851 var authnum = prompt("<?php echo xlt('Please enter card comfirmation authorization') ?>", "");
852 if (authnum != null) {
853 $('#check_number').val(authnum);
856 </script>
858 <body class="skin-blue" onunload='imclosing()' onLoad="cursor_pointer();"
859 style="text-align: center; margin: auto;">
861 <form id="payfrm" method='post'
862 action='<?php echo $GLOBALS["webroot"] ?>/portal/portal_payment.php'>
863 <input type='hidden' name='form_pid' value='<?php echo attr($pid) ?>'/>
864 <input type='hidden' name='form_save'
865 value='<?php echo xlt('Invoice'); ?>'/>
867 <table>
868 <tr height="10">
869 <td colspan="3">&nbsp;</td>
870 </tr>
872 <tr>
873 <td colspan='3' align='center' class='text'><b><?php echo xlt('Accept Payment for'); ?>&nbsp;:&nbsp;&nbsp;<?php
875 echo htmlspecialchars($patdata['fname'], ENT_QUOTES) . " " . htmlspecialchars($patdata['lname'], ENT_QUOTES) . " " . htmlspecialchars($patdata['mname'], ENT_QUOTES) . " (" . htmlspecialchars($patdata['pid'], ENT_QUOTES) . ")" ?></b>
876 <?php $NameNew = $patdata['fname'] . " " . $patdata['lname'] . " " . $patdata['mname']; ?>
877 </td>
878 </tr>
879 <tr height="15">
880 <td colspan='3'></td>
881 </tr>
882 <tr>
883 <td class='text'>
884 <?php echo xlt('Payment Method'); ?>:
885 </td>
886 <td colspan='2'><select name="form_method" id="form_method"
887 class="text" onChange='CheckVisible("yes")'>
888 <?php
889 $query1112 = "SELECT * FROM list_options where list_id=? ORDER BY seq, title ";
890 $bres1112 = sqlStatement($query1112, array('payment_method'));
891 while ($brow1112 = sqlFetchArray($bres1112)) {
892 if ($brow1112['option_id'] != 'credit_card' || $brow1112['option_id'] == 'electronic' || $brow1112['option_id'] == 'bank_draft') {
893 continue;
896 echo "<option value='" . htmlspecialchars($brow1112['option_id'], ENT_QUOTES) . "'>" . htmlspecialchars(xl_list_label($brow1112['title']), ENT_QUOTES) . "</option>";
899 </select></td>
900 </tr>
902 <tr height="5">
903 <td colspan='3'></td>
904 </tr>
906 <tr>
907 <td class='text'>
908 <?php echo xla('Authorized'); ?>:
909 </td>
910 <td colspan='2'>
911 <?php
912 if (isset($_SESSION['authUserID'])) {
913 echo "<input type='text' id='check_number' name='form_source' style='width:120px;' value='" . htmlspecialchars($payrow['source'], ENT_QUOTES) . "'>";
916 </td>
917 </tr>
918 <tr height="5">
919 <td colspan='3'></td>
920 </tr>
921 <tr>
922 <td class='text' valign="middle">
923 <?php echo xlt('Patient Coverage'); ?>:
924 </td>
925 <td class='text' colspan="2">
926 <input type="radio" name="radio_type_of_coverage" id="radio_type_of_coverage1"
927 value="self" onClick="make_visible_radio();make_self();"/>
928 <?php echo xlt('Self'); ?>
929 <input type="radio" name="radio_type_of_coverage" id="radio_type_of_coverag2" value="insurance"
930 checked="checked"
931 onClick="make_hide_radio();make_insurance();"/>
932 <?php echo xlt('Insurance'); ?>
933 </td>
934 </tr>
935 <tr height="5">
936 <td colspan='3'></td>
937 </tr>
938 <tr id="tr_radio1" style="display: none">
939 <!-- For radio Insurance -->
940 <td class='text' valign="top">
941 <?php echo xlt('Payment against'); ?>:
942 </td>
943 <td class='text' colspan="2">
944 <input type="radio" name="radio_type_of_payment" id="radio_type_of_payment_self1"
945 value="cash" onClick="make_visible_row();make_it_hide_enc_pay();cursor_pointer();"/>
946 <?php echo xlt('Encounter Payment'); ?>
947 </td>
948 </tr>
949 <tr id="tr_radio2">
950 <!-- For radio self -->
951 <td class='text' valign="top"><?php echo xlt('Payment against'); ?>:
952 </td>
953 <td class='text' colspan="2"><input type="radio" name="radio_type_of_payment"
954 id="radio_type_of_payment1" checked="checked"
955 value="copay"
956 onClick="make_visible_row();cursor_pointer();"/><?php echo xlt('Co Pay'); ?>
957 <input type="radio" name="radio_type_of_payment" id="radio_type_of_payment2"
958 value="invoice_balance" onClick="make_visible_row();"/><?php echo xlt('Invoice Balance'); ?>
959 <br/>
960 <input type="radio" name="radio_type_of_payment" id="radio_type_of_payment4" value="pre_payment"
961 onClick="make_hide_row();"/><?php echo xlt('Pre Pay'); ?></td>
962 </tr>
963 <tr height="15">
964 <td colspan='3'></td>
965 </tr>
966 </table>
967 <table width="35%" border="0" cellspacing="0" cellpadding="0" id="table_display_prepayment"
968 style="display: none">
969 <tr>
970 <td class='detail'><?php echo xlt('Pre Payment'); ?></td>
971 <td><input class="form-control" type='text' name='form_prepayment' style='width: 100px'/></td>
972 </tr>
973 </table>
974 <table id="table_display" style="width: 100%; background: #eee;" class="table table-striped table-responsive">
975 <thead>
976 </thead>
977 <tbody>
978 <!-- <table border='0' id="table_display" cellpadding='0' cellspacing='0' width='100%'> -->
979 <tr bgcolor="#cccccc" id="tr_head">
980 <td class="dehead" width="60">
981 <?php echo xlt('DOS') ?>
982 </td>
983 <td class="dehead" width="120">
984 <?php echo xlt('Visit Reason') ?>
985 </td>
986 <td class="dehead" align="center" width="70" id="td_head_total_charge">
987 <?php echo xlt('Total Charge') ?>
988 </td>
989 <td class="dehead" align="center" width="70" id="td_head_rep_doc" style='display: none'>
990 <?php echo xlt('Report/ Form') ?>
991 </td>
992 <td class="dehead" align="center" width="200" id="td_head_description" style='display: none'>
993 <?php echo xlt('Description') ?>
994 </td>
995 <td class="dehead" align="center" width="70" id="td_head_insurance_payment">
996 <?php echo xlt('Insurance Payment') ?>
997 </td>
998 <td class="dehead" align="center" width="70" id="td_head_patient_payment">
999 <?php echo xlt('Patient Payment') ?>
1000 </td>
1001 <td class="dehead" align="center" width="55" id="td_head_patient_co_pay">
1002 <?php echo xlt('Co Pay Paid') ?>
1003 </td>
1004 <td class="dehead" align="center" width="55" id="td_head_co_pay">
1005 <?php echo xlt('Required Co Pay') ?>
1006 </td>
1007 <td class="dehead" align="center" width="70" id="td_head_insurance_balance">
1008 <?php echo xlt('Insurance Balance') ?>
1009 </td>
1010 <td class="dehead" align="center" width="70" id="td_head_patient_balance">
1011 <?php echo xlt('Patient Balance') ?>
1012 </td>
1013 <td class="dehead" align="center" width="50">
1014 <?php echo xlt('Paying') ?>
1015 </td>
1016 </tr>
1017 <?php
1018 $encs = array();
1019 // Get the unbilled service charges and payments by encounter for this patient.
1021 $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
1022 "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";
1023 $bres = sqlStatement($query, array($pid, $pid));
1025 while ($brow = sqlFetchArray($bres)) {
1026 $key = 0 + $brow['encounter'];
1027 if (empty($encs[$key])) {
1028 $encs[$key] = array('encounter' => $brow['encounter'], 'date' => $brow['encdate'], 'last_level_closed' => $brow['last_level_closed'], 'charges' => 0, 'payments' => 0, 'reason' => $brow['reason']
1032 if ($brow['code_type'] === 'COPAY') {
1033 // $encs[$key]['payments'] -= $brow['fee'];
1034 } else {
1035 $encs[$key]['charges'] += $brow['fee'];
1036 // Add taxes.
1037 $sql_array = array();
1038 $query = "SELECT taxrates FROM codes WHERE " . "code_type = ? AND " . "code = ? AND ";
1039 array_push($sql_array, $code_types[$brow['code_type']]['id'], $brow['code']);
1040 if ($brow['modifier']) {
1041 $query .= "modifier = ?";
1042 array_push($sql_array, $brow['modifier']);
1043 } else {
1044 $query .= "(modifier IS NULL OR modifier = '')";
1047 $query .= " LIMIT 1";
1048 $trow = sqlQuery($query, $sql_array);
1049 $encs[$key]['charges'] += calcTaxes($trow, $brow['fee']);
1053 // Do the same for unbilled product sales.
1055 $query = "SELECT fe.encounter, fe.reason, s.drug_id, s.fee, " .
1056 "LEFT(fe.date, 10) AS encdate,fe.last_level_closed " .
1057 "FROM form_encounter AS fe left join drug_sales AS s " .
1058 "on s.pid = ? AND s.fee != 0 " .
1059 "AND fe.pid = s.pid AND fe.encounter = s.encounter " .
1060 "where fe.pid = ? " . "ORDER BY s.encounter";
1062 $dres = sqlStatement($query, array($pid, $pid));
1064 while ($drow = sqlFetchArray($dres)) {
1065 $key = 0 + $drow['encounter'];
1066 if (empty($encs[$key])) {
1067 $encs[$key] = array('encounter' => $drow['encounter'], 'date' => $drow['encdate'], 'last_level_closed' => $drow['last_level_closed'], 'charges' => 0, 'payments' => 0
1071 $encs[$key]['charges'] += $drow['fee'];
1072 // Add taxes.
1073 $trow = sqlQuery("SELECT taxrates FROM drug_templates WHERE drug_id = ? " . "ORDER BY selector LIMIT 1", array($drow['drug_id']
1075 $encs[$key]['charges'] += calcTaxes($trow, $drow['fee']);
1078 ksort($encs, SORT_NUMERIC);
1079 $gottoday = false;
1080 // Bringing on top the Today always
1081 foreach ($encs as $key => $value) {
1082 $dispdate = $value['date'];
1083 if (strcmp($dispdate, $today) == 0 && !$gottoday) {
1084 $gottoday = true;
1085 break;
1089 // If no billing was entered yet for today, then generate a line for
1090 // entering today's co-pay.
1092 if (!$gottoday) {
1093 // echoLine("form_upay[0]", date("Y-m-d"), 0, 0, 0, 0 /*$duept*/);//No encounter yet defined.
1096 $gottoday = false;
1097 foreach ($encs as $key => $value) {
1098 $enc = $value['encounter'];
1099 $reason = $value['reason'];
1100 $dispdate = $value['date'];
1101 if (strcmp($dispdate, $today) == 0 && !$gottoday) {
1102 $dispdate = date("Y-m-d");
1103 $gottoday = true;
1106 // ------------------------------------------------------------------------------------
1107 $inscopay = getCopay($pid, $dispdate);
1108 $patcopay = getPatientCopay($pid, $enc);
1109 // Insurance Payment
1110 // -----------------
1111 $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
1113 $dpayment = $drow['payments'];
1114 $dadjustment = $drow['adjustments'];
1115 // Patient Payment
1116 // ---------------
1117 $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
1119 $dpayment_pat = $drow['payments'];
1121 // ------------------------------------------------------------------------------------
1122 // NumberOfInsurance
1123 $ResultNumberOfInsurance = sqlStatement("SELECT COUNT( DISTINCT TYPE ) NumberOfInsurance FROM insurance_data
1124 where pid = ? and provider>0 ", array($pid
1126 $RowNumberOfInsurance = sqlFetchArray($ResultNumberOfInsurance);
1127 $NumberOfInsurance = $RowNumberOfInsurance['NumberOfInsurance'] * 1;
1128 // ------------------------------------------------------------------------------------
1129 $duept = 0;
1130 if ((($NumberOfInsurance == 0 || $value['last_level_closed'] == 4 || $NumberOfInsurance == $value['last_level_closed']))) { // Patient balance
1131 $brow = sqlQuery("SELECT SUM(fee) AS amount FROM billing WHERE " . "pid = ? and encounter = ? AND activity = 1", array($pid, $enc
1133 $srow = sqlQuery("SELECT SUM(fee) AS amount FROM drug_sales WHERE " . "pid = ? and encounter = ? ", array($pid, $enc
1135 $drow = sqlQuery("SELECT SUM(pay_amount) AS payments, " . "SUM(adj_amount) AS adjustments FROM ar_activity WHERE " . "pid = ? and encounter = ? ", array($pid, $enc
1137 $duept = $brow['amount'] + $srow['amount'] - $drow['payments'] - $drow['adjustments'];
1140 echoLine("form_upay[$enc]", $dispdate, $value['charges'], $dpayment_pat, ($dpayment + $dadjustment), $duept, ($enc . ':' . $reason), $inscopay, $patcopay);
1143 // Continue with display of the data entry form.
1145 <tr>
1146 <td class="dehead" id='td_total_1'></td>
1147 <td class="dehead" id='td_total_2'></td>
1148 <td class="dehead" id='td_total_3'></td>
1149 <td class="dehead" id='td_total_4'></td>
1150 <td class="dehead" id='td_total_5'></td>
1151 <td class="dehead" id='td_total_6'></td>
1152 <td class="dehead" id='td_total_7'></td>
1153 <td class="dehead" id='td_total_8'></td>
1154 <td class="dehead" align="right"><?php echo xlt('Total'); ?></td>
1155 <td class="dehead" align="right"><input class="form-control" type='text' name='form_paytotal'
1156 value='' style='color: #00aa00; width: 65px; padding: 1px 1px;'
1157 readonly/>
1158 </td>
1159 </tr>
1160 </table>
1161 <?php
1162 if (isset($ccdata["name"])) {
1163 echo '<div class="col-xs-12 col-md-4 col-lg-4">
1164 <div class="panel panel-default height">';
1165 if (!isset($_SESSION['authUserID'])) {
1166 echo '<div class="panel-heading">' . xlt("Payment Information") . '<span style="color:#cc0000"><em> ' . xlt("Pending Auth since") . ': </em>' . text($edata["date"]) . '</span></div>';
1167 } else {
1168 echo '<div class="panel-heading">' . xlt("Payment Information") . ' <button type="button" class="btn btn-danger btn-sm" onclick="getAuth()">' . xlt("Authorize") . '</button></div>';
1170 } else {
1171 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>';
1174 <div class="panel-body">
1175 <strong><?php echo xlt('Card Name'); ?>: </strong><span
1176 id="cn"><?php echo attr($ccdata["cc_type"]) ?></span><br>
1177 <strong><?php echo xlt('Name on Card'); ?>: </strong><span
1178 id="nc"><?php echo attr($ccdata["name"]) ?></span><br>
1179 <strong><?php echo xlt('Card Number'); ?>: </strong><span id="ccn">
1180 <?php
1181 if (isset($_SESSION['authUserID'])) {
1182 echo $ccdata["cc_number"] . "</span><br>";
1183 } else {
1184 echo "********** " . substr($ccdata["cc_number"], -4) . "</span><br>";
1187 <strong><?php echo xlt('Exp Date'); ?>: </strong><span
1188 id="ed"><?php echo attr($ccdata["month"]) . "/" . attr($ccdata["year"]) ?></span>
1189 <strong><?php echo xlt('CVV'); ?>: </strong><span id="pin"><?php echo attr($ccdata["pin"]) ?></span><br>
1190 <strong><?php echo xlt('Charge Total'); ?>: </strong><span id="ct"><?php echo attr($invdata["form_paytotal"]) ?></span><br>
1191 </div>
1192 </div>
1193 </div>
1195 <?php
1196 if (!isset($_SESSION['authUserID'])) {
1197 echo '<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#openPayModal">' . xlt("Pay Invoice") . '</button>';
1198 } else {
1199 echo "<button type='submit' class='btn btn-danger' form='payfrm'>" . xlt('Post Payment') . "</button>";
1202 &nbsp;
1203 </p>
1204 <input type="hidden" name="hidden_patient_code" id="hidden_patient_code" value="<?php echo attr($pid); ?>"/>
1205 <input type='hidden' name='mode' id='mode' value=''/>
1206 </form>
1208 <script type="text/javascript">
1209 if (typeof jsondata !== 'undefined') {
1210 formRepopulate(jsondata);
1212 calctotal();
1213 </script>
1214 <!-- credit payment modal -->
1215 <div id="openPayModal" class="modal fade" role="dialog">
1216 <div class="modal-dialog">
1217 <div class="modal-content">
1218 <div class="modal-header">
1219 <h3><?php echo xlt('Submit Payment for Authorization'); ?></h3>
1220 <button type="button" class="close" data-dismiss="modal">&times;</button>
1221 </div>
1222 <div class="modal-body container">
1223 <form id='paycredit' class="form-horizontal col-xs-12 col-sm-6 col-md-6">
1224 <fieldset>
1225 <div class="control-group">
1226 <label label-default="label-default"
1227 class="control-label"><?php echo xlt('Name on Card'); ?></label>
1228 <div class="controls">
1229 <input name="name" id="ccname" type="text" class="form-control"
1230 pattern="\w+ \w+.*"
1231 title="<?php echo xla('Fill your first and last name'); ?>"
1232 required value=""/>
1233 </div>
1234 </div>
1235 <div class="control-group">
1236 <label class="control-label"><?php echo xlt('Card Number'); ?></label>
1237 <div class="controls">
1238 <div class="row">
1239 <div class="col-sm-12">
1240 <input name="cc_number" id="cc_number" type="text"
1241 class="form-control inline col-sm-3"
1242 autocomplete="off" maxlength="19" pattern="\d"
1243 onchange="validateCC()"
1244 title="<?php echo xla('Card Number'); ?>" required value=""/>
1245 <input disabled name="cardtype" id="cardtype" type="text"
1246 class="form-control inline" title="<?php echo xla('Card Type'); ?>"
1247 style="max-width:160px;font-weight:bold;color:red;" value=""/>
1248 </div>
1249 </div>
1250 </div>
1251 </div>
1252 <div class="control-group">
1253 <label label-default="label-default"
1254 class="control-label"><?php echo xlt('Card Expiry Date'); ?></label>
1255 <div class="controls">
1256 <div class="row">
1257 <div class="col-md-4">
1258 <select name="month" id="ccmonth" class="form-control">
1259 <option value=""><?php echo xlt('Select Month'); ?></option>
1260 <option value="01"><?php echo xlt('January'); ?></option>
1261 <option value="02"><?php echo xlt('February'); ?></option>
1262 <option value="03"><?php echo xlt('March'); ?></option>
1263 <option value="04"><?php echo xlt('April'); ?></option>
1264 <option value="05"><?php echo xlt('May'); ?></option>
1265 <option value="06"><?php echo xlt('June'); ?></option>
1266 <option value="07"><?php echo xlt('July'); ?></option>
1267 <option value="08"><?php echo xlt('August'); ?></option>
1268 <option value="09"><?php echo xlt('September'); ?></option>
1269 <option value="10"><?php echo xlt('October'); ?></option>
1270 <option value="11"><?php echo xlt('November'); ?></option>
1271 <option value="12"><?php echo xlt('December'); ?></option>
1272 </select>
1273 </div>
1274 <div class="col-md-3">
1275 <select name="year" id="ccyear" class="form-control">
1276 <option value=""><?php echo xlt('Select Year'); ?></option>
1277 <option value="2018">2018</option>
1278 <option value="2019">2019</option>
1279 <option value="2020">2020</option>
1280 <option value="2021">2021</option>
1281 <option value="2022">2022</option>
1282 <option value="2023">2023</option>
1283 <option value="2024">2024</option>
1284 <option value="2025">2017</option>
1285 </select>
1286 </div>
1287 </div>
1288 </div>
1289 </div>
1290 <div class="control-group">
1291 <label label-default="label-default"
1292 class="control-label"><?php echo xlt('Card CVV'); ?></label>
1293 <div class="controls">
1294 <div class="row">
1295 <div class="col-md-3">
1296 <input name="pin" id="pin" type="text" class="form-control"
1297 autocomplete="off" maxlength="4" pattern="\d{3}"
1298 onfocus="validateCC()"
1299 title="<?php echo xlt('Three or four digits at back of your card'); ?>"
1300 required value=""/>
1301 </div>
1302 <div class="col-md-3">
1303 <img src='./images/img_cvc.png' style='height: 58px; width: auto'>
1304 </div>
1305 </div>
1306 </div>
1307 </div>
1308 <div class="form-actions">
1309 <button id="paySubmit" class="btn btn-danger"><?php echo xlt('Submit'); ?></button>
1310 <button type="button" class="btn btn-default"
1311 data-dismiss="modal"><?php echo xlt('Cancel'); ?></button>
1312 </div>
1313 </fieldset>
1314 <input type='hidden' name='cc_type' id='cc_type' value=''/>
1315 </form>
1316 </div>
1317 <!-- Body -->
1318 <div class="modal-footer">
1319 <button type="button" class="btn btn-default"
1320 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);
1333 function validateCC() {
1334 var result = $('#cc_number').validateCreditCard();
1335 var r = (result.card_type == null ? '' : result.card_type.name.toUpperCase())
1336 var v = (result.valid == true ? ' Okay' : ' Invalid #')
1337 $('#cardtype').val(r + v);
1338 $('#cc_type').val(r);
1339 if (!result.valid) {
1340 alert(ccerr)
1341 return false;
1343 else {
1344 return true;
1347 </script>
1348 </body>
1349 <?php