Merge pull request #17116 from lcdservices/dev-core-1721
[civicrm-core.git] / CRM / Financial / Form / Search.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
bc77d7c0
TO
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 |
6a488035
TO
9 +--------------------------------------------------------------------+
10 */
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
cded2ebf
SB
16 */
17
18/**
19 * @todo Add comments if possible.
6a488035
TO
20 */
21class CRM_Financial_Form_Search extends CRM_Core_Form {
22
23 public $_batchStatus;
24
00be9182 25 public function preProcess() {
6a488035
TO
26 $this->_batchStatus = CRM_Utils_Request::retrieve('batchStatus', 'Positive', CRM_Core_DAO::$_nullObject, FALSE, NULL);
27 $this->assign('batchStatus', $this->_batchStatus);
28 }
29
e0ef6999
EM
30 /**
31 * @return array
32 */
00be9182 33 public function setDefaultValues() {
be2fb01f 34 $defaults = [];
6a488035
TO
35 $status = CRM_Utils_Request::retrieve('status', 'Positive', CRM_Core_DAO::$_nullObject, FALSE, 1);
36 $defaults['batch_update'] = $status;
37 if ($this->_batchStatus) {
38 $defaults['status_id'] = $this->_batchStatus;
39 }
40 return $defaults;
41 }
42
43 public function buildQuickForm() {
353ffa53
TO
44 CRM_Core_Resources::singleton()
45 ->addScriptFile('civicrm', 'packages/jquery/plugins/jquery.redirect.min.js', 0, 'html-header');
6a488035
TO
46 $attributes = CRM_Core_DAO::getAttribute('CRM_Batch_DAO_Batch');
47 $attributes['total']['class'] = $attributes['item_count']['class'] = 'number';
48 $this->add('text', 'title', ts('Batch Name'), $attributes['title']);
e0ef6999 49
be2fb01f 50 $batchStatus = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'status_id', ['labelColumn' => 'name']);
6a488035
TO
51 $this->add(
52 'select',
53 'status_id',
54 ts('Batch Status'),
be2fb01f 55 [
481a74f4 56 '' => ts('- any -'),
fd7abdce
PN
57 array_search('Open', $batchStatus) => ts('Open'),
58 array_search('Closed', $batchStatus) => ts('Closed'),
59 array_search('Exported', $batchStatus) => ts('Exported'),
be2fb01f 60 ],
045f52a3 61 FALSE
6a488035
TO
62 );
63
64 $this->add(
65 'select',
66 'payment_instrument_id',
536f0e02 67 ts('Payment Method'),
be2fb01f 68 ['' => ts('- any -')] + CRM_Contribute_PseudoConstant::paymentInstrument(),
045f52a3 69 FALSE
6a488035
TO
70 );
71
72 $this->add('text', 'total', ts('Total Amount'), $attributes['total']);
73
74 $this->add('text', 'item_count', ts('Number of Items'), $attributes['item_count']);
75 $this->add('text', 'sort_name', ts('Created By'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
76
be2fb01f
CW
77 $this->assign('elements', ['status_id', 'title', 'sort_name', 'payment_instrument_id', 'item_count', 'total']);
78 $this->addElement('checkbox', 'toggleSelect', NULL, NULL, ['class' => 'select-rows']);
79 $batchAction = [
6a488035
TO
80 'reopen' => ts('Re-open'),
81 'close' => ts('Close'),
82 'export' => ts('Export'),
83 'delete' => ts('Delete'),
be2fb01f 84 ];
6a488035 85
ca0e2dda
PN
86 foreach ($batchAction as $action => $ignore) {
87 if (!CRM_Batch_BAO_Batch::checkBatchPermission($action)) {
88 unset($batchAction[$action]);
89 }
90 }
6a488035
TO
91 $this->add('select',
92 'batch_update',
481a74f4 93 ts('Task'),
be2fb01f 94 ['' => ts('- actions -')] + $batchAction);
6a488035 95
045f52a3 96 $this->add('submit', 'submit', ts('Go'),
be2fb01f 97 [
97e557d7 98 'class' => 'crm-form-submit',
6a488035 99 'id' => 'Go',
be2fb01f 100 ]);
6a488035
TO
101
102 $this->addButtons(
be2fb01f
CW
103 [
104 [
6a488035
TO
105 'type' => 'refresh',
106 'name' => ts('Search'),
107 'isDefault' => TRUE,
be2fb01f
CW
108 ],
109 ]
6a488035
TO
110 );
111 parent::buildQuickForm();
112 }
113
00be9182 114 public function postProcess() {
be2fb01f 115 $batchIds = [];
6a488035 116 foreach ($_POST as $key => $value) {
045f52a3
TO
117 if (substr($key, 0, 6) == "check_") {
118 $batch = explode("_", $key);
6a488035
TO
119 $batchIds[] = $batch[1];
120 }
121 }
a7488080 122 if (!empty($_POST['batch_update'])) {
6a488035
TO
123 CRM_Batch_BAO_Batch::closeReOpen($batchIds, $_POST['batch_update']);
124 }
125 }
96025800 126
6a488035 127}