PluginProbe ʕ •ᴥ•ʔ
LatePoint – Calendar Booking Plugin for Appointments and Events / 5.1.6
LatePoint – Calendar Booking Plugin for Appointments and Events v5.1.6
5.6.5 5.6.4 5.6.3 5.6.2 5.6.1 5.6.0 5.5.2 5.5.1 5.5.0 5.4.2 trunk 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.1.8 5.1.9 5.1.91 5.1.92 5.1.93 5.1.94 5.2.0 5.2.1 5.2.10 5.2.11 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.2 5.4.0 5.4.1
latepoint / lib / controllers / transactions_controller.php
latepoint / lib / controllers Last commit date
activities_controller.php 1 year ago auth_controller.php 1 year ago booking_form_settings_controller.php 1 year ago bookings_controller.php 1 year ago calendars_controller.php 1 year ago carts_controller.php 1 year ago controller.php 1 year ago customer_cabinet_controller.php 1 year ago customers_controller.php 1 year ago dashboard_controller.php 1 year ago default_agent_controller.php 1 year ago events_controller.php 1 year ago form_fields_controller.php 1 year ago integrations_controller.php 1 year ago invoices_controller.php 1 year ago manage_booking_by_key_controller.php 1 year ago manage_order_by_key_controller.php 1 year ago notifications_controller.php 1 year ago orders_controller.php 1 year ago pro_controller.php 1 year ago process_jobs_controller.php 1 year ago processes_controller.php 1 year ago search_controller.php 1 year ago services_controller.php 1 year ago settings_controller.php 1 year ago steps_controller.php 1 year ago stripe_connect_controller.php 1 year ago support_topics_controller.php 1 year ago todos_controller.php 1 year ago transactions_controller.php 1 year ago wizard_controller.php 1 year ago
transactions_controller.php
210 lines
1 <?php
2 if (!defined('ABSPATH')) {
3 exit; // Exit if accessed directly.
4 }
5
6
7 if (!class_exists('OsTransactionsController')) :
8
9
10 class OsTransactionsController extends OsController {
11
12 function __construct() {
13 parent::__construct();
14
15 $this->views_folder = LATEPOINT_VIEWS_ABSPATH . 'transactions/';
16 $this->vars['page_header'] = OsMenuHelper::get_menu_items_by_id('payments');
17 $this->vars['breadcrumbs'][] = array('label' => __('Transactions', 'latepoint'), 'link' => OsRouterHelper::build_link(OsRouterHelper::build_route_name('transactions', 'index')));
18
19 $this->action_access['public'] = array_merge( $this->action_access['public'], [ 'view_receipt_by_key' ] );
20 }
21
22 public function edit_form() {
23 if (filter_var($this->params['id'], FILTER_VALIDATE_INT)) {
24 // existing
25 $transaction = new OsTransactionModel($this->params['id']);
26 }else{
27 // new
28 $transaction = new OsTransactionModel();
29 if (filter_var($this->params['order_id'], FILTER_VALIDATE_INT)) {
30 $transaction->order_id = $this->params['order_id'];
31 }
32 }
33 $this->vars['real_or_rand_id'] = ($transaction->is_new_record()) ? 'new_transaction_' . OsUtilHelper::random_text('alnum', 5) : $transaction->id;
34 $this->vars['transaction'] = $transaction;
35
36 $this->format_render(__FUNCTION__);
37 }
38
39 public function view_receipt_by_key(){
40 $receipt_access_key = sanitize_text_field($this->params['key']);
41
42 if(empty($receipt_access_key)) {
43 echo __( 'Invalid Receipt Key', 'latepoint' );
44 exit;
45 }
46
47
48 $transaction = new OsTransactionModel();
49 $transaction = $transaction->where(['access_key' => $receipt_access_key])->set_limit(1)->get_results_as_models();
50
51 if(empty($transaction)) {
52 echo __( 'Receipt not found', 'latepoint' );
53 exit;
54 }
55
56 if(empty($transaction->receipt_number)) $transaction->update_attributes(['receipt_number' => $transaction->generate_receipt_number()]);
57
58 $invoice = new OsInvoiceModel($transaction->invoice_id);
59
60 $this->vars['invoice'] = $invoice;
61 $this->vars['transaction'] = $transaction;
62
63 $this->set_layout( 'clean' );
64 $this->format_render( __FUNCTION__ );
65 }
66
67 public function destroy() {
68 if (filter_var($this->params['id'], FILTER_VALIDATE_INT)) {
69 $this->check_nonce('destroy_transaction_'.$this->params['id']);
70 $transaction = new OsTransactionModel($this->params['id']);
71 if ($transaction->delete()) {
72 $status = LATEPOINT_STATUS_SUCCESS;
73 $response_html = __('Transaction Removed', 'latepoint');
74 } else {
75 $status = LATEPOINT_STATUS_ERROR;
76 $response_html = __('Error Removing Transaction', 'latepoint');
77 }
78 } else {
79 $status = LATEPOINT_STATUS_ERROR;
80 $response_html = __('Error Removing Transaction', 'latepoint');
81 }
82 if ($this->get_return_format() == 'json') {
83 $this->send_json(array('status' => $status, 'message' => $response_html));
84 }
85 }
86
87 /*
88 Index of transactions
89 */
90
91 public function index() {
92
93 $per_page = OsSettingsHelper::get_number_of_records_per_page();
94 $page_number = isset($this->params['page_number']) ? $this->params['page_number'] : 1;
95
96 $this->vars['page_header'] = false;
97
98 $transactions = new OsTransactionModel();
99
100
101 // TABLE SEARCH FILTERS
102 $filter = $this->params['filter'] ?? false;
103 $query_args = [];
104 if ($filter) {
105 if (!empty($filter['id'])) $query_args['id'] = $filter['id'];
106 if (!empty($filter['token'])) $query_args['token'] = $filter['token'];
107 if (!empty($filter['booking_id'])) $query_args['booking_id'] = $filter['booking_id'];
108 if (!empty($filter['processor'])) $query_args['processor'] = $filter['processor'];
109 if (!empty($filter['payment_method'])) $query_args['payment_method'] = $filter['payment_method'];
110 if (!empty($filter['amount'])) $query_args['amount'] = $filter['amount'];
111 if (!empty($filter['status'])) $query_args['status'] = $filter['status'];
112 if (!empty($filter['kind'])) $query_args['kind'] = $filter['kind'];
113
114 if (!empty($filter['customer']['full_name'])) {
115 $transactions->select(LATEPOINT_TABLE_TRANSACTIONS . '.*, ' . LATEPOINT_TABLE_CUSTOMERS . '.first_name, ' . LATEPOINT_TABLE_CUSTOMERS . '.last_name');
116 $transactions->join(LATEPOINT_TABLE_CUSTOMERS, ['id' => LATEPOINT_TABLE_TRANSACTIONS . '.customer_id']);
117
118 $query_args['concat_ws(" ", ' . LATEPOINT_TABLE_CUSTOMERS . '.first_name,' . LATEPOINT_TABLE_CUSTOMERS . '.last_name) LIKE'] = '%' . $filter['customer']['full_name'] . '%';
119 $this->vars['customer_name_query'] = $filter['customer']['full_name'];
120
121 }
122
123 if (!empty($filter['created_at_from']) && !empty($filter['created_at_to'])) {
124 $query_args['created_at >='] = $filter['created_at_from'] . ' 00:00:00';
125 $query_args['created_at <='] = $filter['created_at_to'] . ' 23:59:59';
126 }
127 }
128
129
130 // OUTPUT CSV IF REQUESTED
131 if (isset($this->params['download']) && $this->params['download'] == 'csv') {
132 $csv_filename = 'payments_' . OsUtilHelper::random_text() . '.csv';
133
134 header("Content-Type: text/csv");
135 header("Content-Disposition: attachment; filename={$csv_filename}");
136
137 $labels_row = [__('ID', 'latepoint'),
138 __('Token', 'latepoint'),
139 __('Order ID', 'latepoint'),
140 __('Customer', 'latepoint'),
141 __('Processor', 'latepoint'),
142 __('Method', 'latepoint'),
143 __('Amount', 'latepoint'),
144 __('Status', 'latepoint'),
145 __('Type', 'latepoint'),
146 __('Date', 'latepoint')];
147
148
149 $transactions_data = [];
150 $transactions_data[] = $labels_row;
151
152
153 $transactions_arr = $transactions->where($query_args)->filter_allowed_records()->get_results_as_models();
154
155 if ($transactions_arr) {
156 foreach ($transactions_arr as $transaction) {
157 $values_row = [
158 $transaction->id,
159 $transaction->token,
160 $transaction->order_id,
161 ($transaction->customer_id ? $transaction->customer->full_name : 'n/a'),
162 $transaction->processor,
163 $transaction->payment_method,
164 OsMoneyHelper::format_price($transaction->amount, true, false),
165 $transaction->status,
166 $transaction->kind,
167 $transaction->created_at,
168 ];
169 $values_row = apply_filters('latepoint_transaction_row_for_csv_export', $values_row, $transaction, $this->params);
170 $transactions_data[] = $values_row;
171 }
172
173 }
174
175 $transactions_data = apply_filters('latepoint_transactions_data_for_csv_export', $transactions_data, $this->params);
176 OsCSVHelper::array_to_csv($transactions_data);
177 return;
178 }
179
180 if ($query_args) $transactions->where($query_args);
181 $transactions->filter_allowed_records();
182
183
184 $count_transactions = clone $transactions;
185 $total_transactions = $count_transactions->count();
186
187 $transactions = $transactions->order_by(LATEPOINT_TABLE_TRANSACTIONS . '.created_at desc')->set_limit($per_page);
188 if ($page_number > 1) {
189 $transactions = $transactions->set_offset(($page_number - 1) * $per_page);
190 }
191
192 $this->vars['transactions'] = $transactions->get_results_as_models();
193
194 $this->vars['total_transactions'] = $total_transactions;
195 $this->vars['current_page_number'] = $page_number;
196 $this->vars['per_page'] = $per_page;
197 $total_pages = ceil($total_transactions / $per_page);
198 $this->vars['total_pages'] = $total_pages;
199
200 $this->vars['showing_from'] = (($page_number - 1) * $per_page) ? (($page_number - 1) * $per_page) : 1;
201 $this->vars['showing_to'] = min($page_number * $per_page, $total_transactions);
202
203 $this->format_render(['json_view_name' => '_table_body', 'html_view_name' => __FUNCTION__], [], ['total_pages' => $total_pages, 'showing_from' => $this->vars['showing_from'], 'showing_to' => $this->vars['showing_to'], 'total_records' => $total_transactions]);
204 }
205
206
207 }
208
209
210 endif;