lazhen
2024-10-14 133f1a1dc59bbf13a35dc3d64e2ddaf6b37a335f
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
Quintiq file version 2.0
#parent: #root
StaticMethod Dispatch (
  Date startDate,
  Date endDate,
  const OfflinePlanTable offlinePlan,
  RecycleBin owner
)
{
  TextBody:
  [*
    // Akari Sep-4-2024 (created)
    owner.DispatchShiftSchedulingInformation( relflush );
    macroPlan := offlinePlan.MacroPlan();
    now := DateTime::Now();
    
    shiftPatterns := selectset( macroPlan,ShiftPattern,object,true );
    shiftPatternIndexTree := NamedValueTree::Create();
    for( i := 0; i < shiftPatterns.Size(); i++){
      shiftPattern := shiftPatterns.Element( i );
      shiftPatternHandle := shiftPatternIndexTree.GetHandle( shiftPattern.Name() );
      shiftPatternIndexTree.Root().AddChild( shiftPatternHandle,i );
    }
    
    units := selectset( macroPlan,Unit,object, true );
    unitIndexTree := NamedValueTree::Create();
    for( i := 0; i < units.Size(); i++){
      unit := units.Element( i );
      unitHandle := unitIndexTree.GetHandle( unit.Name() );
      unitIndexTree.Root().AddChild( unitHandle,i );
    }
    
    traverse( offlinePlan,OfflinePlanRow,row ){
      productID := row.ProductID();
      productLine := row.ProductionLine();
      factory := constnull( Unit );
      {
        unitHandle := unitIndexTree.GetHandle( productLine );
        unitIndex := guard( unitIndexTree.Root().Child( unitHandle ), null( NamedValue ));
        if( not isnull( unitIndex )){
          unit := units.Element( unitIndex.GetValueAsNumber() );
          temp1 := unit;
          temp2 := unit.Parent();
          while( not isnull( temp1.Parent())){
            temp2 := temp1;
            temp1 := temp1.Parent();
          }
          factory := temp2;
        }
      }
      traverse( row,OfflinePlanCell,cell ,startDate <= cell.OfflinePlanColumn().ColumnDate() and endDate > cell.OfflinePlanColumn().ColumnDate()){
        shiftDate := cell.OfflinePlanColumn().ColumnDate();
        shiftName := cell.Shift();
        shiftVolume := cell.Quantity();
        shiftDayTime := constnull( ShiftDayTime );
        {
          shiftPatternHandle := shiftPatternIndexTree.GetHandle( shiftName );
          shiftPatternIndex := guard( shiftPatternIndexTree.Root().Child( shiftPatternHandle ),null( NamedValue ));
          if( not isnull( shiftPatternIndex )){
            shiftPattern := shiftPatterns.Element( shiftPatternIndex.GetValueAsNumber() );
            shiftDayTime := select( shiftPattern,ShiftDayTime,object,true );
          }
        }
        if( shiftVolume <> 0 ){
          shiftSchedulingInformations := DispatchShiftSchedulingInformation::SplitShifts( owner,shiftName,shiftVolume );
        
        traverse( shiftSchedulingInformations,Elements,shiftSchedulingInformation ){
          shiftSchedulingInformation.InterfaceTime( now );
          shiftSchedulingInformation.VersionName( macroPlan.MDSMacroPlan().Description() );
          shiftSchedulingInformation.Product( productID );
          shiftSchedulingInformation.ProductLine( productLine );
          shiftSchedulingInformation.ShiftDate( shiftDate );
    //      shiftSchedulingInformation.InterfaceTime( now );
    //      shiftSchedulingInformation.InterfaceTime( now );
    //      shiftSchedulingInformation.InterfaceTime( now );
    //      shiftSchedulingInformation.InterfaceTime( now );
          
          
          if( not isnull( shiftDayTime )){
            shiftSchedulingInformation.ShiftStartDate( shiftDayTime.StartDateTime() );
            shiftSchedulingInformation.ShiftEndDate( shiftDayTime.EndDateTIme() );
          }
          if( not isnull( factory )){
            shiftSchedulingInformation.FactoryName( factory.Name() );
          }
        }
        }
      }
    }
  *]
}