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. | |
52187095 | 33 | * |
7b966967 | 34 | * @var string |
89d18ebd | 35 | */ |
52187095 | 36 | protected $_batchStatus = 'open'; |
89d18ebd | 37 | |
00be9182 | 38 | public function preProcess() { |
562fda4b CW |
39 | // This reuses some styles from search forms |
40 | CRM_Core_Resources::singleton()->addStyleFile('civicrm', 'css/searchForm.css', 1, 'html-header'); | |
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); |
0bcbe589 | 48 | $validStatus = FALSE; |
be2fb01f | 49 | if (in_array($this->_batchStatus, ['Open', 'Reopened'])) { |
0bcbe589 | 50 | $validStatus = TRUE; |
89d18ebd | 51 | } |
0bcbe589 | 52 | $this->assign('validStatus', $validStatus); |
be2fb01f | 53 | $this->_values = civicrm_api3('Batch', 'getSingle', ['id' => self::$_entityID]); |
6a488035 | 54 | $batchTitle = CRM_Core_DAO::getFieldValue('CRM_Batch_BAO_Batch', self::$_entityID, 'title'); |
94fd9d17 | 55 | $this->setTitle(ts('Accounting Batch - %1', [1 => $batchTitle])); |
6a488035 | 56 | |
be2fb01f | 57 | $columnHeaders = [ |
408b79bf | 58 | 'created_by' => ts('Created By'), |
59 | 'status' => ts('Status'), | |
60 | 'description' => ts('Description'), | |
536f0e02 | 61 | 'payment_instrument' => ts('Payment Method'), |
a3933cca | 62 | 'item_count' => ts('Expected Number of Items'), |
63 | 'assigned_item_count' => ts('Actual Number of Items'), | |
64 | 'total' => ts('Expected Total Amount'), | |
65 | 'assigned_total' => ts('Actual Total Amount'), | |
408b79bf | 66 | 'opened_date' => ts('Opened'), |
be2fb01f | 67 | ]; |
6a488035 TO |
68 | $this->assign('columnHeaders', $columnHeaders); |
69 | } | |
52187095 | 70 | $this->assign('batchStatus', $this->_batchStatus); |
6a488035 | 71 | } |
353ffa53 | 72 | |
6a488035 | 73 | /** |
fe482240 | 74 | * Build the form object. |
6a488035 TO |
75 | */ |
76 | public function buildQuickForm() { | |
89d18ebd | 77 | if ($this->_batchStatus == 'Closed') { |
cbd83dde | 78 | $this->add('xbutton', 'export_batch', ts('Export Batch'), ['type' => 'submit']); |
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'])) { |
cbd83dde | 88 | $this->add('xbutton', 'close_batch', ts('Close Batch'), ['type' => 'submit']); |
ca0e2dda | 89 | if (CRM_Batch_BAO_Batch::checkBatchPermission('export', $this->_values['created_id'])) { |
1684bccd | 90 | $this->add('xbutton', 'export_batch', ts('Close and Export Batch'), ['type' => 'submit']); |
ca0e2dda PN |
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 | |
cbd83dde | 102 | $this->add('xbutton', 'rSubmit', ts('Go'), |
be2fb01f | 103 | [ |
cbd83dde | 104 | 'type' => 'submit', |
97e557d7 | 105 | 'class' => 'crm-form-submit', |
6a488035 | 106 | 'id' => 'GoRemove', |
be2fb01f | 107 | ]); |
6a488035 | 108 | |
045f52a3 | 109 | self::$_entityID = CRM_Utils_Request::retrieve('bid', 'Positive'); |
6a488035 TO |
110 | |
111 | $this->addButtons( | |
be2fb01f CW |
112 | [ |
113 | [ | |
353ffa53 | 114 | 'type' => 'submit', |
6a488035 TO |
115 | 'name' => ts('Search'), |
116 | 'isDefault' => TRUE, | |
be2fb01f CW |
117 | ], |
118 | ] | |
6a488035 | 119 | ); |
03e04002 | 120 | |
6a488035 | 121 | $this->addElement('checkbox', 'toggleSelect', NULL, NULL); |
481a74f4 | 122 | $this->add('select', |
6a488035 TO |
123 | 'trans_assign', |
124 | ts('Task'), | |
be2fb01f | 125 | ['' => ts('- actions -')] + ['Assign' => ts('Assign to Batch')]); |
6a488035 | 126 | |
cbd83dde | 127 | $this->add('xbutton', 'submit', ts('Go'), |
be2fb01f | 128 | [ |
cbd83dde | 129 | 'type' => 'submit', |
97e557d7 | 130 | 'class' => 'crm-form-submit', |
6a488035 | 131 | 'id' => 'Go', |
be2fb01f | 132 | ]); |
6a488035 TO |
133 | $this->applyFilter('__ALL__', 'trim'); |
134 | ||
135 | $this->addElement('hidden', 'batch_id', self::$_entityID); | |
136 | ||
137 | $this->add('text', 'name', ts('Batch Name')); | |
138 | } | |
139 | ||
f2ac86d1 | 140 | /** |
141 | * Set the default values for the form. | |
142 | */ | |
00be9182 | 143 | public function setDefaultValues() { |
89d18ebd | 144 | // do not setdefault unless it is open/reopened batch |
be2fb01f | 145 | if (!in_array($this->_batchStatus, ['Open', 'Reopened'])) { |
6a488035 TO |
146 | return; |
147 | } | |
148 | if (isset(self::$_entityID)) { | |
149 | $paymentInstrumentID = CRM_Core_DAO::getFieldValue('CRM_Batch_BAO_Batch', self::$_entityID, 'payment_instrument_id'); | |
4804d6ee | 150 | $defaults['contribution_payment_instrument_id'] = $paymentInstrumentID; |
6a488035 TO |
151 | $this->assign('paymentInstrumentID', $paymentInstrumentID); |
152 | } | |
153 | return $defaults; | |
154 | } | |
155 | ||
e0ef6999 | 156 | /** |
23f0202e | 157 | * Get action links. |
158 | * | |
159 | * @return array | |
e0ef6999 | 160 | */ |
00be9182 | 161 | public function &links() { |
6a488035 | 162 | if (!(self::$_links)) { |
be2fb01f CW |
163 | self::$_links = [ |
164 | 'view' => [ | |
353ffa53 TO |
165 | 'name' => ts('View'), |
166 | 'url' => 'civicrm/contact/view/contribution', | |
167 | 'qs' => 'reset=1&id=%%contid%%&cid=%%cid%%&action=view&context=contribution&selectedChild=contribute', | |
6a488035 | 168 | 'title' => ts('View Contribution'), |
be2fb01f CW |
169 | ], |
170 | 'assign' => [ | |
353ffa53 TO |
171 | 'name' => ts('Assign'), |
172 | 'ref' => 'disable-action', | |
6a488035 TO |
173 | 'title' => ts('Assign Transaction'), |
174 | 'extra' => 'onclick = "assignRemove( %%id%%,\'' . 'assign' . '\' );"', | |
be2fb01f CW |
175 | ], |
176 | ]; | |
6a488035 TO |
177 | } |
178 | return self::$_links; | |
179 | } | |
96025800 | 180 | |
6a488035 | 181 | } |