From 110846d23e6d86ad6fb883836640dc32b39ea86e Mon Sep 17 00:00:00 2001
From: renhao <renhui.hao@capgemini.com>
Date: 星期三, 20 九月 2023 13:55:59 +0800
Subject: [PATCH] Merge branch 'dev_release'

---
 _Main/BL/Type_MacroPlan/StaticMethod_DoSync0.qbl                         |    3 
 _Main/BL/Type_MappingProduct/TypeIndex_MappingProductTypeIndex.qbl       |    4 
 _Main/BL/Type_MacroPlan/Method_MappingCustomerOrderData.qbl              |    5 
 _Main/BL/Type_MacroPlan/Method_MappingOperationBOMDataRouting#576.qbl    |   16 +
 _Main/BL/Type_MacroPlan/Method_MappingExternalSupplyData.qbl             |   28 ++-
 _Main/BL/Type_MacroPlan/Method_DeleteSnaityCheck.qbl                     |   21 +++
 _Main/BL/Type_MacroPlan/Method_MappingUnitData.qbl                       |   11 
 _Main/BL/Type_MacroPlan/Method_ApiLanesData.qbl                          |    2 
 _Main/BL/Type_MappingOperation/TypeIndex_MappingOperationTypeIndex.qbl   |   18 +-
 _Main/BL/EDI/Broker_Broker_OTD_BaseConversionFactor.qbl                  |    4 
 _Main/BL/Type_Product_MP/StaticMethod_CreateOrUpdate.qbl                 |   11 +
 _Main/BL/Type_MacroPlan/Method_MappingProductData.qbl                    |   45 +++---
 _Main/BL/Type_MacroPlan/Method_InitialUnitAndStockingPoint.qbl           |  110 ++++++++++++---
 _Main/BL/Type_MappingOperation/Attribute_SequenceNumber.qbl              |    1 
 _Main/BL/Type_MacroPlan/Method_MappingForecastData.qbl                   |    7 
 _Main/BL/EDI/Broker_Broker_OTD_Operation.qbl                             |    1 
 _Main/BL/Type_MacroPlan/Method_MappingOperationBOMData.qbl               |   31 ++-
 _Main/BL/Type_MacroPlan/Method_MappingOperationBOMDataSupplyPurchase.qbl |   19 +-
 _Main/BL/EDI/Broker_Broker_OTD_Product.qbl                               |    1 
 _Main/BL/Type_MacroPlan/Method_MappingOperationCostData.qbl              |    2 
 _Main/BL/Type_Product_MP/Attribute_KeyProduct.qbl                        |    7 +
 _Main/BL/Type_Lane/StaticMethod_CreateLaneFromJson.qbl                   |   18 ++
 _Main/BL/Type_Product_MP/Attribute_BusinessTypeCommon.qbl                |    7 +
 _Main/BL/Type_MappingProduct/Attribute_BusinessType.qbl                  |    1 
 24 files changed, 262 insertions(+), 111 deletions(-)

diff --git a/_Main/BL/EDI/Broker_Broker_OTD_BaseConversionFactor.qbl b/_Main/BL/EDI/Broker_Broker_OTD_BaseConversionFactor.qbl
index 7f8c525..4bca9ec 100644
--- a/_Main/BL/EDI/Broker_Broker_OTD_BaseConversionFactor.qbl
+++ b/_Main/BL/EDI/Broker_Broker_OTD_BaseConversionFactor.qbl
@@ -34,10 +34,6 @@
       OthersMayFlushTable: true
       OthersMayInsertRow: true
       Parameters: '/owner="YUXTEST"'
