Quintiq file version 2.0 
 | 
#parent: #root 
 | 
StaticMethod Initialize ( 
 | 
  MacroPlan owner 
 | 
) 
 | 
{ 
 | 
  TextBody: 
 | 
  [* 
 | 
    // 甄兰鸽 Aug-12-2024 (created) 
 | 
    owner.DLEngineLogisticsCostReport( relflush ); 
 | 
    produtparent              := DLEngineLogisticsCostReport::GetDefaultProductParent(); 
 | 
    name                      := DLEngineLogisticsCostReport::GetDefaultName(); 
 | 
    allunit                   := DLEngineLogisticsCostReport::GetDefaultAllUnit(); 
 | 
    ccunit                    := DLEngineLogisticsCostReport::GetDefaultCCUnit(); 
 | 
    dlunit                    := DLEngineLogisticsCostReport::GetDefaultDLUnit(); 
 | 
    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 ); 
 | 
    showtable                 := owner.DLEngineLogisticsCostReport( relnew, ID := name + 'Show', Name := name, IsShow := true ); 
 | 
    search                    := owner.DLEngineLogisticsCostSearch( relnew, Generation := allunit, MqbMlb := allunit, Power := allunit ); 
 | 
     
 | 
    products                  := construct( Product_MPs ); 
 | 
     
 | 
    table.GenerateColumn( owner ); 
 | 
    //发往长春的销量需要在trip plan里面找到起始库存点为大连装配线边库,目的地为长春外租库的产品 算出发往长春的销量后,在发动机成本参数表里找到对应的包装容量和长春入库单价,用公式计算,月度进行汇总 
 | 
    //在 trip plan里找到大连装配线边库到大连外租库的运输数量 
 | 
    traverse( owner, Unit.Lane.LaneLeg, laneleg ){ 
 | 
      //起始库存点是否是大连装配线边库 
 | 
      originsp               := selectobject( owner, StockingPoint_MP, sp, sp.ID() = laneleg.OriginStockingPointID() ); 
 | 
      isdlspline             := table.IsInUnit( originsp, dlline ); 
 | 
      //目的地是否是长春外租库 
 | 
      destisp                := selectobject( owner, StockingPoint_MP, sp, sp.ID() = laneleg.DestinationStockingPointID() ); 
 | 
      isccrent               := table.IsInUnit( destisp, ccrent ); 
 | 
      //目的地是否是大连外租库 
 | 
      destisp                := selectobject( owner, StockingPoint_MP, sp, sp.ID() = laneleg.DestinationStockingPointID() ); 
 | 
      isdlrent               := table.IsInUnit( destisp, dlrent ); 
 | 
      if( isdlspline and ( isccrent or 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 ); 
 | 
          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(); 
 | 
            if( isccrent ){//目的地是长春外租库 
 | 
              //在发动机成本参数表找到对应的包装容量 
 | 
              enginecost     := selectobject( owner, LogisticsCostEngine, engine, engine.Generation().ToLower() = product.Generation().ToLower() 
 | 
                                                 and engine.MLB_MQB() = product.MQBMLB() 
 | 
                                                 and engine.Factory() = ccunit ); 
 | 
              if( not isnull( enginecost ) ){ 
 | 
                products.Add( product ); 
 | 
                cell         := selectobject( row, Cell, cell, cell.Column() = column ); 
 | 
                cell.CCRentQuantity( cell.CCRentQuantity() + quantity ); 
 | 
                //长春外租库入库费用:入库量/包装容量*入库单价 
 | 
                entercost    := ceil( quantity / enginecost.PackagingCapacity() ) * enginecost.WarehousingPrice(); 
 | 
                //长春外租库出库费用: 出库量/包装容量*出库单价 
 | 
                outcost      := ceil( quantity / enginecost.PackagingCapacity() ) * enginecost.WarehousingPrice(); 
 | 
                cell.CCRentEnterCost( cell.CCRentEnterCost() + entercost ); 
 | 
                cell.CCRentOutCost( cell.CCRentOutCost() + outcost ); 
 | 
              } 
 | 
            } 
 | 
            if( isdlrent ){//目的地是大连外租库 
 | 
              //在发动机成本参数表找到对应的包装容量 
 | 
              enginecost     := selectobject( owner, LogisticsCostEngine, engine, engine.Generation().ToLower() = product.Generation().ToLower()  
 | 
                                                 and engine.MLB_MQB() = product.MQBMLB() 
 | 
                                                 and engine.Factory() = dlunit  ); 
 | 
              //在运输成本参数表里找到发动机对应运输单价和装载容量 
 | 
              transcost      := selectobject( owner, LogisticsCostTransport, 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.FactoryToDLRentTransCost( cell.FactoryToDLRentTransCost() + cost ); 
 | 
              } 
 | 
            } 
 | 
          } 
 | 
        } 
 | 
      } 
 | 
    } 
 | 
    //大连外租库入库费用:入库量/包装容量*入库单价,入库量等于大连工厂该产品产量减去发往长春的数量 
 | 
    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' ) ){//财务产量报表里的大连产量, 不为0 
 | 
          product             := row.Product_MP(); 
 | 
          products.Add( product ); 
 | 
          productparents      := product.GetAllParent(); 
 | 
          if( exists( productparents, Elements, e, e.ID() = produtparent ) ){//查询产品类型是发动机 
 | 
            //查询对应的发动机成本 
 | 
            enginecost        := selectobject( owner, LogisticsCostEngine, engine, engine.Generation().ToLower() = product.Generation().ToLower()  
 | 
                                                 and engine.MLB_MQB() = product.MQBMLB() 
 | 
                                                 and engine.Factory() = dlunit ); 
 | 
            if( not isnull( enginecost ) ){ 
 | 
              ccrow               := table.GetRow( row.Name() ); 
 | 
              traverse( row, FinancialProductionCell, cell, cell.Value() <> '0' ){ 
 | 
                column        := selectobject( table, Column, column, column.Name() = cell.FinancialProductionColumn().Name() ); 
 | 
                //大连外租库入库费用 
 | 
                ccrow.SetDLRentEnterCost( column, enginecost, cell ); 
 | 
              } 
 | 
            } 
 | 
          } 
 | 
        } 
 | 
      } 
 | 
    } 
 | 
    //大连外租库出库费用:出库量/包装容量*出库单价,出库量等于大连工厂该产品销量减去发往长春的数量 
 | 
    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' ) ){//财务销量报表里的大连产量, 不为0 
 | 
          product             := row.Product_MP(); 
 | 
          productparents      := product.GetAllParent(); 
 | 
          if( exists( productparents, Elements, e, e.ID() = produtparent ) ){//查询产品类型是发动机 
 | 
            products.Add( product ); 
 | 
            //查询对应的发动机成本 
 | 
            enginecost        := selectobject( owner, LogisticsCostEngine, engine, engine.Generation().ToLower() = product.Generation().ToLower()  
 | 
                                                 and engine.MLB_MQB() = product.MQBMLB() 
 | 
                                                 and engine.Factory() = dlunit ); 
 | 
            if( not isnull( enginecost ) ){ 
 | 
              ccrow               := table.GetRow( row.Name() ); 
 | 
              traverse( row, FinancialSalesCell, cell, cell.Value() <> '0' ){ 
 | 
                column        := selectobject( table, Column, column, column.Name() = cell.FinancialSalesColumn().Name() ); 
 | 
                //大连外租库出库费用 
 | 
                ccrow.SetDLRentOutCost( column, enginecost, cell ); 
 | 
              } 
 | 
            } 
 | 
          } 
 | 
        } 
 | 
      } 
 | 
    } 
 | 
    //长春长途运输费用:调拨数量/包装容量/装载容量*运输单价,调拨计划里找到该产品从DL到CC的调拨数量,即起始地大连装配线边库,目的地为长春外租库对应的运输数量,在发动机成本参数表找到对应的包装容量,在运输成本参数表里找到发动机对应运输单价和装载容量,用公式计算得出结果,月度进行汇总 
 | 
    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 ) ){//查询产品类型是发动机 
 | 
        //起始库存点是否是大连 
 | 
        originsp               := selectobject( owner, StockingPoint_MP, sp, sp.ID() = tprow.SourceStockpoingPointID() ); 
 | 
        isdl                   := table.IsInUnit( originsp, dlunit ); 
 | 
        //目的地库存点是否是长春 
 | 
        destisp                := selectobject( owner, StockingPoint_MP, sp, sp.ID() = tprow.TargetStockpoingPointID() ); 
 | 
        iscc                   := table.IsInUnit( destisp, ccunit ); 
 | 
        if( isdl and iscc ){ 
 | 
          //查询对应的发动机成本 
 | 
          enginecost           := selectobject( owner, LogisticsCostEngine, engine, engine.Generation().ToLower() = product.Generation().ToLower()  
 | 
                                                 and engine.MLB_MQB() = product.MQBMLB() 
 | 
                                                 and engine.Factory() = ccunit ); 
 | 
          //在运输成本参数表里找到发动机对应运输单价和装载容量 
 | 
          transcost            := selectobject( owner, LogisticsCostTransport, trans, 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( enginecost ) and not isnull( transcost ) ){ 
 | 
            row                := table.GetRow( product.ID() ); 
 | 
            products.Add( product ); 
 | 
            traverse( tprow,TransferPlanCell, tpcell, tpcell.TransferPlanColumn().ColumnDate() <> Date::MinDate() and [Number]tpcell.Value() > 0){ 
 | 
              periodtime       := tpcell.TransferPlanColumn().ColumnDate().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.CCLongTransCoat( cell.CCLongTransCoat() + cost ); 
 | 
            } 
 | 
          } 
 | 
        } 
 | 
      } 
 | 
    } 
 | 
    //长春短途运输费用:客户需求数量/包装容量/装载容量*运输单价,客户需求数量取自forecast里sales 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() = ccunit or exists( parentsalessegments, Elements, psalessegment, psalessegment.Name() = ccunit ); 
 | 
      if( iscc ){ 
 | 
        product               := forecast.Product_MP(); 
 | 
        productparents        := product.GetAllParent(); 
 | 
        if( exists( productparents, Elements, e, e.ID() = produtparent ) ){//查询产品类型是发动机 
 | 
          products.Add( forecast.Product_MP() ); 
 | 
           
 | 
          //查询对应的发动机成本 
 | 
          enginecost          := selectobject( owner, LogisticsCostEngine, engine, engine.Generation().ToLower() = product.Generation().ToLower()  
 | 
                                                 and engine.MLB_MQB() = product.MQBMLB() 
 | 
                                                 and engine.Factory() = ccunit ); 
 | 
          if( not isnull( enginecost ) ){ 
 | 
            row                 := table.GetRow( forecast.ProductID() ); 
 | 
            traverse( forecast, PlanningSalesDemandInPeriod, psdip, psdip.Quantity() > 0 ){ 
 | 
              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( [Number]psdip.Quantity() / enginecost.PackagingCapacity() ) * enginecost.WarehousingPrice(); 
 | 
              cell             := selectobject( row, Cell, cell, cell.Column() = column ); 
 | 
              cell.CCShortTransCost( cell.CCShortTransCost() + cost ); 
 | 
            } 
 | 
          } 
 | 
        } 
 | 
      } 
 | 
    } 
 | 
    //外租库仓储费用:仓储数量/包装容量*仓储单价,在Actual inventories里取到长春外租库/大连外租库该发动机的仓储量,根据发动机号找到对应的Generation 和横纵制,在发动机成本参数表里找到对应的仓储单价和包装容量,用公式计算,月度进行汇总 
 | 
    traverse( owner, StockingPoint_MP, stockingpoint ){ 
 | 
      unit                    := stockingpoint.Unit(); 
 | 
      parentunits             := unit.GetAllParent(); 
 | 
      //是否属于长春外租库 
 | 
      isccrent                := stockingpoint.ID() = ccrent or unit.ID() = ccrent or exists( parentunits, Elements, punit, punit.ID() = ccrent ); 
 | 
      //是否属于大连外租库 
 | 
      isdlrent                := stockingpoint.ID() = dlrent or unit.ID() = dlrent or exists( parentunits, Elements, punit, punit.ID() = dlrent ); 
 | 
      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 ) ){ 
 | 
          //获取行 
 | 
          product             := pisp.Product_MP(); 
 | 
          productparents      := product.GetAllParent(); 
 | 
          if( exists( productparents, Elements, e, e.ID() = produtparent ) ){//查询产品类型是发动机 
 | 
            row               := table.GetRow( pisp.ProductID() ); 
 | 
            products.Add( pisp.Product_MP() ); 
 | 
            traverse( pisp, ProductInStockingPointInPeriod, pispip, not pispip.Period_MP().IsHistorical() and pispip.Period_MP().StartDate() < startofnextyear and pispip.NewSupplyQuantity() <> 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 ){ 
 | 
                //在发动机成本参数表找到对应的包装容量 
 | 
                enginecost     := selectobject( owner, LogisticsCostEngine, engine, engine.Generation().ToLower() = product.Generation().ToLower()  
 | 
                                                   and engine.MLB_MQB() = product.MQBMLB() 
 | 
                                                   and engine.Factory() = ccunit ); 
 | 
                 if( not isnull( enginecost ) ){ 
 | 
                   cost        := ceil( [Number]pispip.NewSupplyQuantity() / enginecost.PackagingCapacity() ) * enginecost.StoragePrice();//四舍五入 
 | 
                   cell.CCRentStorageCost( cell.CCRentStorageCost() + cost ); 
 | 
                 } 
 | 
              } else { 
 | 
                //在发动机成本参数表找到对应的包装容量 
 | 
                enginecost     := selectobject( owner, LogisticsCostEngine, engine, engine.Generation().ToLower() = product.Generation().ToLower()  
 | 
                                                   and engine.MLB_MQB() = product.MQBMLB() 
 | 
                                                   and engine.Factory() = dlunit  ); 
 | 
                 if( not isnull( enginecost ) ){ 
 | 
                   cost        := ceil( [Number]pispip.NewSupplyQuantity() / enginecost.PackagingCapacity() ) * enginecost.StoragePrice();//四舍五入 
 | 
                   cell.DLRentStorageCost( cell.DLRentStorageCost() + cost );; 
 | 
                 } 
 | 
              } 
 | 
            }    
 | 
          } 
 | 
        } 
 | 
      } 
 | 
    } 
 | 
    rows := selectsortedset( table, Row, row, row.Name() ); 
 | 
    i    := 0; 
 | 
    traverse( rows, Elements, e ){ 
 | 
      e.RowNr( i ); 
 | 
      i := i + 1; 
 | 
    } 
 | 
    info( '-------------------------------------end---------------------------------' ); 
 | 
    // 
 | 
    showtable.Generate( search, products ); 
 | 
  *] 
 | 
} 
 |