Fix weekend rates

This commit is contained in:
Senad Uka
2019-10-28 20:35:34 +01:00
parent c83866860d
commit 81538600a6
3 changed files with 24 additions and 4 deletions

View File

@@ -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);
}
}