-      PrimaryKeyColumns: ISENABLED
-      PrimaryKeyColumns: PRODUCTID
-      PrimaryKeyColumns: SOURCEUNITOFMEASURENAME
-      PrimaryKeyColumns: TARGETUNITOFMEASURENAME
       RecordModificationHintStrategy: 'None'
       EDIODBCLinkColumn FACTOR
       {
diff --git a/_Main/BL/EDI/Broker_Broker_OTD_Operation.qbl b/_Main/BL/EDI/Broker_Broker_OTD_Operation.qbl
index 64aa83d..e269f2f 100644
--- a/_Main/BL/EDI/Broker_Broker_OTD_Operation.qbl
+++ b/_Main/BL/EDI/Broker_Broker_OTD_Operation.qbl
@@ -15,6 +15,7 @@
       PrimaryKeyColumns: PlantName
       PrimaryKeyColumns: ProcessSection
       PrimaryKeyColumns: ProductID
+      PrimaryKeyColumns: SequenceNumber
       TargetType: MappingOperation
       TypeIndex: MappingOperationTypeIndex
       EDIMLColumn ActualCapacity { Attribute: ActualCapacity ValueType: Real }
diff --git a/_Main/BL/EDI/Broker_Broker_OTD_Product.qbl b/_Main/BL/EDI/Broker_Broker_OTD_Product.qbl
index 15ca8ab..7bcabef 100644
--- a/_Main/BL/EDI/Broker_Broker_OTD_Product.qbl
+++ b/_Main/BL/EDI/Broker_Broker_OTD_Product.qbl
@@ -9,6 +9,7 @@
   {
     EDIMLTable MappingProduct
     {
+      PrimaryKeyColumns: BusinessType
       PrimaryKeyColumns: ID
       TargetType: MappingProduct
       TypeIndex: MappingProductTypeIndex
diff --git a/_Main/BL/Type_Lane/StaticMethod_CreateLaneFromJson.qbl b/_Main/BL/Type_Lane/StaticMethod_CreateLaneFromJson.qbl
index 6d55643..0c19698 100644
--- a/_Main/BL/Type_Lane/StaticMethod_CreateLaneFromJson.qbl
+++ b/_Main/BL/Type_Lane/StaticMethod_CreateLaneFromJson.qbl
@@ -1,7 +1,8 @@
 Quintiq file version 2.0
 #parent: #root
 StaticMethod CreateLaneFromJson (
-  JSON datarow
+  JSON datarow,
+  MacroPlan macroplan
 ) as Lane
 {
   Description: 'Read the json data and use it to create lane data'
@@ -14,6 +15,11 @@
     userleadtime := datarow.Get( "userleadtime" );
     processingtime := Duration::Zero();
     
+    unitofmeasurename := "PCS";
+    currencyid := "CNY";
+    startdate := Date::Date( 1900, 1, 1 );
+    enddate := Date::Date( 9999, 12, 31 );
+    capacitytype := "Transport quantity";
     if( userleadtime.IsNull() )
     {
       processingtime := Duration::Zero(); 
@@ -24,6 +30,16 @@
       };
     
     unit := Unit::FindUnitTypeIndex( unitid );
+    if( isnull( unit)){
+      unit :=macroplan.Unit( relnew, 
+                 ID := unitid, 
+                 Name := unitid, 
+                 UnitOfMeasureName := unitofmeasurename, 
+                 CurrencyID := currencyid, 
+                 StartDate := startdate, 
+                 EndDate := enddate, 
+                 CapacityType := capacitytype );
+    }
     
     result := Lane::CreateLane( unit, id, name, processingtime);
     
diff --git a/_Main/BL/Type_MacroPlan/Method_ApiLanesData.qbl b/_Main/BL/Type_MacroPlan/Method_ApiLanesData.qbl
index 0561aae..0020767 100644
--- a/_Main/BL/Type_MacroPlan/Method_ApiLanesData.qbl
+++ b/_Main/BL/Type_MacroPlan/Method_ApiLanesData.qbl
@@ -14,7 +14,7 @@
     for( i:=0; i<data_length; i++ )
     {
       datarow := data.Get( i );
-      a := Lane::CreateLaneFromJson( datarow );
+      a := Lane::CreateLaneFromJson( datarow ,this);
       updates.Add( a );
       }
     origindataset := selectset( this, Unit.Lane, l, true );
diff --git a/_Main/BL/Type_MacroPlan/Method_DeleteSnaityCheck.qbl b/_Main/BL/Type_MacroPlan/Method_DeleteSnaityCheck.qbl
new file mode 100644
index 0000000..d5d02e1
--- /dev/null
+++ b/_Main/BL/Type_MacroPlan/Method_DeleteSnaityCheck.qbl
@@ -0,0 +1,21 @@
+Quintiq file version 2.0
+#parent: #root
+Method DeleteSnaityCheck
+{
+  TextBody:
+  [*
+    // renhao Sep-13-2023 (created)
+    //鍒犻櫎娌℃湁姹囩巼鐨勮揣甯�
+    traverse(  this,Currency_MP,currency,not currency.IsBase() and currency.CurrencyRate_MP( relsize ) = 0 ){
+      currency.Delete();
+    }
+    //鍒犻櫎娌℃湁浜у搧鐨勮溅閬�
+    traverse( this,Unit.Lane,lane,not isnull( lane) and lane.ProductInLane(relsize )=0 ){
+      lane.Delete();
+    }
+    //鍒犻櫎娌℃湁鐢ㄥ埌浜у搧鍜宭ane鐨勫簱瀛樼偣
+    traverse( this,StockingPoint_MP,stock,stock.ProductInStockingPoint_MP(relsize ) = 0 ){
+      stock.Delete();
+    }
+  *]
+}
diff --git a/_Main/BL/Type_MacroPlan/Method_InitialUnitAndStockingPoint.qbl b/_Main/BL/Type_MacroPlan/Method_InitialUnitAndStockingPoint.qbl
index 767523f..c71e147 100644
--- a/_Main/BL/Type_MacroPlan/Method_InitialUnitAndStockingPoint.qbl
+++ b/_Main/BL/Type_MacroPlan/Method_InitialUnitAndStockingPoint.qbl
@@ -6,51 +6,111 @@
   [*
     // Administrator Sep-1-2023 (created)
     
-    unitOfMeasure_MP := UnitOfMeasure_MP::FindByName( this, "PCS" );
-    if ( isnull( unitOfMeasure_MP ) ) {
-      unitOfMeasure_MP := UnitOfMeasure_MP::Create( this, "PCS", false, false );
-    }
-    
     //Set the Default values
     unitofmeasurename := "PCS";
+    currencyid := "CNY";
+    startdate := Date::Date( 1900, 1, 1 );
+    enddate := Date::Date( 9999, 12, 31 );
     capacitytype := "Transport quantity";
     
-    if ( isnull( Unit::FindById( this, "绌鸿繍" ) ) ) {
-      Unit::Create( "绌鸿繍", this, "绌鸿繍", unitOfMeasure_MP, null( Unit ), capacitytype, "", null( SupplyChainView ), 0, 0, false ); 
-    }
+    if( isnull( Unit::FindById( this, "绌鸿繍" ) ) ){
+      this.Unit( relnew, 
+                 ID := "绌鸿繍", 
+                 Name := "绌鸿繍", 
+                 UnitOfMeasureName := unitofmeasurename, 
+                 CurrencyID := currencyid, 
+                 StartDate := startdate, 
+                 EndDate := enddate, 
+                 CapacityType := capacitytype );
+      }
     
-    if ( isnull( Unit::FindById( this, "搴撳瓨浜嬪姟澶勭悊" ) ) ) {
-      Unit::Create( "搴撳瓨浜嬪姟澶勭悊", this, "搴撳瓨浜嬪姟澶勭悊", unitOfMeasure_MP, null( Unit ), capacitytype, "", null( SupplyChainView ), 0, 0, false ); 
+    if( isnull( Unit::FindById( this, "搴撳瓨浜嬪姟澶勭悊" ) ) ){
+      this.Unit( relnew, 
+                 ID := "搴撳瓨浜嬪姟澶勭悊", 
+                 Name := "搴撳瓨浜嬪姟澶勭悊", 
+                 UnitOfMeasureName := unitofmeasurename, 
+                 CurrencyID := currencyid, 
+                 StartDate := startdate, 
+                 EndDate := enddate, 
+                 CapacityType := capacitytype );
     }
     
     unitofmeasurename := "PCS";
+    name := "鎵嬪姩鍒涘缓搴撳瓨鐐�";
+    currencyname := "CNY";
+    isplannedinfinite := false;
+    datestart := Date::Construct(1900, 1, 1) ;
+    dateend := Date::Construct(9999, 12, 31);
+    groupname := " ";
+    description := " ";
+    isfromdb := true;
     
-    if ( isnull( StockingPoint_MP::FindById( this, "F13_FG_STOCK" ) ) ) {
-      StockingPoint_MP::Create( "F13_FG_STOCK", this, null( Unit ), "F13_FG_STOCK", null( SupplyChainView ), 0, 0, false );
+    if( isnull( StockingPoint_MP::FindById( this, "F13_FG_STOCK" ) ) ){
+      StockingPoint_MP::Create( this, 
+                                "F13_FG_STOCK", 
+                                "F13", 
+                                name, 
+                                unitofmeasurename, 
+                                currencyname, 
+                                isplannedinfinite, 
+                                datestart, 
+                                dateend, 
+                                groupname, 
+                                description, 
+                                isfromdb );
     }
     
-    if ( isnull( StockingPoint_MP::FindById( this, "H10_SA_STOCK" ) ) ) {
-      StockingPoint_MP::Create( "H10_SA_STOCK", this, null( Unit ), "H10_SA_STOCK", null( SupplyChainView ), 0, 0, false );
+    if( isnull( StockingPoint_MP::FindById( this, "H10_SA_STOCK" ) ) ){
+      StockingPoint_MP::Create( this, 
+                                "H10_SA_STOCK", 
+                                "H10", 
+                                name, 
+                                unitofmeasurename, 
+                                currencyname, 
+                                isplannedinfinite, 
+                                datestart, 
+                                dateend, 
+                                groupname, 
+                                description, 
+                                isfromdb );
     }
     
-    if ( isnull( StockingPoint_MP::FindById( this, "Q10_FG_STOCK" ) ) ) {
-      StockingPoint_MP::Create( "Q10_FG_STOCK", this, null( Unit ), "Q10_FG_STOCK", null( SupplyChainView ), 0, 0, false );
+    if( isnull( StockingPoint_MP::FindById( this, "Q10_FG_STOCK" ) ) ){
+      StockingPoint_MP::Create( this, 
+                                "Q10_FG_STOCK", 
+                                "Q10", 
+                                name, 
+                                unitofmeasurename, 
+                                currencyname, 
+                                isplannedinfinite, 
+                                datestart, 
+                                dateend, 
+                                groupname, 
+                                description, 
+                                isfromdb );
     }
     
-    if ( isnull( Currency_MP::FindById( this, "CNY" ) ) ) {
-      Currency_MP::Create( "CNY", this, "CNY", "", false, false );
-    }
+    existcurrency := Currency_MP::FindById( this, "CNY" );
+    if( isnull( existcurrency ) ){
+      Currency_MP::CreateCurrency( this, "CNY", "CNY", "", true );
+      currency := Currency_MP::FindById( this, "EUR" );
+      currency.IsBase(false);
+      Transaction::Transaction().Propagate();
+      }
     
     isproductcatagory := false;
     isfromdb := false;
-    if ( isnull( ProductLevel_MP::FindProductLevelTypeIndex( "1" ) ) ) {
+    existproductlevel := ProductLevel_MP::FindProductLevelTypeIndex( "2" );
+    if( isnull( existproductlevel ) ){
       ProductLevel_MP::Create( "1", isproductcatagory, this, isfromdb );
-    }
-    if ( isnull( ProductLevel_MP::FindProductLevelTypeIndex( "2" ) ) ) {
       ProductLevel_MP::Create( "2", isproductcatagory, this, isfromdb );
-    }
-    if ( isnull( ProductLevel_MP::FindProductLevelTypeIndex( "3" ) ) ) {
       ProductLevel_MP::Create( "3", isproductcatagory, this, isfromdb );
-    }
+      }
+    
+    existsalestlevel := SalesLevel_MP::FindSalesLevelTypeIndex( "2")
+    if( isnull( existsalestlevel ) ){
+        SalesLevel_MP::Create( "1",this,isfromdb);
+        SalesLevel_MP::Create( "2",this,isfromdb);
+      }
   *]
 }
diff --git a/_Main/BL/Type_MacroPlan/Method_MappingCustomerOrderData.qbl b/_Main/BL/Type_MacroPlan/Method_MappingCustomerOrderData.qbl
index 873ed35..7ec0576 100644
--- a/_Main/BL/Type_MacroPlan/Method_MappingCustomerOrderData.qbl
+++ b/_Main/BL/Type_MacroPlan/Method_MappingCustomerOrderData.qbl
@@ -17,12 +17,13 @@
     }
     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( listToDeal, Elements, item, item.OrderDate() >= queryStartDate and item.OrderDate() <= queryEndDate, not isnull( Product_MP::FindById( this, item.ProductID() ) ) and not isnull( StockingPoint_MP::FindById( this, item.StockPointID() ) ) and not isnull( SalesSegment_MP::FindByName( this, item.SalesSegmentName() ) ) );
+    listToDeal := selectset( listToDeal, Elements, item, item.OrderDate() >= queryStartDate /*and item.OrderDate() <= queryEndDate*/, not isnull( Product_MP::FindById( this, item.ProductID() ) ) and not isnull( StockingPoint_MP::FindById( this, item.StockPointID() ) ) and not isnull( SalesSegment_MP::FindByName( this, item.SalesSegmentName() ) ) );
     
     totalcount := listToDeal.Size();
     info( "CustomerOrder has " + totalcount.AsQUILL() + " rows in total" );
     
     count := 0;
+    priorityName :="Normal";
     // 澶勭悊
     traverse( listToDeal, Elements, item ) {
       count := count + 1;
@@ -33,7 +34,7 @@
     //    info( item.ProductID().AsQUILL() );
       CustomerOrder::CreateOrUpdate( this, item.CurrencyID(), item.Customer(), item.CustomerID(), item.ID(), 
                                      item.OrderDate(), item.OrderID(), item.OrderLineID(), item.Price(), 
-                                     item.PriorityName(), item.ProductID(), 
+                                     priorityName, item.ProductID(), 
                                      item.StockPointID(), 
                                      item.SalesSegmentName(), 
                                      item.Quantity(), item.UnitOfMeasureName(), item.OrderType(), item.IsAvailable());
diff --git a/_Main/BL/Type_MacroPlan/Method_MappingExternalSupplyData.qbl b/_Main/BL/Type_MacroPlan/Method_MappingExternalSupplyData.qbl
index ea2ad61..ead549d 100644
--- a/_Main/BL/Type_MacroPlan/Method_MappingExternalSupplyData.qbl
+++ b/_Main/BL/Type_MacroPlan/Method_MappingExternalSupplyData.qbl
@@ -8,9 +8,11 @@
   TextBody:
   [*
     // renhao Aug-14-2023 (created)
-    
-    listtodeal := selectset( this,MappingExternalSupply,externalSupply, true );
+    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( this,MappingExternalSupply,externalSupply, externalSupply.UserQuantity()>0 and externalSupply.Date() >= queryStartDate /*and externalSupply.Date() <= queryEndDate*/);
     totalcount := listtodeal.Size();
+    description := "鍦ㄩ�斿湪鍒�";
     info( "ExternalSupply has " + totalcount.AsQUILL() + " rows in total" );
     
     count := 0;
@@ -18,12 +20,14 @@
       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( this,MappingProduct,product,product.ID() = externalSupply.ProductID() and product.KeyProduct() = nuclear,true);
+       }
+      product := select( this,MappingProduct,product,product.ID() = externalSupply.ProductID(),true);
+      
       
       if( not isnull( product)){
-        productMP :=  select( this,Product_MP,productMP,productMP.ID() = externalSupply.ProductID() ,true);
+        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++ ){
@@ -34,25 +38,23 @@
                                                stockingpoint,
                                                externalSupply.Date(),
                                                externalSupply.ManufacturedDate(),
-                                               externalSupply.UserQuantity(),"鍦ㄩ�斿湪鍒�");
+                                               externalSupply.UserQuantity(),description);
             }
           }
           
         }else{
-        if( not isnull( stockingpoint) and not isnull( productMP)){
-          InventorySupply::CreateOrUpdate( externalSupply.ID(),
+          
+            InventorySupply::CreateOrUpdate( externalSupply.ID(),
                                            productMP,
                                            stockingpoint,
                                            externalSupply.Date(),
                                            externalSupply.ManufacturedDate(),
-                                           externalSupply.UserQuantity(),"鍦ㄩ�斿湪鍒�");
-        }
+                                           externalSupply.UserQuantity(),description);
+          }
       
         }
         
-      }else{
-        info( "Invaild product" );
-        }
+      }
     }
   *]
 }
