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

CRM-21445 Fix divide by zero with contribution page discount #11292

Closed
Closed
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
12 changes: 7 additions & 5 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -5687,15 +5687,17 @@ public static function getSalesTaxFinancialAccounts() {
* Create tax entry in civicrm_entity_financial_trxn table.
*
* @param array $entityParams
*
* @param array $eftParams
*
*/
public static function createProportionalEntry($entityParams, $eftParams) {
$paid = $entityParams['line_item_amount'] * ($entityParams['trxn_total_amount'] / $entityParams['contribution_total_amount']);
// Record Entity Financial Trxn; CRM-20145
$eftParams['amount'] = CRM_Contribute_BAO_Contribution_Utils::formatAmount($paid);
civicrm_api3('EntityFinancialTrxn', 'create', $eftParams);
$contributionTotalAmount = (float) $entityParams['contribution_total_amount'];
if (!empty($contributionTotalAmount)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattwire we need to create proportional entry in civicrm_entity_financial_trxn table even though the contribution total is 0.00 with civicrm_entity_financial_trxn.amount as 0.00. If there are no such entries then there would be problem while assigning transactions in financial batch or hopefully in quickbook reports as this transaction won't be listed because of missing entries.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pradnayak Ok. Happy to go with your PR if that's the case

$paid = $entityParams['line_item_amount'] * ($entityParams['trxn_total_amount'] / $entityParams['contribution_total_amount']);
// Record Entity Financial Trxn; CRM-20145
$eftParams['amount'] = CRM_Contribute_BAO_Contribution_Utils::formatAmount($paid);
civicrm_api3('EntityFinancialTrxn', 'create', $eftParams);
}
}

/**
Expand Down