/
portal_payment.php
1663 lines (1551 loc) · 82.4 KB
/
portal_payment.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
*
* namespace OnsitePortal
*
* @package OpenEMR
* @link http://www.open-emr.org
* @author Rod Roark <rod@sunsetsystems.com>
* @author Jerry Padgett <sjpadgett@gmail.com>
* @author Brady Miller <brady.g.miller@gmail.com>
* @copyright Copyright (c) 2006-2020 Rod Roark <rod@sunsetsystems.com>
* @copyright Copyright (c) 2016-2019 Jerry Padgett <sjpadgett@gmail.com>
* @copyright Copyright (c) 2019 Brady Miller <brady.g.miller@gmail.com>
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
*/
// Will start the (patient) portal OpenEMR session/cookie.
require_once(__DIR__ . "/../src/Common/Session/SessionUtil.php");
OpenEMR\Common\Session\SessionUtil::portalSessionStart();
$isPortal = false;
if (isset($_SESSION['pid']) && isset($_SESSION['patient_portal_onsite_two'])) {
$pid = $_SESSION['pid'];
$ignoreAuth_onsite_portal = true;
$isPortal = true;
require_once(__DIR__ . "/../interface/globals.php");
} else {
OpenEMR\Common\Session\SessionUtil::portalSessionCookieDestroy();
$ignoreAuth = false;
require_once(__DIR__ . "/../interface/globals.php");
if (!isset($_SESSION['authUserID'])) {
$landingpage = "index.php";
header('Location: ' . $landingpage);
exit();
}
}
require_once(__DIR__ . "/lib/appsql.class.php");
require_once("$srcdir/patient.inc");
require_once("$srcdir/payment.inc.php");
require_once("$srcdir/forms.inc");
require_once("../custom/code_types.inc.php");
require_once("$srcdir/options.inc.php");
require_once("$srcdir/encounter_events.inc.php");
use OpenEMR\Billing\BillingUtilities;
use OpenEMR\Common\Crypto\CryptoGen;
use OpenEMR\Common\Csrf\CsrfUtils;
use OpenEMR\PaymentProcessing\Sphere\SpherePayment;
$cryptoGen = new CryptoGen();
$appsql = new ApplicationTable();
$pid = isset($_REQUEST['pid']) ? $_REQUEST['pid'] : $pid;
$pid = $_REQUEST['hidden_patient_code'] > 0 ? $_REQUEST['hidden_patient_code'] : $pid;
$recid = isset($_REQUEST['recid']) ? (int) $_REQUEST['recid'] : 0;
$adminUser = '';
$portalPatient = '';
$query = "SELECT pao.portal_username as recip_id, Concat_Ws(' ', patient_data.fname, patient_data.lname) as username FROM patient_data " .
"LEFT JOIN patient_access_onsite pao ON pao.pid = patient_data.pid " .
"WHERE patient_data.pid = ? AND pao.portal_pwd_status = 1";
$portalPatient = sqlQueryNoLog($query, $pid);
if ($_SESSION['authUserID']) {
$query = "SELECT users.username as recip_id, users.authorized as dash, CONCAT(users.fname,' ',users.lname) as username " .
"FROM users WHERE id = ?";
$adminUser = sqlQueryNoLog($query, $_SESSION['authUserID']);
}
if ($recid) {
$edata = $appsql->getPortalAuditRec($recid);
} else {
$edata = $appsql->getPortalAudit($pid, 'review', 'payment');
}
$ccdata = array();
$invdata = array();
if ($edata) {
$ccdata = json_decode($cryptoGen->decryptStandard($edata['checksum']), true);
$invdata = json_decode($edata['table_args'], true);
echo "<script>var jsondata='" . $edata['table_args'] . "';var ccdata='" . $edata['checksum'] . "'</script>";
}
function bucks($amount)
{
if ($amount) {
$amount = oeFormatMoney($amount);
return $amount;
}
return '';
}
function rawbucks($amount)
{
if ($amount) {
$amount = sprintf("%.2f", $amount);
return $amount;
}
return '';
}
// Display a row of data for an encounter.
//
$var_index = 0;
$sum_charges = $sum_ptpaid = $sum_inspaid = $sum_duept = $sum_copay = $sum_patcopay = $sum_balance = 0;
function echoLine($iname, $date, $charges, $ptpaid, $inspaid, $duept, $encounter = 0, $copay = 0, $patcopay = 0)
{
global $sum_charges, $sum_ptpaid, $sum_inspaid, $sum_duept, $sum_copay, $sum_patcopay, $sum_balance;
global $var_index;
$var_index++;
$balance = bucks($charges - $ptpaid - $inspaid);
$balance = (round($duept, 2) != 0) ? 0 : $balance; // if balance is due from patient, then insurance balance is displayed as zero
$encounter = $encounter ? $encounter : '';
echo " <tr id='tr_" . attr($var_index) . "' >\n";
echo " <td class='detail'>" . text(oeFormatShortDate($date)) . "</td>\n";
echo " <td class='detail' id='" . attr($date) . "' align='left'>" . text($encounter) . "</td>\n";
echo " <td class='detail' align='center' id='td_charges_$var_index' >" . text(bucks($charges)) . "</td>\n";
echo " <td class='detail' align='center' id='td_inspaid_$var_index' >" . text(bucks($inspaid * -1)) . "</td>\n";
echo " <td class='detail' align='center' id='td_ptpaid_$var_index' >" . text(bucks($ptpaid * -1)) . "</td>\n";
echo " <td class='detail' align='center' id='td_patient_copay_$var_index' >" . text(bucks($patcopay)) . "</td>\n";
echo " <td class='detail' align='center' id='td_copay_$var_index' >" . text(bucks($copay)) . "</td>\n";
echo " <td class='detail' align='center' id='balance_$var_index'>" . text(bucks($balance)) . "</td>\n";
echo " <td class='detail' align='center' id='duept_$var_index'>" . text(bucks(round($duept, 2) * 1)) . "</td>\n";
echo " <td class='detail' align='center'><input class='form-control' name='" . attr($iname) . "' id='paying_" . attr($var_index) .
"' " . " value='" . '' . "' onchange='coloring();calctotal()' autocomplete='off' " . "onkeyup='calctotal()'/></td>\n";
echo " </tr>\n";
$sum_charges += (float)$charges * 1;
$sum_ptpaid += (float)$ptpaid * -1;
$sum_inspaid += (float)$inspaid * -1;
$sum_duept += (float)$duept * 1;
$sum_patcopay += (float)$patcopay * 1;
$sum_copay += (float)$copay * 1;
$sum_balance += (float)$balance * 1;
}
// We use this to put dashes, colons, etc. back into a timestamp.
//
function decorateString($fmt, $str)
{
$res = '';
while ($fmt) {
$fc = substr($fmt, 0, 1);
$fmt = substr($fmt, 1);
if ($fc == '.') {
$res .= substr($str, 0, 1);
$str = substr($str, 1);
} else {
$res .= $fc;
}
}
return $res;
}
// Compute taxes from a tax rate string and a possibly taxable amount.
//
function calcTaxes($row, $amount)
{
$total = 0;
if (empty($row['taxrates'])) {
return $total;
}
$arates = explode(':', $row['taxrates']);
if (empty($arates)) {
return $total;
}
foreach ($arates as $value) {
if (empty($value)) {
continue;
}
$trow = sqlQuery("SELECT option_value FROM list_options WHERE " . "list_id = 'taxrate' AND option_id = ? LIMIT 1", array($value
));
if (empty($trow['option_value'])) {
echo "<!-- Missing tax rate '" . text($value) . "'! -->\n";
continue;
}
$tax = sprintf("%01.2f", $amount * $trow['option_value']);
// echo "<!-- Rate = '$value', amount = '$amount', tax = '$tax' -->\n";
$total += $tax;
}
return $total;
}
$now = time();
$today = date('Y-m-d', $now);
$timestamp = date('Y-m-d H:i:s', $now);
$patdata = sqlQuery("SELECT " . "p.fname, p.mname, p.lname, p.postal_code, 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
));
$alertmsg = ''; // anything here pops up in an alert box
// If the Save button was clicked...
if ($_POST['form_save']) {
$form_pid = $_POST['form_pid'];
$form_method = trim($_POST['form_method']);
$form_source = trim($_POST['form_source']);
$patdata = getPatientData($form_pid, 'fname,mname,lname,pubpid');
$NameNew = $patdata['fname'] . " " . $patdata['lname'] . " " . $patdata['mname'];
if ($_REQUEST['radio_type_of_payment'] == 'pre_payment') {
$payment_id = sqlInsert(
"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(0, $form_pid, $_SESSION['authUserID'], 0, $form_source, $_REQUEST['form_prepayment'], $NameNew, $form_method)
);
frontPayment($form_pid, 0, $form_method, $form_source, $_REQUEST['form_prepayment'], 0, $timestamp);//insertion to 'payments' table.
}
if ($_POST['form_upay'] && $_REQUEST['radio_type_of_payment'] != 'pre_payment') {
foreach ($_POST['form_upay'] as $enc => $payment) {
if ($amount = (float)$payment) {
$zero_enc = $enc;
//----------------------------------------------------------------------------------------------------
//Fetching the existing code and modifier
$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)
);
if ($RowSearch = sqlFetchArray($ResultSearchNew)) {
$Codetype = $RowSearch['code_type'];
$Code = $RowSearch['code'];
$Modifier = $RowSearch['modifier'];
} else {
$Codetype = '';
$Code = '';
$Modifier = '';
}
//----------------------------------------------------------------------------------------------------
if ($_REQUEST['radio_type_of_payment'] == 'copay') {//copay saving to ar_session and ar_activity tables
$session_id = sqlInsert(
"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($_SESSION['authUserID'], $form_source, $amount, $form_pid, $form_method)
);
sqlBeginTrans();
$sequence_no = sqlQuery("SELECT IFNULL(MAX(sequence_no),0) + 1 AS increment FROM ar_activity WHERE pid = ? AND encounter = ?", array($form_pid, $enc));
$insrt_id = sqlInsert(
"INSERT INTO ar_activity (pid,encounter,sequence_no,code_type,code,modifier,payer_type,post_time,post_user,session_id,pay_amount,account_code)" .
" VALUES (?,?,?,?,?,?,0,now(),?,?,?,'PCP')",
array($form_pid, $enc, $sequence_no['increment'], $Codetype, $Code, $Modifier, $_SESSION['authUserID'], $session_id, $amount)
);
sqlCommitTrans();
frontPayment($form_pid, $enc, $form_method, $form_source, $amount, 0, $timestamp);//insertion to 'payments' table.
}
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.
if ($_REQUEST['radio_type_of_payment'] == 'cash') {
sqlStatement(
"update form_encounter set last_level_closed=? where encounter=? and pid=? ",
array(4, $enc, $form_pid)
);
sqlStatement(
"update billing set billed=? where encounter=? and pid=?",
array(1, $enc, $form_pid)
);
}
$adjustment_code = 'patient_payment';
$payment_id = sqlInsert(
"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(0, $form_pid, $_SESSION['authUserID'], 0, $form_source, $amount, $NameNew, $adjustment_code, $form_method)
);
//--------------------------------------------------------------------------------------------------------------------
frontPayment($form_pid, $enc, $form_method, $form_source, 0, $amount, $timestamp);//insertion to 'payments' table.
//--------------------------------------------------------------------------------------------------------------------
$resMoneyGot = sqlStatement(
"SELECT sum(pay_amount) as PatientPay FROM ar_activity where deleted IS NULL AND pid =? and " .
"encounter =? and payer_type=0 and account_code='PCP'",
array($form_pid, $enc)
);//new fees screen copay gives account_code='PCP'
$rowMoneyGot = sqlFetchArray($resMoneyGot);
$Copay = $rowMoneyGot['PatientPay'];
//--------------------------------------------------------------------------------------------------------------------
//Looping the existing code and modifier
$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)
);
while ($RowSearch = sqlFetchArray($ResultSearchNew)) {
$Codetype = $RowSearch['code_type'];
$Code = $RowSearch['code'];
$Modifier = $RowSearch['modifier'];
$Fee = $RowSearch['fee'];
$resMoneyGot = sqlStatement(
"SELECT sum(pay_amount) as MoneyGot FROM ar_activity where deleted IS NULL AND 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)
);
//new fees screen copay gives account_code='PCP'
$rowMoneyGot = sqlFetchArray($resMoneyGot);
$MoneyGot = $rowMoneyGot['MoneyGot'];
$resMoneyAdjusted = sqlStatement(
"SELECT sum(adj_amount) as MoneyAdjusted FROM ar_activity where deleted IS NULL AND " .
"pid =? and code_type=? and code=? and modifier=? and encounter =?",
array($form_pid, $Codetype, $Code, $Modifier, $enc)
);
$rowMoneyAdjusted = sqlFetchArray($resMoneyAdjusted);
$MoneyAdjusted = $rowMoneyAdjusted['MoneyAdjusted'];
$Remainder = $Fee - $Copay - $MoneyGot - $MoneyAdjusted;
$Copay = 0;
if (round($Remainder, 2) != 0 && $amount != 0) {
if ($amount - $Remainder >= 0) {
$insert_value = $Remainder;
$amount = $amount - $Remainder;
} else {
$insert_value = $amount;
$amount = 0;
}
sqlBeginTrans();
$sequence_no = sqlQuery("SELECT IFNULL(MAX(sequence_no),0) + 1 AS increment FROM ar_activity WHERE pid = ? AND encounter = ?", array($form_pid, $enc));
sqlStatement(
"insert into ar_activity set " .
"pid = ?" .
", encounter = ?" .
", sequence_no = ?" .
", code_type = ?" .
", code = ?" .
", modifier = ?" .
", payer_type = ?" .
", post_time = now() " .
", post_user = ?" .
", session_id = ?" .
", pay_amount = ?" .
", adj_amount = ?" .
", account_code = 'PP'",
array($form_pid, $enc, $sequence_no['increment'], $Codetype, $Code, $Modifier, 0, $_SESSION['authUserID'], $payment_id, $insert_value, 0)
);
sqlCommitTrans();
}//if
}//while
if ($amount != 0) {//if any excess is there.
sqlBeginTrans();
$sequence_no = sqlQuery("SELECT IFNULL(MAX(sequence_no),0) + 1 AS increment FROM ar_activity WHERE pid = ? AND encounter = ?", array($form_pid, $enc));
sqlStatement(
"insert into ar_activity set " .
"pid = ?" .
", encounter = ?" .
", sequence_no = ?" .
", code_type = ?" .
", code = ?" .
", modifier = ?" .
", payer_type = ?" .
", post_time = now() " .
", post_user = ?" .
", session_id = ?" .
", pay_amount = ?" .
", adj_amount = ?" .
", account_code = 'PP'",
array($form_pid, $enc, $sequence_no['increment'], $Codetype, $Code, $Modifier, 0, $_SESSION['authUserID'], $payment_id, $amount, 0)
);
sqlCommitTrans();
}
//--------------------------------------------------------------------------------------------------------------------
}//invoice_balance
}//if ($amount = 0 + $payment)
}//foreach
}//if ($_POST['form_upay'])
}//if ($_POST['form_save'])
if ($_POST['form_save'] || $_REQUEST['receipt']) {
if ($_REQUEST['receipt']) {
$form_pid = $_GET['patient'];
$timestamp = decorateString('....-..-.. ..:..:..', $_GET['time']);
}
// Get details for what we guess is the primary facility.
$frow = sqlQuery("SELECT * FROM facility " . "ORDER BY billing_location DESC, accepts_assignment DESC, id LIMIT 1");
// Get the patient's name and chart number.
$patdata = getPatientData($form_pid, 'fname,mname,lname,pubpid');
// Re-fetch payment info.
$payrow = sqlQuery("SELECT " . "SUM(amount1) AS amount1, " . "SUM(amount2) AS amount2, " . "MAX(method) AS method, " . "MAX(source) AS source, " . "MAX(dtime) AS dtime, " .
// "MAX(user) AS user " .
"MAX(user) AS user, " . "MAX(encounter) as encounter " . "FROM payments WHERE " . "pid = ? AND dtime = ?", array($form_pid, $timestamp
));
// Create key for deleting, just in case.
$ref_id = ($_REQUEST['radio_type_of_payment'] == 'copay') ? $session_id : $payment_id;
$payment_key = $form_pid . '.' . preg_replace('/[^0-9]/', '', $timestamp) . '.' . $ref_id;
// get facility from encounter
$tmprow = sqlQuery("SELECT facility_id FROM form_encounter WHERE encounter = ?", array($payrow['encounter']));
$frow = sqlQuery("SELECT * FROM facility " . " WHERE id = ?", array($tmprow['facility_id']
));
// Now proceed with printing the receipt.
?>
<title><?php echo xlt('Receipt for Payment'); ?></title>
<script src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery/dist/jquery.min.js"></script>
<script>
function goHome() {
window.location.replace("./patient/onsiteactivityviews");
}
function notifyPatient() {
let pid = <?php echo js_escape($pid); ?>;
let note = $('#pop_receipt').html();
let formURL = './messaging/handle_note.php';
let sn = <?php echo js_escape($adminUser['username']); ?>;
let rid = <?php echo js_escape($portalPatient['recip_id']); ?>;
let rn = <?php echo js_escape($portalPatient['username']); ?>;
$.ajax({
url: formURL,
type: "POST",
data: {
'csrf_token_form': <?php echo js_escape(CsrfUtils::collectCsrfToken('messages-portal')); ?>,
'task': 'add',
'pid': pid,
'inputBody': note,
'title': 'Bill/Collect',
'recipient_name': rn,
'recipient_id': rid,
'sender_id': owner,
'sender_name': sn
},
success: function (data, textStatus, jqXHR) {
alert('Receipt sent to patient via Messages.')
},
error: function (jqXHR, status, error) {
console.log(status + ": " + error);
}
});
}
</script>
<?php
ob_start();
echo '<htlm><head></head><body style="text-align: center; margin: auto;">';
?>
<div id='pop_receipt' style='display: block'>
<p>
<h2><?php echo xlt('Receipt for Payment'); ?></h2>
<p><?php echo text($frow['name']) ?>
<br /><?php echo text($frow['street']) ?>
<br /><?php echo text($frow['city'] . ', ' . $frow['state']) . ' ' . text($frow['postal_code']) ?>
<br /><?php echo text($frow['phone']) ?>
<p>
<div class="text-center" style="margin: auto;">
<table border='0' cellspacing='8' class="text-center" style="margin: auto;">
<tr>
<td><?php echo xlt('Date'); ?>:</td>
<td><?php echo text(oeFormatSDFT(strtotime($payrow['dtime']))) ?></td>
</tr>
<tr>
<td><?php echo xlt('Patient'); ?>:</td>
<td><?php echo text($patdata['fname']) . " " . text($patdata['mname']) . " " . text($patdata['lname']) . " (" . text($patdata['pubpid']) . ")" ?></td>
</tr>
<tr>
<td><?php echo xlt('Paid Via'); ?>:</td>
<td><?php echo generate_display_field(array('data_type' => '1', 'list_id' => 'payment_method'), $payrow['method']); ?></td>
</tr>
<tr>
<td><?php echo xlt('Authorized Id'); ?>:</td>
<td><?php echo text($payrow['source']) ?></td>
</tr>
<tr>
<td><?php echo xlt('Amount for This Visit'); ?>:</td>
<td><?php echo text(oeFormatMoney($payrow['amount1'])) ?></td>
</tr>
<tr>
<td><?php echo xlt('Amount for Past Balance'); ?>:</td>
<td><?php echo text(oeFormatMoney($payrow['amount2'])) ?></td>
</tr>
<tr>
<td><?php echo xlt('Received By'); ?>:</td>
<td><?php echo text($payrow['user']) ?></td>
</tr>
</table>
</div>
</div>
<button class='btn btn-sm' type='button' onclick='goHome()' id='returnhome'><?php echo xla('Return Home'); ?></button>
<button class='btn btn-sm' type='button' onclick="notifyPatient()"><?php echo xla('Notify Patient'); ?></button>
</body></html>
<?php
ob_end_flush();
} else {
//
// Here we display the form for data entry.
//
?>
<title><?php echo xlt('Record Payment'); ?></title>
<style>
.dehead {
color: #000000;
font-weight: bold
}
.detail {
padding: 1px 1px;
color: #000000;
font-weight: normal
}
</style>
<script src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-creditcardvalidator/jquery.creditCardValidator.js"></script>
<script src="<?php echo $GLOBALS['webroot'] ?>/library/textformat.js?v=<?php echo $v_js_includes; ?>"></script>
<script>
var chargeMsg = <?php $amsg = xl('Payment was successfully authorized and your card is charged.') . "\n" .
xl("You will be notified when your payment is applied for this invoice.") . "\n" .
xl('Until then you will continue to see payment details here.') . "\n" . xl('Thank You.');
echo json_encode($amsg);
?>;
var publicKey = <?php echo json_encode($cryptoGen->decryptStandard($GLOBALS['gateway_public_key'])); ?>;
var apiKey = <?php echo json_encode($cryptoGen->decryptStandard($GLOBALS['gateway_api_key'])); ?>;
function calctotal() {
var flag = 0;
var f = document.forms["invoiceForm"];
var total = 0;
for (var i = 0; i < f.elements.length; ++i) {
var elem = f.elements[i];
var ename = elem.name;
if (ename.indexOf('form_upay[') == 0 || ename.indexOf('form_bpay[') == 0) {
if (elem.value.length > 0) {
total += Number(elem.value);
if (total < 0) flag = 1;
}
}
}
f.form_paytotal.value = Number(total).toFixed(2);
if (flag) {
$('#invoiceForm')[0].reset();
alert(<?php echo xlj('Negative payments not accepted'); ?>)
}
return true;
}
function coloring() {
for (var i = 1; ; ++i) {
if (document.getElementById('paying_' + i)) {
paying = document.getElementById('paying_' + i).value * 1;
patient_balance = document.getElementById('duept_' + i).innerHTML * 1;
if (patient_balance > 0 && paying > 0) {
if (paying > patient_balance) {
document.getElementById('paying_' + i).style.background = '#FF0000';
}
else if (paying < patient_balance) {
document.getElementById('paying_' + i).style.background = '#99CC00';
}
else if (paying == patient_balance) {
document.getElementById('paying_' + i).style.background = '#ffffff';
}
}
else {
document.getElementById('paying_' + i).style.background = '#ffffff';
}
}
else {
break;
}
}
}
function CheckVisible(MakeBlank) {//Displays and hides the check number text box.
if (document.getElementById('form_method').options[document.getElementById('form_method').selectedIndex].value == 'check_payment' ||
document.getElementById('form_method').options[document.getElementById('form_method').selectedIndex].value == 'bank_draft') {
document.getElementById('check_number').disabled = false;
}
else {
document.getElementById('check_number').disabled = true;
}
}
function validate() {
var f = document.forms["invoiceForm"];
ok = -1;
//no checks taken here....
issue = 'no';
if (document.getElementById('radio_type_of_payment_self1').checked == false &&
document.getElementById('radio_type_of_payment1').checked == false
&& document.getElementById('radio_type_of_payment2').checked == false
&& document.getElementById('radio_type_of_payment4').checked == false) {
alert("<?php //echo addslashes( xl('Please Select Type Of Payment.')) ?>");
return false;
}
if (document.getElementById('radio_type_of_payment_self1').checked == true || document.getElementById('radio_type_of_payment1').checked == true) {
for (var i = 0; i < f.elements.length; ++i) {
var elem = f.elements[i];
var ename = elem.name;
if (ename.indexOf('form_upay[0') == 0) //Today is this text box.
{
if (elem.value * 1 > 0) {//A warning message, if the amount is posted with out encounter.
if (confirm(<?php echo xlj('Are you sure to post for today?'); ?>)) {
ok = 1;
}
else {
elem.focus();
return false;
}
}
break;
}
}
}
else if (document.getElementsByName('form_paytotal')[0].value <= 0)//total 0
{
alert(<?php echo xlj('Invalid Total!'); ?>)
return false;
}
if (ok == -1) {
if (confirm(<?php echo xlj('Payment Validated: Save?'); ?>)) {
return true;
}
else {
return false;
}
}
}
function cursor_pointer() {//Point the cursor to the latest encounter(Today)
var f = document.forms["invoiceForm"];
var total = 0;
for (var i = 0; i < f.elements.length; ++i) {
var elem = f.elements[i];
var ename = elem.name;
if (ename.indexOf('form_upay[') == 0) {
elem.focus();
break;
}
}
}
function make_it_hide_enc_pay() {
document.getElementById('td_head_insurance_payment').style.display = "none";
document.getElementById('td_head_patient_co_pay').style.display = "none";
document.getElementById('td_head_co_pay').style.display = "none";
document.getElementById('td_head_insurance_balance').style.display = "none";
for (var i = 1; ; ++i) {
var td_inspaid_elem = document.getElementById('td_inspaid_' + i)
var td_patient_copay_elem = document.getElementById('td_patient_copay_' + i)
var td_copay_elem = document.getElementById('td_copay_' + i)
var balance_elem = document.getElementById('balance_' + i)
if (td_inspaid_elem) {
td_inspaid_elem.style.display = "none";
td_patient_copay_elem.style.display = "none";
td_copay_elem.style.display = "none";
balance_elem.style.display = "none";
}
else {
break;
}
}
document.getElementById('td_total_4').style.display = "none";
document.getElementById('td_total_7').style.display = "none";
document.getElementById('td_total_8').style.display = "none";
document.getElementById('td_total_6').style.display = "none";
document.getElementById('table_display').width = "420px";
}
function make_visible() {
document.getElementById('td_head_rep_doc').style.display = "";
document.getElementById('td_head_description').style.display = "";
document.getElementById('td_head_total_charge').style.display = "none";
document.getElementById('td_head_insurance_payment').style.display = "none";
document.getElementById('td_head_patient_payment').style.display = "none";
document.getElementById('td_head_patient_co_pay').style.display = "none";
document.getElementById('td_head_co_pay').style.display = "none";
document.getElementById('td_head_insurance_balance').style.display = "none";
document.getElementById('td_head_patient_balance').style.display = "none";
for (var i = 1; ; ++i) {
var td_charges_elem = document.getElementById('td_charges_' + i)
var td_inspaid_elem = document.getElementById('td_inspaid_' + i)
var td_ptpaid_elem = document.getElementById('td_ptpaid_' + i)
var td_patient_copay_elem = document.getElementById('td_patient_copay_' + i)
var td_copay_elem = document.getElementById('td_copay_' + i)
var balance_elem = document.getElementById('balance_' + i)
var duept_elem = document.getElementById('duept_' + i)
if (td_charges_elem) {
td_charges_elem.style.display = "none";
td_inspaid_elem.style.display = "none";
td_ptpaid_elem.style.display = "none";
td_patient_copay_elem.style.display = "none";
td_copay_elem.style.display = "none";
balance_elem.style.display = "none";
duept_elem.style.display = "none";
}
else {
break;
}
}
document.getElementById('td_total_7').style.display = "";
document.getElementById('td_total_8').style.display = "";
document.getElementById('td_total_1').style.display = "none";
document.getElementById('td_total_2').style.display = "none";
document.getElementById('td_total_3').style.display = "none";
document.getElementById('td_total_4').style.display = "none";
document.getElementById('td_total_5').style.display = "none";
document.getElementById('td_total_6').style.display = "none";
document.getElementById('table_display').width = "505px";
}
function make_it_hide() {
document.getElementById('td_head_rep_doc').style.display = "none";
document.getElementById('td_head_description').style.display = "none";
document.getElementById('td_head_total_charge').style.display = "";
document.getElementById('td_head_insurance_payment').style.display = "";
document.getElementById('td_head_patient_payment').style.display = "";
document.getElementById('td_head_patient_co_pay').style.display = "";
document.getElementById('td_head_co_pay').style.display = "";
document.getElementById('td_head_insurance_balance').style.display = "";
document.getElementById('td_head_patient_balance').style.display = "";
for (var i = 1; ; ++i) {
var td_charges_elem = document.getElementById('td_charges_' + i)
var td_inspaid_elem = document.getElementById('td_inspaid_' + i)
var td_ptpaid_elem = document.getElementById('td_ptpaid_' + i)
var td_patient_copay_elem = document.getElementById('td_patient_copay_' + i)
var td_copay_elem = document.getElementById('td_copay_' + i)
var balance_elem = document.getElementById('balance_' + i)
var duept_elem = document.getElementById('duept_' + i)
if (td_charges_elem) {
td_charges_elem.style.display = "";
td_inspaid_elem.style.display = "";
td_ptpaid_elem.style.display = "";
td_patient_copay_elem.style.display = "";
td_copay_elem.style.display = "";
balance_elem.style.display = "";
duept_elem.style.display = "";
}
else {
break;
}
}
document.getElementById('td_total_1').style.display = "";
document.getElementById('td_total_2').style.display = "";
document.getElementById('td_total_3').style.display = "";
document.getElementById('td_total_4').style.display = "";
document.getElementById('td_total_5').style.display = "";
document.getElementById('td_total_6').style.display = "";
document.getElementById('td_total_7').style.display = "";
document.getElementById('td_total_8').style.display = "";
document.getElementById('table_display').width = "100%";
}
function make_visible_radio() {
document.getElementById('tr_radio1').style.display = "";
document.getElementById('tr_radio2').style.display = "none";
}
function make_hide_radio() {
document.getElementById('tr_radio1').style.display = "none";
document.getElementById('tr_radio2').style.display = "";
}
function make_visible_row() {
document.getElementById('table_display').style.display = "";
document.getElementById('table_display_prepayment').style.display = "none";
}
function make_hide_row() {
document.getElementById('table_display').style.display = "none";
document.getElementById('table_display_prepayment').style.display = "";
}
function make_self() {
make_visible_row();
make_it_hide();
make_it_hide_enc_pay();
document.getElementById('radio_type_of_payment_self1').checked = true;
cursor_pointer();
}
function make_insurance() {
make_visible_row();
make_it_hide();
cursor_pointer();
document.getElementById('radio_type_of_payment1').checked = true;
}
$('#paySubmit').click(function (e) {
e.preventDefault();e.stopPropagation();
$("#mode").val("portal-save");
let inv_values = JSON.stringify(getFormObj('invoiceForm'));
let extra_values = JSON.stringify(getFormObj('paymentForm'));
let extra = "&inv_values=" + encodeURIComponent(inv_values) + "&extra_values=" + encodeURIComponent(extra_values);
let flag = 0
let liburl = './lib/paylib.php';
$.ajax({
type: "POST",
url: liburl,
data: $("#invoiceForm").serialize() + extra,
beforeSend: function (xhr) {
if (validateCC() !== true) return false;
if ($('#cardCode').val() == "" || $('#cardHolderName').val() == "" || $('#expYear').val() == "" || $('#expMonth').val() == "") {
alert(<?php echo xlj('Invalid Credit Card Values: Please correct'); ?>)
return false;
}
if (validate() != true) {
flag = 1;
alert(<?php echo xlj('Validation error: Fix and resubmit. This popup info is preserved!'); ?>)
return false;
}
$("#openPayModal .close").click()
},
error: function (qXHR, textStatus, errorThrow) {
console.log("There was an error:" + errorThrow);
},
success: function (templateHtml, textStatus, jqXHR) {
let msg = <?php $amsg = xl('Payment successfully sent for review and posting to your account.') . "\n" .
xl("You will be notified when the payment transaction is confirmed.") . "\n" .
xl('Until then you will continue to see payment details here.') . "\n" . xl('Thank You.');
echo json_encode($amsg); // backward compatable 5.0.1
?>;
alert(msg);
window.location.reload(false);
}
});
if (flag) {
$("#openPayModal .close").click();
}
});
$('#openPayModal').on('show.bs.modal', function () {
let total = $("#form_paytotal").val();
if(Number(total) < 1) {
let error = <?php echo json_encode("Please enter a payment amount"); ?>;
alert(error);
return false;
}
$("#payTotal").text(total);
$("#paymentAmount").val(total);
});
$("#invoiceForm").on('submit', function (e) {
e.preventDefault();
let thisform = this;
$("#mode").val("review-save");
let inv_values = JSON.stringify(getFormObj('invoiceForm'));
let extra_values = JSON.stringify(getFormObj('paymentForm'));
let extra = "&inv_values=" + inv_values + "&extra_values=" + extra_values;
let flag = 0
let liburl = '<?php echo $GLOBALS["webroot"] ?>/portal/lib/paylib.php';
$.ajax({
type: "POST",
url: liburl,
data: $("#invoiceForm").serialize() + extra,
beforeSend: function (xhr) {
if (validate() != true) {
flag = 1;
alert(<?php echo xlj('Validation error: Fix and resubmit.'); ?>)
return false;
}
},
error: function (xhr, textStatus, error) {
alert(<?php echo xlj('There is a Post error'); ?>)
console.log("There was an error:" + textStatus);
return false;
},
success: function (templateHtml, textStatus, jqXHR) {
thisform.submit();
}
});
});
function getFormObj(formId) {
let formObj = {};
let inputs = $('#' + formId).serializeArray();
$.each(inputs, function (i, input) {
formObj[input.name] = input.value;
});
return formObj;
}
function formRepopulate(jsondata) {
let data = $.parseJSON(jsondata);
$.each(data, function (name, val) {
let $el = $('[name="' + name + '"]'),
type = $el.attr('type');
switch (type) {
case 'checkbox':
$el.prop('checked', true);
break;
case 'radio':
$el.filter('[value="' + val + '"]').prop('checked', true);
break;
default:
$el.val(val);
}
});
}
function getAuth() {
let authnum = document.getElementById("check_number").value;
authnum = prompt(<?php echo xlj('Please enter card comfirmation authorization'); ?>, authnum);
if (authnum != null) {
document.getElementById("check_number").value = authnum;
}
}
</script>
<body class="skin-blue" onunload='imclosing()' onLoad="cursor_pointer();"
style="text-align: center; margin: auto;">
<form id="invoiceForm" method='post' action='<?php echo $GLOBALS["webroot"] ?>/portal/portal_payment.php'>
<input type='hidden' name='form_pid' value='<?php echo attr($pid) ?>'/>
<input type='hidden' name='form_save' value='<?php echo xla('Invoice'); ?>'/>
<table>
<tr height="10">
<td colspan="3"> </td>
</tr>
<tr>
<td colspan='3' align='center' class='text'>
<b><?php echo xlt('Accept Payment for'); ?> : <?php
echo text($patdata['fname']) . " " .
text($patdata['lname']) . " " .
text($patdata['mname']) . " (" .
text($patdata['pid']) . ")" ?></b>
<?php $NameNew = $patdata['fname'] . " " . $patdata['lname'] . " " . $patdata['mname']; ?>
</td>
</tr>
<tr height="15">
<td colspan='3'></td>
</tr>
<tr>
<td class='text'>
<?php echo xlt('Payment Method'); ?>:
</td>
<td colspan='2'><select name="form_method" id="form_method" class="form-control" onChange='CheckVisible("yes")'>
<?php
$query1112 = "SELECT * FROM list_options where list_id=? ORDER BY seq, title ";
$bres1112 = sqlStatement($query1112, array('payment_method'));
while ($brow1112 = sqlFetchArray($bres1112)) {
if ($brow1112['option_id'] != 'credit_card' || $brow1112['option_id'] == 'debit' || $brow1112['option_id'] == 'bank_draft') {
continue;
}
echo "<option value='" . attr($brow1112['option_id']) . "'>" .
text(xl_list_label($brow1112['title'])) . "</option>";
}
?>
</select></td>
</tr>
<?php if (isset($_SESSION['authUserID'])) { ?>
<tr height="5">
<td colspan='3'></td>
</tr>
<tr>
<td class='text'>
<?php echo xlt('Authorized'); ?>:
</td>
<td colspan='2'>
<?php if ($ccdata['authCode'] && empty($payrow['source'])) {
$payrow['source'] = $ccdata['authCode'] . " : " . $ccdata['transId'];
}
?>
<input class="form-control form-control-sm" id='check_number' name='form_source' style='' value='<?php echo attr($payrow['source']) ?>' />
</td>