From 0b84c9999f07bc46275f5947c4b8ebf5ce0c25cf Mon Sep 17 00:00:00 2001
From: 陈清红 <420599804@qq.com>
Date: 星期一, 14 四月 2025 15:51:58 +0800
Subject: [PATCH] BUG&优化项

---
 _Main/BL/Type_InventoryPlanArchiveVersion/StaticMethod_GenerateData.qbl |  134 ++++++++++++++++++++++++++++++++------------
 1 files changed, 98 insertions(+), 36 deletions(-)

diff --git a/_Main/BL/Type_InventoryPlanArchiveVersion/StaticMethod_GenerateData.qbl b/_Main/BL/Type_InventoryPlanArchiveVersion/StaticMethod_GenerateData.qbl
index c3446fa..510f0a4 100644
--- a/_Main/BL/Type_InventoryPlanArchiveVersion/StaticMethod_GenerateData.qbl
+++ b/_Main/BL/Type_InventoryPlanArchiveVersion/StaticMethod_GenerateData.qbl
@@ -9,63 +9,125 @@
   TextBody:
   [*
     //interfaceDataset.InventoryPlanArchiveVersion( relflush );
-    info( '-------------------------Start---------------------');
-    machineproductparent   := MachiningPipelineReport::GetDefaultProductParent();
-    engineproductparent    := EnginePipelineReport::GetDefaultProductParent();
-    allunit                := AssemblyOnlinePlanVersion::GetDefaultAllUnit();
-    name                   := InventoryPlanArchiveVersion::GetDefaultName();//search                 := 
-    interfaceDataset.InventoryPlanArchiveVersionSearch( relnew, Product := allunit, Unit := allunit, StartDate := Date::MinDate(), EndDate := Date::MaxDate() );//, TimeUnit := Translations::MP_GlobalParameters_Day()
+    info( '-------------------------Start---------------------' );
+    //machineproductparent   := MachiningPipelineReport::GetDefaultProductParent(); // 鏈哄姞浠�
+    //engineproductparent    := EnginePipelineReport::GetDefaultProductParent(); // 鍙戝姩鏈�
+    allunit                := AssemblyOnlinePlanVersion::GetDefaultAllUnit(); // <All>
+    name                   := InventoryPlanArchiveVersion::GetDefaultName(); // Inventory plan archive 
+    interfaceDataset.InventoryPlanArchiveVersionSearch( relnew, 
+                                                        Product   := allunit, 
+                                                        Unit      := allunit, 
+                                                        StartDate := Date::MinDate(), 
+                                                        EndDate   := Date::MaxDate() );//, TimeUnit := Translations::MP_GlobalParameters_Day()
+    
+    // 鍒涘缓鏄剧ず琛ㄦ牸
     table                  := selectobject( interfaceDataset, InventoryPlanArchiveVersion, version, not version.IsShow() );
     if( isnull( table ) ){
       table                := interfaceDataset.InventoryPlanArchiveVersion( relnew, ID := name, Name := name );
     }
+    
     //showtable              := selectobject( interfaceDataset, InventoryPlanArchiveVersion, version, version.IsShow() );
     //if( isnull( showtable ) ){ 
     //  showtable               := interfaceDataset.InventoryPlanArchiveVersion( relnew, ID := name, Name := name, IsShow := true );
     //}
+    
+    // 鍒涘缓涓嶅瓨鍦ㄥ垪
     periods                := selectuniquevalues(  macroPlan, Period_MP, period, not period.IsHistorical() and period.TimeUnit() = Translations::MP_GlobalParameters_Day()
                                                    and not exists( table, Column, column, column.StartDate() = period.StartDate() ), period.StartDate() );//column.TimeUnit() = Translations::MP_GlobalParameters_Day() and 
     if( periods.Size() > 0 ){
       table.GenerateColumn( periods, false );
     }
+    
+    // 鏈�灏忔椂闂�
+    minDate := minselect( table, Column, tempC, true, tempC.StartDate() ).StartDate();
+    maxDate := maxselect( table, Column, tempC, true, tempC.StartDate() ).StartDate();
+    info( "鏈�灏忔椂闂达細", minDate.Format( "Y-M2-D2" ), "    鏈�澶ф椂闂达細", maxDate.Format( "Y-M2-D2" ) );
+    
     actinventorytree       := NamedValueTree::Create();
-    inventoryqrys          := construct( Reals );
-    inventoryindex         := 0;
-    traverse( interfaceDataset,InterfaceLoginfo.MachineStockData, actinventory ){
-      inventoryqrys.Add( actinventory.Total() );
-      actinventoryKey      := actinventory.MaterialNo() + actinventory.DDay().AsQUILL();
+    // 鏈哄姞瀹為檯搴撳瓨
+    traverse ( interfaceDataset,InterfaceLoginfo.MachineStockData, actinventory, 
+    //           actinventory.Fac() = "CC" and actinventory.MaterialNo() = "06U105101A" and actinventory.DDay() = Date::Construct( 2025, 4, 9 ) and// 娴嬭瘯杩囨护锛堢敓浜ч渶瑕佹敞閲婏級
+               actinventory.DDay() >= minDate and actinventory.DDay() <= maxDate ) {
+      // 搴撲綅鏄惁缁戝畾搴撳瓨鐐�
+      iid  := select( interfaceDataset, InventoryInterfaceData, tempIID, tempIID.Date() = actinventory.DDay()             and 
+                                                                         tempIID.PartNumber() = actinventory.MaterialNo() );
+      iidd := select( iid, InventoryInterfaceDataDetail, tempIIDD, tempIIDD.InventoryPoint() = actinventory.Lgort() and
+                                                                   tempIIDD.Fac()            = actinventory.Fac() );
+      flag := guard( iidd.InventoryPointSelection().IsIncluded(), false );
+    //  info( "鏄惁琚簱瀛樼偣閫夋嫨锛�", flag,  "    鏁伴噺锛�", actinventory.Total() );
+      actinventoryKey      := ifexpr( actinventory.Fac() = "DL", FinancialProductionReport::GetDefaultDLUnit(), FinancialProductionReport::GetDefaultCCUnit() ) +
+                              actinventory.MaterialNo()                                                                                                         + 
+                              actinventory.DDay().Format( "Y-M2-D2" );
       actinventoryhandle   := actinventorytree.GetHandle( actinventoryKey );
-      actinventorytree.Root().AddChild( actinventoryhandle,inventoryindex ); 
-      inventoryindex       := inventoryindex + 1;
-    }
-    traverse( interfaceDataset,InterfaceLoginfo.FinishedEngineInventory,actinventory ){
-      product               := selectobject( macroPlan, Product_MP, product, product.Notes() = actinventory.FourCode() );
-      if( not isnull( product ) ){
-        inventoryqrys.Add( actinventory.Total() );
-        actinventoryKey     := actinventory.FourCode() + actinventory.DDay().AsQUILL();
-        actinventoryhandle  := actinventorytree.GetHandle( actinventoryKey );
-        actinventorytree.Root().AddChild( actinventoryhandle,inventoryindex ); 
-        inventoryindex      := inventoryindex + 1;
+      if ( guard( actinventorytree.Root().Child( actinventoryhandle ).GetValueAsReal() > 0, false ) ) { // 鍒ゆ柇鏄惁瀛樺湪锛屽瓨鍦�
+        if ( flag ) {
+          targetNV := actinventorytree.Root().Child( actinventoryhandle );
+          targetNV.SetValue( targetNV.GetValueAsReal() + actinventory.Total() );
+        }
+      } else { // 涓嶅瓨鍦�
+        if ( flag ) {
+          actinventorytree.Root().AddChild( actinventoryhandle, actinventory.Total() );
+        }
       }
     }
-    traverse( macroPlan, Product_MP, product, exists( product.GetAllParent(), Elements, e, e.ID() = machineproductparent or e.ID() = engineproductparent ) ){ 
+    // 鍙戝姩鏈哄疄闄呭簱瀛�
+    traverse ( interfaceDataset, InterfaceLoginfo.FinishedEngineInventory, actinventory, 
+    //           actinventory.Fac() = "CC" and actinventory.FourCode() = "6908" and actinventory.DDay() = Date::Construct( 2025, 4, 2 ) and// 娴嬭瘯杩囨护锛堢敓浜ч渶瑕佹敞閲婏級
+               actinventory.DDay() >= minDate and actinventory.DDay() <= maxDate ) {
+      // 搴撲綅鏄惁缁戝畾搴撳瓨鐐�
+      iid  := select( interfaceDataset, InventoryInterfaceData, tempIID, tempIID.Date() = actinventory.DDay()           and 
+                                                                         tempIID.PartNumber() = actinventory.FourCode() );
+      iidd := select( iid, InventoryInterfaceDataDetail, tempIIDD, tempIIDD.InventoryPoint() = actinventory.BIPlace() and
+                                                                   tempIIDD.Fac()            = actinventory.Fac() );
+      flag := guard( iidd.InventoryPointSelection().IsIncluded(), false );
+      
+      product               := selectobject( macroPlan, Product_MP, product, product.ID() = actinventory.FourCode() );
+      if ( not isnull( product ) ) {
+        actinventoryKey     := ifexpr( actinventory.Fac() = "DL", FinancialProductionReport::GetDefaultDLUnit(), FinancialProductionReport::GetDefaultCCUnit() ) +
+                               actinventory.FourCode() + 
+                               actinventory.DDay().Format( "Y-M2-D2" );
+        actinventoryhandle  := actinventorytree.GetHandle( actinventoryKey );
+        if ( guard( actinventorytree.Root().Child( actinventoryhandle ).GetValueAsReal() > 0, false ) ) { // 鍒ゆ柇鏄惁瀛樺湪锛屽瓨鍦�
+          if ( flag ) {
+            targetNV := actinventorytree.Root().Child( actinventoryhandle );
+            targetNV.SetValue( targetNV.GetValueAsReal() + actinventory.Total() );
+          }
+        } else { // 涓嶅瓨鍦�
+          if ( flag ) {
+            actinventorytree.Root().AddChild( actinventoryhandle, actinventory.Total() );
+          }
+        }
+      }
+    }
+    
+    //handle := actinventorytree.GetHandle( "VWED CC06U105101A2025-04-09" );
+    //info( "鏁伴噺锛�", guard( actinventorytree.Root().Child( handle ).GetValueAsReal(), 0 ) );
+    
+    // 淇濆瓨宸查噸缃�0鐨勪骇鍝�
+    resetNVT := NamedValueTree::Create();
+    
+    traverse ( macroPlan, Product_MP, product
+    //           ,product.ID() = "6909" 
+              ) { 
       traverse ( product, ProductInStockingPoint_MP, pispmp, not pispmp.IsSystem() and pispmp.IsLeaf() ) {
-        unit                 := ifexpr( pispmp.StockingPointID().Regex( "澶ц繛" ) or pispmp.StockingPointID().Regex( "DL" ), FinancialProductionReport::GetDefaultDLUnit(), FinancialProductionReport::GetDefaultCCUnit() );
-        inventoryrow         := table.GetRowByUnit( pispmp.Product_MP(), unit );
-        traverse ( pispmp, ProductInStockingPointInPeriodPlanning.astype( ProductInStockingPointInPeriodPlanningLeaf ), pispippl, not pispippl.IsPeriodFrozen() ) {
+        unit                 := ifexpr( pispmp.StockingPointID().Regex( "澶ц繛" ) or pispmp.StockingPointID().Regex( "DL" ), 
+                                        FinancialProductionReport::GetDefaultDLUnit(), 
+                                        FinancialProductionReport::GetDefaultCCUnit() ); // 宸ュ巶
+        inventoryrow         := table.GetRowByUnit( pispmp.Product_MP(), unit ); // 鍒涘缓搴撳瓨瀛樻。琛�
+    //    info( pispmp.Name() );
+        
+        traverse ( pispmp, ProductInStockingPointInPeriodPlanning.astype( ProductInStockingPointInPeriodPlanningLeaf ), pispippl, 
+    //               pispmp.ProductID() = "6909" and pispippl.Start().Date() = Date::Construct( 2025, 3, 31 ) and // 娴嬭瘯杩囨护锛堢敓浜ч渶瑕佹敞閲婏級
+                   not pispippl.IsPeriodFrozen() ) {
           startdate          := pispippl.Start().Date();
-          daycolumn          := table.GetColumnByTimeUnit( Translations::MP_GlobalParameters_Day(), startdate );
+          daycolumn          := table.GetColumnByTimeUnit( Translations::MP_GlobalParameters_Day(), startdate ); // 鑾峰彇搴撳瓨瀛樻。鍒�
     //      weekcolumn         := table.GetColumnByTimeUnit( Translations::MP_GlobalParameters_Week(), startdate );
     //      monthcolumn        := table.GetColumnByTimeUnit( Translations::MP_GlobalParameters_Month(), startdate );
-          actinventoryKey    := pispmp.ProductID() + startdate.AsQUILL();
+          actinventoryKey    := unit + pispmp.ProductID() + startdate.Format( "Y-M2-D2" );
           actinventoryhandle := actinventorytree.GetHandle( actinventoryKey );
-          actinventoryindex  := guard( actinventorytree.Root().Child( actinventoryhandle ),null( NamedValue ));
-          
-          actinventoryqty    := 0.0;
-          if( not isnull( actinventoryindex )){
-            actinventoryqty  := inventoryqrys.Element( actinventoryindex.GetValueAsNumber() );
-          }
-          inventoryrow.SetQuantity( daycolumn, pispippl.InventoryLevelEnd(), actinventoryqty );
+          actinventoryQty    := guard( actinventorytree.Root().Child( actinventoryhandle ).GetValueAsReal(), 0 );
+    //      info( "鏁伴噺锛�", actinventoryQty );
+          inventoryrow.SetQuantity( daycolumn, pispippl.InventoryLevelEnd(), actinventoryQty, resetNVT );
     //      inventoryrow.SetQuantity( weekcolumn, pispippl.InventoryLevelEnd(), actinventoryqty );
     //      inventoryrow.SetQuantity( monthcolumn, pispippl.InventoryLevelEnd(), actinventoryqty );
       
@@ -73,7 +135,7 @@
       }
     }
     
-    info( '-------------------------End---------------------');
+    info( '-------------------------End---------------------' );
     //productids             := selectuniquevalues( table, Row, row, row.Name() );
     //productlines           := selectuniquevalues( table, Row, row, row.Unit() );
     //showtable.Generate( search, productids, productlines );

--
Gitblit v1.9.3