Reports fixes
This commit is contained in:
parent
dcf39fc8cd
commit
f2ea71ea6f
|
@ -285,7 +285,7 @@ class WC_Report_Sales_By_Date extends WC_Admin_Report {
|
||||||
),
|
),
|
||||||
'_qty' => array(
|
'_qty' => array(
|
||||||
'type' => 'order_item_meta',
|
'type' => 'order_item_meta',
|
||||||
'function' => '',
|
'function' => 'SUM',
|
||||||
'name' => 'order_item_count',
|
'name' => 'order_item_count',
|
||||||
'join_type' => 'LEFT',
|
'join_type' => 'LEFT',
|
||||||
),
|
),
|
||||||
|
@ -295,7 +295,7 @@ class WC_Report_Sales_By_Date extends WC_Admin_Report {
|
||||||
'query_type' => 'get_results',
|
'query_type' => 'get_results',
|
||||||
'filter_range' => true,
|
'filter_range' => true,
|
||||||
'order_status' => false,
|
'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_refunded = 0;
|
||||||
$this->report_data->total_shipping_tax_refunded = 0;
|
$this->report_data->total_shipping_tax_refunded = 0;
|
||||||
$this->report_data->total_refunds = 0;
|
$this->report_data->total_refunds = 0;
|
||||||
$this->report_data->refunded_order_items = 0;
|
|
||||||
|
|
||||||
foreach ( $this->report_data->partial_refunds as $key => $value ) {
|
$refunded_orders = array_merge( $this->report_data->partial_refunds, $this->report_data->full_refunds );
|
||||||
if ( is_null( $value->item_type ) ) {
|
|
||||||
// Null when the order was refunded, but not the line items themselves.
|
foreach ( $refunded_orders as $key => $value ) {
|
||||||
$this->report_data->total_tax_refunded += ( $value->total_tax * -1 );
|
$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;
|
|
||||||
} 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;
|
$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 = 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 );
|
$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->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
|
// 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_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 );
|
$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
|
// 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_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_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
|
// 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;
|
$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;
|
||||||
|
|
Loading…
Reference in New Issue