Quintiq file version 2.0 
 | 
#parent: #root 
 | 
StaticMethod CreateWithProductInTrips ( 
 | 
  ProductInStockingPointInPeriodPlannings pispips, 
 | 
  LaneLeg laneleg 
 | 
) as Trip 
 | 
{ 
 | 
  Description: 'Given multiple PISPIP, create trip with product in trip for every PISPIP.' 
 | 
  TextBody: 
 | 
  [* 
 | 
    // desmondt Jun-7-2015 (created) 
 | 
    // Do not select existing trips, will retain all existing and create new trips. 
 | 
    trips := construct( Trips ); 
 | 
    newtrip := null( Trip ); 
 | 
    // To get the number of stocking points inorder to make sure all the selected instances are planned. 
 | 
    nrofsp := counter( pispips, Elements.StockingPointInPeriod.StockingPoint_MP, sp, true ); 
 | 
     
 | 
    for( x := 0; x < nrofsp; x++ ) 
 | 
    { 
 | 
      // Sort by decending UnfulfilledQuantity 
 | 
      sortedpispips := selectsortedset( pispips, Elements, e, true, -e.GetUnfulfilledQuantity() ); 
 | 
     
 | 
      traverse( sortedpispips, Elements, pispip ) 
 | 
      { 
 | 
        if( isnull( laneleg ) ) 
 | 
        {  
 | 
          // Select a lane with least lead time 
 | 
          laneleg := minselect( pispip, ProductInStockingPoint_MP.LaneLegOutput.LaneLeg, ll, 
 | 
                                ll.GetIsEnabled(), 
 | 
                                ll.LeadTime() ); 
 | 
        } 
 | 
        // Look for existing trip that can transport the product in sp in period 
 | 
        trip := select( trips, Elements, e, 
 | 
                        e.LaneLeg() = laneleg, 
 | 
                        e.Arrival() = pispip.Period_MP().End() ); 
 | 
     
 | 
        if( not isnull( trip ) ) 
 | 
        { 
 | 
          suggestedqty := trip.GetSuggestedQuantity( pispip ); 
 | 
     
 | 
          // If there is already an existing trip and no product in it, add product in trip. 
 | 
          pit := trip.AddProduct( pispip, 
 | 
                                  0.0, 
 | 
                                  true ); 
 | 
     
 | 
          // Avoid replacing quantity with 0, suggested quantity will be 0 on second loop if it was fulfilled in the first loop 
 | 
          pit.Update( maxvalue( suggestedqty, pit.Quantity() ), true ); 
 | 
        } 
 | 
        else 
 | 
        { 
 | 
          // Create new trip with product in trip if there is no existing trip 
 | 
          newtrip := Trip::CreateWithProductInTrip( laneleg, pispip ); 
 | 
          trips.Add( newtrip ); 
 | 
        } 
 | 
      } 
 | 
    } 
 | 
     
 | 
    return newtrip; 
 | 
  *] 
 | 
} 
 |