//.........这里部分代码省略.........
}
}
}
if (!empty($lifeMember)) {
foreach ($priceFieldIDS as $priceFieldId) {
if (($id = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldId, 'membership_type_id')) && in_array($membershipOrgDetails[$id], $unallowedOrgs)) {
$errors['_qf_default'] = ts('You already have a lifetime membership and cannot select a membership with a shorter term.');
break;
}
}
}
if (!empty($priceFieldIDS)) {
$ids = implode(',', $priceFieldIDS);
$priceFieldIDS['id'] = $fields['priceSetId'];
$self->set('memberPriceFieldIDS', $priceFieldIDS);
$count = CRM_Price_BAO_PriceSet::getMembershipCount($ids);
foreach ($count as $id => $occurrence) {
if ($occurrence > 1) {
$errors['_qf_default'] = ts('You have selected multiple memberships for the same organization or entity. Please review your selections and choose only one membership per entity. Contact the site administrator if you need assistance.');
}
}
}
if (empty($priceFieldMemTypes) && $self->_membershipBlock['is_required'] == 1) {
$errors['_qf_default'] = ts('Please select at least one membership option.');
}
}
CRM_Price_BAO_PriceSet::processAmount($self->_values['fee'], $fields, $lineItem);
if ($fields['amount'] < 0) {
$errors['_qf_default'] = ts('Contribution can not be less than zero. Please select the options accordingly');
}
$amount = $fields['amount'];
}
if (isset($fields['selectProduct']) && $fields['selectProduct'] != 'no_thanks') {
$productDAO = new CRM_Contribute_DAO_Product();
$productDAO->id = $fields['selectProduct'];
$productDAO->find(TRUE);
$min_amount = $productDAO->min_contribution;
if ($amount < $min_amount) {
$errors['selectProduct'] = ts('The premium you have selected requires a minimum contribution of %1', array(1 => CRM_Utils_Money::format($min_amount)));
CRM_Core_Session::setStatus($errors['selectProduct']);
}
}
//CRM-16285 - Function to handle validation errors on form, for recurring contribution field.
CRM_Contribute_BAO_ContributionRecur::validateRecurContribution($fields, $files, $self, $errors);
if (!empty($fields['is_recur']) && CRM_Utils_Array::value('payment_processor_id', $fields) == 0) {
$errors['_qf_default'] = ts('You cannot set up a recurring contribution if you are not paying online by credit card.');
}
// validate PCP fields - if not anonymous, we need a nick name value
if ($self->_pcpId && !empty($fields['pcp_display_in_roll']) && CRM_Utils_Array::value('pcp_is_anonymous', $fields) == 0 && CRM_Utils_Array::value('pcp_roll_nickname', $fields) == '') {
$errors['pcp_roll_nickname'] = ts('Please enter a name to include in the Honor Roll, or select \'contribute anonymously\'.');
}
// return if this is express mode
$config = CRM_Core_Config::singleton();
if ($self->_paymentProcessor && $self->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_BUTTON) {
if (!empty($fields[$self->_expressButtonName . '_x']) || !empty($fields[$self->_expressButtonName . '_y']) || CRM_Utils_Array::value($self->_expressButtonName, $fields)) {
return $errors;
}
}
//validate the pledge fields.
if (!empty($self->_values['pledge_block_id'])) {
//validation for pledge payment.
if (!empty($self->_values['pledge_id'])) {
if (empty($fields['pledge_amount'])) {
$errors['pledge_amount'] = ts('At least one payment option needs to be checked.');
}
} elseif (!empty($fields['is_pledge'])) {
/**
* global form rule
*
* @param array $fields the input form values
* @param array $files the uploaded files if any
* @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();
$amount = self::computeAmount($fields, $self);
//check for atleast one pricefields should be selected
if (CRM_Utils_Array::value('priceSetId', $fields)) {
$priceField = new CRM_Price_DAO_Field();
$priceField->price_set_id = $fields['priceSetId'];
$priceField->find();
$check = array();
while ($priceField->fetch()) {
if (!empty($fields["price_{$priceField->id}"])) {
$check[] = $priceField->id;
}
}
if (empty($check)) {
if ($self->_useForMember == 1) {
$errors['_qf_default'] = ts('Select at least one option from Membership Type(s).');
} else {
$errors['_qf_default'] = ts('Select at least one option from Contribution(s).');
}
}
require_once 'CRM/Price/BAO/Set.php';
if ($self->_useForMember == 1 && !empty($check)) {
$priceFieldIDS = array();
$priceFieldMemTypes = array();
foreach ($self->_priceSet['fields'] as $priceId => $value) {
if (!empty($fields['price_' . $priceId])) {
if (is_array($fields['price_' . $priceId])) {
foreach ($fields['price_' . $priceId] as $priceFldVal => $isSet) {
if ($isSet) {
$priceFieldIDS[] = $priceFldVal;
}
}
} else {
$priceFieldIDS[] = $fields['price_' . $priceId];
}
if (CRM_Utils_Array::value('options', $value)) {
foreach ($value['options'] as $val) {
if (CRM_Utils_Array::value('membership_type_id', $val)) {
$priceFieldMemTypes[] = $val['membership_type_id'];
}
}
}
}
}
$ids = implode(',', $priceFieldIDS);
$priceFieldIDS['id'] = $fields['priceSetId'];
$self->set('memberPriceFieldIDS', $priceFieldIDS);
$count = CRM_Price_BAO_Set::getMembershipCount($ids);
foreach ($count as $id => $occurance) {
if ($occurance > 1) {
$errors['_qf_default'] = ts('You have selected multiple memberships for the same organization or entity. Please review your selections and choose only one membership per entity. Contact the site administrator if you need assistance.');
}
}
if (empty($priceFieldMemTypes)) {
$errors['_qf_default'] = ts('Please select at least one membership option.');
}
}
CRM_Price_BAO_Set::processAmount($self->_values['fee'], $fields, $lineItem);
if ($fields['amount'] < 0) {
$errors['_qf_default'] = ts('Contribution can not be less than zero. Please select the options accordingly');
}
$amount = $fields['amount'];
}
if (isset($fields['selectProduct']) && $fields['selectProduct'] != 'no_thanks' && $self->_values['amount_block_is_active']) {
require_once 'CRM/Contribute/DAO/Product.php';
require_once 'CRM/Utils/Money.php';
$productDAO = new CRM_Contribute_DAO_Product();
$productDAO->id = $fields['selectProduct'];
$productDAO->find(true);
$min_amount = $productDAO->min_contribution;
if ($amount < $min_amount) {
$errors['selectProduct'] = ts('The premium you have selected requires a minimum contribution of %1', array(1 => CRM_Utils_Money::format($min_amount)));
}
}
if ($self->_values['honor_block_is_active'] && CRM_Utils_Array::value('honor_type_id', $fields)) {
// make sure there is a first name and last name if email is not there
if (!CRM_Utils_Array::value('honor_email', $fields)) {
if (!CRM_Utils_Array::value('honor_first_name', $fields) || !CRM_Utils_Array::value('honor_last_name', $fields)) {
$errors['honor_last_name'] = ts('In Honor Of - First Name and Last Name, OR an Email Address is required.');
}
}
}
if (isset($fields['is_recur']) && $fields['is_recur']) {
if ($fields['frequency_interval'] <= 0) {
$errors['frequency_interval'] = ts('Please enter a number for how often you want to make this recurring contribution (EXAMPLE: Every 3 months).');
}
if ($fields['frequency_unit'] == '0') {
//.........这里部分代码省略.........
//.........这里部分代码省略.........
}
}
}
if (!empty($lifeMember)) {
foreach ($priceFieldIDS as $priceFieldId) {
if (($id = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldId, 'membership_type_id')) && in_array($membershipOrgDetails[$id], $unallowedOrgs)) {
$errors['_qf_default'] = ts('You already have a lifetime membership and cannot select a membership with a shorter term.');
break;
}
}
}
if (!empty($priceFieldIDS)) {
$ids = implode(',', $priceFieldIDS);
$priceFieldIDS['id'] = $fields['priceSetId'];
$self->set('memberPriceFieldIDS', $priceFieldIDS);
$count = CRM_Price_BAO_PriceSet::getMembershipCount($ids);
foreach ($count as $id => $occurance) {
if ($occurance > 1) {
$errors['_qf_default'] = ts('You have selected multiple memberships for the same organization or entity. Please review your selections and choose only one membership per entity. Contact the site administrator if you need assistance.');
}
}
}
if (empty($priceFieldMemTypes)) {
$errors['_qf_default'] = ts('Please select at least one membership option.');
}
}
CRM_Price_BAO_PriceSet::processAmount($self->_values['fee'], $fields, $lineItem);
if ($fields['amount'] < 0) {
$errors['_qf_default'] = ts('Contribution can not be less than zero. Please select the options accordingly');
}
$amount = $fields['amount'];
}
if (isset($fields['selectProduct']) && $fields['selectProduct'] != 'no_thanks') {
$productDAO = new CRM_Contribute_DAO_Product();
$productDAO->id = $fields['selectProduct'];
$productDAO->find(TRUE);
$min_amount = $productDAO->min_contribution;
if ($amount < $min_amount) {
$errors['selectProduct'] = ts('The premium you have selected requires a minimum contribution of %1', array(1 => CRM_Utils_Money::format($min_amount)));
CRM_Core_Session::setStatus($errors['selectProduct']);
}
}
if (!empty($fields['is_recur'])) {
if ($fields['frequency_interval'] <= 0) {
$errors['frequency_interval'] = ts('Please enter a number for how often you want to make this recurring contribution (EXAMPLE: Every 3 months).');
}
if ($fields['frequency_unit'] == '0') {
$errors['frequency_unit'] = ts('Please select a period (e.g. months, years ...) for how often you want to make this recurring contribution (EXAMPLE: Every 3 MONTHS).');
}
}
if (!empty($fields['is_recur']) && CRM_Utils_Array::value('payment_processor', $fields) == 0) {
$errors['_qf_default'] = ts('You cannot set up a recurring contribution if you are not paying online by credit card.');
}
if (!empty($fields['is_for_organization']) && !property_exists($self, 'organizationName')) {
if (empty($fields['onbehalf']['organization_name'])) {
if (!empty($fields['org_option']) && !$fields['onbehalfof_id']) {
$errors['organization_id'] = ts('Please select an organization or enter a new one.');
} elseif (empty($fields['org_option'])) {
$errors['onbehalf']['organization_name'] = ts('Please enter the organization name.');
}
}
foreach ($fields['onbehalf'] as $key => $value) {
if (strstr($key, 'email')) {
$emailLocType = explode('-', $key);
}
}
/**
* Calculate non deductible amount.
*
* CRM-11956
* if non_deductible_amount exists i.e. Additional Details field set was opened [and staff typed something] -
* if non_deductible_amount does NOT exist - then calculate it depending on:
* $financialType->is_deductible and whether there is a product (premium).
*
* @param $params
* @param $formValues
*
* @return array
*/
protected function calculateNonDeductibleAmount($params, $formValues)
{
if (!empty($params['non_deductible_amount'])) {
return $params['non_deductible_amount'];
}
$priceSetId = CRM_Utils_Array::value('price_set_id', $params);
// return non-deductible amount if it is set at the price field option level
if ($priceSetId && !empty($params['line_item'])) {
$nonDeductibleAmount = CRM_Price_BAO_PriceSet::getNonDeductibleAmountFromPriceSet($priceSetId, $params['line_item']);
if (!empty($nonDeductibleAmount)) {
return $nonDeductibleAmount;
}
}
$financialType = new CRM_Financial_DAO_FinancialType();
$financialType->id = $params['financial_type_id'];
$financialType->find(TRUE);
if ($financialType->is_deductible) {
if (isset($formValues['product_name'][0])) {
$selectProduct = $formValues['product_name'][0];
}
// if there is a product - compare the value to the contribution amount
if (isset($selectProduct)) {
$productDAO = new CRM_Contribute_DAO_Product();
$productDAO->id = $selectProduct;
$productDAO->find(TRUE);
// product value exceeds contribution amount
if ($params['total_amount'] < $productDAO->price) {
return $params['total_amount'];
} else {
return $productDAO->price;
}
} else {
return '0.00';
}
} else {
return $params['total_amount'];
}
return 0;
}
请发表评论