Quintiq file version 2.0 
 | 
#parent: #root 
 | 
StaticMethod Initialize ( 
 | 
  MacroPlan owner 
 | 
) 
 | 
{ 
 | 
  TextBody: 
 | 
  [* 
 | 
    // 甄兰鸽 Aug-12-2024 (created) 
 | 
    owner.CCEngineLogisticsCostReport( relflush ); 
 | 
    produtparent              := CCEngineLogisticsCostReport::GetDefaultProductParent(); 
 | 
    name                      := CCEngineLogisticsCostReport::GetDefaultName(); 
 | 
    allunit                   := CCEngineLogisticsCostReport::GetDefaultAllUnit(); 
 | 
    ccunit                    := CCEngineLogisticsCostReport::GetDefaultCCUnit(); 
 | 
    ccline                    := CCEngineLogisticsCostReport::GetStockingPointCCLine(); 
 | 
    ccrent                    := CCEngineLogisticsCostReport::GetStockingPointCCRent(); 
 | 
     
 | 
    startofplanning           := owner.StartOfPlanning().Date(); 
 | 
    //startofyear               := startofplanning.StartOfYear(); 
 | 
    startofnextyear           := startofplanning.StartOfNextYear(); 
 | 
     
 | 
    table                     := owner.CCEngineLogisticsCostReport( relnew, ID := name, Name := name ); 
 | 
    showtable                 := owner.CCEngineLogisticsCostReport( relnew, ID := name + 'Show', Name := name, IsShow := true ); 
 | 
    search                    := owner.CCEngineLogisticsCostSearch( relnew, Generation := allunit, MqbMlb := allunit, Power := allunit ); 
 | 
     
 | 
    products                  := construct( Product_MPs ); 
 | 
     
 | 
    table.GenerateColumn( owner ); 
 | 
    //外租库入库费用:取自财务产量报表的产量,在产品表根据发动机号找到对应的Generation 和横纵制,在发动机成本参数表里找到对应的包装容量和入库单价,用公式计算,月度进行汇总 
 | 
    traverse( owner, FinancialProductionSource, source, not source.IsImport() ){//财务产量报表非导入 
 | 
      traverse( source, FinancialProductionReport, report, not report.IsShow() ){//财务产量报表不显示 
 | 
        traverse( report, FinancialProductionRow, row, row.Unit() = ccunit and exists( row, FinancialProductionCell, cell, cell.Value() <> '0' ) ){//财务产量报表里的长春产量, 不为0 
 | 
          ccrow               := table.GetRow( row.Name() ); 
 | 
          product             := row.Product_MP(); 
 | 
          productparents      := product.GetAllParent(); 
 | 
          if( exists( productparents, Elements, e, e.ID() = produtparent ) ){//查询产品类型是发动机 
 | 
            //查询对应的发动机成本 
 | 
            enginecost          := selectobject( owner, LogisticsCostEngine, engine, engine.Generation() = product.Generation()  
 | 
                                                 and engine.MLB_MQB() = product.MQBMLB() 
 | 
                                                 and engine.Factory() = ccunit 
 | 
                                                 and exists( productparents, Elements, e, e.ID() = engine.Product() ) ); 
 | 
            if( not isnull( enginecost ) ){ 
 | 
              products.Add( product ); 
 | 
              traverse( row, FinancialProductionCell, cell, cell.Value() <> '0' ){ 
 | 
                //入库量/包装容量*入库单价,入库量等于长春产量 
 | 
                quantity          := ceil( [Number]cell.Value() / enginecost.PackagingCapacity() ) * enginecost.WarehousingPrice(); 
 | 
                column            := selectobject( table, Column, column, column.Name() = cell.FinancialProductionColumn().Name() ); 
 | 
                //外租库入库费用 
 | 
                ccrow.SetRentEnterCost( column, quantity ); 
 | 
              } 
 | 
            } 
 | 
          } 
 | 
        } 
 | 
      } 
 | 
    } 
 | 
    //外租库出库费用:出库量等于长春销量,取自财务销量报表的销量,在产品表根据发动机号找到对应的Generation 和横纵制,在发动机成本参数表里找到对应的包装容量和出库单价,用公式计算,月度进行汇总 
 | 
    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 
 | 
          ccrow               := table.GetRow( row.Name() ); 
 | 
          product             := row.Product_MP(); 
 | 
          productparents      := product.GetAllParent(); 
 | 
          if( exists( productparents, Elements, e, e.ID() = produtparent ) ){//查询产品类型是发动机 
 | 
            //查询对应的发动机成本 
 | 
            enginecost          := selectobject( owner, LogisticsCostEngine, engine, engine.Generation() = product.Generation()  
 | 
                                                 and engine.MLB_MQB() = product.MQBMLB() 
 | 
                                                 and engine.Factory() = ccunit  
 | 
                                                 and exists( productparents, Elements, e, e.ID() = engine.Product() ) ); 
 | 
            if( not isnull( enginecost ) ){ 
 | 
              products.Add( product ); 
 | 
              traverse( row, FinancialSalesCell, cell, cell.Value() <> '0' ){ 
 | 
                //出库量/包装容量*出库单价,入库量等于长春销量 
 | 
                quantity          := ceil( [Number]cell.Value() / enginecost.PackagingCapacity() ) * enginecost.WarehousingPrice(); 
 | 
                column            := selectobject( table, Column, column, column.Name() = cell.FinancialSalesColumn().Name() ); 
 | 
                //外租库出库费用 
 | 
                ccrow.SetRentOutCost( column, quantity ); 
 | 
              } 
 | 
            } 
 | 
          } 
 | 
        } 
 | 
      } 
 | 
    } 
 | 
    //厂内到外租库运输费用:,在 trip plan里找到长春装配线边库到长春外租库的运输数量,,,用公式计算得出结果,月度进行汇总 
 | 
    traverse( owner, Unit.Lane.LaneLeg, laneleg ){ 
 | 
      //起始库存点是否是长春装配线边库 
 | 
      originsp               := selectobject( owner, StockingPoint_MP, sp, sp.ID() = laneleg.OriginStockingPointID() ); 
 | 
      isccspline             := table.IsInUnit( originsp, ccline ); 
 | 
      //目的地是否是长春外租库 
 | 
      destisp                := selectobject( owner, StockingPoint_MP, sp, sp.ID() = laneleg.DestinationStockingPointID() ); 
 | 
      isccrent               := table.IsInUnit( destisp, ccrent ); 
 | 
      if( isccspline and isccrent ){ 
 | 
        traverse( laneleg, Trip, trip, trip.Arrival().Date() < startofnextyear ){ 
 | 
          periodtime         := trip.Arrival().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 ){ 
 | 
            row              := table.GetRow( pit.ProductID() ); 
 | 
            product          := pit.Product_MP(); 
 | 
            productparents   := product.GetAllParent(); 
 | 
            if( exists( productparents, Elements, e, e.ID() = produtparent ) ){////查询产品类型是发动机 
 | 
              //在发动机成本参数表找到对应的包装容量 
 | 
              enginecost       := selectobject( owner, LogisticsCostEngine, engine, engine.Generation() = product.Generation()  
 | 
                                                 and engine.MLB_MQB() = product.MQBMLB() 
 | 
                                                 and engine.Factory() = ccunit  
 | 
                                                 and exists( productparents, Elements, e, e.ID() = engine.Product() ) ); 
 | 
              //在运输成本参数表里找到发动机对应运输单价和装载容量 
 | 
              transcost        := selectobject( owner, LogisticsCostTransport, trans, trans.Origin() = ccline  
 | 
                                                and trans.Destination() = ccrent  
 | 
                                                and exists( productparents, Elements, e, e.ID() = trans.Product() ) ); 
 | 
              if( not isnull( enginecost ) and not isnull( transcost ) ){ 
 | 
                products.Add( product ); 
 | 
                //运输数量/包装容量/装载容量*运输单价 
 | 
                quantity       := ceil( ceil( [Number]pit.Quantity() / enginecost.PackagingCapacity() ) / transcost.LoadingCapacity() ) * transcost.TransportPrice();//四舍五入 
 | 
                 
 | 
                row.SetFactoryToRentTransCost( column, quantity ); 
 | 
              } 
 | 
            } 
 | 
          } 
 | 
        } 
 | 
      } 
 | 
    } 
 | 
    //外租库仓储费用:仓储数量/包装容量*仓储单价,在Actual inventories里取到长春外租库该发动机的仓储量,根据发动机号找到对应的Generation 和横纵制,在发动机成本参数表里找到对应的仓储单价和包装容量,用公式计算,月度进行汇总 
 | 
    traverse( owner, StockingPoint_MP, stockingpoint ){ 
 | 
      //是否属于长春外租库 
 | 
      isccrent               := table.IsInUnit( stockingpoint, ccrent ); 
 | 
      if( isccrent ){ 
 | 
        traverse( stockingpoint, ProductInStockingPoint_MP, pisp,  pisp.Product_MP().IsLeaf() ){ 
 | 
          //获取行 
 | 
          product            := pisp.Product_MP(); 
 | 
          productparents     := product.GetAllParent(); 
 | 
          row                := table.GetRow( pisp.ProductID() ); 
 | 
          if( exists( productparents, Elements, e, e.ID() = produtparent ) ){////查询产品类型是发动机 
 | 
            //查询对应的发动机成本 
 | 
            enginecost         := selectobject( owner, LogisticsCostEngine, engine, engine.Generation() = product.Generation()  
 | 
                                                 and engine.MLB_MQB() = product.MQBMLB() 
 | 
                                                 and engine.Factory() = ccunit  
 | 
                                                 and exists( productparents, Elements, e, e.ID() = engine.Product() ) ); 
 | 
            if( not isnull( enginecost ) ){ 
 | 
              products.Add( product ); 
 | 
              //当product planning的日期区间在需要的日期区间内  
 | 
              traverse( pisp, ProductInStockingPointInPeriod, pispip, not pispip.Period_MP().IsHistorical() and pispip.Period_MP().StartDate() < startofnextyear 
 | 
                        ){ 
 | 
                periodtime := pispip.Start().StartOfMonth().Date(); 
 | 
                periodname := periodtime.Format( "M2/D2/Y" ); 
 | 
                quantity   := ceil( [Number]pispip.NewSupplyQuantity() / enginecost.PackagingCapacity() ) * enginecost.StoragePrice();//四舍五入 
 | 
                 
 | 
                column := selectobject( table, Column, column, column.Name() = periodname and column.StartDate() = periodtime ); 
 | 
                 
 | 
                row.SetRentStorageCost( column, quantity ); 
 | 
              }     
 | 
            } 
 | 
          } 
 | 
        } 
 | 
      } 
 | 
    } 
 | 
    rows := selectsortedset( table, Row, row, row.Name() ); 
 | 
    i    := 0; 
 | 
    traverse( rows, Elements, e ){ 
 | 
      e.RowNr( i ); 
 | 
      i := i + 1; 
 | 
    } 
 | 
    // 
 | 
    showtable.Generate( search, products ); 
 | 
  *] 
 | 
} 
 |