admin
2025-01-22 7e31442f0e9b07764e9c6a9680d3d4aeba5fe1de
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
Quintiq file version 2.0
#parent: #root
Method MPSyncUnit (
  Boolean isoverwritemanualconfig,
  IOUnits iounits
)
{
  Description: 'Synchronization of Unit for MPSync'
  TextBody:
  [*
    // Select a set of existing Unit
    existing := selectset( this, Unit, item, true );
    updates := construct( Units );
    
    // Traverse the new set of valid Unit
    traverse( iounits , Elements, io, io.IsValid() )
    {
      indexkey := io.ID();
      // Find existing Unit
      objectinstance := Unit::FindUnitTypeIndex( indexkey );
      // Find existing UnitOfMeasure_MP
      uom := UnitOfMeasure_MP::FindUnitOfMeasureTypeIndex( io.UnitOfMeasureName() );
      // Find existing Currency_MP
      currency := Currency_MP::FindCurrencyTypeIndex( io.CurrencyID() );
      
      // If no existing Unit is found, create one
      if( isnull( objectinstance ) )
      { 
        // Check if there's valid UnitOfMeasure_MP and Currency_MP
        if( not ( isnull( uom ) or isnull( currency ) ) )
        {
          objectinstance := Unit::Create( this,
                                          io.ID(),
                                          io.ParentUnitID(),
                                          io.DisplayIndex(),
                                          io.Name(),
                                          io.QuantityToProcess(),
                                          io.IconName(),
                                          io.CapacityType(),
                                          io.CurrencyID(),
                                          io.StartDate(),
                                          io.EndDate(),
                                          io.IsPlannedInfinite(),
                                          io.UnitOfMeasureName(),
                                          io.GroupName(),
                                          io.MinimumQuantity(),
                                          io.MaximumQuantity(),
                                          io.LotSize(),
                                          io.GISCountryCode(),
                                          io.GISCity(),
                                          io.GISPostalCode(),
                                          io.HasMaximumQuantity(),
                                          io.HasCapacitySmoothing(),
                                          io.UserCapacitySmoothingLength(),
                                          io.CapacitySmoothingPercentageDelta(),
                                          io.IsOverlapCapacitySmoothing(),
                                          io.IsSmoothCapacityOverAllPeriods(),
                                          io.Notes(),
                                          io.CampaignTypeDuration(),
                                          io.IsIncludedInSupplySpecification(),
                                          io.IsSupplier(),
                                          io.HasUserFrozenFutureDuration(),
                                          io.UserFrozenFutureDuration(),
                                          io.UseShiftOptimization(),
                                          true );
        }
      }
      // Else if the Unit is not manually configured or the imported instance should overwrite manual configuration,
      // update the existing Unit
      else if( not objectinstance.IsManuallyConfigured() or isoverwritemanualconfig )
      {
        // Check if there's valid UnitOfMeasure_MP and Currency_MP
        if( not ( isnull( uom ) or isnull( currency ) ) )
        {
          // Update Unit
          objectinstance.Update( io.ID(), io.Name(),
                                 Unit::FindUnitTypeIndex( io.ParentUnitID() ), io.CapacityType(),  
                                 Group::FindGroupTypeIndex( io.GroupName() ),
                                 UnitOfMeasure_MP::FindUnitOfMeasureTypeIndex( io.UnitOfMeasureName() ),
                                 Currency_MP::FindCurrencyTypeIndex( io.CurrencyID() ),
                                 io.StartDate(), io.EndDate(), io.CampaignTypeDuration(), 
                                 io.IsPlannedInfinite(), io.MinimumQuantity(), io.HasMaximumQuantity(), io.MaximumQuantity(),
                                 io.LotSize(), io.IconName(), 
                                 io.QuantityToProcess(), 
                                 io.GISCountryCode(), io.GISCity(), io.GISPostalCode(), 
                                 io.Notes(), io.HasCapacitySmoothing(), io.IsSmoothCapacityOverAllPeriods(), io.UserCapacitySmoothingLength(),
                                 io.CapacitySmoothingPercentageDelta(),io.IsOverlapCapacitySmoothing(), io.IsIncludedInSupplySpecification(), io.IsSupplier(),
                                 io.HasUserFrozenFutureDuration(),io.UserFrozenFutureDuration(),
                                 io.UseShiftOptimization(),
                                 true  );
                                 
          updates.Add( objectinstance );
        }
        
        if( not isnull( objectinstance ) )
        {
          objectinstance.CustomUpdate(io, isoverwritemanualconfig );
        }
      }
    }
    
    // Get the set of old Unit to be deleted
    tobedeleteset := existing.Difference( updates );
    
    // Traverse the set of Unit to be deleted
    // Only delete Unit that is not manually configured or the imported instance should overwrite manual configuration
    traverse( tobedeleteset, Elements, ele,
              not ele.IsManuallyConfigured() or isoverwritemanualconfig )
    {
      ele.Delete();
    }
  *]
}