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
Quintiq file version 2.0
#parent: #root
StaticMethod GenerateForecast (
  ArchiveExecutionStatus archiveExecutionStatus,
  MacroPlan macroPlan,
  Boolean isClearForecast
)
{
  TextBody:
  [*
    if( isClearForecast ){
      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()) {
      if( tdd.ProductID() = "6914" or tdd.ProductID() = "6916" or tdd.ProductID() = "6917" or tdd.ProductID() = "06S100010R" or tdd.ProductID() = "06S100010M" or tdd.ProductID() = "06S100010N" ){
        tdd.StockingPointID( "大连发动机的长春外租库" );
      }
      
      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,
                                     IDHolder::GetGUID(),
                                     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" ); 
      }
    }
  *]
}