3 * This is a report to create a patient ledger of charges with payments
6 * Copyright (C) 2015 Rich Genandt <rgenandt@gmail.com>
8 * LICENSE: This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
21 * @author Terry Hill <terry@lillysystems.com>
22 * @link http://www.open-emr.org
24 require_once("./../verify_session.php");
29 require_once('../../interface/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'].'/formdata.inc.php');
35 require_once($GLOBALS['srcdir'].'/appointments.inc.php');
37 $enc_units = $total_units = 0;
38 $enc_chg = $total_chg = 0;
39 $enc_pmt = $total_pmt = 0;
40 $enc_adj = $total_adj = 0;
41 $enc_bal = $total_bal = 0;
45 $pat_pid = $_GET['patient_id'];
46 $type_form = $_GET['form'];
48 //if (! acl_check('acct', 'rep')) die(xlt("Unauthorized access."));
50 function GetAllUnapplied($pat='',$from_dt='',$to_dt='') {
52 if(!$pat) return($all);
53 $sql = "SELECT ar_session.*, ins.name, " .
54 "pat.lname, pat.fname, pat.mname, " .
55 "(SELECT SUM(ar_activity.pay_amount) FROM ar_activity WHERE " .
56 "ar_activity.session_id = ar_session.session_id) AS applied " .
58 "LEFT JOIN insurance_companies AS ins on ar_session.payer_id = ins.id " .
59 "LEFT JOIN patient_data AS pat on ar_session.patient_id = pat.pid " .
61 "ar_session.created_time >= ? AND ar_session.created_time <= ? " .
62 "AND ar_session.patient_id=?";
63 $result = sqlStatement($sql, array($from_dt, $to_dt, $pat));
65 while($row = sqlFetchArray($result)) {
72 function User_Id_Look($thisField) {
73 if(!$thisField) return '';
75 $rlist= sqlStatement("SELECT lname, fname, mname FROM users WHERE id=?",array($thisField));
76 $rrow= sqlFetchArray($rlist);
78 $ret = $rrow{'lname'}.', '.$rrow{'fname'}.' '.$rrow{'mname'};
83 function List_Look($thisData, $thisList) {
84 if($thisList == 'occurrence') {
85 if(!$thisData ||
$thisData == '') return xl('Unknown or N/A');
87 if($thisData == '') return '';
88 $fres=sqlStatement("SELECT title FROM list_options WHERE list_id=? ".
89 "AND option_id=?", array($thisList, $thisData));
91 $rret=sqlFetchArray($fres);
92 $dispValue= xl_list_label($rret{'title'});
93 if($thisList == 'occurrence' && $dispValue == '') {
94 $dispValue = xl('Unknown or N/A');
97 $dispValue= xl('Not Found');
102 function GetAllCredits($enc = '', $pat='') {
104 if(!$enc ||
!$pat) return($all);
105 $sql = "SELECT activity.*, session.*, ins.name FROM ar_activity AS ".
106 "activity LEFT JOIN ar_session AS session USING (session_id) ".
107 "LEFT JOIN insurance_companies AS ins ON session.payer_id = ".
108 "ins.id WHERE encounter=? AND pid=? ".
109 "ORDER BY sequence_no";
110 $result = sqlStatement($sql, array($enc, $pat));
112 while($row = sqlFetchArray($result)) {
118 function PrintEncHeader($dt, $rsn, $dr) {
119 global $bgcolor, $orow;
120 $bgcolor = (($bgcolor == "#FFFFDD") ?
"#FFDDDD" : "#FFFFDD");
121 echo "<tr bgcolor='#FFFFFF'>";
122 if(strlen($rsn) > 50) $rsn = substr($rsn,0,50).'...';
123 echo "<td colspan='4'><span class='bold'>".xlt('Encounter Dt / Rsn'). ": </span><span class='detail'>".text(substr($dt,0,10))." / ".text($rsn)."</span></td>";
124 echo "<td colspan='5'><span class='bold'>" . xlt('Provider'). ": </span><span class='detail'>".text(User_Id_Look($dr))."</span></td>";
128 function PrintEncFooter() {
129 global $enc_units, $enc_chg, $enc_pmt, $enc_adj, $enc_bal;
130 echo "<tr bgcolor='#DDFFFF'>";
131 echo "<td colspan='3'> </td>";
132 echo "<td class='detail'>". xlt('Encounter Balance').":</td>";
133 echo "<td class='detail' style='text-align: right;'>".text($enc_units)."</td>";
134 echo "<td class='detail' style='text-align: right;'>".text(oeFormatMoney($enc_chg))."</td>";
135 echo "<td class='detail' style='text-align: right;'>".text(oeFormatMoney($enc_pmt))."</td>";
136 echo "<td class='detail' style='text-align: right;'>".text(oeFormatMoney($enc_adj))."</td>";
137 echo "<td class='detail' style='text-align: right;'>".text(oeFormatMoney($enc_bal))."</td>";
140 function PrintCreditDetail($detail, $pat, $unassigned=false) {
141 global $enc_pmt, $total_pmt, $enc_adj, $total_adj, $enc_bal, $total_bal;
142 global $bgcolor, $orow, $enc_units, $enc_chg;
143 foreach($detail as $pmt) {
145 if(($pmt['pay_total'] - $pmt['applied']) == 0) continue;
147 $bgcolor = (($bgcolor == "#FFFFDD") ?
"#FFDDDD" : "#FFFFDD");
148 $print = "<tr bgcolor='" . attr($bgcolor) . "'>";
149 $print .= "<td class='detail'> </td>";
150 $method = List_Look($pmt['payment_method'],'payment_method');
151 $desc = $pmt['description'];
152 $ref = $pmt['reference'];
154 $memo = List_Look($pmt['adjustment_code'],'payment_adjustment_code');
156 $memo = $pmt['memo'];
158 $description = $method;
160 if($description) { $description .= ' - '; }
161 $description .= $ref;
164 if($description) { $description .= ': '; }
165 $description .= $desc;
168 if($description) { $description .= ' '; }
169 $description .= '['.$memo.']';
171 $print .= "<td class='detail' colspan='2'>".
172 text($description)." </td>";
173 $payer = ($pmt['name'] == '') ?
xl('Patient') : $pmt['name'];
175 $pmt_date = substr($pmt['post_to_date'],0,10);
177 $pmt_date = substr($pmt['post_time'],0,10);
179 $print .= "<td class='detail'>".
180 text($pmt_date)." / ".text($payer)."</td>";
181 $type = List_Look($pmt['payment_type'],'payment_type');
182 $print .= "<td class='detail'>".text($type)." </td>";
184 $pmt_amt = $pmt['pay_total'] - $pmt['applied'];
185 $uac_bal = oeFormatMoney($pmt_amt * -1);
186 $uac_appl = oeFormatMoney($pmt['applied']);
187 $uac_total = oeFormatMoney($pmt['pay_total']);
188 $pmt_amt = $pmt['pay_total'];
189 $total_pmt = $total_pmt - $uac_bal;
194 $pmt_amt = $pmt['pay_amount'];
195 $adj_amt = $pmt['adj_amount'];
196 $enc_pmt = $enc_pmt +
$pmt['pay_amount'];
197 $total_pmt = $total_pmt +
$pmt['pay_amount'];
198 $enc_adj = $enc_adj +
$pmt['adj_amount'];
199 $total_adj = $total_adj +
$pmt['adj_amount'];
202 if($pmt_amt != 0) $print_pmt = oeFormatMoney($pmt_amt);
204 if($adj_amt != 0) $print_adj = oeFormatMoney($adj_amt);
205 $print .= "<td class='detail' style='text-align: right;'>".text($uac_appl)." </td>";
206 $print .= "<td class='detail' style='text-align: right;'>".text($print_pmt)." </td>";
207 $print .= "<td class='detail' style='text-align: right;'>".text($print_adj)." </td>";
208 $print .= "<td class='detail' style='text-align: right;'>".text($uac_bal)." </td>";
211 if($pmt['follow_up_note'] != '') {
212 $bgcolor = (($bgcolor == "#FFFFDD") ?
"#FFDDDD" : "#FFFFDD");
213 $print = "<tr bgcolor='". attr($bgcolor) ."'>";
214 $print .= "<td class='detail' colspan='2'> </td>";
215 $print .= "<td colspan='7'>". xlt('Follow Up Note') .": ";
216 $print .= text($pmt['follow_up_note']);
217 $print .= "</td></tr>\n";
221 $total_bal = $total_bal +
$uac_bal;
223 $enc_bal = $enc_bal - $pmt_amt - $adj_amt;
224 $total_bal = $total_bal - $pmt_amt - $adj_amt;
228 $bgcolor = (($bgcolor == "#FFFFDD") ?
"#FFDDDD" : "#FFFFDD");
230 if(!isset($_REQUEST['form_from_date'])) { $_REQUEST['form_from_date'] = ''; }
231 if(!isset($_REQUEST['form_to_date'])) { $_REQUEST['form_to_date'] = ''; }
232 if(!isset($_REQUEST['form_facility'])) { $_REQUEST['form_facility'] = ''; }
233 if(!isset($_REQUEST['form_provider'])) { $_REQUEST['form_provider'] = ''; }
234 if($type_form=='0') {
235 if(!isset($_REQUEST['form_patient'])) { $_REQUEST['form_patient'] = ''; }
236 if(!isset($_REQUEST['form_pid'])) { $_REQUEST['form_pid'] = ''; }
240 if(!isset($_REQUEST['form_patient'])) { $_REQUEST['form_patient'] = $pat_pid; }
241 if(!isset($_REQUEST['form_pid'])) { $_REQUEST['form_pid'] = $pat_pid; }
243 if(!isset($_REQUEST['form_csvexport'])) { $_REQUEST['form_csvexport'] = ''; }
244 if(!isset($_REQUEST['form_refresh'])) { $_REQUEST['form_refresh'] = ''; }
245 if(!isset($_REQUEST['$form_dob'])) { $_REQUEST['$form_dob'] = ''; }
247 if (substr($GLOBALS['ledger_begin_date'],0,1) == 'Y') {
248 $ledger_time = substr($GLOBALS['ledger_begin_date'],1,1);
249 $last_year = mktime(0,0,0,date('m'),date('d'),date('Y')-$ledger_time);
251 elseif (substr($GLOBALS['ledger_begin_date'],0,1) == 'M') {
252 $ledger_time = substr($GLOBALS['ledger_begin_date'],1,1);
253 $last_year = mktime(0,0,0,date('m')-$ledger_time ,date('d'),date('Y'));
255 elseif (substr($GLOBALS['ledger_begin_date'],0,1) == 'D') {
256 $ledger_time = substr($GLOBALS['ledger_begin_date'],1,1);
257 $last_year = mktime(0,0,0,date('m') ,date('d')-$ledger_time,date('Y'));
260 $form_from_date = date('Y-m-d', $last_year);
261 if($_REQUEST['form_from_date']) {
262 $form_from_date = fixDate($_REQUEST['form_from_date'], $last_year);
264 $form_to_date = fixDate($_REQUEST['form_to_date'] , date('Y-m-d'));
265 $form_facility = $_REQUEST['form_facility'];
266 $form_provider = $_REQUEST['form_provider'];
267 $form_patient = $_REQUEST['form_patient'];
268 $form_pid = $_REQUEST['form_pid'];
269 $form_dob = $_REQUEST['form_dob'];
271 if ($_REQUEST['form_csvexport']) {
272 header("Pragma: public");
273 header("Expires: 0");
274 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
275 header("Content-Type: application/force-download");
276 header("Content-Disposition: attachment; filename=svc_financial_report_".attr($form_from_date)."--".attr($form_to_date).".csv");
277 header("Content-Description: File Transfer");
282 <link rel
="stylesheet" href
="<?php echo $css_header;?>" type
="text/css">
283 <link rel
="stylesheet" href
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.min.css">
285 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js?v=<?php echo $v_js_includes; ?>"></script
>
286 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-3-1-1/index.js"></script
>
287 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/js/common.js?v=<?php echo $v_js_includes; ?>"></script
>
288 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.full.min.js"></script
>
290 <script type
="text/javascript">
291 var mypcc
= '<?php echo $GLOBALS['phone_country_code
']; ?>';
294 function checkSubmit() {
295 var pat
= document
.forms
[0].elements
['form_patient'].value
;
296 if(!pat || pat
== 0) {
297 alert('<?php echo xls('A Patient Must Be Selected to Generate This Report
') ?>');
300 document
.forms
[0].elements
['form_refresh'].value
= true;
301 document
.forms
[0].elements
['form_csvexport'].value
= '';
302 document
.forms
[0].submit();
304 function setpatient(pid
, lname
, fname
, dob
) {
305 document
.forms
[0].elements
['form_patient'].value
= lname +
', ' + fname
;
306 document
.forms
[0].elements
['form_pid'].value
= pid
;
307 document
.forms
[0].elements
['form_dob'].value
= dob
;
309 function sel_patient() {
310 dlgopen('../main/calendar/find_patient_popup.php?pflag=0', '_blank', 500, 400);
314 <style type
="text/css">
316 /* specifically include & exclude from printing */
322 #report_parameters_daterange {
338 /* specifically exclude some from the screen */
340 #report_parameters_daterange {
355 <title
><?php
echo xlt('Patient Ledger by Date') ?
></title
>
358 $
(document
).ready(function() {
359 $
('.datepicker').datetimepicker({
360 <?php
$datetimepicker_timepicker = false; ?
>
361 <?php
$datetimepicker_formatInput = false; ?
>
362 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
363 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
369 <body
class="body_top">
370 <?php
if($type_form == '0') { ?
>
371 <span
class='title' id
='title'><?php
echo xlt('Report'); ?
> - <?php
echo xlt('Patient Ledger by Date'); ?
></span
>
373 <span
class='title' id
='title'><?php
echo xlt('Patient Ledger'); ?
></span
>
375 <form method
='post' action
='./pat_ledger.php?form=<?php echo attr($type_form);?>&patient_id=<?php echo attr($form_pid);?>' id
='theform'>
376 <div id
="report_parameters">
377 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
378 <input type
='hidden' name
='form_csvexport' id
='form_csvexport' value
=''/>
381 <?php
if($type_form == '1') { ?
>
386 <div style
='float:left'>
389 <?php
if($type_form == '0') { ?
>
390 <td
class='label_custom'>
391 <?php
echo xlt('Facility'); ?
>:
394 <?php
dropdown_facility($form_facility, 'form_facility', true); ?
>
396 <td
><?php
echo xlt('Provider'); ?
>:</td
>
398 $query = "SELECT id, lname, fname FROM users WHERE ".
399 "authorized=1 AND active!=0 ORDER BY lname, fname";
400 $ures = sqlStatement($query);
401 echo " <select name='form_provider'>\n";
402 echo " <option value=''>-- " . xlt('All') . " --\n";
403 while ($urow = sqlFetchArray($ures)) {
404 $provid = $urow['id'];
405 echo " <option value='" . attr($provid) ."'";
406 if ($provid == $_REQUEST['form_provider']) echo " selected";
407 echo ">" . text($urow['lname']) . ", " . text($urow['fname']) . "\n";
414 <?php
echo xlt('From'); ?
>: 
; 
; 
; 
;
415 <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'>
417 <td
class='label_custom'>
418 <?php
echo xlt('To'); ?
>:
421 <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'>
423 <?php
if($type_form == '0') { ?
>
424 <td
><span
class='label_custom'><?php
echo xlt('Patient'); ?
>: 
; 
;</span
></td
>
426 <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
'); ?>' />
428 <input type
='hidden' name
='form_patient' value
='<?php echo attr($form_patient); ?>' />
430 <input type
='hidden' name
='form_pid' value
='<?php echo attr($form_pid); ?>' />
431 <input type
='hidden' name
='form_dob' value
='<?php echo attr($form_dob); ?>' />
438 <td align
='left' valign
='middle' height
="100%">
439 <table style
='border-left:1px solid; width:100%; height:100%' >
442 <div style
='margin-left:15px'>
443 <a href
='#' class='css_button' onclick
="checkSubmit();" >
444 <span
><?php
echo xlt('Submit'); ?
></span
></a
>
446 <?php
if ($_REQUEST['form_refresh'] ||
$_REQUEST['form_csvexport']) { ?
>
447 <div id
="controls"> <!-- print is patched out until I feel like convert to patient side
-->
448 <!-- <a href
='#' class='css_button' id
='printbutton'>
449 <span
><?php
//echo xlt('Print Ledger'); ?></span></a> -->
450 <?php
if($type_form == '1') { ?
>
451 <!-- <a href
="../patient_file/summary/demographics.php" <?php
// if (!$GLOBALS['concurrent_layout']) echo "target='Main'"; ?> class="css_button" onclick="top.restoreSession()">-->
452 <!-- <span
><?php
//echo xlt('Back To Patient');?></span></a> -->
463 </div
> <!-- end of parameters
-->
467 $from_date = $form_from_date . ' 00:00:00';
468 $to_date = $form_to_date . ' 23:59:59';
469 if ($_REQUEST['form_refresh'] ||
$_REQUEST['form_csvexport']) {
471 $sqlBindArray = array();
472 $query = "select b.code_type, b.code, b.code_text, b.pid, b.provider_id, ".
473 "b.billed, b.payer_id, b.units, b.fee, b.bill_date, b.id, ".
475 "fe.encounter, fe.date, fe.reason, fe.provider_id ".
476 "FROM form_encounter AS fe ".
477 "LEFT JOIN billing AS b ON b.pid=fe.pid AND b.encounter=fe.encounter ".
478 "LEFT JOIN insurance_companies AS ins ON b.payer_id = ins.id ".
479 "LEFT OUTER JOIN code_types AS c ON c.ct_key = b.code_type ".
480 "WHERE fe.date >= ? AND fe.date <= ? AND fe.pid = ? ";
481 array_push($sqlBindArray,$from_date,$to_date,$form_pid);
482 if ($form_facility) {
483 $query .= "AND fe.facility_id = ? ";
484 array_push($sqlBindArray,$form_facility);
486 if ($form_provider) {
487 $query .= "AND b.provider_id = ? ";
488 array_push($sqlBindArray,$form_provider);
490 $query .= "AND c.ct_proc = '1' ";
491 $query .= "AND activity > 0 ORDER BY fe.date, fe.id ";
492 $res = sqlStatement($query,$sqlBindArray);
494 if ($_REQUEST['form_csvexport']) {
497 echo '"Code/Enc Dt",';
498 echo '"Description",';
499 echo '"Billed/Who",';
500 echo '"Type/Units",';
501 echo '"Chg/Pmt Amount",'."\n";
504 if(!$form_facility) $form_facility = '3';
505 $facility = sqlQuery("SELECT * FROM facility WHERE id=?", array($form_facility));
506 $patient = sqlQuery("SELECT * from patient_data WHERE pid=?", array($form_patient));
507 $pat_dob = $patient['DOB'];
508 $pat_name = $patient['fname']. ' ' . $patient['lname'];
510 <div id
="report_header">
511 <table width
="98%" border
="0" cellspacing
="0" cellpadding
="0">
513 <td
class="title" ><?php
echo text($facility{'name'}); ?
></td
>
516 <td
class="title" ><?php
echo text($facility{'street'}); ?
></td
>
519 <td
class="title" ><?php
echo text($facility{'city'}).", ".text($facility{'state'})." ".text($facility{'postal_code'}); ?
></td
>
522 <td
class="title" ><?php
echo xlt('Phone').': ' .text($facility{'phone'}); ?
></td
>
525 <td
class="title" ><?php
echo xlt('Tax Id').': ' .text($facility{'federal_ein'}); ?
></td
>
527 <tr
><td
> 
;</td
></tr
>
529 <td
class="title" ><?php
echo xlt('Patient Ledger'); ?
></td
>
533 $title = xl('All Providers');
534 if($form_provider) { $title = xl('For Provider') . ': '.User_Id_Look($form_provider); }
536 <td
class="title" ><?php
echo text($title); ?
></td
>
540 $title = xl('For Dates') . ': '.$form_from_date.' - '.$form_to_date;
542 <td
class="title" ><?php
echo text($title); ?
></td
>
546 <table width
="100%" border
="0" cellspacing
="0" cellpadding
="0">
548 <td
class='bold' ><?php
echo xlt('Date')?
>:
549 <?php
echo text(date('Y-m-d')); ?
></td
>
550 <td
class='bold' ><?php
echo xlt('Patient')?
>:
551 <?php
if($type_form == '1') { ?
>
552 <?php
echo text($pat_name); ?
></td
>
554 <?php
echo text($form_patient); ?
></td
>
556 <td
class='bold' ><?php
echo xlt('DOB')?
>:
557 <?php
if($type_form == '1') { ?
>
558 <?php
echo text($pat_dob);?
></td
>
560 <?php
echo text($form_dob); ?
></td
>
562 <td
class='bold' > <?php
echo xlt('ID')?
>:
563 <?php
echo text($form_pid);?
></td
>
567 <div id
="report_results">
570 <td
class='bold' ><?php
echo xlt('Code'); ?
></td
>
571 <td colspan
="2" class='bold' ><?php
echo xlt('Description'); ?
></td
>
572 <td
class='bold' ><?php
echo xlt('Billed Date'); ?
> / <?php
echo xlt('Payor'); ?
></td
>
573 <td
class='bold' ><?php
echo xlt('Type'); ?
> 
; 
; 
; 
; 
; 
; 
;
574 <?php
echo xlt('Units'); ?
></td
>
575 <td
class='bold' > 
; 
; 
; 
; 
;<?php
echo xlt('Charge'); ?
></td
>
576 <td align
='right' class='bold' > 
; 
;<?php
echo xlt('Payment'); ?
></td
>
577 <td align
='right' class='bold' > 
; 
; 
; 
; 
;<?php
echo xlt('Adjustment'); ?
></td
>
578 <td align
='right' class='bold' > 
; 
; 
;<?php
echo xlt('Balance'); ?
></td
>
581 <td
> 
; 
; 
;</td
>
582 <td colspan
="2" > 
; 
; 
;</td
>
583 <td
> 
; 
; 
; 
; 
; 
;</td
>
584 <td
> 
; 
; 
; 
; 
; 
; 
; 
;
585  
; 
; 
;</td
>
586 <td
class='bold' > 
; 
; 
;<?php
echo xlt('UAC Appl'); ?
></td
>
587 <td align
='right' class='bold' > 
; 
; 
; 
; 
;<?php
echo xlt('UAC Tot'); ?
></td
>
594 $prev_encounter_id = -1;
595 $hdr_printed = false;
597 while ($erow = sqlFetchArray($res)) {
600 if($erow['encounter'] != $prev_encounter_id) {
601 if($prev_encounter_id != -1) {
602 $credits = GetAllCredits($prev_encounter_id, $form_pid);
603 if(count($credits) > 0) {
605 PrintEncHeader($prev_row{'date'},
606 $prev_row{'reason'}, $prev_row{'provider_id'});
608 PrintCreditDetail($credits, $form_pid);
610 if($hdr_printed) PrintEncFooter();
611 $hdr_printed = false;
613 $enc_units = $enc_chg = $enc_pmt = $enc_adj = $enc_bal = 0;
616 // Now print an encounter heading line -
618 PrintEncHeader($erow{'date'},
619 $erow{'reason'}, $erow{'provider_id'});
623 $code_desc = $erow['code_text'];
624 if(strlen($code_desc) > 50) $code_desc = substr($code_desc,0,50).'...';
625 $bgcolor = (($bgcolor == "#FFFFDD") ?
"#FFDDDD" : "#FFFFDD");
626 $print = "<tr bgcolor='". attr($bgcolor) ."'>";
627 $print .= "<td class='detail'>".text($erow['code'])."</td>";
628 $print .= "<td class='detail' colspan='2'>".text($code_desc)."</td>";
629 $who = ($erow['name'] == '') ?
xl('Self') : $erow['name'];
630 $bill = substr($erow['bill_date'],0,10);
631 if($bill == '') { $bill = 'unbilled'; }
632 $print .= "<td class='detail'>".text($bill)." / ".text($who)."</td>";
633 $print .= "<td class='detail' style='text-align: right;'>". text($erow['units'])."</td>";
634 $print .= "<td class='detail' style='text-align: right;'>". text(oeFormatMoney($erow['fee']))."</td>";
635 $print .= "<td> </td><td> </td><td> </td>";
638 $total_units +
= $erow['units'];
639 $total_chg +
= $erow['fee'];
640 $total_bal +
= $erow['fee'];
641 $enc_units +
= $erow['units'];
642 $enc_chg +
= $erow['fee'];
643 $enc_bal +
= $erow['fee'];
646 if ($_REQUEST['form_csvexport']) {
652 $prev_encounter_id = $erow{'encounter'};
655 if($prev_encounter_id != -1) {
656 $credits = GetAllCredits($prev_encounter_id, $form_pid);
657 if(count($credits) > 0) {
659 PrintEncHeader($prev_row{'date'},
660 $prev_row{'reason'}, $prev_row{'provider_id'});
662 PrintCreditDetail($credits, $form_pid);
664 if($hdr_printed) PrintEncFooter();
666 // This is the end of the encounter/charge loop -
667 $uac = GetAllUnapplied($form_pid,$from_date,$to_date);
668 if(count($uac) > 0) {
670 $bgcolor = (($bgcolor == "#FFFFDD") ?
"#FFDDDD" : "#FFFFDD");
671 echo "<tr bgcolor='#FFFFFF'><td colspan='9'> </td></tr>\n";
673 PrintCreditDetail($uac, $form_pid, true);
675 if (!$_REQUEST['form_csvexport'] && $orow) {
676 echo "<tr bgcolor='#DDFFFF'>\n";
677 echo " <td colspan='2'> </td>";
678 echo " <td class='bold' colspan='2'>" . xlt("Grand Total") ."</td>\n";
679 echo " <td class='bold' style='text-align: right;'>". text($total_units) ."</td>\n";
680 echo " <td class='bold' style='text-align: right;'>". text(oeFormatMoney($total_chg)) ."</td>\n";
681 echo " <td class='bold' style='text-align: right;'>". text(oeFormatMoney($total_pmt)) ."</td>\n";
682 echo " <td class='bold' style='text-align: right;'>". text(oeFormatMoney($total_adj)) ."</td>\n";
683 echo " <td class='bold' style='text-align: right;'>". text(oeFormatMoney($total_bal)) . "</td>\n";
687 <tr
><td
> 
;</td
></tr
><br
><br
>
688 <?php
if($GLOBALS['print_next_appointment_on_ledger'] == 1) {
689 $next_day = mktime(0,0,0,date('m'),date('d')+
1,date('Y'));
690 # add one day to date so it will not get todays appointment
691 $current_date2 = date('Y-m-d', $next_day);
692 $events = fetchNextXAppts($current_date2,$form_pid);
693 $next_appoint_date = oeFormatShortDate($events[0]['pc_eventDate']);
694 $next_appoint_time = substr($events[0]['pc_startTime'],0,5);
695 if(strlen(umname
) != 0 ) {
696 $next_appoint_provider = $events[0]['ufname'] . ' ' . $events[0]['umname'] . ' ' . $events[0]['ulname'];
700 $next_appoint_provider = $events[0]['ufname'] . ' ' . $events[0]['ulname'];
702 if(strlen($next_appoint_time) != 0) {
705 <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
>
710 } // end ($GLOBALS['print_next_appointment_on_ledger'] == 1)
711 } // end (!$_REQUEST['form_csvexport'] && $orow)
714 if (! $_REQUEST['form_csvexport']) {
715 if ( $_REQUEST['form_refresh'] && $orow <= 0) {
716 echo "<span style='font-size:10pt;'>";
717 echo xlt('No matches found. Try search again.');
719 echo '<script>document.getElementById("report_results").style.display="none";</script>';
720 echo '<script>document.getElementById("controls").style.display="none";</script>';
723 if (!$_REQUEST['form_refresh'] && !$_REQUEST['form_csvexport']) { ?
>
725 <?php
echo xlt('Please input search criteria above, and click Submit to view results.' ); ?
>
733 } // End not csv export