3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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 +--------------------------------------------------------------------+
29 * This class generates form components for batch entry.
31 class CRM_Batch_Form_Batch
extends CRM_Admin_Form
{
34 * PreProcess function.
36 public function preProcess() {
38 // Set the user context.
39 $session = CRM_Core_Session
::singleton();
40 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/batch', "reset=1"));
44 * Build the form object.
46 public function buildQuickForm() {
47 parent
::buildQuickForm();
49 if ($this->_action
& CRM_Core_Action
::DELETE
) {
53 $this->applyFilter('__ALL__', 'trim');
54 $attributes = CRM_Core_DAO
::getAttribute('CRM_Batch_DAO_Batch');
55 $this->add('text', 'title', ts('Batch Name'), $attributes['name'], TRUE);
57 $batchTypes = CRM_Batch_BAO_Batch
::buildOptions('type_id');
59 $type = $this->add('select', 'type_id', ts('Type'), $batchTypes);
61 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
65 $this->add('textarea', 'description', ts('Description'), $attributes['description']);
66 $this->add('text', 'item_count', ts('Number of Items'), $attributes['item_count'], TRUE);
67 $this->add('text', 'total', ts('Total Amount'), $attributes['total'], TRUE);
71 * Set default values for the form.
73 public function setDefaultValues() {
76 if ($this->_action
& CRM_Core_Action
::ADD
) {
77 // Set batch name default.
78 $defaults['title'] = CRM_Batch_BAO_Batch
::generateBatchName();
81 $defaults = $this->_values
;
87 * Process the form submission.
89 public function postProcess() {
90 $params = $this->controller
->exportValues($this->_name
);
91 if ($this->_action
& CRM_Core_Action
::DELETE
) {
92 CRM_Core_Session
::setStatus("", ts("Batch Deleted"), "success");
93 CRM_Batch_BAO_Batch
::deleteBatch($this->_id
);
98 $params['id'] = $this->_id
;
101 $session = CRM_Core_Session
::singleton();
102 $params['created_id'] = $session->get('userID');
103 $params['created_date'] = CRM_Utils_Date
::processDate(date("Y-m-d"), date("H:i:s"));
106 // always create with data entry status
107 $params['status_id'] = CRM_Core_PseudoConstant
::getKey('CRM_Batch_BAO_Batch', 'status_id', 'Data Entry');
108 $batch = CRM_Batch_BAO_Batch
::create($params);
110 // redirect to batch entry page.
111 $session = CRM_Core_Session
::singleton();
112 if ($this->_action
& CRM_Core_Action
::ADD
) {
113 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/batch/entry', "id={$batch->id}&reset=1&action=add"));
116 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/batch/entry', "id={$batch->id}&reset=1"));