Commit f7ca3918 authored by Monish Deb's avatar Monish Deb
Browse files

Fix validation error on Batch import

parent 3ce5e2e0
......@@ -13,6 +13,18 @@ class CRM_Lineitemedit_Upgrader extends CRM_Lineitemedit_Upgrader_Base {
CRM_Lineitemedit_Util::generatePriceField();
}
public function uninstall() {
CRM_Lineitemedit_Util::disableEnablePriceField();
}
public function disable() {
CRM_Lineitemedit_Util::disableEnablePriceField();
}
public function enable() {
CRM_Lineitemedit_Util::disableEnablePriceField(TRUE);
}
/**
* Example: Run a couple simple queries.
*
......
......@@ -988,14 +988,31 @@ ORDER BY ps.id, pf.weight ;
$priceFieldValueParams = $priceFieldValue;
unset($priceFieldValueParams['id'], $priceFieldValueParams['name'], $priceFieldValueParams['weight']);
for ($i = 1; $i <= 10; ++$i) {
$p = civicrm_api3('PriceField', 'create', array_merge($priceFieldParams, ['label' => ts('Additional Line Item') . " $i"]));
civicrm_api3('PriceFieldValue', 'create', array_merge(
$priceFieldValueParams,
[
'label' => ts('Additional Item') . " $i",
'price_field_id' => $p['id'],
]
));
$params = array_merge($priceFieldParams, ['label' => ts('Additional Line Item') . " $i"]);
$priceField = civicrm_api3('PriceField', 'get', $params)['values'];
if (empty($priceField)) {
$p = civicrm_api3('PriceField', 'create', $params);
civicrm_api3('PriceFieldValue', 'create', array_merge(
$priceFieldValueParams,
[
'label' => ts('Additional Item') . " $i",
'price_field_id' => $p['id'],
]
));
}
else {
civicrm_api3('PriceField', 'create', ['id' => key($priceField), 'is_active' => TRUE]);
}
}
}
public static function disableEnablePriceField($enable = FALSE) {
$priceSetID = civicrm_api3('PriceSet', 'getvalue', ['name' => 'default_contribution_amount', 'return' => 'id']);
$priceFields = civicrm_api3('PriceField', 'get', ['price_set_id' => $priceSetID, 'is_active' => !$enable])['values'];
foreach ($priceFields as $id => $value) {
if ($value['name'] != 'contribution_amount') {
civicrm_api3('PriceField', 'create', ['id' => $id, 'is_active' => $enable]);
}
}
}
......
......@@ -5,8 +5,8 @@
<description>This extension allows a backend user to add, edit and cancel line item(s) associated with a Contribution.</description>
<license>AGPL-3.0</license>
<maintainer>
<author>Monish Deb</author>
<email>everyone@jmaconsulting.biz</email>
<author>Monish Deb, Joe Murray, JMA Consulting</author>
<email>support@jmaconsulting.biz</email>
</maintainer>
<urls>
<url desc="Main Extension Page">https://github.com/JMAConsulting/biz.jmaconsulting.lineitemedit</url>
......@@ -15,11 +15,12 @@
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls>
<releaseDate>2018-03-06</releaseDate>
<version>2.0</version>
<version>2.1</version>
<develStage>stable</develStage>
<compatibility>
<ver>4.7</ver>
<ver>5.0</ver>
<ver>5.8</ver>
</compatibility>
<comments>This extension allows a backend user to add, edit and cancel line item(s) associated with a Contribution.
</comments>
......
......@@ -161,6 +161,15 @@ function lineitemedit_civicrm_postProcess($formName, &$form) {
}
}
}
if ('CRM_Batch_Form_Entry' == $formName) {
CRM_Lineitemedit_Util::disableEnablePriceField(TRUE);
}
}
function lineitemedit_civicrm_validateForm($formName, &$fields, &$files, &$form, &$errors) {
if ('CRM_Batch_Form_Entry' == $formName && empty($errors)) {
CRM_Lineitemedit_Util::disableEnablePriceField();
}
}
function lineitemedit_civicrm_pre($op, $entity, $entityID, &$params) {
......
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