From 1776e96734507d48364d1ffa91fff4923702fc06 Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Fri, 8 Jul 2016 01:24:56 +0530 Subject: [PATCH] CRM-16189, added Closing Accounting form (#8583) * 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 | 133 ++++++++++++++++++ CRM/Contribute/xml/Menu/Contribute.xml | 9 ++ CRM/Upgrade/Incremental/sql/4.7.8.mysql.tpl | 10 ++ .../CRM/Contribute/Form/CloseAccPeriod.tpl | 34 +++++ xml/templates/civicrm_navigation.tpl | 3 +- 5 files changed, 188 insertions(+), 1 deletion(-) create mode 100644 CRM/Contribute/Form/CloseAccPeriod.php create mode 100644 templates/CRM/Contribute/Form/CloseAccPeriod.tpl diff --git a/CRM/Contribute/Form/CloseAccPeriod.php b/CRM/Contribute/Form/CloseAccPeriod.php new file mode 100644 index 0000000000..6a19ea4b7c --- /dev/null +++ b/CRM/Contribute/Form/CloseAccPeriod.php @@ -0,0 +1,133 @@ +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'); + } + +} diff --git a/CRM/Contribute/xml/Menu/Contribute.xml b/CRM/Contribute/xml/Menu/Contribute.xml index ef8694e9d3..d1dc1cf134 100644 --- a/CRM/Contribute/xml/Menu/Contribute.xml +++ b/CRM/Contribute/xml/Menu/Contribute.xml @@ -318,4 +318,13 @@ 630 CiviContribute + + civicrm/admin/contribute/closeaccperiod + Close Accounting Period + CRM_Contribute_Form_CloseAccPeriod + access CiviContribute,administer CiviCRM,administer Accounting + 1 + 640 + CiviContribute + diff --git a/CRM/Upgrade/Incremental/sql/4.7.8.mysql.tpl b/CRM/Upgrade/Incremental/sql/4.7.8.mysql.tpl index 6fc87f8fc0..5c1cfb611b 100644 --- a/CRM/Upgrade/Incremental/sql/4.7.8.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/4.7.8.mysql.tpl @@ -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 index 0000000000..95c376f459 --- /dev/null +++ b/templates/CRM/Contribute/Form/CloseAccPeriod.tpl @@ -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 | + +--------------------------------------------------------------------+ +*} + + + + + + +
{$form.closing_date.label}{$form.closing_date.html}
+ +
{include file="CRM/common/formButtons.tpl" location="bottom"}
\ No newline at end of file diff --git a/xml/templates/civicrm_navigation.tpl b/xml/templates/civicrm_navigation.tpl index 18d6074ef5..96266ec5aa 100644 --- a/xml/templates/civicrm_navigation.tpl +++ b/xml/templates/civicrm_navigation.tpl @@ -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 ), -- 2.25.1