//CRM-16480 if contact is selected, validate financial type and amount field.
foreach ($params['field'] as $key => $value) {
+ if (isset($value['trxn_id'])) {
+ if (0 < CRM_Core_DAO::singleValueQuery('SELECT id FROM civicrm_contribution WHERE trxn_id = %1', array(1 => array($value['trxn_id'], 'String')))) {
+ $errors["field[$key][trxn_id]"] = ts('Transaction ID must be unique within the database');
+ }
+ }
foreach ($fields as $field => $label) {
if (!empty($params['primary_contact_id'][$key]) && empty($value[$field])) {
$errors["field[$key][$field]"] = ts('%1 is a required field.', array(1 => $label));
* @return array
* Array of basic contact types information.
*/
- public static function &basicTypeInfo($all = FALSE) {
+ public static function basicTypeInfo($all = FALSE) {
static $_cache = NULL;
if ($_cache === NULL) {
* @return array
* Array of sub type information
*/
- public static function &subTypeInfo($contactType = NULL, $all = FALSE, $ignoreCache = FALSE, $reset = FALSE) {
+ public static function subTypeInfo($contactType = NULL, $all = FALSE, $ignoreCache = FALSE, $reset = FALSE) {
static $_cache = NULL;
if ($reset === TRUE) {
// skip some contacts ?
$skipOnHold = isset($form->skipOnHold) ? $form->skipOnHold : FALSE;
$skipDeceased = isset($form->skipDeceased) ? $form->skipDeceased : TRUE;
-
- list($contributions, $contacts) = self::buildContributionArray($groupBy, $form, $returnProperties, $skipOnHold, $skipDeceased, $messageToken, $task, $separator);
+ $contributionIDs = $form->getVar('_contributionIds');
+ if ($form->_includesSoftCredits) {
+ //@todo - comment on what is stored there
+ $contributionIDs = $form->getVar('_contributionContactIds');
+ }
+ list($contributions, $contacts) = self::buildContributionArray($groupBy, $contributionIDs, $returnProperties, $skipOnHold, $skipDeceased, $messageToken, $task, $separator, $form->_includesSoftCredits);
$html = array();
foreach ($contributions as $contributionId => $contribution) {
$contact = &$contacts[$contribution['contact_id']];
* around contact_id of contribution_recur_id
*
* @param string $groupBy
- * @param CRM_Contribute_Form_Task $form
+ * @param array $contributionIDs
* @param array $returnProperties
* @param bool $skipOnHold
* @param bool $skipDeceased
* @param array $messageToken
* @param string $task
* @param string $separator
+ * @param bool $isIncludeSoftCredits
*
* @return array
*/
- public static function buildContributionArray($groupBy, $form, $returnProperties, $skipOnHold, $skipDeceased, $messageToken, $task, $separator) {
+ public static function buildContributionArray($groupBy, $contributionIDs, $returnProperties, $skipOnHold, $skipDeceased, $messageToken, $task, $separator, $isIncludeSoftCredits) {
$contributions = $contacts = $notSent = array();
- $contributionIDs = $form->getVar('_contributionIds');
- if ($form->_includesSoftCredits) {
- //@todo - comment on what is stored there
- $contributionIDs = $form->getVar('_contributionContactIds');
- }
foreach ($contributionIDs as $item => $contributionId) {
// get contribution information
$contribution = CRM_Utils_Token::getContributionTokenDetails(array('contribution_id' => $contributionId),
$task
);
$contribution = $contributions[$contributionId] = $contribution[$contributionId];
- if ($form->_includesSoftCredits) {
+
+ if ($isIncludeSoftCredits) {
//@todo find out why this happens & add comments
list($contactID) = explode('-', $item);
$contactID = (int) $contactID;
$contactID = $contribution['contact_id'];
}
if (!isset($contacts[$contactID])) {
- list($contact) = CRM_Utils_Token::getTokenDetails(array('contact_id' => $contactID),
- $returnProperties,
- $skipOnHold,
- $skipDeceased,
- NULL,
- $messageToken,
- $task
- );
- $contacts[$contactID] = $contact[$contactID];
+ $contacts[$contactID] = array();
$contacts[$contactID]['contact_aggregate'] = 0;
$contacts[$contactID]['combined'] = $contacts[$contactID]['contribution_ids'] = array();
}
$contacts[$contactID]['aggregates'][$groupBy][$groupByID] += $contribution['total_amount'];
}
}
+ // Assign the available contributions before calling tokens so hooks parsing smarty can access it.
+ // Note that in core code you can only use smarty here if enable if for the whole site, incl
+ // CiviMail, with a big performance impact.
+ // Hooks allow more nuanced smarty usage here.
+ CRM_Core_Smarty::singleton()->assign('contributions', $contributions);
+ foreach ($contacts as $contactID => $contact) {
+ $tokenResolvedContacts = CRM_Utils_Token::getTokenDetails(array('contact_id' => $contactID),
+ $returnProperties,
+ $skipOnHold,
+ $skipDeceased,
+ NULL,
+ $messageToken,
+ $task
+ );
+ $contacts[$contactID] = array_merge($tokenResolvedContacts[0][$contactID], $contact);
+ }
return array($contributions, $contacts);
}
*/
public function preProcess() {
+ $this->setAction(CRM_Core_Action::UPDATE);
+
$this->contributionRecurID = CRM_Utils_Request::retrieve('crid', 'Integer', $this, FALSE);
if ($this->contributionRecurID) {
$this->_paymentProcessor = CRM_Contribute_BAO_ContributionRecur::getPaymentProcessor($this->contributionRecurID);
}
if (CRM_Contribute_BAO_ContributionRecur::supportsFinancialTypeChange($this->contributionRecurID)) {
- $this->addEntityRef('financial_type_id', ts('Financial Type'), array('entity' => 'FinancialType'), TRUE);
+ $this->addEntityRef('financial_type_id', ts('Financial Type'), array('entity' => 'FinancialType'), !$this->_selfService);
}
$type = 'next';
if (is_numeric($subType)) {
return $subType;
}
- $contactTypes = civicrm_api3('Contact', 'getoptions', array('field' => 'contact_type'));
- if ($entityType != 'Contact' && !array_key_exists($entityType, $contactTypes['values'])) {
- // Not quite sure if we want to fail this hard. But quiet ignore would be pretty bad too.
- // Am inclined to go with this for RC release & considering softening.
+
+ $contactTypes = CRM_Contact_BAO_ContactType::basicTypeInfo(TRUE);
+ if ($entityType != 'Contact' && !array_key_exists($entityType, $contactTypes)) {
throw new CRM_Core_Exception('Invalid Entity Filter');
}
- $subTypes = civicrm_api3('Contact', 'getoptions', array('field' => 'contact_sub_type'));
- if (!isset($subTypes['values'][$subType])) {
- // Same comments about fail hard as above.
+ $subTypes = CRM_Contact_BAO_ContactType::subTypeInfo($entityType, TRUE);
+ if (!array_key_exists($subType, $subTypes)) {
throw new CRM_Core_Exception('Invalid Filter');
}
return $subType;
'name' => 'contribution_status_id',
'title' => ts('Contribution Status'),
),
+ 'trxn_id' => array(
+ 'name' => 'contribution_trxn_id',
+ 'title' => ts('Contribution Transaction ID'),
+ ),
);
}
return self::$_memberBatchEntryFields;
if ($fkDAO->find(TRUE)) {
$this->$dbName = $fkDAO->id;
}
- unset($fkDAO);
+ $fkDAO->free();
}
elseif (in_array($FKClassName, CRM_Core_DAO::$_testEntitiesToSkip)) {
$depObject = new $FKClassName();
$depObject->find(TRUE);
$this->$dbName = $depObject->id;
- unset($depObject);
+ $depObject->free();
}
elseif ($daoName == 'CRM_Member_DAO_MembershipType' && $fieldName == 'member_of_contact_id') {
// FIXME: the fields() metadata is not specific enough
$depObject = CRM_Core_DAO::createTestObject($FKClassName, array('contact_type' => 'Organization'));
$this->$dbName = $depObject->id;
- unset($depObject);
+ $depObject->free();
}
else {
//if it is required we need to generate the dependency object first
$depObject = CRM_Core_DAO::createTestObject($FKClassName, CRM_Utils_Array::value($dbName, $params, 1));
$this->$dbName = $depObject->id;
- unset($depObject);
+ $depObject->free();
}
}
$event = new \Civi\Core\DAO\Event\PostDelete($this, $result);
\Civi::service('dispatcher')->dispatch("DAO::post-delete", $event);
+ $this->free();
return $result;
}
$this->templates['text'] = implode("\n", $template);
}
- if ($this->body_html) {
+ // To check for an html part strip tags
+ if (trim(strip_tags($this->body_html))) {
$template = array();
if ($this->header) {
-- CRM-18537
DELETE FROM civicrm_state_province WHERE name = 'Fernando de Noronha';
+
+-- CRM-17118 extend civicrm_address postal_code to accept full data strings from paypal etc.
+ALTER TABLE civicrm_address CHANGE `postal_code` `postal_code` varchar(64) ;
+
{/if}
{foreach from=$fields item=field key=fieldName}
<div class="crm-grid-cell">
- {if $field.name|substr:0:11 ne 'soft_credit'}
+ {if $field.name|substr:0:11 ne 'soft_credit' and $field.name ne 'trxn_id'}
<img src="{$config->resourceBase}i/copy.png"
alt="{ts 1=$field.title}Click to copy %1 from row one to all rows.{/ts}"
fname="{$field.name}" class="action-icon"
$this->assertEquals(date('Y-m-d', strtotime('07/22/2013')), $result['values'][1]['join_date']);
$this->assertEquals(date('Y-m-d', strtotime('07/03/2013')), $result['values'][2]['join_date']);
$this->assertEquals(date('Y-m-d', strtotime('now')), $result['values'][3]['join_date']);
- $result = $this->callAPISuccess('contribution', 'get', array('return' => 'total_amount'));
+ $result = $this->callAPISuccess('contribution', 'get', array('return' => array('total_amount', 'trxn_id')));
$this->assertEquals(3, $result['count']);
- foreach ($result['values'] as $contribution) {
+ foreach ($result['values'] as $key => $contribution) {
$this->assertEquals($this->callAPISuccess('line_item', 'getvalue', array(
'contribution_id' => $contribution['id'],
'return' => 'line_total',
)), $contribution['total_amount']);
+ $this->assertEquals($params['field'][$key]['trxn_id'], $contribution['trxn_id']);
}
}
'receive_date' => '07/24/2013',
'receive_date_time' => NULL,
'payment_instrument' => 1,
+ 'trxn_id' => 'TX101',
'check_number' => NULL,
'contribution_status_id' => 1,
),
'receive_date' => '07/17/2013',
'receive_date_time' => NULL,
'payment_instrument' => NULL,
+ 'trxn_id' => 'TX102',
'check_number' => NULL,
'contribution_status_id' => 1,
),
'receive_date' => '07/17/2013',
'receive_date_time' => NULL,
'payment_instrument' => NULL,
+ 'trxn_id' => 'TX103',
'check_number' => NULL,
'contribution_status_id' => 1,
),
--- /dev/null
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.7 |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2016 |
+ +--------------------------------------------------------------------+
+ | 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 |
+ +--------------------------------------------------------------------+
+ */
+
+/**
+ * Test APIv3 civicrm_contribute_* functions
+ *
+ * @package CiviCRM_APIv3
+ * @subpackage API_Contribution
+ * @group headless
+ */
+class CRM_Contribute_Form_Task_PDFLetterCommonTest extends CiviUnitTestCase {
+
+ /**
+ * Assume empty database with just civicrm_data.
+ */
+ protected $_individualId;
+
+ /**
+ * Clean up after each test.
+ */
+ public function tearDown() {
+ $this->quickCleanUpFinancialEntities();
+ CRM_Utils_Hook::singleton()->reset();
+ }
+
+ /**
+ * Test the buildContributionArray function.
+ */
+ public function testBuildContributionArray() {
+ $this->_individualId = $this->individualCreate();
+ $params = array('contact_id' => $this->_individualId, 'total_amount' => 6, 'financial_type_id' => 'Donation');
+ $contributionIDs = $returnProperties = $messageToken = array();
+ $result = $this->callAPISuccess('Contribution', 'create', $params);
+ $contributionIDs[] = $result['id'];
+ $result = $this->callAPISuccess('Contribution', 'create', $params);
+ $contributionIDs[] = $result['id'];
+ $this->hookClass->setHook('civicrm_tokenValues', array($this, 'hookTokenValues'));
+
+ list($contributions, $contacts) = CRM_Contribute_Form_Task_PDFLetterCommon::buildContributionArray('contact_id', $contributionIDs, $returnProperties, TRUE, TRUE, $messageToken, 'test', '**', FALSE);
+
+ $this->assertEquals('Anthony', $contacts[$this->_individualId]['first_name']);
+ $this->assertEquals('emo', $contacts[$this->_individualId]['favourite_emoticon']);
+ $this->assertEquals('Donation', $contributions[$result['id']]['financial_type']);
+ }
+
+ /**
+ * Implement token values hook.
+ *
+ * @param array $details
+ * @param array $contactIDs
+ * @param int $jobID
+ * @param array $tokens
+ * @param string $className
+ */
+ public function hookTokenValues(&$details, $contactIDs, $jobID, $tokens, $className) {
+ foreach ($details as $index => $detail) {
+ $details[$index]['favourite_emoticon'] = 'emo';
+ }
+ }
+
+}
$this->callAPISuccess('ContactType', 'delete', array('id' => $contactType['id']));
}
+ /**
+ * Test calling getTree for a custom field extending a disabled contact type.
+ */
+ public function testGetTreeContactSubTypeForDisabledChangedContactType() {
+ $contactType = $this->callAPISuccess('ContactType', 'create', array('name' => 'Big Bank', 'label' => 'biggee', 'parent_id' => 'Organization'));
+ $customGroup = $this->CustomGroupCreate(array('extends' => 'Organization', 'extends_entity_column_value' => array('Big_Bank')));
+ $customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id']));
+ $this->callAPISuccess('ContactType', 'create', array('id' => $contactType['id'], 'is_active' => 0));
+ $result1 = CRM_Core_BAO_CustomGroup::getTree('Organization', NULL, NULL, NULL, array('Big_Bank'));
+ $this->assertEquals('Custom Field', $result1[$customGroup['id']]['fields'][$customField['id']]['label']);
+ $this->customGroupDelete($customGroup['id']);
+ $this->callAPISuccess('ContactType', 'delete', array('id' => $contactType['id']));
+ }
+
/**
* Test calling getTree with contact subtype data.
*
for ($i = 0; $i < 30; $i++) {
$baoObj = CRM_Core_DAO::createTestObject($baoString, array('currency' => 'USD'));
$ids[] = $baoObj->id;
+ $baoObj->free();
}
// each case is array(0 => $inputtedApiOptions, 1 => $expectedResultCount)
for ($i = 0; $i < 3 - $totalEntities; $i++) {
$baoObj = CRM_Core_DAO::createTestObject($baoString, array('currency' => 'USD'));
$ids[] = $baoObj->id;
+ $baoObj->free();
}
$totalEntities = 3;
}
<name>postal_code</name>
<title>Postal Code</title>
<type>varchar</type>
- <length>12</length>
+ <length>64</length>
<import>true</import>
<headerPattern>/postal|zip/i</headerPattern>
<dataPattern>/\d?\d{4}(-\d{4})?/</dataPattern>