Skip to content

Commit

Permalink
CIVICRM-1502 Add support for new membership terms for pending contrib…
Browse files Browse the repository at this point in the history
…utions
  • Loading branch information
agileware-fj committed Nov 3, 2021
1 parent d1f75aa commit e7285f0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
5 changes: 2 additions & 3 deletions info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
<url desc="Support">https://support.agileware.com.au</url>
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls>
<releaseDate>2021-10-25</releaseDate>
<version>1.1</version>
<releaseDate>2021-11-03</releaseDate>
<version>1.2</version>
<develStage>stable</develStage>
<compatibility>
<ver>4.7</ver>
<ver>5.x</ver>
</compatibility>
<civix>
Expand Down
42 changes: 33 additions & 9 deletions lineitemtweaks.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,18 +248,42 @@ function _lineitemtweaks_fix_membership_lineitem($contribution, &$params) {
if ($membership_type['duration_unit'] != 'lifetime') {
// Normal memberships (Not lifetime)
if (!__lineitemtweaks_new_membership($membership["id"])) {
$lastMembershipLog = civicrm_api3('MembershipLog', 'get', array(
'sequential' => 1,
'membership_id' => $membership["id"],
'options' => array('limit' => 1, 'sort' => "id DESC"),
));
if ($lastMembershipLog["count"]) {
$lastMembershipLog = $lastMembershipLog["values"][0];
$membershipToUse = $lastMembershipLog;
$status = FALSE;

if (!empty($contribution['id'])) {
$status = Civi\Api4\Contribution::get(FALSE)
->addSelect('contribution_status_id:name')
->addWhere('id', '=', $contribution['id'])
->execute()
->first();
$status = $status['contribution_status_id:name'];
}

if ($status == 'Pending') {
// Derive new membership dates according to the end date and number of terms
$membershipToUse = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType(
$membership['id'],
NULL,
NULL,
$params['qty'] ?? 1
);
}
else {
// Get new membership dates from the log, which should be written out already.
$lastMembershipLog = civicrm_api3('MembershipLog', 'get', [
'sequential' => 1,
'membership_id' => $membership["id"],
'options' => ['limit' => 1, 'sort' => "id DESC"],
]);
if ($lastMembershipLog["count"]) {
$lastMembershipLog = $lastMembershipLog["values"][0];
$membershipToUse = $lastMembershipLog;

}
}
}

$from = strftime('%m/%Y', strtotime($membershipToUse['start_date']));
$from = strftime('%m/%Y', strtotime($membershipToUse['log_start_date'] ?? $membershipToUse['start_date']));
$to = strftime('%m/%Y', strtotime($membershipToUse['end_date']));

$label = civicrm_api3('Setting', 'getvalue', array('name' => 'lineitemtweaks_membership_label'));
Expand Down

0 comments on commit e7285f0

Please sign in to comment.