diff --git a/_Main/BL/Type_MacroPlan/Method_MappingForecastData.qbl b/_Main/BL/Type_MacroPlan/Method_MappingForecastData.qbl
index 903aea0..47e8597 100644
--- a/_Main/BL/Type_MacroPlan/Method_MappingForecastData.qbl
+++ b/_Main/BL/Type_MacroPlan/Method_MappingForecastData.qbl
@@ -11,9 +11,9 @@
     // 寰呭鐞嗘暟鎹�
     listToDeal := construct( structured[MappingForecast] );
     if( isnull( businessTypes ) or businessTypes.Size() = 0 ) {
-        listToDeal := selectset( this, MappingForecast, item, true );
+        listToDeal := selectset( this, MappingForecast, item, item.Quantity() > 0 );
     } else {
-        listToDeal := selectset( this, MappingForecast, item, businessTypes.Find( item.BusinessType() ) <> -1 );
+        listToDeal := selectset( this, MappingForecast, item, businessTypes.Find( item.BusinessType() ) <> -1 and item.Quantity()>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() );
@@ -23,6 +23,7 @@
     info( "Forecast has " + totalcount.AsQUILL() + " rows in total" );
     
     count := 0;
+    priorityName := "Normal";
     // 澶勭悊
     traverse( listToDeal, Elements, item ) {
       count := count + 1;
@@ -31,7 +32,7 @@
         }
     //  if( not isnull( Product_MP::FindById( this, item.ProductID() ) ) ){
       Forecast::CreateOrUpdate( this, 
-                                item.ProductID(), item.SalesSegmentName(), item.StockingPointID(), item.PriorityName(),
+                                item.ProductID(), item.SalesSegmentName(), item.StockingPointID(), priorityName,
                                 item.CurrencyID(), item.UnitOfMeasureName(),
                                 item.ID(), item.StartDate(), item.EndDate(), item.Quantity(), item.Price());
     //  }else{
diff --git a/_Main/BL/Type_MacroPlan/Method_MappingOperationBOMData.qbl b/_Main/BL/Type_MacroPlan/Method_MappingOperationBOMData.qbl
index 892f5ef..b807827 100644
--- a/_Main/BL/Type_MacroPlan/Method_MappingOperationBOMData.qbl
+++ b/_Main/BL/Type_MacroPlan/Method_MappingOperationBOMData.qbl
@@ -12,16 +12,17 @@
     
     keyProductList := construct( Strings );
     if( isKeyProduct ) {
-        keyProductList := selectuniquevalues( this, MappingProduct, item, item.KeyProduct(), item.ID() );
+        keyProductList := selectuniquevalues( this, MappingProduct, item, item.ProductMajorType()="鎴愬搧" or item.ProductMajorType()="鍗婃垚鍝�", item.ID() );
     }
     bomList := selectsortedset(  this, MappingBOM, item,
                                  ifexpr( isnull( businessTypes ) or businessTypes.Size() = 0, 
                                          true, 
     //                                     businessTypes.Difference( businessTypes.Difference( item.BusinessType().Tokenize( ", " ) ) ).Size() > 0 )
                                          businessTypes.Find( item.BusinessType() ) >= 0 )
-                                 and ifexpr( isKeyProduct, 
-                                             keyProductList.Size() > 0 and keyProductList.Find( item.ComponentCode() ) >= 0,
-                                             true ),
+    //                             and ifexpr( isKeyProduct, 
+    //                                         keyProductList.Size() > 0 and keyProductList.Find( item.ComponentCode() ) >= 0,
+    //                                         true )
+                                 ,
                                  item.OrganCode() + "_" + item.ProductCode() + "_" + item.ProcessSection() );
     // 鎸塺outing鍙妑outingStep鍒嗙粍
     routingIds := selectuniquevalues( bomList, Elements, item, true, item.OrganCode() + "_" + item.ProductCode() );
@@ -29,14 +30,16 @@
         routingRows := selectset( bomList, Elements, item, true, routingId = item.OrganCode() + "_" + item.ProductCode() );
         if( routingRows.Size() > 0 ) {
             firstRow := routingRows.Element( 0 );
-            stockingPointId := firstRow.OrganCode()  + "_" + firstRow.ProductType() + "_Stock";
-            inputStockingPointId := firstRow.OrganCode()  + "_" + firstRow.ComponentType() + "_Stock";
+    //        stockingPointId := firstRow.OrganCode()  + "_" + firstRow.ProductType() + "_Stock";
+    //        inputStockingPointId := firstRow.OrganCode()  + "_" + firstRow.ComponentType() + "_Stock";
+            stockingPointId := firstRow.OrganCode()  + "_Stock";
+    
             // ========妫�鏌�========
             product := Product_MP::FindProductTypeIndex( firstRow.ProductCode() );
             if( not isnull( product ) ) {
     //              error( "product : " + firstRow.ProductCode() + " not found" );
               stockingPoint := StockingPoint_MP::FindStockingPointTypeIndex( stockingPointId );
-              inputStockingPoint := StockingPoint_MP::FindStockingPointTypeIndex(  inputStockingPointId );
+    
     //          info( stockingPointId.AsQUILL() );
       //        if( isnull( stockingPoint ) ) {
       //            error( "stockingPoint : " + stockingPointId + " not found" );
@@ -55,8 +58,14 @@
                   // ========鍒嗙粍澶勭悊杈撳叆========
                   
                 }
-                if( not isnull( inputStockingPoint)){
-                  this.MappingOperationBOMDataRouting( routing,routingRows,inputStockingPoint,keyProductList);
+                if( not isnull( stockingPoint)){
+                  if( isKeyProduct){
+                      keyRows := selectset( routingRows,Elements,routingrow,keyProductList.Find( routingrow.ComponentCode())>=0);
+                      this.MappingOperationBOMDataRouting( routing,keyRows);
+                    }else{
+                      this.MappingOperationBOMDataRouting( routing,routingRows);
+                    }
+                    
                 }
               }
            }
@@ -64,9 +73,9 @@
     }
     if( createPurchaseSupplyMaterial ) {
         toCreateBomList := selectuniquevalues( bomList, Elements, item, 
-                                               item.ProductType() = "P", item.OrganCode() + item.ComponentCode());
+                                               item.ComponentType() = "P", item.OrganCode() + item.ComponentCode());
         traverse( toCreateBomList, Elements, key ) {
-            boms := selectset( bomList, Elements, item, item.ProductType() = "P" and item.OrganCode() + item.ComponentCode() = key );
+            boms := selectset( bomList, Elements, item, item.ComponentType() = "P" and item.OrganCode() + item.ComponentCode() = key );
             bom := boms.First();
             this.MappingOperationBOMDataSupplyPurchase( bom.OrganCode(), bom.ComponentCode(), bom.ComponentType());
         }
