From f1de76007e7834e17d87712e3342efd84876c200 Mon Sep 17 00:00:00 2001
From: lihongji <3117313295@qq.com>
Date: 星期六, 12 十月 2024 16:32:16 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev' into dev

---
 _Main/BL/Type_CCEngineLogisticsCostReport0/StaticMethod_InitializeNew.qbl |  400 ++++++++++++++++++++++++++++++++------------------------
 1 files changed, 226 insertions(+), 174 deletions(-)

diff --git a/_Main/BL/Type_CCEngineLogisticsCostReport0/StaticMethod_InitializeNew.qbl b/_Main/BL/Type_CCEngineLogisticsCostReport0/StaticMethod_InitializeNew.qbl
index aa66e0d..cff8bf9 100644
--- a/_Main/BL/Type_CCEngineLogisticsCostReport0/StaticMethod_InitializeNew.qbl
+++ b/_Main/BL/Type_CCEngineLogisticsCostReport0/StaticMethod_InitializeNew.qbl
@@ -36,53 +36,60 @@
     //  unit                    := stockingpoint.Unit();
     //  parentunits             := unit.GetAllParent();
       //鏄惁灞炰簬闀挎槬澶栫搴撶敤浜庨暱鏄ュ绉熷簱浠撳偍璐圭敤
-      isccrent                := stockingpoint.ID().StartsWith( '闀挎槬' ) or stockingpoint.ID().StartsWith( 'CC' );
+    //  isccrent                := stockingpoint.ID().StartsWith( '闀挎槬' ) or stockingpoint.ID().StartsWith( 'CC' );
       //鏄惁灞炰簬澶ц繛鍙戝姩鏈虹殑闀挎槬澶栫搴撶敤浜庨暱鏄ュ叆搴�/鍑哄簱璐圭敤
       isdltoccrent            := stockingpoint.ID().StartsWith( '澶ц繛鍙戝姩鏈虹殑闀挎槬' );
       //鏄惁灞炰簬澶ц繛澶栫搴撶敤浜庡ぇ杩炲绉熷簱浠撳偍璐圭敤
