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

BASW-131: Membership end date rules #6

Open
wants to merge 3 commits into
base: 7.x-4.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
50 changes: 34 additions & 16 deletions includes/utils.inc
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function wf_crm_field_options($field, $context, $data) {
elseif ($table == 'membership' && $name == 'num_terms') {
$ret = drupal_map_assoc(range(1, 9));
}
elseif ($table == 'membership' && $name == 'start_date_rules') {
elseif ($table == 'membership' && in_array($name, array('start_date_rules', 'end_date_rules'))) {
$ret = array(0 => '- ' . t('Automatic') . ' -', 1 => '- ' . t('User Select') . ' -', 2 => t('Relative to active membership end date'));
}
// Aside from the above special cases, most lists can be fetched from api.getoptions
Expand All @@ -99,7 +99,7 @@ function wf_crm_field_options($field, $context, $data) {
// Pass data into api.getoptions for contextual filtering
$params += wf_crm_aval($data, "$ent:$c:$table:$n", array());
// We need the same options as membership_type_id for start_date_memberships
if($params['field'] == 'start_date_memberships') {
if (in_array($params['field'], array('start_date_memberships', 'end_date_memberships'))) {
$params['field'] = 'membership_type_id';
}
}
Expand Down Expand Up @@ -1186,20 +1186,7 @@ function wf_crm_get_fields($var = 'fields') {
'value' => 1,
'empty_option' => t('Enter Dates Manually'),
);
// Membership Date Rule Fields
$fields['membership_start_date_rules'] = array(
'name' => t('Start Date'),
'type' => 'select',
'expose_list' => TRUE,
'value' => 0,
'exposed_empty_option' => '- ' . t('Automatic') . ' -',
);
$fields['membership_start_date_memberships'] = array (
'name' => t('Select Membership Types'),
'type' => 'select',
'expose_list' => TRUE,
'extra' => array('multiple' => 1),
);

if (isset($sets['contribution'])) {
$fields['membership_fee_amount'] = array(
'name' => t('Membership Fee'),
Expand Down Expand Up @@ -1242,6 +1229,37 @@ function wf_crm_get_fields($var = 'fields') {
'empty_option' => t('None'),
);
}
// Membership Date Rule Fields
$fields['membership_start_date_rules'] = array(
'name' => t('Start Date'),
'type' => 'select',
'expose_list' => TRUE,
'value' => 0,
'exposed_empty_option' => t('Automatic'),
);
$fields['membership_start_date_memberships'] = array (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe membership_start_date_rules_memberships is more clear, same for end_date_rules

'name' => t('Select Membership Types'),
'type' => 'select',
'expose_list' => TRUE,
'extra' => array('multiple' => 1),
);
$fields['membership_end_date_rules'] = array(
'name' => t('End Date'),
'type' => 'select',
'expose_list' => TRUE,
'value' => 0,
'exposed_empty_option' => t('Automatic'),
);
$fields['membership_end_date_memberships'] = array (
'name' => t('Select Membership Types'),
'type' => 'select',
'expose_list' => TRUE,
'extra' => array('multiple' => 1),
);
$fields['membership_pro_rate_membership'] = array(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this field is not related to the commit, it should not be here, and while it is fine for this PR, I think it is important to not do that when you open the PR against webform_civicrm core repo.

'name' => t('Pro-rate Price of Membership'),
'type' => 'checkbox',
);
}
// CiviGrant fields
if (isset($sets['grant'])) {
Expand Down
9 changes: 7 additions & 2 deletions includes/wf_crm_admin_form.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1312,8 +1312,13 @@ class wf_crm_admin_form {
// Remove 'create_civicrm_webform_element' option for membership date rules
if (strpos($field['form_key'], '_start_date_rules') !== FALSE
||
strpos($field['form_key'], '_start_date_memberships') !== FALSE) {
unset($options['create_civicrm_webform_element']);
strpos($field['form_key'], '_start_date_memberships') !== FALSE
||
strpos($field['form_key'], '_end_date_rules') !== FALSE
||
strpos($field['form_key'], '_end_date_memberships') !== FALSE
) {
unset($options['create_civicrm_webform_element']);
}
$options += wf_crm_field_options($field, 'config_form', $this->data);
$item += array(
Expand Down
13 changes: 13 additions & 0 deletions includes/wf_crm_admin_help.inc
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,19 @@ class wf_crm_admin_help {
<p>If so it will set the start date of the new membership to be the day following the end date of the existing active membership.</p>
<p>If the user currently has multiple relevant membership types the start date will be one day following the end date of the membership with the latest end date.</p>');
}

public static function membership_end_date_rules() {
print '<p>'.
t('"Automatic" indicates that new membership end date will be calculated according to the start date and the membership duration').
'</p>';
}

public static function membership_pro_rate_membership() {
print '<p>'.
t('If this box is ticket, the membership price will be calculated based on the number of days left until the end date compared to the number of days in a regular membership period').
'</p>';
}

public static function membership_fee_amount() {
print '<p>' .
t('Price for this membership per term. If this field is enabled, the default minimum membership fee from CiviCRM membership type settings will not be loaded.') .
Expand Down
13 changes: 13 additions & 0 deletions js/webform_civicrm_admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ var wfCiviAdmin = (function ($, D) {
$target.show();
}
}).change();

$('select[name$=_membership_start_date_rules]', context).change(function(e, type) {
var $dateRuleMembershipField = $(this).parent().siblings('[class$="-start-date-memberships"]');
var $relativeToExistingMembership = 2;
Expand All @@ -522,6 +523,18 @@ var wfCiviAdmin = (function ($, D) {
$dateRuleMembershipField.hide();
}
}).trigger('change', 'init');

$('select[name$=_membership_end_date_rules]', context).change(function(e, type) {
var $dateRuleMembershipField = $(this).parent().siblings('[class$="-end-date-memberships"]');
var $relativeToExistingMembership = 2;
if ($(this).val() == $relativeToExistingMembership) {
$dateRuleMembershipField.show();
}
else {
$dateRuleMembershipField.hide();
}
}).trigger('change', 'init');

function billingMessages() {
var $pageSelect = $('[name=civicrm_1_contribution_1_contribution_contribution_page_id]');
// Warning about contribution page with no email
Expand Down