Reports fixes

This commit is contained in:
Mike Jolley 2016-11-23 15:36:52 +00:00
parent dcf39fc8cd
commit f2ea71ea6f
1 changed files with 16 additions and 20 deletions

View File

@ -285,7 +285,7 @@ class WC_Report_Sales_By_Date extends WC_Admin_Report {
),
'_qty' => array(
'type' => 'order_item_meta',
'function' => '',
'function' => 'SUM',
'name' => 'order_item_count',
'join_type' => 'LEFT',
),
@ -295,7 +295,7 @@ class WC_Report_Sales_By_Date extends WC_Admin_Report {
'query_type' => 'get_results',
'filter_range' => true,
'order_status' => false,
'parent_order_status' => array( 'completed', 'processing', 'on-hold', 'refunded' ),
'parent_order_status' => array( 'completed', 'processing', 'on-hold' ),
) );
/**
@ -305,21 +305,18 @@ class WC_Report_Sales_By_Date extends WC_Admin_Report {
$this->report_data->total_shipping_refunded = 0;
$this->report_data->total_shipping_tax_refunded = 0;
$this->report_data->total_refunds = 0;
$this->report_data->refunded_order_items = 0;
foreach ( $this->report_data->partial_refunds as $key => $value ) {
if ( is_null( $value->item_type ) ) {
// Null when the order was refunded, but not the line items themselves.
$this->report_data->total_tax_refunded += ( $value->total_tax * -1 );
$this->report_data->total_refunds += $value->total_refund;
} elseif ( 'shipping' === $value->item_type ) {
$this->report_data->total_shipping_tax_refunded += ( $value->total_shipping_tax * -1 );
$this->report_data->total_shipping_refunded += wc_format_decimal( $value->total_refund, 2 );
$this->report_data->total_refunds += $value->total_refund;
} elseif ( 'line_item' === $value->item_type ) {
$this->report_data->total_tax_refunded += ( $value->total_tax * -1 );
$this->report_data->refunded_order_items += absint( $value->order_item_count );
$this->report_data->total_refunds += $value->total_refund;
$refunded_orders = array_merge( $this->report_data->partial_refunds, $this->report_data->full_refunds );
foreach ( $refunded_orders as $key => $value ) {
$this->report_data->total_tax_refunded += ( $value->total_tax < 0 ? $value->total_tax * -1 : $value->total_tax );
$this->report_data->total_refunds += $value->total_refund;
$this->report_data->total_shipping_tax_refunded += ( $value->total_shipping_tax < 0 ? $value->total_shipping_tax * -1 : $value->total_shipping_tax );
$this->report_data->total_shipping_refunded += ( $value->total_shipping < 0 ? $value->total_shipping * -1 : $value->total_shipping );
// Only applies to parial.
if ( isset( $value->order_item_count ) ) {
$this->report_data->refunded_order_items += ( $value->order_item_count < 0 ? $value->order_item_count * -1 : $value->order_item_count );
}
}
@ -328,18 +325,17 @@ 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.
// Total the refunds and sales amounts. Sales subract refunds. Note - 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_shipping - $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_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 );
// Total orders and discounts also includes those which have been refunded at some point
$this->report_data->total_orders = absint( array_sum( wp_list_pluck( $this->report_data->order_counts, 'count' ) ) );
$this->report_data->total_coupons = number_format( array_sum( wp_list_pluck( $this->report_data->coupons, 'discount_amount' ) ), 2, '.', '' );
$this->report_data->total_refunded_orders = absint( count( $this->report_data->full_refunds ) );
$this->report_data->total_orders = absint( array_sum( wp_list_pluck( $this->report_data->order_counts, 'count' ) ) ) - $this->report_data->total_refunded_orders;
// Item counts
$this->report_data->total_items = absint( array_sum( wp_list_pluck( $this->report_data->order_items, 'order_item_count' ) ) ) - $this->report_data->refunded_order_items;