The Third Reminders email bug fix - contributed by arnabnaha
[openemr.git] / interface / billing / edit_payment.php
blobef2ad07ba08a683d333e991dd9ed49c7276cda67
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=split('_',$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 sqlStatement("insert into ar_activity set " .
180 "pid = '" . trim(formData("HiddenPId$CountRow" )) .
181 "', encounter = '" . trim(formData("HiddenEncounter$CountRow" )) .
182 "', code_type = '" . trim(formData("HiddenCodetype$CountRow" )) .
183 "', code = '" . trim(formData("HiddenCode$CountRow" )) .
184 "', modifier = '" . trim(formData("HiddenModifier$CountRow" )) .
185 "', payer_type = '" . trim(formData("HiddenIns$CountRow" )) .
186 "', reason_code = '" . trim(formData("ReasonCode$CountRow" )) .
187 "', post_time = '" . trim($created_time ) .
188 "', post_user = '" . trim($user_id ) .
189 "', session_id = '" . trim(formData('payment_id')) .
190 "', modified_time = '" . trim($created_time ) .
191 "', pay_amount = '" . trim(formData("Payment$CountRow" )) .
192 "', adj_amount = '" . 0 .
193 "', account_code = '" . "$AccountCode" .
194 "'");
197 else
199 sqlStatement("delete from ar_activity " .
200 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow" )) .
201 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow" )) .
202 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow" )) .
203 "' and code ='" . trim(formData("HiddenCode$CountRow" )) .
204 "' and modifier ='" . trim(formData("HiddenModifier$CountRow" )) .
205 "' and pay_amount>0");
207 //==============================================================================================================================
208 if (isset($_POST["AdjAmount$CountRow"]) && $_POST["AdjAmount$CountRow"]*1!=0)
210 if(trim(formData('type_name' ))=='insurance')
212 $AdjustString="Ins adjust Ins".trim(formData("HiddenIns$CountRow" ));
213 $AccountCode="IA";
215 elseif(trim(formData('type_name' ))=='patient')
217 $AdjustString="Pt adjust";
218 $AccountCode="PA";
220 $resPayment = sqlStatement("SELECT * from ar_activity " .
221 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow" )) .
222 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow" )) .
223 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow" )) .
224 "' and code ='" . trim(formData("HiddenCode$CountRow" )) .
225 "' and modifier ='" . trim(formData("HiddenModifier$CountRow" )) .
226 "' and adj_amount!=0");
227 if(sqlNumRows($resPayment)>0)
229 sqlStatement("update ar_activity set " .
230 " post_user = '" . trim($user_id ) .
231 "', modified_time = '" . trim($created_time ) .
232 "', adj_amount = '" . trim(formData("AdjAmount$CountRow" )) .
233 "', memo = '" . "$AdjustString" .
234 "', account_code = '" . "$AccountCode" .
235 "', payer_type = '" . trim(formData("HiddenIns$CountRow" )) .
236 "' where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow" )) .
237 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow" )) .
238 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow" )) .
239 "' and code ='" . trim(formData("HiddenCode$CountRow" )) .
240 "' and modifier ='" . trim(formData("HiddenModifier$CountRow" )) .
241 "' and adj_amount!=0");
243 else
245 sqlStatement("insert into ar_activity set " .
246 "pid = '" . trim(formData("HiddenPId$CountRow" )) .
247 "', encounter = '" . trim(formData("HiddenEncounter$CountRow" )) .
248 "', code_type = '" . trim(formData("HiddenCodetype$CountRow" )) .
249 "', code = '" . trim(formData("HiddenCode$CountRow" )) .
250 "', modifier = '" . trim(formData("HiddenModifier$CountRow" )) .
251 "', payer_type = '" . trim(formData("HiddenIns$CountRow" )) .
252 "', post_time = '" . trim($created_time ) .
253 "', post_user = '" . trim($user_id ) .
254 "', session_id = '" . trim(formData('payment_id')) .
255 "', modified_time = '" . trim($created_time ) .
256 "', pay_amount = '" . 0 .
257 "', adj_amount = '" . trim(formData("AdjAmount$CountRow" )) .
258 "', memo = '" . "$AdjustString" .
259 "', account_code = '" . "$AccountCode" .
260 "'");
264 else
266 sqlStatement("delete from ar_activity " .
267 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow" )) .
268 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow" )) .
269 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow" )) .
270 "' and code ='" . trim(formData("HiddenCode$CountRow" )) .
271 "' and modifier ='" . trim(formData("HiddenModifier$CountRow" )) .
272 "' and adj_amount!=0");
274 //==============================================================================================================================
275 if (isset($_POST["Deductible$CountRow"]) && $_POST["Deductible$CountRow"]*1>0)
277 $resPayment = sqlStatement("SELECT * from ar_activity " .
278 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow" )) .
279 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow" )) .
280 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow" )) .
281 "' and code ='" . trim(formData("HiddenCode$CountRow" )) .
282 "' and modifier ='" . trim(formData("HiddenModifier$CountRow" )) .
283 "' and memo like 'Deductable%'");
284 if(sqlNumRows($resPayment)>0)
286 sqlStatement("update ar_activity set " .
287 " post_user = '" . trim($user_id ) .
288 "', modified_time = '" . trim($created_time ) .
289 "', memo = '" . "Deductable $".trim(formData("Deductible$CountRow" )) .
290 "', account_code = '" . "Deduct" .
291 "', payer_type = '" . trim(formData("HiddenIns$CountRow" )) .
292 "' where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow" )) .
293 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow" )) .
294 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow" )) .
295 "' and code ='" . trim(formData("HiddenCode$CountRow" )) .
296 "' and modifier ='" . trim(formData("HiddenModifier$CountRow" )) .
297 "' and memo like 'Deductable%'");
299 else
301 sqlStatement("insert into ar_activity set " .
302 "pid = '" . trim(formData("HiddenPId$CountRow" )) .
303 "', encounter = '" . trim(formData("HiddenEncounter$CountRow" )) .
304 "', code_type = '" . trim(formData("HiddenCodetype$CountRow" )) .
305 "', code = '" . trim(formData("HiddenCode$CountRow" )) .
306 "', modifier = '" . trim(formData("HiddenModifier$CountRow" )) .
307 "', payer_type = '" . trim(formData("HiddenIns$CountRow" )) .
308 "', post_time = '" . trim($created_time ) .
309 "', post_user = '" . trim($user_id ) .
310 "', session_id = '" . trim(formData('payment_id')) .
311 "', modified_time = '" . trim($created_time ) .
312 "', pay_amount = '" . 0 .
313 "', adj_amount = '" . 0 .
314 "', memo = '" . "Deductable $".trim(formData("Deductible$CountRow" )) .
315 "', account_code = '" . "Deduct" .
316 "'");
319 else
321 sqlStatement("delete from ar_activity " .
322 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow" )) .
323 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow" )) .
324 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow" )) .
325 "' and code ='" . trim(formData("HiddenCode$CountRow" )) .
326 "' and modifier ='" . trim(formData("HiddenModifier$CountRow" )) .
327 "' and memo like 'Deductable%'");
329 //==============================================================================================================================
330 if (isset($_POST["Takeback$CountRow"]) && $_POST["Takeback$CountRow"]*1>0)
332 $resPayment = sqlStatement("SELECT * from ar_activity " .
333 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow" )) .
334 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow" )) .
335 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow" )) .
336 "' and code ='" . trim(formData("HiddenCode$CountRow" )) .
337 "' and modifier ='" . trim(formData("HiddenModifier$CountRow" )) .
338 "' and pay_amount < 0");
339 if(sqlNumRows($resPayment)>0)
341 sqlStatement("update ar_activity set " .
342 " post_user = '" . trim($user_id ) .
343 "', modified_time = '" . trim($created_time ) .
344 "', pay_amount = '" . trim(formData("Takeback$CountRow" ))*-1 .
345 "', account_code = '" . "Takeback" .
346 "', payer_type = '" . trim(formData("HiddenIns$CountRow" )) .
347 "' where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow" )) .
348 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow" )) .
349 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow" )) .
350 "' and code ='" . trim(formData("HiddenCode$CountRow" )) .
351 "' and modifier ='" . trim(formData("HiddenModifier$CountRow" )) .
352 "' and pay_amount < 0");
354 else
356 sqlStatement("insert into ar_activity set " .
357 "pid = '" . trim(formData("HiddenPId$CountRow" )) .
358 "', encounter = '" . trim(formData("HiddenEncounter$CountRow" )) .
359 "', code_type = '" . trim(formData("HiddenCodetype$CountRow" )) .
360 "', code = '" . trim(formData("HiddenCode$CountRow" )) .
361 "', modifier = '" . trim(formData("HiddenModifier$CountRow" )) .
362 "', payer_type = '" . trim(formData("HiddenIns$CountRow" )) .
363 "', post_time = '" . trim($created_time ) .
364 "', post_user = '" . trim($user_id ) .
365 "', session_id = '" . trim(formData('payment_id')) .
366 "', modified_time = '" . trim($created_time ) .
367 "', pay_amount = '" . trim(formData("Takeback$CountRow" ))*-1 .
368 "', adj_amount = '" . 0 .
369 "', account_code = '" . "Takeback" .
370 "'");
373 else
375 sqlStatement("delete from ar_activity " .
376 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow" )) .
377 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow" )) .
378 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow" )) .
379 "' and code ='" . trim(formData("HiddenCode$CountRow" )) .
380 "' and modifier ='" . trim(formData("HiddenModifier$CountRow" )) .
381 "' and pay_amount < 0");
383 //==============================================================================================================================
384 if (isset($_POST["FollowUp$CountRow"]) && $_POST["FollowUp$CountRow"]=='y')
386 $resPayment = sqlStatement("SELECT * from ar_activity " .
387 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow" )) .
388 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow" )) .
389 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow" )) .
390 "' and code ='" . trim(formData("HiddenCode$CountRow" )) .
391 "' and modifier ='" . trim(formData("HiddenModifier$CountRow" )) .
392 "' and follow_up ='y'");
393 if(sqlNumRows($resPayment)>0)
395 sqlStatement("update ar_activity set " .
396 " post_user = '" . trim($user_id ) .
397 "', modified_time = '" . trim($created_time ) .
398 "', follow_up = '" . "y" .
399 "', follow_up_note = '" . trim(formData("FollowUpReason$CountRow" )) .
400 "', payer_type = '" . trim(formData("HiddenIns$CountRow" )) .
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'");
408 else
410 sqlStatement("insert into ar_activity set " .
411 "pid = '" . trim(formData("HiddenPId$CountRow" )) .
412 "', encounter = '" . trim(formData("HiddenEncounter$CountRow" )) .
413 "', code_type = '" . trim(formData("HiddenCodetype$CountRow" )) .
414 "', code = '" . trim(formData("HiddenCode$CountRow" )) .
415 "', modifier = '" . trim(formData("HiddenModifier$CountRow" )) .
416 "', payer_type = '" . trim(formData("HiddenIns$CountRow" )) .
417 "', post_time = '" . trim($created_time ) .
418 "', post_user = '" . trim($user_id ) .
419 "', session_id = '" . trim(formData('payment_id')) .
420 "', modified_time = '" . trim($created_time ) .
421 "', pay_amount = '" . 0 .
422 "', adj_amount = '" . 0 .
423 "', follow_up = '" . "y" .
424 "', follow_up_note = '" . trim(formData("FollowUpReason$CountRow" )) .
425 "'");
428 else
430 sqlStatement("delete from ar_activity " .
431 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow" )) .
432 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow" )) .
433 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow" )) .
434 "' and code ='" . trim(formData("HiddenCode$CountRow" )) .
435 "' and modifier ='" . trim(formData("HiddenModifier$CountRow" )) .
436 "' and follow_up ='y'");
438 //==============================================================================================================================
440 else
441 break;
443 //=========
444 //INSERTION of new entries,continuation of modification.
445 //=========
446 for($CountRow=$CountIndexAbove+1;$CountRow<=$CountIndexAbove+$CountIndexBelow;$CountRow++)
448 if (isset($_POST["HiddenEncounter$CountRow"]))
450 DistributionInsert($CountRow,$created_time,$user_id);
452 else
453 break;
455 if($_REQUEST['global_amount']=='yes')
456 sqlStatement("update ar_session set global_amount=".trim(formData("HidUnappliedAmount" ))*1 ." where session_id ='$payment_id'");
457 if($_POST["mode"]=="FinishPayments")
459 $Message='Finish';
461 $_POST["mode"] = "searchdatabase";
462 $Message='Modify';
465 //==============================================================================
466 //Search Code
467 //===============================================================================
468 $payment_id=$payment_id*1 > 0 ? $payment_id : $_REQUEST['payment_id'];
469 $ResultSearchSub = sqlStatement("SELECT distinct encounter,code_type,code,modifier, pid from ar_activity where session_id ='$payment_id' order by pid,encounter,code,modifier");
470 //==============================================================================
471 $DateFormat=DateFormatRead();
472 //==============================================================================
473 //===============================================================================
476 <html>
477 <head>
478 <?php if (function_exists('html_header_show')) html_header_show(); ?>
480 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
482 <!-- supporting javascript code -->
484 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js"></script>
488 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
489 <link rel="stylesheet" type="text/css" href="../../library/js/fancybox/jquery.fancybox-1.2.6.css" media="screen" />
490 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
491 <script type="text/javascript" src="../../library/textformat.js"></script>
492 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
493 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
494 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
495 <script type="text/javascript" src="../../library/dialog.js"></script>
496 <script type="text/javascript" src="../../library/js/jquery.1.3.2.js"></script>
497 <script type="text/javascript" src="../../library/js/fancybox/jquery.fancybox-1.2.6.js"></script>
498 <script language='JavaScript'>
499 var mypcc = '1';
500 </script>
501 <?php include_once("{$GLOBALS['srcdir']}/payment_jav.inc.php"); ?>
502 <?php include_once("{$GLOBALS['srcdir']}/ajax/payment_ajax_jav.inc.php"); ?>
503 <script type="text/javascript" src="../../library/js/common.js"></script>
504 <script LANGUAGE="javascript" TYPE="text/javascript">
505 function ModifyPayments()
506 {//Used while modifying the allocation
507 if(!FormValidations())//FormValidations contains the form checks
509 return false;
511 if(CompletlyBlankAbove())//The distribution rows already in the database are checked.
513 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) ?>")
514 return false;
516 if(!CheckPayingEntityAndDistributionPostFor())//Ensures that Insurance payment is distributed under Ins1,Ins2,Ins3 and Patient paymentat under Pat.
518 return false;
520 if(CompletlyBlankBelow())//The newly added distribution rows are checked.
522 alert("<?php echo htmlspecialchars( xl('Fill any of the Below Row.'), ENT_QUOTES) ?>")
523 return false;
525 PostValue=CheckUnappliedAmount();//Decides TdUnappliedAmount >0, or <0 or =0
526 if(PostValue==1)
528 alert("<?php echo htmlspecialchars( xl('Cannot Modify Payments.Undistributed is Negative.'), ENT_QUOTES) ?>")
529 return false;
531 if(confirm("<?php echo htmlspecialchars( xl('Would you like to Modify Payments?'), ENT_QUOTES) ?>"))
533 document.getElementById('mode').value='ModifyPayments';
534 top.restoreSession();
535 document.forms[0].submit();
537 else
538 return false;
540 function FinishPayments()
542 if(!FormValidations())//FormValidations contains the form checks
544 return false;
546 if(CompletlyBlankAbove())//The distribution rows already in the database are checked.
548 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) ?>")
549 return false;
551 if(!CheckPayingEntityAndDistributionPostFor())//Ensures that Insurance payment is distributed under Ins1,Ins2,Ins3 and Patient paymentat under Pat.
553 return false;
555 if(CompletlyBlankBelow())//The newly added distribution rows are checked.
557 alert("<?php echo htmlspecialchars( xl('Fill any of the Below Row.'), ENT_QUOTES) ?>")
558 return false;
560 PostValue=CheckUnappliedAmount();//Decides TdUnappliedAmount >0, or <0 or =0
561 if(PostValue==1)
563 alert("<?php echo htmlspecialchars( xl('Cannot Modify Payments.Undistributed is Negative.'), ENT_QUOTES) ?>")
564 return false;
566 if(PostValue==2)
568 if(confirm("<?php echo htmlspecialchars( xl('Would you like to Modify and Finish Payments?'), ENT_QUOTES) ?>"))
570 UnappliedAmount=document.getElementById('TdUnappliedAmount').innerHTML*1;
571 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) ?>"))
573 document.getElementById('mode').value='FinishPayments';
574 document.getElementById('global_amount').value='yes';
575 top.restoreSession();
576 document.forms[0].submit();
578 else
580 document.getElementById('mode').value='FinishPayments';
581 top.restoreSession();
582 document.forms[0].submit();
585 else
586 return false;
588 else
590 if(confirm("<?php echo htmlspecialchars( xl('Would you like to Modify and Finish Payments?'), ENT_QUOTES) ?>"))
592 document.getElementById('mode').value='FinishPayments';
593 top.restoreSession();
594 document.forms[0].submit();
596 else
597 return false;
601 function CompletlyBlankAbove()
602 {//The distribution rows already in the database are checked.
603 //It is not allowed to be made completly empty.If needed delete option need to be used.
604 CountIndexAbove=document.getElementById('CountIndexAbove').value*1;
605 for(RowCount=1;RowCount<=CountIndexAbove;RowCount++)
607 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)
609 return true;
612 return false;
614 function CompletlyBlankBelow()
615 {//The newly added distribution rows are checked.
616 //It is not allowed to be made completly empty.
617 CountIndexAbove=document.getElementById('CountIndexAbove').value*1;
618 CountIndexBelow=document.getElementById('CountIndexBelow').value*1;
619 if(CountIndexBelow==0)
620 return false;
621 for(RowCount=CountIndexAbove+1;RowCount<=CountIndexAbove+CountIndexBelow;RowCount++)
623 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 else
628 return false;
630 return true;
632 function OnloadAction()
633 {//Displays message while loading after some action.
634 after_value=document.getElementById('ActionStatus').value;
635 if(after_value=='Delete')
637 alert("<?php echo htmlspecialchars( xl('Successfully Deleted'), ENT_QUOTES) ?>")
638 return true;
640 if(after_value=='Modify' || after_value=='Finish')
642 alert("<?php echo htmlspecialchars( xl('Successfully Modified'), ENT_QUOTES) ?>")
643 return true;
645 after_value=document.getElementById('after_value').value;
646 payment_id=document.getElementById('payment_id').value;
647 if(after_value=='distribute')
650 else if(after_value=='new_payment')
652 if(document.getElementById('TablePatientPortion'))
654 document.getElementById('TablePatientPortion').style.display='none';
656 if(confirm("<?php echo htmlspecialchars( xl('Successfully Saved.Would you like to Distribute?'), ENT_QUOTES) ?>"))
658 if(document.getElementById('TablePatientPortion'))
660 document.getElementById('TablePatientPortion').style.display='';
666 function DeletePaymentDistribution(DeleteId)
667 {//Confirms deletion of payment distribution.
668 if(confirm("<?php echo htmlspecialchars( xl('Would you like to Delete Payment Distribution?'), ENT_QUOTES) ?>"))
670 document.getElementById('mode').value='DeletePaymentDistribution';
671 document.getElementById('DeletePaymentDistributionId').value=DeleteId;
672 top.restoreSession();
673 document.forms[0].submit();
675 else
676 return false;
678 //========================================================================================
679 </script>
680 <script language="javascript" type="text/javascript">
681 document.onclick=HideTheAjaxDivs;
682 </script>
683 <style>
684 .class1{width:125px;}
685 .class2{width:250px;}
686 .class3{width:100px;}
687 .bottom{border-bottom:1px solid black;}
688 .top{border-top:1px solid black;}
689 .left{border-left:1px solid black;}
690 .right{border-right:1px solid black;}
691 #ajax_div_insurance {
692 position: absolute;
693 z-index:10;
695 left: 20px;
696 top: 300px;
698 background-color: #FBFDD0;
699 border: 1px solid #ccc;
700 padding: 10px;
702 #ajax_div_patient {
703 position: absolute;
704 z-index:10;
706 left: 20px;
707 top: 300px;
709 background-color: #FBFDD0;
710 border: 1px solid #ccc;
711 padding: 10px;
713 </style>
714 <link rel="stylesheet" href="<?php echo $css_header; ?>" type="text/css">
715 </head>
716 <body class="body_top" onLoad="OnloadAction()" >
717 <form name='new_payment' method='post' action="edit_payment.php" onsubmit='
718 <?php
719 if($payment_id*1==0)
722 top.restoreSession();return SavePayment();
723 <?php
725 else
728 return false;
729 <?php
732 ' style="display:inline" >
733 <table width="1024" border="0" cellspacing="0" cellpadding="0">
734 <?php
735 if($_REQUEST['ParentPage']=='new_payment')
738 <tr>
739 <td colspan="3" align="left"><b><?php echo htmlspecialchars( xl('Payments'), ENT_QUOTES) ?></b></td>
740 </tr>
741 <tr height="15">
742 <td colspan="3" align="left" ></td>
743 </tr>
744 <tr>
745 <td colspan="3" align="left">
746 <ul class="tabNav">
747 <li class='current'><a href='new_payment.php'><?php echo htmlspecialchars( xl('New Payment'), ENT_QUOTES) ?></a></li>
748 <li><a href='search_payments.php'><?php echo htmlspecialchars( xl('Search Payment'), ENT_QUOTES) ?></a></li>
749 <li><a href='era_payments.php'><?php echo htmlspecialchars( xl('ERA Posting'), ENT_QUOTES) ?></a></li>
750 </ul> </td>
751 </tr>
752 <?php
754 else
757 <tr height="5">
758 <td colspan="3" align="left" ></td>
759 </tr>
760 <?php
763 <tr>
764 <td colspan="3" align="left" >
766 <?php
767 if($payment_id*1>0)
770 <?php
771 require_once("payment_master.inc.php"); //Check/cash details are entered here.
773 <?php
776 </td>
777 </tr>
778 </table>
782 <?php
783 if($payment_id*1>0)
784 {//Distribution rows already in the database are displayed.
787 <table width="1024" border="0" cellspacing="0" cellpadding="10" bgcolor="#DEDEDE"><tr><td>
788 <table width="1004" border="0" cellspacing="0" cellpadding="0">
790 <tr>
791 <td colspan="13" align="left" >
793 <?php //
794 $resCount = sqlStatement("SELECT distinct encounter,code_type,code,modifier from ar_activity where session_id ='$payment_id' ");
795 $TotalRows=sqlNumRows($resCount);
796 $CountPatient=0;
797 $CountIndex=0;
798 $CountIndexAbove=0;
799 $paymenttot=0;
800 $adjamttot=0;
801 $deductibletot=0;
802 $takebacktot=0;
803 $allowedtot=0;
804 if($RowSearchSub = sqlFetchArray($ResultSearchSub))
808 $CountPatient++;
809 $PId=$RowSearchSub['pid'];
810 $EncounterMaster=$RowSearchSub['encounter'];
811 // Only use the code_type in the queries below if it is specified in the ar_activity table.
812 // If it is not specified in the ar_activity table, also note it is not requested from the
813 // billing table in below query, thus making it blank in all queries below in this script.
814 $CodetypeMaster=$RowSearchSub['code_type'];
815 $sql_select_part_codetype = "";
816 $sql_where_part_codetype = "";
817 if (!empty($CodetypeMaster)) {
818 $sql_select_part_codetype = "billing.code_type,";
819 $sql_where_part_codetype = "and billing.code_type ='$CodetypeMaster'";
821 $CodeMaster=$RowSearchSub['code'];
822 $ModifierMaster=$RowSearchSub['modifier'];
823 $res = sqlStatement("SELECT fname,lname,mname FROM patient_data where pid ='$PId'");
824 $row = sqlFetchArray($res);
825 $fname=$row['fname'];
826 $lname=$row['lname'];
827 $mname=$row['mname'];
828 $NameDB=$lname.' '.$fname.' '.$mname;
829 $ResultSearch = sqlStatement("SELECT billing.id,last_level_closed,billing.encounter,form_encounter.`date`,$sql_select_part_codetype billing.code,billing.modifier,fee
830 FROM billing ,form_encounter
831 where billing.encounter=form_encounter.encounter and billing.pid=form_encounter.pid and
832 code_type!='ICD9' and code_type!='COPAY' and billing.activity!=0 and
833 form_encounter.pid ='$PId' and billing.pid ='$PId' and billing.encounter ='$EncounterMaster'
834 $sql_where_part_codetype
835 and billing.code ='$CodeMaster'
836 and billing.modifier ='$ModifierMaster'
837 ORDER BY form_encounter.`date`,form_encounter.encounter,billing.code,billing.modifier");
838 if(sqlNumRows($ResultSearch)>0)
840 if($CountPatient==1)
842 $Table='yes';
844 <table width="1004" border="0" cellpadding="0" cellspacing="0" align="center" id="TableDistributePortion">
845 <tr class="text" bgcolor="#dddddd">
846 <td width="25" class="left top" >&nbsp;</td>
847 <td width="144" class="left top" ><?php echo htmlspecialchars( xl('Patient Name'), ENT_QUOTES) ?></td>
848 <td width="55" class="left top" ><?php echo htmlspecialchars( xl('Post For'), ENT_QUOTES) ?></td>
849 <td width="70" class="left top" ><?php echo htmlspecialchars( xl('Service Date'), ENT_QUOTES) ?></td>
850 <td width="50" class="left top" ><?php echo htmlspecialchars( xl('Encounter'), ENT_QUOTES) ?></td>
851 <td width="65" class="left top" ><?php echo htmlspecialchars( xl('Service Code'), ENT_QUOTES) ?></td>
852 <td width="50" class="left top" ><?php echo htmlspecialchars( xl('Charge'), ENT_QUOTES) ?></td>
853 <td width="40" class="left top" ><?php echo htmlspecialchars( xl('Copay'), ENT_QUOTES) ?></td>
854 <td width="40" class="left top" ><?php echo htmlspecialchars( xl('Remdr'), ENT_QUOTES) ?></td>
855 <td width="60" class="left top" ><?php echo htmlspecialchars( xl('Allowed(c)'), ENT_QUOTES) ?></td><!-- (c) means it is calculated.Not stored one. -->
856 <td width="60" class="left top" ><?php echo htmlspecialchars( xl('Payment'), ENT_QUOTES) ?></td>
857 <td width="70" class="left top" ><?php echo htmlspecialchars( xl('Adj Amount'), ENT_QUOTES) ?></td>
858 <td width="60" class="left top" ><?php echo htmlspecialchars( xl('Deductible'), ENT_QUOTES) ?></td>
859 <td width="60" class="left top" ><?php echo htmlspecialchars( xl('Takeback'), ENT_QUOTES) ?></td>
860 <td width="60" class="left top" ><?php echo htmlspecialchars( xl('MSP Code'), ENT_QUOTES) ?></td>
861 <td width="40" class="left top" ><?php echo htmlspecialchars( xl('Resn'), ENT_QUOTES) ?></td>
862 <td width="110" class="left top right" ><?php echo htmlspecialchars( xl('Follow Up Reason'), ENT_QUOTES) ?></td>
863 </tr>
864 <?php
866 while ($RowSearch = sqlFetchArray($ResultSearch))
868 $CountIndex++;
869 $CountIndexAbove++;
870 $ServiceDateArray=split(' ',$RowSearch['date']);
871 $ServiceDate=oeFormatShortDate($ServiceDateArray[0]);
872 $Codetype=$RowSearch['code_type'];
873 $Code=$RowSearch['code'];
874 $Modifier =$RowSearch['modifier'];
875 if($Modifier!='')
876 $ModifierString=", $Modifier";
877 else
878 $ModifierString="";
879 $Fee=$RowSearch['fee'];
880 $Encounter=$RowSearch['encounter'];
882 $resPayer = sqlStatement("SELECT payer_type from ar_activity where session_id ='$payment_id' and
883 pid ='$PId' and encounter ='$Encounter' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' ");
884 $rowPayer = sqlFetchArray($resPayer);
885 $Ins=$rowPayer['payer_type'];
887 //Always associating the copay to a particular charge.
888 $BillingId=$RowSearch['id'];
889 $resId = sqlStatement("SELECT id FROM billing where code_type!='ICD9' and code_type!='COPAY' and
890 pid ='$PId' and encounter ='$Encounter' and billing.activity!=0 order by id");
891 $rowId = sqlFetchArray($resId);
892 $Id=$rowId['id'];
894 if($BillingId!=$Id)//multiple cpt in single encounter
896 $Copay=0.00;
898 else
900 $resCopay = sqlStatement("SELECT sum(fee) as copay FROM billing where
901 code_type='COPAY' and pid ='$PId' and encounter ='$Encounter' and billing.activity!=0");
902 $rowCopay = sqlFetchArray($resCopay);
903 $Copay=$rowCopay['copay']*-1;
905 $resMoneyGot = sqlStatement("SELECT sum(pay_amount) as PatientPay FROM ar_activity where
906 pid ='$PId' and encounter ='$Encounter' and payer_type=0 and account_code='PCP'");//new fees screen copay gives account_code='PCP'
907 $rowMoneyGot = sqlFetchArray($resMoneyGot);
908 $PatientPay=$rowMoneyGot['PatientPay'];
910 $Copay=$Copay+$PatientPay;
913 //For calculating Remainder
914 if($Ins==0)
915 {//Fetch all values
916 $resMoneyGot = sqlStatement("SELECT sum(pay_amount) as MoneyGot FROM ar_activity where
917 pid ='$PId' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and encounter ='$Encounter' and !(payer_type=0 and
918 account_code='PCP')");
919 //new fees screen copay gives account_code='PCP'
920 $rowMoneyGot = sqlFetchArray($resMoneyGot);
921 $MoneyGot=$rowMoneyGot['MoneyGot'];
923 $resMoneyAdjusted = sqlStatement("SELECT sum(adj_amount) as MoneyAdjusted FROM ar_activity where
924 pid ='$PId' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and encounter ='$Encounter'");
925 $rowMoneyAdjusted = sqlFetchArray($resMoneyAdjusted);
926 $MoneyAdjusted=$rowMoneyAdjusted['MoneyAdjusted'];
928 else//Fetch till that much got
930 //Fetch the HIGHEST sequence_no till this session.
931 //Used maily in the case if primary/others pays once more.
932 $resSequence = sqlStatement("SELECT sequence_no from ar_activity where session_id ='$payment_id' and
933 pid ='$PId' and encounter ='$Encounter' order by sequence_no desc ");
934 $rowSequence = sqlFetchArray($resSequence);
935 $Sequence=$rowSequence['sequence_no'];
937 $resMoneyGot = sqlStatement("SELECT sum(pay_amount) as MoneyGot FROM ar_activity where
938 pid ='$PId' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and encounter ='$Encounter' and
939 payer_type > 0 and payer_type <='$Ins' and sequence_no<='$Sequence'");
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' and
945 payer_type > 0 and payer_type <='$Ins' and sequence_no<='$Sequence'");
946 $rowMoneyAdjusted = sqlFetchArray($resMoneyAdjusted);
947 $MoneyAdjusted=$rowMoneyAdjusted['MoneyAdjusted'];
949 $Remainder=$Fee-$Copay-$MoneyGot-$MoneyAdjusted;
951 //For calculating RemainderJS.Used while restoring back the values.
952 if($Ins==0)
953 {//Got just before Patient
954 $resMoneyGot = sqlStatement("SELECT sum(pay_amount) as MoneyGot FROM ar_activity where
955 pid ='$PId' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and encounter ='$Encounter' and payer_type !=0");
956 $rowMoneyGot = sqlFetchArray($resMoneyGot);
957 $MoneyGot=$rowMoneyGot['MoneyGot'];
959 $resMoneyAdjusted = sqlStatement("SELECT sum(adj_amount) as MoneyAdjusted FROM ar_activity where
960 pid ='$PId' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and encounter ='$Encounter' and payer_type !=0");
961 $rowMoneyAdjusted = sqlFetchArray($resMoneyAdjusted);
962 $MoneyAdjusted=$rowMoneyAdjusted['MoneyAdjusted'];
964 else
965 {//Got just before the previous
966 //Fetch the LOWEST sequence_no till this session.
967 //Used maily in the case if primary/others pays once more.
968 $resSequence = sqlStatement("SELECT sequence_no from ar_activity where session_id ='$payment_id' and
969 pid ='$PId' and encounter ='$Encounter' order by sequence_no ");
970 $rowSequence = sqlFetchArray($resSequence);
971 $Sequence=$rowSequence['sequence_no'];
973 $resMoneyGot = sqlStatement("SELECT sum(pay_amount) as MoneyGot FROM ar_activity where
974 pid ='$PId' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and encounter ='$Encounter'
975 and payer_type > 0 and payer_type <='$Ins' and sequence_no<'$Sequence'");
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'
981 and payer_type <='$Ins' and sequence_no<'$Sequence' ");
982 $rowMoneyAdjusted = sqlFetchArray($resMoneyAdjusted);
983 $MoneyAdjusted=$rowMoneyAdjusted['MoneyAdjusted'];
985 //Stored in hidden so that can be used while restoring back the values.
986 $RemainderJS=$Fee-$Copay-$MoneyGot-$MoneyAdjusted;
988 $resPayment = sqlStatement("SELECT pay_amount from ar_activity where session_id ='$payment_id' and
989 pid ='$PId' and encounter ='$Encounter' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and pay_amount>0");
990 $rowPayment = sqlFetchArray($resPayment);
991 $PaymentDB=$rowPayment['pay_amount']*1;
992 $PaymentDB=$PaymentDB == 0 ? '' : $PaymentDB;
994 $resPayment = sqlStatement("SELECT pay_amount from ar_activity where session_id ='$payment_id' and
995 pid ='$PId' and encounter ='$Encounter' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and pay_amount<0");
996 $rowPayment = sqlFetchArray($resPayment);
997 $TakebackDB=$rowPayment['pay_amount']*-1;
998 $TakebackDB=$TakebackDB == 0 ? '' : $TakebackDB;
1000 $resPayment = sqlStatement("SELECT adj_amount from ar_activity where session_id ='$payment_id' and
1001 pid ='$PId' and encounter ='$Encounter' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and adj_amount!=0");
1002 $rowPayment = sqlFetchArray($resPayment);
1003 $AdjAmountDB=$rowPayment['adj_amount']*1;
1004 $AdjAmountDB=$AdjAmountDB == 0 ? '' : $AdjAmountDB;
1006 $resPayment = sqlStatement("SELECT memo 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 memo like 'Deductable%'");
1008 $rowPayment = sqlFetchArray($resPayment);
1009 $DeductibleDB=$rowPayment['memo'];
1010 $DeductibleDB=str_replace('Deductable $','',$DeductibleDB);
1012 $resPayment = sqlStatement("SELECT follow_up,follow_up_note 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 follow_up = 'y'");
1014 $rowPayment = sqlFetchArray($resPayment);
1015 $FollowUpDB=$rowPayment['follow_up'];
1016 $FollowUpReasonDB=$rowPayment['follow_up_note'];
1018 $resPayment = sqlStatement("SELECT reason_code 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'");
1020 $rowPayment = sqlFetchArray($resPayment);
1021 $ReasonCodeDB=$rowPayment['reason_code'];
1023 if($Ins==1)
1025 $AllowedDB=number_format($Fee-$AdjAmountDB,2);
1027 else
1029 $AllowedDB = 0;
1031 $AllowedDB=$AllowedDB == 0 ? '' : $AllowedDB;
1033 if($CountIndex==$TotalRows)
1035 $StringClass=' bottom left top ';
1037 else
1039 $StringClass=' left top ';
1042 if($Ins==1)
1044 $bgcolor='#ddddff';
1046 elseif($Ins==2)
1048 $bgcolor='#ffdddd';
1050 elseif($Ins==3)
1052 $bgcolor='#F2F1BC';
1054 elseif($Ins==0)
1056 $bgcolor='#AAFFFF';
1058 $paymenttot=$paymenttot+$PaymentDB;
1059 $adjamttot=$adjamttot+$AdjAmountDB;
1060 $deductibletot=$deductibletot+$DeductibleDB;
1061 $takebacktot=$takebacktot+$TakebackDB;
1062 $allowedtot=$allowedtot+$AllowedDB;
1064 <tr class="text" bgcolor='<?php echo $bgcolor; ?>' id="trCharges<?php echo $CountIndex; ?>">
1065 <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>
1066 <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>
1067 <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>
1068 <td class="<?php echo $StringClass; ?>" ><?php echo htmlspecialchars($ServiceDate); ?></td>
1069 <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>
1070 <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>
1071 <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>
1072 <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>
1073 <td align="right" id="RemainderTd<?php echo $CountIndex; ?>" class="<?php echo $StringClass; ?>" ><?php echo htmlspecialchars(round($Remainder,2)); ?></td>
1074 <input name="HiddenRemainderTd<?php echo $CountIndex; ?>" id="HiddenRemainderTd<?php echo $CountIndex; ?>" value="<?php echo htmlspecialchars(round($RemainderJS,2)); ?>" type="hidden"/>
1075 <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>
1076 <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>
1077 <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>
1078 <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>
1079 <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>
1080 <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>
1081 <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>
1082 <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>
1083 </tr>
1084 <?php
1087 }//while ($RowSearch = sqlFetchArray($ResultSearch))
1089 <?php
1090 }//if(sqlNumRows($ResultSearch)>0)
1092 }while ($RowSearchSub = sqlFetchArray($ResultSearchSub));
1093 if($Table=='yes')
1096 <tr class="text">
1097 <td align="left" colspan="9">&nbsp;</td>
1098 <td class="left bottom" bgcolor="#6699FF" id="allowtotal" align="right" ><?php echo htmlspecialchars(number_format($allowedtot,2)); ?></td>
1099 <td class="left bottom" bgcolor="#6699FF" id="paymenttotal" align="right" ><?php echo htmlspecialchars(number_format($paymenttot,2)); ?></td>
1100 <td class="left bottom" bgcolor="#6699FF" id="AdjAmounttotal" align="right" ><?php echo htmlspecialchars(number_format($adjamttot,2)); ?></td>
1101 <td class="left bottom" bgcolor="#6699FF" id="deductibletotal" align="right"><?php echo htmlspecialchars(number_format($deductibletot,2)); ?></td>
1102 <td class="left bottom right" bgcolor="#6699FF" id="takebacktotal" align="right"><?php echo htmlspecialchars(number_format($takebacktot,2)); ?></td>
1103 <td align="center">&nbsp;</td>
1104 <td align="center">&nbsp;</td>
1105 </tr>
1106 </table>
1107 <?php
1110 <?php
1112 echo '<br/>';
1114 }//if($RowSearchSub = sqlFetchArray($ResultSearchSub))
1115 ?> </td>
1116 </tr>
1117 <tr>
1118 <td colspan="13" align="left" >
1119 <?php
1120 require_once("payment_pat_sel.inc.php"); //Patient ajax section and listing of charges.
1122 </td>
1123 </tr>
1124 <tr>
1125 <td colspan="13" align="left" >
1126 <table border="0" cellspacing="0" cellpadding="0" width="217" align="center">
1127 <tr height="5">
1128 <td ></td>
1129 <td ></td>
1130 <td></td>
1131 </tr>
1132 <tr>
1133 <td width="110"><a href="#" onClick="javascript:return ModifyPayments();" class="css_button"><span><?php echo htmlspecialchars( xl('Modify Payments'), ENT_QUOTES);?></span></a>
1134 </td>
1135 <td width="107"><a href="#" onClick="javascript:return FinishPayments();" class="css_button"><span><?php echo htmlspecialchars( xl('Finish Payments'), ENT_QUOTES);?></span></a>
1136 </td>
1137 </tr>
1138 </table>
1140 <?php
1141 }//if($payment_id*1>0)
1142 ?> </td>
1143 </tr>
1144 </table>
1145 </td></tr></table>
1147 <input type="hidden" name="hidden_patient_code" id="hidden_patient_code" value="<?php echo htmlspecialchars($hidden_patient_code);?>"/>
1148 <input type='hidden' name='mode' id='mode' value='' />
1149 <input type='hidden' name='ajax_mode' id='ajax_mode' value='' />
1150 <input type="hidden" name="after_value" id="after_value" value="<?php echo htmlspecialchars($_POST["mode"]);?>"/>
1151 <input type="hidden" name="payment_id" id="payment_id" value="<?php echo htmlspecialchars($payment_id);?>"/>
1152 <input type="hidden" name="hidden_type_code" id="hidden_type_code" value="<?php echo htmlspecialchars($TypeCode);?>"/>
1153 <input type='hidden' name='global_amount' id='global_amount' value='' />
1154 <input type='hidden' name='DeletePaymentDistributionId' id='DeletePaymentDistributionId' value='' />
1155 <input type="hidden" name="ActionStatus" id="ActionStatus" value="<?php echo htmlspecialchars($Message);?>"/>
1156 <input type='hidden' name='CountIndexAbove' id='CountIndexAbove' value='<?php echo htmlspecialchars($CountIndexAbove*1);?>' />
1157 <input type='hidden' name='CountIndexBelow' id='CountIndexBelow' value='<?php echo htmlspecialchars($CountIndexBelow*1);?>' />
1158 <input type="hidden" name="ParentPage" id="ParentPage" value="<?php echo htmlspecialchars($_REQUEST['ParentPage']);?>"/>
1159 </form>
1161 </body>
1162 </html>