yanweiyuan3
2023-08-09 588bc7829387dfc761cc25f06f77d4c81818bd10
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
Quintiq file version 2.0
#parent: #root
Function CalcPreviousPeriodLastShiftDay
{
  TextBody:
  [*
    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( UnitPeriodTransportTime ).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 );
  *]
}