3 * This is a report to create a patient ledger of charges with payments
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>;.
22 * @author Terry Hill <terry@lillysystems.com>
23 * @author Brady Miller <brady.g.miller@gmail.com>
24 * @link http://www.open-emr.org
27 $sanitize_all_escapes=true;
28 $fake_register_globals=false;
29 require_once('../globals.php');
30 require_once($GLOBALS['srcdir'].'/patient.inc');
31 require_once($GLOBALS['srcdir'].'/acl.inc');
32 require_once($GLOBALS['srcdir'].'/formatting.inc.php');
33 require_once($GLOBALS['srcdir'].'/options.inc.php');
34 require_once($GLOBALS['srcdir'].'/appointments.inc.php');
36 $enc_units = $total_units = 0;
37 $enc_chg = $total_chg = 0;
38 $enc_pmt = $total_pmt = 0;
39 $enc_adj = $total_adj = 0;
40 $enc_bal = $total_bal = 0;
44 $pat_pid = $_GET['patient_id'];
45 $type_form = $_GET['form'];
47 if (! acl_check('acct', 'rep')) die(xlt("Unauthorized access."));
49 function GetAllUnapplied($pat='',$from_dt='',$to_dt='') {
51 if(!$pat) return($all);
52 $sql = "SELECT ar_session.*, ins.name, " .
53 "pat.lname, pat.fname, pat.mname, " .
54 "(SELECT SUM(ar_activity.pay_amount) FROM ar_activity WHERE " .
55 "ar_activity.session_id = ar_session.session_id) AS applied " .
57 "LEFT JOIN insurance_companies AS ins on ar_session.payer_id = ins.id " .
58 "LEFT JOIN patient_data AS pat on ar_session.patient_id = pat.pid " .
60 "ar_session.created_time >= ? AND ar_session.created_time <= ? " .
61 "AND ar_session.patient_id=?";
62 $result = sqlStatement($sql, array($from_dt, $to_dt, $pat));
64 while($row = sqlFetchArray($result)) {
71 function User_Id_Look($thisField) {
72 if(!$thisField) return '';
74 $rlist= sqlStatement("SELECT lname, fname, mname FROM users WHERE id=?",array($thisField));
75 $rrow= sqlFetchArray($rlist);
77 $ret = $rrow{'lname'}.', '.$rrow{'fname'}.' '.$rrow{'mname'};
82 function List_Look($thisData, $thisList) {
83 if($thisList == 'occurrence') {
84 if(!$thisData ||
$thisData == '') return xl('Unknown or N/A');
86 if($thisData == '') return '';
87 $fres=sqlStatement("SELECT title FROM list_options WHERE list_id = ? ".
88 "AND option_id = ? AND activity = 1", array($thisList, $thisData));
90 $rret=sqlFetchArray($fres);
91 $dispValue= xl_list_label($rret{'title'});
92 if($thisList == 'occurrence' && $dispValue == '') {
93 $dispValue = xl('Unknown or N/A');
96 $dispValue= xl('Not Found');
101 function GetAllCredits($enc = '', $pat='') {
103 if(!$enc ||
!$pat) return($all);
104 $sql = "SELECT activity.*, session.*, ins.name FROM ar_activity AS ".
105 "activity LEFT JOIN ar_session AS session USING (session_id) ".
106 "LEFT JOIN insurance_companies AS ins ON session.payer_id = ".
107 "ins.id WHERE encounter=? AND pid=? ".
108 "ORDER BY sequence_no";
109 $result = sqlStatement($sql, array($enc, $pat));
111 while($row = sqlFetchArray($result)) {
117 function PrintEncHeader($dt, $rsn, $dr) {
118 global $bgcolor, $orow;
119 $bgcolor = (($bgcolor == "#FFFFDD") ?
"#FFDDDD" : "#FFFFDD");
120 echo "<tr bgcolor='#FFFFFF'>";
121 if(strlen($rsn) > 50) $rsn = substr($rsn,0,50).'...';
122 echo "<td colspan='4'><span class='bold'>".xlt('Encounter Dt / Rsn'). ": </span><span class='detail'>".text(substr($dt,0,10))." / ".text($rsn)."</span></td>";
123 echo "<td colspan='5'><span class='bold'>" . xlt('Provider'). ": </span><span class='detail'>".text(User_Id_Look($dr))."</span></td>";
127 function PrintEncFooter() {
128 global $enc_units, $enc_chg, $enc_pmt, $enc_adj, $enc_bal;
129 echo "<tr bgcolor='#DDFFFF'>";
130 echo "<td colspan='3'> </td>";
131 echo "<td class='detail'>". xlt('Encounter Balance').":</td>";
132 echo "<td class='detail' style='text-align: right;'>".text($enc_units)."</td>";
133 echo "<td class='detail' style='text-align: right;'>".text(oeFormatMoney($enc_chg))."</td>";
134 echo "<td class='detail' style='text-align: right;'>".text(oeFormatMoney($enc_pmt))."</td>";
135 echo "<td class='detail' style='text-align: right;'>".text(oeFormatMoney($enc_adj))."</td>";
136 echo "<td class='detail' style='text-align: right;'>".text(oeFormatMoney($enc_bal))."</td>";
139 function PrintCreditDetail($detail, $pat, $unassigned=false) {
140 global $enc_pmt, $total_pmt, $enc_adj, $total_adj, $enc_bal, $total_bal;
141 global $bgcolor, $orow, $enc_units, $enc_chg;
142 foreach($detail as $pmt) {
144 if(($pmt['pay_total'] - $pmt['applied']) == 0) continue;
146 $bgcolor = (($bgcolor == "#FFFFDD") ?
"#FFDDDD" : "#FFFFDD");
147 $print = "<tr bgcolor='" . attr($bgcolor) . "'>";
148 $print .= "<td class='detail'> </td>";
149 $method = List_Look($pmt['payment_method'],'payment_method');
150 $desc = $pmt['description'];
151 $ref = $pmt['reference'];
153 $memo = List_Look($pmt['adjustment_code'],'payment_adjustment_code');
155 $memo = $pmt['memo'];
157 $description = $method;
159 if($description) { $description .= ' - '; }
160 $description .= $ref;
163 if($description) { $description .= ': '; }
164 $description .= $desc;
167 if($description) { $description .= ' '; }
168 $description .= '['.$memo.']';
170 $print .= "<td class='detail' colspan='2'>".
171 text($description)." </td>";
172 $payer = ($pmt['name'] == '') ?
xl('Patient') : $pmt['name'];
174 $pmt_date = substr($pmt['post_to_date'],0,10);
176 $pmt_date = substr($pmt['post_time'],0,10);
178 $print .= "<td class='detail'>".
179 text($pmt_date)." / ".text($payer)."</td>";
180 $type = List_Look($pmt['payment_type'],'payment_type');
181 $print .= "<td class='detail'>".text($type)." </td>";
183 $pmt_amt = $pmt['pay_total'] - $pmt['applied'];
184 $uac_bal = oeFormatMoney($pmt_amt * -1);
185 $uac_appl = oeFormatMoney($pmt['applied']);
186 $uac_total = oeFormatMoney($pmt['pay_total']);
187 $pmt_amt = $pmt['pay_total'];
188 $total_pmt = $total_pmt - $uac_bal;
193 $pmt_amt = $pmt['pay_amount'];
194 $adj_amt = $pmt['adj_amount'];
195 $enc_pmt = $enc_pmt +
$pmt['pay_amount'];
196 $total_pmt = $total_pmt +
$pmt['pay_amount'];
197 $enc_adj = $enc_adj +
$pmt['adj_amount'];
198 $total_adj = $total_adj +
$pmt['adj_amount'];
201 if($pmt_amt != 0) $print_pmt = oeFormatMoney($pmt_amt);
203 if($adj_amt != 0) $print_adj = oeFormatMoney($adj_amt);
204 $print .= "<td class='detail' style='text-align: right;'>".text($uac_appl)." </td>";
205 $print .= "<td class='detail' style='text-align: right;'>".text($print_pmt)." </td>";
206 $print .= "<td class='detail' style='text-align: right;'>".text($print_adj)." </td>";
207 $print .= "<td class='detail' style='text-align: right;'>".text($uac_bal)." </td>";
210 if($pmt['follow_up_note'] != '') {
211 $bgcolor = (($bgcolor == "#FFFFDD") ?
"#FFDDDD" : "#FFFFDD");
212 $print = "<tr bgcolor='". attr($bgcolor) ."'>";
213 $print .= "<td class='detail' colspan='2'> </td>";
214 $print .= "<td colspan='7'>". xlt('Follow Up Note') .": ";
215 $print .= text($pmt['follow_up_note']);
216 $print .= "</td></tr>\n";
220 $total_bal = $total_bal +
$uac_bal;
222 $enc_bal = $enc_bal - $pmt_amt - $adj_amt;
223 $total_bal = $total_bal - $pmt_amt - $adj_amt;
227 $bgcolor = (($bgcolor == "#FFFFDD") ?
"#FFDDDD" : "#FFFFDD");
229 if(!isset($_REQUEST['form_from_date'])) { $_REQUEST['form_from_date'] = ''; }
230 if(!isset($_REQUEST['form_to_date'])) { $_REQUEST['form_to_date'] = ''; }
231 if(!isset($_REQUEST['form_facility'])) { $_REQUEST['form_facility'] = ''; }
232 if(!isset($_REQUEST['form_provider'])) { $_REQUEST['form_provider'] = ''; }
233 if($type_form=='0') {
234 if(!isset($_REQUEST['form_patient'])) { $_REQUEST['form_patient'] = ''; }
235 if(!isset($_REQUEST['form_pid'])) { $_REQUEST['form_pid'] = ''; }
239 if(!isset($_REQUEST['form_patient'])) { $_REQUEST['form_patient'] = $pat_pid; }
240 if(!isset($_REQUEST['form_pid'])) { $_REQUEST['form_pid'] = $pat_pid; }
242 if(!isset($_REQUEST['form_csvexport'])) { $_REQUEST['form_csvexport'] = ''; }
243 if(!isset($_REQUEST['form_refresh'])) { $_REQUEST['form_refresh'] = ''; }
244 if(!isset($_REQUEST['$form_dob'])) { $_REQUEST['$form_dob'] = ''; }
246 if (substr($GLOBALS['ledger_begin_date'],0,1) == 'Y') {
247 $ledger_time = substr($GLOBALS['ledger_begin_date'],1,1);
248 $last_year = mktime(0,0,0,date('m'),date('d'),date('Y')-$ledger_time);
250 elseif (substr($GLOBALS['ledger_begin_date'],0,1) == 'M') {
251 $ledger_time = substr($GLOBALS['ledger_begin_date'],1,1);
252 $last_year = mktime(0,0,0,date('m')-$ledger_time ,date('d'),date('Y'));
254 elseif (substr($GLOBALS['ledger_begin_date'],0,1) == 'D') {
255 $ledger_time = substr($GLOBALS['ledger_begin_date'],1,1);
256 $last_year = mktime(0,0,0,date('m') ,date('d')-$ledger_time,date('Y'));
259 $form_from_date = date('Y-m-d', $last_year);
260 if($_REQUEST['form_from_date']) {
261 $form_from_date = fixDate($_REQUEST['form_from_date'], $last_year);
263 $form_to_date = fixDate($_REQUEST['form_to_date'] , date('Y-m-d'));
264 $form_facility = $_REQUEST['form_facility'];
265 $form_provider = $_REQUEST['form_provider'];
266 $form_patient = $_REQUEST['form_patient'];
267 $form_pid = $_REQUEST['form_pid'];
268 $form_dob = $_REQUEST['form_dob'];
270 if ($_REQUEST['form_csvexport']) {
271 header("Pragma: public");
272 header("Expires: 0");
273 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
274 header("Content-Type: application/force-download");
275 header("Content-Disposition: attachment; filename=svc_financial_report_".attr($form_from_date)."--".attr($form_to_date).".csv");
276 header("Content-Description: File Transfer");
282 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js?v=<?php echo $v_js_includes; ?>"></script
>
283 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-3-1-1/index.js"></script
>
284 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/js/common.js?v=<?php echo $v_js_includes; ?>"></script
>
285 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.full.min.js"></script
>
287 <script type
="text/javascript">
288 var mypcc
= '<?php echo $GLOBALS['phone_country_code
']; ?>';
291 function checkSubmit() {
292 var pat
= document
.forms
[0].elements
['form_patient'].value
;
293 if(!pat || pat
== 0) {
294 alert('<?php echo xls('A Patient Must Be Selected to Generate This Report
') ?>');
297 document
.forms
[0].elements
['form_refresh'].value
= true;
298 document
.forms
[0].elements
['form_csvexport'].value
= '';
299 document
.forms
[0].submit();
301 function setpatient(pid
, lname
, fname
, dob
) {
302 document
.forms
[0].elements
['form_patient'].value
= lname +
', ' + fname
;
303 document
.forms
[0].elements
['form_pid'].value
= pid
;
304 document
.forms
[0].elements
['form_dob'].value
= dob
;
306 function sel_patient() {
307 dlgopen('../main/calendar/find_patient_popup.php?pflag=0', '_blank', 500, 400);
311 <link rel
="stylesheet" href
="<?php echo $css_header;?>" type
="text/css">
312 <link rel
="stylesheet" href
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.min.css">
314 <?php
html_header_show();?
>
315 <style type
="text/css">
317 /* specifically include & exclude from printing */
323 #report_parameters_daterange {
339 /* specifically exclude some from the screen */
341 #report_parameters_daterange {
356 <title
><?php
echo xlt('Patient Ledger by Date') ?
></title
>
358 <script language
="JavaScript">
359 $
(document
).ready(function() {
360 var win
= top
.printLogSetup ? top
: opener
.top
;
361 win
.printLogSetup(document
.getElementById('printbutton'));
363 $
('.datepicker').datetimepicker({
364 <?php
$datetimepicker_timepicker = false; ?
>
365 <?php
$datetimepicker_formatInput = false; ?
>
366 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
367 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
373 <body
class="body_top">
374 <?php
if($type_form == '0') { ?
>
375 <span
class='title' id
='title'><?php
echo xlt('Report'); ?
> - <?php
echo xlt('Patient Ledger by Date'); ?
></span
>
377 <span
class='title' id
='title'><?php
echo xlt('Patient Ledger'); ?
></span
>
379 <form method
='post' action
='pat_ledger.php?form=<?php echo attr($type_form);?>&patient_id=<?php echo attr($form_pid);?>' id
='theform'>
380 <div id
="report_parameters">
381 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
382 <input type
='hidden' name
='form_csvexport' id
='form_csvexport' value
=''/>
385 <?php
if($type_form == '1') { ?
>
390 <div style
='float:left'>
393 <?php
if($type_form == '0') { ?
>
395 <?php
echo xlt('Facility'); ?
>:
398 <?php
dropdown_facility($form_facility, 'form_facility', true); ?
>
400 <td
><?php
echo xlt('Provider'); ?
>:</td
>
402 $query = "SELECT id, lname, fname FROM users WHERE ".
403 "authorized=1 AND active!=0 ORDER BY lname, fname";
404 $ures = sqlStatement($query);
405 echo " <select name='form_provider'>\n";
406 echo " <option value=''>-- " . xlt('All') . " --\n";
407 while ($urow = sqlFetchArray($ures)) {
408 $provid = $urow['id'];
409 echo " <option value='" . attr($provid) ."'";
410 if ($provid == $_REQUEST['form_provider']) echo " selected";
411 echo ">" . text($urow['lname']) . ", " . text($urow['fname']) . "\n";
418 <?php
echo xlt('From'); ?
>: 
; 
; 
; 
;
419 <input type
='text' class='datepicker' name
='form_from_date' id
="form_from_date" size
='10' value
='<?php echo attr($form_from_date) ?>' title
='yyyy-mm-dd'>
422 <?php
echo xlt('To'); ?
>:
425 <input type
='text' class='datepicker' name
='form_to_date' id
="form_to_date" size
='10' value
='<?php echo attr($form_to_date) ?>' title
='yyyy-mm-dd'>
427 <?php
if($type_form == '0') { ?
>
428 <td
><span
class='label'><?php
echo xlt('Patient'); ?
>: 
; 
;</span
></td
>
430 <input type
='text' size
='20' name
='form_patient' 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
'); ?>' />
432 <input type
='hidden' name
='form_patient' value
='<?php echo attr($form_patient); ?>' />
434 <input type
='hidden' name
='form_pid' value
='<?php echo attr($form_pid); ?>' />
435 <input type
='hidden' name
='form_dob' value
='<?php echo attr($form_dob); ?>' />
442 <td align
='left' valign
='middle' height
="100%">
443 <table style
='border-left:1px solid; width:100%; height:100%' >
446 <div style
='margin-left:15px'>
447 <a href
='#' class='css_button' onclick
="checkSubmit();" >
448 <span
><?php
echo xlt('Submit'); ?
></span
></a
>
450 <?php
if ($_REQUEST['form_refresh'] ||
$_REQUEST['form_csvexport']) { ?
>
452 <a href
='#' class='css_button' id
='printbutton'>
453 <span
><?php
echo xlt('Print Ledger'); ?
></span
></a
>
454 <?php
if($type_form == '1') { ?
>
455 <a href
="../patient_file/summary/demographics.php" class="css_button" onclick
="top.restoreSession()">
456 <span
><?php
echo xlt('Back To Patient');?
></span
></a
>
467 </div
> <!-- end of parameters
-->
471 $from_date = $form_from_date . ' 00:00:00';
472 $to_date = $form_to_date . ' 23:59:59';
473 if ($_REQUEST['form_refresh'] ||
$_REQUEST['form_csvexport']) {
475 $sqlBindArray = array();
476 $query = "select b.code_type, b.code, b.code_text, b.pid, b.provider_id, ".
477 "b.billed, b.payer_id, b.units, b.fee, b.bill_date, b.id, ".
479 "fe.encounter, fe.date, fe.reason, fe.provider_id ".
480 "FROM form_encounter AS fe ".
481 "LEFT JOIN billing AS b ON b.pid=fe.pid AND b.encounter=fe.encounter ".
482 "LEFT JOIN insurance_companies AS ins ON b.payer_id = ins.id ".
483 "LEFT OUTER JOIN code_types AS c ON c.ct_key = b.code_type ".
484 "WHERE fe.date >= ? AND fe.date <= ? AND fe.pid = ? ";
485 array_push($sqlBindArray,$from_date,$to_date,$form_pid);
486 if ($form_facility) {
487 $query .= "AND fe.facility_id = ? ";
488 array_push($sqlBindArray,$form_facility);
490 if ($form_provider) {
491 $query .= "AND b.provider_id = ? ";
492 array_push($sqlBindArray,$form_provider);
494 $query .= "AND c.ct_proc = '1' ";
495 $query .= "AND activity > 0 ORDER BY fe.date, fe.id ";
496 $res = sqlStatement($query,$sqlBindArray);
498 if ($_REQUEST['form_csvexport']) {
501 echo '"Code/Enc Dt",';
502 echo '"Description",';
503 echo '"Billed/Who",';
504 echo '"Type/Units",';
505 echo '"Chg/Pmt Amount",'."\n";
508 if(!$form_facility) $form_facility = '3';
509 $facility = sqlQuery("SELECT * FROM facility WHERE id=?", array($form_facility));
510 $patient = sqlQuery("SELECT * from patient_data WHERE pid=?", array($form_patient));
511 $pat_dob = $patient['DOB'];
512 $pat_name = $patient['fname']. ' ' . $patient['lname'];
514 <div id
="report_header">
515 <table width
="98%" border
="0" cellspacing
="0" cellpadding
="0">
517 <td
class="title" ><?php
echo text($facility{'name'}); ?
></td
>
520 <td
class="title" ><?php
echo text($facility{'street'}); ?
></td
>
523 <td
class="title" ><?php
echo text($facility{'city'}).", ".text($facility{'state'})." ".text($facility{'postal_code'}); ?
></td
>
526 <td
class="title" ><?php
echo xlt('Phone').': ' .text($facility{'phone'}); ?
></td
>
529 <td
class="title" ><?php
echo xlt('Tax Id').': ' .text($facility{'federal_ein'}); ?
></td
>
531 <tr
><td
> 
;</td
></tr
>
533 <td
class="title" ><?php
echo xlt('Patient Ledger'); ?
></td
>
537 $title = xl('All Providers');
538 if($form_provider) { $title = xl('For Provider') . ': '.User_Id_Look($form_provider); }
540 <td
class="title" ><?php
echo text($title); ?
></td
>
544 $title = xl('For Dates') . ': '.$form_from_date.' - '.$form_to_date;
546 <td
class="title" ><?php
echo text($title); ?
></td
>
550 <table width
="100%" border
="0" cellspacing
="0" cellpadding
="0">
552 <td
class='bold' ><?php
echo xlt('Date')?
>:
553 <?php
echo text(date('Y-m-d')); ?
></td
>
554 <td
class='bold' ><?php
echo xlt('Patient')?
>:
555 <?php
if($type_form == '1') { ?
>
556 <?php
echo text($pat_name); ?
></td
>
558 <?php
echo text($form_patient); ?
></td
>
560 <td
class='bold' ><?php
echo xlt('DOB')?
>:
561 <?php
if($type_form == '1') { ?
>
562 <?php
echo text($pat_dob);?
></td
>
564 <?php
echo text($form_dob); ?
></td
>
566 <td
class='bold' > <?php
echo xlt('ID')?
>:
567 <?php
echo text($form_pid);?
></td
>
571 <div id
="report_results">
574 <td
class='bold' ><?php
echo xlt('Code'); ?
></td
>
575 <td colspan
="2" class='bold' ><?php
echo xlt('Description'); ?
></td
>
576 <td
class='bold' ><?php
echo xlt('Billed Date'); ?
> / <?php
echo xlt('Payor'); ?
></td
>
577 <td
class='bold' ><?php
echo xlt('Type'); ?
> 
; 
; 
; 
; 
; 
; 
;
578 <?php
echo xlt('Units'); ?
></td
>
579 <td
class='bold' > 
; 
; 
; 
; 
;<?php
echo xlt('Charge'); ?
></td
>
580 <td align
='right' class='bold' > 
; 
;<?php
echo xlt('Payment'); ?
></td
>
581 <td align
='right' class='bold' > 
; 
; 
; 
; 
;<?php
echo xlt('Adjustment'); ?
></td
>
582 <td align
='right' class='bold' > 
; 
; 
;<?php
echo xlt('Balance'); ?
></td
>
585 <td
> 
; 
; 
;</td
>
586 <td colspan
="2" > 
; 
; 
;</td
>
587 <td
> 
; 
; 
; 
; 
; 
;</td
>
588 <td
> 
; 
; 
; 
; 
; 
; 
; 
;
589  
; 
; 
;</td
>
590 <td
class='bold' > 
; 
; 
;<?php
echo xlt('UAC Appl'); ?
></td
>
591 <td align
='right' class='bold' > 
; 
; 
; 
; 
;<?php
echo xlt('UAC Tot'); ?
></td
>
598 $prev_encounter_id = -1;
599 $hdr_printed = false;
601 while ($erow = sqlFetchArray($res)) {
604 if($erow['encounter'] != $prev_encounter_id) {
605 if($prev_encounter_id != -1) {
606 $credits = GetAllCredits($prev_encounter_id, $form_pid);
607 if(count($credits) > 0) {
609 PrintEncHeader($prev_row{'date'},
610 $prev_row{'reason'}, $prev_row{'provider_id'});
612 PrintCreditDetail($credits, $form_pid);
614 if($hdr_printed) PrintEncFooter();
615 $hdr_printed = false;
617 $enc_units = $enc_chg = $enc_pmt = $enc_adj = $enc_bal = 0;
620 // Now print an encounter heading line -
622 PrintEncHeader($erow{'date'},
623 $erow{'reason'}, $erow{'provider_id'});
627 $code_desc = $erow['code_text'];
628 if(strlen($code_desc) > 50) $code_desc = substr($code_desc,0,50).'...';
629 $bgcolor = (($bgcolor == "#FFFFDD") ?
"#FFDDDD" : "#FFFFDD");
630 $print = "<tr bgcolor='". attr($bgcolor) ."'>";
631 $print .= "<td class='detail'>".text($erow['code'])."</td>";
632 $print .= "<td class='detail' colspan='2'>".text($code_desc)."</td>";
633 $who = ($erow['name'] == '') ?
xl('Self') : $erow['name'];
634 $bill = substr($erow['bill_date'],0,10);
635 if($bill == '') { $bill = 'unbilled'; }
636 $print .= "<td class='detail'>".text($bill)." / ".text($who)."</td>";
637 $print .= "<td class='detail' style='text-align: right;'>". text($erow['units'])."</td>";
638 $print .= "<td class='detail' style='text-align: right;'>". text(oeFormatMoney($erow['fee']))."</td>";
639 $print .= "<td> </td><td> </td><td> </td>";
642 $total_units +
= $erow['units'];
643 $total_chg +
= $erow['fee'];
644 $total_bal +
= $erow['fee'];
645 $enc_units +
= $erow['units'];
646 $enc_chg +
= $erow['fee'];
647 $enc_bal +
= $erow['fee'];
650 if ($_REQUEST['form_csvexport']) {
656 $prev_encounter_id = $erow{'encounter'};
659 if($prev_encounter_id != -1) {
660 $credits = GetAllCredits($prev_encounter_id, $form_pid);
661 if(count($credits) > 0) {
663 PrintEncHeader($prev_row{'date'},
664 $prev_row{'reason'}, $prev_row{'provider_id'});
666 PrintCreditDetail($credits, $form_pid);
668 if($hdr_printed) PrintEncFooter();
670 // This is the end of the encounter/charge loop -
671 $uac = GetAllUnapplied($form_pid,$from_date,$to_date);
672 if(count($uac) > 0) {
674 $bgcolor = (($bgcolor == "#FFFFDD") ?
"#FFDDDD" : "#FFFFDD");
675 echo "<tr bgcolor='#FFFFFF'><td colspan='9'> </td></tr>\n";
677 PrintCreditDetail($uac, $form_pid, true);
679 if (!$_REQUEST['form_csvexport'] && $orow) {
680 echo "<tr bgcolor='#DDFFFF'>\n";
681 echo " <td colspan='2'> </td>";
682 echo " <td class='bold' colspan='2'>" . xlt("Grand Total") ."</td>\n";
683 echo " <td class='bold' style='text-align: right;'>". text($total_units) ."</td>\n";
684 echo " <td class='bold' style='text-align: right;'>". text(oeFormatMoney($total_chg)) ."</td>\n";
685 echo " <td class='bold' style='text-align: right;'>". text(oeFormatMoney($total_pmt)) ."</td>\n";
686 echo " <td class='bold' style='text-align: right;'>". text(oeFormatMoney($total_adj)) ."</td>\n";
687 echo " <td class='bold' style='text-align: right;'>". text(oeFormatMoney($total_bal)) . "</td>\n";
691 <tr
><td
> 
;</td
></tr
><br
><br
>
692 <?php
if($GLOBALS['print_next_appointment_on_ledger'] == 1) {
693 $next_day = mktime(0,0,0,date('m'),date('d')+
1,date('Y'));
694 # add one day to date so it will not get todays appointment
695 $current_date2 = date('Y-m-d', $next_day);
696 $events = fetchNextXAppts($current_date2,$form_pid);
697 $next_appoint_date = oeFormatShortDate($events[0]['pc_eventDate']);
698 $next_appoint_time = substr($events[0]['pc_startTime'],0,5);
699 if(strlen(umname
) != 0 ) {
700 $next_appoint_provider = $events[0]['ufname'] . ' ' . $events[0]['umname'] . ' ' . $events[0]['ulname'];
704 $next_appoint_provider = $events[0]['ufname'] . ' ' . $events[0]['ulname'];
706 if(strlen($next_appoint_time) != 0) {
709 <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
>
714 } // end ($GLOBALS['print_next_appointment_on_ledger'] == 1)
715 } // end (!$_REQUEST['form_csvexport'] && $orow)
718 if (! $_REQUEST['form_csvexport']) {
719 if ( $_REQUEST['form_refresh'] && $orow <= 0) {
720 echo "<span style='font-size:10pt;'>";
721 echo xlt('No matches found. Try search again.');
723 echo '<script>document.getElementById("report_results").style.display="none";</script>';
724 echo '<script>document.getElementById("controls").style.display="none";</script>';
727 if (!$_REQUEST['form_refresh'] && !$_REQUEST['form_csvexport']) { ?
>
729 <?php
echo xlt('Please input search criteria above, and click Submit to view results.' ); ?
>
737 } // End not csv export