3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * This class generates form components for batch entry.
15 class CRM_Batch_Form_Batch
extends CRM_Admin_Form
{
18 * PreProcess function.
20 public function preProcess() {
22 // Set the user context.
23 $session = CRM_Core_Session
::singleton();
24 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/batch', "reset=1"));
28 * Build the form object.
30 public function buildQuickForm() {
31 parent
::buildQuickForm();
33 if ($this->_action
& CRM_Core_Action
::DELETE
) {
37 $this->applyFilter('__ALL__', 'trim');
38 $attributes = CRM_Core_DAO
::getAttribute('CRM_Batch_DAO_Batch');
39 $this->add('text', 'title', ts('Batch Name'), $attributes['name'], TRUE);
41 $batchTypes = CRM_Batch_BAO_Batch
::buildOptions('type_id');
43 $type = $this->add('select', 'type_id', ts('Type'), $batchTypes);
45 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
49 $this->add('textarea', 'description', ts('Description'), $attributes['description']);
50 $this->add('text', 'item_count', ts('Number of Items'), $attributes['item_count'], TRUE);
51 $this->add('text', 'total', ts('Total Amount'), $attributes['total'], TRUE);
55 * Set default values for the form.
57 public function setDefaultValues() {
60 if ($this->_action
& CRM_Core_Action
::ADD
) {
61 // Set batch name default.
62 $defaults['title'] = CRM_Batch_BAO_Batch
::generateBatchName();
65 $defaults = $this->_values
;
71 * Process the form submission.
73 public function postProcess() {
74 $params = $this->controller
->exportValues($this->_name
);
75 if ($this->_action
& CRM_Core_Action
::DELETE
) {
76 CRM_Core_Session
::setStatus("", ts("Batch Deleted"), "success");
77 CRM_Batch_BAO_Batch
::deleteBatch($this->_id
);
82 $params['id'] = $this->_id
;
85 $session = CRM_Core_Session
::singleton();
86 $params['created_id'] = $session->get('userID');
87 $params['created_date'] = CRM_Utils_Date
::processDate(date("Y-m-d"), date("H:i:s"));
90 // always create with data entry status
91 $params['status_id'] = CRM_Core_PseudoConstant
::getKey('CRM_Batch_BAO_Batch', 'status_id', 'Data Entry');
92 $batch = CRM_Batch_BAO_Batch
::create($params);
94 // redirect to batch entry page.
95 $session = CRM_Core_Session
::singleton();
96 if ($this->_action
& CRM_Core_Action
::ADD
) {
97 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/batch/entry', "id={$batch->id}&reset=1&action=add"));
100 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/batch/entry', "id={$batch->id}&reset=1"));