Revert "Schema - Fix boolean fields in various tables"
[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() {
44 $attributes = CRM_Core_DAO::getAttribute('CRM_Batch_DAO_Batch');
45 $attributes['total']['class'] = $attributes['item_count']['class'] = 'number';
46 $this->add('text', 'title', ts('Batch Name'), $attributes['title']);
e0ef6999 47
be2fb01f 48 $batchStatus = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'status_id', ['labelColumn' => 'name']);
6a488035
TO
49 $this->add(
50 'select',
51 'status_id',
52 ts('Batch Status'),
be2fb01f 53 [
481a74f4 54 '' => ts('- any -'),
fd7abdce
PN
55 array_search('Open', $batchStatus) => ts('Open'),
56 array_search('Closed', $batchStatus) => ts('Closed'),
57 array_search('Exported', $batchStatus) => ts('Exported'),
be2fb01f 58 ],
045f52a3 59 FALSE
6a488035
TO
60 );
61
62 $this->add(
63 'select',
64 'payment_instrument_id',
536f0e02 65 ts('Payment Method'),
be2fb01f 66 ['' => ts('- any -')] + CRM_Contribute_PseudoConstant::paymentInstrument(),
045f52a3 67 FALSE
6a488035
TO
68 );
69
70 $this->add('text', 'total', ts('Total Amount'), $attributes['total']);
71
72 $this->add('text', 'item_count', ts('Number of Items'), $attributes['item_count']);
73 $this->add('text', 'sort_name', ts('Created By'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
74
be2fb01f
CW
75 $this->assign('elements', ['status_id', 'title', 'sort_name', 'payment_instrument_id', 'item_count', 'total']);
76 $this->addElement('checkbox', 'toggleSelect', NULL, NULL, ['class' => 'select-rows']);
77 $batchAction = [
6a488035
TO
78 'reopen' => ts('Re-open'),
79 'close' => ts('Close'),
80 'export' => ts('Export'),
81 'delete' => ts('Delete'),
be2fb01f 82 ];
6a488035 83
ca0e2dda
PN
84 foreach ($batchAction as $action => $ignore) {
85 if (!CRM_Batch_BAO_Batch::checkBatchPermission($action)) {
86 unset($batchAction[$action]);
87 }
88 }
6a488035
TO
89 $this->add('select',
90 'batch_update',
481a74f4 91 ts('Task'),
be2fb01f 92 ['' => ts('- actions -')] + $batchAction);
6a488035 93
9d0008ba 94 $this->add('xbutton', 'submit', ts('Go'),
be2fb01f 95 [
9d0008ba 96 'type' => 'submit',
97e557d7 97 'class' => 'crm-form-submit',
6a488035 98 'id' => 'Go',
be2fb01f 99 ]);
6a488035
TO
100
101 $this->addButtons(
be2fb01f
CW
102 [
103 [
6a488035
TO
104 'type' => 'refresh',
105 'name' => ts('Search'),
106 'isDefault' => TRUE,
be2fb01f
CW
107 ],
108 ]
6a488035
TO
109 );
110 parent::buildQuickForm();
111 }
112
00be9182 113 public function postProcess() {
be2fb01f 114 $batchIds = [];
6a488035 115 foreach ($_POST as $key => $value) {
045f52a3
TO
116 if (substr($key, 0, 6) == "check_") {
117 $batch = explode("_", $key);
6a488035
TO
118 $batchIds[] = $batch[1];
119 }
120 }
a7488080 121 if (!empty($_POST['batch_update'])) {
6a488035
TO
122 CRM_Batch_BAO_Batch::closeReOpen($batchIds, $_POST['batch_update']);
123 }
124 }
96025800 125
6a488035 126}