yanweiyuan3
2023-08-09 588bc7829387dfc761cc25f06f77d4c81818bd10
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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;
  *]
}