|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Gateways Reports Table Class |
|
4
|
|
|
* |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
// Exit if accessed directly |
|
8
|
|
|
if ( ! defined( 'ABSPATH' ) ) exit; |
|
9
|
|
|
|
|
10
|
|
|
// Load WP_List_Table if not loaded |
|
11
|
|
|
if ( ! class_exists( 'WP_List_Table' ) ) { |
|
12
|
|
|
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
13
|
|
|
} |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* WPInv_Gateawy_Reports_Table Class |
|
17
|
|
|
* |
|
18
|
|
|
* Renders the Gateway Reports table |
|
19
|
|
|
* |
|
20
|
|
|
* @since 1.0.19 |
|
21
|
|
|
*/ |
|
22
|
|
|
class WPInv_Gateways_Report_Table extends WP_List_Table { |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var int Number of items per page |
|
26
|
|
|
* @since 1.0.19 |
|
27
|
|
|
*/ |
|
28
|
|
|
public $per_page = 300; |
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Get things started |
|
33
|
|
|
* |
|
34
|
|
|
* @since 1.0.19 |
|
35
|
|
|
* @see WP_List_Table::__construct() |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct() { |
|
38
|
|
|
global $status, $page; |
|
39
|
|
|
|
|
40
|
|
|
// Set parent defaults |
|
41
|
|
|
parent::__construct( array( |
|
42
|
|
|
'singular' => 'id', |
|
43
|
|
|
'plural' => 'ids', |
|
44
|
|
|
'ajax' => false, |
|
45
|
|
|
) ); |
|
46
|
|
|
|
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Gets the name of the primary column. |
|
51
|
|
|
* |
|
52
|
|
|
* @since 1.0.19 |
|
53
|
|
|
* @access protected |
|
54
|
|
|
* |
|
55
|
|
|
* @return string Name of the primary column. |
|
56
|
|
|
*/ |
|
57
|
|
|
protected function get_primary_column_name() { |
|
58
|
|
|
return 'label'; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* This function renders most of the columns in the list table. |
|
63
|
|
|
* |
|
64
|
|
|
* @since 1.0.19 |
|
65
|
|
|
* |
|
66
|
|
|
* @param array $item Contains all the data of the gateways |
|
67
|
|
|
* @param string $column_name The name of the column |
|
68
|
|
|
* |
|
69
|
|
|
* @return string Column Name |
|
70
|
|
|
*/ |
|
71
|
|
|
public function column_default( $item, $column_name ) { |
|
72
|
|
|
return esc_html( $item[ $column_name ] ); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Retrieve the table columns |
|
77
|
|
|
* |
|
78
|
|
|
* @since 1.0.19 |
|
79
|
|
|
* @return array $columns Array of all the list table columns |
|
80
|
|
|
*/ |
|
81
|
|
|
public function get_columns() { |
|
82
|
|
|
$columns = array( |
|
83
|
|
|
'label' => __( 'Gateway', 'invoicing' ), |
|
84
|
|
|
'complete_sales' => __( 'Complete Sales', 'invoicing' ), |
|
85
|
|
|
'pending_sales' => __( 'Pending / Failed Sales', 'invoicing' ), |
|
86
|
|
|
'total_sales' => __( 'Total Sales', 'invoicing' ), |
|
87
|
|
|
); |
|
88
|
|
|
|
|
89
|
|
|
return $columns; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Retrieve the current page number |
|
94
|
|
|
* |
|
95
|
|
|
* @since 1.0.19 |
|
96
|
|
|
* @return int Current page number |
|
97
|
|
|
*/ |
|
98
|
|
|
public function get_paged() { |
|
99
|
|
|
return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Outputs the reporting views |
|
104
|
|
|
* |
|
105
|
|
|
* @since 1.0.19 |
|
106
|
|
|
* @return void |
|
107
|
|
|
*/ |
|
108
|
|
|
public function bulk_actions( $which = '' ) { |
|
109
|
|
|
return array(); |
|
|
|
|
|
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Build all the reports data |
|
114
|
|
|
* |
|
115
|
|
|
* @since 1.0.19 |
|
116
|
|
|
* @return array $reports_data All the data for gateway reports |
|
117
|
|
|
*/ |
|
118
|
|
|
public function reports_data() { |
|
119
|
|
|
|
|
120
|
|
|
$reports_data = array(); |
|
121
|
|
|
$gateways = wpinv_get_payment_gateways(); |
|
122
|
|
|
|
|
123
|
|
|
foreach ( $gateways as $gateway_id => $gateway ) { |
|
124
|
|
|
|
|
125
|
|
|
$complete_count = wpinv_count_sales_by_gateway( $gateway_id, 'publish' ); |
|
126
|
|
|
$pending_count = wpinv_count_sales_by_gateway( $gateway_id, array( 'pending', 'failed' ) ); |
|
127
|
|
|
|
|
128
|
|
|
$reports_data[] = array( |
|
129
|
|
|
'ID' => $gateway_id, |
|
130
|
|
|
'label' => $gateway['admin_label'], |
|
131
|
|
|
'complete_sales' => wpinv_format_amount( $complete_count, false ), |
|
132
|
|
|
'pending_sales' => wpinv_format_amount( $pending_count, false ), |
|
133
|
|
|
'total_sales' => wpinv_format_amount( $complete_count + $pending_count, false ), |
|
134
|
|
|
); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
return $reports_data; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* Setup the final data for the table |
|
142
|
|
|
* |
|
143
|
|
|
* @since 1.0.19 |
|
144
|
|
|
* @return void |
|
145
|
|
|
*/ |
|
146
|
|
|
public function prepare_items() { |
|
147
|
|
|
$columns = $this->get_columns(); |
|
148
|
|
|
$hidden = array(); // No hidden columns |
|
149
|
|
|
$sortable = $this->get_sortable_columns(); |
|
150
|
|
|
$this->_column_headers = array( $columns, $hidden, $sortable ); |
|
151
|
|
|
$this->items = $this->reports_data(); |
|
152
|
|
|
} |
|
153
|
|
|
} |
|
154
|
|
|
|