3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
28 * This class generates form components for closing an account period.
30 class CRM_Contribute_Form_CloseAccPeriod
extends CRM_Core_Form
{
37 public function setDefaultValues() {
38 $defaults = $period = array();
39 $period = Civi
::settings()->get('closing_date');
41 $prior = CRM_Contribute_BAO_Contribution
::checkContributeSettings('prior_financial_period');
44 $defaults['closing_date'] = $period;
49 'M' => date('n', strtotime($prior)),
50 'd' => date('j', strtotime($prior)),
52 if ($period['M'] == 1) {
58 $defaults['closing_date'] = $period;
61 $defaults['closing_date'] = array(
62 'M' => date('n', strtotime("-1 month")),
70 * Build the form object.
72 public function buildQuickForm() {
73 $this->add('date', 'closing_date', ts('Accounting Period to Close'), CRM_Core_SelectValues
::date(NULL, 'M d'), TRUE);
74 $confirmClose = ts('Are you sure you want to close accounting period?');
75 $this->addButtons(array(
78 'name' => ts('Cancel'),
82 'name' => ts('Close Accounting Period'),
83 'js' => array('onclick' => 'return confirm(\'' . $confirmClose . '\');'),
92 * @param array $fields
93 * The input form values.
95 * The uploaded files if any.
99 public static function formRule($fields, $files, $self) {
103 * Process the form submission.
105 public function postProcess() {
106 // store the submitted values in an array
107 $params = $this->controller
->exportValues($this->_name
);
109 $activityType = CRM_Core_OptionGroup
::getValue('activity_type',
110 'Close Accounting Period',
113 $activityParams = array(
114 'source_contact_id' => CRM_Core_Session
::singleton()->get('userID'),
115 'assignee_contact_id' => CRM_Core_Session
::singleton()->get('userID'),
116 'activity_type_id' => $activityType,
117 'subject' => ts('Close Accounting Period'),
118 'status_id' => CRM_Core_OptionGroup
::getValue('activity_status',
122 'activity_date_time' => date('YmdHis'),
124 CRM_Activity_BAO_Activity
::create($activityParams);
125 // Set Prior Financial Period
126 $priorFinPeriod = $params['closing_date']['M'] . '/' . $params['closing_date']['d'] . '/' . date('Y');
127 Civi
::settings()->set('prior_financial_period', date('m/d/Y', strtotime($priorFinPeriod)));
129 Civi
::settings()->set('closing_date', $params['closing_date']);
130 CRM_Core_Session
::setStatus(ts("Accounting Period has been closed successfully!"), ts('Success'), 'success');