PluginProbe ʕ •ᴥ•ʔ
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 4.6.0
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v4.6.0
4.6.1 4.6.0 4.5.1 4.5.0 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 3 months ago InvoicesListTable.php 2 months ago InvoicesViewController.php 1 year ago
InvoicesListTable.php
349 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 array_merge(
50 [
51 'invoice' => __( 'Invoice', 'surecart' ),
52 'issue_date' => __( 'Issued', 'surecart' ),
53 'due_date' => __( 'Due', 'surecart' ),
54 'status' => __( 'Status', 'surecart' ),
55 'customer' => __( 'Customer', 'surecart' ),
56 'method' => __( 'Method', 'surecart' ),
57 'total' => __( 'Total', 'surecart' ),
58 'created' => __( 'Created', 'surecart' ),
59 'mode' => '',
60 ],
61 parent::get_columns()
62 );
63 }
64
65 /**
66 * Show the payment method for the invoice.
67 *
68 * @param Invoice $invoice Invoice model.
69 *
70 * @return string
71 */
72 public function column_method( $invoice ) {
73 if ( isset( $invoice->checkout->manual_payment_method->name ) ) {
74 return '<sc-tag>' . esc_html( $invoice->checkout->manual_payment_method->name ) . '</sc-tag>';
75 }
76 ob_start();
77 ?>
78 <sc-payment-method id="sc-method-<?php echo esc_attr( $invoice->id ); ?>"></sc-payment-method>
79 <script>
80 document.getElementById('sc-method-<?php echo esc_attr( $invoice->id ); ?>').paymentMethod = <?php echo wp_json_encode( $invoice->checkout->payment_method ); ?>;
81 </script>
82 <?php
83 return ob_get_clean();
84 }
85
86 /**
87 * Define which columns are hidden.
88 *
89 * @return array
90 */
91 public function get_hidden_columns() {
92 return array();
93 }
94
95 /**
96 * Get the table data.
97 *
98 * @return object
99 */
100 protected function table_data() {
101 $status = $this->getStatus();
102 $mode = sanitize_text_field( wp_unslash( $_GET['mode'] ?? '' ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
103 $where = array(
104 'query' => $this->get_search_query(),
105 );
106
107 if ( ! empty( $mode ) ) {
108 $where['live_mode'] = 'live' === $mode;
109 }
110
111 if ( $status ) {
112 $where['status'] = [ $status ];
113 }
114
115 // Check if there is any sc_collection in the query, then filter it.
116 if ( ! empty( $_GET['sc_customer'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
117 $where['customer_ids'] = array( sanitize_text_field( wp_unslash( $_GET['sc_customer'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
118 }
119
120 return Invoice::where( $where )
121 ->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' ] )
122 ->paginate(
123 [
124 'per_page' => $this->get_items_per_page( 'invoices' ),
125 'page' => $this->get_pagenum(),
126 ]
127 );
128 }
129
130 /**
131 * Generates views links.
132 *
133 * @return array
134 */
135 protected function get_views() {
136 $statuses = [
137 'all' => __( 'All', 'surecart' ),
138 'paid' => __( 'Paid', 'surecart' ),
139 'draft' => __( 'Draft', 'surecart' ),
140 'open' => __( 'Open', 'surecart' ),
141 ];
142
143 $link = \SureCart::getUrl()->index( 'invoices' );
144 $status_links = [];
145
146 foreach ( $statuses as $status => $label ) {
147 $current_link_attributes = '';
148
149 if ( ! empty( $_GET['status'] ) ) {
150 if ( $status === $_GET['status'] ) {
151 $current_link_attributes = ' class="current" aria-current="page"';
152 }
153 } elseif ( 'all' === $status ) {
154 $current_link_attributes = ' class="current" aria-current="page"';
155 }
156
157 $link = add_query_arg( 'status', $status, $link );
158
159 if ( isset( $_GET['live_mode'] ) ) {
160 $link = add_query_arg( 'live_mode', sanitize_text_field( wp_unslash( $_GET['live_mode'] ) ), $link );
161 }
162
163 $status_links[ $status ] = "<a href='$link'$current_link_attributes>" . $label . '</a>';
164 }
165
166 // filter links.
167 return apply_filters( 'sc_invoice_status_links', $status_links );
168 }
169
170 /**
171 * Get the query status.
172 *
173 * @return array
174 */
175 public function getStatus() {
176 $status = sanitize_text_field( wp_unslash( $_GET['status'] ?? 'all' ) );
177 if ( 'all' === $status ) {
178 return [];
179 }
180 return $status ? [ esc_html( $status ) ] : [];
181 }
182
183 /**
184 * Handle the total column.
185 *
186 * @param Invoice $invoice Invoice Model.
187 *
188 * @return string
189 */
190 public function column_total( $invoice ) {
191 return $invoice->checkout->total_display_amount;
192 }
193
194 /**
195 * Handle invoice due date.
196 *
197 * @param Invoice $invoice Invoice model.
198 *
199 * @return string
200 */
201 public function column_due_date( $invoice ) {
202 return $invoice->due_date_date ?? '-';
203 }
204
205 /**
206 * Handle invoice issue date.
207 *
208 * @param Invoice $invoice Invoice model.
209 *
210 * @return string
211 */
212 public function column_issue_date( $invoice ) {
213 return $invoice->issue_date_date ?? '-';
214 }
215
216 /**
217 * Show customer as tag.
218 *
219 * @param Invoice $invoice The invoice model.
220 */
221 public function column_customer( $invoice ) {
222 $customer = $invoice->checkout->customer ?? null;
223
224 if ( empty( $customer ) ) {
225 return '-';
226 }
227
228 $url = \SureCart::getUrl()->edit( 'customer', $customer->id );
229 return '<a href="' . esc_url( $url ) . '">' . esc_html( ! empty( $customer->name ) ? $customer->name : $customer->email ) . '</a>';
230 }
231
232 /**
233 * Handle the status.
234 *
235 * @param Invoice $invoice Invoice Model.
236 *
237 * @return string
238 */
239 public function column_status( $invoice ) {
240 if ( ! empty( $invoice->checkout->charge->fully_refunded ) ) {
241 return '<sc-tag type="danger">' . __( 'Refunded', 'surecart' ) . '</sc-tag>';
242 }
243 return '<sc-invoice-status-badge status="' . esc_attr( $invoice->status ) . '"></sc-invoice-status-badge>';
244 }
245
246 /**
247 * Handle Invoice column.
248 *
249 * @param Invoice $invoice Invoice model.
250 *
251 * @return string
252 */
253 public function column_invoice( $invoice ) {
254 ob_start();
255 ?>
256 <a class="row-title" aria-label="<?php echo esc_attr__( 'Edit Invoice', 'surecart' ); ?>" href="<?php echo esc_url( \SureCart::getUrl()->edit( 'invoice', $invoice->id ) ); ?>">
257 <?php echo ! empty( $invoice->checkout->order->number ) ? '#' . esc_html( $invoice->checkout->order->number ) : esc_html_e( '(draft)', 'surecart' ); ?>
258 </a>
259
260 <?php
261 echo wp_kses_post(
262 $this->row_actions(
263 array_filter(
264 [
265 'edit' => '<a href="' . esc_url( \SureCart::getUrl()->edit( 'invoice', $invoice->id ) ) . '" aria-label="' . esc_attr__( 'Edit Invoice', 'surecart' ) . '">' . __( 'Edit', 'surecart' ) . '</a>',
266 '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,
267 ]
268 ),
269 )
270 );
271
272 return ob_get_clean();
273 }
274
275 /**
276 * Handle the mode column.
277 *
278 * @param Invoice $invoice Invoice model.
279 *
280 * @return string
281 */
282 public function column_mode( $invoice ) {
283 return empty( $invoice->checkout->live_mode ) ? '<sc-tag type="warning">' . __( 'Test', 'surecart' ) . '</sc-tag>' : '';
284 }
285
286 /**
287 * Displays extra table navigation.
288 *
289 * @param string $which Top or bottom placement.
290 */
291 protected function extra_tablenav( $which ) {
292 ?>
293 <input type="hidden" name="page" value="sc-invoices" />
294
295 <?php if ( ! empty( $_GET['status'] ) ) : ?>
296 <input type="hidden" name="status" value="<?php echo esc_attr( $_GET['status'] ); ?>" />
297 <?php endif; ?>
298
299 <?php if ( ! empty( $_GET['live_mode'] ) ) : ?>
300 <input type="hidden" name="live_mode" value="<?php echo esc_attr( $_GET['live_mode'] ); ?>" />
301 <?php endif; ?>
302
303 <div class="alignleft actions">
304 <?php
305 if ( 'top' === $which ) {
306 ob_start();
307 $this->mode_dropdown();
308
309 /**
310 * Fires before the Filter button on the Posts and Pages list tables.
311 *
312 * The Filter button allows sorting by date and/or category on the
313 * Posts list table, and sorting by date on the Pages list table.
314 *
315 * @since 2.1.0
316 * @since 4.4.0 The `$post_type` parameter was added.
317 * @since 4.6.0 The `$which` parameter was added.
318 *
319 * @param string $post_type The post type slug.
320 * @param string $which The location of the extra table nav markup:
321 * 'top' or 'bottom' for WP_Posts_List_Table,
322 * 'bar' for WP_Media_List_Table.
323 */
324 do_action( 'restrict_manage_invoices', $this->screen->post_type, $which );
325
326 $output = ob_get_clean();
327
328 if ( ! empty( $output ) ) {
329 echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
330 submit_button( __( 'Filter', 'surecart' ), '', 'filter_action', false, array( 'id' => 'filter-by-fulfillment-submit' ) );
331 }
332 }
333
334 ?>
335 </div>
336
337 <?php
338 /**
339 * Fires immediately following the closing "actions" div in the tablenav for the posts
340 * list table.
341 *
342 * @since 4.4.0
343 *
344 * @param string $which The location of the extra table nav markup: 'top' or 'bottom'.
345 */
346 do_action( 'manage_invoices_extra_tablenav', $which );
347 }
348 }
349