Ignore refunded amounts when calculating gross total.

This commit is contained in:
Jeff Stieler 2019-08-20 11:41:28 -07:00
parent dd9948aa1a
commit bfefb2d647
2 changed files with 17 additions and 17 deletions

View File

@ -70,7 +70,7 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
$this->report_columns = array( $this->report_columns = array(
'orders_count' => "SUM( CASE WHEN {$table_name}.parent_id = 0 THEN 1 ELSE 0 END ) as orders_count", 'orders_count' => "SUM( CASE WHEN {$table_name}.parent_id = 0 THEN 1 ELSE 0 END ) as orders_count",
'num_items_sold' => "SUM({$table_name}.num_items_sold) as num_items_sold", 'num_items_sold' => "SUM({$table_name}.num_items_sold) as num_items_sold",
'gross_revenue' => "SUM({$table_name}.gross_total) AS gross_revenue", 'gross_revenue' => "SUM( CASE WHEN {$table_name}.gross_total > 0 THEN {$table_name}.gross_total END ) AS gross_revenue",
'coupons' => 'SUM(discount_amount) AS coupons', 'coupons' => 'SUM(discount_amount) AS coupons',
'coupons_count' => 'coupons_count', 'coupons_count' => 'coupons_count',
'refunds' => "ABS( SUM( CASE WHEN {$table_name}.gross_total < 0 THEN {$table_name}.gross_total END ) ) AS refunds", 'refunds' => "ABS( SUM( CASE WHEN {$table_name}.gross_total < 0 THEN {$table_name}.gross_total END ) ) AS refunds",

View File

@ -66,7 +66,7 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case {
'num_items_sold' => 4, 'num_items_sold' => 4,
'avg_items_per_order' => 4, 'avg_items_per_order' => 4,
'avg_order_value' => 68, 'avg_order_value' => 68,
'gross_revenue' => 85, 'gross_revenue' => 97,
'coupons' => 20, 'coupons' => 20,
'coupons_count' => 1, 'coupons_count' => 1,
'refunds' => 12, 'refunds' => 12,
@ -86,7 +86,7 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case {
'date_end' => $end_time, 'date_end' => $end_time,
'date_end_gmt' => $end_time, 'date_end_gmt' => $end_time,
'subtotals' => array( 'subtotals' => array(
'gross_revenue' => 85, 'gross_revenue' => 97,
'net_revenue' => 68, 'net_revenue' => 68,
'coupons' => 20, 'coupons' => 20,
'coupons_count' => 1, 'coupons_count' => 1,
@ -210,7 +210,7 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case {
'num_items_sold' => 8, 'num_items_sold' => 8,
'avg_items_per_order' => 4, 'avg_items_per_order' => 4,
'avg_order_value' => 50, 'avg_order_value' => 50,
'gross_revenue' => 100, 'gross_revenue' => 150,
'coupons' => 0, 'coupons' => 0,
'coupons_count' => 0, 'coupons_count' => 0,
'refunds' => 50, 'refunds' => 50,
@ -230,7 +230,7 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case {
'date_end' => $end_time, 'date_end' => $end_time,
'date_end_gmt' => $end_time, 'date_end_gmt' => $end_time,
'subtotals' => array( 'subtotals' => array(
'gross_revenue' => 100, 'gross_revenue' => 150,
'net_revenue' => 100, 'net_revenue' => 100,
'coupons' => 0, 'coupons' => 0,
'coupons_count' => 0, 'coupons_count' => 0,
@ -376,13 +376,13 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case {
'num_items_sold' => 0, 'num_items_sold' => 0,
'avg_items_per_order' => 0, 'avg_items_per_order' => 0,
'avg_order_value' => 0, 'avg_order_value' => 0,
'gross_revenue' => -60, 'gross_revenue' => 0, // @todo - does this value make sense?
'coupons' => 0, 'coupons' => 0,
'coupons_count' => 0, 'coupons_count' => 0,
'refunds' => 60, 'refunds' => 60,
'taxes' => 0, 'taxes' => 0,
'shipping' => 0, 'shipping' => 0,
'net_revenue' => -60, 'net_revenue' => -60, // @todo - does this value make sense?
'num_returning_customers' => 1, 'num_returning_customers' => 1,
'num_new_customers' => 0, 'num_new_customers' => 0,
'products' => 0, 'products' => 0,
@ -396,8 +396,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case {
'date_end' => $end_time, 'date_end' => $end_time,
'date_end_gmt' => $end_time, 'date_end_gmt' => $end_time,
'subtotals' => array( 'subtotals' => array(
'gross_revenue' => -60, 'gross_revenue' => 0, // @todo - does this value make sense?
'net_revenue' => -60, 'net_revenue' => -60, // @todo - does this value make sense?
'coupons' => 0, 'coupons' => 0,
'coupons_count' => 0, 'coupons_count' => 0,
'shipping' => 0, 'shipping' => 0,
@ -490,13 +490,13 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case {
'num_items_sold' => 0, 'num_items_sold' => 0,
'avg_items_per_order' => 0, 'avg_items_per_order' => 0,
'avg_order_value' => 0, 'avg_order_value' => 0,
'gross_revenue' => -10, 'gross_revenue' => 0, // @todo - does this value make sense?
'coupons' => 0, 'coupons' => 0,
'coupons_count' => 0, 'coupons_count' => 0,
'refunds' => 10, 'refunds' => 10,
'taxes' => 0, 'taxes' => 0,
'shipping' => 0, 'shipping' => 0,
'net_revenue' => -10, 'net_revenue' => -10, // @todo - does this value make sense?
'num_returning_customers' => 1, 'num_returning_customers' => 1,
'num_new_customers' => 0, 'num_new_customers' => 0,
'products' => 0, 'products' => 0,
@ -510,8 +510,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case {
'date_end' => $end_time, 'date_end' => $end_time,
'date_end_gmt' => $end_time, 'date_end_gmt' => $end_time,
'subtotals' => array( 'subtotals' => array(
'gross_revenue' => -10, 'gross_revenue' => 0, // @todo - does this value make sense?
'net_revenue' => -10, 'net_revenue' => -10, // @todo - does this value make sense?
'coupons' => 0, 'coupons' => 0,
'coupons_count' => 0, 'coupons_count' => 0,
'shipping' => 0, 'shipping' => 0,
@ -547,13 +547,13 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case {
'num_items_sold' => 0, 'num_items_sold' => 0,
'avg_items_per_order' => 0, 'avg_items_per_order' => 0,
'avg_order_value' => 0, 'avg_order_value' => 0,
'gross_revenue' => -50, 'gross_revenue' => 0, // @todo - does this value make sense?
'coupons' => 0, 'coupons' => 0,
'coupons_count' => 0, 'coupons_count' => 0,
'refunds' => 50, 'refunds' => 50,
'taxes' => 0, 'taxes' => 0,
'shipping' => 0, 'shipping' => 0,
'net_revenue' => -50, 'net_revenue' => -50, // @todo - does this value make sense?
'num_returning_customers' => 1, 'num_returning_customers' => 1,
'num_new_customers' => 0, 'num_new_customers' => 0,
'products' => 0, 'products' => 0,
@ -567,8 +567,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case {
'date_end' => $end_time, 'date_end' => $end_time,
'date_end_gmt' => $end_time, 'date_end_gmt' => $end_time,
'subtotals' => array( 'subtotals' => array(
'gross_revenue' => -50, 'gross_revenue' => 0, // @todo - does this value make sense?
'net_revenue' => -50, 'net_revenue' => -50, // @todo - does this value make sense?
'coupons' => 0, 'coupons' => 0,
'coupons_count' => 0, 'coupons_count' => 0,
'shipping' => 0, 'shipping' => 0,