本文整理汇总了PHP中CRM_Contribute_BAO_Contribution::validateFinancialType方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Contribute_BAO_Contribution::validateFinancialType方法的具体用法?PHP CRM_Contribute_BAO_Contribution::validateFinancialType怎么用?PHP CRM_Contribute_BAO_Contribution::validateFinancialType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Contribute_BAO_Contribution
的用法示例。
在下文中一共展示了CRM_Contribute_BAO_Contribution::validateFinancialType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: formRule
/**
* Global form rule.
*
* @param array $fields
* The input form values.
* @param array $files
* The uploaded files if any.
* @param $self
*
* @return bool|array
* true if no errors, else array of errors
*/
public static function formRule($fields, $files, $self)
{
$errors = array();
// Check for Credit Card Contribution.
if ($self->_mode) {
if (empty($fields['payment_processor_id'])) {
$errors['payment_processor_id'] = ts('Payment Processor is a required field.');
} else {
// validate payment instrument (e.g. credit card number)
CRM_Core_Payment_Form::validatePaymentInstrument($fields['payment_processor_id'], $fields, $errors, NULL);
}
}
// Do the amount validations.
if (empty($fields['total_amount']) && empty($self->_lineItems)) {
if ($priceSetId = CRM_Utils_Array::value('price_set_id', $fields)) {
CRM_Price_BAO_PriceField::priceSetValidation($priceSetId, $fields, $errors);
}
}
$softErrors = CRM_Contribute_Form_SoftCredit::formRule($fields, $errors, $self);
if (!empty($fields['total_amount']) && (!empty($fields['net_amount']) || !empty($fields['fee_amount']))) {
$sum = CRM_Utils_Rule::cleanMoney($fields['net_amount']) + CRM_Utils_Rule::cleanMoney($fields['fee_amount']);
// For taxable contribution we need to deduct taxable amount from
// (net amount + fee amount) before comparing it with total amount
if (!empty($self->_values['tax_amount'])) {
$componentDetails = CRM_Contribute_BAO_Contribution::getComponentDetails($self->_id);
if (!(CRM_Utils_Array::value('membership', $componentDetails) || CRM_Utils_Array::value('participant', $componentDetails))) {
$sum = CRM_Utils_Money::format($sum - $self->_values['tax_amount'], NULL, '%a');
}
}
if (CRM_Utils_Rule::cleanMoney($fields['total_amount']) != $sum) {
$errors['total_amount'] = ts('The sum of fee amount and net amount must be equal to total amount');
}
}
//CRM-16285 - Function to handle validation errors on form, for recurring contribution field.
CRM_Contribute_BAO_ContributionRecur::validateRecurContribution($fields, $files, $self, $errors);
// Form rule for status http://wiki.civicrm.org/confluence/display/CRM/CiviAccounts+4.3+Data+Flow
if ($self->_action & CRM_Core_Action::UPDATE && $self->_id && $self->_values['contribution_status_id'] != $fields['contribution_status_id']) {
CRM_Contribute_BAO_Contribution::checkStatusValidation($self->_values, $fields, $errors);
}
// CRM-16015, add form-rule to restrict change of financial type if using price field of different financial type
if ($self->_action & CRM_Core_Action::UPDATE && $self->_id && $self->_values['financial_type_id'] != $fields['financial_type_id']) {
CRM_Contribute_BAO_Contribution::checkFinancialTypeChange(NULL, $self->_id, $errors);
}
//FIXME FOR NEW DATA FLOW http://wiki.civicrm.org/confluence/display/CRM/CiviAccounts+4.3+Data+Flow
if (!empty($fields['fee_amount']) && !empty($fields['financial_type_id']) && ($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;
}
// $trxn_id must be unique CRM-13919
if (!empty($fields['trxn_id'])) {
$queryParams = array(1 => array($fields['trxn_id'], 'String'));
$query = 'select count(*) from civicrm_contribution where trxn_id = %1';
if ($self->_id) {
$queryParams[2] = array((int) $self->_id, 'Integer');
$query .= ' and id !=%2';
}
$tCnt = CRM_Core_DAO::singleValueQuery($query, $queryParams);
if ($tCnt) {
$errors['trxn_id'] = ts('Transaction ID\'s must be unique. Transaction \'%1\' already exists in your database.', array(1 => $fields['trxn_id']));
}
}
$errors = array_merge($errors, $softErrors);
return $errors;
}
示例2: formRule
/**
* Global validation rules for the form.
*
* @param array $values
* Posted values of the form.
*
* @param $files
* @param $self
*
* @return array
* list of errors to be posted back to the form
*/
public static function formRule($values, $files, $self)
{
$errors = array();
$contributionPageId = $self->_id;
//CRM-4286
if (strstr($values['title'], '/')) {
$errors['title'] = ts("Please do not use '/' in Title");
}
// ensure on-behalf-of profile meets minimum requirements
if (!empty($values['is_organization'])) {
if (empty($values['onbehalf_profile_id'])) {
$errors['onbehalf_profile_id'] = ts('Please select a profile to collect organization information on this contribution page.');
} else {
$requiredProfileFields = array('organization_name', 'email');
if (!CRM_Core_BAO_UFGroup::checkValidProfile($values['onbehalf_profile_id'], $requiredProfileFields)) {
$errors['onbehalf_profile_id'] = ts('Profile does not contain the minimum required fields for an On Behalf Of Organization');
}
}
}
//CRM-11494
$start = CRM_Utils_Date::processDate($values['start_date']);
$end = CRM_Utils_Date::processDate($values['end_date']);
if ($end < $start && $end != 0) {
$errors['end_date'] = ts('End date should be after Start date.');
}
if (!empty($self->_values['payment_processor']) && ($financialType = CRM_Contribute_BAO_Contribution::validateFinancialType($values['financial_type_id']))) {
$errors['financial_type_id'] = ts("Financial Account of account relationship of 'Expense Account is' is not configured for Financial Type : ") . $financialType;
}
//dont allow on behalf of save when
//pre or post profile consists of membership fields
if ($contributionPageId && !empty($values['is_organization'])) {
$ufJoinParams = array('module' => 'CiviContribute', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $contributionPageId);
list($contributionProfiles['custom_pre_id'], $contributionProfiles['custom_post_id']) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
$conProfileType = NULL;
if ($contributionProfiles['custom_pre_id']) {
$preProfileType = CRM_Core_BAO_UFField::getProfileType($contributionProfiles['custom_pre_id']);
if ($preProfileType == 'Membership') {
$conProfileType = "'Includes Profile (top of page)'";
}
}
if ($contributionProfiles['custom_post_id']) {
$postProfileType = CRM_Core_BAO_UFField::getProfileType($contributionProfiles['custom_post_id']);
if ($postProfileType == 'Membership') {
$conProfileType = empty($conProfileType) ? "'Includes Profile (bottom of page)'" : "{$conProfileType} and 'Includes Profile (bottom of page)'";
}
}
if (!empty($conProfileType)) {
$errors['is_organization'] = ts("You should move the membership related fields configured in %1 to the 'On Behalf' profile for this Contribution Page", array(1 => $conProfileType));
}
}
return $errors;
}
示例3: formRule
//.........这里部分代码省略.........
//then disable contribution amount section. CRM-3801,
$membershipBlock = new CRM_Member_DAO_MembershipBlock();
$membershipBlock->entity_table = 'civicrm_contribution_page';
$membershipBlock->entity_id = $self->_id;
$membershipBlock->is_active = 1;
$hasMembershipBlk = FALSE;
if ($membershipBlock->find(TRUE)) {
if (!empty($fields['amount_block_is_active']) && ($setID = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $self->_id, NULL, 1))) {
$extends = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $setID, 'extends');
if ($extends && $extends == CRM_Core_Component::getComponentID('CiviMember')) {
$errors['amount_block_is_active'] = ts('You cannot use a Membership Price Set when the Contribution Amounts section is enabled. Click the Memberships tab above, and select your Membership Price Set on that form. Membership Price Sets may include additional fields for non-membership options that require an additional fee (e.g. magazine subscription) or an additional voluntary contribution.');
return $errors;
}
}
$hasMembershipBlk = TRUE;
if ($membershipBlock->is_separate_payment && empty($fields['amount_block_is_active'])) {
$errors['amount_block_is_active'] = ts('To disable Contribution Amounts section you need to first disable Separate Membership Payment option from Membership Settings.');
}
//CRM-16165, Don't allow reccuring contribution if membership block contain any renewable membership option
$membershipTypes = unserialize($membershipBlock->membership_types);
if (!empty($fields['is_recur']) && !empty($membershipTypes)) {
if (!$membershipBlock->is_separate_payment) {
$errors['is_recur'] = ts('You need to enable Separate Membership Payment when online contribution page is configured for both Membership and Recurring Contribution.');
} elseif (count(array_filter($membershipTypes)) != 0) {
$errors['is_recur'] = ts('You cannot enable both Recurring Contributions and Auto-renew memberships on the same online contribution page.');
}
}
}
//check for the amount label (mandatory)
if (!empty($fields['amount_block_is_active']) && empty($fields['amount_label'])) {
$errors['amount_label'] = ts('Please enter the contribution amount label.');
}
$minAmount = CRM_Utils_Array::value('min_amount', $fields);
$maxAmount = CRM_Utils_Array::value('max_amount', $fields);
if (!empty($minAmount) && !empty($maxAmount)) {
$minAmount = CRM_Utils_Rule::cleanMoney($minAmount);
$maxAmount = CRM_Utils_Rule::cleanMoney($maxAmount);
if ((double) $minAmount > (double) $maxAmount) {
$errors['min_amount'] = ts('Minimum Amount should be less than Maximum Amount');
}
}
if (isset($fields['is_pay_later'])) {
if (empty($fields['pay_later_text'])) {
$errors['pay_later_text'] = ts('Please enter the text for the \'pay later\' checkbox displayed on the contribution form.');
}
if (empty($fields['pay_later_receipt'])) {
$errors['pay_later_receipt'] = ts('Please enter the instructions to be sent to the contributor when they choose to \'pay later\'.');
}
}
// don't allow price set w/ membership signup, CRM-5095
if ($priceSetId = CRM_Utils_Array::value('price_set_id', $fields)) {
// don't allow price set w/ membership.
if ($hasMembershipBlk) {
$errors['price_set_id'] = ts('You cannot enable both a Contribution Price Set and Membership Signup on the same online contribution page.');
}
} else {
if (isset($fields['is_recur'])) {
if (empty($fields['recur_frequency_unit'])) {
$errors['recur_frequency_unit'] = ts('At least one recurring frequency option needs to be checked.');
}
}
// validation for pledge fields.
if (!empty($fields['is_pledge_active'])) {
if (empty($fields['pledge_frequency_unit'])) {
$errors['pledge_frequency_unit'] = ts('At least one pledge frequency option needs to be checked.');
}
if (!empty($fields['is_recur'])) {
$errors['is_recur'] = ts('You cannot enable both Recurring Contributions AND Pledges on the same online contribution page.');
}
}
// If Contribution amount section is enabled, then
// Allow other amounts must be enabled OR the Fixed Contribution
// Contribution options must contain at least one set of values.
if (!empty($fields['amount_block_is_active'])) {
if (empty($fields['is_allow_other_amount']) && !$priceSetId) {
//get the values of amount block
$values = CRM_Utils_Array::value('value', $fields);
$isSetRow = FALSE;
for ($i = 1; $i < self::NUM_OPTION; $i++) {
if (isset($values[$i]) && strlen(trim($values[$i])) > 0) {
$isSetRow = TRUE;
}
}
if (!$isSetRow) {
$errors['amount_block_is_active'] = ts('If you want to enable the \'Contribution Amounts section\', you need to either \'Allow Other Amounts\' and/or enter at least one row in the \'Fixed Contribution Amounts\' table.');
}
}
}
}
if (!empty($fields['payment_processor']) && ($financialType = CRM_Contribute_BAO_Contribution::validateFinancialType($self->_defaultValues['financial_type_id']))) {
$errors['payment_processor'] = ts("Financial Account of account relationship of 'Expense Account is' is not configured for Financial Type : ") . $financialType;
}
if (!empty($fields['is_recur_interval'])) {
foreach (array_keys($fields['payment_processor']) as $paymentProcessorID) {
$paymentProcessorTypeId = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessor', $paymentProcessorID, 'payment_processor_type_id');
$paymentProcessorType = CRM_Core_PseudoConstant::paymentProcessorType(FALSE, $paymentProcessorTypeId, 'name');
}
}
return $errors;
}
示例4: formRule
/**
* global form rule
*
* @param array $fields the input form values
* @param array $files the uploaded files if any
* @param $self
*
* @internal param array $options additional user data
*
* @return true if no errors, else array of errors
* @access public
* @static
*/
static function formRule($fields, $files, $self)
{
$errors = array();
//check for Credit Card Contribution.
if ($self->_mode) {
if (empty($fields['payment_processor_id'])) {
$errors['payment_processor_id'] = ts('Payment Processor is a required field.');
}
}
// do the amount validations.
if (empty($fields['total_amount']) && empty($self->_lineItems)) {
if ($priceSetId = CRM_Utils_Array::value('price_set_id', $fields)) {
CRM_Price_BAO_PriceField::priceSetValidation($priceSetId, $fields, $errors);
}
}
$softErrors = CRM_Contribute_Form_SoftCredit::formRule($fields, $errors, $self);
if (!empty($fields['total_amount']) && (!empty($fields['net_amount']) || !empty($fields['fee_amount']))) {
$sum = CRM_Utils_Rule::cleanMoney($fields['net_amount']) + CRM_Utils_Rule::cleanMoney($fields['fee_amount']);
if (CRM_Utils_Rule::cleanMoney($fields['total_amount']) != $sum) {
$errors['total_amount'] = ts('The sum of fee amount and net amount must be equal to total amount');
}
}
//form rule for status http://wiki.civicrm.org/confluence/display/CRM/CiviAccounts+4.3+Data+Flow
if ($self->_id && $self->_values['contribution_status_id'] != $fields['contribution_status_id']) {
CRM_Contribute_BAO_Contribution::checkStatusValidation($self->_values, $fields, $errors);
}
//FIXME FOR NEW DATA FLOW http://wiki.civicrm.org/confluence/display/CRM/CiviAccounts+4.3+Data+Flow
if (!empty($fields['fee_amount']) && ($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;
}
// $trxn_id must be unique CRM-13919
if (!empty($fields['trxn_id'])) {
$queryParams = array(1 => array($fields['trxn_id'], 'String'));
$query = 'select count(*) from civicrm_contribution where trxn_id = %1';
if ($self->_id) {
$queryParams[2] = array((int) $self->_id, 'Integer');
$query .= ' and id !=%2';
}
$tCnt = CRM_Core_DAO::singleValueQuery($query, $queryParams);
if ($tCnt) {
$errors['trxn_id'] = ts('Transaction ID\'s must be unique. Transaction \'%1\' already exists in your database.', array(1 => $fields['trxn_id']));
}
}
$errors = array_merge($errors, $softErrors);
return $errors;
}