diff --git a/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/DataStore.php index a42af30eb95..7b2740eaa3f 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/DataStore.php @@ -70,7 +70,7 @@ class DataStore extends ReportsDataStore implements DataStoreInterface { $this->report_columns = array( '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", - '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_count' => 'coupons_count', 'refunds' => "ABS( SUM( CASE WHEN {$table_name}.gross_total < 0 THEN {$table_name}.gross_total END ) ) AS refunds", diff --git a/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-orders-stats.php b/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-orders-stats.php index ac0bd9dec49..36202e117bc 100644 --- a/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-orders-stats.php +++ b/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-orders-stats.php @@ -66,7 +66,7 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'num_items_sold' => 4, 'avg_items_per_order' => 4, 'avg_order_value' => 68, - 'gross_revenue' => 85, + 'gross_revenue' => 97, 'coupons' => 20, 'coupons_count' => 1, 'refunds' => 12, @@ -86,7 +86,7 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'date_end' => $end_time, 'date_end_gmt' => $end_time, 'subtotals' => array( - 'gross_revenue' => 85, + 'gross_revenue' => 97, 'net_revenue' => 68, 'coupons' => 20, 'coupons_count' => 1, @@ -210,7 +210,7 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'num_items_sold' => 8, 'avg_items_per_order' => 4, 'avg_order_value' => 50, - 'gross_revenue' => 100, + 'gross_revenue' => 150, 'coupons' => 0, 'coupons_count' => 0, 'refunds' => 50, @@ -230,7 +230,7 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'date_end' => $end_time, 'date_end_gmt' => $end_time, 'subtotals' => array( - 'gross_revenue' => 100, + 'gross_revenue' => 150, 'net_revenue' => 100, 'coupons' => 0, 'coupons_count' => 0, @@ -376,13 +376,13 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'num_items_sold' => 0, 'avg_items_per_order' => 0, 'avg_order_value' => 0, - 'gross_revenue' => -60, + 'gross_revenue' => 0, // @todo - does this value make sense? 'coupons' => 0, 'coupons_count' => 0, 'refunds' => 60, 'taxes' => 0, 'shipping' => 0, - 'net_revenue' => -60, + 'net_revenue' => -60, // @todo - does this value make sense? 'num_returning_customers' => 1, 'num_new_customers' => 0, 'products' => 0, @@ -396,8 +396,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'date_end' => $end_time, 'date_end_gmt' => $end_time, 'subtotals' => array( - 'gross_revenue' => -60, - 'net_revenue' => -60, + 'gross_revenue' => 0, // @todo - does this value make sense? + 'net_revenue' => -60, // @todo - does this value make sense? 'coupons' => 0, 'coupons_count' => 0, 'shipping' => 0, @@ -490,13 +490,13 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'num_items_sold' => 0, 'avg_items_per_order' => 0, 'avg_order_value' => 0, - 'gross_revenue' => -10, + 'gross_revenue' => 0, // @todo - does this value make sense? 'coupons' => 0, 'coupons_count' => 0, 'refunds' => 10, 'taxes' => 0, 'shipping' => 0, - 'net_revenue' => -10, + 'net_revenue' => -10, // @todo - does this value make sense? 'num_returning_customers' => 1, 'num_new_customers' => 0, 'products' => 0, @@ -510,8 +510,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'date_end' => $end_time, 'date_end_gmt' => $end_time, 'subtotals' => array( - 'gross_revenue' => -10, - 'net_revenue' => -10, + 'gross_revenue' => 0, // @todo - does this value make sense? + 'net_revenue' => -10, // @todo - does this value make sense? 'coupons' => 0, 'coupons_count' => 0, 'shipping' => 0, @@ -547,13 +547,13 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'num_items_sold' => 0, 'avg_items_per_order' => 0, 'avg_order_value' => 0, - 'gross_revenue' => -50, + 'gross_revenue' => 0, // @todo - does this value make sense? 'coupons' => 0, 'coupons_count' => 0, 'refunds' => 50, 'taxes' => 0, 'shipping' => 0, - 'net_revenue' => -50, + 'net_revenue' => -50, // @todo - does this value make sense? 'num_returning_customers' => 1, 'num_new_customers' => 0, 'products' => 0, @@ -567,8 +567,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'date_end' => $end_time, 'date_end_gmt' => $end_time, 'subtotals' => array( - 'gross_revenue' => -50, - 'net_revenue' => -50, + 'gross_revenue' => 0, // @todo - does this value make sense? + 'net_revenue' => -50, // @todo - does this value make sense? 'coupons' => 0, 'coupons_count' => 0, 'shipping' => 0,