4 * Payment processing report.
5 * Supports void and credit with Sphere payment processing.
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
;
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")]);
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;
48 <title
><?php
echo xlt('Payment Processing'); ?
></title
>
50 <?php Header
::setupHeader(["datetime-picker","report-helper"]); ?
>
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 ?>
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);
79 if ($GLOBALS['payment_gateway'] == 'Sphere') {
80 echo SphereRevert
::renderRevertSphereJs();
86 /* specifically include & exclude from printing */
92 #report_parameters_daterange {
96 #report_results table {
101 /* specifically exclude some from the screen */
103 #report_parameters_daterange {
111 <body
class="body_top">
113 <!-- Required
for the popup date selectors
-->
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)) . " " . xlt('to{{Range}}') . " " . text(oeFormatShortDate($to_date)); ?
>
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">
130 <div style
='float: left'>
134 <td
class='col-form-label'><?php
echo xlt('Service'); ?
>:</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
>
141 <td
class='col-form-label'><?php
echo xlt('Patient'); ?
>:</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
'); ?>' />
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
>
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
>
161 <td
class='col-form-label'><?php
echo xlt('Action'); ?
>:</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
>
170 <td
class='col-form-label'></td
>
179 <td
class='h-100' align
='left' valign
='middle'>
180 <table
class='w-100 h-100' style
='border-left: 1px solid;'>
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'); ?
>
188 <?php
if (!empty($_POST['form_refresh'])) { ?
>
189 <a href
='#' class='btn btn-secondary btn-print' id
='printbutton'>
190 <?php
echo xlt('Print'); ?
>
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
>
224 <!-- added
for better
print-ability
-->
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"> 
;<?php
echo text(oeFormatDateTime($auditEntry['date'])); ?
></td
>
233 <td
class="detail"> 
;<?php
echo text($auditEntry['service']); ?
></td
>
234 <td
class="detail"> 
;<?php
echo text($auditEntry['front_label']); ?
></td
>
235 <td
class="detail"> 
;<?php
echo text($auditEntry['ticket']); ?
></td
>
236 <td
class="detail"> 
;<?php
echo text($auditEntry['transaction_id']); ?
></td
>
237 <td
class="detail"> 
;<?php
echo text($auditEntry['pid']); ?
></td
>
238 <td
class="detail"> 
;<?php
echo text($auditEntry['action_name_label'] ??
''); ?
></td
>
239 <td
class="detail"> 
;<?php
echo (!empty($auditEntry['success'])) ?
xlt("Yes") : xlt("No"); ?
></td
>
240 <td
class="detail"> 
;<?php
echo text($auditEntry['amount']); ?
></td
>
241 <td
class="detail"> 
;<?php
echo text($auditEntry['error_message'] ??
''); ?
></td
>
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']);
281 <!-- end of search results
-->
283 <div
class='text'><?php
echo xlt('Please input search criteria above, and click Submit to view results.'); ?
>
286 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
='' /></form
>