Quintiq file version 2.0 
 | 
#parent: #root 
 | 
StaticMethod DeductionOfReplacementLoss ( 
 | 
  MacroPlan macroPlan, 
 | 
  NewOfflinePlanTable nopt 
 | 
) 
 | 
{ 
 | 
  TextBody: 
 | 
  [* 
 | 
    // 保存上一份存档 
 | 
    newNOPT := NewOfflinePlanCell::SaveAsDraft( macroPlan, nopt ); 
 | 
     
 | 
    // 执行换型损失 
 | 
    allProductionLines := selectuniquevalues( newNOPT, NewOfflinePlanRow, tempNOPR, true, tempNOPR.ProductionLine() ); 
 | 
     
 | 
    traverse ( allProductionLines, Elements, pl 
 | 
    //           , pl = "CC MoMo"  
 | 
             )  
 | 
    { 
 | 
      // 下线计划当前产线下的行 
 | 
      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, 16 ) // 测试时可以过滤时间 
 | 
               )  
 | 
      {          
 | 
        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.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; 
 | 
          } 
 | 
        } 
 | 
      } 
 | 
    } 
 | 
  *] 
 | 
} 
 |