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
25 $sanitize_all_escapes=true;
26 $fake_register_globals=false;
27 require_once('../globals.php');
28 require_once($GLOBALS['srcdir'].'/patient.inc');
29 require_once($GLOBALS['srcdir'].'/acl.inc');
30 require_once($GLOBALS['srcdir'].'/formatting.inc.php');
31 require_once($GLOBALS['srcdir'].'/options.inc.php');
32 require_once($GLOBALS['srcdir'].'/appointments.inc.php');
34 $enc_units = $total_units = 0;
35 $enc_chg = $total_chg = 0;
36 $enc_pmt = $total_pmt = 0;
37 $enc_adj = $total_adj = 0;
38 $enc_bal = $total_bal = 0;
42 $pat_pid = $_GET['patient_id'];
43 $type_form = $_GET['form'];
45 if (! acl_check('acct', 'rep')) die(xlt("Unauthorized access."));
47 function GetAllUnapplied($pat='',$from_dt='',$to_dt='') {
49 if(!$pat) return($all);
50 $sql = "SELECT ar_session.*, ins.name, " .
51 "pat.lname, pat.fname, pat.mname, " .
52 "(SELECT SUM(ar_activity.pay_amount) FROM ar_activity WHERE " .
53 "ar_activity.session_id = ar_session.session_id) AS applied " .
55 "LEFT JOIN insurance_companies AS ins on ar_session.payer_id = ins.id " .
56 "LEFT JOIN patient_data AS pat on ar_session.patient_id = pat.pid " .
58 "ar_session.created_time >= ? AND ar_session.created_time <= ? " .
59 "AND ar_session.patient_id=?";
60 $result = sqlStatement($sql, array($from_dt, $to_dt, $pat));
62 while($row = sqlFetchArray($result)) {
69 function User_Id_Look($thisField) {
70 if(!$thisField) return '';
72 $rlist= sqlStatement("SELECT lname, fname, mname FROM users WHERE id=?",array($thisField));
73 $rrow= sqlFetchArray($rlist);
75 $ret = $rrow{'lname'}.', '.$rrow{'fname'}.' '.$rrow{'mname'};
80 function List_Look($thisData, $thisList) {
81 if($thisList == 'occurrence') {
82 if(!$thisData ||
$thisData == '') return xl('Unknown or N/A');
84 if($thisData == '') return '';
85 $fres=sqlStatement("SELECT title FROM list_options WHERE list_id = ? ".
86 "AND option_id = ? AND activity = 1", array($thisList, $thisData));
88 $rret=sqlFetchArray($fres);
89 $dispValue= xl_list_label($rret{'title'});
90 if($thisList == 'occurrence' && $dispValue == '') {
91 $dispValue = xl('Unknown or N/A');
94 $dispValue= xl('Not Found');
99 function GetAllCredits($enc = '', $pat='') {
101 if(!$enc ||
!$pat) return($all);
102 $sql = "SELECT activity.*, session.*, ins.name FROM ar_activity AS ".
103 "activity LEFT JOIN ar_session AS session USING (session_id) ".
104 "LEFT JOIN insurance_companies AS ins ON session.payer_id = ".
105 "ins.id WHERE encounter=? AND pid=? ".
106 "ORDER BY sequence_no";
107 $result = sqlStatement($sql, array($enc, $pat));
109 while($row = sqlFetchArray($result)) {
115 function PrintEncHeader($dt, $rsn, $dr) {
116 global $bgcolor, $orow;
117 $bgcolor = (($bgcolor == "#FFFFDD") ?
"#FFDDDD" : "#FFFFDD");
118 echo "<tr bgcolor='#FFFFFF'>";
119 if(strlen($rsn) > 50) $rsn = substr($rsn,0,50).'...';
120 echo "<td colspan='4'><span class='bold'>".xlt('Encounter Dt / Rsn'). ": </span><span class='detail'>".text(substr($dt,0,10))." / ".text($rsn)."</span></td>";
121 echo "<td colspan='5'><span class='bold'>" . xlt('Provider'). ": </span><span class='detail'>".text(User_Id_Look($dr))."</span></td>";
125 function PrintEncFooter() {
126 global $enc_units, $enc_chg, $enc_pmt, $enc_adj, $enc_bal;
127 echo "<tr bgcolor='#DDFFFF'>";
128 echo "<td colspan='3'> </td>";
129 echo "<td class='detail'>". xlt('Encounter Balance').":</td>";
130 echo "<td class='detail' style='text-align: right;'>".text($enc_units)."</td>";
131 echo "<td class='detail' style='text-align: right;'>".text(oeFormatMoney($enc_chg))."</td>";
132 echo "<td class='detail' style='text-align: right;'>".text(oeFormatMoney($enc_pmt))."</td>";
133 echo "<td class='detail' style='text-align: right;'>".text(oeFormatMoney($enc_adj))."</td>";
134 echo "<td class='detail' style='text-align: right;'>".text(oeFormatMoney($enc_bal))."</td>";
137 function PrintCreditDetail($detail, $pat, $unassigned=false) {
138 global $enc_pmt, $total_pmt, $enc_adj, $total_adj, $enc_bal, $total_bal;
139 global $bgcolor, $orow, $enc_units, $enc_chg;
140 foreach($detail as $pmt) {
142 if(($pmt['pay_total'] - $pmt['applied']) == 0) continue;
144 $bgcolor = (($bgcolor == "#FFFFDD") ?
"#FFDDDD" : "#FFFFDD");
145 $print = "<tr bgcolor='" . attr($bgcolor) . "'>";
146 $print .= "<td class='detail'> </td>";
147 $method = List_Look($pmt['payment_method'],'payment_method');
148 $desc = $pmt['description'];
149 $ref = $pmt['reference'];
151 $memo = List_Look($pmt['adjustment_code'],'payment_adjustment_code');
153 $memo = $pmt['memo'];
155 $description = $method;
157 if($description) { $description .= ' - '; }
158 $description .= $ref;
161 if($description) { $description .= ': '; }
162 $description .= $desc;
165 if($description) { $description .= ' '; }
166 $description .= '['.$memo.']';
168 $print .= "<td class='detail' colspan='2'>".
169 text($description)." </td>";
170 $payer = ($pmt['name'] == '') ?
xl('Patient') : $pmt['name'];
172 $pmt_date = substr($pmt['post_to_date'],0,10);
174 $pmt_date = substr($pmt['post_time'],0,10);
176 $print .= "<td class='detail'>".
177 text($pmt_date)." / ".text($payer)."</td>";
178 $type = List_Look($pmt['payment_type'],'payment_type');
179 $print .= "<td class='detail'>".text($type)." </td>";
181 $pmt_amt = $pmt['pay_total'] - $pmt['applied'];
182 $uac_bal = oeFormatMoney($pmt_amt * -1);
183 $uac_appl = oeFormatMoney($pmt['applied']);
184 $uac_total = oeFormatMoney($pmt['pay_total']);
185 $pmt_amt = $pmt['pay_total'];
186 $total_pmt = $total_pmt - $uac_bal;
191 $pmt_amt = $pmt['pay_amount'];
192 $adj_amt = $pmt['adj_amount'];
193 $enc_pmt = $enc_pmt +
$pmt['pay_amount'];
194 $total_pmt = $total_pmt +
$pmt['pay_amount'];
195 $enc_adj = $enc_adj +
$pmt['adj_amount'];
196 $total_adj = $total_adj +
$pmt['adj_amount'];
199 if($pmt_amt != 0) $print_pmt = oeFormatMoney($pmt_amt);
201 if($adj_amt != 0) $print_adj = oeFormatMoney($adj_amt);
202 $print .= "<td class='detail' style='text-align: right;'>".text($uac_appl)." </td>";
203 $print .= "<td class='detail' style='text-align: right;'>".text($print_pmt)." </td>";
204 $print .= "<td class='detail' style='text-align: right;'>".text($print_adj)." </td>";
205 $print .= "<td class='detail' style='text-align: right;'>".text($uac_bal)." </td>";
208 if($pmt['follow_up_note'] != '') {
209 $bgcolor = (($bgcolor == "#FFFFDD") ?
"#FFDDDD" : "#FFFFDD");
210 $print = "<tr bgcolor='". attr($bgcolor) ."'>";
211 $print .= "<td class='detail' colspan='2'> </td>";
212 $print .= "<td colspan='7'>". xlt('Follow Up Note') .": ";
213 $print .= text($pmt['follow_up_note']);
214 $print .= "</td></tr>\n";
218 $total_bal = $total_bal +
$uac_bal;
220 $enc_bal = $enc_bal - $pmt_amt - $adj_amt;
221 $total_bal = $total_bal - $pmt_amt - $adj_amt;
225 $bgcolor = (($bgcolor == "#FFFFDD") ?
"#FFDDDD" : "#FFFFDD");
227 if(!isset($_REQUEST['form_from_date'])) { $_REQUEST['form_from_date'] = ''; }
228 if(!isset($_REQUEST['form_to_date'])) { $_REQUEST['form_to_date'] = ''; }
229 if(!isset($_REQUEST['form_facility'])) { $_REQUEST['form_facility'] = ''; }
230 if(!isset($_REQUEST['form_provider'])) { $_REQUEST['form_provider'] = ''; }
231 if($type_form=='0') {
232 if(!isset($_REQUEST['form_patient'])) { $_REQUEST['form_patient'] = ''; }
233 if(!isset($_REQUEST['form_pid'])) { $_REQUEST['form_pid'] = ''; }
237 if(!isset($_REQUEST['form_patient'])) { $_REQUEST['form_patient'] = $pat_pid; }
238 if(!isset($_REQUEST['form_pid'])) { $_REQUEST['form_pid'] = $pat_pid; }
240 if(!isset($_REQUEST['form_csvexport'])) { $_REQUEST['form_csvexport'] = ''; }
241 if(!isset($_REQUEST['form_refresh'])) { $_REQUEST['form_refresh'] = ''; }
242 if(!isset($_REQUEST['$form_dob'])) { $_REQUEST['$form_dob'] = ''; }
244 if (substr($GLOBALS['ledger_begin_date'],0,1) == 'Y') {
245 $ledger_time = substr($GLOBALS['ledger_begin_date'],1,1);
246 $last_year = mktime(0,0,0,date('m'),date('d'),date('Y')-$ledger_time);
248 elseif (substr($GLOBALS['ledger_begin_date'],0,1) == 'M') {
249 $ledger_time = substr($GLOBALS['ledger_begin_date'],1,1);
250 $last_year = mktime(0,0,0,date('m')-$ledger_time ,date('d'),date('Y'));
252 elseif (substr($GLOBALS['ledger_begin_date'],0,1) == 'D') {
253 $ledger_time = substr($GLOBALS['ledger_begin_date'],1,1);
254 $last_year = mktime(0,0,0,date('m') ,date('d')-$ledger_time,date('Y'));
257 $form_from_date = date('Y-m-d', $last_year);
258 if($_REQUEST['form_from_date']) {
259 $form_from_date = fixDate($_REQUEST['form_from_date'], $last_year);
261 $form_to_date = fixDate($_REQUEST['form_to_date'] , date('Y-m-d'));
262 $form_facility = $_REQUEST['form_facility'];
263 $form_provider = $_REQUEST['form_provider'];
264 $form_patient = $_REQUEST['form_patient'];
265 $form_pid = $_REQUEST['form_pid'];
266 $form_dob = $_REQUEST['form_dob'];
268 if ($_REQUEST['form_csvexport']) {
269 header("Pragma: public");
270 header("Expires: 0");
271 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
272 header("Content-Type: application/force-download");
273 header("Content-Disposition: attachment; filename=svc_financial_report_".attr($form_from_date)."--".attr($form_to_date).".csv");
274 header("Content-Description: File Transfer");
279 <link rel
="stylesheet" href
="<?php echo $css_header;?>" type
="text/css">
280 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js?v=<?php echo $v_js_includes; ?>"></script
>
281 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-3-2/index.js"></script
>
282 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/js/common.js"></script
>
283 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery-ui.js"></script
>
284 <script type
="text/javascript">
285 var mypcc
= '<?php echo $GLOBALS['phone_country_code
']; ?>';
288 function checkSubmit() {
289 var pat
= document
.forms
[0].elements
['form_patient'].value
;
290 if(!pat || pat
== 0) {
291 alert('<?php echo xls('A Patient Must Be Selected to Generate This Report
') ?>');
294 document
.forms
[0].elements
['form_refresh'].value
= true;
295 document
.forms
[0].elements
['form_csvexport'].value
= '';
296 document
.forms
[0].submit();
298 function setpatient(pid
, lname
, fname
, dob
) {
299 document
.forms
[0].elements
['form_patient'].value
= lname +
', ' + fname
;
300 document
.forms
[0].elements
['form_pid'].value
= pid
;
301 document
.forms
[0].elements
['form_dob'].value
= dob
;
303 function sel_patient() {
304 dlgopen('../main/calendar/find_patient_popup.php?pflag=0', '_blank', 500, 400);
308 <link rel
="stylesheet" href
="<?php echo $css_header;?>" type
="text/css">
309 <?php
html_header_show();?
>
310 <style type
="text/css">
312 /* specifically include & exclude from printing */
318 #report_parameters_daterange {
334 /* specifically exclude some from the screen */
336 #report_parameters_daterange {
351 <title
><?php
echo xlt('Patient Ledger by Date') ?
></title
>
353 <script language
="JavaScript">
354 $
(document
).ready(function() {
355 var win
= top
.printLogSetup ? top
: opener
.top
;
356 win
.printLogSetup(document
.getElementById('printbutton'));
361 <body
class="body_top">
362 <?php
if($type_form == '0') { ?
>
363 <span
class='title' id
='title'><?php
echo xlt('Report'); ?
> - <?php
echo xlt('Patient Ledger by Date'); ?
></span
>
365 <span
class='title' id
='title'><?php
echo xlt('Patient Ledger'); ?
></span
>
367 <form method
='post' action
='pat_ledger.php?form=<?php echo attr($type_form);?>&patient_id=<?php echo attr($form_pid);?>' id
='theform'>
368 <div id
="report_parameters">
369 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
370 <input type
='hidden' name
='form_csvexport' id
='form_csvexport' value
=''/>
373 <?php
if($type_form == '1') { ?
>
378 <div style
='float:left'>
381 <?php
if($type_form == '0') { ?
>
383 <?php
echo xlt('Facility'); ?
>:
386 <?php
dropdown_facility($form_facility, 'form_facility', true); ?
>
388 <td
><?php
echo xlt('Provider'); ?
>:</td
>
390 $query = "SELECT id, lname, fname FROM users WHERE ".
391 "authorized=1 AND active!=0 ORDER BY lname, fname";
392 $ures = sqlStatement($query);
393 echo " <select name='form_provider'>\n";
394 echo " <option value=''>-- " . xlt('All') . " --\n";
395 while ($urow = sqlFetchArray($ures)) {
396 $provid = $urow['id'];
397 echo " <option value='" . attr($provid) ."'";
398 if ($provid == $_REQUEST['form_provider']) echo " selected";
399 echo ">" . text($urow['lname']) . ", " . text($urow['fname']) . "\n";
406 <?php
echo xlt('From'); ?
>: 
; 
; 
; 
;
407 <input type
='text' name
='form_from_date' id
="form_from_date" size
='10' value
='<?php echo attr($form_from_date) ?>' onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' title
='yyyy-mm-dd'>
408 <img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22' id
='img_from_date' border
='0' alt
='[?]' style
='cursor:pointer' title
='<?php echo xla("Click here to choose a date"); ?>'>
411 <?php
echo xlt('To'); ?
>:
414 <input type
='text' name
='form_to_date' id
="form_to_date" size
='10' value
='<?php echo attr($form_to_date) ?>' onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' title
='yyyy-mm-dd'>
415 <img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22' id
='img_to_date' border
='0' alt
='[?]' style
='cursor:pointer' title
='<?php echo xla("Click here to choose a date"); ?>'>
417 <?php
if($type_form == '0') { ?
>
418 <td
><span
class='label'><?php
echo xlt('Patient'); ?
>: 
; 
;</span
></td
>
420 <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
'); ?>' />
422 <input type
='hidden' name
='form_patient' value
='<?php echo attr($form_patient); ?>' />
424 <input type
='hidden' name
='form_pid' value
='<?php echo attr($form_pid); ?>' />
425 <input type
='hidden' name
='form_dob' value
='<?php echo attr($form_dob); ?>' />
432 <td align
='left' valign
='middle' height
="100%">
433 <table style
='border-left:1px solid; width:100%; height:100%' >
436 <div style
='margin-left:15px'>
437 <a href
='#' class='css_button' onclick
="checkSubmit();" >
438 <span
><?php
echo xlt('Submit'); ?
></span
></a
>
440 <?php
if ($_REQUEST['form_refresh'] ||
$_REQUEST['form_csvexport']) { ?
>
442 <a href
='#' class='css_button' id
='printbutton'>
443 <span
><?php
echo xlt('Print Ledger'); ?
></span
></a
>
444 <?php
if($type_form == '1') { ?
>
445 <a href
="../patient_file/summary/demographics.php" class="css_button" onclick
="top.restoreSession()">
446 <span
><?php
echo xlt('Back To Patient');?
></span
></a
>
457 </div
> <!-- end of parameters
-->
461 $from_date = $form_from_date . ' 00:00:00';
462 $to_date = $form_to_date . ' 23:59:59';
463 if ($_REQUEST['form_refresh'] ||
$_REQUEST['form_csvexport']) {
465 $sqlBindArray = array();
466 $query = "select b.code_type, b.code, b.code_text, b.pid, b.provider_id, ".
467 "b.billed, b.payer_id, b.units, b.fee, b.bill_date, b.id, ".
469 "fe.encounter, fe.date, fe.reason, fe.provider_id ".
470 "FROM form_encounter AS fe ".
471 "LEFT JOIN billing AS b ON b.pid=fe.pid AND b.encounter=fe.encounter ".
472 "LEFT JOIN insurance_companies AS ins ON b.payer_id = ins.id ".
473 "LEFT OUTER JOIN code_types AS c ON c.ct_key = b.code_type ".
474 "WHERE fe.date >= ? AND fe.date <= ? AND fe.pid = ? ";
475 array_push($sqlBindArray,$from_date,$to_date,$form_pid);
476 if ($form_facility) {
477 $query .= "AND fe.facility_id = ? ";
478 array_push($sqlBindArray,$form_facility);
480 if ($form_provider) {
481 $query .= "AND b.provider_id = ? ";
482 array_push($sqlBindArray,$form_provider);
484 $query .= "AND c.ct_proc = '1' ";
485 $query .= "AND activity > 0 ORDER BY fe.date, fe.id ";
486 $res = sqlStatement($query,$sqlBindArray);
488 if ($_REQUEST['form_csvexport']) {
491 echo '"Code/Enc Dt",';
492 echo '"Description",';
493 echo '"Billed/Who",';
494 echo '"Type/Units",';
495 echo '"Chg/Pmt Amount",'."\n";
498 if(!$form_facility) $form_facility = '3';
499 $facility = sqlQuery("SELECT * FROM facility WHERE id=?", array($form_facility));
500 $patient = sqlQuery("SELECT * from patient_data WHERE pid=?", array($form_patient));
501 $pat_dob = $patient['DOB'];
502 $pat_name = $patient['fname']. ' ' . $patient['lname'];
504 <div id
="report_header">
505 <table width
="98%" border
="0" cellspacing
="0" cellpadding
="0">
507 <td
class="title" ><?php
echo text($facility{'name'}); ?
></td
>
510 <td
class="title" ><?php
echo text($facility{'street'}); ?
></td
>
513 <td
class="title" ><?php
echo text($facility{'city'}).", ".text($facility{'state'})." ".text($facility{'postal_code'}); ?
></td
>
516 <td
class="title" ><?php
echo xlt('Phone').': ' .text($facility{'phone'}); ?
></td
>
519 <td
class="title" ><?php
echo xlt('Tax Id').': ' .text($facility{'federal_ein'}); ?
></td
>
521 <tr
><td
> 
;</td
></tr
>
523 <td
class="title" ><?php
echo xlt('Patient Ledger'); ?
></td
>
527 $title = xl('All Providers');
528 if($form_provider) { $title = xl('For Provider') . ': '.User_Id_Look($form_provider); }
530 <td
class="title" ><?php
echo text($title); ?
></td
>
534 $title = xl('For Dates') . ': '.$form_from_date.' - '.$form_to_date;
536 <td
class="title" ><?php
echo text($title); ?
></td
>
540 <table width
="100%" border
="0" cellspacing
="0" cellpadding
="0">
542 <td
class='bold' ><?php
echo xlt('Date')?
>:
543 <?php
echo text(date('Y-m-d')); ?
></td
>
544 <td
class='bold' ><?php
echo xlt('Patient')?
>:
545 <?php
if($type_form == '1') { ?
>
546 <?php
echo text($pat_name); ?
></td
>
548 <?php
echo text($form_patient); ?
></td
>
550 <td
class='bold' ><?php
echo xlt('DOB')?
>:
551 <?php
if($type_form == '1') { ?
>
552 <?php
echo text($pat_dob);?
></td
>
554 <?php
echo text($form_dob); ?
></td
>
556 <td
class='bold' > <?php
echo xlt('ID')?
>:
557 <?php
echo text($form_pid);?
></td
>
561 <div id
="report_results">
564 <td
class='bold' ><?php
echo xlt('Code'); ?
></td
>
565 <td colspan
="2" class='bold' ><?php
echo xlt('Description'); ?
></td
>
566 <td
class='bold' ><?php
echo xlt('Billed Date'); ?
> / <?php
echo xlt('Payor'); ?
></td
>
567 <td
class='bold' ><?php
echo xlt('Type'); ?
> 
; 
; 
; 
; 
; 
; 
;
568 <?php
echo xlt('Units'); ?
></td
>
569 <td
class='bold' > 
; 
; 
; 
; 
;<?php
echo xlt('Charge'); ?
></td
>
570 <td align
='right' class='bold' > 
; 
;<?php
echo xlt('Payment'); ?
></td
>
571 <td align
='right' class='bold' > 
; 
; 
; 
; 
;<?php
echo xlt('Adjustment'); ?
></td
>
572 <td align
='right' class='bold' > 
; 
; 
;<?php
echo xlt('Balance'); ?
></td
>
575 <td
> 
; 
; 
;</td
>
576 <td colspan
="2" > 
; 
; 
;</td
>
577 <td
> 
; 
; 
; 
; 
; 
;</td
>
578 <td
> 
; 
; 
; 
; 
; 
; 
; 
;
579  
; 
; 
;</td
>
580 <td
class='bold' > 
; 
; 
;<?php
echo xlt('UAC Appl'); ?
></td
>
581 <td align
='right' class='bold' > 
; 
; 
; 
; 
;<?php
echo xlt('UAC Tot'); ?
></td
>
588 $prev_encounter_id = -1;
589 $hdr_printed = false;
591 while ($erow = sqlFetchArray($res)) {
594 if($erow['encounter'] != $prev_encounter_id) {
595 if($prev_encounter_id != -1) {
596 $credits = GetAllCredits($prev_encounter_id, $form_pid);
597 if(count($credits) > 0) {
599 PrintEncHeader($prev_row{'date'},
600 $prev_row{'reason'}, $prev_row{'provider_id'});
602 PrintCreditDetail($credits, $form_pid);
604 if($hdr_printed) PrintEncFooter();
605 $hdr_printed = false;
607 $enc_units = $enc_chg = $enc_pmt = $enc_adj = $enc_bal = 0;
610 // Now print an encounter heading line -
612 PrintEncHeader($erow{'date'},
613 $erow{'reason'}, $erow{'provider_id'});
617 $code_desc = $erow['code_text'];
618 if(strlen($code_desc) > 50) $code_desc = substr($code_desc,0,50).'...';
619 $bgcolor = (($bgcolor == "#FFFFDD") ?
"#FFDDDD" : "#FFFFDD");
620 $print = "<tr bgcolor='". attr($bgcolor) ."'>";
621 $print .= "<td class='detail'>".text($erow['code'])."</td>";
622 $print .= "<td class='detail' colspan='2'>".text($code_desc)."</td>";
623 $who = ($erow['name'] == '') ?
xl('Self') : $erow['name'];
624 $bill = substr($erow['bill_date'],0,10);
625 if($bill == '') { $bill = 'unbilled'; }
626 $print .= "<td class='detail'>".text($bill)." / ".text($who)."</td>";
627 $print .= "<td class='detail' style='text-align: right;'>". text($erow['units'])."</td>";
628 $print .= "<td class='detail' style='text-align: right;'>". text(oeFormatMoney($erow['fee']))."</td>";
629 $print .= "<td> </td><td> </td><td> </td>";
632 $total_units +
= $erow['units'];
633 $total_chg +
= $erow['fee'];
634 $total_bal +
= $erow['fee'];
635 $enc_units +
= $erow['units'];
636 $enc_chg +
= $erow['fee'];
637 $enc_bal +
= $erow['fee'];
640 if ($_REQUEST['form_csvexport']) {
646 $prev_encounter_id = $erow{'encounter'};
649 if($prev_encounter_id != -1) {
650 $credits = GetAllCredits($prev_encounter_id, $form_pid);
651 if(count($credits) > 0) {
653 PrintEncHeader($prev_row{'date'},
654 $prev_row{'reason'}, $prev_row{'provider_id'});
656 PrintCreditDetail($credits, $form_pid);
658 if($hdr_printed) PrintEncFooter();
660 // This is the end of the encounter/charge loop -
661 $uac = GetAllUnapplied($form_pid,$from_date,$to_date);
662 if(count($uac) > 0) {
664 $bgcolor = (($bgcolor == "#FFFFDD") ?
"#FFDDDD" : "#FFFFDD");
665 echo "<tr bgcolor='#FFFFFF'><td colspan='9'> </td></tr>\n";
667 PrintCreditDetail($uac, $form_pid, true);
669 if (!$_REQUEST['form_csvexport'] && $orow) {
670 echo "<tr bgcolor='#DDFFFF'>\n";
671 echo " <td colspan='2'> </td>";
672 echo " <td class='bold' colspan='2'>" . xlt("Grand Total") ."</td>\n";
673 echo " <td class='bold' style='text-align: right;'>". text($total_units) ."</td>\n";
674 echo " <td class='bold' style='text-align: right;'>". text(oeFormatMoney($total_chg)) ."</td>\n";
675 echo " <td class='bold' style='text-align: right;'>". text(oeFormatMoney($total_pmt)) ."</td>\n";
676 echo " <td class='bold' style='text-align: right;'>". text(oeFormatMoney($total_adj)) ."</td>\n";
677 echo " <td class='bold' style='text-align: right;'>". text(oeFormatMoney($total_bal)) . "</td>\n";
681 <tr
><td
> 
;</td
></tr
><br
><br
>
682 <?php
if($GLOBALS['print_next_appointment_on_ledger'] == 1) {
683 $next_day = mktime(0,0,0,date('m'),date('d')+
1,date('Y'));
684 # add one day to date so it will not get todays appointment
685 $current_date2 = date('Y-m-d', $next_day);
686 $events = fetchNextXAppts($current_date2,$form_pid);
687 $next_appoint_date = oeFormatShortDate($events[0]['pc_eventDate']);
688 $next_appoint_time = substr($events[0]['pc_startTime'],0,5);
689 if(strlen(umname
) != 0 ) {
690 $next_appoint_provider = $events[0]['ufname'] . ' ' . $events[0]['umname'] . ' ' . $events[0]['ulname'];
694 $next_appoint_provider = $events[0]['ufname'] . ' ' . $events[0]['ulname'];
696 if(strlen($next_appoint_time) != 0) {
699 <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
>
704 } // end ($GLOBALS['print_next_appointment_on_ledger'] == 1)
705 } // end (!$_REQUEST['form_csvexport'] && $orow)
708 if (! $_REQUEST['form_csvexport']) {
709 if ( $_REQUEST['form_refresh'] && $orow <= 0) {
710 echo "<span style='font-size:10pt;'>";
711 echo xlt('No matches found. Try search again.');
713 echo '<script>document.getElementById("report_results").style.display="none";</script>';
714 echo '<script>document.getElementById("controls").style.display="none";</script>';
717 if (!$_REQUEST['form_refresh'] && !$_REQUEST['form_csvexport']) { ?
>
719 <?php
echo xlt('Please input search criteria above, and click Submit to view results.' ); ?
>
725 <!-- stuff
for the popup calendar
-->
727 <link rel
='stylesheet' href
='<?php echo $css_header ?>' type
='text/css'>
728 <style type
="text/css">@import
url(../../library
/dynarch_calendar
.css
);</style
>
729 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot']; ?>/library/dynarch_calendar.js"></script
>
730 <?php
include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?
>
731 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot']; ?>/library/dynarch_calendar_setup.js"></script
>
732 <script language
="Javascript">
733 Calendar
.setup({inputField
:"form_from_date", ifFormat
:"%Y-%m-%d", button
:"img_from_date"});
734 Calendar
.setup({inputField
:"form_to_date", ifFormat
:"%Y-%m-%d", button
:"img_to_date"});
735 top
.restoreSession();
739 } // End not csv export