feat: Fixes #6772 adds twig email templates to emails (#6773)
[openemr.git] / interface / billing / search_payments.php
blob1e60022a30ebfe4d79c1fb6f7019e51e09309f20
1 <?php
3 /**
4 * Payments in database can be searched through this screen and edit popup is also its part.
5 * Deletion of the payment is done with logging.
8 * @package OpenEMR
9 * @link http://www.open-emr.org
10 * @author Eldho Chacko <eldho@zhservices.com>
11 * @author Paul Simon K <paul@zhservices.com>
12 * @author Brady Miller <brady.g.miller@gmail.com>
13 * @author Rod Roark <rod@sunsetsystems.com>
14 * @copyright Copyright (c) 2010 Z&H Consultancy Services Private Limited <sam@zhservices.com>
15 * @copyright Copyright (c) 2019-2020 Brady Miller <brady.g.miller@gmail.com>
16 * @copyright Copyright (c) 2020 Rod Roark <rod@sunsetsystems.com>
17 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
20 require_once("../globals.php");
21 require_once("../../custom/code_types.inc.php");
22 require_once("$srcdir/patient.inc.php");
23 require_once("$srcdir/options.inc.php");
24 require_once("$srcdir/payment.inc.php");
26 use OpenEMR\Common\Acl\AclMain;
27 use OpenEMR\Common\Twig\TwigContainer;
28 use OpenEMR\Core\Header;
29 use OpenEMR\OeUI\OemrUI;
31 if (!AclMain::aclCheckCore('acct', 'bill', '', 'write') && !AclMain::aclCheckCore('acct', 'eob', '', 'write')) {
32 echo (new TwigContainer(null, $GLOBALS['kernel']))->getTwig()->render('core/unauthorized.html.twig', ['pageTitle' => xl("Search Payment")]);
33 exit;
36 //===============================================================================
37 //Deletion of payment and its corresponding distributions.
38 //===============================================================================
39 set_time_limit(0);
40 if (isset($_POST["mode"])) {
41 if ($_POST["mode"] == "DeletePayments") {
42 $DeletePaymentId = isset($_POST['DeletePaymentId']) ? trim($_POST['DeletePaymentId']) : '';
43 $ResultSearch = sqlStatement(
44 "SELECT distinct encounter, pid from ar_activity where deleted IS NULL AND session_id = ?",
45 [$DeletePaymentId]
47 if (sqlNumRows($ResultSearch) > 0) {
48 while ($RowSearch = sqlFetchArray($ResultSearch)) {
49 $Encounter = $RowSearch['encounter'];
50 $PId = $RowSearch['pid'];
51 sqlStatement("update form_encounter set last_level_closed=last_level_closed - 1 where pid =? and encounter=?", [$PId, $Encounter]);
55 //delete and log that action
56 row_delete("ar_session", "session_id ='" . add_escape_custom($DeletePaymentId) . "'");
57 row_modify("ar_activity", "deleted = NOW()", "deleted IS NULL AND session_id = '" . add_escape_custom($DeletePaymentId) . "'");
58 $Message = 'Delete';
59 //------------------
60 $_POST["mode"] = "SearchPayment";
63 //===============================================================================
64 //Search section.
65 //===============================================================================
66 if ($_POST["mode"] == "SearchPayment") {
67 $FromDate = isset($_POST['FromDate']) ? trim($_POST['FromDate']) : '';
68 $ToDate = isset($_POST['ToDate']) ? trim($_POST['ToDate']) : '';
69 $PaymentMethod = isset($_POST['payment_method']) ? trim($_POST['payment_method']) : '';
70 $CheckNumber = isset($_POST['check_number']) ? trim($_POST['check_number']) : '';
71 $PaymentAmount = isset($_POST['payment_amount']) ? trim($_POST['payment_amount']) : '';
72 $PayingEntity = isset($_POST['type_name']) ? trim($_POST['type_name']) : '';
73 $PaymentCategory = isset($_POST['adjustment_code']) ? trim($_POST['adjustment_code']) : '';
74 $PaymentFrom = isset($_POST['hidden_type_code']) ? trim($_POST['hidden_type_code']) : '';
75 $PaymentStatus = isset($_POST['PaymentStatus']) ? trim($_POST['PaymentStatus']) : '';
76 $PaymentSortBy = isset($_POST['PaymentSortBy']) ? trim($_POST['PaymentSortBy']) : '';
77 $PaymentDate = isset($_POST['payment_date']) ? trim($_POST['payment_date']) : '';
78 $QueryString = "Select * from ar_session where ";
79 $And = '';
81 $sqlBindArray = array();
83 if ($PaymentDate == 'date_val') {
84 $PaymentDateString = ' check_date ';
85 } elseif ($PaymentDate == 'post_to_date') {
86 $PaymentDateString = ' post_to_date ';
87 } elseif ($PaymentDate == 'deposit_date') {
88 $PaymentDateString = ' deposit_date ';
91 if ($FromDate != '') {
92 $QueryString .= " $And $PaymentDateString >=?";
93 $And = ' and ';
94 $sqlBindArray[] = DateToYYYYMMDD($FromDate);
97 if ($ToDate != '') {
98 $QueryString .= " $And $PaymentDateString <=?";
99 $And = ' and ';
100 $sqlBindArray[] = DateToYYYYMMDD($ToDate);
103 if ($PaymentMethod != '') {
104 $QueryString .= " $And payment_method =?";
105 $And = ' and ';
106 $sqlBindArray[] = $PaymentMethod;
109 if ($CheckNumber != '') {
110 $QueryString .= " $And reference like ?";
111 $And = ' and ';
112 $sqlBindArray[] = '%' . $CheckNumber . '%';
115 if ($PaymentAmount != '') {
116 $QueryString .= " $And pay_total =?";
117 $And = ' and ';
118 $sqlBindArray[] = $PaymentAmount;
121 if ($PayingEntity != '') {
122 if ($PayingEntity == 'insurance') {
123 $QueryString .= " $And payer_id !='0'";
126 if ($PayingEntity == 'patient') {
127 $QueryString .= " $And payer_id ='0'";
130 $And = ' and ';
133 if ($PaymentCategory != '') {
134 $QueryString .= " $And adjustment_code =?";
135 $And = ' and ';
136 $sqlBindArray[] = $PaymentCategory;
139 if ($PaymentFrom != '') {
140 if ($PayingEntity == 'insurance' || $PayingEntity == '') {
141 //-------------------
142 $res = sqlStatement("SELECT insurance_companies.name FROM insurance_companies
143 where insurance_companies.id =?", [$PaymentFrom]);
144 $row = sqlFetchArray($res);
145 $div_after_save = $row['name'];
146 //-------------------
148 $QueryString .= " $And payer_id =?";
149 $sqlBindArray[] = $PaymentFrom;
152 if ($PayingEntity == 'patient') {
153 //-------------------
154 $res = sqlStatement("SELECT fname,lname,mname FROM patient_data
155 where pid =?", [$PaymentFrom]);
156 $row = sqlFetchArray($res);
157 $fname = $row['fname'];
158 $lname = $row['lname'];
159 $mname = $row['mname'];
160 $div_after_save = $lname . ' ' . $fname . ' ' . $mname;
161 //-------------------
163 $QueryString .= " $And patient_id =?";
164 $sqlBindArray[] = $PaymentFrom;
167 $And = ' and ';
170 if ($PaymentStatus != '') {
171 $QsString = "select ar_session.session_id, pay_total, global_amount, sum(pay_amount) sum_pay_amount " .
172 "from ar_session,ar_activity WHERE " .
173 "ar_activity.deleted IS NULL AND ar_session.session_id = ar_activity.session_id " .
174 "group by ar_activity.session_id, ar_session.session_id " .
175 "having pay_total - global_amount - sum_pay_amount = 0 or pay_total = 0";
176 $rs = sqlStatement($QsString);
177 while ($rowrs = sqlFetchArray($rs)) {
178 $StringSessionId .= $rowrs['session_id'] . ',';
181 $QsString = "select ar_session.session_id from ar_session where pay_total=0";
182 $rs = sqlStatement($QsString);
183 while ($rowrs = sqlFetchArray($rs)) {
184 $StringSessionId .= $rowrs['session_id'] . ',';
187 $StringSessionId = substr($StringSessionId, 0, -1);
188 if ($PaymentStatus == 'fully_paid') {
189 $QueryString .= " $And session_id in(" . add_escape_custom($StringSessionId) . ") ";
190 } elseif ($PaymentStatus == 'unapplied') {
191 $QueryString .= " $And session_id not in(" . add_escape_custom($StringSessionId) . ") ";
194 $And = ' and ';
197 if ($PaymentSortBy != '') {
198 $SortFieldOld = isset($_POST['SortFieldOld']) ? trim($_POST['SortFieldOld']) : '';
199 $Sort = isset($_POST['Sort']) ? trim($_POST['Sort']) : '';
200 if ($SortFieldOld == $PaymentSortBy) {
201 if ($Sort == 'DESC' || $Sort == '') {
202 $Sort = 'ASC';
203 } else {
204 $Sort = 'DESC';
206 } else {
207 $Sort = 'ASC';
210 $QueryString .= " order by " . escape_sql_column_name($PaymentSortBy, ['ar_session']) . " " . escape_sort_order($Sort);
213 $ResultSearch = sqlStatement($QueryString, $sqlBindArray);
217 //===============================================================================
219 <!DOCTYPE html>
220 <html>
221 <head>
222 <title><?php echo xlt("Search Payment") ?></title>
223 <?php Header::setupHeader(['datetime-picker']); ?>
225 <?php include_once("{$GLOBALS['srcdir']}/payment_jav.inc.php"); ?>
226 <?php include_once("{$GLOBALS['srcdir']}/ajax/payment_ajax_jav.inc.php"); ?>
228 <script>
229 function refreshSearch() {
230 top.restoreSession();
231 SearchPayment();
234 $(function () {
235 <?php if (!empty($_POST['mode']) && ($_POST['mode'] == 'SearchPayment')) { ?>
236 $("html").animate({ scrollTop: $("div table.table").offset().top }, 800);
237 <?php } ?>
239 $(".medium_modal").on('click', function (e) {
240 e.preventDefault();
241 e.stopPropagation();
242 dlgopen('', '', 'modal-full', 800, '', '', {
243 buttons: [
244 {text: <?php echo xlj('Close'); ?>, close: true, style: 'default btn-sm'}
246 sizeHeight: '',
247 onClosed: 'refreshSearch',
248 type: 'iframe',
249 url: $(this).attr('href')
253 $('.datepicker').datetimepicker({
254 <?php $datetimepicker_timepicker = false; ?>
255 <?php $datetimepicker_showseconds = false; ?>
256 <?php $datetimepicker_formatInput = true; ?>
257 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
258 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
262 var mypcc = '1';
264 function SearchPayment() {
265 // Search validations.
266 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 == '') {
267 alert(<?php echo xlj('Please select any Search Option.'); ?>);
268 return false;
270 if (document.getElementById('FromDate').value != '' && document.getElementById('ToDate').value != '') {
271 if (!DateCheckGreater(document.getElementById('FromDate').value, document.getElementById('ToDate').value, '<?php echo DateFormatRead();?>')) {
272 alert(<?php echo xlj('From Date Cannot be Greater than To Date.'); ?>);
273 document.getElementById('FromDate').focus();
274 return false;
277 top.restoreSession();
278 document.getElementById('mode').value = 'SearchPayment';
279 document.forms[0].submit();
282 function DeletePayments(DeleteId) {
283 // Confirms deletion of payment and all its distribution.
284 if (confirm(<?php echo xlj('Would you like to Delete Payments?'); ?>)) {
285 document.getElementById('mode').value = 'DeletePayments';
286 document.getElementById('DeletePaymentId').value = DeleteId;
287 top.restoreSession();
288 document.forms[0].submit();
289 } else
290 return false;
293 function OnloadAction() {
294 // Displays message after deletion.
295 after_value = document.getElementById('after_value').value;
296 if (after_value == 'Delete') {
297 alert(<?php echo xlj('Successfully Deleted'); ?>)
301 function SearchPayingEntityAction() {
302 // Which ajax is to be active(patient,insurance), is decided by the 'Paying Entity' drop down, where this function is called.
303 // So on changing some initialization is need.Done below.
304 document.getElementById('type_code').value = '';
305 document.getElementById('hidden_ajax_close_value').value = '';
306 document.getElementById('hidden_type_code').value = '';
307 document.getElementById('div_insurance_or_patient').innerHTML = '&nbsp;';
308 document.getElementById('description').value = '';
309 if (document.getElementById('ajax_div_insurance')) {
310 $("#ajax_div_patient_error").empty();
311 $("#ajax_div_patient").empty();
312 $("#ajax_div_insurance_error").empty();
313 $("#ajax_div_insurance").empty();
314 $("#ajax_div_insurance").hide();
315 document.getElementById('payment_method').style.display = '';
319 document.onclick = HideTheAjaxDivs;
320 </script>
322 <style>
323 #ajax_div_insurance {
324 position: absolute;
325 z-index: 10;
326 background-color: #FBFDD0;
327 border: 1px solid var(--gray);
328 padding: 10px;
331 @media (min-width: 992px) {
332 .modal-lg {
333 width: 1000px !Important;
336 </style>
337 <?php
338 $arrOeUiSettings = array(
339 'heading_title' => xl('Payments'),
340 'include_patient_name' => false,// use only in appropriate pages
341 'expandable' => true,
342 'expandable_files' => array("search_payments_xpd", "new_payment_xpd", "era_payments_xpd"),//all file names need suffix _xpd
343 'action' => "",//conceal, reveal, search, reset, link or back
344 'action_title' => "",
345 'action_href' => "",//only for actions - reset, link or back
346 'show_help_icon' => false,
347 'help_file_name' => ""
349 $oemr_ui = new OemrUI($arrOeUiSettings);
351 </head>
352 <body onload="OnloadAction()">
353 <div id="container_div" class="<?php echo attr($oemr_ui->oeContainer()); ?> mt-3">
354 <div class="row">
355 <div class="col-sm-12">
356 <?php echo $oemr_ui->pageHeading() . "\r\n"; ?>
357 </div>
358 </div>
359 <nav class="navbar navbar-nav navbar-expand-md navbar-light text-body bg-light mb-4 p-4">
360 <button class="navbar-toggler icon-bar" data-target="#myNavbar" data-toggle="collapse" type="button"><span class="navbar-toggler-icon"></span></button>
361 <div class="collapse navbar-collapse" id="myNavbar">
362 <ul class="navbar-nav mr-auto">
363 <li class="nav-item">
364 <a class="nav-link font-weight-bold" href='new_payment.php'><?php echo xlt('New Payment'); ?></a>
365 </li>
366 <li class="nav-item">
367 <a class="nav-link active font-weight-bold" href='search_payments.php'><?php echo xlt('Search Payment'); ?></a>
368 </li>
369 <li class="nav-item">
370 <a class="nav-link font-weight-bold" href='era_payments.php'><?php echo xlt('ERA Posting'); ?></a>
371 </li>
372 </ul>
373 </div>
374 </nav>
375 <div class="row">
376 <div class="col-sm-12">
377 <form id="new_payment" method='post' name='new_payment'>
378 <fieldset>
379 <div class="jumbotron py-4">
380 <div class="row h3">
381 <?php echo xlt('Payment List'); ?>
382 </div>
383 <div class="row oe-custom-line">
384 <div class="forms col-2">
385 <label class="control-label" for="payment_date"><?php echo xlt('Payment date'); ?>:</label>
386 <?php echo generate_select_list("payment_date", "payment_date", ($PaymentDate ?? ''), "Payment Date", "", ""); ?>
387 </div>
388 <div class="forms col-2">
389 <label class="control-label" for="FromDate"><?php echo xlt('From'); ?>:</label>
390 <input class="form-control datepicker" id='FromDate' name='FromDate' type='text' value='<?php echo attr($FromDate ?? ''); ?>' autocomplete="off" />
391 </div>
392 <div class="forms col-2">
393 <label class="control-label" for="ToDate"><?php echo xlt('To{{Range}}'); ?>:</label>
394 <input class="form-control datepicker" id='ToDate' name='ToDate' type='text' value='<?php echo attr($ToDate ?? ''); ?>' autocomplete="off" />
395 </div>
396 <div class="forms col-3">
397 <label class="control-label" for="payment_method"><?php echo xlt('Payment Method'); ?>:</label>
398 <?php echo generate_select_list("payment_method", "payment_method", ($PaymentMethod ?? ''), "Payment Method", " ", ""); ?>
399 </div>
400 <div class="forms col-3">
401 <label class="control-label" for="check_number"><?php echo xlt('Check Number'); ?>:</label>
402 <input autocomplete="off" class="form-control" id="check_number" name="check_number" type="text" value="<?php echo attr($_POST['check_number'] ?? ''); ?>" />
403 </div>
404 </div>
405 <div class="row oe-custom-line">
406 <div class="forms col-4">
407 <label class="control-label" for="payment_method"><?php echo xlt('Payment Amount'); ?>:</label>
408 <input autocomplete="off" class="form-control" id="payment_amount" name="payment_amount" onkeyup="ValidateNumeric(this);" type="text" value="<?php echo attr($_POST['payment_amount'] ?? ''); ?>" />
409 </div>
410 <div class="forms col-2">
411 <label class="control-label" for="type_name"><?php echo xlt('Paying Entity'); ?>:</label>
412 <?php echo generate_select_list("type_name", "payment_type", ($type_name ?? ''), "Paying Entity", " ", "", "SearchPayingEntityAction()"); ?>
413 </div>
414 <div class="forms col-3">
415 <label class="control-label" for="adjustment_code"><?php echo xlt('Payment Category'); ?>:</label>
416 <?php echo generate_select_list("adjustment_code", "payment_adjustment_code", ($adjustment_code ?? ''), "Paying Category", " ", ""); ?>
417 </div>
418 <div class="forms col-3">
419 <label class="control-label" for="PaymentStatus"><?php echo xlt('Pay Status'); ?>:</label>
420 <?php echo generate_select_list("PaymentStatus", "payment_status", ($PaymentStatus ?? ''), "Pay Status", " ", ""); ?>
421 </div>
422 </div>
423 <div class="row oe-custom-line">
424 <div class="forms col-4">
425 <label class="control-label" for="type_code"><?php echo xlt('Payment From'); ?>:</label>
426 <input id="hidden_ajax_close_value" type="hidden" value="<?php echo attr($div_after_save ?? ''); ?>" />
427 <input autocomplete="off" class="form-control" id='type_code' name='type_code' onkeydown="PreventIt(event)" type="text" value="<?php echo attr($div_after_save ?? ''); ?>" />
428 <!--onKeyUp="ajaxFunction(event,'non','search_payments.php');"-->
429 <div id='ajax_div_insurance_section'>
430 <div id='ajax_div_insurance_error'></div>
431 <div id="ajax_div_insurance" style="display:none;"></div>
432 </div>
433 </div>
434 <div class="forms col-2">
435 <label class="control-label" for="div_insurance_or_patient"><?php echo xlt('Payor ID'); ?>:</label>
436 <div class="form-control" id="div_insurance_or_patient"><?php echo attr($_POST['hidden_type_code'] ?? ''); ?></div>
437 <input id="description" name="description" type="hidden" />
438 <input id="deposit_date" name="deposit_date" style="display:none" type="text" />
439 </div>
440 <div class="forms col-3">
441 <label class="control-label" for="PaymentSortBy"><?php echo xlt('Sort Result by'); ?>:</label>
442 <?php echo generate_select_list("PaymentSortBy", "payment_sort_by", ($PaymentSortBy ?? ''), "Sort Result by", " ", ""); ?>
443 </div>
444 </div>
445 <!-- can change position of buttons by creating a class 'position-override' and adding rule text-align:center or right as the case may be in individual stylesheets -->
446 <div class="form-group mt-3">
447 <div class="col-sm-12 text-left position-override">
448 <div class="btn-group" role="group">
449 <a class="btn btn-primary btn-search" href="#" onclick="javascript:return SearchPayment();"><span><?php echo xlt('Search'); ?></span></a>
450 </div>
451 </div>
452 </div>
453 </div>
454 </fieldset><!--End of Search-->
455 <?php
456 if (!empty($_POST["mode"]) && ($_POST["mode"] == "SearchPayment")) {
457 echo "&nbsp;" . "<br />"; // do not remove else below div will not display !!
459 <div class="table-responsive-sm">
460 <table class="table table-sm table-bordered">
461 <?php
462 if (sqlNumRows($ResultSearch) > 0) { ?>
463 <thead class="bg-dark text-light">
464 <tr>
465 <th>&nbsp;</th>
466 <th><?php echo xlt('ID'); ?></th>
467 <th><?php echo xlt('Date'); ?></th>
468 <th><?php echo xlt('Paying Entity'); ?></th>
469 <th><?php echo xlt('Payer'); ?></th>
470 <th><?php echo xlt('Ins Code'); ?></th>
471 <th><?php echo xlt('Payment Method'); ?></th>
472 <th><?php echo xlt('Check Number'); ?></th>
473 <th><?php echo xlt('Pay Status'); ?></th>
474 <th><?php echo xlt('Payment'); ?></th>
475 <th><?php echo xlt('Undistributed'); ?></th>
476 </tr>
477 </thead>
478 <?php
479 $CountIndex = 0;
480 while ($RowSearch = sqlFetchArray($ResultSearch)) {
481 $Payer = '';
482 if ($RowSearch['payer_id'] * 1 > 0) {
483 //-------------------
484 $res = sqlStatement("SELECT insurance_companies.name FROM insurance_companies
485 where insurance_companies.id =?", [$RowSearch['payer_id']]);
486 $row = sqlFetchArray($res);
487 $Payer = $row['name'];
488 //-------------------
489 } elseif ($RowSearch['patient_id'] * 1 > 0) {
490 //-------------------
491 $res = sqlStatement("SELECT fname,lname,mname FROM patient_data
492 where pid =?", [$RowSearch['patient_id']]);
493 $row = sqlFetchArray($res);
494 $fname = $row['fname'];
495 $lname = $row['lname'];
496 $mname = $row['mname'];
497 $Payer = $lname . ' ' . $fname . ' ' . $mname;
498 //-------------------
500 //=============================================
501 $CountIndex++;
502 if ($CountIndex % 2 == 1) {
503 $bgcolor = '#ddddff';
504 } else {
505 $bgcolor = '#ffdddd';
508 <tr bgcolor='<?php echo attr($bgcolor); ?>' class="text">
509 <td>
510 <a href="#" onclick="javascript:return DeletePayments(<?php echo attr_js($RowSearch['session_id']); ?>);"><img border="0" src="../pic/Delete.gif"></a>
511 </td>
512 <td>
513 <a class="medium_modal" href="edit_payment.php?payment_id=<?php echo attr_url($RowSearch['session_id']); ?>"><?php echo text($RowSearch['session_id']); ?></a>
514 </td>
515 <td>
516 <a class="medium_modal" href='edit_payment.php?payment_id=<?php echo attr_url($RowSearch['session_id']); ?>'"><?php echo $RowSearch['check_date'] == '0000-00-00' ? '&nbsp;' : text(oeFormatShortDate($RowSearch['check_date'])); ?></a>
517 </td>
518 <td>
519 <a class="medium_modal" href='edit_payment.php?payment_id=<?php echo attr_url($RowSearch['session_id']); ?>'">
520 <?php
521 $frow['data_type'] = 1;
522 $frow['list_id'] = 'payment_type';
523 $PaymentType = '';
524 if ($RowSearch['payment_type'] == 'insurance' || $RowSearch['payer_id'] * 1 > 0) {
525 $PaymentType = 'insurance';
526 } elseif ($RowSearch['payment_type'] == 'patient' || $RowSearch['patient_id'] * 1 > 0) {
527 $PaymentType = 'patient';
528 } elseif (($RowSearch['payer_id'] * 1 == 0 && $RowSearch['patient_id'] * 1 == 0)) {
529 $PaymentType = '';
531 generate_print_field($frow, $PaymentType);
532 ?></a>
533 </td>
534 <td>
535 <!--<a class='iframe medium_modal' href="edit_payment.php?payment_id=<?php echo htmlspecialchars($RowSearch['session_id']); ?>"><?php echo $Payer == '' ? '&nbsp;' : htmlspecialchars($Payer); ?></a>-->
536 <a class="medium_modal" href='edit_payment.php?payment_id=<?php echo attr_url($RowSearch['session_id']); ?>')"><?php echo $Payer == '' ? '&nbsp;' : text($Payer); ?></a><!--link to iframe-->
537 </td>
538 <td>
539 <a class="medium_modal" href='edit_payment.php?payment_id=<?php echo attr_url($RowSearch['session_id']); ?>'><?php echo $RowSearch['payer_id'] * 1 > 0 ? text($RowSearch['payer_id']) : '&nbsp;'; ?></a>
540 </td>
541 <td class="text-left">
542 <!--<a class='iframe medium_modal' href="edit_payment.php?payment_id=<?php echo attr_url($RowSearch['session_id']); ?>"><?php
543 $frow['data_type'] = 1;
544 $frow['list_id'] = 'payment_method';
545 generate_print_field($frow, $RowSearch['payment_method']);
546 ?></a>-->
547 <a class="medium_modal" href='edit_payment.php?payment_id=<?php echo attr_url($RowSearch['session_id']); ?>'">
548 <?php
549 $frow['data_type'] = 1;
550 $frow['list_id'] = 'payment_method';
551 generate_print_field($frow, $RowSearch['payment_method']);
552 ?></a>
553 </td>
554 <td class="text-left">
555 <!--<a class='iframe medium_modal' href="edit_payment.php?payment_id=<?php echo attr_url($RowSearch['session_id']); ?>"><?php echo $RowSearch['reference'] == '' ? '&nbsp;' : text($RowSearch['reference']); ?></a>-->
556 <a class="medium_modal" href='edit_payment.php?payment_id=<?php echo attr_url($RowSearch['session_id']); ?>'"><?php echo $RowSearch['reference'] == '' ? '&nbsp;' : text($RowSearch['reference']); ?></a>
557 </td>
558 <td class="text-left">
559 <a class="medium_modal" href='edit_payment.php?payment_id=<?php echo attr_url($RowSearch['session_id']); ?>'">
560 <?php
561 $rs = sqlStatement("select pay_total,global_amount from ar_session where session_id=?", [$RowSearch['session_id']]);
562 $row = sqlFetchArray($rs);
563 $pay_total = $row['pay_total'];
564 $global_amount = $row['global_amount'];
565 $rs = sqlStatement(
566 "select sum(pay_amount) sum_pay_amount from ar_activity where " .
567 "deleted IS NULL AND session_id = ?",
568 [$RowSearch['session_id']]
570 $row = sqlFetchArray($rs);
571 $pay_amount = $row['sum_pay_amount'];
572 $UndistributedAmount = $pay_total - $pay_amount - $global_amount;
573 echo $UndistributedAmount * 1 == 0 ? xlt('Fully Paid') : xlt('Unapplied'); ?></a>
574 </td>
575 <td class="text-right">
576 <a class="medium_modal" href='edit_payment.php?payment_id=<?php echo attr_url($RowSearch['session_id']); ?>'"><?php echo text($RowSearch['pay_total']); ?></a>
577 </td>
578 <td class="<?php echo attr($StringClass ?? ''); ?>right text-right">
579 <a class="medium_modal" href='edit_payment.php?payment_id=<?php echo attr_url($RowSearch['session_id']); ?>'"><?php echo text(number_format($UndistributedAmount, 2)); ?></a>
580 </td>
581 </tr>
582 <?php
583 }// End of while ($RowSearch = sqlFetchArray($ResultSearch))
584 } else { // End of if(sqlNumRows($ResultSearch)>0)
586 <tr>
587 <td class="text" colspan="11"><?php echo xlt('No Result Found, for the above search criteria.'); ?></td>
588 </tr>
589 <?php
590 }// End of else
592 </table>
593 </div><!--End of table-responsive div-->
594 <?php
595 }// End of if ($_POST["mode"] == "SearchPayment")
597 <div class="row">
598 <input id='mode' name='mode' type='hidden' value='' />
599 <input id='ajax_mode' name='ajax_mode' type='hidden' value='' />
600 <input id="hidden_type_code" name="hidden_type_code" type="hidden" value="<?php echo attr($_POST['hidden_type_code'] ?? ''); ?>" />
601 <input id='DeletePaymentId' name='DeletePaymentId' type='hidden' value='' />
602 <input id='SortFieldOld' name='SortFieldOld' type='hidden' value='<?php echo attr($PaymentSortBy ?? ''); ?>' />
603 <input id='Sort' name='Sort' type='hidden' value='<?php echo attr($Sort ?? ''); ?>' />
604 <input id="after_value" name="after_value" type="hidden" value="<?php echo attr($Message ?? ''); ?>" />
605 </div>
606 </form>
607 </div>
608 </div>
609 </div><!--end of container div-->
610 <?php $oemr_ui->oeBelowContainerDiv(); ?>
611 </body>
612 </html>