Fully responsive globals.php with vertical menu (#2460)
[openemr.git] / interface / billing / indigent_patients_report.php
blob66155a838685157c2e1dc4e10c74e0213649924c
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 * @package OpenEMR
8 * @link http://www.open-emr.org
9 * @author Rod Roark <rod@sunsetsystems.com>
10 * @author Brady Miller <brady.g.miller@gmail.com>
11 * @copyright Copyright (c) 2005-2015 Rod Roark <rod@sunsetsystems.com>
12 * @copyright Copyright (c) 2017-2019 Brady Miller <brady.g.miller@gmail.com>
13 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
17 require_once("../globals.php");
18 require_once("$srcdir/patient.inc");
20 use OpenEMR\Core\Header;
22 $alertmsg = '';
24 function bucks($amount)
26 if ($amount) {
27 return oeFormatMoney($amount);
30 return "";
33 $form_start_date = (!empty($_POST['form_start_date'])) ? DateToYYYYMMDD($_POST['form_start_date']) : date('Y-01-01');
34 $form_end_date = (!empty($_POST['form_end_date'])) ? DateToYYYYMMDD($_POST['form_end_date']) : date('Y-m-d');
37 <html>
38 <head>
40 <style type="text/css">
42 /* specifically include & exclude from printing */
43 @media print {
44 #report_parameters {
45 visibility: hidden;
46 display: none;
48 #report_parameters_daterange {
49 visibility: visible;
50 display: inline;
52 #report_results table {
53 margin-top: 0px;
57 /* specifically exclude some from the screen */
58 @media screen {
59 #report_parameters_daterange {
60 visibility: hidden;
61 display: none;
65 </style>
67 <?php Header::setupHeader('datetime-picker'); ?>
69 <title><?php echo xlt('Indigent Patients Report')?></title>
71 <script language="JavaScript">
73 $(function() {
74 var win = top.printLogSetup ? top : opener.top;
75 win.printLogSetup(document.getElementById('printbutton'));
77 $('.datepicker').datetimepicker({
78 <?php $datetimepicker_timepicker = false; ?>
79 <?php $datetimepicker_showseconds = false; ?>
80 <?php $datetimepicker_formatInput = true; ?>
81 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
82 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
83 });
84 });
86 </script>
88 </head>
90 <body class="body_top">
92 <span class='title'><?php echo xlt('Report'); ?> - <?php echo xlt('Indigent Patients'); ?></span>
94 <form method='post' action='indigent_patients_report.php' id='theform' onsubmit='return top.restoreSession()'>
95 <input type="hidden" name="csrf_token_form" value="<?php echo attr(collectCsrfToken()); ?>" />
97 <div id="report_parameters">
99 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
101 <table>
102 <tr>
103 <td width='410px'>
104 <div style='float:left'>
106 <table class='text'>
107 <tr>
108 <td class='control-label'>
109 <?php echo xlt('Visits From'); ?>:
110 </td>
111 <td>
112 <input type='text' class='datepicker form-control' name='form_start_date' id="form_start_date" size='10' value='<?php echo attr(oeFormatShortDate($form_start_date)); ?>'>
113 </td>
114 <td class='control-label'>
115 <?php xl('To', 'e'); ?>:
116 </td>
117 <td>
118 <input type='text' class='datepicker form-control' name='form_end_date' id="form_end_date" size='10' value='<?php echo attr(oeFormatShortDate($form_end_date)); ?>'>
119 </td>
120 </tr>
121 </table>
123 </div>
125 </td>
126 <td align='left' valign='middle' height="100%">
127 <table style='border-left:1px solid; width:100%; height:100%' >
128 <tr>
129 <td>
130 <div class="text-center">
131 <div class="btn-group" role="group">
132 <a href='#' class='btn btn-default btn-save' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
133 <?php echo xlt('Submit'); ?>
134 </a>
135 <?php if ($_POST['form_refresh']) { ?>
136 <a href='#' class='btn btn-default btn-print' id='printbutton'>
137 <?php echo xlt('Print'); ?>
138 </a>
139 <?php } ?>
140 </div>
141 </div>
142 </td>
143 </tr>
144 </table>
145 </td>
146 </tr>
147 </table>
148 </div> <!-- end of parameters -->
150 <div id="report_results">
151 <table>
153 <thead bgcolor="#dddddd">
154 <th>
155 &nbsp;<?php echo xlt('Patient'); ?>
156 </th>
157 <th>
158 &nbsp;<?php echo xlt('SSN'); ?>
159 </th>
160 <th>
161 &nbsp;<?php echo xlt('Invoice'); ?>
162 </th>
163 <th>
164 &nbsp;<?php echo xlt('Svc Date'); ?>
165 </th>
166 <th>
167 &nbsp;<?php echo xlt('Due Date'); ?>
168 </th>
169 <th align="right">
170 <?php echo xlt('Amount'); ?>&nbsp;
171 </th>
172 <th align="right">
173 <?php echo xlt('Paid'); ?>&nbsp;
174 </th>
175 <th align="right">
176 <?php echo xlt('Balance'); ?>&nbsp;
177 </th>
178 </thead>
180 <?php
181 if ($_POST['form_refresh']) {
182 if (!verifyCsrfToken($_POST["csrf_token_form"])) {
183 csrfNotVerified();
186 $where = "";
187 $sqlBindArray = array();
189 if ($form_start_date) {
190 $where .= " AND e.date >= ?";
191 array_push($sqlBindArray, $form_start_date);
194 if ($form_end_date) {
195 $where .= " AND e.date <= ?";
196 array_push($sqlBindArray, $form_end_date);
199 $rez = sqlStatement("SELECT " .
200 "e.date, e.encounter, p.pid, p.lname, p.fname, p.mname, p.ss " .
201 "FROM form_encounter AS e, patient_data AS p, insurance_data AS i " .
202 "WHERE p.pid = e.pid AND i.pid = e.pid AND i.type = 'primary' " .
203 "AND i.provider = ''$where " .
204 "ORDER BY p.lname, p.fname, p.mname, p.pid, e.date", $sqlBindArray);
206 $total_amount = 0;
207 $total_paid = 0;
209 for ($irow = 0; $row = sqlFetchArray($rez); ++$irow) {
210 $patient_id = $row['pid'];
211 $encounter_id = $row['encounter'];
212 $invnumber = $row['pid'] . "." . $row['encounter'];
213 $inv_duedate = '';
214 $arow = sqlQuery("SELECT SUM(fee) AS amount FROM drug_sales WHERE " .
215 "pid = ? AND encounter = ?", array($patient_id, $encounter_id));
216 $inv_amount = $arow['amount'];
217 $arow = sqlQuery("SELECT SUM(fee) AS amount FROM billing WHERE " .
218 "pid = ? AND encounter = ? AND " .
219 "activity = 1 AND code_type != 'COPAY'", array($patient_id, $encounter_id));
220 $inv_amount += $arow['amount'];
221 $arow = sqlQuery("SELECT SUM(fee) AS amount FROM billing WHERE " .
222 "pid = ? AND encounter = ? AND " .
223 "activity = 1 AND code_type = 'COPAY'", array($patient_id, $encounter_id));
224 $inv_paid = 0 - $arow['amount'];
225 $arow = sqlQuery("SELECT SUM(pay_amount) AS pay, " .
226 "sum(adj_amount) AS adj FROM ar_activity WHERE " .
227 "pid = ? AND encounter = ?", array($patient_id, $encounter_id));
228 $inv_paid += floatval($arow['pay']);
229 $inv_amount -= floatval($arow['adj']);
230 $total_amount += $inv_amount;
231 $total_paid += $inv_paid;
233 $bgcolor = (($irow & 1) ? "#ffdddd" : "#ddddff");
235 <tr bgcolor='<?php echo $bgcolor ?>'>
236 <td class="detail">
237 &nbsp;<?php echo text($row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname']); ?>
238 </td>
239 <td class="detail">
240 &nbsp;<?php echo text($row['ss']); ?>
241 </td>
242 <td class="detail">
243 &nbsp;<?php echo text($invnumber); ?></a>
244 </td>
245 <td class="detail">
246 &nbsp;<?php echo text(oeFormatShortDate(substr($row['date'], 0, 10))); ?>
247 </td>
248 <td class="detail">
249 &nbsp;<?php echo text(oeFormatShortDate($inv_duedate)); ?>
250 </td>
251 <td class="detail" align="right">
252 <?php echo bucks($inv_amount); ?>&nbsp;
253 </td>
254 <td class="detail" align="right">
255 <?php echo bucks($inv_paid); ?>&nbsp;
256 </td>
257 <td class="detail" align="right">
258 <?php echo bucks($inv_amount - $inv_paid); ?>&nbsp;
259 </td>
260 </tr>
261 <?php
264 <tr bgcolor='#dddddd'>
265 <td class="detail">
266 &nbsp;<?php echo xlt('Totals'); ?>
267 </td>
268 <td class="detail">
269 &nbsp;
270 </td>
271 <td class="detail">
272 &nbsp;
273 </td>
274 <td class="detail">
275 &nbsp;
276 </td>
277 <td class="detail">
278 &nbsp;
279 </td>
280 <td class="detail" align="right">
281 <?php echo bucks($total_amount); ?>&nbsp;
282 </td>
283 <td class="detail" align="right">
284 <?php echo bucks($total_paid); ?>&nbsp;
285 </td>
286 <td class="detail" align="right">
287 <?php echo bucks($total_amount - $total_paid); ?>&nbsp;
288 </td>
289 </tr>
290 <?php
294 </table>
295 </div>
297 </form>
298 <script>
299 <?php
300 if ($alertmsg) {
301 echo "alert(" . js_escape($alertmsg) . ");\n";
304 </script>
305 </body>
307 </html>