Minor fixes to links and comments
[openemr.git] / interface / reports / payment_summary.php
blob87485bade2f54d1a66f52ea14253eb625bcc79b5
1 <?php
2 // Copyright (C) 2010 Medical Information Integration, LLC
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License
5 // as published by the Free Software Foundation; either version 2
6 // of the License, or (at your option) any later version.
8 //SANITIZE ALL ESCAPES
9 $sanitize_all_escapes=true;
11 //STOP FAKE REGISTER GLOBALS
12 $fake_register_globals=false;
14 require_once("../globals.php");
15 require_once("$srcdir/patient.inc");
16 require_once("$srcdir/options.inc.php");
17 require_once("../drugs/drugs.inc.php");
19 $form_payment_method = htmlspecialchars($_POST['form_method'], ENT_QUOTES);
20 $form_facility = htmlspecialchars($_POST['form_facility'], ENT_QUOTES);
21 $form_use_date = htmlspecialchars($_POST['form_use_date'], ENT_QUOTES);
22 $form_from_date = htmlspecialchars(fixDate( $_POST['form_from_date'], date('Y-01-01')), ENT_QUOTES);
23 $form_to_date = htmlspecialchars(fixDate( $_POST['form_to_date'], date('Y-m-d')), ENT_QUOTES);
25 // patient_data.language = race
26 // payments.dtime = DOS
28 $sqlBindArray = array();
30 $sql = "
31 SELECT concat( patient_data.fname, ' ', patient_data.lname ) AS patient_name,
32 patient_data.id,
33 patient_data.sex,
34 DATE_FORMAT( FROM_DAYS( DATEDIFF( NOW( ) , patient_data.DOB ) ) , '%Y' ) +0 AS age,
35 patient_data.DOB,
36 payments.dtime AS DOS,
37 patient_data.city,
38 patient_data.state AS county,
39 patient_data.ethnoracial AS race,
40 patient_data.postal_code AS zip,
41 payments.method AS method,
42 payments.amount1 + payments.amount2 AS total_amount
43 FROM patient_data,
44 payments,
45 users,
46 facility
47 where patient_data.pid = payments.pid
48 and payments.user = users.username
49 and users.facility_id = facility.id
50 and payments.dtime >= ?
51 and payments.dtime <= DATE_ADD(?, INTERVAL 1 DAY)";
53 array_push($sqlBindArray, $form_from_date, $form_to_date);
55 if($form_payment_method != '-- All --'){
56 $sql .= " and payments.method = ?";
57 array_push($sqlBindArray, $form_payment_method);
60 if ( strlen($form_facility) > 0 ){
61 $sql .= " and facility.id = ?";
62 array_push($sqlBindArray, $form_facility);
65 //echo $sql;
67 if ($_POST['form_refresh'] == "export"){
68 $result = sqlStatement($sql, $sqlBindArray);
70 $out = "First/Last Name, Sex, Age, Race, DOB, DOS, City, County, Zip, Payment Method\n";
72 while($row = sqlFetchArray($result)){
73 $out .= "{$row['patient_name']}, {$row['sex']}, {$row['age']}, {$row['race']}, {$row['DOB']}, {$row['DOS']}, {$row['city']}, {$row['county']}, {$row['zip']}, {$row['method']}\n";
76 $dt_str = date("Ymd");
78 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
79 header("Content-Length: " . strlen($out));
80 header("Content-type: text/x-csv");
81 header("Content-type: application/csv");
82 header("Content-Disposition: attachment; filename=payment_summary_".$dt_str.".csv");
83 echo $out;
84 exit;
87 <html>
88 <head>
89 <?php html_header_show();?>
90 <title>
91 <?php echo htmlspecialchars(xl('Clinical Reports'), ENT_QUOTES) ?>
92 </title>
93 <script type="text/javascript" src="../../library/overlib_mini.js"></script>
94 <script type="text/javascript" src="../../library/textformat.js"></script>
95 <script type="text/javascript" src="../../library/dialog.js"></script>
96 <script type="text/javascript" src="../../library/js/jquery.1.3.2.js"></script>
97 <script language="JavaScript">
99 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
101 // The OnClick handler for receipt display.
102 function show_receipt(payid) {
103 // dlgopen('../patient_file/front_payment.php?receipt=1&payid=' + payid, '_blank', 550, 400);
104 return false;
107 </script>
108 <link rel='stylesheet' href='<?php echo $css_header ?>' type='text/css'>
109 <style type="text/css">
110 /* specifically include & exclude from printing */
111 @media print {
112 #report_parameters {
113 visibility: hidden;
114 display: none;
116 #report_parameters_daterange {
117 visibility: visible;
118 display: inline;
120 #report_results table {
121 margin-top: 0px;
125 /* specifically exclude some from the screen */
126 @media screen {
127 #report_parameters_daterange {
128 visibility: hidden;
129 display: none;
132 .optional_area {
133 <?php if($type != 'Prescription' || $type == '') {
134 ?> display: none;
135 <?php
139 </style>
140 <script language="javascript" type="text/javascript">
141 function checkType(){
142 if($('#type').val() == 'Prescription'){
143 $('.optional_area').css("display", "inline");
145 else{
146 $('.optional_area').css("display", "none");
149 </script>
150 </head>
152 <body class="body_top">
154 <!-- Required for the popup date selectors -->
155 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
156 <span class='title'>
157 <?php echo htmlspecialchars(xl('Report - Facility/Prov Payment Summary'), ENT_QUOTES) ?>
158 </span>
159 <!-- Search can be done using age range, gender, and ethnicity filters.
160 Search options include diagnosis, procedure, prescription, medical history, and lab results.
162 <div id="report_parameters_daterange"> <?php echo date("d F Y", strtotime($form_from_date)) ." &nbsp; to &nbsp; ". date("d F Y", strtotime($form_to_date)); ?> </div>
163 <form method='post' id='theform' action='<?php echo $_SERVER['REQUEST_URI'] ?>'>
164 <div id="report_parameters">
165 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
166 <table>
167 <tr>
168 <td width='630px'><div style='float:left'>
169 <table class='text'>
170 <tr>
171 <td class='label'> <?php echo htmlspecialchars(xl('Payment Method'), ENT_QUOTES) ?>: </td>
172 <td><select name='form_method'>
173 <?php
174 $payment_methods = array(
175 htmlspecialchars(xl('-- All --'), ENT_QUOTES),
176 htmlspecialchars(xl('Cash'), ENT_QUOTES),
177 htmlspecialchars(xl('Check'), ENT_QUOTES),
178 htmlspecialchars(xl('MC'), ENT_QUOTES),
179 htmlspecialchars(xl('VISA'), ENT_QUOTES),
180 htmlspecialchars(xl('AMEX'), ENT_QUOTES),
181 htmlspecialchars(xl('DISC'), ENT_QUOTES),
182 htmlspecialchars(xl('Other'), ENT_QUOTES));
184 foreach ($payment_methods as $value) {
185 echo " <option value='$value'";
186 if ($value == $form_payment_method) echo " selected";
187 echo ">$value</option>\n";
190 </select></td>
191 <td><?php echo htmlspecialchars(xl('Facility'), ENT_QUOTES) ?>: </td>
192 <td colspan="3"><?php
193 // Build a drop-down list of facilities.
195 $query = "SELECT id, name FROM facility ORDER BY name";
196 $fres = sqlStatement($query);
197 echo " <select name='form_facility'>\n";
198 echo " <option value=''>-- " . htmlspecialchars(xl('All Facilities'), ENT_QUOTES) . " --\n";
199 while ($frow = sqlFetchArray($fres)) {
200 $facid = $frow['id'];
201 echo " <option value='$facid'";
202 if ($facid == $form_facility) echo " selected";
203 echo ">" . htmlspecialchars($frow['name'], ENT_QUOTES) . "\n";
205 echo " </select>\n";
206 ?>&nbsp;</td>
207 </tr>
208 <tr>
209 <td>&nbsp;</td>
210 <td><select name='form_use_edate'>
211 <option value='0'>
212 <?php echo htmlspecialchars(xl('Payment Date'), ENT_QUOTES) ?>
213 </option>
214 <option value='1'<?php if ($form_use_edate) echo ' selected' ?>>
215 <?php echo htmlspecialchars(xl('Invoice Date'), ENT_QUOTES) ?>
216 </option>
217 </select></td>
218 <td><?php echo htmlspecialchars(xl('From'), ENT_QUOTES) ?>:</td>
219 <td>
220 <table border="0" cellpadding="0" cellspacing="0">
221 <tr>
222 <td>
223 <input type='text' name='form_from_date' id="form_from_date" size='10' value='<?php echo $form_from_date ?>' onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
224 </td>
225 <td>
226 <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 htmlspecialchars(xl('Click here to choose a date'), ENT_QUOTES) ?>'>
227 </td>
228 </tr>
229 </table>
230 </td>
231 <td class='label'><?php echo htmlspecialchars(xl('To'), ENT_QUOTES) ?>: </td>
232 <td>
233 <table border="0" cellpadding="0" cellspacing="0">
234 <tr>
235 <td>
236 <input type='text' name='form_to_date' id="form_to_date" size='10' value='<?php echo $form_to_date ?>' onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
237 </td>
238 <td>
239 <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 htmlspecialchars(xl('Click here to choose a date'), ENT_QUOTES); ?>'>
240 </td>
241 </tr>
242 </table>
243 </td>
244 </tr>
245 </table>
246 </div></td>
247 <td align='left' valign='middle' height="100%"><table style='border-left:1px solid; width:100%; height:100%' >
248 <tr>
249 <td><div style='margin-left:15px'> <a href='#' class='css_button' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'> <span>
250 <?php echo htmlspecialchars(xl('Submit'), ENT_QUOTES) ?>
251 </span> </a>
252 <?php if ($_POST['form_refresh'] || $_POST['form_orderby'] ) { ?>
253 <a href='#' class='css_button' onclick='window.print()'> <span>
254 <?php echo htmlspecialchars(xl('Print'), ENT_QUOTES) ?>
255 </span> </a>
256 <?php } ?>
257 <?php if ($_POST['form_refresh']) { ?>
258 <a href='#' class='css_button' onclick='$("#form_refresh").attr("value","export"); $("#theform").submit();'> <span>
259 <?php echo htmlspecialchars(xl('Export'), ENT_QUOTES) ?>
260 </span> </a>
261 <?php } ?>
262 </div></td>
263 </tr>
264 </table></td>
265 </tr>
266 </table>
267 </div>
268 <!-- end of parameters -->
270 <?php
272 // SQL scripts for the various searches
273 if ($_POST['form_refresh']) {
274 $result = sqlStatement($sql, $sqlBindArray);
276 if(sqlNumRows($result) > 0){
278 <div id="report_results">
279 <table>
280 <thead>
281 <th><?php echo htmlspecialchars(xl('First/Last Name'), ENT_QUOTES) ?></th>
282 <th> <?php echo htmlspecialchars(xl('Sex'), ENT_QUOTES) ?></th>
283 <th> <?php echo htmlspecialchars(xl('Age'), ENT_QUOTES) ?></th>
284 <th> <?php echo htmlspecialchars(xl('Race'), ENT_QUOTES) ?></th>
285 <th> <?php echo htmlspecialchars(xl('DOB'), ENT_QUOTES) ?></th>
286 <th> <?php echo htmlspecialchars(xl('DOS'), ENT_QUOTES) ?></th>
287 <th> <?php echo htmlspecialchars(xl('City'), ENT_QUOTES) ?></th>
288 <th> <?php echo htmlspecialchars(xl('County'), ENT_QUOTES) ?></th>
289 <th> <?php echo htmlspecialchars(xl('Zip'), ENT_QUOTES) ?></th>
290 <th> <?php echo htmlspecialchars(xl('Payment Amount'), ENT_QUOTES) ?></th>
291 <th> <?php echo htmlspecialchars(xl('Payment Method'), ENT_QUOTES) ?></th>
292 </thead>
293 <tbody>
294 <?php
295 $total = 0;
296 while($row = sqlFetchArray($result)){
297 $total += (float)$row['total_amount'];
299 <tr>
300 <td><?php echo htmlspecialchars($row['patient_name'], ENT_QUOTES); ?>
301 &nbsp;</td>
302 <td><?php echo htmlspecialchars($row['sex'], ENT_QUOTES) ?>
303 &nbsp;</td>
304 <td><?php echo htmlspecialchars($row['age'], ENT_QUOTES) ?>
305 &nbsp;</td>
306 <td><?php echo htmlspecialchars($row['race'], ENT_QUOTES) ?>
307 &nbsp;</td>
308 <td><?php echo htmlspecialchars($row['DOB'], ENT_QUOTES) ?>
309 &nbsp;</td>
310 <td><?php echo htmlspecialchars($row['DOS'], ENT_QUOTES) ?>
311 &nbsp;</td>
312 <td><?php echo htmlspecialchars($row['city'], ENT_QUOTES) ?>
313 &nbsp;</td>
314 <td><?php echo htmlspecialchars($row['county'], ENT_QUOTES) ?>
315 &nbsp;</td>
316 <td><?php echo htmlspecialchars($row['zip'], ENT_QUOTES) ?>
317 &nbsp;</td>
318 <td><?php echo htmlspecialchars($row['total_amount'], ENT_QUOTES) ?>
319 &nbsp;</td>
320 <td><?php echo htmlspecialchars($row['method'], ENT_QUOTES) ?>
321 &nbsp;</td>
322 </tr>
323 <?php
326 <tr style="border: 2px solid #000;">
327 <td>&nbsp;</td>
328 <td>&nbsp;</td>
329 <td>&nbsp;</td>
330 <td>&nbsp;</td>
331 <td>&nbsp;</td>
332 <td>&nbsp;</td>
333 <td>&nbsp;</td>
334 <td>&nbsp;</td>
335 <td><strong><?php echo htmlspecialchars(xl('Total Amount'), ENT_QUOTES) ?></strong>&nbsp;</td>
336 <td><?php echo htmlspecialchars(number_format($total, 2), ENT_QUOTES) ?>&nbsp;</td>
337 <td>&nbsp;</td>
338 </tr>
339 </tbody>
340 </table>
341 </div>
342 <!-- end of results -->
343 <?php
346 <?php
348 else
351 <div class='text'> <?php echo htmlspecialchars(xl('Please input search criteria above, and click Submit to view results.'), ENT_QUOTES) ?> </div>
352 <?php
355 </form>
356 </body>
358 <!-- stuff for the popup calendar -->
359 <style type="text/css">
360 @import url(../../library/dynarch_calendar.css);
361 </style>
362 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
363 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
364 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
365 <script language="Javascript">
366 Calendar.setup({inputField:"form_from_date", ifFormat:"%Y-%m-%d", button:"img_from_date"});
367 Calendar.setup({inputField:"form_to_date", ifFormat:"%Y-%m-%d", button:"img_to_date"});
368 </script>
369 </html>