Skip to content

Work Periods (WP) Automation and Constraints

maxceem edited this page Apr 21, 2021 · 17 revisions

Work Period (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.

ResourceBooking is created

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.

WorkPeriod deleting

We should not allow deleting WorkPeriod if we fully or partially paid for it, i. e. if its paymentStatus is partially-completed or completed

ResourceBooking canceling or deleting

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.

ResourceBooking startDate or endDate is changed

  • Once startDate or endDate 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 or endDate 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 or endDate 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.

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
28 29 30 31             <- Work Period 5 - NOT paid
      ˄

✅ 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.

❌ 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.