Merge pull request #821 from dlobo/CRM-12674
[civicrm-core.git] / CRM / Financial / Form / BatchTransaction.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.3 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
10 | |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
19 | |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
27 */
28
29 /**
30 *
31 * @package CRM
32 * @copyright CiviCRM LLC (c) 2004-2013
33 * $Id$
34 *
35 */
36
37 /**
38 * This class generates form components for Financial Type
39 *
40 */
41 class CRM_Financial_Form_BatchTransaction extends CRM_Contribute_Form {
42 static $_links = NULL;
43 static $_entityID;
44
45 /**
46 * Batch status
47 * @var
48 */
49 protected $_batchStatusId;
50
51 function preProcess() {
52 self::$_entityID = CRM_Utils_Request::retrieve( 'bid' , 'Positive' ) ? CRM_Utils_Request::retrieve( 'bid' , 'Positive' ) : $_POST['batch_id'];
53 $this->assign('entityID', self::$_entityID);
54 if (isset(self::$_entityID)) {
55 $this->_batchStatusId = CRM_Core_DAO::getFieldValue('CRM_Batch_BAO_Batch', self::$_entityID, 'status_id');
56 $this->assign('statusID', $this->_batchStatusId);
57
58 $batchTitle = CRM_Core_DAO::getFieldValue('CRM_Batch_BAO_Batch', self::$_entityID, 'title');
59 CRM_Utils_System::setTitle(ts('Accounting Batch - %1', array(1 => $batchTitle)));
60
61 $columnHeaders =
62 array(
63 'created_by' => ts('Created By'),
64 'status' => ts('Status'),
65 'description'=> ts('Description'),
66 'payment_instrument' => ts('Payment Instrument'),
67 'item_count' => ts('Entered Transactions'),
68 'assigned_item_count' => ts('Assigned Transactions'),
69 'total' => ts('Entered Total'),
70 'assigned_total' => ts('Assigned Total'),
71 'opened_date' => ts('Opened'),
72 );
73 $this->assign('columnHeaders', $columnHeaders);
74 }
75 }
76 /**
77 * Function to build the form
78 *
79 * @return None
80 * @access public
81 */
82 public function buildQuickForm() {
83 if ($this->_batchStatusId == 2) {
84 $this->add('submit', 'export_batch', ts('Export Batch'));
85 }
86
87 // do not build rest of form unless it is open batch
88 if ($this->_batchStatusId != 1 ) {
89 return;
90 }
91
92 parent::buildQuickForm();
93 $this->add('submit', 'close_batch', ts('Close Batch'));
94 $this->add('submit', 'export_batch', ts('Close & Export Batch'));
95
96 // text for sort_name
97 $this->addElement('text',
98 'sort_name',
99 ts('Contributor Name or Email'),
100 CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact',
101 'sort_name'
102 )
103 );
104
105 $this->_group = CRM_Core_PseudoConstant::group();
106
107 // multiselect for groups
108 if ($this->_group) {
109 $this->add('select', 'group', ts('Groups'), $this->_group, FALSE,
110 array('id' => 'group', 'multiple' => 'multiple', 'title' => ts('- select -'))
111 );
112 }
113 $contactTags = CRM_Core_BAO_Tag::getTags();
114
115 if ($contactTags) {
116 $this->add('select', 'contact_tags', ts('Tags'), $contactTags, FALSE,
117 array('id' => 'contact_tags', 'multiple' => 'multiple', 'title' => ts('- select -'))
118 );
119 }
120 CRM_Contribute_BAO_Query::buildSearchForm($this);
121 $this->addElement('checkbox', 'toggleSelects', NULL, NULL);
122
123 $this->add( 'select',
124 'trans_remove',
125 ts('Task'),
126 array( '' => ts( '- actions -' )) + array( 'Remove' => ts('Remove from Batch')));
127
128 $this->add('submit','rSubmit', ts('Go'),
129 array(
130 'class' => 'form-submit',
131 'id' => 'GoRemove',
132 ));
133
134 self::$_entityID = CRM_Utils_Request::retrieve('bid' , 'Positive');
135
136 $this->addButtons(
137 array(
138 array('type' => 'submit',
139 'name' => ts('Search'),
140 'isDefault' => TRUE,
141 )
142 )
143 );
144
145 $this->addElement('checkbox', 'toggleSelect', NULL, NULL);
146 $this->add( 'select',
147 'trans_assign',
148 ts('Task'),
149 array( '' => ts( '- actions -' )) + array( 'Assign' => ts( 'Assign to Batch' )));
150
151 $this->add('submit','submit', ts('Go'),
152 array(
153 'class' => 'form-submit',
154 'id' => 'Go',
155 ));
156 $this->applyFilter('__ALL__', 'trim');
157
158 $this->addElement('hidden', 'batch_id', self::$_entityID);
159
160 $this->add('text', 'name', ts('Batch Name'));
161 }
162
163 function setDefaultValues() {
164 // do not setdefault unless it is open batch
165 if ($this->_batchStatusId != 1 ) {
166 return;
167 }
168 if (isset(self::$_entityID)) {
169 $paymentInstrumentID = CRM_Core_DAO::getFieldValue('CRM_Batch_BAO_Batch', self::$_entityID, 'payment_instrument_id');
170 $defaults['contribution_payment_instrument_id'] = $paymentInstrumentID;
171 $this->assign('paymentInstrumentID', $paymentInstrumentID);
172 }
173 return $defaults;
174 }
175
176 function &links() {
177 if (!(self::$_links)) {
178 self::$_links = array(
179 'view' => array(
180 'name' => ts('View'),
181 'url' => 'civicrm/contact/view/contribution',
182 'qs' => 'reset=1&id=%%contid%%&cid=%%cid%%&action=view&context=contribution&selectedChild=contribute',
183 'title' => ts('View Contribution'),
184 ),
185 'assign' => array(
186 'name' => ts('Assign'),
187 'ref' => 'disable-action',
188 'title' => ts('Assign Transaction'),
189 'extra' => 'onclick = "assignRemove( %%id%%,\'' . 'assign' . '\' );"',
190 )
191 );
192 }
193 return self::$_links;
194 }
195 }
196
197