Unverified Commit 3ebbe2df authored by Monish Deb's avatar Monish Deb Committed by GitHub
Browse files

Merge pull request #15 from agileware/CIVICRM-868

CIVICRM-868: Hiding tax field on edit line item form if no tax collected.
parents 9578151c e97ddb76
......@@ -28,7 +28,18 @@ class CRM_Lineitemedit_Form_Edit extends CRM_Core_Form {
$this->assignFormVariables();
}
/**
* Check if there is tax value for selected financial type.
* @param $financialTypeId
* @return bool
*/
private function isTaxEnabledInFinancialType($financialTypeId) {
$taxRates = CRM_Core_PseudoConstant::getTaxRates();
return (isset($taxRates[$financialTypeId])) ? TRUE : FALSE;
}
public function assignFormVariables($params = []) {
$this->_lineitemInfo = civicrm_api3('lineItem', 'getsingle', array('id' => $this->_id));
$this->_lineitemInfo['tax_amount'] = CRM_Utils_Array::value('tax_amount', $this->_lineitemInfo, 0.00);
foreach (CRM_Lineitemedit_Util::getLineitemFieldNames() as $attribute) {
......@@ -105,6 +116,8 @@ class CRM_Lineitemedit_Form_Edit extends CRM_Core_Form {
$this->assign('taxRates', json_encode(CRM_Core_PseudoConstant::getTaxRates()));
$this->assign('isTaxEnabled', $this->isTaxEnabledInFinancialType($this->_values['financial_type_id']));
$this->addFormRule(array(__CLASS__, 'formRule'), $this);
$this->addButtons(array(
......@@ -148,6 +161,10 @@ class CRM_Lineitemedit_Form_Edit extends CRM_Core_Form {
$this->_lineitemInfo['contribution_id'],
'contact_id'
);
if (!$this->isTaxEnabledInFinancialType($values['financial_type_id'])) {
$values['tax_amount'] = '';
}
$params = array(
'id' => $this->_id,
'financial_type_id' => $values['financial_type_id'],
......@@ -157,6 +174,7 @@ class CRM_Lineitemedit_Form_Edit extends CRM_Core_Form {
'line_total' => $values['line_total'],
'tax_amount' => CRM_Utils_Array::value('tax_amount', $values, 0.00),
);
$lineItem = CRM_Price_BAO_LineItem::create($params);
$lineItem = $lineItem->toArray();
......
{* HEADER *}
{foreach from=$fieldNames item=fieldName}
<div class="crm-section">
<div class="crm-section" {if $fieldName == 'tax_amount'}id="crm-section-tax-amount"{/if} {if $fieldName == 'tax_amount' and not $isTaxEnabled}style="display: none;"{/if}>
<div class="label">{$form.$fieldName.label}</div>
<div class="content">
{if in_array($fieldName, array('unit_price', 'line_total', 'tax_amount'))}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment