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 = '')
57 $sql = "SELECT ar_session.*, ins.name, " .
58 "pat.lname, pat.fname, pat.mname, " .
59 "(SELECT SUM(ar_activity.pay_amount) FROM ar_activity WHERE " .
60 "ar_activity.session_id = ar_session.session_id) AS applied " .
62 "LEFT JOIN insurance_companies AS ins on ar_session.payer_id = ins.id " .
63 "LEFT JOIN patient_data AS pat on ar_session.patient_id = pat.pid " .
65 "ar_session.created_time >= ? AND ar_session.created_time <= ? " .
66 "AND ar_session.patient_id=?";
67 $result = sqlStatement($sql, array($from_dt, $to_dt, $pat));
69 while ($row = sqlFetchArray($result)) {
77 function User_Id_Look($thisField)
84 $rlist= sqlStatement("SELECT lname, fname, mname FROM users WHERE id=?", array($thisField));
85 $rrow= sqlFetchArray($rlist);
87 $ret = $rrow{'lname'}.', '.$rrow{'fname'}.' '.$rrow{'mname'};
93 function List_Look($thisData, $thisList)
95 if ($thisList == 'occurrence') {
96 if (!$thisData ||
$thisData == '') {
97 return xl('Unknown or N/A');
101 if ($thisData == '') {
105 $fres=sqlStatement("SELECT title FROM list_options WHERE list_id=? ".
106 "AND option_id=?", array($thisList, $thisData));
108 $rret=sqlFetchArray($fres);
109 $dispValue= xl_list_label($rret{'title'});
110 if ($thisList == 'occurrence' && $dispValue == '') {
111 $dispValue = xl('Unknown or N/A');
114 $dispValue= xl('Not Found');
120 function GetAllCredits($enc = '', $pat = '')
123 if (!$enc ||
!$pat) {
127 $sql = "SELECT activity.*, session.*, ins.name FROM ar_activity AS ".
128 "activity LEFT JOIN ar_session AS session USING (session_id) ".
129 "LEFT JOIN insurance_companies AS ins ON session.payer_id = ".
130 "ins.id WHERE encounter=? AND pid=? ".
131 "ORDER BY sequence_no";
132 $result = sqlStatement($sql, array($enc, $pat));
134 while ($row = sqlFetchArray($result)) {
141 function PrintEncHeader($dt, $rsn, $dr)
143 global $bgcolor, $orow;
144 $bgcolor = (($bgcolor == "#FFFFDD") ?
"#FFDDDD" : "#FFFFDD");
145 echo "<tr bgcolor='#FFFFFF'>";
146 if (strlen($rsn) > 50) {
147 $rsn = substr($rsn, 0, 50).'...';
150 echo "<td colspan='4'><span class='bold'>".xlt('Encounter Dt / Rsn'). ": </span><span class='detail'>".text(substr($dt, 0, 10))." / ".text($rsn)."</span></td>";
151 echo "<td colspan='5'><span class='bold'>" . xlt('Provider'). ": </span><span class='detail'>".text(User_Id_Look($dr))."</span></td>";
155 function PrintEncFooter()
157 global $enc_units, $enc_chg, $enc_pmt, $enc_adj, $enc_bal;
158 echo "<tr bgcolor='#DDFFFF'>";
159 echo "<td colspan='3'> </td>";
160 echo "<td class='detail'>". xlt('Encounter Balance').":</td>";
161 echo "<td class='detail' style='text-align: right;'>".text($enc_units)."</td>";
162 echo "<td class='detail' style='text-align: right;'>".text(oeFormatMoney($enc_chg))."</td>";
163 echo "<td class='detail' style='text-align: right;'>".text(oeFormatMoney($enc_pmt))."</td>";
164 echo "<td class='detail' style='text-align: right;'>".text(oeFormatMoney($enc_adj))."</td>";
165 echo "<td class='detail' style='text-align: right;'>".text(oeFormatMoney($enc_bal))."</td>";
168 function PrintCreditDetail($detail, $pat, $unassigned = false)
170 global $enc_pmt, $total_pmt, $enc_adj, $total_adj, $enc_bal, $total_bal;
171 global $bgcolor, $orow, $enc_units, $enc_chg;
172 foreach ($detail as $pmt) {
174 if (($pmt['pay_total'] - $pmt['applied']) == 0) {
179 $bgcolor = (($bgcolor == "#FFFFDD") ?
"#FFDDDD" : "#FFFFDD");
180 $print = "<tr bgcolor='" . attr($bgcolor) . "'>";
181 $print .= "<td class='detail'> </td>";
182 $method = List_Look($pmt['payment_method'], 'payment_method');
183 $desc = $pmt['description'];
184 $ref = $pmt['reference'];
186 $memo = List_Look($pmt['adjustment_code'], 'payment_adjustment_code');
188 $memo = $pmt['memo'];
191 $description = $method;
194 $description .= ' - ';
197 $description .= $ref;
202 $description .= ': ';
205 $description .= $desc;
213 $description .= '['.$memo.']';
216 $print .= "<td class='detail' colspan='2'>".
217 text($description)." </td>";
218 $payer = ($pmt['name'] == '') ?
xl('Patient') : $pmt['name'];
220 $pmt_date = substr($pmt['post_to_date'], 0, 10);
222 $pmt_date = substr($pmt['post_time'], 0, 10);
225 $print .= "<td class='detail'>".
226 text($pmt_date)." / ".text($payer)."</td>";
227 $type = List_Look($pmt['payment_type'], 'payment_type');
228 $print .= "<td class='detail'>".text($type)." </td>";
230 $pmt_amt = $pmt['pay_total'] - $pmt['applied'];
231 $uac_bal = oeFormatMoney($pmt_amt * -1);
232 $uac_appl = oeFormatMoney($pmt['applied']);
233 $uac_total = oeFormatMoney($pmt['pay_total']);
234 $pmt_amt = $pmt['pay_total'];
235 $total_pmt = $total_pmt - $uac_bal;
240 $pmt_amt = $pmt['pay_amount'];
241 $adj_amt = $pmt['adj_amount'];
242 $enc_pmt = $enc_pmt +
$pmt['pay_amount'];
243 $total_pmt = $total_pmt +
$pmt['pay_amount'];
244 $enc_adj = $enc_adj +
$pmt['adj_amount'];
245 $total_adj = $total_adj +
$pmt['adj_amount'];
250 $print_pmt = oeFormatMoney($pmt_amt);
255 $print_adj = oeFormatMoney($adj_amt);
258 $print .= "<td class='detail' style='text-align: right;'>".text($uac_appl)." </td>";
259 $print .= "<td class='detail' style='text-align: right;'>".text($print_pmt)." </td>";
260 $print .= "<td class='detail' style='text-align: right;'>".text($print_adj)." </td>";
261 $print .= "<td class='detail' style='text-align: right;'>".text($uac_bal)." </td>";
264 if ($pmt['follow_up_note'] != '') {
265 $bgcolor = (($bgcolor == "#FFFFDD") ?
"#FFDDDD" : "#FFFFDD");
266 $print = "<tr bgcolor='". attr($bgcolor) ."'>";
267 $print .= "<td class='detail' colspan='2'> </td>";
268 $print .= "<td colspan='7'>". xlt('Follow Up Note') .": ";
269 $print .= text($pmt['follow_up_note']);
270 $print .= "</td></tr>\n";
275 $total_bal = $total_bal +
$uac_bal;
277 $enc_bal = $enc_bal - $pmt_amt - $adj_amt;
278 $total_bal = $total_bal - $pmt_amt - $adj_amt;
284 $bgcolor = (($bgcolor == "#FFFFDD") ?
"#FFDDDD" : "#FFFFDD");
286 if (!isset($_REQUEST['form_from_date'])) {
287 $_REQUEST['form_from_date'] = '';
290 if (!isset($_REQUEST['form_to_date'])) {
291 $_REQUEST['form_to_date'] = '';
294 if (!isset($_REQUEST['form_facility'])) {
295 $_REQUEST['form_facility'] = '';
298 if (!isset($_REQUEST['form_provider'])) {
299 $_REQUEST['form_provider'] = '';
302 if ($type_form=='0') {
303 if (!isset($_REQUEST['form_patient'])) {
304 $_REQUEST['form_patient'] = '';
307 if (!isset($_REQUEST['form_pid'])) {
308 $_REQUEST['form_pid'] = '';
311 if (!isset($_REQUEST['form_patient'])) {
312 $_REQUEST['form_patient'] = $pat_pid;
315 if (!isset($_REQUEST['form_pid'])) {
316 $_REQUEST['form_pid'] = $pat_pid;
320 if (!isset($_REQUEST['form_csvexport'])) {
321 $_REQUEST['form_csvexport'] = '';
324 if (!isset($_REQUEST['form_refresh'])) {
325 $_REQUEST['form_refresh'] = '';
328 if (!isset($_REQUEST['$form_dob'])) {
329 $_REQUEST['$form_dob'] = '';
332 if (substr($GLOBALS['ledger_begin_date'], 0, 1) == 'Y') {
333 $ledger_time = substr($GLOBALS['ledger_begin_date'], 1, 1);
334 $last_year = mktime(0, 0, 0, date('m'), date('d'), date('Y')-$ledger_time);
335 } elseif (substr($GLOBALS['ledger_begin_date'], 0, 1) == 'M') {
336 $ledger_time = substr($GLOBALS['ledger_begin_date'], 1, 1);
337 $last_year = mktime(0, 0, 0, date('m')-$ledger_time, date('d'), date('Y'));
338 } elseif (substr($GLOBALS['ledger_begin_date'], 0, 1) == 'D') {
339 $ledger_time = substr($GLOBALS['ledger_begin_date'], 1, 1);
340 $last_year = mktime(0, 0, 0, date('m'), date('d')-$ledger_time, date('Y'));
343 $form_from_date = date('Y-m-d', $last_year);
344 if ($_REQUEST['form_from_date']) {
345 $form_from_date = fixDate($_REQUEST['form_from_date'], $last_year);
348 $form_to_date = fixDate($_REQUEST['form_to_date'], date('Y-m-d'));
349 $form_facility = $_REQUEST['form_facility'];
350 $form_provider = $_REQUEST['form_provider'];
351 $form_patient = $_REQUEST['form_patient'];
352 $form_pid = $_REQUEST['form_pid'];
353 $form_dob = $_REQUEST['form_dob'];
355 if ($_REQUEST['form_csvexport']) {
356 header("Pragma: public");
357 header("Expires: 0");
358 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
359 header("Content-Type: application/force-download");
360 header("Content-Disposition: attachment; filename=svc_financial_report_".attr($form_from_date)."--".attr($form_to_date).".csv");
361 header("Content-Description: File Transfer");
366 <link rel
="stylesheet" href
="<?php echo $css_header;?>" type
="text/css">
367 <link rel
="stylesheet" href
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.min.css">
369 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-3-1-1/index.js"></script
>
370 <script type
="text/javascript" src
="<?php echo $GLOBALS['webroot'] ?>/library/js/common.js?v=<?php echo $v_js_includes; ?>"></script
>
371 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.full.min.js"></script
>
373 <script type
="text/javascript">
374 var mypcc
= '<?php echo $GLOBALS['phone_country_code
']; ?>';
377 function checkSubmit() {
378 var pat
= document
.forms
[0].elements
['form_patient'].value
;
379 if(!pat || pat
== 0) {
380 alert('<?php echo xls('A Patient Must Be Selected to Generate This Report
') ?>');
383 document
.forms
[0].elements
['form_refresh'].value
= true;
384 document
.forms
[0].elements
['form_csvexport'].value
= '';
385 document
.forms
[0].submit();
387 function setpatient(pid
, lname
, fname
, dob
) {
388 document
.forms
[0].elements
['form_patient'].value
= lname +
', ' + fname
;
389 document
.forms
[0].elements
['form_pid'].value
= pid
;
390 document
.forms
[0].elements
['form_dob'].value
= dob
;
392 function sel_patient() {
393 dlgopen('../main/calendar/find_patient_popup.php?pflag=0', '_blank', 500, 400);
397 <style type
="text/css">
399 /* specifically include & exclude from printing */
405 #report_parameters_daterange {
421 /* specifically exclude some from the screen */
423 #report_parameters_daterange {
438 <title
><?php
echo xlt('Patient Ledger by Date') ?
></title
>
441 $
(document
).ready(function() {
442 $
('.datepicker').datetimepicker({
443 <?php
$datetimepicker_timepicker = false; ?
>
444 <?php
$datetimepicker_formatInput = false; ?
>
445 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
446 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
452 <body
class="skin-blue">
453 <?php
if ($type_form == '0') { ?
>
454 <span
class='title' id
='title'><?php
echo xlt('Report'); ?
> - <?php
echo xlt('Patient Ledger by Date'); ?
></span
>
456 <span
class='title' id
='title'><?php
echo xlt('Patient Ledger'); ?
></span
>
458 <form method
='post' action
='./pat_ledger.php?form=<?php echo attr($type_form);?>&patient_id=<?php echo attr($form_pid);?>' id
='theform'>
459 <div id
="report_parameters">
460 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
461 <input type
='hidden' name
='form_csvexport' id
='form_csvexport' value
=''/>
464 <?php
if ($type_form == '1') { ?
>
469 <div style
='float:left'>
472 <?php
if ($type_form == '0') { ?
>
473 <td
class='label_custom'>
474 <?php
echo xlt('Facility'); ?
>:
477 <?php
dropdown_facility($form_facility, 'form_facility', true); ?
>
479 <td
><?php
echo xlt('Provider'); ?
>:</td
>
481 $query = "SELECT id, lname, fname FROM users WHERE ".
482 "authorized=1 AND active!=0 ORDER BY lname, fname";
483 $ures = sqlStatement($query);
484 echo " <select name='form_provider'>\n";
485 echo " <option value=''>-- " . xlt('All') . " --\n";
486 while ($urow = sqlFetchArray($ures)) {
487 $provid = $urow['id'];
488 echo " <option value='" . attr($provid) ."'";
489 if ($provid == $_REQUEST['form_provider']) {
493 echo ">" . text($urow['lname']) . ", " . text($urow['fname']) . "\n";
501 <?php
echo xlt('From'); ?
>: 
; 
; 
; 
;
502 <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'>
504 <td
class='label_custom'>
505 <?php
echo xlt('To'); ?
>:
508 <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'>
510 <?php
if ($type_form == '0') { ?
>
511 <td
><span
class='label_custom'><?php
echo xlt('Patient'); ?
>: 
; 
;</span
></td
>
513 <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
'); ?>' />
515 <input type
='hidden' name
='form_patient' value
='<?php echo attr($form_patient); ?>' />
517 <input type
='hidden' name
='form_pid' value
='<?php echo attr($form_pid); ?>' />
518 <input type
='hidden' name
='form_dob' value
='<?php echo attr($form_dob); ?>' />
525 <td align
='left' valign
='middle' height
="100%">
526 <table style
='border-left:1px solid; width:100%; height:100%' >
529 <div style
='margin-left:15px'>
530 <a href
='#' class='css_button' onclick
="checkSubmit();" >
531 <span
><?php
echo xlt('Submit'); ?
></span
></a
>
533 <?php
if ($_REQUEST['form_refresh'] ||
$_REQUEST['form_csvexport']) { ?
>
534 <div id
="controls"> <!-- print is patched out until I feel like convert to patient side
-->
535 <!-- <a href
='#' class='css_button' id
='printbutton'>
536 <span
><?php
//echo xlt('Print Ledger'); ?></span></a> -->
537 <?php
if ($type_form == '1') { ?
>
538 <!-- <a href
="../patient_file/summary/demographics.php" <?php
// if (!$GLOBALS['concurrent_layout']) echo "target='Main'"; ?> class="css_button" onclick="top.restoreSession()">-->
539 <!-- <span
><?php
//echo xlt('Back To Patient');?></span></a> -->
550 </div
> <!-- end of parameters
-->
554 $from_date = $form_from_date . ' 00:00:00';
555 $to_date = $form_to_date . ' 23:59:59';
556 if ($_REQUEST['form_refresh'] ||
$_REQUEST['form_csvexport']) {
558 $sqlBindArray = array();
559 $query = "select b.code_type, b.code, b.code_text, b.pid, b.provider_id, ".
560 "b.billed, b.payer_id, b.units, b.fee, b.bill_date, b.id, ".
562 "fe.encounter, fe.date, fe.reason, fe.provider_id ".
563 "FROM form_encounter AS fe ".
564 "LEFT JOIN billing AS b ON b.pid=fe.pid AND b.encounter=fe.encounter ".
565 "LEFT JOIN insurance_companies AS ins ON b.payer_id = ins.id ".
566 "LEFT OUTER JOIN code_types AS c ON c.ct_key = b.code_type ".
567 "WHERE fe.date >= ? AND fe.date <= ? AND fe.pid = ? ";
568 array_push($sqlBindArray, $from_date, $to_date, $form_pid);
569 if ($form_facility) {
570 $query .= "AND fe.facility_id = ? ";
571 array_push($sqlBindArray, $form_facility);
574 if ($form_provider) {
575 $query .= "AND b.provider_id = ? ";
576 array_push($sqlBindArray, $form_provider);
579 $query .= "AND c.ct_proc = '1' ";
580 $query .= "AND activity > 0 ORDER BY fe.date, fe.id ";
581 $res = sqlStatement($query, $sqlBindArray);
583 if ($_REQUEST['form_csvexport']) {
586 echo '"Code/Enc Dt",';
587 echo '"Description",';
588 echo '"Billed/Who",';
589 echo '"Type/Units",';
590 echo '"Chg/Pmt Amount",'."\n";
593 if (!$form_facility) {
594 $form_facility = '3';
597 $facility = sqlQuery("SELECT * FROM facility WHERE id=?", array($form_facility));
598 $patient = sqlQuery("SELECT * from patient_data WHERE pid=?", array($form_patient));
599 $pat_dob = $patient['DOB'];
600 $pat_name = $patient['fname']. ' ' . $patient['lname'];
602 <div id
="report_header">
603 <table width
="98%" border
="0" cellspacing
="0" cellpadding
="0">
605 <td
class="title" ><?php
echo text($facility{'name'}); ?
></td
>
608 <td
class="title" ><?php
echo text($facility{'street'}); ?
></td
>
611 <td
class="title" ><?php
echo text($facility{'city'}).", ".text($facility{'state'})." ".text($facility{'postal_code'}); ?
></td
>
614 <td
class="title" ><?php
echo xlt('Phone').': ' .text($facility{'phone'}); ?
></td
>
617 <td
class="title" ><?php
echo xlt('Tax Id').': ' .text($facility{'federal_ein'}); ?
></td
>
619 <tr
><td
> 
;</td
></tr
>
621 <td
class="title" ><?php
echo xlt('Patient Ledger'); ?
></td
>
625 $title = xl('All Providers');
626 if ($form_provider) {
627 $title = xl('For Provider') . ': '.User_Id_Look($form_provider);
630 <td
class="title" ><?php
echo text($title); ?
></td
>
634 $title = xl('For Dates') . ': '.$form_from_date.' - '.$form_to_date;
636 <td
class="title" ><?php
echo text($title); ?
></td
>
640 <table width
="100%" border
="0" cellspacing
="0" cellpadding
="0">
642 <td
class='bold' ><?php
echo xlt('Date')?
>:
643 <?php
echo text(date('Y-m-d')); ?
></td
>
644 <td
class='bold' ><?php
echo xlt('Patient')?
>:
645 <?php
if ($type_form == '1') { ?
>
646 <?php
echo text($pat_name); ?
></td
>
648 <?php
echo text($form_patient); ?
></td
>
650 <td
class='bold' ><?php
echo xlt('DOB')?
>:
651 <?php
if ($type_form == '1') { ?
>
652 <?php
echo text($pat_dob);?
></td
>
654 <?php
echo text($form_dob); ?
></td
>
656 <td
class='bold' > <?php
echo xlt('ID')?
>:
657 <?php
echo text($form_pid);?
></td
>
661 <div id
="report_results">
664 <td
class='bold' ><?php
echo xlt('Code'); ?
></td
>
665 <td colspan
="2" class='bold' ><?php
echo xlt('Description'); ?
></td
>
666 <td
class='bold' ><?php
echo xlt('Billed Date'); ?
> / <?php
echo xlt('Payor'); ?
></td
>
667 <td
class='bold' ><?php
echo xlt('Type'); ?
> 
; 
; 
; 
; 
; 
; 
;
668 <?php
echo xlt('Units'); ?
></td
>
669 <td
class='bold' > 
; 
; 
; 
; 
;<?php
echo xlt('Charge'); ?
></td
>
670 <td align
='right' class='bold' > 
; 
;<?php
echo xlt('Payment'); ?
></td
>
671 <td align
='right' class='bold' > 
; 
; 
; 
; 
;<?php
echo xlt('Adjustment'); ?
></td
>
672 <td align
='right' class='bold' > 
; 
; 
;<?php
echo xlt('Balance'); ?
></td
>
675 <td
> 
; 
; 
;</td
>
676 <td colspan
="2" > 
; 
; 
;</td
>
677 <td
> 
; 
; 
; 
; 
; 
;</td
>
678 <td
> 
; 
; 
; 
; 
; 
; 
; 
;
679  
; 
; 
;</td
>
680 <td
class='bold' > 
; 
; 
;<?php
echo xlt('UAC Appl'); ?
></td
>
681 <td align
='right' class='bold' > 
; 
; 
; 
; 
;<?php
echo xlt('UAC Tot'); ?
></td
>
689 $prev_encounter_id = -1;
690 $hdr_printed = false;
692 while ($erow = sqlFetchArray($res)) {
695 if ($erow['encounter'] != $prev_encounter_id) {
696 if ($prev_encounter_id != -1) {
697 $credits = GetAllCredits($prev_encounter_id, $form_pid);
698 if (count($credits) > 0) {
703 $prev_row{'provider_id'}
707 PrintCreditDetail($credits, $form_pid);
714 $hdr_printed = false;
717 $enc_units = $enc_chg = $enc_pmt = $enc_adj = $enc_bal = 0;
721 // Now print an encounter heading line -
731 $code_desc = $erow['code_text'];
732 if (strlen($code_desc) > 50) {
733 $code_desc = substr($code_desc, 0, 50).'...';
736 $bgcolor = (($bgcolor == "#FFFFDD") ?
"#FFDDDD" : "#FFFFDD");
737 $print = "<tr bgcolor='". attr($bgcolor) ."'>";
738 $print .= "<td class='detail'>".text($erow['code'])."</td>";
739 $print .= "<td class='detail' colspan='2'>".text($code_desc)."</td>";
740 $who = ($erow['name'] == '') ?
xl('Self') : $erow['name'];
741 $bill = substr($erow['bill_date'], 0, 10);
746 $print .= "<td class='detail'>".text($bill)." / ".text($who)."</td>";
747 $print .= "<td class='detail' style='text-align: right;'>". text($erow['units'])."</td>";
748 $print .= "<td class='detail' style='text-align: right;'>". text(oeFormatMoney($erow['fee']))."</td>";
749 $print .= "<td> </td><td> </td><td> </td>";
752 $total_units +
= $erow['units'];
753 $total_chg +
= $erow['fee'];
754 $total_bal +
= $erow['fee'];
755 $enc_units +
= $erow['units'];
756 $enc_chg +
= $erow['fee'];
757 $enc_bal +
= $erow['fee'];
760 if ($_REQUEST['form_csvexport']) {
767 $prev_encounter_id = $erow{'encounter'};
771 if ($prev_encounter_id != -1) {
772 $credits = GetAllCredits($prev_encounter_id, $form_pid);
773 if (count($credits) > 0) {
778 $prev_row{'provider_id'}
782 PrintCreditDetail($credits, $form_pid);
790 // This is the end of the encounter/charge loop -
791 $uac = GetAllUnapplied($form_pid, $from_date, $to_date);
792 if (count($uac) > 0) {
794 $bgcolor = (($bgcolor == "#FFFFDD") ?
"#FFDDDD" : "#FFFFDD");
795 echo "<tr bgcolor='#FFFFFF'><td colspan='9'> </td></tr>\n";
798 PrintCreditDetail($uac, $form_pid, true);
801 if (!$_REQUEST['form_csvexport'] && $orow) {
802 echo "<tr bgcolor='#DDFFFF'>\n";
803 echo " <td colspan='2'> </td>";
804 echo " <td class='bold' colspan='2'>" . xlt("Grand Total") ."</td>\n";
805 echo " <td class='bold' style='text-align: right;'>". text($total_units) ."</td>\n";
806 echo " <td class='bold' style='text-align: right;'>". text(oeFormatMoney($total_chg)) ."</td>\n";
807 echo " <td class='bold' style='text-align: right;'>". text(oeFormatMoney($total_pmt)) ."</td>\n";
808 echo " <td class='bold' style='text-align: right;'>". text(oeFormatMoney($total_adj)) ."</td>\n";
809 echo " <td class='bold' style='text-align: right;'>". text(oeFormatMoney($total_bal)) . "</td>\n";
813 <tr
><td
> 
;</td
></tr
><br
><br
>
814 <?php
if ($GLOBALS['print_next_appointment_on_ledger'] == 1) {
815 $next_day = mktime(0, 0, 0, date('m'), date('d')+
1, date('Y'));
816 # add one day to date so it will not get todays appointment
817 $current_date2 = date('Y-m-d', $next_day);
818 $events = fetchNextXAppts($current_date2, $form_pid);
819 $next_appoint_date = oeFormatShortDate($events[0]['pc_eventDate']);
820 $next_appoint_time = substr($events[0]['pc_startTime'], 0, 5);
821 if (strlen(umname
) != 0) {
822 $next_appoint_provider = $events[0]['ufname'] . ' ' . $events[0]['umname'] . ' ' . $events[0]['ulname'];
824 $next_appoint_provider = $events[0]['ufname'] . ' ' . $events[0]['ulname'];
827 if (strlen($next_appoint_time) != 0) {
830 <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
>
835 } // end ($GLOBALS['print_next_appointment_on_ledger'] == 1)
836 } // end (!$_REQUEST['form_csvexport'] && $orow)
840 if (! $_REQUEST['form_csvexport']) {
841 if ($_REQUEST['form_refresh'] && $orow <= 0) {
842 echo "<span style='font-size:10pt;'>";
843 echo xlt('No matches found. Try search again.');
845 echo '<script>document.getElementById("report_results").style.display="none";</script>';
846 echo '<script>document.getElementById("controls").style.display="none";</script>';
849 if (!$_REQUEST['form_refresh'] && !$_REQUEST['form_csvexport']) { ?
>
851 <?php
echo xlt('Please input search criteria above, and click Submit to view results.'); ?
>
861 } // End not csv export