Skip to content

Commit c68ea91

Browse files
committed
Remove tax calculation from overpayment credit note
The overpayment amount is already the gross cash difference (total_payments - contribution_total), where contribution_total is tax-inclusive. Applying tax would inflate the credit note beyond the actual overpayment, throwing accounting off balance.
1 parent 9b0db0c commit c68ea91

File tree

1 file changed

+5
-25
lines changed

1 file changed

+5
-25
lines changed

Civi/Api4/Action/CreditNote/AllocateOverpaymentAction.php

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Civi\Api4\Contribution;
1010
use Civi\Api4\Company;
1111
use Civi\Api4\OptionValue;
12-
use Civi\Api4\EntityFinancialAccount;
1312
use Civi\Financeextras\Utils\OverpaymentUtils;
1413
use Civi\Financeextras\Event\ContributionPaymentUpdatedEvent;
1514

@@ -168,8 +167,10 @@ private function createOverpaymentCreditNote(
168167
->execute()
169168
->first()['value'] ?? NULL;
170169

171-
// Get tax rate for the financial type if configured.
172-
$taxRate = $this->getTaxRateForFinancialType($financialTypeId);
170+
// Note: We do NOT apply tax to the overpayment amount.
171+
// The overpayment is the excess cash paid (total_payments - contribution_total),
172+
// where contribution_total is already tax-inclusive. Adding tax would create
173+
// a credit note larger than the actual overpayment, throwing accounting off balance.
173174

174175
return CreditNote::save(FALSE)
175176
->addRecord([
@@ -186,35 +187,14 @@ private function createOverpaymentCreditNote(
186187
'financial_type_id' => $financialTypeId,
187188
'quantity' => 1,
188189
'unit_price' => $amount,
189-
'tax_rate' => $taxRate,
190+
'tax_rate' => 0,
190191
],
191192
],
192193
])
193194
->execute()
194195
->first();
195196
}
196197

197-
/**
198-
* Get the tax rate for a financial type.
199-
*
200-
* @param int $financialTypeId
201-
* The financial type ID.
202-
*
203-
* @return float
204-
* The tax rate (0 if no sales tax account is configured).
205-
*/
206-
private function getTaxRateForFinancialType(int $financialTypeId): float {
207-
$entityFinancialAccount = EntityFinancialAccount::get(FALSE)
208-
->addSelect('financial_account_id.tax_rate')
209-
->addWhere('account_relationship:name', '=', 'Sales Tax Account is')
210-
->addWhere('entity_table', '=', 'civicrm_financial_type')
211-
->addWhere('entity_id', '=', $financialTypeId)
212-
->execute()
213-
->first();
214-
215-
return (float) ($entityFinancialAccount['financial_account_id.tax_rate'] ?? 0);
216-
}
217-
218198
/**
219199
* Record overpayment adjustment on the contribution to balance it.
220200
*

0 commit comments

Comments
 (0)