Quintiq file version 2.0 
 | 
#parent: #root 
 | 
Function CalcSystemFulfilledQuantity 
 | 
{ 
 | 
  Description: 'Set fulfillment quantity greedy based on demand type' 
 | 
  TextBody: 
 | 
  [* 
 | 
    /* gooi: looks like not needed except on leaf planning 
 | 
    if( this.IsPlanning() and not this.MacroPlan().IsImporting() ) 
 | 
    { 
 | 
      if( this.ProductInStockingPoint_MP().IsNegativeInventoryAllowed() ) 
 | 
      { 
 | 
        // Only dependent demand of input group has optimizer fulfilled quantity. 
 | 
        traverse( this, DependentDemand, d, 
 | 
                  d.OptimizerFulfilledQuantity() = 0 )   // Dependent demand in input group can be fulfilled by optimizer, although negative inventory is allowed 
 | 
        { 
 | 
          d.SystemFulfilledQuantity( d.Quantity() ); 
 | 
        } 
 | 
      } 
 | 
      else 
 | 
      { 
 | 
        totalremaining := this.SupplyQuantity() - this.OptimizerFulfilledDemandQuantity() - this.OptimizerReservedQuantity(); 
 | 
        //we don't allow total remaining qty to go below -ve 
 | 
        //although totalremaining = 0, still need to proceed with the greedy to reset the demands systemfulfilledquantity to 0 
 | 
        totalremaining := maxvalue( totalremaining, 0.0 ); 
 | 
     
 | 
        // DEPENDENT DEMAND 
 | 
        this.CalculateDependentDemandSystemFulfilledQuantity( totalremaining ); 
 | 
     
 | 
        // SALES DEMAND 
 | 
        if( this.ProductInStockingPoint_MP().IsLeaf() ) // fulfill sales demand from leaf pispip only 
 | 
        { 
 | 
          // To minus the disaggregated sales demand in period quantity that is fulfilled by manual planning 
 | 
          totalremaining := totalremaining - sum( this, DisaggregatedSalesDemandInPeriod, dsdip, dsdip.FulfilledQuantity() ); 
 | 
          this.CalculateSalesDemandSystemFulfilledQuantity( totalremaining ); 
 | 
        } 
 | 
      } 
 | 
    } 
 | 
  *] 
 | 
} 
 |