| 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 = "eMotor Assy (France)"  | 
|              )  | 
|     { | 
|       // 下线计划当前产线下的行 | 
|       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( 2024, 4, 17 ) // 测试时可以过滤时间 | 
|                )  | 
|       {          | 
|         for ( i := 1; i < 10; i++ ) { | 
|           nopcell := select( noprs, Elements.NewOfflinePlanCell, tempNOPC, tempNOPC.NewOfflinePlanColumn() = nopc and tempNOPC.OrderNr() = i ); | 
|           // 换型损失参数 | 
|           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 ) ) { | 
|             preNOPCell.Quantity( preNOPCell.Quantity() - cls.ChangeLossNumber() );                  | 
|     //        info( "当前列时间:", nopc.StartDate().Format( "Y-M2-D2" ),  | 
|     //              "    上一个产品当前序号:", preNOPCell.Order(), "    上一个产品数量:", preNOPCell.Quantity(), "    上一个产品名:", preNOPCell.NewOfflinePlanRow().ProductID(), | 
|     //              "    当前产品序号:"      , nopcell.Order()   , "    当前产品数量:"     , nopcell.Quantity(), "    当前产品名:"  , nopcell.NewOfflinePlanRow().ProductID() ); | 
|           } | 
|            | 
|           // 设置上一个生产的产品Cell | 
|           if ( not isnull( nopcell ) ) { | 
|             preNOPCell := nopcell; | 
|           } | 
|         } | 
|       } | 
|     } | 
|   *] | 
| } |