Skip to content

Work Periods (WP) Automation and Constraints

maxceem edited this page Jun 10, 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 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 daysPaid=0
2. startDate="2020-03-07" endDate="2020-03-13" daysWorked=5 daysPaid=0
3. startDate="2020-03-14" endDate="2020-03-20" daysWorked=5 daysPaid=0
4. startDate="2020-03-21" endDate="2020-03-27" daysWorked=5 daysPaid=0
5. startDate="2020-03-28" endDate="2020-04-03" daysWorked=2 daysPaid=0

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.

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 some WorkPeriod has daysWorked set, we don't update it.
  • 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.
    • if some WorkPeriod has daysWorked set (not null) then we have to make sure that such daysWorked is a possible value. If currently set daysWorked is not possible - we have to update it to maximal possible as per new Resource Booking startDate/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.

Examples 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` 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=2 would be updated to 1 to fit the new endDate of 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=5 would be updated to 3 to fit the new endDate of 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.

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
      ˄