[2.5] Report on partial refunds/refunds items rather than full refunds to ensure they are reported when refunded

@claudiosmweb your testing + approval welcome.

Closes #10138
This commit is contained in:
Mike Jolley 2016-01-22 15:50:23 +00:00
parent a26af7b801
commit 6cc700a497
1 changed files with 33 additions and 32 deletions

View File

@ -268,17 +268,20 @@ class WC_Report_Sales_By_Date extends WC_Admin_Report {
'_order_shipping' => array( '_order_shipping' => array(
'type' => 'meta', 'type' => 'meta',
'function' => '', 'function' => '',
'name' => 'total_shipping' 'name' => 'total_shipping',
'join_type' => 'LEFT'
), ),
'_order_tax' => array( '_order_tax' => array(
'type' => 'meta', 'type' => 'meta',
'function' => '', 'function' => '',
'name' => 'total_tax' 'name' => 'total_tax',
'join_type' => 'LEFT'
), ),
'_order_shipping_tax' => array( '_order_shipping_tax' => array(
'type' => 'meta', 'type' => 'meta',
'function' => '', 'function' => '',
'name' => 'total_shipping_tax' 'name' => 'total_shipping_tax',
'join_type' => 'LEFT'
), ),
'_qty' => array( '_qty' => array(
'type' => 'order_item_meta', 'type' => 'order_item_meta',
@ -292,34 +295,32 @@ 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' ), 'parent_order_status' => array( 'completed', 'processing', 'on-hold', 'refunded' ),
) ); ) );
/** /**
* Total up values by combining full refunds and partial refunds for line items. * Total up refunds. Note: when an order is fully refunded, a refund line will be added.
*/ */
$this->report_data->total_tax_refunded = wc_format_decimal( array_sum( wp_list_pluck( $this->report_data->full_refunds, 'total_tax' ) ), 2 ); $this->report_data->total_tax_refunded = 0;
$this->report_data->total_shipping_refunded = wc_format_decimal( array_sum( wp_list_pluck( $this->report_data->full_refunds, 'total_shipping' ) ), 2 ); $this->report_data->total_shipping_refunded = 0;
$this->report_data->total_shipping_tax_refunded = wc_format_decimal( array_sum( wp_list_pluck( $this->report_data->full_refunds, 'total_shipping_tax' ) ), 2 ); $this->report_data->total_shipping_tax_refunded = 0;
$this->report_data->total_refunds = wc_format_decimal( array_sum( wp_list_pluck( $this->report_data->full_refunds, 'total_refund' ) ), 2 ); $this->report_data->total_refunds = 0;
/**
* Loop over partial refunds and increase the above values.
*/
foreach ( $this->report_data->partial_refunds as $key => $value ) { foreach ( $this->report_data->partial_refunds as $key => $value ) {
switch ( $value->item_type ) { if ( is_null( $value->item_type ) ) {
case 'shipping' : // 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_tax_refunded += ( $value->total_shipping_tax * -1 );
$this->report_data->total_shipping_refunded += wc_format_decimal( $value->total_refund, 2 ); $this->report_data->total_shipping_refunded += wc_format_decimal( $value->total_refund, 2 );
$this->report_data->total_refunds += $value->total_refund; $this->report_data->total_refunds += $value->total_refund;
}
elseif( 'line_item' === $value->item_type ) {
break;
case 'line_item' :
$this->report_data->total_tax_refunded += ( $value->total_tax * -1 ); $this->report_data->total_tax_refunded += ( $value->total_tax * -1 );
$this->report_data->refunded_order_items += absint( $value->order_item_count ); $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;
break;
} }
} }
@ -504,7 +505,7 @@ class WC_Report_Sales_By_Date extends WC_Admin_Report {
$order_amounts = $this->prepare_chart_data( $this->report_data->orders, 'post_date', 'total_sales', $this->chart_interval, $this->start_date, $this->chart_groupby ); $order_amounts = $this->prepare_chart_data( $this->report_data->orders, 'post_date', 'total_sales', $this->chart_interval, $this->start_date, $this->chart_groupby );
$coupon_amounts = $this->prepare_chart_data( $this->report_data->coupons, 'post_date', 'discount_amount', $this->chart_interval, $this->start_date, $this->chart_groupby ); $coupon_amounts = $this->prepare_chart_data( $this->report_data->coupons, 'post_date', 'discount_amount', $this->chart_interval, $this->start_date, $this->chart_groupby );
$shipping_amounts = $this->prepare_chart_data( $this->report_data->orders, 'post_date', 'total_shipping', $this->chart_interval, $this->start_date, $this->chart_groupby ); $shipping_amounts = $this->prepare_chart_data( $this->report_data->orders, 'post_date', 'total_shipping', $this->chart_interval, $this->start_date, $this->chart_groupby );
$refund_amounts = $this->prepare_chart_data( array_merge( $this->report_data->partial_refunds, $this->report_data->full_refunds ), 'post_date', 'total_refund', $this->chart_interval, $this->start_date, $this->chart_groupby ); $refund_amounts = $this->prepare_chart_data( $this->report_data->partial_refunds, 'post_date', 'total_refund', $this->chart_interval, $this->start_date, $this->chart_groupby );
$shipping_tax_amounts = $this->prepare_chart_data( $this->report_data->orders, 'post_date', 'total_shipping_tax', $this->chart_interval, $this->start_date, $this->chart_groupby ); $shipping_tax_amounts = $this->prepare_chart_data( $this->report_data->orders, 'post_date', 'total_shipping_tax', $this->chart_interval, $this->start_date, $this->chart_groupby );
$tax_amounts = $this->prepare_chart_data( $this->report_data->orders, 'post_date', 'total_tax', $this->chart_interval, $this->start_date, $this->chart_groupby ); $tax_amounts = $this->prepare_chart_data( $this->report_data->orders, 'post_date', 'total_tax', $this->chart_interval, $this->start_date, $this->chart_groupby );