AbstractReport.php
4 years ago
Orders.php
4 years ago
PaymentMethods.php
4 years ago
Refunds.php
4 years ago
ReportFilterData.php
4 years ago
ReportInterval.php
4 years ago
Revenue.php
4 years ago
SettingsPage.php
4 years ago
Taxes.php
4 years ago
TopPlans.php
4 years ago
index.php
4 years ago
Orders.php
77 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ProfilePress\Core\Admin\SettingsPages\Membership\DashboardPage; |
| 4 | |
| 5 | use ProfilePress\Core\Membership\Models\Order\OrderStatus; |
| 6 | use ProfilePress\Core\Membership\Models\Order\OrderType; |
| 7 | |
| 8 | class Orders extends AbstractReport |
| 9 | { |
| 10 | public function get_total($start_date = '', $end_date = '') |
| 11 | { |
| 12 | static $bucket = []; |
| 13 | |
| 14 | $cache_key = md5('orders_get_total' . $start_date . $end_date); |
| 15 | |
| 16 | if ( ! isset($bucket[$cache_key])) { |
| 17 | $start_date = ! empty($start_date) ? $start_date : ''; |
| 18 | $end_date = ! empty($end_date) ? $end_date : ''; |
| 19 | |
| 20 | $where_clause = $this->get_where_clause(false, $start_date, $end_date); |
| 21 | |
| 22 | $bucket[$cache_key] = $this->wpdb()->get_var( |
| 23 | $this->wpdb()->prepare( |
| 24 | "SELECT COUNT(id) FROM {$this->db_table} WHERE status = %s AND $where_clause", OrderStatus::COMPLETED |
| 25 | ) |
| 26 | ); |
| 27 | } |
| 28 | |
| 29 | return ! $bucket[$cache_key] ? 0 : $bucket[$cache_key]; |
| 30 | } |
| 31 | |
| 32 | public function get_data() |
| 33 | { |
| 34 | $new_orders = $this->wpdb()->get_results( |
| 35 | $this->wpdb()->prepare( |
| 36 | "SELECT COUNT(id) AS order_total, {$this->get_date_column()} FROM {$this->db_table} WHERE status = %s AND order_type = %s AND {$this->get_where_clause($groupBy=true)}", |
| 37 | OrderStatus::COMPLETED, OrderType::NEW_ORDER |
| 38 | ), |
| 39 | 'ARRAY_A' |
| 40 | ); |
| 41 | |
| 42 | $renewal_orders = $this->wpdb()->get_results( |
| 43 | $this->wpdb()->prepare( |
| 44 | "SELECT COUNT(id) AS order_total, {$this->get_date_column()} FROM {$this->db_table} WHERE status = %s AND order_type = %s AND {$this->get_where_clause($groupBy=true)}", |
| 45 | OrderStatus::COMPLETED, OrderType::RENEWAL_ORDER |
| 46 | ), |
| 47 | 'ARRAY_A' |
| 48 | ); |
| 49 | |
| 50 | $no_dataset = []; |
| 51 | $ro_dataset = []; |
| 52 | |
| 53 | foreach ($this->get_labels() as $datetime => $label) { |
| 54 | |
| 55 | $no_data = $this->get_interval_data($new_orders, $datetime); |
| 56 | $ro_data = $this->get_interval_data($renewal_orders, $datetime); |
| 57 | |
| 58 | $no_dataset[] = ! empty($no_data) ? reset($no_data)['order_total'] : 0; |
| 59 | $ro_dataset[] = ! empty($ro_data) ? reset($ro_data)['order_total'] : 0; |
| 60 | } |
| 61 | |
| 62 | return [ |
| 63 | [ |
| 64 | 'label' => esc_html__('New', 'wp-user-avatar'), |
| 65 | 'data' => $no_dataset, |
| 66 | 'borderColor' => 'rgb(54, 162, 235)', |
| 67 | 'backgroundColor' => 'rgba(54, 162, 235, 0.5)' |
| 68 | ], |
| 69 | [ |
| 70 | 'label' => esc_html__('Renewal', 'wp-user-avatar'), |
| 71 | 'data' => $ro_dataset, |
| 72 | 'borderColor' => 'rgb(255, 99, 132)', |
| 73 | 'backgroundColor' => 'rgba(255, 99, 132, 0.5)' |
| 74 | ] |
| 75 | ]; |
| 76 | } |
| 77 | } |