admin
2025-01-22 7e31442f0e9b07764e9c6a9680d3d4aeba5fe1de
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
Quintiq file version 2.0
#parent: #root
StaticMethod Compared (
  RecycleBin recycleBin,
  const OfflinePlanTable baseOfflinePlan,
  const OfflinePlanTable compareOfflinePlan
) as LocalTable
{
  TextBody:
  [*
    // rislai Jun-20-2024 (created)
    table := recycleBin.LocalTable( relnew,Name := LocalCell_OfflinePlanComparison::GetTableName());
    
    localColumns := construct( LocalColumns );
    localColumnIndexTree := NamedValueTree::Create();
    traverse( baseOfflinePlan,OfflinePlanColumn,column,column.ColumnDate() >=  baseOfflinePlan.MacroPlan().StartOfPlanning().Date()){
      localColumnHandle := localColumnIndexTree.GetHandle( column.ColumnDate().AsQUILL() );
      localColumnIndex := guard( localColumnIndexTree.Root().Child( localColumnHandle ),null( NamedValue ));
      if( isnull( localColumnIndex )){
        localColumn := table.LocalColumn( relnew,CustomDate := column.ColumnDate());
        localColumns.Add( localColumn );
        localColumnIndexTree.Root().AddChild( localColumnHandle,localColumns.Size() - 1 );
      }
    }
    traverse( compareOfflinePlan,OfflinePlanColumn,column,column.ColumnDate() >=  compareOfflinePlan.MacroPlan().StartOfPlanning().Date()){
      localColumnHandle := localColumnIndexTree.GetHandle( column.ColumnDate().AsQUILL() );
      localColumnIndex := guard( localColumnIndexTree.Root().Child( localColumnHandle ),null( NamedValue ));
      if( isnull( localColumnIndex )){
        localColumn := table.LocalColumn( relnew,CustomDate := column.ColumnDate());
        localColumns.Add( localColumn );
        localColumnIndexTree.Root().AddChild( localColumnHandle,localColumns.Size() - 1 );
      }
    }
    
    baseOfflinePlanCells := construct( OfflinePlanCells, constcontent );
    baseOfflinePlanCellIndexTree := NamedValueTree::Create();
    compareOfflinePlanCells := construct( OfflinePlanCells, constcontent );
    compareOfflinePlanCellIndexTree := NamedValueTree::Create();
    
    localRows := construct( LocalRows );
    localRowIndexTree := NamedValueTree::Create();
    
    traverse( baseOfflinePlan,OfflinePlanRow,row,row.Type() = "1" ){
      rowKey := row.ProductID() + "@$#" + row.ProductionLine()+ "@$#";
      localRowHandle := localRowIndexTree.GetHandle( rowKey );
      localRowIndex := guard( localRowIndexTree.Root().Child( localRowHandle ),null( NamedValue ));
      if( isnull( localRowIndex )){
        localRow := table.LocalRow( relnew,Index := table.GetRowIndexCache(),CustomName := row.ProductID(),Remark := rowKey );
        localRows.Add( localRow );
        localRowIndexTree.Root().AddChild( localRowHandle,localRows.Size() - 1 );
      }
      traverse( row,OfflinePlanCell,cell ){
        columnKey := cell.OfflinePlanColumn().ColumnDate().AsQUILL();
        cellKey := rowKey + columnKey;
        cellHandle := baseOfflinePlanCellIndexTree.GetHandle( cellKey );
        baseOfflinePlanCells.Add( cell );
        baseOfflinePlanCellIndexTree.Root().AddChild( cellHandle,baseOfflinePlanCells.Size() - 1 );
      }
    }
    traverse( compareOfflinePlan,OfflinePlanRow,row,row.Type() = "1" ){
      rowKey := row.ProductID() + "@$#" + row.ProductionLine()+ "@$#";
      localRowHandle := localRowIndexTree.GetHandle( rowKey );
      localRowIndex := guard( localRowIndexTree.Root().Child( localRowHandle ),null( NamedValue ));
      if( isnull( localRowIndex )){
        localRow := table.LocalRow( relnew,Index := table.GetRowIndexCache(),CustomName := row.ProductID(),Remark := rowKey );
        localRows.Add( localRow );
        localRowIndexTree.Root().AddChild( localRowHandle,localRows.Size() - 1 );
      }
      traverse( row,OfflinePlanCell,cell ){
        columnKey := cell.OfflinePlanColumn().ColumnDate().AsQUILL();
        cellHandle := compareOfflinePlanCellIndexTree.GetHandle( rowKey + columnKey );
        compareOfflinePlanCells.Add( cell );
        compareOfflinePlanCellIndexTree.Root().AddChild( cellHandle,compareOfflinePlanCells.Size() - 1 );
      }
    }
    
    traverse( localRows,Elements,localRow ){
      rowKey := localRow.Remark();
      traverse( localColumns,Elements,localColumn ){
        columnKey := localColumn.CustomDate().AsQUILL();
        cellKey := rowKey + columnKey;
        
        baseOfflinePlanCell := constnull( OfflinePlanCell );
        compareOfflinePlanCell := constnull( OfflinePlanCell );
        baseOfflinePlanCellIndex := guard( baseOfflinePlanCellIndexTree.Root().Child( baseOfflinePlanCellIndexTree.GetHandle( cellKey ) ),null( NamedValue ));
        compareOfflinePlanCellIndex := guard( compareOfflinePlanCellIndexTree.Root().Child( compareOfflinePlanCellIndexTree.GetHandle( cellKey ) ),null( NamedValue ));
        if( not isnull( baseOfflinePlanCellIndex )){
          baseOfflinePlanCell := baseOfflinePlanCells.Element( baseOfflinePlanCellIndex.GetValueAsNumber() ); 
        }
        if( not isnull( compareOfflinePlanCellIndex )){
          compareOfflinePlanCell := compareOfflinePlanCells.Element( compareOfflinePlanCellIndex.GetValueAsNumber() ); 
        }
        
        localRow.LocalCell( relnew,LocalCell_OfflinePlanComparison,LocalColumn := localColumn,
                            BaseVersion := ifexpr( isnull( baseOfflinePlanCell),0.0,baseOfflinePlanCell.Quantity()),
                            CompareVersion := ifexpr( isnull( compareOfflinePlanCell),0.0,compareOfflinePlanCell.Quantity()));
      }
    }
    traverse( table,LocalColumn,column ){
      if( column.LocalCell( relsize ) = 0 ){
        column.Delete(); 
      } 
    }
    
    return table;
  *]
}