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

Further removal of long-deprecated skipCleanMoney #17175

Merged
merged 1 commit into from
May 4, 2020
Merged
Show file tree
Hide file tree
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
9 changes: 2 additions & 7 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -4162,11 +4162,6 @@ public static function getContributionBalance($contributionId, $contributionTota
public static function checkTaxAmount($params, $isLineItem = FALSE) {
$taxRates = CRM_Core_PseudoConstant::getTaxRates();

// This function should be only called after standardisation (removal of
// thousand separator & using a decimal point for cents separator.
// However, we don't know if that is always true :-(
// There is a deprecation notice tho :-)
$unknownIfMoneyIsClean = empty($params['skipCleanMoney']) && !$isLineItem;
// Update contribution.
if (!empty($params['id'])) {
// CRM-19126 and CRM-19152 If neither total or financial_type_id are set on an update
Expand Down Expand Up @@ -4213,7 +4208,7 @@ public static function checkTaxAmount($params, $isLineItem = FALSE) {
empty($params['skipLineItem']) && !$isLineItem
) {
$taxRateParams = $taxRates[$params['financial_type_id']];
$taxAmount = CRM_Contribute_BAO_Contribution_Utils::calculateTaxAmount(CRM_Utils_Array::value('total_amount', $params), $taxRateParams, $unknownIfMoneyIsClean);
$taxAmount = CRM_Contribute_BAO_Contribution_Utils::calculateTaxAmount(CRM_Utils_Array::value('total_amount', $params), $taxRateParams);
$params['tax_amount'] = round($taxAmount['tax_amount'], 2);

// Get Line Item on update of contribution
Expand Down Expand Up @@ -4247,7 +4242,7 @@ public static function checkTaxAmount($params, $isLineItem = FALSE) {
// update line item of contrbution
if (isset($params['financial_type_id']) && array_key_exists($params['financial_type_id'], $taxRates) && $isLineItem) {
$taxRate = $taxRates[$params['financial_type_id']];
$taxAmount = CRM_Contribute_BAO_Contribution_Utils::calculateTaxAmount($params['line_total'], $taxRate, $unknownIfMoneyIsClean);
$taxAmount = CRM_Contribute_BAO_Contribution_Utils::calculateTaxAmount($params['line_total'], $taxRate);
$params['tax_amount'] = round($taxAmount['tax_amount'], 2);
}
}
Expand Down
18 changes: 3 additions & 15 deletions CRM/Contribute/BAO/Contribution/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -473,26 +473,14 @@ public static function getFirstLastDetails($contactID) {
* Amount of field.
* @param float $taxRate
* Tax rate of selected financial account for field.
* @param bool $ugWeDoNotKnowIfItNeedsCleaning_Help
* This should ALWAYS BE FALSE and then be removed. A 'clean' money string uses a standardised format
* such as '1000.99' for one thousand $/Euro/CUR and ninety nine cents/units.
* However, we are in the habit of not necessarily doing that so need to grandfather in
* the new expectation.
*
* @return array
* array of tax amount
*
*/
public static function calculateTaxAmount($amount, $taxRate, $ugWeDoNotKnowIfItNeedsCleaning_Help = FALSE) {
$taxAmount = [];
if ($ugWeDoNotKnowIfItNeedsCleaning_Help) {
Civi::log()->warning('Deprecated function, make sure money is in usable format before calling this.', ['civi.tag' => 'deprecated']);
$amount = CRM_Utils_Rule::cleanMoney($amount);
}
// There can not be any rounding at this stage - as this is prior to quantity multiplication
$taxAmount['tax_amount'] = ($taxRate / 100) * $amount;

return $taxAmount;
public static function calculateTaxAmount($amount, $taxRate) {
// There can not be any rounding at this stage - as it should be done at point of display.
return ['tax_amount' => ($taxRate / 100) * $amount];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion CRM/Price/Page/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function browse() {
$getTaxDetails = TRUE;
}
if (isset($priceField[$priceFieldBAO->id]['tax_rate'])) {
$taxAmount = CRM_Contribute_BAO_Contribution_Utils::calculateTaxAmount($priceField[$priceFieldBAO->id]['price'], $priceField[$priceFieldBAO->id]['tax_rate'], TRUE);
$taxAmount = CRM_Contribute_BAO_Contribution_Utils::calculateTaxAmount($priceField[$priceFieldBAO->id]['price'], $priceField[$priceFieldBAO->id]['tax_rate']);
$priceField[$priceFieldBAO->id]['tax_amount'] = $taxAmount['tax_amount'];
}
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Price/Page/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function browse() {
if ($invoicing && isset($customOption[$id]['tax_rate'])) {
$getTaxDetails = TRUE;
}
$taxAmount = CRM_Contribute_BAO_Contribution_Utils::calculateTaxAmount($customOption[$id]['amount'], $customOption[$id]['tax_rate'], TRUE);
$taxAmount = CRM_Contribute_BAO_Contribution_Utils::calculateTaxAmount($customOption[$id]['amount'], $customOption[$id]['tax_rate']);
$customOption[$id]['tax_amount'] = $taxAmount['tax_amount'];
}
if (!empty($values['financial_type_id'])) {
Expand Down