diff --git a/CRM/Batch/Form/Entry.php b/CRM/Batch/Form/Entry.php index 60e967723ddb..b5900b044412 100644 --- a/CRM/Batch/Form/Entry.php +++ b/CRM/Batch/Form/Entry.php @@ -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, @@ -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); } @@ -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 @@ -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'); } @@ -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) { @@ -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, @@ -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 diff --git a/CRM/Core/BAO/UFGroup.php b/CRM/Core/BAO/UFGroup.php index a1f53680799b..3af88e2ffd46 100644 --- a/CRM/Core/BAO/UFGroup.php +++ b/CRM/Core/BAO/UFGroup.php @@ -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); @@ -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', @@ -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(); @@ -3373,6 +3367,9 @@ public static function setComponentDefaults(&$fields, $componentId, $component, } } } + elseif (isset($values[$fldName])) { + $defaults[$fldName] = $values[$fldName]; + } } } diff --git a/CRM/Member/BAO/Membership.php b/CRM/Member/BAO/Membership.php index 4831547ca356..527ba6435873 100644 --- a/CRM/Member/BAO/Membership.php +++ b/CRM/Member/BAO/Membership.php @@ -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); diff --git a/CRM/Member/Form/Task/Batch.php b/CRM/Member/Form/Task/Batch.php index 389f1343a931..dedefe52d22f 100644 --- a/CRM/Member/Form/Task/Batch.php +++ b/CRM/Member/Form/Task/Batch.php @@ -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)) { @@ -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'); } diff --git a/templates/CRM/Batch/Form/Entry.tpl b/templates/CRM/Batch/Form/Entry.tpl index a54396e8e011..6be276ec9e95 100644 --- a/templates/CRM/Batch/Form/Entry.tpl +++ b/templates/CRM/Batch/Form/Entry.tpl @@ -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') ) }
{include file="CRM/common/jcalendar.tpl" elementName=$n elementIndex=$rowNumber batchUpdate=1} @@ -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++; @@ -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'); } }); } diff --git a/templates/CRM/Member/Form/Task/Batch.tpl b/templates/CRM/Member/Form/Task/Batch.tpl index b5ff8c9fadf9..9a7aaad8e1fe 100644 --- a/templates/CRM/Member/Form/Task/Batch.tpl +++ b/templates/CRM/Member/Form/Task/Batch.tpl @@ -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')} - {include file="CRM/common/jcalendar.tpl" elementName=$n elementIndex=$mid batchUpdate=1} - {else} - {$form.field.$mid.$n.html} - {/if} + {$form.field.$mid.$n.html} {/foreach} {/foreach}