lihongji
2024-12-10 a520b98f6d6951245266e7b80ad3b3e22aa8af72
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
Quintiq file version 2.0
#parent: #root
StaticMethod DeductionOfReplacementLoss (
  MacroPlan macroPlan,
  NewOfflinePlanTable nopt,
  Entitys entitys
)
{
  TextBody:
  [*
    // 保存上一份存档
    newNOPT := NewOfflinePlanCell::SaveAsDraft( macroPlan, nopt );
    
    // 执行换型损失
    allProductionLines := selectuniquevalues( newNOPT, NewOfflinePlanRow, tempNOPR, true, tempNOPR.ProductionLine() );
    
    traverse ( allProductionLines, Elements, pl
    //           , pl = "CC ZKG" 
               , exists( entitys, Elements.astype( Unit ), tempU, tempU.Name() = pl ) 
             ) 
    {
      // 下线计划当前产线下的行
      noprs      := selectset( newNOPT, NewOfflinePlanRow, tempNOPR, tempNOPR.ProductionLine() = pl and tempNOPR.Type() = "1" );
      
      // 上一个生产的产品Cell
      preNOPCell := null( NewOfflinePlanCell );
      
      traverse ( newNOPT, NewOfflinePlanColumn, nopc
    //             , nopc.StartDate() >= macroPlan.StartOfPlanning().Date() and nopc.StartDate() <= Date::Construct( 2025, 1, 7 ) // 测试时可以过滤时间
               ) 
      {         
        for ( i := 1; i < 10; i++ ) {
          nopcell := select( noprs, Elements.NewOfflinePlanCell, tempNOPC, tempNOPC.NewOfflinePlanColumn() = nopc and tempNOPC.OrderNr() = i and tempNOPC.Order() <> "" );
          
          // 换型损失参数
          cls     := select( macroPlan, ChangeLossSetting, tempCLS,
                             tempCLS.Unit().ID()          = pl                                                      and 
                             tempCLS.ProductFirst().ID()  = guard( preNOPCell.NewOfflinePlanRow().ProductID(), "" ) and
                             tempCLS.ProductSecond().ID() = guard( nopcell.NewOfflinePlanRow().ProductID(), "" )    and
                             tempCLS.StartDate()          <= nopc.StartDate()                                       and
                             tempCLS.EndDate()            >= nopc.StartDate()                       
                            );
    
          // 扣减换型损失
          if ( not isnull( preNOPCell ) and not isnull( nopcell ) and not isnull( cls ) ) {
    //        info( "当前产品序号:", nopcell.OrderNr(),  "    ", nopcell.Order(), "    ", i );
    //        info( "当前列时间:", nopc.StartDate().Format( "Y-M2-D2" ), 
    //              "    上一个产品当前序号:", preNOPCell.Order(), "    上一个产品数量:", preNOPCell.Quantity(), "    上一个产品名:", preNOPCell.NewOfflinePlanRow().ProductID(),
    //              "    当前产品序号:"      , nopcell.Order()   , "    当前产品数量:"     , nopcell.Quantity(), "    当前产品名:"  , nopcell.NewOfflinePlanRow().ProductID(), 
    //              "    需要扣减的数量:", cls.ChangeLossNumber() );
            preNOPCell.Quantity( preNOPCell.Quantity() - cls.ChangeLossNumber() ); 
          }
          
          // 设置上一个生产的产品Cell
          if ( not isnull( nopcell ) ) {
            preNOPCell := nopcell;
          }
        }
      }
    }
  *]
}