/** * Calculate non deductible amount. * * CRM-11956 * if non_deductible_amount exists i.e. Additional Details field set was opened [and staff typed something] - * if non_deductible_amount does NOT exist - then calculate it depending on: * $financialType->is_deductible and whether there is a product (premium). * * @param $params * @param $formValues * * @return array */ protected function calculateNonDeductibleAmount($params, $formValues) { if (!empty($params['non_deductible_amount'])) { return $params['non_deductible_amount']; } $priceSetId = CRM_Utils_Array::value('price_set_id', $params); // return non-deductible amount if it is set at the price field option level if ($priceSetId && !empty($params['line_item'])) { $nonDeductibleAmount = CRM_Price_BAO_PriceSet::getNonDeductibleAmountFromPriceSet($priceSetId, $params['line_item']); if (!empty($nonDeductibleAmount)) { return $nonDeductibleAmount; } } $financialType = new CRM_Financial_DAO_FinancialType(); $financialType->id = $params['financial_type_id']; $financialType->find(TRUE); if ($financialType->is_deductible) { if (isset($formValues['product_name'][0])) { $selectProduct = $formValues['product_name'][0]; } // if there is a product - compare the value to the contribution amount if (isset($selectProduct)) { $productDAO = new CRM_Contribute_DAO_Product(); $productDAO->id = $selectProduct; $productDAO->find(TRUE); // product value exceeds contribution amount if ($params['total_amount'] < $productDAO->price) { return $params['total_amount']; } else { return $productDAO->price; } } else { return '0.00'; } } else { return $params['total_amount']; } return 0; }
/** * Get non-deductible amount. * * This is a bit too much about wierd form interpretation to be this deep. * * CRM-11885 * if non_deductible_amount exists i.e. Additional Details fieldset was opened [and staff typed something] -> keep * it. * * @param array $params * @param CRM_Financial_BAO_FinancialType $financialType * @param bool $online * @param CRM_Contribute_Form_Contribution_Confirm $form * * @return array */ protected static function getNonDeductibleAmount($params, $financialType, $online, $form) { if (isset($params['non_deductible_amount']) && !empty($params['non_deductible_amount'])) { return $params['non_deductible_amount']; } $priceSetId = CRM_Utils_Array::value('priceSetId', $params); // return non-deductible amount if it is set at the price field option level if ($priceSetId && !empty($form->_lineItem)) { $nonDeductibleAmount = CRM_Price_BAO_PriceSet::getNonDeductibleAmountFromPriceSet($priceSetId, $form->_lineItem); } if (!empty($nonDeductibleAmount)) { return $nonDeductibleAmount; } else { if ($financialType->is_deductible) { if ($online && isset($params['selectProduct'])) { $selectProduct = CRM_Utils_Array::value('selectProduct', $params); } if (!$online && isset($params['product_name'][0])) { $selectProduct = $params['product_name'][0]; } // if there is a product - compare the value to the contribution amount if (isset($selectProduct) && $selectProduct != 'no_thanks') { $productDAO = new CRM_Contribute_DAO_Product(); $productDAO->id = $selectProduct; $productDAO->find(TRUE); // product value exceeds contribution amount if ($params['amount'] < $productDAO->price) { $nonDeductibleAmount = $params['amount']; return $nonDeductibleAmount; } else { return $productDAO->price; } } else { return '0.00'; } } else { return $params['amount']; } } }