From 0d728947dc4e717bc81f77be4810281cf7eeb15f Mon Sep 17 00:00:00 2001
From: yanweiyuan3 <yanweiyuan3@gmail.com>
Date: 星期二, 26 九月 2023 21:15:29 +0800
Subject: [PATCH] Update Dosync method for organcode

---
 _Main/BL/Type_MacroPlan/StaticMethod_DoSync0.qbl             |    2 
 _Main/BL/Type_MacroPlan/Method_MappingCustomerOrderData.qbl  |    7 +++
 _Main/BL/Type_MacroPlan/Method_MappingExternalSupplyData.qbl |   10 ++++-
 _Main/BL/Type_MacroPlan/Method_MappingProductData.qbl        |    4 +-
 _Main/BL/Type_MacroPlan/Method_MappingActualPISPIPData.qbl   |    9 +++-
 _Main/BL/Type_MacroPlan/Method_MappingForecastData.qbl       |    8 +++
 _Main/BL/Type_MacroPlan/Method_MappingUnitData.qbl           |    4 +
 _Main/BL/Type_MacroPlan/Method_MappingSalesSegmentData.qbl   |    5 ++
 _Main/BL/Type_MacroPlan/Method_MappingOperationBOMData.qbl   |    4 +
 _Main/BL/Type_MacroPlan/Method_MappingOperationCostData.qbl  |    8 +++
 _Main/BL/Type_MacroPlan/Method_MappingOperationData.qbl      |    4 +
 11 files changed, 51 insertions(+), 14 deletions(-)

