陈清红
2025-04-14 880f3c0257eeb8c37761d484258fdd102a369a19
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
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();
    ccfactory                 := CCEngineLogisticsCostReport::GetCCFactory();
    ccunit                    := CCEngineLogisticsCostReport::GetDefaultCCUnit();
    //ccline                    := CCEngineLogisticsCostReport::GetStockingPointCCLine();
    ccrent                    := CCEngineLogisticsCostReport::GetStockingPointCCRent();
    
    startofplanning           := owner.StartOfPlanning().Date();
    //startofyear               := startofplanning.StartOfYear();
    startofnextyear           := startofplanning.StartOfNextYear();
    
    table                     := selectobject(owner, CCEngineLogisticsCostReport, report, report.ID() = name );
    if( isnull( table ) ){
      table                   := owner.CCEngineLogisticsCostReport( relnew, ID := name, Name := name );
    }
    table.Column( relflush );
    table.Row( relflush );
    showname                  := name + 'Show';
    if( not exists( owner, CCEngineLogisticsCostReport, report, report.ID() = showname and report.IsShow() ) ){
      owner.CCEngineLogisticsCostReport( relnew, ID := showname, Name := name, IsShow := true );
    }
    if( isnull( owner.CCEngineLogisticsCostSearch() ) ){
      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
          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() = ccfactory );//ccunit
            if( not isnull( enginecosts ) and enginecosts.Size() > 0 ){
              ccrow           := table.GetRow( row.Name() );
              products.Add( product );
              traverse( row, FinancialProductionCell, cell, cell.Value() <> '0' ){
                cellcolumn    := cell.FinancialProductionColumn();
                enginecost    := selectobject( enginecosts, Elements, engine, engine.StartDate() <= cellcolumn.Period() and engine.EndDate() >= cellcolumn.Period() );
                if( not isnull( enginecost ) ){
                  //入库量/包装容量*入库单价,入库量等于长春产量
                  quantity    := ceil( cell.Quantity() / 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
          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() = ccfactory );
            if( not isnull( enginecosts ) and enginecosts.Size() > 0 ){
              ccrow           := table.GetRow( row.Name() );
              products.Add( product );
              traverse( row, FinancialSalesCell, cell, cell.Value() <> '0' ){
                cellcolumn    := cell.FinancialSalesColumn();
                enginecost    := selectobject( enginecosts, Elements, engine, engine.StartDate() <= cellcolumn.Period() and engine.EndDate() >= cellcolumn.Period() );
                if( not isnull( enginecost ) ){
                  //出库量/包装容量*出库单价,入库量等于长春销量
                  quantity    := ceil( [Number]cell.Value() / enginecost.PackagingCapacity() ) * enginecost.OutboundPrice();
                  column      := selectobject( table, Column, column, column.Name() = cell.FinancialSalesColumn().Name() );
                  //外租库出库费用
                  ccrow.SetRentOutCost( column, quantity );
                }
              }
            }
          }
        }
      }
    }
    //厂内到外租库运输费用:,在 trip plan里找到长春装配线边库到长春外租库的运输数量,,,用公式计算得出结果,月度进行汇总CC-MOMO到长春外租库
    traverse( owner, Unit.Lane.LaneLeg, laneleg ){
      //起始库存点是否是长春装配线边库
      originsp               := selectobject( owner, StockingPoint_MP, sp, sp.ID() = laneleg.OriginStockingPointID() );
      isccspline             := table.IsInUnit( originsp, 'CC 厂内库' );
      //目的地是否是长春外租库
      destisp                := selectobject( owner, StockingPoint_MP, sp, sp.ID() = laneleg.DestinationStockingPointID() );
      isccrent               := table.IsInUnit( destisp, ccrent );
      if( isccspline and isccrent ){
        traverse( table, Column, column ){
          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() );
            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, floor( 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() = 'CC 厂内库' and trans.Destination() = ccrent and exists( product.GetAllParent(), Elements, e, ifexpr( trans.Product().FindString( '发动机', 0 ) >= 0, e.ID() = produtparent,  e.ID() = trans.Product() ) ) );
              if( not isnull( enginecost ) and not isnull( transcost ) ){
                cost := ceil( ceil( quantity / enginecost.PackagingCapacity() ) / transcost.LoadingCapacity() ) * transcost.TransportPrice();//四舍五入
                row.SetFactoryToRentTransCost( column, cost );
              }
            }
          }
        }
      }
    }
    //外租库仓储费用:仓储数量/包装容量*仓储单价,在Actual inventories里取到长春外租库该发动机的仓储量,根据发动机号找到对应的Generation 和横纵制,在发动机成本参数表里找到对应的仓储单价和包装容量,用公式计算,月度进行汇总
    traverse( owner, StockingPoint_MP, stockingpoint, table.IsInUnit( stockingpoint, ccrent ) ){//是否属于长春外租库
      traverse( stockingpoint, ProductInStockingPoint_MP, pisp,  pisp.Product_MP().IsLeaf() and exists( pisp.Product_MP().GetAllParent(), Elements, e, e.ID() = produtparent )//查询产品类型是发动机
                and exists( pisp, ProductInStockingPointInPeriod, pispip, not pispip.Period_MP().IsHistorical() and pispip.Period_MP().StartDate() < startofnextyear and pispip.PlannedInventoryLevelEnd() <> 0 ) ){
        //获取行
        product              := pisp.Product_MP();
        //查询对应的发动机成本
        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 );
        if( not isnull( enginecosts ) and enginecosts.Size() > 0 ){
          row                := table.GetRow( pisp.ProductID() );
          products.Add( product );
          traverse( table, Column, column ){
            
            pispips          := selectset( pisp, ProductInStockingPointInPeriod, pispip, pispip.Start().Date() >= column.StartDate() 
                                            and pispip.Start().Date() < column.StartDate().StartOfNextMonth() 
                                            and pispip.PlannedInventoryLevelEnd() <> 0 );
            cost             := column.CalcEngineCost( pispips, enginecosts );
            row.SetRentStorageCost( column, cost ); 
          }
        }
      }
    }
  *]
}