From f831ac20c0b75099e46af81b1fafa9dbf98d7a9b Mon Sep 17 00:00:00 2001 From: Elliott Eggleston Date: Mon, 7 Oct 2019 16:24:37 +0200 Subject: [PATCH] dev/financial#72 add 'Template' contribution status This status exists to exclude template contributions from reports that don't yet know about the is_template field to be added to civicrm_contribution. This status is not meant to be available to be set via the UI, just for the process creating a ContributionRecur record and associated template contribution. --- CRM/Contribute/BAO/Contribution.php | 5 +++++ CRM/Contribute/BAO/Contribution/Utils.php | 14 +++++++++++--- CRM/Upgrade/Incremental/php/FiveTwenty.php | 12 ++++++++++++ xml/templates/civicrm_data.tpl | 1 + 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 13d89cb19c..e35df394cc 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -3916,6 +3916,11 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac $fieldName = 'soft_credit_type_id'; $params['condition'] = "v.name IN ('in_honor_of','in_memory_of')"; break; + + case 'contribution_status_id': + if ($context !== 'validate') { + $params['condition'] = "v.name <> 'Template'"; + } } return CRM_Core_PseudoConstant::get($className, $fieldName, $params, $context); } diff --git a/CRM/Contribute/BAO/Contribution/Utils.php b/CRM/Contribute/BAO/Contribution/Utils.php index 8872707de7..8ab4f3e822 100644 --- a/CRM/Contribute/BAO/Contribution/Utils.php +++ b/CRM/Contribute/BAO/Contribution/Utils.php @@ -545,14 +545,22 @@ LIMIT 1 $statusNames = CRM_Contribute_BAO_Contribution::buildOptions('contribution_status_id', 'validate'); } - $statusNamesToUnset = []; + $statusNamesToUnset = [ + // For records which represent a data template for a recurring + // contribution that may not yet have a payment. This status should not + // be available from forms. 'Template' contributions should only be created + // in conjunction with a ContributionRecur record, and should have their + // is_template field set to 1. This status excludes them from reports + // that are still ignorant of the is_template field. + 'Template', + ]; // on create fetch statuses on basis of component if (!$id) { - $statusNamesToUnset = [ + $statusNamesToUnset = array_merge($statusNamesToUnset, [ 'Refunded', 'Chargeback', 'Pending refund', - ]; + ]); // Event registration and New Membership backoffice form support partially paid payment, // so exclude this status only for 'New Contribution' form diff --git a/CRM/Upgrade/Incremental/php/FiveTwenty.php b/CRM/Upgrade/Incremental/php/FiveTwenty.php index 9485ff8813..c8c238e282 100644 --- a/CRM/Upgrade/Incremental/php/FiveTwenty.php +++ b/CRM/Upgrade/Incremental/php/FiveTwenty.php @@ -84,6 +84,18 @@ class CRM_Upgrade_Incremental_php_FiveTwenty extends CRM_Upgrade_Incremental_Bas $this->addTask('Add order_reference field to civicrm_financial_trxn', 'addColumn', 'civicrm_financial_trxn', 'order_reference', "varchar(255) COMMENT 'Payment Processor external order reference'", FALSE, '5.20.alpha1'); $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev); + $this->addTask('Add "Template" contribution status', 'templateStatus'); + } + + public static function templateStatus(CRM_Queue_TaskContext $ctx) { + CRM_Core_BAO_OptionValue::ensureOptionValueExists([ + 'option_group_id' => 'contribution_status', + 'name' => 'Template', + 'label' => ts('Template'), + 'is_active' => TRUE, + 'component_id' => 'CiviContribute', + ]); + return TRUE; } } diff --git a/xml/templates/civicrm_data.tpl b/xml/templates/civicrm_data.tpl index 42eff2a277..50c0050423 100644 --- a/xml/templates/civicrm_data.tpl +++ b/xml/templates/civicrm_data.tpl @@ -448,6 +448,7 @@ VALUES (@option_group_id_cs, '{ts escape="sql"}Partially paid{/ts}', 8, 'Partially paid', NULL, 0, NULL, 8, NULL, 0, 1, 1, NULL, NULL, NULL), (@option_group_id_cs, '{ts escape="sql"}Pending refund{/ts}', 9, 'Pending refund', NULL, 0, NULL, 9, NULL, 0, 1, 1, NULL, NULL, NULL), (@option_group_id_cs, '{ts escape="sql"}Chargeback{/ts}', 10, 'Chargeback', NULL, 0, NULL, 10, NULL, 0, 1, 1, NULL, NULL, NULL), + (@option_group_id_cs, '{ts escape="sql"}Template{/ts}' , 11, 'Template', NULL, 0, NULL, 11, '{ts escape="sql"}Status for contribution records which represent a template for a recurring contribution rather than an actual contribution. This status is transitional, to ensure that said contributions don\'t appear in reports. The is_template field is the preferred way to find and filter these contributions.{/ts}', 0, 1, 1, NULL, NULL, NULL), (@option_group_id_pcp, '{ts escape="sql"}Waiting Review{/ts}', 1, 'Waiting Review', NULL, 0, NULL, 1, NULL, 0, 1, 1, NULL, NULL, NULL), (@option_group_id_pcp, '{ts escape="sql"}Approved{/ts}' , 2, 'Approved' , NULL, 0, NULL, 2, NULL, 0, 1, 1, NULL, NULL, NULL), -- 2.25.1