@@ -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
0 commit comments