minor changes to prior commit
[openemr.git] / interface / reports / front_receipts_report.php
blob27592dd6f4d9af6d9b350318cba769ab9a02d9c2
1 <?php
2 /**
3 * This report lists front office receipts for a given date range.
5 * @package OpenEMR
6 * @link http://www.open-emr.org
7 * @author Rod Roark <rod@sunsetsystems.com>
8 * @author Brady Miller <brady.g.miller@gmail.com>
9 * @copyright Copyright (c) 2006-2015 Rod Roark <rod@sunsetsystems.com>
10 * @copyright Copyright (c) 2017-2018 Brady Miller <brady.g.miller@gmail.com>
11 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
15 require_once("../globals.php");
16 require_once("$srcdir/patient.inc");
18 use OpenEMR\Core\Header;
20 $from_date = (isset($_POST['form_from_date'])) ? DateToYYYYMMDD($_POST['form_from_date']) : date('Y-m-d');
21 $to_date = (isset($_POST['form_to_date'])) ? DateToYYYYMMDD($_POST['form_to_date']) : date('Y-m-d');
23 function bucks($amt)
25 return ($amt != 0.00) ? oeFormatMoney($amt) : '';
28 <html>
29 <head>
31 <title><?php echo xlt('Front Office Receipts'); ?></title>
33 <?php Header::setupHeader('datetime-picker'); ?>
35 <script language="JavaScript">
36 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
38 $(document).ready(function() {
39 var win = top.printLogSetup ? top : opener.top;
40 win.printLogSetup(document.getElementById('printbutton'));
42 $('.datepicker').datetimepicker({
43 <?php $datetimepicker_timepicker = false; ?>
44 <?php $datetimepicker_showseconds = false; ?>
45 <?php $datetimepicker_formatInput = true; ?>
46 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
47 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
48 });
49 });
51 // The OnClick handler for receipt display.
52 function show_receipt(pid,timestamp) {
53 dlgopen('../patient_file/front_payment.php?receipt=1&patient=' + pid +
54 '&time=' + timestamp, '_blank', 550, 400, '', '', {
55 onClosed: 'reload'
56 });
58 </script>
60 <style type="text/css">
61 /* specifically include & exclude from printing */
62 @media print {
63 #report_parameters {
64 visibility: hidden;
65 display: none;
67 #report_parameters_daterange {
68 visibility: visible;
69 display: inline;
71 #report_results {
72 margin-top: 30px;
76 /* specifically exclude some from the screen */
77 @media screen {
78 #report_parameters_daterange {
79 visibility: hidden;
80 display: none;
83 </style>
84 </head>
86 <body class="body_top">
88 <!-- Required for the popup date selectors -->
89 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
91 <span class='title'><?php echo xlt('Report'); ?> - <?php echo xlt('Front Office Receipts'); ?></span>
93 <div id="report_parameters_daterange">
94 <?php echo text(oeFormatShortDate($from_date)) ." &nbsp; " . xlt("to") . " &nbsp; ". text(oeFormatShortDate($to_date)); ?>
95 </div>
97 <form name='theform' method='post' action='front_receipts_report.php' id='theform' onsubmit='return top.restoreSession()'>
99 <div id="report_parameters">
101 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
103 <table>
104 <tr>
105 <td width='410px'>
106 <div style='float:left'>
108 <table class='text'>
109 <tr>
110 <td class='control-label'>
111 <?php echo xlt('From'); ?>:
112 </td>
113 <td>
114 <input type='text' class='datepicker form-control' name='form_from_date' id="form_from_date" size='10' value='<?php echo attr(oeFormatShortDate($from_date)); ?>'>
115 </td>
116 <td class='control-label'>
117 <?php xl('To', 'e'); ?>:
118 </td>
119 <td>
120 <input type='text' class='datepicker form-control' name='form_to_date' id="form_to_date" size='10' value='<?php echo attr(oeFormatShortDate($to_date)); ?>'>
121 </td>
122 </tr>
123 </table>
125 </div>
127 </td>
128 <td align='left' valign='middle' height="100%">
129 <table style='border-left:1px solid; width:100%; height:100%' >
130 <tr>
131 <td>
132 <div class="text-center">
133 <div class="btn-group" role="group">
134 <a href='#' class='btn btn-default btn-save' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
135 <?php echo xlt('Submit'); ?>
136 </a>
137 <?php if ($_POST['form_refresh']) { ?>
138 <a href='#' class='btn btn-default btn-print' id='printbutton'>
139 <?php echo xlt('Print'); ?>
140 </a>
141 <?php } ?>
142 </div>
143 </div>
144 </td>
145 </tr>
146 </table>
147 </td>
148 </tr>
149 </table>
150 </div> <!-- end of parameters -->
152 <?php
153 if ($_POST['form_refresh'] || $_POST['form_orderby']) {
155 <div id="report_results">
156 <table>
157 <thead>
158 <th> <?php echo xlt('Time'); ?> </th>
159 <th> <?php echo xlt('Patient'); ?> </th>
160 <th> <?php echo xlt('ID'); ?> </th>
161 <th> <?php echo xlt('Method'); ?> </th>
162 <th> <?php echo xlt('Source'); ?> </th>
163 <th align='right'> <?php echo xlt('Today'); ?> </th>
164 <th align='right'> <?php echo xlt('Previous'); ?> </th>
165 <th align='right'> <?php echo xlt('Total'); ?> </th>
166 </thead>
167 <tbody>
168 <?php
169 if (true || $_POST['form_refresh']) {
170 $total1 = 0.00;
171 $total2 = 0.00;
173 $query = "SELECT r.pid, r.dtime, " .
174 "SUM(r.amount1) AS amount1, " .
175 "SUM(r.amount2) AS amount2, " .
176 "MAX(r.method) AS method, " .
177 "MAX(r.source) AS source, " .
178 "MAX(r.user) AS user, " .
179 "p.fname, p.mname, p.lname, p.pubpid " .
180 "FROM payments AS r " .
181 "LEFT OUTER JOIN patient_data AS p ON " .
182 "p.pid = r.pid " .
183 "WHERE " .
184 "r.dtime >= ? AND " .
185 "r.dtime <= ? " .
186 "GROUP BY r.dtime, r.pid ORDER BY r.dtime, r.pid";
188 // echo "<!-- $query -->\n"; // debugging
189 $res = sqlStatement($query, array($from_date.' 00:00:00', $to_date.' 23:59:59'));
191 while ($row = sqlFetchArray($res)) {
192 // Make the timestamp URL-friendly.
193 $timestamp = preg_replace('/[^0-9]/', '', $row['dtime']);
195 <tr>
196 <td nowrap>
197 <a href="javascript:show_receipt(<?php echo $row['pid'] . ",'$timestamp'"; ?>)">
198 <?php echo text(oeFormatShortDate(substr($row['dtime'], 0, 10))) . text(substr($row['dtime'], 10, 6)); ?>
199 </a>
200 </td>
201 <td>
202 <?php echo text($row['lname']) . ', ' . text($row['fname']) . ' ' . text($row['mname']); ?>
203 </td>
204 <td>
205 <?php echo text($row['pubpid']); ?>
206 </td>
207 <td>
208 <?php echo text($row['method']); ?>
209 </td>
210 <td>
211 <?php echo text($row['source']); ?>
212 </td>
213 <td align='right'>
214 <?php echo text(bucks($row['amount1'])); ?>
215 </td>
216 <td align='right'>
217 <?php echo text(bucks($row['amount2'])); ?>
218 </td>
219 <td align='right'>
220 <?php echo text(bucks($row['amount1'] + $row['amount2'])); ?>
221 </td>
222 </tr>
223 <?php
224 $total1 += $row['amount1'];
225 $total2 += $row['amount2'];
229 <tr>
230 <td colspan='8'>
231 &nbsp;
232 </td>
233 </tr>
235 <tr class="report_totals">
236 <td colspan='5'>
237 <?php echo xlt('Totals'); ?>
238 </td>
239 <td align='right'>
240 <?php echo text(bucks($total1)); ?>
241 </td>
242 <td align='right'>
243 <?php echo text(bucks($total2)); ?>
244 </td>
245 <td align='right'>
246 <?php echo text(bucks($total1 + $total2)); ?>
247 </td>
248 </tr>
250 <?php
253 </tbody>
254 </table>
255 </div> <!-- end of results -->
256 <?php } else { ?>
257 <div class='text'>
258 <?php echo xlt('Please input search criteria above, and click Submit to view results.'); ?>
259 </div>
260 <?php } ?>
262 </form>
263 </body>
264 </html>