rislai
2024-08-07 1e5e1f4d15d1f2eea93c35f5e32b95a17a0a96e0
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
92
93
Quintiq file version 2.0
#parent: #root
StaticMethod CreateFullTable (
  const MacroPlans owners,
  RecycleBin recycleBin,
  const Archive archive
) as LocalTable
{
  TextBody:
  [*
    // rislai Aug-7-2024 (created)
    tables := construct( MP_Tables );
    traverse( owners,Elements,owner ){
      table := select( owner,MP_Table,table,table.Name() = MP_Cell_ScheduleSummary::GetTableName() ); 
      if( isnull( table )){
        table :=  MP_Cell_ScheduleSummary::Create( owner );
      }
      tables.Add( table );
    }
    
    scheduleSummaryOutputDataIndexTree := NamedValueTree::Create();
    scheduleSummaryOutputDatas := selectset( archive,ScheduleSummaryOutputLine.ScheduleSummaryOutputData,data,
                                             exists( tables,Elements.MP_Row,row,row.CustomName() = data.ScheduleSummaryOutputLine().LineName() ));
    
    for( i :=0;i < scheduleSummaryOutputDatas.Size();i++ ){
      scheduleSummaryOutputData := scheduleSummaryOutputDatas.Element( i );
      scheduleSummaryOutputDataKey := scheduleSummaryOutputData.ScheduleSummaryOutputLine().LineName() + scheduleSummaryOutputData.Date().AsQUILL();
      scheduleSummaryOutputDataHandle := scheduleSummaryOutputDataIndexTree.GetHandle( scheduleSummaryOutputDataKey );
      scheduleSummaryOutputDataIndexTree.Root().AddChild( scheduleSummaryOutputDataHandle,i );
    }
    
    localTable := recycleBin.LocalTable( relnew,Name := MP_Cell_ScheduleSummary::GetTableName() );
    startDate := minselect( tables,Elements.MP_Column,column,column.CustomDate() ).CustomDate();
    endDate := maxselect( tables,Elements.MP_Column,column,column.CustomDate() ).CustomDate();
    
    localColumns := construct( LocalColumns );
    localColumnIndexTree := NamedValueTree::Create();
    for( i := startDate.StartOfMonth(); i <= endDate.StartOfMonth(); i := i.StartOfNextMonth() ){
       localColumn := localTable.LocalColumn( relnew,CustomDate := i );
       localColumnHandle := localColumnIndexTree.GetHandle( i.AsQUILL() );
       localColumns.Add( localColumn );
       localColumnIndexTree.Root().AddChild( localColumnHandle,localColumns.Size() - 1 );
    }
    traverse( tables,Elements.MP_Row,row ){
    
       localRow := localTable.LocalRow( relnew,CustomName := row.Name(),Index := localTable.GetRowIndexCache() );
    
       traverse( localColumns,Elements,localColumn ){
          cells := selectset( row,MP_Cell.astype( MP_Cell_ScheduleSummary ),cell,cell.MP_Column().CustomDate() >= localColumn.CustomDate() and cell.MP_Column().CustomDate() < localColumn.CustomDate().StartOfNextMonth() );
          
          output := 0.0;
          
          scheduleSummaryOutputDataKey := row.Name() + localColumn.CustomDate().AsQUILL();
          scheduleSummaryOutputDataHandle := scheduleSummaryOutputDataIndexTree.GetHandle( scheduleSummaryOutputDataKey );
          scheduleSummaryOutputDataIndex := guard( scheduleSummaryOutputDataIndexTree.Root().Child( scheduleSummaryOutputDataHandle ),null( NamedValue ));
          if( not isnull( scheduleSummaryOutputDataIndex )){
            scheduleSummaryOutputData := scheduleSummaryOutputDatas.Element( scheduleSummaryOutputDataIndex.GetValueAsNumber() );
            output := scheduleSummaryOutputData.Output();
          }
          
          maxShiftPattern := "";
          maxShiftPatternCount := 0;
          
          workingDay := 0;
          capacity := 0.0;
          
          traverse( cells,Elements,cell ){
             workingDay := workingDay + cell.WorkingDay();
             capacity := capacity + cell.Capacity();
    
             if( maxShiftPattern <> cell.ShiftPattern() ){
               if( maxShiftPatternCount = 0 ){
                  maxShiftPattern := cell.ShiftPattern();
                  maxShiftPatternCount ++;
               }else{
                  maxShiftPatternCount --; 
               }
             }else{
                maxShiftPatternCount ++; 
             }
          }
          
          localCell := localRow.LocalCell( relnew,LocalCell_ScheduleSummary,LocalColumn := localColumn );
          localCell.ShiftPattern( maxShiftPattern );
          localCell.WorkingDay( workingDay );
          localCell.Capacity( capacity );
          localCell.Output( output );
       }
    }
    
    return localTable;
  *]
}