3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
37 * This class generates form components for batch entry
40 class CRM_Batch_Form_Batch
extends CRM_Admin_Form
{
42 public function preProcess() {
44 // set the usercontext
45 $session = CRM_Core_Session
::singleton();
46 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/batch', "reset=1"));
50 * Build the form object
55 public function buildQuickForm() {
56 parent
::buildQuickForm();
58 if ($this->_action
& CRM_Core_Action
::DELETE
) {
62 $this->applyFilter('__ALL__', 'trim');
63 $attributes = CRM_Core_DAO
::getAttribute('CRM_Batch_DAO_Batch');
64 $this->add('text', 'title', ts('Batch Name'), $attributes['name'], TRUE);
66 $batchTypes = CRM_Batch_BAO_Batch
::buildOptions('type_id');
68 $type = $this->add('select', 'type_id', ts('Type'), $batchTypes);
70 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
74 $this->add('textarea', 'description', ts('Description'), $attributes['description']);
75 $this->add('text', 'item_count', ts('Number of Items'), $attributes['item_count'], TRUE);
76 $this->add('text', 'total', ts('Total Amount'), $attributes['total'], TRUE);
80 * Set default values for the form.
86 function setDefaultValues() {
89 if ($this->_action
& CRM_Core_Action
::ADD
) {
90 // set batch name default
91 $defaults['title'] = CRM_Batch_BAO_Batch
::generateBatchName();
94 $defaults = $this->_values
;
100 * Process the form submission
106 public function postProcess() {
107 $params = $this->controller
->exportValues($this->_name
);
108 if ($this->_action
& CRM_Core_Action
::DELETE
) {
109 CRM_Core_Session
::setStatus("", ts("Batch Deleted"), "success");
110 CRM_Batch_BAO_Batch
::deleteBatch($this->_id
);
115 $params['id'] = $this->_id
;
118 $session = CRM_Core_Session
::singleton();
119 $params['created_id'] = $session->get('userID');
120 $params['created_date'] = CRM_Utils_Date
::processDate( date( "Y-m-d" ), date( "H:i:s" ) );
123 // always create with data entry status
124 $params['status_id'] = CRM_Core_OptionGroup
::getValue('batch_status','Data Entry', 'name');
125 $batch = CRM_Batch_BAO_Batch
::create($params);
127 // redirect to batch entry page.
128 $session = CRM_Core_Session
::singleton();
129 if ( $this->_action
& CRM_Core_Action
::ADD
) {
130 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/batch/entry', "id={$batch->id}&reset=1&action=add"));
133 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/batch/entry', "id={$batch->id}&reset=1"));