From 01dac39932a11daa87b383b430dfaf3958acb7bd Mon Sep 17 00:00:00 2001 From: Jitendra Purohit Date: Mon, 24 Jul 2017 16:50:17 +0530 Subject: [PATCH] Add separate option group for pledge status --- CRM/Pledge/BAO/Pledge.php | 6 ++++-- CRM/Pledge/BAO/PledgePayment.php | 17 +++++++++++------ CRM/Pledge/BAO/Query.php | 2 +- CRM/Pledge/DAO/Pledge.php | 10 +++++----- CRM/Pledge/Form/Pledge.php | 2 +- CRM/Report/Form/Pledge/Detail.php | 8 +++++--- CRM/Report/Form/Pledge/Pbnp.php | 4 ++-- CRM/Report/Form/Pledge/Summary.php | 4 ++-- tests/phpunit/api/v3/PledgeTest.php | 5 ++++- xml/schema/Pledge/Pledge.xml | 4 ++-- xml/templates/civicrm_data.tpl | 15 ++++++++++++--- 11 files changed, 49 insertions(+), 28 deletions(-) diff --git a/CRM/Pledge/BAO/Pledge.php b/CRM/Pledge/BAO/Pledge.php index aa80503a15..ead46a0a07 100644 --- a/CRM/Pledge/BAO/Pledge.php +++ b/CRM/Pledge/BAO/Pledge.php @@ -495,7 +495,7 @@ GROUP BY currency 'honor_type' => CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_ContributionSoft', 'soft_credit_type_id', $honorDAO->soft_credit_type_id), 'honorId' => $pledgeDAO->contact_id, 'amount' => $pledgeDAO->amount, - 'status' => CRM_Contribute_PseudoConstant::contributionStatus($pledgeDAO->status_id), + 'status' => CRM_Core_PseudoConstant::getLabel('CRM_Pledge_BAO_Pledge', 'status_id', $pledgeDAO->status_id), 'create_date' => $pledgeDAO->create_date, 'acknowledge_date' => $pledgeDAO->acknowledge_date, 'type' => CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', @@ -790,7 +790,9 @@ GROUP BY currency */ public static function getContactPledges($contactID) { $pledgeDetails = array(); - $pledgeStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); + $pledgeStatuses = CRM_Core_OptionGroup::values('pledge_status', + FALSE, FALSE, FALSE, NULL, 'name' + ); $status = array(); diff --git a/CRM/Pledge/BAO/PledgePayment.php b/CRM/Pledge/BAO/PledgePayment.php index 5d56d843a4..2319d0b3d8 100644 --- a/CRM/Pledge/BAO/PledgePayment.php +++ b/CRM/Pledge/BAO/PledgePayment.php @@ -603,10 +603,13 @@ WHERE civicrm_pledge.id = %2 */ public static function calculatePledgeStatus($pledgeId) { $paymentStatusTypes = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); + $pledgeStatusTypes = CRM_Core_OptionGroup::values('pledge_status', + FALSE, FALSE, FALSE, NULL, 'name', TRUE + ); //return if the pledge is cancelled. $currentPledgeStatus = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_Pledge', $pledgeId, 'status_id', 'id', TRUE); - if ($currentPledgeStatus == array_search('Cancelled', $paymentStatusTypes)) { + if ($currentPledgeStatus == array_search('Cancelled', $pledgeStatusTypes)) { return $currentPledgeStatus; } @@ -621,18 +624,18 @@ WHERE civicrm_pledge.id = %2 } if (array_search('Overdue', $allStatus)) { - $statusId = array_search('Overdue', $paymentStatusTypes); + $statusId = array_search('Overdue', $pledgeStatusTypes); } elseif (array_search('Completed', $allStatus)) { if (count(array_count_values($allStatus)) == 1) { - $statusId = array_search('Completed', $paymentStatusTypes); + $statusId = array_search('Completed', $pledgeStatusTypes); } else { - $statusId = array_search('In Progress', $paymentStatusTypes); + $statusId = array_search('In Progress', $pledgeStatusTypes); } } else { - $statusId = array_search('Pending', $paymentStatusTypes); + $statusId = array_search('Pending', $pledgeStatusTypes); } return $statusId; @@ -722,7 +725,9 @@ WHERE civicrm_pledge_payment.id = {$paymentId} */ public static function getOldestPledgePayment($pledgeID, $limit = 1) { // get pending / overdue statuses - $pledgeStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); + $pledgeStatuses = CRM_Core_OptionGroup::values('pledge_status', + FALSE, FALSE, FALSE, NULL, 'name' + ); // get pending and overdue payments $status[] = array_search('Pending', $pledgeStatuses); diff --git a/CRM/Pledge/BAO/Query.php b/CRM/Pledge/BAO/Query.php index 5b9f344b90..ee9b5676fc 100644 --- a/CRM/Pledge/BAO/Query.php +++ b/CRM/Pledge/BAO/Query.php @@ -405,7 +405,7 @@ class CRM_Pledge_BAO_Query extends CRM_Core_BAO_Query { break; case 'pledge_status': - $from .= " $side JOIN civicrm_option_group option_group_pledge_status ON (option_group_pledge_status.name = 'contribution_status')"; + $from .= " $side JOIN civicrm_option_group option_group_pledge_status ON (option_group_pledge_status.name = 'pledge_status')"; $from .= " $side JOIN civicrm_option_value pledge_status ON (civicrm_pledge.status_id = pledge_status.value AND option_group_pledge_status.id = pledge_status.option_group_id ) "; break; diff --git a/CRM/Pledge/DAO/Pledge.php b/CRM/Pledge/DAO/Pledge.php index 8ee1a482d3..cda4ed3aa6 100644 --- a/CRM/Pledge/DAO/Pledge.php +++ b/CRM/Pledge/DAO/Pledge.php @@ -30,7 +30,7 @@ * * Generated from xml/schema/CRM/Pledge/Pledge.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:d323ed81c70c68905fc53ffd849a9e81) + * (GenCodeChecksum:02d420c23b3c72fc2687cd857cc7d178) */ require_once 'CRM/Core/DAO.php'; require_once 'CRM/Utils/Type.php'; @@ -171,7 +171,7 @@ class CRM_Pledge_DAO_Pledge extends CRM_Core_DAO { */ public $additional_reminder_day; /** - * Implicit foreign key to civicrm_option_values in the contribution_status option group. + * Implicit foreign key to civicrm_option_values in the pledge_status option group. * * @var int unsigned */ @@ -541,7 +541,7 @@ class CRM_Pledge_DAO_Pledge extends CRM_Core_DAO { 'name' => 'status_id', 'type' => CRM_Utils_Type::T_INT, 'title' => ts('Pledge Status Id') , - 'description' => 'Implicit foreign key to civicrm_option_values in the contribution_status option group.', + 'description' => 'Implicit foreign key to civicrm_option_values in the pledge_status option group.', 'import' => true, 'where' => 'civicrm_pledge.status_id', 'headerPattern' => '', @@ -552,8 +552,8 @@ class CRM_Pledge_DAO_Pledge extends CRM_Core_DAO { 'bao' => 'CRM_Pledge_BAO_Pledge', 'localizable' => 0, 'pseudoconstant' => array( - 'optionGroupName' => 'contribution_status', - 'optionEditPath' => 'civicrm/admin/options/contribution_status', + 'optionGroupName' => 'pledge_status', + 'optionEditPath' => 'civicrm/admin/options/pledge_status', ) ) , 'pledge_is_test' => array( diff --git a/CRM/Pledge/Form/Pledge.php b/CRM/Pledge/Form/Pledge.php index dad93c060d..612aac95b0 100644 --- a/CRM/Pledge/Form/Pledge.php +++ b/CRM/Pledge/Form/Pledge.php @@ -179,7 +179,7 @@ class CRM_Pledge_Form_Pledge extends CRM_Core_Form { } $pledgeStatus = CRM_Pledge_BAO_Pledge::buildOptions('status_id'); - $pledgeStatusNames = CRM_Core_OptionGroup::values('contribution_status', + $pledgeStatusNames = CRM_Core_OptionGroup::values('pledge_status', FALSE, FALSE, FALSE, NULL, 'name', TRUE ); // get default status label (pending) diff --git a/CRM/Report/Form/Pledge/Detail.php b/CRM/Report/Form/Pledge/Detail.php index abee2b539b..66423f2643 100644 --- a/CRM/Report/Form/Pledge/Detail.php +++ b/CRM/Report/Form/Pledge/Detail.php @@ -68,7 +68,9 @@ class CRM_Report_Form_Pledge_Detail extends CRM_Report_Form { * Class constructor. */ public function __construct() { - $this->_pledgeStatuses = CRM_Contribute_PseudoConstant::contributionStatus(); + $this->_pledgeStatuses = CRM_Core_OptionGroup::values('pledge_status', + FALSE, FALSE, FALSE, NULL, 'label' + ); // Check if CiviCampaign is a) enabled and b) has active campaigns $config = CRM_Core_Config::singleton(); $campaignEnabled = in_array("CiviCampaign", $config->enableComponents); @@ -167,7 +169,7 @@ class CRM_Report_Form_Pledge_Detail extends CRM_Report_Form { 'title' => ts('Pledge Status'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, - 'options' => CRM_Core_OptionGroup::values('contribution_status'), + 'options' => CRM_Core_OptionGroup::values('pledge_status'), ), 'financial_type_id' => array( 'title' => ts('Financial Type'), @@ -596,7 +598,7 @@ class CRM_Report_Form_Pledge_Detail extends CRM_Report_Form { //handle status id if (array_key_exists('civicrm_pledge_status_id', $row)) { if ($value = $row['civicrm_pledge_status_id']) { - $rows[$rowNum]['civicrm_pledge_status_id'] = CRM_Contribute_PseudoConstant::contributionStatus($value); + $rows[$rowNum]['civicrm_pledge_status_id'] = CRM_Core_PseudoConstant::getLabel('CRM_Pledge_BAO_Pledge', 'status_id', $value); } $entryFound = TRUE; } diff --git a/CRM/Report/Form/Pledge/Pbnp.php b/CRM/Report/Form/Pledge/Pbnp.php index 4bc34245c3..42dcfbe9e4 100644 --- a/CRM/Report/Form/Pledge/Pbnp.php +++ b/CRM/Report/Form/Pledge/Pbnp.php @@ -129,7 +129,7 @@ class CRM_Report_Form_Pledge_Pbnp extends CRM_Report_Form { 'title' => ts('Pledge Status'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, - 'options' => CRM_Core_OptionGroup::values('contribution_status'), + 'options' => CRM_Core_OptionGroup::values('pledge_status'), ), 'installments' => array( 'title' => ts('Installments'), @@ -372,7 +372,7 @@ class CRM_Report_Form_Pledge_Pbnp extends CRM_Report_Form { //handle the Status Ids if (array_key_exists('civicrm_pledge_status_id', $row)) { if ($value = $row['civicrm_pledge_status_id']) { - $rows[$rowNum]['civicrm_pledge_status_id'] = CRM_Contribute_PseudoConstant::contributionStatus($value); + $rows[$rowNum]['civicrm_pledge_status_id'] = CRM_Core_PseudoConstant::getLabel('CRM_Pledge_BAO_Pledge', 'status_id', $value); } $entryFound = TRUE; } diff --git a/CRM/Report/Form/Pledge/Summary.php b/CRM/Report/Form/Pledge/Summary.php index e0d4983678..d64e501e93 100644 --- a/CRM/Report/Form/Pledge/Summary.php +++ b/CRM/Report/Form/Pledge/Summary.php @@ -156,7 +156,7 @@ class CRM_Report_Form_Pledge_Summary extends CRM_Report_Form { 'title' => ts('Pledge Status'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, - 'options' => CRM_Core_OptionGroup::values('contribution_status'), + 'options' => CRM_Core_OptionGroup::values('pledge_status'), ), 'financial_type_id' => array( 'title' => ts('Financial Type'), @@ -429,7 +429,7 @@ class CRM_Report_Form_Pledge_Summary extends CRM_Report_Form { //handle status id if (array_key_exists('civicrm_pledge_status_id', $row)) { if ($value = $row['civicrm_pledge_status_id']) { - $rows[$rowNum]['civicrm_pledge_status_id'] = CRM_Contribute_PseudoConstant::contributionStatus($value); + $rows[$rowNum]['civicrm_pledge_status_id'] = CRM_Core_PseudoConstant::getLabel('CRM_Pledge_BAO_Pledge', 'status_id', $value); } $entryFound = TRUE; } diff --git a/tests/phpunit/api/v3/PledgeTest.php b/tests/phpunit/api/v3/PledgeTest.php index bfafec6374..3994190a86 100644 --- a/tests/phpunit/api/v3/PledgeTest.php +++ b/tests/phpunit/api/v3/PledgeTest.php @@ -199,8 +199,11 @@ class api_v3_PledgeTest extends CiviUnitTestCase { 'start_date' => 'first saturday of march last year', ); $this->_pledge = $this->callAPISuccess('pledge', 'create', array_merge($this->_params, $overdueParams)); + $pledgeStatuses = CRM_Core_OptionGroup::values('pledge_status', + FALSE, FALSE, FALSE, NULL, 'name' + ); $params = array( - 'pledge_status_id' => '6', + 'pledge_status_id' => array_search('Overdue', $pledgeStatuses), ); $result = $this->callAPISuccess('pledge', 'get', $params); $emptyResult = $this->callAPISuccess('pledge', 'get', array( diff --git a/xml/schema/Pledge/Pledge.xml b/xml/schema/Pledge/Pledge.xml index 585b8e3311..897c36e326 100644 --- a/xml/schema/Pledge/Pledge.xml +++ b/xml/schema/Pledge/Pledge.xml @@ -290,9 +290,9 @@ false int unsigned - contribution_status + pledge_status - Implicit foreign key to civicrm_option_values in the contribution_status option group. + Implicit foreign key to civicrm_option_values in the pledge_status option group. 2.1 diff --git a/xml/templates/civicrm_data.tpl b/xml/templates/civicrm_data.tpl index 0b4ba711ff..e23f93a86a 100644 --- a/xml/templates/civicrm_data.tpl +++ b/xml/templates/civicrm_data.tpl @@ -210,7 +210,8 @@ VALUES ('msg_mode' , '{ts escape="sql"}Message Mode{/ts}' , NULL, 1, 1, 0), ('contact_date_reminder_options' , '{ts escape="sql"}Contact Date Reminder Options{/ts}' , NULL, 1, 1, 1), ('wysiwyg_presets' , '{ts escape="sql"}WYSIWYG Editor Presets{/ts}' , NULL, 1, 1, 0), - ('relative_date_filters' , '{ts escape="sql"}Relative Date Filters{/ts}' , NULL, 1, 1, 0); + ('relative_date_filters' , '{ts escape="sql"}Relative Date Filters{/ts}' , NULL, 1, 1, 0), + ('pledge_status' , '{ts escape="sql"}Pledge Status{/ts}' , NULL, 1, 1, 1); SELECT @option_group_id_pcm := max(id) from civicrm_option_group where name = 'preferred_communication_method'; SELECT @option_group_id_act := max(id) from civicrm_option_group where name = 'activity_type'; @@ -290,6 +291,7 @@ SELECT @option_group_id_msg_mode := max(id) from civicrm_option_group where name SELECT @option_group_id_contactDateMode := max(id) from civicrm_option_group where name = 'contact_date_reminder_options'; SELECT @option_group_id_date_filter := max(id) from civicrm_option_group where name = 'relative_date_filters'; SELECT @option_group_id_wysiwyg_presets := max(id) from civicrm_option_group where name = 'wysiwyg_presets'; +SELECT @option_group_id_ps := max(id) from civicrm_option_group where name = 'pledge_status'; SELECT @contributeCompId := max(id) FROM civicrm_component where name = 'CiviContribute'; SELECT @eventCompId := max(id) FROM civicrm_component where name = 'CiviEvent'; @@ -637,7 +639,7 @@ VALUES (@option_group_id_report, {localize}'{ts escape="sql"}Contribution and Membership Details{/ts}'{/localize}, 'member/contributionDetail', 'CRM_Report_Form_Member_ContributionDetail', NULL, 0, NULL, 48, {localize}'{ts escape="sql"}Contribution details for any type of contribution, plus associated membership information for contributions which are in payment for memberships.{/ts}'{/localize}, 0, 0, 1, @memberCompId, NULL, NULL), (@option_group_id_report, {localize}'{ts escape="sql"}Recurring Contributions Report{/ts}'{/localize}, 'contribute/recur', 'CRM_Report_Form_Contribute_Recur', NULL, 0, NULL, 49, {localize}'{ts escape="sql"}Provides information about the status of recurring contributions{/ts}'{/localize}, 0, 0, 1, @contributeCompId, NULL, NULL), (@option_group_id_report, {localize}'{ts escape="sql"}Recurring Contributions Summary{/ts}'{/localize}, 'contribute/recursummary', 'CRM_Report_Form_Contribute_RecurSummary', NULL, 0, NULL, 49, {localize}'{ts escape="sql"}Provides simple summary for each payment instrument for which there are recurring contributions (e.g. Credit Card, Standing Order, Direct Debit, etc., NULL), showing within a given date range.{/ts}'{/localize}, 0, 0, 1, @contributeCompId, NULL, NULL), - (@option_group_id_report, {localize}'{ts escape="sql"}Deferred Revenue Details{/ts}'{/localize}, 'contribute/deferredrevenue', 'CRM_Report_Form_Contribute_DeferredRevenue', NULL, 0, NULL, 50, {localize}'{ts escape="sql"}Deferred Revenue Details Report{/ts}'{/localize}, 0, 0, 1, @contributeCompId, NULL, NULL), + (@option_group_id_report, {localize}'{ts escape="sql"}Deferred Revenue Details{/ts}'{/localize}, 'contribute/deferredrevenue', 'CRM_Report_Form_Contribute_DeferredRevenue', NULL, 0, NULL, 50, {localize}'{ts escape="sql"}Deferred Revenue Details Report{/ts}'{/localize}, 0, 0, 1, @contributeCompId, NULL, NULL), (@option_group_id_acs, '{ts escape="sql"}Scheduled{/ts}', 1, 'Scheduled', NULL, 0, 1, 1, NULL, 0, 1, 1, NULL, NULL, NULL), (@option_group_id_acs, '{ts escape="sql"}Completed{/ts}', 2, 'Completed', NULL, 1, NULL, 2, NULL, 0, 1, 1, NULL, NULL, NULL), @@ -1025,7 +1027,14 @@ VALUES (@option_group_id_date_filter, '{ts escape="sql"}From end of previous week{/ts}', 'greater_previous.week', 'greater_previous.week', NULL, NULL, NULL,59, NULL, 0, 0, 1, NULL, NULL, NULL), (@option_group_id_date_filter, '{ts escape="sql"}From end of previous calendar month{/ts}', 'greater_previous.month', 'greater_previous.month', NULL, NULL, NULL,60, NULL, 0, 0, 1, NULL, NULL, NULL), (@option_group_id_date_filter, '{ts escape="sql"}From end of previous quarter{/ts}', 'greater_previous.quarter', 'greater_previous.quarter', NULL, NULL, NULL,61, NULL, 0, 0, 1, NULL, NULL, NULL), - (@option_group_id_date_filter, '{ts escape="sql"}From end of previous calendar year{/ts}', 'greater_previous.year', 'greater_previous.year', NULL, NULL, NULL,62, NULL, 0, 0, 1, NULL, NULL, NULL); + (@option_group_id_date_filter, '{ts escape="sql"}From end of previous calendar year{/ts}', 'greater_previous.year', 'greater_previous.year', NULL, NULL, NULL,62, NULL, 0, 0, 1, NULL, NULL, NULL), + +-- Pledge Status + (@option_group_id_ps, '{ts escape="sql"}Completed{/ts}' , 1, 'Completed' , NULL, 0, NULL, 1, NULL, 0, 1, 1, NULL, NULL, NULL), + (@option_group_id_ps, '{ts escape="sql"}Pending{/ts}' , 2, 'Pending' , NULL, 0, NULL, 2, NULL, 0, 1, 1, NULL, NULL, NULL), + (@option_group_id_ps, '{ts escape="sql"}Cancelled{/ts}' , 3, 'Cancelled' , NULL, 0, NULL, 3, NULL, 0, 1, 1, NULL, NULL, NULL), + (@option_group_id_ps, '{ts escape="sql"}In Progress{/ts}', 4, 'In Progress', NULL, 0, NULL, 5, NULL, 0, 1, 1, NULL, NULL, NULL), + (@option_group_id_ps, '{ts escape="sql"}Overdue{/ts}' , 5, 'Overdue' , NULL, 0, NULL, 6, NULL, 0, 1, 1, NULL, NULL, NULL); -- financial accounts SELECT @opval := value FROM civicrm_option_value WHERE name = 'Revenue' and option_group_id = @option_group_id_fat; -- 2.25.1