ongoing internationalization of date widget
[openemr.git] / interface / reports / pat_ledger.php
blob3e3a25f350a980e1a4b7adf4daee3747fa3b0920
1 <?php
2 /**
3 * This is a report to create a patient ledger of charges with payments
4 * applied.
6 * Copyright (C) 2015 Rich Genandt <rgenandt@gmail.com>
7 * Copyright (C) 2017 Brady Miller <brady.g.miller@gmail.com>
9 * LICENSE: This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
20 * @package OpenEMR
21 * @author WMT
22 * @author Terry Hill <terry@lillysystems.com>
23 * @author Brady Miller <brady.g.miller@gmail.com>
24 * @link http://www.open-emr.org
28 require_once('../globals.php');
29 require_once($GLOBALS['srcdir'].'/patient.inc');
30 require_once($GLOBALS['srcdir'].'/acl.inc');
31 require_once($GLOBALS['srcdir'].'/options.inc.php');
32 require_once($GLOBALS['srcdir'].'/appointments.inc.php');
34 use OpenEMR\Core\Header;
35 use OpenEMR\Services\FacilityService;
37 $facilityService = new FacilityService();
39 $enc_units = $total_units = 0;
40 $enc_chg = $total_chg = 0;
41 $enc_pmt = $total_pmt = 0;
42 $enc_adj = $total_adj = 0;
43 $enc_bal = $total_bal = 0;
44 $bgcolor = "#FFFFDD";
45 $orow = 0;
47 $pat_pid = $_GET['patient_id'];
48 $type_form = $_GET['form'];
50 if (! acl_check('acct', 'rep')) {
51 die(xlt("Unauthorized access."));
54 function GetAllUnapplied($pat = '', $from_dt = '', $to_dt = '')
56 $all = array();
57 if (!$pat) {
58 return($all);
61 $sql = "SELECT ar_session.*, ins.name, " .
62 "pat.lname, pat.fname, pat.mname, " .
63 "(SELECT SUM(ar_activity.pay_amount) FROM ar_activity WHERE " .
64 "ar_activity.session_id = ar_session.session_id) AS applied " .
65 "FROM ar_session " .
66 "LEFT JOIN insurance_companies AS ins on ar_session.payer_id = ins.id " .
67 "LEFT JOIN patient_data AS pat on ar_session.patient_id = pat.pid " .
68 "WHERE " .
69 "ar_session.created_time >= ? AND ar_session.created_time <= ? " .
70 "AND ar_session.patient_id=?";
71 $result = sqlStatement($sql, array($from_dt, $to_dt, $pat));
72 $iter = 0;
73 while ($row = sqlFetchArray($result)) {
74 $all[$iter] = $row;
75 $iter++;
78 return($all);
81 function User_Id_Look($thisField)
83 if (!$thisField) {
84 return '';
87 $ret = '';
88 $rlist= sqlStatement("SELECT lname, fname, mname FROM users WHERE id=?", array($thisField));
89 $rrow= sqlFetchArray($rlist);
90 if ($rrow) {
91 $ret = $rrow{'lname'}.', '.$rrow{'fname'}.' '.$rrow{'mname'};
94 return $ret;
97 function List_Look($thisData, $thisList)
99 if ($thisList == 'occurrence') {
100 if (!$thisData || $thisData == '') {
101 return xl('Unknown or N/A');
105 if ($thisData == '') {
106 return '';
109 $fres=sqlStatement("SELECT title FROM list_options WHERE list_id = ? ".
110 "AND option_id = ? AND activity = 1", array($thisList, $thisData));
111 if ($fres) {
112 $rret=sqlFetchArray($fres);
113 $dispValue= xl_list_label($rret{'title'});
114 if ($thisList == 'occurrence' && $dispValue == '') {
115 $dispValue = xl('Unknown or N/A');
117 } else {
118 $dispValue= xl('Not Found');
121 return $dispValue;
124 function GetAllCredits($enc = '', $pat = '')
126 $all = array();
127 if (!$enc || !$pat) {
128 return($all);
131 $sql = "SELECT activity.*, session.*, ins.name FROM ar_activity AS ".
132 "activity LEFT JOIN ar_session AS session USING (session_id) ".
133 "LEFT JOIN insurance_companies AS ins ON session.payer_id = ".
134 "ins.id WHERE encounter=? AND pid=? ".
135 "ORDER BY sequence_no";
136 $result = sqlStatement($sql, array($enc, $pat));
137 $iter = 0;
138 while ($row = sqlFetchArray($result)) {
139 $all[$iter] = $row;
140 $iter++;
143 return($all);
145 function PrintEncHeader($dt, $rsn, $dr)
147 global $bgcolor, $orow;
148 $bgcolor = (($bgcolor == "#FFFFDD") ? "#FFDDDD" : "#FFFFDD");
149 echo "<tr bgcolor='#FFFFFF'>";
150 if (strlen($rsn) > 50) {
151 $rsn = substr($rsn, 0, 50).'...';
154 echo "<td colspan='4'><span class='bold'>".xlt('Encounter Dt / Rsn'). ": </span><span class='detail'>".text(substr($dt, 0, 10))." / ".text($rsn)."</span></td>";
155 echo "<td colspan='5'><span class='bold'>" . xlt('Provider'). ": </span><span class='detail'>".text(User_Id_Look($dr))."</span></td>";
156 echo "</tr>\n";
157 $orow++;
159 function PrintEncFooter()
161 global $enc_units, $enc_chg, $enc_pmt, $enc_adj, $enc_bal;
162 echo "<tr bgcolor='#DDFFFF'>";
163 echo "<td colspan='3'>&nbsp;</td>";
164 echo "<td class='detail'>". xlt('Encounter Balance').":</td>";
165 echo "<td class='detail' style='text-align: center;'>".text($enc_units)."</td>";
166 echo "<td class='detail' style='text-align: center;'>".text(oeFormatMoney($enc_chg))."</td>";
167 echo "<td class='detail' style='text-align: right;'>".text(oeFormatMoney($enc_pmt))."</td>";
168 echo "<td class='detail' style='text-align: right;'>".text(oeFormatMoney($enc_adj))."</td>";
169 echo "<td class='detail' style='text-align: right;'>".text(oeFormatMoney($enc_bal))."</td>";
170 echo "</tr>\n";
172 function PrintCreditDetail($detail, $pat, $unassigned = false)
174 global $enc_pmt, $total_pmt, $enc_adj, $total_adj, $enc_bal, $total_bal;
175 global $bgcolor, $orow, $enc_units, $enc_chg;
176 foreach ($detail as $pmt) {
177 $uap_flag = false;
178 if ($unassigned) {
179 if (($pmt['pay_total'] - $pmt['applied']) == 0) {
180 if (!$GLOBALS['show_payment_history']) {
181 continue;
183 $uap_flag = true;
187 $bgcolor = (($bgcolor == "#FFFFDD") ? "#FFDDDD" : "#FFFFDD");
188 $print = "<tr bgcolor='" . attr($bgcolor) . "'>";
189 $print .= "<td class='detail'>&nbsp;</td>";
190 $method = List_Look($pmt['payment_method'], 'payment_method');
191 $desc = $pmt['description'];
192 $ref = $pmt['reference'];
193 if ($unassigned) {
194 $memo = List_Look($pmt['adjustment_code'], 'payment_adjustment_code');
195 } else {
196 $memo = $pmt['memo'];
199 $description = $method;
200 if ($ref) {
201 if ($description) {
202 $description .= ' - ';
205 $description .= $ref;
208 if ($desc) {
209 if ($description) {
210 $description .= ': ';
213 $description .= $desc;
216 if ($memo) {
217 if ($description) {
218 $description .= ' ';
221 $description .= '['.$memo.']';
223 if ($uap_flag === true) {
224 if ($description) {
225 $description .= ' ';
227 $description .= '{Pay History}';
229 $print .= "<td class='detail' colspan='2'>".
230 text($description)."&nbsp;</td>";
231 $payer = ($pmt['name'] == '') ? xl('Patient') : $pmt['name'];
232 if ($unassigned) {
233 $pmt_date = substr($pmt['post_to_date'], 0, 10);
234 } else {
235 $pmt_date = substr($pmt['post_time'], 0, 10);
238 $print .= "<td class='detail'>".
239 text($pmt_date)."&nbsp;/&nbsp;".text($payer)."</td>";
240 $type = List_Look($pmt['payment_type'], 'payment_type');
241 $print .= "<td class='detail'>".text($type)."&nbsp;</td>";
242 if ($unassigned) {
243 $pmt_amt = $pmt['pay_total'] - $pmt['applied'];
244 $uac_bal = $pmt_amt * -1;
245 $uac_appl = $pmt['applied'];
246 $uac_total = $pmt['pay_total'];
247 $pmt_amt = $pmt['pay_total'];
248 $total_pmt = $total_pmt - $uac_bal;
249 } else {
250 $uac_total = '';
251 $uac_bal = '';
252 $uac_appl = '';
253 $pmt_amt = $pmt['pay_amount'];
254 $adj_amt = $pmt['adj_amount'];
255 $enc_pmt = $enc_pmt + $pmt['pay_amount'];
256 $total_pmt = $total_pmt + $pmt['pay_amount'];
257 $enc_adj = $enc_adj + $pmt['adj_amount'];
258 $total_adj = $total_adj + $pmt['adj_amount'];
261 $print_pmt = '';
262 if ($pmt_amt != 0) {
263 $print_pmt = oeFormatMoney($pmt_amt);
266 $print_adj = '';
267 if ($adj_amt != 0) {
268 $print_adj = oeFormatMoney($adj_amt);
271 $print_appl = $uac_appl ? oeFormatMoney($uac_appl) : "";
272 $print_bal = $uac_bal ? oeFormatMoney($uac_bal) : "";
274 $print .= "<td class='detail' style='text-align: center;'>".text($print_appl)."&nbsp;</td>";
275 $print .= "<td class='detail' style='text-align: right;'>".text($print_pmt)."&nbsp;</td>";
276 $print .= "<td class='detail' style='text-align: right;'>".text($print_adj)."&nbsp;</td>";
277 $print .= "<td class='detail' style='text-align: right;'>".text($print_bal)."&nbsp;</td>";
278 $print .= "</tr>\n";
279 echo $print;
280 if ($pmt['follow_up_note'] != '') {
281 $bgcolor = (($bgcolor == "#FFFFDD") ? "#FFDDDD" : "#FFFFDD");
282 $print = "<tr bgcolor='". attr($bgcolor) ."'>";
283 $print .= "<td class='detail' colspan='2'>&nbsp;</td>";
284 $print .= "<td colspan='7'>". xlt('Follow Up Note') .": ";
285 $print .= text($pmt['follow_up_note']);
286 $print .= "</td></tr>\n";
287 echo $print;
290 if ($unassigned) {
291 $total_bal = $total_bal + $uac_bal;
292 } else {
293 $enc_bal = $enc_bal - $pmt_amt - $adj_amt;
294 $total_bal = $total_bal - $pmt_amt - $adj_amt;
297 $orow++;
300 $bgcolor = (($bgcolor == "#FFFFDD") ? "#FFDDDD" : "#FFFFDD");
302 if (!isset($_REQUEST['form_from_date'])) {
303 $_REQUEST['form_from_date'] = '';
306 if (!isset($_REQUEST['form_to_date'])) {
307 $_REQUEST['form_to_date'] = '';
310 if (!isset($_REQUEST['form_facility'])) {
311 $_REQUEST['form_facility'] = '';
314 if (!isset($_REQUEST['form_provider'])) {
315 $_REQUEST['form_provider'] = '';
318 if ($type_form=='0') {
319 if (!isset($_REQUEST['form_patient'])) {
320 $_REQUEST['form_patient'] = '';
323 if (!isset($_REQUEST['form_pid'])) {
324 $_REQUEST['form_pid'] = '';
326 } else {
327 if (!isset($_REQUEST['form_patient'])) {
328 $_REQUEST['form_patient'] = $pat_pid;
331 if (!isset($_REQUEST['form_pid'])) {
332 $_REQUEST['form_pid'] = $pat_pid;
336 if (!isset($_REQUEST['form_csvexport'])) {
337 $_REQUEST['form_csvexport'] = '';
340 if (!isset($_REQUEST['form_refresh'])) {
341 $_REQUEST['form_refresh'] = '';
344 if (!isset($_REQUEST['$form_dob'])) {
345 $_REQUEST['$form_dob'] = '';
348 if (substr($GLOBALS['ledger_begin_date'], 0, 1) == 'Y') {
349 $ledger_time = substr($GLOBALS['ledger_begin_date'], 1, 1);
350 $last_year = mktime(0, 0, 0, date('m'), date('d'), date('Y')-$ledger_time);
351 } elseif (substr($GLOBALS['ledger_begin_date'], 0, 1) == 'M') {
352 $ledger_time = substr($GLOBALS['ledger_begin_date'], 1, 1);
353 $last_year = mktime(0, 0, 0, date('m')-$ledger_time, date('d'), date('Y'));
354 } elseif (substr($GLOBALS['ledger_begin_date'], 0, 1) == 'D') {
355 $ledger_time = substr($GLOBALS['ledger_begin_date'], 1, 1);
356 $last_year = mktime(0, 0, 0, date('m'), date('d')-$ledger_time, date('Y'));
359 $form_from_date = date('Y-m-d', $last_year);
360 if ($_REQUEST['form_from_date']) {
361 $form_from_date = fixDate($_REQUEST['form_from_date'], $last_year);
364 $form_to_date = fixDate($_REQUEST['form_to_date'], date('Y-m-d'));
365 $form_facility = $_REQUEST['form_facility'];
366 $form_provider = $_REQUEST['form_provider'];
367 $form_patient = $_REQUEST['form_patient'];
368 $form_pid = $_REQUEST['form_pid'];
369 $form_dob = $_REQUEST['form_dob'];
371 if ($_REQUEST['form_csvexport']) {
372 header("Pragma: public");
373 header("Expires: 0");
374 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
375 header("Content-Type: application/force-download");
376 header("Content-Disposition: attachment; filename=svc_financial_report_".attr($form_from_date)."--".attr($form_to_date).".csv");
377 header("Content-Description: File Transfer");
378 } else {
380 <html>
381 <head>
383 <?php Header::setupHeader('datetime-picker'); ?>
384 <script type="text/javascript">
385 var mypcc = '<?php echo $GLOBALS['phone_country_code']; ?>';
386 var pt_name;
387 var pt_id;
388 function checkSubmit() {
389 var pat = document.forms[0].elements['form_patient'].value;
390 if(!pat || pat == 0) {
391 alert('<?php echo xls('A Patient Must Be Selected to Generate This Report') ?>');
392 return false;
394 document.forms[0].elements['form_refresh'].value = true;
395 document.forms[0].elements['form_csvexport'].value = '';
396 document.forms[0].submit();
398 function setpatient(pid, lname, fname, dob) {
399 document.forms[0].elements['form_patient'].value = lname + ', ' + fname;
400 document.forms[0].elements['form_pid'].value = pid;
401 document.forms[0].elements['form_dob'].value = dob;
403 function sel_patient() {
404 dlgopen('../main/calendar/find_patient_popup.php?pflag=0', '_blank', 500, 400);
406 </script>
408 <style type="text/css">
410 /* specifically include & exclude from printing */
411 @media print {
412 #report_parameters {
413 visibility: hidden;
414 display: none;
416 #report_parameters_daterange {
417 visibility: visible;
418 display: inline;
420 #report_results {
421 margin-top: 30px;
423 #report_header {
424 visibility: visible;
425 display: inline;
427 #title {
428 visibility: hidden;
429 display: none;
432 /* specifically exclude some from the screen */
433 @media screen {
434 #report_parameters_daterange {
435 visibility: hidden;
436 display: none;
438 #report_header {
439 visibility: hidden;
440 display: none;
442 #title {
443 visibility: visible;
444 display: inline;
447 </style>
449 <title><?php echo xlt('Patient Ledger by Date') ?></title>
451 <script language="JavaScript">
452 $(document).ready(function() {
453 var win = top.printLogSetup ? top : opener.top;
454 win.printLogSetup(document.getElementById('printbutton'));
456 $('.datepicker').datetimepicker({
457 <?php $datetimepicker_timepicker = false; ?>
458 <?php $datetimepicker_showseconds = false; ?>
459 <?php $datetimepicker_formatInput = false; ?>
460 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
461 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
464 </script>
466 </head>
467 <body class="body_top">
468 <?php if ($type_form == '0') { ?>
469 <span class='title' id='title'><?php echo xlt('Report'); ?> - <?php echo xlt('Patient Ledger by Date'); ?></span>
470 <?php } else { ?>
471 <span class='title' id='title'><?php echo xlt('Patient Ledger'); ?></span>
472 <?php } ?>
473 <form method='post' action='pat_ledger.php?form=<?php echo attr($type_form);?>&patient_id=<?php echo attr($form_pid);?>' id='theform'>
474 <div id="report_parameters">
475 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
476 <input type='hidden' name='form_csvexport' id='form_csvexport' value=''/>
477 <table>
478 <tr>
479 <?php if ($type_form == '1') { ?>
480 <td width='35%'>
481 <?php } else { ?>
482 <td width='70%'>
483 <?php } ?>
484 <div style='float:left'>
485 <table class='text'>
486 <tr>
487 <?php if ($type_form == '0') { ?>
488 <td class='control-label'>
489 <?php echo xlt('Facility'); ?>:
490 </td>
491 <td>
492 <?php dropdown_facility($form_facility, 'form_facility', true); ?>
493 </td>
494 <td class='control-label'><?php echo xlt('Provider'); ?>:</td>
495 <td><?php
496 $query = "SELECT id, lname, fname FROM users WHERE ".
497 "authorized=1 AND active!=0 ORDER BY lname, fname";
498 $ures = sqlStatement($query);
499 echo " <select name='form_provider' class='form-control'>\n";
500 echo " <option value=''>-- " . xlt('All') . " --\n";
501 while ($urow = sqlFetchArray($ures)) {
502 $provid = $urow['id'];
503 echo " <option value='" . attr($provid) ."'";
504 if ($provid == $_REQUEST['form_provider']) {
505 echo " selected";
508 echo ">" . text($urow['lname']) . ", " . text($urow['fname']) . "\n";
511 echo " </select>\n";
512 ?></td>
513 </tr><tr>
514 <?php } ?>
515 <td class='control-label'>
516 <?php echo xlt('From'); ?>:&nbsp;&nbsp;&nbsp;&nbsp;
517 </td>
518 <td>
519 <input type='text' class='datepicker form-control' name='form_from_date' id="form_from_date" size='10' value='<?php echo attr($form_from_date) ?>' title='yyyy-mm-dd'>
520 </td>
521 <td class='control-label' class='control-label'>
522 <?php echo xlt('To'); ?>:
523 </td>
524 <td>
525 <input type='text' class='datepicker form-control' name='form_to_date' id="form_to_date" size='10' value='<?php echo attr($form_to_date) ?>' title='yyyy-mm-dd'>
526 </td>
527 <?php if ($type_form == '0') { ?>
528 <td><span class='control-label'><?php echo xlt('Patient'); ?>:&nbsp;&nbsp;</span></td>
529 <td>
530 <input type='text' size='20' name='form_patient' class='form-control' style='width:100%;cursor:pointer;cursor:hand' id='form_patient' value='<?php echo attr($form_patient) ? attr($form_patient) : xla('Click To Select'); ?>' onclick='sel_patient()' title='<?php echo xla('Click to select patient'); ?>' />
531 <?php } else { ?>
532 <input type='hidden' name='form_patient' value='<?php echo attr($form_patient); ?>' />
533 <?php } ?>
534 <input type='hidden' name='form_pid' value='<?php echo attr($form_pid); ?>' />
535 <input type='hidden' name='form_dob' value='<?php echo attr($form_dob); ?>' />
537 </td>
538 </tr>
539 </table>
540 </div>
541 </td>
542 <td align='left' valign='middle' height="100%">
543 <table style='border-left:1px solid; width:100%; height:100%' >
544 <tr>
545 <td>
546 <div class="text-center">
547 <div class="btn-group" role="group">
548 <a href='#' class='btn btn-default btn-save' onclick="checkSubmit();" >
549 <?php echo xlt('Submit'); ?>
550 </a>
551 <?php if ($_REQUEST['form_refresh'] || $_REQUEST['form_csvexport']) { ?>
552 <a href='#' class='btn btn-default btn-print' id='printbutton'>
553 <?php echo xlt('Print Ledger'); ?>
554 </a>
555 <?php if ($type_form == '1') { ?>
556 <a href="../patient_file/summary/demographics.php" class="btn btn-default btn-transmit" onclick="top.restoreSession()">
557 <?php echo xlt('Back To Patient');?>
558 </a>
559 <?php } ?>
560 <?php } ?>
561 </div>
562 </div>
563 </td>
564 </tr>
565 </table>
566 </td>
567 </tr>
568 </table>
569 </div> <!-- end of parameters -->
571 <?php
572 } // end not export
573 $from_date = $form_from_date . ' 00:00:00';
574 $to_date = $form_to_date . ' 23:59:59';
575 if ($_REQUEST['form_refresh'] || $_REQUEST['form_csvexport']) {
576 $rows = array();
577 $sqlBindArray = array();
578 $query = "select b.code_type, b.code, b.code_text, b.pid, b.provider_id, ".
579 "b.billed, b.payer_id, b.units, b.fee, b.bill_date, b.id, ".
580 "ins.name, ".
581 "fe.encounter, fe.date, fe.reason, fe.provider_id ".
582 "FROM form_encounter AS fe ".
583 "LEFT JOIN billing AS b ON b.pid=fe.pid AND b.encounter=fe.encounter ".
584 "LEFT JOIN insurance_companies AS ins ON b.payer_id = ins.id ".
585 "LEFT OUTER JOIN code_types AS c ON c.ct_key = b.code_type ".
586 "WHERE fe.date >= ? AND fe.date <= ? AND fe.pid = ? ";
587 array_push($sqlBindArray, $from_date, $to_date, $form_pid);
588 if ($form_facility) {
589 $query .= "AND fe.facility_id = ? ";
590 array_push($sqlBindArray, $form_facility);
593 if ($form_provider) {
594 $query .= "AND b.provider_id = ? ";
595 array_push($sqlBindArray, $form_provider);
598 $query .= "AND c.ct_proc = '1' ";
599 $query .= "AND activity > 0 ORDER BY fe.date, fe.id ";
600 $res = sqlStatement($query, $sqlBindArray);
602 if ($_REQUEST['form_csvexport']) {
603 // CSV headers:
604 if (true) {
605 echo '"Code/Enc Dt",';
606 echo '"Description",';
607 echo '"Billed/Who",';
608 echo '"Type/Units",';
609 echo '"Chg/Pmt Amount",'."\n";
611 } else {
612 if (!$form_facility) {
613 $form_facility = '3';
616 $facility = $facilityService->getById($form_facility);
617 $patient = sqlQuery("SELECT * from patient_data WHERE pid=?", array($form_patient));
618 $pat_dob = $patient['DOB'];
619 $pat_name = $patient['fname']. ' ' . $patient['lname'];
621 <div id="report_header">
622 <table width="98%" border="0" cellspacing="0" cellpadding="0">
623 <tr>
624 <td class="title" ><?php echo text($facility{'name'}); ?></td>
625 </tr>
626 <tr>
627 <td class="title" ><?php echo text($facility{'street'}); ?></td>
628 </tr>
629 <tr>
630 <td class="title" ><?php echo text($facility{'city'}).", ".text($facility{'state'})." ".text($facility{'postal_code'}); ?></td>
631 </tr>
632 <tr>
633 <td class="title" ><?php echo xlt('Phone').': ' .text($facility{'phone'}); ?></td>
634 </tr>
635 <tr>
636 <td class="title" ><?php echo xlt('Tax Id').': ' .text($facility{'federal_ein'}); ?></td>
637 </tr>
638 <tr><td>&nbsp;</td></tr>
639 <tr>
640 <td class="title" ><?php echo xlt('Patient Ledger'); ?></td>
641 </tr>
642 <tr>
643 <?php
644 $title = xl('All Providers');
645 if ($form_provider) {
646 $title = xl('For Provider') . ': '.User_Id_Look($form_provider);
649 <td class="title" ><?php echo text($title); ?></td>
650 </tr>
651 <tr>
652 <?php
653 $title = xl('For Dates') . ': '.$form_from_date.' - '.$form_to_date;
655 <td class="title" ><?php echo text($title); ?></td>
656 </tr>
657 </table>
658 <br/>
659 <table width="100%" border="0" cellspacing="0" cellpadding="0">
660 <tr>
661 <td class='bold' ><?php echo xlt('Date')?>:
662 <?php echo text(date('Y-m-d')); ?></td>
663 <td class='bold' ><?php echo xlt('Patient')?>:
664 <?php if ($type_form == '1') { ?>
665 <?php echo text($pat_name); ?></td>
666 <?php } else { ?>
667 <?php echo text($form_patient); ?></td>
668 <?php } ?>
669 <td class='bold' ><?php echo xlt('DOB')?>:
670 <?php if ($type_form == '1') { ?>
671 <?php echo text($pat_dob);?></td>
672 <?php } else { ?>
673 <?php echo text($form_dob); ?></td>
674 <?php } ?>
675 <td class='bold' > <?php echo xlt('ID')?>:
676 <?php echo text($form_pid);?></td>
677 </tr>
678 </table>
679 </div>
680 <div id="report_results">
681 <table >
682 <tr>
683 <td class='bold' ><?php echo xlt('Code'); ?></td>
684 <td colspan="2" class='bold' ><?php echo xlt('Description'); ?></td>
685 <td class='bold' ><?php echo xlt('Billed Date'); ?> / <?php echo xlt('Payor'); ?></td>
686 <td class='bold' ><?php echo xlt('Type'); ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
687 <?php echo xlt('Units'); ?></td>
688 <td class='bold' >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo xlt('Charge'); ?></td>
689 <td align='right' class='bold' >&nbsp;&nbsp;<?php echo xlt('Payment'); ?></td>
690 <td align='right' class='bold' >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo xlt('Adjustment'); ?></td>
691 <td align='right' class='bold' >&nbsp;&nbsp;&nbsp;<?php echo xlt('Balance'); ?></td>
692 </tr>
693 <tr>
694 <td>&nbsp;&nbsp;&nbsp;</td>
695 <td colspan="2" >&nbsp;&nbsp;&nbsp;</td>
696 <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
697 <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
698 &nbsp;&nbsp;&nbsp;</td>
699 <td class='bold' >&nbsp;&nbsp;&nbsp;<?php echo xlt('UAC Appl'); ?></td>
700 <td align='right' class='bold' >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo xlt('UAC Tot'); ?></td>
701 <td>&nbsp;</td>
702 <td>&nbsp;</td>
703 </tr>
704 <?php
707 $orow = 0;
708 $prev_encounter_id = -1;
709 $hdr_printed = false;
710 $prev_row = array();
711 while ($erow = sqlFetchArray($res)) {
712 $print = '';
713 $csv = '';
714 if ($erow['encounter'] != $prev_encounter_id) {
715 if ($prev_encounter_id != -1) {
716 $credits = GetAllCredits($prev_encounter_id, $form_pid);
717 if (count($credits) > 0) {
718 if (!$hdr_printed) {
719 PrintEncHeader(
720 $prev_row{'date'},
721 $prev_row{'reason'},
722 $prev_row{'provider_id'}
726 PrintCreditDetail($credits, $form_pid);
729 if ($hdr_printed) {
730 PrintEncFooter();
733 $hdr_printed = false;
736 $enc_units = $enc_chg = $enc_pmt = $enc_adj = $enc_bal = 0;
739 if ($erow{'id'}) {
740 // Now print an encounter heading line -
741 if (!$hdr_printed) {
742 PrintEncHeader(
743 $erow{'date'},
744 $erow{'reason'},
745 $erow{'provider_id'}
747 $hdr_printed = true;
750 $code_desc = $erow['code_text'];
751 if (strlen($code_desc) > 50) {
752 $code_desc = substr($code_desc, 0, 50).'...';
755 $bgcolor = (($bgcolor == "#FFFFDD") ? "#FFDDDD" : "#FFFFDD");
756 $print = "<tr bgcolor='". attr($bgcolor) ."'>";
757 $print .= "<td class='detail'>".text($erow['code'])."</td>";
758 $print .= "<td class='detail' colspan='2'>".text($code_desc)."</td>";
759 $who = ($erow['name'] == '') ? xl('Self') : $erow['name'];
760 $bill = substr($erow['bill_date'], 0, 10);
761 if ($bill == '') {
762 $bill = 'unbilled';
765 $print .= "<td class='detail'>".text($bill)."&nbsp;/&nbsp;".text($who)."</td>";
766 $print .= "<td class='detail' style='text-align: center;'>". text($erow['units'])."</td>";
767 $print .= "<td class='detail' style='text-align: center;'>". text(oeFormatMoney($erow['fee']))."</td>";
768 $print .= "<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>";
769 $print .= "</tr>\n";
771 $total_units += $erow['units'];
772 $total_chg += $erow['fee'];
773 $total_bal += $erow['fee'];
774 $enc_units += $erow['units'];
775 $enc_chg += $erow['fee'];
776 $enc_bal += $erow['fee'];
777 $orow++;
779 if ($_REQUEST['form_csvexport']) {
780 echo $csv;
781 } else {
782 echo $print;
786 $prev_encounter_id = $erow{'encounter'};
787 $prev_row = $erow;
790 if ($prev_encounter_id != -1) {
791 $credits = GetAllCredits($prev_encounter_id, $form_pid);
792 if (count($credits) > 0) {
793 if (!$hdr_printed) {
794 PrintEncHeader(
795 $prev_row{'date'},
796 $prev_row{'reason'},
797 $prev_row{'provider_id'}
801 PrintCreditDetail($credits, $form_pid);
804 if ($hdr_printed) {
805 PrintEncFooter();
809 // This is the end of the encounter/charge loop -
810 $uac = GetAllUnapplied($form_pid, $from_date, $to_date);
811 if (count($uac) > 0) {
812 if ($orow) {
813 $bgcolor = (($bgcolor == "#FFFFDD") ? "#FFDDDD" : "#FFFFDD");
814 echo "<tr bgcolor='#FFFFFF'><td colspan='9'>&nbsp;</td></tr>\n";
817 PrintCreditDetail($uac, $form_pid, true);
820 if (!$_REQUEST['form_csvexport'] && $orow) {
821 echo "<tr bgcolor='#DDFFFF'>\n";
822 echo " <td colspan='2'>&nbsp;</td>";
823 echo " <td class='bold' colspan='2'>" . xlt("Grand Total") ."</td>\n";
824 echo " <td class='bold' style='text-align: center;'>". text($total_units) ."</td>\n";
825 echo " <td class='bold' style='text-align: center;'>". text(oeFormatMoney($total_chg)) ."</td>\n";
826 echo " <td class='bold' style='text-align: right;'>". text(oeFormatMoney($total_pmt)) ."</td>\n";
827 echo " <td class='bold' style='text-align: right;'>". text(oeFormatMoney($total_adj)) ."</td>\n";
828 echo " <td class='bold' style='text-align: right;'>". text(oeFormatMoney($total_bal)) . "</td>\n";
829 echo " </tr>\n";
831 </table>
832 <tr><td>&nbsp;</td></tr><br><br>
833 <?php if ($GLOBALS['print_next_appointment_on_ledger'] == 1) {
834 $next_day = mktime(0, 0, 0, date('m'), date('d')+1, date('Y'));
835 # add one day to date so it will not get todays appointment
836 $current_date2 = date('Y-m-d', $next_day);
837 $events = fetchNextXAppts($current_date2, $form_pid);
838 $next_appoint_date = oeFormatShortDate($events[0]['pc_eventDate']);
839 $next_appoint_time = substr($events[0]['pc_startTime'], 0, 5);
840 if (strlen(umname) != 0) {
841 $next_appoint_provider = $events[0]['ufname'] . ' ' . $events[0]['umname'] . ' ' . $events[0]['ulname'];
842 } else {
843 $next_appoint_provider = $events[0]['ufname'] . ' ' . $events[0]['ulname'];
846 if (strlen($next_appoint_time) != 0) {
848 <tr>
849 <td class="title" ><?php echo xlt('Next Appointment Date') . ': ' . text($next_appoint_date) . ' ' . xlt('Time') . ' ' . text($next_appoint_time) . ' ' . xlt('Provider') . ' ' . text($next_appoint_provider); ?></td>
850 </tr>
852 <?php
854 } // end ($GLOBALS['print_next_appointment_on_ledger'] == 1)
855 } // end (!$_REQUEST['form_csvexport'] && $orow)
856 echo "</div>\n";
859 if (! $_REQUEST['form_csvexport']) {
860 if ($_REQUEST['form_refresh'] && $orow <= 0) {
861 echo "<span style='font-size:10pt;'>";
862 echo xlt('No matches found. Try search again.');
863 echo "</span>";
864 echo '<script>document.getElementById("report_results").style.display="none";</script>';
865 echo '<script>document.getElementById("controls").style.display="none";</script>';
868 if (!$_REQUEST['form_refresh'] && !$_REQUEST['form_csvexport']) { ?>
869 <div class='text'>
870 <?php echo xlt('Please input search criteria above, and click Submit to view results.'); ?>
871 </div><?php
872 } ?>
873 </form>
874 </body>
876 </html>
877 <?php
878 } // End not csv export