Bugfixes / Format change

This commit is contained in:
Senad Uka
2019-09-03 16:27:34 +02:00
parent 2e244d7bb7
commit f0a3e430a2
3 changed files with 25 additions and 42 deletions

View File

@@ -91,8 +91,8 @@ const incidentType = {
const incidentTypeExplanations = {}; const incidentTypeExplanations = {};
incidentTypeExplanations[incidentType.UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION] = 'Door left unlocked'; incidentTypeExplanations[incidentType.UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION] = 'Door left unlocked';
incidentTypeExplanations[incidentType.UNLOCKED_INCIDENT_STANDALONE] = 'Door left unlocked'; incidentTypeExplanations[incidentType.UNLOCKED_INCIDENT_STANDALONE] = 'Door left unlocked';
incidentTypeExplanations[incidentType.UNSCHEDULED_INCIDENT_BEFORE_RESERVATION] = 'Room used before reservation started'; incidentTypeExplanations[incidentType.UNSCHEDULED_INCIDENT_BEFORE_RESERVATION] = 'Room used before reservation';
incidentTypeExplanations[incidentType.UNSCHEDULED_INCIDENT_AFTER_RESERVATION] = 'Room used after reservation ended'; incidentTypeExplanations[incidentType.UNSCHEDULED_INCIDENT_AFTER_RESERVATION] = 'Room used after reservation';
incidentTypeExplanations[incidentType.UNSCHEDULED_INCIDENT_STANDALONE] = 'Room used without reservation'; incidentTypeExplanations[incidentType.UNSCHEDULED_INCIDENT_STANDALONE] = 'Room used without reservation';
incidentTypeExplanations[incidentType.BOOKING_MOVED_TO_ANOTHER_DAY] = 'Reservation moved to another day'; incidentTypeExplanations[incidentType.BOOKING_MOVED_TO_ANOTHER_DAY] = 'Reservation moved to another day';
incidentTypeExplanations[incidentType.BOOKING_SHORTENED] = 'Reservation shortened after grace period'; incidentTypeExplanations[incidentType.BOOKING_SHORTENED] = 'Reservation shortened after grace period';

View File

@@ -41,11 +41,8 @@ const createFeeFromIncident = (incident) => {
let date = ''; let date = '';
let price = 0; let price = 0;
let quantity = 0; let quantity = 0;
// let priceExplanation = '';
let bookingTimeExplanation = ''; let bookingTimeExplanation = '';
let incidentTimeExplanation = ''; let incidentTimeExplanation = '';
let incidentTypeExplanation = '';
let additionalIncidentExplanation = '';
let roomExplanation = ''; let roomExplanation = '';
let dateExplanation = ''; let dateExplanation = '';
@@ -67,68 +64,60 @@ const createFeeFromIncident = (incident) => {
roomExplanation = resourceName; roomExplanation = resourceName;
dateExplanation = bookingStartMoment.clone().startOf('day').format('MMM DD'); dateExplanation = bookingStartMoment.clone().startOf('day').format('MMM DD');
bookingTimeExplanation = `[${bookingStartMoment.clone().format('HH:mm')} to ${bookingEndMoment.clone().format('HH:mm')}]`; bookingTimeExplanation = `[${bookingStartMoment.clone().format('HH:mm')} to ${bookingEndMoment.clone().format('HH:mm')}]`;
incidentTimeExplanation = ''; // `UNLOCK : ${unlockMoment.clone().format('HH:mm a')}`; incidentTimeExplanation = `unlock : ${unlockMoment.clone().format('HH:mm')}`;
incidentExplanation += ` ${unlockedIncidentLevelsPrices[incidentLevel].description},`; incidentExplanation += `, ${unlockedIncidentLevelsPrices[incidentLevel].description}, ${incidentTimeExplanation}`;
incidentTypeExplanation = '';
date = bookingStartMoment.clone().startOf('day').format(); date = bookingStartMoment.clone().startOf('day').format();
price = +incidentPrice.toFixed(2); price = +incidentPrice.toFixed(2);
quantity = 1.00; quantity = 1.00;
// priceExplanation = `$${price}, 1 x $${price.toFixed(2)}`;
break; break;
case incidentType.UNSCHEDULED_INCIDENT_BEFORE_RESERVATION: case incidentType.UNSCHEDULED_INCIDENT_BEFORE_RESERVATION:
roomExplanation = resourceName; roomExplanation = resourceName;
dateExplanation = bookingStartMoment.clone().startOf('day').format('MMM DD'); dateExplanation = bookingStartMoment.clone().startOf('day').format('MMM DD');
bookingTimeExplanation = `[${bookingStartMoment.clone().format('HH:mm')} to ${bookingEndMoment.clone().format('HH:mm')}]`; bookingTimeExplanation = `[${bookingStartMoment.clone().format('HH:mm')} to ${bookingEndMoment.clone().format('HH:mm')}]`;
incidentTimeExplanation = ` Unlock : ${unlockMoment.clone().format('HH:mm a')},`; incidentTimeExplanation = `unlock : ${unlockMoment.clone().format('HH:mm')}`;
incidentTypeExplanation = ''; incidentExplanation += `, ${incidentTimeExplanation}`;
date = bookingStartMoment.clone().startOf('day').format(); date = bookingStartMoment.clone().startOf('day').format();
price = +chargePrice.toFixed(2); price = +chargePrice.toFixed(2);
quantity = +timeIntervalsToCharge.toFixed(2); quantity = +timeIntervalsToCharge.toFixed(2);
// priceExplanation = `$${totalChargeFee.toFixed(2)}, ${quantity} x $${price.toFixed(2)}`;
break; break;
case incidentType.UNSCHEDULED_INCIDENT_AFTER_RESERVATION: case incidentType.UNSCHEDULED_INCIDENT_AFTER_RESERVATION:
roomExplanation = resourceName; roomExplanation = resourceName;
dateExplanation = bookingStartMoment.clone().startOf('day').format('MMM DD'); dateExplanation = bookingStartMoment.clone().startOf('day').format('MMM DD');
bookingTimeExplanation = `[${bookingStartMoment.clone().format('HH:mm')} to ${bookingEndMoment.clone().format('HH:mm')}]`; bookingTimeExplanation = `[${bookingStartMoment.clone().format('HH:mm')} to ${bookingEndMoment.clone().format('HH:mm')}]`;
incidentTimeExplanation = ` Lock : ${lockMoment.clone().format('HH:mm a')},`; incidentTimeExplanation = `lock : ${lockMoment.clone().format('HH:mm')}`;
incidentTypeExplanation = ''; incidentExplanation += `, ${incidentTimeExplanation}`;
date = bookingStartMoment.clone().startOf('day').format(); date = bookingStartMoment.clone().startOf('day').format();
price = +chargePrice.toFixed(2); price = +chargePrice.toFixed(2);
quantity = +timeIntervalsToCharge.toFixed(2); quantity = +timeIntervalsToCharge.toFixed(2);
// priceExplanation = `$${totalChargeFee.toFixed(2)}, ${quantity} x $${price.toFixed(2)}`;
break; break;
case incidentType.UNLOCKED_INCIDENT_STANDALONE: case incidentType.UNLOCKED_INCIDENT_STANDALONE:
roomExplanation = resourceName; roomExplanation = resourceName;
dateExplanation = unlockMoment.clone().startOf('day').format('MMM DD'); dateExplanation = unlockMoment.clone().startOf('day').format('MMM DD');
bookingTimeExplanation = `[${unlockMoment.clone().format('HH:mm')} to ${lockMoment.clone().format('HH:mm')}]`; bookingTimeExplanation = `[${unlockMoment.clone().format('HH:mm')} to ${lockMoment.clone().format('HH:mm')}]`;
incidentTimeExplanation = ''; // `UNLOCK : ${unlockMoment.clone().format('HH:mm a')}`; incidentTimeExplanation = `unlock : ${unlockMoment.clone().format('HH:mm')}`;
incidentExplanation += ` ${unlockedIncidentLevelsPrices[incidentLevel].description},`; incidentExplanation += `, ${unlockedIncidentLevelsPrices[incidentLevel].description}, ${incidentTimeExplanation}`;
incidentTypeExplanation = '';
date = unlockMoment.clone().startOf('day').format(); date = unlockMoment.clone().startOf('day').format();
price = +incidentPrice.toFixed(2); price = +incidentPrice.toFixed(2);
quantity = 1.00; quantity = 1.00;
// priceExplanation = `$${price.toFixed(2)}, 1 x $${price.toFixed(2)}`;
break; break;
case incidentType.UNSCHEDULED_INCIDENT_STANDALONE: case incidentType.UNSCHEDULED_INCIDENT_STANDALONE:
roomExplanation = resourceName; roomExplanation = resourceName;
dateExplanation = unlockMoment.clone().startOf('day').format('MMM DD'); dateExplanation = unlockMoment.clone().startOf('day').format('MMM DD');
bookingTimeExplanation = `[${unlockMoment.clone().format('HH:mm')} to ${lockMoment.clone().format('HH:mm')}]`; bookingTimeExplanation = `[${unlockMoment.clone().format('HH:mm')} to ${lockMoment.clone().format('HH:mm')}]`;
incidentTimeExplanation = ` Unlock : ${unlockMoment.clone().format('HH:mm a')} Lock : ${lockMoment.clone().format('HH:mm a')},`; //incidentTimeExplanation = `unlock : ${unlockMoment.clone().format('HH:mm')}, lock : ${lockMoment.clone().format('HH:mm')}`;
incidentTypeExplanation = '';
date = unlockMoment.clone().startOf('day').format(); date = unlockMoment.clone().startOf('day').format();
price = +chargePrice.toFixed(2); price = +chargePrice.toFixed(2);
quantity = +timeIntervalsToCharge.toFixed(2); quantity = +timeIntervalsToCharge.toFixed(2);
// priceExplanation = `$${totalChargeFee.toFixed(2)}, ${quantity} x $${price.toFixed(2)}`;
break; break;
case incidentType.BOOKING_MOVED_TO_ANOTHER_DAY: case incidentType.BOOKING_MOVED_TO_ANOTHER_DAY:
// if (oldResourceName !== newResourceName){ // if (oldResourceName !== newResourceName){
@@ -141,14 +130,13 @@ const createFeeFromIncident = (incident) => {
// dateExplanation = `${oldBookingStartMoment.clone().format('ddd, MMM DD')} -> ${newBookingStartMoment.clone().format('ddd, MMM DD')}`; // dateExplanation = `${oldBookingStartMoment.clone().format('ddd, MMM DD')} -> ${newBookingStartMoment.clone().format('ddd, MMM DD')}`;
dateExplanation = `${incidentTimestampMoment.clone().format('MMM DD')}`; dateExplanation = `${incidentTimestampMoment.clone().format('MMM DD')}`;
bookingTimeExplanation = `[${newBookingStartMoment.clone().format('HH:mm')} to ${newBookingEndMoment.clone().format('HH:mm')}]`; bookingTimeExplanation = `[${newBookingStartMoment.clone().format('HH:mm')} to ${newBookingEndMoment.clone().format('HH:mm')}]`;
incidentTimeExplanation = ` Moved on : ${incidentTimestampMoment.clone().format('MMM DD, HH:mm a')},`; incidentTimeExplanation = `moved on : ${incidentTimestampMoment.clone().format('MMM DD, HH:mm')}`;
incidentTypeExplanation = '[Cancellation]'; incidentExplanation += `, ${incidentTimeExplanation}`;
date = incidentTimestampMoment.clone().startOf('day').format(); date = incidentTimestampMoment.clone().startOf('day').format();
price = +totalChargeFee.toFixed(2); price = +totalChargeFee.toFixed(2);
quantity = 1.00; quantity = 1.00;
// priceExplanation = `$${totalChargeFee.toFixed(2)}, 1 x $${price.toFixed(2)}`;
break; break;
case incidentType.BOOKING_SHORTENED: case incidentType.BOOKING_SHORTENED:
// if (oldResourceName !== newResourceName){ // if (oldResourceName !== newResourceName){
@@ -161,28 +149,26 @@ const createFeeFromIncident = (incident) => {
// dateExplanation = `${oldBookingStartMoment.clone().format('ddd, MMM DD')}`; // dateExplanation = `${oldBookingStartMoment.clone().format('ddd, MMM DD')}`;
dateExplanation = `${incidentTimestampMoment.clone().format('MMM DD')}`; dateExplanation = `${incidentTimestampMoment.clone().format('MMM DD')}`;
bookingTimeExplanation = `[${newBookingStartMoment.clone().format('HH:mm')} to ${newBookingEndMoment.clone().format('HH:mm')}]`; bookingTimeExplanation = `[${newBookingStartMoment.clone().format('HH:mm')} to ${newBookingEndMoment.clone().format('HH:mm')}]`;
incidentTimeExplanation = ` Shortened on : ${incidentTimestampMoment.clone().format('MMM DD, HH:mm a')},`; incidentTimeExplanation = `shortened on : ${incidentTimestampMoment.clone().format('MMM DD, HH:mm')}`;
incidentTypeExplanation = '[Cancellation]'; incidentExplanation += `, ${incidentTimeExplanation}`;
date = incidentTimestampMoment.clone().startOf('day').format(); date = incidentTimestampMoment.clone().startOf('day').format();
price = +totalChargeFee.toFixed(2); price = +totalChargeFee.toFixed(2);
quantity = 1.00; quantity = 1.00;
// priceExplanation = `$${totalChargeFee.toFixed(2)}, 1 x $${price.toFixed(2)}`;
break; break;
case incidentType.BOOKING_CANCELED_LATE: case incidentType.BOOKING_CANCELED_LATE:
roomExplanation = oldResourceName; roomExplanation = oldResourceName;
// dateExplanation = `${oldBookingStartMoment.clone().format('ddd, MMM DD')}`; // dateExplanation = `${oldBookingStartMoment.clone().format('ddd, MMM DD')}`;
dateExplanation = `${incidentTimestampMoment.clone().format('MMM DD')}`; dateExplanation = `${incidentTimestampMoment.clone().format('MMM DD')}`;
bookingTimeExplanation = `[${oldBookingStartMoment.clone().format('HH:mm')} to ${oldBookingEndMoment.clone().format('HH:mm')}]`; bookingTimeExplanation = `[${oldBookingStartMoment.clone().format('HH:mm')} to ${oldBookingEndMoment.clone().format('HH:mm')}]`;
incidentTimeExplanation = ` Canceled on : ${incidentTimestampMoment.clone().format('MMM DD, HH:mm a')},`; incidentTimeExplanation = `canceled on : ${incidentTimestampMoment.clone().format('MMM DD, HH:mm')}`;
incidentTypeExplanation = '[Cancellation]'; incidentExplanation += `, ${incidentTimeExplanation}`;
date = incidentTimestampMoment.clone().startOf('day').format(); date = incidentTimestampMoment.clone().startOf('day').format();
price = +totalChargeFee.toFixed(2); price = +totalChargeFee.toFixed(2);
quantity = 1.00; quantity = 1.00;
// priceExplanation = `$${totalChargeFee.toFixed(2)}, 1 x $${price.toFixed(2)}`;
break; break;
} }
@@ -242,7 +228,8 @@ const createNegativeFeeForDiscount = (memberData, dateRange) => {
let membershipFeeForDiscount = 0; let membershipFeeForDiscount = 0;
membershipFees.forEach((membershipFee) => { membershipFees.forEach((membershipFee) => {
const {name, price} = membershipFee; const {name, price} = membershipFee;
if (DISCOUNT_PLANS.indexOf(name) !== -1){ const cleanName = name.replace('[', '').replace(']', '').trim();
if (DISCOUNT_PLANS.indexOf(cleanName) !== -1){
membershipFeeForDiscount = price; membershipFeeForDiscount = price;
} }
}); });
@@ -310,6 +297,7 @@ const getMembersFeesForDateRange = (dateRange, memberIds) => {
} }
}); });
const memberIdTeamMappings = {};
const membersMap = {}; const membersMap = {};
const oneMemberObject = { const oneMemberObject = {
totalBookedHours: 0, totalBookedHours: 0,
@@ -323,13 +311,12 @@ const getMembersFeesForDateRange = (dateRange, memberIds) => {
bookingData: Object.assign({}, oneMemberObject), bookingData: Object.assign({}, oneMemberObject),
membershipFees: membershipsMap[member.memberId] || [], membershipFees: membershipsMap[member.memberId] || [],
}; };
});
const memberIdTeamMappings = {};
membersList.forEach((member) => {
memberIdTeamMappings[member.memberId] = member.teamId; memberIdTeamMappings[member.memberId] = member.teamId;
}); });
const memberIdsToUse = memberIds.length > 0 ? memberIds : Object.keys(membersMap);
const allFees = []; const allFees = [];
allIncidents.forEach((incident) => { allIncidents.forEach((incident) => {
@@ -440,7 +427,7 @@ const getMembersFeesForDateRange = (dateRange, memberIds) => {
}); });
//add discount //add discount
memberIds.forEach((memberId) => { memberIdsToUse.forEach((memberId) => {
const discountFee = createNegativeFeeForDiscount(membersMap[memberId], dateRange); const discountFee = createNegativeFeeForDiscount(membersMap[memberId], dateRange);
if (discountFee){ if (discountFee){
allFees.push(discountFee); allFees.push(discountFee);

View File

@@ -39,12 +39,8 @@ const reformatMembershipsName = (memberships) => {
memberships.forEach((membership) => { memberships.forEach((membership) => {
const { name, _id } = membership; const { name, _id } = membership;
if (name && name.length > 0 && name[0] !== '['){ if (name && name.length > 0 && name[0] !== '[' && DISCOUNT_PLANS.indexOf(name) !== -1){
DISCOUNT_PLANS.forEach((discountPlan) => { asyncMembershipUpdates.push(API.put(`memberships/${_id}`, {name: `[${name}]`}));
if (name === discountPlan){
asyncMembershipUpdates.push(API.put(`memberships/${_id}`, {name: `[${name}]`}));
}
});
} }
}); });