From f7e27cb24f4cdbe6a25af74549867dbd49b1b401 Mon Sep 17 00:00:00 2001
From: xiaoding721 <33130084+xiaoding721@users.noreply.github.com>
Date: 星期四, 17 十月 2024 19:21:11 +0800
Subject: [PATCH] Merge branch 'dev' of http://47.101.211.7:10101/r/VWED into dev

---
 _Main/BL/Type_PackagingPlanCell/StaticMethod_SetPackagingAndUnpackingValues.qbl |   56 ++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 48 insertions(+), 8 deletions(-)

diff --git a/_Main/BL/Type_PackagingPlanCell/StaticMethod_SetPackagingAndUnpackingValues.qbl b/_Main/BL/Type_PackagingPlanCell/StaticMethod_SetPackagingAndUnpackingValues.qbl
index 6bbd1c1..72ed702 100644
--- a/_Main/BL/Type_PackagingPlanCell/StaticMethod_SetPackagingAndUnpackingValues.qbl
+++ b/_Main/BL/Type_PackagingPlanCell/StaticMethod_SetPackagingAndUnpackingValues.qbl
@@ -6,9 +6,12 @@
 {
   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, 3 ) ) {
+    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
@@ -22,7 +25,7 @@
                                                                           pmp.ID(),
                                                                           pmp.ParentID() ) );
         // Unit
-        u                       := select( macroPlan, Unit, tempU, tempU.ID().Regex( ppr.FactoryAbbreviation() + " " + ppr.Category() ) );
+        us                      := selectset( macroPlan, Unit, tempU, tempU.ID().Regex( ppr.FactoryAbbreviation() + " " + ppr.Category() ) );
          
         // 鍖呰搴撳瓨鍑虹幇璐熷�硷紝闇�瑕佽缃寘瑁呴噺
         if ( ppcell.PackagingInventory() < 0 and not isnull( ppls ) and not isnull( ppnc ) ) {
@@ -31,17 +34,24 @@
           // 鍖呰寮�濮嬬殑绱㈠紩
           indexPPCell           := ppcell.Previous();
           
-          info( "浜х嚎鍚嶏細", u.ID(), "    寮�濮嬫椂闂达細", ppcell.StartDate().Format( "Y-M2-D2" ), "    鍖呰搴撳瓨鏁伴噺锛�", ppcell.PackagingInventory(), "    闇�瑕佸寘瑁呯殑鏁伴噺锛�", needPackagingQuantity, 
-                "    鍖呰lotsize锛�",guard( ppls.LotSize(), 0 ), "    鏈�澶у寘瑁呭閲忥細", ppnc.MaximumDailyPackagingQuantity() );
+    //      info( "浜х嚎涓暟锛�", us.Size(), "    寮�濮嬫椂闂达細", ppcell.StartDate().Format( "Y-M2-D2" ), "    鍖呰搴撳瓨鏁伴噺锛�", ppcell.PackagingInventory(), "    闇�瑕佸寘瑁呯殑鏁伴噺锛�", needPackagingQuantity, 
+    //            "    鍖呰lotsize锛�",guard( ppls.LotSize(), 0 ), "    鏈�澶у寘瑁呭閲忥細", ppnc.MaximumDailyPackagingQuantity() );
           
-          while ( not isnull( indexPPCell ) and needPackagingQuantity > 0 ) {
+          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 );
+    //        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();
@@ -50,6 +60,36 @@
       }
     }
     
-    // 璁剧疆鍖呰鍊硷紙绗﹀悎澶х被涓嬫墍鏈変骇鍝佸寘瑁呴噺鍔犲拰涓嶈兘澶т簬鏈�澶у寘瑁呴噺锛�
+    // 璁剧疆鍖呰鍊硷紙绗﹀悎澶х被涓嬫墍鏈変骇鍝侀潪鍖呰閲忓簱瀛樺姞鍜屼笉鑳藉ぇ浜庣郴缁熷�硷級
+    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 );
+            }
+          }
+        }
+      }
+    }
   *]
 }

--
Gitblit v1.9.3