lazhen
2024-10-11 cbf2cc895f1d1e7dcf522a462e77709d92667747
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
Quintiq file version 2.0
#parent: #root
StaticMethod BatchSetUnitShiftPattern (
  Unit unit,
  ShiftPattern shiftPattern,
  Date startDate,
  Date endDate,
  Numbers weekdays
)
{
  TextBody:
  [*
    // Akari Oct-10-2024 (created)
    owner := unit.MacroPlan();
    dayPeriod_MPs := selectsortedset( owner,Period_MP,period_MP, 
                                      period_MP.TimeUnit() = 'Day' and 
                                      period_MP.StartDate() >= startDate and 
                                      period_MP.EndDate() <= endDate and exists( weekdays, Elements,dayOfWeek,dayOfWeek = period_MP.StartDate().DayOfWeek() ) ,period_MP.StartDate());
    weekPeriod_MPs := selectsortedset( owner,Period_MP,period_MP, 
                                       period_MP.TimeUnit() = 'Week' and 
                                       period_MP.StartDate() >= startDate and 
                                       period_MP.EndDate() <= endDate and exists( weekdays, Elements,dayOfWeek,dayOfWeek = period_MP.StartDate().DayOfWeek() ),period_MP.StartDate());
    
    if( dayPeriod_MPs.Size() > 0 ){
      unitPeriodTimes := selectset( unit,UnitPeriod.astype( UnitPeriodTime ),unitPeriodTime,exists( dayPeriod_MPs,Elements,period_MP,period_MP = unitPeriodTime.Period_MP()) and not isnull( unitPeriodTime.UnitAvailability()));
      if( unitPeriodTimes.Size() > 0 ){
        LocalTool::SetUnitShiftPattern( owner,unitPeriodTimes,shiftPattern );
      }
      
    }
    if( weekPeriod_MPs.Size() <> 0 ){
      traverse( weekPeriod_MPs,Elements,period_MP ){
        unitPeriodTimes := selectset( unit,UnitPeriod.astype( UnitPeriodTime ),unitPeriodTime,period_MP = unitPeriodTime.Period_MP() and not isnull( unitPeriodTime.UnitAvailability()));
        if( unitPeriodTimes.Size() > 0 ){
          LocalTool::SetUnitShiftPattern( owner,unitPeriodTimes,shiftPattern );
        }
      }
    }
  *]
}