xiaoding721
2024-10-17 ffb76f7a9a094cd200367d23b6822f4c1f7c873c
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
Quintiq file version 2.0
#parent: #root
StaticMethod CreateFullTable (
  const MacroPlans owners,
  RecycleBin recycleBin,
  const Archive archive,
  const MacroPlan owner
) as LocalTable
{
  TextBody:
  [*
    // rislai Aug-7-2024 (created)
    tables := MP_Table::GetMP_Tables_ScheduleSummary( owners );
    
    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 );
    }
    
    localRows := construct( LocalRows );
    localRowIndexTree := NamedValueTree::Create();
    
    localCells := construct( LocalCell_ScheduleSummarys );
    localCellIndexTree := NamedValueTree::Create();
    
    units := selectset( owner,Unit,unit,unit.HasCapacityTypeTime() and not unit.HasChild());
    unitIndexTree := NamedValueTree::Create();
    for( i := 0 ; i< units.Size() ; i++ ){
      unit := units.Element( i );
      unitHandle := unitIndexTree.GetHandle( unit.ID() );
      unitIndexTree.Root().AddChild( unitHandle,i );
    }
    
    
    //shiftPatternCount := NamedValueTree::Create();
    traverse( tables,Elements.MP_Row,row ){
       rowMacroPlan := row.MP_Table().MacroPlan();
       localRow := null( LocalRow );
       {
         localRowHandle := localRowIndexTree.GetHandle( row.Name() );
         localRowIndex := guard( localRowIndexTree.Root().Child( localRowHandle ),null( NamedValue ));
         if( isnull( localRowIndex )){
           localRow := localTable.LocalRow( relnew,CustomName := row.Name(),Index := localTable.GetRowIndexCache() );
           localRows.Add( localRow );
           localRowIndexTree.Root().AddChild( localRowHandle,localRows.Size() - 1 );
         }else{
           localRow := localRows.Element( localRowIndex.GetValueAsNumber());
         }
       }
       traverse( localColumns,Elements,localColumn ){
          cells := selectset( row,MP_Cell.astype( MP_Cell_ScheduleSummary ),cell,
                              ifexpr( rowMacroPlan = owner , true , cell.IsFristWeekData()) and
                              cell.MP_Column().CustomDate() >= localColumn.CustomDate() and 
                              cell.MP_Column().CustomDate() < localColumn.CustomDate().StartOfNextMonth() );
          
          isFuture := owner.StartOfPlanning().Date() < localColumn.CustomDate();
          
          output := 0.0;
          if( isFuture ){
            unitHandle := unitIndexTree.GetHandle( row.Name() );
            unitIndex := guard( unitIndexTree.Root().Child( unitHandle ),null( NamedValue ));
            if( not isnull( unitIndex )){
              unit := units.Element( unitIndex.GetValueAsNumber() );
              output := sum( unit,UnitPeriod.astype( UnitPeriodTime ).PeriodTask_MP.NewSupply,np,
                             np.PeriodTask_MP().UnitPeriod().StartDate() >= localColumn.CustomDate() and 
                             np.PeriodTask_MP().UnitPeriod().StartDate() < localColumn.CustomDate().StartOfNextMonth() and
                             np.PeriodTask_MP().UnitPeriod().Period_MP().TimeUnit() = "Day",
                             np.Quantity() );
              output := sum( unit,StockingPoint_MP.ProductInStockingPoint_MP.ProductInStockingPointInPeriod,pispip,
                             pispip.Period_MP().StartDate() >= localColumn.CustomDate() and
                             pispip.Period_MP().StartDate() < localColumn.CustomDate().StartOfNextMonth() and
                             pispip.Period_MP().TimeUnit() = "Day",
                             pispip.NewSupplyProductionQuantity());
            }
          }else{
            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 := null( LocalCell_ScheduleSummary );
          {
            localCellHandle := localCellIndexTree.GetHandle( row.Name() + localColumn.CustomDate().AsQUILL() );
            localCellIndex := guard( localCellIndexTree.Root().Child( localCellHandle ),null( NamedValue ));
            if( isnull( localCellIndex )){
              localCell := localRow.LocalCell( relnew,LocalCell_ScheduleSummary,LocalColumn := localColumn );
              localCells.Add( localCell );
              localCellIndexTree.Root().AddChild( localCellHandle , localCells.Size() - 1 );
            }else{
              localCell := localCells.Element( localCellIndex.GetValueAsNumber() ); 
            }
          }
          
          if( not maxShiftPattern = "" ){
            localCell.ShiftPattern( maxShiftPattern );
          }
          localCell.WorkingDay( localCell.WorkingDay() + workingDay );
          localCell.Capacity( localCell.Capacity() + capacity );
          localCell.Output( localCell.Output() + output );
       }
    }
    
    traverse( localTable,LocalRow.LocalCell.astype( LocalCell_ScheduleSummary ),cell ){
      cell.Capacity( cell.Capacity() / tables.Size() );
      cell.Output( cell.Output() / tables.Size() );
    }
    
    //startDate := owner.StartOfPlanning().Date() + 7;
    //endDate := maxselect( owner,Unit.UnitPeriod.astype( UnitPeriodTime ).Period_MP,period,period.EndDate(),period.TimeUnit() = "Month" ).EndDate();
    //columns := construct( MP_Columns );
    //columnIndexTree := NamedValueTree::Create();
    //for( i := startDate;i < endDate; i := i + 1){
    //  column := table.MP_Column( relnew,CustomDate := i );
    //  columnHandle := columnIndexTree.GetHandle( i.AsQUILL() );
    //  columns.Add( column );
    //  columnIndexTree.Root().AddChild( columnHandle,columns.Size() - 1 );
    //}
    
    
    return localTable;
  *]
}