3 * This is a report to create a patient ledger of charges with payments
7 * @link http://www.open-emr.org
9 * @author Terry Hill <terry@lillysystems.com>
10 * @author Brady Miller <brady.g.miller@gmail.com>
11 * @copyright Copyright (c) 2015 Rich Genandt <rgenandt@gmail.com>
12 * @copyright Copyright (c) 2017-2018 Brady Miller <brady.g.miller@gmail.com>
13 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
16 require_once('../globals.php');
17 require_once($GLOBALS['srcdir'].'/patient.inc');
18 require_once($GLOBALS['srcdir'].'/acl.inc');
19 require_once($GLOBALS['srcdir'].'/options.inc.php');
20 require_once($GLOBALS['srcdir'].'/appointments.inc.php');
22 use OpenEMR\Core\Header
;
23 use OpenEMR\Services\FacilityService
;
25 $facilityService = new FacilityService();
27 $enc_units = $total_units = 0;
28 $enc_chg = $total_chg = 0;
29 $enc_pmt = $total_pmt = 0;
30 $enc_adj = $total_adj = 0;
31 $enc_bal = $total_bal = 0;
35 $pat_pid = $_GET['patient_id'];
36 $type_form = $_GET['form'];
38 if (! acl_check('acct', 'rep')) {
39 die(xlt("Unauthorized access."));
42 function GetAllUnapplied($pat = '', $from_dt = '', $to_dt = '')
49 $sql = "SELECT ar_session.*, ins.name, " .
50 "pat.lname, pat.fname, pat.mname, " .
51 "(SELECT SUM(ar_activity.pay_amount) FROM ar_activity WHERE " .
52 "ar_activity.session_id = ar_session.session_id) AS applied " .
54 "LEFT JOIN insurance_companies AS ins on ar_session.payer_id = ins.id " .
55 "LEFT JOIN patient_data AS pat on ar_session.patient_id = pat.pid " .
57 "ar_session.created_time >= ? AND ar_session.created_time <= ? " .
58 "AND ar_session.patient_id=?";
59 $result = sqlStatement($sql, array($from_dt, $to_dt, $pat));
61 while ($row = sqlFetchArray($result)) {
69 function User_Id_Look($thisField)
76 $rlist= sqlStatement("SELECT lname, fname, mname FROM users WHERE id=?", array($thisField));
77 $rrow= sqlFetchArray($rlist);
79 $ret = $rrow{'lname'}.', '.$rrow{'fname'}.' '.$rrow{'mname'};
85 function List_Look($thisData, $thisList)
87 if ($thisList == 'occurrence') {
88 if (!$thisData ||
$thisData == '') {
89 return xl('Unknown or N/A');
93 if ($thisData == '') {
97 $fres=sqlStatement("SELECT title FROM list_options WHERE list_id = ? ".
98 "AND option_id = ? AND activity = 1", array($thisList, $thisData));
100 $rret=sqlFetchArray($fres);
101 $dispValue= xl_list_label($rret{'title'});
102 if ($thisList == 'occurrence' && $dispValue == '') {
103 $dispValue = xl('Unknown or N/A');
106 $dispValue= xl('Not Found');
112 function GetAllCredits($enc = '', $pat = '')
115 if (!$enc ||
!$pat) {
119 $sql = "SELECT activity.*, session.*, ins.name FROM ar_activity AS ".
120 "activity LEFT JOIN ar_session AS session USING (session_id) ".
121 "LEFT JOIN insurance_companies AS ins ON session.payer_id = ".
122 "ins.id WHERE encounter=? AND pid=? ".
123 "ORDER BY sequence_no";
124 $result = sqlStatement($sql, array($enc, $pat));
126 while ($row = sqlFetchArray($result)) {
133 function PrintEncHeader($dt, $rsn, $dr)
135 global $bgcolor, $orow;
136 $bgcolor = (($bgcolor == "#FFFFDD") ?
"#FFDDDD" : "#FFFFDD");
137 echo "<tr bgcolor='#FFFFFF'>";
138 if (strlen($rsn) > 50) {
139 $rsn = substr($rsn, 0, 50).'...';
142 echo "<td colspan='4'><span class='bold'>".xlt('Encounter Dt / Rsn'). ": </span><span class='detail'>".text(substr($dt, 0, 10))." / ".text($rsn)."</span></td>";
143 echo "<td colspan='5'><span class='bold'>" . xlt('Provider'). ": </span><span class='detail'>".text(User_Id_Look($dr))."</span></td>";
147 function PrintEncFooter()
149 global $enc_units, $enc_chg, $enc_pmt, $enc_adj, $enc_bal;
150 echo "<tr bgcolor='#DDFFFF'>";
151 echo "<td colspan='3'> </td>";
152 echo "<td class='detail'>". xlt('Encounter Balance').":</td>";
153 echo "<td class='detail' style='text-align: center;'>".text($enc_units)."</td>";
154 echo "<td class='detail' style='text-align: center;'>".text(oeFormatMoney($enc_chg))."</td>";
155 echo "<td class='detail' style='text-align: right;'>".text(oeFormatMoney($enc_pmt))."</td>";
156 echo "<td class='detail' style='text-align: right;'>".text(oeFormatMoney($enc_adj))."</td>";
157 echo "<td class='detail' style='text-align: right;'>".text(oeFormatMoney($enc_bal))."</td>";
160 function PrintCreditDetail($detail, $pat, $unassigned = false)
162 global $enc_pmt, $total_pmt, $enc_adj, $total_adj, $enc_bal, $total_bal;
163 global $bgcolor, $orow, $enc_units, $enc_chg;
164 foreach ($detail as $pmt) {
167 if (($pmt['pay_total'] - $pmt['applied']) == 0) {
168 if (!$GLOBALS['show_payment_history']) {
175 $bgcolor = (($bgcolor == "#FFFFDD") ?
"#FFDDDD" : "#FFFFDD");
176 $print = "<tr bgcolor='" . attr($bgcolor) . "'>";
177 $print .= "<td class='detail'> </td>";
178 $method = List_Look($pmt['payment_method'], 'payment_method');
179 $desc = $pmt['description'];
180 $ref = $pmt['reference'];
182 $memo = List_Look($pmt['adjustment_code'], 'payment_adjustment_code');
184 $memo = $pmt['memo'];
187 $description = $method;
190 $description .= ' - ';
193 $description .= $ref;
198 $description .= ': ';
201 $description .= $desc;
209 $description .= '['.$memo.']';
211 if ($uap_flag === true) {
215 $description .= '{Pay History}';
217 $print .= "<td class='detail' colspan='2'>".
218 text($description)." </td>";
219 $payer = ($pmt['name'] == '') ?
xl('Patient') : $pmt['name'];
221 $pmt_date = substr($pmt['post_to_date'], 0, 10);
223 $pmt_date = substr($pmt['post_time'], 0, 10);
226 $print .= "<td class='detail'>".
227 text($pmt_date)." / ".text($payer)."</td>";
228 $type = List_Look($pmt['payment_type'], 'payment_type');
229 $print .= "<td class='detail'>".text($type)." </td>";
231 $pmt_amt = $pmt['pay_total'] - $pmt['applied'];
232 $uac_bal = $pmt_amt * -1;
233 $uac_appl = $pmt['applied'];
234 $uac_total = $pmt['pay_total'];
235 $pmt_amt = $pmt['pay_total'];
236 $total_pmt = $total_pmt - $uac_bal;
241 $pmt_amt = $pmt['pay_amount'];
242 $adj_amt = $pmt['adj_amount'];
243 $enc_pmt = $enc_pmt +
$pmt['pay_amount'];
244 $total_pmt = $total_pmt +
$pmt['pay_amount'];
245 $enc_adj = $enc_adj +
$pmt['adj_amount'];
246 $total_adj = $total_adj +
$pmt['adj_amount'];
251 $print_pmt = oeFormatMoney($pmt_amt);
256 $print_adj = oeFormatMoney($adj_amt);
259 $print_appl = $uac_appl ?
oeFormatMoney($uac_appl) : "";
260 $print_bal = $uac_bal ?
oeFormatMoney($uac_bal) : "";
262 $print .= "<td class='detail' style='text-align: center;'>".text($print_appl)." </td>";
263 $print .= "<td class='detail' style='text-align: right;'>".text($print_pmt)." </td>";
264 $print .= "<td class='detail' style='text-align: right;'>".text($print_adj)." </td>";
265 $print .= "<td class='detail' style='text-align: right;'>".text($print_bal)." </td>";
268 if ($pmt['follow_up_note'] != '') {
269 $bgcolor = (($bgcolor == "#FFFFDD") ?
"#FFDDDD" : "#FFFFDD");
270 $print = "<tr bgcolor='". attr($bgcolor) ."'>";
271 $print .= "<td class='detail' colspan='2'> </td>";
272 $print .= "<td colspan='7'>". xlt('Follow Up Note') .": ";
273 $print .= text($pmt['follow_up_note']);
274 $print .= "</td></tr>\n";
279 $total_bal = $total_bal +
$uac_bal;
281 $enc_bal = $enc_bal - $pmt_amt - $adj_amt;
282 $total_bal = $total_bal - $pmt_amt - $adj_amt;
288 $bgcolor = (($bgcolor == "#FFFFDD") ?
"#FFDDDD" : "#FFFFDD");
291 if (!isset($_REQUEST['form_facility'])) {
292 $_REQUEST['form_facility'] = '';
295 if (!isset($_REQUEST['form_provider'])) {
296 $_REQUEST['form_provider'] = '';
299 if ($type_form=='0') {
300 if (!isset($_REQUEST['form_patient'])) {
301 $_REQUEST['form_patient'] = '';
304 if (!isset($_REQUEST['form_pid'])) {
305 $_REQUEST['form_pid'] = '';
308 if (!isset($_REQUEST['form_patient'])) {
309 $_REQUEST['form_patient'] = $pat_pid;
312 if (!isset($_REQUEST['form_pid'])) {
313 $_REQUEST['form_pid'] = $pat_pid;
317 if (!isset($_REQUEST['form_csvexport'])) {
318 $_REQUEST['form_csvexport'] = '';
321 if (!isset($_REQUEST['form_refresh'])) {
322 $_REQUEST['form_refresh'] = '';
325 if (!isset($_REQUEST['$form_dob'])) {
326 $_REQUEST['$form_dob'] = '';
329 if (substr($GLOBALS['ledger_begin_date'], 0, 1) == 'Y') {
330 $ledger_time = substr($GLOBALS['ledger_begin_date'], 1, 1);
331 $last_year = mktime(0, 0, 0, date('m'), date('d'), date('Y')-$ledger_time);
332 } elseif (substr($GLOBALS['ledger_begin_date'], 0, 1) == 'M') {
333 $ledger_time = substr($GLOBALS['ledger_begin_date'], 1, 1);
334 $last_year = mktime(0, 0, 0, date('m')-$ledger_time, date('d'), date('Y'));
335 } elseif (substr($GLOBALS['ledger_begin_date'], 0, 1) == 'D') {
336 $ledger_time = substr($GLOBALS['ledger_begin_date'], 1, 1);
337 $last_year = mktime(0, 0, 0, date('m'), date('d')-$ledger_time, date('Y'));
340 $form_from_date = date('Y-m-d', $last_year);
341 if ($_REQUEST['form_from_date']) {
342 $form_from_date = DateToYYYYMMDD($_POST['form_from_date']);
345 $form_to_date = (!empty($_POST['form_to_date'])) ?
DateToYYYYMMDD($_POST['form_to_date']) : date('Y-m-d');
346 $form_facility = $_REQUEST['form_facility'];
347 $form_provider = $_REQUEST['form_provider'];
348 $form_patient = $_REQUEST['form_patient'];
349 $form_pid = $_REQUEST['form_pid'];
350 $form_dob = $_REQUEST['form_dob'];
352 if ($_REQUEST['form_csvexport']) {
353 header("Pragma: public");
354 header("Expires: 0");
355 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
356 header("Content-Type: application/force-download");
357 header("Content-Disposition: attachment; filename=svc_financial_report_".attr($form_from_date)."--".attr($form_to_date).".csv");
358 header("Content-Description: File Transfer");
364 <title
><?php
echo xlt('Patient Ledger by Date'); ?
></title
>
366 <?php Header
::setupHeader('datetime-picker'); ?
>
368 <script type
="text/javascript">
371 function checkSubmit() {
372 var pat
= document
.forms
[0].elements
['form_patient'].value
;
373 if(!pat || pat
== 0) {
374 alert('<?php echo xls('A Patient Must Be Selected to Generate This Report
') ?>');
377 document
.forms
[0].elements
['form_refresh'].value
= true;
378 document
.forms
[0].elements
['form_csvexport'].value
= '';
379 document
.forms
[0].submit();
381 function setpatient(pid
, lname
, fname
, dob
) {
382 document
.forms
[0].elements
['form_patient'].value
= lname +
', ' + fname
;
383 document
.forms
[0].elements
['form_pid'].value
= pid
;
384 document
.forms
[0].elements
['form_dob'].value
= dob
;
386 function sel_patient() {
387 dlgopen('../main/calendar/find_patient_popup.php?pflag=0', '_blank', 500, 400);
391 <style type
="text/css">
392 /* specifically include & exclude from printing */
398 #report_parameters_daterange {
414 /* specifically exclude some from the screen */
416 #report_parameters_daterange {
431 <script language
="JavaScript">
432 $
(document
).ready(function() {
433 var win
= top
.printLogSetup ? top
: opener
.top
;
434 win
.printLogSetup(document
.getElementById('printbutton'));
436 $
('.datepicker').datetimepicker({
437 <?php
$datetimepicker_timepicker = false; ?
>
438 <?php
$datetimepicker_showseconds = false; ?
>
439 <?php
$datetimepicker_formatInput = true; ?
>
440 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
441 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
446 <body
class="body_top">
447 <?php
if ($type_form == '0') { ?
>
448 <span
class='title' id
='title'><?php
echo xlt('Report'); ?
> - <?php
echo xlt('Patient Ledger by Date'); ?
></span
>
450 <span
class='title' id
='title'><?php
echo xlt('Patient Ledger'); ?
></span
>
452 <form method
='post' action
='pat_ledger.php?form=<?php echo attr($type_form);?>&patient_id=<?php echo attr($form_pid);?>' id
='theform' onsubmit
='return top.restoreSession()'>
453 <div id
="report_parameters">
454 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
455 <input type
='hidden' name
='form_csvexport' id
='form_csvexport' value
=''/>
458 <?php
if ($type_form == '1') { ?
>
463 <div style
='float:left'>
466 <?php
if ($type_form == '0') { ?
>
467 <td
class='control-label'>
468 <?php
echo xlt('Facility'); ?
>:
471 <?php
dropdown_facility($form_facility, 'form_facility', true); ?
>
473 <td
class='control-label'><?php
echo xlt('Provider'); ?
>:</td
>
475 $query = "SELECT id, lname, fname FROM users WHERE ".
476 "authorized=1 AND active!=0 ORDER BY lname, fname";
477 $ures = sqlStatement($query);
478 echo " <select name='form_provider' class='form-control'>\n";
479 echo " <option value=''>-- " . xlt('All') . " --\n";
480 while ($urow = sqlFetchArray($ures)) {
481 $provid = $urow['id'];
482 echo " <option value='" . attr($provid) ."'";
483 if ($provid == $_REQUEST['form_provider']) {
487 echo ">" . text($urow['lname']) . ", " . text($urow['fname']) . "\n";
494 <td
class='control-label'>
495 <?php
echo xlt('From'); ?
>: 
; 
; 
; 
;
498 <input type
='text' class='datepicker form-control' name
='form_from_date' id
="form_from_date" size
='10' value
='<?php echo attr(oeFormatShortDate($form_from_date)); ?>'>
500 <td
class='control-label' class='control-label'>
501 <?php
echo xlt('To'); ?
>:
504 <input type
='text' class='datepicker form-control' name
='form_to_date' id
="form_to_date" size
='10' value
='<?php echo attr(oeFormatShortDate($form_to_date)); ?>'>
506 <?php
if ($type_form == '0') { ?
>
507 <td
><span
class='control-label'><?php
echo xlt('Patient'); ?
>: 
; 
;</span
></td
>
509 <input type
='text' size
='20' name
='form_patient' class='form-control' style
='width:100%;cursor:pointer;cursor:hand' id
='form_patient' value
='<?php echo ($form_patient) ? attr($form_patient) : xla('Click To Select
'); ?>' onclick
='sel_patient()' title
='<?php echo xla('Click to select patient
'); ?>' />
511 <input type
='hidden' name
='form_patient' value
='<?php echo attr($form_patient); ?>' />
513 <input type
='hidden' name
='form_pid' value
='<?php echo attr($form_pid); ?>' />
514 <input type
='hidden' name
='form_dob' value
='<?php echo attr($form_dob); ?>' />
521 <td align
='left' valign
='middle' height
="100%">
522 <table style
='border-left:1px solid; width:100%; height:100%' >
525 <div
class="text-center">
526 <div
class="btn-group" role
="group">
527 <a href
='#' class='btn btn-default btn-save' onclick
="checkSubmit();" >
528 <?php
echo xlt('Submit'); ?
>
530 <?php
if ($_REQUEST['form_refresh'] ||
$_REQUEST['form_csvexport']) { ?
>
531 <a href
='#' class='btn btn-default btn-print' id
='printbutton'>
532 <?php
echo xlt('Print Ledger'); ?
>
534 <?php
if ($type_form == '1') { ?
>
535 <a href
="../patient_file/summary/demographics.php" class="btn btn-default btn-transmit" onclick
="top.restoreSession()">
536 <?php
echo xlt('Back To Patient');?
>
548 </div
> <!-- end of parameters
-->
552 $from_date = $form_from_date . ' 00:00:00';
553 $to_date = $form_to_date . ' 23:59:59';
554 if ($_REQUEST['form_refresh'] ||
$_REQUEST['form_csvexport']) {
556 $sqlBindArray = array();
557 $query = "select b.code_type, b.code, b.code_text, b.pid, b.provider_id, ".
558 "b.billed, b.payer_id, b.units, b.fee, b.bill_date, b.id, ".
560 "fe.encounter, fe.date, fe.reason, fe.provider_id ".
561 "FROM form_encounter AS fe ".
562 "LEFT JOIN billing AS b ON b.pid=fe.pid AND b.encounter=fe.encounter ".
563 "LEFT JOIN insurance_companies AS ins ON b.payer_id = ins.id ".
564 "LEFT OUTER JOIN code_types AS c ON c.ct_key = b.code_type ".
565 "WHERE fe.date >= ? AND fe.date <= ? AND fe.pid = ? ";
566 array_push($sqlBindArray, $from_date, $to_date, $form_pid);
567 if ($form_facility) {
568 $query .= "AND fe.facility_id = ? ";
569 array_push($sqlBindArray, $form_facility);
572 if ($form_provider) {
573 $query .= "AND b.provider_id = ? ";
574 array_push($sqlBindArray, $form_provider);
577 $query .= "AND c.ct_proc = '1' ";
578 $query .= "AND activity > 0 ORDER BY fe.date, fe.id ";
579 $res = sqlStatement($query, $sqlBindArray);
581 if ($_REQUEST['form_csvexport']) {
584 echo '"Code/Enc Dt",';
585 echo '"Description",';
586 echo '"Billed/Who",';
587 echo '"Type/Units",';
588 echo '"Chg/Pmt Amount",'."\n";
591 if (!$form_facility) {
592 $form_facility = '3';
595 $facility = $facilityService->getById($form_facility);
596 $patient = sqlQuery("SELECT * from patient_data WHERE pid=?", array($form_patient));
597 $pat_dob = $patient['DOB'];
598 $pat_name = $patient['fname']. ' ' . $patient['lname'];
600 <div id
="report_header">
601 <table width
="98%" border
="0" cellspacing
="0" cellpadding
="0">
603 <td
class="title" ><?php
echo text($facility{'name'}); ?
></td
>
606 <td
class="title" ><?php
echo text($facility{'street'}); ?
></td
>
609 <td
class="title" ><?php
echo text($facility{'city'}).", ".text($facility{'state'})." ".text($facility{'postal_code'}); ?
></td
>
612 <td
class="title" ><?php
echo xlt('Phone').': ' .text($facility{'phone'}); ?
></td
>
615 <td
class="title" ><?php
echo xlt('Tax Id').': ' .text($facility{'federal_ein'}); ?
></td
>
617 <tr
><td
> 
;</td
></tr
>
619 <td
class="title" ><?php
echo xlt('Patient Ledger'); ?
></td
>
623 $title = xl('All Providers');
624 if ($form_provider) {
625 $title = xl('For Provider') . ': '.User_Id_Look($form_provider);
628 <td
class="title" ><?php
echo text($title); ?
></td
>
632 $title = xl('For Dates') . ': ' . oeFormatShortDate($form_from_date) . ' - ' . oeFormatShortDate($form_to_date);
634 <td
class="title" ><?php
echo text($title); ?
></td
>
638 <table width
="100%" border
="0" cellspacing
="0" cellpadding
="0">
640 <td
class='bold' ><?php
echo xlt('Date')?
>:
641 <?php
echo text(date('Y-m-d')); ?
></td
>
642 <td
class='bold' ><?php
echo xlt('Patient')?
>:
643 <?php
if ($type_form == '1') { ?
>
644 <?php
echo text($pat_name); ?
></td
>
646 <?php
echo text($form_patient); ?
></td
>
648 <td
class='bold' ><?php
echo xlt('DOB')?
>:
649 <?php
if ($type_form == '1') { ?
>
650 <?php
echo text($pat_dob);?
></td
>
652 <?php
echo text($form_dob); ?
></td
>
654 <td
class='bold' > <?php
echo xlt('ID')?
>:
655 <?php
echo text($form_pid);?
></td
>
659 <div id
="report_results">
662 <td
class='bold' ><?php
echo xlt('Code'); ?
></td
>
663 <td colspan
="2" class='bold' ><?php
echo xlt('Description'); ?
></td
>
664 <td
class='bold' ><?php
echo xlt('Billed Date'); ?
> / <?php
echo xlt('Payor'); ?
></td
>
665 <td
class='bold' ><?php
echo xlt('Type'); ?
> 
; 
; 
; 
; 
; 
; 
;
666 <?php
echo xlt('Units'); ?
></td
>
667 <td
class='bold' > 
; 
; 
; 
; 
;<?php
echo xlt('Charge'); ?
></td
>
668 <td align
='right' class='bold' > 
; 
;<?php
echo xlt('Payment'); ?
></td
>
669 <td align
='right' class='bold' > 
; 
; 
; 
; 
;<?php
echo xlt('Adjustment'); ?
></td
>
670 <td align
='right' class='bold' > 
; 
; 
;<?php
echo xlt('Balance'); ?
></td
>
673 <td
> 
; 
; 
;</td
>
674 <td colspan
="2" > 
; 
; 
;</td
>
675 <td
> 
; 
; 
; 
; 
; 
;</td
>
676 <td
> 
; 
; 
; 
; 
; 
; 
; 
;
677  
; 
; 
;</td
>
678 <td
class='bold' > 
; 
; 
;<?php
echo xlt('UAC Appl'); ?
></td
>
679 <td align
='right' class='bold' > 
; 
; 
; 
; 
;<?php
echo xlt('UAC Tot'); ?
></td
>
687 $prev_encounter_id = -1;
688 $hdr_printed = false;
690 while ($erow = sqlFetchArray($res)) {
693 if ($erow['encounter'] != $prev_encounter_id) {
694 if ($prev_encounter_id != -1) {
695 $credits = GetAllCredits($prev_encounter_id, $form_pid);
696 if (count($credits) > 0) {
701 $prev_row{'provider_id'}
705 PrintCreditDetail($credits, $form_pid);
712 $hdr_printed = false;
715 $enc_units = $enc_chg = $enc_pmt = $enc_adj = $enc_bal = 0;
719 // Now print an encounter heading line -
729 $code_desc = $erow['code_text'];
730 if (strlen($code_desc) > 50) {
731 $code_desc = substr($code_desc, 0, 50).'...';
734 $bgcolor = (($bgcolor == "#FFFFDD") ?
"#FFDDDD" : "#FFFFDD");
735 $print = "<tr bgcolor='". attr($bgcolor) ."'>";
736 $print .= "<td class='detail'>".text($erow['code'])."</td>";
737 $print .= "<td class='detail' colspan='2'>".text($code_desc)."</td>";
738 $who = ($erow['name'] == '') ?
xl('Self') : $erow['name'];
739 $bill = substr($erow['bill_date'], 0, 10);
744 $print .= "<td class='detail'>".text($bill)." / ".text($who)."</td>";
745 $print .= "<td class='detail' style='text-align: center;'>". text($erow['units'])."</td>";
746 $print .= "<td class='detail' style='text-align: center;'>". text(oeFormatMoney($erow['fee']))."</td>";
747 $print .= "<td> </td><td> </td><td> </td>";
750 $total_units +
= $erow['units'];
751 $total_chg +
= $erow['fee'];
752 $total_bal +
= $erow['fee'];
753 $enc_units +
= $erow['units'];
754 $enc_chg +
= $erow['fee'];
755 $enc_bal +
= $erow['fee'];
758 if ($_REQUEST['form_csvexport']) {
765 $prev_encounter_id = $erow{'encounter'};
769 if ($prev_encounter_id != -1) {
770 $credits = GetAllCredits($prev_encounter_id, $form_pid);
771 if (count($credits) > 0) {
776 $prev_row{'provider_id'}
780 PrintCreditDetail($credits, $form_pid);
788 // This is the end of the encounter/charge loop -
789 $uac = GetAllUnapplied($form_pid, $from_date, $to_date);
790 if (count($uac) > 0) {
792 $bgcolor = (($bgcolor == "#FFFFDD") ?
"#FFDDDD" : "#FFFFDD");
793 echo "<tr bgcolor='#FFFFFF'><td colspan='9'> </td></tr>\n";
796 PrintCreditDetail($uac, $form_pid, true);
799 if (!$_REQUEST['form_csvexport'] && $orow) {
800 echo "<tr bgcolor='#DDFFFF'>\n";
801 echo " <td colspan='2'> </td>";
802 echo " <td class='bold' colspan='2'>" . xlt("Grand Total") ."</td>\n";
803 echo " <td class='bold' style='text-align: center;'>". text($total_units) ."</td>\n";
804 echo " <td class='bold' style='text-align: center;'>". text(oeFormatMoney($total_chg)) ."</td>\n";
805 echo " <td class='bold' style='text-align: right;'>". text(oeFormatMoney($total_pmt)) ."</td>\n";
806 echo " <td class='bold' style='text-align: right;'>". text(oeFormatMoney($total_adj)) ."</td>\n";
807 echo " <td class='bold' style='text-align: right;'>". text(oeFormatMoney($total_bal)) . "</td>\n";
811 <tr
><td
> 
;</td
></tr
><br
><br
>
812 <?php
if ($GLOBALS['print_next_appointment_on_ledger'] == 1) {
813 $next_day = mktime(0, 0, 0, date('m'), date('d')+
1, date('Y'));
814 # add one day to date so it will not get todays appointment
815 $current_date2 = date('Y-m-d', $next_day);
816 $events = fetchNextXAppts($current_date2, $form_pid);
817 $next_appoint_date = oeFormatShortDate($events[0]['pc_eventDate']);
818 $next_appoint_time = substr($events[0]['pc_startTime'], 0, 5);
819 if (strlen($events[0]['umname']) != 0) {
820 $next_appoint_provider = $events[0]['ufname'] . ' ' . $events[0]['umname'] . ' ' . $events[0]['ulname'];
822 $next_appoint_provider = $events[0]['ufname'] . ' ' . $events[0]['ulname'];
825 if (strlen($next_appoint_time) != 0) { ?
>
827 <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
>
831 } // end ($GLOBALS['print_next_appointment_on_ledger'] == 1)
832 } // end (!$_REQUEST['form_csvexport'] && $orow)
836 if (! $_REQUEST['form_csvexport']) {
837 if ($_REQUEST['form_refresh'] && $orow <= 0) {
838 echo "<span style='font-size:10pt;'>";
839 echo xlt('No matches found. Try search again.');
841 echo '<script>document.getElementById("report_results").style.display="none";</script>';
842 echo '<script>document.getElementById("controls").style.display="none";</script>';
845 if (!$_REQUEST['form_refresh'] && !$_REQUEST['form_csvexport']) { ?
>
847 <?php
echo xlt('Please input search criteria above, and click Submit to view results.'); ?
>
855 } // End not csv export