Quintiq file version 2.0 
 | 
#parent: #root 
 | 
Function CalcShelfLifePlannedEndAgeAndQuantityVectorAsBinaryValue 
 | 
{ 
 | 
  TextBody: 
 | 
  [* 
 | 
    // Get the shelf life supply vectors 
 | 
    quantityvector := RealVector::Construct( this.ShelfLifeSupplyAfterDDQuantityVectorAsBinaryValue() ); 
 | 
    agevector := RealVector::Construct( this.ShelfLifeSupplyAfterDDAgeVectorAsBinaryValue() ); 
 | 
    pispippl := this.ProductInStockingPointInPeriodPlanningLeaf(); 
 | 
     
 | 
    // Check if the product has shelf life or maturation 
 | 
    product := pispippl.ProductInStockingPoint_MP().Product_MP(); 
 | 
    if( product.HasShelfLifeOrMaturation() ) 
 | 
    { 
 | 
      // Deduct the values of the elements in the shelf life supply vectors with the values of sales demand and operation demand   
 | 
      salesdemands := pispippl.GetSortedLeafSalesDemandsInPeriod(); 
 | 
      salesdemand := sum( salesdemands, Elements, e, 
 | 
                          true, 
 | 
                          ifexpr( e.HasOptimizerFulfillment() or not e.IsWithinThresholdQuantity(), 
 | 
                                  e.OptimizerFulfilledQuantity(), 
 | 
                                  e.QuantityForSystemFulfilledQuantity() ) ); 
 | 
     
 | 
      salesdemandforaggregated := sum ( pispippl.GetDisaggregatedSalesDemandInPeriod(),  
 | 
                                     Elements,  
 | 
                                     e,  
 | 
                                     true,  
 | 
                                     ifexpr( e.HasOptimizerFulfillment() or not e.IsWithinThresholdQuantity(), 
 | 
                                     e.OptimizerFulfilledQuantity(), 
 | 
                                     e.QuantityForSystemFulfilledQuantity() ) );  
 | 
     
 | 
      salesdemandfornegativesupply := sum( pispippl, InventorySupply, invsup, invsup.Quantity() < 0, abs( invsup.Quantity() ) );      
 | 
     
 | 
      salesdemand := salesdemand + salesdemandforaggregated + salesdemandfornegativesupply;  
 | 
             
 | 
      // The quantity and age consumed by sales demand 
 | 
      source_quantityconsumedvector := RealVector::Construct(); 
 | 
      source_ageconsumedvector := RealVector::Construct(); 
 | 
       
 | 
      ShelfLife::SetAvailableAgeAndQuantityVectorAfterDemand( quantityvector, agevector, 
 | 
                                                              source_quantityconsumedvector, source_ageconsumedvector, 
 | 
                                                              salesdemand, 
 | 
                                                              false, // do not ignore maturation 
 | 
                                                              true, // consume oldest product first if possible 
 | 
                                                              pispippl, 
 | 
                                                              0.0 // the passed in source_agevector has not been aged so there is need to un-age  
 | 
                                                            ); 
 | 
       
 | 
      // Get the age that is considered expired 
 | 
      if( product.HasShelfLife() ) 
 | 
      { 
 | 
        isnonexpiredinperiodvector := BooleanVector::Construct(); 
 | 
        traverse( agevector.AsValues(), Elements, age ) 
 | 
        { 
 | 
          isusableinperiod := product.GetIsUsableInTargetPeriod( [Real] age, pispippl.Start(), pispippl.Period_MP() ); 
 | 
          isnonexpiredinperiodvector.Append( isusableinperiod ); 
 | 
        } 
 | 
             
 | 
        agevector := agevector.GetSelection( isnonexpiredinperiodvector ); 
 | 
        quantityvector := quantityvector.GetSelection( isnonexpiredinperiodvector ); 
 | 
      } 
 | 
       
 | 
      durationindays := pispippl.Period_MP().DurationInDays(); 
 | 
      durationindays := durationindays; 
 | 
      agevector := agevector.Plus( durationindays ); 
 | 
    } 
 | 
     
 | 
    this.ShelfLifePlannedEndAgeVectorAsBinaryValue( agevector.AsBinaryValue() ); 
 | 
    this.ShelfLifePlannedEndQuantityVectorAsBinaryValue( quantityvector.AsBinaryValue() ); 
 | 
  *] 
 | 
} 
 |