lihongji
2024-10-12 f1de76007e7834e17d87712e3342efd84876c200
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
Quintiq file version 2.0
#parent: #root
StaticMethod RefreshOfflinePlan (
  MacroPlan macroPlan
)
{
  TextBody:
  [*
    macroPlan.NewOfflinePlanTable( relflush );
    
    nopt := macroPlan.NewOfflinePlanTable( relnew, SaveDateTime := DateTime::ActualTime() );
    
    // 生成下线计划表【一条产线在同一天不会产生两次相同产品的周期任务】
    traverse ( macroPlan, Unit, u, u.HasCapacityTypeTime() 
    //           and u.Name() = "eMotor Assy (France)" // 测试本地场景时可以过滤
    //           and u.Name() = "DL-MoMo"              // 测试实际场景时可以过滤
              ) 
    {
      // 循环遍历周期任务的NewSupply【生成明细下线计划】
      traverse ( u, Operation, o ) {
        traverse ( o, PeriodTaskOperation.NewSupply, ns ) {
          // ProductInStockingPoint_MP
          pisp     := ns.AsProductionSupply().ProductInStockingPoint_MP();
          // ProductInStockingPointInPeriodPlanningLeaf
          pispippl := ns.ProductInStockingPointInPeriodPlanningLeaf();
          // Period_MP
          pmp      := pispippl.Period_MP();
          // ShiftPattern
          sp       := ns.PeriodTask_MP().UnitPeriod().astype( UnitPeriodTimeBase ).ShiftPattern();
          // ShiftDayTime
          sdt      := select( sp, ShiftDayTime, tempSDT, tempSDT.Name() = tempSDT.ShiftPattern().Name() );
          
          // 生成下线计划【产线明细】行
          detailedNOPR   := select( nopt, NewOfflinePlanRow, tempNOPR, tempNOPR.ProductionLine() = u.ID() and tempNOPR.ProductID() = pisp.ProductID() and tempNOPR.Type() = "1" );
          if ( isnull( detailedNOPR ) ) {
            detailedNOPR := nopt.NewOfflinePlanRow( relnew, ProductionLine := u.ID(), ProductID := pisp.ProductID(), Type := "1" );
          }
          
          // 生成下线计划列
          nopc   := select( nopt, NewOfflinePlanColumn, tempNOPC, tempNOPC.StartDate() = pmp.StartDate() and tempNOPC.EndDate() = pmp.EndDate() );
          if ( isnull( nopc ) ) {
            nopc := nopt.NewOfflinePlanColumn( relnew, StartDate := pmp.StartDate(), EndDate := pmp.EndDate() );
          }
          
          // 生成下线计划【产线明细】单元格
          detaileNOPCell := select( detailedNOPR, NewOfflinePlanCell, tempNOPCell, tempNOPCell.NewOfflinePlanColumn() = nopc );
          if ( isnull ( detaileNOPCell ) ) {
            detaileNOPCell := detailedNOPR.NewOfflinePlanCell( relnew, 
                                                               Quantity          := ns.Quantity().Round( 0 ), 
                                                               InventoryWeight   := pispippl.InventoryLevelEnd() - pispippl.MinInventoryLevel(),
                                                               ShiftPatternName  := guard( sdt.Name(), "" ),
                                                               ShiftPatternStart := guard( sdt.StartDateTime().Format( "H:m" ), "" ),
                                                               ShiftPatternEnd   := guard( sdt.EndDateTIme().Format( "H:m" ), "" ) );
            detaileNOPCell.NewOfflinePlanColumn( relset, nopc );
          }
        }
      }
      
      // 设置生产顺序【对下线计划明细生效】
      
      
      // 【生成合计下线计划】
      totalNOPR   := nopt.NewOfflinePlanRow( relnew, ProductID := "All", ProductionLine := u.ID(), Type := "2" );
      detailNOPRs := selectset( nopt, NewOfflinePlanRow, tempNOPR, tempNOPR.ProductionLine() = u.ID() and tempNOPR.Type() = "1" );
      traverse ( detailNOPRs, Elements, detailNOPR ) {
        traverse ( detailNOPR, NewOfflinePlanCell, detailNOPCell ) {
          // 生产下线计划【产线合计】单元格
          totalNOPRCell   := select( totalNOPR, NewOfflinePlanCell, tempNOPCell, tempNOPCell.NewOfflinePlanColumn() = detailNOPCell.NewOfflinePlanColumn() );
          if ( isnull( totalNOPRCell ) ) {
            totalNOPRCell := totalNOPR.NewOfflinePlanCell( relnew );
            totalNOPRCell.NewOfflinePlanColumn( relset, detailNOPCell.NewOfflinePlanColumn() ); // 设置列
            // 将明细单元格关联到合计单元格
            totalNOPRCell.Detailed( relinsert, detailNOPCell );
          } else {
            // 将明细单元格关联到合计单元格
            totalNOPRCell.Detailed( relinsert, detailNOPCell );
          }
        }
      }
      
      // 补齐空格子
      traverse ( nopt, NewOfflinePlanRow, nopr ) {
        traverse ( nopt, NewOfflinePlanColumn, nopc ) {
          cell   := select( nopr, NewOfflinePlanCell, tempNOPCell, tempNOPCell.NewOfflinePlanColumn() = nopc );
          if ( isnull( cell ) ) {
            cell := nopr.NewOfflinePlanCell( relnew );
            cell.NewOfflinePlanColumn( relset, nopc );
          }
        }
      }
    }
  *]
}