|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Contains the class that displays a single report. |
|
4
|
|
|
* |
|
5
|
|
|
* |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
defined( 'ABSPATH' ) || exit; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* GetPaid_Reports_Report Class. |
|
12
|
|
|
*/ |
|
13
|
|
|
class GetPaid_Reports_Report { |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @var array |
|
17
|
|
|
*/ |
|
18
|
|
|
public $views; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Class constructor. |
|
22
|
|
|
* |
|
23
|
|
|
*/ |
|
24
|
|
|
public function __construct() { |
|
25
|
|
|
|
|
26
|
|
|
$this->views = array( |
|
27
|
|
|
|
|
28
|
|
|
'items' => array( |
|
29
|
|
|
'label' => __( 'Items', 'invoicing' ), |
|
30
|
|
|
'class' => 'GetPaid_Reports_Report_Items', |
|
31
|
|
|
), |
|
32
|
|
|
|
|
33
|
|
|
'gateways' => array( |
|
34
|
|
|
'label' => __( 'Payment Methods', 'invoicing' ), |
|
35
|
|
|
'class' => 'GetPaid_Reports_Report_Gateways', |
|
36
|
|
|
), |
|
37
|
|
|
|
|
38
|
|
|
'discounts' => array( |
|
39
|
|
|
'label' => __( 'Discount Codes', 'invoicing' ), |
|
40
|
|
|
'class' => 'GetPaid_Reports_Report_Discounts', |
|
41
|
|
|
), |
|
42
|
|
|
|
|
43
|
|
|
); |
|
44
|
|
|
|
|
45
|
|
|
$this->views = apply_filters( 'wpinv_report_views', $this->views ); |
|
46
|
|
|
|
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Retrieves the current range. |
|
51
|
|
|
* |
|
52
|
|
|
*/ |
|
53
|
|
|
public function get_range() { |
|
54
|
|
|
$valid_ranges = $this->get_periods(); |
|
55
|
|
|
|
|
56
|
|
|
if ( isset( $_GET['date_range'] ) && array_key_exists( $_GET['date_range'], $valid_ranges ) ) { |
|
57
|
|
|
return sanitize_key( $_GET['date_range'] ); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
return '7_days'; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Returns an array of date ranges. |
|
65
|
|
|
* |
|
66
|
|
|
* @return array |
|
67
|
|
|
*/ |
|
68
|
|
|
public function get_periods() { |
|
69
|
|
|
|
|
70
|
|
|
$periods = array( |
|
71
|
|
|
'today' => __( 'Today', 'invoicing' ), |
|
72
|
|
|
'yesterday' => __( 'Yesterday', 'invoicing' ), |
|
73
|
|
|
'week' => __( 'This week', 'invoicing' ), |
|
74
|
|
|
'last_week' => __( 'Last week', 'invoicing' ), |
|
75
|
|
|
'7_days' => __( 'Last 7 days', 'invoicing' ), |
|
76
|
|
|
'month' => __( 'This month', 'invoicing' ), |
|
77
|
|
|
'last_month' => __( 'Last month', 'invoicing' ), |
|
78
|
|
|
'30_days' => __( 'Last 30 days', 'invoicing' ), |
|
79
|
|
|
'year' => __( 'This year', 'invoicing' ), |
|
80
|
|
|
'last_year' => __( 'Last Year', 'invoicing' ), |
|
81
|
|
|
'custom' => __( 'Custom Date Range', 'invoicing' ), |
|
82
|
|
|
); |
|
83
|
|
|
|
|
84
|
|
|
return apply_filters( 'getpaid_earning_periods', $periods ); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Displays the range selector. |
|
89
|
|
|
* |
|
90
|
|
|
*/ |
|
91
|
|
|
public function display_range_selector() { |
|
92
|
|
|
|
|
93
|
|
|
$range = $this->get_range(); |
|
94
|
|
|
?> |
|
95
|
|
|
|
|
96
|
|
|
<form method="get" class="getpaid-filter-earnings float-right"> |
|
97
|
|
|
<?php getpaid_hidden_field( 'page', 'wpinv-reports' ); ?> |
|
98
|
|
|
<?php getpaid_hidden_field( 'tab', 'reports' ); ?> |
|
99
|
|
|
<select name='date_range'> |
|
100
|
|
|
<?php foreach( $this->get_periods() as $key => $label ) :?> |
|
101
|
|
|
<option value="<?php echo sanitize_key( $key ); ?>" <?php selected( $key, $range ); ?>><?php echo sanitize_text_field( $label ); ?></option> |
|
102
|
|
|
<?php endforeach;?> |
|
103
|
|
|
</select> |
|
104
|
|
|
<span class="getpaid-date-range-picker <?php echo 'custom' == $range ? '' : 'd-none'; ?>"> |
|
105
|
|
|
<input type="text" name="from" class="getpaid-from align-middle" /> |
|
106
|
|
|
<?php _e( 'to', 'invoicing' ); ?> |
|
107
|
|
|
<input type="text" name="to" class="getpaid-to align-middle" /> |
|
108
|
|
|
</span> |
|
109
|
|
|
<button type="submit" class="button button-primary"> |
|
110
|
|
|
<i class="fa fa-chevron-right fa-lg"></i> |
|
111
|
|
|
<span class="screen-reader-text"><?php _e( 'Next', 'invoicing' ); ?></span> |
|
112
|
|
|
</button> |
|
113
|
|
|
</form> |
|
114
|
|
|
|
|
115
|
|
|
<?php |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Displays the reports tab. |
|
120
|
|
|
* |
|
121
|
|
|
*/ |
|
122
|
|
|
public function display() { |
|
123
|
|
|
?> |
|
124
|
|
|
|
|
125
|
|
|
<div class="mt-4" style="max-width: 1200px;"> |
|
126
|
|
|
|
|
127
|
|
|
<section class="mb-4"> |
|
128
|
|
|
|
|
129
|
|
|
<!-- Period Selector Card --> |
|
130
|
|
|
<div class="card mw-100"> |
|
131
|
|
|
|
|
132
|
|
|
<div class="card-body py-0"> |
|
133
|
|
|
|
|
134
|
|
|
<!--Grid row--> |
|
135
|
|
|
<div class="row"> |
|
136
|
|
|
|
|
137
|
|
|
<!--Grid column--> |
|
138
|
|
|
<div class="col-md-6 offset-md-6"> |
|
139
|
|
|
<?php $this->display_range_selector(); ?> |
|
140
|
|
|
</div> |
|
141
|
|
|
<!--Grid column--> |
|
142
|
|
|
|
|
143
|
|
|
</div> |
|
144
|
|
|
<!--Grid row--> |
|
145
|
|
|
|
|
146
|
|
|
</div> |
|
147
|
|
|
|
|
148
|
|
|
</div> |
|
149
|
|
|
<!-- Period SelectorCard --> |
|
150
|
|
|
|
|
151
|
|
|
</section> |
|
152
|
|
|
|
|
153
|
|
|
<div class="row"> |
|
154
|
|
|
<div class="col-12 col-md-8"> |
|
155
|
|
|
<?php echo $this->display_left(); ?> |
|
|
|
|
|
|
156
|
|
|
</div> |
|
157
|
|
|
|
|
158
|
|
|
<div class="col-12 col-md-4"> |
|
159
|
|
|
<div class="row getpaid-report-cards"> |
|
160
|
|
|
<?php foreach( $this->get_cards() as $key => $card ) : ?> |
|
161
|
|
|
<div class="col-12 mb-4"> |
|
162
|
|
|
|
|
163
|
|
|
<!-- <?php echo sanitize_text_field( $card['label'] ); ?> Card --> |
|
164
|
|
|
<div class="card p-0 m-0 shadow-none <?php echo sanitize_html_class( $key ); ?>"> |
|
165
|
|
|
|
|
166
|
|
|
<div class="card-body"> |
|
167
|
|
|
|
|
168
|
|
|
<p class="getpaid-current text-uppercase small mb-2"> |
|
169
|
|
|
<strong><?php echo sanitize_text_field( $card['label'] ); ?></strong> |
|
170
|
|
|
<span title="<?php echo esc_attr( $card['description'] ); ?>" class="wpi-help-tip dashicons dashicons-editor-help text-muted" style="margin-top: -2px;"></span> |
|
171
|
|
|
</p> |
|
172
|
|
|
<h5 class="font-weight-bold mb-0"> |
|
173
|
|
|
<span class="getpaid-report-card-value"> |
|
174
|
|
|
<span class="spinner is-active float-none"></span> |
|
175
|
|
|
</span> |
|
176
|
|
|
<small class="getpaid-report-card-growth ml-2"></small> |
|
177
|
|
|
</h5> |
|
178
|
|
|
|
|
179
|
|
|
<hr> |
|
180
|
|
|
|
|
181
|
|
|
<p class="getpaid-previous text-uppercase text-muted small mb-2"><strong><?php _e( 'Previous Period', 'invoicing' ); ?></strong></p> |
|
182
|
|
|
<h5 class="getpaid-report-card-previous-value font-weight-bold text-muted mb-0"> |
|
183
|
|
|
<span class="spinner is-active float-none"></span> |
|
184
|
|
|
</h5> |
|
185
|
|
|
|
|
186
|
|
|
</div> |
|
187
|
|
|
|
|
188
|
|
|
</div> |
|
189
|
|
|
<!-- <?php echo sanitize_text_field( $card['label'] ); ?> Card --> |
|
190
|
|
|
|
|
191
|
|
|
</div> |
|
192
|
|
|
<?php endforeach; ?> |
|
193
|
|
|
</div> |
|
194
|
|
|
|
|
195
|
|
|
<?php echo $this->display_right(); ?> |
|
|
|
|
|
|
196
|
|
|
</div> |
|
197
|
|
|
</div> |
|
198
|
|
|
|
|
199
|
|
|
</div> |
|
200
|
|
|
|
|
201
|
|
|
<?php |
|
202
|
|
|
|
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
/** |
|
206
|
|
|
* Displays the left side. |
|
207
|
|
|
* |
|
208
|
|
|
*/ |
|
209
|
|
|
public function display_left() { |
|
210
|
|
|
$graphs = array( |
|
211
|
|
|
'sales' => __( 'Earnings', 'invoicing' ), |
|
212
|
|
|
'refunds' => __( 'Refunds', 'invoicing' ), |
|
213
|
|
|
'tax' => __( 'Taxes', 'invoicing' ), |
|
214
|
|
|
'fees' => __( 'Fees', 'invoicing' ), |
|
215
|
|
|
'discount' => __( 'Discounts', 'invoicing' ), |
|
216
|
|
|
'invoices' => __( 'Invoices', 'invoicing' ), |
|
217
|
|
|
'items' => __( 'Purchased Items', 'invoicing' ), |
|
218
|
|
|
); |
|
219
|
|
|
|
|
220
|
|
|
?> |
|
221
|
|
|
|
|
222
|
|
|
<?php foreach ( $graphs as $key => $graph ) : ?> |
|
223
|
|
|
<div class="row mb-4"> |
|
224
|
|
|
<div class="col-12"> |
|
225
|
|
|
<div class="card m-0 p-0" style="max-width:100%"> |
|
226
|
|
|
<div class="card-header"> |
|
227
|
|
|
<strong><?php echo wpinv_clean( $graph ); ?></strong> |
|
228
|
|
|
</div> |
|
229
|
|
|
<div class="card-body"> |
|
230
|
|
|
<canvas id="getpaid-chartjs-<?php echo sanitize_key( $key ); ?>"></canvas> |
|
231
|
|
|
</div> |
|
232
|
|
|
</div> |
|
233
|
|
|
</div> |
|
234
|
|
|
</div> |
|
235
|
|
|
<?php endforeach; ?> |
|
236
|
|
|
|
|
237
|
|
|
<?php |
|
238
|
|
|
|
|
239
|
|
|
} |
|
240
|
|
|
|
|
241
|
|
|
/** |
|
242
|
|
|
* Retrieves the download url. |
|
243
|
|
|
* |
|
244
|
|
|
*/ |
|
245
|
|
|
public function get_download_url( $graph, $file_type ) { |
|
246
|
|
|
|
|
247
|
|
|
return wp_nonce_url( |
|
248
|
|
|
add_query_arg( |
|
249
|
|
|
array( |
|
250
|
|
|
'getpaid-admin-action' => 'download_graph', |
|
251
|
|
|
'file_type' => urlencode( $file_type ), |
|
252
|
|
|
'graph' => urlencode( $graph ), |
|
253
|
|
|
) |
|
254
|
|
|
), |
|
255
|
|
|
'getpaid-nonce', |
|
256
|
|
|
'getpaid-nonce' |
|
257
|
|
|
); |
|
258
|
|
|
|
|
259
|
|
|
} |
|
260
|
|
|
|
|
261
|
|
|
/** |
|
262
|
|
|
* Displays the right side. |
|
263
|
|
|
* |
|
264
|
|
|
*/ |
|
265
|
|
|
public function display_right() { |
|
266
|
|
|
|
|
267
|
|
|
?> |
|
268
|
|
|
|
|
269
|
|
|
<?php foreach ( $this->views as $key => $view ) : ?> |
|
270
|
|
|
<div class="row mb-4"> |
|
271
|
|
|
<div class="col-12"> |
|
272
|
|
|
<div class="card m-0 p-0" style="max-width:100%"> |
|
273
|
|
|
<div class="card-header"> |
|
274
|
|
|
<div class="row"> |
|
275
|
|
|
<div class="col-9"> |
|
276
|
|
|
<strong><?php echo $view['label']; ?></strong> |
|
277
|
|
|
</div> |
|
278
|
|
|
<div class="col-3"> |
|
279
|
|
|
<a title="<?php esc_attr_e( 'Download JSON', 'invoicing' ); ?>" href="<?php echo esc_url( $this->get_download_url( $key, 'json' ) ); ?>"> |
|
280
|
|
|
<i class="fa fa-download text-dark" style="font-size: 16px" aria-hidden="true"></i> |
|
281
|
|
|
<span class="screen-reader-text"><?php _e( 'Download JSON', 'invoicing' ); ?></span> |
|
282
|
|
|
</a> |
|
283
|
|
|
<a title="<?php esc_attr_e( 'Download CSV', 'invoicing' ); ?>" href="<?php echo esc_url( $this->get_download_url( $key, 'csv' ) ); ?>"> |
|
284
|
|
|
<i class="fa fa-file-csv text-dark" style="font-size: 16px" aria-hidden="true"></i> |
|
285
|
|
|
<span class="screen-reader-text"><?php _e( 'Download CSV', 'invoicing' ); ?></span> |
|
286
|
|
|
</a> |
|
287
|
|
|
<a title="<?php esc_attr_e( 'Download XML', 'invoicing' ); ?>" href="<?php echo esc_url( $this->get_download_url( $key, 'xml' ) ); ?>"> |
|
288
|
|
|
<i class="fa fa-file-code text-dark" style="font-size: 16px" aria-hidden="true"></i> |
|
289
|
|
|
<span class="screen-reader-text"><?php _e( 'Download XML', 'invoicing' ); ?></span> |
|
290
|
|
|
</a> |
|
291
|
|
|
</div> |
|
292
|
|
|
</div> |
|
293
|
|
|
</div> |
|
294
|
|
|
<div class="card-body"> |
|
295
|
|
|
<?php |
|
296
|
|
|
$class = $view['class']; |
|
297
|
|
|
$class = new $class(); |
|
298
|
|
|
$class->display_stats(); |
|
299
|
|
|
?> |
|
300
|
|
|
</div> |
|
301
|
|
|
</div> |
|
302
|
|
|
</div> |
|
303
|
|
|
</div> |
|
304
|
|
|
<?php endforeach; ?> |
|
305
|
|
|
|
|
306
|
|
|
<?php |
|
307
|
|
|
|
|
308
|
|
|
} |
|
309
|
|
|
|
|
310
|
|
|
/** |
|
311
|
|
|
* Returns a list of report cards. |
|
312
|
|
|
* |
|
313
|
|
|
*/ |
|
314
|
|
|
public function get_cards() { |
|
315
|
|
|
|
|
316
|
|
|
$cards = array( |
|
317
|
|
|
'total_sales' => array( |
|
318
|
|
|
'description' => __( 'Gross sales in the period.', 'invoicing' ), |
|
319
|
|
|
'label' => __( 'Gross Revenue', 'invoicing' ), |
|
320
|
|
|
), |
|
321
|
|
|
'net_sales' => array( |
|
322
|
|
|
'description' => __( 'Net sales in the period.', 'invoicing' ), |
|
323
|
|
|
'label' => __( 'Net Revenue', 'invoicing' ), |
|
324
|
|
|
), |
|
325
|
|
|
'average_sales' => array( |
|
326
|
|
|
'description' => __( 'Average net daily/monthly sales.', 'invoicing' ), |
|
327
|
|
|
'label' => __( 'Avg. Net Sales', 'invoicing' ), |
|
328
|
|
|
), |
|
329
|
|
|
'average_total_sales' => array( |
|
330
|
|
|
'description' => __( 'Average gross daily/monthly sales.', 'invoicing' ), |
|
331
|
|
|
'label' => __( 'Avg. Gross Sales', 'invoicing' ), |
|
332
|
|
|
), |
|
333
|
|
|
'total_invoices' => array( |
|
334
|
|
|
'description' => __( 'Number of paid invoices.', 'invoicing' ), |
|
335
|
|
|
'label' => __( 'Paid Invoices', 'invoicing' ), |
|
336
|
|
|
), |
|
337
|
|
|
'total_items' => array( |
|
338
|
|
|
'description' => __( 'Number of items purchased.', 'invoicing' ), |
|
339
|
|
|
'label' => __( 'Purchased Items', 'invoicing' ), |
|
340
|
|
|
), |
|
341
|
|
|
'refunded_items' => array( |
|
342
|
|
|
'description' => __( 'Number of items refunded.', 'invoicing' ), |
|
343
|
|
|
'label' => __( 'Refunded Items', 'invoicing' ), |
|
344
|
|
|
), |
|
345
|
|
|
'total_tax' => array( |
|
346
|
|
|
'description' => __( 'Total charged for taxes.', 'invoicing' ), |
|
347
|
|
|
'label' => __( 'Tax', 'invoicing' ), |
|
348
|
|
|
), |
|
349
|
|
|
'total_refunded_tax' => array( |
|
350
|
|
|
'description' => __( 'Total refunded for taxes.', 'invoicing' ), |
|
351
|
|
|
'label' => __( 'Refunded Tax', 'invoicing' ), |
|
352
|
|
|
), |
|
353
|
|
|
'total_fees' => array( |
|
354
|
|
|
'description' => __( 'Total fees charged.', 'invoicing' ), |
|
355
|
|
|
'label' => __( 'Fees', 'invoicing' ), |
|
356
|
|
|
), |
|
357
|
|
|
'total_refunds' => array( |
|
358
|
|
|
'description' => __( 'Total of refunded invoices.', 'invoicing' ), |
|
359
|
|
|
'label' => __( 'Refunded', 'invoicing' ), |
|
360
|
|
|
), |
|
361
|
|
|
'total_discount' => array( |
|
362
|
|
|
'description' => __( 'Total of discounts used.', 'invoicing' ), |
|
363
|
|
|
'label' => __( 'Discounted', 'invoicing' ), |
|
364
|
|
|
), |
|
365
|
|
|
); |
|
366
|
|
|
|
|
367
|
|
|
return apply_filters( 'wpinv_report_cards', $cards ); |
|
368
|
|
|
} |
|
369
|
|
|
|
|
370
|
|
|
|
|
371
|
|
|
|
|
372
|
|
|
} |
|
373
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.