From 2a2008e78e050e8c25d8b40453c962eb15c0ab84 Mon Sep 17 00:00:00 2001
From: admin <admin@admin.com>
Date: 星期四, 10 十月 2024 10:25:12 +0800
Subject: [PATCH] 包装计划优化

---
 _Main/BL/Type_PackagingPlanCell/StaticMethod_GenerateReport.qbl |  122 +++++++++++++++++++++++-----------------
 1 files changed, 69 insertions(+), 53 deletions(-)

diff --git a/_Main/BL/Type_PackagingPlanCell/StaticMethod_GenerateReport.qbl b/_Main/BL/Type_PackagingPlanCell/StaticMethod_GenerateReport.qbl
index 88d7ea9..bfdadff 100644
--- a/_Main/BL/Type_PackagingPlanCell/StaticMethod_GenerateReport.qbl
+++ b/_Main/BL/Type_PackagingPlanCell/StaticMethod_GenerateReport.qbl
@@ -13,21 +13,23 @@
     planPre     := macroPlan.PackagingPlanColumn( relnew, StartDate := macroPlan.StartOfPlanning().Date() - 1 );
     
     // 鐢熸垚鎶ヨ〃
-    traverse ( macroPlan, Product_MP.ProductInStockingPoint_MP, pisp, pisp.IsLeaf() and not pisp.IsSystem() ) {
-      // 鍒涘缓琛�
-      ppr := select( macroPlan, PackagingPlanRow, tempPPR, tempPPR.ProductID() = pisp.ProductID() and tempPPR.StockingPointID() = pisp.StockingPointID() );
-      if ( isnull( ppr ) ) {
-        ppr := macroPlan.PackagingPlanRow( relnew, ProductID := pisp.ProductID(), StockingPointID := pisp.StockingPointID(), Factory := "澶ц繛宸ュ巶", Category := "ZKG" );
-      }
+    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( "闀挎槬" ), "闀挎槬宸ュ巶", "澶ц繛宸ュ巶" );
       
-      // 鍒涘缓璁″垝鍓嶄竴澶╂牸瀛�
-      planPreCell      := ppr.PackagingPlanCell( relnew, PackagingPlanColumn := planPre, InitialPackagingInventory := 200 );
+      // 鍒涘缓琛�
+      ppr := select( macroPlan, PackagingPlanRow, tempPPR, tempPPR.ProductID() = pisp.ProductID() and tempPPR.Factory() = factory );
+      if ( isnull( ppr ) ) {
+        ppr := macroPlan.PackagingPlanRow( relnew, ProductID := pisp.ProductID(), StockingPointID := pisp.StockingPointID(), Factory := factory, Category := guard( pisp.Product_MP().ParentID(), "" ) );
+      }
       
       // 鍑哄彂鍦板簱瀛樼偣Trip
       originTrips      := selectset( macroPlan, Unit.Lane.LaneLeg.Trip, tempT, tempT.LaneLeg().AsOriginStockingPointLeg().StockingPoint_MP().ID() = pisp.StockingPointID() );
       // 鐩殑鍦板簱瀛樼偣Trip
       destinationTrips := selectset( macroPlan, Unit.Lane.LaneLeg.Trip, tempT, tempT.LaneLeg().AsDestinationStockingPointLeg().StockingPoint_MP().ID() = pisp.StockingPointID() );
       
