4 * This report lists front office receipts for a given date range.
7 * @link http://www.open-emr.org
8 * @author Rod Roark <rod@sunsetsystems.com>
9 * @author Brady Miller <brady.g.miller@gmail.com>
10 * @copyright Copyright (c) 2006-2015 Rod Roark <rod@sunsetsystems.com>
11 * @copyright Copyright (c) 2017-2018 Brady Miller <brady.g.miller@gmail.com>
12 * @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.php");
17 require_once "$srcdir/options.inc.php";
19 use OpenEMR\Common\Acl\AclMain
;
20 use OpenEMR\Common\Csrf\CsrfUtils
;
21 use OpenEMR\Common\Twig\TwigContainer
;
22 use OpenEMR\Common\Utils\FormatMoney
;
23 use OpenEMR\Core\Header
;
25 if (!AclMain
::aclCheckCore('acct', 'rep_a')) {
26 echo (new TwigContainer(null, $GLOBALS['kernel']))->getTwig()->render('core/unauthorized.html.twig', ['pageTitle' => xl("Front Office Receipts")]);
31 if (!CsrfUtils
::verifyCsrfToken($_POST["csrf_token_form"])) {
32 CsrfUtils
::csrfNotVerified();
36 $from_date = (isset($_POST['form_from_date'])) ?
DateToYYYYMMDD($_POST['form_from_date']) : date('Y-m-d');
37 $to_date = (isset($_POST['form_to_date'])) ?
DateToYYYYMMDD($_POST['form_to_date']) : date('Y-m-d');
43 <title
><?php
echo xlt('Front Office Receipts'); ?
></title
>
45 <?php Header
::setupHeader('datetime-picker'); ?
>
48 <?php
require($GLOBALS['srcdir'] . "/restoreSession.php"); ?
>
51 var win
= top
.printLogSetup ? top
: opener
.top
;
52 win
.printLogSetup(document
.getElementById('printbutton'));
54 $
('.datepicker').datetimepicker({
55 <?php
$datetimepicker_timepicker = false; ?
>
56 <?php
$datetimepicker_showseconds = false; ?
>
57 <?php
$datetimepicker_formatInput = true; ?
>
58 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
59 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
63 // The OnClick handler for receipt display.
64 function show_receipt(pid
,timestamp
) {
65 dlgopen('../patient_file/front_payment.php?receipt=1&patient=' +
encodeURIComponent(pid
) +
66 '&time=' +
encodeURIComponent(timestamp
), '_blank', 850, 550, '', '', {
73 /* specifically include & exclude from printing */
79 #report_parameters_daterange {
88 /* specifically exclude some from the screen */
90 #report_parameters_daterange {
98 <body
class="body_top">
100 <!-- Required
for the popup date selectors
-->
101 <div id
="overDiv" style
="position:absolute; visibility:hidden; z-index:1000;"></div
>
103 <span
class='title'><?php
echo xlt('Report'); ?
> - <?php
echo xlt('Front Office Receipts'); ?
></span
>
105 <div id
="report_parameters_daterange">
106 <?php
echo text(oeFormatShortDate($from_date)) . " " . xlt("to{{Range}}") . " " . text(oeFormatShortDate($to_date)); ?
>
109 <form name
='theform' method
='post' action
='front_receipts_report.php' id
='theform' onsubmit
='return top.restoreSession()'>
110 <input type
="hidden" name
="csrf_token_form" value
="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
112 <div id
="report_parameters">
114 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
119 <div style
='float:left'>
123 <td
class='col-form-label'>
124 <?php
echo xlt('Facility'); ?
>:
128 $form_facility = $_POST['form_facility'] ??
null;
129 dropdown_facility($form_facility, 'form_facility', false);
132 <td
class='col-form-label'>
133 <?php
echo xlt('Provider') ?
>:
136 <?php
# Build a drop-down list of providers.
139 $query = "SELECT id, lname, fname FROM users WHERE " .
140 "authorized = 1 ORDER BY lname, fname"; #(CHEMED) facility filter
142 $ures = sqlStatement($query);
144 echo " <select name='form_provider' class='form-control'>\n";
145 echo " <option value=''>-- " . xlt('All') . " --\n";
147 while ($urow = sqlFetchArray($ures)) {
148 $provid = $urow['id'];
149 echo " <option value='" . attr($provid) . "'";
150 if (!empty($_POST['form_provider']) && ($provid == $_POST['form_provider'])) {
154 echo ">" . text($urow['lname']) . ", " . text($urow['fname']) . "\n";
155 if (!empty($_POST['form_provider']) && ($provid == $_POST['form_provider'])) {
156 $provider_name = $urow['lname'] . ", " . $urow['fname'];
165 <td
class='col-form-label'>
166 <?php
echo xlt('From'); ?
>:
169 <input type
='text' class='datepicker form-control' name
='form_from_date' id
="form_from_date" size
='10' value
='<?php echo attr(oeFormatShortDate($from_date)); ?>'>
171 <td
class='col-form-label'>
172 <?php
xl('To{{Range}}', 'e'); ?
>:
175 <input type
='text' class='datepicker form-control' name
='form_to_date' id
="form_to_date" size
='10' value
='<?php echo attr(oeFormatShortDate($to_date)); ?>'>
183 <td
class='h-100' align
='left' valign
='middle'>
184 <table
class='w-100 h-100' style
='border-left:1px solid;'>
187 <div
class="text-center">
188 <div
class="btn-group" role
="group">
189 <a href
='#' class='btn btn-secondary btn-save' onclick
='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
190 <?php
echo xlt('Submit'); ?
>
192 <?php
if (!empty($_POST['form_refresh'])) { ?
>
193 <a href
='#' class='btn btn-secondary btn-print' id
='printbutton'>
194 <?php
echo xlt('Print'); ?
>
205 </div
> <!-- end of parameters
-->
208 if (!empty($_POST['form_refresh']) ||
!empty($_POST['form_orderby'])) {
210 <div id
="report_results">
211 <table
class='table table-striped'>
212 <thead
class='thead-light'>
213 <th
> <?php
echo xlt('Time'); ?
> </th
>
214 <th
> <?php
echo xlt('Patient'); ?
> </th
>
215 <th
> <?php
echo xlt('ID'); ?
> </th
>
216 <th
> <?php
echo xlt('Method'); ?
> </th
>
217 <th
> <?php
echo xlt('Source'); ?
> </th
>
218 <th align
='right'> <?php
echo xlt('Today'); ?
> </th
>
219 <th align
='right'> <?php
echo xlt('Previous'); ?
> </th
>
220 <th align
='right'> <?php
echo xlt('Total'); ?
> </th
>
224 if (true ||
$_POST['form_refresh']) {
228 $inputArray = array($from_date . ' 00:00:00', $to_date . ' 23:59:59');
229 $query = "SELECT r.pid, r.dtime, " .
230 "SUM(r.amount1) AS amount1, " .
231 "SUM(r.amount2) AS amount2, " .
232 "MAX(r.method) AS method, " .
233 "MAX(r.source) AS source, " .
234 "MAX(r.user) AS user, " .
235 "p.fname, p.mname, p.lname, p.pubpid " .
236 "FROM payments AS r " .
237 "JOIN form_encounter AS fe ON fe.encounter=r.encounter " .
238 "LEFT OUTER JOIN patient_data AS p ON " .
241 "r.dtime >= ? AND " .
243 if ($_POST['form_facility'] != "") {
244 $inputArray[] = $_POST['form_facility'];
245 $query .= "fe.facility_id = ? AND ";
247 if ($_POST['form_provider'] != "") {
248 $inputArray[] = $_POST['form_provider'];
249 $query .= "fe.provider_id = ? AND ";
251 $query .= "1 GROUP BY r.dtime, r.pid ORDER BY r.dtime, r.pid";
253 // echo " $query \n"; // debugging
254 $res = sqlStatement($query, $inputArray);
256 while ($row = sqlFetchArray($res)) {
257 // Make the timestamp URL-friendly.
258 $timestamp = preg_replace('/[^0-9]/', '', $row['dtime']);
262 <a href
="javascript:show_receipt(<?php echo attr_js($row['pid']); ?>, <?php echo attr_js($timestamp); ?>)">
263 <?php
echo text(oeFormatShortDate(substr($row['dtime'], 0, 10))) . text(substr($row['dtime'], 10, 6)); ?
>
267 <?php
echo text($row['lname']) . ', ' . text($row['fname']) . ' ' . text($row['mname']); ?
>
270 <?php
echo text($row['pubpid']); ?
>
273 <?php
echo text($row['method']); ?
>
276 <?php
echo text($row['source']); ?
>
279 <?php
echo text(FormatMoney
::getBucks($row['amount1'])); ?
>
282 <?php
echo text(FormatMoney
::getBucks($row['amount2'])); ?
>
285 <?php
echo text(FormatMoney
::getBucks($row['amount1'] +
$row['amount2'])); ?
>
289 $total1 +
= $row['amount1'];
290 $total2 +
= $row['amount2'];
291 $method = $row['method'];
292 if (empty($total1_by_method[$method])) {
293 $total1_by_method[$method] = 0;
295 $total1_by_method[$method] +
= $row['amount1'];
296 if (empty($total2_by_method[$method])) {
297 $total2_by_method[$method] = 0;
299 $total2_by_method[$method] +
= $row['amount2'];
310 $method_keys = array_keys(array_unique(array_merge($total1_by_method, $total2_by_method)));
311 foreach ($method_keys as $method_key) { ?
>
312 <tr
class="report_totals_by_method">
314 <?php
echo xlt('Totals by Method') . ' ' . text($method_key); ?
>
316 <?php
echo text(FormatMoney
::getBucks($total1_by_method[$method_key])); ?
>
319 <?php
echo text(FormatMoney
::getBucks($total2_by_method[$method_key])); ?
>
322 <?php
echo text(FormatMoney
::getBucks($total1_by_method[$method_key] +
$total2_by_method[$method_key])); ?
>
327 <tr
class="report_totals">
329 <?php
echo xlt('Totals'); ?
>
332 <?php
echo text(FormatMoney
::getBucks($total1)); ?
>
335 <?php
echo text(FormatMoney
::getBucks($total2)); ?
>
338 <?php
echo text(FormatMoney
::getBucks($total1 +
$total2)); ?
>
347 </div
> <!-- end of results
-->
350 <?php
echo xlt('Please input search criteria above, and click Submit to view results.'); ?
>