_Main/BL/Type_CCEngineLogisticsCostReport0/StaticMethod_InitializeNew.qbl
@@ -11,16 +11,10 @@
    produtparent              := DLEngineLogisticsCostReport::GetDefaultProductParent();
    name                      := DLEngineLogisticsCostReport::GetDefaultName();
    allunit                   := DLEngineLogisticsCostReport::GetDefaultAllUnit();
    ccunit                    := DLEngineLogisticsCostReport::GetDefaultCCUnit();
    dlunit                    := DLEngineLogisticsCostReport::GetDefaultDLUnit();
    ccfactory                 := DLEngineLogisticsCostReport::GetCCFactory();
    dlfactory                 := DLEngineLogisticsCostReport::GetDLFactory();
    //dlline                    := DLEngineLogisticsCostReport::GetStockingPointDLLine();
    //ccrent                    := DLEngineLogisticsCostReport::GetStockingPointCCRent();
    //dlrent                    := DLEngineLogisticsCostReport::GetStockingPointCCRent();
    
    startofplanning           := owner.StartOfPlanning().Date();
    //startofyear               := startofplanning.StartOfYear();
    startofnextyear           := startofplanning.StartOfNextYear();
    
    table                     := owner.DLEngineLogisticsCostReport( relnew, ID := name, Name := name );
@@ -33,15 +27,8 @@
    //外租库仓储费用:仓储数量/包装容量*仓储单价,在Actual inventories里取到长春外租库/大连外租库该发动机的仓储量,根据发动机号找到对应的Generation 和横纵制,在发动机成本参数表里找到对应的仓储单价和包装容量,用公式计算,月度进行汇总
    //长春外租库入库/出库费用,大连发动机的长春外租库的New supply
    traverse( owner, StockingPoint_MP, stockingpoint, stockingpoint.ID().EndsWith( '外租库' ) ){
    //  unit                    := stockingpoint.Unit();
    //  parentunits             := unit.GetAllParent();
      //是否属于长春外租库用于长春外租库仓储费用
    //  isccrent                := stockingpoint.ID().StartsWith( '长春' ) or stockingpoint.ID().StartsWith( 'CC' );
      //是否属于大连发动机的长春外租库用于长春入库/出库费用
      isdltoccrent            := stockingpoint.ID().StartsWith( '大连发动机的长春' );
      //是否属于大连外租库用于大连外租库仓储费用
      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 ) ) ){
@@ -51,9 +38,7 @@
          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() ) ) );
            transcosts        := selectset( owner, LogisticsCostTransport, trans, trans.LoadingCapacity() <> 0 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 
@@ -67,30 +52,34 @@
                  //在发动机成本参数表找到对应的包装容量
                  enginecost  := selectobject( enginecosts, Elements, engine, engine.StartDate() <= pispip.Start().Date() and engine.EndDate() >= pispip.Start().Date()
                                                     and engine.Factory() = ccfactory );
                   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 );//长春外租库仓储费用
                  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 );//长春外租库仓储费用
                  transcost   := selectobject( transcosts, Elements, trans, trans.StartDate() <= column.StartDate() and trans.EndDate() >= column.StartDate() and trans.Origin() = '长春外租库' and trans.Destination() = '客户库' );
                  if( not isnull( transcost ) ){
                    cost      := ceil( ceil( pispip.NewSupplyQuantity() / enginecost.PackagingCapacity() ) / transcost.LoadingCapacity() ) * transcost.TransportPrice();
                    cell.CCShorTransCost( cell.CCShorTransCost() + cost );//长春短途运输费用
                  }
                } else {
                  //在发动机成本参数表找到对应的包装容量
                  enginecost     := selectobject( enginecosts, Elements, engine, engine.StartDate() <= pispip.Start().Date() and engine.EndDate() >= pispip.Start().Date()
                  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( 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 );
                     }
                   }
                  if( not isnull( enginecost ) ){
                    cost      := ceil( pispip.PlannedInventoryLevelEnd() / enginecost.PackagingCapacity() ) * enginecost.StoragePrice();//四舍五入
                    cell.DLRentStorCost( cell.DLRentStorCost() + cost );//大连外租库仓储费用
                    row.SetDLRentEnterCost( column, enginecost, pispip.NewSupplyQuantity() );//大连外租库入库费用
                    transcost := selectobject( transcosts, Elements, trans, trans.StartDate() <= pispip.Start().Date() and trans.EndDate() >= pispip.Start().Date() and trans.Origin() = '大连厂内库' and trans.Destination() = '大连外租库' );
                    if( not isnull( transcost ) ){
                      cost    := ceil( ceil( pispip.NewSupplyQuantity() / enginecost.PackagingCapacity() ) / transcost.LoadingCapacity() ) * transcost.TransportPrice();//四舍五入
                      row.SetFactoryToRentTransCost( column, cost );
                    }
                  }
                }
              }   
            }
@@ -98,123 +87,37 @@
        }
      }
    }
    //在 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( '大连外租库' );
    //  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到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' ) );
      isdl                    := laneleg.OriginStockingPointID().EndsWith( '厂内库' ) and ( laneleg.OriginStockingPointID().StartsWith( '大连' ) or laneleg.OriginStockingPointID().StartsWith( 'DL' ) );
      //目的地库存点是否是长春(长春外租库)
      iscc                   := laneleg.DestinationStockingPointID() = '大连发动机的长春外租库';
      iscc                    := laneleg.DestinationStockingPointID() = '大连发动机的长春外租库';
        if( isdl and iscc ){
    //  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() );
          alltrips            := selectset( laneleg, Trip, trip, trip.Arrival().Date() < column.StartDate().StartOfNextMonth() and trip.Arrival().Date() >= 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 ){//, producttrip = '6912'
        
              row          := table.GetRow( 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()
              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()
                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 );
                  cost        := ceil( ceil( quantity / enginecost.PackagingCapacity() ) / transcost.LoadingCapacity() ) * transcost.TransportPrice();//四舍五入
                  cell        := selectobject( row, Cell, cell, cell.Column() = column );
                  cell.CCLongTransCost( cell.CCLongTransCost() + cost )
                }
            }
@@ -259,62 +162,60 @@
      }
    }
    //长春短途运输费用:客户需求数量/包装容量/装载容量*运输单价,客户需求数量取自forecast里sales segment为长春的数量汇总,再用公式计算,月度进行汇总(取客户需求数量换算成车次)
    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' )
    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' )
    //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 );
          //在运输成本参数表里找到发动机对应运输单价和装载容量
          transcosts           := selectset( owner, LogisticsCostTransport, trans, trans.LoadingCapacity() <> 0 and trans.Origin() = '长春外租库'
                                                  and trans.Destination() = '客户库'
                                                  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() );
    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 );
    //      //在运输成本参数表里找到发动机对应运输单价和装载容量
    //      transcosts           := selectset( owner, LogisticsCostTransport, trans, trans.LoadingCapacity() <> 0 and trans.Origin() = '长春外租库'
    //                                              and trans.Destination() = '客户库'
    //                                              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 );
    //       }
    //    }
    //  }
    //}
    traverse( dlproducts, Elements, ccproduct){
      
      row               := table.GetRow( 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() );
          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() );
            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 );
           }
            cost              := ceil( quantity / enginecost.PackagingCapacity() ) * enginecost.OutboundPrice();
            row.SetDLRentOutCost( column, cost );
          }
        }
      }
    }