Skip to content

Commit

Permalink
CRM-20294 Update membership dates in profiles to use datepicker
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Mar 17, 2017
1 parent f5af41a commit 04b40ea
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 63 deletions.
91 changes: 46 additions & 45 deletions CRM/Batch/Form/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ public function setDefaultValues() {

$completeStatus = CRM_Contribute_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed');
$specialFields = array(
'join_date' => $currentDate,
'join_date' => date('Y-m-d'),
'receive_date' => $currentDate,
'receive_date_time' => $currentTime,
'contribution_status_id' => $completeStatus,
Expand Down Expand Up @@ -414,7 +414,7 @@ public function postProcess() {
$params['actualBatchTotal'] = 0;

// get the profile information
$batchTypes = CRM_Core_Pseudoconstant::get('CRM_Batch_DAO_Batch', 'type_id', array('flip' => 1), 'validate');
$batchTypes = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'type_id', array('flip' => 1), 'validate');
if (in_array($this->_batchInfo['type_id'], array($batchTypes['Pledge Payment'], $batchTypes['Contribution']))) {
$this->processContribution($params);
}
Expand Down Expand Up @@ -637,24 +637,13 @@ private function processContribution(&$params) {
* @return bool
*/
private function processMembership(&$params) {
$dateTypes = array(
'join_date' => 'joinDate',
'membership_start_date' => 'startDate',
'membership_end_date' => 'endDate',
);

$dates = array(
'join_date',
'start_date',
'end_date',
'reminder_date',
);

// get the price set associated with offline membership
$priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', 'default_membership_type_amount', 'id', 'name');
$this->_priceSet = $priceSets = current(CRM_Price_BAO_PriceSet::getSetDetail($priceSetId));

if (isset($params['field'])) {
// @todo - most of the wrangling in this function is because the api is not being used, especially date stuff.
$customFields = array();
foreach ($params['field'] as $key => $value) {
// if contact is not selected we should skip the row
Expand All @@ -669,28 +658,6 @@ private function processMembership(&$params) {

$membershipTypeId = $value['membership_type_id'] = $value['membership_type'][1];

foreach ($dateTypes as $dateField => $dateVariable) {
$$dateVariable = CRM_Utils_Date::processDate($value[$dateField]);
$fDate[$dateField] = CRM_Utils_Array::value($dateField, $value);
}

$calcDates = array();
$calcDates[$membershipTypeId] = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membershipTypeId,
$joinDate, $startDate, $endDate
);

foreach ($calcDates as $memType => $calcDate) {
foreach ($dates as $d) {
//first give priority to form values then calDates.
$date = CRM_Utils_Array::value($d, $value);
if (!$date) {
$date = CRM_Utils_Array::value($d, $calcDate);
}

$value[$d] = CRM_Utils_Date::processDate($date);
}
}

if (!empty($value['send_receipt'])) {
$value['receipt_date'] = date('Y-m-d His');
}
Expand Down Expand Up @@ -810,8 +777,6 @@ private function processMembership(&$params) {
// end of contribution related section

unset($value['membership_type']);
unset($value['membership_start_date']);
unset($value['membership_end_date']);

$value['is_renew'] = FALSE;
if (!empty($params['member_option']) && CRM_Utils_Array::value($key, $params['member_option']) == 2) {
Expand All @@ -827,12 +792,11 @@ private function processMembership(&$params) {
$campaignId = CRM_Utils_Array::value('campaign_id', $this->_values);
}
}
foreach (array('join_date', 'start_date', 'end_date') as $dateType) {
//CRM-18000 - ignore $dateType if its not explicitly passed
if (!empty($fDate[$dateType]) || !empty($fDate['membership_' . $dateType])) {
$formDates[$dateType] = CRM_Utils_Array::value($dateType, $value);
}
}

$formDates = array(
'end_date' => CRM_Utils_Array::value('membership_end_date', $value),
'start_date' => CRM_Utils_Array::value('membership_start_date', $value),
);
$membershipSource = CRM_Utils_Array::value('source', $value);
list($membership) = CRM_Member_BAO_Membership::processMembership(
$value['contact_id'], $value['membership_type_id'], FALSE,
Expand All @@ -848,7 +812,44 @@ private function processMembership(&$params) {
CRM_Member_BAO_Membership::recordMembershipContribution($contrbutionParams);
}
else {
$membership = CRM_Member_BAO_Membership::create($value, CRM_Core_DAO::$_nullArray);
$dateTypes = array(
'join_date' => 'joinDate',
'membership_start_date' => 'startDate',
'membership_end_date' => 'endDate',
);

$dates = array(
'join_date',
'start_date',
'end_date',
'reminder_date',
);
foreach ($dateTypes as $dateField => $dateVariable) {
$$dateVariable = CRM_Utils_Date::processDate($value[$dateField]);
$fDate[$dateField] = CRM_Utils_Array::value($dateField, $value);
}

$calcDates = array();
$calcDates[$membershipTypeId] = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membershipTypeId,
$joinDate, $startDate, $endDate
);

foreach ($calcDates as $memType => $calcDate) {
foreach ($dates as $d) {
//first give priority to form values then calDates.
$date = CRM_Utils_Array::value($d, $value);
if (!$date) {
$date = CRM_Utils_Array::value($d, $calcDate);
}

$value[$d] = CRM_Utils_Date::processDate($date);
}
}

unset($value['membership_start_date']);
unset($value['membership_end_date']);
$ids = array();
$membership = CRM_Member_BAO_Membership::create($value, $ids);
}

//process premiums
Expand Down
11 changes: 4 additions & 7 deletions CRM/Core/BAO/UFGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -1216,9 +1216,6 @@ public static function getValues(
elseif (in_array($name, array(
'birth_date',
'deceased_date',
'membership_start_date',
'membership_end_date',
'join_date',
))) {
// @todo this set should be determined from metadata, not hard-coded.
$values[$index] = CRM_Utils_Date::customFormat($details->$name);
Expand Down Expand Up @@ -2330,9 +2327,6 @@ public static function buildProfile(
*/
static public function getNonUpgradedDateFields() {
return array(
'membership_start_date' => 'activityDate',
'membership_end_date' => 'activityDate',
'join_date' => 'activityDate',
'receive_date' => 'activityDateTime',
'receipt_date' => 'activityDateTime',
'thankyou_date' => 'activityDateTime',
Expand Down Expand Up @@ -3321,7 +3315,7 @@ public static function setComponentDefaults(&$fields, $componentId, $component,
elseif ($name == 'membership_status') {
$defaults[$fldName] = $values['status_id'];
}
elseif ($customFieldInfo = CRM_Core_BAO_CustomField::getKeyID($name, TRUE)) {
elseif (CRM_Core_BAO_CustomField::getKeyID($name, TRUE) !== array(NULL, NULL)) {
if (empty($formattedGroupTree)) {
//get the groupTree as per subTypes.
$groupTree = array();
Expand Down Expand Up @@ -3373,6 +3367,9 @@ public static function setComponentDefaults(&$fields, $componentId, $component,
}
}
}
elseif (isset($values[$fldName])) {
$defaults[$fldName] = $values[$fldName];
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion CRM/Member/BAO/Membership.php
Original file line number Diff line number Diff line change
Expand Up @@ -1942,7 +1942,7 @@ public static function processMembership($contactID, $membershipTypeID, $is_test
// Insert renewed dates for CURRENT membership
$memParams = array();
$memParams['join_date'] = CRM_Utils_Date::isoToMysql($membership->join_date);
$memParams['start_date'] = CRM_Utils_Date::isoToMysql($membership->start_date);
$memParams['start_date'] = CRM_Utils_Array::value('start_date', $formDates, CRM_Utils_Date::isoToMysql($membership->start_date));
$memParams['end_date'] = CRM_Utils_Array::value('end_date', $formDates);
if (empty($memParams['end_date'])) {
$memParams['end_date'] = CRM_Utils_Array::value('end_date', $dates);
Expand Down
2 changes: 0 additions & 2 deletions CRM/Member/Form/Task/Batch.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ public function buildQuickForm() {

$this->assign('profileTitle', $this->_title);
$this->assign('componentIds', $this->_memberIds);
$fileFieldExists = FALSE;

//load all campaigns.
if (array_key_exists('member_campaign_id', $this->_fields)) {
Expand Down Expand Up @@ -194,7 +193,6 @@ public function setDefaultValues() {

$defaults = array();
foreach ($this->_memberIds as $memberId) {
$details[$memberId] = array();
CRM_Core_BAO_UFGroup::setProfileDefaults(NULL, $this->_fields, $defaults, FALSE, $memberId, 'Membership');
}

Expand Down
7 changes: 4 additions & 3 deletions templates/CRM/Batch/Form/Entry.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
{/if}
{foreach from=$fields item=field key=fieldName}
{assign var=n value=$field.name}
{if in_array( $n, array( 'thankyou_date', 'cancel_date', 'receipt_date', 'receive_date', 'join_date', 'membership_start_date', 'membership_end_date' ) ) }
{if in_array( $n, array( 'thankyou_date', 'cancel_date', 'receipt_date', 'receive_date') ) }
<div class="compressed crm-grid-cell">
<span class="crm-batch-{$n}-{$rowNumber}">
{include file="CRM/common/jcalendar.tpl" elementName=$n elementIndex=$rowNumber batchUpdate=1}
Expand Down Expand Up @@ -255,7 +255,8 @@ function checkColumns(parentRow) {
parentRow.find('div .required').each(function () {
//special case to handle contact autocomplete select
var fieldId = cj(this).attr('id');
if (fieldId.substring(0, 16) == 'primary_contact_') {
// datepicker hasTimeEntry would not have an id - not sure why.
if (typeof fieldId != 'undefined' && fieldId.substring(0, 16) == 'primary_contact_') {
// if display value is set then make sure we also check if contact id is set
if (!cj(this).val()) {
inValidRow++;
Expand Down Expand Up @@ -386,7 +387,7 @@ function updateContactInfo(blockNo, prefix) {
cj('select[id="member_option_' + blockNo + '"]').prop('disabled', false).val(2);
cj('select[id="field_' + blockNo + '_membership_type_0"]').val(memTypeContactId).change();
cj('select[id="field_' + blockNo + '_membership_type_1"]').val(membershipTypeId).change();
setDateFieldValue('join_date', membershipJoinDate, blockNo)
cj('#field_' + blockNo + '_' + 'join_date').val(membershipJoinDate).trigger('change');
}
});
}
Expand Down
6 changes: 1 addition & 5 deletions templates/CRM/Member/Form/Task/Batch.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@

{foreach from=$fields item=field key=fieldName}
{assign var=n value=$field.name}
{if ($n eq 'join_date') or ($n eq 'membership_start_date') or ($n eq 'membership_end_date')}
<td class="compressed">{include file="CRM/common/jcalendar.tpl" elementName=$n elementIndex=$mid batchUpdate=1}</td>
{else}
<td class="compressed">{$form.field.$mid.$n.html}</td>
{/if}
<td class="compressed">{$form.field.$mid.$n.html}</td>
{/foreach}
</tr>
{/foreach}
Expand Down

0 comments on commit 04b40ea

Please sign in to comment.