/
front_payment.php
1735 lines (1622 loc) · 89 KB
/
front_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
/**
* Front payment gui.
*
* @package OpenEMR
* @link http://www.open-emr.org
* @author Rod Roark <rod@sunsetsystems.com>
* @author Brady Miller <brady.g.miller@gmail.com>
* @copyright Copyright (c) 2006-2020 Rod Roark <rod@sunsetsystems.com>
* @copyright Copyright (c) 2017-2018 Brady Miller <brady.g.miller@gmail.com>
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
*/
require_once("../globals.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\Acl\AclMain;
use OpenEMR\Common\Csrf\CsrfUtils;
use OpenEMR\Common\Twig\TwigContainer;
use OpenEMR\Core\Header;
use OpenEMR\OeUI\OemrUI;
use OpenEMR\PaymentProcessing\Sphere\SpherePayment;
use OpenEMR\Services\FacilityService;
if (!empty($_REQUEST['receipt']) && empty($_POST['form_save'])) {
if (!AclMain::aclCheckCore('acct', 'bill') && !AclMain::aclCheckCore('acct', 'rep_a') && !AclMain::aclCheckCore('patients', 'rx')) {
echo (new TwigContainer(null, $GLOBALS['kernel']))->getTwig()->render('core/unauthorized.html.twig', ['pageTitle' => xl("Receipt for Payment")]);
exit;
}
} else {
if (!AclMain::aclCheckCore('acct', 'bill', '', 'write')) {
if (!empty($_POST['form_save'])) {
$pageTitle = xl("Receipt for Payment");
} else {
$pageTitle = xl("Record Payment");
}
echo (new TwigContainer(null, $GLOBALS['kernel']))->getTwig()->render('core/unauthorized.html.twig', ['pageTitle' => $pageTitle]);
exit;
}
}
$pid = (!empty($_REQUEST['hidden_patient_code']) && ($_REQUEST['hidden_patient_code'] > 0)) ? $_REQUEST['hidden_patient_code'] : $pid;
$facilityService = new FacilityService();
?>
<!DOCTYPE html>
<html>
<head>
<?php Header::setupHeader(['opener']);?>
<?php if ($GLOBALS['payment_gateway'] == 'Stripe') { ?>
<script src="https://js.stripe.com/v3/"></script>
<?php } ?>
<?php if ($GLOBALS['payment_gateway'] == 'AuthorizeNet') {
// Must be loaded from their server
$script = "https://jstest.authorize.net/v1/Accept.js"; // test script
if ($GLOBALS['gateway_mode_production']) {
$script = "https://js.authorize.net/v1/Accept.js"; // Production script
} ?>
<script src=<?php echo $script; ?> charset="utf-8"></script>
<?php } ?>
<?php
// Format dollars for display.
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;
function echoLine($iname, $date, $charges, $ptpaid, $inspaid, $duept, $encounter = 0, $copay = 0, $patcopay = 0)
{
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>" . text(oeFormatShortDate($date)) . "</td>\n";
echo " <td class='text-center' id='" . attr($date) . "'>" . text($encounter) . "</td>\n";
echo " <td class='text-center' id='td_charges_$var_index' >" . text(bucks($charges)) . "</td>\n";
echo " <td class='text-center' id='td_inspaid_$var_index' >" . text(bucks($inspaid * -1)) . "</td>\n";
echo " <td class='text-center' id='td_ptpaid_$var_index' >" . text(bucks($ptpaid * -1)) . "</td>\n";
echo " <td class='text-center' id='td_patient_copay_$var_index' >" . text(bucks($patcopay)) . "</td>\n";
echo " <td class='text-center' id='td_copay_$var_index' >" . text(bucks($copay)) . "</td>\n";
echo " <td class='text-center' id='balance_$var_index'>" . text(bucks($balance)) . "</td>\n";
echo " <td class='text-center' id='duept_$var_index'>" . text(bucks(round($duept, 2) * 1)) . "</td>\n";
echo " <td class='text-right'><input type='text' class='form-control' name='" . attr($iname) . "' id='paying_" . attr($var_index) . "' " .
" value='' onchange='coloring();calctotal()' autocomplete='off' " .
"onkeyup='calctotal()'/></td>\n";
echo " </tr>\n";
}
// 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 = ? AND activity = 1 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.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 (!empty($_POST['form_save'])) {
if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"])) {
CsrfUtils::csrfNotVerified();
}
$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) {
$payment = floatval($payment);
if ($amount = $payment) {
$zero_enc = $enc;
if ($_REQUEST['radio_type_of_payment'] == 'invoice_balance') {
if (!$enc) {
$enc = calendar_arrived($form_pid);
}
} else {
if (!$enc) {
$enc = calendar_arrived($form_pid);
}
}
//----------------------------------------------------------------------------------------------------
//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 pid =? and " .
"encounter = ? and payer_type = 0 and account_code = 'PCP' AND deleted IS NULL",
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 pid = ? AND deleted IS NULL " .
"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 " .
"pid = ? and code_type = ? and code = ? and modifier = ? and encounter = ? AND deleted IS NULL",
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 (!empty($_POST['form_save']) || !empty($_REQUEST['receipt'])) {
if (!empty($_REQUEST['receipt'])) {
$form_pid = $_GET['patient'];
$timestamp = decorateString('....-..-.. ..:..:..', $_GET['time']);
}
// Get details for what we guess is the primary facility.
$frow = $facilityService->getPrimaryBusinessEntity(array("useLegacyImplementation" => true));
// 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;
if ($_REQUEST['radio_type_of_payment'] != 'pre_payment') {
// get facility from encounter
$tmprow = sqlQuery("SELECT `facility_id` FROM `form_encounter` WHERE `encounter` = ?", array($payrow['encounter']));
$frow = $facilityService->getById($tmprow['facility_id']);
} else {
// if pre_payment, then no encounter yet, so get main office address
$frow = $facilityService->getPrimaryBillingLocation();
}
// Now proceed with printing the receipt.
?>
<title><?php echo xlt('Receipt for Payment'); ?></title>
<?php Header::setupHeader(); ?>
<script>
<?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
$(function () {
var win = top.printLogSetup ? top : opener.top;
win.printLogSetup(document.getElementById('printbutton'));
});
function closeHow(e) {
if (opener) {
dlgclose();
return;
}
top.activateTabByName('pat', true);
top.tabCloseByName(window.name);
}
// This is action to take before printing and is called from restoreSession.php.
function printlog_before_print() {
let divstyle = document.getElementById('hideonprint').style;
divstyle.display = 'none';
// currently exit is not hidden by default in case receipt print is not needed
// and left here for future option to force users to print via global etc..
// can still print later via reports.
divstyle = document.getElementById('showonprint').style;
divstyle.display = '';
}
// Process click on Delete button.
function deleteme() {
dlgopen('deleter.php?payment=' + <?php echo js_url($payment_key); ?> + '&csrf_token_form=' + <?php echo js_url(CsrfUtils::collectCsrfToken()); ?>, '_blank', 500, 450);
return false;
}
// Called by the deleteme.php window on a successful delete.
function imdeleted() {
if (opener) {
dlgclose(); // we're in reports/leftnav and callback reloads.
} else {
window.history.back(); // this is us full screen.
}
}
// Called to switch to the specified encounter having the specified DOS.
// This also closes the popup window.
function toencounter(enc, datestr, topframe) {
top.restoreSession();
top.goToEncounter(enc);
if (opener) dlgclose();
}
</script>
<style>
@media print {
#donebutton {
display: none;
}
}
</style>
</head>
<body>
<div class="container mt-3">
<div class="row">
<div class="col-12 text-center">
<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="table-responsive">
<table class="table table-borderless">
<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('How Paid'); ?>:</td>
<td><?php echo generate_display_field(array('data_type' => '1', 'list_id' => 'payment_method'), $payrow['method']); ?></td>
</tr>
<tr>
<td><?php echo xlt('Check or Reference Number'); ?>:</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
if ($_REQUEST['radio_type_of_payment'] == 'pre_payment') {
echo xlt('Pre-payment Amount');
} else {
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 id='hideonprint'>
<button type="button" class="btn btn-primary btn-print" value='<?php echo xla('Print'); ?>' id='printbutton'>
<?php echo xlt('Print'); ?>
</button>
<?php
$todaysenc = todaysEncounterIf($pid);
if ($todaysenc && $todaysenc != $encounter) {
echo " <input type='button' class='btn btn-primary' " .
"value='" . xla('Open Today`s Visit') . "' " .
"onclick='toencounter(" . attr_js($todaysenc) . ", " . attr_js($today) . ", (opener ? opener.top : top))' />\n";
}
?>
<?php if (AclMain::aclCheckCore('admin', 'super') || AclMain::aclCheckCore('acct', 'bill')) {
// allowing biller to delete payments ?>
<button type="button" class="btn btn-danger btn-delete" value='<?php echo xla('Delete'); ?>' onclick="deleteme()">
<?php echo xlt('Delete'); ?>
</button>
<?php } ?>
</div>
<div class='mt-3' id='showonprint'>
<button type="button" class="btn btn-secondary btn-cancel" value='<?php echo xla('Exit'); ?>' id='donebutton' onclick="closeHow(event)">
<?php echo xlt('Exit'); ?>
</button>
</div>
</div>
</div>
</div>
</body>
<?php
//
// End of receipt printing logic.
//
} else {
//
// Here we display the form for data entry.
//
?>
<title><?php echo xlt('Record Payment'); ?></title>
<style>
#ajax_div_patient {
position: absolute;
z-index:10;
background-color: #FBFDD0;
border: 1px solid #ccc;
padding: 10px;
}
</style>
<!--Removed standard dependencies 12/29/17 as not needed any longer since moved to a tab/frame not popup.-->
<!-- supporting javascript code -->
<script>
var mypcc = '1';
</script>
<?php include_once("{$GLOBALS['srcdir']}/ajax/payment_ajax_jav.inc.php"); ?>
<script>
document.onclick=HideTheAjaxDivs;
</script>
<?php Header::setupAssets('topdialog'); ?>
<script src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-creditcardvalidator/jquery.creditCardValidator.js"></script>
<script>
var chargeMsg = <?php echo xlj('Payment was successfully authorized and charged. Thank You.'); ?>;
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() {
$('#openPayModal').on('show.bs.modal', function () {
let total = $("[name='form_paytotal']").val();
let prepay = $("#form_prepayment").val();
if (Number(total) < 1) {
if (Number(prepay) < 1) {
let error = <?php echo xlj("Please enter a payment amount"); ?>;
alert(error);
return false;
}
total = prepay;
}
$("#form_method").val('credit_card');
$("#payTotal").text(total);
$("#paymentAmount").val(total);
});
});
<?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
function closeHow(e) {
if (opener) {
dlgclose();
return;
}
top.activateTabByName('pat', true);
top.tabCloseByName(window.name);
}
function calctotal() {
var f = document.forms[0];
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);
}
}
f.form_paytotal.value = Number(total).toFixed(2);
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;
//balance=document.getElementById('balance_'+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 = 'var(--white)';
}
} else {
document.getElementById('paying_' + i).style.background = 'var(--white)';
}
}
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(notSubmit = false) {
var f = document.forms[0];
let ok = -1;
top.restoreSession();
issue = 'no';
// prevent an empty form submission
let flgempty = true;
for (let i = 0; i < f.elements.length; ++i) {
let ename = f.elements[i].name;
if (f.elements[i].value == 'pre_payment' && f.elements[i].checked === true) {
if (Number(f.elements.namedItem("form_prepayment").value) !== 0) {
flgempty = false;
}
break;
}
if (ename.indexOf('form_upay[') === 0 || ename.indexOf('form_bpay[') === 0) {
if (Number(f.elements[i].value) !== 0) flgempty = false;
}
}
if (flgempty) {
alert(<?php echo xlj('A Payment is Required!. Please input a payment line item entry.'); ?>);
return false;
}
// continue validation.
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').value == '')) {
alert(<?php echo xlj('Please Fill the Check or Reference Number'); ?>);
document.getElementById('check_number').focus();
return false;
}
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 xlj('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('If patient has appointment click OK to create encounter otherwise, cancel this and then create an encounter for today visit.'); ?>)) {
ok = 2;
} else {
elem.focus();
return false;
}
}
break;
}
}
}
if (document.getElementById('radio_type_of_payment1').checked == true){//CO-PAY
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]') == 0) {//Today is this text box.
if (f.form_paytotal.value * 1 != elem.value * 1) {//Total CO-PAY is not posted against today
//A warning message, if the amount is posted against an old encounter.
if (confirm(<?php echo xlj('You are posting against an old encounter?'); ?>)) {
ok = 1;
} else {
elem.focus();
return false;
}
}
break;
}
}
}//Co Pay
else if (document.getElementById('radio_type_of_payment2').checked == true) {//Invoice Balance
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) {
if (elem.value * 1 > 0) {
alert(<?php echo xlj('Invoice Balance cannot be posted. No Encounter is created.'); ?>);
return false;
}
break;
}
}
}
if (notSubmit) {
return true;
}
if (ok === -1) {
if (confirm(<?php echo xlj('Would you like to save?'); ?>)) {
return true;
}
else {
return false;
}
}
return ok;
}
function cursor_pointer() { //Point the cursor to the latest encounter(Today)
var f = document.forms[0];
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 = "635px";
}
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;
}
</script>
<style>
@media (min-width: 992px) {
.modal-lg {
width: 1000px !Important;
}
}
</style>
<title><?php echo xlt('Record Payment'); ?></title>
<?php $NameNew = $patdata['fname'] . " " . $patdata['lname'] . " " . $patdata['mname']; ?>
<?php
$arrOeUiSettings = array(
'heading_title' => xl('Accept Payment'),
'include_patient_name' => true,// use only in appropriate pages
'expandable' => false,
'expandable_files' => array(),//all file names need suffix _xpd
'action' => "",//conceal, reveal, search, reset, link or back
'action_title' => "",
'action_href' => "",//only for actions - reset, link or back
'show_help_icon' => false,
'help_file_name' => ""
);
$oemr_ui = new OemrUI($arrOeUiSettings);
?>
</head>