Lai,Risheng
2023-11-02 30c02e0c981b16be0918483543f4b812956c45d4
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
Quintiq file version 2.0
#parent: #root
Function CalcPreviousPeriodLastShiftDay
{
  Description:
  [*
    This is to facilitate the assignment of capacity to unit period bucket with rolling shift functionality.
    E.g. We have a shift pattern of 7 days where day 1 is 8 hour, day 2 is 7 hour, day 3 is 6 hour, so forth. We also have a daily bucket of 14 days. Instead of restarting shift patterns or
    assigning each daily bucket with 8 hour, we would like to see bucket 1 ( assuming bucket 1 falls on the first week day with only 1 unit) had the capacity of 8 hour, and bucket 2 is 7 hours.
  *]
  TextBody:
  [*
    // desmondt May-11-2015 (created)
    
    value := 0;
    // Skip the calculation if its null
    if( not isnull( this.Period_MP() ) )
    {
      value := maxvalue( this.StartDate() - this.Period_MP().Start().StartOfWeek().Date(), 0 );
      periodduration := this.Period_MP().Duration().Days();
      // Check if there is ShiftPattern
      if( not isnull( this.ShiftPattern() ) )
      {
        nrofdays := this.ShiftPattern().NumberOfDays();
        // Check if have pervious and its belong to same ShiftPattern
        if( this.HasPreviousAndBelongToSameShiftPattern() )
        {
          lastshiftday := this.Previous().astype( UnitPeriodTimeBase ).PreviousPeriodLastShiftDay();
          // Check if the last ShiftDay is equal to nr of days and the sum with period duration is lesser or equal to nr of day
          if( not lastshiftday = nrofdays and
              lastshiftday + periodduration <= nrofdays )
          {
            value := periodduration + lastshiftday;
          }
          // Check if the last shift day + the period duration is greater than the nr of days
          if( lastshiftday + periodduration > nrofdays )
          {
            value := periodduration - ( nrofdays - lastshiftday )
          }
        }
        else
        {
          value := periodduration + value;
        }
        // If the pre period last shift days greater than nr of days
        if( value > nrofdays )
        {
          value := value mod nrofdays
          if( value = 0 )
          {
            value := nrofdays;
          }
        }
        value :=  minvalue( nrofdays, value );
      }
    }
    this.PreviousPeriodLastShiftDay( value );
  *]
}