lazhen
2024-10-08 c75cd6f6eb1e06a27e28c26ca9df0324b7ed675f
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
Quintiq file version 2.0
#parent: #root
StaticMethod GenerateReport (
  MacroPlan macroPlan
)
{
  TextBody:
  [*
    macroPlan.PackagingPlanRow( relflush );
    macroPlan.PackagingPlanColumn( relflush );
    
    // 创建计划前一天列
    planPre     := macroPlan.PackagingPlanColumn( relnew, StartDate := macroPlan.StartOfPlanning().Date() - 1 );
    
    // 生成报表
    traverse ( macroPlan, Product_MP.ProductInStockingPoint_MP, pisp, pisp.IsLeaf() and not pisp.IsSystem() ) {
      // 创建行
      ppr := select( macroPlan, PackagingPlanRow, tempPPR, tempPPR.ProductID() = pisp.ProductID() and tempPPR.StockingPointID() = pisp.StockingPointID() );
      if ( isnull( ppr ) ) {
        ppr := macroPlan.PackagingPlanRow( relnew, ProductID := pisp.ProductID(), StockingPointID := pisp.StockingPointID(), Factory := "大连工厂", Category := "ZKG" );
      }
      
      // 创建计划前一天格子
      planPreCell      := ppr.PackagingPlanCell( relnew, PackagingPlanColumn := planPre, InitialPackagingInventory := 200 );
      
      // 出发地库存点Trip
      originTrips      := selectset( macroPlan, Unit.Lane.LaneLeg.Trip, tempT, tempT.LaneLeg().AsOriginStockingPointLeg().StockingPoint_MP().ID() = pisp.StockingPointID() );
      // 目的地库存点Trip
      destinationTrips := selectset( macroPlan, Unit.Lane.LaneLeg.Trip, tempT, tempT.LaneLeg().AsDestinationStockingPointLeg().StockingPoint_MP().ID() = pisp.StockingPointID() );
      
      traverse ( pisp, ProductInStockingPointInPeriodPlanning.astype( ProductInStockingPointInPeriodPlanningLeaf ), pispipl, not pispipl.IsPeriodFrozen() ) {
        // 创建列
        ppc := select( macroPlan, PackagingPlanColumn, tempPPC, tempPPC.StartDate() = pispipl.Start().Date() );
        if ( isnull( ppc ) ) {
          ppc := macroPlan.PackagingPlanColumn( relnew, StartDate := pispipl.Start().Date() );
        }
        
        // 创建单元格
        cell := select( ppr, PackagingPlanCell, tempPPCell, tempPPCell.PackagingPlanColumn() = ppc );
        if ( isnull( cell ) ) {
          cell := ppr.PackagingPlanCell( relnew, NetDemand := pispipl.DependentDemandAndSalesDemandQuantity() - pispipl.NewSupplyQuantity(), EndingInventory := pispipl.InventoryLevelEnd() );
          cell.PackagingPlanColumn( relset, ppc );
        }
        
        // 设置调出&调进
        outs := selectset( originTrips, Elements, tempT, tempT.Departure().Date() = pispipl.Start().Date() );
        traverse ( outs, Elements, out ) {
          cell.Out( cell.Out() + out.Quantity() );
        }
        
        transferIns := selectset( destinationTrips, Elements, tempT, tempT.Arrival().Date() = pispipl.Start().Date() );
        traverse ( transferIns, Elements, ti ) {
          cell.TransferIn( cell.TransferIn() + ti.Quantity() );
        }
        
        // 设置前一天库存
        if ( pispipl.Start().Date() = macroPlan.StartOfPlanning().Date() ) {
    //      prePISPIPL := pispipl.PreviousPlanningPISPIP().astype( ProductInStockingPointInPeriodPlanningLeaf );
          planPreCell.EndingInventory( 2000 );
        }
      }
    }
    
    Transaction::Transaction().Propagate( attribute( PackagingPlanRow, FactoryAbbreviation ) );
    PackagingPlanCell::CalculationPackagingPlanProperties();
    Transaction::Transaction().Propagate( relation( PackagingPlanCell, Next ) );
    
    // 设置包装&拆包-数量
    traverse ( macroPlan, PackagingPlanRow, ppr, ( ppr.ProductID() = "Windshield" and ppr.StockingPointID() = "Bosch" ) or ( ppr.ProductID() = "Windshield" and ppr.StockingPointID() = "Components (Spain)" ) ) {
      traverse ( ppr, PackagingPlanCell, ppc/*, ppc.StartDate() = Date::Construct( 2020, 4, 1 )*/ ) {
        // 设置包装数量
        if ( ppc.PackagingInventory() < ppc.Out() ) { // 包装库存是否小于调出
          prePPC                := ppc.Previous();
          needPackagingQuantity := ppc.Out() - prePPC.PackagingInventory();
          while ( not isnull( prePPC ) and needPackagingQuantity > 0.0 ) {
            // 获取包装lotsize
            ppls                   := select( macroPlan, PackagingPlanLotSize, tempPPLS, tempPPLS.Factory() =  ppc.PackagingPlanRow().Factory()    and 
                                                                                        tempPPLS.ProductID() = ppc.PackagingPlanRow().ProductID() );
            
            // 获取最大包装数量
            maxPackageReflection   := Reflection::FindAttribute( "PackagingPlanCapability", ppc.PackagingPlanRow().FactoryAbbreviation() + "_" + ppc.PackagingPlanRow().Category() + "_Package" );
            maxPackageQuantity     := maxPackageReflection.GetNumber( macroPlan.PackagingPlanCapability() );
            
            // 获取最终包装数量
            finalPackagingQuantity := minvalue( ceil( needPackagingQuantity / ppls.LotSize() ), ceil( ( maxPackageQuantity - prePPC.Package() ) / ppls.LotSize() ) ) * ppls.LotSize();
            needPackagingQuantity  := needPackagingQuantity - finalPackagingQuantity;
            
            // 设置包装值
            prePPC.Package( prePPC.Package() + finalPackagingQuantity );
            
            //debuginfo( "需要包装数量:", needPackagingQuantity, "    lotsize: ", ppls.LotSize(), "    最大包装数量:", maxPackageQuantity, "    最终补的数量:", finalPackagingQuantity );
            PackagingPlanCell::CalculationPackagingPlanProperties();
          
            prePPC := prePPC.Previous();
          }
        }
        
        // 设置拆包数量
        if ( ppc.TransferIn() > 0.0 ) { // 有调入数量
          // 获取包装lotsize
          ppls                 := select( macroPlan, PackagingPlanLotSize, tempPPLS, tempPPLS.Factory() =  ppc.PackagingPlanRow().Factory()    and 
                                                                                     tempPPLS.ProductID() = ppc.PackagingPlanRow().ProductID() );
        
          // 设置拆包值
          ppc.Unpacking( ppc.TransferIn() );
        }
      }
    }
  *]
}