migrated ubiquitous libraries to composer autoloader (#421)
[openemr.git] / interface / reports / pat_ledger.php
bloba82461b20254a0aa75c63238ab55e66e3fd3288b
1 <?php
2 /**
3 * This is a report to create a patient ledger of charges with payments
4 * applied.
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>;.
19 * @package OpenEMR
20 * @author WMT
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;
39 $bgcolor = "#FFFFDD";
40 $orow = 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='') {
48 $all = array();
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 " .
54 "FROM ar_session " .
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 " .
57 "WHERE " .
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));
61 $iter = 0;
62 while($row = sqlFetchArray($result)) {
63 $all[$iter] = $row;
64 $iter++;
66 return($all);
69 function User_Id_Look($thisField) {
70 if(!$thisField) return '';
71 $ret = '';
72 $rlist= sqlStatement("SELECT lname, fname, mname FROM users WHERE id=?",array($thisField));
73 $rrow= sqlFetchArray($rlist);
74 if($rrow) {
75 $ret = $rrow{'lname'}.', '.$rrow{'fname'}.' '.$rrow{'mname'};
77 return $ret;
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));
87 if($fres) {
88 $rret=sqlFetchArray($fres);
89 $dispValue= xl_list_label($rret{'title'});
90 if($thisList == 'occurrence' && $dispValue == '') {
91 $dispValue = xl('Unknown or N/A');
93 } else {
94 $dispValue= xl('Not Found');
96 return $dispValue;
99 function GetAllCredits($enc = '', $pat='') {
100 $all = array();
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));
108 $iter = 0;
109 while($row = sqlFetchArray($result)) {
110 $all[$iter] = $row;
111 $iter++;
113 return($all);
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>";
122 echo "</tr>\n";
123 $orow++;
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'>&nbsp;</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>";
135 echo "</tr>\n";
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) {
141 if($unassigned) {
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'>&nbsp;</td>";
147 $method = List_Look($pmt['payment_method'],'payment_method');
148 $desc = $pmt['description'];
149 $ref = $pmt['reference'];
150 if($unassigned) {
151 $memo = List_Look($pmt['adjustment_code'],'payment_adjustment_code');
152 } else {
153 $memo = $pmt['memo'];
155 $description = $method;
156 if($ref) {
157 if($description) { $description .= ' - '; }
158 $description .= $ref;
160 if($desc) {
161 if($description) { $description .= ': '; }
162 $description .= $desc;
164 if($memo) {
165 if($description) { $description .= ' '; }
166 $description .= '['.$memo.']';
168 $print .= "<td class='detail' colspan='2'>".
169 text($description)."&nbsp;</td>";
170 $payer = ($pmt['name'] == '') ? xl('Patient') : $pmt['name'];
171 if($unassigned) {
172 $pmt_date = substr($pmt['post_to_date'],0,10);
173 } else {
174 $pmt_date = substr($pmt['post_time'],0,10);
176 $print .= "<td class='detail'>".
177 text($pmt_date)."&nbsp;/&nbsp;".text($payer)."</td>";
178 $type = List_Look($pmt['payment_type'],'payment_type');
179 $print .= "<td class='detail'>".text($type)."&nbsp;</td>";
180 if($unassigned) {
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;
187 } else {
188 $uac_total = '';
189 $uac_bal = '';
190 $uac_appl = '';
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'];
198 $print_pmt = '';
199 if($pmt_amt != 0) $print_pmt = oeFormatMoney($pmt_amt);
200 $print_adj = '';
201 if($adj_amt != 0) $print_adj = oeFormatMoney($adj_amt);
202 $print .= "<td class='detail' style='text-align: right;'>".text($uac_appl)."&nbsp;</td>";
203 $print .= "<td class='detail' style='text-align: right;'>".text($print_pmt)."&nbsp;</td>";
204 $print .= "<td class='detail' style='text-align: right;'>".text($print_adj)."&nbsp;</td>";
205 $print .= "<td class='detail' style='text-align: right;'>".text($uac_bal)."&nbsp;</td>";
206 $print .= "</tr>\n";
207 echo $print;
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'>&nbsp;</td>";
212 $print .= "<td colspan='7'>". xlt('Follow Up Note') .": ";
213 $print .= text($pmt['follow_up_note']);
214 $print .= "</td></tr>\n";
215 echo $print;
217 if($unassigned) {
218 $total_bal = $total_bal + $uac_bal;
219 } else {
220 $enc_bal = $enc_bal - $pmt_amt - $adj_amt;
221 $total_bal = $total_bal - $pmt_amt - $adj_amt;
223 $orow++;
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'] = ''; }
235 else
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");
275 } else {
277 <html>
278 <head>
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']; ?>';
286 var pt_name;
287 var pt_id;
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') ?>');
292 return false;
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);
306 </script>
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 */
313 @media print {
314 #report_parameters {
315 visibility: hidden;
316 display: none;
318 #report_parameters_daterange {
319 visibility: visible;
320 display: inline;
322 #report_results {
323 margin-top: 30px;
325 #report_header {
326 visibility: visible;
327 display: inline;
329 #title {
330 visibility: hidden;
331 display: none;
334 /* specifically exclude some from the screen */
335 @media screen {
336 #report_parameters_daterange {
337 visibility: hidden;
338 display: none;
340 #report_header {
341 visibility: hidden;
342 display: none;
344 #title {
345 visibility: visible;
346 display: inline;
349 </style>
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'));
358 </script>
360 </head>
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>
364 <?php }else{ ?>
365 <span class='title' id='title'><?php echo xlt('Patient Ledger'); ?></span>
366 <?php } ?>
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=''/>
371 <table>
372 <tr>
373 <?php if($type_form == '1') { ?>
374 <td width='35%'>
375 <?php }else{ ?>
376 <td width='70%'>
377 <?php } ?>
378 <div style='float:left'>
379 <table class='text'>
380 <tr>
381 <?php if($type_form == '0') { ?>
382 <td class='label'>
383 <?php echo xlt('Facility'); ?>:
384 </td>
385 <td>
386 <?php dropdown_facility($form_facility, 'form_facility', true); ?>
387 </td>
388 <td><?php echo xlt('Provider'); ?>:</td>
389 <td><?php
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";
401 echo " </select>\n";
402 ?></td>
403 </tr><tr>
404 <?php } ?>
405 <td colspan="2">
406 <?php echo xlt('From'); ?>:&nbsp;&nbsp;&nbsp;&nbsp;
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"); ?>'>
409 </td>
410 <td class='label'>
411 <?php echo xlt('To'); ?>:
412 </td>
413 <td>
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"); ?>'>
416 </td>
417 <?php if($type_form == '0') { ?>
418 <td><span class='label'><?php echo xlt('Patient'); ?>:&nbsp;&nbsp;</span></td>
419 <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'); ?>' />
421 <?php }else{ ?>
422 <input type='hidden' name='form_patient' value='<?php echo attr($form_patient); ?>' />
423 <?php } ?>
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); ?>' />
427 </td>
428 </tr>
429 </table>
430 </div>
431 </td>
432 <td align='left' valign='middle' height="100%">
433 <table style='border-left:1px solid; width:100%; height:100%' >
434 <tr>
435 <td>
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']) { ?>
441 <div id="controls">
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>
447 <?php } ?>
448 </div>
449 <?php } ?>
450 </div>
451 </td>
452 </tr>
453 </table>
454 </td>
455 </tr>
456 </table>
457 </div> <!-- end of parameters -->
459 <?php
460 } // end not export
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']) {
464 $rows = array();
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, ".
468 "ins.name, ".
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']) {
489 // CSV headers:
490 if (true) {
491 echo '"Code/Enc Dt",';
492 echo '"Description",';
493 echo '"Billed/Who",';
494 echo '"Type/Units",';
495 echo '"Chg/Pmt Amount",'."\n";
497 } else {
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">
506 <tr>
507 <td class="title" ><?php echo text($facility{'name'}); ?></td>
508 </tr>
509 <tr>
510 <td class="title" ><?php echo text($facility{'street'}); ?></td>
511 </tr>
512 <tr>
513 <td class="title" ><?php echo text($facility{'city'}).", ".text($facility{'state'})." ".text($facility{'postal_code'}); ?></td>
514 </tr>
515 <tr>
516 <td class="title" ><?php echo xlt('Phone').': ' .text($facility{'phone'}); ?></td>
517 </tr>
518 <tr>
519 <td class="title" ><?php echo xlt('Tax Id').': ' .text($facility{'federal_ein'}); ?></td>
520 </tr>
521 <tr><td>&nbsp;</td></tr>
522 <tr>
523 <td class="title" ><?php echo xlt('Patient Ledger'); ?></td>
524 </tr>
525 <tr>
526 <?php
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>
531 </tr>
532 <tr>
533 <?php
534 $title = xl('For Dates') . ': '.$form_from_date.' - '.$form_to_date;
536 <td class="title" ><?php echo text($title); ?></td>
537 </tr>
538 </table>
539 <br/>
540 <table width="100%" border="0" cellspacing="0" cellpadding="0">
541 <tr>
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>
547 <?php }else{ ?>
548 <?php echo text($form_patient); ?></td>
549 <?php } ?>
550 <td class='bold' ><?php echo xlt('DOB')?>:
551 <?php if($type_form == '1') { ?>
552 <?php echo text($pat_dob);?></td>
553 <?php }else{ ?>
554 <?php echo text($form_dob); ?></td>
555 <?php } ?>
556 <td class='bold' > <?php echo xlt('ID')?>:
557 <?php echo text($form_pid);?></td>
558 </tr>
559 </table>
560 </div>
561 <div id="report_results">
562 <table >
563 <tr>
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'); ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
568 <?php echo xlt('Units'); ?></td>
569 <td class='bold' >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo xlt('Charge'); ?></td>
570 <td align='right' class='bold' >&nbsp;&nbsp;<?php echo xlt('Payment'); ?></td>
571 <td align='right' class='bold' >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo xlt('Adjustment'); ?></td>
572 <td align='right' class='bold' >&nbsp;&nbsp;&nbsp;<?php echo xlt('Balance'); ?></td>
573 </tr>
574 <tr>
575 <td>&nbsp;&nbsp;&nbsp;</td>
576 <td colspan="2" >&nbsp;&nbsp;&nbsp;</td>
577 <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
578 <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
579 &nbsp;&nbsp;&nbsp;</td>
580 <td class='bold' >&nbsp;&nbsp;&nbsp;<?php echo xlt('UAC Appl'); ?></td>
581 <td align='right' class='bold' >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo xlt('UAC Tot'); ?></td>
582 <td>&nbsp;</td>
583 <td>&nbsp;</td>
584 </tr>
585 <?php
587 $orow = 0;
588 $prev_encounter_id = -1;
589 $hdr_printed = false;
590 $prev_row = array();
591 while ($erow = sqlFetchArray($res)) {
592 $print = '';
593 $csv = '';
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) {
598 if(!$hdr_printed) {
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;
609 if($erow{'id'}) {
610 // Now print an encounter heading line -
611 if(!$hdr_printed) {
612 PrintEncHeader($erow{'date'},
613 $erow{'reason'}, $erow{'provider_id'});
614 $hdr_printed = true;
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)."&nbsp;/&nbsp;".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>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>";
630 $print .= "</tr>\n";
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'];
638 $orow++;
640 if ($_REQUEST['form_csvexport']) {
641 echo $csv;
642 } else {
643 echo $print;
646 $prev_encounter_id = $erow{'encounter'};
647 $prev_row = $erow;
649 if($prev_encounter_id != -1) {
650 $credits = GetAllCredits($prev_encounter_id, $form_pid);
651 if(count($credits) > 0) {
652 if(!$hdr_printed) {
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) {
663 if($orow) {
664 $bgcolor = (($bgcolor == "#FFFFDD") ? "#FFDDDD" : "#FFFFDD");
665 echo "<tr bgcolor='#FFFFFF'><td colspan='9'>&nbsp;</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'>&nbsp;</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";
678 echo " </tr>\n";
680 </table>
681 <tr><td>&nbsp;</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'];
692 else
694 $next_appoint_provider = $events[0]['ufname'] . ' ' . $events[0]['ulname'];
696 if(strlen($next_appoint_time) != 0) {
698 <tr>
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>
700 </tr>
702 <?php
704 } // end ($GLOBALS['print_next_appointment_on_ledger'] == 1)
705 } // end (!$_REQUEST['form_csvexport'] && $orow)
706 echo "</div>\n";
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.');
712 echo "</span>";
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']) { ?>
718 <div class='text'>
719 <?php echo xlt('Please input search criteria above, and click Submit to view results.' ); ?>
720 </div>
721 <?php } ?>
722 </form>
723 </body>
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();
736 </script>
737 </html>
738 <?php
739 } // End not csv export