function __construct() { $this->_columns = array('civicrm_entity_batch' => array('dao' => 'CRM_Batch_DAO_EntityBatch', 'filters' => array('batch_id' => array('title' => 'Batch', 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Civigiftaid_Utils_Contribution::getBatchIdTitle('id desc')))), 'civicrm_contribution' => array('dao' => 'CRM_Contribute_DAO_Contribution', 'fields' => array('contribution_id' => array('name' => 'id', 'title' => 'Contribution ID', 'no_display' => true, 'required' => true), 'contact_id' => array('name' => 'contact_id', 'title' => 'Name of Donor', 'no_display' => false, 'required' => true), 'receive_date' => array('name' => 'receive_date', 'title' => 'Contribution Date', 'no_display' => false, 'required' => true))), 'civicrm_address' => array('dao' => 'CRM_Core_DAO_Address', 'grouping' => 'contact-fields', 'fields' => array('street_address' => NULL, 'city' => NULL, 'state_province_id' => array('title' => ts('State/Province')), 'country_id' => array('title' => ts('Country')), 'postal_code' => NULL))); parent::__construct(); // set defaults if (is_array($this->_columns['civicrm_value_gift_aid_submission'])) { foreach ($this->_columns['civicrm_value_gift_aid_submission']['fields'] as $field => $values) { $this->_columns['civicrm_value_gift_aid_submission']['fields'][$field]['default'] = 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['title'] = $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"); $batchParams['status_id'] = 0; $batchMode = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'mode_id', array('labelColumn' => 'name')); $batchParams['mode_id'] = CRM_Utils_Array::key('Manual Batch', $batchMode); $batchParams['modified_date'] = date('YmdHis'); $batchParams['modified_id'] = $session->get('userID'); require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); //require_once 'CRM/Core/BAO/Batch.php'; //version 4.2 require_once 'CRM/Batch/BAO/Batch.php'; $createdBatch = CRM_Batch_BAO_Batch::create($batchParams); $batchID = $createdBatch->id; $batchLabel = $batchParams['title']; // Save current settings for the batch CRM_Civigiftaid_BAO_BatchSettings::create(array('batch_id' => $batchID)); require_once 'CRM/Civigiftaid/Utils/Contribution.php'; list($total, $added, $notAdded) = CRM_Civigiftaid_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 civigiftaid_civicrm_giftAidEligible(&$isEligible, $contactId, $date, $contributionId) { if (!CRM_Civigiftaid_Form_Admin::isGloballyEnabled()) { if ($isEligible != 0) { $isEligible = CRM_Civigiftaid_Utils_Contribution::getContribAmtForEnabledFinanceTypes($contributionId) != 0; } } }
/** * process the form after the input has been submitted and validated * * @access public * @return None */ public function postProcess() { require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); require_once 'CRM/Civigiftaid/Utils/Contribution.php'; list($total, $removed, $notRemoved) = CRM_Civigiftaid_Utils_Contribution::removeContributionFromBatch($this->_contributionIds); if ($removed <= 0) { //$transaction->rollback( ); $status = ts('Could not removed contribution from batch, as there were no valid contribution(s) to be removed.'); } else { $transaction->commit(); $status = ts('Total Selected Contribution(s): %1', array(1 => $total)); CRM_Core_Session::setStatus($status); if ($removed) { $status = ts('Total Contribution(s) removed from batch: %1', array(1 => $removed)); } if ($notRemoved) { $status = ts('Total Contribution(s) not removed from batch: %1', array(1 => $notRemoved)); } } CRM_Core_Session::setStatus($status); }
/** * Alter the rows for display * * @param array $rows */ public function alterDisplay(&$rows) { $entryFound = FALSE; require_once 'CRM/Contact/DAO/Contact.php'; foreach ($rows as $rowNum => $row) { // i.e. remove row from report if it has financial type ineligible for Gift Aid if (FALSE === $this->hasEligibleFinancialType($row)) { unset($rows[$rowNum]); continue; } // handle contribution status id if (array_key_exists('civicrm_contribution_contact_id', $row)) { if ($value = $row['civicrm_contribution_contact_id']) { $contact = new CRM_Contact_DAO_Contact(); $contact->id = $value; $contact->find(TRUE); $rows[$rowNum]['civicrm_contribution_contact_id'] = $contact->display_name; $url = CRM_Utils_System::url("civicrm/contact/view", 'reset=1&cid=' . $value, $this->_absoluteUrl); $rows[$rowNum]['civicrm_contribution_contact_id_link'] = $url; $rows[$rowNum]['civicrm_contribution_contact_id_hover'] = ts("View Contact Summary for this Contact."); } if (isset($row['civicrm_line_item_amount'])) { $rows[$rowNum]['civicrm_line_item_gift_aid_amount'] = CRM_Civigiftaid_Utils_Contribution::calculateGiftAidAmt($row['civicrm_line_item_amount']); } if (!empty($row['civicrm_line_item_entity_table'])) { $rows[$rowNum]['civicrm_line_item_entity_table'] = CRM_Civigiftaid_Utils_Contribution::getLineItemName($row['civicrm_line_item_entity_table']); } $entryFound = TRUE; } // handle State/Province Codes if (array_key_exists('civicrm_address_state_province_id', $row)) { if ($value = $row['civicrm_address_state_province_id']) { $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant::stateProvince($value, FALSE); } $entryFound = TRUE; } // handle Country Codes if (array_key_exists('civicrm_address_country_id', $row)) { if ($value = $row['civicrm_address_country_id']) { $rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant::country($value, FALSE); } $entryFound = TRUE; } // skip looking further in rows, if first row itself doesn't // have the column we need if (!$entryFound) { break; } } }