3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2017
35 * This class provides the functionality to delete a group of
36 * contributions. This class provides functionality for the actual
39 class CRM_Financial_Form_Export
extends CRM_Core_Form
{
42 * The financial batch id, used when editing the field
49 * Financial batch ids.
51 protected $_batchIds = array();
56 protected $_exportStatusId;
61 protected $_exportFormat;
64 * Download export File.
66 protected $_downloadFile = TRUE;
69 * Build all the data structures needed to build the form.
71 public function preProcess() {
72 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
74 // this mean it's a batch action
76 if (!empty($_GET['batch_id'])) {
78 $batchIds = explode(',', $_GET['batch_id']);
79 foreach ($batchIds as $batchId) {
80 CRM_Utils_Type
::validate($batchId, 'Positive');
83 $this->_batchIds
= $_GET['batch_id'];
84 $this->set('batchIds', $this->_batchIds
);
87 $this->_batchIds
= $this->get('batchIds');
89 if (!empty($_GET['export_format']) && in_array($_GET['export_format'], array('IIF', 'CSV'))) {
90 $this->_exportFormat
= $_GET['export_format'];
94 $this->_batchIds
= $this->_id
;
97 $this->_exportStatusId
= CRM_Core_PseudoConstant
::getKey('CRM_Batch_DAO_Batch', 'status_id', 'Exported');
99 // check if batch status is valid, do not allow exported batches to export again
100 $batchStatus = CRM_Batch_BAO_Batch
::getBatchStatuses($this->_batchIds
);
102 foreach ($batchStatus as $batchStatusId) {
103 if ($batchStatusId == $this->_exportStatusId
) {
104 $url = CRM_Core_Session
::singleton()->readUserContext();
105 CRM_Core_Error
::statusBounce(ts('You cannot export batches which have already been exported.'), $url);
109 $session = CRM_Core_Session
::singleton();
110 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/financial/financialbatches',
111 "reset=1&batchStatus={$this->_exportStatusId}"));
115 * Build the form object.
117 public function buildQuickForm() {
118 // this mean it's a batch action
119 if (!empty($this->_batchIds
)) {
120 $batchNames = CRM_Batch_BAO_Batch
::getBatchNames($this->_batchIds
);
121 $this->assign('batchNames', $batchNames);
122 // Skip building the form if we already have batches and an export format
123 if ($this->_exportFormat
) {
124 $this->postProcess();
128 $optionTypes = array(
129 'IIF' => ts('Export to IIF'),
130 'CSV' => ts('Export to CSV'),
133 $this->addRadio('export_format', NULL, $optionTypes, NULL, '<br/>', TRUE);
139 'name' => ts('Export Batch'),
140 'spacing' => ' ',
145 'name' => ts('Cancel'),
152 * Process the form after the input has been submitted and validated.
154 public function postProcess() {
155 if (!$this->_exportFormat
) {
156 $params = $this->exportValues();
157 $this->_exportFormat
= $params['export_format'];
161 $batchIds = array($this->_id
);
163 elseif (!empty($this->_batchIds
)) {
164 $batchIds = explode(',', $this->_batchIds
);
166 // Recalculate totals
167 $totals = CRM_Batch_BAO_Batch
::batchTotals($batchIds);
169 // build batch params
170 $session = CRM_Core_Session
::singleton();
171 $batchParams['modified_date'] = date('YmdHis');
172 $batchParams['modified_id'] = $session->get('userID');
173 $batchParams['status_id'] = $this->_exportStatusId
;
175 foreach ($batchIds as $batchId) {
176 $batchParams['id'] = $batchId;
178 $batchParams = array_merge($batchParams, $totals[$batchId]);
179 CRM_Batch_BAO_Batch
::create($batchParams);
182 CRM_Batch_BAO_Batch
::exportFinancialBatch($batchIds, $this->_exportFormat
, $this->_downloadFile
);