hongji.li
2023-10-25 ae5ce946294a27532534b52bd21d37567d4a6887
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
Quintiq file version 2.0
#parent: #root
Method DoASyncMappingOperationBOMData (
  Strings businessTypes,
  Boolean isKeyProduct,
  Boolean createPurchaseSupplyMaterial,
  const GlobalOTDTable globalOTDTable,
  Strings organcodelist
)
{
  TextBody:
  [*
    // yypsybs Aug-21-2023 (created)
    keyProductList := construct( Strings );
    if( isKeyProduct ) {
       keyProductList := selectuniquevalues( globalOTDTable, Global_MappingProduct_MP, item, item.ProductMajorType()="成品" or item.ProductMajorType()="半成品", item.ID() );
    }
    bomList := selectsortedset(  globalOTDTable, Global_MappingOperationBOM, item,
                                 ifexpr( isnull( businessTypes ) or businessTypes.Size() = 0, 
                                         true, 
    //                                     businessTypes.Difference( businessTypes.Difference( item.BusinessType().Tokenize( ", " ) ) ).Size() > 0 )
                                         ( businessTypes.Find( item.BusinessType() ) >= 0 ) and 
                                         ( organcodelist.Find( item.OrganCode() ) >= 0 ) )
    //                             and ifexpr( isKeyProduct, 
    //                                         keyProductList.Size() > 0 and keyProductList.Find( item.ComponentCode() ) >= 0,
    //                                         true )
                                 ,
                                 item.OrganCode() + "_" + item.ProductCode() + "_" + item.ProcessSection() );
    // 按routing及routingStep分组
    routingIds := selectuniquevalues( bomList, Elements, item, true, item.OrganCode() + "_" + item.ProductCode() );
    traverse( routingIds, Elements, routingId ) {
        routingRows := selectset( bomList, Elements, item, true, routingId = item.OrganCode() + "_" + item.ProductCode() );
        if( routingRows.Size() > 0 ) {
            firstRow := routingRows.Element( 0 );
    //        stockingPointId := firstRow.OrganCode()  + "_" + firstRow.ProductType() + "_Stock";
    //        inputStockingPointId := firstRow.OrganCode()  + "_" + firstRow.ComponentType() + "_Stock";
            stockingPointId := firstRow.OrganCode()  + "_Stock";
    
            // ========检查========
            product := Product_MP::FindProductTypeIndex( firstRow.ProductCode() );
            if( not isnull( product ) ) {
    //              error( "product : " + firstRow.ProductCode() + " not found" );
              stockingPoint := StockingPoint_MP::FindStockingPointTypeIndex( stockingPointId );
    
    //          info( stockingPointId.AsQUILL() );
      //        if( isnull( stockingPoint ) ) {
      //            error( "stockingPoint : " + stockingPointId + " not found" );
      //        }
              routing := Routing::FindRoutingTypeIndex(  routingId );
              if( not isnull( routing ) ) {
    //              error( "routing : " + routingId + " not found" );
                // ========处理输出========
                if( not isnull( stockingPoint ) ) {
    //              info( 1 );
                  operationsInLastSteps := Operation::FindFinalOperationsByRoutingId( this, routingId );
                  traverse( operationsInLastSteps, Elements, operationsInLastStep ) {
                      operationsInLastStep.CreateOperationBOM( product, stockingPoint, false, true );
                      operationsInLastStep.GetOperationBOM( product.ID(), stockingPoint.ID(), false ).Quantity( 1 );
                  }
                  // ========分组处理输入========
                  
                }
                
                if( not isnull( stockingPoint)){
                  if( isKeyProduct){
                      keyRows := selectset( routingRows,Elements,routingrow,keyProductList.Find( routingrow.ComponentCode())>=0);
                      this.DoASyncMappingOperationBOMDataRouting( routing,globalOTDTable,keyRows);
                    }else{
                      this.DoASyncMappingOperationBOMDataRouting( routing,globalOTDTable,routingRows);
                    }
                    
                }
              }
           }
        }
    }
    if( createPurchaseSupplyMaterial ) {
      toCreateBomList := construct( Strings );
      alterCodes := construct( Strings );
      
      if( isKeyProduct){
          toCreateBomList := selectuniquevalues( bomList, Elements, item, 
                                               item.ComponentType() = "P" and keyProductList.Find( item.ComponentCode())>=0, item.OrganCode() + item.ComponentCode());
                                           
          alterCodes := selectuniquevalues( bomList, Elements, item, 
                                               not item.AlternativeMaterialCode() = "" and item.AlternativeMaterialType() = "P" and keyProductList.Find( item.ComponentCode())>=0, item.OrganCode() + item.AlternativeMaterialCode());
        }else{
          toCreateBomList := selectuniquevalues( bomList, Elements, item, 
                                               item.ComponentType() = "P" , item.OrganCode() + item.ComponentCode());
        
          alterCodes := selectuniquevalues( bomList, Elements, item, 
                                               not item.AlternativeMaterialCode() = "" and item.AlternativeMaterialType() = "P", item.OrganCode() + item.AlternativeMaterialCode());
        }
        toCreateBomList := toCreateBomList.Union( alterCodes);
        traverse( toCreateBomList, Elements, key ) {
            boms := selectset( bomList, Elements, item, item.ComponentType() = "P" and item.OrganCode() + item.ComponentCode() = key );
            bom := boms.First();
            this.MappingOperationBOMDataSupplyPurchase( bom.OrganCode(), bom.ComponentCode(), bom.ComponentType());
        }
    }
    
    
    //
    //keyProductList := construct( Strings );
    //if( isKeyProduct ) {
    //    keyProductList := selectuniquevalues( globalOTDTable, Global_MappingProduct_MP, item, item.ProductMajorType()="成品" or item.ProductMajorType()="半成品", item.ID() );
    //}
    //bomList := selectsortedset(  globalOTDTable, Global_MappingOperationBOM, item,
    //                             ifexpr( isnull( businessTypes ) or businessTypes.Size() = 0, 
    //                                     true, 
    ////                                     businessTypes.Difference( businessTypes.Difference( item.BusinessType().Tokenize( ", " ) ) ).Size() > 0 )
    //                                     businessTypes.Find( item.BusinessType() ) >= 0 )
    ////                             and ifexpr( isKeyProduct, 
    ////                                         keyProductList.Size() > 0 and keyProductList.Find( item.ComponentCode() ) >= 0,
    ////                                         true )
    //                             ,
    //                             item.OrganCode() + "_" + item.ProductCode() + "_" + item.ProcessSection() );
    //// 按routing及routingStep分组
    //routingIds := selectuniquevalues( bomList, Elements, item, true, item.OrganCode() + "_" + item.ProductCode() );
    //traverse( routingIds, Elements, routingId ) {
    //    routingRows := selectset( bomList, Elements, item, true, routingId = item.OrganCode() + "_" + item.ProductCode() );
    //    if( routingRows.Size() > 0 ) {
    //        firstRow := routingRows.Element( 0 );
    ////        stockingPointId := firstRow.OrganCode()  + "_" + firstRow.ProductType() + "_Stock";
    ////        inputStockingPointId := firstRow.OrganCode()  + "_" + firstRow.ComponentType() + "_Stock";
    //        stockingPointId := firstRow.OrganCode()  + "_Stock";
    //
    //        // ========检查========
    //        product := Product_MP::FindProductTypeIndex( firstRow.ProductCode() );
    //        if( not isnull( product ) ) {
    ////              error( "product : " + firstRow.ProductCode() + " not found" );
    //          stockingPoint := StockingPoint_MP::FindStockingPointTypeIndex( stockingPointId );
    //
    ////          info( stockingPointId.AsQUILL() );
    //  //        if( isnull( stockingPoint ) ) {
    //  //            error( "stockingPoint : " + stockingPointId + " not found" );
    //  //        }
    //          routing := Routing::FindRoutingTypeIndex(  routingId );
    //          if( not isnull( routing ) ) {
    ////              error( "routing : " + routingId + " not found" );
    //            // ========处理输出========
    //            if( not isnull( stockingPoint ) ) {
    ////              info( 1 );
    //              operationsInLastSteps := Operation::FindFinalOperationsByRoutingId( this, routingId );
    //              traverse( operationsInLastSteps, Elements, operationsInLastStep ) {
    //                  operationsInLastStep.CreateOperationBOM( product, stockingPoint, false, true );
    //                  operationsInLastStep.GetOperationBOM( product.ID(), stockingPoint.ID(), false ).Quantity( 1 );
    //              }
    //              // ========分组处理输入========
    //              
    //            }
    //            if( not isnull( stockingPoint)){
    //              if( isKeyProduct){
    //                  keyRows := selectset( routingRows,Elements,routingrow,keyProductList.Find( routingrow.ComponentCode())>=0);
    //                  this.MappingOperationBOMDataRouting( routing,globalOTDTable,keyRows);
    //                }else{
    //                  this.MappingOperationBOMDataRouting( routing,globalOTDTable,routingRows);
    //                }
    //                
    //            }
    //          }
    //       }
    //    }
    //}
    //if( createPurchaseSupplyMaterial ) {
    //    toCreateBomList := selectuniquevalues( bomList, Elements, item, 
    //                                           item.ComponentType() = "P", item.OrganCode() + item.ComponentCode());
    //    traverse( toCreateBomList, Elements, key ) {
    //        boms := selectset( bomList, Elements, item, item.ComponentType() = "P" and item.OrganCode() + item.ComponentCode() = key );
    //        bom := boms.First();
    //        this.MappingOperationBOMDataSupplyPurchase( bom.OrganCode(), bom.ComponentCode(), bom.ComponentType());
    //    }
    //}
  *]
}