Skip to content

Commit

Permalink
Merge pull request #23346 from mattwire/totaltaxamount
Browse files Browse the repository at this point in the history
Fix calculation and assignment of taxAmount on contribution page confirmation
  • Loading branch information
mattwire authored Jul 6, 2022
2 parents 4e15c97 + b694755 commit 7ce31c2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
26 changes: 17 additions & 9 deletions CRM/Contribute/Form/Contribution/Confirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,10 @@ public function preProcess() {
$this->setFormAmountFields($this->_params['priceSetId']);
}

$this->_params['tax_amount'] = $this->get('tax_amount');
if (!empty($this->get('tax_amount'))) {
CRM_Core_Error::deprecatedWarning('tax_amount should be not passed in');
$this->_params['tax_amount'] = $this->get('tax_amount');
}
$this->_useForMember = $this->get('useForMember');

CRM_Contribute_Form_AbstractEditPayment::formatCreditCardDetails($this->_params);
Expand Down Expand Up @@ -492,15 +495,18 @@ public function buildQuickForm() {
// Make a copy of line items array to use for display only
$tplLineItems = $this->_lineItem;
if (CRM_Invoicing_Utils::isInvoicingEnabled()) {
// @todo $params seems like exactly the wrong place to get totalTaxAmount from
// this is a calculated variable so we it should be transparent how we
// calculated it rather than coming from 'params'
$this->assign('totalTaxAmount', $params['tax_amount']);
$taxAmount = 0;
foreach ($tplLineItems ?? [] as $lineItems) {
foreach ($lineItems as $lineItem) {
$taxAmount += (float) ($lineItem['tax_amount'] ?? 0);
}
}

$this->assign('totalTaxAmount', $taxAmount);
$this->assign('taxTerm', CRM_Invoicing_Utils::getTaxTerm());
}
$this->assignLineItemsToTemplate($tplLineItems);

$isDisplayLineItems = $this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config');

$this->assign('isDisplayLineItems', $isDisplayLineItems);

if (!$isDisplayLineItems) {
Expand All @@ -509,6 +515,9 @@ public function buildQuickForm() {
$this->assign('is_quick_config', 1);
$this->_params['is_quick_config'] = 1;
}
else {
$this->assignLineItemsToTemplate($tplLineItems);
}

if (!empty($params['selectProduct']) && $params['selectProduct'] !== 'no_thanks') {
$option = $params['options_' . $params['selectProduct']] ?? NULL;
Expand Down Expand Up @@ -565,8 +574,6 @@ public function buildQuickForm() {
$this->assign('priceSetID', $this->_priceSetId);

// The concept of contributeMode is deprecated.
// the is_monetary concept probably should be too as it can be calculated from
// the existence of 'amount' & seems fragile.
if ($this->_contributeMode === 'notify' ||
$this->_amount <= 0.0 || $this->_params['is_pay_later']
) {
Expand Down Expand Up @@ -1124,6 +1131,7 @@ protected function processFormContribution(
// lets store it in the form variable so postProcess hook can get to this and use it
$form->_contributionID = $contribution->id;
}
// @fixme: This is assigned to the smarty template for the receipt. It's value should be calculated and not taken from $params.
$form->assign('totalTaxAmount', $params['tax_amount'] ?? NULL);

// process soft credit / pcp params first
Expand Down
4 changes: 0 additions & 4 deletions CRM/Contribute/Form/Contribution/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -1363,10 +1363,6 @@ public function submit($params) {
CRM_Price_BAO_PriceSet::processAmount($this->_values['fee'], $params, $lineItem[$priceSetId], $priceSetId);
}

if ($params['tax_amount']) {
$this->set('tax_amount', $params['tax_amount']);
}

if ($proceFieldAmount) {
$lineItem[$params['priceSetId']][$fieldOption]['unit_price'] = $proceFieldAmount;
$lineItem[$params['priceSetId']][$fieldOption]['line_total'] = $proceFieldAmount;
Expand Down

0 comments on commit 7ce31c2

Please sign in to comment.