2 // +-----------------------------------------------------------------------------+
3 // Copyright (C) 2010 Z&H Consultancy Services Private Limited <sam@zhservices.com>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
18 // A copy of the GNU General Public License is included along with this program:
19 // openemr/interface/login/GnuGPL.html
20 // For more information write to the Free Software
21 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 // Author: Eldho Chacko <eldho@zhservices.com>
24 // Paul Simon K <paul@zhservices.com>
26 // +------------------------------------------------------------------------------+
27 //===============================================================================
28 //Payments can be edited here.It includes deletion of an allocation,modifying the
29 //same or adding a new allocation.Log is kept for the deleted ones.
30 //===============================================================================
31 require_once("../globals.php");
32 require_once("$srcdir/log.inc");
33 require_once("$srcdir/invoice_summary.inc.php");
34 require_once("$srcdir/sl_eob.inc.php");
35 require_once("$srcdir/parse_era.inc.php");
36 require_once("../../library/acl.inc");
37 require_once("$srcdir/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'");
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'];
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'];
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'));
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 " .
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 //==================================================================
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)
141 if(trim(formData("HiddenIns$CountRow" ))==2)
145 if(trim(formData("HiddenIns$CountRow" ))==3)
150 elseif(trim(formData('type_name' ))=='patient')
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");
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" .
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" ));
219 elseif(trim(formData('type_name' ))=='patient')
221 $AdjustString="Pt adjust";
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");
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" .
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%' OR memo like 'Deductible%')");
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 = '" . "Deductible $".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%' OR memo like 'Deductible%')");
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 = '" . "Deductible $".trim(formData("Deductible$CountRow" )) .
326 "', account_code = '" . "Deduct" .
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%' OR memo like 'Deductible%')");
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");
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" .
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'");
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" )) .
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 //==============================================================================================================================
464 //INSERTION of new entries,continuation of modification.
466 for($CountRow=$CountIndexAbove+
1;$CountRow<=$CountIndexAbove+
$CountIndexBelow;$CountRow++
)
468 if (isset($_POST["HiddenEncounter$CountRow"]))
470 DistributionInsert($CountRow,$created_time,$user_id);
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")
481 $_POST["mode"] = "searchdatabase";
485 //==============================================================================
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 //===============================================================================
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?v=<?php echo $v_js_includes; ?>"></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?v=<?php echo $v_js_includes; ?>"></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'>
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
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) ?>")
536 if(!CheckPayingEntityAndDistributionPostFor())//Ensures that Insurance payment is distributed under Ins1,Ins2,Ins3 and Patient paymentat under Pat.
540 if(CompletlyBlankBelow())//The newly added distribution rows are checked.
542 alert("<?php echo htmlspecialchars( xl('Fill any of the Below Row.'), ENT_QUOTES) ?>")
545 PostValue
=CheckUnappliedAmount();//Decides TdUnappliedAmount >0, or <0 or =0
548 alert("<?php echo htmlspecialchars( xl('Cannot Modify Payments.Undistributed is Negative.'), ENT_QUOTES) ?>")
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();
560 function FinishPayments()
562 if(!FormValidations())//FormValidations contains the form checks
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) ?>")
571 if(!CheckPayingEntityAndDistributionPostFor())//Ensures that Insurance payment is distributed under Ins1,Ins2,Ins3 and Patient paymentat under Pat.
575 if(CompletlyBlankBelow())//The newly added distribution rows are checked.
577 alert("<?php echo htmlspecialchars( xl('Fill any of the Below Row.'), ENT_QUOTES) ?>")
580 PostValue
=CheckUnappliedAmount();//Decides TdUnappliedAmount >0, or <0 or =0
583 alert("<?php echo htmlspecialchars( xl('Cannot Modify Payments.Undistributed is Negative.'), ENT_QUOTES) ?>")
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();
600 document
.getElementById('mode').value
='FinishPayments';
601 top
.restoreSession();
602 document
.forms
[0].submit();
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();
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)
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)
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)
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) ?>")
660 if(after_value
=='Modify' || after_value
=='Finish')
662 alert("<?php echo htmlspecialchars( xl('Successfully Modified'), ENT_QUOTES) ?>")
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();
698 //========================================================================================
700 <script language
="javascript" type
="text/javascript">
701 document
.onclick
=HideTheAjaxDivs
;
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 {
718 background
-color
: #FBFDD0;
719 border
: 1px solid
#ccc;
729 background
-color
: #FBFDD0;
730 border
: 1px solid
#ccc;
734 <link rel
="stylesheet" href
="<?php echo $css_header; ?>" type
="text/css">
736 <body
class="body_top" onLoad
="OnloadAction()" >
737 <form name
='new_payment' method
='post' action
="edit_payment.php" onsubmit
='
742 top.restoreSession();return SavePayment();
752 ' style
="display:inline" >
753 <table width
="1024" border
="0" cellspacing
="0" cellpadding
="0">
755 if($_REQUEST['ParentPage']=='new_payment')
759 <td colspan
="3" align
="left"><b
><?php
echo htmlspecialchars( xl('Payments'), ENT_QUOTES
) ?
></b
></td
>
762 <td colspan
="3" align
="left" ></td
>
765 <td colspan
="3" align
="left">
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
>
778 <td colspan
="3" align
="left" ></td
>
784 <td colspan
="3" align
="left" >
791 require_once("payment_master.inc.php"); //Check/cash details are entered here.
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">
811 <td colspan
="13" align
="left" >
814 $resCount = sqlStatement("SELECT distinct encounter,code_type,code,modifier from ar_activity where session_id ='$payment_id' ");
815 $TotalRows=sqlNumRows($resCount);
824 if($RowSearchSub = sqlFetchArray($ResultSearchSub))
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)
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" > 
;</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
>
886 while ($RowSearch = sqlFetchArray($ResultSearch))
890 $ServiceDateArray=explode(' ',$RowSearch['date']);
891 $ServiceDate=oeFormatShortDate($ServiceDateArray[0]);
892 $Codetype=$RowSearch['code_type'];
893 $Code=$RowSearch['code'];
894 $Modifier =$RowSearch['modifier'];
896 $ModifierString=", $Modifier";
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);
914 if($BillingId!=$Id)//multiple cpt in single encounter
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
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.
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'];
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%' OR memo like 'Deductible%')");
1028 $rowPayment = sqlFetchArray($resPayment);
1029 $DeductibleDB=$rowPayment['memo'];
1030 $DeductibleDB=str_replace('Deductable $','',$DeductibleDB);
1031 $DeductibleDB=str_replace('Deductible $','',$DeductibleDB);
1033 $resPayment = sqlStatement("SELECT follow_up,follow_up_note from ar_activity where session_id ='$payment_id' and
1034 pid ='$PId' and encounter ='$Encounter' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and follow_up = 'y'");
1035 $rowPayment = sqlFetchArray($resPayment);
1036 $FollowUpDB=$rowPayment['follow_up'];
1037 $FollowUpReasonDB=$rowPayment['follow_up_note'];
1039 $resPayment = sqlStatement("SELECT reason_code from ar_activity where session_id ='$payment_id' and
1040 pid ='$PId' and encounter ='$Encounter' and code_type='$Codetype' and code='$Code' and modifier='$Modifier'");
1041 $rowPayment = sqlFetchArray($resPayment);
1042 $ReasonCodeDB=$rowPayment['reason_code'];
1046 $AllowedDB=number_format($Fee-$AdjAmountDB,2);
1052 $AllowedDB=$AllowedDB == 0 ?
'' : $AllowedDB;
1054 if($CountIndex==$TotalRows)
1056 $StringClass=' bottom left top ';
1060 $StringClass=' left top ';
1079 $paymenttot=$paymenttot+
$PaymentDB;
1080 $adjamttot=$adjamttot+
$AdjAmountDB;
1081 $deductibletot=$deductibletot+
$DeductibleDB;
1082 $takebacktot=$takebacktot+
$TakebackDB;
1083 $allowedtot=$allowedtot+
$AllowedDB;
1085 <tr
class="text" bgcolor
='<?php echo $bgcolor; ?>' id
="trCharges<?php echo $CountIndex; ?>">
1086 <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
>
1087 <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
>
1088 <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
>
1089 <td
class="<?php echo $StringClass; ?>" ><?php
echo htmlspecialchars($ServiceDate); ?
></td
>
1090 <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
>
1091 <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
>
1092 <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
>
1093 <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
>
1094 <td align
="right" id
="RemainderTd<?php echo $CountIndex; ?>" class="<?php echo $StringClass; ?>" ><?php
echo htmlspecialchars(round($Remainder,2)); ?
></td
>
1095 <input name
="HiddenRemainderTd<?php echo $CountIndex; ?>" id
="HiddenRemainderTd<?php echo $CountIndex; ?>" value
="<?php echo htmlspecialchars(round($RemainderJS,2)); ?>" type
="hidden"/>
1096 <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
>
1097 <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
>
1098 <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
>
1099 <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
>
1100 <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
>
1101 <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
>
1102 <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
>
1103 <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
>
1108 }//while ($RowSearch = sqlFetchArray($ResultSearch))
1111 }//if(sqlNumRows($ResultSearch)>0)
1113 }while ($RowSearchSub = sqlFetchArray($ResultSearchSub));
1118 <td align
="left" colspan
="9"> 
;</td
>
1119 <td
class="left bottom" bgcolor
="#6699FF" id
="allowtotal" align
="right" ><?php
echo htmlspecialchars(number_format($allowedtot,2)); ?
></td
>
1120 <td
class="left bottom" bgcolor
="#6699FF" id
="paymenttotal" align
="right" ><?php
echo htmlspecialchars(number_format($paymenttot,2)); ?
></td
>
1121 <td
class="left bottom" bgcolor
="#6699FF" id
="AdjAmounttotal" align
="right" ><?php
echo htmlspecialchars(number_format($adjamttot,2)); ?
></td
>
1122 <td
class="left bottom" bgcolor
="#6699FF" id
="deductibletotal" align
="right"><?php
echo htmlspecialchars(number_format($deductibletot,2)); ?
></td
>
1123 <td
class="left bottom right" bgcolor
="#6699FF" id
="takebacktotal" align
="right"><?php
echo htmlspecialchars(number_format($takebacktot,2)); ?
></td
>
1124 <td align
="center"> 
;</td
>
1125 <td align
="center"> 
;</td
>
1135 }//if($RowSearchSub = sqlFetchArray($ResultSearchSub))
1139 <td colspan
="13" align
="left" >
1141 require_once("payment_pat_sel.inc.php"); //Patient ajax section and listing of charges.
1146 <td colspan
="13" align
="left" >
1147 <table border
="0" cellspacing
="0" cellpadding
="0" width
="217" align
="center">
1154 <td width
="110"><a href
="#" onClick
="javascript:return ModifyPayments();" class="css_button"><span
><?php
echo htmlspecialchars( xl('Modify Payments'), ENT_QUOTES
);?
></span
></a
>
1156 <td width
="107"><a href
="#" onClick
="javascript:return FinishPayments();" class="css_button"><span
><?php
echo htmlspecialchars( xl('Finish Payments'), ENT_QUOTES
);?
></span
></a
>
1162 }//if($payment_id*1>0)
1168 <input type
="hidden" name
="hidden_patient_code" id
="hidden_patient_code" value
="<?php echo htmlspecialchars($hidden_patient_code);?>"/>
1169 <input type
='hidden' name
='mode' id
='mode' value
='' />
1170 <input type
='hidden' name
='ajax_mode' id
='ajax_mode' value
='' />
1171 <input type
="hidden" name
="after_value" id
="after_value" value
="<?php echo htmlspecialchars($_POST["mode
"]);?>"/>
1172 <input type
="hidden" name
="payment_id" id
="payment_id" value
="<?php echo htmlspecialchars($payment_id);?>"/>
1173 <input type
="hidden" name
="hidden_type_code" id
="hidden_type_code" value
="<?php echo htmlspecialchars($TypeCode);?>"/>
1174 <input type
='hidden' name
='global_amount' id
='global_amount' value
='' />
1175 <input type
='hidden' name
='DeletePaymentDistributionId' id
='DeletePaymentDistributionId' value
='' />
1176 <input type
="hidden" name
="ActionStatus" id
="ActionStatus" value
="<?php echo htmlspecialchars($Message);?>"/>
1177 <input type
='hidden' name
='CountIndexAbove' id
='CountIndexAbove' value
='<?php echo htmlspecialchars($CountIndexAbove*1);?>' />
1178 <input type
='hidden' name
='CountIndexBelow' id
='CountIndexBelow' value
='<?php echo htmlspecialchars($CountIndexBelow*1);?>' />
1179 <input type
="hidden" name
="ParentPage" id
="ParentPage" value
="<?php echo htmlspecialchars($_REQUEST['ParentPage']);?>"/>