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'].'/formdata.inc.php');
33 require_once($GLOBALS['srcdir'].'/appointments.inc.php');
35 $enc_units = $total_units = 0;
36 $enc_chg = $total_chg = 0;
37 $enc_pmt = $total_pmt = 0;
38 $enc_adj = $total_adj = 0;
39 $enc_bal = $total_bal = 0;
43 $pat_pid = $_GET['patient_id'];
44 $type_form = $_GET['form'];
46 if (! acl_check('acct', 'rep')) die(xlt("Unauthorized access."));
48 function GetAllUnapplied($pat='',$from_dt='',$to_dt='') {
50 if(!$pat) return($all);
51 $sql = "SELECT ar_session.*, ins.name, " .
52 "pat.lname, pat.fname, pat.mname, " .
53 "(SELECT SUM(ar_activity.pay_amount) FROM ar_activity WHERE " .
54 "ar_activity.session_id = ar_session.session_id) AS applied " .
56 "LEFT JOIN insurance_companies AS ins on ar_session.payer_id = ins.id " .
57 "LEFT JOIN patient_data AS pat on ar_session.patient_id = pat.pid " .
59 "ar_session.created_time >= ? AND ar_session.created_time <= ? " .
60 "AND ar_session.patient_id=?";
61 $result = sqlStatement($sql, array($from_dt, $to_dt, $pat));
63 while($row = sqlFetchArray($result)) {
70 function User_Id_Look($thisField) {
71 if(!$thisField) return '';
73 $rlist= sqlStatement("SELECT lname, fname, mname FROM users WHERE id=?",array($thisField));
74 $rrow= sqlFetchArray($rlist);
76 $ret = $rrow{'lname'}.', '.$rrow{'fname'}.' '.$rrow{'mname'};
81 function List_Look($thisData, $thisList) {
82 if($thisList == 'occurrence') {
83 if(!$thisData ||
$thisData == '') return xl('Unknown or N/A');
85 if($thisData == '') return '';
86 $fres=sqlStatement("SELECT title FROM list_options WHERE list_id=? ".
87 "AND option_id=?", array($thisList, $thisData));
89 $rret=sqlFetchArray($fres);
90 $dispValue= xl_list_label($rret{'title'});
91 if($thisList == 'occurrence' && $dispValue == '') {
92 $dispValue = xl('Unknown or N/A');
95 $dispValue= xl('Not Found');
100 function GetAllCredits($enc = '', $pat='') {
102 if(!$enc ||
!$pat) return($all);
103 $sql = "SELECT activity.*, session.*, ins.name FROM ar_activity AS ".
104 "activity LEFT JOIN ar_session AS session USING (session_id) ".
105 "LEFT JOIN insurance_companies AS ins ON session.payer_id = ".
106 "ins.id WHERE encounter=? AND pid=? ".
107 "ORDER BY sequence_no";
108 $result = sqlStatement($sql, array($enc, $pat));
110 while($row = sqlFetchArray($result)) {
116 function PrintEncHeader($dt, $rsn, $dr) {
117 global $bgcolor, $orow;
118 $bgcolor = (($bgcolor == "#FFFFDD") ?
"#FFDDDD" : "#FFFFDD");
119 echo "<tr bgcolor='#FFFFFF'>";
120 if(strlen($rsn) > 50) $rsn = substr($rsn,0,50).'...';
121 echo "<td colspan='4'><span class='bold'>".xlt('Encounter Dt / Rsn'). ": </span><span class='detail'>".text(substr($dt,0,10))." / ".text($rsn)."</span></td>";
122 echo "<td colspan='5'><span class='bold'>" . xlt('Provider'). ": </span><span class='detail'>".text(User_Id_Look($dr))."</span></td>";
126 function PrintEncFooter() {
127 global $enc_units, $enc_chg, $enc_pmt, $enc_adj, $enc_bal;
128 echo "<tr bgcolor='#DDFFFF'>";
129 echo "<td colspan='3'> </td>";
130 echo "<td class='detail'>". xlt('Encounter Balance').":</td>";
131 echo "<td class='detail' style='text-align: right;'>".text($enc_units)."</td>";
132 echo "<td class='detail' style='text-align: right;'>".text(oeFormatMoney($enc_chg))."</td>";
133 echo "<td class='detail' style='text-align: right;'>".text(oeFormatMoney($enc_pmt))."</td>";
134 echo "<td class='detail' style='text-align: right;'>".text(oeFormatMoney($enc_adj))."</td>";
135 echo "<td class='detail' style='text-align: right;'>".text(oeFormatMoney($enc_bal))."</td>";
138 function PrintCreditDetail($detail, $pat, $unassigned=false) {
139 global $enc_pmt, $total_pmt, $enc_adj, $total_adj, $enc_bal, $total_bal;
140 global $bgcolor, $orow, $enc_units, $enc_chg;
141 foreach($detail as $pmt) {
143 if(($pmt['pay_total'] - $pmt['applied']) == 0) continue;
145 $bgcolor = (($bgcolor == "#FFFFDD") ?
"#FFDDDD" : "#FFFFDD");
146 $print = "<tr bgcolor='" . attr($bgcolor) . "'>";
147 $print .= "<td class='detail'> </td>";
148 $method = List_Look($pmt['payment_method'],'payment_method');
149 $desc = $pmt['description'];
150 $ref = $pmt['reference'];
152 $memo = List_Look($pmt['adjustment_code'],'payment_adjustment_code');
154 $memo = $pmt['memo'];
156 $description = $method;
158 if($description) { $description .= ' - '; }
159 $description .= $ref;
162 if($description) { $description .= ': '; }
163 $description .= $desc;
166 if($description) { $description .= ' '; }
167 $description .= '['.$memo.']';
169 $print .= "<td class='detail' colspan='2'>".
170 text($description)." </td>";
171 $payer = ($pmt['name'] == '') ?
xl('Patient') : $pmt['name'];
173 $pmt_date = substr($pmt['post_to_date'],0,10);
175 $pmt_date = substr($pmt['post_time'],0,10);
177 $print .= "<td class='detail'>".
178 text($pmt_date)." / ".text($payer)."</td>";
179 $type = List_Look($pmt['payment_type'],'payment_type');
180 $print .= "<td class='detail'>".text($type)." </td>";
182 $pmt_amt = $pmt['pay_total'] - $pmt['applied'];
183 $uac_bal = oeFormatMoney($pmt_amt * -1);
184 $uac_appl = oeFormatMoney($pmt['applied']);
185 $uac_total = oeFormatMoney($pmt['pay_total']);
186 $pmt_amt = $pmt['pay_total'];
187 $total_pmt = $total_pmt - $uac_bal;
192 $pmt_amt = $pmt['pay_amount'];
193 $adj_amt = $pmt['adj_amount'];
194 $enc_pmt = $enc_pmt +
$pmt['pay_amount'];
195 $total_pmt = $total_pmt +
$pmt['pay_amount'];
196 $enc_adj = $enc_adj +
$pmt['adj_amount'];
197 $total_adj = $total_adj +
$pmt['adj_amount'];
200 if($pmt_amt != 0) $print_pmt = oeFormatMoney($pmt_amt);
202 if($adj_amt != 0) $print_adj = oeFormatMoney($adj_amt);
203 $print .= "<td class='detail' style='text-align: right;'>".text($uac_appl)." </td>";
204 $print .= "<td class='detail' style='text-align: right;'>".text($print_pmt)." </td>";
205 $print .= "<td class='detail' style='text-align: right;'>".text($print_adj)." </td>";
206 $print .= "<td class='detail' style='text-align: right;'>".text($uac_bal)." </td>";
209 if($pmt['follow_up_note'] != '') {
210 $bgcolor = (($bgcolor == "#FFFFDD") ?
"#FFDDDD" : "#FFFFDD");
211 $print = "<tr bgcolor='". attr($bgcolor) ."'>";
212 $print .= "<td class='detail' colspan='2'> </td>";
213 $print .= "<td colspan='7'>". xlt('Follow Up Note') .": ";
214 $print .= text($pmt['follow_up_note']);
215 $print .= "</td></tr>\n";
219 $total_bal = $total_bal +
$uac_bal;
221 $enc_bal = $enc_bal - $pmt_amt - $adj_amt;
222 $total_bal = $total_bal - $pmt_amt - $adj_amt;
226 $bgcolor = (($bgcolor == "#FFFFDD") ?
"#FFDDDD" : "#FFFFDD");
228 if(!isset($_REQUEST['form_from_date'])) { $_REQUEST['form_from_date'] = ''; }
229 if(!isset($_REQUEST['form_to_date'])) { $_REQUEST['form_to_date'] = ''; }
230 if(!isset($_REQUEST['form_facility'])) { $_REQUEST['form_facility'] = ''; }
231 if(!isset($_REQUEST['form_provider'])) { $_REQUEST['form_provider'] = ''; }
232 if($type_form=='0') {
233 if(!isset($_REQUEST['form_patient'])) { $_REQUEST['form_patient'] = ''; }
234 if(!isset($_REQUEST['form_pid'])) { $_REQUEST['form_pid'] = ''; }
238 if(!isset($_REQUEST['form_patient'])) { $_REQUEST['form_patient'] = $pat_pid; }
239 if(!isset($_REQUEST['form_pid'])) { $_REQUEST['form_pid'] = $pat_pid; }
241 if(!isset($_REQUEST['form_csvexport'])) { $_REQUEST['form_csvexport'] = ''; }
242 if(!isset($_REQUEST['form_refresh'])) { $_REQUEST['form_refresh'] = ''; }
243 if(!isset($_REQUEST['$form_dob'])) { $_REQUEST['$form_dob'] = ''; }
245 if (substr($GLOBALS['ledger_begin_date'],0,1) == 'Y') {
246 $ledger_time = substr($GLOBALS['ledger_begin_date'],1,1);
247 $last_year = mktime(0,0,0,date('m'),date('d'),date('Y')-$ledger_time);
249 elseif (substr($GLOBALS['ledger_begin_date'],0,1) == 'M') {
250 $ledger_time = substr($GLOBALS['ledger_begin_date'],1,1);
251 $last_year = mktime(0,0,0,date('m')-$ledger_time ,date('d'),date('Y'));
253 elseif (substr($GLOBALS['ledger_begin_date'],0,1) == 'D') {
254 $ledger_time = substr($GLOBALS['ledger_begin_date'],1,1);
255 $last_year = mktime(0,0,0,date('m') ,date('d')-$ledger_time,date('Y'));
258 $form_from_date = date('Y-m-d', $last_year);
259 if($_REQUEST['form_from_date']) {
260 $form_from_date = fixDate($_REQUEST['form_from_date'], $last_year);
262 $form_to_date = fixDate($_REQUEST['form_to_date'] , date('Y-m-d'));
263 $form_facility = $_REQUEST['form_facility'];
264 $form_provider = $_REQUEST['form_provider'];
265 $form_patient = $_REQUEST['form_patient'];
266 $form_pid = $_REQUEST['form_pid'];
267 $form_dob = $_REQUEST['form_dob'];
269 if ($_REQUEST['form_csvexport']) {
270 header("Pragma: public");
271 header("Expires: 0");
272 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
273 header("Content-Type: application/force-download");
274 header("Content-Disposition: attachment; filename=svc_financial_report_".attr($form_from_date)."--".attr($form_to_date).".csv");
275 header("Content-Description: File Transfer");
280 <link rel
="stylesheet" href
="<?php echo $css_header;?>" type
="text/css">
281 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js"></script
>
282 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.1.3.2.js"></script
>
283 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/js/common.js"></script
>
284 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery-ui.js"></script
>
285 <script type
="text/javascript">
286 var mypcc
= '<?php echo $GLOBALS['phone_country_code
']; ?>';
289 function checkSubmit() {
290 var pat
= document
.forms
[0].elements
['form_patient'].value
;
291 if(!pat || pat
== 0) {
292 alert('<?php echo xls('A Patient Must Be Selected to Generate This Report
') ?>');
295 document
.forms
[0].elements
['form_refresh'].value
= true;
296 document
.forms
[0].elements
['form_csvexport'].value
= '';
297 document
.forms
[0].submit();
299 function setpatient(pid
, lname
, fname
, dob
) {
300 document
.forms
[0].elements
['form_patient'].value
= lname +
', ' + fname
;
301 document
.forms
[0].elements
['form_pid'].value
= pid
;
302 document
.forms
[0].elements
['form_dob'].value
= dob
;
304 function sel_patient() {
305 dlgopen('../main/calendar/find_patient_popup.php?pflag=0', '_blank', 500, 400);
309 <link rel
="stylesheet" href
="<?php echo $css_header;?>" type
="text/css">
310 <?php
html_header_show();?
>
311 <style type
="text/css">
313 /* specifically include & exclude from printing */
319 #report_parameters_daterange {
335 /* specifically exclude some from the screen */
337 #report_parameters_daterange {
352 <title
><?php
echo xlt('Patient Ledger by Date') ?
></title
>
354 <script language
="JavaScript">
355 $
(document
).ready(function() {
356 var win
= top
.printLogSetup ? top
: opener
.top
;
357 win
.printLogSetup(document
.getElementById('printbutton'));
362 <body
class="body_top">
363 <?php
if($type_form == '0') { ?
>
364 <span
class='title' id
='title'><?php
echo xlt('Report'); ?
> - <?php
echo xlt('Patient Ledger by Date'); ?
></span
>
366 <span
class='title' id
='title'><?php
echo xlt('Patient Ledger'); ?
></span
>
368 <form method
='post' action
='pat_ledger.php?form=<?php echo attr($type_form);?>&patient_id=<?php echo attr($form_pid);?>' id
='theform'>
369 <div id
="report_parameters">
370 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
371 <input type
='hidden' name
='form_csvexport' id
='form_csvexport' value
=''/>
374 <?php
if($type_form == '1') { ?
>
379 <div style
='float:left'>
382 <?php
if($type_form == '0') { ?
>
384 <?php
echo xlt('Facility'); ?
>:
387 <?php
dropdown_facility($form_facility, 'form_facility', true); ?
>
389 <td
><?php
echo xlt('Provider'); ?
>:</td
>
391 $query = "SELECT id, lname, fname FROM users WHERE ".
392 "authorized=1 AND active!=0 ORDER BY lname, fname";
393 $ures = sqlStatement($query);
394 echo " <select name='form_provider'>\n";
395 echo " <option value=''>-- " . xlt('All') . " --\n";
396 while ($urow = sqlFetchArray($ures)) {
397 $provid = $urow['id'];
398 echo " <option value='" . attr($provid) ."'";
399 if ($provid == $_REQUEST['form_provider']) echo " selected";
400 echo ">" . text($urow['lname']) . ", " . text($urow['fname']) . "\n";
407 <?php
echo xlt('From'); ?
>: 
; 
; 
; 
;
408 <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'>
409 <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"); ?>'>
412 <?php
echo xlt('To'); ?
>:
415 <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'>
416 <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"); ?>'>
418 <?php
if($type_form == '0') { ?
>
419 <td
><span
class='label'><?php
echo xlt('Patient'); ?
>: 
; 
;</span
></td
>
421 <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
'); ?>' />
423 <input type
='hidden' name
='form_patient' value
='<?php echo attr($form_patient); ?>' />
425 <input type
='hidden' name
='form_pid' value
='<?php echo attr($form_pid); ?>' />
426 <input type
='hidden' name
='form_dob' value
='<?php echo attr($form_dob); ?>' />
433 <td align
='left' valign
='middle' height
="100%">
434 <table style
='border-left:1px solid; width:100%; height:100%' >
437 <div style
='margin-left:15px'>
438 <a href
='#' class='css_button' onclick
="checkSubmit();" >
439 <span
><?php
echo xlt('Submit'); ?
></span
></a
>
441 <?php
if ($_REQUEST['form_refresh'] ||
$_REQUEST['form_csvexport']) { ?
>
443 <a href
='#' class='css_button' id
='printbutton'>
444 <span
><?php
echo xlt('Print Ledger'); ?
></span
></a
>
445 <?php
if($type_form == '1') { ?
>
446 <a href
="../patient_file/summary/demographics.php" <?php
if (!$GLOBALS['concurrent_layout']) echo "target='Main'"; ?
> class="css_button" onclick
="top.restoreSession()">
447 <span
><?php
echo xlt('Back To Patient');?
></span
></a
>
458 </div
> <!-- end of parameters
-->
462 $from_date = $form_from_date . ' 00:00:00';
463 $to_date = $form_to_date . ' 23:59:59';
464 if ($_REQUEST['form_refresh'] ||
$_REQUEST['form_csvexport']) {
466 $sqlBindArray = array();
467 $query = "select b.code_type, b.code, b.code_text, b.pid, b.provider_id, ".
468 "b.billed, b.payer_id, b.units, b.fee, b.bill_date, b.id, ".
470 "fe.encounter, fe.date, fe.reason, fe.provider_id ".
471 "FROM form_encounter AS fe ".
472 "LEFT JOIN billing AS b ON b.pid=fe.pid AND b.encounter=fe.encounter ".
473 "LEFT JOIN insurance_companies AS ins ON b.payer_id = ins.id ".
474 "LEFT OUTER JOIN code_types AS c ON c.ct_key = b.code_type ".
475 "WHERE fe.date >= ? AND fe.date <= ? AND fe.pid = ? ";
476 array_push($sqlBindArray,$from_date,$to_date,$form_pid);
477 if ($form_facility) {
478 $query .= "AND fe.facility_id = ? ";
479 array_push($sqlBindArray,$form_facility);
481 if ($form_provider) {
482 $query .= "AND b.provider_id = ? ";
483 array_push($sqlBindArray,$form_provider);
485 $query .= "AND c.ct_proc = '1' ";
486 $query .= "AND activity > 0 ORDER BY fe.date, fe.id ";
487 $res = sqlStatement($query,$sqlBindArray);
489 if ($_REQUEST['form_csvexport']) {
492 echo '"Code/Enc Dt",';
493 echo '"Description",';
494 echo '"Billed/Who",';
495 echo '"Type/Units",';
496 echo '"Chg/Pmt Amount",'."\n";
499 if(!$form_facility) $form_facility = '3';
500 $facility = sqlQuery("SELECT * FROM facility WHERE id=?", array($form_facility));
501 $patient = sqlQuery("SELECT * from patient_data WHERE pid=?", array($form_patient));
502 $pat_dob = $patient['DOB'];
503 $pat_name = $patient['fname']. ' ' . $patient['lname'];
505 <div id
="report_header">
506 <table width
="98%" border
="0" cellspacing
="0" cellpadding
="0">
508 <td
class="title" ><?php
echo text($facility{'name'}); ?
></td
>
511 <td
class="title" ><?php
echo text($facility{'street'}); ?
></td
>
514 <td
class="title" ><?php
echo text($facility{'city'}).", ".text($facility{'state'})." ".text($facility{'postal_code'}); ?
></td
>
517 <td
class="title" ><?php
echo xlt('Phone').': ' .text($facility{'phone'}); ?
></td
>
520 <td
class="title" ><?php
echo xlt('Tax Id').': ' .text($facility{'federal_ein'}); ?
></td
>
522 <tr
><td
> 
;</td
></tr
>
524 <td
class="title" ><?php
echo xlt('Patient Ledger'); ?
></td
>
528 $title = xl('All Providers');
529 if($form_provider) { $title = xl('For Provider') . ': '.User_Id_Look($form_provider); }
531 <td
class="title" ><?php
echo text($title); ?
></td
>
535 $title = xl('For Dates') . ': '.$form_from_date.' - '.$form_to_date;
537 <td
class="title" ><?php
echo text($title); ?
></td
>
541 <table width
="100%" border
="0" cellspacing
="0" cellpadding
="0">
543 <td
class='bold' ><?php
echo xlt('Date')?
>:
544 <?php
echo text(date('Y-m-d')); ?
></td
>
545 <td
class='bold' ><?php
echo xlt('Patient')?
>:
546 <?php
if($type_form == '1') { ?
>
547 <?php
echo text($pat_name); ?
></td
>
549 <?php
echo text($form_patient); ?
></td
>
551 <td
class='bold' ><?php
echo xlt('DOB')?
>:
552 <?php
if($type_form == '1') { ?
>
553 <?php
echo text($pat_dob);?
></td
>
555 <?php
echo text($form_dob); ?
></td
>
557 <td
class='bold' > <?php
echo xlt('ID')?
>:
558 <?php
echo text($form_pid);?
></td
>
562 <div id
="report_results">
565 <td
class='bold' ><?php
echo xlt('Code'); ?
></td
>
566 <td colspan
="2" class='bold' ><?php
echo xlt('Description'); ?
></td
>
567 <td
class='bold' ><?php
echo xlt('Billed Date'); ?
> / <?php
echo xlt('Payor'); ?
></td
>
568 <td
class='bold' ><?php
echo xlt('Type'); ?
> 
; 
; 
; 
; 
; 
; 
;
569 <?php
echo xlt('Units'); ?
></td
>
570 <td
class='bold' > 
; 
; 
; 
; 
;<?php
echo xlt('Charge'); ?
></td
>
571 <td align
='right' class='bold' > 
; 
;<?php
echo xlt('Payment'); ?
></td
>
572 <td align
='right' class='bold' > 
; 
; 
; 
; 
;<?php
echo xlt('Adjustment'); ?
></td
>
573 <td align
='right' class='bold' > 
; 
; 
;<?php
echo xlt('Balance'); ?
></td
>
576 <td
> 
; 
; 
;</td
>
577 <td colspan
="2" > 
; 
; 
;</td
>
578 <td
> 
; 
; 
; 
; 
; 
;</td
>
579 <td
> 
; 
; 
; 
; 
; 
; 
; 
;
580  
; 
; 
;</td
>
581 <td
class='bold' > 
; 
; 
;<?php
echo xlt('UAC Appl'); ?
></td
>
582 <td align
='right' class='bold' > 
; 
; 
; 
; 
;<?php
echo xlt('UAC Tot'); ?
></td
>
589 $prev_encounter_id = -1;
590 $hdr_printed = false;
592 while ($erow = sqlFetchArray($res)) {
595 if($erow['encounter'] != $prev_encounter_id) {
596 if($prev_encounter_id != -1) {
597 $credits = GetAllCredits($prev_encounter_id, $form_pid);
598 if(count($credits) > 0) {
600 PrintEncHeader($prev_row{'date'},
601 $prev_row{'reason'}, $prev_row{'provider_id'});
603 PrintCreditDetail($credits, $form_pid);
605 if($hdr_printed) PrintEncFooter();
606 $hdr_printed = false;
608 $enc_units = $enc_chg = $enc_pmt = $enc_adj = $enc_bal = 0;
611 // Now print an encounter heading line -
613 PrintEncHeader($erow{'date'},
614 $erow{'reason'}, $erow{'provider_id'});
618 $code_desc = $erow['code_text'];
619 if(strlen($code_desc) > 50) $code_desc = substr($code_desc,0,50).'...';
620 $bgcolor = (($bgcolor == "#FFFFDD") ?
"#FFDDDD" : "#FFFFDD");
621 $print = "<tr bgcolor='". attr($bgcolor) ."'>";
622 $print .= "<td class='detail'>".text($erow['code'])."</td>";
623 $print .= "<td class='detail' colspan='2'>".text($code_desc)."</td>";
624 $who = ($erow['name'] == '') ?
xl('Self') : $erow['name'];
625 $bill = substr($erow['bill_date'],0,10);
626 if($bill == '') { $bill = 'unbilled'; }
627 $print .= "<td class='detail'>".text($bill)." / ".text($who)."</td>";
628 $print .= "<td class='detail' style='text-align: right;'>". text($erow['units'])."</td>";
629 $print .= "<td class='detail' style='text-align: right;'>". text(oeFormatMoney($erow['fee']))."</td>";
630 $print .= "<td> </td><td> </td><td> </td>";
633 $total_units +
= $erow['units'];
634 $total_chg +
= $erow['fee'];
635 $total_bal +
= $erow['fee'];
636 $enc_units +
= $erow['units'];
637 $enc_chg +
= $erow['fee'];
638 $enc_bal +
= $erow['fee'];
641 if ($_REQUEST['form_csvexport']) {
647 $prev_encounter_id = $erow{'encounter'};
650 if($prev_encounter_id != -1) {
651 $credits = GetAllCredits($prev_encounter_id, $form_pid);
652 if(count($credits) > 0) {
654 PrintEncHeader($prev_row{'date'},
655 $prev_row{'reason'}, $prev_row{'provider_id'});
657 PrintCreditDetail($credits, $form_pid);
659 if($hdr_printed) PrintEncFooter();
661 // This is the end of the encounter/charge loop -
662 $uac = GetAllUnapplied($form_pid,$from_date,$to_date);
663 if(count($uac) > 0) {
665 $bgcolor = (($bgcolor == "#FFFFDD") ?
"#FFDDDD" : "#FFFFDD");
666 echo "<tr bgcolor='#FFFFFF'><td colspan='9'> </td></tr>\n";
668 PrintCreditDetail($uac, $form_pid, true);
670 if (!$_REQUEST['form_csvexport'] && $orow) {
671 echo "<tr bgcolor='#DDFFFF'>\n";
672 echo " <td colspan='2'> </td>";
673 echo " <td class='bold' colspan='2'>" . xlt("Grand Total") ."</td>\n";
674 echo " <td class='bold' style='text-align: right;'>". text($total_units) ."</td>\n";
675 echo " <td class='bold' style='text-align: right;'>". text(oeFormatMoney($total_chg)) ."</td>\n";
676 echo " <td class='bold' style='text-align: right;'>". text(oeFormatMoney($total_pmt)) ."</td>\n";
677 echo " <td class='bold' style='text-align: right;'>". text(oeFormatMoney($total_adj)) ."</td>\n";
678 echo " <td class='bold' style='text-align: right;'>". text(oeFormatMoney($total_bal)) . "</td>\n";
682 <tr
><td
> 
;</td
></tr
><br
><br
>
683 <?php
if($GLOBALS['print_next_appointment_on_ledger'] == 1) {
684 $next_day = mktime(0,0,0,date('m'),date('d')+
1,date('Y'));
685 # add one day to date so it will not get todays appointment
686 $current_date2 = date('Y-m-d', $next_day);
687 $events = fetchNextXAppts($current_date2,$form_pid);
688 $next_appoint_date = oeFormatShortDate($events[0]['pc_eventDate']);
689 $next_appoint_time = substr($events[0]['pc_startTime'],0,5);
690 if(strlen(umname
) != 0 ) {
691 $next_appoint_provider = $events[0]['ufname'] . ' ' . $events[0]['umname'] . ' ' . $events[0]['ulname'];
695 $next_appoint_provider = $events[0]['ufname'] . ' ' . $events[0]['ulname'];
697 if(strlen($next_appoint_time) != 0) {
700 <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
>
705 } // end ($GLOBALS['print_next_appointment_on_ledger'] == 1)
706 } // end (!$_REQUEST['form_csvexport'] && $orow)
709 if (! $_REQUEST['form_csvexport']) {
710 if ( $_REQUEST['form_refresh'] && $orow <= 0) {
711 echo "<span style='font-size:10pt;'>";
712 echo xlt('No matches found. Try search again.');
714 echo '<script>document.getElementById("report_results").style.display="none";</script>';
715 echo '<script>document.getElementById("controls").style.display="none";</script>';
718 if (!$_REQUEST['form_refresh'] && !$_REQUEST['form_csvexport']) { ?
>
720 <?php
echo xlt('Please input search criteria above, and click Submit to view results.' ); ?
>
726 <!-- stuff
for the popup calendar
-->
728 <link rel
='stylesheet' href
='<?php echo $css_header ?>' type
='text/css'>
729 <style type
="text/css">@import
url(../../library
/dynarch_calendar
.css
);</style
>
730 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot']; ?>/library/dynarch_calendar.js"></script
>
731 <?php
include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?
>
732 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot']; ?>/library/dynarch_calendar_setup.js"></script
>
733 <script language
="Javascript">
734 Calendar
.setup({inputField
:"form_from_date", ifFormat
:"%Y-%m-%d", button
:"img_from_date"});
735 Calendar
.setup({inputField
:"form_to_date", ifFormat
:"%Y-%m-%d", button
:"img_to_date"});
736 top
.restoreSession();
740 } // End not csv export