more organization of autoloaded files (#424)
[openemr.git] / interface / billing / edit_payment.php
blob641858e9149a761412d5705978f1e4fc6ba99f41
1 <?php
2 // +-----------------------------------------------------------------------------+
3 // Copyright (C) 2010 Z&H Consultancy Services Private Limited <sam@zhservices.com>
4 //
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
18 // A copy of the GNU General Public License is included along with this program:
19 // openemr/interface/login/GnuGPL.html
20 // For more information write to the Free Software
21 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 // Author: Eldho Chacko <eldho@zhservices.com>
24 // Paul Simon K <paul@zhservices.com>
26 // +------------------------------------------------------------------------------+
27 //===============================================================================
28 //Payments can be edited here.It includes deletion of an allocation,modifying the
29 //same or adding a new allocation.Log is kept for the deleted ones.
30 //===============================================================================
31 require_once("../globals.php");
32 require_once("$srcdir/log.inc");
33 require_once("$srcdir/invoice_summary.inc.php");
34 require_once("$srcdir/sl_eob.inc.php");
35 require_once("$srcdir/parse_era.inc.php");
36 require_once("../../library/acl.inc");
37 require_once("$srcdir/auth.inc");
38 require_once("../../custom/code_types.inc.php");
39 require_once("$srcdir/patient.inc");
40 require_once("$srcdir/billrep.inc");
41 require_once(dirname(__FILE__) . "/../../library/classes/OFX.class.php");
42 require_once(dirname(__FILE__) . "/../../library/classes/X12Partner.class.php");
43 require_once("$srcdir/options.inc.php");
44 require_once("$srcdir/formatting.inc.php");
45 require_once("$srcdir/payment.inc.php");
46 //===============================================================================
47 $screen='edit_payment';
48 //===============================================================================
49 // deletion of payment distribution code
50 //===============================================================================
51 if (isset($_POST["mode"]))
53 if ($_POST["mode"] == "DeletePaymentDistribution")
55 $DeletePaymentDistributionId=trim(formData('DeletePaymentDistributionId' ));
56 $DeletePaymentDistributionIdArray=explode('_',$DeletePaymentDistributionId);
57 $payment_id=$DeletePaymentDistributionIdArray[0];
58 $PId=$DeletePaymentDistributionIdArray[1];
59 $Encounter=$DeletePaymentDistributionIdArray[2];
60 $Code=$DeletePaymentDistributionIdArray[3];
61 $Modifier=$DeletePaymentDistributionIdArray[4];
62 $Codetype=$DeletePaymentDistributionIdArray[5];
63 //delete and log that action
64 row_delete("ar_activity", "session_id ='$payment_id' and pid ='$PId' AND " .
65 "encounter='$Encounter' and code_type='$Codetype' and code='$Code' and modifier='$Modifier'");
66 $Message='Delete';
67 //------------------
68 $_POST["mode"] = "searchdatabase";
71 //===============================================================================
72 //Modify Payment Code.
73 //===============================================================================
74 if (isset($_POST["mode"]))
76 if ($_POST["mode"] == "ModifyPayments" || $_POST["mode"] == "FinishPayments")
78 $payment_id=$_REQUEST['payment_id'];
79 //ar_session Code
80 //===============================================================================
81 if(trim(formData('type_name' ))=='insurance')
83 $QueryPart="payer_id = '" . trim(formData('hidden_type_code' )) .
84 "', patient_id = '" . 0 ;
86 elseif(trim(formData('type_name' ))=='patient')
88 $QueryPart="payer_id = '" . 0 .
89 "', patient_id = '" . trim(formData('hidden_type_code' )) ;
91 $user_id=$_SESSION['authUserID'];
92 $closed=0;
93 $modified_time = date('Y-m-d H:i:s');
94 $check_date=DateToYYYYMMDD(formData('check_date'));
95 $deposit_date=DateToYYYYMMDD(formData('deposit_date'));
96 $post_to_date=DateToYYYYMMDD(formData('post_to_date'));
97 if($post_to_date=='')
98 $post_to_date=date('Y-m-d');
99 if(formData('deposit_date')=='')
100 $deposit_date=$post_to_date;
102 sqlStatement("update ar_session set " .
103 $QueryPart .
104 "', user_id = '" . trim($user_id ) .
105 "', closed = '" . trim($closed ) .
106 "', reference = '" . trim(formData('check_number' )) .
107 "', check_date = '" . trim($check_date ) .
108 "', deposit_date = '" . trim($deposit_date ) .
109 "', pay_total = '" . trim(formData('payment_amount')) .
110 "', modified_time = '" . trim($modified_time ) .
111 "', payment_type = '" . trim(formData('type_name' )) .
112 "', description = '" . trim(formData('description' )) .
113 "', adjustment_code = '" . trim(formData('adjustment_code' )) .
114 "', post_to_date = '" . trim($post_to_date ) .
115 "', payment_method = '" . trim(formData('payment_method' )) .
116 "' where session_id='$payment_id'");
117 //===============================================================================
118 $CountIndexAbove=$_REQUEST['CountIndexAbove'];
119 $CountIndexBelow=$_REQUEST['CountIndexBelow'];
120 $hidden_patient_code=$_REQUEST['hidden_patient_code'];
121 $user_id=$_SESSION['authUserID'];
122 $created_time = date('Y-m-d H:i:s');
123 //==================================================================
124 //UPDATION
125 //It is done with out deleting any old entries.
126 //==================================================================
127 for($CountRow=1;$CountRow<=$CountIndexAbove;$CountRow++)
129 if (isset($_POST["HiddenEncounter$CountRow"]))
131 if (isset($_POST["Payment$CountRow"]) && $_POST["Payment$CountRow"]*1>0)
133 if(trim(formData('type_name' ))=='insurance')
135 if(trim(formData("HiddenIns$CountRow" ))==1)
137 $AccountCode="IPP";
139 if(trim(formData("HiddenIns$CountRow" ))==2)
141 $AccountCode="ISP";
143 if(trim(formData("HiddenIns$CountRow" ))==3)
145 $AccountCode="ITP";
148 elseif(trim(formData('type_name' ))=='patient')
150 $AccountCode="PP";
152 $resPayment = sqlStatement("SELECT * from ar_activity " .
153 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow" )) .
154 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow" )) .
155 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow" )) .
156 "' and code ='" . trim(formData("HiddenCode$CountRow" )) .
157 "' and modifier ='" . trim(formData("HiddenModifier$CountRow" )) .
158 "' and pay_amount>0");
159 if(sqlNumRows($resPayment)>0)
161 sqlStatement("update ar_activity set " .
162 " post_user = '" . trim($user_id ) .
163 "', modified_time = '" . trim($created_time ) .
164 "', pay_amount = '" . trim(formData("Payment$CountRow" )) .
165 "', account_code = '" . "$AccountCode" .
166 "', payer_type = '" . trim(formData("HiddenIns$CountRow" )) .
167 "', reason_code = '" . trim(formData("ReasonCode$CountRow" )) .
168 "' where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow" )) .
169 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow" )) .
170 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow" )) .
171 "' and code ='" . trim(formData("HiddenCode$CountRow" )) .
172 "' and modifier ='" . trim(formData("HiddenModifier$CountRow" )) .
173 "' and pay_amount>0");
175 else
177 sqlBeginTrans();
178 $sequence_no = sqlQuery( "SELECT IFNULL(MAX(sequence_no),0) + 1 AS increment FROM ar_activity WHERE pid = ? AND encounter = ?", array(trim(formData("HiddenPId$CountRow" )), trim(formData("HiddenEncounter$CountRow" ))));
179 sqlStatement("insert into ar_activity set " .
180 "pid = '" . trim(formData("HiddenPId$CountRow" )) .
181 "', encounter = '" . trim(formData("HiddenEncounter$CountRow" )) .
182 "', sequence_no = '" . $sequence_no['increment'] .
183 "', code_type = '" . trim(formData("HiddenCodetype$CountRow" )) .
184 "', code = '" . trim(formData("HiddenCode$CountRow" )) .
185 "', modifier = '" . trim(formData("HiddenModifier$CountRow" )) .
186 "', payer_type = '" . trim(formData("HiddenIns$CountRow" )) .
187 "', reason_code = '" . trim(formData("ReasonCode$CountRow" )) .
188 "', post_time = '" . trim($created_time ) .
189 "', post_user = '" . trim($user_id ) .
190 "', session_id = '" . trim(formData('payment_id')) .
191 "', modified_time = '" . trim($created_time ) .
192 "', pay_amount = '" . trim(formData("Payment$CountRow" )) .
193 "', adj_amount = '" . 0 .
194 "', account_code = '" . "$AccountCode" .
195 "'");
196 sqlCommitTrans();
199 else
201 sqlStatement("delete from ar_activity " .
202 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow" )) .
203 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow" )) .
204 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow" )) .
205 "' and code ='" . trim(formData("HiddenCode$CountRow" )) .
206 "' and modifier ='" . trim(formData("HiddenModifier$CountRow" )) .
207 "' and pay_amount>0");
209 //==============================================================================================================================
210 if (isset($_POST["AdjAmount$CountRow"]) && $_POST["AdjAmount$CountRow"]*1!=0)
212 if(trim(formData('type_name' ))=='insurance')
214 $AdjustString="Ins adjust Ins".trim(formData("HiddenIns$CountRow" ));
215 $AccountCode="IA";
217 elseif(trim(formData('type_name' ))=='patient')
219 $AdjustString="Pt adjust";
220 $AccountCode="PA";
222 $resPayment = sqlStatement("SELECT * from ar_activity " .
223 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow" )) .
224 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow" )) .
225 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow" )) .
226 "' and code ='" . trim(formData("HiddenCode$CountRow" )) .
227 "' and modifier ='" . trim(formData("HiddenModifier$CountRow" )) .
228 "' and adj_amount!=0");
229 if(sqlNumRows($resPayment)>0)
231 sqlStatement("update ar_activity set " .
232 " post_user = '" . trim($user_id ) .
233 "', modified_time = '" . trim($created_time ) .
234 "', adj_amount = '" . trim(formData("AdjAmount$CountRow" )) .
235 "', memo = '" . "$AdjustString" .
236 "', account_code = '" . "$AccountCode" .
237 "', payer_type = '" . trim(formData("HiddenIns$CountRow" )) .
238 "' where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow" )) .
239 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow" )) .
240 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow" )) .
241 "' and code ='" . trim(formData("HiddenCode$CountRow" )) .
242 "' and modifier ='" . trim(formData("HiddenModifier$CountRow" )) .
243 "' and adj_amount!=0");
245 else
247 sqlBeginTrans();
248 $sequence_no = sqlQuery( "SELECT IFNULL(MAX(sequence_no),0) + 1 AS increment FROM ar_activity WHERE pid = ? AND encounter = ?", array(trim(formData("HiddenPId$CountRow" )), trim(formData("HiddenEncounter$CountRow" ))));
249 sqlStatement("insert into ar_activity set " .
250 "pid = '" . trim(formData("HiddenPId$CountRow" )) .
251 "', encounter = '" . trim(formData("HiddenEncounter$CountRow" )) .
252 "', sequence_no = '" . $sequence_no['increment'] .
253 "', code_type = '" . trim(formData("HiddenCodetype$CountRow" )) .
254 "', code = '" . trim(formData("HiddenCode$CountRow" )) .
255 "', modifier = '" . trim(formData("HiddenModifier$CountRow" )) .
256 "', payer_type = '" . trim(formData("HiddenIns$CountRow" )) .
257 "', post_time = '" . trim($created_time ) .
258 "', post_user = '" . trim($user_id ) .
259 "', session_id = '" . trim(formData('payment_id')) .
260 "', modified_time = '" . trim($created_time ) .
261 "', pay_amount = '" . 0 .
262 "', adj_amount = '" . trim(formData("AdjAmount$CountRow" )) .
263 "', memo = '" . "$AdjustString" .
264 "', account_code = '" . "$AccountCode" .
265 "'");
266 sqlCommitTrans();
270 else
272 sqlStatement("delete from ar_activity " .
273 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow" )) .
274 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow" )) .
275 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow" )) .
276 "' and code ='" . trim(formData("HiddenCode$CountRow" )) .
277 "' and modifier ='" . trim(formData("HiddenModifier$CountRow" )) .
278 "' and adj_amount!=0");
280 //==============================================================================================================================
281 if (isset($_POST["Deductible$CountRow"]) && $_POST["Deductible$CountRow"]*1>0)
283 $resPayment = sqlStatement("SELECT * from ar_activity " .
284 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow" )) .
285 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow" )) .
286 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow" )) .
287 "' and code ='" . trim(formData("HiddenCode$CountRow" )) .
288 "' and modifier ='" . trim(formData("HiddenModifier$CountRow" )) .
289 "' and (memo like 'Deductable%' OR memo like 'Deductible%')");
290 if(sqlNumRows($resPayment)>0)
292 sqlStatement("update ar_activity set " .
293 " post_user = '" . trim($user_id ) .
294 "', modified_time = '" . trim($created_time ) .
295 "', memo = '" . "Deductible $".trim(formData("Deductible$CountRow" )) .
296 "', account_code = '" . "Deduct" .
297 "', payer_type = '" . trim(formData("HiddenIns$CountRow" )) .
298 "' where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow" )) .
299 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow" )) .
300 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow" )) .
301 "' and code ='" . trim(formData("HiddenCode$CountRow" )) .
302 "' and modifier ='" . trim(formData("HiddenModifier$CountRow" )) .
303 "' and (memo like 'Deductable%' OR memo like 'Deductible%')");
305 else
307 sqlBeginTrans();
308 $sequence_no = sqlQuery( "SELECT IFNULL(MAX(sequence_no),0) + 1 AS increment FROM ar_activity WHERE pid = ? AND encounter = ?", array(trim(formData("HiddenPId$CountRow")), trim(formData("HiddenEncounter$CountRow"))));
309 sqlStatement("insert into ar_activity set " .
310 "pid = '" . trim(formData("HiddenPId$CountRow" )) .
311 "', encounter = '" . trim(formData("HiddenEncounter$CountRow" )) .
312 "', sequence_no = '" . $sequence_no['increment'] .
313 "', code_type = '" . trim(formData("HiddenCodetype$CountRow" )) .
314 "', code = '" . trim(formData("HiddenCode$CountRow" )) .
315 "', modifier = '" . trim(formData("HiddenModifier$CountRow" )) .
316 "', payer_type = '" . trim(formData("HiddenIns$CountRow" )) .
317 "', post_time = '" . trim($created_time ) .
318 "', post_user = '" . trim($user_id ) .
319 "', session_id = '" . trim(formData('payment_id')) .
320 "', modified_time = '" . trim($created_time ) .
321 "', pay_amount = '" . 0 .
322 "', adj_amount = '" . 0 .
323 "', memo = '" . "Deductible $".trim(formData("Deductible$CountRow" )) .
324 "', account_code = '" . "Deduct" .
325 "'");
326 sqlCommitTrans();
329 else
331 sqlStatement("delete from ar_activity " .
332 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow" )) .
333 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow" )) .
334 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow" )) .
335 "' and code ='" . trim(formData("HiddenCode$CountRow" )) .
336 "' and modifier ='" . trim(formData("HiddenModifier$CountRow" )) .
337 "' and (memo like 'Deductable%' OR memo like 'Deductible%')");
339 //==============================================================================================================================
340 if (isset($_POST["Takeback$CountRow"]) && $_POST["Takeback$CountRow"]*1>0)
342 $resPayment = sqlStatement("SELECT * from ar_activity " .
343 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow" )) .
344 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow" )) .
345 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow" )) .
346 "' and code ='" . trim(formData("HiddenCode$CountRow" )) .
347 "' and modifier ='" . trim(formData("HiddenModifier$CountRow" )) .
348 "' and pay_amount < 0");
349 if(sqlNumRows($resPayment)>0)
351 sqlStatement("update ar_activity set " .
352 " post_user = '" . trim($user_id ) .
353 "', modified_time = '" . trim($created_time ) .
354 "', pay_amount = '" . trim(formData("Takeback$CountRow" ))*-1 .
355 "', account_code = '" . "Takeback" .
356 "', payer_type = '" . trim(formData("HiddenIns$CountRow" )) .
357 "' where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow" )) .
358 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow" )) .
359 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow" )) .
360 "' and code ='" . trim(formData("HiddenCode$CountRow" )) .
361 "' and modifier ='" . trim(formData("HiddenModifier$CountRow" )) .
362 "' and pay_amount < 0");
364 else
366 sqlBeginTrans();
367 $sequence_no = sqlQuery( "SELECT IFNULL(MAX(sequence_no),0) + 1 AS increment FROM ar_activity WHERE pid = ? AND encounter = ?", array(trim(formData("HiddenPId$CountRow" )), trim(formData("HiddenEncounter$CountRow" ))));
368 sqlStatement("insert into ar_activity set " .
369 "pid = '" . trim(formData("HiddenPId$CountRow" )) .
370 "', encounter = '" . trim(formData("HiddenEncounter$CountRow" )) .
371 "', sequence_no = '" . $sequence_no['increment'] .
372 "', code_type = '" . trim(formData("HiddenCodetype$CountRow" )) .
373 "', code = '" . trim(formData("HiddenCode$CountRow" )) .
374 "', modifier = '" . trim(formData("HiddenModifier$CountRow" )) .
375 "', payer_type = '" . trim(formData("HiddenIns$CountRow" )) .
376 "', post_time = '" . trim($created_time ) .
377 "', post_user = '" . trim($user_id ) .
378 "', session_id = '" . trim(formData('payment_id')) .
379 "', modified_time = '" . trim($created_time ) .
380 "', pay_amount = '" . trim(formData("Takeback$CountRow" ))*-1 .
381 "', adj_amount = '" . 0 .
382 "', account_code = '" . "Takeback" .
383 "'");
384 sqlCommitTrans();
387 else
389 sqlStatement("delete from ar_activity " .
390 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow" )) .
391 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow" )) .
392 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow" )) .
393 "' and code ='" . trim(formData("HiddenCode$CountRow" )) .
394 "' and modifier ='" . trim(formData("HiddenModifier$CountRow" )) .
395 "' and pay_amount < 0");
397 //==============================================================================================================================
398 if (isset($_POST["FollowUp$CountRow"]) && $_POST["FollowUp$CountRow"]=='y')
400 $resPayment = sqlStatement("SELECT * from ar_activity " .
401 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow" )) .
402 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow" )) .
403 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow" )) .
404 "' and code ='" . trim(formData("HiddenCode$CountRow" )) .
405 "' and modifier ='" . trim(formData("HiddenModifier$CountRow" )) .
406 "' and follow_up ='y'");
407 if(sqlNumRows($resPayment)>0)
409 sqlStatement("update ar_activity set " .
410 " post_user = '" . trim($user_id ) .
411 "', modified_time = '" . trim($created_time ) .
412 "', follow_up = '" . "y" .
413 "', follow_up_note = '" . trim(formData("FollowUpReason$CountRow" )) .
414 "', payer_type = '" . trim(formData("HiddenIns$CountRow" )) .
415 "' where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow" )) .
416 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow" )) .
417 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow" )) .
418 "' and code ='" . trim(formData("HiddenCode$CountRow" )) .
419 "' and modifier ='" . trim(formData("HiddenModifier$CountRow" )) .
420 "' and follow_up ='y'");
422 else
424 sqlBeginTrans();
425 $sequence_no = sqlQuery( "SELECT IFNULL(MAX(sequence_no),0) + 1 AS increment FROM ar_activity WHERE pid = ? AND encounter = ?", array(trim(formData("HiddenPId$CountRow" )), trim(formData("HiddenEncounter$CountRow" ))));
426 sqlStatement("insert into ar_activity set " .
427 "pid = '" . trim(formData("HiddenPId$CountRow" )) .
428 "', encounter = '" . trim(formData("HiddenEncounter$CountRow" )) .
429 "', sequence_no = '" . $sequence_no['increment'] .
430 "', code_type = '" . trim(formData("HiddenCodetype$CountRow" )) .
431 "', code = '" . trim(formData("HiddenCode$CountRow" )) .
432 "', modifier = '" . trim(formData("HiddenModifier$CountRow" )) .
433 "', payer_type = '" . trim(formData("HiddenIns$CountRow" )) .
434 "', post_time = '" . trim($created_time ) .
435 "', post_user = '" . trim($user_id ) .
436 "', session_id = '" . trim(formData('payment_id')) .
437 "', modified_time = '" . trim($created_time ) .
438 "', pay_amount = '" . 0 .
439 "', adj_amount = '" . 0 .
440 "', follow_up = '" . "y" .
441 "', follow_up_note = '" . trim(formData("FollowUpReason$CountRow" )) .
442 "'");
443 sqlCommitTrans();
446 else
448 sqlStatement("delete from ar_activity " .
449 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow" )) .
450 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow" )) .
451 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow" )) .
452 "' and code ='" . trim(formData("HiddenCode$CountRow" )) .
453 "' and modifier ='" . trim(formData("HiddenModifier$CountRow" )) .
454 "' and follow_up ='y'");
456 //==============================================================================================================================
458 else
459 break;
461 //=========
462 //INSERTION of new entries,continuation of modification.
463 //=========
464 for($CountRow=$CountIndexAbove+1;$CountRow<=$CountIndexAbove+$CountIndexBelow;$CountRow++)
466 if (isset($_POST["HiddenEncounter$CountRow"]))
468 DistributionInsert($CountRow,$created_time,$user_id);
470 else
471 break;
473 if($_REQUEST['global_amount']=='yes')
474 sqlStatement("update ar_session set global_amount=".trim(formData("HidUnappliedAmount" ))*1 ." where session_id ='$payment_id'");
475 if($_POST["mode"]=="FinishPayments")
477 $Message='Finish';
479 $_POST["mode"] = "searchdatabase";
480 $Message='Modify';
483 //==============================================================================
484 //Search Code
485 //===============================================================================
486 $payment_id=$payment_id*1 > 0 ? $payment_id : $_REQUEST['payment_id'];
487 $ResultSearchSub = sqlStatement("SELECT distinct encounter,code_type,code,modifier, pid from ar_activity where session_id ='$payment_id' order by pid,encounter,code,modifier");
488 //==============================================================================
489 $DateFormat=DateFormatRead();
490 //==============================================================================
491 //===============================================================================
494 <html>
495 <head>
496 <?php if (function_exists('html_header_show')) html_header_show(); ?>
498 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
500 <!-- supporting javascript code -->
502 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
506 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
507 <link rel="stylesheet" type="text/css" href="../../library/js/fancybox/jquery.fancybox-1.2.6.css" media="screen" />
508 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
509 <script type="text/javascript" src="../../library/textformat.js"></script>
510 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
511 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
512 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
513 <script type="text/javascript" src="../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
514 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-3-2/index.js"></script>
515 <script type="text/javascript" src="../../library/js/fancybox/jquery.fancybox-1.2.6.js"></script>
516 <script language='JavaScript'>
517 var mypcc = '1';
518 </script>
519 <?php include_once("{$GLOBALS['srcdir']}/payment_jav.inc.php"); ?>
520 <?php include_once("{$GLOBALS['srcdir']}/ajax/payment_ajax_jav.inc.php"); ?>
521 <script type="text/javascript" src="../../library/js/common.js"></script>
522 <script LANGUAGE="javascript" TYPE="text/javascript">
523 function ModifyPayments()
524 {//Used while modifying the allocation
525 if(!FormValidations())//FormValidations contains the form checks
527 return false;
529 if(CompletlyBlankAbove())//The distribution rows already in the database are checked.
531 alert("<?php echo htmlspecialchars( xl('None of the Top Distribution Row Can be Completly Blank.'), ENT_QUOTES);echo htmlspecialchars('\n');echo htmlspecialchars( xl('Use Delete Option to Remove.'), ENT_QUOTES) ?>")
532 return false;
534 if(!CheckPayingEntityAndDistributionPostFor())//Ensures that Insurance payment is distributed under Ins1,Ins2,Ins3 and Patient paymentat under Pat.
536 return false;
538 if(CompletlyBlankBelow())//The newly added distribution rows are checked.
540 alert("<?php echo htmlspecialchars( xl('Fill any of the Below Row.'), ENT_QUOTES) ?>")
541 return false;
543 PostValue=CheckUnappliedAmount();//Decides TdUnappliedAmount >0, or <0 or =0
544 if(PostValue==1)
546 alert("<?php echo htmlspecialchars( xl('Cannot Modify Payments.Undistributed is Negative.'), ENT_QUOTES) ?>")
547 return false;
549 if(confirm("<?php echo htmlspecialchars( xl('Would you like to Modify Payments?'), ENT_QUOTES) ?>"))
551 document.getElementById('mode').value='ModifyPayments';
552 top.restoreSession();
553 document.forms[0].submit();
555 else
556 return false;
558 function FinishPayments()
560 if(!FormValidations())//FormValidations contains the form checks
562 return false;
564 if(CompletlyBlankAbove())//The distribution rows already in the database are checked.
566 alert("<?php echo htmlspecialchars( xl('None of the Top Distribution Row Can be Completly Blank.'), ENT_QUOTES);echo htmlspecialchars('\n');echo htmlspecialchars( xl('Use Delete Option to Remove.'), ENT_QUOTES) ?>")
567 return false;
569 if(!CheckPayingEntityAndDistributionPostFor())//Ensures that Insurance payment is distributed under Ins1,Ins2,Ins3 and Patient paymentat under Pat.
571 return false;
573 if(CompletlyBlankBelow())//The newly added distribution rows are checked.
575 alert("<?php echo htmlspecialchars( xl('Fill any of the Below Row.'), ENT_QUOTES) ?>")
576 return false;
578 PostValue=CheckUnappliedAmount();//Decides TdUnappliedAmount >0, or <0 or =0
579 if(PostValue==1)
581 alert("<?php echo htmlspecialchars( xl('Cannot Modify Payments.Undistributed is Negative.'), ENT_QUOTES) ?>")
582 return false;
584 if(PostValue==2)
586 if(confirm("<?php echo htmlspecialchars( xl('Would you like to Modify and Finish Payments?'), ENT_QUOTES) ?>"))
588 UnappliedAmount=document.getElementById('TdUnappliedAmount').innerHTML*1;
589 if(confirm("<?php echo htmlspecialchars( xl('Undistributed is'), ENT_QUOTES) ?>" + ' ' + UnappliedAmount + '.' + "<?php echo htmlspecialchars('\n');echo htmlspecialchars( xl('Would you like the balance amount to apply to Global Account?'), ENT_QUOTES) ?>"))
591 document.getElementById('mode').value='FinishPayments';
592 document.getElementById('global_amount').value='yes';
593 top.restoreSession();
594 document.forms[0].submit();
596 else
598 document.getElementById('mode').value='FinishPayments';
599 top.restoreSession();
600 document.forms[0].submit();
603 else
604 return false;
606 else
608 if(confirm("<?php echo htmlspecialchars( xl('Would you like to Modify and Finish Payments?'), ENT_QUOTES) ?>"))
610 document.getElementById('mode').value='FinishPayments';
611 top.restoreSession();
612 document.forms[0].submit();
614 else
615 return false;
619 function CompletlyBlankAbove()
620 {//The distribution rows already in the database are checked.
621 //It is not allowed to be made completly empty.If needed delete option need to be used.
622 CountIndexAbove=document.getElementById('CountIndexAbove').value*1;
623 for(RowCount=1;RowCount<=CountIndexAbove;RowCount++)
625 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)
627 return true;
630 return false;
632 function CompletlyBlankBelow()
633 {//The newly added distribution rows are checked.
634 //It is not allowed to be made completly empty.
635 CountIndexAbove=document.getElementById('CountIndexAbove').value*1;
636 CountIndexBelow=document.getElementById('CountIndexBelow').value*1;
637 if(CountIndexBelow==0)
638 return false;
639 for(RowCount=CountIndexAbove+1;RowCount<=CountIndexAbove+CountIndexBelow;RowCount++)
641 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)
645 else
646 return false;
648 return true;
650 function OnloadAction()
651 {//Displays message while loading after some action.
652 after_value=document.getElementById('ActionStatus').value;
653 if(after_value=='Delete')
655 alert("<?php echo htmlspecialchars( xl('Successfully Deleted'), ENT_QUOTES) ?>")
656 return true;
658 if(after_value=='Modify' || after_value=='Finish')
660 alert("<?php echo htmlspecialchars( xl('Successfully Modified'), ENT_QUOTES) ?>")
661 return true;
663 after_value=document.getElementById('after_value').value;
664 payment_id=document.getElementById('payment_id').value;
665 if(after_value=='distribute')
668 else if(after_value=='new_payment')
670 if(document.getElementById('TablePatientPortion'))
672 document.getElementById('TablePatientPortion').style.display='none';
674 if(confirm("<?php echo htmlspecialchars( xl('Successfully Saved.Would you like to Distribute?'), ENT_QUOTES) ?>"))
676 if(document.getElementById('TablePatientPortion'))
678 document.getElementById('TablePatientPortion').style.display='';
684 function DeletePaymentDistribution(DeleteId)
685 {//Confirms deletion of payment distribution.
686 if(confirm("<?php echo htmlspecialchars( xl('Would you like to Delete Payment Distribution?'), ENT_QUOTES) ?>"))
688 document.getElementById('mode').value='DeletePaymentDistribution';
689 document.getElementById('DeletePaymentDistributionId').value=DeleteId;
690 top.restoreSession();
691 document.forms[0].submit();
693 else
694 return false;
696 //========================================================================================
697 </script>
698 <script language="javascript" type="text/javascript">
699 document.onclick=HideTheAjaxDivs;
700 </script>
701 <style>
702 .class1{width:125px;}
703 .class2{width:250px;}
704 .class3{width:100px;}
705 .bottom{border-bottom:1px solid black;}
706 .top{border-top:1px solid black;}
707 .left{border-left:1px solid black;}
708 .right{border-right:1px solid black;}
709 #ajax_div_insurance {
710 position: absolute;
711 z-index:10;
713 left: 20px;
714 top: 300px;
716 background-color: #FBFDD0;
717 border: 1px solid #ccc;
718 padding: 10px;
720 #ajax_div_patient {
721 position: absolute;
722 z-index:10;
724 left: 20px;
725 top: 300px;
727 background-color: #FBFDD0;
728 border: 1px solid #ccc;
729 padding: 10px;
731 </style>
732 <link rel="stylesheet" href="<?php echo $css_header; ?>" type="text/css">
733 </head>
734 <body class="body_top" onLoad="OnloadAction()" >
735 <form name='new_payment' method='post' action="edit_payment.php" onsubmit='
736 <?php
737 if($payment_id*1==0)
740 top.restoreSession();return SavePayment();
741 <?php
743 else
746 return false;
747 <?php
750 ' style="display:inline" >
751 <table width="1024" border="0" cellspacing="0" cellpadding="0">
752 <?php
753 if($_REQUEST['ParentPage']=='new_payment')
756 <tr>
757 <td colspan="3" align="left"><b><?php echo htmlspecialchars( xl('Payments'), ENT_QUOTES) ?></b></td>
758 </tr>
759 <tr height="15">
760 <td colspan="3" align="left" ></td>
761 </tr>
762 <tr>
763 <td colspan="3" align="left">
764 <ul class="tabNav">
765 <li class='current'><a href='new_payment.php'><?php echo htmlspecialchars( xl('New Payment'), ENT_QUOTES) ?></a></li>
766 <li><a href='search_payments.php'><?php echo htmlspecialchars( xl('Search Payment'), ENT_QUOTES) ?></a></li>
767 <li><a href='era_payments.php'><?php echo htmlspecialchars( xl('ERA Posting'), ENT_QUOTES) ?></a></li>
768 </ul> </td>
769 </tr>
770 <?php
772 else
775 <tr height="5">
776 <td colspan="3" align="left" ></td>
777 </tr>
778 <?php
781 <tr>
782 <td colspan="3" align="left" >
784 <?php
785 if($payment_id*1>0)
788 <?php
789 require_once("payment_master.inc.php"); //Check/cash details are entered here.
791 <?php
794 </td>
795 </tr>
796 </table>
800 <?php
801 if($payment_id*1>0)
802 {//Distribution rows already in the database are displayed.
805 <table width="1024" border="0" cellspacing="0" cellpadding="10" bgcolor="#DEDEDE"><tr><td>
806 <table width="1004" border="0" cellspacing="0" cellpadding="0">
808 <tr>
809 <td colspan="13" align="left" >
811 <?php //
812 $resCount = sqlStatement("SELECT distinct encounter,code_type,code,modifier from ar_activity where session_id ='$payment_id' ");
813 $TotalRows=sqlNumRows($resCount);
814 $CountPatient=0;
815 $CountIndex=0;
816 $CountIndexAbove=0;
817 $paymenttot=0;
818 $adjamttot=0;
819 $deductibletot=0;
820 $takebacktot=0;
821 $allowedtot=0;
822 if($RowSearchSub = sqlFetchArray($ResultSearchSub))
826 $CountPatient++;
827 $PId=$RowSearchSub['pid'];
828 $EncounterMaster=$RowSearchSub['encounter'];
829 // Only use the code_type in the queries below if it is specified in the ar_activity table.
830 // If it is not specified in the ar_activity table, also note it is not requested from the
831 // billing table in below query, thus making it blank in all queries below in this script.
832 $CodetypeMaster=$RowSearchSub['code_type'];
833 $sql_select_part_codetype = "";
834 $sql_where_part_codetype = "";
835 if (!empty($CodetypeMaster)) {
836 $sql_select_part_codetype = "billing.code_type,";
837 $sql_where_part_codetype = "and billing.code_type ='$CodetypeMaster'";
839 $CodeMaster=$RowSearchSub['code'];
840 $ModifierMaster=$RowSearchSub['modifier'];
841 $res = sqlStatement("SELECT fname,lname,mname FROM patient_data where pid ='$PId'");
842 $row = sqlFetchArray($res);
843 $fname=$row['fname'];
844 $lname=$row['lname'];
845 $mname=$row['mname'];
846 $NameDB=$lname.' '.$fname.' '.$mname;
847 $ResultSearch = sqlStatement("SELECT billing.id,last_level_closed,billing.encounter,form_encounter.`date`,$sql_select_part_codetype billing.code,billing.modifier,fee
848 FROM billing ,form_encounter
849 where billing.encounter=form_encounter.encounter and billing.pid=form_encounter.pid and
850 code_type!='ICD9' and code_type!='COPAY' and billing.activity!=0 and
851 form_encounter.pid ='$PId' and billing.pid ='$PId' and billing.encounter ='$EncounterMaster'
852 $sql_where_part_codetype
853 and billing.code ='$CodeMaster'
854 and billing.modifier ='$ModifierMaster'
855 ORDER BY form_encounter.`date`,form_encounter.encounter,billing.code,billing.modifier");
856 if(sqlNumRows($ResultSearch)>0)
858 if($CountPatient==1)
860 $Table='yes';
862 <table width="1004" border="0" cellpadding="0" cellspacing="0" align="center" id="TableDistributePortion">
863 <tr class="text" bgcolor="#dddddd">
864 <td width="25" class="left top" >&nbsp;</td>
865 <td width="144" class="left top" ><?php echo htmlspecialchars( xl('Patient Name'), ENT_QUOTES) ?></td>
866 <td width="55" class="left top" ><?php echo htmlspecialchars( xl('Post For'), ENT_QUOTES) ?></td>
867 <td width="70" class="left top" ><?php echo htmlspecialchars( xl('Service Date'), ENT_QUOTES) ?></td>
868 <td width="50" class="left top" ><?php echo htmlspecialchars( xl('Encounter'), ENT_QUOTES) ?></td>
869 <td width="65" class="left top" ><?php echo htmlspecialchars( xl('Service Code'), ENT_QUOTES) ?></td>
870 <td width="50" class="left top" ><?php echo htmlspecialchars( xl('Charge'), ENT_QUOTES) ?></td>
871 <td width="40" class="left top" ><?php echo htmlspecialchars( xl('Copay'), ENT_QUOTES) ?></td>
872 <td width="40" class="left top" ><?php echo htmlspecialchars( xl('Remdr'), ENT_QUOTES) ?></td>
873 <td width="60" class="left top" ><?php echo htmlspecialchars( xl('Allowed(c)'), ENT_QUOTES) ?></td><!-- (c) means it is calculated.Not stored one. -->
874 <td width="60" class="left top" ><?php echo htmlspecialchars( xl('Payment'), ENT_QUOTES) ?></td>
875 <td width="70" class="left top" ><?php echo htmlspecialchars( xl('Adj Amount'), ENT_QUOTES) ?></td>
876 <td width="60" class="left top" ><?php echo htmlspecialchars( xl('Deductible'), ENT_QUOTES) ?></td>
877 <td width="60" class="left top" ><?php echo htmlspecialchars( xl('Takeback'), ENT_QUOTES) ?></td>
878 <td width="60" class="left top" ><?php echo htmlspecialchars( xl('MSP Code'), ENT_QUOTES) ?></td>
879 <td width="40" class="left top" ><?php echo htmlspecialchars( xl('Resn'), ENT_QUOTES) ?></td>
880 <td width="110" class="left top right" ><?php echo htmlspecialchars( xl('Follow Up Reason'), ENT_QUOTES) ?></td>
881 </tr>
882 <?php
884 while ($RowSearch = sqlFetchArray($ResultSearch))
886 $CountIndex++;
887 $CountIndexAbove++;
888 $ServiceDateArray=explode(' ',$RowSearch['date']);
889 $ServiceDate=oeFormatShortDate($ServiceDateArray[0]);
890 $Codetype=$RowSearch['code_type'];
891 $Code=$RowSearch['code'];
892 $Modifier =$RowSearch['modifier'];
893 if($Modifier!='')
894 $ModifierString=", $Modifier";
895 else
896 $ModifierString="";
897 $Fee=$RowSearch['fee'];
898 $Encounter=$RowSearch['encounter'];
900 $resPayer = sqlStatement("SELECT payer_type from ar_activity where session_id ='$payment_id' and
901 pid ='$PId' and encounter ='$Encounter' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' ");
902 $rowPayer = sqlFetchArray($resPayer);
903 $Ins=$rowPayer['payer_type'];
905 //Always associating the copay to a particular charge.
906 $BillingId=$RowSearch['id'];
907 $resId = sqlStatement("SELECT id FROM billing where code_type!='ICD9' and code_type!='COPAY' and
908 pid ='$PId' and encounter ='$Encounter' and billing.activity!=0 order by id");
909 $rowId = sqlFetchArray($resId);
910 $Id=$rowId['id'];
912 if($BillingId!=$Id)//multiple cpt in single encounter
914 $Copay=0.00;
916 else
918 $resCopay = sqlStatement("SELECT sum(fee) as copay FROM billing where
919 code_type='COPAY' and pid ='$PId' and encounter ='$Encounter' and billing.activity!=0");
920 $rowCopay = sqlFetchArray($resCopay);
921 $Copay=$rowCopay['copay']*-1;
923 $resMoneyGot = sqlStatement("SELECT sum(pay_amount) as PatientPay FROM ar_activity where
924 pid ='$PId' and encounter ='$Encounter' and payer_type=0 and account_code='PCP'");//new fees screen copay gives account_code='PCP'
925 $rowMoneyGot = sqlFetchArray($resMoneyGot);
926 $PatientPay=$rowMoneyGot['PatientPay'];
928 $Copay=$Copay+$PatientPay;
931 //For calculating Remainder
932 if($Ins==0)
933 {//Fetch all values
934 $resMoneyGot = sqlStatement("SELECT sum(pay_amount) as MoneyGot FROM ar_activity where
935 pid ='$PId' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and encounter ='$Encounter' and !(payer_type=0 and
936 account_code='PCP')");
937 //new fees screen copay gives account_code='PCP'
938 $rowMoneyGot = sqlFetchArray($resMoneyGot);
939 $MoneyGot=$rowMoneyGot['MoneyGot'];
941 $resMoneyAdjusted = sqlStatement("SELECT sum(adj_amount) as MoneyAdjusted FROM ar_activity where
942 pid ='$PId' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and encounter ='$Encounter'");
943 $rowMoneyAdjusted = sqlFetchArray($resMoneyAdjusted);
944 $MoneyAdjusted=$rowMoneyAdjusted['MoneyAdjusted'];
946 else//Fetch till that much got
948 //Fetch the HIGHEST sequence_no till this session.
949 //Used maily in the case if primary/others pays once more.
950 $resSequence = sqlStatement("SELECT sequence_no from ar_activity where session_id ='$payment_id' and
951 pid ='$PId' and encounter ='$Encounter' order by sequence_no desc ");
952 $rowSequence = sqlFetchArray($resSequence);
953 $Sequence=$rowSequence['sequence_no'];
955 $resMoneyGot = sqlStatement("SELECT sum(pay_amount) as MoneyGot FROM ar_activity where
956 pid ='$PId' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and encounter ='$Encounter' and
957 payer_type > 0 and payer_type <='$Ins' and sequence_no<='$Sequence'");
958 $rowMoneyGot = sqlFetchArray($resMoneyGot);
959 $MoneyGot=$rowMoneyGot['MoneyGot'];
961 $resMoneyAdjusted = sqlStatement("SELECT sum(adj_amount) as MoneyAdjusted FROM ar_activity where
962 pid ='$PId' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and encounter ='$Encounter' and
963 payer_type > 0 and payer_type <='$Ins' and sequence_no<='$Sequence'");
964 $rowMoneyAdjusted = sqlFetchArray($resMoneyAdjusted);
965 $MoneyAdjusted=$rowMoneyAdjusted['MoneyAdjusted'];
967 $Remainder=$Fee-$Copay-$MoneyGot-$MoneyAdjusted;
969 //For calculating RemainderJS.Used while restoring back the values.
970 if($Ins==0)
971 {//Got just before Patient
972 $resMoneyGot = sqlStatement("SELECT sum(pay_amount) as MoneyGot FROM ar_activity where
973 pid ='$PId' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and encounter ='$Encounter' and payer_type !=0");
974 $rowMoneyGot = sqlFetchArray($resMoneyGot);
975 $MoneyGot=$rowMoneyGot['MoneyGot'];
977 $resMoneyAdjusted = sqlStatement("SELECT sum(adj_amount) as MoneyAdjusted FROM ar_activity where
978 pid ='$PId' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and encounter ='$Encounter' and payer_type !=0");
979 $rowMoneyAdjusted = sqlFetchArray($resMoneyAdjusted);
980 $MoneyAdjusted=$rowMoneyAdjusted['MoneyAdjusted'];
982 else
983 {//Got just before the previous
984 //Fetch the LOWEST sequence_no till this session.
985 //Used maily in the case if primary/others pays once more.
986 $resSequence = sqlStatement("SELECT sequence_no from ar_activity where session_id ='$payment_id' and
987 pid ='$PId' and encounter ='$Encounter' order by sequence_no ");
988 $rowSequence = sqlFetchArray($resSequence);
989 $Sequence=$rowSequence['sequence_no'];
991 $resMoneyGot = sqlStatement("SELECT sum(pay_amount) as MoneyGot FROM ar_activity where
992 pid ='$PId' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and encounter ='$Encounter'
993 and payer_type > 0 and payer_type <='$Ins' and sequence_no<'$Sequence'");
994 $rowMoneyGot = sqlFetchArray($resMoneyGot);
995 $MoneyGot=$rowMoneyGot['MoneyGot'];
997 $resMoneyAdjusted = sqlStatement("SELECT sum(adj_amount) as MoneyAdjusted FROM ar_activity where
998 pid ='$PId' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and encounter ='$Encounter'
999 and payer_type <='$Ins' and sequence_no<'$Sequence' ");
1000 $rowMoneyAdjusted = sqlFetchArray($resMoneyAdjusted);
1001 $MoneyAdjusted=$rowMoneyAdjusted['MoneyAdjusted'];
1003 //Stored in hidden so that can be used while restoring back the values.
1004 $RemainderJS=$Fee-$Copay-$MoneyGot-$MoneyAdjusted;
1006 $resPayment = sqlStatement("SELECT pay_amount from ar_activity where session_id ='$payment_id' and
1007 pid ='$PId' and encounter ='$Encounter' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and pay_amount>0");
1008 $rowPayment = sqlFetchArray($resPayment);
1009 $PaymentDB=$rowPayment['pay_amount']*1;
1010 $PaymentDB=$PaymentDB == 0 ? '' : $PaymentDB;
1012 $resPayment = sqlStatement("SELECT pay_amount from ar_activity where session_id ='$payment_id' and
1013 pid ='$PId' and encounter ='$Encounter' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and pay_amount<0");
1014 $rowPayment = sqlFetchArray($resPayment);
1015 $TakebackDB=$rowPayment['pay_amount']*-1;
1016 $TakebackDB=$TakebackDB == 0 ? '' : $TakebackDB;
1018 $resPayment = sqlStatement("SELECT adj_amount from ar_activity where session_id ='$payment_id' and
1019 pid ='$PId' and encounter ='$Encounter' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and adj_amount!=0");
1020 $rowPayment = sqlFetchArray($resPayment);
1021 $AdjAmountDB=$rowPayment['adj_amount']*1;
1022 $AdjAmountDB=$AdjAmountDB == 0 ? '' : $AdjAmountDB;
1024 $resPayment = sqlStatement("SELECT memo from ar_activity where session_id ='$payment_id' and
1025 pid ='$PId' and encounter ='$Encounter' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and (memo like 'Deductable%' OR memo like 'Deductible%')");
1026 $rowPayment = sqlFetchArray($resPayment);
1027 $DeductibleDB=$rowPayment['memo'];
1028 $DeductibleDB=str_replace('Deductable $','',$DeductibleDB);
1029 $DeductibleDB=str_replace('Deductible $','',$DeductibleDB);
1031 $resPayment = sqlStatement("SELECT follow_up,follow_up_note from ar_activity where session_id ='$payment_id' and
1032 pid ='$PId' and encounter ='$Encounter' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and follow_up = 'y'");
1033 $rowPayment = sqlFetchArray($resPayment);
1034 $FollowUpDB=$rowPayment['follow_up'];
1035 $FollowUpReasonDB=$rowPayment['follow_up_note'];
1037 $resPayment = sqlStatement("SELECT reason_code from ar_activity where session_id ='$payment_id' and
1038 pid ='$PId' and encounter ='$Encounter' and code_type='$Codetype' and code='$Code' and modifier='$Modifier'");
1039 $rowPayment = sqlFetchArray($resPayment);
1040 $ReasonCodeDB=$rowPayment['reason_code'];
1042 if($Ins==1)
1044 $AllowedDB=number_format($Fee-$AdjAmountDB,2);
1046 else
1048 $AllowedDB = 0;
1050 $AllowedDB=$AllowedDB == 0 ? '' : $AllowedDB;
1052 if($CountIndex==$TotalRows)
1054 $StringClass=' bottom left top ';
1056 else
1058 $StringClass=' left top ';
1061 if($Ins==1)
1063 $bgcolor='#ddddff';
1065 elseif($Ins==2)
1067 $bgcolor='#ffdddd';
1069 elseif($Ins==3)
1071 $bgcolor='#F2F1BC';
1073 elseif($Ins==0)
1075 $bgcolor='#AAFFFF';
1077 $paymenttot=$paymenttot+$PaymentDB;
1078 $adjamttot=$adjamttot+$AdjAmountDB;
1079 $deductibletot=$deductibletot+$DeductibleDB;
1080 $takebacktot=$takebacktot+$TakebackDB;
1081 $allowedtot=$allowedtot+$AllowedDB;
1083 <tr class="text" bgcolor='<?php echo $bgcolor; ?>' id="trCharges<?php echo $CountIndex; ?>">
1084 <td align="left" class="<?php echo $StringClass; ?>" ><a href="#" onClick="javascript:return DeletePaymentDistribution('<?php echo htmlspecialchars($payment_id.'_'.$PId.'_'.$Encounter.'_'.$Code.'_'.$Modifier.'_'.$Codetype); ?>');" ><img src="../pic/Delete.gif" border="0"/></a></td>
1085 <td align="left" class="<?php echo $StringClass; ?>" ><?php echo htmlspecialchars($NameDB); ?><input name="HiddenPId<?php echo $CountIndex; ?>" value="<?php echo htmlspecialchars($PId); ?>" type="hidden"/></td>
1086 <td align="left" class="<?php echo $StringClass; ?>" ><input name="HiddenIns<?php echo $CountIndex; ?>" id="HiddenIns<?php echo $CountIndex; ?>" value="<?php echo htmlspecialchars($Ins); ?>" type="hidden"/><?php echo generate_select_list("payment_ins$CountIndex", "payment_ins", "$Ins", "Insurance/Patient",'','','ActionOnInsPat("'.$CountIndex.'")'); ?></td>
1087 <td class="<?php echo $StringClass; ?>" ><?php echo htmlspecialchars($ServiceDate); ?></td>
1088 <td align="right" class="<?php echo $StringClass; ?>" ><input name="HiddenEncounter<?php echo $CountIndex; ?>" value="<?php echo htmlspecialchars($Encounter); ?>" type="hidden"/><?php echo htmlspecialchars($Encounter); ?></td>
1089 <td class="<?php echo $StringClass; ?>" ><input name="HiddenCodetype<?php echo $CountIndex; ?>" value="<?php echo htmlspecialchars($Codetype); ?>" type="hidden"/><input name="HiddenCode<?php echo $CountIndex; ?>" value="<?php echo htmlspecialchars($Code); ?>" type="hidden"/><?php echo htmlspecialchars($Codetype."-".$Code.$ModifierString); ?><input name="HiddenModifier<?php echo $CountIndex; ?>" value="<?php echo htmlspecialchars($Modifier); ?>" type="hidden"/></td>
1090 <td align="right" class="<?php echo $StringClass; ?>" ><input name="HiddenChargeAmount<?php echo $CountIndex; ?>" id="HiddenChargeAmount<?php echo $CountIndex; ?>" value="<?php echo htmlspecialchars($Fee); ?>" type="hidden"/><?php echo htmlspecialchars($Fee); ?></td>
1091 <td align="right" class="<?php echo $StringClass; ?>" ><input name="HiddenCopayAmount<?php echo $CountIndex; ?>" id="HiddenCopayAmount<?php echo $CountIndex; ?>" value="<?php echo htmlspecialchars($Copay); ?>" type="hidden"/><?php echo htmlspecialchars(number_format($Copay,2)); ?></td>
1092 <td align="right" id="RemainderTd<?php echo $CountIndex; ?>" class="<?php echo $StringClass; ?>" ><?php echo htmlspecialchars(round($Remainder,2)); ?></td>
1093 <input name="HiddenRemainderTd<?php echo $CountIndex; ?>" id="HiddenRemainderTd<?php echo $CountIndex; ?>" value="<?php echo htmlspecialchars(round($RemainderJS,2)); ?>" type="hidden"/>
1094 <td class="<?php echo $StringClass; ?>" ><input name="Allowed<?php echo $CountIndex; ?>" id="Allowed<?php echo $CountIndex; ?>" onKeyDown="PreventIt(event)" autocomplete="off" value="<?php echo htmlspecialchars($AllowedDB); ?>" onChange="ValidateNumeric(this);ScreenAdjustment(this,<?php echo $CountIndex; ?>);UpdateTotalValues(1,<?php echo $TotalRows; ?>,'Allowed','allowtotal');UpdateTotalValues(1,<?php echo $TotalRows; ?>,'Payment','paymenttotal');UpdateTotalValues(1,<?php echo $TotalRows; ?>,'AdjAmount','AdjAmounttotal');RestoreValues(<?php echo $CountIndex; ?>)" type="text" style="width:60px;text-align:right; font-size:12px" /></td>
1095 <td class="<?php echo $StringClass; ?>" ><input type="text" name="Payment<?php echo $CountIndex; ?>" onKeyDown="PreventIt(event)" autocomplete="off" id="Payment<?php echo $CountIndex; ?>" value="<?php echo htmlspecialchars($PaymentDB); ?>" onChange="ValidateNumeric(this);ScreenAdjustment(this,<?php echo $CountIndex; ?>);UpdateTotalValues(1,<?php echo $TotalRows; ?>,'Payment','paymenttotal');RestoreValues(<?php echo $CountIndex; ?>)" style="width:60px;text-align:right; font-size:12px" /></td>
1096 <td class="<?php echo $StringClass; ?>" ><input name="AdjAmount<?php echo $CountIndex; ?>" onKeyDown="PreventIt(event)" autocomplete="off" id="AdjAmount<?php echo $CountIndex; ?>" value="<?php echo htmlspecialchars($AdjAmountDB); ?>" onChange="ValidateNumeric(this);ScreenAdjustment(this,<?php echo $CountIndex; ?>);UpdateTotalValues(1,<?php echo $TotalRows; ?>,'AdjAmount','AdjAmounttotal');RestoreValues(<?php echo $CountIndex; ?>)" type="text" style="width:70px;text-align:right; font-size:12px" /></td>
1097 <td class="<?php echo $StringClass; ?>" ><input name="Deductible<?php echo $CountIndex; ?>" id="Deductible<?php echo $CountIndex; ?>" onKeyDown="PreventIt(event)" onChange="ValidateNumeric(this);UpdateTotalValues(1,<?php echo $TotalRows; ?>,'Deductible','deductibletotal');" value="<?php echo htmlspecialchars($DeductibleDB); ?>" autocomplete="off" type="text" style="width:60px;text-align:right; font-size:12px" /></td>
1098 <td class="<?php echo $StringClass; ?>" ><input name="Takeback<?php echo $CountIndex; ?>" onKeyDown="PreventIt(event)" autocomplete="off" id="Takeback<?php echo $CountIndex; ?>" value="<?php echo htmlspecialchars($TakebackDB); ?>" onChange="ValidateNumeric(this);ScreenAdjustment(this,<?php echo $CountIndex; ?>);UpdateTotalValues(1,<?php echo $TotalRows; ?>,'Takeback','takebacktotal');RestoreValues(<?php echo $CountIndex; ?>)" type="text" style="width:60px;text-align:right; font-size:12px" /></td>
1099 <td align="left" class="<?php echo $StringClass; ?>" ><input name="HiddenReasonCode<?php echo $CountIndex; ?>" id="HiddenReasonCode<?php echo $CountIndex; ?>" value="<?php echo htmlspecialchars($ReasonCodeDB); ?>" type="hidden"/><?php echo generate_select_list( "ReasonCode$CountIndex", "msp_remit_codes", "$ReasonCodeDB", "MSP Code" ); ?></td>
1100 <td align="center" class="<?php echo $StringClass; ?>" ><input type="checkbox" id="FollowUp<?php echo $CountIndex; ?>" name="FollowUp<?php echo $CountIndex; ?>" value="y" onClick="ActionFollowUp(<?php echo $CountIndex; ?>)" <?php echo $FollowUpDB=='y' ? ' checked ' : ''; ?> /></td>
1101 <td class="<?php echo $StringClass; ?> right" ><input onKeyDown="PreventIt(event)" id="FollowUpReason<?php echo $CountIndex; ?>" name="FollowUpReason<?php echo $CountIndex; ?>" <?php echo $FollowUpDB=='y' ? '' : ' readonly '; ?> type="text" value="<?php echo htmlspecialchars($FollowUpReasonDB); ?>" style="width:110px;font-size:12px" /></td>
1102 </tr>
1103 <?php
1106 }//while ($RowSearch = sqlFetchArray($ResultSearch))
1108 <?php
1109 }//if(sqlNumRows($ResultSearch)>0)
1111 }while ($RowSearchSub = sqlFetchArray($ResultSearchSub));
1112 if($Table=='yes')
1115 <tr class="text">
1116 <td align="left" colspan="9">&nbsp;</td>
1117 <td class="left bottom" bgcolor="#6699FF" id="allowtotal" align="right" ><?php echo htmlspecialchars(number_format($allowedtot,2)); ?></td>
1118 <td class="left bottom" bgcolor="#6699FF" id="paymenttotal" align="right" ><?php echo htmlspecialchars(number_format($paymenttot,2)); ?></td>
1119 <td class="left bottom" bgcolor="#6699FF" id="AdjAmounttotal" align="right" ><?php echo htmlspecialchars(number_format($adjamttot,2)); ?></td>
1120 <td class="left bottom" bgcolor="#6699FF" id="deductibletotal" align="right"><?php echo htmlspecialchars(number_format($deductibletot,2)); ?></td>
1121 <td class="left bottom right" bgcolor="#6699FF" id="takebacktotal" align="right"><?php echo htmlspecialchars(number_format($takebacktot,2)); ?></td>
1122 <td align="center">&nbsp;</td>
1123 <td align="center">&nbsp;</td>
1124 </tr>
1125 </table>
1126 <?php
1129 <?php
1131 echo '<br/>';
1133 }//if($RowSearchSub = sqlFetchArray($ResultSearchSub))
1134 ?> </td>
1135 </tr>
1136 <tr>
1137 <td colspan="13" align="left" >
1138 <?php
1139 require_once("payment_pat_sel.inc.php"); //Patient ajax section and listing of charges.
1141 </td>
1142 </tr>
1143 <tr>
1144 <td colspan="13" align="left" >
1145 <table border="0" cellspacing="0" cellpadding="0" width="217" align="center">
1146 <tr height="5">
1147 <td ></td>
1148 <td ></td>
1149 <td></td>
1150 </tr>
1151 <tr>
1152 <td width="110"><a href="#" onClick="javascript:return ModifyPayments();" class="css_button"><span><?php echo htmlspecialchars( xl('Modify Payments'), ENT_QUOTES);?></span></a>
1153 </td>
1154 <td width="107"><a href="#" onClick="javascript:return FinishPayments();" class="css_button"><span><?php echo htmlspecialchars( xl('Finish Payments'), ENT_QUOTES);?></span></a>
1155 </td>
1156 </tr>
1157 </table>
1159 <?php
1160 }//if($payment_id*1>0)
1161 ?> </td>
1162 </tr>
1163 </table>
1164 </td></tr></table>
1166 <input type="hidden" name="hidden_patient_code" id="hidden_patient_code" value="<?php echo htmlspecialchars($hidden_patient_code);?>"/>
1167 <input type='hidden' name='mode' id='mode' value='' />
1168 <input type='hidden' name='ajax_mode' id='ajax_mode' value='' />
1169 <input type="hidden" name="after_value" id="after_value" value="<?php echo htmlspecialchars($_POST["mode"]);?>"/>
1170 <input type="hidden" name="payment_id" id="payment_id" value="<?php echo htmlspecialchars($payment_id);?>"/>
1171 <input type="hidden" name="hidden_type_code" id="hidden_type_code" value="<?php echo htmlspecialchars($TypeCode);?>"/>
1172 <input type='hidden' name='global_amount' id='global_amount' value='' />
1173 <input type='hidden' name='DeletePaymentDistributionId' id='DeletePaymentDistributionId' value='' />
1174 <input type="hidden" name="ActionStatus" id="ActionStatus" value="<?php echo htmlspecialchars($Message);?>"/>
1175 <input type='hidden' name='CountIndexAbove' id='CountIndexAbove' value='<?php echo htmlspecialchars($CountIndexAbove*1);?>' />
1176 <input type='hidden' name='CountIndexBelow' id='CountIndexBelow' value='<?php echo htmlspecialchars($CountIndexBelow*1);?>' />
1177 <input type="hidden" name="ParentPage" id="ParentPage" value="<?php echo htmlspecialchars($_REQUEST['ParentPage']);?>"/>
1178 </form>
1180 </body>
1181 </html>