+      // 鍒涘缓鍗曞厓鏍�
       traverse ( pisp, ProductInStockingPointInPeriodPlanning.astype( ProductInStockingPointInPeriodPlanningLeaf ), pispipl, not pispipl.IsPeriodFrozen() ) {
         // 鍒涘缓鍒�
         ppc := select( macroPlan, PackagingPlanColumn, tempPPC, tempPPC.StartDate() = pispipl.Start().Date() );
@@ -38,16 +40,22 @@
         // 鍒涘缓鍗曞厓鏍�
         cell := select( ppr, PackagingPlanCell, tempPPCell, tempPPCell.PackagingPlanColumn() = ppc );
         if ( isnull( cell ) ) {
-          cell := ppr.PackagingPlanCell( relnew, NetDemand := pispipl.DependentDemandAndSalesDemandQuantity() - pispipl.NewSupplyQuantity(), EndingInventory := pispipl.InventoryLevelEnd() );
+          cell := ppr.PackagingPlanCell( relnew );
+          cell.NetDemand( pispipl.DependentDemandAndSalesDemandQuantity() - pispipl.NewSupplyQuantity() );
+          cell.EndingInventory( pispipl.InventoryLevelEnd() );
           cell.PackagingPlanColumn( relset, ppc );
+        } else {
+          cell.NetDemand( cell.NetDemand() + ( pispipl.DependentDemandAndSalesDemandQuantity() - pispipl.NewSupplyQuantity() ) );
+          cell.EndingInventory( cell.EndingInventory() + pispipl.InventoryLevelEnd() );
         }
         
-        // 璁剧疆璋冨嚭&璋冭繘
+        // 璁剧疆璋冨嚭
         outs := selectset( originTrips, Elements, tempT, tempT.Departure().Date() = pispipl.Start().Date() );
         traverse ( outs, Elements, out ) {
           cell.Out( cell.Out() + out.Quantity() );
         }
         
+        // 璁剧疆璋冭繘
         transferIns := selectset( destinationTrips, Elements, tempT, tempT.Arrival().Date() = pispipl.Start().Date() );
         traverse ( transferIns, Elements, ti ) {
           cell.TransferIn( cell.TransferIn() + ti.Quantity() );
@@ -55,8 +63,16 @@
         
         // 璁剧疆鍓嶄竴澶╁簱瀛�
         if ( pispipl.Start().Date() = macroPlan.StartOfPlanning().Date() ) {
-    //      prePISPIPL := pispipl.PreviousPlanningPISPIP().astype( ProductInStockingPointInPeriodPlanningLeaf );
-          planPreCell.EndingInventory( 2000 );
+          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() );
+          }
         }
       }
     }
@@ -66,46 +82,46 @@
     Transaction::Transaction().Propagate( relation( PackagingPlanCell, Next ) );
     
     // 璁剧疆鍖呰&鎷嗗寘-鏁伴噺
