Skip to content

Commit f4fd16b

Browse files
Merge pull request #231 from compucorp/comcl-1077-fix-non-deductible-amount
COMCL-1077: Fix Non Deductible Amount Calculation
2 parents aafac7f + b47c740 commit f4fd16b

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

Civi/Financeextras/Hook/ValidateForm/ContributionCreate.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public function handle() {
2020
$this->validatePaymentForm();
2121
$this->validateConsistentIncomeAccountOwners();
2222
$this->removeInvalidSoftCreditErrors();
23+
$this->updateNonDeductibleAmountFromLineTotal();
2324
}
2425

2526
public function validatePaymentForm() {
@@ -42,7 +43,6 @@ public function updateTotalAmountFromLineTotal() {
4243
return;
4344
}
4445

45-
$data = &$this->form->controller->container();
4646
if (empty($this->fields['total_amount']) && !empty($this->fields['fe_record_payment_amount'])) {
4747
$data = &$this->form->controller->container();
4848
$total = array_sum($data['values']['Contribution']['item_line_total']) + array_sum($data['values']['Contribution']['item_tax_amount']);
@@ -121,4 +121,31 @@ private function removeInvalidSoftCreditErrors(): void {
121121

122122
}
123123

124+
private function updateNonDeductibleAmountFromLineTotal(): void {
125+
try {
126+
if ($this->form->_mode !== 'live') {
127+
return;
128+
}
129+
130+
$data = &$this->form->controller->container();
131+
132+
if ((isset($data['values']['Contribution']['non_deductible_amount']) && (!empty($data['values']['Contribution']['non_deductible_amount']))) ||
133+
isset($data['values']['Contribution']['price_set_id']) || isset($data['values']['Contribution']['priceSetId'])
134+
) {
135+
return;
136+
}
137+
138+
$financialType = new \CRM_Financial_DAO_FinancialType();
139+
$financialType->id = $data['values']['Contribution']['financial_type_id'];
140+
$financialType->find(TRUE);
141+
142+
if (!$financialType->is_deductible && !empty($data['values']['Contribution']['item_line_total']) && !empty($data['values']['Contribution']['item_tax_amount'])) {
143+
$total = array_sum($data['values']['Contribution']['item_line_total']) + array_sum($data['values']['Contribution']['item_tax_amount']);
144+
$data['values']['Contribution']['non_deductible_amount'] = $total ?? $this->fields['fe_record_payment_amount'];
145+
}
146+
}
147+
catch (\Throwable $e) {
148+
}
149+
}
150+
124151
}

0 commit comments

Comments
 (0)