admin
2025-01-22 7e31442f0e9b07764e9c6a9680d3d4aeba5fe1de
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
Quintiq file version 2.0
#parent: #root
StaticMethod CreateData (
  MacroPlan macroPlan
)
{
  TextBody:
  [*
    macroPlan.CC_EngineRackRow( relflush );
    macroPlan.CC_EngineRackColumn( relflush );
    
    // 创建行
    genrations := selectuniquevalues( macroPlan, Product_MP, tempPMP, tempPMP.Generation().TrimBoth() <> "", tempPMP.Generation() );
    mqbmlbs    := selectuniquevalues( macroPlan, Product_MP, tempPMP, tempPMP.MQBMLB().TrimBoth() <> "", tempPMP.MQBMLB() );
    traverse ( genrations, Elements, g ) {
      traverse ( mqbmlbs, Elements, m ) {
        macroPlan.CC_EngineRackRow( relnew, Generation := g, MLB_MQB := m, Index := 1  );
      }
    }
    
    // 创建列
    indexDate := macroPlan.StartOfPlanning().Date().StartOfMonth();
    for ( i := 0; i < 12; i++ ) {
      macroPlan.CC_EngineRackColumn( relnew, StartDate := indexDate );
      indexDate := indexDate.StartOfNextMonth();
    }
    
    // 创建单元格
    traverse ( macroPlan, CC_EngineRackRow, ccerr ) { // 循环行
      info( "当前遍历的行:", ccerr.Generation(), " ", ccerr.MLB_MQB() );
      traverse ( macroPlan, CC_EngineRackColumn, ccerc ) { // 循环列
        // 发动机成本参数
        lce  := select( macroPlan, LogisticsCostEngine, tempLCE, tempLCE.Generation() = ccerr.Generation() and tempLCE.MLB_MQB() = ccerr.MLB_MQB() and tempLCE.Factory() = "长春工厂" 
                        and tempLCE.StartDate() <= ccerc.StartDate() and tempLCE.EndDate() >= ccerc.StartDate().StartOfNextMonth() );
        
        // 料架成本参数
        lcmr := select( macroPlan, LogisticsCostMaterialRack, tempLCMR, tempLCMR.Factory() = "长春工厂" 
                        and tempLCMR.StartDate() <= ccerc.StartDate() and tempLCMR.EndDate() >= ccerc.StartDate().StartOfNextMonth() );
                        
        // 运输成本参数
        lct  := select( macroPlan, LogisticsCostTransport, tempLCT, tempLCT.Product() = "发动机料架" and tempLCT.Origin() = "长春外租库" and tempLCT.Destination() = "CC 厂内库" );
        
        // 空料架比例
        mrpc := select( macroPlan, MaterialRackProportionRow.MaterialRackProportionCell, tempMRPCell, tempMRPCell.MaterialRackProportionRow().Generation() = "长春外租库" and tempMRPCell.MaterialRackColumn().Month() = ccerc.StartDate().Month() );
        
        // 客户库料架总数量
        mrcc := select( macroPlan, MaterialRackCustomRow.MaterialRackCustomCell, tempMRCCell, tempMRCCell.MaterialRackCustomRow().Generation() = ccerr.Generation() and tempMRCCell.MaterialRackCustomRow().MLB_MQB() = ccerr.MLB_MQB() and tempMRCCell.MaterialRackColumn().Month() = ccerc.StartDate().Month() );
        
        cell := ccerr.CC_EngineRackCell( relnew );
        
        // 料架总数量
        mrtcell := select( macroPlan, MaterialRackTotalRow.MaterialRackTotalCell, tempMRTCell, 
                           tempMRTCell.MaterialRackTotalRow().Generation() = ccerr.Generation()        and
                           tempMRTCell.MaterialRackTotalRow().MLB_MQB()    = ccerr.MLB_MQB()           and
                           tempMRTCell.MaterialRackColumn().Month()        = ccerc.StartDate().Month() );
        cell.TotalQuantityOfMaterialRacks( guard( mrtcell.Quantity(), 0 ) );
        
        // 空料架数量:【350bar MQB料架总数量 - 所有350bar MQB总库存 / 包装容量-客户库料架数量】* 长春外租库空料架比例
        plannedInventory := sum( macroPlan, Product_MP.ProductInStockingPoint_MP.ProductInStockingPointInPeriod, tempPISPIP,
                                 tempPISPIP.ProductInStockingPoint_MP().Product_MP().IsLeaf()                                                                       and
                                 exists( tempPISPIP.ProductInStockingPoint_MP().Product_MP(), AllParent.AsParent, tempPMP, tempPMP.ID() = "发动机" )                and
                                 //tempPISPIP.ProductInStockingPoint_MP().StockingPointID()                                             = "大连发动机的长春外租库"  and
                                 tempPISPIP.ProductInStockingPoint_MP().Product_MP().Generation()                                       = ccerr.Generation()        and
                                 tempPISPIP.ProductInStockingPoint_MP().Product_MP().MQBMLB()                                           = ccerr.MLB_MQB()           and
                                 tempPISPIP.Start().Date().Year()                                                                       = ccerc.StartDate().Year()  and 
                                 tempPISPIP.Start().Date().Month()                                                                      = ccerc.StartDate().Month(),
                                 tempPISPIP.PlannedInventoryLevelEnd() ) / ( ccerc.StartDate().StartOfNextMonth() - ccerc.StartDate() );
        cell.PackagingCapacity( guard( lce.PackagingCapacity(), 1 ) );
        cell.PlannedInventory( plannedInventory );
        if ( ccerr.Generation() = "350bar" and ccerr.MLB_MQB() = "MQB" ) {
          cell.NumberOfEmptyShelves( [Number] guard( ( cell.TotalQuantityOfMaterialRacks() - ( plannedInventory / lce.PackagingCapacity() ) - guard( mrcc.Quantity(), 0 ) ) * guard( mrpc.Quantity(), 1 ), 0 ) );
        } else {
          cell.NumberOfEmptyShelves( [Number] guard( cell.TotalQuantityOfMaterialRacks() - ( plannedInventory / lce.PackagingCapacity() ), 0 ) );
        }
        
        // 外租库入库费用(发动机销量 / 包装容量[向上取整] * 料架入库单价)
        engineSales := sum( macroPlan, FSImportData, tempFSID, 
                            tempFSID.Unit()              = FinancialProductionReport::GetDefaultCCUnit() and
                            tempFSID.Generation()        = ccerr.Generation()                            and
                            tempFSID.MqbMlb()            = ccerr.MLB_MQB()                               and
                            tempFSID.StartDate().Year()  = ccerc.StartDate().Year()                      and
                            tempFSID.StartDate().Month() = ccerc.StartDate().Month(),
                            tempFSID.Quantity() );
        cell.StorageFeesForRentedWarehouses( [Number] ( engineSales / guard( lce.PackagingCapacity(), 1 ) * guard( lcmr.WarehousingPrice(), 1 ) ) );
             
        // 外租库出库费用(发动机产量 / 包装容量[向上取整] * 料架出库单价)
        engineProductions := sum( macroPlan, FPImportData, tempFPID, 
                                  tempFPID.Unit()              = FinancialProductionReport::GetDefaultCCUnit() and
                                  tempFPID.Generation()        = ccerr.Generation()                            and
                                  tempFPID.MqbMlb()            = ccerr.MLB_MQB()                               and
                                  tempFPID.StartDate().Year()  = ccerc.StartDate().Year()                      and
                                  tempFPID.StartDate().Month() = ccerc.StartDate().Month(),
                                  tempFPID.Quantity() );
        cell.OutboundExpensesForRentedWarehouses( [Number] ( engineProductions / guard( lce.PackagingCapacity(), 1 ) * guard( lcmr.OutboundPrice(), 1 ) ) );
        
        // 外租库运输费用:发动机运输量 / 包装容量 / 装载容量(向上取整) * 料架运输单价
        transportationQuantity := sum( macroPlan, Unit.Lane.LaneLeg.Trip.ProductInTrip, tempPIT, 
                                       tempPIT.Product_MP().Generation()                                                = ccerr.Generation()        and
                                       tempPIT.Product_MP().MQBMLB()                                                    = ccerr.MLB_MQB()           and
                                       tempPIT.Trip().Departure().Date().Year()                                         = ccerc.StartDate().Year()  and
                                       tempPIT.Trip().Departure().Date().Month()                                        = ccerc.StartDate().Month() and
                                       tempPIT.Trip().LaneLeg().AsOriginStockingPointLeg().StockingPoint_MP().ID()      = "CC 厂内库"               and
                                       tempPIT.Trip().LaneLeg().AsDestinationStockingPointLeg().StockingPoint_MP().ID() = "长春外租库",
                                       tempPIT.Quantity()
                                      );
    //    info( "时间:", ccerc.StartDate().Format( "Y-M2-D2" ), "    运输数据:", transportationQuantity, "     运输单价:", lct.TransportPrice() );
        cell.ExternalRentalWarehouseTransportationCosts( [Number] ( transportationQuantity / guard( lce.PackagingCapacity(), 1 ) / guard( lct.LoadingCapacity(), 1 ) * guard( lct.TransportPrice(), 1 ) ) );
             
        // 外租库仓储费用:【350bar MQB料架总数量 - 所有350bar MQB总库存 / 包装容量 - 客户库料架数量】* 长春外租库空料架比例*料架仓储单价。发动机库存取Actual inventories里取到长春外租库该发动机的仓储量,料架总数量需要手动维护。
        cell.UnitPriceOfEmptyShelfStorage( lcmr.StoragePrice() );
        if ( ccerr.Generation() = "350bar" and ccerr.MLB_MQB() = "MQB" ) {
          cell.RentalWarehouseStorageFees( [Number] guard( ( cell.TotalQuantityOfMaterialRacks() - ceil( plannedInventory / lce.PackagingCapacity() ) - guard( mrcc.Quantity(), 0 ) ) * guard( mrpc.Quantity(), 1 ) * lcmr.StoragePrice() * ( ccerc.StartDate().StartOfNextMonth() - ccerc.StartDate() ), 0 ) );
        } else {
          cell.RentalWarehouseStorageFees( [Number] guard( ( cell.TotalQuantityOfMaterialRacks() - ceil( plannedInventory / lce.PackagingCapacity() ) ) * lcmr.StoragePrice()* ( ccerc.StartDate().StartOfNextMonth() - ccerc.StartDate() ), 0 ) );
        }
        
        // 清洗费用:发动机入库量 / 包装容量 * 料架清洗单价。发动机入库量取发动机销量,包装容量取自发动机成本表。料架清洗单价取料架成本表。
        cell.CleaningCost( [Number] ( engineProductions / guard( lce.PackagingCapacity(), 1 ) * lcmr.CleanPrice() ) );
        
        // 预计总费用
        cell.EstimatedTotalCost( cell.StorageFeesForRentedWarehouses()             + 
                                 cell.OutboundExpensesForRentedWarehouses()        + 
                                 cell.ExternalRentalWarehouseTransportationCosts() + 
                                 cell.RentalWarehouseStorageFees()                 +
                                 cell.CleaningCost()
                                );
                                
        // 系数
        cell.Coefficient( 1.05 );
        
        // 总费用
        cell.TotalCost( [Number] ( cell.EstimatedTotalCost() * cell.Coefficient() ) );
        
        cell.CC_EngineRackColumn( relset, ccerc );
      }
    }
    
    // 创建SUM行
    sumR   := macroPlan.CC_EngineRackRow( relnew, Generation := "SUM", MLB_MQB := "", Index := 2 );
    traverse ( macroPlan, CC_EngineRackColumn, ccerc ) {
      cell := sumR.CC_EngineRackCell( relnew );
      cell.CC_EngineRackColumn( relset, ccerc );
      
      cell.NumberOfEmptyShelves( sum( ccerc, CC_EngineRackCell, tempCCERCell, tempCCERCell.CC_EngineRackRow().Generation() <> "SUM", tempCCERCell.NumberOfEmptyShelves() ) );
      cell.StorageFeesForRentedWarehouses( sum( ccerc, CC_EngineRackCell, tempCCERCell, tempCCERCell.CC_EngineRackRow().Generation() <> "SUM", tempCCERCell.StorageFeesForRentedWarehouses() ) );
      cell.OutboundExpensesForRentedWarehouses( sum( ccerc, CC_EngineRackCell, tempCCERCell, tempCCERCell.CC_EngineRackRow().Generation() <> "SUM", tempCCERCell.OutboundExpensesForRentedWarehouses() ) );
      cell.ExternalRentalWarehouseTransportationCosts( sum( ccerc, CC_EngineRackCell, tempCCERCell, tempCCERCell.CC_EngineRackRow().Generation() <> "SUM", tempCCERCell.ExternalRentalWarehouseTransportationCosts() ) );
      cell.RentalWarehouseStorageFees( sum( ccerc, CC_EngineRackCell, tempCCERCell, tempCCERCell.CC_EngineRackRow().Generation() <> "SUM", tempCCERCell.RentalWarehouseStorageFees() ) );
      cell.CleaningCost( sum( ccerc, CC_EngineRackCell, tempCCERCell, tempCCERCell.CC_EngineRackRow().Generation() <> "SUM", tempCCERCell.CleaningCost() ) );
      cell.EstimatedTotalCost( sum( ccerc, CC_EngineRackCell, tempCCERCell, tempCCERCell.CC_EngineRackRow().Generation() <> "SUM", tempCCERCell.EstimatedTotalCost() ) );
      cell.Coefficient( 1.05 );
      cell.TotalCost( sum( ccerc, CC_EngineRackCell, tempCCERCell, tempCCERCell.CC_EngineRackRow().Generation() <> "SUM", tempCCERCell.TotalCost() ) );
    }
    
    // 创建SUM列
    sumC   := macroPlan.CC_EngineRackColumn( relnew, StartDate := Date::MaxDate() );
    traverse ( macroPlan, CC_EngineRackRow, ccerr ) {
      cell := ccerr.CC_EngineRackCell( relnew );
      cell.CC_EngineRackColumn( relset, sumC );
      
      cell.NumberOfEmptyShelves( sum( ccerr, CC_EngineRackCell, tempCCERCell, not tempCCERCell.CC_EngineRackColumn().StartDate().IsMaxInfinity(), tempCCERCell.NumberOfEmptyShelves() ) );
      cell.StorageFeesForRentedWarehouses( sum( ccerr, CC_EngineRackCell, tempCCERCell, not tempCCERCell.CC_EngineRackColumn().StartDate().IsMaxInfinity(), tempCCERCell.StorageFeesForRentedWarehouses() ) );
      cell.OutboundExpensesForRentedWarehouses( sum( ccerr, CC_EngineRackCell, tempCCERCell, not tempCCERCell.CC_EngineRackColumn().StartDate().IsMaxInfinity(), tempCCERCell.OutboundExpensesForRentedWarehouses() ) );
      cell.ExternalRentalWarehouseTransportationCosts( sum( ccerr, CC_EngineRackCell, tempCCERCell, not tempCCERCell.CC_EngineRackColumn().StartDate().IsMaxInfinity(), tempCCERCell.ExternalRentalWarehouseTransportationCosts() ) );
      cell.RentalWarehouseStorageFees( sum( ccerr, CC_EngineRackCell, tempCCERCell, not tempCCERCell.CC_EngineRackColumn().StartDate().IsMaxInfinity(), tempCCERCell.RentalWarehouseStorageFees() ) );
      cell.CleaningCost( sum( ccerr, CC_EngineRackCell, tempCCERCell, not tempCCERCell.CC_EngineRackColumn().StartDate().IsMaxInfinity(), tempCCERCell.CleaningCost() ) );
      cell.EstimatedTotalCost( sum( ccerr, CC_EngineRackCell, tempCCERCell, not tempCCERCell.CC_EngineRackColumn().StartDate().IsMaxInfinity(), tempCCERCell.EstimatedTotalCost() ) );
      cell.Coefficient( 1.05 );
      cell.TotalCost( sum( ccerr, CC_EngineRackCell, tempCCERCell, not tempCCERCell.CC_EngineRackColumn().StartDate().IsMaxInfinity(), tempCCERCell.TotalCost() ) );             
    }
  *]
}