-
Notifications
You must be signed in to change notification settings - Fork 32
Work Periods (WP) Automation and Constraints
We have to keep Work Periods in sync with data in Resource Bookings because Work Periods represent the weeks of time between Resource Bookings' start and end dates.
General rules for Work Periods:
- Work Periods should be created, updated, deleted automatically for the Resource Bookoings, based on the Resource Bookings start/end dates
- For each Work Period we have to calculated
daysWorkedautomatically to reflect how many working days fit that particular week based on the Resource Bookings start/end dates (see section ResourceBooking is created for details) - We should be able to manually update
daysWorkedusing endpoints to some other values other than set automatically - When we change Resource Bookings start/end dates, we should not re-calculate
daysWorkedfor the Work Periods expect for the first and last Work Period ifdaysWorkedchanged for them because of the changing of the start/end dates for the Resource Booking (see section ResourceBookingstartDateorendDateis changed for details)
Imagine we created a ResourceBooking for some work from the 1st March 2021 till 30th March 2021:
March 2021
Su Mo Tu We Th Fr Sa
˯
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
˄
In such a case, we have to create for this ResourceBooking 5 WorkPeriods to cover all this time.
Each WorkPeriod should ALWAYS represent 1 FULL week from Sunday to Saturday and daysWorked defines how many days the member worked at that week.
Sunday and Saturday are treated as days off and should NOT be counted as daysWorked. So full week working days would be equal to 5 by default.
In the situation above, we have to create 5 WorkPeriods:
1. startDate="2020-02-28" endDate="2020-03-06" daysWorked=5
2. startDate="2020-03-07" endDate="2020-03-13" daysWorked=5
3. startDate="2020-03-14" endDate="2020-03-20" daysWorked=5
4. startDate="2020-03-21" endDate="2020-03-27" daysWorked=5
5. startDate="2020-03-28" endDate="2020-04-03" daysWorked=2
NOTE, that WorkPeriod 5 represents the FULL week from Sunday 28 March till Satruday 3 April, but we set that in that week member worked only 2 days, because ResourceBooking was assigned only until 30 March.
We should not allow deleting WorkPeriod if we fully or partially paid for it or if the payment is in progress. This means that if any associated WorkPeriodsPayment has status completed, in-progress or scheduled we should not be able to remove WorkPeriod.
We should not allow canceling Resource Booking or deleting if at least one payment was already processed or in progress for at least one of the Work Period of the Resource Booking. In other words, if at least one Work Period has associated WorkPeriodPayment with status completed, in-progress or scheduled.
- Once
startDateorendDateis set, we don't allow removing them. Because we if remove dates, we have to remove all corresponding WorkPeriods. - If we extend the duration of Resource Booking by making
startDateearlier orendDatelater, then:- For existent Work Periods which are in the middle for time period DO NOT recalculate
daysWorked - For the first and last existent Work Periods we have to recalculate
daysWorkedif it's changed due tostartDateorendDatechange - Just create new WorkPeriods if new weeks added to the Resource Booking, and calculated
daysWorkedfor them
- For existent Work Periods which are in the middle for time period DO NOT recalculate
- If we reduce the duration of Resource Booking by making
startDatelater orendDateearlier, then:- if some weeks are fully removed from the Resource Booking duration we should remove corresponding WoekPeriods
- if currently set
daysWorkedis not possible - we have to update it to maximal possible as per new Resource BookingstartDate/endDate.
⚠️ CONSTRAINTS:- we should NOT allow deleting WorkPeriod if the payment for such WorkPeriod was already in-progress or completed, even if partial payment. In such case, if we try to change the dates for the Resource Booking we should return an error.
We have a Resource Booking with Start 1 March 2021 and End 30 March 2021. And we have 5 corresponding Work Periods: 4 already paid, and 1 not yet paid.
March 2021
Su Mo Tu We Th Fr Sa
˯
1 2 3 4 5 6 <- Work Period 1 - PAID
7 8 9 10 11 12 13 <- Work Period 2 - PAID
14 15 16 17 18 19 20 <- Work Period 3 - PAID
21 22 23 24 25 26 27 <- Work Period 4 - PAID, `daysWorked` is set to `5`
28 29 30 31 <- Work Period 5 - NOT paid, `daysWorked` is set to `2`
˄
✅ We allow reducing ResourceBooking End to 29 March.
- Work Period 5
daysWorked=2would be updated to1to fit the newendDateof the Resource Booking
✅ We allow reducing ResourceBooking End to 24 March.
- As a result Work Period 5 would be fully removed, which is fine because it’s not paid yet.
- Also, Work Period 4
daysWorked=5would be updated to3to fit the newendDateof the Resource Booking
❌ We don't allow reducing ResourceBooking End to 20 March.
- This is because this would result in deleting Work Period 4 which was already paid.
Imagine we have a Resource Booking from 11 March 2021 till 23 March 2021:
March 2021
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6
˯
7 8 9 10 11 12 13 <- Work Period 1, `daysWorked=2` (2 is maximum working days, were set automatically)
14 15 16 17 18 19 20 <- Work Period 2, `daysWorked=3` (imagine manager set working days to `3` event though it's possible to have `5`)
21 22 23 24 25 26 27 <- Work Period 3, `daysWorked=2` (imagine manager set working days to `2` event though it's possible to have `4`)
˄
28 29 30 31
And we change startDate to 9 March 2021 and endDate to 30 March 2021, this would lead to the next situation:
March 2021
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6
˯
7 8 9 10 11 12 13 <- Work Period 1, `daysWorked=4` (updated to `4`, because it was the first WorkPeriod and it have to be recalcualted)
14 15 16 17 18 19 20 <- Work Period 2, `daysWorked=3` (stays as it was before as `3` - we don't update Work Period in the middle)
21 22 23 24 25 26 27 <- Work Period 3, `daysWorked=5` (as this was the last Work Period, we recalculated days worked for it)
28 29 30 31 <- Work Period 4, `daysWorked=2` (this Work Period has been created)
˄