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/auth.inc");
38 require_once("../../custom/code_types.inc.php");
39 require_once("$srcdir/patient.inc");
40 require_once("$srcdir/billrep.inc");
41 require_once("$srcdir/options.inc.php");
42 require_once("$srcdir/payment.inc.php");
43 //===============================================================================
44 $screen='edit_payment';
45 //===============================================================================
46 // deletion of payment distribution code
47 //===============================================================================
48 if (isset($_POST["mode"])) {
49 if ($_POST["mode"] == "DeletePaymentDistribution") {
50 $DeletePaymentDistributionId=trim(formData('DeletePaymentDistributionId'));
51 $DeletePaymentDistributionIdArray=explode('_', $DeletePaymentDistributionId);
52 $payment_id=$DeletePaymentDistributionIdArray[0];
53 $PId=$DeletePaymentDistributionIdArray[1];
54 $Encounter=$DeletePaymentDistributionIdArray[2];
55 $Code=$DeletePaymentDistributionIdArray[3];
56 $Modifier=$DeletePaymentDistributionIdArray[4];
57 $Codetype=$DeletePaymentDistributionIdArray[5];
58 //delete and log that action
59 row_delete("ar_activity", "session_id ='$payment_id' and pid ='$PId' AND " .
60 "encounter='$Encounter' and code_type='$Codetype' and code='$Code' and modifier='$Modifier'");
63 $_POST["mode"] = "searchdatabase";
67 //===============================================================================
68 //Modify Payment Code.
69 //===============================================================================
70 if (isset($_POST["mode"])) {
71 if ($_POST["mode"] == "ModifyPayments" ||
$_POST["mode"] == "FinishPayments") {
72 $payment_id=$_REQUEST['payment_id'];
74 //===============================================================================
75 if (trim(formData('type_name'))=='insurance') {
76 $QueryPart="payer_id = '" . trim(formData('hidden_type_code')) .
77 "', patient_id = '" . 0 ;
78 } elseif (trim(formData('type_name'))=='patient') {
79 $QueryPart="payer_id = '" . 0 .
80 "', patient_id = '" . trim(formData('hidden_type_code')) ;
83 $user_id=$_SESSION['authUserID'];
85 $modified_time = date('Y-m-d H:i:s');
86 $check_date=DateToYYYYMMDD(formData('check_date'));
87 $deposit_date=DateToYYYYMMDD(formData('deposit_date'));
88 $post_to_date=DateToYYYYMMDD(formData('post_to_date'));
89 if ($post_to_date=='') {
90 $post_to_date=date('Y-m-d');
93 if (formData('deposit_date')=='') {
94 $deposit_date=$post_to_date;
97 sqlStatement("update ar_session set " .
99 "', user_id = '" . trim($user_id) .
100 "', closed = '" . trim($closed) .
101 "', reference = '" . trim(formData('check_number')) .
102 "', check_date = '" . trim($check_date) .
103 "', deposit_date = '" . trim($deposit_date) .
104 "', pay_total = '" . trim(formData('payment_amount')) .
105 "', modified_time = '" . trim($modified_time) .
106 "', payment_type = '" . trim(formData('type_name')) .
107 "', description = '" . trim(formData('description')) .
108 "', adjustment_code = '" . trim(formData('adjustment_code')) .
109 "', post_to_date = '" . trim($post_to_date) .
110 "', payment_method = '" . trim(formData('payment_method')) .
111 "' where session_id='$payment_id'");
112 //===============================================================================
113 $CountIndexAbove=$_REQUEST['CountIndexAbove'];
114 $CountIndexBelow=$_REQUEST['CountIndexBelow'];
115 $hidden_patient_code=$_REQUEST['hidden_patient_code'];
116 $user_id=$_SESSION['authUserID'];
117 $created_time = date('Y-m-d H:i:s');
118 //==================================================================
120 //It is done with out deleting any old entries.
121 //==================================================================
122 for ($CountRow=1; $CountRow<=$CountIndexAbove; $CountRow++
) {
123 if (isset($_POST["HiddenEncounter$CountRow"])) {
124 if (isset($_POST["Payment$CountRow"]) && $_POST["Payment$CountRow"]*1>0) {
125 if (trim(formData('type_name'))=='insurance') {
126 if (trim(formData("HiddenIns$CountRow"))==1) {
130 if (trim(formData("HiddenIns$CountRow"))==2) {
134 if (trim(formData("HiddenIns$CountRow"))==3) {
137 } elseif (trim(formData('type_name'))=='patient') {
141 $resPayment = sqlStatement("SELECT * from ar_activity " .
142 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow")) .
143 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
144 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
145 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
146 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
147 "' and pay_amount>0");
148 if (sqlNumRows($resPayment)>0) {
149 sqlStatement("update ar_activity set " .
150 " post_user = '" . trim($user_id) .
151 "', modified_time = '" . trim($created_time) .
152 "', pay_amount = '" . trim(formData("Payment$CountRow")) .
153 "', account_code = '" . "$AccountCode" .
154 "', payer_type = '" . trim(formData("HiddenIns$CountRow")) .
155 "', reason_code = '" . trim(formData("ReasonCode$CountRow")) .
156 "' where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow")) .
157 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
158 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
159 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
160 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
161 "' and pay_amount>0");
164 $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"))));
165 sqlStatement("insert into ar_activity set " .
166 "pid = '" . trim(formData("HiddenPId$CountRow")) .
167 "', encounter = '" . trim(formData("HiddenEncounter$CountRow")) .
168 "', sequence_no = '" . $sequence_no['increment'] .
169 "', code_type = '" . trim(formData("HiddenCodetype$CountRow")) .
170 "', code = '" . trim(formData("HiddenCode$CountRow")) .
171 "', modifier = '" . trim(formData("HiddenModifier$CountRow")) .
172 "', payer_type = '" . trim(formData("HiddenIns$CountRow")) .
173 "', reason_code = '" . trim(formData("ReasonCode$CountRow")) .
174 "', post_time = '" . trim($created_time) .
175 "', post_user = '" . trim($user_id) .
176 "', session_id = '" . trim(formData('payment_id')) .
177 "', modified_time = '" . trim($created_time) .
178 "', pay_amount = '" . trim(formData("Payment$CountRow")) .
179 "', adj_amount = '" . 0 .
180 "', account_code = '" . "$AccountCode" .
185 sqlStatement("delete from ar_activity " .
186 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow")) .
187 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
188 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
189 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
190 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
191 "' and pay_amount>0");
194 //==============================================================================================================================
195 if (isset($_POST["AdjAmount$CountRow"]) && $_POST["AdjAmount$CountRow"]*1!=0) {
196 if (trim(formData('type_name'))=='insurance') {
197 $AdjustString="Ins adjust Ins".trim(formData("HiddenIns$CountRow"));
199 } elseif (trim(formData('type_name'))=='patient') {
200 $AdjustString="Pt adjust";
204 $resPayment = sqlStatement("SELECT * from ar_activity " .
205 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow")) .
206 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
207 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
208 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
209 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
210 "' and adj_amount!=0");
211 if (sqlNumRows($resPayment)>0) {
212 sqlStatement("update ar_activity set " .
213 " post_user = '" . trim($user_id) .
214 "', modified_time = '" . trim($created_time) .
215 "', adj_amount = '" . trim(formData("AdjAmount$CountRow")) .
216 "', memo = '" . "$AdjustString" .
217 "', account_code = '" . "$AccountCode" .
218 "', payer_type = '" . trim(formData("HiddenIns$CountRow")) .
219 "' where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow")) .
220 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
221 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
222 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
223 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
224 "' and adj_amount!=0");
227 $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"))));
228 sqlStatement("insert into ar_activity set " .
229 "pid = '" . trim(formData("HiddenPId$CountRow")) .
230 "', encounter = '" . trim(formData("HiddenEncounter$CountRow")) .
231 "', sequence_no = '" . $sequence_no['increment'] .
232 "', code_type = '" . trim(formData("HiddenCodetype$CountRow")) .
233 "', code = '" . trim(formData("HiddenCode$CountRow")) .
234 "', modifier = '" . trim(formData("HiddenModifier$CountRow")) .
235 "', payer_type = '" . trim(formData("HiddenIns$CountRow")) .
236 "', post_time = '" . trim($created_time) .
237 "', post_user = '" . trim($user_id) .
238 "', session_id = '" . trim(formData('payment_id')) .
239 "', modified_time = '" . trim($created_time) .
240 "', pay_amount = '" . 0 .
241 "', adj_amount = '" . trim(formData("AdjAmount$CountRow")) .
242 "', memo = '" . "$AdjustString" .
243 "', account_code = '" . "$AccountCode" .
248 sqlStatement("delete from ar_activity " .
249 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow")) .
250 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
251 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
252 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
253 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
254 "' and adj_amount!=0");
257 //==============================================================================================================================
258 if (isset($_POST["Deductible$CountRow"]) && $_POST["Deductible$CountRow"]*1>0) {
259 $resPayment = sqlStatement("SELECT * from ar_activity " .
260 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow")) .
261 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
262 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
263 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
264 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
265 "' and (memo like 'Deductable%' OR memo like 'Deductible%')");
266 if (sqlNumRows($resPayment)>0) {
267 sqlStatement("update ar_activity set " .
268 " post_user = '" . trim($user_id) .
269 "', modified_time = '" . trim($created_time) .
270 "', memo = '" . "Deductible $".trim(formData("Deductible$CountRow")) .
271 "', account_code = '" . "Deduct" .
272 "', payer_type = '" . trim(formData("HiddenIns$CountRow")) .
273 "' where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow")) .
274 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
275 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
276 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
277 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
278 "' and (memo like 'Deductable%' OR memo like 'Deductible%')");
281 $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"))));
282 sqlStatement("insert into ar_activity set " .
283 "pid = '" . trim(formData("HiddenPId$CountRow")) .
284 "', encounter = '" . trim(formData("HiddenEncounter$CountRow")) .
285 "', sequence_no = '" . $sequence_no['increment'] .
286 "', code_type = '" . trim(formData("HiddenCodetype$CountRow")) .
287 "', code = '" . trim(formData("HiddenCode$CountRow")) .
288 "', modifier = '" . trim(formData("HiddenModifier$CountRow")) .
289 "', payer_type = '" . trim(formData("HiddenIns$CountRow")) .
290 "', post_time = '" . trim($created_time) .
291 "', post_user = '" . trim($user_id) .
292 "', session_id = '" . trim(formData('payment_id')) .
293 "', modified_time = '" . trim($created_time) .
294 "', pay_amount = '" . 0 .
295 "', adj_amount = '" . 0 .
296 "', memo = '" . "Deductible $".trim(formData("Deductible$CountRow")) .
297 "', account_code = '" . "Deduct" .
302 sqlStatement("delete from ar_activity " .
303 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow")) .
304 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
305 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
306 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
307 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
308 "' and (memo like 'Deductable%' OR memo like 'Deductible%')");
311 //==============================================================================================================================
312 if (isset($_POST["Takeback$CountRow"]) && $_POST["Takeback$CountRow"]*1>0) {
313 $resPayment = sqlStatement("SELECT * from ar_activity " .
314 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow")) .
315 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
316 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
317 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
318 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
319 "' and pay_amount < 0");
320 if (sqlNumRows($resPayment)>0) {
321 sqlStatement("update ar_activity set " .
322 " post_user = '" . trim($user_id) .
323 "', modified_time = '" . trim($created_time) .
324 "', pay_amount = '" . trim(formData("Takeback$CountRow"))*-1 .
325 "', account_code = '" . "Takeback" .
326 "', payer_type = '" . trim(formData("HiddenIns$CountRow")) .
327 "' where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow")) .
328 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
329 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
330 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
331 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
332 "' and pay_amount < 0");
335 $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"))));
336 sqlStatement("insert into ar_activity set " .
337 "pid = '" . trim(formData("HiddenPId$CountRow")) .
338 "', encounter = '" . trim(formData("HiddenEncounter$CountRow")) .
339 "', sequence_no = '" . $sequence_no['increment'] .
340 "', code_type = '" . trim(formData("HiddenCodetype$CountRow")) .
341 "', code = '" . trim(formData("HiddenCode$CountRow")) .
342 "', modifier = '" . trim(formData("HiddenModifier$CountRow")) .
343 "', payer_type = '" . trim(formData("HiddenIns$CountRow")) .
344 "', post_time = '" . trim($created_time) .
345 "', post_user = '" . trim($user_id) .
346 "', session_id = '" . trim(formData('payment_id')) .
347 "', modified_time = '" . trim($created_time) .
348 "', pay_amount = '" . trim(formData("Takeback$CountRow"))*-1 .
349 "', adj_amount = '" . 0 .
350 "', account_code = '" . "Takeback" .
355 sqlStatement("delete from ar_activity " .
356 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow")) .
357 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
358 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
359 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
360 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
361 "' and pay_amount < 0");
364 //==============================================================================================================================
365 if (isset($_POST["FollowUp$CountRow"]) && $_POST["FollowUp$CountRow"]=='y') {
366 $resPayment = sqlStatement("SELECT * from ar_activity " .
367 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow")) .
368 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
369 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
370 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
371 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
372 "' and follow_up ='y'");
373 if (sqlNumRows($resPayment)>0) {
374 sqlStatement("update ar_activity set " .
375 " post_user = '" . trim($user_id) .
376 "', modified_time = '" . trim($created_time) .
377 "', follow_up = '" . "y" .
378 "', follow_up_note = '" . trim(formData("FollowUpReason$CountRow")) .
379 "', payer_type = '" . trim(formData("HiddenIns$CountRow")) .
380 "' where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow")) .
381 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
382 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
383 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
384 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
385 "' and follow_up ='y'");
388 $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"))));
389 sqlStatement("insert into ar_activity set " .
390 "pid = '" . trim(formData("HiddenPId$CountRow")) .
391 "', encounter = '" . trim(formData("HiddenEncounter$CountRow")) .
392 "', sequence_no = '" . $sequence_no['increment'] .
393 "', code_type = '" . trim(formData("HiddenCodetype$CountRow")) .
394 "', code = '" . trim(formData("HiddenCode$CountRow")) .
395 "', modifier = '" . trim(formData("HiddenModifier$CountRow")) .
396 "', payer_type = '" . trim(formData("HiddenIns$CountRow")) .
397 "', post_time = '" . trim($created_time) .
398 "', post_user = '" . trim($user_id) .
399 "', session_id = '" . trim(formData('payment_id')) .
400 "', modified_time = '" . trim($created_time) .
401 "', pay_amount = '" . 0 .
402 "', adj_amount = '" . 0 .
403 "', follow_up = '" . "y" .
404 "', follow_up_note = '" . trim(formData("FollowUpReason$CountRow")) .
409 sqlStatement("delete from ar_activity " .
410 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow")) .
411 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
412 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
413 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
414 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
415 "' and follow_up ='y'");
418 //==============================================================================================================================
425 //INSERTION of new entries,continuation of modification.
427 for ($CountRow=$CountIndexAbove+
1; $CountRow<=$CountIndexAbove+
$CountIndexBelow; $CountRow++
) {
428 if (isset($_POST["HiddenEncounter$CountRow"])) {
429 DistributionInsert($CountRow, $created_time, $user_id);
435 if ($_REQUEST['global_amount']=='yes') {
436 sqlStatement("update ar_session set global_amount=".trim(formData("HidUnappliedAmount"))*1 ." where session_id ='$payment_id'");
439 if ($_POST["mode"]=="FinishPayments") {
443 $_POST["mode"] = "searchdatabase";
448 //==============================================================================
450 //===============================================================================
451 $payment_id=$payment_id*1 > 0 ?
$payment_id : $_REQUEST['payment_id'];
452 $ResultSearchSub = sqlStatement("SELECT distinct encounter,code_type,code,modifier, pid from ar_activity where session_id ='$payment_id' order by pid,encounter,code,modifier");
453 //==============================================================================
455 //==============================================================================
456 //===============================================================================
461 <?php
if (function_exists('html_header_show')) {
465 <link rel
="stylesheet" href
="<?php echo $css_header;?>" type
="text/css">
466 <link rel
="stylesheet" type
="text/css" href
="../../library/js/fancybox/jquery.fancybox-1.2.6.css" media
="screen" />
467 <link rel
="stylesheet" href
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.min.css">
469 <!-- supporting javascript code
-->
470 <script type
="text/javascript" src
="../../library/textformat.js?v=<?php echo $v_js_includes; ?>"></script
>
471 <script type
="text/javascript" src
="../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script
>
472 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-7-2/index.js"></script
>
473 <script type
="text/javascript" src
="../../library/js/fancybox/jquery.fancybox-1.2.6.js"></script
>
474 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.full.min.js"></script
>
476 <script language
='JavaScript'>
479 <?php
include_once("{$GLOBALS['srcdir']}/payment_jav.inc.php"); ?
>
480 <?php
include_once("{$GLOBALS['srcdir']}/ajax/payment_ajax_jav.inc.php"); ?
>
481 <script type
="text/javascript" src
="../../library/js/common.js?v=<?php echo $v_js_includes; ?>"></script
>
482 <script LANGUAGE
="javascript" TYPE
="text/javascript">
483 function ModifyPayments()
484 {//Used while modifying the allocation
485 if(!FormValidations())//FormValidations contains the form checks
489 if(CompletlyBlankAbove())//The distribution rows already in the database are checked.
491 alert("<?php echo htmlspecialchars(xl('None of the Top Distribution Row Can be Completly Blank.'), ENT_QUOTES);
492 echo htmlspecialchars('\n');echo htmlspecialchars(xl('Use Delete Option to Remove.'), ENT_QUOTES) ?>")
495 if(!CheckPayingEntityAndDistributionPostFor())//Ensures that Insurance payment is distributed under Ins1,Ins2,Ins3 and Patient paymentat under Pat.
499 if(CompletlyBlankBelow())//The newly added distribution rows are checked.
501 alert("<?php echo htmlspecialchars(xl('Fill any of the Below Row.'), ENT_QUOTES) ?>")
504 PostValue
=CheckUnappliedAmount();//Decides TdUnappliedAmount >0, or <0 or =0
507 alert("<?php echo htmlspecialchars(xl('Cannot Modify Payments.Undistributed is Negative.'), ENT_QUOTES) ?>")
510 if(confirm("<?php echo htmlspecialchars(xl('Would you like to Modify Payments?'), ENT_QUOTES) ?>"))
512 document
.getElementById('mode').value
='ModifyPayments';
513 top
.restoreSession();
514 document
.forms
[0].submit();
519 function FinishPayments()
521 if(!FormValidations())//FormValidations contains the form checks
525 if(CompletlyBlankAbove())//The distribution rows already in the database are checked.
527 alert("<?php echo htmlspecialchars(xl('None of the Top Distribution Row Can be Completly Blank.'), ENT_QUOTES);
528 echo htmlspecialchars('\n');echo htmlspecialchars(xl('Use Delete Option to Remove.'), ENT_QUOTES) ?>")
531 if(!CheckPayingEntityAndDistributionPostFor())//Ensures that Insurance payment is distributed under Ins1,Ins2,Ins3 and Patient paymentat under Pat.
535 if(CompletlyBlankBelow())//The newly added distribution rows are checked.
537 alert("<?php echo htmlspecialchars(xl('Fill any of the Below Row.'), ENT_QUOTES) ?>")
540 PostValue
=CheckUnappliedAmount();//Decides TdUnappliedAmount >0, or <0 or =0
543 alert("<?php echo htmlspecialchars(xl('Cannot Modify Payments.Undistributed is Negative.'), ENT_QUOTES) ?>")
548 if(confirm("<?php echo htmlspecialchars(xl('Would you like to Modify and Finish Payments?'), ENT_QUOTES) ?>"))
550 UnappliedAmount
=document
.getElementById('TdUnappliedAmount').innerHTML
*1;
551 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) ?>"))
553 document
.getElementById('mode').value
='FinishPayments';
554 document
.getElementById('global_amount').value
='yes';
555 top
.restoreSession();
556 document
.forms
[0].submit();
560 document
.getElementById('mode').value
='FinishPayments';
561 top
.restoreSession();
562 document
.forms
[0].submit();
570 if(confirm("<?php echo htmlspecialchars(xl('Would you like to Modify and Finish Payments?'), ENT_QUOTES) ?>"))
572 document
.getElementById('mode').value
='FinishPayments';
573 top
.restoreSession();
574 document
.forms
[0].submit();
581 function CompletlyBlankAbove()
582 {//The distribution rows already in the database are checked.
583 //It is not allowed to be made completly empty.If needed delete option need to be used.
584 CountIndexAbove
=document
.getElementById('CountIndexAbove').value
*1;
585 for(RowCount
=1;RowCount
<=CountIndexAbove
;RowCount++
)
587 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)
594 function CompletlyBlankBelow()
595 {//The newly added distribution rows are checked.
596 //It is not allowed to be made completly empty.
597 CountIndexAbove
=document
.getElementById('CountIndexAbove').value
*1;
598 CountIndexBelow
=document
.getElementById('CountIndexBelow').value
*1;
599 if(CountIndexBelow
==0)
601 for(RowCount
=CountIndexAbove+
1;RowCount
<=CountIndexAbove+CountIndexBelow
;RowCount++
)
603 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)
612 function OnloadAction()
613 {//Displays message while loading after some action.
614 after_value
=document
.getElementById('ActionStatus').value
;
615 if(after_value
=='Delete')
617 alert("<?php echo htmlspecialchars(xl('Successfully Deleted'), ENT_QUOTES) ?>")
620 if(after_value
=='Modify' || after_value
=='Finish')
622 alert("<?php echo htmlspecialchars(xl('Successfully Modified'), ENT_QUOTES) ?>")
625 after_value
=document
.getElementById('after_value').value
;
626 payment_id
=document
.getElementById('payment_id').value
;
627 if(after_value
=='distribute')
630 else if(after_value
=='new_payment')
632 if(document
.getElementById('TablePatientPortion'))
634 document
.getElementById('TablePatientPortion').style
.display
='none';
636 if(confirm("<?php echo htmlspecialchars(xl('Successfully Saved.Would you like to Distribute?'), ENT_QUOTES) ?>"))
638 if(document
.getElementById('TablePatientPortion'))
640 document
.getElementById('TablePatientPortion').style
.display
='';
646 function DeletePaymentDistribution(DeleteId
)
647 {//Confirms deletion of payment distribution.
648 if(confirm("<?php echo htmlspecialchars(xl('Would you like to Delete Payment Distribution?'), ENT_QUOTES) ?>"))
650 document
.getElementById('mode').value
='DeletePaymentDistribution';
651 document
.getElementById('DeletePaymentDistributionId').value
=DeleteId
;
652 top
.restoreSession();
653 document
.forms
[0].submit();
658 //========================================================================================
660 $
(document
).ready(function() {
661 $
('.datepicker').datetimepicker({
662 <?php
$datetimepicker_timepicker = false; ?
>
663 <?php
$datetimepicker_showseconds = false; ?
>
664 <?php
$datetimepicker_formatInput = true; ?
>
665 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
666 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
671 <script language
="javascript" type
="text/javascript">
672 document
.onclick
=HideTheAjaxDivs
;
675 .class1
{width
:125px
;}
676 .class2
{width
:250px
;}
677 .class3
{width
:100px
;}
678 .bottom
{border
-bottom
:1px solid black
;}
679 .top
{border
-top
:1px solid black
;}
680 .left
{border
-left
:1px solid black
;}
681 .right
{border
-right
:1px solid black
;}
682 #ajax_div_insurance {
689 background
-color
: #FBFDD0;
690 border
: 1px solid
#ccc;
700 background
-color
: #FBFDD0;
701 border
: 1px solid
#ccc;
705 <link rel
="stylesheet" href
="<?php echo $css_header; ?>" type
="text/css">
707 <body
class="body_top" onLoad
="OnloadAction()" >
708 <form name
='new_payment' method
='post' action
="edit_payment.php" onsubmit
='
710 if ($payment_id*1==0) {
712 top.restoreSession();return SavePayment();
720 ' style
="display:inline" >
721 <table width
="1024" border
="0" cellspacing
="0" cellpadding
="0">
723 if ($_REQUEST['ParentPage']=='new_payment') {
726 <td colspan
="3" align
="left"><b
><?php
echo htmlspecialchars(xl('Payments'), ENT_QUOTES
) ?
></b
></td
>
729 <td colspan
="3" align
="left" ></td
>
732 <td colspan
="3" align
="left">
734 <li
class='current'><a href
='new_payment.php'><?php
echo htmlspecialchars(xl('New Payment'), ENT_QUOTES
) ?
></a
></li
>
735 <li
><a href
='search_payments.php'><?php
echo htmlspecialchars(xl('Search Payment'), ENT_QUOTES
) ?
></a
></li
>
736 <li
><a href
='era_payments.php'><?php
echo htmlspecialchars(xl('ERA Posting'), ENT_QUOTES
) ?
></a
></li
>
743 <td colspan
="3" align
="left" ></td
>
749 <td colspan
="3" align
="left" >
752 if ($payment_id*1>0) {
755 require_once("payment_master.inc.php"); //Check/cash details are entered here.
767 if ($payment_id*1>0) {//Distribution rows already in the database are displayed.
770 <table width
="1024" border
="0" cellspacing
="0" cellpadding
="10" bgcolor
="#DEDEDE"><tr
><td
>
771 <table width
="1004" border
="0" cellspacing
="0" cellpadding
="0">
774 <td colspan
="13" align
="left" >
777 $resCount = sqlStatement("SELECT distinct encounter,code_type,code,modifier from ar_activity where session_id ='$payment_id' ");
778 $TotalRows=sqlNumRows($resCount);
787 if ($RowSearchSub = sqlFetchArray($ResultSearchSub)) {
790 $PId=$RowSearchSub['pid'];
791 $EncounterMaster=$RowSearchSub['encounter'];
792 // Only use the code_type in the queries below if it is specified in the ar_activity table.
793 // If it is not specified in the ar_activity table, also note it is not requested from the
794 // billing table in below query, thus making it blank in all queries below in this script.
795 $CodetypeMaster=$RowSearchSub['code_type'];
796 $sql_select_part_codetype = "";
797 $sql_where_part_codetype = "";
798 if (!empty($CodetypeMaster)) {
799 $sql_select_part_codetype = "billing.code_type,";
800 $sql_where_part_codetype = "and billing.code_type ='$CodetypeMaster'";
803 $CodeMaster=$RowSearchSub['code'];
804 $ModifierMaster=$RowSearchSub['modifier'];
805 $res = sqlStatement("SELECT fname,lname,mname FROM patient_data where pid ='$PId'");
806 $row = sqlFetchArray($res);
807 $fname=$row['fname'];
808 $lname=$row['lname'];
809 $mname=$row['mname'];
810 $NameDB=$lname.' '.$fname.' '.$mname;
811 $ResultSearch = sqlStatement("SELECT billing.id,last_level_closed,billing.encounter,form_encounter.`date`,$sql_select_part_codetype billing.code,billing.modifier,fee
812 FROM billing ,form_encounter
813 where billing.encounter=form_encounter.encounter and billing.pid=form_encounter.pid and
814 code_type!='ICD9' and code_type!='COPAY' and billing.activity!=0 and
815 form_encounter.pid ='$PId' and billing.pid ='$PId' and billing.encounter ='$EncounterMaster'
816 $sql_where_part_codetype
817 and billing.code ='$CodeMaster'
818 and billing.modifier ='$ModifierMaster'
819 ORDER BY form_encounter.`date`,form_encounter.encounter,billing.code,billing.modifier");
820 if (sqlNumRows($ResultSearch)>0) {
821 if ($CountPatient==1) {
824 <table width
="1004" border
="0" cellpadding
="0" cellspacing
="0" align
="center" id
="TableDistributePortion">
825 <tr
class="text" bgcolor
="#dddddd">
826 <td width
="25" class="left top" > 
;</td
>
827 <td width
="144" class="left top" ><?php
echo htmlspecialchars(xl('Patient Name'), ENT_QUOTES
) ?
></td
>
828 <td width
="55" class="left top" ><?php
echo htmlspecialchars(xl('Post For'), ENT_QUOTES
) ?
></td
>
829 <td width
="70" class="left top" ><?php
echo htmlspecialchars(xl('Service Date'), ENT_QUOTES
) ?
></td
>
830 <td width
="50" class="left top" ><?php
echo htmlspecialchars(xl('Encounter'), ENT_QUOTES
) ?
></td
>
831 <td width
="65" class="left top" ><?php
echo htmlspecialchars(xl('Service Code'), ENT_QUOTES
) ?
></td
>
832 <td width
="50" class="left top" ><?php
echo htmlspecialchars(xl('Charge'), ENT_QUOTES
) ?
></td
>
833 <td width
="40" class="left top" ><?php
echo htmlspecialchars(xl('Copay'), ENT_QUOTES
) ?
></td
>
834 <td width
="40" class="left top" ><?php
echo htmlspecialchars(xl('Remdr'), ENT_QUOTES
) ?
></td
>
835 <td width
="60" class="left top" ><?php
echo htmlspecialchars(xl('Allowed(c)'), ENT_QUOTES
) ?
></td
><!-- (c
) means it is calculated
.Not stored one
. -->
836 <td width
="60" class="left top" ><?php
echo htmlspecialchars(xl('Payment'), ENT_QUOTES
) ?
></td
>
837 <td width
="70" class="left top" ><?php
echo htmlspecialchars(xl('Adj Amount'), ENT_QUOTES
) ?
></td
>
838 <td width
="60" class="left top" ><?php
echo htmlspecialchars(xl('Deductible'), ENT_QUOTES
) ?
></td
>
839 <td width
="60" class="left top" ><?php
echo htmlspecialchars(xl('Takeback'), ENT_QUOTES
) ?
></td
>
840 <td width
="60" class="left top" ><?php
echo htmlspecialchars(xl('MSP Code'), ENT_QUOTES
) ?
></td
>
841 <td width
="40" class="left top" ><?php
echo htmlspecialchars(xl('Resn'), ENT_QUOTES
) ?
></td
>
842 <td width
="110" class="left top right" ><?php
echo htmlspecialchars(xl('Follow Up Reason'), ENT_QUOTES
) ?
></td
>
847 while ($RowSearch = sqlFetchArray($ResultSearch)) {
850 $ServiceDateArray=explode(' ', $RowSearch['date']);
851 $ServiceDate=oeFormatShortDate($ServiceDateArray[0]);
852 $Codetype=$RowSearch['code_type'];
853 $Code=$RowSearch['code'];
854 $Modifier =$RowSearch['modifier'];
856 $ModifierString=", $Modifier";
861 $Fee=$RowSearch['fee'];
862 $Encounter=$RowSearch['encounter'];
864 $resPayer = sqlStatement("SELECT payer_type from ar_activity where session_id ='$payment_id' and
865 pid ='$PId' and encounter ='$Encounter' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' ");
866 $rowPayer = sqlFetchArray($resPayer);
867 $Ins=$rowPayer['payer_type'];
869 //Always associating the copay to a particular charge.
870 $BillingId=$RowSearch['id'];
871 $resId = sqlStatement("SELECT id FROM billing where code_type!='ICD9' and code_type!='COPAY' and
872 pid ='$PId' and encounter ='$Encounter' and billing.activity!=0 order by id");
873 $rowId = sqlFetchArray($resId);
876 if ($BillingId!=$Id) {//multiple cpt in single encounter
879 $resCopay = sqlStatement("SELECT sum(fee) as copay FROM billing where
880 code_type='COPAY' and pid ='$PId' and encounter ='$Encounter' and billing.activity!=0");
881 $rowCopay = sqlFetchArray($resCopay);
882 $Copay=$rowCopay['copay']*-1;
884 $resMoneyGot = sqlStatement("SELECT sum(pay_amount) as PatientPay FROM ar_activity where
885 pid ='$PId' and encounter ='$Encounter' and payer_type=0 and account_code='PCP'");//new fees screen copay gives account_code='PCP'
886 $rowMoneyGot = sqlFetchArray($resMoneyGot);
887 $PatientPay=$rowMoneyGot['PatientPay'];
889 $Copay=$Copay+
$PatientPay;
892 //For calculating Remainder
893 if ($Ins==0) {//Fetch all values
894 $resMoneyGot = sqlStatement("SELECT sum(pay_amount) as MoneyGot FROM ar_activity where
895 pid ='$PId' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and encounter ='$Encounter' and !(payer_type=0 and
896 account_code='PCP')");
897 //new fees screen copay gives account_code='PCP'
898 $rowMoneyGot = sqlFetchArray($resMoneyGot);
899 $MoneyGot=$rowMoneyGot['MoneyGot'];
901 $resMoneyAdjusted = sqlStatement("SELECT sum(adj_amount) as MoneyAdjusted FROM ar_activity where
902 pid ='$PId' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and encounter ='$Encounter'");
903 $rowMoneyAdjusted = sqlFetchArray($resMoneyAdjusted);
904 $MoneyAdjusted=$rowMoneyAdjusted['MoneyAdjusted'];
905 } else //Fetch till that much got
907 //Fetch the HIGHEST sequence_no till this session.
908 //Used maily in the case if primary/others pays once more.
909 $resSequence = sqlStatement("SELECT sequence_no from ar_activity where session_id ='$payment_id' and
910 pid ='$PId' and encounter ='$Encounter' order by sequence_no desc ");
911 $rowSequence = sqlFetchArray($resSequence);
912 $Sequence=$rowSequence['sequence_no'];
914 $resMoneyGot = sqlStatement("SELECT sum(pay_amount) as MoneyGot FROM ar_activity where
915 pid ='$PId' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and encounter ='$Encounter' and
916 payer_type > 0 and payer_type <='$Ins' and sequence_no<='$Sequence'");
917 $rowMoneyGot = sqlFetchArray($resMoneyGot);
918 $MoneyGot=$rowMoneyGot['MoneyGot'];
920 $resMoneyAdjusted = sqlStatement("SELECT sum(adj_amount) as MoneyAdjusted FROM ar_activity where
921 pid ='$PId' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and encounter ='$Encounter' and
922 payer_type > 0 and payer_type <='$Ins' and sequence_no<='$Sequence'");
923 $rowMoneyAdjusted = sqlFetchArray($resMoneyAdjusted);
924 $MoneyAdjusted=$rowMoneyAdjusted['MoneyAdjusted'];
927 $Remainder=$Fee-$Copay-$MoneyGot-$MoneyAdjusted;
929 //For calculating RemainderJS.Used while restoring back the values.
930 if ($Ins==0) {//Got just before Patient
931 $resMoneyGot = sqlStatement("SELECT sum(pay_amount) as MoneyGot FROM ar_activity where
932 pid ='$PId' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and encounter ='$Encounter' and payer_type !=0");
933 $rowMoneyGot = sqlFetchArray($resMoneyGot);
934 $MoneyGot=$rowMoneyGot['MoneyGot'];
936 $resMoneyAdjusted = sqlStatement("SELECT sum(adj_amount) as MoneyAdjusted FROM ar_activity where
937 pid ='$PId' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and encounter ='$Encounter' and payer_type !=0");
938 $rowMoneyAdjusted = sqlFetchArray($resMoneyAdjusted);
939 $MoneyAdjusted=$rowMoneyAdjusted['MoneyAdjusted'];
940 } else {//Got just before the previous
941 //Fetch the LOWEST sequence_no till this session.
942 //Used maily in the case if primary/others pays once more.
943 $resSequence = sqlStatement("SELECT sequence_no from ar_activity where session_id ='$payment_id' and
944 pid ='$PId' and encounter ='$Encounter' order by sequence_no ");
945 $rowSequence = sqlFetchArray($resSequence);
946 $Sequence=$rowSequence['sequence_no'];
948 $resMoneyGot = sqlStatement("SELECT sum(pay_amount) as MoneyGot FROM ar_activity where
949 pid ='$PId' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and encounter ='$Encounter'
950 and payer_type > 0 and payer_type <='$Ins' and sequence_no<'$Sequence'");
951 $rowMoneyGot = sqlFetchArray($resMoneyGot);
952 $MoneyGot=$rowMoneyGot['MoneyGot'];
954 $resMoneyAdjusted = sqlStatement("SELECT sum(adj_amount) as MoneyAdjusted FROM ar_activity where
955 pid ='$PId' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and encounter ='$Encounter'
956 and payer_type <='$Ins' and sequence_no<'$Sequence' ");
957 $rowMoneyAdjusted = sqlFetchArray($resMoneyAdjusted);
958 $MoneyAdjusted=$rowMoneyAdjusted['MoneyAdjusted'];
961 //Stored in hidden so that can be used while restoring back the values.
962 $RemainderJS=$Fee-$Copay-$MoneyGot-$MoneyAdjusted;
964 $resPayment = sqlStatement("SELECT pay_amount from ar_activity where session_id ='$payment_id' and
965 pid ='$PId' and encounter ='$Encounter' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and pay_amount>0");
966 $rowPayment = sqlFetchArray($resPayment);
967 $PaymentDB=$rowPayment['pay_amount']*1;
968 $PaymentDB=$PaymentDB == 0 ?
'' : $PaymentDB;
970 $resPayment = sqlStatement("SELECT pay_amount from ar_activity where session_id ='$payment_id' and
971 pid ='$PId' and encounter ='$Encounter' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and pay_amount<0");
972 $rowPayment = sqlFetchArray($resPayment);
973 $TakebackDB=$rowPayment['pay_amount']*-1;
974 $TakebackDB=$TakebackDB == 0 ?
'' : $TakebackDB;
976 $resPayment = sqlStatement("SELECT adj_amount from ar_activity where session_id ='$payment_id' and
977 pid ='$PId' and encounter ='$Encounter' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and adj_amount!=0");
978 $rowPayment = sqlFetchArray($resPayment);
979 $AdjAmountDB=$rowPayment['adj_amount']*1;
980 $AdjAmountDB=$AdjAmountDB == 0 ?
'' : $AdjAmountDB;
982 $resPayment = sqlStatement("SELECT memo from ar_activity where session_id ='$payment_id' and
983 pid ='$PId' and encounter ='$Encounter' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and (memo like 'Deductable%' OR memo like 'Deductible%')");
984 $rowPayment = sqlFetchArray($resPayment);
985 $DeductibleDB=$rowPayment['memo'];
986 $DeductibleDB=str_replace('Deductable $', '', $DeductibleDB);
987 $DeductibleDB=str_replace('Deductible $', '', $DeductibleDB);
989 $resPayment = sqlStatement("SELECT follow_up,follow_up_note from ar_activity where session_id ='$payment_id' and
990 pid ='$PId' and encounter ='$Encounter' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and follow_up = 'y'");
991 $rowPayment = sqlFetchArray($resPayment);
992 $FollowUpDB=$rowPayment['follow_up'];
993 $FollowUpReasonDB=$rowPayment['follow_up_note'];
995 $resPayment = sqlStatement("SELECT reason_code from ar_activity where session_id ='$payment_id' and
996 pid ='$PId' and encounter ='$Encounter' and code_type='$Codetype' and code='$Code' and modifier='$Modifier'");
997 $rowPayment = sqlFetchArray($resPayment);
998 $ReasonCodeDB=$rowPayment['reason_code'];
1001 $AllowedDB=number_format($Fee-$AdjAmountDB, 2);
1006 $AllowedDB=$AllowedDB == 0 ?
'' : $AllowedDB;
1008 if ($CountIndex==$TotalRows) {
1009 $StringClass=' bottom left top ';
1011 $StringClass=' left top ';
1016 } elseif ($Ins==2) {
1018 } elseif ($Ins==3) {
1020 } elseif ($Ins==0) {
1024 $paymenttot=$paymenttot+
$PaymentDB;
1025 $adjamttot=$adjamttot+
$AdjAmountDB;
1026 $deductibletot=$deductibletot+
$DeductibleDB;
1027 $takebacktot=$takebacktot+
$TakebackDB;
1028 $allowedtot=$allowedtot+
$AllowedDB;
1030 <tr
class="text" bgcolor
='<?php echo $bgcolor; ?>' id
="trCharges<?php echo $CountIndex; ?>">
1031 <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
>
1032 <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
>
1033 <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
>
1034 <td
class="<?php echo $StringClass; ?>" ><?php
echo htmlspecialchars($ServiceDate); ?
></td
>
1035 <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
>
1036 <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
>
1037 <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
>
1038 <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
>
1039 <td align
="right" id
="RemainderTd<?php echo $CountIndex; ?>" class="<?php echo $StringClass; ?>" ><?php
echo htmlspecialchars(round($Remainder, 2)); ?
></td
>
1040 <input name
="HiddenRemainderTd<?php echo $CountIndex; ?>" id
="HiddenRemainderTd<?php echo $CountIndex; ?>" value
="<?php echo htmlspecialchars(round($RemainderJS, 2)); ?>" type
="hidden"/>
1041 <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
>
1042 <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
>
1043 <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
>
1044 <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
>
1045 <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
>
1046 <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
>
1047 <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
>
1048 <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
>
1051 }//while ($RowSearch = sqlFetchArray($ResultSearch))
1054 }//if(sqlNumRows($ResultSearch)>0)
1055 } while ($RowSearchSub = sqlFetchArray($ResultSearchSub));
1056 if ($Table=='yes') {
1059 <td align
="left" colspan
="9"> 
;</td
>
1060 <td
class="left bottom" bgcolor
="#6699FF" id
="allowtotal" align
="right" ><?php
echo htmlspecialchars(number_format($allowedtot, 2)); ?
></td
>
1061 <td
class="left bottom" bgcolor
="#6699FF" id
="paymenttotal" align
="right" ><?php
echo htmlspecialchars(number_format($paymenttot, 2)); ?
></td
>
1062 <td
class="left bottom" bgcolor
="#6699FF" id
="AdjAmounttotal" align
="right" ><?php
echo htmlspecialchars(number_format($adjamttot, 2)); ?
></td
>
1063 <td
class="left bottom" bgcolor
="#6699FF" id
="deductibletotal" align
="right"><?php
echo htmlspecialchars(number_format($deductibletot, 2)); ?
></td
>
1064 <td
class="left bottom right" bgcolor
="#6699FF" id
="takebacktotal" align
="right"><?php
echo htmlspecialchars(number_format($takebacktot, 2)); ?
></td
>
1065 <td align
="center"> 
;</td
>
1066 <td align
="center"> 
;</td
>
1075 }//if($RowSearchSub = sqlFetchArray($ResultSearchSub))
1079 <td colspan
="13" align
="left" >
1081 require_once("payment_pat_sel.inc.php"); //Patient ajax section and listing of charges.
1086 <td colspan
="13" align
="left" >
1087 <table border
="0" cellspacing
="0" cellpadding
="0" width
="217" align
="center">
1094 <td width
="110"><a href
="#" onClick
="javascript:return ModifyPayments();" class="css_button"><span
><?php
echo htmlspecialchars(xl('Modify Payments'), ENT_QUOTES
);?
></span
></a
>
1096 <td width
="107"><a href
="#" onClick
="javascript:return FinishPayments();" class="css_button"><span
><?php
echo htmlspecialchars(xl('Finish Payments'), ENT_QUOTES
);?
></span
></a
>
1102 }//if($payment_id*1>0)
1108 <input type
="hidden" name
="hidden_patient_code" id
="hidden_patient_code" value
="<?php echo htmlspecialchars($hidden_patient_code);?>"/>
1109 <input type
='hidden' name
='mode' id
='mode' value
='' />
1110 <input type
='hidden' name
='ajax_mode' id
='ajax_mode' value
='' />
1111 <input type
="hidden" name
="after_value" id
="after_value" value
="<?php echo htmlspecialchars($_POST["mode
"]);?>"/>
1112 <input type
="hidden" name
="payment_id" id
="payment_id" value
="<?php echo htmlspecialchars($payment_id);?>"/>
1113 <input type
="hidden" name
="hidden_type_code" id
="hidden_type_code" value
="<?php echo htmlspecialchars($TypeCode);?>"/>
1114 <input type
='hidden' name
='global_amount' id
='global_amount' value
='' />
1115 <input type
='hidden' name
='DeletePaymentDistributionId' id
='DeletePaymentDistributionId' value
='' />
1116 <input type
="hidden" name
="ActionStatus" id
="ActionStatus" value
="<?php echo htmlspecialchars($Message);?>"/>
1117 <input type
='hidden' name
='CountIndexAbove' id
='CountIndexAbove' value
='<?php echo htmlspecialchars($CountIndexAbove*1);?>' />
1118 <input type
='hidden' name
='CountIndexBelow' id
='CountIndexBelow' value
='<?php echo htmlspecialchars($CountIndexBelow*1);?>' />
1119 <input type
="hidden" name
="ParentPage" id
="ParentPage" value
="<?php echo htmlspecialchars($_REQUEST['ParentPage']);?>"/>