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
Quintiq file version 2.0
#parent: #root
StaticMethod DeductionOfReplacementLoss (
  MacroPlan macroPlan,
  OfflinePlanTable opt
)
{
  TextBody:
  [*
    // 保存上一份存档
    newOPT := OfflinePlanCell::SaveAsDraft( macroPlan, opt );
    
    // 执行换型损失
    allProductionLines := selectuniquevalues( newOPT, OfflinePlanRow, tempORR, true, tempORR.ProductionLine() );
    
    traverse ( allProductionLines, Elements, pl ) {
      oprs := selectset( newOPT, OfflinePlanRow, tempORT, tempORT.ProductionLine() = pl and ( tempORT.Type() = "1" or tempORT.Type() = "2" ) );
      
      traverse ( newOPT, OfflinePlanColumn, opc, 
                 opc.ColumnDate() >= macroPlan.StartOfPlanning().Date() 
    //             opc.ColumnDate() >= macroPlan.StartOfPlanning().Date() and opc.ColumnDate() <= Date::Construct( 2024, 4, 17 ) // 测试时可以过滤时间
                ) {
        for ( i := 1; i < 10; i++ ) {
          firstOrderCell  := select( oprs, Elements.OfflinePlanCell, tempOPC, tempOPC.OfflinePlanColumn() = opc and tempOPC.Value() = ( "#" + i.Format( "N(LPad0(2))" ) ) );
          secondOrderCell := select( oprs, Elements.OfflinePlanCell, tempOPC, tempOPC.OfflinePlanColumn() = opc and tempOPC.Value() = ( "#" + ( i + 1 ).Format( "N(LPad0(2))" ) ) );
          // 换型损失参数
          cls        := select( macroPlan, ChangeLossSetting, tempCLS, 
                                guard( tempCLS.ProductFirst().ID()  = firstOrderCell.OfflinePlanRow().ProductID() , false ) and
                                guard( tempCLS.ProductSecond().ID() = secondOrderCell.OfflinePlanRow().ProductID(), false ) and
                                guard( tempCLS.StartDate()          <= opc.ColumnDate()                           , false ) and
                                guard( tempCLS.EndDate()            >= opc.ColumnDate()                           , false )
                               );
          if ( not isnull( firstOrderCell ) and not isnull( secondOrderCell ) and not isnull( cls ) ) {
            firstQuantityCell := select( oprs, Elements.OfflinePlanCell, tempOPC, 
                                         tempOPC.OfflinePlanColumn() = opc     and 
                                         tempOPC.OfflinePlanRow().Type() = "1" and 
                                         tempOPC.OfflinePlanRow().ProductID() = firstOrderCell.OfflinePlanRow().ProductID()
                                        );
            firstQuantityCell.Value( [String] ( [Number]firstQuantityCell.Value() - cls.ChangeLossNumber() ) );                 
    //        info( "当前列时间:", opc.ColumnDate().Format( "Y-M2-D2" ), "    当前序号:", i, "    单元格的值:", firstOrderCell.Value(), "    产品名:", firstOrderCell.OfflinePlanRow().ProductID(),
    //              "下一个序号:", i + 1, "    单元格的值:", secondOrderCell.Value(), "    产品名:", secondOrderCell.OfflinePlanRow().ProductID() );
          }
        }
      }
    }
    
    // 重置总计行
    totalOPRs := selectset( newOPT, OfflinePlanRow, tempOPR, tempOPR.Type() = "3" );
    traverse ( newOPT, OfflinePlanColumn, opc, opc.OfflinePlanCell( relsize ) > 0 and opc.ColumnDate() >= macroPlan.StartOfPlanning().Date() ) {
      traverse ( totalOPRs, Elements, totalOPR ) {
        total     := sum( opc, OfflinePlanCell, tempOPC, tempOPC.OfflinePlanRow().ProductionLine() = totalOPR.ProductionLine() and tempOPC.OfflinePlanRow().Type() = "1", [Real]tempOPC.Value() );
        totalCell := select( totalOPR, OfflinePlanCell, tempOPC, tempOPC.OfflinePlanColumn() = opc );
        totalCell.Value( [String]total );
      }
    }
  *]
}