acknowledgments update
[openemr.git] / interface / billing / indigent_patients_report.php
blobfc64eadeb4b9b14580a2ad54e24f7271b54cbd64
1 <?php
2 // Copyright (C) 2005-2010 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 </script>
68 </head>
70 <body class="body_top">
72 <span class='title'><?php xl('Report','e'); ?> - <?php xl('Indigent Patients','e'); ?></span>
74 <form method='post' action='indigent_patients_report.php' id='theform'>
76 <div id="report_parameters">
78 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
80 <table>
81 <tr>
82 <td width='410px'>
83 <div style='float:left'>
85 <table class='text'>
86 <tr>
87 <td class='label'>
88 <?php xl('Visits From','e'); ?>:
89 </td>
90 <td>
91 <input type='text' name='form_start_date' id="form_start_date" size='10' value='<?php echo $form_start_date ?>'
92 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
93 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
94 id='img_start_date' border='0' alt='[?]' style='cursor:pointer'
95 title='<?php xl('Click here to choose a date','e'); ?>'>
96 </td>
97 <td class='label'>
98 <?php xl('To','e'); ?>:
99 </td>
100 <td>
101 <input type='text' name='form_end_date' id="form_end_date" size='10' value='<?php echo $form_end_date ?>'
102 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
103 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
104 id='img_end_date' border='0' alt='[?]' style='cursor:pointer'
105 title='<?php xl('Click here to choose a date','e'); ?>'>
106 </td>
107 </tr>
108 </table>
110 </div>
112 </td>
113 <td align='left' valign='middle' height="100%">
114 <table style='border-left:1px solid; width:100%; height:100%' >
115 <tr>
116 <td>
117 <div style='margin-left:15px'>
118 <a href='#' class='css_button' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
119 <span>
120 <?php xl('Submit','e'); ?>
121 </span>
122 </a>
124 <?php if ($_POST['form_refresh']) { ?>
125 <a href='#' class='css_button' onclick='window.print()'>
126 <span>
127 <?php xl('Print','e'); ?>
128 </span>
129 </a>
130 <?php } ?>
131 </div>
132 </td>
133 </tr>
134 </table>
135 </td>
136 </tr>
137 </table>
138 </div> <!-- end of parameters -->
140 <div id="report_results">
141 <table>
143 <thead bgcolor="#dddddd">
144 <th>
145 &nbsp;<?php xl('Patient','e')?>
146 </th>
147 <th>
148 &nbsp;<?php xl('SSN','e')?>
149 </th>
150 <th>
151 &nbsp;<?php xl('Invoice','e')?>
152 </th>
153 <th>
154 &nbsp;<?php xl('Svc Date','e')?>
155 </th>
156 <th>
157 &nbsp;<?php xl('Due Date','e')?>
158 </th>
159 <th align="right">
160 <?php xl('Amount','e')?>&nbsp;
161 </th>
162 <th align="right">
163 <?php xl('Paid','e')?>&nbsp;
164 </th>
165 <th align="right">
166 <?php xl('Balance','e')?>&nbsp;
167 </th>
168 </thead>
170 <?php
171 if ($_POST['form_search']) {
173 $where = "";
175 if ($form_start_date) {
176 $where .= " AND e.date >= '$form_start_date'";
178 if ($form_end_date) {
179 $where .= " AND e.date <= '$form_end_date'";
182 $rez = sqlStatement("SELECT " .
183 "e.date, e.encounter, p.pid, p.lname, p.fname, p.mname, p.ss " .
184 "FROM form_encounter AS e, patient_data AS p, insurance_data AS i " .
185 "WHERE p.pid = e.pid AND i.pid = e.pid AND i.type = 'primary' " .
186 "AND i.provider = ''$where " .
187 "ORDER BY p.lname, p.fname, p.mname, p.pid, e.date"
190 $total_amount = 0;
191 $total_paid = 0;
193 for ($irow = 0; $row = sqlFetchArray($rez); ++$irow) {
194 $patient_id = $row['pid'];
195 $encounter_id = $row['encounter'];
196 $invnumber = $row['pid'] . "." . $row['encounter'];
198 if ($INTEGRATED_AR) {
199 $inv_duedate = '';
200 $arow = sqlQuery("SELECT SUM(fee) AS amount FROM drug_sales WHERE " .
201 "pid = '$patient_id' AND encounter = '$encounter_id'");
202 $inv_amount = $arow['amount'];
203 $arow = sqlQuery("SELECT SUM(fee) AS amount FROM billing WHERE " .
204 "pid = '$patient_id' AND encounter = '$encounter_id' AND " .
205 "activity = 1 AND code_type != 'COPAY'");
206 $inv_amount += $arow['amount'];
207 $arow = sqlQuery("SELECT SUM(fee) AS amount FROM billing WHERE " .
208 "pid = '$patient_id' AND encounter = '$encounter_id' AND " .
209 "activity = 1 AND code_type = 'COPAY'");
210 $inv_paid = 0 - $arow['amount'];
211 $arow = sqlQuery("SELECT SUM(pay_amount) AS pay, " .
212 "sum(adj_amount) AS adj FROM ar_activity WHERE " .
213 "pid = '$patient_id' AND encounter = '$encounter_id'");
214 $inv_paid += $arow['pay'];
215 $inv_amount -= $arow['adj'];
217 else {
218 $ares = SLQuery("SELECT duedate, amount, paid FROM ar WHERE " .
219 "ar.invnumber = '$invnumber'");
220 if ($sl_err) die($sl_err);
221 if (SLRowCount($ares) == 0) continue;
222 $arow = SLGetRow($ares, 0);
223 $inv_amount = $arow['amount'];
224 $inv_paid = $arow['paid'];
225 $inv_duedate = $arow['duedate'];
227 $total_amount += bucks($inv_amount);
228 $total_paid += bucks($inv_paid);
230 $bgcolor = (($irow & 1) ? "#ffdddd" : "#ddddff");
232 <tr bgcolor='<?php echo $bgcolor ?>'>
233 <td class="detail">
234 &nbsp;<?php echo $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'] ?>
235 </td>
236 <td class="detail">
237 &nbsp;<?php echo $row['ss'] ?>
238 </td>
239 <td class="detail">
240 &nbsp;<?php echo $invnumber ?></a>
241 </td>
242 <td class="detail">
243 &nbsp;<?php echo oeFormatShortDate(substr($row['date'], 0, 10)) ?>
244 </td>
245 <td class="detail">
246 &nbsp;<?php echo oeFormatShortDate($inv_duedate) ?>
247 </td>
248 <td class="detail" align="right">
249 <?php echo bucks($inv_amount) ?>&nbsp;
250 </td>
251 <td class="detail" align="right">
252 <?php echo bucks($inv_paid) ?>&nbsp;
253 </td>
254 <td class="detail" align="right">
255 <?php echo bucks($inv_amount - $inv_paid) ?>&nbsp;
256 </td>
257 </tr>
258 <?php
261 <tr bgcolor='#dddddd'>
262 <td class="detail">
263 &nbsp;<?php xl('Totals','e'); ?>
264 </td>
265 <td class="detail">
266 &nbsp;
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" align="right">
278 <?php echo bucks($total_amount) ?>&nbsp;
279 </td>
280 <td class="detail" align="right">
281 <?php echo bucks($total_paid) ?>&nbsp;
282 </td>
283 <td class="detail" align="right">
284 <?php echo bucks($total_amount - $total_paid) ?>&nbsp;
285 </td>
286 </tr>
287 <?php
289 if (!$INTEGRATED_AR) SLClose();
292 </table>
293 </div>
295 </form>
296 <script>
297 <?php
298 if ($alertmsg) {
299 echo "alert('$alertmsg');\n";
302 </script>
303 </body>
305 <!-- stuff for the popup calendar -->
306 <link rel='stylesheet' href='<?php echo $css_header ?>' type='text/css'>
307 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
308 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
309 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
310 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
311 <script type="text/javascript" src="../../library/js/jquery.1.3.2.js"></script>
313 <script language="Javascript">
314 Calendar.setup({inputField:"form_start_date", ifFormat:"%Y-%m-%d", button:"img_start_date"});
315 Calendar.setup({inputField:"form_end_date", ifFormat:"%Y-%m-%d", button:"img_end_date"});
316 </script>
318 </html>