PluginProbe ʕ •ᴥ•ʔ
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 3.0.3
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v3.0.3
4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.11.0 1.11.1 1.11.2 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.9.0 1.9.1 1.9.2 1.9.3 1.9.4 1.9.5 2.0.0 2.0.1 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.10.0 2.10.1 2.11.0 2.11.1 2.11.2 2.11.3 2.11.4 2.12.0 2.13.0 2.14.0 2.14.1 2.15.0 2.15.1 2.16.0 2.16.1 2.16.2 2.16.3 2.17.0 2.17.1 2.17.2 2.18.0 2.19.0 2.19.2 2.19.3 2.19.4 2.2.0 2.2.1 2.20.0 2.20.1 2.20.2 2.20.3 2.20.4 2.20.5 2.20.6 2.21.0 2.22.0 2.22.1 2.23.0 2.24.0 2.25.0 2.25.1 2.25.2 2.26.0 2.27.0 2.27.1 2.28.0 2.29.0 2.29.1 2.29.2 2.29.3 2.29.4 2.3.0 2.3.1 2.30.0 2.31.0 2.31.1 2.31.2 2.31.3 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.40.0 2.40.1 2.5.0 2.5.1 2.5.2 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.9.0 3.0.0 3.0.0-RC1 3.0.0-RC2 3.0.0-beta1 3.0.0-beta2 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.10.0 3.10.1 3.11.0 3.12.0 3.13.0 3.13.1 3.13.2 3.13.3 3.13.4 3.14.0 3.15.0 3.15.1 3.15.2 3.15.3 3.15.4 3.15.5 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.16.6 3.16.7 3.16.8 3.17.0 3.17.1 3.17.2 3.17.3 3.17.4 3.17.5 3.17.6 3.18.0 3.19.0 3.19.1 3.19.2 3.2.0 3.2.1 3.2.2 3.20.0 3.20.1 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 4.0.0 4.0.1 4.0.2 4.0.3 trunk 4.1.0 0.2.19.1 4.1.1 1.0.0 4.2.0 1.0.1 1.0.2
surecart / app / src / Controllers / Admin / Invoices / InvoicesListTable.php
surecart / app / src / Controllers / Admin / Invoices Last commit date
InvoiceScriptsController.php 1 year ago InvoicesListTable.php 1 year ago InvoicesViewController.php 1 year ago
InvoicesListTable.php
357 lines
1 <?php
2
3 namespace SureCart\Controllers\Admin\Invoices;
4
5 use SureCart\Controllers\Admin\Tables\HasModeFilter;
6 use SureCart\Controllers\Admin\Tables\ListTable;
7 use SureCart\Models\Invoice;
8
9 /**
10 * Create a new table class that will extend the WP_List_Table
11 */
12 class InvoicesListTable extends ListTable {
13 use HasModeFilter;
14
15 /**
16 * Prepare the items for the table to process.
17 *
18 * @return void
19 */
20 public function prepare_items() {
21 $columns = $this->get_columns();
22 $hidden = $this->get_hidden_columns();
23 $sortable = $this->get_sortable_columns();
24
25 $this->_column_headers = array( $columns, $hidden, $sortable );
26
27 $query = $this->table_data();
28 if ( is_wp_error( $query ) ) {
29 $this->items = [];
30 return;
31 }
32
33 $this->set_pagination_args(
34 [
35 'total_items' => $query->pagination->count,
36 'per_page' => $this->get_items_per_page( 'invoices' ),
37 ]
38 );
39
40 $this->items = $query->data;
41 }
42
43 /**
44 * Override the parent columns method. Defines the columns to use in your listing table.
45 *
46 * @return array
47 */
48 public function get_columns() {
49 return [
50 'invoice' => __( 'Invoice', 'surecart' ),
51 'issue_date' => __( 'Issued', 'surecart' ),
52 'due_date' => __( 'Due', 'surecart' ),
53 'status' => __( 'Status', 'surecart' ),
54 'customer' => __( 'Customer', 'surecart' ),
55 'method' => __( 'Method', 'surecart' ),
56 'total' => __( 'Total', 'surecart' ),
57 'date' => __( 'Created', 'surecart' ),
58 'mode' => '',
59 ];
60 }
61
62 /**
63 * Show the payment method for the invoice.
64 *
65 * @param Invoice $invoice Invoice model.
66 *
67 * @return string
68 */
69 public function column_method( $invoice ) {
70 if ( isset( $invoice->checkout->manual_payment_method->name ) ) {
71 return '<sc-tag>' . $invoice->checkout->manual_payment_method->name . '</sc-tag>';
72 }
73 ob_start();
74 ?>
75 <sc-payment-method id="sc-method-<?php echo esc_attr( $invoice->id ); ?>"></sc-payment-method>
76 <script>
77 document.getElementById('sc-method-<?php echo esc_attr( $invoice->id ); ?>').paymentMethod = <?php echo wp_json_encode( $invoice->checkout->payment_method ); ?>;
78 </script>
79 <?php
80 return ob_get_clean();
81 }
82
83 /**
84 * Define which columns are hidden.
85 *
86 * @return array
87 */
88 public function get_hidden_columns() {
89 return array();
90 }
91
92 /**
93 * Get the table data.
94 *
95 * @return object
96 */
97 protected function table_data() {
98 $status = $this->getStatus();
99 $mode = sanitize_text_field( wp_unslash( $_GET['mode'] ?? '' ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
100 $where = array(
101 'query' => $this->get_search_query(),
102 );
103
104 if ( ! empty( $mode ) ) {
105 $where['live_mode'] = 'live' === $mode;
106 }
107
108 if ( $status ) {
109 $where['status'] = [ $status ];
110 }
111
112 // Check if there is any sc_collection in the query, then filter it.
113 if ( ! empty( $_GET['sc_customer'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
114 $where['customer_ids'] = array( sanitize_text_field( wp_unslash( $_GET['sc_customer'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
115 }
116
117 return Invoice::where( $where )
118 ->with( [ 'charge', 'checkout', 'checkout.order', 'checkout.charge', 'checkout.payment_method', 'checkout.manual_payment_method', 'checkout.customer', 'payment_method.card', 'payment_method.payment_instrument', 'payment_method.paypal_account', 'payment_method.bank_account' ] )
119 ->paginate(
120 [
121 'per_page' => $this->get_items_per_page( 'invoices' ),
122 'page' => $this->get_pagenum(),
123 ]
124 );
125 }
126
127 /**
128 * Generates views links.
129 *
130 * @return array
131 */
132 protected function get_views() {
133 $statuses = [
134 'all' => __( 'All', 'surecart' ),
135 'paid' => __( 'Paid', 'surecart' ),
136 'draft' => __( 'Draft', 'surecart' ),
137 'open' => __( 'Open', 'surecart' ),
138 ];
139
140 $link = \SureCart::getUrl()->index( 'invoices' );
141 $status_links = [];
142
143 foreach ( $statuses as $status => $label ) {
144 $current_link_attributes = '';
145
146 if ( ! empty( $_GET['status'] ) ) {
147 if ( $status === $_GET['status'] ) {
148 $current_link_attributes = ' class="current" aria-current="page"';
149 }
150 } elseif ( 'all' === $status ) {
151 $current_link_attributes = ' class="current" aria-current="page"';
152 }
153
154 $link = add_query_arg( 'status', $status, $link );
155
156 if ( isset( $_GET['live_mode'] ) ) {
157 $link = add_query_arg( 'live_mode', sanitize_text_field( wp_unslash( $_GET['live_mode'] ) ), $link );
158 }
159
160 $status_links[ $status ] = "<a href='$link'$current_link_attributes>" . $label . '</a>';
161 }
162
163 // filter links.
164 return apply_filters( 'sc_invoice_status_links', $status_links );
165 }
166
167 /**
168 * Get the query status.
169 *
170 * @return array
171 */
172 public function getStatus() {
173 $status = sanitize_text_field( wp_unslash( $_GET['status'] ?? 'all' ) );
174 if ( 'all' === $status ) {
175 return [];
176 }
177 return $status ? [ esc_html( $status ) ] : [];
178 }
179
180 /**
181 * Handle the total column.
182 *
183 * @param Invoice $invoice Invoice Model.
184 *
185 * @return string
186 */
187 public function column_total( $invoice ) {
188 return '<sc-format-number type="currency" currency="' . strtoupper( esc_html( $invoice->checkout->currency ?? 'u' ) ) . '" value="' . (float) $invoice->checkout->total_amount . '"></sc-format-number>';
189 }
190
191 /**
192 * Handle the total column.
193 *
194 * @param Invoice $invoice Invoice model.
195 *
196 * @return string
197 */
198 public function column_date( $invoice ) {
199 return '<sc-format-date date="' . (int) $invoice->created_at . '" type="timestamp" month="short" day="numeric" year="numeric" hour="numeric" minute="numeric"></sc-format-date>';
200 }
201
202 /**
203 * Handle invoice due date.
204 *
205 * @param Invoice $invoice Invoice model.
206 *
207 * @return string
208 */
209 public function column_due_date( $invoice ) {
210 return $invoice->due_date ? '<sc-format-date date="' . (int) $invoice->due_date . '" type="timestamp" month="short" day="numeric" year="numeric"></sc-format-date>' : '-';
211 }
212
213 /**
214 * Handle invoice issue date.
215 *
216 * @param Invoice $invoice Invoice model.
217 *
218 * @return string
219 */
220 public function column_issue_date( $invoice ) {
221 return $invoice->issue_date ? '<sc-format-date date="' . (int) $invoice->issue_date . '" type="timestamp" month="short" day="numeric" year="numeric"></sc-format-date>' : '-';
222 }
223
224 /**
225 * Show customer as tag.
226 *
227 * @param Invoice $invoice The invoice model.
228 */
229 public function column_customer( $invoice ) {
230 $customer = $invoice->checkout->customer ?? null;
231
232 if ( empty( $customer ) ) {
233 return '-';
234 }
235
236 $url = \SureCart::getUrl()->edit( 'customer', $customer->id );
237 return '<a href="' . esc_url( $url ) . '">' . ( ! empty( $customer->name ) ? $customer->name : $customer->email ) . '</a>';
238 }
239
240 /**
241 * Handle the status.
242 *
243 * @param Invoice $invoice Invoice Model.
244 *
245 * @return string
246 */
247 public function column_status( $invoice ) {
248 if ( ! empty( $invoice->checkout->charge->fully_refunded ) ) {
249 return '<sc-tag type="danger">' . __( 'Refunded', 'surecart' ) . '</sc-tag>';
250 }
251 return '<sc-invoice-status-badge status="' . esc_attr( $invoice->status ) . '"></sc-invoice-status-badge>';
252 }
253
254 /**
255 * Handle Invoice column.
256 *
257 * @param Invoice $invoice Invoice model.
258 *
259 * @return string
260 */
261 public function column_invoice( $invoice ) {
262 ob_start();
263 ?>
264 <a class="row-title" aria-label="<?php echo esc_attr__( 'Edit Invoice', 'surecart' ); ?>" href="<?php echo esc_url( \SureCart::getUrl()->edit( 'invoice', $invoice->id ) ); ?>">
265 <?php echo ! empty( $invoice->checkout->order->number ) ? '#' . esc_html( $invoice->checkout->order->number ) : esc_html_e( '(draft)', 'surecart' ); ?>
266 </a>
267
268 <?php
269 echo wp_kses_post(
270 $this->row_actions(
271 array_filter(
272 [
273 'edit' => '<a href="' . esc_url( \SureCart::getUrl()->edit( 'invoice', $invoice->id ) ) . '" aria-label="' . esc_attr__( 'Edit Invoice', 'surecart' ) . '">' . __( 'Edit', 'surecart' ) . '</a>',
274 'view' => 'open' === $invoice->status && ! empty( $invoice->checkout_url ) ? '<a href="' . esc_url( $invoice->checkout_url ) . '" aria-label="' . esc_attr__( 'View Payment Page', 'surecart' ) . '">' . __( 'View Payment Page', 'surecart' ) . '</a>' : null,
275 ]
276 ),
277 )
278 );
279
280 return ob_get_clean();
281 }
282
283 /**
284 * Handle the mode column.
285 *
286 * @param Invoice $invoice Invoice model.
287 *
288 * @return string
289 */
290 public function column_mode( $invoice ) {
291 return empty( $invoice->checkout->live_mode ) ? '<sc-tag type="warning">' . __( 'Test', 'surecart' ) . '</sc-tag>' : '';
292 }
293
294 /**
295 * Displays extra table navigation.
296 *
297 * @param string $which Top or bottom placement.
298 */
299 protected function extra_tablenav( $which ) {
300 ?>
301 <input type="hidden" name="page" value="sc-invoices" />
302
303 <?php if ( ! empty( $_GET['status'] ) ) : ?>
304 <input type="hidden" name="status" value="<?php echo esc_attr( $_GET['status'] ); ?>" />
305 <?php endif; ?>
306
307 <?php if ( ! empty( $_GET['live_mode'] ) ) : ?>
308 <input type="hidden" name="live_mode" value="<?php echo esc_attr( $_GET['live_mode'] ); ?>" />
309 <?php endif; ?>
310
311 <div class="alignleft actions">
312 <?php
313 if ( 'top' === $which ) {
314 ob_start();
315 $this->mode_dropdown();
316
317 /**
318 * Fires before the Filter button on the Posts and Pages list tables.
319 *
320 * The Filter button allows sorting by date and/or category on the
321 * Posts list table, and sorting by date on the Pages list table.
322 *
323 * @since 2.1.0
324 * @since 4.4.0 The `$post_type` parameter was added.
325 * @since 4.6.0 The `$which` parameter was added.
326 *
327 * @param string $post_type The post type slug.
328 * @param string $which The location of the extra table nav markup:
329 * 'top' or 'bottom' for WP_Posts_List_Table,
330 * 'bar' for WP_Media_List_Table.
331 */
332 do_action( 'restrict_manage_invoices', $this->screen->post_type, $which );
333
334 $output = ob_get_clean();
335
336 if ( ! empty( $output ) ) {
337 echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
338 submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'filter-by-fulfillment-submit' ) );
339 }
340 }
341
342 ?>
343 </div>
344
345 <?php
346 /**
347 * Fires immediately following the closing "actions" div in the tablenav for the posts
348 * list table.
349 *
350 * @since 4.4.0
351 *
352 * @param string $which The location of the extra table nav markup: 'top' or 'bottom'.
353 */
354 do_action( 'manage_invoices_extra_tablenav', $which );
355 }
356 }
357