From 83ec31b01a61d9a6bc74933572991469eeea4d44 Mon Sep 17 00:00:00 2001
From: admin <admin@admin.com>
Date: 星期一, 11 十一月 2024 19:33:19 +0800
Subject: [PATCH] 包装计划优化

---
 _Main/BL/Type_PackagingPlanCell/StaticMethod_GenerateReport.qbl                   |  103 -----------
 _Main/BL/Type_PackagingPlanCell/StaticMethod_SetPackage_Capacity.qbl              |   44 ++++
 _Main/BL/Type_PackagingPlanCell/StaticMethod_SetPackage_Lotsize.qbl               |   63 +++++++
 _Main/BL/Type_PackagingPlanCell/StaticMethod_CreateData.qbl                       |  110 ++++++++++++
 _Main/BL/Type_PackagingPlanCell/StaticMethod_SetUnpackage_Lotsize.qbl             |   64 +++++++
 _Main/BL/Type_PackagingPlanCell/StaticMethod_SetPackagingAndUnpackingValuesDL.qbl |  134 --------------
 6 files changed, 288 insertions(+), 230 deletions(-)

diff --git a/_Main/BL/Type_PackagingPlanCell/StaticMethod_CreateData.qbl b/_Main/BL/Type_PackagingPlanCell/StaticMethod_CreateData.qbl
new file mode 100644
index 0000000..7f720f8
--- /dev/null
+++ b/_Main/BL/Type_PackagingPlanCell/StaticMethod_CreateData.qbl
@@ -0,0 +1,110 @@
+Quintiq file version 2.0
+#parent: #root
+StaticMethod CreateData (
+  MacroPlan macroPlan
+)
+{
+  Description: '鍒涘缓鏁版嵁'
+  TextBody:
+  [*
+    macroPlan.PackagingPlanRow( relflush );
+    macroPlan.PackagingPlanColumn( relflush );
+    
+    // 鍒涘缓璁″垝鍓嶄竴澶╁垪
+    planPre     := macroPlan.PackagingPlanColumn( relnew, StartDate := macroPlan.StartOfPlanning().Date() - 1 );
+    
+    // 鐢熸垚鎶ヨ〃
+    traverse ( macroPlan, Product_MP.ProductInStockingPoint_MP, pisp, pisp.IsLeaf() and not pisp.IsSystem() and 
+               ( pisp.StockingPointID().Regex( "CC" ) or pisp.StockingPointID().Regex( "DL" ) or pisp.StockingPointID().Regex( "澶ц繛" ) or pisp.StockingPointID().Regex( "闀挎槬" ) ) ) {
+      // 褰撳墠pisp鎵�澶勫湴鐐�
+      factory             := ifexpr( pisp.StockingPointID().Regex( "CC" ) or pisp.StockingPointID().Regex( "闀挎槬" ), "闀挎槬宸ュ巶", "澶ц繛宸ュ巶" );
+      factoryAbbreviation := ifexpr( pisp.StockingPointID().Regex( "CC" ) or pisp.StockingPointID().Regex( "闀挎槬" ), "CC", "DL" );
+      
+      // 鍒涘缓琛�
+      ppr := select( macroPlan, PackagingPlanRow, tempPPR, tempPPR.ProductID() = pisp.ProductID() and tempPPR.Factory() = factory );
+      if ( isnull( ppr ) ) {
+        ppr := macroPlan.PackagingPlanRow( relnew, ProductID := pisp.ProductID(), Factory := factory, Category := guard( pisp.Product_MP().ParentID(), "" ) );
+      }
+      
+      // 寰幆pispippl
+      traverse ( pisp, ProductInStockingPointInPeriodPlanning.astype( ProductInStockingPointInPeriodPlanningLeaf ), pispipl, not pispipl.IsPeriodFrozen() ) {
+        // 鍒涘缓鍒�
+        ppc := select( macroPlan, PackagingPlanColumn, tempPPC, tempPPC.StartDate() = pispipl.Start().Date() );
+        if ( isnull( ppc ) ) {
+          ppc := macroPlan.PackagingPlanColumn( relnew, StartDate := pispipl.Start().Date() );
+        }
+        
+        // 鍒涘缓鍗曞厓鏍�
+        cell := select( ppr, PackagingPlanCell, tempPPCell, tempPPCell.PackagingPlanColumn() = ppc );
+        if ( isnull( cell ) ) {
+          cell := ppr.PackagingPlanCell( relnew ); 
+          cell.PackagingPlanColumn( relset, ppc );
+        }
+        
+        // 璁剧疆璋冨嚭
+        traverse ( pispipl, AsDeparturePISPIP, pit,
+                   pit.Quantity()                > 0                                                                         and
+                   pit.Trip().LaneLeg().AsOriginStockingPointLeg().StockingPoint_MP().ID().Regex( factoryAbbreviation )      and
+                   TransferPlanRow::IdentifyTheFactory( pit.Trip().LaneLeg().AsOriginStockingPointLeg().StockingPoint_MP() ) <> TransferPlanRow::IdentifyTheFactory( pit.Trip().LaneLeg().AsDestinationStockingPointLeg().StockingPoint_MP() )
+                  ) 
+        {
+          cell.Out( cell.Out() + pit.Quantity() );
+        }
+        
+        // 璁剧疆璋冭繘
+        traverse ( pispipl, AsArrivalPISPIP, pit,
+                   pit.Quantity()              > 0                                                                           and
+                   pit.Trip().LaneLeg().AsDestinationStockingPointLeg().StockingPoint_MP().ID().Regex( factoryAbbreviation ) and
+                   TransferPlanRow::IdentifyTheFactory( pit.Trip().LaneLeg().AsOriginStockingPointLeg().StockingPoint_MP() ) <> TransferPlanRow::IdentifyTheFactory( pit.Trip().LaneLeg().AsDestinationStockingPointLeg().StockingPoint_MP() )
+                  ) 
+        {
+          cell.TransferIn( cell.TransferIn() + pit.Quantity() );
+        }
+        
+        // 澶ц繛宸ュ巶璁剧疆鍊�
+        if ( factory = "澶ц繛宸ュ巶" ) {
+          // 鍑�闇�姹�&鍓╀綑搴撳瓨&渚涘簲閲�
+          cell.NetDemand( cell.NetDemand() + pispipl.DependentDemandAndSalesDemandQuantity() );
+          cell.EndingInventory( cell.EndingInventory() + pispipl.InventoryLevelEnd() );
+        }
+        
+        // 闀挎槬宸ュ巶璁剧疆鍊�
+        if ( factory = "闀挎槬宸ュ巶" ) {
+          // 鍓╀綑搴撳瓨&渚涘簲閲�
+          cell.EndingInventory( cell.EndingInventory() + pispipl.InventoryLevelEnd() );
+          
+          // 鍑�闇�姹傘�愬彧鍙栫嚎杈瑰簱銆�&鍖呰搴撳瓨&闈炲寘瑁呭簱瀛�
+          if ( pisp.StockingPointID().Regex( "澶栫搴�" ) ) {
+            cell.CC_PackagingInventory( pispipl.InventoryLevelEnd() );
+          } else if ( pisp.StockingPointID().Regex( "绾胯竟搴�" ) ) {
+            cell.CC_UnpackagedInventory( pispipl.InventoryLevelEnd() );
+            cell.NetDemand( cell.NetDemand() + pispipl.DependentDemandAndSalesDemandQuantity() );
+          }
+        }
+        
+        // 璁剧疆New Supply锛岀函鐢熶骇鍊�
+        traverse ( pispipl, NewSupply, ns, ns.PeriodTask_MP().istype( PeriodTaskOperation ) ) {
+          cell.NewSupply( cell.NewSupply() + ns.Quantity() );
+        }
+        
+        // 璁剧疆鍓嶄竴澶╁簱瀛�
+        if ( pispipl.Start().Date() = macroPlan.StartOfPlanning().Date() ) {
+          prePISPIPL  := pispipl.PreviousPlanningPISPIP().astype( ProductInStockingPointInPeriodPlanningLeaf ); // 鍓嶄竴涓猵ispippl
+          // 鍒涘缓璁″垝鍓嶄竴澶╂牸瀛�
+          preCell := select( ppr, PackagingPlanCell, tempPPCell, tempPPCell.PackagingPlanColumn() = planPre );
+          if ( isnull( preCell ) ) {
+            preCell := ppr.PackagingPlanCell( relnew );
+            preCell.EndingInventory( prePISPIPL.InventoryLevelEnd() );
+            preCell.PackagingPlanColumn( relset, planPre );
+          } else {
+            preCell.EndingInventory( preCell.EndingInventory() + prePISPIPL.InventoryLevelEnd() );
+          }
+        }
+      }
+    }
+    
+    Transaction::Transaction().Propagate( attribute( PackagingPlanRow, FactoryAbbreviation ) );
+    PackagingPlanCell::CalculationPackagingPlanProperties();
+    Transaction::Transaction().Propagate( relation( PackagingPlanCell, Next ) );
+  *]
+}
diff --git a/_Main/BL/Type_PackagingPlanCell/StaticMethod_GenerateReport.qbl b/_Main/BL/Type_PackagingPlanCell/StaticMethod_GenerateReport.qbl
index 9408e3a..dc2965f 100644
--- a/_Main/BL/Type_PackagingPlanCell/StaticMethod_GenerateReport.qbl
+++ b/_Main/BL/Type_PackagingPlanCell/StaticMethod_GenerateReport.qbl
@@ -6,110 +6,15 @@
 {
   TextBody:
   [*
-    macroPlan.PackagingPlanRow( relflush );
-    macroPlan.PackagingPlanColumn( relflush );
-    
-    // 鍒涘缓璁″垝鍓嶄竴澶╁垪
-    planPre     := macroPlan.PackagingPlanColumn( relnew, StartDate := macroPlan.StartOfPlanning().Date() - 1 );
-    
-    // 鐢熸垚鎶ヨ〃
-    traverse ( macroPlan, Product_MP.ProductInStockingPoint_MP, pisp, pisp.IsLeaf() and not pisp.IsSystem() and 
-               ( pisp.StockingPointID().Regex( "CC" ) or pisp.StockingPointID().Regex( "DL" ) or pisp.StockingPointID().Regex( "澶ц繛" ) or pisp.StockingPointID().Regex( "闀挎槬" ) ) ) {
-      // 褰撳墠pisp鎵�澶勫湴鐐�
-      factory             := ifexpr( pisp.StockingPointID().Regex( "CC" ) or pisp.StockingPointID().Regex( "闀挎槬" ), "闀挎槬宸ュ巶", "澶ц繛宸ュ巶" );
-      factoryAbbreviation := ifexpr( pisp.StockingPointID().Regex( "CC" ) or pisp.StockingPointID().Regex( "闀挎槬" ), "CC", "DL" );
-      
-      // 鍒涘缓琛�
-      ppr := select( macroPlan, PackagingPlanRow, tempPPR, tempPPR.ProductID() = pisp.ProductID() and tempPPR.Factory() = factory );
-      if ( isnull( ppr ) ) {
-        ppr := macroPlan.PackagingPlanRow( relnew, ProductID := pisp.ProductID(), Factory := factory, Category := guard( pisp.Product_MP().ParentID(), "" ) );
-      }
-      
-      // 寰幆pispippl
-      traverse ( pisp, ProductInStockingPointInPeriodPlanning.astype( ProductInStockingPointInPeriodPlanningLeaf ), pispipl, not pispipl.IsPeriodFrozen() ) {
-        // 鍒涘缓鍒�
-        ppc := select( macroPlan, PackagingPlanColumn, tempPPC, tempPPC.StartDate() = pispipl.Start().Date() );
-        if ( isnull( ppc ) ) {
-          ppc := macroPlan.PackagingPlanColumn( relnew, StartDate := pispipl.Start().Date() );
-        }
-        
-        // 鍒涘缓鍗曞厓鏍�
-        cell := select( ppr, PackagingPlanCell, tempPPCell, tempPPCell.PackagingPlanColumn() = ppc );
-        if ( isnull( cell ) ) {
-          cell := ppr.PackagingPlanCell( relnew ); 
-          cell.PackagingPlanColumn( relset, ppc );
-        }
-        
-        // 璁剧疆璋冨嚭
-        traverse ( pispipl, AsDeparturePISPIP, pit,
-                   pit.Quantity()                > 0                                                                         and
-                   pit.Trip().LaneLeg().AsOriginStockingPointLeg().StockingPoint_MP().ID().Regex( factoryAbbreviation )      and
-                   TransferPlanRow::IdentifyTheFactory( pit.Trip().LaneLeg().AsOriginStockingPointLeg().StockingPoint_MP() ) <> TransferPlanRow::IdentifyTheFactory( pit.Trip().LaneLeg().AsDestinationStockingPointLeg().StockingPoint_MP() )
-                  ) 
-        {
-          cell.Out( cell.Out() + pit.Quantity() );
-        }
-        
-        // 璁剧疆璋冭繘
-        traverse ( pispipl, AsArrivalPISPIP, pit,
-                   pit.Quantity()              > 0                                                                           and
-                   pit.Trip().LaneLeg().AsDestinationStockingPointLeg().StockingPoint_MP().ID().Regex( factoryAbbreviation ) and
-                   TransferPlanRow::IdentifyTheFactory( pit.Trip().LaneLeg().AsOriginStockingPointLeg().StockingPoint_MP() ) <> TransferPlanRow::IdentifyTheFactory( pit.Trip().LaneLeg().AsDestinationStockingPointLeg().StockingPoint_MP() )
-                  ) 
-        {
-          cell.TransferIn( cell.TransferIn() + pit.Quantity() );
-        }
-        
-        // 澶ц繛宸ュ巶璁剧疆鍊�
-        if ( factory = "澶ц繛宸ュ巶" ) {
-          // 鍑�闇�姹�&鍓╀綑搴撳瓨&渚涘簲閲�
-          cell.NetDemand( cell.NetDemand() + pispipl.DependentDemandAndSalesDemandQuantity() );
-          cell.EndingInventory( cell.EndingInventory() + pispipl.InventoryLevelEnd() );
-        }
-        
-        // 闀挎槬宸ュ巶璁剧疆鍊�
-        if ( factory = "闀挎槬宸ュ巶" ) {
-          // 鍓╀綑搴撳瓨&渚涘簲閲�
-          cell.EndingInventory( cell.EndingInventory() + pispipl.InventoryLevelEnd() );
-          
-          // 鍑�闇�姹傘�愬彧鍙栫嚎杈瑰簱銆�&鍖呰搴撳瓨&闈炲寘瑁呭簱瀛�
-          if ( pisp.StockingPointID().Regex( "澶栫搴�" ) ) {
-            cell.CC_PackagingInventory( pispipl.InventoryLevelEnd() );
-          } else if ( pisp.StockingPointID().Regex( "绾胯竟搴�" ) ) {
-            cell.CC_UnpackagedInventory( pispipl.InventoryLevelEnd() );
-            cell.NetDemand( cell.NetDemand() + pispipl.DependentDemandAndSalesDemandQuantity() );
-          }
-        }
-        
-        // 璁剧疆New Supply锛岀函鐢熶骇鍊�
-        traverse ( pispipl, NewSupply, ns, ns.PeriodTask_MP().istype( PeriodTaskOperation ) ) {
-          cell.NewSupply( cell.NewSupply() + ns.Quantity() );
-        }
-        
-        // 璁剧疆鍓嶄竴澶╁簱瀛�
-        if ( pispipl.Start().Date() = macroPlan.StartOfPlanning().Date() ) {
-          prePISPIPL  := pispipl.PreviousPlanningPISPIP().astype( ProductInStockingPointInPeriodPlanningLeaf ); // 鍓嶄竴涓猵ispippl
-          // 鍒涘缓璁″垝鍓嶄竴澶╂牸瀛�
-          preCell := select( ppr, PackagingPlanCell, tempPPCell, tempPPCell.PackagingPlanColumn() = planPre );
-          if ( isnull( preCell ) ) {
-            preCell := ppr.PackagingPlanCell( relnew );
-            preCell.EndingInventory( prePISPIPL.InventoryLevelEnd() );
-            preCell.PackagingPlanColumn( relset, planPre );
-          } else {
-            preCell.EndingInventory( preCell.EndingInventory() + prePISPIPL.InventoryLevelEnd() );
-          }
-        }
-      }
-    }
-    
-    Transaction::Transaction().Propagate( attribute( PackagingPlanRow, FactoryAbbreviation ) );
-    PackagingPlanCell::CalculationPackagingPlanProperties();
-    Transaction::Transaction().Propagate( relation( PackagingPlanCell, Next ) );
+    // 鍒涘缓鏁版嵁
+    PackagingPlanCell::CreateData( macroPlan );
     
     // 璁剧疆鍖呰&鎷嗗寘-鏁伴噺锛堝ぇ杩炲伐鍘傦級
     PackagingPlanCell::SetPackagingAndUnpackingValuesDL( macroPlan );
+    
     // 璁剧疆鍖呰&鎷嗗寘-鏁伴噺锛堥暱鏄ュ伐鍘傦級
     PackagingPlanCell::SetPackagingAndUnpackingValuesCC( macroPlan );
+    
     //traverse ( macroPlan, PackagingPlanRow, ppr, ( ppr.ProductID() = "Windshield" and ppr.StockingPointID() = "Bosch" ) or ( ppr.ProductID() = "Windshield" and ppr.StockingPointID() = "Components (Spain)" ) ) {
     //  traverse ( ppr, PackagingPlanCell, ppc/*, ppc.StartDate() = Date::Construct( 2020, 4, 1 )*/ ) {
     //    // 璁剧疆鍖呰鏁伴噺
diff --git a/_Main/BL/Type_PackagingPlanCell/StaticMethod_SetPackage_Capacity.qbl b/_Main/BL/Type_PackagingPlanCell/StaticMethod_SetPackage_Capacity.qbl
new file mode 100644
index 0000000..9ca94a0
--- /dev/null
+++ b/_Main/BL/Type_PackagingPlanCell/StaticMethod_SetPackage_Capacity.qbl
@@ -0,0 +1,44 @@
+Quintiq file version 2.0
+#parent: #root
+StaticMethod SetPackage_Capacity (
+  MacroPlan macroPlan
+)
+{
+  TextBody:
+  [*
+    // 璁″垝寮�濮嬫椂闂�
+    plannedStartDate := macroPlan.StartOfPlanning().Date();
+    
+    // 璁剧疆鍖呰鍊硷紙绗﹀悎澶х被涓嬫墍鏈変骇鍝侀潪鍖呰閲忓簱瀛樺姞鍜屼笉鑳藉ぇ浜庣郴缁熷�硷級
+    factorys               := selectuniquevalues( macroPlan, PackagingPlanRow, tempPPR, true, tempPPR.FactoryAbbreviation() );
+    categorys              := selectuniquevalues( macroPlan, PackagingPlanRow, tempPPR, true, tempPPR.Category() );
+    traverse ( factorys, Elements, f/*, f = "DL"*/ ) {
+      traverse ( categorys, Elements, c/*, c = "ZKG"*/ ) {
+        // 绯荤粺瑙勫畾鐨勬渶澶ч潪鍖呰搴撳瓨鏁伴噺
+        ppmqReflection     := Reflection::FindAttribute( "PackagingPlanMaximumQuantity", f + "_" + c );
+        maxPackageQuantity := guard( ppmqReflection.GetNumber( macroPlan.PackagingPlanMaximumQuantity() ), 0 );
+        // 褰撳墠宸ュ巶涓嬩竴绫讳骇鍝佽
+        pprs               := selectset( macroPlan, PackagingPlanRow, tempPPR, tempPPR.FactoryAbbreviation() = f and tempPPR.Category() = c );
+         
+    //    info( "褰撳墠宸ュ巶锛�", f, "    褰撳墠澶х被锛�", c, "    澶х被涓嬬殑鏈�澶у寘瑁呮暟閲忥細", maxPackageQuantity );
+        traverse ( macroPlan, PackagingPlanColumn, ppc, ppc.StartDate() > plannedStartDate and maxPackageQuantity > 0 ) {
+          sumUnpackagedInventoryQuantity := sum( pprs, Elements.PackagingPlanCell, tempPPCell, tempPPCell.PackagingPlanColumn() = ppc, tempPPCell.UnpackagedInventory() ).Round( 0 );
+          
+          // 闇�瑕佸寘瑁�
+          if ( sumUnpackagedInventoryQuantity > maxPackageQuantity ) {
+            // 闇�瑕佸寘瑁呯殑鏁伴噺
+            needPackagingQuantity := [Number] ( sumUnpackagedInventoryQuantity - maxPackageQuantity );
+            // 鎸夐潪鍖呰搴撳瓨鎺掑簭鍚庣殑琛�
+            itemPPRs              := selectsortedset( pprs, Elements, tempPPR, true, 
+                                                      -select( tempPPR, PackagingPlanCell, tempPPCell, tempPPCell.PackagingPlanColumn() = ppc ).UnpackagedInventory() );
+            
+    //        info( "闇�瑕佸寘瑁呮椂闂达細", ppc.StartDate().Format( "Y-M2-D2" ), "    闇�瑕佸寘瑁呯殑鏁伴噺锛�", needPackagingQuantity );
+            traverse ( itemPPRs, Elements, ppr, needPackagingQuantity > 0 ) {
+              PackagingPlanCell::Package( macroPlan, ppr, ppc, needPackagingQuantity );
+            }
+          }
+        }
+      }
+    }
+  *]
+}
diff --git a/_Main/BL/Type_PackagingPlanCell/StaticMethod_SetPackage_Lotsize.qbl b/_Main/BL/Type_PackagingPlanCell/StaticMethod_SetPackage_Lotsize.qbl
new file mode 100644
index 0000000..9012f37
--- /dev/null
+++ b/_Main/BL/Type_PackagingPlanCell/StaticMethod_SetPackage_Lotsize.qbl
@@ -0,0 +1,63 @@
+Quintiq file version 2.0
+#parent: #root
+StaticMethod SetPackage_Lotsize (
+  MacroPlan macroPlan
+)
+{
+  TextBody:
+  [*
+    // 璁″垝寮�濮嬫椂闂�
+    plannedStartDate := macroPlan.StartOfPlanning().Date();
+    
+    // 璁剧疆鍖呰鍊硷紙绗﹀悎lotsize鍜屼竴鏃ユ渶澶у寘瑁呴噺锛�
+    traverse ( macroPlan, PackagingPlanRow, ppr, ppr.Factory() = "澶ц繛宸ュ巶" /*and ppr.ProductID() = "06K103011CM"*/ ) {
+      traverse ( ppr, PackagingPlanCell, ppcell/*, ppcell.StartDate() <= Date::Construct( 2025, 1, 4 )*/ ) {
+        // Product_MP
+        pmp                     := select( macroPlan, Product_MP, tempPMP, tempPMP.IsLeaf() and tempPMP.ID() = ppr.ProductID() );
+        // 鍖呰lotsize
+        ppls                    := select( macroPlan, PackagingPlanLotSize, tempPPLS, tempPPLS.Factory() = ppr.Factory() and 
+                                           tempPPLS.ProductID() = ifexpr( exists( macroPlan, PackagingPlanLotSize, tempPPLS1, tempPPLS1.ProductID() = pmp.ID() ),
+                                                                          pmp.ID(),
+                                                                          pmp.ParentID() ) );
+        // 涓�鏃ュ寘瑁呭閲�
+        ppnc                    := select( macroPlan, PackagingPlanNewCapability, tempPPNC, tempPPNC.Factory() = ppr.Factory() and 
+                                           tempPPNC.ProductID() = ifexpr( exists( macroPlan, PackagingPlanNewCapability, tempPPNC1, tempPPNC1.ProductID() = pmp.ID() ),
+                                                                          pmp.ID(),
+                                                                          pmp.ParentID() ) );
+        // Unit
+        us                      := selectset( macroPlan, Unit, tempU, tempU.ID().Regex( ppr.FactoryAbbreviation() + " " + ppr.Category() ) );
+         
+        // 鍖呰搴撳瓨鍑虹幇璐熷�硷紝闇�瑕佽缃寘瑁呴噺
+        if ( ppcell.PackagingInventory() < 0 and not isnull( ppls ) and not isnull( ppnc ) ) {
+          // 闇�瑕佸寘瑁呯殑鏁伴噺
+          needPackagingQuantity := abs( ppcell.PackagingInventory() ).Round( 0 );
+          // 鍖呰寮�濮嬬殑绱㈠紩
+          indexPPCell           := ppcell.Previous();
+          
+    //      info( "浜х嚎涓暟锛�", us.Size(), "    寮�濮嬫椂闂达細", ppcell.StartDate().Format( "Y-M2-D2" ), "    鍖呰搴撳瓨鏁伴噺锛�", ppcell.PackagingInventory(), "    闇�瑕佸寘瑁呯殑鏁伴噺锛�", needPackagingQuantity, 
+    //            "    鍖呰lotsize锛�",guard( ppls.LotSize(), 0 ), "    鏈�澶у寘瑁呭閲忥細", ppnc.MaximumDailyPackagingQuantity() );
+          
+          while ( not isnull( indexPPCell )                                                   and 
+                  indexPPCell.StartDate() >= plannedStartDate                                 and 
+                  exists( us, Elements.UnitPeriod.astype( UnitPeriodTime ).ShiftPlan, tempSP, 
+                          tempSP.UnitPeriodTime().StartDate() = indexPPCell.StartDate(),
+                          tempSP.Outcome() <> "" )                                            and
+                  needPackagingQuantity > 0 ) {
+            // 鑳藉寘瑁呯殑鏁伴噺
+            canPackagingQuantity  := ifexpr( ceil( needPackagingQuantity / ppls.LotSize() ) < floor( ppnc.MaximumDailyPackagingQuantity() / ppls.LotSize() ),
+                                             ceil( needPackagingQuantity / ppls.LotSize() ),
+                                             floor( ppnc.MaximumDailyPackagingQuantity() / ppls.LotSize() ) ) * ppls.LotSize();
+    //        info( "寮�濮嬪寘瑁呯殑鏃ユ湡锛�", indexPPCell.StartDate().Format( "Y-M2-D2" ), "    鑳藉寘瑁呯殑鏁伴噺:", canPackagingQuantity );
+            
+            indexPPCell.Package( canPackagingQuantity );
+            Transaction::Transaction().Propagate( attribute( PackagingPlanCell, PackagingInventory ) );
+            Transaction::Transaction().Propagate( attribute( PackagingPlanCell, UnpackagedInventory ) );
+            
+            needPackagingQuantity := needPackagingQuantity - canPackagingQuantity;
+            indexPPCell           := indexPPCell.Previous();
+          }
+        }
+      }
+    }
+  *]
+}
diff --git a/_Main/BL/Type_PackagingPlanCell/StaticMethod_SetPackagingAndUnpackingValuesDL.qbl b/_Main/BL/Type_PackagingPlanCell/StaticMethod_SetPackagingAndUnpackingValuesDL.qbl
index 3e2e0e5..eb6eca2 100644
--- a/_Main/BL/Type_PackagingPlanCell/StaticMethod_SetPackagingAndUnpackingValuesDL.qbl
+++ b/_Main/BL/Type_PackagingPlanCell/StaticMethod_SetPackagingAndUnpackingValuesDL.qbl
@@ -6,141 +6,13 @@
 {
   TextBody:
   [*
-    // 璁″垝寮�濮嬫椂闂�
-    plannedStartDate := macroPlan.StartOfPlanning().Date();
-    
     // 璁剧疆鍖呰鍊硷紙绗﹀悎lotsize鍜屼竴鏃ユ渶澶у寘瑁呴噺锛�
-    traverse ( macroPlan, PackagingPlanRow, ppr, ppr.Factory() = "澶ц繛宸ュ巶" /*and ppr.ProductID() = "06K103011CM"*/ ) {
-      traverse ( ppr, PackagingPlanCell, ppcell/*, ppcell.StartDate() <= Date::Construct( 2025, 1, 4 )*/ ) {
-        // Product_MP
-        pmp                     := select( macroPlan, Product_MP, tempPMP, tempPMP.IsLeaf() and tempPMP.ID() = ppr.ProductID() );
-        // 鍖呰lotsize
-        ppls                    := select( macroPlan, PackagingPlanLotSize, tempPPLS, tempPPLS.Factory() = ppr.Factory() and 
-                                           tempPPLS.ProductID() = ifexpr( exists( macroPlan, PackagingPlanLotSize, tempPPLS1, tempPPLS1.ProductID() = pmp.ID() ),
-                                                                          pmp.ID(),
-                                                                          pmp.ParentID() ) );
-        // 涓�鏃ュ寘瑁呭閲�
-        ppnc                    := select( macroPlan, PackagingPlanNewCapability, tempPPNC, tempPPNC.Factory() = ppr.Factory() and 
-                                           tempPPNC.ProductID() = ifexpr( exists( macroPlan, PackagingPlanNewCapability, tempPPNC1, tempPPNC1.ProductID() = pmp.ID() ),
-                                                                          pmp.ID(),
-                                                                          pmp.ParentID() ) );
-        // Unit
-        us                      := selectset( macroPlan, Unit, tempU, tempU.ID().Regex( ppr.FactoryAbbreviation() + " " + ppr.Category() ) );
-         
-        // 鍖呰搴撳瓨鍑虹幇璐熷�硷紝闇�瑕佽缃寘瑁呴噺
-        if ( ppcell.PackagingInventory() < 0 and not isnull( ppls ) and not isnull( ppnc ) ) {
-          // 闇�瑕佸寘瑁呯殑鏁伴噺
-          needPackagingQuantity := abs( ppcell.PackagingInventory() ).Round( 0 );
-          // 鍖呰寮�濮嬬殑绱㈠紩
-          indexPPCell           := ppcell.Previous();
-          
-    //      info( "浜х嚎涓暟锛�", us.Size(), "    寮�濮嬫椂闂达細", ppcell.StartDate().Format( "Y-M2-D2" ), "    鍖呰搴撳瓨鏁伴噺锛�", ppcell.PackagingInventory(), "    闇�瑕佸寘瑁呯殑鏁伴噺锛�", needPackagingQuantity, 
-    //            "    鍖呰lotsize锛�",guard( ppls.LotSize(), 0 ), "    鏈�澶у寘瑁呭閲忥細", ppnc.MaximumDailyPackagingQuantity() );
-          
-          while ( not isnull( indexPPCell )                                                   and 
-                  indexPPCell.StartDate() >= plannedStartDate                                 and 
-                  exists( us, Elements.UnitPeriod.astype( UnitPeriodTime ).ShiftPlan, tempSP, 
-                          tempSP.UnitPeriodTime().StartDate() = indexPPCell.StartDate(),
-                          tempSP.Outcome() <> "" )                                            and
-                  needPackagingQuantity > 0 ) {
-            // 鑳藉寘瑁呯殑鏁伴噺
-            canPackagingQuantity  := ifexpr( ceil( needPackagingQuantity / ppls.LotSize() ) < floor( ppnc.MaximumDailyPackagingQuantity() / ppls.LotSize() ),
-                                             ceil( needPackagingQuantity / ppls.LotSize() ),
-                                             floor( ppnc.MaximumDailyPackagingQuantity() / ppls.LotSize() ) ) * ppls.LotSize();
-    //        info( "寮�濮嬪寘瑁呯殑鏃ユ湡锛�", indexPPCell.StartDate().Format( "Y-M2-D2" ), "    鑳藉寘瑁呯殑鏁伴噺:", canPackagingQuantity );
-            
-            indexPPCell.Package( canPackagingQuantity );
-            Transaction::Transaction().Propagate( attribute( PackagingPlanCell, PackagingInventory ) );
-            Transaction::Transaction().Propagate( attribute( PackagingPlanCell, UnpackagedInventory ) );
-            
-            needPackagingQuantity := needPackagingQuantity - canPackagingQuantity;
-            indexPPCell           := indexPPCell.Previous();
-          }
-        }
-      }
-    }
+    PackagingPlanCell::SetPackage_Lotsize( macroPlan );
     
     // 璁剧疆鍖呰鍊硷紙绗﹀悎澶х被涓嬫墍鏈変骇鍝侀潪鍖呰閲忓簱瀛樺姞鍜屼笉鑳藉ぇ浜庣郴缁熷�硷級
-    factorys               := selectuniquevalues( macroPlan, PackagingPlanRow, tempPPR, true, tempPPR.FactoryAbbreviation() );
-    categorys              := selectuniquevalues( macroPlan, PackagingPlanRow, tempPPR, true, tempPPR.Category() );
-    traverse ( factorys, Elements, f/*, f = "DL"*/ ) {
-      traverse ( categorys, Elements, c/*, c = "ZKG"*/ ) {
-        // 绯荤粺瑙勫畾鐨勬渶澶ч潪鍖呰搴撳瓨鏁伴噺
-        ppmqReflection     := Reflection::FindAttribute( "PackagingPlanMaximumQuantity", f + "_" + c );
-        maxPackageQuantity := guard( ppmqReflection.GetNumber( macroPlan.PackagingPlanMaximumQuantity() ), 0 );
-        // 褰撳墠宸ュ巶涓嬩竴绫讳骇鍝佽
-        pprs               := selectset( macroPlan, PackagingPlanRow, tempPPR, tempPPR.FactoryAbbreviation() = f and tempPPR.Category() = c );
-         
-    //    info( "褰撳墠宸ュ巶锛�", f, "    褰撳墠澶х被锛�", c, "    澶х被涓嬬殑鏈�澶у寘瑁呮暟閲忥細", maxPackageQuantity );
-        traverse ( macroPlan, PackagingPlanColumn, ppc, ppc.StartDate() > plannedStartDate and maxPackageQuantity > 0 ) {
-          sumUnpackagedInventoryQuantity := sum( pprs, Elements.PackagingPlanCell, tempPPCell, tempPPCell.PackagingPlanColumn() = ppc, tempPPCell.UnpackagedInventory() ).Round( 0 );
-          
-          // 闇�瑕佸寘瑁�
-          if ( sumUnpackagedInventoryQuantity > maxPackageQuantity ) {
-            // 闇�瑕佸寘瑁呯殑鏁伴噺
-            needPackagingQuantity := [Number] ( sumUnpackagedInventoryQuantity - maxPackageQuantity );
-            // 鎸夐潪鍖呰搴撳瓨鎺掑簭鍚庣殑琛�
-            itemPPRs              := selectsortedset( pprs, Elements, tempPPR, true, 
-                                                      -select( tempPPR, PackagingPlanCell, tempPPCell, tempPPCell.PackagingPlanColumn() = ppc ).UnpackagedInventory() );
-            
-    //        info( "闇�瑕佸寘瑁呮椂闂达細", ppc.StartDate().Format( "Y-M2-D2" ), "    闇�瑕佸寘瑁呯殑鏁伴噺锛�", needPackagingQuantity );
-            traverse ( itemPPRs, Elements, ppr, needPackagingQuantity > 0 ) {
-              PackagingPlanCell::Package( macroPlan, ppr, ppc, needPackagingQuantity );
-            }
-          }
-        }
-      }
-    }
+    PackagingPlanCell::SetPackage_Capacity( macroPlan );
     
     // 璁剧疆鎷嗗寘鍊硷紙绗﹀悎lotsize鍜屼竴鏃ユ渶澶у寘瑁呴噺锛�
-    traverse ( macroPlan, PackagingPlanRow, ppr, ppr.Factory() = "澶ц繛宸ュ巶" /*and ppr.ProductID() = "06K103011CM"*/ ) {
-      traverse ( ppr, PackagingPlanCell, ppcell/*, ppcell.StartDate() <= Date::Construct( 2025, 1, 4 )*/ ) {
-        // Product_MP
-        pmp                     := select( macroPlan, Product_MP, tempPMP, tempPMP.IsLeaf() and tempPMP.ID() = ppr.ProductID() );
-        // 鍖呰lotsize
-        ppls                    := select( macroPlan, PackagingPlanLotSize, tempPPLS, tempPPLS.Factory() = ppr.Factory() and 
-                                           tempPPLS.ProductID() = ifexpr( exists( macroPlan, PackagingPlanLotSize, tempPPLS1, tempPPLS1.ProductID() = pmp.ID() ),
-                                                                          pmp.ID(),
-                                                                          pmp.ParentID() ) );
-        // 涓�鏃ュ寘瑁呭閲�
-        ppnc                    := select( macroPlan, PackagingPlanNewCapability, tempPPNC, tempPPNC.Factory() = ppr.Factory() and 
-                                           tempPPNC.ProductID() = ifexpr( exists( macroPlan, PackagingPlanNewCapability, tempPPNC1, tempPPNC1.ProductID() = pmp.ID() ),
-                                                                          pmp.ID(),
-                                                                          pmp.ParentID() ) );
-        // Unit
-        us                      := selectset( macroPlan, Unit, tempU, tempU.ID().Regex( ppr.FactoryAbbreviation() + " " + ppr.Category() ) );
-         
-        // 褰撳墠闈炲寘瑁呭簱瀛� + 涓嬩竴澶╃殑NewSupply < 涓嬩竴澶╃殑鍑�闇�姹�
-        if ( ppcell.UnpackagedInventory() < guard( ppcell.Next().NetDemand(), 0 ) and not isnull( ppls ) and not isnull( ppnc ) ) {
-          // 闇�瑕佸寘瑁呯殑鏁伴噺
-          needPackagingQuantity := abs( ppcell.PackagingInventory() ).Round( 0 );
-          // 鍖呰寮�濮嬬殑绱㈠紩
-          indexPPCell           := ppcell.Previous();
-          
-    //      info( "浜х嚎涓暟锛�", us.Size(), "    寮�濮嬫椂闂达細", ppcell.StartDate().Format( "Y-M2-D2" ), "    鍖呰搴撳瓨鏁伴噺锛�", ppcell.PackagingInventory(), "    闇�瑕佸寘瑁呯殑鏁伴噺锛�", needPackagingQuantity, 
-    //            "    鍖呰lotsize锛�",guard( ppls.LotSize(), 0 ), "    鏈�澶у寘瑁呭閲忥細", ppnc.MaximumDailyPackagingQuantity() );
-          
-          while ( not isnull( indexPPCell )                                                   and 
-                  indexPPCell.StartDate() >= plannedStartDate                                 and 
-                  exists( us, Elements.UnitPeriod.astype( UnitPeriodTime ).ShiftPlan, tempSP, 
-                          tempSP.UnitPeriodTime().StartDate() = indexPPCell.StartDate(),
-                          tempSP.Outcome() <> "" )                                            and
-                  needPackagingQuantity > 0 ) {
-            // 鑳藉寘瑁呯殑鏁伴噺
-            canPackagingQuantity  := ifexpr( ceil( needPackagingQuantity / ppls.LotSize() ) < floor( ppnc.MaximumDailyPackagingQuantity() / ppls.LotSize() ),
-                                             ceil( needPackagingQuantity / ppls.LotSize() ),
-                                             floor( ppnc.MaximumDailyPackagingQuantity() / ppls.LotSize() ) ) * ppls.LotSize();
-    //        info( "寮�濮嬪寘瑁呯殑鏃ユ湡锛�", indexPPCell.StartDate().Format( "Y-M2-D2" ), "    鑳藉寘瑁呯殑鏁伴噺:", canPackagingQuantity );
-            
-            indexPPCell.Package( canPackagingQuantity );
-            Transaction::Transaction().Propagate( attribute( PackagingPlanCell, PackagingInventory ) );
-            Transaction::Transaction().Propagate( attribute( PackagingPlanCell, UnpackagedInventory ) );
-            
-            needPackagingQuantity := needPackagingQuantity - canPackagingQuantity;
-            indexPPCell           := indexPPCell.Previous();
-          }
-        }
-      }
-    }
+    PackagingPlanCell::SetUnpackage_Lotsize( macroPlan );
   *]
 }
diff --git a/_Main/BL/Type_PackagingPlanCell/StaticMethod_SetUnpackage_Lotsize.qbl b/_Main/BL/Type_PackagingPlanCell/StaticMethod_SetUnpackage_Lotsize.qbl
new file mode 100644
index 0000000..128015d
--- /dev/null
+++ b/_Main/BL/Type_PackagingPlanCell/StaticMethod_SetUnpackage_Lotsize.qbl
@@ -0,0 +1,64 @@
+Quintiq file version 2.0
+#parent: #root
+StaticMethod SetUnpackage_Lotsize (
+  MacroPlan macroPlan
+)
+{
+  TextBody:
+  [*
+    // 璁″垝寮�濮嬫椂闂�
+    plannedStartDate := macroPlan.StartOfPlanning().Date();
+    
+    // 璁剧疆鎷嗗寘鍊硷紙绗﹀悎lotsize鍜屼竴鏃ユ渶澶у寘瑁呴噺锛�
+    traverse ( macroPlan, PackagingPlanRow, ppr, ppr.Factory() = "澶ц繛宸ュ巶" /*and ppr.ProductID() = "06K103011CM"*/ ) {
+      traverse ( ppr, PackagingPlanCell, ppcell/*, ppcell.StartDate() <= Date::Construct( 2025, 1, 4 )*/ ) {
+        // Product_MP
+        pmp                     := select( macroPlan, Product_MP, tempPMP, tempPMP.IsLeaf() and tempPMP.ID() = ppr.ProductID() );
+        // 鍖呰lotsize
+        ppls                    := select( macroPlan, PackagingPlanLotSize, tempPPLS, tempPPLS.Factory() = ppr.Factory() and 
+                                           tempPPLS.ProductID() = ifexpr( exists( macroPlan, PackagingPlanLotSize, tempPPLS1, tempPPLS1.ProductID() = pmp.ID() ),
+                                                                          pmp.ID(),
+                                                                          pmp.ParentID() ) );
+        // 涓�鏃ュ寘瑁呭閲�
+        ppnc                    := select( macroPlan, PackagingPlanNewCapability, tempPPNC, tempPPNC.Factory() = ppr.Factory() and 
+                                           tempPPNC.ProductID() = ifexpr( exists( macroPlan, PackagingPlanNewCapability, tempPPNC1, tempPPNC1.ProductID() = pmp.ID() ),
+                                                                          pmp.ID(),
+                                                                          pmp.ParentID() ) );
+        // Unit
+        us                      := selectset( macroPlan, Unit, tempU, tempU.ID().Regex( ppr.FactoryAbbreviation() + " " + ppr.Category() ) );
+         
+        // 褰撳墠闈炲寘瑁呭簱瀛� + 涓嬩竴澶╃殑NewSupply < 涓嬩竴澶╃殑鍑�闇�姹�
+        if ( ppcell.UnpackagedInventory() < guard( ppcell.Next().NetDemand(), 0 ) and not isnull( ppls ) and not isnull( ppnc ) ) {
+          // 闇�瑕佸寘瑁呯殑鏁伴噺
+          needPackagingQuantity := abs( ppcell.PackagingInventory() ).Round( 0 );
+          // 鍖呰寮�濮嬬殑绱㈠紩
+          indexPPCell           := ppcell.Previous();
+          
+    //      info( "浜х嚎涓暟锛�", us.Size(), "    寮�濮嬫椂闂达細", ppcell.StartDate().Format( "Y-M2-D2" ), "    鍖呰搴撳瓨鏁伴噺锛�", ppcell.PackagingInventory(), "    闇�瑕佸寘瑁呯殑鏁伴噺锛�", needPackagingQuantity, 
+    //            "    鍖呰lotsize锛�",guard( ppls.LotSize(), 0 ), "    鏈�澶у寘瑁呭閲忥細", ppnc.MaximumDailyPackagingQuantity() );
+          
+          while ( not isnull( indexPPCell )                                                   and 
+                  indexPPCell.StartDate() >= plannedStartDate                                 and 
+                  exists( us, Elements.UnitPeriod.astype( UnitPeriodTime ).ShiftPlan, tempSP, 
+                          tempSP.UnitPeriodTime().StartDate() = indexPPCell.StartDate(),
+                          tempSP.Outcome() <> "" )                                            and
+                  needPackagingQuantity > 0 ) {
+            // 鑳藉寘瑁呯殑鏁伴噺
+            canPackagingQuantity := ifexpr( ceil( needPackagingQuantity / ppls.LotSize() ) < floor( ppnc.MaximumDailyPackagingQuantity() / ppls.LotSize() ),
+                                            ceil( needPackagingQuantity / ppls.LotSize() ),
+                                            floor( ppnc.MaximumDailyPackagingQuantity() / ppls.LotSize() ) ) * ppls.LotSize();
+            canPackagingQuantity := minvalue( canPackagingQuantity, [Number]indexPPCell.PackagingInventory() ); 
+    //        info( "寮�濮嬪寘瑁呯殑鏃ユ湡锛�", indexPPCell.StartDate().Format( "Y-M2-D2" ), "    鑳藉寘瑁呯殑鏁伴噺:", canPackagingQuantity );
+            
+            indexPPCell.Next().Unpacking( canPackagingQuantity );
+            Transaction::Transaction().Propagate( attribute( PackagingPlanCell, PackagingInventory ) );
+            Transaction::Transaction().Propagate( attribute( PackagingPlanCell, UnpackagedInventory ) );
+            
+            needPackagingQuantity := needPackagingQuantity - canPackagingQuantity;
+            indexPPCell           := indexPPCell.Previous();
+          }
+        }
+      }
+    }
+  *]
+}

--
Gitblit v1.9.3