@@ -769,11 +769,12 @@ public function addOrdersCount()
769
769
*/
770
770
public function addRevenueToSelect ($ convertCurrency = false )
771
771
{
772
- $ expr = $ this ->getTotalsExpression (
772
+ $ expr = $ this ->getTotalsExpressionWithDiscountRefunded (
773
773
!$ convertCurrency ,
774
774
$ this ->getConnection ()->getIfNullSql ('main_table.base_subtotal_refunded ' , 0 ),
775
775
$ this ->getConnection ()->getIfNullSql ('main_table.base_subtotal_canceled ' , 0 ),
776
- $ this ->getConnection ()->getIfNullSql ('main_table.base_discount_canceled ' , 0 )
776
+ $ this ->getConnection ()->getIfNullSql ('ABS(main_table.base_discount_refunded) ' , 0 ),
777
+ $ this ->getConnection ()->getIfNullSql ('ABS(main_table.base_discount_canceled) ' , 0 )
777
778
);
778
779
$ this ->getSelect ()->columns (['revenue ' => $ expr ]);
779
780
@@ -791,11 +792,12 @@ public function addSumAvgTotals($storeId = 0)
791
792
/**
792
793
* calculate average and total amount
793
794
*/
794
- $ expr = $ this ->getTotalsExpression (
795
+ $ expr = $ this ->getTotalsExpressionWithDiscountRefunded (
795
796
$ storeId ,
796
797
$ this ->getConnection ()->getIfNullSql ('main_table.base_subtotal_refunded ' , 0 ),
797
798
$ this ->getConnection ()->getIfNullSql ('main_table.base_subtotal_canceled ' , 0 ),
798
- $ this ->getConnection ()->getIfNullSql ('main_table.base_discount_canceled ' , 0 )
799
+ $ this ->getConnection ()->getIfNullSql ('ABS(main_table.base_discount_refunded) ' , 0 ),
800
+ $ this ->getConnection ()->getIfNullSql ('ABS(main_table.base_discount_canceled) ' , 0 )
799
801
);
800
802
801
803
$ this ->getSelect ()->columns (
@@ -808,13 +810,15 @@ public function addSumAvgTotals($storeId = 0)
808
810
}
809
811
810
812
/**
811
- * Get SQL expression for totals
813
+ * Get SQL expression for totals.
812
814
*
813
815
* @param int $storeId
814
816
* @param string $baseSubtotalRefunded
815
817
* @param string $baseSubtotalCanceled
816
818
* @param string $baseDiscountCanceled
817
819
* @return string
820
+ * @deprecated
821
+ * @see getTotalsExpressionWithDiscountRefunded
818
822
*/
819
823
protected function getTotalsExpression (
820
824
$ storeId ,
@@ -825,10 +829,40 @@ protected function getTotalsExpression(
825
829
$ template = ($ storeId != 0 )
826
830
? '(main_table.base_subtotal - %2$s - %1$s - ABS(main_table.base_discount_amount) - %3$s) '
827
831
: '((main_table.base_subtotal - %1$s - %2$s - ABS(main_table.base_discount_amount) + %3$s) '
828
- . ' * main_table.base_to_global_rate) ' ;
832
+ . ' * main_table.base_to_global_rate) ' ;
829
833
return sprintf ($ template , $ baseSubtotalRefunded , $ baseSubtotalCanceled , $ baseDiscountCanceled );
830
834
}
831
835
836
+ /**
837
+ * Get SQL expression for totals with discount refunded.
838
+ *
839
+ * @param int $storeId
840
+ * @param string $baseSubtotalRefunded
841
+ * @param string $baseSubtotalCanceled
842
+ * @param string $baseDiscountRefunded
843
+ * @param string $baseDiscountCanceled
844
+ * @return string
845
+ */
846
+ private function getTotalsExpressionWithDiscountRefunded (
847
+ $ storeId ,
848
+ $ baseSubtotalRefunded ,
849
+ $ baseSubtotalCanceled ,
850
+ $ baseDiscountRefunded ,
851
+ $ baseDiscountCanceled
852
+ ) {
853
+ $ template = ($ storeId != 0 )
854
+ ? '(main_table.base_subtotal - %2$s - %1$s - (ABS(main_table.base_discount_amount) - %3$s - %4$s)) '
855
+ : '((main_table.base_subtotal - %1$s - %2$s - (ABS(main_table.base_discount_amount) - %3$s - %4$s)) '
856
+ . ' * main_table.base_to_global_rate) ' ;
857
+ return sprintf (
858
+ $ template ,
859
+ $ baseSubtotalRefunded ,
860
+ $ baseSubtotalCanceled ,
861
+ $ baseDiscountRefunded ,
862
+ $ baseDiscountCanceled
863
+ );
864
+ }
865
+
832
866
/**
833
867
* Sort order by total amount
834
868
*
0 commit comments