Quintiq file version 2.0 
 | 
#parent: #root 
 | 
Method LimitSuggestedQuantityToAvailableCapacity ( 
 | 
  Real quantity, 
 | 
  Boolean usecurrentcapacity 
 | 
) declarative remote as Real 
 | 
{ 
 | 
  Description: 'Only limit the suggested quantity to remaining available capacity' 
 | 
  TextBody: 
 | 
  [* 
 | 
    // soh yee Jun-25-2013 (created) 
 | 
     
 | 
    up := this.UnitPeriod(); 
 | 
    value := quantity; 
 | 
     
 | 
    // Passed in quantity, convert to quantity to process as unit capacity is calculated based on quantity to process setting. 
 | 
    // Only limit the suggested quantity to remaining capacity. 
 | 
    if( not up.IsPlannedInfinite() ) 
 | 
    { 
 | 
      ontype( up ) 
 | 
      { 
 | 
        UnitPeriodTimeBase as upt: 
 | 
        { 
 | 
          freecapacity := ifexpr( usecurrentcapacity, upt.FreeCapacity() , upt.TotalAvailableCapacity() ) * this.RequiredCapacity(); 
 | 
          value := freecapacity.HoursAsReal(); 
 | 
        } 
 | 
        UnitPeriodQuantityBase as upq: 
 | 
        { 
 | 
          value := ifexpr( usecurrentcapacity, upq.FreeCapacity(), upq.TotalAvailableCapacity() ); 
 | 
        } 
 | 
      } 
 | 
     
 | 
      // Find the max quantity allowed by taking lot size into consideration. 
 | 
      // E.g., if available capacity = 1000, lot size = 30, process max quantity = 3000, the actual max quantity is 990. If we pass in 1000 to the next method, 
 | 
      // it will round to 1020 instead of 990. 
 | 
      if( this.Process_MP().HasLotSize() ) 
 | 
      { 
 | 
        lotsize := this.Process_MP().LotSize(); 
 | 
        value := floor( value / lotsize ) * lotsize; 
 | 
      } 
 | 
      quantityout := guard( value / this.Process_MP().QuantityToProcessFactor(), value );    // Convert the quantity to process back to quantity out again. 
 | 
      value := minvalue( quantity, quantityout );                       // Take the min value between available capacity and unfulfilled quantity, in quantity out. 
 | 
    } 
 | 
     
 | 
    return value; 
 | 
  *] 
 | 
} 
 |