From f3dec8f5b480474c9a3b2ea0fabb0f6b9fdc0423 Mon Sep 17 00:00:00 2001
From: renhao <renhui.hao@capgemini.com>
Date: 星期五, 13 十月 2023 17:11:34 +0800
Subject: [PATCH] Merge branch 'dev'

---
 _Main/BL/Type_MacroPlan/Method_MappingExternalSupplyData.qbl |   80 ++++++++++++++++++++++++++--------------
 1 files changed, 52 insertions(+), 28 deletions(-)

diff --git a/_Main/BL/Type_MacroPlan/Method_MappingExternalSupplyData.qbl b/_Main/BL/Type_MacroPlan/Method_MappingExternalSupplyData.qbl
index c04e1ba..4db0d6c 100644
--- a/_Main/BL/Type_MacroPlan/Method_MappingExternalSupplyData.qbl
+++ b/_Main/BL/Type_MacroPlan/Method_MappingExternalSupplyData.qbl
@@ -2,42 +2,66 @@
 #parent: #root
 Method MappingExternalSupplyData (
   Strings businessTypes,
-  Boolean nuclear
+  Boolean nuclear,
+  GlobalOTDTable globalOTDTable,
+  Strings organcodelist
 )
 {
   TextBody:
   [*
     // renhao Aug-14-2023 (created)
+    queryStartDate := guard( min( this, Period_MP, item, true, item.StartDate() ) - Duration::Days( 30 ), DateTime::MinDateTime() ).Date();
+    queryEndDate := guard( max( this, Period_MP, item, true, item.EndDate() ), Date::MaxDate() );
+    listtodeal := selectset( globalOTDTable,
+                             Global_MappingInventorySupply,
+                             externalSupply, 
+                             ( externalSupply.UserQuantity()>0 ) and 
+                             ( externalSupply.Date() >= queryStartDate ) and 
+                             ( organcodelist.Find( externalSupply.StockingPointID().SubString( 0, 3 ) ) >= 0 )/*and externalSupply.Date() <= queryEndDate*/);
+    totalcount := listtodeal.Size();
+    description := "鍦ㄩ�斿湪鍒�";
+    info( "ExternalSupply has " + totalcount.AsQUILL() + " rows in total" );
     
-    listtodeal := selectset( this,MappingExternalSupply,externalSupply, not isnull( StockingPoint_MP::FindById( this, externalSupply.StockingPointID() ) ) );
-    
+    count := 0;
     traverse( listtodeal,Elements,externalSupply){
-    //  product := select( this,MappingProduct,product,product.ID() = externalSupply.ProductID() and product.KeyProduct() = nuclear,true);
-    //  
-    //  if( not isnull( product)){
-    //    productMP :=  select( this,Product_MP,productMP,productMP.ID() = externalSupply.ProductID() ,true);
-    //    stockingpoint := select( this,StockingPoint_MP,st,st.ID() = externalSupply.StockingPointID(),true);
-    //    if( not isnull(businessTypes)){
-    //    
-    //      for( i :=0 ;i < businessTypes.Size();i++ ){
-    //        businessType := businessTypes.Element( i);
-    //        if( product.BusinessType() = businessType and not product.IsCommon()){
-    //          InventorySupply::Create(externalSupply.ID(),productMP,stockingpoint,externalSupply.Date(),externalSupply.ManufacturedDate(),externalSupply.UserQuantity(),"鍦ㄩ�斿湪鍒�",true);
-    //        }
-    //      }
-    //      
-    //    }else{
-      productMP :=  Product_MP::FindById( this, externalSupply.ProductID() );
-      stockingpoint := StockingPoint_MP::FindById( this, externalSupply.StockingPointID() );
-      if( not isnull( stockingpoint) and not isnull( productMP)){
-        InventorySupply::Create(externalSupply.ID(),productMP,stockingpoint,externalSupply.Date(),externalSupply.ManufacturedDate(),externalSupply.UserQuantity(),"鍦ㄩ�斿湪鍒�",true);
-      }
+      count := count + 1;
+      if( count - [Number](count/1000) * 1000 = 0 or count = totalcount ){
+        info( "Now is dealing with the " + count.AsQUILL() + "ExternalSupply " + "( " + count.AsQUILL() + "/" + totalcount.AsQUILL() + " ) " + (count/totalcount*100).Round( 1 ).AsQUILL() + "%" );
+       }
+      product := select( globalOTDTable,Global_MappingProduct_MP,product,product.ID() = externalSupply.ProductID(),true);
       
-    //    }
-    //    
-    //  }else{
-    //    info( "Invaild product" );
-    //    }
+      
+      if( not isnull( product)){
+        productMP :=  Product_MP :: FindProductTypeIndex( externalSupply.ProductID());
+        stockingpoint := select( this,StockingPoint_MP,st,st.ID() = externalSupply.StockingPointID(),true);
+        if( not isnull( stockingpoint) and not isnull( productMP)){
+        if( not isnull(businessTypes)){
+        
+          for( i :=0 ;i < businessTypes.Size();i++ ){
+            businessType := businessTypes.Element( i );
+            if( product.BusinessType() = businessType and not product.IsCommon()){
+              InventorySupply::CreateOrUpdate( externalSupply.ID(),
+                                               productMP,
+                                               stockingpoint,
+                                               externalSupply.Date(),
+                                               externalSupply.ManufacturedDate(),
+                                               externalSupply.UserQuantity(),description);
+            }
+          }
+          
+        }else{
+          
+            InventorySupply::CreateOrUpdate( externalSupply.ID(),
+                                           productMP,
+                                           stockingpoint,
+                                           externalSupply.Date(),
+                                           externalSupply.ManufacturedDate(),
+                                           externalSupply.UserQuantity(),description);
+          }
+      
+        }
+        
+      }
     }
   *]
 }

--
Gitblit v1.9.3