Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 | 2 | /* |
bc77d7c0 TO |
3 | +--------------------------------------------------------------------+ |
4 | | Copyright CiviCRM LLC. All rights reserved. | | |
5 | | | | |
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 | +--------------------------------------------------------------------+ | |
006389de | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | ||
18 | /** | |
19 | * This class generates form components for Financial Type | |
6a488035 | 20 | */ |
b7519cbf | 21 | class CRM_Financial_Form_BatchTransaction extends CRM_Contribute_Form_Search { |
7b966967 SL |
22 | public static $_links = NULL; |
23 | public static $_entityID; | |
6a488035 TO |
24 | |
25 | /** | |
fe482240 | 26 | * Batch status. |
7b966967 | 27 | * @var int |
6a488035 TO |
28 | */ |
29 | protected $_batchStatusId; | |
30 | ||
89d18ebd PN |
31 | /** |
32 | * Batch status name. | |
7b966967 | 33 | * @var string |
89d18ebd PN |
34 | */ |
35 | protected $_batchStatus; | |
36 | ||
00be9182 | 37 | public function preProcess() { |
562fda4b CW |
38 | // This reuses some styles from search forms |
39 | CRM_Core_Resources::singleton()->addStyleFile('civicrm', 'css/searchForm.css', 1, 'html-header'); | |
40 | ||
0efdabe7 | 41 | self::$_entityID = CRM_Utils_Request::retrieve('bid', 'Positive') ? CRM_Utils_Request::retrieve('bid', 'Positive') : CRM_Utils_Array::value('batch_id', $_POST); |
6a488035 TO |
42 | $this->assign('entityID', self::$_entityID); |
43 | if (isset(self::$_entityID)) { | |
44 | $this->_batchStatusId = CRM_Core_DAO::getFieldValue('CRM_Batch_BAO_Batch', self::$_entityID, 'status_id'); | |
be2fb01f | 45 | $batchStatuses = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'status_id', ['labelColumn' => 'name', 'condition' => " v.value={$this->_batchStatusId}"]); |
89d18ebd | 46 | $this->_batchStatus = $batchStatuses[$this->_batchStatusId]; |
6a488035 | 47 | $this->assign('statusID', $this->_batchStatusId); |
89d18ebd | 48 | $this->assign('batchStatus', $this->_batchStatus); |
0bcbe589 | 49 | $validStatus = FALSE; |
be2fb01f | 50 | if (in_array($this->_batchStatus, ['Open', 'Reopened'])) { |
0bcbe589 | 51 | $validStatus = TRUE; |
89d18ebd | 52 | } |
0bcbe589 | 53 | $this->assign('validStatus', $validStatus); |
be2fb01f | 54 | $this->_values = civicrm_api3('Batch', 'getSingle', ['id' => self::$_entityID]); |
6a488035 | 55 | $batchTitle = CRM_Core_DAO::getFieldValue('CRM_Batch_BAO_Batch', self::$_entityID, 'title'); |
be2fb01f | 56 | CRM_Utils_System::setTitle(ts('Accounting Batch - %1', [1 => $batchTitle])); |
6a488035 | 57 | |
be2fb01f | 58 | $columnHeaders = [ |
408b79bf | 59 | 'created_by' => ts('Created By'), |
60 | 'status' => ts('Status'), | |
61 | 'description' => ts('Description'), | |
536f0e02 | 62 | 'payment_instrument' => ts('Payment Method'), |
a3933cca | 63 | 'item_count' => ts('Expected Number of Items'), |
64 | 'assigned_item_count' => ts('Actual Number of Items'), | |
65 | 'total' => ts('Expected Total Amount'), | |
66 | 'assigned_total' => ts('Actual Total Amount'), | |
408b79bf | 67 | 'opened_date' => ts('Opened'), |
be2fb01f | 68 | ]; |
6a488035 TO |
69 | $this->assign('columnHeaders', $columnHeaders); |
70 | } | |
71 | } | |
353ffa53 | 72 | |
6a488035 | 73 | /** |
fe482240 | 74 | * Build the form object. |
6a488035 TO |
75 | */ |
76 | public function buildQuickForm() { | |
89d18ebd | 77 | if ($this->_batchStatus == 'Closed') { |
03e04002 | 78 | $this->add('submit', 'export_batch', ts('Export Batch')); |
6a488035 | 79 | } |
03e04002 | 80 | |
89d18ebd | 81 | // do not build rest of form unless it is open/reopened batch |
be2fb01f | 82 | if (!in_array($this->_batchStatus, ['Open', 'Reopened'])) { |
6a488035 TO |
83 | return; |
84 | } | |
85 | ||
86 | parent::buildQuickForm(); | |
f07fc4c9 | 87 | if (CRM_Batch_BAO_Batch::checkBatchPermission('close', $this->_values['created_id'])) { |
ca0e2dda PN |
88 | $this->add('submit', 'close_batch', ts('Close Batch')); |
89 | if (CRM_Batch_BAO_Batch::checkBatchPermission('export', $this->_values['created_id'])) { | |
90 | $this->add('submit', 'export_batch', ts('Close & Export Batch')); | |
91 | } | |
92 | } | |
6a488035 | 93 | |
6a488035 TO |
94 | CRM_Contribute_BAO_Query::buildSearchForm($this); |
95 | $this->addElement('checkbox', 'toggleSelects', NULL, NULL); | |
96 | ||
481a74f4 | 97 | $this->add('select', |
6a488035 TO |
98 | 'trans_remove', |
99 | ts('Task'), | |
be2fb01f | 100 | ['' => ts('- actions -')] + ['Remove' => ts('Remove from Batch')]); |
6a488035 | 101 | |
045f52a3 | 102 | $this->add('submit', 'rSubmit', ts('Go'), |
be2fb01f | 103 | [ |
97e557d7 | 104 | 'class' => 'crm-form-submit', |
6a488035 | 105 | 'id' => 'GoRemove', |
be2fb01f | 106 | ]); |
6a488035 | 107 | |
045f52a3 | 108 | self::$_entityID = CRM_Utils_Request::retrieve('bid', 'Positive'); |
6a488035 TO |
109 | |
110 | $this->addButtons( | |
be2fb01f CW |
111 | [ |
112 | [ | |
353ffa53 | 113 | 'type' => 'submit', |
6a488035 TO |
114 | 'name' => ts('Search'), |
115 | 'isDefault' => TRUE, | |
be2fb01f CW |
116 | ], |
117 | ] | |
6a488035 | 118 | ); |
03e04002 | 119 | |
6a488035 | 120 | $this->addElement('checkbox', 'toggleSelect', NULL, NULL); |
481a74f4 | 121 | $this->add('select', |
6a488035 TO |
122 | 'trans_assign', |
123 | ts('Task'), | |
be2fb01f | 124 | ['' => ts('- actions -')] + ['Assign' => ts('Assign to Batch')]); |
6a488035 | 125 | |
045f52a3 | 126 | $this->add('submit', 'submit', ts('Go'), |
be2fb01f | 127 | [ |
97e557d7 | 128 | 'class' => 'crm-form-submit', |
6a488035 | 129 | 'id' => 'Go', |
be2fb01f | 130 | ]); |
6a488035 TO |
131 | $this->applyFilter('__ALL__', 'trim'); |
132 | ||
133 | $this->addElement('hidden', 'batch_id', self::$_entityID); | |
134 | ||
135 | $this->add('text', 'name', ts('Batch Name')); | |
136 | } | |
137 | ||
f2ac86d1 | 138 | /** |
139 | * Set the default values for the form. | |
140 | */ | |
00be9182 | 141 | public function setDefaultValues() { |
89d18ebd | 142 | // do not setdefault unless it is open/reopened batch |
be2fb01f | 143 | if (!in_array($this->_batchStatus, ['Open', 'Reopened'])) { |
6a488035 TO |
144 | return; |
145 | } | |
146 | if (isset(self::$_entityID)) { | |
147 | $paymentInstrumentID = CRM_Core_DAO::getFieldValue('CRM_Batch_BAO_Batch', self::$_entityID, 'payment_instrument_id'); | |
4804d6ee | 148 | $defaults['contribution_payment_instrument_id'] = $paymentInstrumentID; |
6a488035 TO |
149 | $this->assign('paymentInstrumentID', $paymentInstrumentID); |
150 | } | |
151 | return $defaults; | |
152 | } | |
153 | ||
e0ef6999 | 154 | /** |
23f0202e | 155 | * Get action links. |
156 | * | |
157 | * @return array | |
e0ef6999 | 158 | */ |
00be9182 | 159 | public function &links() { |
6a488035 | 160 | if (!(self::$_links)) { |
be2fb01f CW |
161 | self::$_links = [ |
162 | 'view' => [ | |
353ffa53 TO |
163 | 'name' => ts('View'), |
164 | 'url' => 'civicrm/contact/view/contribution', | |
165 | 'qs' => 'reset=1&id=%%contid%%&cid=%%cid%%&action=view&context=contribution&selectedChild=contribute', | |
6a488035 | 166 | 'title' => ts('View Contribution'), |
be2fb01f CW |
167 | ], |
168 | 'assign' => [ | |
353ffa53 TO |
169 | 'name' => ts('Assign'), |
170 | 'ref' => 'disable-action', | |
6a488035 TO |
171 | 'title' => ts('Assign Transaction'), |
172 | 'extra' => 'onclick = "assignRemove( %%id%%,\'' . 'assign' . '\' );"', | |
be2fb01f CW |
173 | ], |
174 | ]; | |
6a488035 TO |
175 | } |
176 | return self::$_links; | |
177 | } | |
96025800 | 178 | |
6a488035 | 179 | } |