Skip to content

Work Periods (WP) Automation and Constraints

maxceem edited this page Apr 22, 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 time between Resource Bookings start and end dates.

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

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 or if the payment is in progress. This means that if any associated WorkPeriodsPayment has status completed or in-progress we should not be able to remove WorkPeriod.

ResourceBooking canceling or deleting

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 or in-progress.

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.

Default Days Worked calucalation

We don't set daysWorked for Work Periods when creating them. But if we want to process a payment and a manager didn't specify the daysWorked we would have to calculate its default value based on the Resource Booking startDate and endDate using the next logic. We count as daysWorked all the days inside Work Periods which are:

  • working days (not Sunday or Saturday)
  • which are between startDate and endDate of the Resource Booking

For example, we have a Resource Booking with Start 5 March 2021 and End `30 March 2021

March 2021

Su Mo Tu We Th Fr Sa  
                ˯
    1  2  3  4  5  6    <- default "daysWorked" = 1
 7  8  9 10 11 12 13    <- default "daysWorked" = 5
14 15 16 17 18 19 20    <- default "daysWorked" = 5
21 22 23 24 25 26 27    <- default "daysWorked" = 5
28 29 30 31             <- default "daysWorked" = 2
      ˄