chore(deps): bump twig/twig from 3.17.1 to 3.19.0 (#7951)
[openemr.git] / interface / reports / payment_processing_report.php
blob5577c4365544fbdb141be29bd24fc761088cf6a2
1 <?php
3 /**
4 * Payment processing report.
5 * Supports void and credit with Sphere payment processing.
7 * @package OpenEMR
8 * @link https://www.open-emr.org
9 * @author Brady Miller <brady.g.miller@gmail.com>
10 * @copyright Copyright (c) 2021 Brady Miller <brady.g.miller@gmail.com>
11 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
14 require_once("../globals.php");
16 use OpenEMR\Common\Acl\AclMain;
17 use OpenEMR\Common\Csrf\CsrfUtils;
18 use OpenEMR\Common\Twig\TwigContainer;
19 use OpenEMR\Core\Header;
20 use OpenEMR\PaymentProcessing\PaymentProcessing;
21 use OpenEMR\PaymentProcessing\Sphere\SphereRevert;
23 if (!empty($_POST)) {
24 if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"])) {
25 CsrfUtils::csrfNotVerified();
29 if (!AclMain::aclCheckCore('acct', 'rep_a')) {
30 echo (new TwigContainer(null, $GLOBALS['kernel']))->getTwig()->render('core/unauthorized.html.twig', ['pageTitle' => xl("Payment Processing")]);
31 exit;
34 // If from date is empty, default to 1 week ago.
35 $from_date = (!empty($_POST['form_from_date'])) ? DateTimeToYYYYMMDDHHMMSS($_POST['form_from_date']) : date('Y-m-d H:i:s', strtotime('-1 week'));
36 $to_date = (!empty($_POST['form_to_date'])) ? DateTimeToYYYYMMDDHHMMSS($_POST['form_to_date']) : date('Y-m-d H:i:s');
38 $patient = $_POST['form_patient'] ?? null;
39 $service = $_POST['form_service'] ?? null;
40 $ticket = $_POST['form_ticket'] ?? null;
41 $transId = $_POST['form_trans_id'] ?? null;
42 $actionName = $_POST['form_action_name'] ?? null;
45 <html>
47 <head>
48 <title><?php echo xlt('Payment Processing'); ?></title>
50 <?php Header::setupHeader(["datetime-picker","report-helper"]); ?>
52 <script>
53 $(function () {
54 var win = top.printLogSetup ? top : opener.top;
55 win.printLogSetup(document.getElementById('printbutton'));
57 $('.datepicker').datetimepicker({
58 <?php $datetimepicker_timepicker = true; ?>
59 <?php $datetimepicker_showseconds = false; ?>
60 <?php $datetimepicker_formatInput = true; ?>
61 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
62 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
63 });
64 });
66 function refreshme() {
67 document.forms[0].submit();
70 function setpatient(pid, lname, fname, dob) {
71 document.forms[0].elements['form_patient'].value = pid;
74 function sel_patient() {
75 dlgopen('../main/calendar/find_patient_popup.php?pflag=0', '_blank', 500, 400);
78 <?php
79 if ($GLOBALS['payment_gateway'] == 'Sphere') {
80 echo SphereRevert::renderRevertSphereJs();
83 </script>
85 <style>
86 /* specifically include & exclude from printing */
87 @media print {
88 #report_parameters {
89 visibility: hidden;
90 display: none;
92 #report_parameters_daterange {
93 visibility: visible;
94 display: inline;
96 #report_results table {
97 margin-top: 0px;
101 /* specifically exclude some from the screen */
102 @media screen {
103 #report_parameters_daterange {
104 visibility: hidden;
105 display: none;
108 </style>
109 </head>
111 <body class="body_top">
113 <!-- Required for the popup date selectors -->
114 <div id="overDiv"
115 style="position: absolute; visibility: hidden; z-index: 1000;"></div>
117 <span class='title'><?php echo xlt('Payment Processing'); ?></span>
119 <div id="report_parameters_daterange"><?php echo text(oeFormatShortDate($from_date)) . " &nbsp; " . xlt('to{{Range}}') . " &nbsp; " . text(oeFormatShortDate($to_date)); ?>
120 </div>
122 <form method='post' name='theform' id='theform' action='payment_processing_report.php' onsubmit='return top.restoreSession()'>
123 <input type="hidden" name="csrf_token_form" value="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
125 <div id="report_parameters">
127 <table>
128 <tr>
129 <td width='650px'>
130 <div style='float: left'>
132 <table class='text'>
133 <tr>
134 <td class='col-form-label'><?php echo xlt('Service'); ?>:</td>
135 <td>
136 <select name='form_service' id='form_service' class='form-control'>
137 <option value=''><?php echo xlt('All'); ?></option>
138 <option value='sphere' <?php echo ($service == 'sphere') ? 'selected' : '' ?>><?php echo xlt('Sphere'); ?></option>
139 </select>
140 </td>
141 <td class='col-form-label'><?php echo xlt('Patient'); ?>:</td>
142 <td>
143 <input type='text' size='20' name='form_patient' class='form-control' style='cursor:pointer;' id='form_patient' value='<?php echo attr($patient); ?>' onclick='sel_patient()' title='<?php echo xla('Click to select patient'); ?>' />
144 </td>
145 </tr>
146 <tr>
147 <td class='col-form-label'><?php echo xlt('From'); ?>:</td>
148 <td><input type='text' name='form_from_date' id="form_from_date" class='datepicker form-control' size='10' value='<?php echo attr(oeFormatDateTime($from_date)); ?>' /></td>
149 <td class='col-form-label'><?php echo xlt('To{{Range}}'); ?>:</td>
150 <td><input type='text' name='form_to_date' id="form_to_date" class='datepicker form-control' size='10' value='<?php echo attr(oeFormatDateTime($to_date)); ?>'></td>
151 </tr>
153 <tr>
154 <td class='col-form-label'><?php echo xlt('Ticket'); ?>:</td>
155 <td><input type='text' name='form_ticket' id='form_ticket' class='form-control' value='<?php echo attr($ticket); ?>' /></td>
156 <td class='col-form-label'><?php echo xlt('Transaction ID'); ?>:</td>
157 <td><input type='text' name='form_trans_id' id='form_trans_id' class='form-control' value='<?php echo attr($transId); ?>' /></td>
158 </tr>
160 <tr>
161 <td class='col-form-label'><?php echo xlt('Action'); ?>:</td>
162 <td>
163 <select name='form_action_name' id='form_action_name' class='form-control'>
164 <option value=''><?php echo xlt('All'); ?></option>
165 <option value='Sale' <?php echo ($actionName == 'Sale') ? 'selected' : '' ?>><?php echo xlt('Sale'); ?></option>
166 <option value='credit' <?php echo ($actionName == 'credit') ? 'selected' : '' ?>><?php echo xlt('Credit'); ?></option>
167 <option value='void' <?php echo ($actionName == 'void') ? 'selected' : '' ?>><?php echo xlt('Void'); ?></option>
168 </select>
169 </td>
170 <td class='col-form-label'></td>
171 <td></td>
172 </tr>
174 </table>
176 </div>
178 </td>
179 <td class='h-100' align='left' valign='middle'>
180 <table class='w-100 h-100' style='border-left: 1px solid;'>
181 <tr>
182 <td>
183 <div class="text-center">
184 <div class="btn-group" role="group">
185 <a href='#' class='btn btn-secondary btn-save' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
186 <?php echo xlt('Submit'); ?>
187 </a>
188 <?php if (!empty($_POST['form_refresh'])) { ?>
189 <a href='#' class='btn btn-secondary btn-print' id='printbutton'>
190 <?php echo xlt('Print'); ?>
191 </a>
192 <?php } ?>
193 </div>
194 </div>
195 </td>
196 </tr>
197 </table>
198 </td>
199 </tr>
200 </table>
202 </div>
203 <!-- end of search parameters --> <?php
204 if (!empty($_POST['form_refresh'])) {
205 $showDate = ($from_date != $to_date) || (!$to_date);
207 <div id="report_results">
208 <table class='table'>
210 <thead class='thead-light'>
211 <th><?php echo xlt('Date'); ?></th>
212 <th><?php echo xlt('Service'); ?></th>
213 <th><?php echo xlt('Front'); ?></th>
214 <th><?php echo xlt('Ticket'); ?></th>
215 <th><?php echo xlt('Transaction ID'); ?></th>
216 <th><?php echo xlt('Patient'); ?></th>
217 <th><?php echo xlt('Action'); ?></th>
218 <th><?php echo xlt('Success'); ?></th>
219 <th><?php echo xlt('Amount'); ?></th>
220 <th><?php echo xlt('Error Message'); ?></th>
221 <th><?php echo xlt('Void/Credit'); ?></th>
222 </thead>
223 <tbody>
224 <!-- added for better print-ability -->
225 <?php
226 $auditEntries = PaymentProcessing::fetchAudit($from_date, $to_date, $patient, $service, $ticket, $transId, $actionName);
228 foreach ($auditEntries as $auditEntry) {
231 <tr valign='top' bgcolor='<?php echo attr($bgcolor ?? ''); ?>'>
232 <td class="detail">&nbsp;<?php echo text(oeFormatDateTime($auditEntry['date'])); ?></td>
233 <td class="detail">&nbsp;<?php echo text($auditEntry['service']); ?></td>
234 <td class="detail">&nbsp;<?php echo text($auditEntry['front_label']); ?></td>
235 <td class="detail">&nbsp;<?php echo text($auditEntry['ticket']); ?></td>
236 <td class="detail">&nbsp;<?php echo text($auditEntry['transaction_id']); ?></td>
237 <td class="detail">&nbsp;<?php echo text($auditEntry['pid']); ?></td>
238 <td class="detail">&nbsp;<?php echo text($auditEntry['action_name_label'] ?? ''); ?></td>
239 <td class="detail">&nbsp;<?php echo (!empty($auditEntry['success'])) ? xlt("Yes") : xlt("No"); ?></td>
240 <td class="detail">&nbsp;<?php echo text($auditEntry['amount']); ?></td>
241 <td class="detail">&nbsp;<?php echo text($auditEntry['error_message'] ?? ''); ?></td>
242 <td class="detail">
243 <?php
244 if ($auditEntry['action_name'] == 'Sale') {
245 if (!empty($auditEntry['reverted'])) {
246 // Charge has already been reverted
247 if ($auditEntry['revert_action_name'] == 'void') {
248 echo xlt("This charge was reversed via void on following date") . ": " . text(oeFormatDateTime($auditEntry['revert_date'])) . "<br>" .
249 xlt("The transaction_id for the void was") . ": " . text($auditEntry['revert_transaction_id']);
250 } else { // $auditEntry['revert_action_name'] == 'credit'
251 echo xlt("This charge was reversed via credit on following date") . ": " . text(oeFormatDateTime($auditEntry['revert_date'])) . "<br>" .
252 xlt("The Transaction ID for the credit was") . ": " . text($auditEntry['revert_transaction_id']);
255 if (!empty($auditEntry['offer_void'])) {
256 if (($auditEntry['service'] == 'sphere') && ($GLOBALS['payment_gateway'] == 'Sphere')) {
257 echo SphereRevert::renderSphereVoidButton($auditEntry['front'], $auditEntry['transaction_id'], $auditEntry['uuid']);
260 if (!empty($auditEntry['offer_credit'])) {
261 if (($auditEntry['service'] == 'sphere') && ($GLOBALS['payment_gateway'] == 'Sphere')) {
262 echo SphereRevert::renderSphereCreditButton($auditEntry['front'], $auditEntry['transaction_id'], $auditEntry['uuid']);
265 } elseif (($auditEntry['action_name'] == 'void') || ($auditEntry['action_name'] == 'credit')) {
266 if (!empty($auditEntry['success'])) {
267 if ($auditEntry['action_name'] == 'void') {
268 echo xlt("This transaction voided the following Transaction ID" . ": " . $auditEntry['map_transaction_id']);
269 } else { // $auditEntry['action_name'] == 'credit'
270 echo xlt("This transaction credited the following Transaction ID" . ": " . $auditEntry['map_transaction_id']);
275 </td>
276 </tr>
277 <?php } ?>
278 </tbody>
279 </table>
280 </div>
281 <!-- end of search results -->
282 <?php } else { ?>
283 <div class='text'><?php echo xlt('Please input search criteria above, and click Submit to view results.'); ?>
284 </div>
285 <?php } ?>
286 <input type='hidden' name='form_refresh' id='form_refresh' value='' /></form>
288 </body>
290 </html>