lazhen
2025-01-09 8afe90b633046db39042aada36b88193062f8cff
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
71
Quintiq file version 2.0
#parent: #root
Method SynchronizeInventorySpecInServiceLevel
{
  Description:
  [*
    This method updates the InventorySpecificationInServiceLevel instances that link this service level to the relevant inventory specifications.
    An inventory specification is relevant for the service level if it can influence the service level.
    This means that it is specified either on a pispip of the service level, or on an upstream pispip of this service level.
  *]
  TextBody:
  [*
    // Martijn Oct-18-2016 (created)
    
    // Set all IsSynchronized of the InventorySpecificationInServiceLevel related to this service level to false
    // This allows us to track which InvSpecInSL are outdated and need to be deleted
    traverse( this, InventorySpecificationInServiceLevel, invspecinsl )
    {
      invspecinsl.IsSynchronized( false );
    }
    
    sdips := this.GetSalesDemandInPeriods()
    pispips := selectset( sdips, Elements.AsSalesDemandInPeriodBase, pispip, true );
    
    // Add all upstream pispips to the pispips set
    traverse( pispips, Elements, pispip )
    {
      pispip.GetUpstreamPISPIPs( 20, pispips );
    }
    
    traverse( pispips, Elements.InventorySpecification, invspec )
    {
      // Create the instance of the invspecinservicelevel that links the inventory specification to the service level
      // The create method will check whether it already exists
      invspecinsl := InventorySpecificationInServiceLevel::Create( invspec, this );
      // This invspecinsl has been synchronized
      invspecinsl.IsSynchronized( true );
    }
    
    // Delete all the remaining invspecinsl that have not been synchronized
    // since these invspecinsl are outdated
    traverse( this, InventorySpecificationInServiceLevel, invspecinsl, not invspecinsl.IsSynchronized() )
    {
      invspecinsl.Delete()
    }
    
    // Delete all the unused PeriodTaskOperations and Trips (that were created to identify the upstream pispips )
    // Any PeriodTaskOperation/Trip with a userquantity or with feedback should not be deleted
    traverse( this, AsAllServiceLevelBase.Unit.Operation.PeriodTaskOperation, periodtaskoperation,
              periodtaskoperation.Quantity() = 0.0
              and not periodtaskoperation.HasUserQuantity()
              and not periodtaskoperation.HasFeedback() )
    {
      periodtaskoperation.Delete();
    }
    traverse( this, AsAllServiceLevelBase.Unit.Lane.LaneLeg.Trip, trip )
    {
      traverse( trip, ProductInTrip, pit,
                pit.Quantity() = 0.0
                and not pit.HasUserQuantity()
                and not pit.HasFeedback() )
      {
        pit.Delete();
      }
      if( trip.ProductInTrip( relsize ) = 0 )
      {
        trip.Delete();
      }
    }
  *]
}