Merge pull request #10793 from eileenmcnaughton/tpl
[civicrm-core.git] / CRM / Financial / Form / Search.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
7e9e8871 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
0f03f337 6 | Copyright CiviCRM LLC (c) 2004-2017 |
6a488035
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28/**
29 *
30 * @package CRM
0f03f337 31 * @copyright CiviCRM LLC (c) 2004-2017
cded2ebf
SB
32 */
33
34/**
35 * @todo Add comments if possible.
6a488035
TO
36 */
37class CRM_Financial_Form_Search extends CRM_Core_Form {
38
39 public $_batchStatus;
40
00be9182 41 public function preProcess() {
6a488035
TO
42 $this->_batchStatus = CRM_Utils_Request::retrieve('batchStatus', 'Positive', CRM_Core_DAO::$_nullObject, FALSE, NULL);
43 $this->assign('batchStatus', $this->_batchStatus);
44 }
45
e0ef6999
EM
46 /**
47 * @return array
48 */
00be9182 49 public function setDefaultValues() {
6a488035
TO
50 $defaults = array();
51 $status = CRM_Utils_Request::retrieve('status', 'Positive', CRM_Core_DAO::$_nullObject, FALSE, 1);
52 $defaults['batch_update'] = $status;
53 if ($this->_batchStatus) {
54 $defaults['status_id'] = $this->_batchStatus;
55 }
56 return $defaults;
57 }
58
59 public function buildQuickForm() {
353ffa53
TO
60 CRM_Core_Resources::singleton()
61 ->addScriptFile('civicrm', 'packages/jquery/plugins/jquery.redirect.min.js', 0, 'html-header');
6a488035
TO
62 $attributes = CRM_Core_DAO::getAttribute('CRM_Batch_DAO_Batch');
63 $attributes['total']['class'] = $attributes['item_count']['class'] = 'number';
64 $this->add('text', 'title', ts('Batch Name'), $attributes['title']);
e0ef6999 65
fd7abdce 66 $batchStatus = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'status_id', array('labelColumn' => 'name'));
6a488035
TO
67 $this->add(
68 'select',
69 'status_id',
70 ts('Batch Status'),
71 array(
481a74f4 72 '' => ts('- any -'),
fd7abdce
PN
73 array_search('Open', $batchStatus) => ts('Open'),
74 array_search('Closed', $batchStatus) => ts('Closed'),
75 array_search('Exported', $batchStatus) => ts('Exported'),
6a488035 76 ),
045f52a3 77 FALSE
6a488035
TO
78 );
79
80 $this->add(
81 'select',
82 'payment_instrument_id',
536f0e02 83 ts('Payment Method'),
481a74f4 84 array('' => ts('- any -')) + CRM_Contribute_PseudoConstant::paymentInstrument(),
045f52a3 85 FALSE
6a488035
TO
86 );
87
88 $this->add('text', 'total', ts('Total Amount'), $attributes['total']);
89
90 $this->add('text', 'item_count', ts('Number of Items'), $attributes['item_count']);
91 $this->add('text', 'sort_name', ts('Created By'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
92
93 $this->assign('elements', array('status_id', 'title', 'sort_name', 'payment_instrument_id', 'item_count', 'total'));
94 $this->addElement('checkbox', 'toggleSelect', NULL, NULL, array('class' => 'select-rows'));
95 $batchAction = array(
96 'reopen' => ts('Re-open'),
97 'close' => ts('Close'),
98 'export' => ts('Export'),
99 'delete' => ts('Delete'),
100 );
101
102 $this->add('select',
103 'batch_update',
481a74f4 104 ts('Task'),
6a488035
TO
105 array('' => ts('- actions -')) + $batchAction);
106
045f52a3 107 $this->add('submit', 'submit', ts('Go'),
6a488035 108 array(
97e557d7 109 'class' => 'crm-form-submit',
6a488035
TO
110 'id' => 'Go',
111 ));
112
113 $this->addButtons(
114 array(
115 array(
116 'type' => 'refresh',
117 'name' => ts('Search'),
118 'isDefault' => TRUE,
21dfd5f5 119 ),
6a488035
TO
120 )
121 );
122 parent::buildQuickForm();
123 }
124
00be9182 125 public function postProcess() {
6a488035
TO
126 $batchIds = array();
127 foreach ($_POST as $key => $value) {
045f52a3
TO
128 if (substr($key, 0, 6) == "check_") {
129 $batch = explode("_", $key);
6a488035
TO
130 $batchIds[] = $batch[1];
131 }
132 }
a7488080 133 if (!empty($_POST['batch_update'])) {
6a488035
TO
134 CRM_Batch_BAO_Batch::closeReOpen($batchIds, $_POST['batch_update']);
135 }
136 }
96025800 137
6a488035 138}