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