Fix weekend rates
This commit is contained in:
@@ -193,7 +193,16 @@ const bulkWriteReservationsWithChangesTracking = (reservations, resourcesMap) =>
|
||||
if (parseFloat(instance.previous('hourlyRate') > 0)) {
|
||||
instance.setDataValue('hourlyRate', instance.previous('hourlyRate'));
|
||||
}else{
|
||||
const hourlyRate = resourceId ? resourcesMap[resourceId].price : 0;
|
||||
//Determine if we should apply weekend price or work day price
|
||||
const newStartWeekDay = moment.utc(instance.start).isoWeekday();
|
||||
const isWeekend = newStartWeekDay > 5; //6 - Saturday, 7 - Sunday
|
||||
let hourlyRate;
|
||||
if (isWeekend){
|
||||
hourlyRate = resourceId ? resourcesMap[resourceId].price.weekendPrice : 0;
|
||||
}else{
|
||||
hourlyRate = resourceId ? resourcesMap[resourceId].price.price : 0;
|
||||
}
|
||||
console.log(hourlyRate);
|
||||
instance.setDataValue('hourlyRate', hourlyRate);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,9 +9,17 @@ const fetchRates = () => {
|
||||
const rates = result.data || [];
|
||||
const cleanedRates = [];
|
||||
rates.forEach(rate => {
|
||||
const additionalRates = rate.rates;
|
||||
let weekendRate = rate.price; //fallback price
|
||||
additionalRates.forEach(additionalRate => {
|
||||
if (additionalRate.isWeekendRate){
|
||||
weekendRate = additionalRate.price;
|
||||
}
|
||||
});
|
||||
cleanedRates.push({
|
||||
rateId: rate['_id'],
|
||||
price: rate.price,
|
||||
weekendPrice: weekendRate
|
||||
});
|
||||
});
|
||||
resolve(cleanedRates);
|
||||
|
||||
Reference in New Issue
Block a user