From ae3b7f21551deb0e163eb5dbd4bea0a70bd54c50 Mon Sep 17 00:00:00 2001
From: lazhen <17772815105@139.com>
Date: 星期四, 10 十月 2024 17:54:30 +0800
Subject: [PATCH] Merge branch 'dev' of http://47.101.211.7:10101/r/VWED into dev-zlg

---
 _Main/BL/Type_PackagingPlanCell/StaticMethod_GenerateReport.qbl |  141 ++++++++++++++++++++++++++++------------------
 1 files changed, 85 insertions(+), 56 deletions(-)

diff --git a/_Main/BL/Type_PackagingPlanCell/StaticMethod_GenerateReport.qbl b/_Main/BL/Type_PackagingPlanCell/StaticMethod_GenerateReport.qbl
index cfbbdbf..9eb8dff 100644
--- a/_Main/BL/Type_PackagingPlanCell/StaticMethod_GenerateReport.qbl
+++ b/_Main/BL/Type_PackagingPlanCell/StaticMethod_GenerateReport.qbl
@@ -13,21 +13,26 @@
     planPre     := macroPlan.PackagingPlanColumn( relnew, StartDate := macroPlan.StartOfPlanning().Date() - 1 );
     
     // 鐢熸垚鎶ヨ〃
-    traverse ( macroPlan, Product_MP.ProductInStockingPoint_MP, pisp, pisp.IsLeaf() and not pisp.IsSystem() ) {
+    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.StockingPointID() = pisp.StockingPointID() );
+      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 := "澶ц繛宸ュ巶", Category := "ZKG" );
+        ppr := macroPlan.PackagingPlanRow( relnew, ProductID := pisp.ProductID(), StockingPointID := pisp.StockingPointID(), Factory := factory, Category := guard( pisp.Product_MP().ParentID(), "" ) );
       }
       
-      // 鍒涘缓璁″垝鍓嶄竴澶╂牸瀛�
-      planPreCell      := ppr.PackagingPlanCell( relnew, PackagingPlanColumn := planPre, InitialPackagingInventory := 200 );
-      
       // 鍑哄彂鍦板簱瀛樼偣Trip
-      originTrips      := selectset( macroPlan, Unit.Lane.LaneLeg.Trip, tempT, tempT.LaneLeg().AsOriginStockingPointLeg().StockingPoint_MP().ID() = pisp.StockingPointID() );
+      originTrips      := selectset( macroPlan, Unit.Lane.LaneLeg.Trip, tempT, tempT.LaneLeg().AsOriginStockingPointLeg().StockingPoint_MP().ID().Regex( factoryAbbreviation )      and
+                                     TransferPlanRow::IdentifyTheFactory( tempT.LaneLeg().AsOriginStockingPointLeg().StockingPoint_MP() ) <> TransferPlanRow::IdentifyTheFactory( tempT.LaneLeg().AsDestinationStockingPointLeg().StockingPoint_MP() ) );
       // 鐩殑鍦板簱瀛樼偣Trip
-      destinationTrips := selectset( macroPlan, Unit.Lane.LaneLeg.Trip, tempT, tempT.LaneLeg().AsDestinationStockingPointLeg().StockingPoint_MP().ID() = pisp.StockingPointID() );
+      destinationTrips := selectset( macroPlan, Unit.Lane.LaneLeg.Trip, tempT, tempT.LaneLeg().AsDestinationStockingPointLeg().StockingPoint_MP().ID().Regex( factoryAbbreviation ) and
+                                     TransferPlanRow::IdentifyTheFactory( tempT.LaneLeg().AsOriginStockingPointLeg().StockingPoint_MP() ) <> TransferPlanRow::IdentifyTheFactory( tempT.LaneLeg().AsDestinationStockingPointLeg().StockingPoint_MP() ) );  
       
+      // 寰幆pispippl
       traverse ( pisp, ProductInStockingPointInPeriodPlanning.astype( ProductInStockingPointInPeriodPlanningLeaf ), pispipl, not pispipl.IsPeriodFrozen() ) {
         // 鍒涘缓鍒�
         ppc := select( macroPlan, PackagingPlanColumn, tempPPC, tempPPC.StartDate() = pispipl.Start().Date() );
@@ -38,25 +43,48 @@
         // 鍒涘缓鍗曞厓鏍�
         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() );
+        traverse ( outs, Elements.ProductInTrip, outPIT, outPIT.ProductID() = pisp.ProductID() ) {
+          cell.Out( cell.Out() + outPIT.Quantity() );
         }
         
+        // 璁剧疆璋冭繘
         transferIns := selectset( destinationTrips, Elements, tempT, tempT.Arrival().Date() = pispipl.Start().Date() );
-        traverse ( transferIns, Elements, ti ) {
-          cell.TransferIn( cell.TransferIn() + ti.Quantity() );
+        traverse ( transferIns, Elements.ProductInTrip, tiPIT, tiPIT.ProductID() = pisp.ProductID() ) {
+          cell.TransferIn( cell.TransferIn() + tiPIT.Quantity() );
+        }
+        
+        // 闀挎槬宸ュ巶鐗规畩鎯呭喌璁剧疆鍖呰搴撳瓨鍜岄潪鍖呰搴撳瓨
+        if ( factory = "闀挎槬宸ュ巶" ) {
+          if ( pisp.StockingPointID().Regex( "澶栫搴�" ) ) {
+            cell.CC_PackagingInventory( pispipl.InventoryLevelEnd() );
+          } else if ( pisp.StockingPointID().Regex( "绾胯竟搴�" ) ) {
+            cell.CC_UnpackagedInventory( pispipl.InventoryLevelEnd() );
+          }
         }
         
         // 璁剧疆鍓嶄竴澶╁簱瀛�
         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,45 +94,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() );
-            
-            // 鑾峰彇鏈�缁堝寘瑁呮暟閲�
-            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