| 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 ); | 
|   *] | 
| } |