Skip to content
Snippets Groups Projects
Commit 37c78286 authored by colemanw's avatar colemanw
Browse files

Remove giftaid CRM-9794

----------------------------------------
* CRM-9794:
  http://issues.civicrm.org/jira/browse/CRM-9794
parent 617c5251
No related branches found
No related tags found
No related merge requests found
Showing
with 0 additions and 2302 deletions
<?xml version="1.0" encoding="iso-8859-1" ?>
<CustomData>
<CustomGroups>
<CustomGroup>
<name>Gift_Aid_Declaration</name>
<title>Gift Aid Declaration</title>
<extends>Individual</extends>
<style>Tab</style>
<collapse_display>0</collapse_display>
<help_pre></help_pre>
<help_post></help_post>
<weight>1</weight>
<is_active>1</is_active>
<table_name>civicrm_value_gift_aid_declaration</table_name>
<is_multiple>1</is_multiple>
<collapse_adv_display>0</collapse_adv_display>
<created_date>2010-10-03 02:28:19</created_date>
</CustomGroup>
<CustomGroup>
<name>Gift_Aid</name>
<title>Gift Aid</title>
<extends>Contribution</extends>
<style>Inline</style>
<collapse_display>1</collapse_display>
<help_pre>Stores the values that are submitted in the Gift Aid Report</help_pre>
<help_post></help_post>
<weight>2</weight>
<is_active>1</is_active>
<table_name>civicrm_value_gift_aid_submission</table_name>
<is_multiple>0</is_multiple>
<collapse_adv_display>0</collapse_adv_display>
<created_date>2010-10-03 02:32:44</created_date>
</CustomGroup>
</CustomGroups>
<CustomFields>
<CustomField>
<name>Eligible_for_Gift_Aid</name>
<label>Eligible for Gift Aid?</label>
<data_type>Boolean</data_type>
<html_type>Radio</html_type>
<is_required>1</is_required>
<is_searchable>0</is_searchable>
<is_search_range>0</is_search_range>
<weight>1</weight>
<is_active>1</is_active>
<is_view>0</is_view>
<text_length>255</text_length>
<note_columns>60</note_columns>
<note_rows>4</note_rows>
<column_name>eligible_for_gift_aid</column_name>
<custom_group_name>Gift_Aid_Declaration</custom_group_name>
</CustomField>
<CustomField>
<name>Start_Date</name>
<label>Start Date</label>
<data_type>Date</data_type>
<html_type>Select Date</html_type>
<is_required>1</is_required>
<is_searchable>0</is_searchable>
<is_search_range>0</is_search_range>
<weight>2</weight>
<is_active>1</is_active>
<is_view>0</is_view>
<text_length>255</text_length>
<date_format>dd-mm-yy</date_format>
<note_columns>60</note_columns>
<note_rows>4</note_rows>
<column_name>start_date</column_name>
<custom_group_name>Gift_Aid_Declaration</custom_group_name>
</CustomField>
<CustomField>
<name>End_Date</name>
<label>End Date</label>
<data_type>Date</data_type>
<html_type>Select Date</html_type>
<is_required>0</is_required>
<is_searchable>0</is_searchable>
<is_search_range>0</is_search_range>
<weight>3</weight>
<is_active>1</is_active>
<is_view>0</is_view>
<text_length>255</text_length>
<date_format>dd-mm-yy</date_format>
<note_columns>60</note_columns>
<note_rows>4</note_rows>
<column_name>end_date</column_name>
<custom_group_name>Gift_Aid_Declaration</custom_group_name>
</CustomField>
<CustomField>
<name>Reason_Ended</name>
<label>Reason Ended</label>
<data_type>String</data_type>
<html_type>Radio</html_type>
<is_required>0</is_required>
<is_searchable>0</is_searchable>
<is_search_range>0</is_search_range>
<weight>5</weight>
<is_active>1</is_active>
<is_view>0</is_view>
<text_length>32</text_length>
<note_columns>60</note_columns>
<note_rows>4</note_rows>
<column_name>reason_ended</column_name>
<option_group_name>reason_ended</option_group_name>
<custom_group_name>Gift_Aid_Declaration</custom_group_name>
</CustomField>
<CustomField>
<name>Source</name>
<label>Source</label>
<data_type>String</data_type>
<html_type>Text</html_type>
<is_required>0</is_required>
<is_searchable>0</is_searchable>
<is_search_range>0</is_search_range>
<weight>6</weight>
<is_active>1</is_active>
<is_view>0</is_view>
<text_length>32</text_length>
<note_columns>60</note_columns>
<note_rows>4</note_rows>
<column_name>source</column_name>
<custom_group_name>Gift_Aid_Declaration</custom_group_name>
</CustomField>
<CustomField>
<name>Notes</name>
<label>Notes</label>
<data_type>Memo</data_type>
<html_type>TextArea</html_type>
<is_required>0</is_required>
<is_searchable>0</is_searchable>
<is_search_range>0</is_search_range>
<weight>7</weight>
<attributes>rows=4, cols=60</attributes>
<is_active>1</is_active>
<is_view>0</is_view>
<text_length>255</text_length>
<note_columns>60</note_columns>
<note_rows>4</note_rows>
<column_name>notes</column_name>
<custom_group_name>Gift_Aid_Declaration</custom_group_name>
</CustomField>
<CustomField>
<name>Eligible_for_Gift_Aid</name>
<label>Eligible for Gift Aid?</label>
<data_type>Boolean</data_type>
<html_type>Radio</html_type>
<is_required>1</is_required>
<is_searchable>0</is_searchable>
<is_search_range>0</is_search_range>
<weight>1</weight>
<is_active>1</is_active>
<is_view>0</is_view>
<text_length>255</text_length>
<note_columns>60</note_columns>
<note_rows>4</note_rows>
<column_name>eligible_for_gift_aid</column_name>
<custom_group_name>Gift_Aid</custom_group_name>
</CustomField>
<CustomField>
<name>Contributor_Name</name>
<label>Contributor Name</label>
<data_type>String</data_type>
<html_type>Text</html_type>
<is_required>0</is_required>
<is_searchable>1</is_searchable>
<is_search_range>0</is_search_range>
<weight>2</weight>
<is_active>1</is_active>
<is_view>1</is_view>
<text_length>255</text_length>
<note_columns>60</note_columns>
<note_rows>4</note_rows>
<column_name>name</column_name>
<custom_group_name>Gift_Aid</custom_group_name>
</CustomField>
<CustomField>
<name>Address</name>
<label>Address</label>
<data_type>Memo</data_type>
<html_type>TextArea</html_type>
<is_required>0</is_required>
<is_searchable>1</is_searchable>
<is_search_range>0</is_search_range>
<weight>4</weight>
<attributes>rows=4, cols=60</attributes>
<is_active>1</is_active>
<is_view>1</is_view>
<text_length>255</text_length>
<note_columns>60</note_columns>
<note_rows>4</note_rows>
<column_name>address</column_name>
<custom_group_name>Gift_Aid</custom_group_name>
</CustomField>
<CustomField>
<name>Post_Code</name>
<label>Post Code</label>
<data_type>String</data_type>
<html_type>Text</html_type>
<is_required>0</is_required>
<is_searchable>1</is_searchable>
<is_search_range>0</is_search_range>
<weight>6</weight>
<is_active>1</is_active>
<is_view>1</is_view>
<text_length>16</text_length>
<note_columns>60</note_columns>
<note_rows>4</note_rows>
<column_name>post_code</column_name>
<custom_group_name>Gift_Aid</custom_group_name>
</CustomField>
<CustomField>
<name>Amount</name>
<label>Amount</label>
<data_type>Money</data_type>
<html_type>Text</html_type>
<is_required>0</is_required>
<is_searchable>1</is_searchable>
<is_search_range>1</is_search_range>
<weight>7</weight>
<is_active>1</is_active>
<is_view>1</is_view>
<text_length>255</text_length>
<note_columns>60</note_columns>
<note_rows>4</note_rows>
<column_name>amount</column_name>
<custom_group_name>Gift_Aid</custom_group_name>
</CustomField>
<CustomField>
<name>Gift_Aid_Amount</name>
<label>Gift Aid Amount</label>
<data_type>Money</data_type>
<html_type>Text</html_type>
<is_required>0</is_required>
<is_searchable>1</is_searchable>
<is_search_range>1</is_search_range>
<weight>8</weight>
<is_active>1</is_active>
<is_view>1</is_view>
<text_length>255</text_length>
<note_columns>60</note_columns>
<note_rows>4</note_rows>
<column_name>gift_aid_amount</column_name>
<custom_group_name>Gift_Aid</custom_group_name>
</CustomField>
</CustomFields>
<OptionGroups>
<OptionGroup>
<name>reason_ended</name>
<label>Reason Ended</label>
<is_active>1</is_active>
</OptionGroup>
</OptionGroups>
<OptionValues>
<OptionValue>
<label>Contact Declined</label>
<value>Contact Declined</value>
<name>Contact_Declined</name>
<is_default>0</is_default>
<weight>2</weight>
<is_optgroup>0</is_optgroup>
<is_reserved>0</is_reserved>
<is_active>1</is_active>
<option_group_name>reason_ended</option_group_name>
</OptionValue>
<OptionValue>
<label>HMRC Declined</label>
<value>HMRC Declined</value>
<name>HMRC_Declined</name>
<is_default>0</is_default>
<weight>1</weight>
<is_optgroup>0</is_optgroup>
<is_reserved>0</is_reserved>
<is_active>1</is_active>
<option_group_name>reason_ended</option_group_name>
</OptionValue>
</OptionValues>
<ProfileGroups>
<ProfileGroup>
<is_active>1</is_active>
<group_type>Contribution,Individual,Contact</group_type>
<title>Gift Aid</title>
<add_captcha>0</add_captcha>
<is_map>0</is_map>
<is_edit_link>0</is_edit_link>
<is_uf_link>0</is_uf_link>
<is_update_dupe>2</is_update_dupe>
<name>Gift_Aid</name>
<created_date>2010-10-03 14:54:18</created_date>
<is_proximity_search>0</is_proximity_search>
</ProfileGroup>
</ProfileGroups>
<ProfileFields>
<ProfileField>
<field_name>custom.civicrm_value_gift_aid_submission.eligible_for_gift_aid</field_name>
<is_active>1</is_active>
<is_view>0</is_view>
<is_required>1</is_required>
<weight>1</weight>
<help_post>&lt;p&gt;By selecting 'Yes' above you are confirming that
&lt;ol&gt;
&lt;li&gt;you are a UK taxpayer and&lt;/li&gt;
&lt;li&gt;the amount of income and/or capital gains tax you pay is at least as much as we will reclaim on your donations in this tax year.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;b&gt;About Gift Aid&lt;/b&gt;&lt;p&gt;
&lt;p&gt;Gift Aid increases the value of donations to charities by allowing them to reclaim basic rate tax on your gift. We would like to reclaim gift aid on your behalf. We can only reclaim Gift Aid if you are a UK taxpayer. Please confirm that you are a eligible for gift aid above. &lt;a href="http://www.hmrc.gov.uk/individuals/giving/gift-aid.htm"&gt;More about Gift Aid&lt;/a&gt;.&lt;/p&gt;</help_post>
<visibility>User and User Admin Only</visibility>
<in_selector>0</in_selector>
<is_searchable>0</is_searchable>
<label>Can we reclaim gift aid on your donation?</label>
<field_type>Contribution</field_type>
<profile_group_name>Gift_Aid</profile_group_name>
</ProfileField>
<ProfileField>
<field_name>first_name</field_name>
<is_active>1</is_active>
<is_view>0</is_view>
<is_required>1</is_required>
<weight>2</weight>
<help_post></help_post>
<visibility>User and User Admin Only</visibility>
<in_selector>0</in_selector>
<is_searchable>0</is_searchable>
<label>First Name</label>
<field_type>Individual</field_type>
<profile_group_name>Gift_Aid</profile_group_name>
</ProfileField>
<ProfileField>
<field_name>last_name</field_name>
<is_active>1</is_active>
<is_view>0</is_view>
<is_required>1</is_required>
<weight>3</weight>
<help_post></help_post>
<visibility>User and User Admin Only</visibility>
<in_selector>0</in_selector>
<is_searchable>0</is_searchable>
<label>Last Name</label>
<field_type>Individual</field_type>
<profile_group_name>Gift_Aid</profile_group_name>
</ProfileField>
<ProfileField>
<field_name>street_address</field_name>
<is_active>1</is_active>
<is_view>0</is_view>
<is_required>1</is_required>
<weight>4</weight>
<help_post></help_post>
<visibility>User and User Admin Only</visibility>
<in_selector>0</in_selector>
<is_searchable>0</is_searchable>
<label>Street Address</label>
<field_type>Contact</field_type>
<profile_group_name>Gift_Aid</profile_group_name>
</ProfileField>
<ProfileField>
<field_name>supplemental_address_1</field_name>
<is_active>1</is_active>
<is_view>0</is_view>
<is_required>0</is_required>
<weight>5</weight>
<help_post></help_post>
<visibility>User and User Admin Only</visibility>
<in_selector>0</in_selector>
<is_searchable>0</is_searchable>
<label>Supplemental Address 1</label>
<field_type>Contact</field_type>
<profile_group_name>Gift_Aid</profile_group_name>
</ProfileField>
<ProfileField>
<field_name>supplemental_address_2</field_name>
<is_active>1</is_active>
<is_view>0</is_view>
<is_required>0</is_required>
<weight>6</weight>
<help_post></help_post>
<visibility>User and User Admin Only</visibility>
<in_selector>0</in_selector>
<is_searchable>0</is_searchable>
<label>Supplemental Address 2</label>
<field_type>Contact</field_type>
<profile_group_name>Gift_Aid</profile_group_name>
</ProfileField>
<ProfileField>
<field_name>city</field_name>
<is_active>1</is_active>
<is_view>0</is_view>
<is_required>0</is_required>
<weight>7</weight>
<help_post></help_post>
<visibility>User and User Admin Only</visibility>
<in_selector>0</in_selector>
<is_searchable>0</is_searchable>
<label>City</label>
<field_type>Contact</field_type>
<profile_group_name>Gift_Aid</profile_group_name>
</ProfileField>
<ProfileField>
<field_name>state_province</field_name>
<is_active>1</is_active>
<is_view>0</is_view>
<is_required>0</is_required>
<weight>8</weight>
<help_post></help_post>
<visibility>User and User Admin Only</visibility>
<in_selector>0</in_selector>
<is_searchable>0</is_searchable>
<label>County</label>
<field_type>Contact</field_type>
<profile_group_name>Gift_Aid</profile_group_name>
</ProfileField>
<ProfileField>
<field_name>postal_code</field_name>
<is_active>1</is_active>
<is_view>0</is_view>
<is_required>1</is_required>
<weight>9</weight>
<help_post></help_post>
<visibility>User and User Admin Only</visibility>
<in_selector>0</in_selector>
<is_searchable>0</is_searchable>
<label>Post code</label>
<field_type>Contact</field_type>
<profile_group_name>Gift_Aid</profile_group_name>
</ProfileField>
</ProfileFields>
</CustomData>
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.1 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2011 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2011
* $Id$
*
*/
require_once 'CRM/Contribute/Form/Task.php';
/**
* This class provides the functionality to delete a group of
* contacts. This class provides functionality for the actual
* addition of contacts to groups.
*/
require_once 'CRM/Utils/String.php';
class GiftAid_Form_Task_AddToGiftAid extends CRM_Contribute_Form_Task {
protected $_id = NULL;
/**
* build all the data structures needed to build the form
*
* @return void
* @access public
*/ function preProcess() {
parent::preProcess();
require_once 'GiftAid/Utils/Contribution.php';
list($total, $added, $alreadyAdded, $notValid) = GiftAid_Utils_Contribution::_validateContributionToBatch($this->_contributionIds);
$this->assign('selectedContributions', $total);
$this->assign('totalAddedContributions', count($added));
$this->assign('alreadyAddedContributions', count($alreadyAdded));
$this->assign('notValidContributions', count($notValid));
// get details of contribution that will be added to this batch.
$contributionsAddedRows = array();
$contributionsAddedRows = GiftAid_Utils_Contribution::getContributionDetails($added);
$this->assign('contributionsAddedRows', $contributionsAddedRows);
// get details of contribution thatare already added to this batch.
$contributionsAlreadyAddedRows = array();
$contributionsAlreadyAddedRows = GiftAid_Utils_Contribution::getContributionDetails($alreadyAdded);
$this->assign('contributionsAlreadyAddedRows', $contributionsAlreadyAddedRows);
}
/**
* Build the form
*
* @access public
*
* @return void
*/
function buildQuickForm() {
$attributes = CRM_Core_DAO::getAttribute('CRM_Batch_DAO_Batch');
$this->add('text', 'title',
ts('Batch Label'),
$attributes['label'], TRUE
);
$this->addRule('title', ts('Label already exists in Database.'),
'objectExists', array('CRM_Batch_DAO_Batch', $this->_id, 'label')
);
$this->add('textarea', 'description', ts('Description:') . ' ',
$attributes['description']
);
$defaults = array('label' => ts('Gift Aid Batch %1 (%2)'),
'%1' => date('d-m-Y'),
'%2' => date('H:i:s'),
);
$this->setDefaults($defaults);
$this->addDefaultButtons(ts('Add to batch'));
}
/**
* 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_Batch_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);
}
//end of function
}
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.1 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2011 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2011
* $Id$
*
*/
require_once 'CRM/Report/Form.php';
require_once 'GiftAid/Utils/Contribution.php';
class GiftAid_Report_Form_Contribute_GiftAid extends CRM_Report_Form {
protected $_addressField = FALSE;
protected $_customGroupExtends = array('Contribution'); 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' => GiftAid_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,
),
),
),
);
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;
}
}
}
function select() {
$select = array();
$this->_columnHeaders = array();
foreach ($this->_columns as $tableName => $table) {
if (array_key_exists('fields', $table)) {
foreach ($table['fields'] as $fieldName => $field) {
if (CRM_Utils_Array::value('required', $field) ||
CRM_Utils_Array::value($fieldName, $this->_params['fields'])
) {
if ($tableName == 'civicrm_address') {
$this->_addressField = TRUE;
}
elseif ($tableName == 'civicrm_email') {
$this->_emailField = TRUE;
}
// only include statistics columns if set
if (CRM_Utils_Array::value('statistics', $field)) {
foreach ($field['statistics'] as $stat => $label) {
switch (strtolower($stat)) {
case 'sum':
$select[] = "SUM({$field['dbAlias']}) as {$tableName}_{$fieldName}_{$stat}";
$this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label;
$this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['type'] = $field['type'];
$this->_statFields[] = "{$tableName}_{$fieldName}_{$stat}";
break;
case 'count':
$select[] = "COUNT({$field['dbAlias']}) as {$tableName}_{$fieldName}_{$stat}";
$this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label;
$this->_statFields[] = "{$tableName}_{$fieldName}_{$stat}";
break;
case 'avg':
$select[] = "ROUND(AVG({$field['dbAlias']}),2) as {$tableName}_{$fieldName}_{$stat}";
$this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['type'] = $field['type'];
$this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label;
$this->_statFields[] = "{$tableName}_{$fieldName}_{$stat}";
break;
}
}
}
else {
$select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
$this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = $field['title'];
$this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array::value('type', $field);
}
}
}
}
}
$this->_select = "SELECT " . implode(', ', $select) . " ";
}
function from() {
$this->_from = "
FROM civicrm_entity_batch {$this->_aliases['civicrm_entity_batch']}
INNER JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']}
ON {$this->_aliases['civicrm_entity_batch']}.entity_table = 'civicrm_contribution' AND
{$this->_aliases['civicrm_entity_batch']}.entity_id = {$this->_aliases['civicrm_contribution']}.id";
}
function where() {
parent::where();
if (empty($this->_where)) {
$this->_where = "WHERE value_gift_aid_submission_civireport.amount IS NOT NULL";
}
else {
$this->_where .= " AND value_gift_aid_submission_civireport.amount IS NOT NULL";
}
}
function statistics(&$rows) {
$statistics = parent::statistics($rows);
$select = "
SELECT SUM( value_gift_aid_submission_civireport.amount ) as amount,
SUM( value_gift_aid_submission_civireport.gift_aid_amount ) as giftaid_amount";
$sql = "{$select} {$this->_from} {$this->_where}";
$dao = CRM_Core_DAO::executeQuery($sql);
if ($dao->fetch()) {
$statistics['counts']['amount'] = array('value' => $dao->amount,
'title' => 'Total Amount',
'type' => CRM_Utils_Type::T_MONEY,
);
$statistics['counts']['giftaid'] = array('value' => $dao->giftaid_amount,
'title' => 'Total Gift Aid Amount',
'type' => CRM_Utils_Type::T_MONEY,
);
}
return $statistics;
}
function postProcess() {
parent::postProcess();
}
}
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.1 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2011 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2011
* $Id$
*
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2011
* $Id$
*
*/
class GiftAid_Utils_Contribution {
/**
* Given an array of contributionIDs, add them to a batch
*
* @param array $contributionIDs (reference ) the array of contribution ids to be added
* @param int $batchID - the batchID to be added to
*
* @return array (total, added, notAdded) ids of contributions added to the batch
* @access public
* @static
*/
static
function addContributionToBatch($contributionIDs, $batchID) {
$date = date('YmdHis');
$contributionsAdded = array();
$contributionsNotAdded = array();
require_once "GiftAid/Utils/GiftAid.php";
require_once "CRM/Contribute/BAO/Contribution.php";
require_once 'CRM/Core/DAO/EntityBatch.php';
require_once "CRM/Core/BAO/Address.php";
require_once "CRM/Contact/BAO/Contact.php";
require_once "CRM/Utils/Address.php";
$charityColumnExists = CRM_Core_DAO::checkFieldExists('civicrm_value_gift_aid_submission', 'charity');
foreach ($contributionIDs as $contributionID) {
$batchContribution = &new CRM_Batch_DAO_EntityBatch();
$batchContribution->entity_table = 'civicrm_contribution';
$batchContribution->entity_id = $contributionID;
// check if the selected contribution id already in a batch
// if not, add to batchContribution else keep the count of contributions that are not added
if ($batchContribution->find(TRUE)) {
$contributionsNotAdded[] = $contributionID;
continue;
}
// get additional info
// get contribution details from Contribution using contribution id
$params = array('id' => $contributionID);
CRM_Contribute_BAO_Contribution::retrieve($params, $contribution, $ids);
$contactId = $contribution['contact_id'];
// check if contribution is valid for gift aid
if (GiftAid_Utils_GiftAid::isEligibleForGiftAid($contactId, $contribution['receive_date'], $contributionID)) {
$batchContribution->batch_id = $batchID;
$batchContribution->save();
// get display name
$displayName = CRM_Contact_BAO_Contact::displayName($contactId);
// get Address & Postal Code from Address
$params = array('contact_id' => $contactId,
'is_primary' => 1,
);
$address = CRM_Core_BAO_Address::getValues($params);
$address = $address[1];
//adds all address lines to the report
$fullFormatedAddress = CRM_Utils_Address::format($address);;
// get gift aid amount
$giftAidAmount = self::_calculateGiftAidAmt($contribution['total_amount']);
// FIXME: check if there is customTable method
$query = "
INSERT INTO civicrm_value_gift_aid_submission
(entity_id, eligible_for_gift_aid, name, address, post_code, amount, gift_aid_amount)
VALUES
( %1, 1, %2, %3, %4, %5, %6 )
ON DUPLICATE KEY UPDATE
name = %2,
address = %3,
post_code = %4,
amount = %5,
gift_aid_amount = %6
";
$sqlParams = array(1 => array($contributionID, 'Integer'),
2 => array($displayName, 'String'),
3 => array($fullFormatedAddress, 'String'),
4 => array($address['postal_code'], 'String'),
5 => array($contribution['total_amount'], 'Money'),
6 => array($giftAidAmount, 'Money'),
);
CRM_Core_DAO::executeQuery($query, $sqlParams);
$contributionsAdded[] = $contributionID;
}
else {
$contributionsNotAdded[] = $contributionID;
}
}
if (!empty($contributionsAdded)) {
// if there is any extra work required to be done for contributions that are batched,
// should be done via hook
GiftAid_Utils_Hook::batchContributions($batchID, $contributionsAdded);
}
return array(count($contributionIDs),
count($contributionsAdded),
count($contributionsNotAdded),
);
}
/*
this function calculate the gift aid amount
formula used is: (basic rate of year*contributed amount)/(100-basic rate of year)
*/
function _calculateGiftAidAmt($contributionAmount) {
$basicRate = variable_get('giftaid_value');
return (($contributionAmount * $basicRate) / 100);
//$basicRate = 20;
//return (( $basicRate * $contributionAmount ) / ( 100- $basicRate ));
}
/*
* this function check contribution is valid for giftaid or not:
* 1 - if contribution_id already inserted in batch_contribution
* 2 - if contributions are not valid for gift aid
*/
static
function _validateContributionToBatch(&$contributionIDs) {
$contributionsAdded = array();
$contributionsAlreadyAdded = array();
$contributionsNotValid = array();
require_once "GiftAid/Utils/GiftAid.php";
require_once "CRM/Core/DAO/EntityBatch.php";
require_once "CRM/Contribute/BAO/Contribution.php";
foreach ($contributionIDs as $contributionID) {
$batchContribution = &new CRM_Batch_DAO_EntityBatch();
$batchContribution->entity_table = 'civicrm_contribution';
$batchContribution->entity_id = $contributionID;
// check if the selected contribution id already in a batch
// if not, increment $numContributionsAdded else keep the count of contributions that are already added
if (!$batchContribution->find(TRUE)) {
// get contact_id, & contribution receive date from Contribution using contribution id
$params = array('id' => $contributionID);
CRM_Contribute_BAO_Contribution::retrieve($params, $defaults, $ids);
// check if contribution is not valid for gift aid, increment $numContributionsNotValid
if (GiftAid_Utils_GiftAid::isEligibleForGiftAid($defaults['contact_id'], $defaults['receive_date'], $contributionID)) {
$contributionsAdded[] = $contributionID;
}
else {
$contributionsNotValid[] = $contributionID;
}
}
else {
$contributionsAlreadyAdded[] = $contributionID;
}
}
return array(count($contributionIDs),
$contributionsAdded,
$contributionsAlreadyAdded,
$contributionsNotValid,
);
}
/*
* this function returns the array of batchID & title
*/
static
function getBatchIdTitle($orderBy = 'id') {
$query = "SELECT * FROM civicrm_batch ORDER BY " . $orderBy;
$dao = &CRM_Core_DAO::executeQuery($query);
$result = array();
while ($dao->fetch()) {
$result[$dao->id] = $dao->id . " - " . $dao->label;
}
return $result;
}
/*
* this function returns the array of contribution
* @param array $contributionIDs an array of contribution ids
* @return array $result an array of contributions
*/
static
function getContributionDetails($contributionIds) {
if (empty($contributionIds)) {
return;
}
$query = " SELECT contribution.id, contact.id contact_id, contact.display_name, contribution.total_amount, contribution_type.name,
contribution.source, contribution.receive_date, batch.label FROM civicrm_contribution contribution
LEFT JOIN civicrm_contact contact ON ( contribution.contact_id = contact.id )
LEFT JOIN civicrm_contribution_type contribution_type ON ( contribution_type.id = contribution.contribution_type_id )
LEFT JOIN civicrm_entity_batch entity_batch ON ( entity_batch.entity_id = contribution.id )
LEFT JOIN civicrm_batch batch ON ( batch.id = entity_batch.batch_id )
WHERE contribution.id IN (" . implode(',', $contributionIds) . ")";
$dao = CRM_Core_DAO::executeQuery($query);
$result = array();
while ($dao->fetch()) {
$result[$dao->id]['contact_id'] = $dao->contact_id;
$result[$dao->id]['display_name'] = $dao->display_name;
$result[$dao->id]['total_amount'] = $dao->total_amount;
$result[$dao->id]['financial_account'] = $dao->name;
$result[$dao->id]['source'] = $dao->source;
$result[$dao->id]['receive_date'] = $dao->receive_date;
$result[$dao->id]['batch'] = $dao->label;
}
return $result;
}
}
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.1 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2011 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2011
* $Id$
*
*/
require_once 'CRM/Core/DAO.php';
require_once 'CRM/Core/Error.php';
require_once 'CRM/Utils/Array.php';
require_once 'CRM/Utils/Date.php';
require_once 'GiftAid/Utils/Hook.php';
class GiftAid_Utils_GiftAid {
/**
* How long a positive Gift Aid declaration is valid for under HMRC rules (years).
*/
CONST DECLARATION_LIFETIME = 3;
/**
* Get Gift Aid declaration record for Individual.
*
* @param int $contactID - the Individual for whom we retrieve declaration
* @param date $date - date for which we retrieve declaration (in ISO date format)
* - e.g. the date for which you would like to check if the contact has a valid
* declaration
*
* @return array - declaration record as associative array,
* else empty array.
* @access public
* @static
*/
static
function getDeclaration($contactID, $date = NULL, $charity = NULL) {
static $charityColumnExists = NULL;
if (is_null($date)) {
$date = date('Y-m-d H:i:s');
}
if ($charityColumnExists === NULL) {
$charityColumnExists = CRM_Core_DAO::checkFieldExists('civicrm_value_gift_aid_declaration', 'charity');
}
$charityClause = '';
if ($charityColumnExists) {
$charityClause = $charity ? " AND charity='{$charity}'" : " AND ( charity IS NULL OR charity = '' )";
}
// Get current declaration: start_date in past, end_date in future or null
// - if > 1, pick latest end_date
$currentDeclaration = array();
$sql = "
SELECT id, eligible_for_gift_aid, start_date, end_date, reason_ended, source, notes
FROM civicrm_value_gift_aid_declaration
WHERE entity_id = %1 AND start_date <= %2 AND (end_date > %2 OR end_date IS NULL) {$charityClause}
ORDER BY end_date DESC";
$sqlParams = array(1 => array($contactID, 'Integer'),
2 => array(CRM_Utils_Date::isoToMysql($date), 'Timestamp'),
);
// allow query to be modified via hook
GiftAid_Utils_Hook::alterDeclarationQuery($sql, $sqlParams);
$dao = CRM_Core_DAO::executeQuery($sql, $sqlParams);
if ($dao->fetch()) {
$currentDeclaration['id'] = $dao->id;
$currentDeclaration['eligible_for_gift_aid'] = $dao->eligible_for_gift_aid;
$currentDeclaration['start_date'] = $dao->start_date;
$currentDeclaration['end_date'] = $dao->end_date;
$currentDeclaration['reason_ended'] = $dao->reason_ended;
$currentDeclaration['source'] = $dao->source;
$currentDeclaration['notes'] = $dao->notes;
}
//CRM_Core_Error::debug('currentDeclaration', $currentDeclaration);
return $currentDeclaration;
}
static
function isEligibleForGiftAid($contactID, $date = NULL, $contributionID = NULL) {
$charity = NULL;
if ($contributionID &&
CRM_Core_DAO::checkFieldExists('civicrm_value_gift_aid_submission', 'charity')
) {
$charity = CRM_Core_DAO::singleValueQuery('SELECT charity FROM civicrm_value_gift_aid_submission WHERE entity_id = %1',
array(1 => array($contributionID, 'Integer'))
);
}
$declaration = self::getDeclaration($contactID, $date, $charity);
if (isset($declaration['eligible_for_gift_aid'])) {
$isEligible = ($declaration['eligible_for_gift_aid'] == 1);
}
// hook can alter the eligibility if needed
GiftAid_Utils_Hook::giftAidEligible($isEligible, $contactID, $date, $contributionID);
return $isEligible;
}
/**
* Create / update Gift Aid declaration records on Individual when
* "Eligible for Gift Aid" field on Contribution is updated.
* See http://wiki.civicrm.org/confluence/display/CRM/Gift+aid+implementation
*
* TODO change arguments to single $param array
*
* @param array $params - fields to store in declaration:
* - entity_id: the Individual for whom we will create/update declaration
* - eligible_for_gift_aid: 1 for positive declaration, 0 for negative
* - start_date: start date of declaration (in ISO date format)
* - end_date: end date of declaration (in ISO date format)
*
* @return array TODO
* @access public
* @static
*/
static
function setDeclaration($params) {
static $charityColumnExists = NULL;
if (!CRM_Utils_Array::value('entity_id', $params)) {
return (array(
'is_error' => 1,
'error_message' => 'entity_id is required',
));
}
$charity = CRM_Utils_Array::value('charity', $params);
// Retrieve existing declarations for this user.
$currentDeclaration = GiftAid_Utils_GiftAid::getDeclaration($params['entity_id'],
$params['start_date'],
$charity
);
$charityClause = '';
if ($charityColumnExists === NULL) {
$charityColumnExists = CRM_Core_DAO::checkFieldExists('civicrm_value_gift_aid_declaration', 'charity');
}
if ($charityColumnExists) {
$charityClause = $charity ? " AND charity='{$charity}'" : " AND ( charity IS NULL OR charity = '' )";
}
// Get future declarations: start_date in future, end_date in future or null
// - if > 1, pick earliest start_date
$futureDeclaration = array();
$sql = "
SELECT id, eligible_for_gift_aid, start_date, end_date
FROM civicrm_value_gift_aid_declaration
WHERE entity_id = %1 AND start_date > %2 AND (end_date > %2 OR end_date IS NULL) {$charityClause}
ORDER BY start_date";
$dao = CRM_Core_DAO::executeQuery($sql, array(
1 => array($params['entity_id'], 'Integer'),
2 => array(CRM_Utils_Date::isoToMysql($params['start_date']), 'Timestamp'),
));
if ($dao->fetch()) {
$futureDeclaration['id'] = $dao->id;
$futureDeclaration['eligible_for_gift_aid'] = $dao->eligible_for_gift_aid;
$futureDeclaration['start_date'] = $dao->start_date;
$futureDeclaration['end_date'] = $dao->end_date;
}
#CRM_Core_Error::debug('futureDeclaration', $futureDeclaration);
$specifiedEndTimestamp = NULL;
if (CRM_Utils_Array::value('end_date', $params)) {
$specifiedEndTimestamp = strtotime(CRM_Utils_Array::value('end_date', $params));
}
// Calculate new_end_date for negative declaration
// - new_end_date =
// if end_date specified then (specified end_date)
// else (start_date of first future declaration if any, else null)
$futureTimestamp = NULL;
if (CRM_Utils_Array::value('start_date', $futureDeclaration)) {
$futureTimestamp = strtotime(CRM_Utils_Array::value('start_date', $futureDeclaration));
}
if ($specifiedEndTimestamp) {
$endTimestamp = $specifiedEndTimestamp;
}
elseif ($futureTimestamp) {
$endTimestamp = $futureTimestamp;
}
else {
$endTimestamp = NULL;
}
if ($params['eligible_for_gift_aid'] == 1) {
if (!$currentDeclaration) {
// There is no current declaration so create new.
GiftAid_Utils_GiftAid::_insertDeclaration($params, $endTimestamp);
}
elseif ($currentDeclaration['eligible_for_gift_aid'] == 1 && $endTimestamp) {
// - if current positive, extend its end_date to new_end_date.
$updateParams = array(
'id' => $currentDeclaration['id'],
'end_date' => date('YmdHis', $endTimestamp),
);
GiftAid_Utils_GiftAid::_updateDeclaration($updateParams);
}
elseif ($currentDeclaration['eligible_for_gift_aid'] == 0) {
// - if current negative, set its end_date to now and create new ending new_end_date.
$updateParams = array(
'id' => $currentDeclaration['id'],
'end_date' => CRM_Utils_Date::isoToMysql($params['start_date']),
);
GiftAid_Utils_GiftAid::_updateDeclaration($updateParams);
GiftAid_Utils_GiftAid::_insertDeclaration($params, $endTimestamp);
}
}
elseif ($params['eligible_for_gift_aid'] == 0) {
if (!$currentDeclaration) {
// There is no current declaration so create new.
GiftAid_Utils_GiftAid::_insertDeclaration($params, $endTimestamp);
}
elseif ($currentDeclaration['eligible_for_gift_aid'] == 1) {
// - if current positive, set its end_date to now and create new ending new_end_date.
$updateParams = array(
'id' => $currentDeclaration['id'],
'end_date' => CRM_Utils_Date::isoToMysql($params['start_date']),
);
GiftAid_Utils_GiftAid::_updateDeclaration($updateParams);
GiftAid_Utils_GiftAid::_insertDeclaration($params, $endTimestamp);
}
// - if current negative, leave as is.
}
return array(
'is_error' => 0,
// TODO 'inserted' => array(id => A, entity_id = B, ...),
// TODO 'updated' => array(id => A, entity_id = B, ...),
);
}
/*
* Private helper function for setDeclaration
* - update a declaration record.
*/
static
function _updateDeclaration($params) {
// Update (currently we only need to update end_date but can make generic)
// $params['end_date'] should by in date('YmdHis') format
$sql = "
UPDATE civicrm_value_gift_aid_declaration
SET end_date = %1
WHERE id = %2";
$dao = CRM_Core_DAO::executeQuery($sql, array(
1 => array($params['end_date'], 'Timestamp'),
2 => array($params['id'], 'Integer'),
));
}
/*
* Private helper function for setDeclaration
* - insert a declaration record.
*/
static
function _insertDeclaration($params, $endTimestamp) {
static $charityColumnExists = NULL;
$charityClause = '';
if ($charityColumnExists === NULL) {
$charityColumnExists = CRM_Core_DAO::checkFieldExists('civicrm_value_gift_aid_declaration', 'charity');
}
if (!CRM_Utils_Array::value('charity', $params)) {
$charityColumnExists = FALSE;
}
if ($charityColumnExists) {
$charityCol = ', charity';
$charityVal = ', %8';
}
// Insert
$sql = "
INSERT INTO civicrm_value_gift_aid_declaration (entity_id, eligible_for_gift_aid, start_date, end_date, reason_ended, source, notes {$charityCol})
VALUES (%1, %2, %3, %4, %5, %6, %7 {$charityVal})";
$queryParams = array(
1 => array($params['entity_id'], 'Integer'),
2 => array($params['eligible_for_gift_aid'], 'Integer'),
3 => array(CRM_Utils_Date::isoToMysql($params['start_date']), 'Timestamp'),
4 => array(($endTimestamp ? date('YmdHis', $endTimestamp) : ''), 'Timestamp'),
5 => array(CRM_Utils_Array::value('reason_ended', $params, ''), 'String'),
6 => array(CRM_Utils_Array::value('source', $params, ''), 'String'),
7 => array(CRM_Utils_Array::value('notes', $params, ''), 'String'),
);
if ($charityColumnExists) {
$queryParams[8] = array(CRM_Utils_Array::value('charity', $params, ''), 'String');
}
$dao = CRM_Core_DAO::executeQuery($sql, $queryParams);
}
}
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.1 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2011 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CiviCRM_Hook
* @copyright CiviCRM LLC (c) 2004-2011
* $Id: $
*
*/
abstract class GiftAid_Utils_Hook {
static $_nullObject = NULL;
/**
* We only need one instance of this object. So we use the singleton
* pattern and cache the instance in this variable
*
* @var object
* @static
*/
static private $_singleton = NULL;
/**
* Constructor and getter for the singleton instance
*
* @return instance of $config->userHookClass
*/
static function singleton() {
if (self::$_singleton == NULL) {
$config = CRM_Core_Config::singleton();
$class = $config->userHookClass;
require_once (str_replace('_', DIRECTORY_SEPARATOR, $config->userHookClass) . '.php');
self::$_singleton = new $class();
}
return self::$_singleton;
}
abstract function invoke($numParams,
&$arg1, &$arg2, &$arg3, &$arg4, &$arg5,
$fnSuffix
);
/**
* This hook allows filtering contributions for gift-aid
*
* @param bool $isEligible eligibilty already detected if getDeclaration() method.
* @param integer $contactID contact being checked
* @param date $date date gift-aid declaration was made on
* @param $contributionID contribution id if any being referred
*
* @access public
*/
static
function giftAidEligible(&$isEligible, $contactID, $date = NULL, $contributionID = NULL) {
return self::singleton()->invoke(4, $isEligible, $contactID, $date, $contributionID, self::$_nullObject, 'civicrm_giftAidEligible');
}
/**
* This hook allows doing any extra processing for contributions that are added to a batch.
*
* @param $contributionsAdded contribution ids that have been batched
*
* @access public
*/
static
function batchContributions($batchID, $contributionsAdded) {
return self::singleton()->invoke(2, $batchID, $contributionsAdded, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_batchContributions');
}
/**
* This hook allows altering getDeclaration() query
*
* @param string $query declaration query
* @param array $queryParams params required by query
*
* @access public
*/
static
function alterDeclarationQuery(&$query, &$queryParams) {
return self::singleton()->invoke(2, $query, $queryParams, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_alterDeclarationQuery');
}
}
Gift Aid module for UK Charity
Required:
Drupal 7
CiviCRM 4.1
<?php
/**
* Form function, called by drupal_get_form()
* in giftaid_menu().
*/
function giftaid_form($form, &$form_state) {
$form['giftaid_value'] = array(
'#type' => 'textfield',
'#title' => t('Basic Rate'),
'#default_value' => variable_get('giftaid_value'),
'#size' => 2,
'#maxlength' => 2,
'#description' => t('The basic rate for Gift Aid that system used.'),
'#required' => TRUE,
);
return system_settings_form($form);
}
function giftaid_form_validate($form, &$form_state) {
$giftaid_value = $form_state['values']['giftaid_value'];
if (!is_numeric($giftaid_value)) {
form_set_error('giftaid_value', t('You must enter an integer for the basic rate.'));
}
elseif ($giftaid_value <= 0) {
form_set_error('giftaid_value', t('The basic rate must be positive.'));
}
}
name = CiviCRM GiftAid
description = Gift Aid Support for CiviCRM
version = 4.1
dependencies[] = civicrm
package = CiviCRM
core = 7.x
php = 5.2
<?php
//setting the default value
function civicrm_giftaid_install() {
variable_set('giftaid_value', 28);
}
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.1 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2011 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2011
* $Id$
*
*/
define('CIVICRM_GIFTAID_TASKID', 1435);
/**
* Implements hook_menu().
*/
function civicrm_giftaid_menu() {
$items = array();
$items['admin/config/system/gift-aid'] = array(
'title' => 'Gift Aid Settings',
'description' => 'Configure Gift Aid Basic Rate',
'page callback' => 'drupal_get_form',
'page arguments' => array('giftaid_form'),
'access arguments' => array('access administration pages'),
'type' => MENU_NORMAL_ITEM,
'file' => 'civicrm_giftaid.admin.inc',
);
return $items;
}
function civicrm_giftaid_civicrm_config(&$config) {
$template = &CRM_Core_Smarty::singleton();
$giftAidRoot = dirname(__FILE__);
$giftAidDir = $giftAidRoot . DIRECTORY_SEPARATOR . 'templates';
if (is_array($template->template_dir)) {
array_unshift($template->template_dir, $giftAidDir);
}
else {
$template->template_dir = array($giftAidDir, $template->template_dir);
}
// also fix php include path
$include_path = $giftAidRoot . PATH_SEPARATOR . get_include_path();
set_include_path($include_path);
}
function civicrm_giftaid_civicrm_searchTasks($objectType, &$tasks) {
if ($objectType == 'contribution') {
$tasks[CIVICRM_GIFTAID_TASKID] = array('title' => ts('Add to Gift Aid batch'),
'class' => 'GiftAid_Form_Task_AddToGiftAid',
'result' => FALSE,
);
}
}
/*
* Implementation of hook_civicrm_custom
* Create / update Gift Aid declaration records on Individual when
* "Eligible for Gift Aid" field on Contribution is updated.
*/
function civicrm_giftaid_civicrm_custom($op, $groupID, $entityID, &$params) {
/* TODO && $op != 'edit' */
if ($op != 'create'
) {
return;
}
require_once 'CRM/Core/DAO.php';
$tableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $groupID, 'table_name', 'id');
if ($tableName == 'civicrm_value_gift_aid_submission') {
// Iterate through $params to get new declaration value
$newStatus = NULL;
if (!is_array($params) || empty($params)) {
return;
}
foreach ($params as $field) {
if ($field['column_name'] == 'eligible_for_gift_aid') {
$newStatus = $field['value'];
break;
}
}
if (is_null($newStatus)) {
return;
}
// Get contactID.
$sql = "SELECT contact_id, receive_date FROM civicrm_contribution WHERE id = %1";
$dao = CRM_Core_DAO::executeQuery($sql, array(1 => array($entityID, 'Integer')));
if ($dao->fetch()) {
$contactID = $dao->contact_id;
$contributionDate = $dao->receive_date;
}
if ($contactID) {
require_once 'GiftAid/Utils/GiftAid.php';
$params = array(
'entity_id' => $contactID,
'eligible_for_gift_aid' => $newStatus,
'start_date' => $contributionDate,
);
GiftAid_Utils_GiftAid::setDeclaration($params);
}
}
}
/*
* Implementation of hook_civicrm_validate
* Validate set of Gift Aid declaration records on Individual,
* from multi-value custom field edit form:
* - check end > start,
* - check for overlaps between declarations.
*/
function civicrm_giftaid_civicrm_validate($formName, &$fields, &$files, &$form) {
$errors = array();
if ($formName == 'CRM_Contact_Form_CustomData') {
$groupID = $form->getVar('_groupID');
require_once 'CRM/Core/DAO.php';
$tableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $groupID, 'table_name', 'id');
if ($tableName == 'civicrm_value_gift_aid_declaration') {
// Assemble multi-value field values from custom_X_Y into
// array $declarations of sets of values as column_name => value
$sql = "SELECT id, column_name FROM civicrm_custom_field WHERE custom_group_id = %1";
$dao = CRM_Core_DAO::executeQuery($sql, array(1 => array($groupID, 'Integer')));
$columnNames = array();
while ($dao->fetch()) {
$columnNames[$dao->id] = $dao->column_name;
}
$declarations = array();
foreach ($fields as $name => $value) {
if (preg_match('/^custom_(\d+)_(-?\d+)$/', $name, $matches)) {
$columnName = CRM_Utils_Array::value($matches[1], $columnNames);
if ($columnName) {
$declarations[$matches[2]][$columnName]['value'] = $value;
$declarations[$matches[2]][$columnName]['name'] = $name;
}
}
}
require_once 'CRM/Utils/Date.php';
// Iterate through each distinct pair of declarations, checking for overlap.
foreach ($declarations as $id1 => $values1) {
$start1 = CRM_Utils_Date::processDate($values1['start_date']['value']);
if ($values1['end_date']['value'] == '') {
$end1 = '25000101000000';
}
else {
$end1 = CRM_Utils_Date::processDate($values1['end_date']['value']);
}
if ($values1['end_date']['value'] != '' && $start1 >= $end1) {
$errors[$values1['end_date']['name']] = 'End date must be later than start date.';
continue;
}
$charity1 = NULL;
if (array_key_exists('charity', $values1)) {
$charity1 = CRM_Utils_Array::value('value', $values1['charity']);
}
foreach ($declarations as $id2 => $values2) {
$charity2 = NULL;
if (array_key_exists('charity', $values2)) {
$charity2 = CRM_Utils_Array::value('value', $values2['charity']);
}
if (($id2 <= $id1) || ($charity1 != $charity2)) {
continue;
}
$start2 = CRM_Utils_Date::processDate($values2['start_date']['value']);
if ($values2['end_date']['value'] == '') {
$end2 = '25000101000000';
}
else {
$end2 = CRM_Utils_Date::processDate($values2['end_date']['value']);
}
if ($start1 < $end2 && $end1 > $start2) {
$message = 'This declaration overlaps with the one from ' . $values2['start_date']['value'];
if ($values2['end_date']['value']) {
$message .= ' to ' . $values2['end_date']['value'];
}
$errors[$values1['start_date']['name']] = $message;
$message = 'This declaration overlaps with the one from ' . $values1['start_date']['value'];
if ($values1['end_date']['value']) {
$message .= ' to ' . $values1['end_date']['value'];
}
$errors[$values2['start_date']['name']] = $message;
}
}
}
}
}
if (!empty($errors)) {
return $errors;
}
}
{*
+--------------------------------------------------------------------+
| CiviCRM version 4.1 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2011 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*}
<div class="crm-block crm-form-block crm-export-form-block">
<h2>{ts}Add To Gift Aid{/ts}</h2>
<div class="help">
<p>{ts}Use this form to submit Gift Aid contributions. Note that this action is irreversible, i.e. you cannot take contributions out of a batch once they have been added.{/ts}</p>
</div>
<table class="form-layout">
<tr>
<td>
<table class="form-layout">
<tr><td class="label">{$form.title.label}</td><td>{$form.title.html}</td><tr>
<tr><td class="label">{$form.description.label}</td><td>{$form.description.html}</td></tr>
</table>
</td>
</tr>
</table>
<h3>{ts}Summary{/ts}</h3>
<table class="report" style="width: 100%">
<tr>
<td>
<div class="crm-accordion-header">
Number of selected contributions: {$selectedContributions}
</div>
</td>
</tr>
<tr>
{if $totalAddedContributions}
<td>
<div class="crm-accordion-wrapper crm-accordion_title-accordion crm-accordion-closed">
<div class="crm-accordion-header">
<div class="icon crm-accordion-pointer"></div>
Number of contributions that will be added to this batch: {$totalAddedContributions}
</div><!-- /.crm-accordion-header -->
<div class="crm-accordion-body">
<table class="selector">
<thead >
<tr>
<th>{ts}Name{/ts}</th>
<th>{ts}Amount{/ts}</th>
<th>{ts}Type{/ts}</th>
<th>{ts}Source{/ts}</th>
<th>{ts}Recieved{/ts}</th>
</tr>
</thead>
{foreach from=$contributionsAddedRows item=row}
<tr>
<td><a href="{crmURL p='civicrm/contact/view' q="reset=1&cid=`$row.contact_id`"}">{$row.display_name}</a></td>
<td>{$row.total_amount}</td>
<td>{$row.financial_account}</td>
<td>{$row.source}</td>
<td>{$row.receive_date}</td>
</tr>
{/foreach}
</table>
</div><!-- /.crm-accordion-body -->
</div><!-- /.crm-accordion-wrapper -->
</td>
{else}
<td>
<div class="crm-accordion-header">
Number of selected contributions: {$totalAddedContributions}
</div>
</td>
{/if}
</tr>
<tr>
{if $alreadyAddedContributions}
<td><div class="crm-accordion-wrapper crm-accordion_title-accordion crm-accordion-closed">
<div class="crm-accordion-header">
<div class="icon crm-accordion-pointer"></div>
Number of contributions already in a batch: {$alreadyAddedContributions}
</div><!-- /.crm-accordion-header -->
<div class="crm-accordion-body">
<table class="selector">
<thead class="crm-accordion-header">
<tr>
<th>{ts}Name{/ts}</th>
<th>{ts}Amount{/ts}</th>
<th>{ts}Type{/ts}</th>
<th>{ts}Source{/ts}</th>
<th>{ts}Recieved{/ts}</th>
<th>{ts}Batch{/ts}</th>
</tr>
</thead>
{foreach from=$contributionsAlreadyAddedRows item=row}
<tr>
<td><a href="{crmURL p='civicrm/contact/view' q="reset=1&cid=`$row.contact_id`"}">{$row.display_name}</a></td>
<td>{$row.total_amount}</td>
<td>{$row.financial_account}</td>
<td>{$row.source}</td>
<td>{$row.receive_date}</td>
<td>{$row.batch}</td>
</tr>
{/foreach}
</table>
</div><!-- /.crm-accordion-body -->
</div><!-- /.crm-accordion-wrapper -->
</td>
{else}
<td>
<div class="crm-accordion-header">
Number of contributions already in a batch: {$alreadyAddedContributions}
</div>
</td>
{/if}
</tr>
<tr>
<td>
<div class="crm-accordion-header">
Number of contributions not valid for gift aid: {$notValidContributions}
</div>
</td>
</tr>
</table>
<p>{ts}Use this form to submit Gift Aid contributions. Note that this action is irreversible, i.e. you cannot take contributions out of a batch once they have been added.{/ts}</p>
{$form.buttons.html}
</div>
{literal}
<script type="text/javascript">
cj(function() {
cj().crmaccordions();
});
</script>
{/literal}
\ No newline at end of file
{*
+--------------------------------------------------------------------+
| CiviCRM version 4.1 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2011 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*}
{include file="CRM/Report/Form.tpl"}
\ No newline at end of file
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.1 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2011 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
require_once 'CiviTest/CiviUnitTestCase.php';
require_once 'tools/drupal/modules/civicrm_giftaid/GiftAid/Utils/GiftAid.php';
/**
* Test class for GiftAid Declaration functions - civicrm_giftAid_*
*
* @package CiviCRM
*/
class DeclarationTest extends CiviUnitTestCase {
public function dataProvider() {
return array(
// 01-jan-10 user makes contrib, says yes
// input => cid, eligible, start-date, end-date
array('ip' => array(1, 1, '2010-01-01', NULL),
// output
'op' => array(array(1, 1, '2010-01-01 00:00:00', '2013-01-01 00:00:00')),
),
// 01-jun-10 user makes contrib, says yes
// input
array('ip' => array(1, 1, '2010-06-01', NULL),
// output
'op' => array(array(1, 1, '2010-01-01 00:00:00', '2013-06-01 00:00:00')),
),
// 01-jan-11 user makes contrib, says no
// input
array('ip' => array(1, 0, '2011-01-11', NULL),
// output row1
'op' => array(array(1, 1, '2010-01-01 00:00:00', '2011-01-11 00:00:00'),
array(1, 0, '2011-01-11 00:00:00', NULL),
// output row2
),
),
// 01-jun-11 user makes contrib, says no
// input
array('ip' => array(1, 0, '2011-06-11', NULL),
// output row1
'op' => array(array(1, 1, '2010-01-01 00:00:00', '2011-01-11 00:00:00'),
array(1, 0, '2011-01-11 00:00:00', NULL),
// output row2
),
),
// 01-jan-12 user sets up monthly regular contrib, says yes
// input
array('ip' => array(1, 1, '2012-01-01', NULL),
// output row1
'op' => array(array(1, 1, '2010-01-01 00:00:00', '2011-01-11 00:00:00'),
array(1, 0, '2011-01-11 00:00:00', '2012-01-01 00:00:00'),
array(1, 1, '2012-01-01 00:00:00', '2015-01-01 00:00:00'),
// output row2
),
),
);
}
/**
* @dataProvider dataProvider
*/
public function testDeclarations($input, $output) {
$count = 0;
$params = $tableRows = array();
$declarationFields = array('entity_id', 'eligible_for_gift_aid', 'start_date', 'end_date');
foreach ($declarationFields as $field) {
$params[$field] = $input[$count];
$count++;
}
$result = GiftAid_Utils_GiftAid::setDeclaration($params);
$sql = "select * from civicrm_value_gift_aid_declaration";
$dao = &CRM_Core_DAO::executeQuery($sql);
$count = 0;
while ($dao->fetch()) {
foreach ($declarationFields as $field) {
$tableRows[$count][] = $dao->$field;
}
$count++;
}
$this->assertEquals($output, $tableRows, 'In line ' . __LINE__);
}
}
<?xml version="1.0" encoding="iso-8859-1" ?>
<CustomData>
<CustomGroups>
<CustomGroup>
<name>Gift_Aid_Declaration</name>
<title>Gift Aid Declaration</title>
<extends>Individual</extends>
<style>Tab</style>
<collapse_display>0</collapse_display>
<help_pre></help_pre>
<help_post></help_post>
<weight>1</weight>
<is_active>1</is_active>
<table_name>civicrm_value_gift_aid_declaration</table_name>
<is_multiple>1</is_multiple>
<collapse_adv_display>0</collapse_adv_display>
<created_date>2010-10-03 02:28:19</created_date>
</CustomGroup>
<CustomGroup>
<name>Gift_Aid</name>
<title>Gift Aid</title>
<extends>Contribution</extends>
<style>Inline</style>
<collapse_display>1</collapse_display>
<help_pre>Stores the values that are submitted in the Gift Aid Report</help_pre>
<help_post></help_post>
<weight>2</weight>
<is_active>1</is_active>
<table_name>civicrm_value_gift_aid_submission</table_name>
<is_multiple>0</is_multiple>
<collapse_adv_display>0</collapse_adv_display>
<created_date>2010-10-03 02:32:44</created_date>
</CustomGroup>
</CustomGroups>
<CustomFields>
<CustomField>
<name>name_of_charity</name>
<label>Name of charity</label>
<data_type>String</data_type>
<html_type>Text</html_type>
<is_required>0</is_required>
<is_searchable>0</is_searchable>
<is_search_range>0</is_search_range>
<is_active>1</is_active>
<is_view>0</is_view>
<weight>8</weight>
<text_length>32</text_length>
<note_columns>60</note_columns>
<note_rows>4</note_rows>
<column_name>charity</column_name>
<custom_group_name>Gift_Aid_Declaration</custom_group_name>
</CustomField>
<CustomField>
<name>name_of_charity</name>
<label>Name of charity</label>
<data_type>String</data_type>
<html_type>Text</html_type>
<is_required>0</is_required>
<is_searchable>0</is_searchable>
<is_search_range>0</is_search_range>
<is_active>1</is_active>
<is_view>0</is_view>
<weight>7</weight>
<text_length>32</text_length>
<note_columns>60</note_columns>
<note_rows>4</note_rows>
<column_name>charity</column_name>
<custom_group_name>Gift_Aid</custom_group_name>
</CustomField>
</CustomFields>
<ContributionTypes>
<ContributionType>
<name>Gift Aid</name>
<is_deductible>0</is_deductible>
<is_reserved>1</is_reserved>
<is_active>1</is_active>
</ContributionType>
</ContributionTypes>
</CustomData>
name = CiviCRM GiftAid Alpha
description = Additional features for Gift Aid for Alpha
version = 3.4
dependencies[] = civicrm
dependencies[] = civicrm_giftaid
package = CiviCRM
core = 6.x
php = 5.2
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.1 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2011 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2011
* $Id$
*
*/
// ******** Support for pending contribution based on the giftaid value ********* //
define('CIVICRM_GIFTAID_PENDING_CONTRIBUTION', 1);
// ******** Support for multiple charities ********* //
define('CIVICRM_GIFTAID_CHARITY_DECLARATION_CF_NAME', 'charity');
define('CIVICRM_GIFTAID_CHARITY_SUBMISSION_CF_NAME', 'charity');
// ******** Contribution types automatically set as not eligable for gift aid ******** //
// enter comma separated values for multiple contribution types
define('CIVICRM_GIFTAID_NOT_ELIGIBLE_CONTRIBUTION_TYPES', '');
function civicrm_giftaid_civicrm_batchContributions($batchID, $contributionsAdded) {
if (!CIVICRM_GIFTAID_PENDING_CONTRIBUTION) {
return;
}
// get financial account.
$contributionTypes = array_flip(CRM_Contribute_PseudoConstant::contributionType());
$contributionTypeId = $contributionTypes['Gift Aid'];
if (!$contributionTypeId ||
empty($contributionsAdded)
) {
CRM_Core_Error::fatal('Required resources missing for creating pending contribution.');
}
$query = "SELECT sum(gift_add_submission.gift_aid_amount)
FROM civicrm_value_gift_aid_submission gift_add_submission
WHERE entity_id IN (" . implode(',', $contributionsAdded) . ")";
$totalAmount = CRM_Core_DAO::singleValueQuery($query);
$config = CRM_Core_Config::singleton();
$session = CRM_Core_Session::singleton();
// get contribution status
$contributionStatus = array_flip(CRM_Contribute_PseudoConstant::contributionStatus());
$contributionStatusId = $contributionStatus['Pending'];
// create a pending contribution
$contribParams = array('contact_id' => $session->get('userID'),
'financial_account_id' => $contributionTypeId,
'receive_date' => date('YmdHis'),
'total_amount' => $totalAmount,
'invoice_id' => md5(uniqid(rand(), TRUE)),
'currency' => $config->defaultCurrency,
'source' => ts('Gift aid batch'),
'contribution_status_id' => $contributionStatusId,
);
$pendingContribution = &CRM_Contribute_BAO_Contribution::add($contribParams, CRM_Core_DAO::$_nullArray);
// and add to the batch - $batchID
$batchContribution = new CRM_Batch_DAO_EntityBatch();
$batchContribution->entity_table = 'civicrm_contribution';
$batchContribution->entity_id = $pendingContribution->id;
$batchContribution->batch_id = $batchID;
$batchContribution->save();
}
function civicrm_giftaid_civicrm_giftAidEligible(&$isEligible, $contactID, $date, $contributionID) {
if ($isEligible &&
$contactID &&
$contributionID &&
CIVICRM_GIFTAID_CHARITY_DECLARATION_CF_NAME &&
CIVICRM_GIFTAID_CHARITY_SUBMISSION_CF_NAME
) {
// ************* Support for multiple charities **************** //
// Note there is no point processing further if $isEligible is false, which is based on declaration date
$cgID = _civicrm_giftaid_getCustomGroupID('Gift_Aid');
if (!$cgID) {
return;
}
$charity = NULL;
if ($contributionID &&
CRM_Core_DAO::checkFieldExists('civicrm_value_gift_aid_submission', 'charity')
) {
$charity = CRM_Core_DAO::singleValueQuery('SELECT charity FROM civicrm_value_gift_aid_submission WHERE entity_id = %1',
array(1 => array($contributionID, 'Integer'))
);
}
// do a declaration fetch again, in order to get the declaration id
$declaration = GiftAid_Utils_GiftAid::getDeclaration($contactID, $date, $charity);
// now use declaration id to fetch charity
$sql = "SELECT " . CIVICRM_GIFTAID_CHARITY_DECLARATION_CF_NAME . " as charity
FROM civicrm_value_gift_aid_declaration
WHERE id = %1";
$declaredCharity = CRM_Core_DAO::singleValueQuery($sql, array(1 => array($declaration['id'], 'Integer')));
// if declaration has charity set AND donation doesn't have same charity specified,
// set the eligibility to false
if ($declaredCharity) {
require_once 'CRM/Dedupe/Finder.php';
require_once 'CRM/Core/BAO/CustomGroup.php';
$infoGroupTree = CRM_Core_BAO_CustomGroup::getTree('Contribution',
CRM_Core_DAO::$_nullObject,
$contributionID,
$cgID
);
$infoGroupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($infoGroupTree, 1, CRM_Core_DAO::$_nullObject);
foreach ($infoGroupTree as $gId => $groupTree) {
foreach ($groupTree['fields'] as $fId => $fieldTree) {
if ($fieldTree['column_name'] == CIVICRM_GIFTAID_CHARITY_SUBMISSION_CF_NAME &&
$declaredCharity != $fieldTree['element_value']
) {
$isEligible = FALSE;
break;
}
}
}
}
}
if ($isEligible && $contributionID &&
CIVICRM_GIFTAID_NOT_ELIGIBLE_CONTRIBUTION_TYPES
) {
// ******** Contribution types automatically set as not eligable for gift aid ********** //
// get financial account.
$query = "SELECT financial_account.name
FROM civicrm_contribution contribution
INNER JOIN civicrm_financial_account financial_account ON ( contribution.financial_account_id = financial_account.id )
WHERE contribution.id = %1";
$params = array(1 => array($contributionID, 'Integer'));
$contributionType = CRM_Core_DAO::singleValueQuery($query, $params);
$notEligibleContributionTypes = explode(',', CIVICRM_GIFTAID_NOT_ELIGIBLE_CONTRIBUTION_TYPES);
foreach ($notEligibleContributionTypes as & $type) {
$type = trim($type);
}
$isEligible = in_array($contributionType, $notEligibleContributionTypes) ? FALSE : $isEligible;
}
}
function _civicrm_giftaid_getCustomGroupID($customGroupName) {
require_once 'CRM/Utils/Type.php';
$customGroupName = CRM_Utils_Type::escape($customGroupName, 'String');
return CRM_Core_DAO::getFieldValue("CRM_Core_DAO_CustomGroup", $customGroupName, 'id', 'name');
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment