Support for optional logging of print actions.
[openemr.git] / interface / billing / indigent_patients_report.php
blob911463c7c73acb0e81a3b8d311c6669a328b2f05
1 <?php
2 // Copyright (C) 2005-2015 Rod Roark <rod@sunsetsystems.com>
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 // This is the Indigent Patients Report. It displays a summary of
10 // encounters within the specified time period for patients without
11 // insurance.
13 require_once("../globals.php");
14 require_once("$srcdir/patient.inc");
15 require_once("$srcdir/sql-ledger.inc");
16 require_once("$srcdir/formatting.inc.php");
18 $alertmsg = '';
20 function bucks($amount) {
21 if ($amount) return oeFormatMoney($amount);
22 return "";
25 $form_start_date = fixDate($_POST['form_start_date'], date("Y-01-01"));
26 $form_end_date = fixDate($_POST['form_end_date'], date("Y-m-d"));
28 $INTEGRATED_AR = $GLOBALS['oer_config']['ws_accounting']['enabled'] === 2;
30 if (!$INTEGRATED_AR) SLConnect();
32 <html>
33 <head>
34 <?php html_header_show(); ?>
35 <style type="text/css">
37 /* specifically include & exclude from printing */
38 @media print {
39 #report_parameters {
40 visibility: hidden;
41 display: none;
43 #report_parameters_daterange {
44 visibility: visible;
45 display: inline;
47 #report_results table {
48 margin-top: 0px;
52 /* specifically exclude some from the screen */
53 @media screen {
54 #report_parameters_daterange {
55 visibility: hidden;
56 display: none;
59 </style><link rel="stylesheet" href="<?php echo $css_header; ?>" type="text/css">
60 <title><?php xl('Indigent Patients Report','e')?></title>
62 <script type="text/javascript" src="../../library/js/jquery.1.3.2.js"></script>
64 <script language="JavaScript">
66 $(document).ready(function() {
67 var win = top.printLogSetup ? top : opener.top;
68 win.printLogSetup(document.getElementById('printbutton'));
69 });
71 </script>
73 </head>
75 <body class="body_top">
77 <span class='title'><?php xl('Report','e'); ?> - <?php xl('Indigent Patients','e'); ?></span>
79 <form method='post' action='indigent_patients_report.php' id='theform'>
81 <div id="report_parameters">
83 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
85 <table>
86 <tr>
87 <td width='410px'>
88 <div style='float:left'>
90 <table class='text'>
91 <tr>
92 <td class='label'>
93 <?php xl('Visits From','e'); ?>:
94 </td>
95 <td>
96 <input type='text' name='form_start_date' id="form_start_date" size='10' value='<?php echo $form_start_date ?>'
97 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
98 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
99 id='img_start_date' border='0' alt='[?]' style='cursor:pointer'
100 title='<?php xl('Click here to choose a date','e'); ?>'>
101 </td>
102 <td class='label'>
103 <?php xl('To','e'); ?>:
104 </td>
105 <td>
106 <input type='text' name='form_end_date' id="form_end_date" size='10' value='<?php echo $form_end_date ?>'
107 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
108 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
109 id='img_end_date' border='0' alt='[?]' style='cursor:pointer'
110 title='<?php xl('Click here to choose a date','e'); ?>'>
111 </td>
112 </tr>
113 </table>
115 </div>
117 </td>
118 <td align='left' valign='middle' height="100%">
119 <table style='border-left:1px solid; width:100%; height:100%' >
120 <tr>
121 <td>
122 <div style='margin-left:15px'>
123 <a href='#' class='css_button' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
124 <span>
125 <?php xl('Submit','e'); ?>
126 </span>
127 </a>
129 <?php if ($_POST['form_refresh']) { ?>
130 <a href='#' class='css_button' id='printbutton'>
131 <span>
132 <?php xl('Print','e'); ?>
133 </span>
134 </a>
135 <?php } ?>
136 </div>
137 </td>
138 </tr>
139 </table>
140 </td>
141 </tr>
142 </table>
143 </div> <!-- end of parameters -->
145 <div id="report_results">
146 <table>
148 <thead bgcolor="#dddddd">
149 <th>
150 &nbsp;<?php xl('Patient','e')?>
151 </th>
152 <th>
153 &nbsp;<?php xl('SSN','e')?>
154 </th>
155 <th>
156 &nbsp;<?php xl('Invoice','e')?>
157 </th>
158 <th>
159 &nbsp;<?php xl('Svc Date','e')?>
160 </th>
161 <th>
162 &nbsp;<?php xl('Due Date','e')?>
163 </th>
164 <th align="right">
165 <?php xl('Amount','e')?>&nbsp;
166 </th>
167 <th align="right">
168 <?php xl('Paid','e')?>&nbsp;
169 </th>
170 <th align="right">
171 <?php xl('Balance','e')?>&nbsp;
172 </th>
173 </thead>
175 <?php
176 if ($_POST['form_search']) {
178 $where = "";
180 if ($form_start_date) {
181 $where .= " AND e.date >= '$form_start_date'";
183 if ($form_end_date) {
184 $where .= " AND e.date <= '$form_end_date'";
187 $rez = sqlStatement("SELECT " .
188 "e.date, e.encounter, p.pid, p.lname, p.fname, p.mname, p.ss " .
189 "FROM form_encounter AS e, patient_data AS p, insurance_data AS i " .
190 "WHERE p.pid = e.pid AND i.pid = e.pid AND i.type = 'primary' " .
191 "AND i.provider = ''$where " .
192 "ORDER BY p.lname, p.fname, p.mname, p.pid, e.date"
195 $total_amount = 0;
196 $total_paid = 0;
198 for ($irow = 0; $row = sqlFetchArray($rez); ++$irow) {
199 $patient_id = $row['pid'];
200 $encounter_id = $row['encounter'];
201 $invnumber = $row['pid'] . "." . $row['encounter'];
203 if ($INTEGRATED_AR) {
204 $inv_duedate = '';
205 $arow = sqlQuery("SELECT SUM(fee) AS amount FROM drug_sales WHERE " .
206 "pid = '$patient_id' AND encounter = '$encounter_id'");
207 $inv_amount = $arow['amount'];
208 $arow = sqlQuery("SELECT SUM(fee) AS amount FROM billing WHERE " .
209 "pid = '$patient_id' AND encounter = '$encounter_id' AND " .
210 "activity = 1 AND code_type != 'COPAY'");
211 $inv_amount += $arow['amount'];
212 $arow = sqlQuery("SELECT SUM(fee) AS amount FROM billing WHERE " .
213 "pid = '$patient_id' AND encounter = '$encounter_id' AND " .
214 "activity = 1 AND code_type = 'COPAY'");
215 $inv_paid = 0 - $arow['amount'];
216 $arow = sqlQuery("SELECT SUM(pay_amount) AS pay, " .
217 "sum(adj_amount) AS adj FROM ar_activity WHERE " .
218 "pid = '$patient_id' AND encounter = '$encounter_id'");
219 $inv_paid += $arow['pay'];
220 $inv_amount -= $arow['adj'];
222 else {
223 $ares = SLQuery("SELECT duedate, amount, paid FROM ar WHERE " .
224 "ar.invnumber = '$invnumber'");
225 if ($sl_err) die($sl_err);
226 if (SLRowCount($ares) == 0) continue;
227 $arow = SLGetRow($ares, 0);
228 $inv_amount = $arow['amount'];
229 $inv_paid = $arow['paid'];
230 $inv_duedate = $arow['duedate'];
232 $total_amount += bucks($inv_amount);
233 $total_paid += bucks($inv_paid);
235 $bgcolor = (($irow & 1) ? "#ffdddd" : "#ddddff");
237 <tr bgcolor='<?php echo $bgcolor ?>'>
238 <td class="detail">
239 &nbsp;<?php echo $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'] ?>
240 </td>
241 <td class="detail">
242 &nbsp;<?php echo $row['ss'] ?>
243 </td>
244 <td class="detail">
245 &nbsp;<?php echo $invnumber ?></a>
246 </td>
247 <td class="detail">
248 &nbsp;<?php echo oeFormatShortDate(substr($row['date'], 0, 10)) ?>
249 </td>
250 <td class="detail">
251 &nbsp;<?php echo oeFormatShortDate($inv_duedate) ?>
252 </td>
253 <td class="detail" align="right">
254 <?php echo bucks($inv_amount) ?>&nbsp;
255 </td>
256 <td class="detail" align="right">
257 <?php echo bucks($inv_paid) ?>&nbsp;
258 </td>
259 <td class="detail" align="right">
260 <?php echo bucks($inv_amount - $inv_paid) ?>&nbsp;
261 </td>
262 </tr>
263 <?php
266 <tr bgcolor='#dddddd'>
267 <td class="detail">
268 &nbsp;<?php xl('Totals','e'); ?>
269 </td>
270 <td class="detail">
271 &nbsp;
272 </td>
273 <td class="detail">
274 &nbsp;
275 </td>
276 <td class="detail">
277 &nbsp;
278 </td>
279 <td class="detail">
280 &nbsp;
281 </td>
282 <td class="detail" align="right">
283 <?php echo bucks($total_amount) ?>&nbsp;
284 </td>
285 <td class="detail" align="right">
286 <?php echo bucks($total_paid) ?>&nbsp;
287 </td>
288 <td class="detail" align="right">
289 <?php echo bucks($total_amount - $total_paid) ?>&nbsp;
290 </td>
291 </tr>
292 <?php
294 if (!$INTEGRATED_AR) SLClose();
297 </table>
298 </div>
300 </form>
301 <script>
302 <?php
303 if ($alertmsg) {
304 echo "alert('$alertmsg');\n";
307 </script>
308 </body>
310 <!-- stuff for the popup calendar -->
311 <link rel='stylesheet' href='<?php echo $css_header ?>' type='text/css'>
312 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
313 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
314 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
315 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
316 <script type="text/javascript" src="../../library/js/jquery.1.3.2.js"></script>
318 <script language="Javascript">
319 Calendar.setup({inputField:"form_start_date", ifFormat:"%Y-%m-%d", button:"img_start_date"});
320 Calendar.setup({inputField:"form_end_date", ifFormat:"%Y-%m-%d", button:"img_end_date"});
321 </script>
323 </html>