| Quintiq file version 2.0 | 
| #parent: #root | 
| StaticMethod GenerateForecast ( | 
|   ArchiveExecutionStatus archiveExecutionStatus, | 
|   MacroPlan macroPlan | 
| ) | 
| { | 
|   TextBody: | 
|   [* | 
|     traverse ( macroPlan, SalesDemand.astype( Forecast ), f ) { | 
|       f.Delete(); | 
|     } | 
|      | 
|     productMPs := selectset( macroPlan,Product_MP,prod,not prod.IsSystem() ); | 
|     productMPIndexTree := NamedValueTree::Create(); | 
|     productMPIndexTreeNotes := NamedValueTree::Create(); | 
|     for( i := 0; i < productMPs.Size(); i++ ){ | 
|       productMP := productMPs.Element( i ); | 
|        | 
|       productMPHandle := productMPIndexTree.GetHandle( productMP.ID() ); | 
|       productMPIndexTree.Root().AddChild( productMPHandle,i ); | 
|        | 
|       productMPHandleNotes := productMPIndexTreeNotes.GetHandle( productMP.Notes() ); | 
|       productMPIndexTreeNotes.Root().AddChild( productMPHandleNotes,i ); | 
|     } | 
|      | 
|     stockingPoints := selectset( macroPlan,StockingPoint_MP,sotckingPoint,not sotckingPoint.IsSystem() ); | 
|     stockingPointIndexTree := NamedValueTree::Create(); | 
|     for( i := 0; i < stockingPoints.Size(); i++ ){ | 
|       stockingPoint := stockingPoints.Element( i ); | 
|       stockingPointHandle := stockingPointIndexTree.GetHandle( stockingPoint.ID() ); | 
|       stockingPointIndexTree.Root().AddChild( stockingPointHandle, i ); | 
|     } | 
|      | 
|     traverse ( archiveExecutionStatus, TemporaryDemandData, tdd ,tdd.Origin() = "" or tdd.StartDate() >= macroPlan.StartOfPlanning().Date()) { | 
|       targetProduct_MP := null( Product_MP ); | 
|        | 
|       productMPHandleNotes := productMPIndexTreeNotes.GetHandle( tdd.ProductID()); | 
|       productMPIndexNotes := guard( productMPIndexTreeNotes.Root().Child( productMPHandleNotes ),null( NamedValue )); | 
|       if( isnull( productMPIndexNotes )){ | 
|         productMPHandle := productMPIndexTree.GetHandle( tdd.ProductID()); | 
|         productMPIndex := guard( productMPIndexTree.Root().Child( productMPHandle ),null( NamedValue )); | 
|         if( not isnull( productMPIndex )){ | 
|           targetProduct_MP := productMPs.Element( productMPIndex.GetValueAsNumber() ); | 
|         } | 
|       }else{ | 
|         targetProduct_MP := productMPs.Element( productMPIndexNotes.GetValueAsNumber() ); | 
|       } | 
|        | 
|       targetStockingPoint_MP := null( StockingPoint_MP ); | 
|       stockingPointHandle := stockingPointIndexTree.GetHandle( tdd.StockingPointID() ); | 
|       stockingPointIndex := guard( stockingPointIndexTree.Root().Child( stockingPointHandle ),null( NamedValue )); | 
|       if( not isnull( stockingPointIndex )){ | 
|         targetStockingPoint_MP := stockingPoints.Element( stockingPointIndex.GetValueAsNumber() );  | 
|       } | 
|     //  targetProduct_MP       := select( macroPlan, Product_MP, tempPMP, tempPMP.Notes() = tdd.ProductID() ); | 
|       // targetProduct_MP       := select( macroPlan, Product_MP, tempPMP, tempPMP.ID() = tdd.ProductID() ); | 
|     //  targetStockingPoint_MP := select( macroPlan, StockingPoint_MP, tempSPMP, tempSPMP.ID() = tdd.StockingPointID() ); | 
|       // info( tdd.SalesSegmentName() ); | 
|       if ( not isnull( targetProduct_MP ) and not isnull( targetStockingPoint_MP ) ) { | 
|         forcest := Forecast::Create( targetProduct_MP, | 
|                           targetStockingPoint_MP, | 
|                           [String]tdd.ID(), | 
|                           tdd.StartDate(), | 
|                           tdd.EndDate(), | 
|                           tdd.Quantity(), | 
|                           [Real]tdd.Price(), | 
|                           tdd.PriorityName(), | 
|                           tdd.SalesSegmentName(), | 
|                           tdd.CurrencyID(), | 
|                           tdd.UnitOfMeasureName(), | 
|                           0.0, | 
|                           false, | 
|                           false ); | 
|         forcest.Origin( tdd.Origin() ); | 
|       } | 
|       if( isnull( targetProduct_MP )){ | 
|         info( tdd.ProductID() + " -> 未找到Product_MP" );  | 
|       } | 
|       if( isnull( targetStockingPoint_MP )){ | 
|         info( tdd.StockingPointID() + " -> 未找到StockingPoint_MP" );  | 
|       } | 
|     } | 
|   *] | 
| } |