fix: set default x12 partner for item in billing manager (#7502)
[openemr.git] / interface / billing / edit_payment.php
blob40548c7180f1952e9fd40198e43bdff3a77c040c
1 <?php
3 /*
4 * Payments can be edited here whch includes deletion of an allocation, modifying the
5 * same or adding a new allocation. Log is kept for the deleted ones.
6 * The functions of this class support the billing process like the script billing_process.php.
8 * @package OpenEMR
9 * @link http://www.open-emr.org
10 * @author Eldho Chacko <eldho@zhservices.com>
11 * @author Paul Simon K <paul@zhservices.com>
12 * @author Stephen Waite <stephen.waite@cmsvt.com>
13 * @author Brady Miller <brady.g.miller@gmail.com>
14 * @author Rod Roark <rod@sunsetsystems.com>
15 * @copyright Copyright (c) 2010 Z&H Consultancy Services Private Limited <sam@zhservices.com>
16 * @copyright Copyright (C) 2018-2020 Stephen Waite <stephen.waite@cmsvt.com>
17 * @copyright Copyright (c) 2019-2020 Brady Miller <brady.g.miller@gmail.com>
18 * @copyright Copyright (c) 2020 Rod Roark <rod@sunsetsystems.com>
19 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
23 require_once("../globals.php");
24 require_once("../../custom/code_types.inc.php");
25 require_once("$srcdir/patient.inc.php");
26 require_once("$srcdir/options.inc.php");
27 require_once("$srcdir/payment.inc.php");
29 use OpenEMR\Common\Acl\AclMain;
30 use OpenEMR\Common\Twig\TwigContainer;
31 use OpenEMR\Core\Header;
33 if (!AclMain::aclCheckCore('acct', 'bill', '', 'write') && !AclMain::aclCheckCore('acct', 'eob', '', 'write')) {
34 echo (new TwigContainer(null, $GLOBALS['kernel']))->getTwig()->render('core/unauthorized.html.twig', ['pageTitle' => xl("Confirm Payment")]);
35 exit;
38 $screen = 'edit_payment';
40 // Deletion of payment distribution code
42 if (isset($_POST["mode"])) {
43 if ($_POST["mode"] == "DeletePaymentDistribution") {
44 $DeletePaymentDistributionId = (isset($_POST['DeletePaymentDistributionId']) ? trim($_POST['DeletePaymentDistributionId']) : '');
45 $DeletePaymentDistributionIdArray = explode('_', $DeletePaymentDistributionId);
46 $payment_id = $DeletePaymentDistributionIdArray[0];
47 $PId = $DeletePaymentDistributionIdArray[1];
48 $Encounter = $DeletePaymentDistributionIdArray[2];
49 $Code = $DeletePaymentDistributionIdArray[3];
50 $Modifier = $DeletePaymentDistributionIdArray[4];
51 $Codetype = $DeletePaymentDistributionIdArray[5];
52 //delete and log that action
53 row_modify(
54 "ar_activity",
55 "deleted = NOW()",
56 "session_id = '" . add_escape_custom($payment_id) . "' AND " .
57 "pid = '" . add_escape_custom($PId) . "' AND " .
58 "deleted IS NULL AND " .
59 "encounter = '" . add_escape_custom($Encounter) . "' AND " .
60 "code_type = '" . add_escape_custom($Codetype) . "' AND " .
61 "code = '" . add_escape_custom($Code) . "' AND " .
62 "modifier='" . add_escape_custom($Modifier) . "'"
64 $Message = 'Delete';
65 //------------------
66 $_POST["mode"] = "searchdatabase";
70 //===============================================================================
71 //Modify Payment Code.
72 //===============================================================================
74 if (isset($_POST["mode"])) {
75 if ($_POST["mode"] == "ModifyPayments" || $_POST["mode"] == "FinishPayments") {
76 $payment_id = $_REQUEST['payment_id'];
77 //ar_session Code
78 //===============================================================================
79 if (trim($_POST['type_name']) == 'insurance') {
80 $QueryPart = "payer_id = '" . trim(formData('hidden_type_code')) .
81 "', patient_id = '" . 0;
82 } elseif (trim($_POST['type_name']) == 'patient') {
83 $QueryPart = "payer_id = '" . 0 .
84 "', patient_id = '" . trim(formData('hidden_type_code'));
87 $user_id = $_SESSION['authUserID'];
88 $closed = 0;
89 $modified_time = date('Y-m-d H:i:s');
90 $check_date = DateToYYYYMMDD(formData('check_date'));
91 $deposit_date = DateToYYYYMMDD(formData('deposit_date'));
92 $post_to_date = DateToYYYYMMDD(formData('post_to_date'));
93 if ($post_to_date == '') {
94 $post_to_date = date('Y-m-d');
97 if ($_POST['deposit_date'] == '') {
98 $deposit_date = $post_to_date;
101 $global_account = "";
102 if (formData('global_reset') == '-0.00') {
103 $global_account = "', global_amount = '" . trim(formData('global_reset'));
106 sqlStatement("update ar_session set " .
107 $QueryPart .
108 "', user_id = '" . trim(add_escape_custom($user_id)) .
109 "', closed = '" . trim(add_escape_custom($closed)) .
110 "', reference = '" . trim(formData('check_number')) .
111 "', check_date = '" . trim(add_escape_custom($check_date)) .
112 "', deposit_date = '" . trim(add_escape_custom($deposit_date)) .
113 "', pay_total = '" . trim(formData('payment_amount')) .
114 "', modified_time = '" . trim(add_escape_custom($modified_time)) .
115 $global_account .
116 "', payment_type = '" . trim(formData('type_name')) .
117 "', description = '" . trim(formData('description')) .
118 "', adjustment_code = '" . trim(formData('adjustment_code')) .
119 "', post_to_date = '" . trim(add_escape_custom($post_to_date)) .
120 "', payment_method = '" . trim(formData('payment_method')) .
121 "' where session_id='" . add_escape_custom($payment_id) . "'");
122 //===============================================================================
123 $CountIndexAbove = $_REQUEST['CountIndexAbove'];
124 $CountIndexBelow = $_REQUEST['CountIndexBelow'];
125 $hidden_patient_code = $_REQUEST['hidden_patient_code'];
126 $user_id = $_SESSION['authUserID'];
127 $created_time = date('Y-m-d H:i:s');
128 //==================================================================
129 //UPDATION
130 //It is done with out deleting any old entries.
131 //==================================================================
132 for ($CountRow = 1; $CountRow <= $CountIndexAbove; $CountRow++) {
133 if (isset($_POST["HiddenEncounter$CountRow"])) {
134 $where1 = "WHERE deleted IS NULL AND session_id = '" . add_escape_custom($payment_id) .
135 "' AND pid ='" . trim(formData("HiddenPId$CountRow")) .
136 "' AND encounter = '" . trim(formData("HiddenEncounter$CountRow")) .
137 "' AND code_type = '" . trim(formData("HiddenCodetype$CountRow")) .
138 "' AND code = '" . trim(formData("HiddenCode$CountRow")) .
139 "' AND modifier = '" . trim(formData("HiddenModifier$CountRow")) .
140 "'";
142 $where = "$where1 AND pay_amount > 0";
143 if (!empty($_POST["Payment$CountRow"])) {
144 if (trim($_POST['type_name']) == 'insurance') {
145 if (trim($_POST["HiddenIns$CountRow"]) == 1) {
146 $AccountCode = "IPP";
148 if (trim($_POST["HiddenIns$CountRow"]) == 2) {
149 $AccountCode = "ISP";
151 if (trim($_POST["HiddenIns$CountRow"]) == 3) {
152 $AccountCode = "ITP";
154 } elseif (trim($_POST['type_name']) == 'patient') {
155 $AccountCode = "PP";
157 $resPayment = sqlStatement("SELECT * from ar_activity $where");
158 if (sqlNumRows($resPayment) > 0) {
159 sqlStatement("UPDATE ar_activity SET deleted = NOW() $where");
161 sqlBeginTrans();
162 $sequence_no = sqlQuery("SELECT IFNULL(MAX(sequence_no),0) + 1 AS increment " .
163 "FROM ar_activity WHERE pid = '" . trim(formData("HiddenPId$CountRow")) .
164 "' AND encounter = '" . trim(formData("HiddenEncounter$CountRow")) . "'");
165 sqlStatement("insert into ar_activity set " .
166 "pid = '" . trim(formData("HiddenPId$CountRow")) .
167 "', encounter = '" . trim(formData("HiddenEncounter$CountRow")) .
168 "', sequence_no = '" . add_escape_custom($sequence_no['increment']) .
169 "', code_type = '" . trim(formData("HiddenCodetype$CountRow")) .
170 "', code = '" . trim(formData("HiddenCode$CountRow")) .
171 "', modifier = '" . trim(formData("HiddenModifier$CountRow")) .
172 "', payer_type = '" . trim(formData("HiddenIns$CountRow")) .
173 "', reason_code = '" . trim(formData("ReasonCode$CountRow")) .
174 "', post_time = '" . trim(add_escape_custom($created_time)) .
175 "', post_user = '" . trim(add_escape_custom($user_id)) .
176 "', session_id = '" . trim(formData('payment_id')) .
177 "', modified_time = '" . trim(add_escape_custom($created_time)) .
178 "', pay_amount = '" . trim(formData("Payment$CountRow")) .
179 "', adj_amount = '" . 0 .
180 "', account_code = '" . add_escape_custom($AccountCode) .
181 "'");
182 sqlCommitTrans();
183 } else {
184 sqlStatement("UPDATE ar_activity SET deleted = NOW() $where");
187 //==============================================================================================================================
189 $where = "$where1 AND adj_amount != 0";
190 if (isset($_POST["AdjAmount$CountRow"]) && floatval($_POST["AdjAmount$CountRow"]) !== 0) {
191 if (trim($_POST['type_name']) == 'insurance') {
192 $AdjustString = "Ins adjust Ins" . trim($_POST["HiddenIns$CountRow"]);
193 $AccountCode = "IA";
194 } elseif (trim($_POST['type_name']) == 'patient') {
195 $AdjustString = "Pt adjust";
196 $AccountCode = "PA";
198 $resPayment = sqlStatement("SELECT * from ar_activity $where");
199 if (sqlNumRows($resPayment) > 0) {
200 sqlStatement("update ar_activity set deleted = NOW() $where");
202 sqlBeginTrans();
203 $sequence_no = sqlQuery("SELECT IFNULL(MAX(sequence_no),0) + 1 AS increment FROM ar_activity WHERE pid = '" . trim(formData("HiddenPId$CountRow")) . "' AND encounter = '" . trim(formData("HiddenEncounter$CountRow")) . "'");
204 sqlStatement("insert into ar_activity set " .
205 "pid = '" . trim(formData("HiddenPId$CountRow")) .
206 "', encounter = '" . trim(formData("HiddenEncounter$CountRow")) .
207 "', sequence_no = '" . add_escape_custom($sequence_no['increment']) .
208 "', code_type = '" . trim(formData("HiddenCodetype$CountRow")) .
209 "', code = '" . trim(formData("HiddenCode$CountRow")) .
210 "', modifier = '" . trim(formData("HiddenModifier$CountRow")) .
211 "', payer_type = '" . trim(formData("HiddenIns$CountRow")) .
212 "', post_time = '" . trim(add_escape_custom($created_time)) .
213 "', post_user = '" . trim(add_escape_custom($user_id)) .
214 "', session_id = '" . trim(formData('payment_id')) .
215 "', modified_time = '" . trim(add_escape_custom($created_time)) .
216 "', pay_amount = '" . 0 .
217 "', adj_amount = '" . trim(formData("AdjAmount$CountRow")) .
218 "', memo = '" . add_escape_custom($AdjustString) .
219 "', account_code = '" . add_escape_custom($AccountCode) .
220 "'");
221 sqlCommitTrans();
222 } else {
223 sqlStatement("update ar_activity set deleted = NOW() $where");
226 //==============================================================================================================================
228 $where = "$where1 AND (memo LIKE 'Deductable%' OR memo LIKE 'Deductible%')";
229 if (!empty($_POST["Deductible$CountRow"])) {
230 $resPayment = sqlStatement("SELECT * from ar_activity $where");
231 if (sqlNumRows($resPayment) > 0) {
232 sqlStatement("update ar_activity set deleted = NOW() $where");
234 sqlBeginTrans();
235 $sequence_no = sqlQuery("SELECT IFNULL(MAX(sequence_no),0) + 1 AS increment FROM ar_activity WHERE pid = '" . trim(formData("HiddenPId$CountRow")) . "' AND encounter = '" . trim(formData("HiddenEncounter$CountRow")) . "'");
236 sqlStatement("insert into ar_activity set " .
237 "pid = '" . trim(formData("HiddenPId$CountRow")) .
238 "', encounter = '" . trim(formData("HiddenEncounter$CountRow")) .
239 "', sequence_no = '" . add_escape_custom($sequence_no['increment']) .
240 "', code_type = '" . trim(formData("HiddenCodetype$CountRow")) .
241 "', code = '" . trim(formData("HiddenCode$CountRow")) .
242 "', modifier = '" . trim(formData("HiddenModifier$CountRow")) .
243 "', payer_type = '" . trim(formData("HiddenIns$CountRow")) .
244 "', post_time = '" . trim(add_escape_custom($created_time)) .
245 "', post_user = '" . trim(add_escape_custom($user_id)) .
246 "', session_id = '" . trim(formData('payment_id')) .
247 "', modified_time = '" . trim(add_escape_custom($created_time)) .
248 "', pay_amount = '" . 0 .
249 "', adj_amount = '" . 0 .
250 "', memo = '" . "Deductible $" . trim(formData("Deductible$CountRow")) .
251 "', account_code = '" . "Deduct" .
252 "'");
253 sqlCommitTrans();
254 } else {
255 sqlStatement("delete from ar_activity $where");
258 //==============================================================================================================================
260 $where = "$where1 AND pay_amount < 0";
261 if (!empty($_POST["Takeback$CountRow"])) {
262 $resPayment = sqlStatement("SELECT * from ar_activity $where");
263 if (sqlNumRows($resPayment) > 0) {
264 sqlStatement("update ar_activity set deleted = NOW() $where");
266 sqlBeginTrans();
267 $sequence_no = sqlQuery("SELECT IFNULL(MAX(sequence_no),0) + 1 AS increment FROM ar_activity WHERE pid = '" . trim(formData("HiddenPId$CountRow")) . "' AND encounter = '" . trim(formData("HiddenEncounter$CountRow")) . "'");
268 sqlStatement("insert into ar_activity set " .
269 "pid = '" . trim(formData("HiddenPId$CountRow")) .
270 "', encounter = '" . trim(formData("HiddenEncounter$CountRow")) .
271 "', sequence_no = '" . add_escape_custom($sequence_no['increment']) .
272 "', code_type = '" . trim(formData("HiddenCodetype$CountRow")) .
273 "', code = '" . trim(formData("HiddenCode$CountRow")) .
274 "', modifier = '" . trim(formData("HiddenModifier$CountRow")) .
275 "', payer_type = '" . trim(formData("HiddenIns$CountRow")) .
276 "', post_time = '" . trim(add_escape_custom($created_time)) .
277 "', post_user = '" . trim(add_escape_custom($user_id)) .
278 "', session_id = '" . trim(formData('payment_id')) .
279 "', modified_time = '" . trim(add_escape_custom($created_time)) .
280 "', pay_amount = '" . trim(formData("Takeback$CountRow")) * -1 .
281 "', adj_amount = '" . 0 .
282 "', account_code = '" . "Takeback" .
283 "'");
284 sqlCommitTrans();
285 } else {
286 sqlStatement("delete from ar_activity $where");
289 //==============================================================================================================================
291 $where = "$where1 AND follow_up = 'y'";
292 if (isset($_POST["FollowUp$CountRow"]) && $_POST["FollowUp$CountRow"] == 'y') {
293 $resPayment = sqlStatement("SELECT * from ar_activity $where");
294 if (sqlNumRows($resPayment) > 0) {
295 sqlStatement("update ar_activity set deleted = NOW() $where");
297 sqlBeginTrans();
298 $sequence_no = sqlQuery("SELECT IFNULL(MAX(sequence_no),0) + 1 AS increment FROM ar_activity WHERE pid = '" . trim(formData("HiddenPId$CountRow")) . "' AND encounter = '" . trim(formData("HiddenEncounter$CountRow")) . "'");
299 sqlStatement("insert into ar_activity set " .
300 "pid = '" . trim(formData("HiddenPId$CountRow")) .
301 "', encounter = '" . trim(formData("HiddenEncounter$CountRow")) .
302 "', sequence_no = '" . add_escape_custom($sequence_no['increment']) .
303 "', code_type = '" . trim(formData("HiddenCodetype$CountRow")) .
304 "', code = '" . trim(formData("HiddenCode$CountRow")) .
305 "', modifier = '" . trim(formData("HiddenModifier$CountRow")) .
306 "', payer_type = '" . trim(formData("HiddenIns$CountRow")) .
307 "', post_time = '" . trim(add_escape_custom($created_time)) .
308 "', post_user = '" . trim(add_escape_custom($user_id)) .
309 "', session_id = '" . trim(formData('payment_id')) .
310 "', modified_time = '" . trim(add_escape_custom($created_time)) .
311 "', pay_amount = '" . 0 .
312 "', adj_amount = '" . 0 .
313 "', follow_up = '" . "y" .
314 "', follow_up_note = '" . trim(formData("FollowUpReason$CountRow")) .
315 "'");
316 sqlCommitTrans();
317 } else {
318 sqlStatement("delete from ar_activity $where");
321 //==============================================================================================================================
322 } else {
323 break;
327 //=========
328 //INSERTION of new entries,continuation of modification.
329 //=========
330 for ($CountRow = $CountIndexAbove + 1; $CountRow <= $CountIndexAbove + $CountIndexBelow; $CountRow++) {
331 if (isset($_POST["HiddenEncounter$CountRow"])) {
332 DistributionInsert($CountRow, $created_time, $user_id);
333 } else {
334 break;
338 if ($_REQUEST['global_amount'] == 'yes') {
339 sqlStatement(
340 "update ar_session set global_amount=? where session_id =?",
341 [(isset($_POST["HidUnappliedAmount"]) ? floatval($_POST["HidUnappliedAmount"]) : 0), $payment_id]
343 } elseif ($_REQUEST['global_reset'] == '-0.00') {
344 sqlStatement("update ar_session set global_amount=? where session_id =?", [0, $payment_id]);
347 if ($_POST["mode"] == "FinishPayments") {
348 $Message = 'Finish';
351 $_POST["mode"] = "searchdatabase";
352 $Message = 'Modify';
356 //==============================================================================
357 //Search Code
358 //===============================================================================
359 $payment_id = !empty($payment_id) ? (int) $payment_id : (int) $_REQUEST['payment_id'];
360 $ResultSearchSub = sqlStatement(
361 "SELECT DISTINCT encounter, code_type, code, modifier, pid " .
362 "FROM ar_activity WHERE deleted IS NULL AND session_id = ? " .
363 "ORDER BY pid, encounter, code, modifier",
364 [$payment_id]
367 //==============================================================================
369 //==============================================================================
370 //===============================================================================
372 <!DOCTYPE html>
373 <html>
374 <head>
375 <title><?php echo xlt('Confirm Payment'); ?></title>
376 <?php Header::setupHeader(['datetime-picker', 'common']); ?>
378 <script>
379 const mypcc = '1';
380 </script>
381 <?php include_once("{$GLOBALS['srcdir']}/payment_jav.inc.php"); ?>
382 <?php include_once("{$GLOBALS['srcdir']}/ajax/payment_ajax_jav.inc.php"); ?>
383 <script>
384 function ModifyPayments() {//Used while modifying the allocation
385 if (!FormValidations())//FormValidations contains the form checks
387 return false;
389 if (CompletlyBlankAbove())//The distribution rows already in the database are checked.
391 alert(<?php echo xlj('None of the Top Distribution Row Can be Completly Blank.'); ?> +"\n" + <?php echo xlj('Use Delete Option to Remove.'); ?>);
392 return false;
394 if (!CheckPayingEntityAndDistributionPostFor()) {
395 //Ensures that Insurance payment is distributed under Ins1,Ins2,Ins3 and Patient paymentat under Pat.
396 return false;
398 if (CompletlyBlankBelow()) {
399 //The newly added distribution rows are checked.
400 alert(<?php echo xlj('Fill any of the Below Row.'); ?>);
401 return false;
403 let PostValue = CheckUnappliedAmount();//Decides TdUnappliedAmount >0, or <0 or =0
404 if (PostValue == 1) {
405 alert(<?php echo xlj('Cannot Modify Payments.Undistributed is Negative.'); ?>);
406 return false;
408 dialog.confirm(<?php echo xlj('Would you like to Modify Payments?'); ?>).then(returned => {
409 if (returned === true) {
410 document.getElementById('mode').value = 'ModifyPayments';
411 top.restoreSession();
412 document.forms[0].submit();
413 } else {
414 dialog.close();
415 return false;
420 function FinishPayments() {
421 if (!FormValidations())//FormValidations contains the form checks
423 return false;
425 if (CompletlyBlankAbove())//The distribution rows already in the database are checked.
427 alert(<?php echo xlj('None of the Top Distribution Row Can be Completly Blank.'); ?> +"\n" + <?php echo xlj('Use Delete Option to Remove.'); ?>);
428 return false;
430 if (!CheckPayingEntityAndDistributionPostFor())//Ensures that Insurance payment is distributed under Ins1,Ins2,Ins3 and Patient paymentat under Pat.
432 return false;
434 if (CompletlyBlankBelow())//The newly added distribution rows are checked.
436 alert(<?php echo xlj('Fill any of the Below Row.'); ?>);
437 return false;
439 let PostValue = CheckUnappliedAmount();//Decides TdUnappliedAmount >0, or <0 or =0
440 if (PostValue == 1) {
441 alert(<?php echo xlj('Cannot Modify Payments.Undistributed is Negative.'); ?>);
442 return false;
444 if (PostValue == 2) {
445 if (confirm(<?php echo xlj('Would you like to Modify and Finish Payments?'); ?>)) {
446 UnappliedAmount = document.getElementById('TdUnappliedAmount').innerHTML * 1;
447 if (confirm(<?php echo xlj('Undistributed is'); ?> +' ' + UnappliedAmount + '.' + '\n' + <?php echo xlj('Would you like the balance amount to apply to Global Account?'); ?>)) {
448 document.getElementById('mode').value = 'FinishPayments';
449 document.getElementById('global_amount').value = 'yes';
450 top.restoreSession();
451 document.forms[0].submit();
452 } else {
453 document.getElementById('mode').value = 'FinishPayments';
454 top.restoreSession();
455 document.forms[0].submit();
457 } else
458 return false;
459 } else {
460 if (confirm(<?php echo xlj('Would you like to Modify and Finish Payments?'); ?>)) {
461 document.getElementById('mode').value = 'FinishPayments';
462 top.restoreSession();
463 document.forms[0].submit();
464 } else
465 return false;
470 function CompletlyBlankAbove() {//The distribution rows already in the database are checked.
471 //It is not allowed to be made completly empty.If needed delete option need to be used.
472 let CountIndexAbove = document.getElementById('CountIndexAbove').value * 1;
473 for (RowCount = 1; RowCount <= CountIndexAbove; RowCount++) {
474 if (document.getElementById('Allowed' + RowCount).value == '' && document.getElementById('Payment' + RowCount).value == '' && document.getElementById('AdjAmount' + RowCount).value == '' && document.getElementById('Deductible' + RowCount).value == '' && document.getElementById('Takeback' + RowCount).value == '' && document.getElementById('FollowUp' + RowCount).checked == false) {
475 return true;
478 return false;
481 function CompletlyBlankBelow() {//The newly added distribution rows are checked.
482 //It is not allowed to be made completly empty.
483 let CountIndexAbove = document.getElementById('CountIndexAbove').value * 1;
484 let CountIndexBelow = document.getElementById('CountIndexBelow').value * 1;
485 if (CountIndexBelow == 0)
486 return false;
487 for (RowCount = CountIndexAbove + 1; RowCount <= CountIndexAbove + CountIndexBelow; RowCount++) {
488 if (document.getElementById('Allowed' + RowCount).value == '' && document.getElementById('Payment' + RowCount).value == '' && document.getElementById('AdjAmount' + RowCount).value == '' && document.getElementById('Deductible' + RowCount).value == '' && document.getElementById('Takeback' + RowCount).value == '' && document.getElementById('FollowUp' + RowCount).checked == false) {
490 } else
491 return false;
493 return true;
496 function OnloadAction() {//Displays message while loading after some action.
497 let after_value = document.getElementById('ActionStatus').value;
498 if (after_value == 'Delete') {
499 alert(<?php echo xlj('Successfully Deleted'); ?>);
500 return true;
502 if (after_value == 'Modify' || after_value == 'Finish') {
503 alert(<?php echo xlj('Successfully Modified'); ?>);
504 return true;
506 after_value = document.getElementById('after_value').value;
507 let payment_id = document.getElementById('payment_id').value;
508 if (after_value == 'distribute') {
509 } else if (after_value == 'new_payment') {
510 if (document.getElementById('TablePatientPortion')) {
511 document.getElementById('TablePatientPortion').style.display = 'none';
513 if (confirm(<?php echo xlj('Successfully Saved.Would you like to Distribute?'); ?>)) {
514 if (document.getElementById('TablePatientPortion')) {
515 document.getElementById('TablePatientPortion').style.display = '';
522 function DeletePaymentDistribution(DeleteId) {//Confirms deletion of payment distribution.
523 if (confirm(<?php echo xlj('Would you like to Delete Payment Distribution?'); ?>)) {
524 document.getElementById('mode').value = 'DeletePaymentDistribution';
525 document.getElementById('DeletePaymentDistributionId').value = DeleteId;
526 top.restoreSession();
527 document.forms[0].submit();
528 } else
529 return false;
532 //========================================================================================
534 $(function () {
535 $('.datepicker').datetimepicker({
536 <?php $datetimepicker_timepicker = false; ?>
537 <?php $datetimepicker_showseconds = false; ?>
538 <?php $datetimepicker_formatInput = true; ?>
539 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
540 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
544 document.onclick = HideTheAjaxDivs;
545 </script>
546 <style>
547 .amt_input {
548 max-width: 75px;
550 .bottom {
551 border-bottom: 1px solid var(--black);
554 .top {
555 border-top: 1px solid var(--black);
558 .left {
559 border-left: 1px solid var(--black);
562 .right {
563 border-right: 1px solid var(--black);
566 .form-group {
567 margin-bottom: 5px;
570 legend {
571 border-bottom: 2px solid #E5E5E5;
572 background: #E5E5E5;
573 padding-left: 10px;
576 .form-horizontal .control-label {
577 padding-top: 2px;
580 fieldset {
581 border-color: #68171A !important;
582 background-color: #f2f2f2;
583 margin-bottom: 10px;
584 padding-bottom: 15px;
587 @media only screen and (max-width: 768px) {
588 [class*="col-"] {
589 width: 100%;
590 text-align: left !important;
593 </style>
594 <?php Header::setupHeader(['datetime-picker', 'common']); ?>
595 </head>
596 <body class="body_top" onload="OnloadAction()">
597 <div class="container-fluid">
598 <?php
599 if ($_REQUEST['ParentPage'] ?? '' == 'new_payment') {
601 <div class="row">
602 <div class="col-12">
603 <h2><?php echo xlt('Payments'); ?></h2>
604 </div>
605 </div>
606 <div class="row">
607 <div class="col-sm-12">
608 <nav class="navbar navbar-nav navbar-expand-md navbar-light text-body bg-light static-top">
609 <button class="navbar-toggler icon-bar" data-target="#myNavbar" data-toggle="collapse" type="button"><span class="navbar-toggler-icon"></span></button>
610 <div class="collapse navbar-collapse" id="myNavbar">
611 <ul class="navbar-nav mr-auto">
612 <li class="nav-item active">
613 <a class="nav-link font-weight-bold" href='new_payment.php'><?php echo xlt('New Payment'); ?></a>
614 </li>
615 <li class="nav-item">
616 <a class="nav-link font-weight-bold" href='search_payments.php'><?php echo xlt('Search Payment'); ?></a>
617 </li>
618 <li class="nav-item">
619 <a class="nav-link font-weight-bold" href='era_payments.php'><?php echo xlt('ERA Posting'); ?></a>
620 </li>
621 </ul>
622 </div>
623 </nav>
624 </div>
625 </div>
626 <?php
629 <?php
630 if (empty($payment_id)) {
631 $onclick = "top.restoreSession();return SavePayment();";
632 } else {
633 $onclick = "return false;";
636 <form class="form" name='new_payment' method='post' action="edit_payment.php" onsubmit='<?php echo $onclick; ?>'>
637 <?php
638 if (!empty($payment_id)) { ?>
639 <fieldset>
640 <?php
641 require_once("payment_master.inc.php"); //Check/cash details are entered here.
643 <?php }//End of if($payment_id*1>0) ?>
644 <?php
645 if (!empty($payment_id)) {//Distribution rows already in the database are displayed.
647 <?php //
648 $resCount = sqlStatement(
649 "SELECT DISTINCT encounter, code_type, code, modifier FROM ar_activity " .
650 "WHERE deleted IS NULL AND session_id = ?",
651 [$payment_id]
653 $TotalRows = sqlNumRows($resCount);
654 $CountPatient = 0;
655 $CountIndex = 0;
656 $CountIndexAbove = 0;
657 $paymenttot = 0;
658 $adjamttot = 0;
659 $deductibletot = 0;
660 $takebacktot = 0;
661 $allowedtot = 0;
662 if ($RowSearchSub = sqlFetchArray($ResultSearchSub)) {
663 do {
664 $CountPatient++;
665 $PId = $RowSearchSub['pid'];
666 $EncounterMaster = $RowSearchSub['encounter'];
667 // Only use the code_type in the queries below if it is specified in the ar_activity table.
668 // If it is not specified in the ar_activity table, also note it is not requested from the
669 // billing table in below query, thus making it blank in all queries below in this script.
670 $CodetypeMaster = $RowSearchSub['code_type'];
671 $sql_select_part_codetype = "";
672 $sql_where_part_codetype = "";
673 if (!empty($CodetypeMaster)) {
674 $sql_select_part_codetype = "billing.code_type,";
675 $sql_where_part_codetype = "and billing.code_type ='" . add_escape_custom($CodetypeMaster) . "'";
677 $CodeMaster = $RowSearchSub['code'];
678 $ModifierMaster = $RowSearchSub['modifier'];
679 $res = sqlStatement("SELECT fname,lname,mname FROM patient_data where pid =?", [$PId]);
680 $row = sqlFetchArray($res);
681 $fname = $row['fname'];
682 $lname = $row['lname'];
683 $mname = $row['mname'];
684 $NameDB = $lname . ' ' . $fname . ' ' . $mname;
685 $ResultSearch = sqlStatement("SELECT billing.id,last_level_closed,billing.encounter,form_encounter.`date`,$sql_select_part_codetype billing.code,billing.modifier,fee
686 FROM billing ,form_encounter
687 where billing.encounter=form_encounter.encounter and billing.pid=form_encounter.pid and
688 code_type !='ICD9' and code_type !='COPAY' and billing.activity !=0 and
689 form_encounter.pid ='" . add_escape_custom($PId) . "' and billing.pid ='" . add_escape_custom($PId) . "' and billing.encounter ='" . add_escape_custom($EncounterMaster) . "'
690 $sql_where_part_codetype
691 and billing.code ='" . add_escape_custom($CodeMaster) . "'
692 and billing.modifier ='" . add_escape_custom($ModifierMaster) . "'
693 ORDER BY form_encounter.`date`,form_encounter.encounter,billing.code,billing.modifier");
694 if (sqlNumRows($ResultSearch) > 0) {
695 if ($CountPatient === 1) {
696 $Table = 'yes';
698 <br /><br />
699 <div class="row" id="tableRow">
700 <legend><?php echo xlt("Distributed Edits") ?></legend>
701 <div class="table-responsive-lg">
702 <table class="table table-sm table-bordered table-light" id="TableDistributedEdit" >
703 <thead class="bg-dark text-light">
704 <tr>
705 <th>&nbsp;</th>
706 <th><?php echo xlt('Patient Name'); ?></th>
707 <th><?php echo xlt('Post For'); ?></th>
708 <th><?php echo xlt('Service Date'); ?></th>
709 <th><?php echo xlt('Enc#'); ?></th>
710 <th><?php echo xlt('Code'); ?></th>
711 <th><?php echo xlt('Charge'); ?></th>
712 <th><?php echo xlt('Copay'); ?></th>
713 <th><?php echo xlt('Bal-Due'); ?></th>
714 <th><?php echo xlt('Allowed(c)'); ?></th><!-- (c) means it is calculated.Not stored one. -->
715 <th><?php echo xlt('Payment'); ?></th>
716 <th><?php echo xlt('Adj Amount'); ?></th>
717 <th><?php echo xlt('Deductible'); ?></th>
718 <th><?php echo xlt('Takeback'); ?></th>
719 <th><?php echo xlt('MSP'); ?></th>
720 <th><?php echo xlt('Resn'); ?></th>
721 <th><?php echo xlt('Follow Up Reason'); ?></th>
722 </tr>
723 </thead>
724 <?php }
725 while ($RowSearch = sqlFetchArray($ResultSearch)) {
726 $CountIndex++;
727 $CountIndexAbove++;
728 $ServiceDateArray = explode(' ', $RowSearch['date']);
729 $ServiceDate = oeFormatShortDate($ServiceDateArray[0]);
730 $Codetype = $RowSearch['code_type'];
731 $Code = $RowSearch['code'];
732 $Modifier = $RowSearch['modifier'];
733 if ($Modifier != '') {
734 $ModifierString = ", $Modifier";
735 } else {
736 $ModifierString = "";
738 $Fee = $RowSearch['fee'];
739 $Encounter = $RowSearch['encounter'];
741 $resPayer = sqlStatement(
742 "SELECT payer_type FROM ar_activity WHERE " .
743 "deleted IS NULL AND session_id = ? AND pid = ? AND encounter = ? " .
744 "AND code_type = ? AND code = ? AND modifier = ?",
745 [$payment_id, $PId, $Encounter, $Codetype, $Code, $Modifier]
747 $rowPayer = sqlFetchArray($resPayer);
748 $Ins = $rowPayer['payer_type'];
750 //Always associating the copay to a particular charge.
751 $BillingId = $RowSearch['id'];
752 $resId = sqlStatement("SELECT id FROM billing where code_type != 'ICD9' and code_type != 'COPAY' and
753 pid =? and encounter =? and billing.activity!=0 order by id", [$PId, $Encounter]);
754 $rowId = sqlFetchArray($resId);
755 $Id = $rowId['id'];
757 if ($BillingId != $Id) {//multiple cpt in single encounter
758 $Copay = 0.00;
759 } else {
760 $resCopay = sqlStatement("SELECT sum(fee) as copay FROM billing where
761 code_type='COPAY' and pid =? and encounter =? and billing.activity!=0", [$PId, $Encounter]);
762 $rowCopay = sqlFetchArray($resCopay);
763 $Copay = $rowCopay['copay'] * -1;
765 $resMoneyGot = sqlStatement(
766 "SELECT sum(pay_amount) AS PatientPay FROM ar_activity WHERE " .
767 "deleted IS NULL AND pid = ? and encounter = ? AND " .
768 "payer_type = 0 AND account_code = 'PCP'",
769 [$PId, $Encounter]
770 ); //new fees screen copay gives account_code='PCP'
771 $rowMoneyGot = sqlFetchArray($resMoneyGot);
772 $PatientPay = $rowMoneyGot['PatientPay'];
774 $Copay = $Copay + $PatientPay;
777 //For calculating Remainder
778 if ($Ins == 0) {//Fetch all values
779 $resMoneyGot = sqlStatement(
780 "SELECT sum(pay_amount) as MoneyGot FROM ar_activity WHERE " .
781 "deleted IS NULL AND pid = ? and code_type = ? AND code = ? AND " .
782 "modifier = ? AND encounter = ? AND " .
783 "!(payer_type = 0 AND account_code = 'PCP')",
784 [$PId, $Codetype, $Code, $Modifier, $Encounter]
786 //new fees screen copay gives account_code='PCP'
787 $rowMoneyGot = sqlFetchArray($resMoneyGot);
788 $MoneyGot = $rowMoneyGot['MoneyGot'];
790 $resMoneyAdjusted = sqlStatement(
791 "SELECT sum(adj_amount) AS MoneyAdjusted FROM ar_activity WHERE " .
792 "deleted IS NULL AND pid = ? and code_type = ? and code = ? AND " .
793 "modifier = ? AND encounter = ?",
794 [$PId, $Codetype, $Code, $Modifier, $Encounter]
796 $rowMoneyAdjusted = sqlFetchArray($resMoneyAdjusted);
797 $MoneyAdjusted = $rowMoneyAdjusted['MoneyAdjusted'];
798 } else {
799 //Fetch till that much got
800 //Fetch the HIGHEST sequence_no till this session.
801 //Used maily in the case if primary/others pays once more.
802 $resSequence = sqlStatement("SELECT sequence_no from ar_activity where session_id=? and
803 pid=? and encounter=? order by sequence_no desc ", [$payment_id, $PId, $Encounter]);
804 $rowSequence = sqlFetchArray($resSequence);
805 $Sequence = $rowSequence['sequence_no'];
807 $resMoneyGot = sqlStatement(
808 "SELECT sum(pay_amount) as MoneyGot FROM ar_activity WHERE " .
809 "deleted IS NULL AND pid = ? and code_type = ? AND code = ? AND " .
810 "modifier = ? and encounter = ? AND " .
811 "payer_type > 0 and payer_type <= ? and sequence_no <= ?",
812 [$PId, $Codetype, $Code, $Modifier, $Encounter, $Ins, $Sequence]
814 $rowMoneyGot = sqlFetchArray($resMoneyGot);
815 $MoneyGot = $rowMoneyGot['MoneyGot'];
817 $resMoneyAdjusted = sqlStatement(
818 "SELECT sum(adj_amount) AS MoneyAdjusted FROM ar_activity WHERE " .
819 "deleted IS NULL AND pid = ? and code_type = ? and code = ? AND " .
820 "modifier = ? AND encounter = ? AND payer_type > 0 AND " .
821 "payer_type <= ? and sequence_no <= ?",
822 [$PId, $Codetype, $Code, $Modifier, $Encounter, $Ins, $Sequence]
824 $rowMoneyAdjusted = sqlFetchArray($resMoneyAdjusted);
825 $MoneyAdjusted = $rowMoneyAdjusted['MoneyAdjusted'];
827 $Remainder = $Fee - $Copay - $MoneyGot - $MoneyAdjusted;
828 //For calculating RemainderJS.Used while restoring back the values.
829 if ($Ins == 0) {//Got just before Patient
830 $resMoneyGot = sqlStatement(
831 "SELECT sum(pay_amount) AS MoneyGot FROM ar_activity WHERE " .
832 "deleted IS NULL AND pid = ? AND code_type = ? AND code = ? AND " .
833 "modifier = ? AND encounter = ? and payer_type != 0",
834 [$PId, $Codetype, $Code, $Modifier, $Encounter]
836 $rowMoneyGot = sqlFetchArray($resMoneyGot);
837 $MoneyGot = $rowMoneyGot['MoneyGot'];
839 $resMoneyAdjusted = sqlStatement(
840 "SELECT sum(adj_amount) AS MoneyAdjusted FROM ar_activity WHERE " .
841 "deleted IS NULL AND pid = ? AND code_type = ? AND code = ? AND " .
842 "modifier = ? and encounter = ? and payer_type != 0",
843 [$PId, $Codetype, $Code, $Modifier, $Encounter]
845 $rowMoneyAdjusted = sqlFetchArray($resMoneyAdjusted);
846 $MoneyAdjusted = $rowMoneyAdjusted['MoneyAdjusted'];
847 } else {
848 //Got just before the previous
849 //Fetch the LOWEST sequence_no till this session.
850 //Used maily in the case if primary/others pays once more.
851 $resSequence = sqlStatement(
852 "SELECT sequence_no FROM ar_activity WHERE " .
853 "session_id = ? AND deleted IS NULL AND pid = ? AND encounter = ? " .
854 "order by sequence_no",
855 [$payment_id, $PId, $Encounter]
857 $rowSequence = sqlFetchArray($resSequence);
858 $Sequence = $rowSequence['sequence_no'];
860 $resMoneyGot = sqlStatement(
861 "SELECT sum(pay_amount) as MoneyGot FROM ar_activity WHERE " .
862 "deleted IS NULL AND pid = ? AND code_type = ? AND code = ? " .
863 "AND modifier = ? AND encounter = ? AND payer_type > 0 AND " .
864 "payer_type <= ? AND sequence_no < ?",
865 [$PId, $Codetype, $Code, $Modifier, $Encounter, $Ins, $Sequence]
867 $rowMoneyGot = sqlFetchArray($resMoneyGot);
868 $MoneyGot = $rowMoneyGot['MoneyGot'];
870 $resMoneyAdjusted = sqlStatement(
871 "SELECT sum(adj_amount) as MoneyAdjusted FROM ar_activity WHERE " .
872 "deleted IS NULL AND pid = ? and code_type = ? and code = ? AND " .
873 "modifier = ? AND encounter = ? AND payer_type <= ? AND sequence_no < ?",
874 [$PId, $Codetype, $Code, $Modifier, $Encounter, $Ins, $Sequence]
876 $rowMoneyAdjusted = sqlFetchArray($resMoneyAdjusted);
877 $MoneyAdjusted = $rowMoneyAdjusted['MoneyAdjusted'];
879 //Stored in hidden so that can be used while restoring back the values.
880 $RemainderJS = $Fee - $Copay - $MoneyGot - $MoneyAdjusted;
882 $resPayment = sqlStatement(
883 "SELECT pay_amount FROM ar_activity WHERE " .
884 "deleted IS NULL AND session_id=? AND pid = ? AND encounter = ? AND " .
885 "code_type = ? AND code = ? AND modifier = ? AND pay_amount > 0",
886 [$payment_id, $PId, $Encounter, $Codetype, $Code, $Modifier]
888 $rowPayment = sqlFetchArray($resPayment);
889 $PaymentDB = floatval($rowPayment['pay_amount'] ?? null);
891 $resPayment = sqlStatement(
892 "SELECT pay_amount FROM ar_activity WHERE " .
893 "deleted IS NULL AND session_id = ? AND pid = ? AND encounter = ? AND " .
894 "code_type = ? AND code = ? AND modifier = ? AND pay_amount < 0",
895 [$payment_id, $PId, $Encounter, $Codetype, $Code, $Modifier]
897 $rowPayment = sqlFetchArray($resPayment);
898 $TakebackDB = floatval($rowPayment['pay_amount'] ?? null);
900 $resPayment = sqlStatement(
901 "SELECT adj_amount FROM ar_activity WHERE " .
902 "deleted IS NULL AND session_id = ? AND pid = ? AND encounter = ? AND " .
903 "code_type = ? AND code = ? AND modifier = ? AND adj_amount != 0",
904 [$payment_id, $PId, $Encounter, $Codetype, $Code, $Modifier]
906 $rowPayment = sqlFetchArray($resPayment);
907 $AdjAmountDB = floatval($rowPayment['adj_amount'] ?? null);
909 $resPayment = sqlStatement(
910 "SELECT memo FROM ar_activity WHERE " .
911 "deleted IS NULL AND session_id = ? AND pid = ? AND encounter = ? AND " .
912 "code_type = ? AND code = ? AND modifier = ? AND " .
913 "(memo LIKE 'Deductable%' OR memo LIKE 'Deductible%')",
914 [$payment_id, $PId, $Encounter, $Codetype, $Code, $Modifier]
916 $rowPayment = sqlFetchArray($resPayment);
917 $DeductibleDB = $rowPayment['memo'] ?? '';
918 $DeductibleDB = str_replace('Deductable $', '', $DeductibleDB);
919 $DeductibleDB = str_replace('Deductible $', '', $DeductibleDB);
921 $resPayment = sqlStatement(
922 "SELECT follow_up, follow_up_note FROM ar_activity WHERE " .
923 "deleted IS NULL AND session_id = ? AND pid = ? AND encounter = ? AND " .
924 "code_type = ? AND code = ? AND modifier = ? AND follow_up = 'y'",
925 [$payment_id, $PId, $Encounter, $Codetype, $Code, $Modifier]
927 $rowPayment = sqlFetchArray($resPayment);
928 $FollowUpDB = $rowPayment['follow_up'] ?? '';
929 $FollowUpReasonDB = $rowPayment['follow_up_note'] ?? '';
931 $resPayment = sqlStatement(
932 "SELECT reason_code FROM ar_activity WHERE " .
933 "deleted IS NULL AND session_id = ? AND pid = ? AND encounter = ? AND " .
934 "code_type = ? AND code = ? AND modifier = ?",
935 [$payment_id, $PId, $Encounter, $Codetype, $Code, $Modifier]
937 $rowPayment = sqlFetchArray($resPayment);
938 $ReasonCodeDB = $rowPayment['reason_code'];
940 if ($Ins == 1) {
941 $AllowedDB = number_format($Fee - floatval($AdjAmountDB), 2);
942 } else {
943 $AllowedDB = 0;
946 if ($Ins == 1) {
947 $bgcolor = '#ddddff';
948 } elseif ($Ins == 2) {
949 $bgcolor = '#ffdddd';
950 } elseif ($Ins == 3) {
951 $bgcolor = '#F2F1BC';
952 } elseif ($Ins == 0) {
953 $bgcolor = '#AAFFFF';
955 $paymenttot = $paymenttot + floatval($PaymentDB);
956 $adjamttot = $adjamttot + floatval($AdjAmountDB);
957 $deductibletot = $deductibletot + floatval($DeductibleDB);
958 $takebacktot = $takebacktot + floatval($TakebackDB);
959 $allowedtot = $allowedtot + floatval($AllowedDB);
962 <tr class="border-dark" bgcolor='<?php echo attr($bgcolor); ?>' class="text" id="trCharges<?php echo attr($CountIndex); ?>">
963 <td align="left">
964 <a href="#" onclick="javascript:return DeletePaymentDistribution(<?php echo attr_js($payment_id . '_' . $PId . '_' . $Encounter . '_' . $Code . '_' . $Modifier . '_' . $Codetype); ?>);"><img border="0" src="../pic/Delete.gif"></a>
965 </td>
966 <td align="left">
967 <?php echo text($NameDB); ?><input name="HiddenPId<?php echo attr($CountIndex); ?>" type="hidden" value="<?php echo attr($PId); ?>" />
968 </td>
969 <td align="left">
970 <input id="HiddenIns<?php echo attr($CountIndex); ?>" name="HiddenIns<?php echo attr($CountIndex); ?>" type="hidden" value="<?php echo attr($Ins); ?>" /><?php echo generate_select_list("payment_ins$CountIndex", "payment_ins", "$Ins", "Insurance/Patient", '', 'w-100', 'ActionOnInsPat("' . $CountIndex . '")'); ?>
971 </td>
972 <td>
973 <?php echo text($ServiceDate); ?>
974 </td>
975 <td align="right">
976 <input name="HiddenEncounter<?php echo attr($CountIndex); ?>" type="hidden" value="<?php echo attr($Encounter); ?>" /><?php echo text($Encounter); ?>
977 </td>
978 <td>
979 <input name="HiddenCodetype<?php echo attr($CountIndex); ?>" type="hidden" value="<?php echo attr($Codetype); ?>" />
980 <input name="HiddenCode<?php echo attr($CountIndex); ?>" type="hidden" value="<?php echo attr($Code); ?>" /><?php echo text($Codetype . "-" . $Code . $ModifierString); ?>
981 <input name="HiddenModifier<?php echo attr($CountIndex); ?>" type="hidden" value="<?php echo attr($Modifier); ?>" />
982 </td>
983 <td align="right">
984 <input id="HiddenChargeAmount<?php echo attr($CountIndex); ?>" name="HiddenChargeAmount<?php echo attr($CountIndex); ?>" type="hidden" value="<?php echo attr($Fee); ?>" /><?php echo text($Fee); ?>
985 </td>
986 <td align="right">
987 <input id="HiddenCopayAmount<?php echo attr($CountIndex); ?>" name="HiddenCopayAmount<?php echo attr($CountIndex); ?>" type="hidden" value="<?php echo attr($Copay); ?>"><?php echo text(number_format($Copay, 2)); ?>
988 </td>
989 <td align="right" id="RemainderTd<?php echo attr($CountIndex); ?>"> <?php echo text(round($Remainder, 2)); ?> </td>
990 <input name="HiddenRemainderTd<?php echo attr($CountIndex); ?>" id="HiddenRemainderTd<?php echo attr($CountIndex); ?>" value="<?php echo attr(round($Remainder, 2)); ?>" type="hidden" />
991 <td>
992 <input autocomplete="off" id="Allowed<?php echo attr($CountIndex); ?>" name="Allowed<?php echo attr($CountIndex); ?>" onchange="ValidateNumeric(this);ScreenAdjustment(this,<?php echo attr_js($CountIndex); ?>);UpdateTotalValues(1,<?php echo attr_js($TotalRows); ?>,'Allowed','allowtotal');UpdateTotalValues(1,<?php echo attr_js($TotalRows); ?>,'Payment','paymenttotal');UpdateTotalValues(1,<?php echo attr_js($TotalRows); ?>,'AdjAmount','AdjAmounttotal');RestoreValues(<?php echo attr_js($CountIndex); ?>)" onkeydown="PreventIt(event)" class="text-right input-sm w-100" type="text" value="<?php echo attr($AllowedDB); ?>" />
993 </td>
995 <td>
996 <input autocomplete="off" id="Payment<?php echo attr($CountIndex); ?>" name="Payment<?php echo attr($CountIndex); ?>" onchange="ValidateNumeric(this);ScreenAdjustment(this,<?php echo attr_js($CountIndex); ?>);UpdateTotalValues(1,<?php echo attr_js($TotalRows); ?>,'Payment','paymenttotal');RestoreValues(<?php echo attr_js($CountIndex); ?>)" onkeydown="PreventIt(event)" class="text-right input-sm w-100" type="text" value="<?php echo attr($PaymentDB); ?>" />
997 </td>
998 <td>
999 <input autocomplete="off" id="AdjAmount<?php echo attr($CountIndex); ?>" name="AdjAmount<?php echo attr($CountIndex); ?>" onchange="ValidateNumeric(this);ScreenAdjustment(this,<?php echo attr_js($CountIndex); ?>);UpdateTotalValues(1,<?php echo attr_js($TotalRows); ?>,'AdjAmount','AdjAmounttotal');RestoreValues(<?php echo attr_js($CountIndex); ?>)" onkeydown="PreventIt(event)" class="text-right input-sm w-100" type="text" value="<?php echo attr($AdjAmountDB); ?>" />
1000 </td>
1001 <td>
1002 <input autocomplete="off" id="Deductible<?php echo attr($CountIndex); ?>" name="Deductible<?php echo attr($CountIndex); ?>" onchange="ValidateNumeric(this);UpdateTotalValues(1,<?php echo attr_js($TotalRows); ?>,'Deductible','deductibletotal');" onkeydown="PreventIt(event)" class="text-right input-sm w-100" type="text" value="<?php echo attr($DeductibleDB); ?>" />
1003 </td>
1004 <td>
1005 <input autocomplete="off" id="Takeback<?php echo attr($CountIndex); ?>" name="Takeback<?php echo attr($CountIndex); ?>" onchange="ValidateNumeric(this);ScreenAdjustment(this,<?php echo attr_js($CountIndex); ?>);UpdateTotalValues(1,<?php echo attr_js($TotalRows); ?>,'Takeback','takebacktotal');RestoreValues(<?php echo attr_js($CountIndex); ?>)" onkeydown="PreventIt(event)" class="text-right input-sm w-100" type="text" value="<?php echo attr($TakebackDB); ?>" />
1006 </td>
1007 <td align="left">
1008 <input id="HiddenReasonCode<?php echo attr($CountIndex); ?>" name="HiddenReasonCode<?php echo attr($CountIndex); ?>" type="hidden" value="<?php echo attr($ReasonCodeDB); ?>" /><?php echo generate_select_list("ReasonCode$CountIndex", "msp_remit_codes", "$ReasonCodeDB", "MSP", '', 'w-100'); ?>
1009 </td>
1010 <td align="center">
1011 <input id="FollowUp<?php echo attr($CountIndex); ?>" name="FollowUp<?php echo attr($CountIndex); ?>" onclick="ActionFollowUp(<?php echo attr_js($CountIndex); ?>)" type="checkbox" value="y" />
1012 </td>
1013 <td>
1014 <input id="FollowUpReason<?php echo attr($CountIndex); ?>" name="FollowUpReason<?php echo attr($CountIndex); ?>" onkeydown="PreventIt(event)" class=" input-sm w-100" type="text" value="<?php echo attr($FollowUpReasonDB); ?>" readonly>
1015 </td>
1016 </tr><?php
1017 }//End of while ($RowSearch = sqlFetchArray($ResultSearch))
1019 <?php
1020 }//End of if(sqlNumRows($ResultSearch)>0)
1021 } while ($RowSearchSub = sqlFetchArray($ResultSearchSub));
1022 if ($Table == 'yes') { ?>
1023 <tr>
1024 <td class="text-right text-dark" align="left" colspan="9"><b><?php echo (xlt("Totals") . ": ") ?></b></td>
1025 <td class="bg-dark text-secondary" align="center" id="allowtotal"><?php echo text(number_format($allowedtot, 2)); ?></td>
1026 <td class="bg-dark text-secondary" align="center" id="paymenttotal"><?php echo text(number_format($paymenttot, 2)); ?></td>
1027 <td class="bg-dark text-secondary" align="center" id="AdjAmounttotal"><?php echo text(number_format($adjamttot, 2)); ?></td>
1028 <td class="bg-dark text-secondary" align="center" id="deductibletotal"><?php echo text(number_format($deductibletot, 2)); ?></td>
1029 <td class="bg-dark text-secondary" align="center" id="takebacktotal"><?php echo text(number_format($takebacktot, 2)); ?></td>
1030 <td align="center" colspan="2">&nbsp;</td>
1031 <td align="right">
1032 <button type="button" class="btn btn-sm btn-secondary btn-refresh pull-right"
1033 onclick="updateAllFormTotals(<?php echo attr_js($TotalRows); ?>);"><?php echo xlt("Recalculate"); ?></button>
1034 </td>
1035 </tr>
1036 </table>
1037 <?php
1040 <?php
1041 echo '<br/>';
1042 }//End of if($RowSearchSub = sqlFetchArray($ResultSearchSub))
1044 </div>
1045 </div>
1046 <div>
1047 <?php
1048 require_once("payment_pat_sel.inc.php"); //Patient ajax section and listing of charges.
1050 </div>
1051 <?php
1052 }//End of if($payment_id*1>0)
1054 <?php //can change position of buttons by creating a class 'position-override' and adding rule text-align:center or right as the case may be in individual stylesheets ?>
1055 <div class="form-group clearfix">
1056 <div class="col-sm-12 text-left position-override">
1057 <div class="btn-group" role="group">
1058 <a class="btn btn-secondary btn-save" href="#" onclick="return ModifyPayments();"><span><?php echo xlt('Modify Payments'); ?></span></a>
1059 <a class="btn btn-secondary btn-save" href="#" onclick="return FinishPayments();"><span><?php echo xlt('Finish Payments'); ?></span></a>
1060 </div>
1061 </div>
1062 </div>
1063 <div class="row">
1064 <input type="hidden" name="hidden_patient_code" id="hidden_patient_code" value="<?php echo attr($hidden_patient_code ?? ''); ?>" />
1065 <input type='hidden' name='mode' id='mode' value='' />
1066 <input type='hidden' name='ajax_mode' id='ajax_mode' value='' />
1067 <input type="hidden" name="after_value" id="after_value" value="<?php echo attr($_POST["mode"] ?? ''); ?>" />
1068 <input type="hidden" name="payment_id" id="payment_id" value="<?php echo attr($payment_id); ?>" />
1069 <input type="hidden" name="hidden_type_code" id="hidden_type_code" value="<?php echo attr($TypeCode); ?>" />
1070 <input type='hidden' name='global_amount' id='global_amount' value='' />
1071 <input type='hidden' name='DeletePaymentDistributionId' id='DeletePaymentDistributionId' value='' />
1072 <input type="hidden" name="ActionStatus" id="ActionStatus" value="<?php echo attr($Message ?? ''); ?>" />
1073 <input type='hidden' name='CountIndexAbove' id='CountIndexAbove' value='<?php echo (int) attr($CountIndexAbove); ?>' />
1074 <input type='hidden' name='CountIndexBelow' id='CountIndexBelow' value='<?php echo (int) attr($CountIndexBelow); ?>' />
1075 <input type="hidden" name="ParentPage" id="ParentPage" value="<?php echo attr($_REQUEST['ParentPage'] ?? ''); ?>" />
1076 </div>
1077 </form>
1078 </div><!-- End of container div-->
1079 <script>
1080 function ResetForm() {//Resets form used in the 'Cancel Changes' button in the master screen.
1081 document.forms[0].reset();
1082 document.getElementById('TdUnappliedAmount').innerHTML = '0.00';
1083 document.getElementById('div_insurance_or_patient').innerHTML = '&nbsp;';
1084 CheckVisible('yes');//Payment Method is made 'Check Payment' and the Check box is made visible.
1085 PayingEntityAction();//Paying Entity is made 'insurance' and Payment Category is 'Insurance Payment'
1088 $(function () {
1089 if (document.getElementById("TableDistributePortion")) {
1090 $("html").animate({scrollTop: $("#TableDistributePortion").offset().top}, 800);
1091 } else if (document.getElementById("TableDistributedEdit")) {
1092 $("html").animate({scrollTop: $("#TableDistributedEdit").offset().top}, 800);
1095 </script>
1096 </body>
1097 </html>