3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * This class generates form components for Financial Type
21 class CRM_Financial_Form_BatchTransaction
extends CRM_Contribute_Form_Search
{
22 public static $_links = NULL;
23 public static $_entityID;
29 protected $_batchStatusId;
35 protected $_batchStatus;
37 public function preProcess() {
38 // This reuses some styles from search forms
39 CRM_Core_Resources
::singleton()->addStyleFile('civicrm', 'css/searchForm.css', 1, 'html-header');
41 self
::$_entityID = CRM_Utils_Request
::retrieve('bid', 'Positive') ? CRM_Utils_Request
::retrieve('bid', 'Positive') : CRM_Utils_Array
::value('batch_id', $_POST);
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');
45 $batchStatuses = CRM_Core_PseudoConstant
::get('CRM_Batch_DAO_Batch', 'status_id', ['labelColumn' => 'name', 'condition' => " v.value={$this->_batchStatusId}"]);
46 $this->_batchStatus
= $batchStatuses[$this->_batchStatusId
];
47 $this->assign('statusID', $this->_batchStatusId
);
48 $this->assign('batchStatus', $this->_batchStatus
);
50 if (in_array($this->_batchStatus
, ['Open', 'Reopened'])) {
53 $this->assign('validStatus', $validStatus);
54 $this->_values
= civicrm_api3('Batch', 'getSingle', ['id' => self
::$_entityID]);
55 $batchTitle = CRM_Core_DAO
::getFieldValue('CRM_Batch_BAO_Batch', self
::$_entityID, 'title');
56 CRM_Utils_System
::setTitle(ts('Accounting Batch - %1', [1 => $batchTitle]));
59 'created_by' => ts('Created By'),
60 'status' => ts('Status'),
61 'description' => ts('Description'),
62 'payment_instrument' => ts('Payment Method'),
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'),
67 'opened_date' => ts('Opened'),
69 $this->assign('columnHeaders', $columnHeaders);
74 * Build the form object.
76 public function buildQuickForm() {
77 if ($this->_batchStatus
== 'Closed') {
78 $this->add('submit', 'export_batch', ts('Export Batch'));
81 // do not build rest of form unless it is open/reopened batch
82 if (!in_array($this->_batchStatus
, ['Open', 'Reopened'])) {
86 parent
::buildQuickForm();
87 if (CRM_Batch_BAO_Batch
::checkBatchPermission('close', $this->_values
['created_id'])) {
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'));
94 CRM_Contribute_BAO_Query
::buildSearchForm($this);
95 $this->addElement('checkbox', 'toggleSelects', NULL, NULL);
100 ['' => ts('- actions -')] +
['Remove' => ts('Remove from Batch')]);
102 $this->add('submit', 'rSubmit', ts('Go'),
104 'class' => 'crm-form-submit',
108 self
::$_entityID = CRM_Utils_Request
::retrieve('bid', 'Positive');
114 'name' => ts('Search'),
120 $this->addElement('checkbox', 'toggleSelect', NULL, NULL);
124 ['' => ts('- actions -')] +
['Assign' => ts('Assign to Batch')]);
126 $this->add('submit', 'submit', ts('Go'),
128 'class' => 'crm-form-submit',
131 $this->applyFilter('__ALL__', 'trim');
133 $this->addElement('hidden', 'batch_id', self
::$_entityID);
135 $this->add('text', 'name', ts('Batch Name'));
139 * Set the default values for the form.
141 public function setDefaultValues() {
142 // do not setdefault unless it is open/reopened batch
143 if (!in_array($this->_batchStatus
, ['Open', 'Reopened'])) {
146 if (isset(self
::$_entityID)) {
147 $paymentInstrumentID = CRM_Core_DAO
::getFieldValue('CRM_Batch_BAO_Batch', self
::$_entityID, 'payment_instrument_id');
148 $defaults['contribution_payment_instrument_id'] = $paymentInstrumentID;
149 $this->assign('paymentInstrumentID', $paymentInstrumentID);
159 public function &links() {
160 if (!(self
::$_links)) {
163 'name' => ts('View'),
164 'url' => 'civicrm/contact/view/contribution',
165 'qs' => 'reset=1&id=%%contid%%&cid=%%cid%%&action=view&context=contribution&selectedChild=contribute',
166 'title' => ts('View Contribution'),
169 'name' => ts('Assign'),
170 'ref' => 'disable-action',
171 'title' => ts('Assign Transaction'),
172 'extra' => 'onclick = "assignRemove( %%id%%,\'' . 'assign' . '\' );"',
176 return self
::$_links;