Merge branch 'AE/groupFixes' of github.com:matrix-israel/openemr into AE/groupFixes
[openemr.git] / interface / billing / indigent_patients_report.php
blob2bcdcb2eb5a61b8c77ba1fbb12a145833f7e272e
1 <?php
2 /**
3 * This is the Indigent Patients Report. It displays a summary of
4 * encounters within the specified time period for patients without
5 * insurance.
7 * Copyright (C) 2005-2015 Rod Roark <rod@sunsetsystems.com>
8 * Copyright (C) 2017 Brady Miller <brady.g.miller@gmail.com>
10 * LICENSE: This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
21 * @package OpenEMR
22 * @author Rod Roark <rod@sunsetsystems.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("$srcdir/patient.inc");
31 $alertmsg = '';
33 function bucks($amount) {
34 if ($amount) return oeFormatMoney($amount);
35 return "";
38 $form_start_date = fixDate($_POST['form_start_date'], date("Y-01-01"));
39 $form_end_date = fixDate($_POST['form_end_date'], date("Y-m-d"));
42 <html>
43 <head>
44 <?php html_header_show(); ?>
45 <style type="text/css">
47 /* specifically include & exclude from printing */
48 @media print {
49 #report_parameters {
50 visibility: hidden;
51 display: none;
53 #report_parameters_daterange {
54 visibility: visible;
55 display: inline;
57 #report_results table {
58 margin-top: 0px;
62 /* specifically exclude some from the screen */
63 @media screen {
64 #report_parameters_daterange {
65 visibility: hidden;
66 display: none;
70 </style><link rel="stylesheet" href="<?php echo $css_header; ?>" type="text/css">
71 <link rel="stylesheet" href="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.min.css">
73 <title><?php xl('Indigent Patients Report','e')?></title>
75 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-3-1-1/index.js"></script>
76 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.full.min.js"></script>
78 <script language="JavaScript">
80 $(document).ready(function() {
81 var win = top.printLogSetup ? top : opener.top;
82 win.printLogSetup(document.getElementById('printbutton'));
84 $('.datepicker').datetimepicker({
85 <?php $datetimepicker_timepicker = false; ?>
86 <?php $datetimepicker_showseconds = false; ?>
87 <?php $datetimepicker_formatInput = false; ?>
88 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
89 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
90 });
91 });
93 </script>
95 </head>
97 <body class="body_top">
99 <span class='title'><?php xl('Report','e'); ?> - <?php xl('Indigent Patients','e'); ?></span>
101 <form method='post' action='indigent_patients_report.php' id='theform'>
103 <div id="report_parameters">
105 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
107 <table>
108 <tr>
109 <td width='410px'>
110 <div style='float:left'>
112 <table class='text'>
113 <tr>
114 <td class='label'>
115 <?php xl('Visits From','e'); ?>:
116 </td>
117 <td>
118 <input type='text' class='datepicker' name='form_start_date' id="form_start_date" size='10' value='<?php echo $form_start_date ?>'
119 title='yyyy-mm-dd'>
120 </td>
121 <td class='label'>
122 <?php xl('To','e'); ?>:
123 </td>
124 <td>
125 <input type='text' class='datepicker' name='form_end_date' id="form_end_date" size='10' value='<?php echo $form_end_date ?>'
126 title='yyyy-mm-dd'>
127 </td>
128 </tr>
129 </table>
131 </div>
133 </td>
134 <td align='left' valign='middle' height="100%">
135 <table style='border-left:1px solid; width:100%; height:100%' >
136 <tr>
137 <td>
138 <div style='margin-left:15px'>
139 <a href='#' class='css_button' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
140 <span>
141 <?php xl('Submit','e'); ?>
142 </span>
143 </a>
145 <?php if ($_POST['form_refresh']) { ?>
146 <a href='#' class='css_button' id='printbutton'>
147 <span>
148 <?php xl('Print','e'); ?>
149 </span>
150 </a>
151 <?php } ?>
152 </div>
153 </td>
154 </tr>
155 </table>
156 </td>
157 </tr>
158 </table>
159 </div> <!-- end of parameters -->
161 <div id="report_results">
162 <table>
164 <thead bgcolor="#dddddd">
165 <th>
166 &nbsp;<?php xl('Patient','e')?>
167 </th>
168 <th>
169 &nbsp;<?php xl('SSN','e')?>
170 </th>
171 <th>
172 &nbsp;<?php xl('Invoice','e')?>
173 </th>
174 <th>
175 &nbsp;<?php xl('Svc Date','e')?>
176 </th>
177 <th>
178 &nbsp;<?php xl('Due Date','e')?>
179 </th>
180 <th align="right">
181 <?php xl('Amount','e')?>&nbsp;
182 </th>
183 <th align="right">
184 <?php xl('Paid','e')?>&nbsp;
185 </th>
186 <th align="right">
187 <?php xl('Balance','e')?>&nbsp;
188 </th>
189 </thead>
191 <?php
192 if ($_POST['form_refresh']) {
194 $where = "";
196 if ($form_start_date) {
197 $where .= " AND e.date >= '$form_start_date'";
199 if ($form_end_date) {
200 $where .= " AND e.date <= '$form_end_date'";
203 $rez = sqlStatement("SELECT " .
204 "e.date, e.encounter, p.pid, p.lname, p.fname, p.mname, p.ss " .
205 "FROM form_encounter AS e, patient_data AS p, insurance_data AS i " .
206 "WHERE p.pid = e.pid AND i.pid = e.pid AND i.type = 'primary' " .
207 "AND i.provider = ''$where " .
208 "ORDER BY p.lname, p.fname, p.mname, p.pid, e.date"
211 $total_amount = 0;
212 $total_paid = 0;
214 for ($irow = 0; $row = sqlFetchArray($rez); ++$irow) {
215 $patient_id = $row['pid'];
216 $encounter_id = $row['encounter'];
217 $invnumber = $row['pid'] . "." . $row['encounter'];
218 $inv_duedate = '';
219 $arow = sqlQuery("SELECT SUM(fee) AS amount FROM drug_sales WHERE " .
220 "pid = '$patient_id' AND encounter = '$encounter_id'");
221 $inv_amount = $arow['amount'];
222 $arow = sqlQuery("SELECT SUM(fee) AS amount FROM billing WHERE " .
223 "pid = '$patient_id' AND encounter = '$encounter_id' AND " .
224 "activity = 1 AND code_type != 'COPAY'");
225 $inv_amount += $arow['amount'];
226 $arow = sqlQuery("SELECT SUM(fee) AS amount FROM billing WHERE " .
227 "pid = '$patient_id' AND encounter = '$encounter_id' AND " .
228 "activity = 1 AND code_type = 'COPAY'");
229 $inv_paid = 0 - $arow['amount'];
230 $arow = sqlQuery("SELECT SUM(pay_amount) AS pay, " .
231 "sum(adj_amount) AS adj FROM ar_activity WHERE " .
232 "pid = '$patient_id' AND encounter = '$encounter_id'");
233 $inv_paid += $arow['pay'];
234 $inv_amount -= $arow['adj'];
235 $total_amount += bucks($inv_amount);
236 $total_paid += bucks($inv_paid);
238 $bgcolor = (($irow & 1) ? "#ffdddd" : "#ddddff");
240 <tr bgcolor='<?php echo $bgcolor ?>'>
241 <td class="detail">
242 &nbsp;<?php echo $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'] ?>
243 </td>
244 <td class="detail">
245 &nbsp;<?php echo $row['ss'] ?>
246 </td>
247 <td class="detail">
248 &nbsp;<?php echo $invnumber ?></a>
249 </td>
250 <td class="detail">
251 &nbsp;<?php echo oeFormatShortDate(substr($row['date'], 0, 10)) ?>
252 </td>
253 <td class="detail">
254 &nbsp;<?php echo oeFormatShortDate($inv_duedate) ?>
255 </td>
256 <td class="detail" align="right">
257 <?php echo bucks($inv_amount) ?>&nbsp;
258 </td>
259 <td class="detail" align="right">
260 <?php echo bucks($inv_paid) ?>&nbsp;
261 </td>
262 <td class="detail" align="right">
263 <?php echo bucks($inv_amount - $inv_paid) ?>&nbsp;
264 </td>
265 </tr>
266 <?php
269 <tr bgcolor='#dddddd'>
270 <td class="detail">
271 &nbsp;<?php xl('Totals','e'); ?>
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">
283 &nbsp;
284 </td>
285 <td class="detail" align="right">
286 <?php echo bucks($total_amount) ?>&nbsp;
287 </td>
288 <td class="detail" align="right">
289 <?php echo bucks($total_paid) ?>&nbsp;
290 </td>
291 <td class="detail" align="right">
292 <?php echo bucks($total_amount - $total_paid) ?>&nbsp;
293 </td>
294 </tr>
295 <?php
299 </table>
300 </div>
302 </form>
303 <script>
304 <?php
305 if ($alertmsg) {
306 echo "alert('$alertmsg');\n";
309 </script>
310 </body>
312 </html>