-    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 )*/ ) {
-        // 璁剧疆鍖呰鏁伴噺
-        if ( ppc.PackagingInventory() < ppc.Out() ) { // 鍖呰搴撳瓨鏄惁灏忎簬璋冨嚭
-          prePPC                := ppc.Previous();
-          needPackagingQuantity := ppc.Out() - prePPC.PackagingInventory();
-          while ( not isnull( prePPC ) and needPackagingQuantity > 0.0 ) {
-            // 鑾峰彇鍖呰lotsize
-            ppls                   := select( macroPlan, PackagingPlanLotSize, tempPPLS, tempPPLS.Factory() =  ppc.PackagingPlanRow().Factory()    and 
-                                                                                        tempPPLS.ProductID() = ppc.PackagingPlanRow().ProductID() );
-            
-            // 鑾峰彇鏈�澶у寘瑁呮暟閲�
-            maxPackageReflection   := Reflection::FindAttribute( "PackagingPlanCapability", ppc.PackagingPlanRow().FactoryAbbreviation() + "_" + ppc.PackagingPlanRow().Category() + "_Package" );
-    //        maxPackageQuantity     := maxPackageReflection.GetNumber( macroPlan.PackagingPlanCapability() ); // 姝ゅ闇�瑕佷慨鏀�
-            maxPackageQuantity     := 100000;
-            
-            // 鑾峰彇鏈�缁堝寘瑁呮暟閲�
-            finalPackagingQuantity := minvalue( ceil( needPackagingQuantity / ppls.LotSize() ), ceil( ( maxPackageQuantity - prePPC.Package() ) / ppls.LotSize() ) ) * ppls.LotSize();
-            needPackagingQuantity  := needPackagingQuantity - finalPackagingQuantity;
-            
-            // 璁剧疆鍖呰鍊�
-            prePPC.Package( prePPC.Package() + finalPackagingQuantity );
-            
-            //debuginfo( "闇�瑕佸寘瑁呮暟閲忥細", needPackagingQuantity, "    lotsize: ", ppls.LotSize(), "    鏈�澶у寘瑁呮暟閲忥細", maxPackageQuantity, "    鏈�缁堣ˉ鐨勬暟閲忥細", finalPackagingQuantity );
-            PackagingPlanCell::CalculationPackagingPlanProperties();
-          
-            prePPC := prePPC.Previous();
-          }
-        }
-        
-        // 璁剧疆鎷嗗寘鏁伴噺
-        if ( ppc.TransferIn() > 0.0 ) { // 鏈夎皟鍏ユ暟閲�
-          // 鑾峰彇鍖呰lotsize
-          ppls                 := select( macroPlan, PackagingPlanLotSize, tempPPLS, tempPPLS.Factory() =  ppc.PackagingPlanRow().Factory()    and 
-                                                                                     tempPPLS.ProductID() = ppc.PackagingPlanRow().ProductID() );
-        
-          // 璁剧疆鎷嗗寘鍊�
-          ppc.Unpacking( ppc.TransferIn() );
-        }
-      }
-    }
+    //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 )*/ ) {
+    //    // 璁剧疆鍖呰鏁伴噺
+    //    if ( ppc.PackagingInventory() < ppc.Out() ) { // 鍖呰搴撳瓨鏄惁灏忎簬璋冨嚭
+    //      prePPC                := ppc.Previous();
+    //      needPackagingQuantity := ppc.Out() - prePPC.PackagingInventory();
+    //      while ( not isnull( prePPC ) and needPackagingQuantity > 0.0 ) {
+    //        // 鑾峰彇鍖呰lotsize
+    //        ppls                   := select( macroPlan, PackagingPlanLotSize, tempPPLS, tempPPLS.Factory() =  ppc.PackagingPlanRow().Factory()    and 
+    //                                                                                    tempPPLS.ProductID() = ppc.PackagingPlanRow().ProductID() );
+    //        
+    //        // 鑾峰彇鏈�澶у寘瑁呮暟閲�
+    //        maxPackageReflection   := Reflection::FindAttribute( "PackagingPlanCapability", ppc.PackagingPlanRow().FactoryAbbreviation() + "_" + ppc.PackagingPlanRow().Category() + "_Package" );
+    ////        maxPackageQuantity     := maxPackageReflection.GetNumber( macroPlan.PackagingPlanCapability() ); // 姝ゅ闇�瑕佷慨鏀�
+    //        maxPackageQuantity     := 100000;
+    //        
+    //        // 鑾峰彇鏈�缁堝寘瑁呮暟閲�
+    //        finalPackagingQuantity := minvalue( ceil( needPackagingQuantity / ppls.LotSize() ), ceil( ( maxPackageQuantity - prePPC.Package() ) / ppls.LotSize() ) ) * ppls.LotSize();
+    //        needPackagingQuantity  := needPackagingQuantity - finalPackagingQuantity;
+    //        
+    //        // 璁剧疆鍖呰鍊�
+    //        prePPC.Package( prePPC.Package() + finalPackagingQuantity );
+    //        
+    //        //debuginfo( "闇�瑕佸寘瑁呮暟閲忥細", needPackagingQuantity, "    lotsize: ", ppls.LotSize(), "    鏈�澶у寘瑁呮暟閲忥細", maxPackageQuantity, "    鏈�缁堣ˉ鐨勬暟閲忥細", finalPackagingQuantity );
+    //        PackagingPlanCell::CalculationPackagingPlanProperties();
+    //      
+    //        prePPC := prePPC.Previous();
+    //      }
+    //    }
+    //    
+    //    // 璁剧疆鎷嗗寘鏁伴噺
+    //    if ( ppc.TransferIn() > 0.0 ) { // 鏈夎皟鍏ユ暟閲�
+    //      // 鑾峰彇鍖呰lotsize
+    //      ppls                 := select( macroPlan, PackagingPlanLotSize, tempPPLS, tempPPLS.Factory() =  ppc.PackagingPlanRow().Factory()    and 
+    //                                                                                 tempPPLS.ProductID() = ppc.PackagingPlanRow().ProductID() );
+    //    
+    //      // 璁剧疆鎷嗗寘鍊�
+    //      ppc.Unpacking( ppc.TransferIn() );
+    //    }
+    //  }
+    //}
   *]
 }

--
Gitblit v1.9.3