From: David Reedy Jr Date: Tue, 17 May 2022 13:15:21 +0000 (-0500) Subject: Calculate unit_price based on qty X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=e66cf74bf76b04c2bf0f13cc93a365198fa25cc2;p=civicrm-core.git Calculate unit_price based on qty --- diff --git a/CRM/Financial/BAO/Order.php b/CRM/Financial/BAO/Order.php index 63476d8749..7374dce222 100644 --- a/CRM/Financial/BAO/Order.php +++ b/CRM/Financial/BAO/Order.php @@ -1036,10 +1036,16 @@ class CRM_Financial_BAO_Order { if ($taxRate) { // Total is tax inclusive. $lineItem['tax_amount'] = ($taxRate / 100) * $this->getOverrideTotalAmount() / (1 + ($taxRate / 100)); - $lineItem['line_total'] = $lineItem['unit_price'] = $this->getOverrideTotalAmount() - $lineItem['tax_amount']; + $lineItem['line_total'] = $this->getOverrideTotalAmount() - $lineItem['tax_amount']; } else { - $lineItem['line_total'] = $lineItem['unit_price'] = $this->getOverrideTotalAmount(); + $lineItem['line_total'] = $this->getOverrideTotalAmount(); + } + if (!empty($lineItem['qty'])) { + $lineItem['unit_price'] = $lineItem['line_total'] / $lineItem['qty']; + } + else { + $lineItem['unit_price'] = $lineItem['line_total']; } }