diff --git "a/_Main/BL/Type_MacroPlan/Method_MappingOperationBOMDataRouting\043576.qbl" "b/_Main/BL/Type_MacroPlan/Method_MappingOperationBOMDataRouting\043576.qbl"
index 059c6c9..e661d1f 100644
--- "a/_Main/BL/Type_MacroPlan/Method_MappingOperationBOMDataRouting\043576.qbl"
+++ "b/_Main/BL/Type_MacroPlan/Method_MappingOperationBOMDataRouting\043576.qbl"
@@ -2,9 +2,7 @@
 #parent: #root
 Method MappingOperationBOMDataRouting (
   Routing routing,
-  MappingBOMs routingRows,
-  StockingPoint_MP stockingPoint,
-  Strings keyProductIds
+  MappingBOMs routingRows
 )
 {
   TextBody:
@@ -32,6 +30,9 @@
                   if( not isnull( component ) ) {
     //                  error( "component : " + noAlterRow.ComponentCode() + " not found" );
                   // 杩炴帴浜у搧涓巓peration
+    //              inputStockingPointId := noAlterRow.OrganCode()  + "_" + noAlterRow.ComponentType() + "_Stock";
+                  inputStockingPointId := noAlterRow.OrganCode() + "_Stock";
+                  stockingPoint := StockingPoint_MP::FindStockingPointTypeIndex( inputStockingPointId);
                   pisp := ProductInStockingPoint_MP::CreateIfNotFound( component, stockingPoint );
                   trash := construct( OperationBOMs );
                   operationBOM := toLink.LinkProduct( component, true, BaseOperationLink::GetGroupID( toLink, true, false ), pisp, 
@@ -54,6 +55,9 @@
     //          }
                 traverse( routingStep, Operation, toLink ) {
                     // 杩炴帴浜у搧涓巓peration
+    //                inputStockingPointId := firstAlterRow.OrganCode()  + "_" + firstAlterRow.ComponentType() + "_Stock";
+                    inputStockingPointId := firstAlterRow.OrganCode() + "_Stock";
+                    stockingPoint := StockingPoint_MP::FindStockingPointTypeIndex( inputStockingPointId);
                     pisp := ProductInStockingPoint_MP::CreateIfNotFound( component, stockingPoint );
                     trash := construct( OperationBOMs );
                     mainBOM := toLink.LinkProduct( component, true, BaseOperationLink::GetGroupID( toLink, true, false ), pisp, 
@@ -67,13 +71,15 @@
                         alterProd := Product_MP::FindById( this, alterRow.AlternativeMaterialCode() );
                         if( not isnull( alterProd ) ) {
         //                    error( "alterProd : " + alterRow.AlternativeMaterialCode() + " not found" );
-                          stockingPointIdAlter := alterRow.OrganCode()  + "_" + alterRow.ProductType() + "_Stock";
+    //                      stockingPointIdAlter := alterRow.OrganCode()  + "_" + alterRow.ComponentType() + "_Stock";
+                          stockingPointIdAlter := alterRow.OrganCode() + "_Stock";
                           stockingPointAlter := StockingPoint_MP::FindById( this, stockingPointIdAlter );
                           if( isnull( stockingPointAlter ) ) {
                               error( "stockingPoint : " + stockingPointIdAlter + " not found" );
                           }
                           pispAlter := ProductInStockingPoint_MP::CreateIfNotFound( alterProd, stockingPointAlter );
-                          mainInput := toLink.LastOperationInput();
+                          //mainInput := toLink.LastOperationInput(); 
+                          mainInput := select( toLink,OperationInput,operationInut,operationInut.ProductID()=alterRow.ComponentCode());
                           trash := construct( OperationBOMs );
                           if( not isnull( mainInput ) ) {
                               alterBom := mainInput.Operation().LinkPISP( pispAlter, true, mainInput.OperationLinkGroupID(), trash );
diff --git a/_Main/BL/Type_MacroPlan/Method_MappingOperationBOMDataSupplyPurchase.qbl b/_Main/BL/Type_MacroPlan/Method_MappingOperationBOMDataSupplyPurchase.qbl
index 6a24698..7ea305b 100644
--- a/_Main/BL/Type_MacroPlan/Method_MappingOperationBOMDataSupplyPurchase.qbl
+++ b/_Main/BL/Type_MacroPlan/Method_MappingOperationBOMDataSupplyPurchase.qbl
@@ -8,25 +8,26 @@
 {
   TextBody:
   [*
-    routingId := "PR_"+orgCode + "_" + productId;
-    unitId := "渚涘簲鍟�";
-    routingStepName := "Purchase";
-    operationId := orgCode + "_PR_" + productId;
-    routing := Routing::CreateOrUpdate( this, routingId );
-    toDeleteSteps := selectset( routing, RoutingStep, routingStep, true );
-    RoutingStep::Delete( toDeleteSteps );
-    routingStep := RoutingStep::Create( routing, routingStepName, "", true );
+    
     product := Product_MP::FindById( this, productId );
     if( isnull( product ) ) {
         info(  "product : " + productId + " not found" );
     }
-    stockingPointId := orgCode + "_" + productType + "_Stock";
+    stockingPointId := orgCode + "_Stock";
     stockingPoint := StockingPoint_MP::FindById( this, stockingPointId );
     if( isnull( stockingPoint ) ) {
         info( "stockingPoint : " + stockingPointId + " not found" );
     }
     
     if( not isnull( product) and not isnull( stockingPoint)){
+      routingId := "PR_"+orgCode + "_" + productId;
+      unitId := "渚涘簲鍟�";
+      routingStepName := "Purchase";
+      operationId := orgCode + "_PR_" + productId;
+      routing := Routing::CreateOrUpdate( this, routingId );
+      toDeleteSteps := selectset( routing, RoutingStep, routingStep, true );
+      RoutingStep::Delete( toDeleteSteps );
+      routingStep := RoutingStep::Create( routing, routingStepName, "", true );
       unit := Unit::FindById( this, unitId );
       if( isnull( unit ) ) {
         unit := this.Unit( relnew, 
diff --git a/_Main/BL/Type_MacroPlan/Method_MappingOperationCostData.qbl b/_Main/BL/Type_MacroPlan/Method_MappingOperationCostData.qbl
index 98be129..3713cc9 100644
--- a/_Main/BL/Type_MacroPlan/Method_MappingOperationCostData.qbl
+++ b/_Main/BL/Type_MacroPlan/Method_MappingOperationCostData.qbl
@@ -27,7 +27,7 @@
                           moperation.ProductID() = item.ProductID(), 
                           moperation.SequenceNumber() ).SequenceNumber()
       if( item.SequenceNumber() = maxsn ){
-        listtodealwithmaxsn.Add( item );
+          listtodealwithmaxsn.Add( item );
         }
       }
     
diff --git a/_Main/BL/Type_MacroPlan/Method_MappingProductData.qbl b/_Main/BL/Type_MacroPlan/Method_MappingProductData.qbl
index fa5aa3b..9a854ef 100644
--- a/_Main/BL/Type_MacroPlan/Method_MappingProductData.qbl
+++ b/_Main/BL/Type_MacroPlan/Method_MappingProductData.qbl
@@ -10,7 +10,7 @@
   [*
     // Administrator Aug-16-2023 (created)
     // list to deal
-    //info( "Get list to deal of product" );
+    info( "Get list to deal of product" );
     listToDeal := construct( structured[MappingProduct] );
     
     if( isnull( businesstypes ) or businesstypes.Size() = 0 ) {
@@ -22,10 +22,10 @@
           }
     } else {
         if( iskeyproduct = true ){
-          listToDeal := selectset( this, MappingProduct, item, item.KeyProduct() = true,  businesstypes.Find(  item.BusinessType()) > 0 );
-          }
+          listToDeal := selectset( this, MappingProduct, item, item.KeyProduct() = true and businesstypes.Find(  item.BusinessType()) >= 0 );
+         }
         else{
-        listToDeal := selectset( this, MappingProduct, item, businesstypes.Find(  item.BusinessType()) > 0 );
+          listToDeal := selectset( this, MappingProduct, item, businesstypes.Find(  item.BusinessType()) >= 0 );
         }
     }
     totalcount := listToDeal.Size();
@@ -38,7 +38,7 @@
                                 "鍏ㄩ儴鐗╂枡浜у搧", 
                                 "PCS", 
                                 "鍏ㄩ儴鐗╂枡浜у搧",
-                                0.0
+                                0.0,false,false
                                 );
     count := 0;
     // Get the ProductMajorType list & ProductSubclassType list
@@ -54,7 +54,7 @@
                                     item.ProductMajorType(), 
                                     "PCS", 
                                     item.ProductMajorType(),
-                                    0.0
+                                    0.0,false,false
                                     );
       }
       productmajortype := item.ProductMajorType();
@@ -62,29 +62,30 @@
         productmajortype := "鍏ㄩ儴鐗╂枡浜у搧";
         }
        
-      if( not item.ProductSubclassType() = "" ){
-        Product_MP::CreateOrUpdate( this, 
-                                    item.ProductSubclassType(), 
-                                    productmajortype, 
-                                    item.ProductSubclassType(), 
-                                    "PCS", 
-                                    item.ProductSubclassType(),
-                                    0.0
-                                    );
-        }
-      productsubclasstype := item.ProductSubclassType();
-      if( productsubclasstype="" ){
-        productsubclasstype := productmajortype;
-        }
+    //  if( not item.ProductSubclassType() = "" ){
+    //    Product_MP::CreateOrUpdate( this, 
+    //                                item.ProductSubclassType(), 
+    //                                productmajortype, 
+    //                                item.ProductSubclassType(), 
+    //                                "PCS", 
+    //                                item.ProductSubclassType(),
+    //                                0.0,false,false
+    //                                );
+    //    }
+    //  productsubclasstype := item.ProductSubclassType();
+    //  if( productsubclasstype="" ){
+    //      productsubclasstype := productmajortype;
+    //    }
       
       if( not item.ID() = "" ){
           Product_MP::CreateOrUpdate( this, 
                                       item.ID(), 
-                                      productsubclasstype, 
+                                      productmajortype, 
                                       item.ID(), 
                                       item.UnitOfMeasureName(), 
                                       item.Name(),
-                                      item.ShelfLife()
+                                      item.ShelfLife(),
+                                      item.KeyProduct(),item.IsCommon()
                                       );
         }
       }
diff --git a/_Main/BL/Type_MacroPlan/Method_MappingUnitData.qbl b/_Main/BL/Type_MacroPlan/Method_MappingUnitData.qbl
index b5618c6..7c856ff 100644
--- a/_Main/BL/Type_MacroPlan/Method_MappingUnitData.qbl
+++ b/_Main/BL/Type_MacroPlan/Method_MappingUnitData.qbl
@@ -22,6 +22,7 @@
     
     //Set the Default values
     unitofmeasurename := "PCS";
+    infinite := "Infinite";
     capacitytype := "Transport quantity";
     
     // Get the root data
@@ -29,7 +30,7 @@
                           "澶╅┈闆嗗洟", 
                           "澶╅┈闆嗗洟", 
                           "", 
-                          capacitytype, 
+                          infinite, 
                           unitofmeasurename );
     
     // Get the sub root data
@@ -37,14 +38,14 @@
                           "鐢熶骇", 
                           "鐢熶骇", 
                           "澶╅┈闆嗗洟", 
-                          capacitytype, 
+                          infinite, 
                           unitofmeasurename );
     
     Unit::CreateOrUpdate( this, 
                           "渚涘簲鍟�", 
                           "渚涘簲鍟�", 
                           "澶╅┈闆嗗洟", 
-                          capacitytype, 
+                          infinite, 
                           unitofmeasurename );
     
     Unit::CreateOrUpdate( this, 
@@ -65,7 +66,7 @@
                             item.OrganCode(), 
                             OrgName, 
                             "鐢熶骇", 
-                            capacitytype, 
+                            infinite, 
                             unitofmeasurename );
                            
       //Get the second level unit
@@ -74,7 +75,7 @@
                             secondlevelid, 
                             secondlevelid, 
                             item.OrganCode(), 
-                            capacitytype, 
+                            infinite, 
                             unitofmeasurename );
         
       //Get the third level unit
diff --git a/_Main/BL/Type_MacroPlan/StaticMethod_DoSync0.qbl b/_Main/BL/Type_MacroPlan/StaticMethod_DoSync0.qbl
index fe4e7a1..1375c53 100644
--- a/_Main/BL/Type_MacroPlan/StaticMethod_DoSync0.qbl
+++ b/_Main/BL/Type_MacroPlan/StaticMethod_DoSync0.qbl
@@ -140,6 +140,9 @@
     // 璁㈠崟闇�姹�-18
     CustomerOrder::DoSync( macroPlan, businessTypes );
     
+    //鍒犻櫎澶氫綑鎶ラ敊鏁版嵁-19
+    macroPlan.DeleteSnaityCheck();
+    
     //// todo 渚涘簲鍟嗚兘鍔�
     //info( "ProviderCapacity::DoSync" )
     
diff --git a/_Main/BL/Type_MappingOperation/Attribute_SequenceNumber.qbl b/_Main/BL/Type_MappingOperation/Attribute_SequenceNumber.qbl
index 4fc6ea4..fed9689 100644
--- a/_Main/BL/Type_MappingOperation/Attribute_SequenceNumber.qbl
+++ b/_Main/BL/Type_MappingOperation/Attribute_SequenceNumber.qbl
@@ -3,5 +3,6 @@
 Attribute SequenceNumber
 {
   #keys: '3[412960.0.86978408][412960.0.86978407][412960.0.86978409]'
+  IsReadOnly: true
   ValueType: Number
 }
diff --git a/_Main/BL/Type_MappingOperation/TypeIndex_MappingOperationTypeIndex.qbl b/_Main/BL/Type_MappingOperation/TypeIndex_MappingOperationTypeIndex.qbl
index 35ab7e4..2fc4aff 100644
--- a/_Main/BL/Type_MappingOperation/TypeIndex_MappingOperationTypeIndex.qbl
+++ b/_Main/BL/Type_MappingOperation/TypeIndex_MappingOperationTypeIndex.qbl
@@ -6,11 +6,7 @@
   [
     TypeIndexAttribute
     {
-      ModelElement: Line
-    }
-    TypeIndexAttribute
-    {
-      ModelElement: BusinessType
+      ModelElement: ProcessSection
     }
     TypeIndexAttribute
     {
@@ -18,7 +14,11 @@
     }
     TypeIndexAttribute
     {
-      ModelElement: OrganCode
+      ModelElement: BusinessType
+    }
+    TypeIndexAttribute
+    {
+      ModelElement: Line
     }
     TypeIndexAttribute
     {
@@ -26,7 +26,11 @@
     }
     TypeIndexAttribute
     {
-      ModelElement: ProcessSection
+      ModelElement: SequenceNumber
+    }
+    TypeIndexAttribute
+    {
+      ModelElement: OrganCode
     }
   ]
 }
