Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
8c9251b3 | 6 | | Copyright CiviCRM LLC (c) 2004-2018 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
37b8953e | 29 | * This class generates form components for batch entry. |
6a488035 TO |
30 | */ |
31 | class CRM_Batch_Form_Batch extends CRM_Admin_Form { | |
32 | ||
37b8953e EM |
33 | /** |
34 | * PreProcess function. | |
35 | */ | |
6a488035 TO |
36 | public function preProcess() { |
37 | parent::preProcess(); | |
37b8953e | 38 | // Set the user context. |
6a488035 TO |
39 | $session = CRM_Core_Session::singleton(); |
40 | $session->replaceUserContext(CRM_Utils_System::url('civicrm/batch', "reset=1")); | |
41 | } | |
42 | ||
43 | /** | |
eceb18cc | 44 | * Build the form object. |
6a488035 TO |
45 | */ |
46 | public function buildQuickForm() { | |
47 | parent::buildQuickForm(); | |
48 | ||
49 | if ($this->_action & CRM_Core_Action::DELETE) { | |
50 | return; | |
51 | } | |
52 | ||
53 | $this->applyFilter('__ALL__', 'trim'); | |
fc4aa398 | 54 | $attributes = CRM_Core_DAO::getAttribute('CRM_Batch_DAO_Batch'); |
6a488035 TO |
55 | $this->add('text', 'title', ts('Batch Name'), $attributes['name'], TRUE); |
56 | ||
fc4aa398 | 57 | $batchTypes = CRM_Batch_BAO_Batch::buildOptions('type_id'); |
8ef12e64 | 58 | |
6a488035 TO |
59 | $type = $this->add('select', 'type_id', ts('Type'), $batchTypes); |
60 | ||
61 | if ($this->_action & CRM_Core_Action::UPDATE) { | |
62 | $type->freeze(); | |
63 | } | |
64 | ||
65 | $this->add('textarea', 'description', ts('Description'), $attributes['description']); | |
73708df6 | 66 | $this->add('text', 'item_count', ts('Number of Items'), $attributes['item_count'], TRUE); |
6a488035 TO |
67 | $this->add('text', 'total', ts('Total Amount'), $attributes['total'], TRUE); |
68 | } | |
69 | ||
70 | /** | |
c490a46a | 71 | * Set default values for the form. |
6a488035 | 72 | */ |
00be9182 | 73 | public function setDefaultValues() { |
6a488035 TO |
74 | $defaults = array(); |
75 | ||
76 | if ($this->_action & CRM_Core_Action::ADD) { | |
37b8953e | 77 | // Set batch name default. |
6a488035 TO |
78 | $defaults['title'] = CRM_Batch_BAO_Batch::generateBatchName(); |
79 | } | |
80 | else { | |
81 | $defaults = $this->_values; | |
82 | } | |
6a488035 TO |
83 | return $defaults; |
84 | } | |
85 | ||
86 | /** | |
eceb18cc | 87 | * Process the form submission. |
6a488035 TO |
88 | */ |
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); | |
94 | return; | |
95 | } | |
96 | ||
97 | if ($this->_id) { | |
98 | $params['id'] = $this->_id; | |
99 | } | |
100 | else { | |
101 | $session = CRM_Core_Session::singleton(); | |
102 | $params['created_id'] = $session->get('userID'); | |
481a74f4 | 103 | $params['created_date'] = CRM_Utils_Date::processDate(date("Y-m-d"), date("H:i:s")); |
6a488035 | 104 | } |
8ef12e64 | 105 | |
6a488035 | 106 | // always create with data entry status |
7f0ddece | 107 | $params['status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Batch_BAO_Batch', 'status_id', 'Data Entry'); |
6a488035 TO |
108 | $batch = CRM_Batch_BAO_Batch::create($params); |
109 | ||
110 | // redirect to batch entry page. | |
111 | $session = CRM_Core_Session::singleton(); | |
481a74f4 | 112 | if ($this->_action & CRM_Core_Action::ADD) { |
6a488035 TO |
113 | $session->replaceUserContext(CRM_Utils_System::url('civicrm/batch/entry', "id={$batch->id}&reset=1&action=add")); |
114 | } | |
115 | else { | |
116 | $session->replaceUserContext(CRM_Utils_System::url('civicrm/batch/entry', "id={$batch->id}&reset=1")); | |
117 | } | |
118 | } | |
96025800 | 119 | |
6a488035 | 120 | } |