-
Notifications
You must be signed in to change notification settings - Fork 33
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 the time when ResourceBooking is assigned
to the job and actively works on it.
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 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.
In the situation above, we have to create 5 WorkPeriods:
1. startDate="2020-02-28" endDate="2020-03-06" daysWorked=null
2. startDate="2020-03-07" endDate="2020-03-13" daysWorked=null
3. startDate="2020-03-14" endDate="2020-03-20" daysWorked=null
4. startDate="2020-03-21" endDate="2020-03-27" daysWorked=null
5. startDate="2020-03-28" endDate="2020-04-03" daysWorked=null
NOTE, that during creating Work Periods we should NOT set daysWorked
and should keep it as null
. This means that days worked should be treated normally as per Resource Booking start/end dates.
If ResourceBooking was created without startDate
or endDate
Work Periods would not be created, because we don't know for which period we should create them.
We should not allow deleting WorkPeriod if we fully or partially paid for it, i. e. if its paymentStatus
is partially-completed
or completed
We should not allow canceling Resource Booking or deleting if at least one payment was already processed for at least one of the Work Period of the Resource Booking. Other words, if at least one Work Period of the Resource Booking has paymentStatus
as partially-completed
or completed
.
- Once
startDate
orendDate
is 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
startDate
earlier orendDate
later, then no problem. We just create new WorkPeriods if new weeks added to the Resource Booking. - If we reduce the duration of Resource Booking by making
startDate
later orendDate
earlier, then if some weeks are fully removed from the Resource Booking duration we should remove corresponding WoekPeriods. ⚠️ CONSTRAINTS:- we should NOT allow deleting WorkPeriod if the payment for such WorkPeriod was already scheduled or processed, even if partial payment. In such case, if we try to change the dates for the Resource Booking we should return an error.
- if some Work Periods have set
daysWorked
we should make sure that with new ResourceBooking start/end dates suchdaysWorked
value is possible, or throw error
Example for the CONSTRAINTS:
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 set to `3`
28 29 30 31 <- Work Period 5 - NOT paid, daysWorked set to `2`
˄
❌ We don't allow reducing ResourceBooking End to 29 March
.
- This is because Work Period 5 has
daysWorked=2
, and if reduce RB.endDate to29 March
, there is only 1 working day left 29 March, which is not possible because we already set that user works2
days this week.
✅ 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, it's fine for Work Period 4 which has
daysWorked=3
as we still can fit 3 days until24 March
.
❌ We don't allow reducing ResourceBooking End to 23 March
.
- This is because Work Period 4 has
daysWorked=3
, and if reduce RB.endDate to23 March
, there are only 2 working days left 22 and 23 March, which is not possible because we already set that user worked3
days.
❌ 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.
At the moment Resource Bookings startDate
and endDate
could be stored in any timezone. In the UI they are displayed in the browser timezone.
But Work Periods should be always the same timezone, because if we show them in different timezones, then some users would see different weeks depend on their timezone:
- Starday - Friday
- Sunday - Saturday
- Monday - Sunday
To overcome this, we would always calculate and show WorkPeriods in a single timezone EDT
.