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

Fix calculation and assignment of taxAmount on contribution page confirmation #23346

Merged
merged 1 commit into from
Jul 6, 2022
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
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) {
Copy link
Contributor

@eileenmcnaughton eileenmcnaughton May 6, 2022

Choose a reason for hiding this comment

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

I guess this is cos we have line items 'handy' - but I'd rather grab it from the db contribution than rely on whatever got through the form wrangling to this point - ie cleanest is ALWAYs assign tax_amount & grab the value from the DB - it will be zero if not a tax situation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think there are a number of issues with "Separate membership payment" and this PR only scratches the surface.

If you look in confirm.tpl and thankyou.tpl you'll see there is special handling for $is_separate_payment which does not include displaying tax. But the tax is also not assigned properly to the form. In my view we should be getting rid of all that special handling and relying on the "lineitems" display in all cases (as we've already done with contributions in the backend).

@demeritcowboy The problems that you found, are they caused by this PR or pre-existing?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok it looks pre-existing, so I see now this is just about replacing the $params part.

I don't have an opinion on where it should come from - maybe just if there's any hooks that would make a difference and one would handle that better.

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