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
Quintiq file version 2.0
#parent: #root
StaticMethod CreateData (
  MacroPlan macroPlan
)
{
  Description: '创建数据'
  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() and 
               ( pisp.StockingPointID().Regex( "CC" ) or pisp.StockingPointID().Regex( "DL" ) or pisp.StockingPointID().Regex( "大连" ) or pisp.StockingPointID().Regex( "长春" ) ) ) {
      // 当前pisp所处地点
      factory             := ifexpr( pisp.StockingPointID().Regex( "CC" ) or pisp.StockingPointID().Regex( "长春" ), "长春工厂", "大连工厂" );
      factoryAbbreviation := ifexpr( pisp.StockingPointID().Regex( "CC" ) or pisp.StockingPointID().Regex( "长春" ), "CC", "DL" );
      
      // 创建行
      ppr := select( macroPlan, PackagingPlanRow, tempPPR, tempPPR.ProductID() = pisp.ProductID() and tempPPR.Factory() = factory );
      if ( isnull( ppr ) ) {
        ppr := macroPlan.PackagingPlanRow( relnew, ProductID := pisp.ProductID(), Factory := factory, Category := guard( pisp.Product_MP().ParentID(), "" ) );
      }
      
      // 循环pispippl
      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 ); 
          cell.PackagingPlanColumn( relset, ppc );
        }
        
        // 设置调出
        traverse ( pispipl, AsDeparturePISPIP, pit,
                   pit.Quantity()                > 0                                                                         and
                   pit.Trip().LaneLeg().AsOriginStockingPointLeg().StockingPoint_MP().ID().Regex( factoryAbbreviation )      and
                   TransferPlanRow::IdentifyTheFactory( pit.Trip().LaneLeg().AsOriginStockingPointLeg().StockingPoint_MP() ) <> TransferPlanRow::IdentifyTheFactory( pit.Trip().LaneLeg().AsDestinationStockingPointLeg().StockingPoint_MP() )
                  ) 
        {
          cell.Out( cell.Out() + pit.Quantity() );
        }
        
        // 设置调进
        traverse ( pispipl, AsArrivalPISPIP, pit,
                   pit.Quantity()              > 0                                                                           and
                   pit.Trip().LaneLeg().AsDestinationStockingPointLeg().StockingPoint_MP().ID().Regex( factoryAbbreviation ) and
                   TransferPlanRow::IdentifyTheFactory( pit.Trip().LaneLeg().AsOriginStockingPointLeg().StockingPoint_MP() ) <> TransferPlanRow::IdentifyTheFactory( pit.Trip().LaneLeg().AsDestinationStockingPointLeg().StockingPoint_MP() )
                  ) 
        {
          cell.TransferIn( cell.TransferIn() + pit.Quantity() );
        }
        
        // 大连工厂设置值
        if ( factory = "大连工厂" ) {
          // 净需求&剩余库存&供应量
          cell.NetDemand( cell.NetDemand() + pispipl.DependentDemandAndSalesDemandQuantity() );
          cell.EndingInventory( [Number] ( cell.EndingInventory() + pispipl.InventoryLevelEnd() ) );
        }
        
        // 长春工厂设置值
        if ( factory = "长春工厂" ) {
          // 剩余库存&供应量
          cell.EndingInventory( [Number] ( cell.EndingInventory() + pispipl.InventoryLevelEnd() ) );
          
          // 净需求【只取线边库】&包装库存&非包装库存
          if ( pisp.StockingPointID().Regex( "外租库" ) ) {
            cell.CC_PackagingInventory( pispipl.InventoryLevelEnd() );
          } else if ( pisp.StockingPointID().Regex( "线边库" ) ) {
            cell.CC_UnpackagedInventory( pispipl.InventoryLevelEnd() );
            cell.NetDemand( cell.NetDemand() + pispipl.DependentDemandAndSalesDemandQuantity() );
          }
        }
        
        // 设置New Supply,纯生产值
        traverse ( pispipl, NewSupply, ns, ns.PeriodTask_MP().istype( PeriodTaskOperation ) ) {
          cell.NewSupply( cell.NewSupply() + ns.Quantity() );
        }
        
        // 设置前一天库存
        if ( pispipl.Start().Date() = macroPlan.StartOfPlanning().Date() ) {
          prePISPIPL  := pispipl.PreviousPlanningPISPIP().astype( ProductInStockingPointInPeriodPlanningLeaf ); // 前一个pispippl
          // 创建计划前一天格子
          preCell := select( ppr, PackagingPlanCell, tempPPCell, tempPPCell.PackagingPlanColumn() = planPre );
          if ( isnull( preCell ) ) {
            preCell := ppr.PackagingPlanCell( relnew );
            preCell.EndingInventory( [Number]prePISPIPL.InventoryLevelEnd() );
            preCell.PackagingPlanColumn( relset, planPre );
          } else {
            preCell.EndingInventory( [Number] ( preCell.EndingInventory() + prePISPIPL.InventoryLevelEnd() ) );
          }
        }
      }
    }
    
    Transaction::Transaction().Propagate( attribute( PackagingPlanRow, FactoryAbbreviation ) );
    PackagingPlanCell::CalculationPackagingPlanProperties();
    Transaction::Transaction().Propagate( relation( PackagingPlanCell, Next ) );
  *]
}