Skip to content
This repository has been archived by the owner on Jul 7, 2021. It is now read-only.

Commit

Permalink
Merge pull request #15 from agileware/CIVICRM-868
Browse files Browse the repository at this point in the history
CIVICRM-868: Hiding tax field on edit line item form if no tax collected.
  • Loading branch information
monishdeb authored Sep 17, 2018
2 parents 9578151 + e97ddb7 commit 3ebbe2d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions CRM/Lineitemedit/Form/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,18 @@ public function preProcess() {
$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) {
Expand Down Expand Up @@ -105,6 +116,8 @@ public function buildQuickForm() {

$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(
Expand Down Expand Up @@ -148,6 +161,10 @@ public function submit($values, $isTest = FALSE) {
$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'],
Expand All @@ -157,6 +174,7 @@ public function submit($values, $isTest = FALSE) {
'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();

Expand Down
2 changes: 1 addition & 1 deletion templates/CRM/Lineitemedit/Form/Edit.tpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{* 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'))}
Expand Down

0 comments on commit 3ebbe2d

Please sign in to comment.