Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed calculation of 'Total' column under "Last Orders" listing on the admin dashboard #21283

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 40 additions & 6 deletions app/code/Magento/Reports/Model/ResourceModel/Order/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -769,11 +769,12 @@ public function addOrdersCount()
*/
public function addRevenueToSelect($convertCurrency = false)
{
$expr = $this->getTotalsExpression(
$expr = $this->getTotalsExpressionWithDiscountRefunded(
!$convertCurrency,
$this->getConnection()->getIfNullSql('main_table.base_subtotal_refunded', 0),
$this->getConnection()->getIfNullSql('main_table.base_subtotal_canceled', 0),
$this->getConnection()->getIfNullSql('main_table.base_discount_canceled', 0)
$this->getConnection()->getIfNullSql('ABS(main_table.base_discount_refunded)', 0),
$this->getConnection()->getIfNullSql('ABS(main_table.base_discount_canceled)', 0)
);
$this->getSelect()->columns(['revenue' => $expr]);

Expand All @@ -791,11 +792,12 @@ public function addSumAvgTotals($storeId = 0)
/**
* calculate average and total amount
*/
$expr = $this->getTotalsExpression(
$expr = $this->getTotalsExpressionWithDiscountRefunded(
$storeId,
$this->getConnection()->getIfNullSql('main_table.base_subtotal_refunded', 0),
$this->getConnection()->getIfNullSql('main_table.base_subtotal_canceled', 0),
$this->getConnection()->getIfNullSql('main_table.base_discount_canceled', 0)
$this->getConnection()->getIfNullSql('ABS(main_table.base_discount_refunded)', 0),
$this->getConnection()->getIfNullSql('ABS(main_table.base_discount_canceled)', 0)
);

$this->getSelect()->columns(
Expand All @@ -808,13 +810,15 @@ public function addSumAvgTotals($storeId = 0)
}

/**
* Get SQL expression for totals
* Get SQL expression for totals.
*
* @param int $storeId
* @param string $baseSubtotalRefunded
* @param string $baseSubtotalCanceled
* @param string $baseDiscountCanceled
* @return string
* @deprecated
* @see getTotalsExpressionWithDiscountRefunded
*/
protected function getTotalsExpression(
$storeId,
Expand All @@ -825,10 +829,40 @@ protected function getTotalsExpression(
$template = ($storeId != 0)
? '(main_table.base_subtotal - %2$s - %1$s - ABS(main_table.base_discount_amount) - %3$s)'
: '((main_table.base_subtotal - %1$s - %2$s - ABS(main_table.base_discount_amount) + %3$s) '
. ' * main_table.base_to_global_rate)';
. ' * main_table.base_to_global_rate)';
return sprintf($template, $baseSubtotalRefunded, $baseSubtotalCanceled, $baseDiscountCanceled);
}

/**
* Get SQL expression for totals with discount refunded.
*
* @param int $storeId
* @param string $baseSubtotalRefunded
* @param string $baseSubtotalCanceled
* @param string $baseDiscountRefunded
* @param string $baseDiscountCanceled
* @return string
*/
private function getTotalsExpressionWithDiscountRefunded(
$storeId,
$baseSubtotalRefunded,
$baseSubtotalCanceled,
$baseDiscountRefunded,
$baseDiscountCanceled
) {
$template = ($storeId != 0)
? '(main_table.base_subtotal - %2$s - %1$s - (ABS(main_table.base_discount_amount) - %3$s - %4$s))'
: '((main_table.base_subtotal - %1$s - %2$s - (ABS(main_table.base_discount_amount) - %3$s - %4$s)) '
. ' * main_table.base_to_global_rate)';
return sprintf(
$template,
$baseSubtotalRefunded,
$baseSubtotalCanceled,
$baseDiscountRefunded,
$baseDiscountCanceled
);
}

/**
* Sort order by total amount
*
Expand Down