3 * This is a report to create a patient ledger of charges with payments
6 * Copyright (C) 2015 Rich Genandt <rgenandt@gmail.com>
7 * Copyright (C) 2017 Brady Miller <brady.g.miller@gmail.com>
9 * LICENSE: This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
22 * @author Terry Hill <terry@lillysystems.com>
23 * @author Brady Miller <brady.g.miller@gmail.com>
24 * @link http://www.open-emr.org
28 require_once('../globals.php');
29 require_once($GLOBALS['srcdir'].'/patient.inc');
30 require_once($GLOBALS['srcdir'].'/acl.inc');
31 require_once($GLOBALS['srcdir'].'/options.inc.php');
32 require_once($GLOBALS['srcdir'].'/appointments.inc.php');
34 use OpenEMR\Core\Header
;
35 use OpenEMR\Services\FacilityService
;
37 $facilityService = new FacilityService();
39 $enc_units = $total_units = 0;
40 $enc_chg = $total_chg = 0;
41 $enc_pmt = $total_pmt = 0;
42 $enc_adj = $total_adj = 0;
43 $enc_bal = $total_bal = 0;
47 $pat_pid = $_GET['patient_id'];
48 $type_form = $_GET['form'];
50 if (! acl_check('acct', 'rep')) {
51 die(xlt("Unauthorized access."));
54 function GetAllUnapplied($pat = '', $from_dt = '', $to_dt = '')
61 $sql = "SELECT ar_session.*, ins.name, " .
62 "pat.lname, pat.fname, pat.mname, " .
63 "(SELECT SUM(ar_activity.pay_amount) FROM ar_activity WHERE " .
64 "ar_activity.session_id = ar_session.session_id) AS applied " .
66 "LEFT JOIN insurance_companies AS ins on ar_session.payer_id = ins.id " .
67 "LEFT JOIN patient_data AS pat on ar_session.patient_id = pat.pid " .
69 "ar_session.created_time >= ? AND ar_session.created_time <= ? " .
70 "AND ar_session.patient_id=?";
71 $result = sqlStatement($sql, array($from_dt, $to_dt, $pat));
73 while ($row = sqlFetchArray($result)) {
81 function User_Id_Look($thisField)
88 $rlist= sqlStatement("SELECT lname, fname, mname FROM users WHERE id=?", array($thisField));
89 $rrow= sqlFetchArray($rlist);
91 $ret = $rrow{'lname'}.', '.$rrow{'fname'}.' '.$rrow{'mname'};
97 function List_Look($thisData, $thisList)
99 if ($thisList == 'occurrence') {
100 if (!$thisData ||
$thisData == '') {
101 return xl('Unknown or N/A');
105 if ($thisData == '') {
109 $fres=sqlStatement("SELECT title FROM list_options WHERE list_id = ? ".
110 "AND option_id = ? AND activity = 1", array($thisList, $thisData));
112 $rret=sqlFetchArray($fres);
113 $dispValue= xl_list_label($rret{'title'});
114 if ($thisList == 'occurrence' && $dispValue == '') {
115 $dispValue = xl('Unknown or N/A');
118 $dispValue= xl('Not Found');
124 function GetAllCredits($enc = '', $pat = '')
127 if (!$enc ||
!$pat) {
131 $sql = "SELECT activity.*, session.*, ins.name FROM ar_activity AS ".
132 "activity LEFT JOIN ar_session AS session USING (session_id) ".
133 "LEFT JOIN insurance_companies AS ins ON session.payer_id = ".
134 "ins.id WHERE encounter=? AND pid=? ".
135 "ORDER BY sequence_no";
136 $result = sqlStatement($sql, array($enc, $pat));
138 while ($row = sqlFetchArray($result)) {
145 function PrintEncHeader($dt, $rsn, $dr)
147 global $bgcolor, $orow;
148 $bgcolor = (($bgcolor == "#FFFFDD") ?
"#FFDDDD" : "#FFFFDD");
149 echo "<tr bgcolor='#FFFFFF'>";
150 if (strlen($rsn) > 50) {
151 $rsn = substr($rsn, 0, 50).'...';
154 echo "<td colspan='4'><span class='bold'>".xlt('Encounter Dt / Rsn'). ": </span><span class='detail'>".text(substr($dt, 0, 10))." / ".text($rsn)."</span></td>";
155 echo "<td colspan='5'><span class='bold'>" . xlt('Provider'). ": </span><span class='detail'>".text(User_Id_Look($dr))."</span></td>";
159 function PrintEncFooter()
161 global $enc_units, $enc_chg, $enc_pmt, $enc_adj, $enc_bal;
162 echo "<tr bgcolor='#DDFFFF'>";
163 echo "<td colspan='3'> </td>";
164 echo "<td class='detail'>". xlt('Encounter Balance').":</td>";
165 echo "<td class='detail' style='text-align: center;'>".text($enc_units)."</td>";
166 echo "<td class='detail' style='text-align: center;'>".text(oeFormatMoney($enc_chg))."</td>";
167 echo "<td class='detail' style='text-align: right;'>".text(oeFormatMoney($enc_pmt))."</td>";
168 echo "<td class='detail' style='text-align: right;'>".text(oeFormatMoney($enc_adj))."</td>";
169 echo "<td class='detail' style='text-align: right;'>".text(oeFormatMoney($enc_bal))."</td>";
172 function PrintCreditDetail($detail, $pat, $unassigned = false)
174 global $enc_pmt, $total_pmt, $enc_adj, $total_adj, $enc_bal, $total_bal;
175 global $bgcolor, $orow, $enc_units, $enc_chg;
176 foreach ($detail as $pmt) {
179 if (($pmt['pay_total'] - $pmt['applied']) == 0) {
180 if (!$GLOBALS['show_payment_history']) {
187 $bgcolor = (($bgcolor == "#FFFFDD") ?
"#FFDDDD" : "#FFFFDD");
188 $print = "<tr bgcolor='" . attr($bgcolor) . "'>";
189 $print .= "<td class='detail'> </td>";
190 $method = List_Look($pmt['payment_method'], 'payment_method');
191 $desc = $pmt['description'];
192 $ref = $pmt['reference'];
194 $memo = List_Look($pmt['adjustment_code'], 'payment_adjustment_code');
196 $memo = $pmt['memo'];
199 $description = $method;
202 $description .= ' - ';
205 $description .= $ref;
210 $description .= ': ';
213 $description .= $desc;
221 $description .= '['.$memo.']';
223 if ($uap_flag === true) {
227 $description .= '{Pay History}';
229 $print .= "<td class='detail' colspan='2'>".
230 text($description)." </td>";
231 $payer = ($pmt['name'] == '') ?
xl('Patient') : $pmt['name'];
233 $pmt_date = substr($pmt['post_to_date'], 0, 10);
235 $pmt_date = substr($pmt['post_time'], 0, 10);
238 $print .= "<td class='detail'>".
239 text($pmt_date)." / ".text($payer)."</td>";
240 $type = List_Look($pmt['payment_type'], 'payment_type');
241 $print .= "<td class='detail'>".text($type)." </td>";
243 $pmt_amt = $pmt['pay_total'] - $pmt['applied'];
244 $uac_bal = $pmt_amt * -1;
245 $uac_appl = $pmt['applied'];
246 $uac_total = $pmt['pay_total'];
247 $pmt_amt = $pmt['pay_total'];
248 $total_pmt = $total_pmt - $uac_bal;
253 $pmt_amt = $pmt['pay_amount'];
254 $adj_amt = $pmt['adj_amount'];
255 $enc_pmt = $enc_pmt +
$pmt['pay_amount'];
256 $total_pmt = $total_pmt +
$pmt['pay_amount'];
257 $enc_adj = $enc_adj +
$pmt['adj_amount'];
258 $total_adj = $total_adj +
$pmt['adj_amount'];
263 $print_pmt = oeFormatMoney($pmt_amt);
268 $print_adj = oeFormatMoney($adj_amt);
271 $print_appl = $uac_appl ?
oeFormatMoney($uac_appl) : "";
272 $print_bal = $uac_bal ?
oeFormatMoney($uac_bal) : "";
274 $print .= "<td class='detail' style='text-align: center;'>".text($print_appl)." </td>";
275 $print .= "<td class='detail' style='text-align: right;'>".text($print_pmt)." </td>";
276 $print .= "<td class='detail' style='text-align: right;'>".text($print_adj)." </td>";
277 $print .= "<td class='detail' style='text-align: right;'>".text($print_bal)." </td>";
280 if ($pmt['follow_up_note'] != '') {
281 $bgcolor = (($bgcolor == "#FFFFDD") ?
"#FFDDDD" : "#FFFFDD");
282 $print = "<tr bgcolor='". attr($bgcolor) ."'>";
283 $print .= "<td class='detail' colspan='2'> </td>";
284 $print .= "<td colspan='7'>". xlt('Follow Up Note') .": ";
285 $print .= text($pmt['follow_up_note']);
286 $print .= "</td></tr>\n";
291 $total_bal = $total_bal +
$uac_bal;
293 $enc_bal = $enc_bal - $pmt_amt - $adj_amt;
294 $total_bal = $total_bal - $pmt_amt - $adj_amt;
300 $bgcolor = (($bgcolor == "#FFFFDD") ?
"#FFDDDD" : "#FFFFDD");
302 if (!isset($_REQUEST['form_from_date'])) {
303 $_REQUEST['form_from_date'] = '';
306 if (!isset($_REQUEST['form_to_date'])) {
307 $_REQUEST['form_to_date'] = '';
310 if (!isset($_REQUEST['form_facility'])) {
311 $_REQUEST['form_facility'] = '';
314 if (!isset($_REQUEST['form_provider'])) {
315 $_REQUEST['form_provider'] = '';
318 if ($type_form=='0') {
319 if (!isset($_REQUEST['form_patient'])) {
320 $_REQUEST['form_patient'] = '';
323 if (!isset($_REQUEST['form_pid'])) {
324 $_REQUEST['form_pid'] = '';
327 if (!isset($_REQUEST['form_patient'])) {
328 $_REQUEST['form_patient'] = $pat_pid;
331 if (!isset($_REQUEST['form_pid'])) {
332 $_REQUEST['form_pid'] = $pat_pid;
336 if (!isset($_REQUEST['form_csvexport'])) {
337 $_REQUEST['form_csvexport'] = '';
340 if (!isset($_REQUEST['form_refresh'])) {
341 $_REQUEST['form_refresh'] = '';
344 if (!isset($_REQUEST['$form_dob'])) {
345 $_REQUEST['$form_dob'] = '';
348 if (substr($GLOBALS['ledger_begin_date'], 0, 1) == 'Y') {
349 $ledger_time = substr($GLOBALS['ledger_begin_date'], 1, 1);
350 $last_year = mktime(0, 0, 0, date('m'), date('d'), date('Y')-$ledger_time);
351 } elseif (substr($GLOBALS['ledger_begin_date'], 0, 1) == 'M') {
352 $ledger_time = substr($GLOBALS['ledger_begin_date'], 1, 1);
353 $last_year = mktime(0, 0, 0, date('m')-$ledger_time, date('d'), date('Y'));
354 } elseif (substr($GLOBALS['ledger_begin_date'], 0, 1) == 'D') {
355 $ledger_time = substr($GLOBALS['ledger_begin_date'], 1, 1);
356 $last_year = mktime(0, 0, 0, date('m'), date('d')-$ledger_time, date('Y'));
359 $form_from_date = date('Y-m-d', $last_year);
360 if ($_REQUEST['form_from_date']) {
361 $form_from_date = fixDate($_REQUEST['form_from_date'], $last_year);
364 $form_to_date = fixDate($_REQUEST['form_to_date'], date('Y-m-d'));
365 $form_facility = $_REQUEST['form_facility'];
366 $form_provider = $_REQUEST['form_provider'];
367 $form_patient = $_REQUEST['form_patient'];
368 $form_pid = $_REQUEST['form_pid'];
369 $form_dob = $_REQUEST['form_dob'];
371 if ($_REQUEST['form_csvexport']) {
372 header("Pragma: public");
373 header("Expires: 0");
374 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
375 header("Content-Type: application/force-download");
376 header("Content-Disposition: attachment; filename=svc_financial_report_".attr($form_from_date)."--".attr($form_to_date).".csv");
377 header("Content-Description: File Transfer");
383 <?php Header
::setupHeader('datetime-picker'); ?
>
384 <script type
="text/javascript">
385 var mypcc
= '<?php echo $GLOBALS['phone_country_code
']; ?>';
388 function checkSubmit() {
389 var pat
= document
.forms
[0].elements
['form_patient'].value
;
390 if(!pat || pat
== 0) {
391 alert('<?php echo xls('A Patient Must Be Selected to Generate This Report
') ?>');
394 document
.forms
[0].elements
['form_refresh'].value
= true;
395 document
.forms
[0].elements
['form_csvexport'].value
= '';
396 document
.forms
[0].submit();
398 function setpatient(pid
, lname
, fname
, dob
) {
399 document
.forms
[0].elements
['form_patient'].value
= lname +
', ' + fname
;
400 document
.forms
[0].elements
['form_pid'].value
= pid
;
401 document
.forms
[0].elements
['form_dob'].value
= dob
;
403 function sel_patient() {
404 dlgopen('../main/calendar/find_patient_popup.php?pflag=0', '_blank', 500, 400);
408 <style type
="text/css">
410 /* specifically include & exclude from printing */
416 #report_parameters_daterange {
432 /* specifically exclude some from the screen */
434 #report_parameters_daterange {
449 <title
><?php
echo xlt('Patient Ledger by Date') ?
></title
>
451 <script language
="JavaScript">
452 $
(document
).ready(function() {
453 var win
= top
.printLogSetup ? top
: opener
.top
;
454 win
.printLogSetup(document
.getElementById('printbutton'));
456 $
('.datepicker').datetimepicker({
457 <?php
$datetimepicker_timepicker = false; ?
>
458 <?php
$datetimepicker_showseconds = false; ?
>
459 <?php
$datetimepicker_formatInput = false; ?
>
460 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
461 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
467 <body
class="body_top">
468 <?php
if ($type_form == '0') { ?
>
469 <span
class='title' id
='title'><?php
echo xlt('Report'); ?
> - <?php
echo xlt('Patient Ledger by Date'); ?
></span
>
471 <span
class='title' id
='title'><?php
echo xlt('Patient Ledger'); ?
></span
>
473 <form method
='post' action
='pat_ledger.php?form=<?php echo attr($type_form);?>&patient_id=<?php echo attr($form_pid);?>' id
='theform'>
474 <div id
="report_parameters">
475 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
476 <input type
='hidden' name
='form_csvexport' id
='form_csvexport' value
=''/>
479 <?php
if ($type_form == '1') { ?
>
484 <div style
='float:left'>
487 <?php
if ($type_form == '0') { ?
>
488 <td
class='control-label'>
489 <?php
echo xlt('Facility'); ?
>:
492 <?php
dropdown_facility($form_facility, 'form_facility', true); ?
>
494 <td
class='control-label'><?php
echo xlt('Provider'); ?
>:</td
>
496 $query = "SELECT id, lname, fname FROM users WHERE ".
497 "authorized=1 AND active!=0 ORDER BY lname, fname";
498 $ures = sqlStatement($query);
499 echo " <select name='form_provider' class='form-control'>\n";
500 echo " <option value=''>-- " . xlt('All') . " --\n";
501 while ($urow = sqlFetchArray($ures)) {
502 $provid = $urow['id'];
503 echo " <option value='" . attr($provid) ."'";
504 if ($provid == $_REQUEST['form_provider']) {
508 echo ">" . text($urow['lname']) . ", " . text($urow['fname']) . "\n";
515 <td
class='control-label'>
516 <?php
echo xlt('From'); ?
>: 
; 
; 
; 
;
519 <input type
='text' class='datepicker form-control' name
='form_from_date' id
="form_from_date" size
='10' value
='<?php echo attr($form_from_date) ?>' title
='yyyy-mm-dd'>
521 <td
class='control-label' class='control-label'>
522 <?php
echo xlt('To'); ?
>:
525 <input type
='text' class='datepicker form-control' name
='form_to_date' id
="form_to_date" size
='10' value
='<?php echo attr($form_to_date) ?>' title
='yyyy-mm-dd'>
527 <?php
if ($type_form == '0') { ?
>
528 <td
><span
class='control-label'><?php
echo xlt('Patient'); ?
>: 
; 
;</span
></td
>
530 <input type
='text' size
='20' name
='form_patient' class='form-control' 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
'); ?>' />
532 <input type
='hidden' name
='form_patient' value
='<?php echo attr($form_patient); ?>' />
534 <input type
='hidden' name
='form_pid' value
='<?php echo attr($form_pid); ?>' />
535 <input type
='hidden' name
='form_dob' value
='<?php echo attr($form_dob); ?>' />
542 <td align
='left' valign
='middle' height
="100%">
543 <table style
='border-left:1px solid; width:100%; height:100%' >
546 <div
class="text-center">
547 <div
class="btn-group" role
="group">
548 <a href
='#' class='btn btn-default btn-save' onclick
="checkSubmit();" >
549 <?php
echo xlt('Submit'); ?
>
551 <?php
if ($_REQUEST['form_refresh'] ||
$_REQUEST['form_csvexport']) { ?
>
552 <a href
='#' class='btn btn-default btn-print' id
='printbutton'>
553 <?php
echo xlt('Print Ledger'); ?
>
555 <?php
if ($type_form == '1') { ?
>
556 <a href
="../patient_file/summary/demographics.php" class="btn btn-default btn-transmit" onclick
="top.restoreSession()">
557 <?php
echo xlt('Back To Patient');?
>
569 </div
> <!-- end of parameters
-->
573 $from_date = $form_from_date . ' 00:00:00';
574 $to_date = $form_to_date . ' 23:59:59';
575 if ($_REQUEST['form_refresh'] ||
$_REQUEST['form_csvexport']) {
577 $sqlBindArray = array();
578 $query = "select b.code_type, b.code, b.code_text, b.pid, b.provider_id, ".
579 "b.billed, b.payer_id, b.units, b.fee, b.bill_date, b.id, ".
581 "fe.encounter, fe.date, fe.reason, fe.provider_id ".
582 "FROM form_encounter AS fe ".
583 "LEFT JOIN billing AS b ON b.pid=fe.pid AND b.encounter=fe.encounter ".
584 "LEFT JOIN insurance_companies AS ins ON b.payer_id = ins.id ".
585 "LEFT OUTER JOIN code_types AS c ON c.ct_key = b.code_type ".
586 "WHERE fe.date >= ? AND fe.date <= ? AND fe.pid = ? ";
587 array_push($sqlBindArray, $from_date, $to_date, $form_pid);
588 if ($form_facility) {
589 $query .= "AND fe.facility_id = ? ";
590 array_push($sqlBindArray, $form_facility);
593 if ($form_provider) {
594 $query .= "AND b.provider_id = ? ";
595 array_push($sqlBindArray, $form_provider);
598 $query .= "AND c.ct_proc = '1' ";
599 $query .= "AND activity > 0 ORDER BY fe.date, fe.id ";
600 $res = sqlStatement($query, $sqlBindArray);
602 if ($_REQUEST['form_csvexport']) {
605 echo '"Code/Enc Dt",';
606 echo '"Description",';
607 echo '"Billed/Who",';
608 echo '"Type/Units",';
609 echo '"Chg/Pmt Amount",'."\n";
612 if (!$form_facility) {
613 $form_facility = '3';
616 $facility = $facilityService->getById($form_facility);
617 $patient = sqlQuery("SELECT * from patient_data WHERE pid=?", array($form_patient));
618 $pat_dob = $patient['DOB'];
619 $pat_name = $patient['fname']. ' ' . $patient['lname'];
621 <div id
="report_header">
622 <table width
="98%" border
="0" cellspacing
="0" cellpadding
="0">
624 <td
class="title" ><?php
echo text($facility{'name'}); ?
></td
>
627 <td
class="title" ><?php
echo text($facility{'street'}); ?
></td
>
630 <td
class="title" ><?php
echo text($facility{'city'}).", ".text($facility{'state'})." ".text($facility{'postal_code'}); ?
></td
>
633 <td
class="title" ><?php
echo xlt('Phone').': ' .text($facility{'phone'}); ?
></td
>
636 <td
class="title" ><?php
echo xlt('Tax Id').': ' .text($facility{'federal_ein'}); ?
></td
>
638 <tr
><td
> 
;</td
></tr
>
640 <td
class="title" ><?php
echo xlt('Patient Ledger'); ?
></td
>
644 $title = xl('All Providers');
645 if ($form_provider) {
646 $title = xl('For Provider') . ': '.User_Id_Look($form_provider);
649 <td
class="title" ><?php
echo text($title); ?
></td
>
653 $title = xl('For Dates') . ': '.$form_from_date.' - '.$form_to_date;
655 <td
class="title" ><?php
echo text($title); ?
></td
>
659 <table width
="100%" border
="0" cellspacing
="0" cellpadding
="0">
661 <td
class='bold' ><?php
echo xlt('Date')?
>:
662 <?php
echo text(date('Y-m-d')); ?
></td
>
663 <td
class='bold' ><?php
echo xlt('Patient')?
>:
664 <?php
if ($type_form == '1') { ?
>
665 <?php
echo text($pat_name); ?
></td
>
667 <?php
echo text($form_patient); ?
></td
>
669 <td
class='bold' ><?php
echo xlt('DOB')?
>:
670 <?php
if ($type_form == '1') { ?
>
671 <?php
echo text($pat_dob);?
></td
>
673 <?php
echo text($form_dob); ?
></td
>
675 <td
class='bold' > <?php
echo xlt('ID')?
>:
676 <?php
echo text($form_pid);?
></td
>
680 <div id
="report_results">
683 <td
class='bold' ><?php
echo xlt('Code'); ?
></td
>
684 <td colspan
="2" class='bold' ><?php
echo xlt('Description'); ?
></td
>
685 <td
class='bold' ><?php
echo xlt('Billed Date'); ?
> / <?php
echo xlt('Payor'); ?
></td
>
686 <td
class='bold' ><?php
echo xlt('Type'); ?
> 
; 
; 
; 
; 
; 
; 
;
687 <?php
echo xlt('Units'); ?
></td
>
688 <td
class='bold' > 
; 
; 
; 
; 
;<?php
echo xlt('Charge'); ?
></td
>
689 <td align
='right' class='bold' > 
; 
;<?php
echo xlt('Payment'); ?
></td
>
690 <td align
='right' class='bold' > 
; 
; 
; 
; 
;<?php
echo xlt('Adjustment'); ?
></td
>
691 <td align
='right' class='bold' > 
; 
; 
;<?php
echo xlt('Balance'); ?
></td
>
694 <td
> 
; 
; 
;</td
>
695 <td colspan
="2" > 
; 
; 
;</td
>
696 <td
> 
; 
; 
; 
; 
; 
;</td
>
697 <td
> 
; 
; 
; 
; 
; 
; 
; 
;
698  
; 
; 
;</td
>
699 <td
class='bold' > 
; 
; 
;<?php
echo xlt('UAC Appl'); ?
></td
>
700 <td align
='right' class='bold' > 
; 
; 
; 
; 
;<?php
echo xlt('UAC Tot'); ?
></td
>
708 $prev_encounter_id = -1;
709 $hdr_printed = false;
711 while ($erow = sqlFetchArray($res)) {
714 if ($erow['encounter'] != $prev_encounter_id) {
715 if ($prev_encounter_id != -1) {
716 $credits = GetAllCredits($prev_encounter_id, $form_pid);
717 if (count($credits) > 0) {
722 $prev_row{'provider_id'}
726 PrintCreditDetail($credits, $form_pid);
733 $hdr_printed = false;
736 $enc_units = $enc_chg = $enc_pmt = $enc_adj = $enc_bal = 0;
740 // Now print an encounter heading line -
750 $code_desc = $erow['code_text'];
751 if (strlen($code_desc) > 50) {
752 $code_desc = substr($code_desc, 0, 50).'...';
755 $bgcolor = (($bgcolor == "#FFFFDD") ?
"#FFDDDD" : "#FFFFDD");
756 $print = "<tr bgcolor='". attr($bgcolor) ."'>";
757 $print .= "<td class='detail'>".text($erow['code'])."</td>";
758 $print .= "<td class='detail' colspan='2'>".text($code_desc)."</td>";
759 $who = ($erow['name'] == '') ?
xl('Self') : $erow['name'];
760 $bill = substr($erow['bill_date'], 0, 10);
765 $print .= "<td class='detail'>".text($bill)." / ".text($who)."</td>";
766 $print .= "<td class='detail' style='text-align: center;'>". text($erow['units'])."</td>";
767 $print .= "<td class='detail' style='text-align: center;'>". text(oeFormatMoney($erow['fee']))."</td>";
768 $print .= "<td> </td><td> </td><td> </td>";
771 $total_units +
= $erow['units'];
772 $total_chg +
= $erow['fee'];
773 $total_bal +
= $erow['fee'];
774 $enc_units +
= $erow['units'];
775 $enc_chg +
= $erow['fee'];
776 $enc_bal +
= $erow['fee'];
779 if ($_REQUEST['form_csvexport']) {
786 $prev_encounter_id = $erow{'encounter'};
790 if ($prev_encounter_id != -1) {
791 $credits = GetAllCredits($prev_encounter_id, $form_pid);
792 if (count($credits) > 0) {
797 $prev_row{'provider_id'}
801 PrintCreditDetail($credits, $form_pid);
809 // This is the end of the encounter/charge loop -
810 $uac = GetAllUnapplied($form_pid, $from_date, $to_date);
811 if (count($uac) > 0) {
813 $bgcolor = (($bgcolor == "#FFFFDD") ?
"#FFDDDD" : "#FFFFDD");
814 echo "<tr bgcolor='#FFFFFF'><td colspan='9'> </td></tr>\n";
817 PrintCreditDetail($uac, $form_pid, true);
820 if (!$_REQUEST['form_csvexport'] && $orow) {
821 echo "<tr bgcolor='#DDFFFF'>\n";
822 echo " <td colspan='2'> </td>";
823 echo " <td class='bold' colspan='2'>" . xlt("Grand Total") ."</td>\n";
824 echo " <td class='bold' style='text-align: center;'>". text($total_units) ."</td>\n";
825 echo " <td class='bold' style='text-align: center;'>". text(oeFormatMoney($total_chg)) ."</td>\n";
826 echo " <td class='bold' style='text-align: right;'>". text(oeFormatMoney($total_pmt)) ."</td>\n";
827 echo " <td class='bold' style='text-align: right;'>". text(oeFormatMoney($total_adj)) ."</td>\n";
828 echo " <td class='bold' style='text-align: right;'>". text(oeFormatMoney($total_bal)) . "</td>\n";
832 <tr
><td
> 
;</td
></tr
><br
><br
>
833 <?php
if ($GLOBALS['print_next_appointment_on_ledger'] == 1) {
834 $next_day = mktime(0, 0, 0, date('m'), date('d')+
1, date('Y'));
835 # add one day to date so it will not get todays appointment
836 $current_date2 = date('Y-m-d', $next_day);
837 $events = fetchNextXAppts($current_date2, $form_pid);
838 $next_appoint_date = oeFormatShortDate($events[0]['pc_eventDate']);
839 $next_appoint_time = substr($events[0]['pc_startTime'], 0, 5);
840 if (strlen(umname
) != 0) {
841 $next_appoint_provider = $events[0]['ufname'] . ' ' . $events[0]['umname'] . ' ' . $events[0]['ulname'];
843 $next_appoint_provider = $events[0]['ufname'] . ' ' . $events[0]['ulname'];
846 if (strlen($next_appoint_time) != 0) {
849 <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
>
854 } // end ($GLOBALS['print_next_appointment_on_ledger'] == 1)
855 } // end (!$_REQUEST['form_csvexport'] && $orow)
859 if (! $_REQUEST['form_csvexport']) {
860 if ($_REQUEST['form_refresh'] && $orow <= 0) {
861 echo "<span style='font-size:10pt;'>";
862 echo xlt('No matches found. Try search again.');
864 echo '<script>document.getElementById("report_results").style.display="none";</script>';
865 echo '<script>document.getElementById("controls").style.display="none";</script>';
868 if (!$_REQUEST['form_refresh'] && !$_REQUEST['form_csvexport']) { ?
>
870 <?php
echo xlt('Please input search criteria above, and click Submit to view results.'); ?
>
878 } // End not csv export