diff --git a/_Main/BL/Type_MacroPlan/Method_MappingActualPISPIPData.qbl b/_Main/BL/Type_MacroPlan/Method_MappingActualPISPIPData.qbl
index c6520fb..a6f9a24 100644
--- a/_Main/BL/Type_MacroPlan/Method_MappingActualPISPIPData.qbl
+++ b/_Main/BL/Type_MacroPlan/Method_MappingActualPISPIPData.qbl
@@ -9,7 +9,12 @@
   TextBody:
   [*
     // renhao Aug-14-2023 (created)
-    listtodeal := selectset( globalOTDTable,Global_MappingActualProductInStockingPointInPeriod,actual,actual.ActualInventoryLevelEnd() > 0 );
+    organcodelist := selectvalues( globalOTDTable, BusinessType.OrganCode, organ, businessTypes.Find( organ.BusinessType().BusinessTypeName() ) <> -1, organ.OrganCodeName() );
+    listtodeal := selectset( globalOTDTable,
+                             Global_MappingActualProductInStockingPointInPeriod,
+                             actual,
+                             ( actual.ActualInventoryLevelEnd() > 0 ) and 
+                             ( organcodelist.Find( actual.StockingPointID().SubString( 0, 3 ) ) >= 0 ) );
     totalcount := listtodeal.Size();
     info( "ActualPISPIP has " + totalcount.AsQUILL() + " rows in total" );
     
@@ -24,7 +29,7 @@
       if( not isnull(businessTypes)){
       
         for( i :=0 ;i < businessTypes.Size();i++ ){
-          businessType := businessTypes.Element( i);
+          businessType := businessTypes.Element( i );
           if( product.BusinessType() = businessType and not product.IsCommon()){
             ActualProductInStockingPointInPeriod::CreateOrUpdate( this,
                                                                   actual.ProductID(),
diff --git a/_Main/BL/Type_MacroPlan/Method_MappingCustomerOrderData.qbl b/_Main/BL/Type_MacroPlan/Method_MappingCustomerOrderData.qbl
index bee6304..4504921 100644
--- a/_Main/BL/Type_MacroPlan/Method_MappingCustomerOrderData.qbl
+++ b/_Main/BL/Type_MacroPlan/Method_MappingCustomerOrderData.qbl
@@ -14,7 +14,12 @@
     if( isnull( businessTypes ) or businessTypes.Size() = 0 ) {
         listToDeal := selectset( globalOTDTable, Global_MappingCustomOrder, item, true );
     } else {
-        listToDeal := selectset( globalOTDTable, Global_MappingCustomOrder, item, businessTypes.Find( item.BusinessType() ) <> -1 );
+        organcodelist := selectvalues( globalOTDTable, BusinessType.OrganCode, organ, businessTypes.Find( organ.BusinessType().BusinessTypeName() ) <> -1, organ.OrganCodeName() );
+        listToDeal := selectset( globalOTDTable, 
+                                 Global_MappingCustomOrder, 
+                                 item, 
+                                 ( businessTypes.Find( item.BusinessType() ) <> -1 ) and 
+                                 ( organcodelist.Find( item.StockingPointID().SubString( 0, 3 ) ) >= 0 ) );
     }
     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() );
diff --git a/_Main/BL/Type_MacroPlan/Method_MappingExternalSupplyData.qbl b/_Main/BL/Type_MacroPlan/Method_MappingExternalSupplyData.qbl
index c6a2bcf..39675d3 100644
--- a/_Main/BL/Type_MacroPlan/Method_MappingExternalSupplyData.qbl
+++ b/_Main/BL/Type_MacroPlan/Method_MappingExternalSupplyData.qbl
@@ -11,7 +11,13 @@
     // 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 externalSupply.Date() <= queryEndDate*/);
+    organcodelist := selectvalues( globalOTDTable, BusinessType.OrganCode, organ, businessTypes.Find( organ.BusinessType().BusinessTypeName() ) <> -1, organ.OrganCodeName() );
+    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" );
@@ -32,7 +38,7 @@
         if( not isnull(businessTypes)){
         
           for( i :=0 ;i < businessTypes.Size();i++ ){
-            businessType := businessTypes.Element( i);
+            businessType := businessTypes.Element( i );
             if( product.BusinessType() = businessType and not product.IsCommon()){
               InventorySupply::CreateOrUpdate( externalSupply.ID(),
                                                productMP,
diff --git a/_Main/BL/Type_MacroPlan/Method_MappingForecastData.qbl b/_Main/BL/Type_MacroPlan/Method_MappingForecastData.qbl
index 21b752b..5fbb66c 100644
--- a/_Main/BL/Type_MacroPlan/Method_MappingForecastData.qbl
+++ b/_Main/BL/Type_MacroPlan/Method_MappingForecastData.qbl
@@ -14,7 +14,13 @@
     if( isnull( businessTypes ) or businessTypes.Size() = 0 ) {
         listToDeal := selectset( globalOTDTable, Global_MappingForecast, item, item.Quantity() > 0 );
     } else {
-        listToDeal := selectset( globalOTDTable, Global_MappingForecast, item, businessTypes.Find( item.BusinessType() ) <> -1 and item.Quantity()>0 );
+        organcodelist := selectvalues( globalOTDTable, BusinessType.OrganCode, organ, businessTypes.Find( organ.BusinessType().BusinessTypeName() ) <> -1, organ.OrganCodeName() );
+        listToDeal := selectset( globalOTDTable, 
+                                 Global_MappingForecast, 
+                                 item, 
+                                 ( businessTypes.Find( item.BusinessType() ) <> -1 ) and 
+                                 ( item.Quantity()>0 ) and 
+                                 ( organcodelist.Find( item.StockingPointID().SubString( 0, 3 ) ) >= 0 ) );
     }
     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() );
diff --git a/_Main/BL/Type_MacroPlan/Method_MappingOperationBOMData.qbl b/_Main/BL/Type_MacroPlan/Method_MappingOperationBOMData.qbl
index ca35281..254be84 100644
--- a/_Main/BL/Type_MacroPlan/Method_MappingOperationBOMData.qbl
+++ b/_Main/BL/Type_MacroPlan/Method_MappingOperationBOMData.qbl
@@ -15,11 +15,13 @@
     if( isKeyProduct ) {
         keyProductList := selectuniquevalues( globalOTDTable, Global_MappingProduct_MP, item, item.ProductMajorType()="鎴愬搧" or item.ProductMajorType()="鍗婃垚鍝�", item.ID() );
     }
+    organcodelist := selectvalues( globalOTDTable, BusinessType.OrganCode, organ, businessTypes.Find( organ.BusinessType().BusinessTypeName() ) <> -1, organ.OrganCodeName() );
     bomList := selectsortedset(  globalOTDTable, Global_MappingOperationBOM, item,
                                  ifexpr( isnull( businessTypes ) or businessTypes.Size() = 0, 
                                          true, 
     //                                     businessTypes.Difference( businessTypes.Difference( item.BusinessType().Tokenize( ", " ) ) ).Size() > 0 )
-                                         businessTypes.Find( item.BusinessType() ) >= 0 )
+                                         ( businessTypes.Find( item.BusinessType() ) >= 0 ) and 
+                                         ( organcodelist.Find( item.OrganCode() ) >= 0 ) )
     //                             and ifexpr( isKeyProduct, 
     //                                         keyProductList.Size() > 0 and keyProductList.Find( item.ComponentCode() ) >= 0,
     //                                         true )
diff --git a/_Main/BL/Type_MacroPlan/Method_MappingOperationCostData.qbl b/_Main/BL/Type_MacroPlan/Method_MappingOperationCostData.qbl
index 1e71d79..9a458dd 100644
--- a/_Main/BL/Type_MacroPlan/Method_MappingOperationCostData.qbl
+++ b/_Main/BL/Type_MacroPlan/Method_MappingOperationCostData.qbl
@@ -1,6 +1,7 @@
 Quintiq file version 2.0
 #parent: #root
 Method MappingOperationCostData (
+  GlobalOTDTable globalOTDTable,
   Strings businesstypes
 )
 {
@@ -14,7 +15,12 @@
     if( isnull( businesstypes ) or businesstypes.Size() = 0 ) {
         listtodeal := selectset( this, MappingOperation, item, true );
     } else {
-        listtodeal := selectset( this, MappingOperation, item, businesstypes.Find( item.BusinessType() ) <> -1 );
+        organcodelist := selectvalues( globalOTDTable, BusinessType.OrganCode, organ, businesstypes.Find( organ.BusinessType().BusinessTypeName() ) <> -1, organ.OrganCodeName() );
+        listtodeal := selectset( this, 
+                                 MappingOperation, 
+                                 item, 
+                                 ( businesstypes.Find( item.BusinessType() ) <> -1 ) and 
+                                 ( organcodelist.Find( item.OrganCode() ) >= 0 ) );
     }
     
     // Get the list to deal with max sequence number
diff --git a/_Main/BL/Type_MacroPlan/Method_MappingOperationData.qbl b/_Main/BL/Type_MacroPlan/Method_MappingOperationData.qbl
index 29e7e21..b09ed68 100644
--- a/_Main/BL/Type_MacroPlan/Method_MappingOperationData.qbl
+++ b/_Main/BL/Type_MacroPlan/Method_MappingOperationData.qbl
@@ -11,8 +11,10 @@
     // 鑾峰彇鏈夊簭鐨勫緟澶勭悊璁板綍
     toDealList := construct( Global_MappingOperations ) ;
     if( not isnull( businessTypes ) and businessTypes.Size() > 0 ) {
+        organcodelist := selectvalues( globalOTDTable, BusinessType.OrganCode, organ, businessTypes.Find( organ.BusinessType().BusinessTypeName() ) <> -1, organ.OrganCodeName() );
         toDealList := selectsortedset( globalOTDTable, Global_MappingOperation, item, 
-                                       businessTypes.Find( item.BusinessType() ) >= 0, 
+                                       ( businessTypes.Find( item.BusinessType() ) >= 0 ) and 
+                                       ( organcodelist.Find( item.OrganCode() ) >= 0 ), 
     //                                   businessTypes.Difference( businessTypes.Difference( item.BusinessType().Tokenize( ", " ) ) ).Size() > 0, 
                                        item.SequenceNumber() );
     } else {
diff --git a/_Main/BL/Type_MacroPlan/Method_MappingProductData.qbl b/_Main/BL/Type_MacroPlan/Method_MappingProductData.qbl
index ab7398e..1e0929e 100644
--- a/_Main/BL/Type_MacroPlan/Method_MappingProductData.qbl
+++ b/_Main/BL/Type_MacroPlan/Method_MappingProductData.qbl
@@ -23,10 +23,10 @@
           }
     } else {
         if( iskeyproduct = true ){
-          listToDeal := selectset( globalOTDTable, Global_MappingProduct_MP, item, item.KeyProduct() = true and businesstypes.Find(  item.BusinessType()) >= 0 );
+          listToDeal := selectset( globalOTDTable, Global_MappingProduct_MP, item, item.KeyProduct() = true and businesstypes.Find( item.BusinessType() ) >= 0 );
          }
         else{
-          listToDeal := selectset( globalOTDTable, Global_MappingProduct_MP, item, businesstypes.Find(  item.BusinessType()) >= 0 );
+          listToDeal := selectset( globalOTDTable, Global_MappingProduct_MP, item, businesstypes.Find( item.BusinessType() ) >= 0 );
         }
     }
     totalcount := listToDeal.Size();
diff --git a/_Main/BL/Type_MacroPlan/Method_MappingSalesSegmentData.qbl b/_Main/BL/Type_MacroPlan/Method_MappingSalesSegmentData.qbl
index cf459b5..d7f21c2 100644
--- a/_Main/BL/Type_MacroPlan/Method_MappingSalesSegmentData.qbl
+++ b/_Main/BL/Type_MacroPlan/Method_MappingSalesSegmentData.qbl
@@ -14,7 +14,10 @@
     if( isnull( businessTypes ) or businessTypes.Size() = 0 ) {
         listToDeal := selectset( globalOTDTable, Global_MappingSalesSegment_MP, item, true );
     } else {
-        listToDeal := selectset( globalOTDTable, Global_MappingSalesSegment_MP, item, businessTypes.Find( item.BusinessType() ) <> -1 );
+        listToDeal := selectset( globalOTDTable, 
+                                 Global_MappingSalesSegment_MP, 
+                                 item, 
+                                 businessTypes.Find( item.BusinessType() ) <> -1 );
     }
     //nameList := construct( structured[String] );
     //nameList := selectvalues( listToDeal, Elements, item, true, item.Name() );
diff --git a/_Main/BL/Type_MacroPlan/Method_MappingUnitData.qbl b/_Main/BL/Type_MacroPlan/Method_MappingUnitData.qbl
index e826ddb..671fe30 100644
--- a/_Main/BL/Type_MacroPlan/Method_MappingUnitData.qbl
+++ b/_Main/BL/Type_MacroPlan/Method_MappingUnitData.qbl
@@ -15,9 +15,11 @@
     if( isnull( businesstypes ) or businesstypes.Size() = 0 ) {
         listtodeal := selectset( globalOTDTable, Global_MappingOperation, item, true );
     } else {
+        organcodelist := selectvalues( globalOTDTable, BusinessType.OrganCode, organ, businesstypes.Find( organ.BusinessType().BusinessTypeName() ) <> -1, organ.OrganCodeName() );
         listtodeal := selectset( globalOTDTable, Global_MappingOperation, item, 
     //                             businesstypes.Difference( businesstypes.Difference( item.BusinessType().Tokenize( ", " ) ) ).Size() > 0
-                                 businesstypes.Find( item.BusinessType() ) >= 0
+                                 ( businesstypes.Find( item.BusinessType() ) >= 0 ) and 
+                                 ( organcodelist.Find( item.OrganCode() ) >= 0 )
                                 );
     }
     
diff --git a/_Main/BL/Type_MacroPlan/StaticMethod_DoSync0.qbl b/_Main/BL/Type_MacroPlan/StaticMethod_DoSync0.qbl
index b4361d5..875645b 100644
--- a/_Main/BL/Type_MacroPlan/StaticMethod_DoSync0.qbl
+++ b/_Main/BL/Type_MacroPlan/StaticMethod_DoSync0.qbl
@@ -131,7 +131,7 @@
     
     // todo 鍒堕�犳垚鏈�-16
     info( "InventoryCost Finished, Start OperationCost Mapping" );
-    macroPlan.MappingOperationCostData( businessTypes );
+    macroPlan.MappingOperationCostData( globalOTDTable, businessTypes );
     
     // 璁㈠崟棰勬祴-17
     Forecast::DoSync( macroPlan, businessTypes ,globalOTDTable);

--
Gitblit v1.9.3