| Quintiq file version 2.0 | 
| #parent: #root | 
| StaticMethod ComparedNew ( | 
|   RecycleBin recycleBin, | 
|   const NewOfflinePlanTable baseOfflinePlan, | 
|   const NewOfflinePlanTable 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,NewOfflinePlanColumn,column,column.StartDate() >=  baseOfflinePlan.MacroPlan().StartOfPlanning().Date()){ | 
|       localColumnHandle := localColumnIndexTree.GetHandle( column.StartDate().AsQUILL() ); | 
|       localColumnIndex := guard( localColumnIndexTree.Root().Child( localColumnHandle ),null( NamedValue )); | 
|       if( isnull( localColumnIndex )){ | 
|         localColumn := table.LocalColumn( relnew,CustomDate := column.StartDate(),TimeUnit := "Day"); | 
|         localColumns.Add( localColumn ); | 
|         localColumnIndexTree.Root().AddChild( localColumnHandle,localColumns.Size() - 1 ); | 
|       } | 
|     } | 
|     traverse( compareOfflinePlan,NewOfflinePlanColumn,column,column.StartDate() >=  compareOfflinePlan.MacroPlan().StartOfPlanning().Date()){ | 
|       localColumnHandle := localColumnIndexTree.GetHandle( column.StartDate().AsQUILL() ); | 
|       localColumnIndex := guard( localColumnIndexTree.Root().Child( localColumnHandle ),null( NamedValue )); | 
|       if( isnull( localColumnIndex )){ | 
|         localColumn := table.LocalColumn( relnew,CustomDate := column.StartDate(),TimeUnit := "Day"); | 
|         localColumns.Add( localColumn ); | 
|         localColumnIndexTree.Root().AddChild( localColumnHandle,localColumns.Size() - 1 ); | 
|       } | 
|     } | 
|      | 
|     baseOfflinePlanCells := construct( NewOfflinePlanCells, constcontent ); | 
|     baseOfflinePlanCellIndexTree := NamedValueTree::Create(); | 
|     compareOfflinePlanCells := construct( NewOfflinePlanCells, constcontent ); | 
|     compareOfflinePlanCellIndexTree := NamedValueTree::Create(); | 
|      | 
|     localRows := construct( LocalRows ); | 
|     localRowIndexTree := NamedValueTree::Create(); | 
|      | 
|     traverse( baseOfflinePlan,NewOfflinePlanRow,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(),ProductID := row.ProductID(),ProductionLine := row.ProductionLine(),CustomName := row.ProductID() + " > " + row.ProductionLine(),Remark := rowKey ); | 
|         localRows.Add( localRow ); | 
|         localRowIndexTree.Root().AddChild( localRowHandle,localRows.Size() - 1 ); | 
|       } | 
|       traverse( row,NewOfflinePlanCell,cell ){ | 
|         columnKey := cell.NewOfflinePlanColumn().StartDate().AsQUILL(); | 
|         cellKey := rowKey + columnKey; | 
|         cellHandle := baseOfflinePlanCellIndexTree.GetHandle( cellKey ); | 
|         baseOfflinePlanCells.Add( cell ); | 
|         baseOfflinePlanCellIndexTree.Root().AddChild( cellHandle,baseOfflinePlanCells.Size() - 1 ); | 
|       } | 
|     } | 
|     traverse( compareOfflinePlan,NewOfflinePlanRow,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(),ProductID := row.ProductID(),ProductionLine := row.ProductionLine(),CustomName := row.ProductID() + " > " + row.ProductionLine(),Remark := rowKey ); | 
|         localRows.Add( localRow ); | 
|         localRowIndexTree.Root().AddChild( localRowHandle,localRows.Size() - 1 ); | 
|       } | 
|       traverse( row,NewOfflinePlanCell,cell ){ | 
|         columnKey := cell.NewOfflinePlanColumn().StartDate().AsQUILL(); | 
|         cellHandle := compareOfflinePlanCellIndexTree.GetHandle( rowKey + columnKey ); | 
|         compareOfflinePlanCells.Add( cell ); | 
|         compareOfflinePlanCellIndexTree.Root().AddChild( cellHandle,compareOfflinePlanCells.Size() - 1 ); | 
|       } | 
|     } | 
|      | 
|     traverse( localRows,Elements,localRow ){ | 
|       info( localRow.ProductionLine() ); | 
|        | 
|       rowKey := localRow.Remark(); | 
|       traverse( localColumns,Elements,localColumn ){ | 
|         columnKey := localColumn.CustomDate().AsQUILL(); | 
|         cellKey := rowKey + columnKey; | 
|          | 
|         baseOfflinePlanCell := constnull( NewOfflinePlanCell ); | 
|         compareOfflinePlanCell := constnull( NewOfflinePlanCell ); | 
|         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())); | 
|       } | 
|     } | 
|      | 
|     startDate := minselect( table,LocalColumn,localColumn,localColumn.CustomDate() ).CustomDate(); | 
|     endDate := maxselect( table,LocalColumn,localColumn,localColumn.CustomDate() ).CustomDate(); | 
|     for( i := startDate.StartOfWeek(); i <= endDate.StartOfNextWeek(); i := i.StartOfNextWeek() ){ | 
|       timeUnit := "Week"; | 
|       localColumnHandle := localColumnIndexTree.GetHandle( i.AsQUILL() + timeUnit); | 
|       localColumn := table.LocalColumn( relnew,CustomDate := i,TimeUnit := timeUnit ); | 
|       localColumns.Add( localColumn ); | 
|       localColumnIndexTree.Root().AddChild( localColumnHandle,localColumns.Size() - 1 ); | 
|     } | 
|     for( i := startDate.StartOfMonth(); i <= endDate.StartOfNextMonth(); i := i.StartOfNextMonth() ){ | 
|       timeUnit := "Month"; | 
|       localColumnHandle := localColumnIndexTree.GetHandle( i.AsQUILL() + timeUnit); | 
|       localColumn := table.LocalColumn( relnew,CustomDate := i,TimeUnit := timeUnit ); | 
|       localColumns.Add( localColumn ); | 
|       localColumnIndexTree.Root().AddChild( localColumnHandle,localColumns.Size() - 1 ); | 
|     } | 
|      | 
|     traverse( table,LocalRow,row ){ | 
|       traverse( table,LocalColumn,column,column.TimeUnit() = "Week"){ | 
|         baseVersionValue := sum( row,LocalCell.astype( LocalCell_OfflinePlanComparison ),cell, | 
|                                  cell.LocalColumn().TimeUnit() = "Day" and | 
|                                  cell.LocalColumn().CustomDate() >= column.CustomDate() and | 
|                                  cell.LocalColumn().CustomDate() < column.CustomDate().StartOfNextWeek(), cell.BaseVersion()); | 
|         compareVersionValue := sum( row,LocalCell.astype( LocalCell_OfflinePlanComparison ),cell, | 
|                                  cell.LocalColumn().TimeUnit() = "Day" and | 
|                                  cell.LocalColumn().CustomDate() >= column.CustomDate() and | 
|                                  cell.LocalColumn().CustomDate() < column.CustomDate().StartOfNextWeek(), cell.CompareVersion()); | 
|                                   | 
|         row.LocalCell( relnew,LocalCell_OfflinePlanComparison,LocalColumn := column,BaseVersion := baseVersionValue,CompareVersion := compareVersionValue ); | 
|       }  | 
|     } | 
|     traverse( table,LocalRow,row ){ | 
|       traverse( table,LocalColumn,column,column.TimeUnit() = "Month"){ | 
|         baseVersionValue := sum( row,LocalCell.astype( LocalCell_OfflinePlanComparison ),cell, | 
|                                  cell.LocalColumn().TimeUnit() = "Day" and | 
|                                  cell.LocalColumn().CustomDate() >= column.CustomDate() and | 
|                                  cell.LocalColumn().CustomDate() < column.CustomDate().StartOfNextMonth(), cell.BaseVersion()); | 
|         compareVersionValue := sum( row,LocalCell.astype( LocalCell_OfflinePlanComparison ),cell, | 
|                                  cell.LocalColumn().TimeUnit() = "Day" and | 
|                                  cell.LocalColumn().CustomDate() >= column.CustomDate() and | 
|                                  cell.LocalColumn().CustomDate() < column.CustomDate().StartOfNextMonth(), cell.CompareVersion()); | 
|                                   | 
|         row.LocalCell( relnew,LocalCell_OfflinePlanComparison,LocalColumn := column,BaseVersion := baseVersionValue,CompareVersion := compareVersionValue ); | 
|       }  | 
|     } | 
|      | 
|     traverse( table,LocalColumn,column ){ | 
|       if( column.LocalCell( relsize ) = 0 ){ | 
|         column.Delete();  | 
|       }  | 
|     } | 
|      | 
|     return table; | 
|   *] | 
| } |