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 ); 
 | 
      } 
 | 
    } 
 | 
  *] 
 | 
} 
 |