From f0a3e430a2857c150a1450e19358c60aa916dafe Mon Sep 17 00:00:00 2001 From: Senad Uka Date: Tue, 3 Sep 2019 16:27:34 +0200 Subject: [PATCH] Bugfixes / Format change --- constants/constants.js | 4 +- services/integration/invoiceIntegration.js | 55 +++++++++------------- services/officeRnD/memberships.js | 8 +--- 3 files changed, 25 insertions(+), 42 deletions(-) diff --git a/constants/constants.js b/constants/constants.js index 7306753..222f0cd 100644 --- a/constants/constants.js +++ b/constants/constants.js @@ -91,8 +91,8 @@ const incidentType = { const incidentTypeExplanations = {}; incidentTypeExplanations[incidentType.UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION] = '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_AFTER_RESERVATION] = 'Room used after reservation ended'; +incidentTypeExplanations[incidentType.UNSCHEDULED_INCIDENT_BEFORE_RESERVATION] = 'Room used before reservation'; +incidentTypeExplanations[incidentType.UNSCHEDULED_INCIDENT_AFTER_RESERVATION] = 'Room used after 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_SHORTENED] = 'Reservation shortened after grace period'; diff --git a/services/integration/invoiceIntegration.js b/services/integration/invoiceIntegration.js index 67b9b81..1af6e79 100644 --- a/services/integration/invoiceIntegration.js +++ b/services/integration/invoiceIntegration.js @@ -41,11 +41,8 @@ const createFeeFromIncident = (incident) => { let date = ''; let price = 0; let quantity = 0; - // let priceExplanation = ''; let bookingTimeExplanation = ''; let incidentTimeExplanation = ''; - let incidentTypeExplanation = ''; - let additionalIncidentExplanation = ''; let roomExplanation = ''; let dateExplanation = ''; @@ -67,68 +64,60 @@ const createFeeFromIncident = (incident) => { roomExplanation = resourceName; dateExplanation = bookingStartMoment.clone().startOf('day').format('MMM DD'); bookingTimeExplanation = `[${bookingStartMoment.clone().format('HH:mm')} to ${bookingEndMoment.clone().format('HH:mm')}]`; - incidentTimeExplanation = ''; // `UNLOCK : ${unlockMoment.clone().format('HH:mm a')}`; - incidentExplanation += ` ${unlockedIncidentLevelsPrices[incidentLevel].description},`; - incidentTypeExplanation = ''; + incidentTimeExplanation = `unlock : ${unlockMoment.clone().format('HH:mm')}`; + incidentExplanation += `, ${unlockedIncidentLevelsPrices[incidentLevel].description}, ${incidentTimeExplanation}`; date = bookingStartMoment.clone().startOf('day').format(); price = +incidentPrice.toFixed(2); quantity = 1.00; - // priceExplanation = `$${price}, 1 x $${price.toFixed(2)}`; break; case incidentType.UNSCHEDULED_INCIDENT_BEFORE_RESERVATION: roomExplanation = resourceName; dateExplanation = bookingStartMoment.clone().startOf('day').format('MMM DD'); bookingTimeExplanation = `[${bookingStartMoment.clone().format('HH:mm')} to ${bookingEndMoment.clone().format('HH:mm')}]`; - incidentTimeExplanation = ` Unlock : ${unlockMoment.clone().format('HH:mm a')},`; - incidentTypeExplanation = ''; + incidentTimeExplanation = `unlock : ${unlockMoment.clone().format('HH:mm')}`; + incidentExplanation += `, ${incidentTimeExplanation}`; date = bookingStartMoment.clone().startOf('day').format(); price = +chargePrice.toFixed(2); quantity = +timeIntervalsToCharge.toFixed(2); - // priceExplanation = `$${totalChargeFee.toFixed(2)}, ${quantity} x $${price.toFixed(2)}`; break; case incidentType.UNSCHEDULED_INCIDENT_AFTER_RESERVATION: roomExplanation = resourceName; dateExplanation = bookingStartMoment.clone().startOf('day').format('MMM DD'); bookingTimeExplanation = `[${bookingStartMoment.clone().format('HH:mm')} to ${bookingEndMoment.clone().format('HH:mm')}]`; - incidentTimeExplanation = ` Lock : ${lockMoment.clone().format('HH:mm a')},`; - incidentTypeExplanation = ''; + incidentTimeExplanation = `lock : ${lockMoment.clone().format('HH:mm')}`; + incidentExplanation += `, ${incidentTimeExplanation}`; date = bookingStartMoment.clone().startOf('day').format(); price = +chargePrice.toFixed(2); quantity = +timeIntervalsToCharge.toFixed(2); - // priceExplanation = `$${totalChargeFee.toFixed(2)}, ${quantity} x $${price.toFixed(2)}`; break; case incidentType.UNLOCKED_INCIDENT_STANDALONE: roomExplanation = resourceName; dateExplanation = unlockMoment.clone().startOf('day').format('MMM DD'); bookingTimeExplanation = `[${unlockMoment.clone().format('HH:mm')} to ${lockMoment.clone().format('HH:mm')}]`; - incidentTimeExplanation = ''; // `UNLOCK : ${unlockMoment.clone().format('HH:mm a')}`; - incidentExplanation += ` ${unlockedIncidentLevelsPrices[incidentLevel].description},`; - incidentTypeExplanation = ''; + incidentTimeExplanation = `unlock : ${unlockMoment.clone().format('HH:mm')}`; + incidentExplanation += `, ${unlockedIncidentLevelsPrices[incidentLevel].description}, ${incidentTimeExplanation}`; date = unlockMoment.clone().startOf('day').format(); price = +incidentPrice.toFixed(2); quantity = 1.00; - // priceExplanation = `$${price.toFixed(2)}, 1 x $${price.toFixed(2)}`; break; case incidentType.UNSCHEDULED_INCIDENT_STANDALONE: roomExplanation = resourceName; dateExplanation = unlockMoment.clone().startOf('day').format('MMM DD'); 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')},`; - incidentTypeExplanation = ''; + //incidentTimeExplanation = `unlock : ${unlockMoment.clone().format('HH:mm')}, lock : ${lockMoment.clone().format('HH:mm')}`; date = unlockMoment.clone().startOf('day').format(); price = +chargePrice.toFixed(2); quantity = +timeIntervalsToCharge.toFixed(2); - // priceExplanation = `$${totalChargeFee.toFixed(2)}, ${quantity} x $${price.toFixed(2)}`; break; case incidentType.BOOKING_MOVED_TO_ANOTHER_DAY: // if (oldResourceName !== newResourceName){ @@ -141,14 +130,13 @@ const createFeeFromIncident = (incident) => { // dateExplanation = `${oldBookingStartMoment.clone().format('ddd, MMM DD')} -> ${newBookingStartMoment.clone().format('ddd, MMM DD')}`; dateExplanation = `${incidentTimestampMoment.clone().format('MMM DD')}`; bookingTimeExplanation = `[${newBookingStartMoment.clone().format('HH:mm')} to ${newBookingEndMoment.clone().format('HH:mm')}]`; - incidentTimeExplanation = ` Moved on : ${incidentTimestampMoment.clone().format('MMM DD, HH:mm a')},`; - incidentTypeExplanation = '[Cancellation]'; + incidentTimeExplanation = `moved on : ${incidentTimestampMoment.clone().format('MMM DD, HH:mm')}`; + incidentExplanation += `, ${incidentTimeExplanation}`; date = incidentTimestampMoment.clone().startOf('day').format(); price = +totalChargeFee.toFixed(2); quantity = 1.00; - // priceExplanation = `$${totalChargeFee.toFixed(2)}, 1 x $${price.toFixed(2)}`; break; case incidentType.BOOKING_SHORTENED: // if (oldResourceName !== newResourceName){ @@ -161,28 +149,26 @@ const createFeeFromIncident = (incident) => { // dateExplanation = `${oldBookingStartMoment.clone().format('ddd, MMM DD')}`; dateExplanation = `${incidentTimestampMoment.clone().format('MMM DD')}`; bookingTimeExplanation = `[${newBookingStartMoment.clone().format('HH:mm')} to ${newBookingEndMoment.clone().format('HH:mm')}]`; - incidentTimeExplanation = ` Shortened on : ${incidentTimestampMoment.clone().format('MMM DD, HH:mm a')},`; - incidentTypeExplanation = '[Cancellation]'; + incidentTimeExplanation = `shortened on : ${incidentTimestampMoment.clone().format('MMM DD, HH:mm')}`; + incidentExplanation += `, ${incidentTimeExplanation}`; date = incidentTimestampMoment.clone().startOf('day').format(); price = +totalChargeFee.toFixed(2); quantity = 1.00; - // priceExplanation = `$${totalChargeFee.toFixed(2)}, 1 x $${price.toFixed(2)}`; break; case incidentType.BOOKING_CANCELED_LATE: roomExplanation = oldResourceName; // dateExplanation = `${oldBookingStartMoment.clone().format('ddd, MMM DD')}`; dateExplanation = `${incidentTimestampMoment.clone().format('MMM DD')}`; bookingTimeExplanation = `[${oldBookingStartMoment.clone().format('HH:mm')} to ${oldBookingEndMoment.clone().format('HH:mm')}]`; - incidentTimeExplanation = ` Canceled on : ${incidentTimestampMoment.clone().format('MMM DD, HH:mm a')},`; - incidentTypeExplanation = '[Cancellation]'; + incidentTimeExplanation = `canceled on : ${incidentTimestampMoment.clone().format('MMM DD, HH:mm')}`; + incidentExplanation += `, ${incidentTimeExplanation}`; date = incidentTimestampMoment.clone().startOf('day').format(); price = +totalChargeFee.toFixed(2); quantity = 1.00; - // priceExplanation = `$${totalChargeFee.toFixed(2)}, 1 x $${price.toFixed(2)}`; break; } @@ -242,7 +228,8 @@ const createNegativeFeeForDiscount = (memberData, dateRange) => { let membershipFeeForDiscount = 0; membershipFees.forEach((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; } }); @@ -310,6 +297,7 @@ const getMembersFeesForDateRange = (dateRange, memberIds) => { } }); + const memberIdTeamMappings = {}; const membersMap = {}; const oneMemberObject = { totalBookedHours: 0, @@ -323,13 +311,12 @@ const getMembersFeesForDateRange = (dateRange, memberIds) => { bookingData: Object.assign({}, oneMemberObject), membershipFees: membershipsMap[member.memberId] || [], }; - }); - const memberIdTeamMappings = {}; - membersList.forEach((member) => { memberIdTeamMappings[member.memberId] = member.teamId; }); + const memberIdsToUse = memberIds.length > 0 ? memberIds : Object.keys(membersMap); + const allFees = []; allIncidents.forEach((incident) => { @@ -440,7 +427,7 @@ const getMembersFeesForDateRange = (dateRange, memberIds) => { }); //add discount - memberIds.forEach((memberId) => { + memberIdsToUse.forEach((memberId) => { const discountFee = createNegativeFeeForDiscount(membersMap[memberId], dateRange); if (discountFee){ allFees.push(discountFee); diff --git a/services/officeRnD/memberships.js b/services/officeRnD/memberships.js index 7049179..fbef195 100644 --- a/services/officeRnD/memberships.js +++ b/services/officeRnD/memberships.js @@ -39,12 +39,8 @@ const reformatMembershipsName = (memberships) => { memberships.forEach((membership) => { const { name, _id } = membership; - if (name && name.length > 0 && name[0] !== '['){ - DISCOUNT_PLANS.forEach((discountPlan) => { - if (name === discountPlan){ - asyncMembershipUpdates.push(API.put(`memberships/${_id}`, {name: `[${name}]`})); - } - }); + if (name && name.length > 0 && name[0] !== '[' && DISCOUNT_PLANS.indexOf(name) !== -1){ + asyncMembershipUpdates.push(API.put(`memberships/${_id}`, {name: `[${name}]`})); } });