function __construct() { $config = CRM_Core_Config::singleton(); $campaignEnabled = in_array("CiviCampaign", $config->enableComponents); if ($campaignEnabled) { $getCampaigns = CRM_Campaign_BAO_Campaign::getPermissionedCampaigns(NULL, NULL, TRUE, FALSE, TRUE); $this->activeCampaigns = $getCampaigns['campaigns']; asort($this->activeCampaigns); } $this->_columns = array('civicrm_contact' => array('dao' => 'CRM_Contact_DAO_Contact', 'fields' => array('sort_name' => array('title' => ts('Donor Name'), 'required' => TRUE, 'no_repeat' => TRUE), 'id' => array('no_display' => TRUE, 'required' => TRUE)), 'filters' => array('sort_name' => array('title' => ts('Donor Name'), 'operator' => 'like'), 'id' => array('title' => ts('Contact ID'), 'no_display' => TRUE, 'type' => CRM_Utils_Type::T_INT)), 'order_bys' => array('sort_name' => array('title' => ts('Last Name, First Name'), 'default' => '1', 'default_weight' => '0', 'default_order' => 'ASC')), 'grouping' => 'contact-fields'), 'civicrm_email' => array('dao' => 'CRM_Core_DAO_Email', 'fields' => array('email' => array('title' => ts('Donor Email'), 'default' => TRUE, 'no_repeat' => TRUE)), 'grouping' => 'contact-fields'), 'civicrm_phone' => array('dao' => 'CRM_Core_DAO_Phone', 'fields' => array('phone' => array('title' => ts('Donor Phone'), 'default' => TRUE, 'no_repeat' => TRUE)), 'grouping' => 'contact-fields'), 'civicrm_contact_honor' => array('dao' => 'CRM_Contact_DAO_Contact', 'fields' => array('sort_name_honor' => array('title' => ts('Honoree Name'), 'name' => 'sort_name', 'alias' => 'contacthonor', 'default' => FALSE, 'no_repeat' => TRUE), 'id_honor' => array('no_display' => TRUE, 'title' => ts('Honoree ID'), 'name' => 'id', 'alias' => 'contacthonor', 'required' => TRUE))), 'civicrm_email_honor' => array('dao' => 'CRM_Core_DAO_Email', 'fields' => array('email_honor' => array('title' => ts('Honoree Email'), 'name' => 'email', 'alias' => 'emailhonor', 'default' => FALSE, 'no_repeat' => TRUE)), 'grouping' => 'contact-fields'), 'civicrm_contribution' => array('dao' => 'CRM_Contribute_DAO_Contribution', 'fields' => array('contribution_id' => array('name' => 'id', 'no_display' => TRUE, 'required' => TRUE), 'contribution_type_id' => array('title' => ts('Contribution Type'), 'default' => TRUE), 'contribution_status_id' => array('title' => ts('Contribution Status')), 'payment_instrument_id' => array('title' => ts('Payment Type')), 'trxn_id' => NULL, 'receive_date' => array('default' => TRUE), 'receipt_date' => NULL, 'honor_type_id' => array('title' => ts('Honor Type'), 'default' => FALSE), 'fee_amount' => NULL, 'net_amount' => NULL, 'total_amount' => array('title' => ts('Amount'), 'required' => TRUE, 'statistics' => array('sum' => ts('Amount')))), 'filters' => array('receive_date' => array('operatorType' => CRM_Report_Form::OP_DATE), 'contribution_type_id' => array('title' => ts('Contribution Type'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::contributionType(), 'type' => CRM_Utils_Type::T_INT), 'payment_instrument_id' => array('title' => ts('Payment Type'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::paymentInstrument(), 'type' => CRM_Utils_Type::T_INT), 'contribution_status_id' => array('title' => ts('Contribution Status'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::contributionStatus(), 'default' => array(1), 'type' => CRM_Utils_Type::T_INT), 'total_amount' => array('title' => ts('Contribution Amount'))), 'order_bys' => array('contribution_type_id' => array('title' => ts('Contribution Type')), 'contribution_status_id' => array('title' => ts('Contribution Status')), 'payment_instrument_id' => array('title' => ts('Payment Instrument'))), 'grouping' => 'contri-fields'), 'civicrm_group' => array('dao' => 'CRM_Contact_DAO_GroupContact', 'alias' => 'cgroup', 'filters' => array('gid' => array('name' => 'group_id', 'title' => ts('Group'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'group' => TRUE, 'options' => CRM_Core_PseudoConstant::group(), 'type' => CRM_Utils_Type::T_INT))), 'civicrm_contribution_ordinality' => array('dao' => 'CRM_Contribute_DAO_Contribution', 'alias' => 'cordinality', 'filters' => array('ordinality' => array('title' => ts('Contribution Ordinality'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => array(0 => 'First by Contributor', 1 => 'Second or Later by Contributor'), 'type' => CRM_Utils_Type::T_INT))), 'civicrm_note' => array('dao' => 'CRM_Core_DAO_Note', 'fields' => array('contribution_note' => array('name' => 'note', 'title' => ts('Contribution Note'))), 'filters' => array('note' => array('name' => 'note', 'title' => ts('Contribution Note'), 'operator' => 'like', 'type' => CRM_Utils_Type::T_STRING)))) + $this->addAddressFields(FALSE); $this->_tagFilter = TRUE; // Don't show Batch display column and filter unless batches are being used $this->_closedBatches = CRM_Core_BAO_Batch::getBatches(); if (!empty($this->_closedBatches)) { $this->_columns['civicrm_batch']['dao'] = 'CRM_Core_DAO_Batch'; $this->_columns['civicrm_batch']['fields']['batch_id'] = array('name' => 'id', 'title' => ts('Batch Name')); $this->_columns['civicrm_batch']['filters']['bid'] = array('name' => 'id', 'title' => ts('Batch Name'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => $this->_closedBatches); $this->_columns['civicrm_entity_batch']['dao'] = 'CRM_Core_DAO_EntityBatch'; $this->_columns['civicrm_entity_batch']['fields']['entity_batch_id'] = array('name' => 'batch_id', 'default' => TRUE, 'no_display' => TRUE); } if ($campaignEnabled && !empty($this->activeCampaigns)) { $this->_columns['civicrm_contribution']['fields']['campaign_id'] = array('title' => ts('Campaign'), 'default' => 'false'); $this->_columns['civicrm_contribution']['filters']['campaign_id'] = array('title' => ts('Campaign'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => $this->activeCampaigns); $this->_columns['civicrm_contribution']['order_bys']['campaign_id'] = array('title' => ts('Campaign')); } parent::__construct(); }
static function getBatchList() { $sortMapper = array(0 => 'batch.title', 1 => 'batch.type_id', 2 => '', 3 => 'batch.total', 4 => 'batch.status_id', 5 => ''); $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer'); $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0; $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25; $sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : NULL; $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc'; $params = $_POST; if ($sort && $sortOrder) { $params['sortBy'] = $sort . ' ' . $sortOrder; } $params['page'] = $offset / $rowCount + 1; $params['rp'] = $rowCount; // get batch list $batches = CRM_Core_BAO_Batch::getBatchListSelector($params); $iFilteredTotal = $iTotal = $params['total']; $selectorElements = array('batch_name', 'batch_type', 'item_count', 'total_amount', 'status', 'created_by', 'links'); echo CRM_Utils_JSON::encodeDataTableSelector($batches, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); CRM_Utils_System::civiExit(); }
/** * 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')); }
/** * This function is a wrapper for ajax batch selector * * @param array $params associated array for params record id. * * @return array $batchList associated array of batch list * @access public */ public function getBatchListSelector(&$params) { // format the params $params['offset'] = ($params['page'] - 1) * $params['rp']; $params['rowCount'] = $params['rp']; $params['sort'] = CRM_Utils_Array::value('sortBy', $params); // get batches $batches = CRM_Core_BAO_Batch::getBatchList($params); // add total $params['total'] = CRM_Core_BAO_Batch::getBatchCount($params); // format params and add links $batchList = array(); if (!empty($batches)) { foreach ($batches as $id => $value) { $batchList[$id]['batch_name'] = $value['title']; $batchList[$id]['batch_type'] = $value['batch_type']; $batchList[$id]['item_count'] = $value['item_count']; $batchList[$id]['total_amount'] = CRM_Utils_Money::format($value['total']); $batchList[$id]['status'] = $value['batch_status']; $batchList[$id]['created_by'] = $value['created_by']; $batchList[$id]['links'] = $value['action']; } return $batchList; } }
/** * 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]); }
/** * 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")); } }
/** * add all the elements shared between contribute search and advnaced search * * @access public * * @return void * @static */ static function buildSearchForm(&$form) { //added contribution source $form->addElement('text', 'contribution_source', ts('Contribution Source'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution', 'source')); CRM_Core_Form_Date::buildDateRange($form, 'contribution_date', 1, '_low', '_high', ts('From'), FALSE, FALSE); $form->add('text', 'contribution_amount_low', ts('From'), array('size' => 8, 'maxlength' => 8)); $form->addRule('contribution_amount_low', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('9.99', ' '))), 'money'); $form->add('text', 'contribution_amount_high', ts('To'), array('size' => 8, 'maxlength' => 8)); $form->addRule('contribution_amount_high', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money'); //adding select option for curreny type -- CRM-4711 $form->add('select', 'contribution_currency_type', ts('Currency Type'), array('' => ts('- select -')) + CRM_Core_PseudoConstant::currencySymbols('name')); $form->add('select', 'contribution_type_id', ts('Contribution Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionType()); $form->add('select', 'contribution_page_id', ts('Contribution Page'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionPage()); $form->add('select', 'contribution_payment_instrument_id', ts('Payment Instrument'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument()); $form->add('select', 'contribution_pcp_made_through_id', ts('Personal Campaign Page'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::pcPage()); $status = array(); $statusValues = CRM_Core_OptionGroup::values("contribution_status"); // Remove status values that are only used for recurring contributions or pledges (In Progress, Overdue). unset($statusValues['5']); unset($statusValues['6']); foreach ($statusValues as $key => $val) { $status[] = $form->createElement('advcheckbox', $key, NULL, $val); } $form->addGroup($status, 'contribution_status_id', ts('Contribution Status')); // add null checkboxes for thank you and receipt $form->addElement('checkbox', 'contribution_thankyou_date_isnull', ts('Thank-you date not set?')); $form->addElement('checkbox', 'contribution_receipt_date_isnull', ts('Receipt not sent?')); //add fields for honor search $form->addElement('text', 'contribution_in_honor_of', ts("In Honor Of")); $form->addElement('checkbox', 'contribution_test', ts('Find Test Contributions?')); $form->addElement('checkbox', 'contribution_pay_later', ts('Find Pay Later Contributions?')); //add field for transaction ID search $form->addElement('text', 'contribution_transaction_id', ts("Transaction ID")); $form->addElement('checkbox', 'contribution_recurring', ts('Find Recurring Contributions?')); $form->addElement('checkbox', 'contribution_recurring_isnull', ts('Find Non Recurring Contributions?')); $form->addElement('text', 'contribution_check_number', ts('Check Number')); //add field for pcp display in roll search $form->addYesNo('contribution_pcp_display_in_roll', ts('Personal Campaign Page Honor Roll?')); // add all the custom searchable fields $contribution = array('Contribution'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $contribution); if ($groupDetails) { $form->assign('contributeGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, FALSE, TRUE); } } } CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'contribution_campaign_id'); // add batch select $batches = CRM_Core_BAO_Batch::getBatches(); if (!empty($batches)) { $form->add('select', 'contribution_batch_id', ts('Batch Name'), array('' => ts('- select -')) + $batches); } $form->assign('validCiviContribute', 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']; 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); }
/** * takes an associative array and creates a contribution object * * @param array $params (reference ) an assoc array of name/value pairs * @param array $ids the array that holds all the db ids * * @return object CRM_Contribute_BAO_Contribution object * @access public * @static */ static function &create(&$params, &$ids) { // FIXME: a cludgy hack to fix the dates to MySQL format $dateFields = array('receive_date', 'cancel_date', 'receipt_date', 'thankyou_date'); foreach ($dateFields as $df) { if (isset($params[$df])) { $params[$df] = CRM_Utils_Date::isoToMysql($params[$df]); } } if (CRM_Utils_Array::value('contribution', $ids) && !CRM_Utils_Array::value('softID', $params)) { if ($softID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionSoft', $ids['contribution'], 'id', 'contribution_id')) { $params['softID'] = $softID; } } $transaction = new CRM_Core_Transaction(); // delete the soft credit record if no soft credit contact ID AND no PCP is set in the form if (CRM_Utils_Array::value('contribution', $ids) && (!CRM_Utils_Array::value('soft_credit_to', $params) && !CRM_Utils_Array::value('pcp_made_through_id', $params)) && CRM_Utils_Array::value('softID', $params)) { $softCredit = new CRM_Contribute_DAO_ContributionSoft(); $softCredit->id = $params['softID']; $softCredit->delete(); } $contribution = self::add($params, $ids); if (is_a($contribution, 'CRM_Core_Error')) { $transaction->rollback(); return $contribution; } $params['contribution_id'] = $contribution->id; if (CRM_Utils_Array::value('custom', $params) && is_array($params['custom'])) { CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_contribution', $contribution->id); } $session = CRM_Core_Session::singleton(); if (CRM_Utils_Array::value('note', $params)) { $noteParams = array('entity_table' => 'civicrm_contribution', 'note' => $params['note'], 'entity_id' => $contribution->id, 'contact_id' => $session->get('userID'), 'modified_date' => date('Ymd')); if (!$noteParams['contact_id']) { $noteParams['contact_id'] = $params['contact_id']; } CRM_Core_BAO_Note::add($noteParams, CRM_Utils_Array::value('note', $ids)); } // make entry in batch entity batch table if (CRM_Utils_Array::value('batch_id', $params)) { $entityParams = array('batch_id' => $params['batch_id'], 'entity_table' => 'civicrm_contribution', 'entity_id' => $contribution->id); // in some update cases we need to get extra fields - ie an update that doesn't pass in all these params $titleFields = array('contact_id', 'total_amount', 'currency', 'contribution_type_id'); $retrieverequired = 0; foreach ($titleFields as $titleField) { if (!isset($contribution->{$titleField})) { $retrieverequired = 1; break; } } if ($retrieverequired == 1) { $contribution->find(true); } CRM_Core_BAO_Batch::addBatchEntity($entityParams); } // check if activity record exist for this contribution, if // not add activity $activity = new CRM_Activity_DAO_Activity(); $activity->source_record_id = $contribution->id; $activity->activity_type_id = CRM_Core_OptionGroup::getValue('activity_type', 'Contribution', 'name'); if (!$activity->find()) { CRM_Activity_BAO_Activity::addActivity($contribution, 'Offline'); } // Handle soft credit and / or link to personal campaign page if (CRM_Utils_Array::value('soft_credit_to', $params) || CRM_Utils_Array::value('pcp_made_through_id', $params)) { $csParams = array(); if ($id = CRM_Utils_Array::value('softID', $params)) { $csParams['id'] = $params['softID']; } $csParams['contribution_id'] = $contribution->id; // If pcp_made_through_id set, we define soft_credit_to contact based on selected PCP, // else use passed soft_credit_to if (CRM_Utils_Array::value('pcp_made_through_id', $params)) { $csParams['pcp_display_in_roll'] = $params['pcp_display_in_roll'] ? 1 : 0; foreach (array('pcp_roll_nickname', 'pcp_personal_note') as $val) { $csParams[$val] = $params[$val]; } $csParams['pcp_id'] = CRM_Utils_Array::value('pcp_made_through_id', $params); $csParams['contact_id'] = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $csParams['pcp_id'], 'contact_id'); } else { $csParams['contact_id'] = $params['soft_credit_to']; $csParams['pcp_id'] = ''; } // first stage: we register whole amount as credited to given person $csParams['amount'] = $contribution->total_amount; self::addSoftContribution($csParams); } $transaction->commit(); // do not add to recent items for import, CRM-4399 if (!CRM_Utils_Array::value('skipRecentView', $params)) { $url = CRM_Utils_System::url('civicrm/contact/view/contribution', "action=view&reset=1&id={$contribution->id}&cid={$contribution->contact_id}&context=home"); // in some update cases we need to get extra fields - ie an update that doesn't pass in all these params $titleFields = array('contact_id', 'total_amount', 'currency', 'contribution_type_id'); $retrieverequired = 0; foreach ($titleFields as $titleField) { if (!isset($contribution->{$titleField})) { $retrieverequired = 1; break; } } if ($retrieverequired == 1) { $contribution->find(true); } $contributionTypes = CRM_Contribute_PseudoConstant::contributionType(); $title = CRM_Contact_BAO_Contact::displayName($contribution->contact_id) . ' - (' . CRM_Utils_Money::format($contribution->total_amount, $contribution->currency) . ' ' . ' - ' . $contributionTypes[$contribution->contribution_type_id] . ')'; $recentOther = array(); if (CRM_Core_Permission::checkActionPermission('CiviContribute', CRM_Core_Action::UPDATE)) { $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/contribution', "action=update&reset=1&id={$contribution->id}&cid={$contribution->contact_id}&context=home"); } if (CRM_Core_Permission::checkActionPermission('CiviContribute', CRM_Core_Action::DELETE)) { $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/contribution', "action=delete&reset=1&id={$contribution->id}&cid={$contribution->contact_id}&context=home"); } // add the recently created Contribution CRM_Utils_Recent::add($title, $url, $contribution->id, 'Contribution', $contribution->contact_id, NULL, $recentOther); } return $contribution; }
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; }