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

Commit 3ebbe2d

Browse files
authored
Merge pull request #15 from agileware/CIVICRM-868
CIVICRM-868: Hiding tax field on edit line item form if no tax collected.
2 parents 9578151 + e97ddb7 commit 3ebbe2d

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

CRM/Lineitemedit/Form/Edit.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,18 @@ public function preProcess() {
2828
$this->assignFormVariables();
2929
}
3030

31+
/**
32+
* Check if there is tax value for selected financial type.
33+
* @param $financialTypeId
34+
* @return bool
35+
*/
36+
private function isTaxEnabledInFinancialType($financialTypeId) {
37+
$taxRates = CRM_Core_PseudoConstant::getTaxRates();
38+
return (isset($taxRates[$financialTypeId])) ? TRUE : FALSE;
39+
}
40+
3141
public function assignFormVariables($params = []) {
42+
3243
$this->_lineitemInfo = civicrm_api3('lineItem', 'getsingle', array('id' => $this->_id));
3344
$this->_lineitemInfo['tax_amount'] = CRM_Utils_Array::value('tax_amount', $this->_lineitemInfo, 0.00);
3445
foreach (CRM_Lineitemedit_Util::getLineitemFieldNames() as $attribute) {
@@ -105,6 +116,8 @@ public function buildQuickForm() {
105116

106117
$this->assign('taxRates', json_encode(CRM_Core_PseudoConstant::getTaxRates()));
107118

119+
$this->assign('isTaxEnabled', $this->isTaxEnabledInFinancialType($this->_values['financial_type_id']));
120+
108121
$this->addFormRule(array(__CLASS__, 'formRule'), $this);
109122

110123
$this->addButtons(array(
@@ -148,6 +161,10 @@ public function submit($values, $isTest = FALSE) {
148161
$this->_lineitemInfo['contribution_id'],
149162
'contact_id'
150163
);
164+
165+
if (!$this->isTaxEnabledInFinancialType($values['financial_type_id'])) {
166+
$values['tax_amount'] = '';
167+
}
151168
$params = array(
152169
'id' => $this->_id,
153170
'financial_type_id' => $values['financial_type_id'],
@@ -157,6 +174,7 @@ public function submit($values, $isTest = FALSE) {
157174
'line_total' => $values['line_total'],
158175
'tax_amount' => CRM_Utils_Array::value('tax_amount', $values, 0.00),
159176
);
177+
160178
$lineItem = CRM_Price_BAO_LineItem::create($params);
161179
$lineItem = $lineItem->toArray();
162180

templates/CRM/Lineitemedit/Form/Edit.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{* HEADER *}
22

33
{foreach from=$fieldNames item=fieldName}
4-
<div class="crm-section">
4+
<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}>
55
<div class="label">{$form.$fieldName.label}</div>
66
<div class="content">
77
{if in_array($fieldName, array('unit_price', 'line_total', 'tax_amount'))}

0 commit comments

Comments
 (0)