Feature to add drug-drug interaction checking for the
[openemr.git] / interface / billing / edit_payment.php
blob819df42cd3ff0542ab1948d769e879d3c4595b04
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.
22 //
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/sql.inc");
38 require_once("$srcdir/auth.inc");
39 require_once("$srcdir/formdata.inc.php");
40 require_once("../../custom/code_types.inc.php");
41 require_once("$srcdir/patient.inc");
42 require_once("$srcdir/billrep.inc");
43 require_once(dirname(__FILE__) . "/../../library/classes/OFX.class.php");
44 require_once(dirname(__FILE__) . "/../../library/classes/X12Partner.class.php");
45 require_once("$srcdir/options.inc.php");
46 require_once("$srcdir/formatting.inc.php");
47 require_once("$srcdir/payment.inc.php");
48 //===============================================================================
49 $screen='edit_payment';
50 //===============================================================================
51 // deletion of payment distribution code
52 //===============================================================================
53 if (isset($_POST["mode"]))
55 if ($_POST["mode"] == "DeletePaymentDistribution")
57 $DeletePaymentDistributionId=trim(formData('DeletePaymentDistributionId' ));
58 $DeletePaymentDistributionIdArray=explode('_',$DeletePaymentDistributionId);
59 $payment_id=$DeletePaymentDistributionIdArray[0];
60 $PId=$DeletePaymentDistributionIdArray[1];
61 $Encounter=$DeletePaymentDistributionIdArray[2];
62 $Code=$DeletePaymentDistributionIdArray[3];
63 $Modifier=$DeletePaymentDistributionIdArray[4];
64 $Codetype=$DeletePaymentDistributionIdArray[5];
65 //delete and log that action
66 row_delete("ar_activity", "session_id ='$payment_id' and pid ='$PId' AND " .
67 "encounter='$Encounter' and code_type='$Codetype' and code='$Code' and modifier='$Modifier'");
68 $Message='Delete';
69 //------------------
70 $_POST["mode"] = "searchdatabase";
73 //===============================================================================
74 //Modify Payment Code.
75 //===============================================================================
76 if (isset($_POST["mode"]))
78 if ($_POST["mode"] == "ModifyPayments" || $_POST["mode"] == "FinishPayments")
80 $payment_id=$_REQUEST['payment_id'];
81 //ar_session Code
82 //===============================================================================
83 if(trim(formData('type_name' ))=='insurance')
85 $QueryPart="payer_id = '" . trim(formData('hidden_type_code' )) .
86 "', patient_id = '" . 0 ;
88 elseif(trim(formData('type_name' ))=='patient')
90 $QueryPart="payer_id = '" . 0 .
91 "', patient_id = '" . trim(formData('hidden_type_code' )) ;
93 $user_id=$_SESSION['authUserID'];
94 $closed=0;
95 $modified_time = date('Y-m-d H:i:s');
96 $check_date=DateToYYYYMMDD(formData('check_date'));
97 $deposit_date=DateToYYYYMMDD(formData('deposit_date'));
98 $post_to_date=DateToYYYYMMDD(formData('post_to_date'));
99 if($post_to_date=='')
100 $post_to_date=date('Y-m-d');
101 if(formData('deposit_date')=='')
102 $deposit_date=$post_to_date;
104 sqlStatement("update ar_session set " .
105 $QueryPart .
106 "', user_id = '" . trim($user_id ) .
107 "', closed = '" . trim($closed ) .
108 "', reference = '" . trim(formData('check_number' )) .
109 "', check_date = '" . trim($check_date ) .
110 "', deposit_date = '" . trim($deposit_date ) .
111 "', pay_total = '" . trim(formData('payment_amount')) .
112 "', modified_time = '" . trim($modified_time ) .
113 "', payment_type = '" . trim(formData('type_name' )) .
114 "', description = '" . trim(formData('description' )) .
115 "', adjustment_code = '" . trim(formData('adjustment_code' )) .
116 "', post_to_date = '" . trim($post_to_date ) .
117 "', payment_method = '" . trim(formData('payment_method' )) .
118 "' where session_id='$payment_id'");
119 //===============================================================================
120 $CountIndexAbove=$_REQUEST['CountIndexAbove'];
121 $CountIndexBelow=$_REQUEST['CountIndexBelow'];
122 $hidden_patient_code=$_REQUEST['hidden_patient_code'];
123 $user_id=$_SESSION['authUserID'];
124 $created_time = date('Y-m-d H:i:s');
125 //==================================================================
126 //UPDATION
127 //It is done with out deleting any old entries.
128 //==================================================================
129 for($CountRow=1;$CountRow<=$CountIndexAbove;$CountRow++)
131 if (isset($_POST["HiddenEncounter$CountRow"]))
133 if (isset($_POST["Payment$CountRow"]) && $_POST["Payment$CountRow"]*1>0)
135 if(trim(formData('type_name' ))=='insurance')
137 if(trim(formData("HiddenIns$CountRow" ))==1)
139 $AccountCode="IPP";
141 if(trim(formData("HiddenIns$CountRow" ))==2)
143 $AccountCode="ISP";
145 if(trim(formData("HiddenIns$CountRow" ))==3)
147 $AccountCode="ITP";
150 elseif(trim(formData('type_name' ))=='patient')
152 $AccountCode="PP";
154 $resPayment = sqlStatement("SELECT * from ar_activity " .
155 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow" )) .
156 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow" )) .
157 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow" )) .
158 "' and code ='" . trim(formData("HiddenCode$CountRow" )) .
159 "' and modifier ='" . trim(formData("HiddenModifier$CountRow" )) .
160 "' and pay_amount>0");
161 if(sqlNumRows($resPayment)>0)
163 sqlStatement("update ar_activity set " .
164 " post_user = '" . trim($user_id ) .
165 "', modified_time = '" . trim($created_time ) .
166 "', pay_amount = '" . trim(formData("Payment$CountRow" )) .
167 "', account_code = '" . "$AccountCode" .
168 "', payer_type = '" . trim(formData("HiddenIns$CountRow" )) .
169 "', reason_code = '" . trim(formData("ReasonCode$CountRow" )) .
170 "' where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow" )) .
171 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow" )) .
172 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow" )) .
173 "' and code ='" . trim(formData("HiddenCode$CountRow" )) .
174 "' and modifier ='" . trim(formData("HiddenModifier$CountRow" )) .
175 "' and pay_amount>0");
177 else
179 sqlBeginTrans();
180 $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" ))));
181 sqlStatement("insert into ar_activity set " .
182 "pid = '" . trim(formData("HiddenPId$CountRow" )) .
183 "', encounter = '" . trim(formData("HiddenEncounter$CountRow" )) .
184 "', sequence_no = '" . $sequence_no['increment'] .
185 "', code_type = '" . trim(formData("HiddenCodetype$CountRow" )) .
186 "', code = '" . trim(formData("HiddenCode$CountRow" )) .
187 "', modifier = '" . trim(formData("HiddenModifier$CountRow" )) .
188 "', payer_type = '" . trim(formData("HiddenIns$CountRow" )) .
189 "', reason_code = '" . trim(formData("ReasonCode$CountRow" )) .
190 "', post_time = '" . trim($created_time ) .
191 "', post_user = '" . trim($user_id ) .
192 "', session_id = '" . trim(formData('payment_id')) .
193 "', modified_time = '" . trim($created_time ) .
194 "', pay_amount = '" . trim(formData("Payment$CountRow" )) .
195 "', adj_amount = '" . 0 .
196 "', account_code = '" . "$AccountCode" .
197 "'");
198 sqlCommitTrans();
201 else
203 sqlStatement("delete from ar_activity " .
204 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow" )) .
205 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow" )) .
206 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow" )) .
207 "' and code ='" . trim(formData("HiddenCode$CountRow" )) .
208 "' and modifier ='" . trim(formData("HiddenModifier$CountRow" )) .
209 "' and pay_amount>0");
211 //==============================================================================================================================
212 if (isset($_POST["AdjAmount$CountRow"]) && $_POST["AdjAmount$CountRow"]*1!=0)
214 if(trim(formData('type_name' ))=='insurance')
216 $AdjustString="Ins adjust Ins".trim(formData("HiddenIns$CountRow" ));
217 $AccountCode="IA";
219 elseif(trim(formData('type_name' ))=='patient')
221 $AdjustString="Pt adjust";
222 $AccountCode="PA";
224 $resPayment = sqlStatement("SELECT * from ar_activity " .
225 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow" )) .
226 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow" )) .
227 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow" )) .
228 "' and code ='" . trim(formData("HiddenCode$CountRow" )) .
229 "' and modifier ='" . trim(formData("HiddenModifier$CountRow" )) .
230 "' and adj_amount!=0");
231 if(sqlNumRows($resPayment)>0)
233 sqlStatement("update ar_activity set " .
234 " post_user = '" . trim($user_id ) .
235 "', modified_time = '" . trim($created_time ) .
236 "', adj_amount = '" . trim(formData("AdjAmount$CountRow" )) .
237 "', memo = '" . "$AdjustString" .
238 "', account_code = '" . "$AccountCode" .
239 "', payer_type = '" . trim(formData("HiddenIns$CountRow" )) .
240 "' where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow" )) .
241 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow" )) .
242 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow" )) .
243 "' and code ='" . trim(formData("HiddenCode$CountRow" )) .
244 "' and modifier ='" . trim(formData("HiddenModifier$CountRow" )) .
245 "' and adj_amount!=0");
247 else
249 sqlBeginTrans();
250 $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" ))));
251 sqlStatement("insert into ar_activity set " .
252 "pid = '" . trim(formData("HiddenPId$CountRow" )) .
253 "', encounter = '" . trim(formData("HiddenEncounter$CountRow" )) .
254 "', sequence_no = '" . $sequence_no['increment'] .
255 "', code_type = '" . trim(formData("HiddenCodetype$CountRow" )) .
256 "', code = '" . trim(formData("HiddenCode$CountRow" )) .
257 "', modifier = '" . trim(formData("HiddenModifier$CountRow" )) .
258 "', payer_type = '" . trim(formData("HiddenIns$CountRow" )) .
259 "', post_time = '" . trim($created_time ) .
260 "', post_user = '" . trim($user_id ) .
261 "', session_id = '" . trim(formData('payment_id')) .
262 "', modified_time = '" . trim($created_time ) .
263 "', pay_amount = '" . 0 .
264 "', adj_amount = '" . trim(formData("AdjAmount$CountRow" )) .
265 "', memo = '" . "$AdjustString" .
266 "', account_code = '" . "$AccountCode" .
267 "'");
268 sqlCommitTrans();
272 else
274 sqlStatement("delete from ar_activity " .
275 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow" )) .
276 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow" )) .
277 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow" )) .
278 "' and code ='" . trim(formData("HiddenCode$CountRow" )) .
279 "' and modifier ='" . trim(formData("HiddenModifier$CountRow" )) .
280 "' and adj_amount!=0");
282 //==============================================================================================================================
283 if (isset($_POST["Deductible$CountRow"]) && $_POST["Deductible$CountRow"]*1>0)
285 $resPayment = sqlStatement("SELECT * from ar_activity " .
286 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow" )) .
287 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow" )) .
288 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow" )) .
289 "' and code ='" . trim(formData("HiddenCode$CountRow" )) .
290 "' and modifier ='" . trim(formData("HiddenModifier$CountRow" )) .
291 "' and memo like 'Deductable%'");
292 if(sqlNumRows($resPayment)>0)
294 sqlStatement("update ar_activity set " .
295 " post_user = '" . trim($user_id ) .
296 "', modified_time = '" . trim($created_time ) .
297 "', memo = '" . "Deductable $".trim(formData("Deductible$CountRow" )) .
298 "', account_code = '" . "Deduct" .
299 "', payer_type = '" . trim(formData("HiddenIns$CountRow" )) .
300 "' where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow" )) .
301 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow" )) .
302 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow" )) .
303 "' and code ='" . trim(formData("HiddenCode$CountRow" )) .
304 "' and modifier ='" . trim(formData("HiddenModifier$CountRow" )) .
305 "' and memo like 'Deductable%'");
307 else
309 sqlBeginTrans();
310 $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"))));
311 sqlStatement("insert into ar_activity set " .
312 "pid = '" . trim(formData("HiddenPId$CountRow" )) .
313 "', encounter = '" . trim(formData("HiddenEncounter$CountRow" )) .
314 "', sequence_no = '" . $sequence_no['increment'] .
315 "', code_type = '" . trim(formData("HiddenCodetype$CountRow" )) .
316 "', code = '" . trim(formData("HiddenCode$CountRow" )) .
317 "', modifier = '" . trim(formData("HiddenModifier$CountRow" )) .
318 "', payer_type = '" . trim(formData("HiddenIns$CountRow" )) .
319 "', post_time = '" . trim($created_time ) .
320 "', post_user = '" . trim($user_id ) .
321 "', session_id = '" . trim(formData('payment_id')) .
322 "', modified_time = '" . trim($created_time ) .
323 "', pay_amount = '" . 0 .
324 "', adj_amount = '" . 0 .
325 "', memo = '" . "Deductable $".trim(formData("Deductible$CountRow" )) .
326 "', account_code = '" . "Deduct" .
327 "'");
328 sqlCommitTrans();
331 else
333 sqlStatement("delete from ar_activity " .
334 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow" )) .
335 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow" )) .
336 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow" )) .
337 "' and code ='" . trim(formData("HiddenCode$CountRow" )) .
338 "' and modifier ='" . trim(formData("HiddenModifier$CountRow" )) .
339 "' and memo like 'Deductable%'");
341 //==============================================================================================================================
342 if (isset($_POST["Takeback$CountRow"]) && $_POST["Takeback$CountRow"]*1>0)
344 $resPayment = sqlStatement("SELECT * from ar_activity " .
345 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow" )) .
346 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow" )) .
347 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow" )) .
348 "' and code ='" . trim(formData("HiddenCode$CountRow" )) .
349 "' and modifier ='" . trim(formData("HiddenModifier$CountRow" )) .
350 "' and pay_amount < 0");
351 if(sqlNumRows($resPayment)>0)
353 sqlStatement("update ar_activity set " .
354 " post_user = '" . trim($user_id ) .
355 "', modified_time = '" . trim($created_time ) .
356 "', pay_amount = '" . trim(formData("Takeback$CountRow" ))*-1 .
357 "', account_code = '" . "Takeback" .
358 "', payer_type = '" . trim(formData("HiddenIns$CountRow" )) .
359 "' where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow" )) .
360 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow" )) .
361 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow" )) .
362 "' and code ='" . trim(formData("HiddenCode$CountRow" )) .
363 "' and modifier ='" . trim(formData("HiddenModifier$CountRow" )) .
364 "' and pay_amount < 0");
366 else
368 sqlBeginTrans();
369 $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" ))));
370 sqlStatement("insert into ar_activity set " .
371 "pid = '" . trim(formData("HiddenPId$CountRow" )) .
372 "', encounter = '" . trim(formData("HiddenEncounter$CountRow" )) .
373 "', sequence_no = '" . $sequence_no['increment'] .
374 "', code_type = '" . trim(formData("HiddenCodetype$CountRow" )) .
375 "', code = '" . trim(formData("HiddenCode$CountRow" )) .
376 "', modifier = '" . trim(formData("HiddenModifier$CountRow" )) .
377 "', payer_type = '" . trim(formData("HiddenIns$CountRow" )) .
378 "', post_time = '" . trim($created_time ) .
379 "', post_user = '" . trim($user_id ) .
380 "', session_id = '" . trim(formData('payment_id')) .
381 "', modified_time = '" . trim($created_time ) .
382 "', pay_amount = '" . trim(formData("Takeback$CountRow" ))*-1 .
383 "', adj_amount = '" . 0 .
384 "', account_code = '" . "Takeback" .
385 "'");
386 sqlCommitTrans();
389 else
391 sqlStatement("delete from ar_activity " .
392 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow" )) .
393 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow" )) .
394 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow" )) .
395 "' and code ='" . trim(formData("HiddenCode$CountRow" )) .
396 "' and modifier ='" . trim(formData("HiddenModifier$CountRow" )) .
397 "' and pay_amount < 0");
399 //==============================================================================================================================
400 if (isset($_POST["FollowUp$CountRow"]) && $_POST["FollowUp$CountRow"]=='y')
402 $resPayment = sqlStatement("SELECT * from ar_activity " .
403 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow" )) .
404 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow" )) .
405 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow" )) .
406 "' and code ='" . trim(formData("HiddenCode$CountRow" )) .
407 "' and modifier ='" . trim(formData("HiddenModifier$CountRow" )) .
408 "' and follow_up ='y'");
409 if(sqlNumRows($resPayment)>0)
411 sqlStatement("update ar_activity set " .
412 " post_user = '" . trim($user_id ) .
413 "', modified_time = '" . trim($created_time ) .
414 "', follow_up = '" . "y" .
415 "', follow_up_note = '" . trim(formData("FollowUpReason$CountRow" )) .
416 "', payer_type = '" . trim(formData("HiddenIns$CountRow" )) .
417 "' where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow" )) .
418 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow" )) .
419 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow" )) .
420 "' and code ='" . trim(formData("HiddenCode$CountRow" )) .
421 "' and modifier ='" . trim(formData("HiddenModifier$CountRow" )) .
422 "' and follow_up ='y'");
424 else
426 sqlBeginTrans();
427 $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" ))));
428 sqlStatement("insert into ar_activity set " .
429 "pid = '" . trim(formData("HiddenPId$CountRow" )) .
430 "', encounter = '" . trim(formData("HiddenEncounter$CountRow" )) .
431 "', sequence_no = '" . $sequence_no['increment'] .
432 "', code_type = '" . trim(formData("HiddenCodetype$CountRow" )) .
433 "', code = '" . trim(formData("HiddenCode$CountRow" )) .
434 "', modifier = '" . trim(formData("HiddenModifier$CountRow" )) .
435 "', payer_type = '" . trim(formData("HiddenIns$CountRow" )) .
436 "', post_time = '" . trim($created_time ) .
437 "', post_user = '" . trim($user_id ) .
438 "', session_id = '" . trim(formData('payment_id')) .
439 "', modified_time = '" . trim($created_time ) .
440 "', pay_amount = '" . 0 .
441 "', adj_amount = '" . 0 .
442 "', follow_up = '" . "y" .
443 "', follow_up_note = '" . trim(formData("FollowUpReason$CountRow" )) .
444 "'");
445 sqlCommitTrans();
448 else
450 sqlStatement("delete from ar_activity " .
451 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow" )) .
452 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow" )) .
453 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow" )) .
454 "' and code ='" . trim(formData("HiddenCode$CountRow" )) .
455 "' and modifier ='" . trim(formData("HiddenModifier$CountRow" )) .
456 "' and follow_up ='y'");
458 //==============================================================================================================================
460 else
461 break;
463 //=========
464 //INSERTION of new entries,continuation of modification.
465 //=========
466 for($CountRow=$CountIndexAbove+1;$CountRow<=$CountIndexAbove+$CountIndexBelow;$CountRow++)
468 if (isset($_POST["HiddenEncounter$CountRow"]))
470 DistributionInsert($CountRow,$created_time,$user_id);
472 else
473 break;
475 if($_REQUEST['global_amount']=='yes')
476 sqlStatement("update ar_session set global_amount=".trim(formData("HidUnappliedAmount" ))*1 ." where session_id ='$payment_id'");
477 if($_POST["mode"]=="FinishPayments")
479 $Message='Finish';
481 $_POST["mode"] = "searchdatabase";
482 $Message='Modify';
485 //==============================================================================
486 //Search Code
487 //===============================================================================
488 $payment_id=$payment_id*1 > 0 ? $payment_id : $_REQUEST['payment_id'];
489 $ResultSearchSub = sqlStatement("SELECT distinct encounter,code_type,code,modifier, pid from ar_activity where session_id ='$payment_id' order by pid,encounter,code,modifier");
490 //==============================================================================
491 $DateFormat=DateFormatRead();
492 //==============================================================================
493 //===============================================================================
496 <html>
497 <head>
498 <?php if (function_exists('html_header_show')) html_header_show(); ?>
500 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
502 <!-- supporting javascript code -->
504 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js"></script>
508 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
509 <link rel="stylesheet" type="text/css" href="../../library/js/fancybox/jquery.fancybox-1.2.6.css" media="screen" />
510 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
511 <script type="text/javascript" src="../../library/textformat.js"></script>
512 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
513 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
514 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
515 <script type="text/javascript" src="../../library/dialog.js"></script>
516 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-3-2/index.js"></script>
517 <script type="text/javascript" src="../../library/js/fancybox/jquery.fancybox-1.2.6.js"></script>
518 <script language='JavaScript'>
519 var mypcc = '1';
520 </script>
521 <?php include_once("{$GLOBALS['srcdir']}/payment_jav.inc.php"); ?>
522 <?php include_once("{$GLOBALS['srcdir']}/ajax/payment_ajax_jav.inc.php"); ?>
523 <script type="text/javascript" src="../../library/js/common.js"></script>
524 <script LANGUAGE="javascript" TYPE="text/javascript">
525 function ModifyPayments()
526 {//Used while modifying the allocation
527 if(!FormValidations())//FormValidations contains the form checks
529 return false;
531 if(CompletlyBlankAbove())//The distribution rows already in the database are checked.
533 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) ?>")
534 return false;
536 if(!CheckPayingEntityAndDistributionPostFor())//Ensures that Insurance payment is distributed under Ins1,Ins2,Ins3 and Patient paymentat under Pat.
538 return false;
540 if(CompletlyBlankBelow())//The newly added distribution rows are checked.
542 alert("<?php echo htmlspecialchars( xl('Fill any of the Below Row.'), ENT_QUOTES) ?>")
543 return false;
545 PostValue=CheckUnappliedAmount();//Decides TdUnappliedAmount >0, or <0 or =0
546 if(PostValue==1)
548 alert("<?php echo htmlspecialchars( xl('Cannot Modify Payments.Undistributed is Negative.'), ENT_QUOTES) ?>")
549 return false;
551 if(confirm("<?php echo htmlspecialchars( xl('Would you like to Modify Payments?'), ENT_QUOTES) ?>"))
553 document.getElementById('mode').value='ModifyPayments';
554 top.restoreSession();
555 document.forms[0].submit();
557 else
558 return false;
560 function FinishPayments()
562 if(!FormValidations())//FormValidations contains the form checks
564 return false;
566 if(CompletlyBlankAbove())//The distribution rows already in the database are checked.
568 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) ?>")
569 return false;
571 if(!CheckPayingEntityAndDistributionPostFor())//Ensures that Insurance payment is distributed under Ins1,Ins2,Ins3 and Patient paymentat under Pat.
573 return false;
575 if(CompletlyBlankBelow())//The newly added distribution rows are checked.
577 alert("<?php echo htmlspecialchars( xl('Fill any of the Below Row.'), ENT_QUOTES) ?>")
578 return false;
580 PostValue=CheckUnappliedAmount();//Decides TdUnappliedAmount >0, or <0 or =0
581 if(PostValue==1)
583 alert("<?php echo htmlspecialchars( xl('Cannot Modify Payments.Undistributed is Negative.'), ENT_QUOTES) ?>")
584 return false;
586 if(PostValue==2)
588 if(confirm("<?php echo htmlspecialchars( xl('Would you like to Modify and Finish Payments?'), ENT_QUOTES) ?>"))
590 UnappliedAmount=document.getElementById('TdUnappliedAmount').innerHTML*1;
591 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) ?>"))
593 document.getElementById('mode').value='FinishPayments';
594 document.getElementById('global_amount').value='yes';
595 top.restoreSession();
596 document.forms[0].submit();
598 else
600 document.getElementById('mode').value='FinishPayments';
601 top.restoreSession();
602 document.forms[0].submit();
605 else
606 return false;
608 else
610 if(confirm("<?php echo htmlspecialchars( xl('Would you like to Modify and Finish Payments?'), ENT_QUOTES) ?>"))
612 document.getElementById('mode').value='FinishPayments';
613 top.restoreSession();
614 document.forms[0].submit();
616 else
617 return false;
621 function CompletlyBlankAbove()
622 {//The distribution rows already in the database are checked.
623 //It is not allowed to be made completly empty.If needed delete option need to be used.
624 CountIndexAbove=document.getElementById('CountIndexAbove').value*1;
625 for(RowCount=1;RowCount<=CountIndexAbove;RowCount++)
627 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)
629 return true;
632 return false;
634 function CompletlyBlankBelow()
635 {//The newly added distribution rows are checked.
636 //It is not allowed to be made completly empty.
637 CountIndexAbove=document.getElementById('CountIndexAbove').value*1;
638 CountIndexBelow=document.getElementById('CountIndexBelow').value*1;
639 if(CountIndexBelow==0)
640 return false;
641 for(RowCount=CountIndexAbove+1;RowCount<=CountIndexAbove+CountIndexBelow;RowCount++)
643 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)
647 else
648 return false;
650 return true;
652 function OnloadAction()
653 {//Displays message while loading after some action.
654 after_value=document.getElementById('ActionStatus').value;
655 if(after_value=='Delete')
657 alert("<?php echo htmlspecialchars( xl('Successfully Deleted'), ENT_QUOTES) ?>")
658 return true;
660 if(after_value=='Modify' || after_value=='Finish')
662 alert("<?php echo htmlspecialchars( xl('Successfully Modified'), ENT_QUOTES) ?>")
663 return true;
665 after_value=document.getElementById('after_value').value;
666 payment_id=document.getElementById('payment_id').value;
667 if(after_value=='distribute')
670 else if(after_value=='new_payment')
672 if(document.getElementById('TablePatientPortion'))
674 document.getElementById('TablePatientPortion').style.display='none';
676 if(confirm("<?php echo htmlspecialchars( xl('Successfully Saved.Would you like to Distribute?'), ENT_QUOTES) ?>"))
678 if(document.getElementById('TablePatientPortion'))
680 document.getElementById('TablePatientPortion').style.display='';
686 function DeletePaymentDistribution(DeleteId)
687 {//Confirms deletion of payment distribution.
688 if(confirm("<?php echo htmlspecialchars( xl('Would you like to Delete Payment Distribution?'), ENT_QUOTES) ?>"))
690 document.getElementById('mode').value='DeletePaymentDistribution';
691 document.getElementById('DeletePaymentDistributionId').value=DeleteId;
692 top.restoreSession();
693 document.forms[0].submit();
695 else
696 return false;
698 //========================================================================================
699 </script>
700 <script language="javascript" type="text/javascript">
701 document.onclick=HideTheAjaxDivs;
702 </script>
703 <style>
704 .class1{width:125px;}
705 .class2{width:250px;}
706 .class3{width:100px;}
707 .bottom{border-bottom:1px solid black;}
708 .top{border-top:1px solid black;}
709 .left{border-left:1px solid black;}
710 .right{border-right:1px solid black;}
711 #ajax_div_insurance {
712 position: absolute;
713 z-index:10;
715 left: 20px;
716 top: 300px;
718 background-color: #FBFDD0;
719 border: 1px solid #ccc;
720 padding: 10px;
722 #ajax_div_patient {
723 position: absolute;
724 z-index:10;
726 left: 20px;
727 top: 300px;
729 background-color: #FBFDD0;
730 border: 1px solid #ccc;
731 padding: 10px;
733 </style>
734 <link rel="stylesheet" href="<?php echo $css_header; ?>" type="text/css">
735 </head>
736 <body class="body_top" onLoad="OnloadAction()" >
737 <form name='new_payment' method='post' action="edit_payment.php" onsubmit='
738 <?php
739 if($payment_id*1==0)
742 top.restoreSession();return SavePayment();
743 <?php
745 else
748 return false;
749 <?php
752 ' style="display:inline" >
753 <table width="1024" border="0" cellspacing="0" cellpadding="0">
754 <?php
755 if($_REQUEST['ParentPage']=='new_payment')
758 <tr>
759 <td colspan="3" align="left"><b><?php echo htmlspecialchars( xl('Payments'), ENT_QUOTES) ?></b></td>
760 </tr>
761 <tr height="15">
762 <td colspan="3" align="left" ></td>
763 </tr>
764 <tr>
765 <td colspan="3" align="left">
766 <ul class="tabNav">
767 <li class='current'><a href='new_payment.php'><?php echo htmlspecialchars( xl('New Payment'), ENT_QUOTES) ?></a></li>
768 <li><a href='search_payments.php'><?php echo htmlspecialchars( xl('Search Payment'), ENT_QUOTES) ?></a></li>
769 <li><a href='era_payments.php'><?php echo htmlspecialchars( xl('ERA Posting'), ENT_QUOTES) ?></a></li>
770 </ul> </td>
771 </tr>
772 <?php
774 else
777 <tr height="5">
778 <td colspan="3" align="left" ></td>
779 </tr>
780 <?php
783 <tr>
784 <td colspan="3" align="left" >
786 <?php
787 if($payment_id*1>0)
790 <?php
791 require_once("payment_master.inc.php"); //Check/cash details are entered here.
793 <?php
796 </td>
797 </tr>
798 </table>
802 <?php
803 if($payment_id*1>0)
804 {//Distribution rows already in the database are displayed.
807 <table width="1024" border="0" cellspacing="0" cellpadding="10" bgcolor="#DEDEDE"><tr><td>
808 <table width="1004" border="0" cellspacing="0" cellpadding="0">
810 <tr>
811 <td colspan="13" align="left" >
813 <?php //
814 $resCount = sqlStatement("SELECT distinct encounter,code_type,code,modifier from ar_activity where session_id ='$payment_id' ");
815 $TotalRows=sqlNumRows($resCount);
816 $CountPatient=0;
817 $CountIndex=0;
818 $CountIndexAbove=0;
819 $paymenttot=0;
820 $adjamttot=0;
821 $deductibletot=0;
822 $takebacktot=0;
823 $allowedtot=0;
824 if($RowSearchSub = sqlFetchArray($ResultSearchSub))
828 $CountPatient++;
829 $PId=$RowSearchSub['pid'];
830 $EncounterMaster=$RowSearchSub['encounter'];
831 // Only use the code_type in the queries below if it is specified in the ar_activity table.
832 // If it is not specified in the ar_activity table, also note it is not requested from the
833 // billing table in below query, thus making it blank in all queries below in this script.
834 $CodetypeMaster=$RowSearchSub['code_type'];
835 $sql_select_part_codetype = "";
836 $sql_where_part_codetype = "";
837 if (!empty($CodetypeMaster)) {
838 $sql_select_part_codetype = "billing.code_type,";
839 $sql_where_part_codetype = "and billing.code_type ='$CodetypeMaster'";
841 $CodeMaster=$RowSearchSub['code'];
842 $ModifierMaster=$RowSearchSub['modifier'];
843 $res = sqlStatement("SELECT fname,lname,mname FROM patient_data where pid ='$PId'");
844 $row = sqlFetchArray($res);
845 $fname=$row['fname'];
846 $lname=$row['lname'];
847 $mname=$row['mname'];
848 $NameDB=$lname.' '.$fname.' '.$mname;
849 $ResultSearch = sqlStatement("SELECT billing.id,last_level_closed,billing.encounter,form_encounter.`date`,$sql_select_part_codetype billing.code,billing.modifier,fee
850 FROM billing ,form_encounter
851 where billing.encounter=form_encounter.encounter and billing.pid=form_encounter.pid and
852 code_type!='ICD9' and code_type!='COPAY' and billing.activity!=0 and
853 form_encounter.pid ='$PId' and billing.pid ='$PId' and billing.encounter ='$EncounterMaster'
854 $sql_where_part_codetype
855 and billing.code ='$CodeMaster'
856 and billing.modifier ='$ModifierMaster'
857 ORDER BY form_encounter.`date`,form_encounter.encounter,billing.code,billing.modifier");
858 if(sqlNumRows($ResultSearch)>0)
860 if($CountPatient==1)
862 $Table='yes';
864 <table width="1004" border="0" cellpadding="0" cellspacing="0" align="center" id="TableDistributePortion">
865 <tr class="text" bgcolor="#dddddd">
866 <td width="25" class="left top" >&nbsp;</td>
867 <td width="144" class="left top" ><?php echo htmlspecialchars( xl('Patient Name'), ENT_QUOTES) ?></td>
868 <td width="55" class="left top" ><?php echo htmlspecialchars( xl('Post For'), ENT_QUOTES) ?></td>
869 <td width="70" class="left top" ><?php echo htmlspecialchars( xl('Service Date'), ENT_QUOTES) ?></td>
870 <td width="50" class="left top" ><?php echo htmlspecialchars( xl('Encounter'), ENT_QUOTES) ?></td>
871 <td width="65" class="left top" ><?php echo htmlspecialchars( xl('Service Code'), ENT_QUOTES) ?></td>
872 <td width="50" class="left top" ><?php echo htmlspecialchars( xl('Charge'), ENT_QUOTES) ?></td>
873 <td width="40" class="left top" ><?php echo htmlspecialchars( xl('Copay'), ENT_QUOTES) ?></td>
874 <td width="40" class="left top" ><?php echo htmlspecialchars( xl('Remdr'), ENT_QUOTES) ?></td>
875 <td width="60" class="left top" ><?php echo htmlspecialchars( xl('Allowed(c)'), ENT_QUOTES) ?></td><!-- (c) means it is calculated.Not stored one. -->
876 <td width="60" class="left top" ><?php echo htmlspecialchars( xl('Payment'), ENT_QUOTES) ?></td>
877 <td width="70" class="left top" ><?php echo htmlspecialchars( xl('Adj Amount'), ENT_QUOTES) ?></td>
878 <td width="60" class="left top" ><?php echo htmlspecialchars( xl('Deductible'), ENT_QUOTES) ?></td>
879 <td width="60" class="left top" ><?php echo htmlspecialchars( xl('Takeback'), ENT_QUOTES) ?></td>
880 <td width="60" class="left top" ><?php echo htmlspecialchars( xl('MSP Code'), ENT_QUOTES) ?></td>
881 <td width="40" class="left top" ><?php echo htmlspecialchars( xl('Resn'), ENT_QUOTES) ?></td>
882 <td width="110" class="left top right" ><?php echo htmlspecialchars( xl('Follow Up Reason'), ENT_QUOTES) ?></td>
883 </tr>
884 <?php
886 while ($RowSearch = sqlFetchArray($ResultSearch))
888 $CountIndex++;
889 $CountIndexAbove++;
890 $ServiceDateArray=explode(' ',$RowSearch['date']);
891 $ServiceDate=oeFormatShortDate($ServiceDateArray[0]);
892 $Codetype=$RowSearch['code_type'];
893 $Code=$RowSearch['code'];
894 $Modifier =$RowSearch['modifier'];
895 if($Modifier!='')
896 $ModifierString=", $Modifier";
897 else
898 $ModifierString="";
899 $Fee=$RowSearch['fee'];
900 $Encounter=$RowSearch['encounter'];
902 $resPayer = sqlStatement("SELECT payer_type from ar_activity where session_id ='$payment_id' and
903 pid ='$PId' and encounter ='$Encounter' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' ");
904 $rowPayer = sqlFetchArray($resPayer);
905 $Ins=$rowPayer['payer_type'];
907 //Always associating the copay to a particular charge.
908 $BillingId=$RowSearch['id'];
909 $resId = sqlStatement("SELECT id FROM billing where code_type!='ICD9' and code_type!='COPAY' and
910 pid ='$PId' and encounter ='$Encounter' and billing.activity!=0 order by id");
911 $rowId = sqlFetchArray($resId);
912 $Id=$rowId['id'];
914 if($BillingId!=$Id)//multiple cpt in single encounter
916 $Copay=0.00;
918 else
920 $resCopay = sqlStatement("SELECT sum(fee) as copay FROM billing where
921 code_type='COPAY' and pid ='$PId' and encounter ='$Encounter' and billing.activity!=0");
922 $rowCopay = sqlFetchArray($resCopay);
923 $Copay=$rowCopay['copay']*-1;
925 $resMoneyGot = sqlStatement("SELECT sum(pay_amount) as PatientPay FROM ar_activity where
926 pid ='$PId' and encounter ='$Encounter' and payer_type=0 and account_code='PCP'");//new fees screen copay gives account_code='PCP'
927 $rowMoneyGot = sqlFetchArray($resMoneyGot);
928 $PatientPay=$rowMoneyGot['PatientPay'];
930 $Copay=$Copay+$PatientPay;
933 //For calculating Remainder
934 if($Ins==0)
935 {//Fetch all values
936 $resMoneyGot = sqlStatement("SELECT sum(pay_amount) as MoneyGot FROM ar_activity where
937 pid ='$PId' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and encounter ='$Encounter' and !(payer_type=0 and
938 account_code='PCP')");
939 //new fees screen copay gives account_code='PCP'
940 $rowMoneyGot = sqlFetchArray($resMoneyGot);
941 $MoneyGot=$rowMoneyGot['MoneyGot'];
943 $resMoneyAdjusted = sqlStatement("SELECT sum(adj_amount) as MoneyAdjusted FROM ar_activity where
944 pid ='$PId' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and encounter ='$Encounter'");
945 $rowMoneyAdjusted = sqlFetchArray($resMoneyAdjusted);
946 $MoneyAdjusted=$rowMoneyAdjusted['MoneyAdjusted'];
948 else//Fetch till that much got
950 //Fetch the HIGHEST sequence_no till this session.
951 //Used maily in the case if primary/others pays once more.
952 $resSequence = sqlStatement("SELECT sequence_no from ar_activity where session_id ='$payment_id' and
953 pid ='$PId' and encounter ='$Encounter' order by sequence_no desc ");
954 $rowSequence = sqlFetchArray($resSequence);
955 $Sequence=$rowSequence['sequence_no'];
957 $resMoneyGot = sqlStatement("SELECT sum(pay_amount) as MoneyGot FROM ar_activity where
958 pid ='$PId' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and encounter ='$Encounter' and
959 payer_type > 0 and payer_type <='$Ins' and sequence_no<='$Sequence'");
960 $rowMoneyGot = sqlFetchArray($resMoneyGot);
961 $MoneyGot=$rowMoneyGot['MoneyGot'];
963 $resMoneyAdjusted = sqlStatement("SELECT sum(adj_amount) as MoneyAdjusted FROM ar_activity where
964 pid ='$PId' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and encounter ='$Encounter' and
965 payer_type > 0 and payer_type <='$Ins' and sequence_no<='$Sequence'");
966 $rowMoneyAdjusted = sqlFetchArray($resMoneyAdjusted);
967 $MoneyAdjusted=$rowMoneyAdjusted['MoneyAdjusted'];
969 $Remainder=$Fee-$Copay-$MoneyGot-$MoneyAdjusted;
971 //For calculating RemainderJS.Used while restoring back the values.
972 if($Ins==0)
973 {//Got just before Patient
974 $resMoneyGot = sqlStatement("SELECT sum(pay_amount) as MoneyGot FROM ar_activity where
975 pid ='$PId' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and encounter ='$Encounter' and payer_type !=0");
976 $rowMoneyGot = sqlFetchArray($resMoneyGot);
977 $MoneyGot=$rowMoneyGot['MoneyGot'];
979 $resMoneyAdjusted = sqlStatement("SELECT sum(adj_amount) as MoneyAdjusted FROM ar_activity where
980 pid ='$PId' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and encounter ='$Encounter' and payer_type !=0");
981 $rowMoneyAdjusted = sqlFetchArray($resMoneyAdjusted);
982 $MoneyAdjusted=$rowMoneyAdjusted['MoneyAdjusted'];
984 else
985 {//Got just before the previous
986 //Fetch the LOWEST sequence_no till this session.
987 //Used maily in the case if primary/others pays once more.
988 $resSequence = sqlStatement("SELECT sequence_no from ar_activity where session_id ='$payment_id' and
989 pid ='$PId' and encounter ='$Encounter' order by sequence_no ");
990 $rowSequence = sqlFetchArray($resSequence);
991 $Sequence=$rowSequence['sequence_no'];
993 $resMoneyGot = sqlStatement("SELECT sum(pay_amount) as MoneyGot FROM ar_activity where
994 pid ='$PId' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and encounter ='$Encounter'
995 and payer_type > 0 and payer_type <='$Ins' and sequence_no<'$Sequence'");
996 $rowMoneyGot = sqlFetchArray($resMoneyGot);
997 $MoneyGot=$rowMoneyGot['MoneyGot'];
999 $resMoneyAdjusted = sqlStatement("SELECT sum(adj_amount) as MoneyAdjusted FROM ar_activity where
1000 pid ='$PId' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and encounter ='$Encounter'
1001 and payer_type <='$Ins' and sequence_no<'$Sequence' ");
1002 $rowMoneyAdjusted = sqlFetchArray($resMoneyAdjusted);
1003 $MoneyAdjusted=$rowMoneyAdjusted['MoneyAdjusted'];
1005 //Stored in hidden so that can be used while restoring back the values.
1006 $RemainderJS=$Fee-$Copay-$MoneyGot-$MoneyAdjusted;
1008 $resPayment = sqlStatement("SELECT pay_amount from ar_activity where session_id ='$payment_id' and
1009 pid ='$PId' and encounter ='$Encounter' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and pay_amount>0");
1010 $rowPayment = sqlFetchArray($resPayment);
1011 $PaymentDB=$rowPayment['pay_amount']*1;
1012 $PaymentDB=$PaymentDB == 0 ? '' : $PaymentDB;
1014 $resPayment = sqlStatement("SELECT pay_amount from ar_activity where session_id ='$payment_id' and
1015 pid ='$PId' and encounter ='$Encounter' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and pay_amount<0");
1016 $rowPayment = sqlFetchArray($resPayment);
1017 $TakebackDB=$rowPayment['pay_amount']*-1;
1018 $TakebackDB=$TakebackDB == 0 ? '' : $TakebackDB;
1020 $resPayment = sqlStatement("SELECT adj_amount from ar_activity where session_id ='$payment_id' and
1021 pid ='$PId' and encounter ='$Encounter' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and adj_amount!=0");
1022 $rowPayment = sqlFetchArray($resPayment);
1023 $AdjAmountDB=$rowPayment['adj_amount']*1;
1024 $AdjAmountDB=$AdjAmountDB == 0 ? '' : $AdjAmountDB;
1026 $resPayment = sqlStatement("SELECT memo from ar_activity where session_id ='$payment_id' and
1027 pid ='$PId' and encounter ='$Encounter' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and memo like 'Deductable%'");
1028 $rowPayment = sqlFetchArray($resPayment);
1029 $DeductibleDB=$rowPayment['memo'];
1030 $DeductibleDB=str_replace('Deductable $','',$DeductibleDB);
1032 $resPayment = sqlStatement("SELECT follow_up,follow_up_note from ar_activity where session_id ='$payment_id' and
1033 pid ='$PId' and encounter ='$Encounter' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and follow_up = 'y'");
1034 $rowPayment = sqlFetchArray($resPayment);
1035 $FollowUpDB=$rowPayment['follow_up'];
1036 $FollowUpReasonDB=$rowPayment['follow_up_note'];
1038 $resPayment = sqlStatement("SELECT reason_code from ar_activity where session_id ='$payment_id' and
1039 pid ='$PId' and encounter ='$Encounter' and code_type='$Codetype' and code='$Code' and modifier='$Modifier'");
1040 $rowPayment = sqlFetchArray($resPayment);
1041 $ReasonCodeDB=$rowPayment['reason_code'];
1043 if($Ins==1)
1045 $AllowedDB=number_format($Fee-$AdjAmountDB,2);
1047 else
1049 $AllowedDB = 0;
1051 $AllowedDB=$AllowedDB == 0 ? '' : $AllowedDB;
1053 if($CountIndex==$TotalRows)
1055 $StringClass=' bottom left top ';
1057 else
1059 $StringClass=' left top ';
1062 if($Ins==1)
1064 $bgcolor='#ddddff';
1066 elseif($Ins==2)
1068 $bgcolor='#ffdddd';
1070 elseif($Ins==3)
1072 $bgcolor='#F2F1BC';
1074 elseif($Ins==0)
1076 $bgcolor='#AAFFFF';
1078 $paymenttot=$paymenttot+$PaymentDB;
1079 $adjamttot=$adjamttot+$AdjAmountDB;
1080 $deductibletot=$deductibletot+$DeductibleDB;
1081 $takebacktot=$takebacktot+$TakebackDB;
1082 $allowedtot=$allowedtot+$AllowedDB;
1084 <tr class="text" bgcolor='<?php echo $bgcolor; ?>' id="trCharges<?php echo $CountIndex; ?>">
1085 <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>
1086 <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>
1087 <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>
1088 <td class="<?php echo $StringClass; ?>" ><?php echo htmlspecialchars($ServiceDate); ?></td>
1089 <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>
1090 <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>
1091 <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>
1092 <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>
1093 <td align="right" id="RemainderTd<?php echo $CountIndex; ?>" class="<?php echo $StringClass; ?>" ><?php echo htmlspecialchars(round($Remainder,2)); ?></td>
1094 <input name="HiddenRemainderTd<?php echo $CountIndex; ?>" id="HiddenRemainderTd<?php echo $CountIndex; ?>" value="<?php echo htmlspecialchars(round($RemainderJS,2)); ?>" type="hidden"/>
1095 <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>
1096 <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>
1097 <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>
1098 <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>
1099 <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>
1100 <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>
1101 <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>
1102 <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>
1103 </tr>
1104 <?php
1107 }//while ($RowSearch = sqlFetchArray($ResultSearch))
1109 <?php
1110 }//if(sqlNumRows($ResultSearch)>0)
1112 }while ($RowSearchSub = sqlFetchArray($ResultSearchSub));
1113 if($Table=='yes')
1116 <tr class="text">
1117 <td align="left" colspan="9">&nbsp;</td>
1118 <td class="left bottom" bgcolor="#6699FF" id="allowtotal" align="right" ><?php echo htmlspecialchars(number_format($allowedtot,2)); ?></td>
1119 <td class="left bottom" bgcolor="#6699FF" id="paymenttotal" align="right" ><?php echo htmlspecialchars(number_format($paymenttot,2)); ?></td>
1120 <td class="left bottom" bgcolor="#6699FF" id="AdjAmounttotal" align="right" ><?php echo htmlspecialchars(number_format($adjamttot,2)); ?></td>
1121 <td class="left bottom" bgcolor="#6699FF" id="deductibletotal" align="right"><?php echo htmlspecialchars(number_format($deductibletot,2)); ?></td>
1122 <td class="left bottom right" bgcolor="#6699FF" id="takebacktotal" align="right"><?php echo htmlspecialchars(number_format($takebacktot,2)); ?></td>
1123 <td align="center">&nbsp;</td>
1124 <td align="center">&nbsp;</td>
1125 </tr>
1126 </table>
1127 <?php
1130 <?php
1132 echo '<br/>';
1134 }//if($RowSearchSub = sqlFetchArray($ResultSearchSub))
1135 ?> </td>
1136 </tr>
1137 <tr>
1138 <td colspan="13" align="left" >
1139 <?php
1140 require_once("payment_pat_sel.inc.php"); //Patient ajax section and listing of charges.
1142 </td>
1143 </tr>
1144 <tr>
1145 <td colspan="13" align="left" >
1146 <table border="0" cellspacing="0" cellpadding="0" width="217" align="center">
1147 <tr height="5">
1148 <td ></td>
1149 <td ></td>
1150 <td></td>
1151 </tr>
1152 <tr>
1153 <td width="110"><a href="#" onClick="javascript:return ModifyPayments();" class="css_button"><span><?php echo htmlspecialchars( xl('Modify Payments'), ENT_QUOTES);?></span></a>
1154 </td>
1155 <td width="107"><a href="#" onClick="javascript:return FinishPayments();" class="css_button"><span><?php echo htmlspecialchars( xl('Finish Payments'), ENT_QUOTES);?></span></a>
1156 </td>
1157 </tr>
1158 </table>
1160 <?php
1161 }//if($payment_id*1>0)
1162 ?> </td>
1163 </tr>
1164 </table>
1165 </td></tr></table>
1167 <input type="hidden" name="hidden_patient_code" id="hidden_patient_code" value="<?php echo htmlspecialchars($hidden_patient_code);?>"/>
1168 <input type='hidden' name='mode' id='mode' value='' />
1169 <input type='hidden' name='ajax_mode' id='ajax_mode' value='' />
1170 <input type="hidden" name="after_value" id="after_value" value="<?php echo htmlspecialchars($_POST["mode"]);?>"/>
1171 <input type="hidden" name="payment_id" id="payment_id" value="<?php echo htmlspecialchars($payment_id);?>"/>
1172 <input type="hidden" name="hidden_type_code" id="hidden_type_code" value="<?php echo htmlspecialchars($TypeCode);?>"/>
1173 <input type='hidden' name='global_amount' id='global_amount' value='' />
1174 <input type='hidden' name='DeletePaymentDistributionId' id='DeletePaymentDistributionId' value='' />
1175 <input type="hidden" name="ActionStatus" id="ActionStatus" value="<?php echo htmlspecialchars($Message);?>"/>
1176 <input type='hidden' name='CountIndexAbove' id='CountIndexAbove' value='<?php echo htmlspecialchars($CountIndexAbove*1);?>' />
1177 <input type='hidden' name='CountIndexBelow' id='CountIndexBelow' value='<?php echo htmlspecialchars($CountIndexBelow*1);?>' />
1178 <input type="hidden" name="ParentPage" id="ParentPage" value="<?php echo htmlspecialchars($_REQUEST['ParentPage']);?>"/>
1179 </form>
1181 </body>
1182 </html>