Merge branch 'add-cancellation-incidents' into 'master'
track and charge cancellation charges See merge request saburly/psihologija!25
This commit was merged in pull request #25.
This commit is contained in:
@@ -68,6 +68,7 @@ const incidentType = {
|
|||||||
UNSCHEDULED_INCIDENT_STANDALONE: 6,
|
UNSCHEDULED_INCIDENT_STANDALONE: 6,
|
||||||
BOOKING_MOVED_TO_ANOTHER_DAY: 7,
|
BOOKING_MOVED_TO_ANOTHER_DAY: 7,
|
||||||
BOOKING_SHORTENED: 8,
|
BOOKING_SHORTENED: 8,
|
||||||
|
BOOKING_CANCELED_LATE: 9,
|
||||||
};
|
};
|
||||||
|
|
||||||
const UI_TIMEZONE = process.env.UI_TIMEZONE || 'America/Los_Angeles';
|
const UI_TIMEZONE = process.env.UI_TIMEZONE || 'America/Los_Angeles';
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ const chargeBookingChanges = (changes) => {
|
|||||||
const newEnd = newReservation.end ? moment.utc(newReservation.end) : null;
|
const newEnd = newReservation.end ? moment.utc(newReservation.end) : null;
|
||||||
|
|
||||||
const reservationTimezone = newReservation.timezone ? newReservation.timezone : UI_TIMEZONE;
|
const reservationTimezone = newReservation.timezone ? newReservation.timezone : UI_TIMEZONE;
|
||||||
const reservationHourlyRate = newReservation.hourlyRate ? newReservation.hourlyRate : undefined;
|
const reservationHourlyRate = oldReservation.hourlyRate ? oldReservation.hourlyRate : undefined;
|
||||||
|
const canceled = newReservation.canceled;
|
||||||
|
|
||||||
if (oldStart && oldEnd && newStart && newEnd && reservationHourlyRate){
|
if (oldStart && oldEnd && newStart && newEnd && reservationHourlyRate){
|
||||||
const oldReservationLength = oldEnd.diff(oldStart, 'hours', true);
|
const oldReservationLength = oldEnd.diff(oldStart, 'hours', true);
|
||||||
@@ -43,60 +44,75 @@ const chargeBookingChanges = (changes) => {
|
|||||||
|
|
||||||
const differenceFromNow = oldStart.diff(moment.utc(), 'hours');
|
const differenceFromNow = oldStart.diff(moment.utc(), 'hours');
|
||||||
|
|
||||||
if (differenceFromNow && (differenceFromNow < 24)){
|
if (differenceFromNow < 24){
|
||||||
// Changed reservation that was within 24hrs from now
|
// Changed reservation that was within 24hrs from now
|
||||||
|
const { reservationId, memberId, resourceId } = newReservation;
|
||||||
|
|
||||||
// Check if new reservation is on same day
|
if (!canceled) {
|
||||||
const sameDay = oldStart.tz(reservationTimezone).isSame(newStart.tz(reservationTimezone), 'day');
|
// Check if new reservation is on same day
|
||||||
|
const sameDay = oldStart.tz(reservationTimezone).isSame(newStart.tz(reservationTimezone), 'day');
|
||||||
|
|
||||||
const { reservationId, memberId, resourceId, hourlyRate } = newReservation;
|
if (sameDay) {
|
||||||
|
// Reservation moved in same day
|
||||||
|
// Check if member shortened the reservation
|
||||||
|
|
||||||
if (sameDay){
|
if (newReservationLength < oldReservationLength) {
|
||||||
// Reservation moved in same day
|
const differenceInLength = oldReservationLength - newReservationLength;
|
||||||
// Check if member shortened the reservation
|
const chargeFee = differenceInLength * reservationHourlyRate * BOOKING_CHANGE_PERCENTAGE_CHARGE / 100;
|
||||||
|
|
||||||
if (newReservationLength < oldReservationLength){
|
const incident = {
|
||||||
const differenceInLength = oldReservationLength - newReservationLength;
|
reservationId,
|
||||||
const chargeFee = differenceInLength*hourlyRate*BOOKING_CHANGE_PERCENTAGE_CHARGE/100;
|
memberId,
|
||||||
|
oldResourceId: oldResourceId || resourceId,
|
||||||
|
newResourceId: resourceId,
|
||||||
|
oldBookingStart: oldReservation.start,
|
||||||
|
oldBookingEnd: oldReservation.end,
|
||||||
|
newBookingStart: newReservation.start,
|
||||||
|
newBookingEnd: newReservation.end,
|
||||||
|
incidentType: incidentType.BOOKING_SHORTENED,
|
||||||
|
chargeFee,
|
||||||
|
};
|
||||||
|
|
||||||
|
incidents.push(incident);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Reservation moved to another day
|
||||||
|
// Add cancellation charge
|
||||||
|
const chargeFee = oldReservationLength * reservationHourlyRate * BOOKING_CHANGE_PERCENTAGE_CHARGE / 100;
|
||||||
|
|
||||||
const incident = {
|
const incident = {
|
||||||
reservationId,
|
reservationId,
|
||||||
memberId,
|
memberId,
|
||||||
oldResourceId: oldResourceId || newReservation.resourceId,
|
oldResourceId: oldResourceId || resourceId,
|
||||||
newResourceId: newReservation.resourceId,
|
newResourceId: resourceId,
|
||||||
oldBookingStart: oldReservation.start,
|
oldBookingStart: oldReservation.start,
|
||||||
oldBookingEnd: oldReservation.end,
|
oldBookingEnd: oldReservation.end,
|
||||||
newBookingStart: newReservation.start,
|
newBookingStart: newReservation.start,
|
||||||
newBookingEnd: newReservation.end,
|
newBookingEnd: newReservation.end,
|
||||||
incidentType: incidentType.BOOKING_SHORTENED,
|
incidentType: incidentType.BOOKING_MOVED_TO_ANOTHER_DAY,
|
||||||
chargeFee,
|
chargeFee,
|
||||||
};
|
};
|
||||||
|
|
||||||
incidents.push(incident);
|
incidents.push(incident);
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
// Reservation moved to another day
|
const chargeFee = 2 * reservationHourlyRate * oldReservationLength * BOOKING_CHANGE_PERCENTAGE_CHARGE / 100;
|
||||||
// Add cancellation charge
|
|
||||||
const chargeFee = oldReservationLength*hourlyRate*BOOKING_CHANGE_PERCENTAGE_CHARGE/100;
|
|
||||||
|
|
||||||
const incident = {
|
const incident = {
|
||||||
reservationId,
|
reservationId,
|
||||||
memberId,
|
memberId,
|
||||||
oldResourceId: oldResourceId || newReservation.resourceId,
|
oldResourceId: oldResourceId || resourceId,
|
||||||
newResourceId: newReservation.resourceId,
|
newResourceId: null,
|
||||||
oldBookingStart: oldReservation.start,
|
oldBookingStart: oldReservation.start,
|
||||||
oldBookingEnd: oldReservation.end,
|
oldBookingEnd: oldReservation.end,
|
||||||
newBookingStart: newReservation.start,
|
newBookingStart: null,
|
||||||
newBookingEnd: newReservation.end,
|
newBookingEnd: null,
|
||||||
incidentType: incidentType.BOOKING_MOVED_TO_ANOTHER_DAY,
|
incidentType: incidentType.BOOKING_CANCELED_LATE,
|
||||||
chargeFee,
|
chargeFee,
|
||||||
};
|
};
|
||||||
|
|
||||||
incidents.push(incident);
|
incidents.push(incident);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else{
|
|
||||||
// New reservation or canceled, not an incident
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -184,6 +184,8 @@ const bulkWriteReservationsWithChangesTracking = (reservations) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
instance.setDataValue('hourlyRate', previous.hourlyRate);
|
||||||
|
|
||||||
if (realChange){
|
if (realChange){
|
||||||
changes.push({
|
changes.push({
|
||||||
oldReservation: previous,
|
oldReservation: previous,
|
||||||
|
|||||||
Reference in New Issue
Block a user