Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
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 | /** | |
29 | * | |
30 | * @package CRM | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * This class generates form components for batch entry | |
38 | * | |
39 | */ | |
40 | class CRM_Batch_Form_Batch extends CRM_Admin_Form { | |
41 | ||
42 | public function preProcess() { | |
43 | parent::preProcess(); | |
44 | // set the usercontext | |
45 | $session = CRM_Core_Session::singleton(); | |
46 | $session->replaceUserContext(CRM_Utils_System::url('civicrm/batch', "reset=1")); | |
47 | } | |
48 | ||
49 | /** | |
c490a46a | 50 | * Build the form object |
6a488035 | 51 | * |
355ba699 | 52 | * @return void |
6a488035 TO |
53 | */ |
54 | public function buildQuickForm() { | |
55 | parent::buildQuickForm(); | |
56 | ||
57 | if ($this->_action & CRM_Core_Action::DELETE) { | |
58 | return; | |
59 | } | |
60 | ||
61 | $this->applyFilter('__ALL__', 'trim'); | |
fc4aa398 | 62 | $attributes = CRM_Core_DAO::getAttribute('CRM_Batch_DAO_Batch'); |
6a488035 TO |
63 | $this->add('text', 'title', ts('Batch Name'), $attributes['name'], TRUE); |
64 | ||
fc4aa398 | 65 | $batchTypes = CRM_Batch_BAO_Batch::buildOptions('type_id'); |
8ef12e64 | 66 | |
6a488035 TO |
67 | $type = $this->add('select', 'type_id', ts('Type'), $batchTypes); |
68 | ||
69 | if ($this->_action & CRM_Core_Action::UPDATE) { | |
70 | $type->freeze(); | |
71 | } | |
72 | ||
73 | $this->add('textarea', 'description', ts('Description'), $attributes['description']); | |
73708df6 | 74 | $this->add('text', 'item_count', ts('Number of Items'), $attributes['item_count'], TRUE); |
6a488035 TO |
75 | $this->add('text', 'total', ts('Total Amount'), $attributes['total'], TRUE); |
76 | } | |
77 | ||
78 | /** | |
c490a46a | 79 | * Set default values for the form. |
6a488035 | 80 | * |
6a488035 | 81 | * |
355ba699 | 82 | * @return void |
6a488035 | 83 | */ |
00be9182 | 84 | public function setDefaultValues() { |
6a488035 TO |
85 | $defaults = array(); |
86 | ||
87 | if ($this->_action & CRM_Core_Action::ADD) { | |
88 | // set batch name default | |
89 | $defaults['title'] = CRM_Batch_BAO_Batch::generateBatchName(); | |
90 | } | |
91 | else { | |
92 | $defaults = $this->_values; | |
93 | } | |
6a488035 TO |
94 | return $defaults; |
95 | } | |
96 | ||
97 | /** | |
c490a46a | 98 | * Process the form submission |
6a488035 | 99 | * |
6a488035 | 100 | * |
355ba699 | 101 | * @return void |
6a488035 TO |
102 | */ |
103 | public function postProcess() { | |
104 | $params = $this->controller->exportValues($this->_name); | |
105 | if ($this->_action & CRM_Core_Action::DELETE) { | |
106 | CRM_Core_Session::setStatus("", ts("Batch Deleted"), "success"); | |
107 | CRM_Batch_BAO_Batch::deleteBatch($this->_id); | |
108 | return; | |
109 | } | |
110 | ||
111 | if ($this->_id) { | |
112 | $params['id'] = $this->_id; | |
113 | } | |
114 | else { | |
115 | $session = CRM_Core_Session::singleton(); | |
116 | $params['created_id'] = $session->get('userID'); | |
481a74f4 | 117 | $params['created_date'] = CRM_Utils_Date::processDate(date("Y-m-d"), date("H:i:s")); |
6a488035 | 118 | } |
8ef12e64 | 119 | |
6a488035 | 120 | // always create with data entry status |
691df66d | 121 | $params['status_id'] = CRM_Core_OptionGroup::getValue('batch_status', 'Data Entry', 'name'); |
6a488035 TO |
122 | $batch = CRM_Batch_BAO_Batch::create($params); |
123 | ||
124 | // redirect to batch entry page. | |
125 | $session = CRM_Core_Session::singleton(); | |
481a74f4 | 126 | if ($this->_action & CRM_Core_Action::ADD) { |
6a488035 TO |
127 | $session->replaceUserContext(CRM_Utils_System::url('civicrm/batch/entry', "id={$batch->id}&reset=1&action=add")); |
128 | } | |
129 | else { | |
130 | $session->replaceUserContext(CRM_Utils_System::url('civicrm/batch/entry', "id={$batch->id}&reset=1")); | |
131 | } | |
132 | } | |
6a488035 | 133 | } |