From 5cae61cb696d334e7d1ca5e2208af99276e9a0c9 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Mon, 8 Feb 2016 11:28:37 +0000 Subject: [PATCH] Show net sales on dashboard Closes #9948 --- includes/admin/class-wc-admin-dashboard.php | 24 +++++++------------ .../admin/reports/class-wc-admin-report.php | 2 +- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/includes/admin/class-wc-admin-dashboard.php b/includes/admin/class-wc-admin-dashboard.php index b8162afa28b..09b26130f4f 100644 --- a/includes/admin/class-wc-admin-dashboard.php +++ b/includes/admin/class-wc-admin-dashboard.php @@ -47,21 +47,15 @@ class WC_Admin_Dashboard { global $wpdb; include_once( 'reports/class-wc-admin-report.php' ); + include_once( 'reports/class-wc-report-sales-by-date.php' ); - $reports = new WC_Admin_Report(); - - // Sales - $query = array(); - $query['fields'] = "SELECT SUM( postmeta.meta_value ) FROM {$wpdb->posts} as posts"; - $query['join'] = "INNER JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id LEFT JOIN {$wpdb->posts} AS parent ON posts.post_parent = parent.ID"; - $query['where'] = "WHERE posts.post_type IN ( '" . implode( "','", array_merge( wc_get_order_types( 'sales-reports' ), array( 'shop_order_refund' ) ) ) . "' ) "; - $query['where'] .= "AND posts.post_status IN ( 'wc-" . implode( "','wc-", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "' ) "; - $query['where'] .= "AND ( parent.post_status IN ( 'wc-" . implode( "','wc-", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "' ) OR parent.ID IS NULL ) "; - $query['where'] .= "AND postmeta.meta_key = '_order_total' "; - $query['where'] .= "AND posts.post_date >= '" . date( 'Y-m-01', current_time( 'timestamp' ) ) . "' "; - $query['where'] .= "AND posts.post_date <= '" . date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ) . "' "; - - $sales = $wpdb->get_var( implode( ' ', apply_filters( 'woocommerce_dashboard_status_widget_sales_query', $query ) ) ); + $reports = new WC_Admin_Report(); + $sales_by_date = new WC_Report_Sales_By_Date(); + $sales_by_date->start_date = strtotime( date( 'Y-m-01', current_time( 'timestamp' ) ) ); + $sales_by_date->end_date = current_time( 'timestamp' ); + $sales_by_date->chart_groupby = 'day'; + $sales_by_date->group_by_query = 'YEAR(posts.post_date), MONTH(posts.post_date), DAY(posts.post_date)'; + $report_data = $sales_by_date->get_report_data(); // Get top seller $query = array(); @@ -132,7 +126,7 @@ class WC_Admin_Dashboard {
  • sales_sparkline( '', max( 7, date( 'd', current_time( 'timestamp' ) ) ) ); ?> - %s sales this month", 'woocommerce' ), wc_price( $sales ) ); ?> + %s net sales this month", 'woocommerce' ), wc_price( $report_data->net_sales ) ); ?>
  • qty ) : ?> diff --git a/includes/admin/reports/class-wc-admin-report.php b/includes/admin/reports/class-wc-admin-report.php index 177a295312d..3fc50b90b43 100644 --- a/includes/admin/reports/class-wc-admin-report.php +++ b/includes/admin/reports/class-wc-admin-report.php @@ -505,7 +505,7 @@ class WC_Admin_Report { $this->end_date = strtotime( 'midnight', strtotime( sanitize_text_field( $_GET['end_date'] ) ) ); if ( ! $this->end_date ) { - $this->end_date = current_time('timestamp'); + $this->end_date = current_time( 'timestamp' ); } $interval = 0;