function __construct() { $this->_columns = array('civicrm_entity_batch' => array('dao' => 'CRM_Core_DAO_EntityBatch', 'filters' => array('batch_id' => array('title' => 'Batch', 'default' => DirectDebit_Utils_Contribution::getLatestBatchId('id desc'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => DirectDebit_Utils_Contribution::getBatchIdTitle('id desc')))), 'civicrm_contribution' => array('dao' => 'CRM_Contribute_DAO_Contribution', 'fields' => array('contribution_id' => array('name' => 'id', 'no_display' => true, 'required' => true), 'contact_name' => array('name' => 'contact_id', 'title' => 'Contributor Name', 'display' => true, 'required' => true), 'contact_id' => array('name' => 'contact_id', 'title' => 'Donor ID', 'display' => true, 'required' => true), 'payment_instrument_id' => array('name' => 'payment_instrument_id', 'title' => 'Payment Method', 'display' => true, 'required' => true), 'receive_date' => array('name' => 'receive_date', 'title' => 'Transaction Date', 'display' => true, 'required' => true), 'contribution_type_id' => array('name' => 'contribution_type_id', 'title' => 'Contribution Type', 'display' => true, 'required' => true), 'trxn_id' => array('name' => 'trxn_id', 'title' => 'Transaction ID', 'display' => true, 'required' => true), 'total_amount' => array('name' => 'total_amount', 'title' => 'Amount', 'display' => true, 'required' => true)))); parent::__construct(); //Set defaults /*if ( is_array( $this->_columns['civicrm_value_direct_debit_details'] ) ) { foreach ( $this->_columns['civicrm_value_direct_debit_details']['fields'] as $field => $values ) { $this->_columns['civicrm_value_direct_debit_details']['fields'][$field]['default'] = true; $this->_columns['civicrm_value_direct_debit_details']['fields'][$field]['required'] = true; } }*/ }
/** * process the form after the input has been submitted and validated * * @access public * @return None */ public function postProcess() { $params = $this->controller->exportValues(); $batchParams = array(); $batchParams['label'] = $params['title']; $batchParams['name'] = CRM_Utils_String::titleToVar($params['title'], 63); $batchParams['description'] = $params['description']; $batchParams['batch_type'] = "Gift Aid"; $session =& CRM_Core_Session::singleton(); $batchParams['created_id'] = $session->get('userID'); $batchParams['created_date'] = date("YmdHis"); require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); require_once 'CRM/Core/BAO/Batch.php'; $createdBatch =& CRM_Core_BAO_Batch::create($batchParams); $batchID = $createdBatch->id; $batchLabel = $batchParams['label']; if ($_POST['contributionRejections']) { $rejectionsCount = @count($_POST['contributionRejections']); $contribution_rejections = @implode(',', $_POST['contributionRejections']); if (!empty($contribution_rejections)) { $sql = "UPDATE civicrm_entity_batch SET batch_id = {$batchID} WHERE entity_id IN ({$contribution_rejections})"; $dao = CRM_Core_DAO::executeQuery($sql); } } $this->_contributionIds = $this->getContributionsList(); require_once 'DirectDebit/Utils/Contribution.php'; list($total, $added, $notAdded) = DirectDebit_Utils_Contribution::addContributionToBatch($this->_contributionIds, $batchID); if ($added <= 0) { // rollback since there were no contributions added, and we might not want to keep an empty batch $transaction->rollback(); $status = ts('Could not create batch "%1", as there were no valid contribution(s) to be added.', array(1 => $batchLabel)); } else { $status = array(ts('Added Contribution(s) to %1', array(1 => $batchLabel)), ts('Total Selected Contribution(s): %1', array(1 => $total))); if ($added) { $status[] = ts('Total Contribution(s) added to batch: %1', array(1 => $added)); } if ($notAdded) { $status[] = ts('Total Contribution(s) already in batch or not valid: %1', array(1 => $notAdded)); } if ($rejectionsCount) { $status[] = ts('Total rejected Contribution(s) moved to batch: %1', array(1 => $rejectionsCount)); } $status = implode('<br/>', $status); } $transaction->commit(); CRM_Core_Session::setStatus($status); $url_array = @explode('&', CIVICRM_DIRECT_DEBIT_BATCH_REPORT_URL); drupal_goto($url_array[0], $url_array[1]); }