diff --git a/_Main/BL/Type_MappingProduct/Attribute_BusinessType.qbl b/_Main/BL/Type_MappingProduct/Attribute_BusinessType.qbl
index 63b7d6b..1d3a4b3 100644
--- a/_Main/BL/Type_MappingProduct/Attribute_BusinessType.qbl
+++ b/_Main/BL/Type_MappingProduct/Attribute_BusinessType.qbl
@@ -3,5 +3,6 @@
 Attribute BusinessType
 {
   #keys: '3[414480.0.61560268][414480.0.61560267][414480.0.61560269]'
+  IsReadOnly: true
   ValueType: String
 }
diff --git a/_Main/BL/Type_MappingProduct/TypeIndex_MappingProductTypeIndex.qbl b/_Main/BL/Type_MappingProduct/TypeIndex_MappingProductTypeIndex.qbl
index 6cd9f83..56be564 100644
--- a/_Main/BL/Type_MappingProduct/TypeIndex_MappingProductTypeIndex.qbl
+++ b/_Main/BL/Type_MappingProduct/TypeIndex_MappingProductTypeIndex.qbl
@@ -8,5 +8,9 @@
     {
       ModelElement: ID
     }
+    TypeIndexAttribute
+    {
+      ModelElement: BusinessType
+    }
   ]
 }
