From 4f70e746b6f75d748aa7635d528179ef8d811222 Mon Sep 17 00:00:00 2001
From: xiaoding721 <33130084+xiaoding721@users.noreply.github.com>
Date: 星期五, 06 九月 2024 10:42:23 +0800
Subject: [PATCH] 更新 StaticMethod_GenerateForecast.qbl

---
 _Main/BL/Type_Archive/StaticMethod_GenerateForecast.qbl |   51 +++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 49 insertions(+), 2 deletions(-)

diff --git a/_Main/BL/Type_Archive/StaticMethod_GenerateForecast.qbl b/_Main/BL/Type_Archive/StaticMethod_GenerateForecast.qbl
index fbb1602..c2e0f8d 100644
--- a/_Main/BL/Type_Archive/StaticMethod_GenerateForecast.qbl
+++ b/_Main/BL/Type_Archive/StaticMethod_GenerateForecast.qbl
@@ -11,10 +11,51 @@
       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       := select( macroPlan, Product_MP, tempPMP, tempPMP.Notes() = tdd.ProductID() );
+      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() );
+    //  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,
@@ -33,6 +74,12 @@
                           false );
         forcest.Origin( tdd.Origin() );
       }
+      if( isnull( targetProduct_MP )){
+        info( tdd.ProductID() + " -> 鏈壘鍒癙roduct_MP" ); 
+      }
+      if( isnull( targetStockingPoint_MP )){
+        info( tdd.StockingPointID() + " -> 鏈壘鍒癝tockingPoint_MP" ); 
+      }
     }
   *]
 }

--
Gitblit v1.9.3