The Third Reminders email bug fix - contributed by arnabnaha
[openemr.git] / interface / billing / search_payments.php
blob38c4e07abb44563a2e31ff3682a109ab24d22042
1 <?php
2 // +-----------------------------------------------------------------------------+
3 // Copyright (C) 2010 Z&H Consultancy Services Private Limited <sam@zhservices.com>
4 //
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
18 // A copy of the GNU General Public License is included along with this program:
19 // openemr/interface/login/GnuGPL.html
20 // For more information write to the Free Software
21 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 //
23 // Author: Eldho Chacko <eldho@zhservices.com>
24 // Paul Simon K <paul@zhservices.com>
26 // +------------------------------------------------------------------------------+
27 //===============================================================================
28 //Payments in database can be searched through this screen and edit popup is also its part.
29 //Deletion of the payment is done with logging.
30 //===============================================================================
31 require_once("../globals.php");
32 require_once("$srcdir/log.inc");
33 require_once("../../library/acl.inc");
34 require_once("../../custom/code_types.inc.php");
35 require_once("$srcdir/patient.inc");
36 require_once("$srcdir/billrep.inc");
37 require_once(dirname(__FILE__) . "/../../library/classes/OFX.class.php");
38 require_once(dirname(__FILE__) . "/../../library/classes/X12Partner.class.php");
39 require_once("$srcdir/options.inc.php");
40 require_once("$srcdir/formatting.inc.php");
41 require_once("$srcdir/payment.inc.php");
42 //===============================================================================
43 //Deletion of payment and its corresponding distributions.
44 //===============================================================================
45 set_time_limit(0);
46 if (isset($_POST["mode"]))
48 if ($_POST["mode"] == "DeletePayments")
50 $DeletePaymentId=trim(formData('DeletePaymentId' ));
51 $ResultSearch = sqlStatement("SELECT distinct encounter,pid from ar_activity where session_id ='$DeletePaymentId'");
52 if(sqlNumRows($ResultSearch)>0)
54 while ($RowSearch = sqlFetchArray($ResultSearch))
56 $Encounter=$RowSearch['encounter'];
57 $PId=$RowSearch['pid'];
58 sqlStatement("update form_encounter set last_level_closed=last_level_closed - 1 where pid ='$PId' and encounter='$Encounter'" );
61 //delete and log that action
62 row_delete("ar_session", "session_id ='$DeletePaymentId'");
63 row_delete("ar_activity", "session_id ='$DeletePaymentId'");
64 $Message='Delete';
65 //------------------
66 $_POST["mode"] = "SearchPayment";
68 //===============================================================================
69 //Search section.
70 //===============================================================================
71 if ($_POST["mode"] == "SearchPayment")
73 $FromDate=trim(formData('FromDate' ));
74 $ToDate=trim(formData('ToDate' ));
75 $PaymentMethod=trim(formData('payment_method' ));
76 $CheckNumber=trim(formData('check_number' ));
77 $PaymentAmount=trim(formData('payment_amount' ));
78 $PayingEntity=trim(formData('type_name' ));
79 $PaymentCategory=trim(formData('adjustment_code' ));
80 $PaymentFrom=trim(formData('hidden_type_code' ));
81 $PaymentStatus=trim(formData('PaymentStatus' ));
82 $PaymentSortBy=trim(formData('PaymentSortBy' ));
83 $PaymentDate=trim(formData('payment_date' ));
84 $QueryString.="Select * from ar_session where ";
85 $And='';
87 if($PaymentDate=='date_val')
89 $PaymentDateString=' check_date ';
91 elseif($PaymentDate=='post_to_date')
93 $PaymentDateString=' post_to_date ';
95 elseif($PaymentDate=='deposit_date')
97 $PaymentDateString=' deposit_date ';
100 if($FromDate!='')
102 $QueryString.=" $And $PaymentDateString >='".DateToYYYYMMDD($FromDate)."'";
103 $And=' and ';
105 if($ToDate!='')
107 $QueryString.=" $And $PaymentDateString <='".DateToYYYYMMDD($ToDate)."'";
108 $And=' and ';
110 if($PaymentMethod!='')
112 $QueryString.=" $And payment_method ='".$PaymentMethod."'";
113 $And=' and ';
115 if($CheckNumber!='')
117 $QueryString.=" $And reference like '%".$CheckNumber."%'";
118 $And=' and ';
120 if($PaymentAmount!='')
122 $QueryString.=" $And pay_total ='".$PaymentAmount."'";
123 $And=' and ';
125 if($PayingEntity!='')
127 if($PayingEntity=='insurance')
129 $QueryString.=" $And payer_id !='0'";
131 if($PayingEntity=='patient')
133 $QueryString.=" $And payer_id ='0'";
135 $And=' and ';
137 if($PaymentCategory!='')
139 $QueryString.=" $And adjustment_code ='".$PaymentCategory."'";
140 $And=' and ';
142 if($PaymentFrom!='')
144 if($PayingEntity=='insurance' || $PayingEntity=='')
146 //-------------------
147 $res = sqlStatement("SELECT insurance_companies.name FROM insurance_companies
148 where insurance_companies.id ='$PaymentFrom'");
149 $row = sqlFetchArray($res);
150 $div_after_save=$row['name'];
151 //-------------------
153 $QueryString.=" $And payer_id ='".$PaymentFrom."'";
155 if($PayingEntity=='patient')
157 //-------------------
158 $res = sqlStatement("SELECT fname,lname,mname FROM patient_data
159 where pid ='$PaymentFrom'");
160 $row = sqlFetchArray($res);
161 $fname=$row['fname'];
162 $lname=$row['lname'];
163 $mname=$row['mname'];
164 $div_after_save=$lname.' '.$fname.' '.$mname;
165 //-------------------
167 $QueryString.=" $And patient_id ='".$PaymentFrom."'";
169 $And=' and ';
172 if($PaymentStatus!='')
174 $QsString="select ar_session.session_id,pay_total,global_amount,sum(pay_amount) sum_pay_amount from ar_session,ar_activity
175 where ar_session.session_id=ar_activity.session_id group by ar_activity.session_id,ar_session.session_id
176 having pay_total-global_amount-sum_pay_amount=0 or pay_total=0";
177 $rs= sqlStatement("$QsString");
178 while($rowrs=sqlFetchArray($rs))
180 $StringSessionId.=$rowrs['session_id'].',';
182 $QsString="select ar_session.session_id from ar_session where pay_total=0";
183 $rs= sqlStatement("$QsString");
184 while($rowrs=sqlFetchArray($rs))
186 $StringSessionId.=$rowrs['session_id'].',';
188 $StringSessionId=substr($StringSessionId, 0, -1);
189 if($PaymentStatus=='fully_paid')
191 $QueryString.=" $And session_id in($StringSessionId) ";
193 elseif($PaymentStatus=='unapplied')
195 $QueryString.=" $And session_id not in($StringSessionId) ";
197 $And=' and ';
199 if($PaymentSortBy!='')
201 $SortFieldOld=trim(formData('SortFieldOld' ));
202 $Sort=trim(formData('Sort' ));
203 if($SortFieldOld==$PaymentSortBy)
205 if($Sort=='DESC' || $Sort=='')
206 $Sort='ASC';
207 else
208 $Sort='DESC';
210 else
212 $Sort='ASC';
214 $QueryString.=" order by $PaymentSortBy $Sort";
216 $ResultSearch = sqlStatement($QueryString);
219 //===============================================================================
220 $DateFormat=DateFormatRead();
222 <html>
223 <head>
224 <?php if (function_exists('html_header_show')) html_header_show(); ?>
226 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
228 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js"></script>
229 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
230 <link rel="stylesheet" type="text/css" href="../../library/js/fancybox/jquery.fancybox-1.2.6.css" media="screen" />
231 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
233 <script type="text/javascript" src="../../library/textformat.js"></script>
234 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
235 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
236 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
237 <script type="text/javascript" src="../../library/dialog.js"></script>
239 <?php include_once("{$GLOBALS['srcdir']}/payment_jav.inc.php"); ?>
240 <script type="text/javascript" src="../../library/js/jquery.1.3.2.js"></script>
241 <?php include_once("{$GLOBALS['srcdir']}/ajax/payment_ajax_jav.inc.php"); ?>
242 <script type="text/javascript" src="../../library/js/common.js"></script>
243 <script type="text/javascript" src="../../library/js/fancybox/jquery.fancybox-1.2.6.js"></script>
245 <script type='text/javascript'>
246 //For different browsers there was disparity in width.So this code is used to adjust the width.
247 if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
248 var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
249 if (ieversion>=5 && ieversion<=8)
251 $(document).ready(function() {
252 // fancy box
253 // special size for
254 $(".medium_modal").fancybox( {
255 'overlayOpacity' : 0.0,
256 'showCloseButton' : true,
257 'frameHeight' : 500,
258 'frameWidth' : 1097,
259 'centerOnScroll' : false
263 else
265 $(document).ready(function() {
266 // fancy box
267 // special size for
268 $(".medium_modal").fancybox( {
269 'overlayOpacity' : 0.0,
270 'showCloseButton' : true,
271 'frameHeight' : 500,
272 'frameWidth' : 1050,
273 'centerOnScroll' : false
278 else
280 $(document).ready(function() {
281 // fancy box
282 // special size for
283 $(".medium_modal").fancybox( {
284 'overlayOpacity' : 0.0,
285 'showCloseButton' : true,
286 'frameHeight' : 500,
287 'frameWidth' : 1050,
288 'centerOnScroll' : false
292 </script>
293 <script language='JavaScript'>
294 var mypcc = '1';
295 </script>
296 <script language='JavaScript'>
297 function SearchPayment()
298 {//Search validations.
299 if(document.getElementById('FromDate').value=='' && document.getElementById('ToDate').value=='' && document.getElementById('PaymentStatus').selectedIndex==0 && document.getElementById('payment_method').selectedIndex==0 && document.getElementById('type_name').selectedIndex==0 && document.getElementById('adjustment_code').selectedIndex==0 && document.getElementById('check_number').value=='' && document.getElementById('payment_amount').value=='' && document.getElementById('hidden_type_code').value=='' )
301 alert("<?php echo htmlspecialchars( xl('Please select any Search Option.'), ENT_QUOTES) ?>");
302 return false;
304 if(document.getElementById('FromDate').value!='' && document.getElementById('ToDate').value!='')
306 if(!DateCheckGreater(document.getElementById('FromDate').value,document.getElementById('ToDate').value,'<?php echo DateFormatRead();?>'))
308 alert("<?php echo htmlspecialchars( xl('From Date Cannot be Greater than To Date.'), ENT_QUOTES) ?>");
309 document.getElementById('FromDate').focus();
310 return false;
313 top.restoreSession();
314 document.getElementById('mode').value='SearchPayment';
315 document.forms[0].submit();
317 function DeletePayments(DeleteId)
318 {//Confirms deletion of payment and all its distribution.
319 if(confirm("<?php echo htmlspecialchars( xl('Would you like to Delete Payments?'), ENT_QUOTES) ?>"))
321 document.getElementById('mode').value='DeletePayments';
322 document.getElementById('DeletePaymentId').value=DeleteId;
323 top.restoreSession();
324 document.forms[0].submit();
326 else
327 return false;
329 function OnloadAction()
330 {//Displays message after deletion.
331 after_value=document.getElementById('after_value').value;
332 if(after_value=='Delete')
334 alert("<?php echo htmlspecialchars( xl('Successfully Deleted'), ENT_QUOTES) ?>")
337 function SearchPayingEntityAction()
339 //Which ajax is to be active(patient,insurance), is decided by the 'Paying Entity' drop down, where this function is called.
340 //So on changing some initialization is need.Done below.
341 document.getElementById('type_code').value='';
342 document.getElementById('hidden_ajax_close_value').value='';
343 document.getElementById('hidden_type_code').value='';
344 document.getElementById('div_insurance_or_patient').innerHTML='&nbsp;';
345 document.getElementById('description').value='';
346 if(document.getElementById('ajax_div_insurance'))
348 $("#ajax_div_patient_error").empty();
349 $("#ajax_div_patient").empty();
350 $("#ajax_div_insurance_error").empty();
351 $("#ajax_div_insurance").empty();
352 $("#ajax_div_insurance").hide();
353 document.getElementById('payment_method').style.display='';
356 </script>
357 <script language="javascript" type="text/javascript">
358 document.onclick=HideTheAjaxDivs;
359 </script>
360 <style>
361 .class1{width:125px;}
362 .class2{width:250px;}
363 .class3{width:100px;}
364 .class4{width:103px;}
365 #ajax_div_insurance {
366 position: absolute;
367 z-index:10;
368 background-color: #FBFDD0;
369 border: 1px solid #ccc;
370 padding: 10px;
372 #ajax_div_patient {
373 position: absolute;
374 z-index:10;
375 background-color: #FBFDD0;
376 border: 1px solid #ccc;
377 padding: 10px;
379 .bottom{border-bottom:1px solid black;}
380 .top{border-top:1px solid black;}
381 .left{border-left:1px solid black;}
382 .right{border-right:1px solid black;}
383 </style>
384 </head>
385 <body class="body_top" onLoad="OnloadAction()">
386 <form name='new_payment' method='post' style="display:inline" >
387 <table width="560" border="0" cellspacing="0" cellpadding="0">
388 <tr>
389 <td colspan="3" align="left"><b><?php echo htmlspecialchars( xl('Payments'), ENT_QUOTES) ?></b></td>
390 </tr>
391 <tr height="15">
392 <td colspan="3" align="left" ></td>
393 </tr>
394 <tr>
395 <td colspan="3" align="left">
396 <ul class="tabNav">
397 <li><a href='new_payment.php'><?php echo htmlspecialchars( xl('New Payment'), ENT_QUOTES) ?></a></li>
398 <li class='current'><a href='search_payments.php'><?php echo htmlspecialchars( xl('Search Payment'), ENT_QUOTES) ?></a></li>
399 <li><a href='era_payments.php'><?php echo htmlspecialchars( xl('ERA Posting'), ENT_QUOTES) ?></a></li>
400 </ul> </td>
401 </tr>
402 <tr>
403 <td colspan="3" align="left" >
404 <table width="974" border="0" cellspacing="0" cellpadding="10" bgcolor="#DEDEDE"><tr><td>
405 <table width="954" border="0" style="border:1px solid black" cellspacing="0" cellpadding="0">
406 <tr height="5">
407 <td width="954" colspan="6" align="left" ></td>
408 </tr>
409 <tr>
410 <td colspan="6" align="left">&nbsp;<font class='title'><?php echo htmlspecialchars( xl('Payment List'), ENT_QUOTES) ?></font></td>
411 </tr>
412 <tr height="5">
413 <td colspan="6" align="left" ></td>
414 </tr>
415 <tr>
416 <td colspan="6" align="left" ><table width="954" border="0" cellspacing="0" cellpadding="0">
417 <tr>
418 <td width="5"></td>
419 <td width="106"></td>
420 <td width="128"></td>
421 <td width="5"></td>
422 <td width="82"></td>
423 <td width="128"></td>
424 <td width="5"></td>
425 <td width="113"></td>
426 <td width="125"></td>
427 <td width="5"></td>
428 <td width="90"></td>
429 <td width="162"></td>
430 </tr>
431 <tr>
432 <td align="right"></td>
433 <td align="left" class="text"><?php echo generate_select_list("payment_date", "payment_date", "$PaymentDate", "Payment Date","","class4 text");?></td>
434 <td colspan="4">
435 <table border="0" cellspacing="0" cellpadding="0">
436 <tr>
437 <td align="left" class="text"><?php echo htmlspecialchars( xl('From'), ENT_QUOTES).':' ?></td>
438 <td><input type='text' style="width:90px;" name='FromDate' id='FromDate' class="text" value='<?php echo htmlspecialchars($FromDate); ?>' />
439 <img src='../../interface/main/calendar/modules/PostCalendar/pntemplates/default/images/new.jpg' align="texttop"
440 id='img_FromDate' border='0' alt='[?]' style='cursor:pointer'
441 title='<?php echo htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES); ?>' />
442 <script>
443 Calendar.setup({inputField:"FromDate", ifFormat:"<?php echo $DateFormat; ?>", button:"img_FromDate"});
444 </script></td>
445 <td width="53">&nbsp;</td>
446 <td align="left" class="text"><?php echo htmlspecialchars( xl('To'), ENT_QUOTES).':' ?></td>
447 <td><input type='text' style="width:103px;" name='ToDate' id='ToDate' class="text" value='<?php echo htmlspecialchars($ToDate); ?>' />
448 <img src='../../interface/main/calendar/modules/PostCalendar/pntemplates/default/images/new.jpg' align="texttop"
449 id='img_ToDate' border='0' alt='[?]' style='cursor:pointer'
450 title='<?php echo htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES); ?>' />
451 <script>
452 Calendar.setup({inputField:"ToDate", ifFormat:"<?php echo $DateFormat; ?>", button:"img_ToDate"});
453 </script></td>
454 </tr>
455 </table>
456 </td>
457 <td class="text"></td>
458 <td align="left" class="text"><?php echo htmlspecialchars( xl('Payment Method'), ENT_QUOTES).':' ?></td>
459 <td align="left"><?php echo generate_select_list("payment_method", "payment_method", "$PaymentMethod", "Payment Method"," ","class1 text");?></td>
460 <td></td>
461 <td align="left" class="text"><?php echo htmlspecialchars( xl('Check Number'), ENT_QUOTES).':' ?></td>
462 <td><input type="text" name="check_number" autocomplete="off" value="<?php echo htmlspecialchars(formData('check_number'));?>" id="check_number" class=" class1 text " /></td>
463 </tr>
464 <tr>
465 <td align="right"></td>
466 <td align="left" class="text"><?php echo htmlspecialchars( xl('Payment Amount'), ENT_QUOTES).':' ?></td>
467 <td align="left"><input type="text" name="payment_amount" autocomplete="off" id="payment_amount" onKeyUp="ValidateNumeric(this);" value="<?php echo htmlspecialchars(formData('payment_amount'));?>" style="text-align:right" class="class1 text " /></td>
468 <td align="left" ></td>
469 <td align="left" class="text"><?php echo htmlspecialchars( xl('Paying Entity'), ENT_QUOTES).':' ?></td>
470 <td align="left"><?php echo generate_select_list("type_name", "payment_type", "$type_name","Paying Entity"," ","class1 text","SearchPayingEntityAction()");?> </td>
471 <td align="left" ></td>
472 <td align="left" class="text"><?php echo htmlspecialchars( xl('Payment Category'), ENT_QUOTES).':' ?></td>
473 <td align="left"><?php echo generate_select_list("adjustment_code", "payment_adjustment_code", "$adjustment_code","Paying Category"," ","class1 text");?> </td>
474 <td></td>
475 <td align="left" class=" text " ><?php echo htmlspecialchars( xl('Pay Status'), ENT_QUOTES).':' ?></td>
476 <td align="left" ><?php echo generate_select_list("PaymentStatus", "payment_status", "$PaymentStatus","Pay Status"," ","class1 text");?></td>
477 </tr>
478 <tr>
479 <td align="right"></td>
480 <td align="left" class="text"><?php echo htmlspecialchars( xl('Payment From'), ENT_QUOTES).':' ?></td>
481 <td align="left" colspan="5" >
483 <table width="335" border="0" cellspacing="0" cellpadding="0">
484 <tr>
485 <td width="280">
486 <input type="hidden" id="hidden_ajax_close_value" value="<?php echo htmlspecialchars($div_after_save);?>" /><input name='type_code' id='type_code' class="text "
487 style=" width:280px;" onKeyDown="PreventIt(event)" value="<?php echo htmlspecialchars($div_after_save);?>" autocomplete="off" /><br>
488 <!--onKeyUp="ajaxFunction(event,'non','search_payments.php');"-->
489 <div id='ajax_div_insurance_section'>
490 <div id='ajax_div_insurance_error'> </div>
491 <div id="ajax_div_insurance" style="display:none;"></div>
492 </div>
493 </div> </td>
494 <td width="50" style="padding-left:5px;"><div name="div_insurance_or_patient" id="div_insurance_or_patient" class="text" style="border:1px solid black; padding-left:5px; width:50px; height:17px;"><?php echo htmlspecialchars(formData('hidden_type_code'));?></div><input type="hidden" name="description" id="description" /><input type="text" name="deposit_date" id="deposit_date" style="display:none"/></td>
495 </tr>
496 </table> </td>
497 <td align="left" class="text"><?php echo htmlspecialchars( xl('Sort Result by'), ENT_QUOTES).':' ?></td>
498 <td align="left" class="text"><?php echo generate_select_list("PaymentSortBy", "payment_sort_by", "$PaymentSortBy","Sort Result by"," ","class1 text");?> </td>
499 <td align="left" class="text"></td>
500 <td align="left" class="text"><table border="0" cellspacing="0" cellpadding="0">
501 <tr>
502 <td><a href="#" class="css_button" onClick="javascript:return SearchPayment();" ><span><?php echo htmlspecialchars( xl('Search'), ENT_QUOTES);?></span></a></td>
503 </tr>
504 </table></td>
505 <td align="left"></td>
506 </tr>
507 <tr height="5">
508 <td colspan="12" align="left" ></td>
509 </tr>
510 </table></td>
511 </tr>
512 </table>
513 </td></tr>
515 <!--Search-->
516 <?php //
517 if ($_POST["mode"] == "SearchPayment")
520 <tr>
521 <td>
522 <table border="0" cellspacing="0" cellpadding="0">
523 <?php //
524 if(sqlNumRows($ResultSearch)>0)
527 <tr class="text" bgcolor="#dddddd">
528 <td width="25" class="left top" >&nbsp;</td>
529 <td width="60" class="left top" ><?php echo htmlspecialchars( xl('ID'), ENT_QUOTES) ?></td>
530 <td width="70" class="left top" ><?php echo htmlspecialchars( xl('Date'), ENT_QUOTES) ?></td>
531 <td width="83" class="left top" ><?php echo htmlspecialchars( xl('Paying Entity'), ENT_QUOTES) ?></td>
532 <td width="245" class="left top" ><?php echo htmlspecialchars( xl('Payer'), ENT_QUOTES) ?></td>
533 <td width="57" class="left top" ><?php echo htmlspecialchars( xl('Ins Code'), ENT_QUOTES) ?></td>
534 <td width="110" class="left top" ><?php echo htmlspecialchars( xl('Payment Method'), ENT_QUOTES) ?></td>
535 <td width="130" class="left top" ><?php echo htmlspecialchars( xl('Check Number'), ENT_QUOTES) ?></td>
536 <td width="70" class="left top" ><?php echo htmlspecialchars( xl('Pay Status'), ENT_QUOTES) ?></td>
537 <td width="50" class="left top" ><?php echo htmlspecialchars( xl('Payment'), ENT_QUOTES) ?></td>
538 <td width="70" class="left top right" ><?php echo htmlspecialchars( xl('Undistributed'), ENT_QUOTES) ?></td>
539 </tr>
540 <?php
541 $CountIndex=0;
542 while ($RowSearch = sqlFetchArray($ResultSearch))
544 $Payer='';
545 if($RowSearch['payer_id']*1 > 0)
547 //-------------------
548 $res = sqlStatement("SELECT insurance_companies.name FROM insurance_companies
549 where insurance_companies.id ='{$RowSearch['payer_id']}'");
550 $row = sqlFetchArray($res);
551 $Payer=$row['name'];
552 //-------------------
554 elseif($RowSearch['patient_id']*1 > 0)
556 //-------------------
557 $res = sqlStatement("SELECT fname,lname,mname FROM patient_data
558 where pid ='{$RowSearch['patient_id']}'");
559 $row = sqlFetchArray($res);
560 $fname=$row['fname'];
561 $lname=$row['lname'];
562 $mname=$row['mname'];
563 $Payer=$lname.' '.$fname.' '.$mname;
564 //-------------------
566 //=============================================
567 $CountIndex++;
568 if($CountIndex==sqlNumRows($ResultSearch))
570 $StringClass=' bottom left top ';
572 else
574 $StringClass=' left top ';
576 if($CountIndex%2==1)
578 $bgcolor='#ddddff';
580 else
582 $bgcolor='#ffdddd';
585 <tr class="text" bgcolor='<?php echo $bgcolor; ?>'>
586 <td class="<?php echo $StringClass; ?>" ><a href="#" onClick="javascript:return DeletePayments(<?php echo htmlspecialchars($RowSearch['session_id']); ?>);" ><img src="../pic/Delete.gif" border="0"/></a></td>
587 <td class="<?php echo $StringClass; ?>" ><a href="edit_payment.php?payment_id=<?php echo htmlspecialchars($RowSearch['session_id']); ?>" class='iframe medium_modal' ><?php echo htmlspecialchars($RowSearch['session_id']); ?></a></td>
588 <td class="<?php echo $StringClass; ?>" ><a href="edit_payment.php?payment_id=<?php echo htmlspecialchars($RowSearch['session_id']); ?>" class='iframe medium_modal' ><?php echo $RowSearch['check_date']=='0000-00-00' ? '&nbsp;' : htmlspecialchars(oeFormatShortDate($RowSearch['check_date'])); ?></a></td>
589 <td class="<?php echo $StringClass; ?>" ><a href="edit_payment.php?payment_id=<?php echo htmlspecialchars($RowSearch['session_id']); ?>" class='iframe medium_modal' ><?php
590 $frow['data_type']=1;
591 $frow['list_id']='payment_type';
592 $PaymentType='';
593 if($RowSearch['payment_type']=='insurance' || $RowSearch['payer_id']*1 > 0)
595 $PaymentType='insurance';
597 elseif($RowSearch['payment_type']=='patient' || $RowSearch['patient_id']*1 > 0)
599 $PaymentType='patient';
601 elseif(($RowSearch['payer_id']*1 == 0 && $RowSearch['patient_id']*1 == 0))
603 $PaymentType='';
606 generate_print_field($frow, $PaymentType);
607 ?></a></td>
608 <td class="<?php echo $StringClass; ?>" ><a href="edit_payment.php?payment_id=<?php echo htmlspecialchars($RowSearch['session_id']); ?>" class='iframe medium_modal' ><?php echo $Payer=='' ? '&nbsp;' : htmlspecialchars($Payer) ;?></a></td>
609 <td class="<?php echo $StringClass; ?>" ><a href="edit_payment.php?payment_id=<?php echo htmlspecialchars($RowSearch['session_id']); ?>" class='iframe medium_modal' ><?php echo $RowSearch['payer_id']*1 > 0 ? htmlspecialchars($RowSearch['payer_id']) : '&nbsp;'; ?></a></td>
610 <td align="left" class="<?php echo $StringClass; ?> " ><a href="edit_payment.php?payment_id=<?php echo htmlspecialchars($RowSearch['session_id']); ?>" class='iframe medium_modal' ><?php
611 $frow['data_type']=1;
612 $frow['list_id']='payment_method';
613 generate_print_field($frow, $RowSearch['payment_method']);
614 ?></a></td>
615 <td align="left" class="<?php echo $StringClass; ?> " ><a href="edit_payment.php?payment_id=<?php echo htmlspecialchars($RowSearch['session_id']); ?>" class='iframe medium_modal' ><?php echo $RowSearch['reference']=='' ? '&nbsp;' : htmlspecialchars($RowSearch['reference']); ?></a></td>
616 <td align="left" class="<?php echo $StringClass; ?> " ><a href="edit_payment.php?payment_id=<?php echo htmlspecialchars($RowSearch['session_id']); ?>" class='iframe medium_modal' ><?php
617 $rs= sqlStatement("select pay_total,global_amount from ar_session where session_id='".$RowSearch['session_id']."'");
618 $row=sqlFetchArray($rs);
619 $pay_total=$row['pay_total'];
620 $global_amount=$row['global_amount'];
621 $rs= sqlStatement("select sum(pay_amount) sum_pay_amount from ar_activity where session_id='".$RowSearch['session_id']."'");
622 $row=sqlFetchArray($rs);
623 $pay_amount=$row['sum_pay_amount'];
624 $UndistributedAmount=$pay_total-$pay_amount-$global_amount;
625 echo $UndistributedAmount*1==0 ? htmlspecialchars( xl('Fully Paid'), ENT_QUOTES) : htmlspecialchars( xl('Unapplied'), ENT_QUOTES); ?></a></td>
626 <td align="right" class="<?php echo $StringClass; ?>" ><a href="edit_payment.php?payment_id=<?php echo htmlspecialchars($RowSearch['session_id']); ?>" class='iframe medium_modal' ><?php echo htmlspecialchars($RowSearch['pay_total']); ?></a></td>
627 <td align="right" class="<?php echo $StringClass; ?> right" ><a href="edit_payment.php?payment_id=<?php echo htmlspecialchars($RowSearch['session_id']); ?>" class='iframe medium_modal' ><?php echo htmlspecialchars(number_format($UndistributedAmount,2)); ?></a></td>
628 </tr>
629 <?php
630 }//while ($RowSearch = sqlFetchArray($ResultSearch))
631 }//if(sqlNumRows($ResultSearch)>0)
632 else
635 <tr>
636 <td colspan="11" class="text"><?php echo htmlspecialchars( xl('No Result Found, for the above search criteria.'), ENT_QUOTES) ?></td>
637 </tr>
638 <?php
639 }// else
641 </table>
642 </td>
643 </tr>
644 <?php
645 }//if ($_POST["mode"] == "SearchPayment")
647 </table>
648 </td>
649 </tr>
650 </table>
651 <input type='hidden' name='mode' id='mode' value='' />
652 <input type='hidden' name='ajax_mode' id='ajax_mode' value='' />
653 <input type="hidden" name="hidden_type_code" id="hidden_type_code" value="<?php echo htmlspecialchars(formData('hidden_type_code'));?>"/>
654 <input type='hidden' name='DeletePaymentId' id='DeletePaymentId' value='' />
655 <input type='hidden' name='SortFieldOld' id='SortFieldOld' value='<?php echo htmlspecialchars($PaymentSortBy);?>' />
656 <input type='hidden' name='Sort' id='Sort' value='<?php echo htmlspecialchars($Sort);?>' />
657 <input type="hidden" name="after_value" id="after_value" value="<?php echo htmlspecialchars($Message);?>"/>
658 </form>
659 </body>
660 </html>