change viewer calling paths (#1410)
[openemr.git] / interface / billing / edit_payment.php
blobc2992ae432c330d1e71793ae7d3b5ba5ec779426
1 <?php
2 // +-----------------------------------------------------------------------------+
3 // Copyright (C) 2010 Z&H Consultancy Services Private Limited <sam@zhservices.com>
4 //
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
18 // A copy of the GNU General Public License is included along with this program:
19 // openemr/interface/login/GnuGPL.html
20 // For more information write to the Free Software
21 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 // Author: Eldho Chacko <eldho@zhservices.com>
24 // Paul Simon K <paul@zhservices.com>
26 // +------------------------------------------------------------------------------+
27 //===============================================================================
28 //Payments can be edited here.It includes deletion of an allocation,modifying the
29 //same or adding a new allocation.Log is kept for the deleted ones.
30 //===============================================================================
31 require_once("../globals.php");
32 require_once("$srcdir/log.inc");
33 require_once("$srcdir/invoice_summary.inc.php");
34 require_once("$srcdir/sl_eob.inc.php");
35 require_once("$srcdir/parse_era.inc.php");
36 require_once("../../library/acl.inc");
37 require_once("$srcdir/auth.inc");
38 require_once("../../custom/code_types.inc.php");
39 require_once("$srcdir/patient.inc");
40 require_once("$srcdir/billrep.inc");
41 require_once("$srcdir/options.inc.php");
42 require_once("$srcdir/payment.inc.php");
43 //===============================================================================
44 $screen='edit_payment';
45 //===============================================================================
46 // deletion of payment distribution code
47 //===============================================================================
49 use OpenEMR\Core\Header;
51 if (isset($_POST["mode"])) {
52 if ($_POST["mode"] == "DeletePaymentDistribution") {
53 $DeletePaymentDistributionId=trim(formData('DeletePaymentDistributionId'));
54 $DeletePaymentDistributionIdArray=explode('_', $DeletePaymentDistributionId);
55 $payment_id=$DeletePaymentDistributionIdArray[0];
56 $PId=$DeletePaymentDistributionIdArray[1];
57 $Encounter=$DeletePaymentDistributionIdArray[2];
58 $Code=$DeletePaymentDistributionIdArray[3];
59 $Modifier=$DeletePaymentDistributionIdArray[4];
60 $Codetype=$DeletePaymentDistributionIdArray[5];
61 //delete and log that action
62 row_delete("ar_activity", "session_id ='$payment_id' and pid ='$PId' AND " .
63 "encounter='$Encounter' and code_type='$Codetype' and code='$Code' and modifier='$Modifier'");
64 $Message='Delete';
65 //------------------
66 $_POST["mode"] = "searchdatabase";
70 //===============================================================================
71 //Modify Payment Code.
72 //===============================================================================
73 if (isset($_POST["mode"])) {
74 if ($_POST["mode"] == "ModifyPayments" || $_POST["mode"] == "FinishPayments") {
75 $payment_id=$_REQUEST['payment_id'];
76 //ar_session Code
77 //===============================================================================
78 if (trim(formData('type_name'))=='insurance') {
79 $QueryPart="payer_id = '" . trim(formData('hidden_type_code')) .
80 "', patient_id = '" . 0 ;
81 } elseif (trim(formData('type_name'))=='patient') {
82 $QueryPart="payer_id = '" . 0 .
83 "', patient_id = '" . trim(formData('hidden_type_code')) ;
86 $user_id=$_SESSION['authUserID'];
87 $closed=0;
88 $modified_time = date('Y-m-d H:i:s');
89 $check_date=DateToYYYYMMDD(formData('check_date'));
90 $deposit_date=DateToYYYYMMDD(formData('deposit_date'));
91 $post_to_date=DateToYYYYMMDD(formData('post_to_date'));
92 if ($post_to_date=='') {
93 $post_to_date=date('Y-m-d');
96 if (formData('deposit_date')=='') {
97 $deposit_date=$post_to_date;
100 sqlStatement("update ar_session set " .
101 $QueryPart .
102 "', user_id = '" . trim($user_id) .
103 "', closed = '" . trim($closed) .
104 "', reference = '" . trim(formData('check_number')) .
105 "', check_date = '" . trim($check_date) .
106 "', deposit_date = '" . trim($deposit_date) .
107 "', pay_total = '" . trim(formData('payment_amount')) .
108 "', modified_time = '" . trim($modified_time) .
109 "', payment_type = '" . trim(formData('type_name')) .
110 "', description = '" . trim(formData('description')) .
111 "', adjustment_code = '" . trim(formData('adjustment_code')) .
112 "', post_to_date = '" . trim($post_to_date) .
113 "', payment_method = '" . trim(formData('payment_method')) .
114 "' where session_id='$payment_id'");
115 //===============================================================================
116 $CountIndexAbove=$_REQUEST['CountIndexAbove'];
117 $CountIndexBelow=$_REQUEST['CountIndexBelow'];
118 $hidden_patient_code=$_REQUEST['hidden_patient_code'];
119 $user_id=$_SESSION['authUserID'];
120 $created_time = date('Y-m-d H:i:s');
121 //==================================================================
122 //UPDATION
123 //It is done with out deleting any old entries.
124 //==================================================================
125 for ($CountRow=1; $CountRow<=$CountIndexAbove; $CountRow++) {
126 if (isset($_POST["HiddenEncounter$CountRow"])) {
127 if (isset($_POST["Payment$CountRow"]) && $_POST["Payment$CountRow"]*1>0) {
128 if (trim(formData('type_name'))=='insurance') {
129 if (trim(formData("HiddenIns$CountRow"))==1) {
130 $AccountCode="IPP";
133 if (trim(formData("HiddenIns$CountRow"))==2) {
134 $AccountCode="ISP";
137 if (trim(formData("HiddenIns$CountRow"))==3) {
138 $AccountCode="ITP";
140 } elseif (trim(formData('type_name'))=='patient') {
141 $AccountCode="PP";
144 $resPayment = sqlStatement("SELECT * from ar_activity " .
145 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow")) .
146 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
147 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
148 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
149 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
150 "' and pay_amount>0");
151 if (sqlNumRows($resPayment)>0) {
152 sqlStatement("update ar_activity set " .
153 " post_user = '" . trim($user_id) .
154 "', modified_time = '" . trim($created_time) .
155 "', pay_amount = '" . trim(formData("Payment$CountRow")) .
156 "', account_code = '" . "$AccountCode" .
157 "', payer_type = '" . trim(formData("HiddenIns$CountRow")) .
158 "', reason_code = '" . trim(formData("ReasonCode$CountRow")) .
159 "' where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow")) .
160 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
161 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
162 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
163 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
164 "' and pay_amount>0");
165 } else {
166 sqlBeginTrans();
167 $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"))));
168 sqlStatement("insert into ar_activity set " .
169 "pid = '" . trim(formData("HiddenPId$CountRow")) .
170 "', encounter = '" . trim(formData("HiddenEncounter$CountRow")) .
171 "', sequence_no = '" . $sequence_no['increment'] .
172 "', code_type = '" . trim(formData("HiddenCodetype$CountRow")) .
173 "', code = '" . trim(formData("HiddenCode$CountRow")) .
174 "', modifier = '" . trim(formData("HiddenModifier$CountRow")) .
175 "', payer_type = '" . trim(formData("HiddenIns$CountRow")) .
176 "', reason_code = '" . trim(formData("ReasonCode$CountRow")) .
177 "', post_time = '" . trim($created_time) .
178 "', post_user = '" . trim($user_id) .
179 "', session_id = '" . trim(formData('payment_id')) .
180 "', modified_time = '" . trim($created_time) .
181 "', pay_amount = '" . trim(formData("Payment$CountRow")) .
182 "', adj_amount = '" . 0 .
183 "', account_code = '" . "$AccountCode" .
184 "'");
185 sqlCommitTrans();
187 } else {
188 sqlStatement("delete from ar_activity " .
189 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow")) .
190 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
191 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
192 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
193 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
194 "' and pay_amount>0");
197 //==============================================================================================================================
198 if (isset($_POST["AdjAmount$CountRow"]) && $_POST["AdjAmount$CountRow"]*1!=0) {
199 if (trim(formData('type_name'))=='insurance') {
200 $AdjustString="Ins adjust Ins".trim(formData("HiddenIns$CountRow"));
201 $AccountCode="IA";
202 } elseif (trim(formData('type_name'))=='patient') {
203 $AdjustString="Pt adjust";
204 $AccountCode="PA";
207 $resPayment = sqlStatement("SELECT * from ar_activity " .
208 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow")) .
209 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
210 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
211 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
212 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
213 "' and adj_amount!=0");
214 if (sqlNumRows($resPayment)>0) {
215 sqlStatement("update ar_activity set " .
216 " post_user = '" . trim($user_id) .
217 "', modified_time = '" . trim($created_time) .
218 "', adj_amount = '" . trim(formData("AdjAmount$CountRow")) .
219 "', memo = '" . "$AdjustString" .
220 "', account_code = '" . "$AccountCode" .
221 "', payer_type = '" . trim(formData("HiddenIns$CountRow")) .
222 "' where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow")) .
223 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
224 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
225 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
226 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
227 "' and adj_amount!=0");
228 } else {
229 sqlBeginTrans();
230 $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"))));
231 sqlStatement("insert into ar_activity set " .
232 "pid = '" . trim(formData("HiddenPId$CountRow")) .
233 "', encounter = '" . trim(formData("HiddenEncounter$CountRow")) .
234 "', sequence_no = '" . $sequence_no['increment'] .
235 "', code_type = '" . trim(formData("HiddenCodetype$CountRow")) .
236 "', code = '" . trim(formData("HiddenCode$CountRow")) .
237 "', modifier = '" . trim(formData("HiddenModifier$CountRow")) .
238 "', payer_type = '" . trim(formData("HiddenIns$CountRow")) .
239 "', post_time = '" . trim($created_time) .
240 "', post_user = '" . trim($user_id) .
241 "', session_id = '" . trim(formData('payment_id')) .
242 "', modified_time = '" . trim($created_time) .
243 "', pay_amount = '" . 0 .
244 "', adj_amount = '" . trim(formData("AdjAmount$CountRow")) .
245 "', memo = '" . "$AdjustString" .
246 "', account_code = '" . "$AccountCode" .
247 "'");
248 sqlCommitTrans();
250 } else {
251 sqlStatement("delete from ar_activity " .
252 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow")) .
253 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
254 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
255 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
256 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
257 "' and adj_amount!=0");
260 //==============================================================================================================================
261 if (isset($_POST["Deductible$CountRow"]) && $_POST["Deductible$CountRow"]*1>0) {
262 $resPayment = sqlStatement("SELECT * from ar_activity " .
263 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow")) .
264 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
265 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
266 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
267 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
268 "' and (memo like 'Deductable%' OR memo like 'Deductible%')");
269 if (sqlNumRows($resPayment)>0) {
270 sqlStatement("update ar_activity set " .
271 " post_user = '" . trim($user_id) .
272 "', modified_time = '" . trim($created_time) .
273 "', memo = '" . "Deductible $".trim(formData("Deductible$CountRow")) .
274 "', account_code = '" . "Deduct" .
275 "', payer_type = '" . trim(formData("HiddenIns$CountRow")) .
276 "' where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow")) .
277 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
278 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
279 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
280 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
281 "' and (memo like 'Deductable%' OR memo like 'Deductible%')");
282 } else {
283 sqlBeginTrans();
284 $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"))));
285 sqlStatement("insert into ar_activity set " .
286 "pid = '" . trim(formData("HiddenPId$CountRow")) .
287 "', encounter = '" . trim(formData("HiddenEncounter$CountRow")) .
288 "', sequence_no = '" . $sequence_no['increment'] .
289 "', code_type = '" . trim(formData("HiddenCodetype$CountRow")) .
290 "', code = '" . trim(formData("HiddenCode$CountRow")) .
291 "', modifier = '" . trim(formData("HiddenModifier$CountRow")) .
292 "', payer_type = '" . trim(formData("HiddenIns$CountRow")) .
293 "', post_time = '" . trim($created_time) .
294 "', post_user = '" . trim($user_id) .
295 "', session_id = '" . trim(formData('payment_id')) .
296 "', modified_time = '" . trim($created_time) .
297 "', pay_amount = '" . 0 .
298 "', adj_amount = '" . 0 .
299 "', memo = '" . "Deductible $".trim(formData("Deductible$CountRow")) .
300 "', account_code = '" . "Deduct" .
301 "'");
302 sqlCommitTrans();
304 } else {
305 sqlStatement("delete from ar_activity " .
306 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow")) .
307 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
308 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
309 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
310 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
311 "' and (memo like 'Deductable%' OR memo like 'Deductible%')");
314 //==============================================================================================================================
315 if (isset($_POST["Takeback$CountRow"]) && $_POST["Takeback$CountRow"]*1>0) {
316 $resPayment = sqlStatement("SELECT * from ar_activity " .
317 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow")) .
318 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
319 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
320 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
321 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
322 "' and pay_amount < 0");
323 if (sqlNumRows($resPayment)>0) {
324 sqlStatement("update ar_activity set " .
325 " post_user = '" . trim($user_id) .
326 "', modified_time = '" . trim($created_time) .
327 "', pay_amount = '" . trim(formData("Takeback$CountRow"))*-1 .
328 "', account_code = '" . "Takeback" .
329 "', payer_type = '" . trim(formData("HiddenIns$CountRow")) .
330 "' where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow")) .
331 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
332 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
333 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
334 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
335 "' and pay_amount < 0");
336 } else {
337 sqlBeginTrans();
338 $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"))));
339 sqlStatement("insert into ar_activity set " .
340 "pid = '" . trim(formData("HiddenPId$CountRow")) .
341 "', encounter = '" . trim(formData("HiddenEncounter$CountRow")) .
342 "', sequence_no = '" . $sequence_no['increment'] .
343 "', code_type = '" . trim(formData("HiddenCodetype$CountRow")) .
344 "', code = '" . trim(formData("HiddenCode$CountRow")) .
345 "', modifier = '" . trim(formData("HiddenModifier$CountRow")) .
346 "', payer_type = '" . trim(formData("HiddenIns$CountRow")) .
347 "', post_time = '" . trim($created_time) .
348 "', post_user = '" . trim($user_id) .
349 "', session_id = '" . trim(formData('payment_id')) .
350 "', modified_time = '" . trim($created_time) .
351 "', pay_amount = '" . trim(formData("Takeback$CountRow"))*-1 .
352 "', adj_amount = '" . 0 .
353 "', account_code = '" . "Takeback" .
354 "'");
355 sqlCommitTrans();
357 } else {
358 sqlStatement("delete from ar_activity " .
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");
367 //==============================================================================================================================
368 if (isset($_POST["FollowUp$CountRow"]) && $_POST["FollowUp$CountRow"]=='y') {
369 $resPayment = sqlStatement("SELECT * from ar_activity " .
370 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow")) .
371 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
372 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
373 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
374 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
375 "' and follow_up ='y'");
376 if (sqlNumRows($resPayment)>0) {
377 sqlStatement("update ar_activity set " .
378 " post_user = '" . trim($user_id) .
379 "', modified_time = '" . trim($created_time) .
380 "', follow_up = '" . "y" .
381 "', follow_up_note = '" . trim(formData("FollowUpReason$CountRow")) .
382 "', payer_type = '" . trim(formData("HiddenIns$CountRow")) .
383 "' where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow")) .
384 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
385 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
386 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
387 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
388 "' and follow_up ='y'");
389 } else {
390 sqlBeginTrans();
391 $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"))));
392 sqlStatement("insert into ar_activity set " .
393 "pid = '" . trim(formData("HiddenPId$CountRow")) .
394 "', encounter = '" . trim(formData("HiddenEncounter$CountRow")) .
395 "', sequence_no = '" . $sequence_no['increment'] .
396 "', code_type = '" . trim(formData("HiddenCodetype$CountRow")) .
397 "', code = '" . trim(formData("HiddenCode$CountRow")) .
398 "', modifier = '" . trim(formData("HiddenModifier$CountRow")) .
399 "', payer_type = '" . trim(formData("HiddenIns$CountRow")) .
400 "', post_time = '" . trim($created_time) .
401 "', post_user = '" . trim($user_id) .
402 "', session_id = '" . trim(formData('payment_id')) .
403 "', modified_time = '" . trim($created_time) .
404 "', pay_amount = '" . 0 .
405 "', adj_amount = '" . 0 .
406 "', follow_up = '" . "y" .
407 "', follow_up_note = '" . trim(formData("FollowUpReason$CountRow")) .
408 "'");
409 sqlCommitTrans();
411 } else {
412 sqlStatement("delete from ar_activity " .
413 " where session_id ='$payment_id' and pid ='" . trim(formData("HiddenPId$CountRow")) .
414 "' and encounter ='" . trim(formData("HiddenEncounter$CountRow")) .
415 "' and code_type ='" . trim(formData("HiddenCodetype$CountRow")) .
416 "' and code ='" . trim(formData("HiddenCode$CountRow")) .
417 "' and modifier ='" . trim(formData("HiddenModifier$CountRow")) .
418 "' and follow_up ='y'");
421 //==============================================================================================================================
422 } else {
423 break;
427 //=========
428 //INSERTION of new entries,continuation of modification.
429 //=========
430 for ($CountRow=$CountIndexAbove+1; $CountRow<=$CountIndexAbove+$CountIndexBelow; $CountRow++) {
431 if (isset($_POST["HiddenEncounter$CountRow"])) {
432 DistributionInsert($CountRow, $created_time, $user_id);
433 } else {
434 break;
438 if ($_REQUEST['global_amount']=='yes') {
439 sqlStatement("update ar_session set global_amount=".trim(formData("HidUnappliedAmount"))*1 ." where session_id ='$payment_id'");
442 if ($_POST["mode"]=="FinishPayments") {
443 $Message='Finish';
446 $_POST["mode"] = "searchdatabase";
447 $Message='Modify';
451 //==============================================================================
452 //Search Code
453 //===============================================================================
454 $payment_id=$payment_id*1 > 0 ? $payment_id : $_REQUEST['payment_id'];
455 $ResultSearchSub = sqlStatement("SELECT distinct encounter,code_type,code,modifier, pid from ar_activity where session_id ='$payment_id' order by pid,encounter,code,modifier");
456 //==============================================================================
458 //==============================================================================
459 //===============================================================================
461 <!DOCTYPE html>
462 <html>
463 <head>
465 <?php Header::setupHeader(['datetime-picker']); ?>
467 <script language='JavaScript'>
468 var mypcc = '1';
469 </script>
470 <?php include_once("{$GLOBALS['srcdir']}/payment_jav.inc.php"); ?>
471 <?php include_once("{$GLOBALS['srcdir']}/ajax/payment_ajax_jav.inc.php"); ?>
472 <script type="text/javascript" src="../../library/js/common.js?v=<?php echo $v_js_includes; ?>"></script>
473 <script LANGUAGE="javascript" TYPE="text/javascript">
474 function ModifyPayments()
475 {//Used while modifying the allocation
476 if(!FormValidations())//FormValidations contains the form checks
478 return false;
480 if(CompletlyBlankAbove())//The distribution rows already in the database are checked.
482 alert("<?php echo htmlspecialchars(xl('None of the Top Distribution Row Can be Completly Blank.'), ENT_QUOTES);
483 echo htmlspecialchars('\n');echo htmlspecialchars(xl('Use Delete Option to Remove.'), ENT_QUOTES) ?>")
484 return false;
486 if(!CheckPayingEntityAndDistributionPostFor())//Ensures that Insurance payment is distributed under Ins1,Ins2,Ins3 and Patient paymentat under Pat.
488 return false;
490 if(CompletlyBlankBelow())//The newly added distribution rows are checked.
492 alert("<?php echo htmlspecialchars(xl('Fill any of the Below Row.'), ENT_QUOTES) ?>")
493 return false;
495 PostValue=CheckUnappliedAmount();//Decides TdUnappliedAmount >0, or <0 or =0
496 if(PostValue==1)
498 alert("<?php echo htmlspecialchars(xl('Cannot Modify Payments.Undistributed is Negative.'), ENT_QUOTES) ?>")
499 return false;
501 if(confirm("<?php echo htmlspecialchars(xl('Would you like to Modify Payments?'), ENT_QUOTES) ?>"))
503 document.getElementById('mode').value='ModifyPayments';
504 top.restoreSession();
505 document.forms[0].submit();
507 else
508 return false;
510 function FinishPayments()
512 if(!FormValidations())//FormValidations contains the form checks
514 return false;
516 if(CompletlyBlankAbove())//The distribution rows already in the database are checked.
518 alert("<?php echo htmlspecialchars(xl('None of the Top Distribution Row Can be Completly Blank.'), ENT_QUOTES);
519 echo htmlspecialchars('\n');echo htmlspecialchars(xl('Use Delete Option to Remove.'), ENT_QUOTES) ?>")
520 return false;
522 if(!CheckPayingEntityAndDistributionPostFor())//Ensures that Insurance payment is distributed under Ins1,Ins2,Ins3 and Patient paymentat under Pat.
524 return false;
526 if(CompletlyBlankBelow())//The newly added distribution rows are checked.
528 alert("<?php echo htmlspecialchars(xl('Fill any of the Below Row.'), ENT_QUOTES) ?>")
529 return false;
531 PostValue=CheckUnappliedAmount();//Decides TdUnappliedAmount >0, or <0 or =0
532 if(PostValue==1)
534 alert("<?php echo htmlspecialchars(xl('Cannot Modify Payments.Undistributed is Negative.'), ENT_QUOTES) ?>")
535 return false;
537 if(PostValue==2)
539 if(confirm("<?php echo htmlspecialchars(xl('Would you like to Modify and Finish Payments?'), ENT_QUOTES) ?>"))
541 UnappliedAmount=document.getElementById('TdUnappliedAmount').innerHTML*1;
542 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) ?>"))
544 document.getElementById('mode').value='FinishPayments';
545 document.getElementById('global_amount').value='yes';
546 top.restoreSession();
547 document.forms[0].submit();
549 else
551 document.getElementById('mode').value='FinishPayments';
552 top.restoreSession();
553 document.forms[0].submit();
556 else
557 return false;
559 else
561 if(confirm("<?php echo htmlspecialchars(xl('Would you like to Modify and Finish Payments?'), ENT_QUOTES) ?>"))
563 document.getElementById('mode').value='FinishPayments';
564 top.restoreSession();
565 document.forms[0].submit();
567 else
568 return false;
572 function CompletlyBlankAbove()
573 {//The distribution rows already in the database are checked.
574 //It is not allowed to be made completly empty.If needed delete option need to be used.
575 CountIndexAbove=document.getElementById('CountIndexAbove').value*1;
576 for(RowCount=1;RowCount<=CountIndexAbove;RowCount++)
578 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)
580 return true;
583 return false;
585 function CompletlyBlankBelow()
586 {//The newly added distribution rows are checked.
587 //It is not allowed to be made completly empty.
588 CountIndexAbove=document.getElementById('CountIndexAbove').value*1;
589 CountIndexBelow=document.getElementById('CountIndexBelow').value*1;
590 if(CountIndexBelow==0)
591 return false;
592 for(RowCount=CountIndexAbove+1;RowCount<=CountIndexAbove+CountIndexBelow;RowCount++)
594 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)
598 else
599 return false;
601 return true;
603 function OnloadAction()
604 {//Displays message while loading after some action.
605 after_value=document.getElementById('ActionStatus').value;
606 if(after_value=='Delete')
608 alert("<?php echo htmlspecialchars(xl('Successfully Deleted'), ENT_QUOTES) ?>")
609 return true;
611 if(after_value=='Modify' || after_value=='Finish')
613 alert("<?php echo htmlspecialchars(xl('Successfully Modified'), ENT_QUOTES) ?>")
614 return true;
616 after_value=document.getElementById('after_value').value;
617 payment_id=document.getElementById('payment_id').value;
618 if(after_value=='distribute')
621 else if(after_value=='new_payment')
623 if(document.getElementById('TablePatientPortion'))
625 document.getElementById('TablePatientPortion').style.display='none';
627 if(confirm("<?php echo htmlspecialchars(xl('Successfully Saved.Would you like to Distribute?'), ENT_QUOTES) ?>"))
629 if(document.getElementById('TablePatientPortion'))
631 document.getElementById('TablePatientPortion').style.display='';
637 function DeletePaymentDistribution(DeleteId)
638 {//Confirms deletion of payment distribution.
639 if(confirm("<?php echo htmlspecialchars(xl('Would you like to Delete Payment Distribution?'), ENT_QUOTES) ?>"))
641 document.getElementById('mode').value='DeletePaymentDistribution';
642 document.getElementById('DeletePaymentDistributionId').value=DeleteId;
643 top.restoreSession();
644 document.forms[0].submit();
646 else
647 return false;
649 //========================================================================================
651 $(document).ready(function() {
652 $('.datepicker').datetimepicker({
653 <?php $datetimepicker_timepicker = false; ?>
654 <?php $datetimepicker_showseconds = false; ?>
655 <?php $datetimepicker_formatInput = true; ?>
656 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
657 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
661 </script>
662 <script language="javascript" type="text/javascript">
663 document.onclick=HideTheAjaxDivs;
664 </script>
665 <style>
666 .class1{width:125px;}
667 .class2{width:250px;}
668 .class3{width:100px;}
669 .bottom{border-bottom:1px solid black;}
670 .top{border-top:1px solid black;}
671 .left{border-left:1px solid black;}
672 .right{border-right:1px solid black;}
673 #ajax_div_insurance {
674 position: absolute;
675 z-index:10;
677 left: 20px;
678 top: 300px;
680 background-color: #FBFDD0;
681 border: 1px solid #ccc;
682 padding: 10px;
684 #ajax_div_patient {
685 position: absolute;
686 z-index:10;
688 left: 20px;
689 top: 300px;
691 background-color: #FBFDD0;
692 border: 1px solid #ccc;
693 padding: 10px;
695 </style>
696 <link rel="stylesheet" href="<?php echo $css_header; ?>" type="text/css">
697 </head>
698 <body class="body_top" onLoad="OnloadAction()" >
699 <form name='new_payment' method='post' action="edit_payment.php" onsubmit='
700 <?php
701 if ($payment_id*1==0) {
703 top.restoreSession();return SavePayment();
704 <?php
705 } else {
707 return false;
708 <?php
711 ' style="display:inline" >
712 <table width="1024" border="0" cellspacing="0" cellpadding="0">
713 <?php
714 if ($_REQUEST['ParentPage']=='new_payment') {
716 <tr>
717 <td colspan="3" align="left"><b><?php echo htmlspecialchars(xl('Payments'), ENT_QUOTES) ?></b></td>
718 </tr>
719 <tr height="15">
720 <td colspan="3" align="left" ></td>
721 </tr>
722 <tr>
723 <td colspan="3" align="left">
724 <ul class="tabNav">
725 <li class='current'><a href='new_payment.php'><?php echo htmlspecialchars(xl('New Payment'), ENT_QUOTES) ?></a></li>
726 <li><a href='search_payments.php'><?php echo htmlspecialchars(xl('Search Payment'), ENT_QUOTES) ?></a></li>
727 <li><a href='era_payments.php'><?php echo htmlspecialchars(xl('ERA Posting'), ENT_QUOTES) ?></a></li>
728 </ul> </td>
729 </tr>
730 <?php
731 } else {
733 <tr height="5">
734 <td colspan="3" align="left" ></td>
735 </tr>
736 <?php
739 <tr>
740 <td colspan="3" align="left" >
742 <?php
743 if ($payment_id*1>0) {
745 <?php
746 require_once("payment_master.inc.php"); //Check/cash details are entered here.
748 <?php
751 </td>
752 </tr>
753 </table>
757 <?php
758 if ($payment_id*1>0) {//Distribution rows already in the database are displayed.
761 <table width="1024" border="0" cellspacing="0" cellpadding="10" bgcolor="#DEDEDE"><tr><td>
762 <table width="1004" border="0" cellspacing="0" cellpadding="0">
764 <tr>
765 <td colspan="13" align="left" >
767 <?php //
768 $resCount = sqlStatement("SELECT distinct encounter,code_type,code,modifier from ar_activity where session_id ='$payment_id' ");
769 $TotalRows=sqlNumRows($resCount);
770 $CountPatient=0;
771 $CountIndex=0;
772 $CountIndexAbove=0;
773 $paymenttot=0;
774 $adjamttot=0;
775 $deductibletot=0;
776 $takebacktot=0;
777 $allowedtot=0;
778 if ($RowSearchSub = sqlFetchArray($ResultSearchSub)) {
779 do {
780 $CountPatient++;
781 $PId=$RowSearchSub['pid'];
782 $EncounterMaster=$RowSearchSub['encounter'];
783 // Only use the code_type in the queries below if it is specified in the ar_activity table.
784 // If it is not specified in the ar_activity table, also note it is not requested from the
785 // billing table in below query, thus making it blank in all queries below in this script.
786 $CodetypeMaster=$RowSearchSub['code_type'];
787 $sql_select_part_codetype = "";
788 $sql_where_part_codetype = "";
789 if (!empty($CodetypeMaster)) {
790 $sql_select_part_codetype = "billing.code_type,";
791 $sql_where_part_codetype = "and billing.code_type ='$CodetypeMaster'";
794 $CodeMaster=$RowSearchSub['code'];
795 $ModifierMaster=$RowSearchSub['modifier'];
796 $res = sqlStatement("SELECT fname,lname,mname FROM patient_data where pid ='$PId'");
797 $row = sqlFetchArray($res);
798 $fname=$row['fname'];
799 $lname=$row['lname'];
800 $mname=$row['mname'];
801 $NameDB=$lname.' '.$fname.' '.$mname;
802 $ResultSearch = sqlStatement("SELECT billing.id,last_level_closed,billing.encounter,form_encounter.`date`,$sql_select_part_codetype billing.code,billing.modifier,fee
803 FROM billing ,form_encounter
804 where billing.encounter=form_encounter.encounter and billing.pid=form_encounter.pid and
805 code_type!='ICD9' and code_type!='COPAY' and billing.activity!=0 and
806 form_encounter.pid ='$PId' and billing.pid ='$PId' and billing.encounter ='$EncounterMaster'
807 $sql_where_part_codetype
808 and billing.code ='$CodeMaster'
809 and billing.modifier ='$ModifierMaster'
810 ORDER BY form_encounter.`date`,form_encounter.encounter,billing.code,billing.modifier");
811 if (sqlNumRows($ResultSearch)>0) {
812 if ($CountPatient==1) {
813 $Table='yes';
815 <table width="1004" border="0" cellpadding="0" cellspacing="0" align="center" id="TableDistributePortion">
816 <tr class="text" bgcolor="#dddddd">
817 <td width="25" class="left top" >&nbsp;</td>
818 <td width="144" class="left top" ><?php echo htmlspecialchars(xl('Patient Name'), ENT_QUOTES) ?></td>
819 <td width="55" class="left top" ><?php echo htmlspecialchars(xl('Post For'), ENT_QUOTES) ?></td>
820 <td width="70" class="left top" ><?php echo htmlspecialchars(xl('Service Date'), ENT_QUOTES) ?></td>
821 <td width="50" class="left top" ><?php echo htmlspecialchars(xl('Encounter'), ENT_QUOTES) ?></td>
822 <td width="65" class="left top" ><?php echo htmlspecialchars(xl('Service Code'), ENT_QUOTES) ?></td>
823 <td width="50" class="left top" ><?php echo htmlspecialchars(xl('Charge'), ENT_QUOTES) ?></td>
824 <td width="40" class="left top" ><?php echo htmlspecialchars(xl('Copay'), ENT_QUOTES) ?></td>
825 <td width="40" class="left top" ><?php echo htmlspecialchars(xl('Remdr'), ENT_QUOTES) ?></td>
826 <td width="60" class="left top" ><?php echo htmlspecialchars(xl('Allowed(c)'), ENT_QUOTES) ?></td><!-- (c) means it is calculated.Not stored one. -->
827 <td width="60" class="left top" ><?php echo htmlspecialchars(xl('Payment'), ENT_QUOTES) ?></td>
828 <td width="70" class="left top" ><?php echo htmlspecialchars(xl('Adj Amount'), ENT_QUOTES) ?></td>
829 <td width="60" class="left top" ><?php echo htmlspecialchars(xl('Deductible'), ENT_QUOTES) ?></td>
830 <td width="60" class="left top" ><?php echo htmlspecialchars(xl('Takeback'), ENT_QUOTES) ?></td>
831 <td width="60" class="left top" ><?php echo htmlspecialchars(xl('MSP Code'), ENT_QUOTES) ?></td>
832 <td width="40" class="left top" ><?php echo htmlspecialchars(xl('Resn'), ENT_QUOTES) ?></td>
833 <td width="110" class="left top right" ><?php echo htmlspecialchars(xl('Follow Up Reason'), ENT_QUOTES) ?></td>
834 </tr>
835 <?php
838 while ($RowSearch = sqlFetchArray($ResultSearch)) {
839 $CountIndex++;
840 $CountIndexAbove++;
841 $ServiceDateArray=explode(' ', $RowSearch['date']);
842 $ServiceDate=oeFormatShortDate($ServiceDateArray[0]);
843 $Codetype=$RowSearch['code_type'];
844 $Code=$RowSearch['code'];
845 $Modifier =$RowSearch['modifier'];
846 if ($Modifier!='') {
847 $ModifierString=", $Modifier";
848 } else {
849 $ModifierString="";
852 $Fee=$RowSearch['fee'];
853 $Encounter=$RowSearch['encounter'];
855 $resPayer = sqlStatement("SELECT payer_type from ar_activity where session_id ='$payment_id' and
856 pid ='$PId' and encounter ='$Encounter' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' ");
857 $rowPayer = sqlFetchArray($resPayer);
858 $Ins=$rowPayer['payer_type'];
860 //Always associating the copay to a particular charge.
861 $BillingId=$RowSearch['id'];
862 $resId = sqlStatement("SELECT id FROM billing where code_type!='ICD9' and code_type!='COPAY' and
863 pid ='$PId' and encounter ='$Encounter' and billing.activity!=0 order by id");
864 $rowId = sqlFetchArray($resId);
865 $Id=$rowId['id'];
867 if ($BillingId!=$Id) {//multiple cpt in single encounter
868 $Copay=0.00;
869 } else {
870 $resCopay = sqlStatement("SELECT sum(fee) as copay FROM billing where
871 code_type='COPAY' and pid ='$PId' and encounter ='$Encounter' and billing.activity!=0");
872 $rowCopay = sqlFetchArray($resCopay);
873 $Copay=$rowCopay['copay']*-1;
875 $resMoneyGot = sqlStatement("SELECT sum(pay_amount) as PatientPay FROM ar_activity where
876 pid ='$PId' and encounter ='$Encounter' and payer_type=0 and account_code='PCP'");//new fees screen copay gives account_code='PCP'
877 $rowMoneyGot = sqlFetchArray($resMoneyGot);
878 $PatientPay=$rowMoneyGot['PatientPay'];
880 $Copay=$Copay+$PatientPay;
883 //For calculating Remainder
884 if ($Ins==0) {//Fetch all values
885 $resMoneyGot = sqlStatement("SELECT sum(pay_amount) as MoneyGot FROM ar_activity where
886 pid ='$PId' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and encounter ='$Encounter' and !(payer_type=0 and
887 account_code='PCP')");
888 //new fees screen copay gives account_code='PCP'
889 $rowMoneyGot = sqlFetchArray($resMoneyGot);
890 $MoneyGot=$rowMoneyGot['MoneyGot'];
892 $resMoneyAdjusted = sqlStatement("SELECT sum(adj_amount) as MoneyAdjusted FROM ar_activity where
893 pid ='$PId' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and encounter ='$Encounter'");
894 $rowMoneyAdjusted = sqlFetchArray($resMoneyAdjusted);
895 $MoneyAdjusted=$rowMoneyAdjusted['MoneyAdjusted'];
896 } else //Fetch till that much got
898 //Fetch the HIGHEST sequence_no till this session.
899 //Used maily in the case if primary/others pays once more.
900 $resSequence = sqlStatement("SELECT sequence_no from ar_activity where session_id ='$payment_id' and
901 pid ='$PId' and encounter ='$Encounter' order by sequence_no desc ");
902 $rowSequence = sqlFetchArray($resSequence);
903 $Sequence=$rowSequence['sequence_no'];
905 $resMoneyGot = sqlStatement("SELECT sum(pay_amount) as MoneyGot FROM ar_activity where
906 pid ='$PId' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and encounter ='$Encounter' and
907 payer_type > 0 and payer_type <='$Ins' and sequence_no<='$Sequence'");
908 $rowMoneyGot = sqlFetchArray($resMoneyGot);
909 $MoneyGot=$rowMoneyGot['MoneyGot'];
911 $resMoneyAdjusted = sqlStatement("SELECT sum(adj_amount) as MoneyAdjusted FROM ar_activity where
912 pid ='$PId' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and encounter ='$Encounter' and
913 payer_type > 0 and payer_type <='$Ins' and sequence_no<='$Sequence'");
914 $rowMoneyAdjusted = sqlFetchArray($resMoneyAdjusted);
915 $MoneyAdjusted=$rowMoneyAdjusted['MoneyAdjusted'];
918 $Remainder=$Fee-$Copay-$MoneyGot-$MoneyAdjusted;
920 //For calculating RemainderJS.Used while restoring back the values.
921 if ($Ins==0) {//Got just before Patient
922 $resMoneyGot = sqlStatement("SELECT sum(pay_amount) as MoneyGot FROM ar_activity where
923 pid ='$PId' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and encounter ='$Encounter' and payer_type !=0");
924 $rowMoneyGot = sqlFetchArray($resMoneyGot);
925 $MoneyGot=$rowMoneyGot['MoneyGot'];
927 $resMoneyAdjusted = sqlStatement("SELECT sum(adj_amount) as MoneyAdjusted FROM ar_activity where
928 pid ='$PId' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and encounter ='$Encounter' and payer_type !=0");
929 $rowMoneyAdjusted = sqlFetchArray($resMoneyAdjusted);
930 $MoneyAdjusted=$rowMoneyAdjusted['MoneyAdjusted'];
931 } else {//Got just before the previous
932 //Fetch the LOWEST sequence_no till this session.
933 //Used maily in the case if primary/others pays once more.
934 $resSequence = sqlStatement("SELECT sequence_no from ar_activity where session_id ='$payment_id' and
935 pid ='$PId' and encounter ='$Encounter' order by sequence_no ");
936 $rowSequence = sqlFetchArray($resSequence);
937 $Sequence=$rowSequence['sequence_no'];
939 $resMoneyGot = sqlStatement("SELECT sum(pay_amount) as MoneyGot FROM ar_activity where
940 pid ='$PId' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and encounter ='$Encounter'
941 and payer_type > 0 and payer_type <='$Ins' and sequence_no<'$Sequence'");
942 $rowMoneyGot = sqlFetchArray($resMoneyGot);
943 $MoneyGot=$rowMoneyGot['MoneyGot'];
945 $resMoneyAdjusted = sqlStatement("SELECT sum(adj_amount) as MoneyAdjusted FROM ar_activity where
946 pid ='$PId' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and encounter ='$Encounter'
947 and payer_type <='$Ins' and sequence_no<'$Sequence' ");
948 $rowMoneyAdjusted = sqlFetchArray($resMoneyAdjusted);
949 $MoneyAdjusted=$rowMoneyAdjusted['MoneyAdjusted'];
952 //Stored in hidden so that can be used while restoring back the values.
953 $RemainderJS=$Fee-$Copay-$MoneyGot-$MoneyAdjusted;
955 $resPayment = sqlStatement("SELECT pay_amount from ar_activity where session_id ='$payment_id' and
956 pid ='$PId' and encounter ='$Encounter' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and pay_amount>0");
957 $rowPayment = sqlFetchArray($resPayment);
958 $PaymentDB=$rowPayment['pay_amount']*1;
959 $PaymentDB=$PaymentDB == 0 ? '' : $PaymentDB;
961 $resPayment = sqlStatement("SELECT pay_amount from ar_activity where session_id ='$payment_id' and
962 pid ='$PId' and encounter ='$Encounter' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and pay_amount<0");
963 $rowPayment = sqlFetchArray($resPayment);
964 $TakebackDB=$rowPayment['pay_amount']*-1;
965 $TakebackDB=$TakebackDB == 0 ? '' : $TakebackDB;
967 $resPayment = sqlStatement("SELECT adj_amount from ar_activity where session_id ='$payment_id' and
968 pid ='$PId' and encounter ='$Encounter' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and adj_amount!=0");
969 $rowPayment = sqlFetchArray($resPayment);
970 $AdjAmountDB=$rowPayment['adj_amount']*1;
971 $AdjAmountDB=$AdjAmountDB == 0 ? '' : $AdjAmountDB;
973 $resPayment = sqlStatement("SELECT memo from ar_activity where session_id ='$payment_id' and
974 pid ='$PId' and encounter ='$Encounter' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and (memo like 'Deductable%' OR memo like 'Deductible%')");
975 $rowPayment = sqlFetchArray($resPayment);
976 $DeductibleDB=$rowPayment['memo'];
977 $DeductibleDB=str_replace('Deductable $', '', $DeductibleDB);
978 $DeductibleDB=str_replace('Deductible $', '', $DeductibleDB);
980 $resPayment = sqlStatement("SELECT follow_up,follow_up_note from ar_activity where session_id ='$payment_id' and
981 pid ='$PId' and encounter ='$Encounter' and code_type='$Codetype' and code='$Code' and modifier='$Modifier' and follow_up = 'y'");
982 $rowPayment = sqlFetchArray($resPayment);
983 $FollowUpDB=$rowPayment['follow_up'];
984 $FollowUpReasonDB=$rowPayment['follow_up_note'];
986 $resPayment = sqlStatement("SELECT reason_code from ar_activity where session_id ='$payment_id' and
987 pid ='$PId' and encounter ='$Encounter' and code_type='$Codetype' and code='$Code' and modifier='$Modifier'");
988 $rowPayment = sqlFetchArray($resPayment);
989 $ReasonCodeDB=$rowPayment['reason_code'];
991 if ($Ins==1) {
992 $AllowedDB=number_format($Fee-$AdjAmountDB, 2);
993 } else {
994 $AllowedDB = 0;
997 $AllowedDB=$AllowedDB == 0 ? '' : $AllowedDB;
999 if ($CountIndex==$TotalRows) {
1000 $StringClass=' bottom left top ';
1001 } else {
1002 $StringClass=' left top ';
1005 if ($Ins==1) {
1006 $bgcolor='#ddddff';
1007 } elseif ($Ins==2) {
1008 $bgcolor='#ffdddd';
1009 } elseif ($Ins==3) {
1010 $bgcolor='#F2F1BC';
1011 } elseif ($Ins==0) {
1012 $bgcolor='#AAFFFF';
1015 $paymenttot=$paymenttot+$PaymentDB;
1016 $adjamttot=$adjamttot+$AdjAmountDB;
1017 $deductibletot=$deductibletot+$DeductibleDB;
1018 $takebacktot=$takebacktot+$TakebackDB;
1019 $allowedtot=$allowedtot+$AllowedDB;
1021 <tr class="text" bgcolor='<?php echo $bgcolor; ?>' id="trCharges<?php echo $CountIndex; ?>">
1022 <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>
1023 <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>
1024 <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>
1025 <td class="<?php echo $StringClass; ?>" ><?php echo htmlspecialchars($ServiceDate); ?></td>
1026 <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>
1027 <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>
1028 <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>
1029 <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>
1030 <td align="right" id="RemainderTd<?php echo $CountIndex; ?>" class="<?php echo $StringClass; ?>" ><?php echo htmlspecialchars(round($Remainder, 2)); ?></td>
1031 <input name="HiddenRemainderTd<?php echo $CountIndex; ?>" id="HiddenRemainderTd<?php echo $CountIndex; ?>" value="<?php echo htmlspecialchars(round($RemainderJS, 2)); ?>" type="hidden"/>
1032 <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>
1033 <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>
1034 <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>
1035 <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>
1036 <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>
1037 <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>
1038 <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>
1039 <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>
1040 </tr>
1041 <?php
1042 }//while ($RowSearch = sqlFetchArray($ResultSearch))
1044 <?php
1045 }//if(sqlNumRows($ResultSearch)>0)
1046 } while ($RowSearchSub = sqlFetchArray($ResultSearchSub));
1047 if ($Table=='yes') {
1049 <tr class="text">
1050 <td align="left" colspan="9">&nbsp;</td>
1051 <td class="left bottom" bgcolor="#6699FF" id="allowtotal" align="right" ><?php echo htmlspecialchars(number_format($allowedtot, 2)); ?></td>
1052 <td class="left bottom" bgcolor="#6699FF" id="paymenttotal" align="right" ><?php echo htmlspecialchars(number_format($paymenttot, 2)); ?></td>
1053 <td class="left bottom" bgcolor="#6699FF" id="AdjAmounttotal" align="right" ><?php echo htmlspecialchars(number_format($adjamttot, 2)); ?></td>
1054 <td class="left bottom" bgcolor="#6699FF" id="deductibletotal" align="right"><?php echo htmlspecialchars(number_format($deductibletot, 2)); ?></td>
1055 <td class="left bottom right" bgcolor="#6699FF" id="takebacktotal" align="right"><?php echo htmlspecialchars(number_format($takebacktot, 2)); ?></td>
1056 <td align="center">&nbsp;</td>
1057 <td align="center">&nbsp;</td>
1058 </tr>
1059 </table>
1060 <?php
1063 <?php
1065 echo '<br/>';
1066 }//if($RowSearchSub = sqlFetchArray($ResultSearchSub))
1067 ?> </td>
1068 </tr>
1069 <tr>
1070 <td colspan="13" align="left" >
1071 <?php
1072 require_once("payment_pat_sel.inc.php"); //Patient ajax section and listing of charges.
1074 </td>
1075 </tr>
1076 <tr>
1077 <td colspan="13" align="left" >
1078 <table border="0" cellspacing="0" cellpadding="0" width="217" align="center">
1079 <tr height="5">
1080 <td ></td>
1081 <td ></td>
1082 <td></td>
1083 </tr>
1084 <tr>
1085 <td width="110"><a href="#" onClick="javascript:return ModifyPayments();" class="css_button"><span><?php echo htmlspecialchars(xl('Modify Payments'), ENT_QUOTES);?></span></a>
1086 </td>
1087 <td width="107"><a href="#" onClick="javascript:return FinishPayments();" class="css_button"><span><?php echo htmlspecialchars(xl('Finish Payments'), ENT_QUOTES);?></span></a>
1088 </td>
1089 </tr>
1090 </table>
1092 <?php
1093 }//if($payment_id*1>0)
1094 ?> </td>
1095 </tr>
1096 </table>
1097 </td></tr></table>
1099 <input type="hidden" name="hidden_patient_code" id="hidden_patient_code" value="<?php echo htmlspecialchars($hidden_patient_code);?>"/>
1100 <input type='hidden' name='mode' id='mode' value='' />
1101 <input type='hidden' name='ajax_mode' id='ajax_mode' value='' />
1102 <input type="hidden" name="after_value" id="after_value" value="<?php echo htmlspecialchars($_POST["mode"]);?>"/>
1103 <input type="hidden" name="payment_id" id="payment_id" value="<?php echo htmlspecialchars($payment_id);?>"/>
1104 <input type="hidden" name="hidden_type_code" id="hidden_type_code" value="<?php echo htmlspecialchars($TypeCode);?>"/>
1105 <input type='hidden' name='global_amount' id='global_amount' value='' />
1106 <input type='hidden' name='DeletePaymentDistributionId' id='DeletePaymentDistributionId' value='' />
1107 <input type="hidden" name="ActionStatus" id="ActionStatus" value="<?php echo htmlspecialchars($Message);?>"/>
1108 <input type='hidden' name='CountIndexAbove' id='CountIndexAbove' value='<?php echo htmlspecialchars($CountIndexAbove*1);?>' />
1109 <input type='hidden' name='CountIndexBelow' id='CountIndexBelow' value='<?php echo htmlspecialchars($CountIndexBelow*1);?>' />
1110 <input type="hidden" name="ParentPage" id="ParentPage" value="<?php echo htmlspecialchars($_REQUEST['ParentPage']);?>"/>
1111 </form>
1113 </body>
1114 </html>