CRM-17951 add Chargeback & refund account relationships and Chargeback status
authoreileen <emcnaughton@wikimedia.org>
Thu, 4 Feb 2016 05:44:39 +0000 (18:44 +1300)
committereileen <emcnaughton@wikimedia.org>
Thu, 4 Feb 2016 12:16:19 +0000 (01:16 +1300)
CRM/Upgrade/Incremental/php/FourSeven.php
xml/templates/civicrm_data.tpl

index a2e49c35cdd8a0e26ce50ff4bd57dd7b06825983..40dfe2bca5e886546f4c7ac0ea6882fdf60718df 100644 (file)
@@ -161,6 +161,7 @@ class CRM_Upgrade_Incremental_php_FourSeven extends CRM_Upgrade_Incremental_Base
    */
   public function upgrade_4_7_2($rev) {
     $this->addTask('Fix Index on civicrm_financial_item combined entity_id + entity_table', 'addCombinedIndexFinancialItemEntityIDEntityType');
+    $this->addTask('enable financial account relationships for chargeback & refund', 'addRefundAndChargeBackAccountsIfNotExist');
   }
 
   /**
@@ -454,4 +455,36 @@ FROM `civicrm_dashboard_contact` WHERE 1 GROUP BY contact_id";
     return TRUE;
   }
 
+  /**
+   * CRM-17951 Add accounts option values for refund and chargeback.
+   *
+   * Add Chargeback contribution status and Chargeback and Contra account relationships,
+   * checking first if one exists.
+   */
+  public function addRefundAndChargeBackAccountsIfNotExist() {
+    // First we enable and edit the record for Credit contra - this exists but is disabled for most sites.
+    // Using the ensure function (below) will not enabled a disabled option (by design).
+    CRM_Core_DAO::executeQuery("UPDATE civicrm_option_value v
+     INNER JOIN civicrm_option_group g on v.option_group_id=g.id and g.name='account_relationship'
+     SET v.is_active=1, v.label='Credit/Contra Revenue Account is', v.name='Credit/Contra Revenue Account is', v.description='Credit/Contra Revenue Account is'
+     WHERE v.name = 'Credit/Contra Account is';");
+
+    CRM_Core_BAO_OptionValue::ensureOptionValueExists(array(
+      'option_group_id' => 'account_relationship',
+      'name' => 'Chargeback Account Is',
+      'label' => ts('Chargeback Account Is'),
+      'is_active' => TRUE,
+      'component_id' => 'CiviContribute',
+    ));
+
+    CRM_Core_BAO_OptionValue::ensureOptionValueExists(array(
+      'option_group_id' => 'contribution_status',
+      'name' => 'Chargeback',
+      'label' => ts('Chargeback'),
+      'is_active' => TRUE,
+      'component_id' => 'CiviContribute',
+    ));
+    return TRUE;
+  }
+
 }
index 3e287673b00d4fd8bb21a80ca4f659e3c78d20c3..7d5247d6f66ea749c6f77c30e3178aa14eac9d63 100644 (file)
@@ -437,6 +437,7 @@ VALUES
   (@option_group_id_cs, '{ts escape="sql"}Refunded{/ts}'   , 7, 'Refunded'   , NULL, 0, NULL, 7, NULL, 0, 1, 1, NULL, NULL),
   (@option_group_id_cs, '{ts escape="sql"}Partially paid{/ts}', 8, 'Partially paid', NULL, 0, NULL, 8, NULL, 0, 1, 1, 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),
+  (@option_group_id_cs, '{ts escape="sql"}Chargeback{/ts}', 10, 'Chargeback', NULL, 0, NULL, 10, NULL, 0, 1, 1, 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),
   (@option_group_id_pcp, '{ts escape="sql"}Approved{/ts}'      , 2, 'Approved'      , NULL, 0, NULL, 2, NULL, 0, 1, 1, NULL, NULL),
@@ -870,7 +871,7 @@ VALUES
 
 -- account_relationship
     (@option_group_id_arel, '{ts escape="sql"}Income Account is{/ts}', 1, 'Income Account is', NULL, 0, 1, 1, 'Income Account is', 0, 1, 1, 2, NULL),
-    (@option_group_id_arel, '{ts escape="sql"}Credit/Contra Account is{/ts}', 2, 'Credit/Contra Account is', NULL, 0, 0, 2, 'Credit/Contra Account is', 0, 1, 0, 2, NULL),
+    (@option_group_id_arel, '{ts escape="sql"}Credit/Contra Revenue Account is{/ts}', 2, 'Credit/Contra Revenue Account is', NULL, 0, 0, 2, 'Credit/Contra Revenue Account is', 0, 1, 1, 2, NULL),
     (@option_group_id_arel, '{ts escape="sql"}Accounts Receivable Account is{/ts}', 3, 'Accounts Receivable Account is', NULL, 0, 0, 3, 'Accounts Receivable Account is', 0, 1, 1, 2, NULL),
     (@option_group_id_arel, '{ts escape="sql"}Credit Liability Account is{/ts}', 4, 'Credit Liability Account is', NULL, 0, 0, 4, 'Credit Liability Account is', 0, 1, 0, 2, NULL),
      (@option_group_id_arel, '{ts escape="sql"}Expense Account is{/ts}', 5, 'Expense Account is', NULL, 0, 0, 5, 'Expense Account is', 0, 1, 1, 2, NULL),
@@ -879,6 +880,7 @@ VALUES
      (@option_group_id_arel, '{ts escape="sql"}Premiums Inventory Account is{/ts}', 8, 'Premiums Inventory Account is', NULL, 0, 0, 8, 'Premiums Inventory Account is', 0, 1, 1, 2, NULL),
      (@option_group_id_arel, '{ts escape="sql"}Discounts Account is{/ts}', 9, 'Discounts Account is', NULL, 0, 0, 9, 'Discounts Account is', 0, 1, 1, 2, NULL),
      (@option_group_id_arel, '{ts escape="sql"}Sales Tax Account is{/ts}', 10, 'Sales Tax Account is', NULL, 0, 0, 10, 'Sales Tax Account is', 0, 1, 1, 2, NULL),
+     (@option_group_id_arel, '{ts escape="sql"}Chargeback Account is{/ts}', 11, 'Chargeback Account is', NULL, 0, 0, 11, 'Chargeback Account is', 0, 1, 1, 2, NULL)
 
 -- event_contacts
    (@option_group_id_ere, '{ts escape="sql"}Participant Role{/ts}', 1, 'participant_role', NULL, 0, NULL, 1, NULL, 0, 0, 1, NULL, NULL),