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
61
62
63
64
65
66
67
68
69
70
Quintiq file version 2.0
#parent: #root
StaticMethod Synchronize (
  FeedbackProductInTrips feedbackpits
) as owning ProductInTrips
{
  Description: 'Create missing product in trips for feedback.'
  TextBody:
  [*
    pits := construct( ProductInTrips );
    
    if( feedbackpits.Size() > 0 )
    {
        // Propagate relations that are needed for feedbacks.
      Transaction::Transaction().Propagate( relation( Feedback, UnitPeriod ) );
      // Propagate relations that are needed for feedbacks.
      Transaction::Transaction().Propagate( relation( FeedbackProductInTrip, LaneLeg ) );
      // Propagate relations that are needed for feedbacks.
      Transaction::Transaction().Propagate( relation( FeedbackProductInTrip, LaneLegOutput ) );
      // Propagate relations that are needed for feedbacks.
      Transaction::Transaction().Propagate( relation( FeedbackProductInTrip, ProductInTrip ) );
    
      // Traverse all feedbacks of product in trip that is valid
      traverse( feedbackpits, Elements, feedback,
                feedback.GetIsValidFeedback() )
      {
        // Get the associated ProductInTrip and LaneLeg of the current feedback
        pit := feedback.ProductInTrip();
        laneleg := feedback.LaneLeg();
      
        // Check if ProductInTrip is null
        if( isnull( pit ) )
        {
          // Check if LaneLeg is enabled
          if( guard( laneleg.GetIsEnabled(), false ) )
          {
            // Get the associated Trip and Product
            trip := feedback.Trip();
            product := guard( feedback.LaneLegOutput().ProductInStockingPoint_MP().Product_MP(), null( Product_MP ) )
      
            // Check if product is null
            if( not isnull( product ) )
            {
              // Check if trip is null, create one of trip is null
              if( isnull( trip ) )
              {
                arrival := Trip::GetTripArrivalDate( feedback.UnitPeriod().Period_MP(), laneleg );
                trip := Trip::Create( laneleg, arrival );
              }
      
              // Associate product to the trip
              trip.AddProduct( product, 0.0, false );
      
              // Propagate the declerative relations for new create trip to feedback
              Transaction::Transaction().Propagate( relation( ProductInTrip, FeedbackProductInTrip ) );
            }
          }
        }
      
        // Check if ProductInTrip is null
        if( not isnull( pit ) )
        {
          pits.Add( pit );
        }
      }
    }
    
    return &pits;
  *]
}