get_columns();
$hidden = $this->get_hidden_columns();
$sortable = $this->get_sortable_columns();
$this->_column_headers = array( $columns, $hidden, $sortable );
$query = $this->table_data();
if ( is_wp_error( $query ) ) {
$this->items = [];
return;
}
$this->set_pagination_args(
[
'total_items' => $query->pagination->count,
'per_page' => $this->get_items_per_page( 'invoices' ),
]
);
$this->items = $query->data;
}
/**
* Override the parent columns method. Defines the columns to use in your listing table.
*
* @return array
*/
public function get_columns() {
return array_merge(
[
'invoice' => __( 'Invoice', 'surecart' ),
'issue_date' => __( 'Issued', 'surecart' ),
'due_date' => __( 'Due', 'surecart' ),
'status' => __( 'Status', 'surecart' ),
'customer' => __( 'Customer', 'surecart' ),
'method' => __( 'Method', 'surecart' ),
'total' => __( 'Total', 'surecart' ),
'created' => __( 'Created', 'surecart' ),
'mode' => '',
],
parent::get_columns()
);
}
/**
* Show the payment method for the invoice.
*
* @param Invoice $invoice Invoice model.
*
* @return string
*/
public function column_method( $invoice ) {
if ( isset( $invoice->checkout->manual_payment_method->name ) ) {
return '' . esc_html( $invoice->checkout->manual_payment_method->name ) . ' ';
}
ob_start();
?>
getStatus();
$mode = sanitize_text_field( wp_unslash( $_GET['mode'] ?? '' ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
$where = array(
'query' => $this->get_search_query(),
);
if ( ! empty( $mode ) ) {
$where['live_mode'] = 'live' === $mode;
}
if ( $status ) {
$where['status'] = [ $status ];
}
// Check if there is any sc_collection in the query, then filter it.
if ( ! empty( $_GET['sc_customer'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
$where['customer_ids'] = array( sanitize_text_field( wp_unslash( $_GET['sc_customer'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
}
return Invoice::where( $where )
->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' ] )
->paginate(
[
'per_page' => $this->get_items_per_page( 'invoices' ),
'page' => $this->get_pagenum(),
]
);
}
/**
* Generates views links.
*
* @return array
*/
protected function get_views() {
$statuses = [
'all' => __( 'All', 'surecart' ),
'paid' => __( 'Paid', 'surecart' ),
'draft' => __( 'Draft', 'surecart' ),
'open' => __( 'Open', 'surecart' ),
];
$status_links = [];
foreach ( $statuses as $status => $label ) {
$link = \SureCart::getUrl()->index( 'invoices' );
$current_link_attributes = '';
if ( ! empty( $_GET['status'] ) ) {
if ( $status === $_GET['status'] ) {
$current_link_attributes = ' class="current" aria-current="page"';
}
} elseif ( 'all' === $status ) {
$current_link_attributes = ' class="current" aria-current="page"';
}
$link = add_query_arg( 'status', $status, $link );
if ( isset( $_GET['live_mode'] ) ) {
$link = add_query_arg( 'live_mode', sanitize_text_field( wp_unslash( $_GET['live_mode'] ) ), $link );
}
$link = esc_url( $link );
$status_links[ $status ] = "" . $label . ' ';
}
// filter links.
return apply_filters( 'sc_invoice_status_links', $status_links );
}
/**
* Get the query status.
*
* @return array
*/
public function getStatus() {
$status = sanitize_text_field( wp_unslash( $_GET['status'] ?? 'all' ) );
if ( 'all' === $status ) {
return [];
}
return $status ? [ esc_html( $status ) ] : [];
}
/**
* Handle the total column.
*
* @param Invoice $invoice Invoice Model.
*
* @return string
*/
public function column_total( $invoice ) {
return $invoice->checkout->total_display_amount;
}
/**
* Handle invoice due date.
*
* @param Invoice $invoice Invoice model.
*
* @return string
*/
public function column_due_date( $invoice ) {
return $invoice->due_date_date ?? '-';
}
/**
* Handle invoice issue date.
*
* @param Invoice $invoice Invoice model.
*
* @return string
*/
public function column_issue_date( $invoice ) {
return $invoice->issue_date_date ?? '-';
}
/**
* Show customer as tag.
*
* @param Invoice $invoice The invoice model.
*/
public function column_customer( $invoice ) {
$customer = $invoice->checkout->customer ?? null;
if ( empty( $customer ) ) {
return '-';
}
$url = \SureCart::getUrl()->edit( 'customer', $customer->id );
return '' . esc_html( ! empty( $customer->name ) ? $customer->name : $customer->email ) . ' ';
}
/**
* Handle the status.
*
* @param Invoice $invoice Invoice Model.
*
* @return string
*/
public function column_status( $invoice ) {
if ( ! empty( $invoice->checkout->charge->fully_refunded ) ) {
return '' . __( 'Refunded', 'surecart' ) . ' ';
}
return ' ';
}
/**
* Handle Invoice column.
*
* @param Invoice $invoice Invoice model.
*
* @return string
*/
public function column_invoice( $invoice ) {
ob_start();
?>
checkout->order->number ) ? '#' . esc_html( $invoice->checkout->order->number ) : esc_html_e( '(draft)', 'surecart' ); ?>
row_actions(
array_filter(
[
'edit' => '' . __( 'Edit', 'surecart' ) . ' ',
'view' => 'open' === $invoice->status && ! empty( $invoice->checkout_url ) ? '' . __( 'View Payment Page', 'surecart' ) . ' ' : null,
]
),
)
);
return ob_get_clean();
}
/**
* Handle the mode column.
*
* @param Invoice $invoice Invoice model.
*
* @return string
*/
public function column_mode( $invoice ) {
return empty( $invoice->checkout->live_mode ) ? '' . __( 'Test', 'surecart' ) . ' ' : '';
}
/**
* Displays extra table navigation.
*
* @param string $which Top or bottom placement.
*/
protected function extra_tablenav( $which ) {
?>
mode_dropdown();
/**
* Fires before the Filter button on the Posts and Pages list tables.
*
* The Filter button allows sorting by date and/or category on the
* Posts list table, and sorting by date on the Pages list table.
*
* @since 2.1.0
* @since 4.4.0 The `$post_type` parameter was added.
* @since 4.6.0 The `$which` parameter was added.
*
* @param string $post_type The post type slug.
* @param string $which The location of the extra table nav markup:
* 'top' or 'bottom' for WP_Posts_List_Table,
* 'bar' for WP_Media_List_Table.
*/
do_action( 'restrict_manage_invoices', $this->screen->post_type, $which );
$output = ob_get_clean();
if ( ! empty( $output ) ) {
echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
submit_button( __( 'Filter', 'surecart' ), '', 'filter_action', false, array( 'id' => 'filter-by-fulfillment-submit' ) );
}
}
?>