lazhen
2024-10-18 06fce9cb4260a08854643380bc981f9e6c6c8ed0
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
Quintiq file version 2.0
#parent: #root
StaticMethod CreateData (
  MacroPlan macroPlan
)
{
  TextBody:
  [*
    macroPlan.MachineLogisticsCostReportRow( relflush );
    macroPlan.MachineLogisticsCostReportColumn( relflush );
    
    // 创建行
    categories := selectuniquevalues( macroPlan, Product_MP, tempPMP, tempPMP.IsLeaf()                           and
                                      exists( tempPMP, AllParent.AsParent, tempPMP1, tempPMP1.ID() = "机加件" ),  
                                      tempPMP.ParentID() );
    traverse ( categories, Elements, c ) {
      macroPlan.MachineLogisticsCostReportRow( relnew, Factory := "大连工厂", Category := c  );
      macroPlan.MachineLogisticsCostReportRow( relnew, Factory := "长春工厂", Category := c );
    }
    
    // 创建列
    indexDate := macroPlan.StartOfPlanning().Date().StartOfMonth();
    for ( i := 0; i < 12; i++ ) {
      macroPlan.MachineLogisticsCostReportColumn( relnew, StartDate := indexDate );
      indexDate := indexDate.StartOfNextMonth();
    }
    
    // 创建单元格
    traverse ( macroPlan, MachineLogisticsCostReportRow, mlcrr ) { // 循环行
      info( "当前遍历的行:", mlcrr.Factory(), " ", mlcrr.Category() );
      traverse ( macroPlan, MachineLogisticsCostReportColumn, mlcrc ) { // 循环列
      
        // 机加成本参数
        lcm  := select( macroPlan, LogisticsCostMachining, tempLCM, tempLCM.Factory() = mlcrr.Factory() and tempLCM.Product() = mlcrr.Category()
                        and tempLCM.StartDate() <= mlcrc.StartDate() and tempLCM.EndDate() >= mlcrc.StartDate().StartOfNextMonth() );
        
        // 运输成本参数
        lct  := select( macroPlan, LogisticsCostTransport, tempLCT, 
                        tempLCT.Product()     = mlcrr.Category()                                      and 
                        tempLCT.Origin()      = mlcrr.Factory() + " " + mlcrr.Category() + "外租库"   and 
                        tempLCT.Destination() = mlcrr.Factory() + " " + mlcrr.Category() + "线边库" );
        lct1 := select( macroPlan, LogisticsCostTransport, tempLCT, 
                        tempLCT.Product()     = mlcrr.Category()                                                   and 
                        tempLCT.Origin()      = ifexpr( mlcrr.Factory() = "大连工厂", "大连厂内库", "CC 厂内库" ) and 
                        tempLCT.Destination() = ifexpr( mlcrr.Factory() = "大连工厂", "大连外租库", "长春外租库" ) );
                        
         // 当前月末最后一天日期                
        lastDayOfThisMonth := mlcrc.StartDate().StartOfNextMonth() - 1; 
        
        cell := mlcrr.MachineLogisticsCostReportCell( relnew );
          
        // 设置包装费用(包装量 * 包装单价)
        packageQuantity := sum( macroPlan, PackagingPlanRow.PackagingPlanCell, tempPPC, 
                                tempPPC.PackagingPlanRow().Category()             = mlcrr.Category()          and
                                tempPPC.PackagingPlanRow().Factory()              = mlcrr.Factory()           and
                                tempPPC.PackagingPlanColumn().StartDate().Year()  = mlcrc.StartDate().Year()  and
                                tempPPC.PackagingPlanColumn().StartDate().Month() = mlcrc.StartDate().Month(),
                                tempPPC.Package() );
        cell.PackingCharges( packageQuantity * guard( lcm.PackagePrice(), 1 ) );
          
        // 设置拆包费用(拆包量 * 拆包单价)
        unpackingQuantity := sum( macroPlan, PackagingPlanRow.PackagingPlanCell, tempPPC, 
                                  tempPPC.PackagingPlanRow().Category()             = mlcrr.Category()          and
                                  tempPPC.PackagingPlanRow().Factory()              = mlcrr.Factory()           and
                                  tempPPC.PackagingPlanColumn().StartDate().Year()  = mlcrc.StartDate().Year()  and
                                  tempPPC.PackagingPlanColumn().StartDate().Month() = mlcrc.StartDate().Month(),
                                  tempPPC.Unpacking() );
        cell.UnpackingCost( unpackingQuantity * guard( lcm.UnpackingPrice(), 1 ) );
          
        // 设置缓冲纸费用(包装类 * 缓冲纸单价)
        cell.BufferPaperCost( packageQuantity * guard( lcm.BufferPaperPrice(), 1 ) );
          
          // 设置木箱单价
        cell.WoodenCratePriceReal( guard( lcm.WoodenCratePrice(), 1 ) );
          
        // 设置调拨费用(调拨数量 / 包装容量 / 装载容量 * 运输单价)
        transferQuantity := sum( macroPlan, TransferPlanRow.TransferPlanCell, tempTPC,
                                 tempTPC.TransferPlanRow().Category()                      = mlcrr.Category()                                               and
                                 tempTPC.TransferPlanRow().Name()                          = ifexpr( mlcrr.Factory() = "大连工厂", "CC to DL", "DL to CC" ) and
                                 guard( tempTPC.TransferPlanColumn().ColumnDate().Year()   = mlcrc.StartDate().Year(), false )                              and
                                 guard(  tempTPC.TransferPlanColumn().ColumnDate().Month() = mlcrc.StartDate().Month(), false ),
                                 [Number]tempTPC.Value() );
        cell.TransferCost( transferQuantity / guard( lcm.PackagingCapacity(), 1 ) / guard( lct.LoadingCapacity(), 1 ) * guard( lct.TransportPrice(), 1 ) );
          
        // 外租库入库费用(入库量[包装量] / 包装容量 * 入库单价)
        cell.StorageFeesForRentedWarehouses( packageQuantity / guard( lcm.PackagingCapacity(), 1 ) * guard( lcm.WarehousingPrice(), 1 ) );
          
        // 外租库出库费用(出库量[拆包量] / 包装容量 * 出库单价)
        cell.OutboundExpensesForRentedWarehouses( unpackingQuantity / guard( lcm.PackagingCapacity(), 1 ) * guard( lcm.OutboundPrice(), 1 ) );
          
        // 外租库运输费用(运输数量 / 包装容量 / 装载容量 * 运输单价)
        transportationQuantity := sum( macroPlan, Unit.Lane.LaneLeg.Trip.ProductInTrip, tempPIT, 
                                       tempPIT.Product_MP().ParentID()                                                  =  mlcrr.Category()   and
                                       tempPIT.Trip().Departure().Date()                                                >= mlcrc.StartDate()  and
                                       tempPIT.Trip().Arrival().Date()                                                  <= lastDayOfThisMonth and
                                       tempPIT.Trip().LaneLeg().AsOriginStockingPointLeg().StockingPoint_MP().ID()      = "CC 厂内库"         and
                                       tempPIT.Trip().LaneLeg().AsDestinationStockingPointLeg().StockingPoint_MP().ID() = "长春外租库",
                                       tempPIT.Quantity()
                                      );
        cell.ExternalRentalWarehouseTransportationCosts( transportationQuantity / guard( lcm.PackagingCapacity(), 1 ) / guard( lct1.LoadingCapacity(), 1 ) * guard( lct1.TransportPrice(), 1 ) );
        
        // 外租库仓储费用:仓储数量/包装容量*仓储单价
        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().Product_MP().ParentID()                                         =  mlcrr.Category()   and
                                 tempPISPIP.Start().Date()                                                                              >= mlcrc.StartDate()  and
                                 tempPISPIP.End().Date()                                                                                <= lastDayOfThisMonth and
                                 tempPISPIP.ProductInStockingPoint_MP().StockingPointID()                                               =  ifexpr( mlcrr.Factory() = "大连工厂", "大连外租库", "长春外租库" ),
                                 tempPISPIP.PlannedInventoryLevelEnd() );
        cell.RentalWarehouseStorageFees( plannedInventory / guard( lcm.PackagingCapacity(), 1 ) * guard( lcm.StoragePrice(), 1 ) );
        
        cell.MachineLogisticsCostReportColumn( relset, mlcrc );
      }
    }
  *]
}