diff --git a/_Main/BL/Type_Product_MP/Attribute_BusinessTypeCommon.qbl b/_Main/BL/Type_Product_MP/Attribute_BusinessTypeCommon.qbl
new file mode 100644
index 0000000..b384b1d
--- /dev/null
+++ b/_Main/BL/Type_Product_MP/Attribute_BusinessTypeCommon.qbl
@@ -0,0 +1,7 @@
+Quintiq file version 2.0
+#parent: #root
+Attribute BusinessTypeCommon
+{
+  #keys: '3[414480.0.138606036][414480.0.138606035][414480.0.138606037]'
+  ValueType: Boolean
+}
diff --git a/_Main/BL/Type_Product_MP/Attribute_KeyProduct.qbl b/_Main/BL/Type_Product_MP/Attribute_KeyProduct.qbl
new file mode 100644
index 0000000..6261b43
--- /dev/null
+++ b/_Main/BL/Type_Product_MP/Attribute_KeyProduct.qbl
@@ -0,0 +1,7 @@
+Quintiq file version 2.0
+#parent: #root
+Attribute KeyProduct
+{
+  #keys: '3[414480.0.138606008][414480.0.138606007][414480.0.138606009]'
+  ValueType: Boolean
+}
diff --git a/_Main/BL/Type_Product_MP/StaticMethod_CreateOrUpdate.qbl b/_Main/BL/Type_Product_MP/StaticMethod_CreateOrUpdate.qbl
index 7d60ea3..2cc1d59 100644
--- a/_Main/BL/Type_Product_MP/StaticMethod_CreateOrUpdate.qbl
+++ b/_Main/BL/Type_Product_MP/StaticMethod_CreateOrUpdate.qbl
@@ -7,7 +7,9 @@
   String name,
   String unitofmeasurename,
   String description,
-  Real shelflife
+  Real shelflife,
+  Boolean keyproduct,
+  Boolean businesstypecommon
 )
 {
   TextBody:
@@ -28,7 +30,7 @@
     //info( productid );
     
     if( isnull( product ) ){
-      Product_MP::Create( owner, 
+      product := Product_MP::Create( owner, 
                           productid, 
                           parentid, 
                           name, 
@@ -44,6 +46,9 @@
                           isexcludedfromfulfilmentkpis, 
                           isfromdb
                           );
+                         
+        product.KeyProduct(keyproduct);
+        product.BusinessTypeCommon(businesstypecommon);
       }else{
         product.Update( productid, 
                         name, 
@@ -60,6 +65,8 @@
                         isexcludedfromfulfilmentkpis, 
                         isfromdb
                         );
+          product.KeyProduct(keyproduct);
+          product.BusinessTypeCommon(businesstypecommon);
         }
   *]
 }

--
Gitblit v1.9.3