/** * process the form after the input has been submitted and validated * * @access public * * @return None */ public function postProcess() { $params = $this->controller->exportValues($this->_name); $params['actualBatchTotal'] = 0; // get the profile information if ($this->_batchInfo['type_id'] == 1) { $this->processContribution($params); } else { $this->processMembership($params); } // update batch to close status $paramValues = array('id' => $this->_batchId, 'status_id' => 2, 'total' => $params['actualBatchTotal']); CRM_Core_BAO_Batch::create($paramValues); // delete from cache table $cacheKeyString = CRM_Core_BAO_Batch::getCacheKeyForBatch($this->_batchId); CRM_Core_BAO_Cache::deleteGroup('batch entry', $cacheKeyString, FALSE); // set success status CRM_Core_Session::setStatus("Your batch has been processed."); CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/batch', 'reset=1&status=2')); }
/** * 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]); }
/** * 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']; require_once 'GiftAid/Utils/Contribution.php'; list($total, $added, $notAdded) = GiftAid_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)); } $status = implode('<br/>', $status); } $transaction->commit(); CRM_Core_Session::setStatus($status); }
/** * Function to process the form * * @access public * * @return None */ public function postProcess() { $params = $this->controller->exportValues($this->_name); if ($this->_action & CRM_Core_Action::DELETE) { CRM_Core_Session::setStatus("Batch has been deleted successfully."); CRM_Core_BAO_Batch::deleteBatch($this->_id); return; } if ($this->_id) { $params['id'] = $this->_id; } else { $session = CRM_Core_Session::singleton(); $params['created_id'] = $session->get('userID'); $params['created_date'] = CRM_Utils_Date::processDate(date("Y-m-d his")); } $batch = CRM_Core_BAO_Batch::create($params); // redirect to batch entry page. $session = CRM_Core_Session::singleton(); if ($this->_action & CRM_Core_Action::ADD) { $session->replaceUserContext(CRM_Utils_System::url('civicrm/batch/entry', "id={$batch->id}&reset=1&action=add")); } else { $session->replaceUserContext(CRM_Utils_System::url('civicrm/batch/entry', "id={$batch->id}&reset=1")); } }
static function importBatch($batchDetails, $rows) { // Step 1: Create batch // Get max batch id //$batch_sql = "SELECT max(id) as max_id FROM civicrm_batch"; // $batch_dao = CRM_Core_DAO::executeQuery($batch_sql); //$batch_dao->fetch(); $batchParams['label'] = $batch_dao->max_id + 1; $batchParams['name'] = CRM_Utils_String::titleToVar($batch_dao->max_id + 1, 63); $session =& CRM_Core_Session::singleton(); $batchParams['created_id'] = $session->get('userID'); $batchParams['created_date'] = date("YmdHis"); // Create the batch require_once 'CRM/Core/BAO/Batch.php'; $createdBatch =& CRM_Core_BAO_Batch::create($batchParams); $batchID = $createdBatch->id; require_once 'CRM/Contact/DAO/Contact.php'; require_once 'CRM/Core/DAO/EntityBatch.php'; $expectedAmt = 0; $expectedEntries = count($rows); $i = 1; foreach ($rows as $key => $row) { $contact =& new CRM_Contact_DAO_Contact(); $contact->external_identifier = $tempdao->VAReference; $contact->find(); $contact->fetch(); // Insert into the quick entries table (Entered rows) $insert_sql = "INSERT INTO " . CIVICRM_MTL_BATCH_ALLOCATION_DETAILS . " SET batch_id = '" . $batchID . "' , weight = '" . $i . "' , name = '" . $contact->display_name . "' , \n amount = '" . $row['grossAmount'] . "' , payment_instrument_id = '" . $batchDetails['payment_instrument_id'] . "'"; $insert_dao = CRM_Core_DAO::executeQuery($insert_sql); // Create the actual contribution using api $params = array('contact_id' => $contact->id, 'contribution_type_id' => $batchDetails['contribution_type_id'], 'total_amount' => $row['grossAmount'], 'receive_date' => $row['donationDate'], 'payment_instrument_id' => $batchDetails['payment_instrument_id'], 'source' => 'Batch Allocation. Batch #' . $batchID, 'version' => 3); $contribution = civicrm_api('Contribution', 'Create', $params); $contribution_id = $contribution['id']; // update campaign id for the contribution, as the api is not saving the campaign against the contribution $campaignUpdateSql = "UPDATE civicrm_contribution SET campaign_id = " . $batchDetails['campaign_id'] . " WHERE id = " . $contribution_id; CRM_Core_DAO::executeQuery($campaignUpdateSql); $expectedAmt += $row['grossAmount']; // Add the contribution to the batch $batchContribution = new CRM_Core_DAO_EntityBatch(); $batchContribution->entity_table = 'civicrm_contribution'; $batchContribution->entity_id = $contribution_id; $batchContribution->batch_id = $batchID; $batchContribution->save(); CRM_Core_DAO::executeQuery("INSERT INTO " . CIVICRM_MTL_BATCH_ENTITY_WEIGHT . " SET entity_id = {$contribution_id} , batch_id = '{$batchID}' , weight = {$i}"); $i++; } $batchDetailsSql = "INSERT INTO " . CIVICRM_MTL_BATCH_DETAILS . " SET entity_id = {$batchID} , expected_entries = '" . $expectedEntries . "' ,\n expected_value = '" . $expectedAmt . "' , batch_status = '3' , batch_type = '" . $batchDetails['batch_type'] . "' , \n payment_instrument_id = '" . $batchDetails['payment_instrument_id'] . "' , expected_posting_date = '" . $batchDetails['expected_posting_date'] . "', \n campaign_id = '" . $batchDetails['campaign_id'] . "', banking_date = '" . $batchDetails['banking_date'] . "' , \n banking_account = '" . $batchDetails['banking_account'] . "' , contribution_type_id = '" . $batchDetails['contribution_type_id'] . "' , \n exclude_from_posting = '" . $batchDetails['exclude_from_posting'] . "'"; CRM_Core_DAO::executeQuery($batchDetailsSql); return $batchID; }