hongjli
2023-09-05 c70ff9aa94e34f968851e813a0b80a25a7b4ea74
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
Quintiq file version 2.0
#parent: #root
Method MappingUnitData (
  Strings businesstypes
)
{
  Description: 'Get unit data from operation mapping'
  TextBody:
  [*
    // Administrator Aug-21-2023 (created)
    // list to deal
    listtodeal := construct( structured[MappingOperation] );
    
    if( isnull( businesstypes ) or businesstypes.Size() = 0 ) {
        listtodeal := selectset( this, MappingOperation, item, true );
    } else {
        listtodeal := selectset( this, MappingOperation, item, 
    //                             businesstypes.Find( item.BusinessType() ) <> -1, 
                                 businesstypes.Difference( businesstypes.Difference( item.BusinessType().Tokenize( ", " ) ) ).Size() > 0
                                  );
    }
    
    //Set the Default values
    unitofmeasurename := "PCS";
    currencyid := "CNY";
    startdate := Date::Date( 1900, 1, 1 );
    enddate := Date::Date( 9999, 12, 31 );
    capacitytype := "Infinite";
    
    // Get the root data
    existroot := Unit::FindById( this, "天马集团" );
    if( isnull( existroot ) ){
      this.Unit( relnew, 
                 ID := "天马集团", 
                 Name := "天马集团", 
                 UnitOfMeasureName := unitofmeasurename, 
                 CurrencyID := currencyid, 
                 StartDate := startdate, 
                 EndDate := enddate, 
                 CapacityType := capacitytype );
     }
    
    // Get the sub root data
    existsubroot := Unit::FindById( this, "生产" );
    if( isnull( existsubroot ) ){
      this.Unit( relnew, ID := "生产", 
                 Name := "生产", 
                 ParentUnitID := "天马集团", 
                 UnitOfMeasureName := unitofmeasurename, 
                 CurrencyID := currencyid, 
                 StartDate := startdate, 
                 EndDate := enddate, 
                 CapacityType := capacitytype );
     }
    
    existsubroot := Unit::FindById( this, "供应商" );
    if( isnull( existsubroot ) ){
      this.Unit( relnew, ID := "供应商", 
                 Name := "供应商", 
                 ParentUnitID := "天马集团",
                 UnitOfMeasureName := unitofmeasurename, 
                 CurrencyID := currencyid, 
                 StartDate := startdate, 
                 EndDate := enddate, 
                 CapacityType := capacitytype );
     }
    
    existsubroot := Unit::FindById( this, "整车运输" );
    if( isnull( existsubroot ) ){
      this.Unit( relnew, ID := "整车运输", 
                 Name := "整车运输", 
                 ParentUnitID := "天马集团", 
                 UnitOfMeasureName := unitofmeasurename, 
                 CurrencyID := currencyid, 
                 StartDate := startdate, 
                 EndDate := enddate, 
                 CapacityType := capacitytype );
     }
    
    // Get the unit list
    traverse( listtodeal, Elements, item){
      //Get the first level unit
      existfirstlevelunit := Unit::FindById( this, item.OrganCode() );
    //  info( item.OrganCode().AsQUILL() );
      OrgName := item.OrganName();
      if( OrgName = ''){
        OrgName := item.OrganCode();
      }
      if( isnull( existfirstlevelunit ) ){
        this.Unit( relnew, ID := item.OrganCode(), 
    //               Name := item.OrganName(), 
                   Name :=OrgName, 
                   ParentUnitID := "生产",  
                   UnitOfMeasureName := unitofmeasurename, 
                   CurrencyID := currencyid, 
                   StartDate := startdate, 
                   EndDate := enddate, 
                   CapacityType := capacitytype );
        }
      //Get the second level unit
      secondlevelid := item.OrganCode() + "_" + item.PlantName();
    //  info( secondlevelid.AsQUILL() );
      existsecondlevelunit := Unit::FindById( this, secondlevelid );
      if( isnull( existsecondlevelunit ) ){
        this.Unit( relnew, ID := secondlevelid, 
                   Name := secondlevelid, 
                   ParentUnitID := item.OrganCode(), 
                   UnitOfMeasureName := unitofmeasurename, 
                   CurrencyID := currencyid, 
                   StartDate := startdate, 
                   EndDate := enddate, 
                   CapacityType := capacitytype );
        }
      //Get the third level unit
      thirdlevelid := secondlevelid + "_" + item.ProcessSection();
    //  info( thirdlevelid.AsQUILL() );
      existthirdlevelunit := Unit::FindById( this, thirdlevelid );
      if( isnull( existthirdlevelunit ) ){
        this.Unit( relnew, ID := thirdlevelid, 
                   Name := thirdlevelid, 
                   ParentUnitID := secondlevelid, 
                   CapacityType := "Time", 
                   UnitOfMeasureName := item.UnitOfMeasureName(), 
                   CurrencyID := currencyid, 
                   StartDate := startdate, 
                   EndDate := enddate );
        }
      //Get the last level unit
      if( item.Line()<>"" ){
        lastlevelid := thirdlevelid + "_" + item.Line();
    //    info( lastlevelid.AsQUILL() );
        existlastlevelunit := Unit::FindById( this, lastlevelid );
        if( isnull( existlastlevelunit ) ){
          this.Unit( relnew, ID := lastlevelid, 
                     Name := lastlevelid, 
                     ParentUnitID := thirdlevelid, 
                     CapacityType := "Time", 
                     UnitOfMeasureName := item.UnitOfMeasureName(),
                     CurrencyID := currencyid, 
                     StartDate := startdate, 
                     EndDate := enddate );
        }
      }
      }
  *]
}