/**
* Get selected membership type from the form values.
*
- * @param int $priceSetID
+ * @param array $priceSet
* @param array $params
*
* @return array
*/
- public static function getSelectedMemberships($priceSetID, $params) {
+ public static function getSelectedMemberships($priceSet, $params) {
$memTypeSelected = array();
- $priceFieldIDS = self::getPriceFieldIDs($params);
- if ($priceSetID && is_array($priceFieldIDS)) {
+ $priceFieldIDS = self::getPriceFieldIDs($params, $priceSet);
+ if (!empty($priceSet) && is_array($priceFieldIDS)) {
foreach ($priceFieldIDS as $priceFieldId) {
if ($id = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldId, 'membership_type_id')) {
$memTypeSelected[$id] = $id;
* Extract price set fields and values from $params.
*
* @param array $params
+ * @param array $priceSet
*
* @return array
*/
- public static function getPriceFieldIDs($params) {
- $priceFieldIDS = $priceSet = $fieldIds = array();
- if (isset(self::$priceSet) && is_array(self::$priceSet)) {
- $priceSet = self::$_priceSet;
- if (isset($priceSet['fields']) && is_array($priceSet['fields'])) {
- $fieldIds = array_keys($priceSet['fields']);
- }
- }
- foreach ($fieldIds as $fieldId) {
- if (!empty($params['price_' . $fieldId])) {
- if (is_array($params['price_' . $fieldId])) {
- foreach ($params['price_' . $fieldId] as $priceFldVal => $isSet) {
- if ($isSet) {
- $priceFieldIDS[] = $priceFldVal;
+ public static function getPriceFieldIDs($params, $priceSet) {
+ $priceFieldIDS = $fieldIds = array();
+ if (isset($priceSet['fields']) && is_array($priceSet['fields'])) {
+ $fieldIds = array_keys($priceSet['fields']);
+ foreach ($fieldIds as $fieldId) {
+ if (!empty($params['price_' . $fieldId])) {
+ if (is_array($params['price_' . $fieldId])) {
+ foreach ($params['price_' . $fieldId] as $priceFldVal => $isSet) {
+ if ($isSet) {
+ $priceFieldIDS[] = $priceFldVal;
+ }
}
}
- }
- else {
- $priceFieldIDS[] = $params['price_' . $fieldId];
+ else {
+ $priceFieldIDS[] = $params['price_' . $fieldId];
+ }
}
}
}
$this->addDate('receive_date', ts('Received'), FALSE, array('formatType' => 'activityDateTime'));
$this->add('select', 'payment_instrument_id',
- ts('Paid By'),
+ ts('Payment Method'),
array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(),
FALSE, array('onChange' => "return showHideByValue('payment_instrument_id','4','checkNumber','table-row','select',false);")
);
$errors = array();
$priceSetId = CRM_Utils_Array::value('price_set_id', $params);
+ $priceSetDetails = CRM_Price_BAO_PriceSet::getSetDetail($priceSetId);
- $selectedMemberships = self::getSelectedMemberships($priceSetId, $params);
-
+ $selectedMemberships = self::getSelectedMemberships($priceSetDetails[$priceSetId], $params);
if ($priceSetId) {
CRM_Price_BAO_PriceField::priceSetValidation($priceSetId, $params, $errors);
- $priceFieldIDS = self::getPriceFieldIDs($params, $self);
+ $priceFieldIDS = self::getPriceFieldIDs($params, $priceSetDetails);
if (!empty($priceFieldIDS)) {
$ids = implode(',', $priceFieldIDS);
}
}
}
+ // Return error if empty $self->_memTypeSelected
+ if (empty($errors) && empty($selectedMemberships)) {
+ $errors['_qf_default'] = ts('Select at least one membership option.');
+ }
+ if (!$self->_mode && empty($params['record_contribution'])) {
+ $errors['record_contribution'] = ts('Record Membership Payment is required when you use a price set.');
+ }
}
- elseif (empty($params['membership_type_id'][1])) {
- $errors['membership_type_id'] = ts('Please select a membership type.');
- }
-
- if (!$priceSetId) {
+ else {
+ if (empty($params['membership_type_id'][1])) {
+ $errors['membership_type_id'] = ts('Please select a membership type.');
+ }
$numterms = CRM_Utils_Array::value('num_terms', $params);
if ($numterms && intval($numterms) != $numterms) {
$errors['num_terms'] = ts('Please enter an integer for the number of terms.');
}
- }
- // Return error if empty $self->_memTypeSelected
- if ($priceSetId && empty($errors) && empty($selectedMemberships)) {
- $errors['_qf_default'] = ts('Select at least one membership option.');
+ if ($self->_mode || isset($params['record_contribution']) && empty($params['financial_type_id'])) {
+ $errors['financial_type_id'] = ts('Please enter the financial Type.');
+ }
}
if (!empty($errors) && (count($selectedMemberships) > 1)) {
return $errors;
}
- if ($priceSetId && !$self->_mode && empty($params['record_contribution'])) {
- $errors['record_contribution'] = ts('Record Membership Payment is required when you using price set.');
- }
-
- if (!$priceSetId && $self->_mode && empty($params['financial_type_id'])) {
- $errors['financial_type_id'] = ts('Please enter the financial Type.');
- }
if (!empty($params['record_contribution']) && empty($params['payment_instrument_id'])) {
- $errors['payment_instrument_id'] = ts('Paid By is a required field.');
+ $errors['payment_instrument_id'] = ts('Payment Method is a required field.');
}
if (!empty($params['is_different_contribution_contact'])) {
//total amount condition arise when membership type having no
//minimum fee
if (isset($params['record_contribution'])) {
- if (!$params['financial_type_id']) {
- $errors['financial_type_id'] = ts('Please enter the financial Type.');
- }
if (CRM_Utils_System::isNull($params['total_amount'])) {
$errors['total_amount'] = ts('Please enter the contribution.');
}
$allMemberStatus = CRM_Member_PseudoConstant::membershipStatus();
$allContributionStatus = CRM_Contribute_PseudoConstant::contributionStatus();
- $lineItems = NULL;
- if (!empty($this->_lineItem)) {
- $lineItems = $this->_lineItem;
- }
-
if ($this->_id) {
$ids['membership'] = $params['id'] = $this->_id;
}
// In form mode these are set in preProcess.
//TODO: set memberships, fixme
$this->setContextVariables($formValues);
- $this->_memTypeSelected = self::getSelectedMemberships($priceSetID, $formValues);
+ $priceSetDetails = CRM_Price_BAO_PriceSet::getSetDetail($priceSetID);
+ $this->_memTypeSelected = self::getSelectedMemberships(
+ $priceSetDetails[$priceSetID],
+ $formValues
+ );
+ if (empty($formValues['financial_type_id'])) {
+ $formValues['financial_type_id'] = $priceSetDetails[$priceSetID]['financial_type_id'];
+ }
$config = CRM_Core_Config::singleton();
$financialType = new CRM_Financial_DAO_FinancialType();
$financialType->id = $params['financial_type_id'];
$financialType->find(TRUE);
+
$contribution = CRM_Contribute_Form_Contribution_Confirm::processFormContribution($this,
$paymentParams,
- $result,
- $this->_contributorContactID,
+ NULL,
+ array(
+ 'contact_id' => $this->_contributorContactID,
+ 'line_item' => $lineItem,
+ 'is_test' => $isTest,
+ 'campaign_id' => CRM_Utils_Array::value('campaign_id', $paymentParams),
+ 'contribution_page_id' => CRM_Utils_Array::value('contribution_page_id', $this->_params),
+ 'source' => CRM_Utils_Array::value('source', $paymentParams, CRM_Utils_Array::value('description', $paymentParams)),
+ 'thankyou_date' => CRM_Utils_Array::value('thankyou_date', $paymentParams),
+ 'payment_instrument_id' => $this->_paymentProcessor['payment_instrument_id'],
+ ),
$financialType,
TRUE,
FALSE,
- $isTest,
- $lineItems,
$this->_bltID
);
}
CRM_Core_Session::setStatus($statusMsg, ts('Complete'), 'success');
-
+ //CRM-15187
+ // dusplay message when membership type is changed
+ if (($this->_action & CRM_Core_Action::UPDATE) && $this->_id && !in_array($this->_memType, $this->_memTypeSelected)) {
+ CRM_Core_Session::setStatus(
+ ts('The financial types associated with the old and new membership types are different. You may want to edit the contribution associated with this membership to adjust its financial type.'),
+ ts('Warning')
+ );
+ CRM_Core_Session::setStatus(
+ ts('The cost of the old and new membership types are different. You may want to edit the contribution associated with this membership to adjust its amount.'),
+ ts('Warning')
+ );
+ }
return $createdMemberships;
}