lazhen
2025-01-09 8afe90b633046db39042aada36b88193062f8cff
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
Quintiq file version 2.0
#parent: #root
StaticMethod BatchSetUnitShiftPattern (
  Unit unit,
  ShiftPattern shiftPattern,
  Date startDate,
  Date endDate,
  Number skipDay
)
{
  TextBody:
  [*
    // Akari Oct-10-2024 (created)
    owner := unit.MacroPlan();
    
    saveDays := construct( Dates );
    for( i := startDate; i < endDate; i := i + skipDay ){
      saveDays.Add( i ); 
    }
    
    
    dayPeriod_MPs := selectsortedset( owner,Period_MP,period_MP, 
                                      period_MP.TimeUnit() = 'Day' and 
                                      period_MP.StartDate() >= startDate and 
                                      period_MP.EndDate() <= endDate and exists( saveDays, Elements,day,day = period_MP.StartDate()) ,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( saveDays, Elements,day,day = period_MP.StartDate()) ,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()));
      if( unitPeriodTimes.Size() > 0 ){
        info( unitPeriodTimes.Size() );
        LocalTool::SetUnitShiftPattern( owner,unitPeriodTimes,shiftPattern );
      }
    }
    if( weekPeriod_MPs.Size() <> 0 ){
      unitPeriodTimes := selectset( unit,UnitPeriod.astype( UnitPeriodTime ),unitPeriodTime,exists( weekPeriod_MPs,Elements,period_MP,period_MP = unitPeriodTime.Period_MP()));
      if( unitPeriodTimes.Size() > 0 ){
        LocalTool::SetUnitShiftPattern( owner,unitPeriodTimes,shiftPattern );
      }
    }
  *]
}