Fixed bugs with primary key on bookings
This commit is contained in:
@@ -23,10 +23,17 @@ const bulkWriteChanges = ((changes) => {
|
||||
};
|
||||
|
||||
if (!oldReservation.start && !oldReservation.end && !oldReservation.resourceId){
|
||||
// new reservation
|
||||
logEntry.oldResourceId = null;
|
||||
logEntry.oldStart = null;
|
||||
logEntry.oldEnd = null;
|
||||
if (newReservation.canceled){
|
||||
//new reservation created and canceled immediately
|
||||
logEntry.oldResourceId = resourceId;
|
||||
logEntry.oldStart = start;
|
||||
logEntry.newEnd = end;
|
||||
}else{
|
||||
// new reservation
|
||||
logEntry.oldResourceId = null;
|
||||
logEntry.oldStart = null;
|
||||
logEntry.oldEnd = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (newReservation.canceled){
|
||||
|
||||
@@ -39,9 +39,10 @@ const createFeeFromIncident = (incident) => {
|
||||
let date = '';
|
||||
let price = 0;
|
||||
let quantity = 0;
|
||||
let priceExplanation = '';
|
||||
// let priceExplanation = '';
|
||||
let bookingTimeExplanation = '';
|
||||
let incidentTimeExplanation = '';
|
||||
let incidentTypeExplanation = '';
|
||||
let additionalIncidentExplanation = '';
|
||||
|
||||
let roomExplanation = '';
|
||||
@@ -62,67 +63,70 @@ const createFeeFromIncident = (incident) => {
|
||||
switch (incidentTypeNumber){
|
||||
case incidentType.UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION:
|
||||
roomExplanation = resourceName;
|
||||
dateExplanation = bookingStartMoment.clone().startOf('day').format('MMM DD, YYYY');
|
||||
dateExplanation = bookingStartMoment.clone().startOf('day').format('MMM DD');
|
||||
bookingTimeExplanation = `${bookingStartMoment.clone().format('HH:mm a')} - ${bookingEndMoment.clone().format('HH:mm a')}`;
|
||||
incidentTimeExplanation = `UNLOCK : ${unlockMoment.clone().format('HH:mm a')}`;
|
||||
unlockedIncidentLevelsPrices[incidentLevel].description
|
||||
additionalIncidentExplanation = unlockedIncidentLevelsPrices[incidentLevel].description;
|
||||
incidentTimeExplanation = ''; // `UNLOCK : ${unlockMoment.clone().format('HH:mm a')}`;
|
||||
additionalIncidentExplanation = ` ${unlockedIncidentLevelsPrices[incidentLevel].description},`;
|
||||
incidentTypeExplanation = '[Additional charge]';
|
||||
|
||||
date = bookingStartMoment.clone().startOf('day').format();
|
||||
|
||||
price = incidentPrice;
|
||||
quantity = 1;
|
||||
priceExplanation = `$${price.toFixed(2)}, 1 x $${price.toFixed(2)}`;
|
||||
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, YYYY');
|
||||
dateExplanation = bookingStartMoment.clone().startOf('day').format('MMM DD');
|
||||
bookingTimeExplanation = `${bookingStartMoment.clone().format('HH:mm a')} - ${bookingEndMoment.clone().format('HH:mm a')}`;
|
||||
incidentTimeExplanation = `UNLOCK : ${unlockMoment.clone().format('HH:mm a')}`;
|
||||
incidentTimeExplanation = ` Unlock : ${unlockMoment.clone().format('HH:mm a')},`;
|
||||
incidentTypeExplanation = '[Additional charge]';
|
||||
|
||||
date = bookingStartMoment.clone().startOf('day').format();
|
||||
|
||||
price = chargePrice;
|
||||
quantity = timeIntervalsToCharge;
|
||||
priceExplanation = `$${totalChargeFee.toFixed(2)}, ${quantity} x $${price.toFixed(2)}`;
|
||||
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, YYYY');
|
||||
dateExplanation = bookingStartMoment.clone().startOf('day').format('MMM DD');
|
||||
bookingTimeExplanation = `${bookingStartMoment.clone().format('HH:mm a')} - ${bookingEndMoment.clone().format('HH:mm a')}`;
|
||||
incidentTimeExplanation = `LOCK : ${lockMoment.clone().format('HH:mm a')}`;
|
||||
incidentTimeExplanation = ` Lock : ${lockMoment.clone().format('HH:mm a')},`;
|
||||
incidentTypeExplanation = '[Additional charge]';
|
||||
|
||||
date = bookingStartMoment.clone().startOf('day').format();
|
||||
|
||||
price = chargePrice;
|
||||
quantity = timeIntervalsToCharge;
|
||||
priceExplanation = `$${totalChargeFee.toFixed(2)}, ${quantity} x $${price.toFixed(2)}`;
|
||||
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, YYYY');
|
||||
bookingTimeExplanation = `NO RESERVATION`;
|
||||
incidentTimeExplanation = `UNLOCK : ${unlockMoment.clone().format('HH:mm a')}`;
|
||||
additionalIncidentExplanation = unlockedIncidentLevelsPrices[incidentLevel].description;
|
||||
dateExplanation = unlockMoment.clone().startOf('day').format('MMM DD');
|
||||
bookingTimeExplanation = `No reservation`;
|
||||
incidentTimeExplanation = ''; // `UNLOCK : ${unlockMoment.clone().format('HH:mm a')}`;
|
||||
additionalIncidentExplanation = ` ${unlockedIncidentLevelsPrices[incidentLevel].description},`;
|
||||
incidentTypeExplanation = '[Additional charge]';
|
||||
|
||||
date = unlockMoment.clone().startOf('day').format();
|
||||
|
||||
price = incidentPrice;
|
||||
quantity = 1;
|
||||
priceExplanation = `$${price.toFixed(2)}, 1 x $${price.toFixed(2)}`;
|
||||
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, YYYY');
|
||||
bookingTimeExplanation = `NO RESERVATION`;
|
||||
incidentTimeExplanation = `UNLOCK : ${unlockMoment.clone().format('HH:mm a')} LOCK : ${lockMoment.clone().format('HH:mm a')}`;
|
||||
additionalIncidentExplanation = '';
|
||||
dateExplanation = unlockMoment.clone().startOf('day').format('MMM DD');
|
||||
bookingTimeExplanation = `No reservation`;
|
||||
incidentTimeExplanation = ` Unlock : ${unlockMoment.clone().format('HH:mm a')} Lock : ${lockMoment.clone().format('HH:mm a')},`;
|
||||
incidentTypeExplanation = '[Additional charge]';
|
||||
|
||||
date = unlockMoment.clone().startOf('day').format();
|
||||
|
||||
price = chargePrice;
|
||||
quantity = timeIntervalsToCharge;
|
||||
priceExplanation = `$${totalChargeFee.toFixed(2)}, ${quantity} x $${price.toFixed(2)}`;
|
||||
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){
|
||||
@@ -131,15 +135,16 @@ const createFeeFromIncident = (incident) => {
|
||||
roomExplanation = oldResourceName;
|
||||
}
|
||||
|
||||
dateExplanation = `${oldBookingStartMoment.clone().format('MMM DD, YYYY')} -> ${newBookingStartMoment.clone().format('MMM DD, YYYY')}`;
|
||||
dateExplanation = `${oldBookingStartMoment.clone().format('MMM DD')} -> ${newBookingStartMoment.clone().format('MMM DD')}`;
|
||||
bookingTimeExplanation = `(${oldBookingStartMoment.clone().format('HH:mm a')} - ${oldBookingEndMoment.clone().format('HH:mm a')}) -> (${newBookingStartMoment.clone().format('HH:mm a')} - ${newBookingEndMoment.clone().format('HH:mm a')})`;
|
||||
incidentTimeExplanation = `MOVED ON : ${incidentTimestampMoment.clone().format('MMM DD, YYYY')}`;
|
||||
incidentTimeExplanation = ` Moved on : ${incidentTimestampMoment.clone().format('MMM DD, HH:mm a')},`;
|
||||
incidentTypeExplanation = '[Cancellation]';
|
||||
|
||||
date = incidentTimestampMoment.clone().startOf('day').format();
|
||||
|
||||
price = totalChargeFee;
|
||||
quantity = 1;
|
||||
priceExplanation = `$${totalChargeFee.toFixed(2)}, 1 x $${price.toFixed(2)}`;
|
||||
price = +totalChargeFee.toFixed(2);
|
||||
quantity = 1.00;
|
||||
// priceExplanation = `$${totalChargeFee.toFixed(2)}, 1 x $${price.toFixed(2)}`;
|
||||
break;
|
||||
case incidentType.BOOKING_SHORTENED:
|
||||
if (oldResourceName !== newResourceName){
|
||||
@@ -148,31 +153,33 @@ const createFeeFromIncident = (incident) => {
|
||||
roomExplanation = oldResourceName;
|
||||
}
|
||||
|
||||
dateExplanation = `${oldBookingStartMoment.clone().format('MMM DD, YYYY')}`;
|
||||
dateExplanation = `${oldBookingStartMoment.clone().format('MMM DD')}`;
|
||||
bookingTimeExplanation = `(${oldBookingStartMoment.clone().format('HH:mm a')} - ${oldBookingEndMoment.clone().format('HH:mm a')}) -> (${newBookingStartMoment.clone().format('HH:mm a')} - ${newBookingEndMoment.clone().format('HH:mm a')})`;
|
||||
incidentTimeExplanation = `SHORTENED ON : ${incidentTimestampMoment.clone().format('MMM DD, YYYY')}`;
|
||||
incidentTimeExplanation = ` Shortened on : ${incidentTimestampMoment.clone().format('MMM DD, HH:mm a')},`;
|
||||
incidentTypeExplanation = '[Cancellation]';
|
||||
|
||||
date = incidentTimestampMoment.clone().startOf('day').format();
|
||||
|
||||
price = totalChargeFee;
|
||||
quantity = 1;
|
||||
priceExplanation = `$${totalChargeFee.toFixed(2)}, 1 x $${price.toFixed(2)}`;
|
||||
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('MMM DD, YYYY')}`;
|
||||
dateExplanation = `${oldBookingStartMoment.clone().format('MMM DD')}`;
|
||||
bookingTimeExplanation = `${oldBookingStartMoment.clone().format('HH:mm a')} - ${oldBookingEndMoment.clone().format('HH:mm a')}`;
|
||||
incidentTimeExplanation = `CANCELED ON : ${incidentTimestampMoment.clone().format('MMM DD, YYYY')}`;
|
||||
incidentTimeExplanation = ` Canceled on : ${incidentTimestampMoment.clone().format('MMM DD, HH:mm a')},`;
|
||||
incidentTypeExplanation = '[Cancellation]';
|
||||
|
||||
date = incidentTimestampMoment.clone().startOf('day').format();
|
||||
|
||||
price = totalChargeFee;
|
||||
quantity = 1;
|
||||
priceExplanation = `$${totalChargeFee.toFixed(2)}, 1 x $${price.toFixed(2)}`;
|
||||
price = +totalChargeFee.toFixed(2);
|
||||
quantity = 1.00;
|
||||
// priceExplanation = `$${totalChargeFee.toFixed(2)}, 1 x $${price.toFixed(2)}`;
|
||||
break;
|
||||
}
|
||||
|
||||
const formattedName = `[INCIDENT FEES] ${officeName}, ${roomExplanation}, ${dateExplanation}, ${bookingTimeExplanation}, ${incidentTimeExplanation}, ${incidentExplanation}, ${additionalIncidentExplanation} ${additionalIncidentExplanation !== '' ? ',' : ''} ${priceExplanation}`;
|
||||
const formattedName = `${incidentTypeExplanation} ${incidentExplanation},${additionalIncidentExplanation}${incidentTimeExplanation} ${officeName}, ${roomExplanation}, ${dateExplanation}, ${bookingTimeExplanation}`;
|
||||
|
||||
return {
|
||||
name: formattedName,
|
||||
@@ -197,18 +204,16 @@ const createFeeFromBooking = (booking, resourceMappings) => {
|
||||
const officeName = officesMap[officeId].officeName || 'Unknown';
|
||||
const resourceName = resourcesMap[resourceId].resourceName || 'Unknown';
|
||||
|
||||
const totalCost = (hourlyRate*reservationLength).toFixed(2);
|
||||
|
||||
const formattedDate = startMoment.clone().startOf('day').format('MMM DD, YYYY');
|
||||
const formattedDate = startMoment.clone().startOf('day').format('MMM DD');
|
||||
const formattedStartTime = startMoment.format('HH:mm a');
|
||||
const formattedEndTime = endMoment.format('HH:mm a');
|
||||
|
||||
const formattedName = `[BOOKING FEES] ${officeName}, ${resourceName}, $${totalCost}, ${reservationLength.toFixed(2)} x $${hourlyRate.toFixed(2)}, ${formattedDate} [${formattedStartTime} - ${formattedEndTime}]`;
|
||||
const formattedName = `[Reservation] ${officeName}, ${resourceName}, ${formattedDate} [${formattedStartTime} - ${formattedEndTime}]`;
|
||||
|
||||
return {
|
||||
name: formattedName,
|
||||
price: hourlyRate,
|
||||
quantity: reservationLength,
|
||||
price: +hourlyRate.toFixed(2),
|
||||
quantity: +reservationLength.toFixed(2),
|
||||
date: startMoment.startOf('day').toISOString(),
|
||||
member: memberId,
|
||||
team: null,
|
||||
|
||||
Reference in New Issue
Block a user