self::deleteContribution($contribution->id);
}
}
- * @param Array $props: whatever is known about this dao object
+
+ /**
+ * Get options for a given contribution field.
+ * @see CRM_Core_DAO::buildOptions
+ *
+ * @param String $fieldName
+ * @param String $context: @see CRM_Core_DAO::buildOptionsContext
- $page = civicrm_api('contribution_page', 'getsingle', array('version' => 3, 'id' => ($props['contribution_page_id'])));
++ * @param Array $props: whatever is known about this dao object
+ */
+ public static function buildOptions($fieldName, $context = NULL, $props = array()) {
+ $className = __CLASS__;
+ $params = array();
+ switch ($fieldName) {
+ // This field is not part of this object but the api supports it
+ case 'payment_processor':
+ $className = 'CRM_Contribute_BAO_ContributionPage';
+ // Filter results by contribution page
+ if (!empty($props['contribution_page_id'])) {
- * @param integer $financialTypeId Financial Type id
++ $page = civicrm_api('contribution_page', 'getsingle', array(
++ 'version' => 3,
++ 'id' => ($props['contribution_page_id'])
++ ));
+ $types = (array) CRM_Utils_Array::value('payment_processor', $page, 0);
+ $params['condition'] = 'id IN (' . implode(',', $types) . ')';
+ }
+ }
+ return CRM_Core_PseudoConstant::get($className, $fieldName, $params, $context);
+ }
++
+ /**
+ * Function to validate financial type
+ *
+ * CRM-13231
+ *
++ * @param integer $financialTypeId Financial Type id
+ *
+ * @access public
+ * @static
+ */
+ static function validateFinancialType($financialTypeId, $relationName = 'Expense Account is') {
+ $expenseTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE '{$relationName}' "));
+ $financialAccount = CRM_Contribute_PseudoConstant::financialAccountType($financialTypeId, $expenseTypeId);
+
+ if (!$financialAccount) {
+ return CRM_Contribute_PseudoConstant::financialType($financialTypeId);
+ }
+ return FALSE;
+ }
}
+
+
}
//FIXME FOR NEW DATA FLOW http://wiki.civicrm.org/confluence/display/CRM/CiviAccounts+4.3+Data+Flow
- if (CRM_Utils_Array::value('fee_amount', $fields)) {
- $financialAccount = array();
- CRM_Core_PseudoConstant::populate($financialAccount,
- 'CRM_Financial_DAO_EntityFinancialAccount',
- $all = TRUE,
- $retrieve = 'financial_account_id',
- $filter = NULL,
- " account_relationship = 5 AND entity_id = {$fields['financial_type_id']} ");
- if (!current($financialAccount)) {
- $errors['financial_type_id'] = ts("Financial Account of account relationship of 'Expense Account is' is not configured for this Financial Type");
- }
+ if (CRM_Utils_Array::value('fee_amount', $fields)
+ && $financialType = CRM_Contribute_BAO_Contribution::validateFinancialType($fields['financial_type_id'])) {
+ $errors['financial_type_id'] = ts("Financial Account of account relationship of 'Expense Account is' is not configured for Financial Type : ") . $financialType;
}
+
+ $errors = array_merge($errors, $softErrors);
return $errors;
}
//delete from financial Type table
$financialType = new CRM_Financial_DAO_EntityFinancialAccount( );
$financialType->id = $financialTypeAccountId;
+ $financialType->find(TRUE);
$financialType->delete();
+ CRM_Core_Session::setStatus(ts('Unbalanced transactions may be created if you delete %1 account.', array(1 => $relationValues[$financialType->account_relationship])));
}
-
+
/**
- * Function to get Financial Account Name
- *
+ * Function to get Financial Account Name
+ *
* @param int $entityId
- *
- * @param string $entityTable
- *
+ *
+ * @param string $entityTable
+ *
* @param string $columnName Column to fetch
* @static
*/
SELECT 'civicrm_financial_type', cft.id, @option_value_rel_id_exp, @financialAccountId
FROM civicrm_financial_type cft
LEFT JOIN civicrm_entity_financial_account ceft
- ON ceft.entity_id = cft.id AND ceft.account_relationship = 5 AND ceft.entity_table = 'civicrm_financial_type'
-ON ceft.entity_id = cft.id AND ceft.account_relationship = @option_value_rel_id_exp AND ceft.entity_table = 'civicrm_financial_type'
++ON ceft.entity_id = cft.id AND ceft.account_relationship = @option_value_rel_id_exp AND ceft.entity_table = 'civicrm_financial_type'
WHERE ceft.entity_id IS NULL;
}
$this->openCiviPage('profile/edit', "reset=1&id=$id&gid=$gid", NULL);
if (!$checkMultiRecord) {
- $this->assertElementContainsText('crm-container', 'No multi-record entries found');
+ $this->assertElementContainsText('crm-container', 'No records');
return array($gid, $profileTitle);
}
- $this->waitForElementPresent("//div[@id='crm-profile-block']/../a");
- $this->click("//div[@id='crm-profile-block']/../a");
- sleep(1);
- $record1 = $this->_addRecords('Edit', FALSE, "//div[@class='crm-container-snippet']/form/div[2]/");
+ $this->waitForElementPresent("//a/span[contains(text(), 'Add New Record')]");
+ $this->click("//a/span[contains(text(), 'Add New Record')]");
+ $record1 = $this->_addRecords();
$this->waitForPageToLoad($this->getTimeoutMsec());
$this->verifyText("//div[@id='browseValues']/div/div/table/thead/tr/th[1]", preg_quote($params['textFieldLabel']));
$this->verifyText("//div[@id='browseValues']/div/div/table/tbody/tr[2]/td[1]", preg_quote($record1['text']));
return $params;
}
- function _addRecords($context = 'Edit') {
- $this->waitForPageToLoad($this->getTimeoutMsec());
+ function _addRecords($context = 'Edit', $waitAtStart = TRUE, $parentElement = '//') {
+ if ($waitAtStart) {
+ $this->waitForPageToLoad($this->getTimeoutMsec());
+ }
$params['text'] = 'text' . substr(sha1(rand()), 0, 3);
- $this->type("{$parentElement}div[@id='crm-profile-block']/div/div[2]/input[@type='text']", $params['text']);
+ $this->type("//div[@id='crm-profile-block']/div/div[2]/input[@type='text']", $params['text']);
if ($context == 'Create') {
$params['firstname'] = 'John' . substr(sha1(rand()), 0, 3);
$this->type('first_name', $params['firstname']);