Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-17666 : Added 'membership_type_id is present check' when saving membership payment. #7384

Merged
merged 2 commits into from
Dec 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CRM/Member/BAO/Membership.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ public static function create(&$params, &$ids, $skipRedirect = FALSE, $activityT
if (!empty($params['relate_contribution_id'])) {
CRM_Member_BAO_MembershipPayment::create(array(
'membership_id' => $membership->id,
'membership_type_id' => $membership->membership_type_id,
'contribution_id' => $params['relate_contribution_id'],
));
}
Expand Down Expand Up @@ -1783,6 +1784,7 @@ public static function getMembershipRenewals($membershipTypeId, $startDate, $end
public static function linkMembershipPayment($membership, $membershipContribution) {
CRM_Member_BAO_MembershipPayment::create(array(
'membership_id' => $membership->id,
'membership_type_id' => $membership->membership_type_id,
'contribution_id' => $membershipContribution->id,
));
}
Expand Down
9 changes: 7 additions & 2 deletions CRM/Member/BAO/MembershipPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,23 @@ public static function create($params) {
// table. However, at this stage we have both - there is still quite a bit of refactoring to do to set the line_iten entity_id right the first time
// however, we can assume at this stage that any contribution id will have only one line item with that membership type in the line item table
// OR the caller will have taken responsibility for updating the line items themselves so we will update using SQL here
$membershipTypeID = civicrm_api3('membership', 'getvalue', array(
if (!isset($params['membership_type_id'])) {
$membership_type_id = civicrm_api3('membership', 'getvalue', array(
'id' => $dao->membership_id,
'return' => 'membership_type_id',
));
}
else {
$membership_type_id = $params['membership_type_id'];
}
$sql = "UPDATE civicrm_line_item li
LEFT JOIN civicrm_price_field_value pv ON pv.id = li.price_field_value_id
SET entity_table = 'civicrm_membership', entity_id = %1
WHERE pv.membership_type_id = %2
AND contribution_id = %3";
CRM_Core_DAO::executeQuery($sql, array(
1 => array($dao->membership_id, 'Integer'),
2 => array($membershipTypeID, 'Integer'),
2 => array($membership_type_id, 'Integer'),
3 => array($dao->contribution_id, 'Integer'),
));
return $dao;
Expand Down
5 changes: 5 additions & 0 deletions api/v3/MembershipPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ function civicrm_api3_membership_payment_create($params) {
function _civicrm_api3_membership_payment_create_spec(&$params) {
$params['membership_id']['api.required'] = 1;
$params['contribution_id']['api.required'] = 1;
$params['membership_type_id'] = array(
'title' => 'Membership type id',
'description' => 'The id of the membership type',
'type' => CRM_Utils_Type::T_INT,
);
}

/**
Expand Down