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; 
 | 
  *] 
 | 
} 
 |