Fully responsive globals.php with vertical menu (#2460)
[openemr.git] / interface / billing / edit_payment.php
blob6c2c7e24d71257f3103e792eaaaa8b693e81fdf2
1 <?php
2 /*
3 * Payments can be edited here whch includes deletion of an allocation, modifying the
4 * same or adding a new allocation. Log is kept for the deleted ones.
5 * The functions of this class support the billing process like the script billing_process.php.
7 * @package OpenEMR
8 * @link http://www.open-emr.org
9 * @author Eldho Chacko <eldho@zhservices.com>
10 * @author Paul Simon K <paul@zhservices.com>
11 * @author Stephen Waite <stephen.waite@cmsvt.com>
12 * @author Brady Miller <brady.g.miller@gmail.com>
13 * @copyright Copyright (c) Z&H Consultancy Services Private Limited <sam@zhservices.com>
14 * @copyright Copyright (C) 2018 Stephen Waite <stephen.waite@cmsvt.com>
15 * @copyright Copyright (c) 2019 Brady Miller <brady.g.miller@gmail.com>
16 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
20 require_once("../globals.php");
21 require_once("$srcdir/invoice_summary.inc.php");
22 require_once("../../library/acl.inc");
23 require_once("$srcdir/auth.inc");
24 require_once("../../custom/code_types.inc.php");
25 require_once("$srcdir/patient.inc");
26 require_once("$srcdir/billrep.inc");
27 require_once("$srcdir/options.inc.php");
28 require_once("$srcdir/payment.inc.php");
30 use OpenEMR\Core\Header;
32 $screen='edit_payment';
34 // Deletion of payment distribution code
36 if (isset($_POST["mode"])) {
37 if ($_POST["mode"] == "DeletePaymentDistribution") {
38 $DeletePaymentDistributionId=(isset($_POST['DeletePaymentDistributionId']) ? trim($_POST['DeletePaymentDistributionId']) : '');
39 $DeletePaymentDistributionIdArray=explode('_', $DeletePaymentDistributionId);
40 $payment_id=$DeletePaymentDistributionIdArray[0];
41 $PId=$DeletePaymentDistributionIdArray[1];
42 $Encounter=$DeletePaymentDistributionIdArray[2];
43 $Code=$DeletePaymentDistributionIdArray[3];
44 $Modifier=$DeletePaymentDistributionIdArray[4];
45 $Codetype=$DeletePaymentDistributionIdArray[5];
46 //delete and log that action
47 row_delete("ar_activity", "session_id ='" . add_escape_custom($payment_id) . "' and pid ='" . add_escape_custom($PId) . "' AND " .
48 "encounter='" . add_escape_custom($Encounter) . "' and code_type='" . add_escape_custom($Codetype) . "' and code='" . add_escape_custom($Code) . "' and modifier='" . add_escape_custom($Modifier) . "'");
49 $Message='Delete';
50 //------------------
51 $_POST["mode"] = "searchdatabase";
55 //===============================================================================
56 //Modify Payment Code.
57 //===============================================================================
58 if (isset($_POST["mode"])) {
59 if ($_POST["mode"] == "ModifyPayments" || $_POST["mode"] == "FinishPayments") {
60 $payment_id=$_REQUEST['payment_id'];
61 //ar_session Code
62 //===============================================================================
63 if (trim($_POST['type_name'])=='insurance') {
64 $QueryPart="payer_id = '" . trim(formData('hidden_type_code')) .
65 "', patient_id = '" . 0 ;
66 } elseif (trim($_POST['type_name'])=='patient') {
67 $QueryPart="payer_id = '" . 0 .
68 "', patient_id = '" . trim(formData('hidden_type_code')) ;
71 $user_id=$_SESSION['authUserID'];
72 $closed=0;
73 $modified_time = date('Y-m-d H:i:s');
74 $check_date=DateToYYYYMMDD(formData('check_date'));
75 $deposit_date=DateToYYYYMMDD(formData('deposit_date'));
76 $post_to_date=DateToYYYYMMDD(formData('post_to_date'));
77 if ($post_to_date=='') {
78 $post_to_date=date('Y-m-d');
81 if ($_POST['deposit_date']=='') {
82 $deposit_date=$post_to_date;
85 sqlStatement("update ar_session set " .
86 $QueryPart .
87 "', user_id = '" . trim(add_escape_custom($user_id)) .
88 "', closed = '" . trim(add_escape_custom($closed)) .
89 "', reference = '" . trim(formData('check_number')) .
90 "', check_date = '" . trim(add_escape_custom($check_date)) .
91 "', deposit_date = '" . trim(add_escape_custom($deposit_date)) .
92 "', pay_total = '" . trim(formData('payment_amount')) .
93 "', modified_time = '" . trim(add_escape_custom($modified_time)) .
94 "', payment_type = '" . trim(formData('type_name')) .
95 "', description = '" . trim(formData('description')) .
96 "', adjustment_code = '" . trim(formData('adjustment_code')) .
97 "', post_to_date = '" . trim(add_escape_custom($post_to_date)) .
98 "', payment_method = '" . trim(formData('payment_method')) .
99 "' where session_id='" . add_escape_custom($payment_id) . "'");
100 //===============================================================================
101 $CountIndexAbove=$_REQUEST['CountIndexAbove'];
102 $CountIndexBelow=$_REQUEST['CountIndexBelow'];
103 $hidden_patient_code=$_REQUEST['hidden_patient_code'];
104 $user_id=$_SESSION['authUserID'];
105 $created_time = date('Y-m-d H:i:s');
106 //==================================================================
107 //UPDATION
108 //It is done with out deleting any old entries.
109 //==================================================================
110 for ($CountRow=1; $CountRow<=$CountIndexAbove; $CountRow++) {
111 if (isset($_POST["HiddenEncounter$CountRow"])) {
112 if (isset($_POST["Payment$CountRow"]) && $_POST["Payment$CountRow"]*1>0) {
113 if (trim($_POST['type_name'])=='insurance') {
114 if (trim($_POST["HiddenIns$CountRow"])==1) {
115 $AccountCode="IPP";
118 if (trim($_POST["HiddenIns$CountRow"])==2) {
119 $AccountCode="ISP";
122 if (trim($_POST["HiddenIns$CountRow"])==3) {
123 $AccountCode="ITP";
125 } elseif (trim($_POST['type_name'])=='patient') {
126 $AccountCode="PP";
129 $resPayment = sqlStatement("SELECT * from ar_activity " .
130 " where session_id ='" . add_escape_custom($payment_id) . "' and pid ='" . trim(formData("HiddenPId$CountRow")) .
131 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
132 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
133 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
134 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
135 "' and pay_amount>0");
136 if (sqlNumRows($resPayment)>0) {
137 sqlStatement("update ar_activity set " .
138 " post_user = '" . trim(add_escape_custom($user_id)) .
139 "', modified_time = '" . trim(add_escape_custom($created_time)) .
140 "', pay_amount = '" . trim(formData("Payment$CountRow")) .
141 "', account_code = '" . add_escape_custom($AccountCode) .
142 "', payer_type = '" . trim(formData("HiddenIns$CountRow")) .
143 "', reason_code = '" . trim(formData("ReasonCode$CountRow")) .
144 "' where session_id ='" . add_escape_custom($payment_id) . "' and pid ='" . trim(formData("HiddenPId$CountRow")) .
145 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
146 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
147 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
148 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
149 "' and pay_amount>0");
150 } else {
151 sqlBeginTrans();
152 $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")) . "'");
153 sqlStatement("insert into ar_activity set " .
154 "pid = '" . trim(formData("HiddenPId$CountRow")) .
155 "', encounter = '" . trim(formData("HiddenEncounter$CountRow")) .
156 "', sequence_no = '" . add_escape_custom($sequence_no['increment']) .
157 "', code_type = '" . trim(formData("HiddenCodetype$CountRow")) .
158 "', code = '" . trim(formData("HiddenCode$CountRow")) .
159 "', modifier = '" . trim(formData("HiddenModifier$CountRow")) .
160 "', payer_type = '" . trim(formData("HiddenIns$CountRow")) .
161 "', reason_code = '" . trim(formData("ReasonCode$CountRow")) .
162 "', post_time = '" . trim(add_escape_custom($created_time)) .
163 "', post_user = '" . trim(add_escape_custom($user_id)) .
164 "', session_id = '" . trim(formData('payment_id')) .
165 "', modified_time = '" . trim(add_escape_custom($created_time)) .
166 "', pay_amount = '" . trim(formData("Payment$CountRow")) .
167 "', adj_amount = '" . 0 .
168 "', account_code = '" . add_escape_custom($AccountCode) .
169 "'");
170 sqlCommitTrans();
172 } else {
173 sqlStatement("delete from ar_activity " .
174 " where session_id ='" . add_escape_custom($payment_id) . "' and pid ='" . trim(formData("HiddenPId$CountRow")) .
175 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
176 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
177 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
178 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
179 "' and pay_amount>0");
182 //==============================================================================================================================
183 if (isset($_POST["AdjAmount$CountRow"]) && $_POST["AdjAmount$CountRow"]*1!=0) {
184 if (trim($_POST['type_name'])=='insurance') {
185 $AdjustString="Ins adjust Ins".trim($_POST["HiddenIns$CountRow"]);
186 $AccountCode="IA";
187 } elseif (trim($_POST['type_name'])=='patient') {
188 $AdjustString="Pt adjust";
189 $AccountCode="PA";
192 $resPayment = sqlStatement("SELECT * from ar_activity " .
193 " where session_id ='" . add_escape_custom($payment_id) . "' and pid ='" . trim(formData("HiddenPId$CountRow")) .
194 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
195 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
196 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
197 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
198 "' and adj_amount!=0");
199 if (sqlNumRows($resPayment)>0) {
200 sqlStatement("update ar_activity set " .
201 " post_user = '" . trim(add_escape_custom($user_id)) .
202 "', modified_time = '" . trim(add_escape_custom($created_time)) .
203 "', adj_amount = '" . trim(formData("AdjAmount$CountRow")) .
204 "', memo = '" . add_escape_custom($AdjustString) .
205 "', account_code = '" . add_escape_custom($AccountCode) .
206 "', payer_type = '" . trim(formData("HiddenIns$CountRow")) .
207 "' where session_id ='" . add_escape_custom($payment_id) . "' and pid ='" . trim(formData("HiddenPId$CountRow")) .
208 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
209 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
210 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
211 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
212 "' and adj_amount!=0");
213 } else {
214 sqlBeginTrans();
215 $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")) . "'");
216 sqlStatement("insert into ar_activity set " .
217 "pid = '" . trim(formData("HiddenPId$CountRow")) .
218 "', encounter = '" . trim(formData("HiddenEncounter$CountRow")) .
219 "', sequence_no = '" . add_escape_custom($sequence_no['increment']) .
220 "', code_type = '" . trim(formData("HiddenCodetype$CountRow")) .
221 "', code = '" . trim(formData("HiddenCode$CountRow")) .
222 "', modifier = '" . trim(formData("HiddenModifier$CountRow")) .
223 "', payer_type = '" . trim(formData("HiddenIns$CountRow")) .
224 "', post_time = '" . trim(add_escape_custom($created_time)) .
225 "', post_user = '" . trim(add_escape_custom($user_id)) .
226 "', session_id = '" . trim(formData('payment_id')) .
227 "', modified_time = '" . trim(add_escape_custom($created_time)) .
228 "', pay_amount = '" . 0 .
229 "', adj_amount = '" . trim(formData("AdjAmount$CountRow")) .
230 "', memo = '" . add_escape_custom($AdjustString) .
231 "', account_code = '" . add_escape_custom($AccountCode) .
232 "'");
233 sqlCommitTrans();
235 } else {
236 sqlStatement("delete from ar_activity " .
237 " where session_id ='" . add_escape_custom($payment_id) . "' and pid ='" . trim(formData("HiddenPId$CountRow")) .
238 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
239 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
240 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
241 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
242 "' and adj_amount!=0");
245 //==============================================================================================================================
246 if (isset($_POST["Deductible$CountRow"]) && $_POST["Deductible$CountRow"]*1>0) {
247 $resPayment = sqlStatement("SELECT * from ar_activity " .
248 " where session_id ='" . add_escape_custom($payment_id) . "' and pid ='" . trim(formData("HiddenPId$CountRow")) .
249 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
250 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
251 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
252 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
253 "' and (memo like 'Deductable%' OR memo like 'Deductible%')");
254 if (sqlNumRows($resPayment)>0) {
255 sqlStatement("update ar_activity set " .
256 " post_user = '" . trim(add_escape_custom($user_id)) .
257 "', modified_time = '" . trim(add_escape_custom($created_time)) .
258 "', memo = '" . "Deductible $".trim(formData("Deductible$CountRow")) .
259 "', account_code = '" . "Deduct" .
260 "', payer_type = '" . trim(formData("HiddenIns$CountRow")) .
261 "' where session_id ='" . add_escape_custom($payment_id) . "' and pid ='" . trim(formData("HiddenPId$CountRow")) .
262 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
263 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
264 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
265 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
266 "' and (memo like 'Deductable%' OR memo like 'Deductible%')");
267 } else {
268 sqlBeginTrans();
269 $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")) . "'");
270 sqlStatement("insert into ar_activity set " .
271 "pid = '" . trim(formData("HiddenPId$CountRow")) .
272 "', encounter = '" . trim(formData("HiddenEncounter$CountRow")) .
273 "', sequence_no = '" . add_escape_custom($sequence_no['increment']) .
274 "', code_type = '" . trim(formData("HiddenCodetype$CountRow")) .
275 "', code = '" . trim(formData("HiddenCode$CountRow")) .
276 "', modifier = '" . trim(formData("HiddenModifier$CountRow")) .
277 "', payer_type = '" . trim(formData("HiddenIns$CountRow")) .
278 "', post_time = '" . trim(add_escape_custom($created_time)) .
279 "', post_user = '" . trim(add_escape_custom($user_id)) .
280 "', session_id = '" . trim(formData('payment_id')) .
281 "', modified_time = '" . trim(add_escape_custom($created_time)) .
282 "', pay_amount = '" . 0 .
283 "', adj_amount = '" . 0 .
284 "', memo = '" . "Deductible $".trim(formData("Deductible$CountRow")) .
285 "', account_code = '" . "Deduct" .
286 "'");
287 sqlCommitTrans();
289 } else {
290 sqlStatement("delete from ar_activity " .
291 " where session_id ='" . add_escape_custom($payment_id) . "' and pid ='" . trim(formData("HiddenPId$CountRow")) .
292 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
293 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
294 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
295 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
296 "' and (memo like 'Deductable%' OR memo like 'Deductible%')");
299 //==============================================================================================================================
300 if (isset($_POST["Takeback$CountRow"]) && $_POST["Takeback$CountRow"]*1>0) {
301 $resPayment = sqlStatement("SELECT * from ar_activity " .
302 " where session_id ='" . add_escape_custom($payment_id) . "' and pid ='" . trim(formData("HiddenPId$CountRow")) .
303 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
304 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
305 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
306 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
307 "' and pay_amount < 0");
308 if (sqlNumRows($resPayment)>0) {
309 sqlStatement("update ar_activity set " .
310 " post_user = '" . trim(add_escape_custom($user_id)) .
311 "', modified_time = '" . trim(add_escape_custom($created_time)) .
312 "', pay_amount = '" . trim(formData("Takeback$CountRow"))*-1 .
313 "', account_code = '" . "Takeback" .
314 "', payer_type = '" . trim(formData("HiddenIns$CountRow")) .
315 "' where session_id ='" . add_escape_custom($payment_id) . "' and pid ='" . trim(formData("HiddenPId$CountRow")) .
316 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
317 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
318 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
319 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
320 "' and pay_amount < 0");
321 } else {
322 sqlBeginTrans();
323 $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")) . "'");
324 sqlStatement("insert into ar_activity set " .
325 "pid = '" . trim(formData("HiddenPId$CountRow")) .
326 "', encounter = '" . trim(formData("HiddenEncounter$CountRow")) .
327 "', sequence_no = '" . add_escape_custom($sequence_no['increment']) .
328 "', code_type = '" . trim(formData("HiddenCodetype$CountRow")) .
329 "', code = '" . trim(formData("HiddenCode$CountRow")) .
330 "', modifier = '" . trim(formData("HiddenModifier$CountRow")) .
331 "', payer_type = '" . trim(formData("HiddenIns$CountRow")) .
332 "', post_time = '" . trim(add_escape_custom($created_time)) .
333 "', post_user = '" . trim(add_escape_custom($user_id)) .
334 "', session_id = '" . trim(formData('payment_id')) .
335 "', modified_time = '" . trim(add_escape_custom($created_time)) .
336 "', pay_amount = '" . trim(formData("Takeback$CountRow"))*-1 .
337 "', adj_amount = '" . 0 .
338 "', account_code = '" . "Takeback" .
339 "'");
340 sqlCommitTrans();
342 } else {
343 sqlStatement("delete from ar_activity " .
344 " where session_id ='" . add_escape_custom($payment_id) . "' and pid ='" . trim(formData("HiddenPId$CountRow")) .
345 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
346 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
347 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
348 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
349 "' and pay_amount < 0");
352 //==============================================================================================================================
353 if (isset($_POST["FollowUp$CountRow"]) && $_POST["FollowUp$CountRow"]=='y') {
354 $resPayment = sqlStatement("SELECT * from ar_activity " .
355 " where session_id ='" . add_escape_custom($payment_id) . "' and pid ='" . trim(formData("HiddenPId$CountRow")) .
356 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
357 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
358 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
359 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
360 "' and follow_up ='y'");
361 if (sqlNumRows($resPayment)>0) {
362 sqlStatement("update ar_activity set " .
363 " post_user = '" . trim(add_escape_custom($user_id)) .
364 "', modified_time = '" . trim(add_escape_custom($created_time)) .
365 "', follow_up = '" . "y" .
366 "', follow_up_note = '" . trim(formData("FollowUpReason$CountRow")) .
367 "', payer_type = '" . trim(formData("HiddenIns$CountRow")) .
368 "' where session_id ='" . add_escape_custom($payment_id) . "' and pid ='" . trim(formData("HiddenPId$CountRow")) .
369 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
370 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
371 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
372 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
373 "' and follow_up ='y'");
374 } else {
375 sqlBeginTrans();
376 $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")) . "'");
377 sqlStatement("insert into ar_activity set " .
378 "pid = '" . trim(formData("HiddenPId$CountRow")) .
379 "', encounter = '" . trim(formData("HiddenEncounter$CountRow")) .
380 "', sequence_no = '" . add_escape_custom($sequence_no['increment']) .
381 "', code_type = '" . trim(formData("HiddenCodetype$CountRow")) .
382 "', code = '" . trim(formData("HiddenCode$CountRow")) .
383 "', modifier = '" . trim(formData("HiddenModifier$CountRow")) .
384 "', payer_type = '" . trim(formData("HiddenIns$CountRow")) .
385 "', post_time = '" . trim(add_escape_custom($created_time)) .
386 "', post_user = '" . trim(add_escape_custom($user_id)) .
387 "', session_id = '" . trim(formData('payment_id')) .
388 "', modified_time = '" . trim(add_escape_custom($created_time)) .
389 "', pay_amount = '" . 0 .
390 "', adj_amount = '" . 0 .
391 "', follow_up = '" . "y" .
392 "', follow_up_note = '" . trim(formData("FollowUpReason$CountRow")) .
393 "'");
394 sqlCommitTrans();
396 } else {
397 sqlStatement("delete from ar_activity " .
398 " where session_id ='" . add_escape_custom($payment_id) . "' and pid ='" . trim(formData("HiddenPId$CountRow")) .
399 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
400 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
401 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
402 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
403 "' and follow_up ='y'");
406 //==============================================================================================================================
407 } else {
408 break;
412 //=========
413 //INSERTION of new entries,continuation of modification.
414 //=========
415 for ($CountRow=$CountIndexAbove+1; $CountRow<=$CountIndexAbove+$CountIndexBelow; $CountRow++) {
416 if (isset($_POST["HiddenEncounter$CountRow"])) {
417 DistributionInsert($CountRow, $created_time, $user_id);
418 } else {
419 break;
423 if ($_REQUEST['global_amount']=='yes') {
424 sqlStatement("update ar_session set global_amount=? where session_id =?", [(isset($_POST["HidUnappliedAmount"]) ? trim($_POST["HidUnappliedAmount"])*1 : ''), $payment_id]);
427 if ($_POST["mode"]=="FinishPayments") {
428 $Message='Finish';
431 $_POST["mode"] = "searchdatabase";
432 $Message='Modify';
436 //==============================================================================
437 //Search Code
438 //===============================================================================
439 $payment_id=$payment_id*1 > 0 ? $payment_id : $_REQUEST['payment_id'];
440 $ResultSearchSub = sqlStatement("SELECT distinct encounter,code_type,code,modifier, pid from ar_activity where session_id =? order by pid,encounter,code,modifier", [$payment_id]);
441 //==============================================================================
443 //==============================================================================
444 //===============================================================================
446 <!DOCTYPE html>
447 <html>
448 <head>
450 <?php Header::setupHeader(['datetime-picker', 'common']); ?>
452 <script language='JavaScript'>
453 var mypcc = '1';
454 </script>
455 <?php include_once("{$GLOBALS['srcdir']}/payment_jav.inc.php"); ?>
456 <?php include_once("{$GLOBALS['srcdir']}/ajax/payment_ajax_jav.inc.php"); ?>
457 <script language="javascript" type="text/javascript">
458 function ModifyPayments()
459 {//Used while modifying the allocation
460 if(!FormValidations())//FormValidations contains the form checks
462 return false;
464 if(CompletlyBlankAbove())//The distribution rows already in the database are checked.
466 alert(<?php echo xlj('None of the Top Distribution Row Can be Completly Blank.'); ?> + "\n" + <?php echo xlj('Use Delete Option to Remove.'); ?>);
467 return false;
469 if(!CheckPayingEntityAndDistributionPostFor())//Ensures that Insurance payment is distributed under Ins1,Ins2,Ins3 and Patient paymentat under Pat.
471 return false;
473 if(CompletlyBlankBelow())//The newly added distribution rows are checked.
475 alert(<?php echo xlj('Fill any of the Below Row.'); ?>);
476 return false;
478 PostValue=CheckUnappliedAmount();//Decides TdUnappliedAmount >0, or <0 or =0
479 if(PostValue==1)
481 alert(<?php echo xlj('Cannot Modify Payments.Undistributed is Negative.'); ?>);
482 return false;
484 if(confirm(<?php echo xlj('Would you like to Modify Payments?'); ?>))
486 document.getElementById('mode').value='ModifyPayments';
487 top.restoreSession();
488 document.forms[0].submit();
490 else
491 return false;
493 function FinishPayments()
495 if(!FormValidations())//FormValidations contains the form checks
497 return false;
499 if(CompletlyBlankAbove())//The distribution rows already in the database are checked.
501 alert(<?php echo xlj('None of the Top Distribution Row Can be Completly Blank.'); ?> + "\n" + <?php echo xlj('Use Delete Option to Remove.'); ?>);
502 return false;
504 if(!CheckPayingEntityAndDistributionPostFor())//Ensures that Insurance payment is distributed under Ins1,Ins2,Ins3 and Patient paymentat under Pat.
506 return false;
508 if(CompletlyBlankBelow())//The newly added distribution rows are checked.
510 alert(<?php echo xlj('Fill any of the Below Row.'); ?>);
511 return false;
513 PostValue=CheckUnappliedAmount();//Decides TdUnappliedAmount >0, or <0 or =0
514 if(PostValue==1)
516 alert(<?php echo xlj('Cannot Modify Payments.Undistributed is Negative.'); ?>);
517 return false;
519 if(PostValue==2)
521 if(confirm(<?php echo xlj('Would you like to Modify and Finish Payments?'); ?>))
523 UnappliedAmount=document.getElementById('TdUnappliedAmount').innerHTML*1;
524 if(confirm(<?php echo xlj('Undistributed is'); ?> + ' ' + UnappliedAmount + '.' + '\n' + <?php echo xlj('Would you like the balance amount to apply to Global Account?'); ?>))
526 document.getElementById('mode').value='FinishPayments';
527 document.getElementById('global_amount').value='yes';
528 top.restoreSession();
529 document.forms[0].submit();
531 else
533 document.getElementById('mode').value='FinishPayments';
534 top.restoreSession();
535 document.forms[0].submit();
538 else
539 return false;
541 else
543 if(confirm(<?php echo xlj('Would you like to Modify and Finish Payments?'); ?>))
545 document.getElementById('mode').value='FinishPayments';
546 top.restoreSession();
547 document.forms[0].submit();
549 else
550 return false;
554 function CompletlyBlankAbove()
555 {//The distribution rows already in the database are checked.
556 //It is not allowed to be made completly empty.If needed delete option need to be used.
557 CountIndexAbove=document.getElementById('CountIndexAbove').value*1;
558 for(RowCount=1;RowCount<=CountIndexAbove;RowCount++)
560 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)
562 return true;
565 return false;
567 function CompletlyBlankBelow()
568 {//The newly added distribution rows are checked.
569 //It is not allowed to be made completly empty.
570 CountIndexAbove=document.getElementById('CountIndexAbove').value*1;
571 CountIndexBelow=document.getElementById('CountIndexBelow').value*1;
572 if(CountIndexBelow==0)
573 return false;
574 for(RowCount=CountIndexAbove+1;RowCount<=CountIndexAbove+CountIndexBelow;RowCount++)
576 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)
580 else
581 return false;
583 return true;
585 function OnloadAction()
586 {//Displays message while loading after some action.
587 after_value=document.getElementById('ActionStatus').value;
588 if(after_value=='Delete')
590 alert(<?php echo xlj('Successfully Deleted'); ?>);
591 return true;
593 if(after_value=='Modify' || after_value=='Finish')
595 alert(<?php echo xlj('Successfully Modified'); ?>);
596 return true;
598 after_value=document.getElementById('after_value').value;
599 payment_id=document.getElementById('payment_id').value;
600 if(after_value=='distribute')
603 else if(after_value=='new_payment')
605 if(document.getElementById('TablePatientPortion'))
607 document.getElementById('TablePatientPortion').style.display='none';
609 if(confirm(<?php echo xlj('Successfully Saved.Would you like to Distribute?'); ?>))
611 if(document.getElementById('TablePatientPortion'))
613 document.getElementById('TablePatientPortion').style.display='';
619 function DeletePaymentDistribution(DeleteId)
620 {//Confirms deletion of payment distribution.
621 if(confirm(<?php echo xlj('Would you like to Delete Payment Distribution?'); ?>))
623 document.getElementById('mode').value='DeletePaymentDistribution';
624 document.getElementById('DeletePaymentDistributionId').value=DeleteId;
625 top.restoreSession();
626 document.forms[0].submit();
628 else
629 return false;
631 //========================================================================================
633 $(function() {
634 $('.datepicker').datetimepicker({
635 <?php $datetimepicker_timepicker = false; ?>
636 <?php $datetimepicker_showseconds = false; ?>
637 <?php $datetimepicker_formatInput = true; ?>
638 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
639 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
643 </script>
644 <script language="javascript" type="text/javascript">
645 document.onclick=HideTheAjaxDivs;
646 </script>
647 <style>
648 .class1 {
649 width: 125px;
651 .class2 {
652 width: 250px;
654 .class3 {
655 width: 100px;
657 .bottom {
658 border-bottom: 1px solid black;
660 .top {
661 border-top: 1px solid black;
663 .left {
664 border-left: 1px solid black;
666 .right {
667 border-right: 1px solid black;
669 #ajax_div_insurance {
670 position: absolute;
671 z-index: 10;
673 left: 20px;
674 top: 300px;
676 background-color: #FBFDD0;
677 border: 1px solid #ccc;
678 padding: 10px;
680 #ajax_div_patient {
681 position: absolute;
682 z-index: 10;
684 left: 20px;
685 top: 300px;
687 background-color: #FBFDD0;
688 border: 1px solid #ccc;
689 padding: 10px;
691 .form-group {
692 margin-bottom: 5px;
694 legend {
695 border-bottom: 2px solid #E5E5E5;
696 background: #E5E5E5;
697 padding-left: 10px;
699 .form-horizontal .control-label {
700 padding-top: 2px;
702 fieldset {
703 border-color: #68171A !important;
704 background-color: #f2f2f2;
705 /*#e7e7e7*/
706 margin-bottom: 10px;
707 padding-bottom: 15px;
709 @media only screen and (max-width: 768px) {
710 [class*="col-"] {
711 width: 100%;
712 text-align: left!Important;
715 </style>
716 <link rel="stylesheet" href="<?php echo $css_header; ?>" type="text/css">
717 </head>
718 <body class="body_top" onload="OnloadAction()">
719 <div class="container">
720 <?php
721 if ($_REQUEST['ParentPage']=='new_payment') {
723 <div class="row">
724 <div class="page-header">
725 <h2><?php echo xlt('Payments'); ?></h2>
726 </div>
727 </div>
729 <div class="row" >
730 <nav class="navbar navbar-default navbar-color navbar-static-top" >
731 <div class="container-fluid">
732 <div class="navbar-header">
733 <button class="navbar-toggle" data-target="#myNavbar" data-toggle="collapse" type="button"><span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span></button>
734 </div>
735 <div class="collapse navbar-collapse" id="myNavbar" >
736 <ul class="nav navbar-nav" >
737 <li class="active oe-bold-black">
738 <a href='new_payment.php' style="font-weight:700; color:#000000"><?php echo xlt('New Payment'); ?></a>
739 </li>
740 <li class="oe-bold-black" >
741 <a href='search_payments.php' style="font-weight:700; color:#000000"><?php echo xlt('Search Payment'); ?></a>
742 </li>
743 <li class="oe-bold-black">
744 <a href='era_payments.php' style="font-weight:700; color:#000000"><?php echo xlt('ERA Posting'); ?></a>
745 </li>
746 </ul>
747 </div>
748 </div>
749 </nav>
750 </div>
751 <?php
754 <div class="row">
755 <form name='new_payment' method='post' action="edit_payment.php" onsubmit='
756 <?php
757 if ($payment_id*1==0) {
758 echo "top.restoreSession();return SavePayment();";
759 } else {
760 echo "return false;";
763 ' style="display:inline" >
764 <?php
765 if ($payment_id*1>0) { ?>
766 <fieldset>
767 <?php
768 require_once("payment_master.inc.php"); //Check/cash details are entered here.
770 <?php
771 }//End of if($payment_id*1>0)
773 <?php
774 if ($payment_id*1>0) {//Distribution rows already in the database are displayed.
776 <?php //
777 $resCount = sqlStatement("SELECT distinct encounter,code_type,code,modifier from ar_activity where session_id =?", [$payment_id]);
778 $TotalRows=sqlNumRows($resCount);
779 $CountPatient=0;
780 $CountIndex=0;
781 $CountIndexAbove=0;
782 $paymenttot=0;
783 $adjamttot=0;
784 $deductibletot=0;
785 $takebacktot=0;
786 $allowedtot=0;
787 if ($RowSearchSub = sqlFetchArray($ResultSearchSub)) {
788 do {
789 $CountPatient++;
790 $PId=$RowSearchSub['pid'];
791 $EncounterMaster=$RowSearchSub['encounter'];
792 // Only use the code_type in the queries below if it is specified in the ar_activity table.
793 // If it is not specified in the ar_activity table, also note it is not requested from the
794 // billing table in below query, thus making it blank in all queries below in this script.
795 $CodetypeMaster=$RowSearchSub['code_type'];
796 $sql_select_part_codetype = "";
797 $sql_where_part_codetype = "";
798 if (!empty($CodetypeMaster)) {
799 $sql_select_part_codetype = "billing.code_type,";
800 $sql_where_part_codetype = "and billing.code_type ='" . add_escape_custom($CodetypeMaster) . "'";
802 $CodeMaster=$RowSearchSub['code'];
803 $ModifierMaster=$RowSearchSub['modifier'];
804 $res = sqlStatement("SELECT fname,lname,mname FROM patient_data where pid =?", [$PId]);
805 $row = sqlFetchArray($res);
806 $fname=$row['fname'];
807 $lname=$row['lname'];
808 $mname=$row['mname'];
809 $NameDB=$lname.' '.$fname.' '.$mname;
810 $ResultSearch = sqlStatement("SELECT billing.id,last_level_closed,billing.encounter,form_encounter.`date`,$sql_select_part_codetype billing.code,billing.modifier,fee
811 FROM billing ,form_encounter
812 where billing.encounter=form_encounter.encounter and billing.pid=form_encounter.pid and
813 code_type!='ICD9' and code_type!='COPAY' and billing.activity!=0 and
814 form_encounter.pid ='" . add_escape_custom($PId) . "' and billing.pid ='" . add_escape_custom($PId) . "' and billing.encounter ='" . add_escape_custom($EncounterMaster) . "'
815 $sql_where_part_codetype
816 and billing.code ='" . add_escape_custom($CodeMaster) . "'
817 and billing.modifier ='" . add_escape_custom($ModifierMaster) . "'
818 ORDER BY form_encounter.`date`,form_encounter.encounter,billing.code,billing.modifier");
819 if (sqlNumRows($ResultSearch)>0) {
820 if ($CountPatient==1) {
821 $Table='yes';
823 <input id="HiddenRemainderTd<?php echo attr($CountIndex); ?>" name="HiddenRemainderTd<?php echo attr($CountIndex); ?>" type="hidden" value="<?php echo attr(round($RemainderJS, 2)); ?>">
824 <div class = "table-responsive">
825 <table class="table-condensed" id="TableDistributePortion" >
826 <thead bgcolor="#DDDDDD" class="text">
827 <td class="left top" >&nbsp;</td>
828 <td class="left top" ><?php echo xlt('Patient Name'); ?></td>
829 <td class="left top" ><?php echo xlt('Post For'); ?></td>
830 <td class="left top" ><?php echo xlt('Service Date'); ?></td>
831 <td class="left top" ><?php echo xlt('Encounter'); ?></td>
832 <td class="left top" ><?php echo xlt('Service Code'); ?></td>
833 <td class="left top" ><?php echo xlt('Charge'); ?></td>
834 <td class="left top" ><?php echo xlt('Copay'); ?></td>
835 <td class="left top" ><?php echo xlt('Remdr'); ?></td>
836 <td class="left top" ><?php echo xlt('Allowed(c)'); ?></td><!-- (c) means it is calculated.Not stored one. -->
837 <td class="left top" ><?php echo xlt('Payment'); ?></td>
838 <td class="left top" ><?php echo xlt('Adj Amount'); ?></td>
839 <td class="left top" ><?php echo xlt('Deductible'); ?></td>
840 <td class="left top" ><?php echo xlt('Takeback'); ?></td>
841 <td class="left top" ><?php echo xlt('MSP Code'); ?></td>
842 <td class="left top" ><?php echo xlt('Resn'); ?></td>
843 <td class="left top right" ><?php echo xlt('Follow Up Reason'); ?></td>
844 </thead>
845 <?php
847 while ($RowSearch = sqlFetchArray($ResultSearch)) {
848 $CountIndex++;
849 $CountIndexAbove++;
850 $ServiceDateArray=explode(' ', $RowSearch['date']);
851 $ServiceDate=oeFormatShortDate($ServiceDateArray[0]);
852 $Codetype=$RowSearch['code_type'];
853 $Code=$RowSearch['code'];
854 $Modifier =$RowSearch['modifier'];
855 if ($Modifier!='') {
856 $ModifierString=", $Modifier";
857 } else {
858 $ModifierString="";
859 $Fee=$RowSearch['fee'];
860 $Encounter=$RowSearch['encounter'];
862 $resPayer = sqlStatement("SELECT payer_type from ar_activity where session_id =? and
863 pid=? and encounter=? and code_type=? and code=? and modifier=?", [$payment_id, $PId, $Encounter, $Codetype, $Code, $Modifier]);
864 $rowPayer = sqlFetchArray($resPayer);
865 $Ins=$rowPayer['payer_type'];
867 //Always associating the copay to a particular charge.
868 $BillingId=$RowSearch['id'];
869 $resId = sqlStatement("SELECT id FROM billing where code_type!='ICD9' and code_type!='COPAY' and
870 pid =? and encounter =? and billing.activity!=0 order by id", [$PId, $Encounter]);
871 $rowId = sqlFetchArray($resId);
872 $Id=$rowId['id'];
875 if ($BillingId!=$Id) {//multiple cpt in single encounter
876 $Copay=0.00;
877 } else {
878 $resCopay = sqlStatement("SELECT sum(fee) as copay FROM billing where
879 code_type='COPAY' and pid =? and encounter =? and billing.activity!=0", [$PId, $Encounter]);
880 $rowCopay = sqlFetchArray($resCopay);
881 $Copay=$rowCopay['copay']*-1;
883 $resMoneyGot = sqlStatement("SELECT sum(pay_amount) as PatientPay FROM ar_activity where
884 pid =? and encounter =? and payer_type=0 and account_code='PCP'", [$PId, $Encounter]);//new fees screen copay gives account_code='PCP'
885 $rowMoneyGot = sqlFetchArray($resMoneyGot);
886 $PatientPay=$rowMoneyGot['PatientPay'];
888 $Copay=$Copay+$PatientPay;
891 //For calculating Remainder
892 if ($Ins==0) {//Fetch all values
893 $resMoneyGot = sqlStatement("SELECT sum(pay_amount) as MoneyGot FROM ar_activity where
894 pid=? and code_type=? and code=? and modifier=? and encounter=? and !(payer_type=0 and
895 account_code='PCP')", [$PId, $Codetype, $Code, $Modifier, $Encounter]);
896 //new fees screen copay gives account_code='PCP'
897 $rowMoneyGot = sqlFetchArray($resMoneyGot);
898 $MoneyGot=$rowMoneyGot['MoneyGot'];
900 $resMoneyAdjusted = sqlStatement("SELECT sum(adj_amount) as MoneyAdjusted FROM ar_activity where
901 pid=? and code_type=? and code=? and modifier=? and encounter=?", [$PId, $Codetype, $Code, $Modifier, $Encounter]);
902 $rowMoneyAdjusted = sqlFetchArray($resMoneyAdjusted);
903 $MoneyAdjusted=$rowMoneyAdjusted['MoneyAdjusted'];
904 } else //Fetch till that much got
906 //Fetch the HIGHEST sequence_no till this session.
907 //Used maily in the case if primary/others pays once more.
908 $resSequence = sqlStatement("SELECT sequence_no from ar_activity where session_id=? and
909 pid=? and encounter=? order by sequence_no desc ", [$payment_id, $PId, $Encounter]);
910 $rowSequence = sqlFetchArray($resSequence);
911 $Sequence=$rowSequence['sequence_no'];
913 $resMoneyGot = sqlStatement("SELECT sum(pay_amount) as MoneyGot FROM ar_activity where
914 pid=? and code_type=? and code=? and modifier=? and encounter=? and
915 payer_type > 0 and payer_type <=? and sequence_no<=?", [$PId, $Codetype, $Code, $Modifier, $Encounter, $Ins, $Sequence]);
916 $rowMoneyGot = sqlFetchArray($resMoneyGot);
917 $MoneyGot=$rowMoneyGot['MoneyGot'];
919 $resMoneyAdjusted = sqlStatement("SELECT sum(adj_amount) as MoneyAdjusted FROM ar_activity where
920 pid =? and code_type=? and code=? and modifier=? and encounter =? and
921 payer_type > 0 and payer_type <=? and sequence_no<=?", [$PId, $Codetype, $Code, $Modifier, $Encounter, $Ins, $Sequence]);
922 $rowMoneyAdjusted = sqlFetchArray($resMoneyAdjusted);
923 $MoneyAdjusted=$rowMoneyAdjusted['MoneyAdjusted'];
925 $Remainder=$Fee-$Copay-$MoneyGot-$MoneyAdjusted;
927 //For calculating RemainderJS.Used while restoring back the values.
928 if ($Ins==0) {//Got just before Patient
929 $resMoneyGot = sqlStatement("SELECT sum(pay_amount) as MoneyGot FROM ar_activity where
930 pid=? and code_type=? and code=? and modifier=? and encounter=? and payer_type !=0", [$PId, $Codetype, $Code, $Modifier, $Encounter]);
931 $rowMoneyGot = sqlFetchArray($resMoneyGot);
932 $MoneyGot=$rowMoneyGot['MoneyGot'];
934 $resMoneyAdjusted = sqlStatement("SELECT sum(adj_amount) as MoneyAdjusted FROM ar_activity where
935 pid=? and code_type=? and code=? and modifier=? and encounter=? and payer_type !=0", [$PId, $Codetype, $Code, $Modifier, $Encounter]);
936 $rowMoneyAdjusted = sqlFetchArray($resMoneyAdjusted);
937 $MoneyAdjusted=$rowMoneyAdjusted['MoneyAdjusted'];
938 } else {//Got just before the previous
939 //Fetch the LOWEST sequence_no till this session.
940 //Used maily in the case if primary/others pays once more.
941 $resSequence = sqlStatement("SELECT sequence_no from ar_activity where session_id =? and
942 pid=? and encounter=? order by sequence_no", [$payment_id, $PId, $Encounter]);
943 $rowSequence = sqlFetchArray($resSequence);
944 $Sequence=$rowSequence['sequence_no'];
946 $resMoneyGot = sqlStatement("SELECT sum(pay_amount) as MoneyGot FROM ar_activity where
947 pid=? and code_type=? and code=? and modifier=? and encounter=?
948 and payer_type > 0 and payer_type <=? and sequence_no<?", [$PId, $Codetype, $Code, $Modifier, $Encounter, $Ins, $Sequence]);
949 $rowMoneyGot = sqlFetchArray($resMoneyGot);
950 $MoneyGot=$rowMoneyGot['MoneyGot'];
952 $resMoneyAdjusted = sqlStatement("SELECT sum(adj_amount) as MoneyAdjusted FROM ar_activity where
953 pid=? and code_type=? and code=? and modifier=? and encounter=?
954 and payer_type <=? and sequence_no<?", [$PId, $Codetype, $Code, $Modifier, $Encounter, $Ins, $Sequence]);
955 $rowMoneyAdjusted = sqlFetchArray($resMoneyAdjusted);
956 $MoneyAdjusted=$rowMoneyAdjusted['MoneyAdjusted'];
958 //Stored in hidden so that can be used while restoring back the values.
959 $RemainderJS=$Fee-$Copay-$MoneyGot-$MoneyAdjusted;
961 $resPayment = sqlStatement("SELECT pay_amount from ar_activity where session_id=? and
962 pid=? and encounter=? and code_type=? and code=? and modifier=? and pay_amount>0", [$payment_id, $PId, $Encounter, $Codetype, $Code, $Modifier]);
963 $rowPayment = sqlFetchArray($resPayment);
964 $PaymentDB=$rowPayment['pay_amount']*1;
965 $PaymentDB=$PaymentDB == 0 ? '' : $PaymentDB;
967 $resPayment = sqlStatement("SELECT pay_amount from ar_activity where session_id =? and
968 pid=? and encounter=? and code_type=? and code=? and modifier=? and pay_amount<0", [$payment_id, $PId, $Encounter, $Codetype, $Code, $Modifier]);
969 $rowPayment = sqlFetchArray($resPayment);
970 $TakebackDB=$rowPayment['pay_amount']*-1;
971 $TakebackDB=$TakebackDB == 0 ? '' : $TakebackDB;
973 $resPayment = sqlStatement("SELECT adj_amount from ar_activity where session_id=? and
974 pid=? and encounter=? and code_type=? and code=? and modifier=? and adj_amount!=0", [$payment_id, $PId, $Encounter, $Codetype, $Code, $Modifier]);
975 $rowPayment = sqlFetchArray($resPayment);
976 $AdjAmountDB=$rowPayment['adj_amount']*1;
977 $AdjAmountDB=$AdjAmountDB == 0 ? '' : $AdjAmountDB;
979 $resPayment = sqlStatement("SELECT memo from ar_activity where session_id=? and
980 pid=? and encounter=? and code_type=? and code=? and modifier=? and
981 (memo like 'Deductable%' OR memo like 'Deductible%')", [$payment_id, $PId, $Encounter, $Codetype, $Code, $Modifier]);
982 $rowPayment = sqlFetchArray($resPayment);
983 $DeductibleDB=$rowPayment['memo'];
984 $DeductibleDB=str_replace('Deductable $', '', $DeductibleDB);
985 $DeductibleDB=str_replace('Deductible $', '', $DeductibleDB);
987 $resPayment = sqlStatement("SELECT follow_up,follow_up_note from ar_activity where session_id=? and
988 pid=? and encounter=? and code_type=? and code=? and modifier=? and
989 follow_up = 'y'", [$payment_id, $PId, $Encounter, $Codetype, $Code, $Modifier]);
990 $rowPayment = sqlFetchArray($resPayment);
991 $FollowUpDB=$rowPayment['follow_up'];
992 $FollowUpReasonDB=$rowPayment['follow_up_note'];
994 $resPayment = sqlStatement("SELECT reason_code from ar_activity where session_id =? and
995 pid=? and encounter=? and code_type=? and code=? and modifier=?", [$payment_id, $PId, $Encounter, $Codetype, $Code, $Modifier]);
996 $rowPayment = sqlFetchArray($resPayment);
997 $ReasonCodeDB=$rowPayment['reason_code'];
999 if ($Ins==1) {
1000 $AllowedDB=number_format($Fee-$AdjAmountDB, 2);
1001 } else {
1002 $AllowedDB = 0;
1004 $AllowedDB=$AllowedDB == 0 ? '' : $AllowedDB;
1006 if ($CountIndex==$TotalRows) {
1007 $StringClass=' bottom left top ';
1008 } else {
1009 $StringClass=' left top ';
1012 if ($Ins==1) {
1013 $bgcolor='#ddddff';
1014 } elseif ($Ins==2) {
1015 $bgcolor='#ffdddd';
1016 } elseif ($Ins==3) {
1017 $bgcolor='#F2F1BC';
1018 } elseif ($Ins==0) {
1019 $bgcolor='#AAFFFF';
1021 $paymenttot=$paymenttot+$PaymentDB;
1022 $adjamttot=$adjamttot+$AdjAmountDB;
1023 $deductibletot=$deductibletot+$DeductibleDB;
1024 $takebacktot=$takebacktot+$TakebackDB;
1025 $allowedtot=$allowedtot+$AllowedDB;
1027 <tr bgcolor='<?php echo attr($bgcolor); ?>' class="text" id="trCharges<?php echo attr($CountIndex); ?>">
1028 <td align="left" class="<?php echo attr($StringClass); ?>">
1029 <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>
1030 </td>
1031 <td align="left" class="<?php echo attr($StringClass); ?>"><?php echo text($NameDB); ?><input name="HiddenPId<?php echo attr($CountIndex); ?>" type="hidden" value="<?php echo attr($PId); ?>"></td>
1032 <td align="left" class="<?php echo attr($StringClass); ?>"><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", '', '', 'ActionOnInsPat("'.$CountIndex.'")'); ?></td>
1033 <td class="<?php echo attr($StringClass); ?>"><?php echo text($ServiceDate); ?></td>
1034 <td align="right" class="<?php echo attr($StringClass); ?>"><input name="HiddenEncounter<?php echo attr($CountIndex); ?>" type="hidden" value="<?php echo attr($Encounter); ?>"><?php echo text($Encounter); ?></td>
1035 <td class="<?php echo attr($StringClass); ?>"><input name="HiddenCodetype<?php echo attr($CountIndex); ?>" type="hidden" value="<?php echo attr($Codetype); ?>"><input name="HiddenCode<?php echo attr($CountIndex); ?>" type="hidden" value="<?php echo attr($Code); ?>"><?php echo text($Codetype."-".$Code.$ModifierString); ?><input name="HiddenModifier<?php echo attr($CountIndex); ?>" type="hidden" value="<?php echo attr($Modifier); ?>"></td>
1036 <td align="right" class="<?php echo attr($StringClass); ?>"><input id="HiddenChargeAmount<?php echo attr($CountIndex); ?>" name="HiddenChargeAmount<?php echo attr($CountIndex); ?>" type="hidden" value="<?php echo attr($Fee); ?>"><?php echo text($Fee); ?></td>
1037 <td align="right" class="<?php echo attr($StringClass); ?>"><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)); ?></td>
1038 <td align="right" class="<?php echo attr($StringClass); ?>" id="RemainderTd<?php echo attr($CountIndex); ?>"><?php echo text(round($Remainder, 2)); ?></td>
1039 <td class="<?php echo attr($StringClass); ?>"><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)" style="width:60px;text-align:right; font-size:12px" type="text" value="<?php echo attr($AllowedDB); ?>"></td>
1040 <td class="<?php echo attr($StringClass); ?>"><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)" style="width:60px;text-align:right; font-size:12px" type="text" value="<?php echo attr($PaymentDB); ?>"></td>
1041 <td class="<?php echo attr($StringClass); ?>"><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)" style="width:70px;text-align:right; font-size:12px" type="text" value="<?php echo attr($AdjAmountDB); ?>"></td>
1042 <td class="<?php echo attr($StringClass); ?>"><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)" style="width:60px;text-align:right; font-size:12px" type="text" value="<?php echo attr($DeductibleDB); ?>"></td>
1043 <td class="<?php echo attr($StringClass); ?>"><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)" style="width:60px;text-align:right; font-size:12px" type="text" value="<?php echo attr($TakebackDB); ?>"></td>
1044 <td align="left" class="<?php echo attr($StringClass); ?>"><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 Code"); ?></td>
1045 <td align="center" class="<?php echo attr($StringClass); ?>"><input id="FollowUp<?php echo attr($CountIndex); ?>" name="FollowUp<?php echo attr($CountIndex); ?>" onclick="ActionFollowUp(<?php echo attr_js($CountIndex); ?>)" type="checkbox" value="y"></td>
1046 <td class="<?php echo attr($StringClass); ?> right"><input id="FollowUpReason<?php echo attr($CountIndex); ?>" name="FollowUpReason<?php echo attr($CountIndex); ?>" onkeydown="PreventIt(event)" style="width:110px;font-size:12px" type="text" value="<?php echo attr($FollowUpReasonDB); ?>"></td>
1047 </tr><?php
1048 }//End of while ($RowSearch = sqlFetchArray($ResultSearch))
1050 <?php
1051 }//End of if(sqlNumRows($ResultSearch)>0)
1052 } while ($RowSearchSub = sqlFetchArray($ResultSearchSub));
1053 if ($Table=='yes') {
1055 <tr class="text">
1056 <td align="left" colspan="9">&nbsp;</td>
1057 <td align="right" bgcolor="#6699FF" class="left bottom" id="allowtotal"><?php echo text(number_format($allowedtot, 2)); ?></td>
1058 <td align="right" bgcolor="#6699FF" class="left bottom" id="paymenttotal"><?php echo text(number_format($paymenttot, 2)); ?></td>
1059 <td align="right" bgcolor="#6699FF" class="left bottom" id="AdjAmounttotal"><?php echo text(number_format($adjamttot, 2)); ?></td>
1060 <td align="right" bgcolor="#6699FF" class="left bottom" id="deductibletotal"><?php echo text(number_format($deductibletot, 2)); ?></td>
1061 <td align="right" bgcolor="#6699FF" class="left bottom right" id="takebacktotal"><?php echo text(number_format($takebacktot, 2)); ?></td>
1062 <td align="center">&nbsp;</td>
1063 <td align="center">&nbsp;</td>
1064 </tr>
1065 </table>
1066 <?php
1069 <?php
1070 echo '<br/>';
1071 }//End of if($RowSearchSub = sqlFetchArray($ResultSearchSub))
1073 </div>
1074 <?php
1075 require_once("payment_pat_sel.inc.php"); //Patient ajax section and listing of charges.
1077 <?php
1078 }//End of if($payment_id*1>0)
1080 <?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 ?>
1081 <div class="form-group clearfix">
1082 <div class="col-sm-12 text-left position-override">
1083 <div class="btn-group" role="group">
1084 <a class="btn btn-default btn-save" href="#" onclick="javascript:return ModifyPayments();"><span><?php echo xlt('Modify Payments');?></span></a>
1085 <a class="btn btn-default btn-save" href="#" onclick="javascript:return FinishPayments();"><span><?php echo xlt('Finish Payments');?></span></a>
1086 </div>
1087 </div>
1088 </div>
1089 <div class="row">
1090 <input type="hidden" name="hidden_patient_code" id="hidden_patient_code" value="<?php echo attr($hidden_patient_code);?>"/>
1091 <input type='hidden' name='mode' id='mode' value='' />
1092 <input type='hidden' name='ajax_mode' id='ajax_mode' value='' />
1093 <input type="hidden" name="after_value" id="after_value" value="<?php echo attr($_POST["mode"]);?>"/>
1094 <input type="hidden" name="payment_id" id="payment_id" value="<?php echo attr($payment_id);?>"/>
1095 <input type="hidden" name="hidden_type_code" id="hidden_type_code" value="<?php echo attr($TypeCode);?>"/>
1096 <input type='hidden' name='global_amount' id='global_amount' value='' />
1097 <input type='hidden' name='DeletePaymentDistributionId' id='DeletePaymentDistributionId' value='' />
1098 <input type="hidden" name="ActionStatus" id="ActionStatus" value="<?php echo attr($Message);?>"/>
1099 <input type='hidden' name='CountIndexAbove' id='CountIndexAbove' value='<?php echo attr($CountIndexAbove*1);?>' />
1100 <input type='hidden' name='CountIndexBelow' id='CountIndexBelow' value='<?php echo attr($CountIndexBelow*1);?>' />
1101 <input type="hidden" name="ParentPage" id="ParentPage" value="<?php echo attr($_REQUEST['ParentPage']);?>"/>
1102 </div>
1103 </form>
1104 </div>
1105 </div><!-- End of container div-->
1106 </body>
1107 </html>