Merge pull request #6399 from colemanw/CRM-16705
[civicrm-core.git] / CRM / Financial / Form / BatchTransaction.php
CommitLineData
6a488035 1<?php
6a488035
TO
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
6a488035 5 +--------------------------------------------------------------------+
e7112fa7 6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 +--------------------------------------------------------------------+
006389de 26 */
6a488035
TO
27
28/**
29 *
30 * @package CRM
e7112fa7 31 * @copyright CiviCRM LLC (c) 2004-2015
6a488035
TO
32 * $Id$
33 *
34 */
35
36/**
37 * This class generates form components for Financial Type
38 *
39 */
40class CRM_Financial_Form_BatchTransaction extends CRM_Contribute_Form {
41 static $_links = NULL;
42 static $_entityID;
43
44 /**
fe482240 45 * Batch status.
6a488035
TO
46 * @var
47 */
48 protected $_batchStatusId;
49
00be9182 50 public function preProcess() {
562fda4b
CW
51 // This reuses some styles from search forms
52 CRM_Core_Resources::singleton()->addStyleFile('civicrm', 'css/searchForm.css', 1, 'html-header');
53
481a74f4 54 self::$_entityID = CRM_Utils_Request::retrieve('bid', 'Positive') ? CRM_Utils_Request::retrieve('bid', 'Positive') : $_POST['batch_id'];
6a488035
TO
55 $this->assign('entityID', self::$_entityID);
56 if (isset(self::$_entityID)) {
57 $this->_batchStatusId = CRM_Core_DAO::getFieldValue('CRM_Batch_BAO_Batch', self::$_entityID, 'status_id');
58 $this->assign('statusID', $this->_batchStatusId);
59
60 $batchTitle = CRM_Core_DAO::getFieldValue('CRM_Batch_BAO_Batch', self::$_entityID, 'title');
61 CRM_Utils_System::setTitle(ts('Accounting Batch - %1', array(1 => $batchTitle)));
62
408b79bf 63 $columnHeaders = array(
64 'created_by' => ts('Created By'),
65 'status' => ts('Status'),
66 'description' => ts('Description'),
536f0e02 67 'payment_instrument' => ts('Payment Method'),
408b79bf 68 'item_count' => ts('Entered Transactions'),
69 'assigned_item_count' => ts('Assigned Transactions'),
70 'total' => ts('Entered Total'),
71 'assigned_total' => ts('Assigned Total'),
72 'opened_date' => ts('Opened'),
73 );
6a488035
TO
74 $this->assign('columnHeaders', $columnHeaders);
75 }
76 }
353ffa53 77
6a488035 78 /**
fe482240 79 * Build the form object.
6a488035 80 *
355ba699 81 * @return void
6a488035
TO
82 */
83 public function buildQuickForm() {
84 if ($this->_batchStatusId == 2) {
03e04002 85 $this->add('submit', 'export_batch', ts('Export Batch'));
6a488035 86 }
03e04002 87
6a488035 88 // do not build rest of form unless it is open batch
481a74f4 89 if ($this->_batchStatusId != 1) {
6a488035
TO
90 return;
91 }
92
93 parent::buildQuickForm();
94 $this->add('submit', 'close_batch', ts('Close Batch'));
95 $this->add('submit', 'export_batch', ts('Close & Export Batch'));
96
97 // text for sort_name
98 $this->addElement('text',
99 'sort_name',
100 ts('Contributor Name or Email'),
101 CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact',
102 'sort_name'
103 )
104 );
105
24431f7b 106 $this->_group = CRM_Core_PseudoConstant::nestedGroup();
03e04002 107
6a488035
TO
108 // multiselect for groups
109 if ($this->_group) {
110 $this->add('select', 'group', ts('Groups'), $this->_group, FALSE,
ab345ca5 111 array('id' => 'group', 'multiple' => 'multiple', 'class' => 'crm-select2')
6a488035
TO
112 );
113 }
114 $contactTags = CRM_Core_BAO_Tag::getTags();
03e04002 115
6a488035
TO
116 if ($contactTags) {
117 $this->add('select', 'contact_tags', ts('Tags'), $contactTags, FALSE,
ab345ca5 118 array('id' => 'contact_tags', 'multiple' => 'multiple', 'class' => 'crm-select2')
6a488035
TO
119 );
120 }
121 CRM_Contribute_BAO_Query::buildSearchForm($this);
122 $this->addElement('checkbox', 'toggleSelects', NULL, NULL);
123
481a74f4 124 $this->add('select',
6a488035
TO
125 'trans_remove',
126 ts('Task'),
481a74f4 127 array('' => ts('- actions -')) + array('Remove' => ts('Remove from Batch')));
6a488035 128
045f52a3 129 $this->add('submit', 'rSubmit', ts('Go'),
6a488035 130 array(
97e557d7 131 'class' => 'crm-form-submit',
6a488035
TO
132 'id' => 'GoRemove',
133 ));
134
045f52a3 135 self::$_entityID = CRM_Utils_Request::retrieve('bid', 'Positive');
6a488035
TO
136
137 $this->addButtons(
138 array(
045f52a3 139 array(
353ffa53 140 'type' => 'submit',
6a488035
TO
141 'name' => ts('Search'),
142 'isDefault' => TRUE,
21dfd5f5 143 ),
6a488035
TO
144 )
145 );
03e04002 146
6a488035 147 $this->addElement('checkbox', 'toggleSelect', NULL, NULL);
481a74f4 148 $this->add('select',
6a488035
TO
149 'trans_assign',
150 ts('Task'),
481a74f4 151 array('' => ts('- actions -')) + array('Assign' => ts('Assign to Batch')));
6a488035 152
045f52a3 153 $this->add('submit', 'submit', ts('Go'),
6a488035 154 array(
97e557d7 155 'class' => 'crm-form-submit',
6a488035
TO
156 'id' => 'Go',
157 ));
158 $this->applyFilter('__ALL__', 'trim');
159
160 $this->addElement('hidden', 'batch_id', self::$_entityID);
161
162 $this->add('text', 'name', ts('Batch Name'));
163 }
164
00be9182 165 public function setDefaultValues() {
6a488035 166 // do not setdefault unless it is open batch
481a74f4 167 if ($this->_batchStatusId != 1) {
6a488035
TO
168 return;
169 }
170 if (isset(self::$_entityID)) {
171 $paymentInstrumentID = CRM_Core_DAO::getFieldValue('CRM_Batch_BAO_Batch', self::$_entityID, 'payment_instrument_id');
172 $defaults['contribution_payment_instrument_id'] = $paymentInstrumentID;
173 $this->assign('paymentInstrumentID', $paymentInstrumentID);
174 }
175 return $defaults;
176 }
177
e0ef6999
EM
178 /**
179 * @return array|null
180 */
00be9182 181 public function &links() {
6a488035
TO
182 if (!(self::$_links)) {
183 self::$_links = array(
353ffa53
TO
184 'view' => array(
185 'name' => ts('View'),
186 'url' => 'civicrm/contact/view/contribution',
187 'qs' => 'reset=1&id=%%contid%%&cid=%%cid%%&action=view&context=contribution&selectedChild=contribute',
6a488035
TO
188 'title' => ts('View Contribution'),
189 ),
190 'assign' => array(
353ffa53
TO
191 'name' => ts('Assign'),
192 'ref' => 'disable-action',
6a488035
TO
193 'title' => ts('Assign Transaction'),
194 'extra' => 'onclick = "assignRemove( %%id%%,\'' . 'assign' . '\' );"',
21dfd5f5 195 ),
6a488035
TO
196 );
197 }
198 return self::$_links;
199 }
96025800 200
6a488035 201}