From 4f1c81dabab0da038cf3f17f52d335a606555c96 Mon Sep 17 00:00:00 2001 From: monishdeb Date: Fri, 8 Aug 2014 20:16:43 +0530 Subject: [PATCH] CRM-15066 fix - Choose to cancel one recurring contribution plan, but Civi cancels the other https://issues.civicrm.org/jira/browse/CRM-15066 --- CRM/Contribute/BAO/ContributionRecur.php | 17 ----------------- api/v3/ContributionRecur.php | 14 +++++++++++++- js/jquery/jquery.crmeditable.js | 6 ++++-- .../CRM/Contribute/Page/ContributionRecur.tpl | 2 +- templates/CRM/common/enableDisableApi.tpl | 2 +- 5 files changed, 19 insertions(+), 22 deletions(-) diff --git a/CRM/Contribute/BAO/ContributionRecur.php b/CRM/Contribute/BAO/ContributionRecur.php index 3a2e828003..c9a1feca18 100644 --- a/CRM/Contribute/BAO/ContributionRecur.php +++ b/CRM/Contribute/BAO/ContributionRecur.php @@ -361,22 +361,6 @@ SELECT r.payment_processor_id return $params; } - /** - * update the is_active flag in the db - * - * @param int $id id of the database record - * @param boolean $is_active value we want to set the is_active field - * - * @return Object DAO object on success, null otherwise - * @static - */ - static function setIsActive($id, $is_active) { - if (!$is_active) { - return self::cancelRecurContribution($id, CRM_Core_DAO::$_nullObject); - } - return FALSE; - } - /** * @param $entityID * @param string $entity @@ -477,4 +461,3 @@ INNER JOIN civicrm_contribution con ON ( con.id = mp.contribution_id ) } } } - diff --git a/api/v3/ContributionRecur.php b/api/v3/ContributionRecur.php index 3eda5882ee..ae5f7a21cc 100644 --- a/api/v3/ContributionRecur.php +++ b/api/v3/ContributionRecur.php @@ -76,6 +76,19 @@ function civicrm_api3_contribution_recur_get($params) { return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); } +/** + * Cancel a recurring contribution of existing contribution_recur.id + * + * @param array $params (reference) array containing id of the recurring contribution + * + * @return boolean returns true is successfully cancelled + */ + +function civicrm_api3_contribution_recur_cancel($params) { + civicrm_api3_verify_one_mandatory($params, NULL, array('id')); + return call_user_func_array(array(_civicrm_api3_get_BAO(__FUNCTION__), 'cancelRecurContribution'), array($params['id'], CRM_Core_DAO::$_nullObject)); +} + /** * delete an existing contribution_recur * @@ -93,4 +106,3 @@ function civicrm_api3_contribution_recur_get($params) { function civicrm_api3_contribution_recur_delete($params) { return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params); } - diff --git a/js/jquery/jquery.crmeditable.js b/js/jquery/jquery.crmeditable.js index b581ec4adc..0fa6da5f9a 100644 --- a/js/jquery/jquery.crmeditable.js +++ b/js/jquery/jquery.crmeditable.js @@ -10,8 +10,10 @@ el = this[0], ret = {}, $row = this.first().closest('.crm-entity'); - ret.entity = $row.data('entity') || $row[0].id.split('-')[0]; - ret.id = $row.data('id') || $row[0].id.split('-')[1]; + ret.entity = $row.data('entity') || $row[0].id.split('-')[0]; + ret.id = $row.data('id') || $row[0].id.split('-')[1]; + ret.action = $row.data('entity-action') || $row[0].id.split('-')[2] || 'setvalue'; + if (!ret.entity || !ret.id) { return false; } diff --git a/templates/CRM/Contribute/Page/ContributionRecur.tpl b/templates/CRM/Contribute/Page/ContributionRecur.tpl index fd5be220e0..dc538eff90 100644 --- a/templates/CRM/Contribute/Page/ContributionRecur.tpl +++ b/templates/CRM/Contribute/Page/ContributionRecur.tpl @@ -69,7 +69,7 @@ {foreach from=$recurRows item=row} {assign var=id value=$row.id} - + {$row.amount|crmMoney}{if $row.is_test} ({ts}test{/ts}){/if} {ts}Every{/ts} {$row.frequency_interval} {$row.frequency_unit} {$row.start_date|crmDate} diff --git a/templates/CRM/common/enableDisableApi.tpl b/templates/CRM/common/enableDisableApi.tpl index 83a9964c39..fd5f454c84 100644 --- a/templates/CRM/common/enableDisableApi.tpl +++ b/templates/CRM/common/enableDisableApi.tpl @@ -41,7 +41,7 @@ function save() { $row.closest('table').block(); - CRM.api3(info.entity, 'setvalue', {id: info.id, field: 'is_active', value: enabled ? 0 : 1}, {success: successMsg}).done(refresh); + CRM.api3(info.entity, info.action, {id: info.id, field: 'is_active', value: enabled ? 0 : 1}, {success: successMsg}).done(refresh); if (enabled) { $(this).dialog('close'); } -- 2.25.1