AbstractReport.php
3 years ago
Orders.php
3 years ago
PaymentMethods.php
3 years ago
Refunds.php
4 years ago
ReportFilterData.php
4 years ago
ReportInterval.php
4 years ago
Revenue.php
4 years ago
SettingsPage.php
1 year ago
Taxes.php
4 years ago
TopPlans.php
4 years ago
index.php
4 years ago
Refunds.php
59 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ProfilePress\Core\Admin\SettingsPages\Membership\DashboardPage; |
| 4 | |
| 5 | use ProfilePress\Core\Membership\Models\Order\OrderStatus; |
| 6 | |
| 7 | class Refunds extends AbstractReport |
| 8 | { |
| 9 | public function get_total($start_date = '', $end_date = '') |
| 10 | { |
| 11 | static $bucket = []; |
| 12 | |
| 13 | $cache_key = md5('refunds_get_total' . $start_date . $end_date); |
| 14 | |
| 15 | if ( ! isset($bucket[$cache_key])) { |
| 16 | $start_date = ! empty($start_date) ? $start_date : ''; |
| 17 | $end_date = ! empty($end_date) ? $end_date : ''; |
| 18 | |
| 19 | $where_clause = $this->get_where_clause(false, $start_date, $end_date); |
| 20 | |
| 21 | $bucket[$cache_key] = $this->wpdb()->get_var( |
| 22 | $this->wpdb()->prepare( |
| 23 | "SELECT COUNT(id) FROM {$this->db_table} WHERE status = %s AND $where_clause", OrderStatus::REFUNDED |
| 24 | ) |
| 25 | ); |
| 26 | } |
| 27 | |
| 28 | return ! $bucket[$cache_key] ? 0 : $bucket[$cache_key]; |
| 29 | } |
| 30 | |
| 31 | public function get_data() |
| 32 | { |
| 33 | $refunds = $this->wpdb()->get_results( |
| 34 | $this->wpdb()->prepare( |
| 35 | "SELECT COUNT(id) AS order_total, {$this->get_date_column()} FROM {$this->db_table} WHERE status = %s AND {$this->get_where_clause($groupBy=true)}", |
| 36 | OrderStatus::REFUNDED |
| 37 | ), |
| 38 | 'ARRAY_A' |
| 39 | ); |
| 40 | |
| 41 | $dataset = []; |
| 42 | |
| 43 | foreach ($this->get_labels() as $datetime => $label) { |
| 44 | |
| 45 | $data = $this->get_interval_data($refunds, $datetime); |
| 46 | |
| 47 | $dataset[] = ! empty($data) ? reset($data)['order_total'] : 0; |
| 48 | } |
| 49 | |
| 50 | return [ |
| 51 | [ |
| 52 | 'data' => $dataset, |
| 53 | 'borderColor' => 'rgb(54, 162, 235)', |
| 54 | 'backgroundColor' => 'rgba(54, 162, 235, 0.5)', |
| 55 | 'fill' => true |
| 56 | ] |
| 57 | ]; |
| 58 | } |
| 59 | } |