-      isdlrent                := stockingpoint.ID().StartsWith( '澶ц繛' ) or stockingpoint.ID().StartsWith( 'DL' );
-      if( isccrent or isdlrent ){
-        traverse( stockingpoint, ProductInStockingPoint_MP, pisp,  pisp.Product_MP().IsLeaf() 
-                  and exists( pisp, ProductInStockingPointInPeriod, pispip, not pispip.Period_MP().IsHistorical() and pispip.Period_MP().StartDate() < startofnextyear and pispip.NewSupplyQuantity() <> 0 ) ){
+      isdlrent                := not isdltoccrent and stockingpoint.ID().StartsWith( '澶ц繛' ) or stockingpoint.ID().StartsWith( 'DL' );
+    //  info( '--------------', isccrent, isdltoccrent, isdlrent );
+      if( isdlrent or isdltoccrent){
+        traverse( stockingpoint, ProductInStockingPoint_MP, pisp,  pisp.Product_MP().IsLeaf()
+                  and exists( pisp, ProductInStockingPointInPeriod, pispip, not pispip.Period_MP().IsHistorical() and pispip.Period_MP().StartDate() < startofnextyear and ( pispip.NewSupplyQuantity() <> 0 or pispip.PlannedInventoryLevelEnd() <> 0 ) ) ){
           //鑾峰彇琛�
           product             := pisp.Product_MP();
           productparents      := product.GetAllParent();
           if( exists( productparents, Elements, e, e.ID() = produtparent ) ){//鏌ヨ浜у搧绫诲瀷鏄彂鍔ㄦ満
             row               := table.GetRow( pisp.ProductID() );
             enginecosts       := selectset( owner, LogisticsCostEngine, engine, engine.PackagingCapacity() <> 0 and engine.Generation().ToLower() = product.Generation().ToLower() and engine.MLB_MQB() = product.MQBMLB() );
+            transcosts        := selectset( owner, LogisticsCostTransport, trans, trans.LoadingCapacity() <> 0 and trans.Origin() = '澶ц繛鍘傚唴搴�'
+                                                  and trans.Destination() = '澶ц繛澶栫搴�'
+                                                  and exists( productparents, Elements, e, ifexpr( trans.Product().FindString( '鍙戝姩鏈�', 0 ) >= 0, e.ID() = produtparent,  e.ID() = trans.Product() ) ) );
             if( not isnull( enginecosts ) and enginecosts.Size() > 0 ){
               products.Add( pisp.Product_MP() );
-              traverse( pisp, ProductInStockingPointInPeriod, pispip, not pispip.Period_MP().IsHistorical() and pispip.Period_MP().StartDate() < startofnextyear and pispip.NewSupplyQuantity() <> 0  ){
+              traverse( pisp, ProductInStockingPointInPeriod, pispip, not pispip.Period_MP().IsHistorical() and pispip.Period_MP().StartDate() < startofnextyear 
+                        and ( pispip.NewSupplyQuantity() <> 0 or pispip.PlannedInventoryLevelEnd() <> 0 ) ){
                 periodtime    := pispip.Start().StartOfMonth().Date();
                 periodname    := periodtime.Format( "M2/D2/Y" );
                 column        := selectobject( table, Column, column, column.Name() = periodname and column.StartDate() = periodtime );
                 cell          := selectobject( row, Cell, cell, cell.Column() = column );
                 
-                if( isccrent or isdltoccrent){
+                if( isdltoccrent){
                   //鍦ㄥ彂鍔ㄦ満鎴愭湰鍙傛暟琛ㄦ壘鍒板搴旂殑鍖呰瀹归噺
                   enginecost  := selectobject( enginecosts, Elements, engine, engine.StartDate() <= pispip.Start().Date() and engine.EndDate() >= pispip.Start().Date()
                                                      and engine.Factory() = ccfactory );
-                   if( not isnull( enginecost ) ){
-                     if( isccrent ){
-                       cost        := ceil( pispip.PlannedInventoryLevelEnd() / enginecost.PackagingCapacity() ) * enginecost.StoragePrice();//鍥涜垗浜斿叆
-                       cell.CCRentStorCost( cell.CCRentStorCost() + cost );//闀挎槬澶栫搴撲粨鍌ㄨ垂鐢�
-                     }else{
-                       cell.CCRentQty( cell.CCRentQty() + pispip.NewSupplyQuantity() );
+                   cell.CCRentQty( cell.CCRentQty() + pispip.NewSupplyQuantity() );
                        //闀挎槬澶栫搴撳叆搴撹垂鐢細鍏ュ簱閲�/鍖呰瀹归噺*鍏ュ簱鍗曚环 
                        entercost  := ceil( pispip.NewSupplyQuantity() / enginecost.PackagingCapacity() ) * enginecost.WarehousingPrice();
                        //闀挎槬澶栫搴撳嚭搴撹垂鐢�: 鍑哄簱閲�/鍖呰瀹归噺*鍑哄簱鍗曚环
                        outcost    := ceil( pispip.NewSupplyQuantity() / enginecost.PackagingCapacity() ) * enginecost.OutboundPrice();
                        cell.CCRentInCost( cell.CCRentInCost() + entercost );
                        cell.CCRentOutOfCost( cell.CCRentOutOfCost() + outcost );
-                     }
-                   }
+                       cost        := ceil( pispip.PlannedInventoryLevelEnd() / enginecost.PackagingCapacity() ) * enginecost.StoragePrice();//鍥涜垗浜斿叆
+                       cell.CCRentStorCost( cell.CCRentStorCost() + cost );//闀挎槬澶栫搴撲粨鍌ㄨ垂鐢�
                 } else {
                   //鍦ㄥ彂鍔ㄦ満鎴愭湰鍙傛暟琛ㄦ壘鍒板搴旂殑鍖呰瀹归噺
                   enginecost     := selectobject( enginecosts, Elements, engine, engine.StartDate() <= pispip.Start().Date() and engine.EndDate() >= pispip.Start().Date()
                                                      and engine.Factory() = dlfactory  );
                    if( not isnull( enginecost ) ){
-                     cost        := ceil( [Number]pispip.PlannedInventoryLevelEnd() / enginecost.PackagingCapacity() ) * enginecost.StoragePrice();//鍥涜垗浜斿叆
+                     cost        := ceil( pispip.PlannedInventoryLevelEnd() / enginecost.PackagingCapacity() ) * enginecost.StoragePrice();//鍥涜垗浜斿叆
                      cell.DLRentStorCost( cell.DLRentStorCost() + cost );//澶ц繛澶栫搴撲粨鍌ㄨ垂鐢�
+    //                 info( '**********************', pispip.NewSupplyQuantity() );
+                     row.SetDLRentEnterCost( column, enginecost, pispip.NewSupplyQuantity() );//澶ц繛澶栫搴撳叆搴撹垂鐢�
+                     transcost        := selectobject( transcosts, Elements, trans, trans.StartDate() <= pispip.Start().Date() and trans.EndDate() >= pispip.Start().Date() );
+                     if( not isnull( transcost ) ){
+                       cost := ceil( ceil( pispip.NewSupplyQuantity() / enginecost.PackagingCapacity() ) / transcost.LoadingCapacity() ) * transcost.TransportPrice();//鍥涜垗浜斿叆
+                       row.SetFactoryToRentTransCost( column, cost );
+                     }
                    }
                 }
               }   
@@ -92,177 +99,222 @@
       }
     }
     //鍦� trip plan閲屾壘鍒板ぇ杩炶閰嶇嚎杈瑰簱鍒板ぇ杩炲绉熷簱鐨勮繍杈撴暟閲�//澶ц繛鍘傚唴搴撳埌澶栫搴�
-    traverse( owner, Unit.Lane.LaneLeg, laneleg ){
-      //璧峰搴撳瓨鐐规槸鍚︽槸澶ц繛瑁呴厤绾胯竟搴�
-      isdlspline             := laneleg.OriginStockingPointID().EndsWith( '鍘傚唴搴�' ) and ( laneleg.OriginStockingPointID().StartsWith( '澶ц繛' ) or laneleg.OriginStockingPointID().StartsWith( 'DL' ) );
-      //鐩殑鍦版槸鍚︽槸澶ц繛澶栫搴�
-      isdlrent               := laneleg.DestinationStockingPointID().EndsWith( '澶栫搴�' ) and ( laneleg.DestinationStockingPointID().StartsWith( '澶ц繛' ) or laneleg.DestinationStockingPointID().StartsWith( 'DL' ) );
-      if( isdlspline and isdlrent ){
-        traverse( laneleg, Trip, trip, trip.Departure().Date() < startofnextyear ){//鐢变簬闇�瑕佽�冭檻浜у搧杩愯緭lead time锛屾瘡涓湀鐨勬眹鎬绘暟鎹渶瑕佹帹杩熶袱澶╄繘琛岃绠�
-          periodtime         := trip.Departure().StartOfMonth().Date();
-          periodname         := periodtime.Format( "M2/D2/Y" );
-          
-          column             := selectobject( table, Column, column, column.Name() = periodname and column.StartDate() = periodtime );
-          enginecosts        := selectset( owner, LogisticsCostEngine, engine, engine.PackagingCapacity() <> 0 and engine.StartDate() <= trip.Departure().Date() and engine.EndDate() >= trip.Departure().Date() );
-          transcosts         := selectset( owner, LogisticsCostTransport, trans, trans.LoadingCapacity() <> 0 and trans.StartDate() <= trip.Departure().Date() and trans.EndDate() >= trip.Departure().Date() );
-          if( not isnull( enginecosts ) and enginecosts.Size() > 0 and not isnull( transcosts ) and transcosts.Size() > 0 ){
-            traverse( trip, ProductInTrip, pit, pit.Quantity() <> 0 and not isnull( column ) and exists( pit.Product_MP().GetAllParent(), Elements, e, e.ID() = produtparent ) ){//鏌ヨ浜у搧绫诲瀷鏄彂鍔ㄦ満
-              quantity       := [Number]pit.Quantity();
-              row            := table.GetRow( pit.ProductID() );
-              product        := pit.Product_MP();
-              productparents := product.GetAllParent();
-              
-              //鍦ㄥ彂鍔ㄦ満鎴愭湰鍙傛暟琛ㄦ壘鍒板搴旂殑鍖呰瀹归噺
-              enginecost     := selectobject( enginecosts, Elements, engine, engine.Generation().ToLower() = product.Generation().ToLower() 
-                                                   and engine.MLB_MQB() = product.MQBMLB()
-                                                   and engine.Factory() = dlfactory  );
-              //鍦ㄨ繍杈撴垚鏈弬鏁拌〃閲屾壘鍒板彂鍔ㄦ満瀵瑰簲杩愯緭鍗曚环鍜岃杞藉閲�
-              transcost      := selectobject( transcosts, Elements, trans, trans.Origin() = laneleg.OriginStockingPointID() 
-                                                  and trans.Destination() = laneleg.DestinationStockingPointID() 
-                                                  and exists( productparents, Elements, e, ifexpr( trans.Product().FindString( '鍙戝姩鏈�', 0 ) >= 0, e.ID() = produtparent,  e.ID() = trans.Product() ) ) );
-              if( not isnull( enginecost ) and not isnull( transcost ) ){
-                products.Add( product );
-                cell         := selectobject( row, Cell, cell, cell.Column() = column );
-                //杩愯緭鏁伴噺/鍖呰瀹归噺/瑁呰浇瀹归噺*杩愯緭鍗曚环
-                cost         := ceil( ceil( quantity / enginecost.PackagingCapacity() ) / transcost.LoadingCapacity() ) * transcost.TransportPrice();//鍥涜垗浜斿叆
-                cell.WerkToDLRentTransCost( cell.WerkToDLRentTransCost() + cost );
-              }
-            }
-          }
-        }
-      }
-    }
-    //澶ц繛澶栫搴撳叆搴撹垂鐢細鍏ュ簱閲�/鍖呰瀹归噺*鍏ュ簱鍗曚环锛屽叆搴撻噺绛変簬澶ц繛宸ュ巶璇ヤ骇鍝佷骇閲忓噺鍘诲彂寰�闀挎槬(澶ц繛鐨勯暱鏄ュ绉熷簱锛夌殑鏁伴噺-newSupply
-    traverse( owner, FinancialProductionSource, source, not source.IsImport() ){//璐㈠姟浜ч噺鎶ヨ〃闈炲鍏�
-      traverse( source, FinancialProductionReport, report, not report.IsShow() ){//璐㈠姟浜ч噺鎶ヨ〃涓嶆樉绀�
-        traverse( report, FinancialProductionRow, row, row.Unit() = dlunit and exists( row, FinancialProductionCell, cell, cell.Value() <> '0' and not cell.FinancialProductionColumn().IsDay() ) ){//璐㈠姟浜ч噺鎶ヨ〃閲岀殑澶ц繛浜ч噺, 涓嶄负0
-          product            := row.Product_MP();
-          productparents     := product.GetAllParent();
-          if( exists( productparents, Elements, e, e.ID() = produtparent ) ){//鏌ヨ浜у搧绫诲瀷鏄彂鍔ㄦ満
-            //鏌ヨ瀵瑰簲鐨勫彂鍔ㄦ満鎴愭湰
-            enginecosts      := selectset( owner, LogisticsCostEngine, engine, engine.PackagingCapacity() <> 0 and engine.Generation().ToLower() = product.Generation().ToLower() 
-                                                 and engine.MLB_MQB() = product.MQBMLB()
-                                                 and engine.Factory() = dlfactory );
-            if( not isnull( enginecosts ) and enginecosts.Size() > 0 ){
-              products.Add( product );
-              ccrow          := table.GetRow( row.Name() );
-              traverse( row, FinancialProductionCell, cell, cell.Value() <> '0' and not cell.FinancialProductionColumn().IsDay() ){
-                cellcolumn   := cell.FinancialProductionColumn();
-                enginecost   := selectobject( enginecosts, Elements, engine, engine.StartDate() <= cellcolumn.Period() and engine.EndDate() >= cellcolumn.Period() );
-                if( not isnull( enginecost ) ){
-                  column     := selectobject( table, Column, column, column.Name() = cell.FinancialProductionColumn().Name() );
-                  //澶ц繛澶栫搴撳叆搴撹垂鐢�
-                  ccrow.SetDLRentEnterCost( column, enginecost, cell );
-                }
-              }
-            }
-          }
-        }
-      }
-    }
-    //澶ц繛澶栫搴撳嚭搴撹垂鐢細鍑哄簱閲�/鍖呰瀹归噺*鍑哄簱鍗曚环锛屽嚭搴撻噺绛変簬澶ц繛宸ュ巶璇ヤ骇鍝侀攢閲忓噺鍘诲彂寰�闀挎槬鐨勬暟閲�-newSupply, 澶ц繛鍘傚唴搴擄紝澶ц繛澶栫搴�
-    traverse( owner, FinancialSalesSource, source, not source.IsImport() ){//璐㈠姟閿�閲忔姤琛ㄩ潪瀵煎叆
-      traverse( source, FinancialSalesReport, report, not report.IsShow() ){//璐㈠姟閿�閲忔姤琛ㄤ笉鏄剧ず
-        traverse( report, FinancialSalesRow, row, row.Unit() = ccunit and exists( row, FinancialSalesCell, cell, cell.Value() <> '0' and not cell.FinancialSalesColumn().IsDay() ) ){//璐㈠姟閿�閲忔姤琛ㄩ噷鐨勫ぇ杩炰骇閲�, 涓嶄负0
-          product            := row.Product_MP();
-          productparents     := product.GetAllParent();
-          if( exists( productparents, Elements, e, e.ID() = produtparent ) ){//鏌ヨ浜у搧绫诲瀷鏄彂鍔ㄦ満
-            //鏌ヨ瀵瑰簲鐨勫彂鍔ㄦ満鎴愭湰
-            enginecosts      := selectset( owner, LogisticsCostEngine, engine, engine.PackagingCapacity() <> 0 and engine.Generation().ToLower() = product.Generation().ToLower() 
-                                                 and engine.MLB_MQB() = product.MQBMLB()
-                                                 and engine.Factory() = dlfactory );
-            if( not isnull( enginecosts ) and enginecosts.Size() > 0 ){
-              products.Add( product );
-              ccrow          := table.GetRow( row.Name() );
-              traverse( row, FinancialSalesCell, cell, cell.Value() <> '0' and not cell.FinancialSalesColumn().IsDay() ){
-                cellcolumn   := cell.FinancialSalesColumn();
-                enginecost   := selectobject( enginecosts, Elements, engine, engine.StartDate() <= cellcolumn.Period() and engine.EndDate() >= cellcolumn.Period() );
-                if(  not isnull( enginecost ) ){
-                  column     := selectobject( table, Column, column, column.Name() = cell.FinancialSalesColumn().Name() );
-                  //澶ц繛澶栫搴撳嚭搴撹垂鐢�
-                  ccrow.SetDLRentOutCost( column, enginecost, cell );
-                }
-              }
-            }
-          }
-        }
-      }
-    }
+    //traverse( owner, Unit.Lane.LaneLeg, laneleg ){
+    //  isdlspline             := laneleg.OriginStockingPointID().EndsWith( '鍘傚唴搴�' ) and ( laneleg.OriginStockingPointID().StartsWith( '澶ц繛' ) or laneleg.OriginStockingPointID().StartsWith( 'DL' ) );
+    //  //鐩殑鍦版槸鍚︽槸澶ц繛澶栫搴�
+    //  isdlrent               := laneleg.DestinationStockingPointID().EndsWith( '澶ц繛澶栫搴�' );
+    //  if( isdlspline and isdlrent ){
+    //    traverse( table, Column, column ){
+    //      alltrips          := selectset( laneleg, Trip, trip, trip.Arrival().Date() < column.StartDate().StartOfNextMonth() and trip.Arrival().Date() >= column.StartDate() );
+    ////      info( '--------------------', alltrips.Size(), column.StartDate() );
+    //      enginecosts        := selectset( owner, LogisticsCostEngine, engine, engine.PackagingCapacity() <> 0 and engine.StartDate() <= column.StartDate() and engine.EndDate() >= column.StartDate() );
+    //      transcosts         := selectset( owner, LogisticsCostTransport, trans, trans.LoadingCapacity() <> 0 and trans.StartDate() <= column.StartDate() and trans.EndDate() >= column.StartDate() );
+    //      if( not isnull( enginecosts ) and enginecosts.Size() > 0 and not isnull( transcosts ) and transcosts.Size() > 0 ){
+    //        producttrips      := selectuniquevalues( alltrips, Elements.ProductInTrip, pit, pit.Quantity() <> 0 and exists( pit.Product_MP().GetAllParent(), Elements, e, e.ID() = produtparent ), pit.ProductID() );
+    ////        info( '--------------2---------------', producttrips.Size() );
+    //        traverse( producttrips, Elements, producttrip ){
+    //    
+    //          row          := table.GetRow( producttrip );
+    //          product         := selectobject( owner, Product_MP, product, product.ID() = producttrip );
+    //          products.Add( product );
+    //          quantity       := sum( alltrips, Elements.ProductInTrip, pit, pit.Product_MP() = product, pit.Quantity() );
+    //          enginecost     := selectobject( enginecosts, Elements, engine, engine.Generation().ToLower() = product.Generation().ToLower()
+    //                                               and engine.MLB_MQB() = product.MQBMLB()
+    //                                               and engine.Factory() = ccfactory );
+    //            //鍦ㄨ繍杈撴垚鏈弬鏁拌〃閲屾壘鍒板彂鍔ㄦ満瀵瑰簲杩愯緭鍗曚环鍜岃杞藉閲�
+    //            transcost      := selectobject( transcosts, Elements, trans, trans.Origin() = laneleg.OriginStockingPointID() 
+    //                                              and trans.Destination() = laneleg.DestinationStockingPointID() 
+    //                                              and exists( product.GetAllParent(), Elements, e, ifexpr( trans.Product().FindString( '鍙戝姩鏈�', 0 ) >= 0, e.ID() = produtparent,  e.ID() = trans.Product() ) ) );
+    ////            info( '-------------------', not isnull( enginecost ) and not isnull( transcost ), isnull( transcost ), product.ID() );
+    //            if( not isnull( enginecost ) and not isnull( transcost ) ){
+    ////              info( '-------------------', product.ID(), transcost.LoadingCapacity() );
+    //              cost := ceil( ceil( quantity / enginecost.PackagingCapacity() ) / transcost.LoadingCapacity() ) * transcost.TransportPrice();//鍥涜垗浜斿叆
+    //              info( quantity, ceil( quantity / enginecost.PackagingCapacity() ), ceil( ceil( quantity / enginecost.PackagingCapacity() ) / transcost.LoadingCapacity() ) );
+    //              row.SetFactoryToRentTransCost( column, cost );
+    //            }
+    //        }
+    //      }
+    //    }
+    //traverse( owner, Unit.Lane.LaneLeg, laneleg ){
+    //  //璧峰搴撳瓨鐐规槸鍚︽槸澶ц繛瑁呴厤绾胯竟搴�
+    //  isdlspline             := laneleg.OriginStockingPointID().EndsWith( '鍘傚唴搴�' ) and ( laneleg.OriginStockingPointID().StartsWith( '澶ц繛' ) or laneleg.OriginStockingPointID().StartsWith( 'DL' ) );
+    //  //鐩殑鍦版槸鍚︽槸澶ц繛澶栫搴�
+    //  isdlrent               := laneleg.DestinationStockingPointID().EndsWith( '澶栫搴�' ) and ( laneleg.DestinationStockingPointID().StartsWith( '澶ц繛' ) or laneleg.DestinationStockingPointID().StartsWith( 'DL' ) );
+    //  if( isdlspline and isdlrent ){
+    //    traverse( laneleg, Trip, trip, trip.Departure().Date() < startofnextyear ){//鐢变簬闇�瑕佽�冭檻浜у搧杩愯緭lead time锛屾瘡涓湀鐨勬眹鎬绘暟鎹渶瑕佹帹杩熶袱澶╄繘琛岃绠�
+    //      periodtime         := trip.Departure().StartOfMonth().Date();
+    //      periodname         := periodtime.Format( "M2/D2/Y" );
+    //      
+    //      column             := selectobject( table, Column, column, column.Name() = periodname and column.StartDate() = periodtime );
+    //      enginecosts        := selectset( owner, LogisticsCostEngine, engine, engine.PackagingCapacity() <> 0 and engine.StartDate() <= trip.Departure().Date() and engine.EndDate() >= trip.Departure().Date() );
+    //      transcosts         := selectset( owner, LogisticsCostTransport, trans, trans.LoadingCapacity() <> 0 and trans.StartDate() <= trip.Departure().Date() and trans.EndDate() >= trip.Departure().Date() );
+    //      if( not isnull( enginecosts ) and enginecosts.Size() > 0 and not isnull( transcosts ) and transcosts.Size() > 0 ){
+    //        traverse( trip, ProductInTrip, pit, pit.Quantity() <> 0 and not isnull( column ) and exists( pit.Product_MP().GetAllParent(), Elements, e, e.ID() = produtparent ) ){//鏌ヨ浜у搧绫诲瀷鏄彂鍔ㄦ満
+    //          quantity       := [Number]pit.Quantity();
+    //          row            := table.GetRow( pit.ProductID() );
+    //          product        := pit.Product_MP();
+    //          productparents := product.GetAllParent();
+    //          
+    //          //鍦ㄥ彂鍔ㄦ満鎴愭湰鍙傛暟琛ㄦ壘鍒板搴旂殑鍖呰瀹归噺
+    //          enginecost     := selectobject( enginecosts, Elements, engine, engine.Generation().ToLower() = product.Generation().ToLower() 
+    //                                               and engine.MLB_MQB() = product.MQBMLB()
+    //                                               and engine.Factory() = dlfactory  );
+    //          //鍦ㄨ繍杈撴垚鏈弬鏁拌〃閲屾壘鍒板彂鍔ㄦ満瀵瑰簲杩愯緭鍗曚环鍜岃杞藉閲�
+    //          transcost      := selectobject( transcosts, Elements, trans, trans.Origin() = laneleg.OriginStockingPointID() 
+    //                                              and trans.Destination() = laneleg.DestinationStockingPointID() 
+    //                                              and exists( productparents, Elements, e, ifexpr( trans.Product().FindString( '鍙戝姩鏈�', 0 ) >= 0, e.ID() = produtparent,  e.ID() = trans.Product() ) ) );
+    //          if( not isnull( enginecost ) and not isnull( transcost ) ){
+    //            products.Add( product );
+    //            cell         := selectobject( row, Cell, cell, cell.Column() = column );
+    //            //杩愯緭鏁伴噺/鍖呰瀹归噺/瑁呰浇瀹归噺*杩愯緭鍗曚环
+    //            cost         := ceil( ceil( quantity / enginecost.PackagingCapacity() ) / transcost.LoadingCapacity() ) * transcost.TransportPrice();//鍥涜垗浜斿叆
+    //            cell.WerkToDLRentTransCost( cell.WerkToDLRentTransCost() + cost );
+    //          }
+    //        }
+    //      }
+    //    }
+    //  }
+    //}
+    
     //闀挎槬闀块�旇繍杈撹垂鐢細璋冩嫧鏁伴噺/鍖呰瀹归噺/瑁呰浇瀹归噺*杩愯緭鍗曚环锛岃皟鎷ㄨ鍒掗噷鎵惧埌璇ヤ骇鍝佷粠DL鍒癈C鐨勮皟鎷ㄦ暟閲忥紝鍗宠捣濮嬪湴澶ц繛瑁呴厤绾胯竟搴擄紝鐩殑鍦颁负闀挎槬澶栫搴撳搴旂殑杩愯緭鏁伴噺锛屽湪鍙戝姩鏈烘垚鏈弬鏁拌〃鎵惧埌瀵瑰簲鐨勫寘瑁呭閲忥紝鍦ㄨ繍杈撴垚鏈弬鏁拌〃閲屾壘鍒板彂鍔ㄦ満瀵瑰簲杩愯緭鍗曚环鍜岃杞藉閲忥紝鐢ㄥ叕寮忚绠楀緱鍑虹粨鏋滐紝鏈堝害杩涜姹囨��
-    traverse( owner, TransferPlanRow, tprow ){
-      product                 := selectobject( owner, Product_MP, product, product.ID() = tprow.ProductID() );
-      productparents          := product.GetAllParent();
-      if( exists( productparents, Elements, e, e.ID() = produtparent ) ){//鏌ヨ浜у搧绫诲瀷鏄彂鍔ㄦ満
-        //璧峰搴撳瓨鐐规槸鍚︽槸澶ц繛(澶ц繛鍘傚唴搴擄級
-        isdl                   := tprow.SourceStockpoingPointID().EndsWith( '鍘傚唴搴�' ) and ( tprow.TargetStockpoingPointID().StartsWith( '澶ц繛' ) or tprow.TargetStockpoingPointID().StartsWith( 'DL' ) );
-        //鐩殑鍦板簱瀛樼偣鏄惁鏄暱鏄ワ紙闀挎槬澶栫搴擄級
-        iscc                   := tprow.TargetStockpoingPointID().EndsWith( '澶栫搴�' ) and ( tprow.TargetStockpoingPointID().StartsWith( '闀挎槬' ) or tprow.TargetStockpoingPointID().StartsWith( 'CC' ) );
+    traverse( owner, Unit.Lane.LaneLeg, laneleg ){
+    //  isdlspline             := laneleg.OriginStockingPointID().EndsWith( '鍘傚唴搴�' ) and ( laneleg.OriginStockingPointID().StartsWith( '澶ц繛' ) or laneleg.OriginStockingPointID().StartsWith( 'DL' ) );
+    //  //鐩殑鍦版槸鍚︽槸澶ц繛澶栫搴�
+    //  isdlrent               := laneleg.DestinationStockingPointID().EndsWith( '澶ц繛澶栫搴�' );
+      //璧峰搴撳瓨鐐规槸鍚︽槸澶ц繛(澶ц繛鍘傚唴搴擄級
+      isdl                   := laneleg.OriginStockingPointID().EndsWith( '鍘傚唴搴�' ) and ( laneleg.OriginStockingPointID().StartsWith( '澶ц繛' ) or laneleg.OriginStockingPointID().StartsWith( 'DL' ) );
+      //鐩殑鍦板簱瀛樼偣鏄惁鏄暱鏄ワ紙闀挎槬澶栫搴擄級
+      iscc                   := laneleg.DestinationStockingPointID() = '澶ц繛鍙戝姩鏈虹殑闀挎槬澶栫搴�';
         if( isdl and iscc ){
-          //鏌ヨ瀵瑰簲鐨勫彂鍔ㄦ満鎴愭湰
-          enginecosts          := selectset( owner, LogisticsCostEngine, engine, engine.PackagingCapacity() <> 0 and engine.Generation().ToLower() = product.Generation().ToLower() 
-                                                 and engine.MLB_MQB() = product.MQBMLB()
-                                                 and engine.Factory() = ccfactory );
-          //鍦ㄨ繍杈撴垚鏈弬鏁拌〃閲屾壘鍒板彂鍔ㄦ満瀵瑰簲杩愯緭鍗曚环鍜岃杞藉閲�
-          transcosts           := selectset( owner, LogisticsCostTransport, trans, trans.LoadingCapacity() <> 0 and trans.Origin() = tprow.SourceStockpoingPointID() 
-                                                  and trans.Destination() = tprow.TargetStockpoingPointID() 
-                                                  and exists( productparents, Elements, e, ifexpr( trans.Product().FindString( '鍙戝姩鏈�', 0 ) >= 0, e.ID() = produtparent,  e.ID() = trans.Product() ) ) );
+    //  if( isdlspline and isdlrent ){
+        traverse( table, Column, column){//, column.StartDate().Month() = 1 
+          alltrips          := selectset( laneleg, Trip, trip, trip.Arrival().Date() < column.StartDate().StartOfNextMonth() and trip.Arrival().Date() >= column.StartDate() );
+    //      info( '--------------------', alltrips.Size(), column.StartDate() );
+          enginecosts        := selectset( owner, LogisticsCostEngine, engine, engine.PackagingCapacity() <> 0 and engine.StartDate() <= column.StartDate() and engine.EndDate() >= column.StartDate() );
+          transcosts         := selectset( owner, LogisticsCostTransport, trans, trans.LoadingCapacity() <> 0 and trans.StartDate() <= column.StartDate() and trans.EndDate() >= column.StartDate() );
           if( not isnull( enginecosts ) and enginecosts.Size() > 0 and not isnull( transcosts ) and transcosts.Size() > 0 ){
-            row                := table.GetRow( product.ID() );
-            products.Add( product );
-            traverse( tprow,TransferPlanCell, tpcell, tpcell.TransferPlanColumn().ColumnDate() <> Date::MinDate() and [Number]tpcell.Value() > 0){
-              tpcolumndate     := tpcell.TransferPlanColumn().ColumnDate();
-              enginecost       := selectobject( enginecosts, Elements, engine, engine.StartDate() <= tpcolumndate and engine.EndDate() >= tpcolumndate );
-              transcost        := selectobject( transcosts, Elements, trans, trans.StartDate() <= tpcolumndate and trans.EndDate() >= tpcolumndate );
-              if( not isnull( enginecost ) and not isnull( transcost ) ){
-                periodtime     := tpcolumndate.StartOfMonth();
-                periodname     := periodtime.Format( "M2/D2/Y" );
-                column         := selectobject( table, Column, column, column.Name() = periodname and column.StartDate() = periodtime );
-                 
-                cost           := ceil( ceil( [Number]tpcell.Value() / enginecost.PackagingCapacity() ) / transcost.LoadingCapacity() ) * transcost.TransportPrice();
-                cell           := selectobject( row, Cell, cell, cell.Column() = column );
-                cell.CCLongTransCost( cell.CCLongTransCost() + cost );
-              }
+            producttrips      := selectuniquevalues( alltrips, Elements.ProductInTrip, pit, pit.Quantity() <> 0 and exists( pit.Product_MP().GetAllParent(), Elements, e, e.ID() = produtparent ), pit.ProductID() );
+    //        info( '--------------2---------------', producttrips.Size() );
+            traverse( producttrips, Elements, producttrip ){//, producttrip = '6912'
+        
+              row          := table.GetRow( producttrip );
+              product         := selectobject( owner, Product_MP, product, product.ID() = producttrip );
+              products.Add( product );
+              quantity       := sum( alltrips, Elements.ProductInTrip, pit, pit.Product_MP() = product, pit.Quantity() );
+              enginecost     := selectobject( enginecosts, Elements, engine, engine.Generation().ToLower() = product.Generation().ToLower()
+                                                   and engine.MLB_MQB() = product.MQBMLB()
+                                                   and engine.Factory() = ccfactory );
+                //鍦ㄨ繍杈撴垚鏈弬鏁拌〃閲屾壘鍒板彂鍔ㄦ満瀵瑰簲杩愯緭鍗曚环鍜岃杞藉閲�
+                transcost      := selectobject( transcosts, Elements, trans, trans.Origin() = laneleg.OriginStockingPointID() 
+                                                  and trans.Destination() = laneleg.DestinationStockingPointID() 
+                                                  and exists( product.GetAllParent(), Elements, e, ifexpr( trans.Product().FindString( '鍙戝姩鏈�', 0 ) >= 0, e.ID() = produtparent,  e.ID() = trans.Product() ) ) );
+    //            info( '-------------------', not isnull( enginecost ) and not isnull( transcost ), isnull( transcost ), product.ID() );
+                if( not isnull( enginecost ) and not isnull( transcost ) ){
+    //              info( '-------------------', product.ID(), transcost.LoadingCapacity() );
+                  cost := ceil( ceil( quantity / enginecost.PackagingCapacity() ) / transcost.LoadingCapacity() ) * transcost.TransportPrice();//鍥涜垗浜斿叆
+    //              info( quantity, ceil( quantity / enginecost.PackagingCapacity() ), ceil( ceil( quantity / enginecost.PackagingCapacity() ) / transcost.LoadingCapacity() ) );
+    //              row.SetFactoryToRentTransCost( column, cost );
+    cell           := selectobject( row, Cell, cell, cell.Column() = column );
+                  cell.CCLongTransCost( cell.CCLongTransCost() + cost )
+                }
             }
           }
         }
+    //traverse( owner, TransferPlanRow, tprow ){
+    //  product                 := selectobject( owner, Product_MP, product, product.ID() = tprow.ProductID() );
+    //  productparents          := product.GetAllParent();
+    //  if( exists( productparents, Elements, e, e.ID() = produtparent ) ){//鏌ヨ浜у搧绫诲瀷鏄彂鍔ㄦ満
+    //    //璧峰搴撳瓨鐐规槸鍚︽槸澶ц繛(澶ц繛鍘傚唴搴擄級
+    //    isdl                   := tprow.SourceStockpoingPointID().EndsWith( '鍘傚唴搴�' ) and ( tprow.TargetStockpoingPointID().StartsWith( '澶ц繛' ) or tprow.TargetStockpoingPointID().StartsWith( 'DL' ) );
+    //    //鐩殑鍦板簱瀛樼偣鏄惁鏄暱鏄ワ紙闀挎槬澶栫搴擄級
+    //    iscc                   := tprow.TargetStockpoingPointID().EndsWith( '澶栫搴�' ) and ( tprow.TargetStockpoingPointID().StartsWith( '闀挎槬' ) or tprow.TargetStockpoingPointID().StartsWith( 'CC' ) );
+    //    if( isdl and iscc ){
+    //      //鏌ヨ瀵瑰簲鐨勫彂鍔ㄦ満鎴愭湰
+    //      enginecosts          := selectset( owner, LogisticsCostEngine, engine, engine.PackagingCapacity() <> 0 and engine.Generation().ToLower() = product.Generation().ToLower() 
+    //                                             and engine.MLB_MQB() = product.MQBMLB()
+    //                                             and engine.Factory() = ccfactory );
+    //      //鍦ㄨ繍杈撴垚鏈弬鏁拌〃閲屾壘鍒板彂鍔ㄦ満瀵瑰簲杩愯緭鍗曚环鍜岃杞藉閲�
+    //      transcosts           := selectset( owner, LogisticsCostTransport, trans, trans.LoadingCapacity() <> 0 and trans.Origin() = tprow.SourceStockpoingPointID() 
+    //                                              and trans.Destination() = tprow.TargetStockpoingPointID() 
+    //                                              and exists( productparents, Elements, e, ifexpr( trans.Product().FindString( '鍙戝姩鏈�', 0 ) >= 0, e.ID() = produtparent,  e.ID() = trans.Product() ) ) );
+    //      if( not isnull( enginecosts ) and enginecosts.Size() > 0 and not isnull( transcosts ) and transcosts.Size() > 0 ){
+    //        row                := table.GetRow( product.ID() );
+    //        products.Add( product );
+    //        traverse( tprow,TransferPlanCell, tpcell, tpcell.TransferPlanColumn().ColumnDate() <> Date::MinDate() and [Number]tpcell.Value() > 0){
+    //          tpcolumndate     := tpcell.TransferPlanColumn().ColumnDate();
+    //          enginecost       := selectobject( enginecosts, Elements, engine, engine.StartDate() <= tpcolumndate and engine.EndDate() >= tpcolumndate );
+    //          transcost        := selectobject( transcosts, Elements, trans, trans.StartDate() <= tpcolumndate and trans.EndDate() >= tpcolumndate );
+    //          if( not isnull( enginecost ) and not isnull( transcost ) ){
+    //            periodtime     := tpcolumndate.StartOfMonth();
+    //            periodname     := periodtime.Format( "M2/D2/Y" );
+    //            column         := selectobject( table, Column, column, column.Name() = periodname and column.StartDate() = periodtime );
+    //             
+    //            cost           := ceil( ceil( [Number]tpcell.Value() / enginecost.PackagingCapacity() ) / transcost.LoadingCapacity() ) * transcost.TransportPrice();
+    //            cell           := selectobject( row, Cell, cell, cell.Column() = column );
+    //            cell.CCLongTransCost( cell.CCLongTransCost() + cost );
+    //          }
+    //        }
+    //      }
+    //    }
       }
     }
     //闀挎槬鐭�旇繍杈撹垂鐢細瀹㈡埛闇�姹傛暟閲�/鍖呰瀹归噺/瑁呰浇瀹归噺*杩愯緭鍗曚环锛屽鎴烽渶姹傛暟閲忓彇鑷猣orecast閲宻ales segment涓洪暱鏄ョ殑鏁伴噺姹囨�伙紝鍐嶇敤鍏紡璁$畻锛屾湀搴﹁繘琛屾眹鎬伙紙鍙栧鎴烽渶姹傛暟閲忔崲绠楁垚杞︽锛�
-    traverse( owner, SalesDemand.astype( Forecast ), forecast, forecast.Quantity() > 0 and not isnull( forecast.SalesSegment_MP() ) and forecast.StartDate() < startofnextyear ){
-      salessegment            := forecast.SalesSegment_MP();
-      parentsalessegments     := salessegment.GetAllParent();
-      //鏄惁灞炰簬闀挎槬
-      iscc                    := salessegment.Name().StartsWith( 'Changchun' ) or exists( parentsalessegments, Elements, psalessegment, psalessegment.Name().StartsWith( 'Changchun' ) );
-      if( iscc ){
-        product               := forecast.Product_MP();
-        productparents        := product.GetAllParent();
-        if( exists( productparents, Elements, e, e.ID() = produtparent ) ){//鏌ヨ浜у搧绫诲瀷鏄彂鍔ㄦ満
-          //鏌ヨ瀵瑰簲鐨勫彂鍔ㄦ満鎴愭湰
+    allforecast                := selectset( owner, SalesDemand.astype( Forecast ), forecast, forecast.Quantity() > 0 and not isnull( forecast.SalesSegment_MP() ) and forecast.StartDate() < startofnextyear and //forecast.ProductID() = '6912' and forecast.StartDate().Month() = 1 and
+                                             ( forecast.SalesSegment_MP().Name().StartsWith( 'Changchun' ) or exists( forecast.SalesSegment_MP().GetAllParent(), Elements, psalessegment, psalessegment.Name().StartsWith( 'Changchun' ) ) or forecast.SalesSegment_MP().Name().StartsWith( 'Foshan' ) or forecast.SalesSegment_MP().Name().StartsWith( 'Tianjin' )
+                                                or exists( forecast.SalesSegment_MP().GetAllParent(), Elements, psalessegment, psalessegment.Name().StartsWith( 'Foshan' ) or psalessegment.Name().StartsWith( 'Tianjin' ) ) )
+                                             and exists( forecast.Product_MP().GetAllParent(), Elements, e, e.ID() = produtparent ) );
+    ccforecasts                := selectset( allforecast, Elements, forecast, forecast.SalesSegment_MP().Name().StartsWith( 'Changchun' ) or exists( forecast.SalesSegment_MP().GetAllParent(), Elements, psalessegment, psalessegment.Name().StartsWith( 'Changchun' ) )  );
+    ccproducts                 := selectuniquevalues( ccforecasts, Elements, forecast, forecast.ProductID() );
+    dlforecasts                 := selectset( allforecast, Elements, forecast, forecast.SalesSegment_MP().Name().StartsWith( 'Foshan' ) or forecast.SalesSegment_MP().Name().StartsWith( 'Tianjin' )
+                                                or exists( forecast.SalesSegment_MP().GetAllParent(), Elements, psalessegment, psalessegment.Name().StartsWith( 'Foshan' ) or psalessegment.Name().StartsWith( 'Tianjin' ) ) );
+    dlproducts                 := selectuniquevalues( dlforecasts, Elements, forecast, forecast.ProductID() );;
+    traverse( ccproducts, Elements, ccproduct){
+      product                 := selectobject( owner, Product_MP, product, product.ID() = ccproduct );
+    //  info( '************', product.ID(), exists( ccforecasts, Elements, forecast, forecast.Quantity() > 0 ));
+      //鏌ヨ瀵瑰簲鐨勫彂鍔ㄦ満鎴愭湰
           enginecosts         := selectset( owner, LogisticsCostEngine, engine, engine.PackagingCapacity() <> 0 and engine.Generation().ToLower() = product.Generation().ToLower() 
-                                                 and engine.MLB_MQB() = product.MQBMLB()
-                                                 and engine.Factory() = ccfactory );
+                                                 and engine.MLB_MQB() = product.MQBMLB()and engine.Factory() = ccfactory );
           //鍦ㄨ繍杈撴垚鏈弬鏁拌〃閲屾壘鍒板彂鍔ㄦ満瀵瑰簲杩愯緭鍗曚环鍜岃杞藉閲�
           transcosts           := selectset( owner, LogisticsCostTransport, trans, trans.LoadingCapacity() <> 0 and trans.Origin() = '闀挎槬澶栫搴�'
                                                   and trans.Destination() = '瀹㈡埛搴�'
-                                                  and exists( productparents, Elements, e, ifexpr( trans.Product().FindString( '鍙戝姩鏈�', 0 ) >= 0, e.ID() = produtparent,  e.ID() = trans.Product() ) ) );
-          if( not isnull( enginecosts ) and enginecosts.Size() > 0 ){
-            products.Add( forecast.Product_MP() );
-            row               := table.GetRow( forecast.ProductID() );
-            traverse( forecast, PlanningSalesDemandInPeriod, psdip, psdip.Quantity() > 0 ){
-              enginecost      := selectobject( enginecosts, Elements, engine, engine.StartDate() <= psdip.StartDate() and engine.EndDate() >= psdip.StartDate() );
-              transcost       := selectobject( transcosts, Elements, trans, trans.StartDate() <= psdip.StartDate() and trans.EndDate() >= psdip.StartDate() );
-              if( not isnull( enginecost ) ){
-                periodtime    := psdip.StartDate().StartOfMonth();
-                periodname    := periodtime.Format( "M2/D2/Y" );
-          //      info( '-------------------------', periodname, periodtime );
-                column         := selectobject( table, Column, column, column.Name() = periodname and column.StartDate() = periodtime );
-          //      info( '-------------------------', column.Name() );
-                cost           := ceil( ceil( [Number]psdip.Quantity() / enginecost.PackagingCapacity() ) / transcost.LoadingCapacity() ) * transcost.TransportPrice();
-                cell           := selectobject( row, Cell, cell, cell.Column() = column );
-                cell.CCShorTransCost( cell.CCShorTransCost() + cost );
-              }
-            }
-          }
+                                                  and exists( product.GetAllParent(), Elements, e, ifexpr( trans.Product().FindString( '鍙戝姩鏈�', 0 ) >= 0, e.ID() = produtparent,  e.ID() = trans.Product() ) ) );
+      if( not isnull( enginecosts ) and enginecosts.Size() > 0 and not isnull( transcosts ) and transcosts.Size() > 0 ){
+        row               := table.GetRow( ccproduct )
+        products.Add( product );
+        traverse( table, Column, column ){
+          allpsdips             := selectset( ccforecasts, Elements.PlanningSalesDemandInPeriod, psdip, psdip.ProductID() = ccproduct and psdip.Quantity() > 0 and psdip.StartDate() < column.StartDate().StartOfNextMonth() and psdip.StartDate() >= column.StartDate() );
+          enginecost      := selectobject( enginecosts, Elements, engine, engine.StartDate() <= column.StartDate() and engine.EndDate() >= column.StartDate() );
+          transcost       := selectobject( transcosts, Elements, trans, trans.StartDate() <= column.StartDate() and trans.EndDate() >= column.StartDate() );
+          if( not isnull( enginecost ) and not isnull( transcost ) ){
+            quantity        := sum( allpsdips, Elements, psdip, psdip.Quantity() );
+            cost           := ceil( ceil( quantity / enginecost.PackagingCapacity() ) / transcost.LoadingCapacity() ) * transcost.TransportPrice();
+             cell           := selectobject( row, Cell, cell, cell.Column() = column );
+             cell.CCShorTransCost( cell.CCShorTransCost() + cost );
+           }
+        }
+      }
+    }
+    //info( '***********1********', dlforecasts.Size() );
+    traverse( dlproducts, Elements, ccproduct){
+      
+      row               := table.GetRow( ccproduct )
+      product                 := selectobject( owner, Product_MP, product, product.ID() = ccproduct );
+      //鏌ヨ瀵瑰簲鐨勫彂鍔ㄦ満鎴愭湰
+          enginecosts         := selectset( owner, LogisticsCostEngine, engine, engine.PackagingCapacity() <> 0 and engine.Generation().ToLower() = product.Generation().ToLower() 
+                                                 and engine.MLB_MQB() = product.MQBMLB()and engine.Factory() = dlfactory );
+      if( not isnull( enginecosts ) and enginecosts.Size() > 0 ){
+        traverse( table, Column, column ){
+          allpsdips             := selectset( dlforecasts, Elements.PlanningSalesDemandInPeriod, psdip, psdip.ProductID() = ccproduct and psdip.Quantity() > 0 and psdip.StartDate() < column.StartDate().StartOfNextMonth() and psdip.StartDate() >= column.StartDate() );
+          enginecost      := selectobject( enginecosts, Elements, engine, engine.StartDate() <= column.StartDate() and engine.EndDate() >= column.StartDate() );
+          if( not isnull( enginecost ) ){
+            products.Add( product );
+            quantity        := sum( allpsdips, Elements, psdip, psdip.Quantity() );
+            
+            cost           := ceil( quantity / enginecost.PackagingCapacity() ) * enginecost.OutboundPrice();
+    //        info( '******************', quantity, cost );
+    //         cell           := selectobject( row, Cell, cell, cell.Column() = column );
+             row.SetDLRentOutCost( column, cost );
+           }
         }
       }
     }

--
Gitblit v1.9.3