hongji.li
2023-11-03 aefafd2142478d4fb07d6b8b45c3047e247389e0
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
Quintiq file version 2.0
#parent: #root
StaticMethod GetDestinationGroupID (
  Operation sourceoperation,
  Operation destinationoperation
) as Number
{
  Description: 'Return the incremental destination group id.'
  TextBody:
  [*
    // DWE2 Feb-1-2016 (created)
    id := 1;
    
    // If already have input, we need to increment the group id
    if( destinationoperation.OperationInput( relsize ) > 0 )
    {
      /* We need to propagate the Systems attribute and relations
         During the creation of operation link, Product/SP/OI/OO/OIG will be created
         Operation have SystemXXX relation to OI/OO/OIG, we need these relation to get new operation link id
         while creating new operation link */
      // To ensure the SystemXXX attribute/relation is propagated in batch creation
      Transaction::Transaction().Propagate();
    
      // Get all operation input with the same uom
      sysinputwithsameuom := selectset( destinationoperation, SystemOperationInput, soi,
                                        soi.PISPUnitOfMeasurement() = sourceoperation.Unit().UnitOfMeasure_MP() );
    
      // Get all operation input group with the same uom
      sysgroupwithsameuom := selectset( destinationoperation, SystemOperationInputGroup, soig,
                                        soig.UnitOfMeasure_MP() = sourceoperation.Unit().UnitOfMeasure_MP() );
    
      // If there is only one input with same uom, we will re use it
      // 99% of the case people will want it to be an alternative resource instead of other resource.
      if( sysinputwithsameuom.Size() = 1 )
      {
        id := sysinputwithsameuom.Element( 0 ).OperationLinkGroupID();
      }
      // If there is on;y one input group with the same uom, we will add to the group
      // 99% of the case people will want it to be an alternative resource instead of other resource.
      else if( sysgroupwithsameuom.Size() = 1 )
      {
        id := sysgroupwithsameuom.Element( 0 ).InputGroupID();
      }
      else
      {
        id := BaseOperationLink::GetGroupID( destinationoperation, true, true );
      }
    }
    
    return id;
  *]
}