CRM-16189, added Closing Accounting form (#8583)
authorPradeep Nayak <pradpnayak@gmail.com>
Thu, 7 Jul 2016 19:54:56 +0000 (01:24 +0530)
committercolemanw <coleman@civicrm.org>
Thu, 7 Jul 2016 19:54:56 +0000 (15:54 -0400)
* CRM-16189, added Closing Accounting form

----------------------------------------
* CRM-16189: Improve support for Accrual Method bookkeeping
  https://issues.civicrm.org/jira/browse/CRM-16189

* CRM-16189 Removed invalid return statement

----------------------------------------
* CRM-16189: Improve support for Accrual Method bookkeeping
  https://issues.civicrm.org/jira/browse/CRM-16189

* CRM-16189 Fixed upgrade script

----------------------------------------
* CRM-16189: Improve support for Accrual Method bookkeeping
  https://issues.civicrm.org/jira/browse/CRM-16189

CRM/Contribute/Form/CloseAccPeriod.php [new file with mode: 0644]
CRM/Contribute/xml/Menu/Contribute.xml
CRM/Upgrade/Incremental/sql/4.7.8.mysql.tpl
templates/CRM/Contribute/Form/CloseAccPeriod.tpl [new file with mode: 0644]
xml/templates/civicrm_navigation.tpl

diff --git a/CRM/Contribute/Form/CloseAccPeriod.php b/CRM/Contribute/Form/CloseAccPeriod.php
new file mode 100644 (file)
index 0000000..6a19ea4
--- /dev/null
@@ -0,0 +1,133 @@
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.7                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2016                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM is distributed in the hope that it will be useful, but   |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+ | See the GNU Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+ */
+/**
+ * This class generates form components for closing an account period.
+ */
+class CRM_Contribute_Form_CloseAccPeriod extends CRM_Core_Form {
+
+  /**
+   * Set default values.
+   *
+   * @return array
+   */
+  public function setDefaultValues() {
+    $defaults = $period = array();
+    $period = Civi::settings()->get('closing_date');
+    if (empty($period)) {
+      $prior = CRM_Contribute_PseudoConstant::checkContributeSettings('prior_financial_period');
+    }
+    else {
+      $defaults['closing_date'] = $period;
+      return $defaults;
+    }
+    if (!empty($prior)) {
+      $period = array(
+        'M' => date('n', strtotime($prior)),
+        'd' => date('j', strtotime($prior)),
+      );
+      if ($period['M'] == 1) {
+        $period['M'] = 12;
+      }
+      else {
+        $period['M']--;
+      }
+      $defaults['closing_date'] = $period;
+    }
+    else {
+      $defaults['closing_date'] = array(
+        'M' => date('n', strtotime("-1 month")),
+        'd' => date('j'),
+      );
+    }
+    return $defaults;
+  }
+
+  /**
+   * Build the form object.
+   */
+  public function buildQuickForm() {
+    $this->add('date', 'closing_date', ts('Accounting Period to Close'), CRM_Core_SelectValues::date(NULL, 'M d'), TRUE);
+    $confirmClose = ts('Are you sure you want to close accounting period?');
+    $this->addButtons(array(
+        array(
+          'type' => 'cancel',
+          'name' => ts('Cancel'),
+        ),
+        array(
+          'type' => 'upload',
+          'name' => ts('Close Accounting Period'),
+          'js' => array('onclick' => 'return confirm(\'' . $confirmClose . '\');'),
+        ),
+      )
+    );
+  }
+
+  /**
+   * Global form rule.
+   *
+   * @param array $fields
+   *   The input form values.
+   * @param array $files
+   *   The uploaded files if any.
+   * @param $self
+   *
+   */
+  public static function formRule($fields, $files, $self) {
+  }
+
+  /**
+   * Process the form submission.
+   */
+  public function postProcess() {
+    // store the submitted values in an array
+    $params = $this->controller->exportValues($this->_name);
+    // Create activity
+    $activityType = CRM_Core_OptionGroup::getValue('activity_type',
+      'Close Accounting Period',
+      'name'
+    );
+    $activityParams = array(
+      'source_contact_id' => CRM_Core_Session::singleton()->get('userID'),
+      'assignee_contact_id' => CRM_Core_Session::singleton()->get('userID'),
+      'activity_type_id' => $activityType,
+      'subject' => ts('Close Accounting Period'),
+      'status_id' => CRM_Core_OptionGroup::getValue('activity_status',
+        'Completed',
+        'name'
+      ),
+      'activity_date_time' => date('YmdHis'),
+    );
+    CRM_Activity_BAO_Activity::create($activityParams);
+    // Set Prior Financial Period
+    $priorFinPeriod = $params['closing_date']['M'] . '/' . $params['closing_date']['d'] . '/' . date('Y');
+    Civi::settings()->set('prior_financial_period', date('m/d/Y', strtotime($priorFinPeriod)));
+    // Set closing date
+    Civi::settings()->set('closing_date', $params['closing_date']);
+    CRM_Core_Session::setStatus(ts("Accounting Period has been closed successfully!"), ts('Success'), 'success');
+  }
+
+}
index ef8694e9d3aa1c5a35a30cb6df262863da880f72..d1dc1cf134fd1670b2212f9b3a3276719bb994ce 100644 (file)
     <weight>630</weight>
     <component>CiviContribute</component>
   </item>
+  <item>
+    <path>civicrm/admin/contribute/closeaccperiod</path>
+    <title>Close Accounting Period</title>
+    <page_callback>CRM_Contribute_Form_CloseAccPeriod</page_callback>
+    <access_arguments>access CiviContribute,administer CiviCRM,administer Accounting</access_arguments>
+    <page_type>1</page_type>
+    <weight>640</weight>
+    <component>CiviContribute</component>
+  </item>
 </menu>
index 6fc87f8fc08afcea8149784dbf956c9731a80fd5..5c1cfb611b41b6cdb03391105a115f8eaf9c5f5c 100644 (file)
@@ -13,3 +13,13 @@ DELETE FROM civicrm_state_province WHERE name = 'Fernando de Noronha';
 -- CRM-17118 extend civicrm_address postal_code to accept full data strings from paypal etc.
 ALTER TABLE civicrm_address CHANGE `postal_code` `postal_code` varchar(64) ;
 
+-- CRM-16189
+SELECT @contributionNavId := id, @domainID := domain_id FROM civicrm_navigation WHERE name = 'Contributions';
+SELECT @navMaxWeight := MAX(ROUND(weight))+1 from civicrm_navigation WHERE parent_id = @contributionNavId;
+
+UPDATE civicrm_navigation SET has_separator = 1 WHERE name = 'Manage Price Sets' AND parent_id = @contributionNavId;
+
+INSERT INTO civicrm_navigation
+  (domain_id, url, label, name, permission, permission_operator, parent_id, is_active, has_separator, weight)
+VALUES
+  (@domainID, 'civicrm/admin/contribute/closeaccperiod?reset=1', '{ts escape="sql" skip="true"}Close Accounting Period{/ts}', 'Close Accounting Period', 'access CiviContribute,administer CiviCRM,administer Accounting', 'AND', @contributionNavId, '1', NULL, @navMaxWeight);
diff --git a/templates/CRM/Contribute/Form/CloseAccPeriod.tpl b/templates/CRM/Contribute/Form/CloseAccPeriod.tpl
new file mode 100644 (file)
index 0000000..95c376f
--- /dev/null
@@ -0,0 +1,34 @@
+{*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.7                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2016                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM is distributed in the hope that it will be useful, but     |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+ | See the GNU Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+*}
+
+<table class="form-layout-compressed">
+  <tr>
+    <td class="label">{$form.closing_date.label}</td>
+    <td class="content">{$form.closing_date.html}</td>
+  </tr>
+</table>
+
+<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
\ No newline at end of file
index 18d6074ef5f3f1172aa2399498e7d4f13290dcad..96266ec5aa4a015cf1c95d7c0168ada2fa7f50c9 100644 (file)
@@ -156,7 +156,8 @@ VALUES
     ( @domainID, 'civicrm/admin/pcp?reset=1&page_type=contribute',          '{ts escape="sql" skip="true"}Personal Campaign Pages{/ts}',    'Personal Campaign Pages',   'access CiviContribute,administer CiviCRM', 'AND',  @contributionlastID, '1', NULL, 11 ),
     ( @domainID, 'civicrm/admin/contribute/managePremiums?reset=1',         '{ts escape="sql" skip="true"}Premiums (Thank-you Gifts){/ts}', 'Premiums',                  'access CiviContribute,administer CiviCRM', 'AND',  @contributionlastID, '1', 1,    12 ),
     ( @domainID, 'civicrm/admin/price?reset=1&action=add',                  '{ts escape="sql" skip="true"}New Price Set{/ts}',              'New Price Set',             'access CiviContribute,administer CiviCRM', 'AND',  @contributionlastID, '1', NULL, 13 ),
-    ( @domainID, 'civicrm/admin/price?reset=1',                             '{ts escape="sql" skip="true"}Manage Price Sets{/ts}',          'Manage Price Sets',         'access CiviContribute,administer CiviCRM', 'AND',  @contributionlastID, '1', NULL, 14 ),
+    ( @domainID, 'civicrm/admin/price?reset=1',                             '{ts escape="sql" skip="true"}Manage Price Sets{/ts}',          'Manage Price Sets',         'access CiviContribute,administer CiviCRM', 'AND',  @contributionlastID, '1', 1, 14 ),
+    ( @domainID, 'civicrm/admin/contribute/closeaccperiod?reset=1',         '{ts escape="sql" skip="true"}Close Accounting Period{/ts}',    'Close Accounting Period',   'access CiviContribute,administer CiviCRM,administer Accounting', 'AND',  @contributionlastID, '1', NULL, 15 ),
 
     ( @domainID, 'civicrm/financial/batch?reset=1&action=add',                             '{ts escape="sql" skip="true"}New Batch{/ts}',          'New Batch',         'create manual batch', 'AND',  @financialTransactionID, '1', NULL, 1 ),
     ( @domainID, 'civicrm/financial/financialbatches?reset=1&batchStatus=1', '{ts escape="sql" skip="true"}Open Batches{/ts}',          'Open Batches',         'view own manual batches,view all manual batches', 'OR',  @financialTransactionID, '1', NULL, 2 ),