Merge pull request #13779 from woocommerce/fix-13777

Net sales fix
This commit is contained in:
Mike Jolley 2017-03-27 18:19:45 +01:00 committed by GitHub
commit 13903220f7
2 changed files with 7 additions and 5 deletions

View File

@ -514,10 +514,11 @@ class WC_Admin_Report {
case 'custom' :
$this->start_date = strtotime( sanitize_text_field( $_GET['start_date'] ) );
$this->end_date = strtotime( 'midnight', strtotime( sanitize_text_field( $_GET['end_date'] ) ) );
if ( ! $this->end_date ) {
$this->end_date = current_time( 'timestamp' );
if ( empty( $_GET['end_date'] ) ) {
$this->end_date = strtotime( 'midnight', current_time( 'timestamp' ) );
} else {
$this->end_date = strtotime( 'midnight', strtotime( sanitize_text_field( $_GET['end_date'] ) ) );
}
$interval = 0;

View File

@ -325,9 +325,10 @@ class WC_Report_Sales_By_Date extends WC_Admin_Report {
$this->report_data->total_shipping = wc_format_decimal( array_sum( wp_list_pluck( $this->report_data->orders, 'total_shipping' ) ) - $this->report_data->total_shipping_refunded, 2 );
$this->report_data->total_shipping_tax = wc_format_decimal( array_sum( wp_list_pluck( $this->report_data->orders, 'total_shipping_tax' ) ) - $this->report_data->total_shipping_tax_refunded, 2 );
// Total the refunds and sales amounts. Sales subract refunds. Note - sales also includes shipping costs.
// Total the refunds and sales amounts. Sales subract refunds. Note - total_sales also includes shipping costs.
$this->report_data->total_sales = wc_format_decimal( array_sum( wp_list_pluck( $this->report_data->orders, 'total_sales' ) ) - $this->report_data->total_refunds, 2 );
$this->report_data->net_sales = wc_format_decimal( $this->report_data->total_sales - $this->report_data->total_tax - $this->report_data->total_shipping_tax, 2 );
$this->report_data->net_sales = wc_format_decimal( $this->report_data->total_sales - $this->report_data->total_shipping - $this->report_data->total_tax - $this->report_data->total_shipping_tax, 2 );
// Calculate average based on net
$this->report_data->average_sales = wc_format_decimal( $this->report_data->net_sales / ( $this->chart_interval + 1 ), 2 );
$this->report_data->average_total_sales = wc_format_decimal( $this->report_data->total_sales / ( $this->chart_interval + 1 ), 2 );