| Quintiq file version 2.0 | 
| #parent: #root | 
| FunctionOverride CalcSystemFulfilledQuantity | 
| { | 
|   TextBody: | 
|   [* | 
|     if( 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 ); | 
|          | 
|         // Calculate the total remaining excluding immature stock quantities because for sales demands,  | 
|         // expired quantity has been excluded when calculating SupplyQuantity | 
|         // it can only be fulfilled with stock that is not expired and is matured if the product has shelf-life and maturation | 
|         totalremaining := maxvalue( totalremaining | 
|                                     - this.ImmatureShelfLifeSupplyQuantity(), 0.0 ); | 
|          | 
|         // SALES DEMAND | 
|         // To minus the disaggregated sales demand in period quantity that is fulfilled by manual planning | 
|         totalremaining := totalremaining - sum( this, DisaggregatedSalesDemandInPeriod, dsdip, dsdip.FulfilledQuantity() ); | 
|         totalremaining := maxvalue( totalremaining, 0.0 ); | 
|         this.CalculateSalesDemandSystemFulfilledQuantity( totalremaining ); | 
|       } | 
|     } | 
|   *] | 
| } |