Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
232624b1 | 4 | | CiviCRM version 4.4 | |
6a488035 TO |
5 | +--------------------------------------------------------------------+ |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
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 | |
31 | * @copyright CiviCRM LLC (c) 2004-2013 | |
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 | /** | |
50 | * Function to build the form | |
51 | * | |
52 | * @return None | |
53 | * @access public | |
54 | */ | |
55 | public function buildQuickForm() { | |
56 | parent::buildQuickForm(); | |
57 | ||
58 | if ($this->_action & CRM_Core_Action::DELETE) { | |
59 | return; | |
60 | } | |
61 | ||
62 | $this->applyFilter('__ALL__', 'trim'); | |
fc4aa398 | 63 | $attributes = CRM_Core_DAO::getAttribute('CRM_Batch_DAO_Batch'); |
6a488035 TO |
64 | $this->add('text', 'title', ts('Batch Name'), $attributes['name'], TRUE); |
65 | ||
fc4aa398 | 66 | $batchTypes = CRM_Batch_BAO_Batch::buildOptions('type_id'); |
8ef12e64 | 67 | |
6a488035 TO |
68 | // unset non-related types |
69 | unset($batchTypes[3]); | |
70 | unset($batchTypes[4]); | |
71 | $type = $this->add('select', 'type_id', ts('Type'), $batchTypes); | |
72 | ||
73 | if ($this->_action & CRM_Core_Action::UPDATE) { | |
74 | $type->freeze(); | |
75 | } | |
76 | ||
77 | $this->add('textarea', 'description', ts('Description'), $attributes['description']); | |
78 | $this->add('text', 'item_count', ts('Number of items'), $attributes['item_count'], TRUE); | |
79 | $this->add('text', 'total', ts('Total Amount'), $attributes['total'], TRUE); | |
80 | } | |
81 | ||
82 | /** | |
83 | * This function sets the default values for the form. | |
84 | * | |
85 | * @access public | |
86 | * | |
87 | * @return None | |
88 | */ | |
89 | function setDefaultValues() { | |
90 | $defaults = array(); | |
91 | ||
92 | if ($this->_action & CRM_Core_Action::ADD) { | |
93 | // set batch name default | |
94 | $defaults['title'] = CRM_Batch_BAO_Batch::generateBatchName(); | |
95 | } | |
96 | else { | |
97 | $defaults = $this->_values; | |
98 | } | |
6a488035 TO |
99 | return $defaults; |
100 | } | |
101 | ||
102 | /** | |
103 | * Function to process the form | |
104 | * | |
105 | * @access public | |
106 | * | |
107 | * @return None | |
108 | */ | |
109 | public function postProcess() { | |
110 | $params = $this->controller->exportValues($this->_name); | |
111 | if ($this->_action & CRM_Core_Action::DELETE) { | |
112 | CRM_Core_Session::setStatus("", ts("Batch Deleted"), "success"); | |
113 | CRM_Batch_BAO_Batch::deleteBatch($this->_id); | |
114 | return; | |
115 | } | |
116 | ||
117 | if ($this->_id) { | |
118 | $params['id'] = $this->_id; | |
119 | } | |
120 | else { | |
121 | $session = CRM_Core_Session::singleton(); | |
122 | $params['created_id'] = $session->get('userID'); | |
123 | $params['created_date'] = CRM_Utils_Date::processDate( date( "Y-m-d" ), date( "H:i:s" ) ); | |
124 | } | |
8ef12e64 | 125 | |
6a488035 | 126 | // always create with data entry status |
fd7abdce | 127 | $params['status_id'] = CRM_Core_OptionGroup::getValue('batch_status','Data Entry');; |
6a488035 TO |
128 | $batch = CRM_Batch_BAO_Batch::create($params); |
129 | ||
130 | // redirect to batch entry page. | |
131 | $session = CRM_Core_Session::singleton(); | |
132 | if ( $this->_action & CRM_Core_Action::ADD ) { | |
133 | $session->replaceUserContext(CRM_Utils_System::url('civicrm/batch/entry', "id={$batch->id}&reset=1&action=add")); | |
134 | } | |
135 | else { | |
136 | $session->replaceUserContext(CRM_Utils_System::url('civicrm/batch/entry', "id={$batch->id}&reset=1")); | |
137 | } | |
138 | } | |
139 | //end of function | |
140 | } | |
141 |