hongji.li
2023-10-17 6a58456625b8ff9b895f87f3d5a5965ab574f87a
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
Quintiq file version 2.0
#parent: #root
Method CapacityAndSaleBudgeChart (
  MacroPlans macroPlans,
  String saleOrCapacity,
  String groupBy,
  String byBusinessTypeOrByOrgCode,
  CapacityAndSaleBudgeFilterBusinessTypes businessTypes,
  CapacityAndSaleBudgeFilterPlaceOfProductionOfArrays placeOfProductionOfArrays,
  CapacityAndSaleBudgeFilterYears years,
  CapacityAndSaleBudgeFilterMonths months,
  GlobalOTDTable otdTable
)
{
  Description: '按入参处理数据,产生需要的CapacityAndSaleBudgeChartElement'
  TextBody:
  [*
    // yypsybs Sep-19-2023 (created)
    // true, false
    //info( saleOrCapacity );
    // 月;季度;半年;年
    //info( groupBy );
    // 面板基地;事业部
    //info( byBusinessTypeOrByOrgCode );
    //traverse( businessTypes, Elements, businessType ) {
    //  info( "businessType : " + businessType.BusinessType() );
    //}
    //traverse( placeOfProductionOfArrays, Elements, placeOfProductionOfArray ) {
    //  info( "placeOfProductionOfArray : " + placeOfProductionOfArray.PlaceOfProductionOfArray() );
    //}
    //traverse( macroPlans, Elements, macroPlan ) {
    //  info( "macroPlan : " + macroPlan.ScenarioName() );  
    //}
    // 年份不选时全选
    if( years.Size() = 0 ) {
      years := selectsortedset( this, CapacityAndSaleBudgeFilterYear, item, true, item.YearNo() );
    }
    //traverse( years, Elements, year ) {
    //  debuginfo( "yearNo : " + [String]year.YearNo() );
    //}
    // 月份不选时全选
    if( months.Size() = 0 ) {
      months := selectsortedset( this, CapacityAndSaleBudgeFilterMonth, item, true, item.MonthNo() );
    }
    //traverse( months, Elements, month ) {
    //  debuginfo( "monthNo : " + [String]month.MonthNo() );
    //}
    
    // ====清理旧数据====
    this.CapacityAndSaleBudgeChartRow( relflush );
    this.CapacityAndSaleBudgeChartElement( relflush );
    
    // ====按面板基地和事业部对产品进行筛选分组====
    historyData := selectset( otdTable, Global_MappingAnnualBudgetData, item, true );
    if( businessTypes.Size() > 0 ) {
      businessTypeStrings := selectuniquevalues( businessTypes, Elements, item, true, item.BusinessType() );
      historyData := selectset( historyData, Elements, item, businessTypeStrings.Find( item.BusinessType() ) > -1 );
    }
    if( placeOfProductionOfArrays.Size() > 0 ) {
      placeOfProductionOfArrayStrings := selectuniquevalues( placeOfProductionOfArrays, Elements, item, true, item.PlaceOfProductionOfArray() );
      historyData := selectset( historyData, Elements, item, placeOfProductionOfArrayStrings.Find( item.OrgCodeFromBom() ) > -1 );
    }
    //info( "historyData : " + [String]historyData.Size() );
    traverse( historyData, Elements, item ) {
      row := CapacityAndSaleBudgeChartRow::CreateIfNotExist( this, item.BusinessType(), item.OrgCodeFromBom() );
      // 记录每行包含哪些product
      CapacityAndSaleBudgeChartRowProduct::CreateIfNotExist( row, item.ProductID() );
    }
    rows := selectset( this, CapacityAndSaleBudgeChartRow, item, true );
    //info( "rows : " + [String]rows.Size() );
    placeOfProductionOfArrayList := selectuniquevalues( historyData, Elements, item, item.OrgCodeFromBom() );
    //traverse( placeOfProductionOfArrayList, Elements, item ) {
    //  info( "placeOfProduction : " + item );  
    //}
    businessTypeList := selectuniquevalues( historyData, Elements, item, item.BusinessType() );
    //traverse( businessTypeList, Elements, item ) {
    //  info( "businessType : " + item );  
    //}
    // 生成图表元素
    traverse( years, Elements, year ) {
    //  debuginfo( "process year start : " + [String]year.YearNo() );
      if( byBusinessTypeOrByOrgCode = "面板基地" and groupBy = "年" ) {
        // 目标
        traverse( placeOfProductionOfArrayList, Elements, placeOfProductionOfArray ) {
          productCodeList := CapacityAndSaleBudgeChartRow::GetProductCodesByPlaceOfProductionOfArray( rows, placeOfProductionOfArray );
          this.CapacityAndSaleBudgeChartElement( relnew, 
                                                 TimeStringAndScenarioName := [String]year.YearNo() + "年-目标",
                                                 BusinessTypeOrPlaceOfProductionOfArray := placeOfProductionOfArray, 
                                                 Quantity := ifexpr( saleOrCapacity = "销售额",
                                                                     Global_MappingAnnualBudgetData::GetSaleByYear( productCodeList, otdTable, year.YearNo() ),
                                                                     Global_MappingForecast::GetQuantityByYear( productCodeList, otdTable, year.YearNo() ) )
                                                 );  
          // S&OP
          traverse( macroPlans, Elements, macroPlan ) {
            this.CapacityAndSaleBudgeChartElement( relnew, 
                                                   TimeStringAndScenarioName := [String]year.YearNo() + "年-" + macroPlan.ScenarioName(),
                                                   BusinessTypeOrPlaceOfProductionOfArray := placeOfProductionOfArray, 
                                                   Quantity := ifexpr( saleOrCapacity = "销售额",
                                                                       Forecast::GetFulfilledBalanceByYear( productCodeList, macroPlan, year.YearNo() ),
                                                                       Product_MP::GetNewSupplyByYear( productCodeList, macroPlan, year.YearNo() ) 
                                                                       )
                                                   ); 
          }                    
        }
      } 
      if ( byBusinessTypeOrByOrgCode = "面板基地" and groupBy = "半年" ) {
        for( halfNo := 1; halfNo <= 2; halfNo := halfNo + 1 ) {
          traverse( placeOfProductionOfArrayList, Elements, placeOfProductionOfArray ) {
            productCodeList := CapacityAndSaleBudgeChartRow::GetProductCodesByPlaceOfProductionOfArray( rows, placeOfProductionOfArray );
            this.CapacityAndSaleBudgeChartElement( relnew, 
                                                   TimeStringAndScenarioName := [String]year.YearNo() + "年-" + ifexpr( halfNo = 1, "上", "下" ) + "半年-目标",
                                                   BusinessTypeOrPlaceOfProductionOfArray := placeOfProductionOfArray, 
                                                   Quantity := ifexpr( saleOrCapacity = "销售额",
                                                                       Global_MappingAnnualBudgetData::GetSaleByHalfYear( productCodeList, otdTable, year.YearNo(), halfNo ),
                                                                       Global_MappingForecast::GetQuantityByHalfYear( productCodeList, otdTable, year.YearNo(), halfNo ) )
                                                   );  
            // S&OP
            traverse( macroPlans, Elements, macroPlan ) {
              this.CapacityAndSaleBudgeChartElement( relnew, 
                                                     TimeStringAndScenarioName := [String]year.YearNo() + "年-" + ifexpr( halfNo = 1, "上", "下" ) + "半年-" + macroPlan.ScenarioName(),
                                                     BusinessTypeOrPlaceOfProductionOfArray := placeOfProductionOfArray, 
                                                     Quantity := ifexpr( saleOrCapacity = "销售额",
                                                                         Forecast::GetFulfilledBalanceByHalfYear( productCodeList, macroPlan, year.YearNo(), halfNo ),
                                                                         Product_MP::GetNewSupplyByHalfYear( productCodeList, macroPlan, year.YearNo(), halfNo )
                                                                         )
                                                     ); 
            }                    
          }
        }
      }
      if ( byBusinessTypeOrByOrgCode = "面板基地" and groupBy = "季度" ) {
        for( seasonNo := 1; seasonNo <= 4; seasonNo := seasonNo + 1 ) {
          traverse( placeOfProductionOfArrayList, Elements, placeOfProductionOfArray ) {
            productCodeList := CapacityAndSaleBudgeChartRow::GetProductCodesByPlaceOfProductionOfArray( rows, placeOfProductionOfArray );
            this.CapacityAndSaleBudgeChartElement( relnew, 
                                                   TimeStringAndScenarioName := [String]year.YearNo() + "年-第" + [String]seasonNo + "季度-目标",
                                                   BusinessTypeOrPlaceOfProductionOfArray := placeOfProductionOfArray, 
                                                   Quantity := ifexpr( saleOrCapacity = "销售额",
                                                                       Global_MappingAnnualBudgetData::GetSaleBySeason( productCodeList, otdTable, year.YearNo(), seasonNo ),
                                                                       Global_MappingForecast::GetQuantityBySeason( productCodeList, otdTable, year.YearNo(), seasonNo ) )
                                                   );  
      //      info( "productCodeList : " + [String]productCodeList.Size() );
            // S&OP
            traverse( macroPlans, Elements, macroPlan ) {
              this.CapacityAndSaleBudgeChartElement( relnew, 
                                                     TimeStringAndScenarioName := [String]year.YearNo() + "年-第" + [String]seasonNo + "季度-" + macroPlan.ScenarioName(),
                                                     BusinessTypeOrPlaceOfProductionOfArray := placeOfProductionOfArray, 
                                                     Quantity := ifexpr( saleOrCapacity = "销售额",
                                                                         Forecast::GetFulfilledBalanceBySeason( productCodeList, macroPlan, year.YearNo(), seasonNo ) ,
                                                                         Product_MP::GetNewSupplyBySeason( productCodeList, macroPlan, year.YearNo(), seasonNo )
                                                                         )
                                                     ); 
            }                    
          }
        }
      }
      if ( byBusinessTypeOrByOrgCode = "面板基地" and groupBy = "月" ) {
        traverse( months, Elements, month ) {
    //      info( "process month start : " + [String]month.MonthNo() );
          monthNoString := ifexpr( month.MonthNo() <= 9, "0" + [String]month.MonthNo(), [String]month.MonthNo() );
          traverse( placeOfProductionOfArrayList, Elements, placeOfProductionOfArray ) {
            productCodeList := CapacityAndSaleBudgeChartRow::GetProductCodesByPlaceOfProductionOfArray( rows, placeOfProductionOfArray );
            this.CapacityAndSaleBudgeChartElement( relnew, 
                                                   TimeStringAndScenarioName := [String]year.YearNo() + "年-第" + monthNoString + "月-目标",
                                                   BusinessTypeOrPlaceOfProductionOfArray := placeOfProductionOfArray, 
                                                   Quantity := ifexpr( saleOrCapacity = "销售额",
                                                                       Global_MappingAnnualBudgetData::GetSaleByMonth( productCodeList, otdTable, year.YearNo(), month.MonthNo() ),
                                                                       Global_MappingForecast::GetQuantityByMonth( productCodeList, otdTable, year.YearNo(), month.MonthNo() ) )
                                                   );  
            // S&OP
            traverse( macroPlans, Elements, macroPlan ) {
              this.CapacityAndSaleBudgeChartElement( relnew, 
                                                     TimeStringAndScenarioName := [String]year.YearNo() + "年-第" + monthNoString + "月-" + macroPlan.ScenarioName(),
                                                     BusinessTypeOrPlaceOfProductionOfArray := placeOfProductionOfArray, 
                                                     Quantity := ifexpr( saleOrCapacity = "销售额",
                                                                         Forecast::GetFulfilledBalanceByMonth( productCodeList, macroPlan, year.YearNo(), month.MonthNo() ),
                                                                         Product_MP::GetNewSupplyByMonth( productCodeList, macroPlan, year.YearNo(), month.MonthNo() ) 
                                                                         )
                                                     ); 
            }
          }
    //      info( "process month end : " + [String]month.MonthNo() );
        }
      }
      if( byBusinessTypeOrByOrgCode = "事业部" and groupBy = "年" ) {
        // 目标
        traverse( businessTypeList, Elements, businessType ) {
          productCodeList := CapacityAndSaleBudgeChartRow::GetProductCodesByBusinessType( rows, businessType );
          this.CapacityAndSaleBudgeChartElement( relnew, 
                                                 TimeStringAndScenarioName := [String]year.YearNo() + "年-目标",
                                                 BusinessTypeOrPlaceOfProductionOfArray := businessType, 
                                                 Quantity := ifexpr( saleOrCapacity = "销售额",
                                                                     Global_MappingAnnualBudgetData::GetSaleByYear( productCodeList, otdTable, year.YearNo() ),
                                                                     Global_MappingForecast::GetQuantityByYear( productCodeList, otdTable, year.YearNo() ) )
                                                 );  
          // S&OP
          traverse( macroPlans, Elements, macroPlan ) {
            this.CapacityAndSaleBudgeChartElement( relnew, 
                                                   TimeStringAndScenarioName := [String]year.YearNo() + "年-" + macroPlan.ScenarioName(),
                                                   BusinessTypeOrPlaceOfProductionOfArray := businessType, 
                                                   Quantity := ifexpr( saleOrCapacity = "销售额",
                                                                       Forecast::GetFulfilledBalanceByYear( productCodeList, macroPlan, year.YearNo() ) ,
                                                                       Product_MP::GetNewSupplyByYear( productCodeList, macroPlan, year.YearNo() )
                                                                       )
                                                   ); 
          }                    
        }
      } 
      if ( byBusinessTypeOrByOrgCode = "事业部" and groupBy = "半年" ) {
        for( halfNo := 1; halfNo <= 2; halfNo := halfNo + 1 ) {
          traverse( businessTypeList, Elements, businessType ) {
            productCodeList := CapacityAndSaleBudgeChartRow::GetProductCodesByBusinessType( rows, businessType );
            this.CapacityAndSaleBudgeChartElement( relnew, 
                                                   TimeStringAndScenarioName := [String]year.YearNo() + "年-" + ifexpr( halfNo = 1, "上", "下" ) + "半年-目标",
                                                   BusinessTypeOrPlaceOfProductionOfArray := businessType, 
                                                   Quantity := ifexpr( saleOrCapacity = "销售额",
                                                                       Global_MappingAnnualBudgetData::GetSaleByHalfYear( productCodeList, otdTable, year.YearNo(), halfNo ),
                                                                       Global_MappingForecast::GetQuantityByHalfYear( productCodeList, otdTable, year.YearNo(), halfNo ) )
                                                   );  
            // S&OP
            traverse( macroPlans, Elements, macroPlan ) {
              this.CapacityAndSaleBudgeChartElement( relnew, 
                                                     TimeStringAndScenarioName := [String]year.YearNo() + "年-" + ifexpr( halfNo = 1, "上", "下" ) + "半年-" + macroPlan.ScenarioName(),
                                                     BusinessTypeOrPlaceOfProductionOfArray := businessType, 
                                                     Quantity := ifexpr( saleOrCapacity = "销售额",
                                                                         Forecast::GetFulfilledBalanceByHalfYear( productCodeList, macroPlan, year.YearNo(), halfNo ) ,
                                                                         Product_MP::GetNewSupplyByHalfYear( productCodeList, macroPlan, year.YearNo(), halfNo )
                                                                         )
                                                     ); 
            }                    
          }
        }
      }
      if ( byBusinessTypeOrByOrgCode = "事业部" and groupBy = "季度" ) {
        for( seasonNo := 1; seasonNo <= 4; seasonNo := seasonNo + 1 ) {
    //      debuginfo( "process season start : " + [String]seasonNo );
          traverse( businessTypeList, Elements, businessType ) {
            productCodeList := CapacityAndSaleBudgeChartRow::GetProductCodesByBusinessType( rows, businessType );
            this.CapacityAndSaleBudgeChartElement( relnew, 
                                                   TimeStringAndScenarioName := [String]year.YearNo() + "年-第" + [String]seasonNo + "季度-目标",
                                                   BusinessTypeOrPlaceOfProductionOfArray := businessType, 
                                                   Quantity := ifexpr( saleOrCapacity = "销售额",
                                                                       Global_MappingAnnualBudgetData::GetSaleBySeason( productCodeList, otdTable, year.YearNo(), seasonNo ),
                                                                       Global_MappingForecast::GetQuantityBySeason( productCodeList, otdTable, year.YearNo(), seasonNo ) )
                                                   );  
            // S&OP
            traverse( macroPlans, Elements, macroPlan ) {
              this.CapacityAndSaleBudgeChartElement( relnew, 
                                                     TimeStringAndScenarioName := [String]year.YearNo() + "年-第" + [String]seasonNo + "季度-" + macroPlan.ScenarioName(),
                                                     BusinessTypeOrPlaceOfProductionOfArray := businessType, 
                                                     Quantity := ifexpr( saleOrCapacity = "销售额",
                                                                         Forecast::GetFulfilledBalanceBySeason( productCodeList, macroPlan, year.YearNo(), seasonNo ),
                                                                         Product_MP::GetNewSupplyBySeason( productCodeList, macroPlan, year.YearNo(), seasonNo ) 
                                                                         )
                                                     ); 
            }                    
          }
    //      info( "process season end : " + [String]seasonNo );
        }
      }
      if ( byBusinessTypeOrByOrgCode = "事业部" and groupBy = "月" ) {
        traverse( months, Elements, month ) {
    //      debuginfo( "process month start : " + [String]month.MonthNo() );
          monthNoString := ifexpr( month.MonthNo() <= 9, "0" + [String]month.MonthNo(), [String]month.MonthNo() );
          traverse( businessTypeList, Elements, businessType ) {
            productCodeList := CapacityAndSaleBudgeChartRow::GetProductCodesByBusinessType( rows, businessType );
            this.CapacityAndSaleBudgeChartElement( relnew, 
                                                   TimeStringAndScenarioName := [String]year.YearNo() + "年-第" + monthNoString + "月-目标",
                                                   BusinessTypeOrPlaceOfProductionOfArray := businessType, 
                                                   Quantity := ifexpr( saleOrCapacity = "销售额",
                                                                       Global_MappingAnnualBudgetData::GetSaleByMonth( productCodeList, otdTable, year.YearNo(), month.MonthNo() ),
                                                                       Global_MappingForecast::GetQuantityByMonth( productCodeList, otdTable, year.YearNo(), month.MonthNo() ) )
                                                   );  
            // S&OP
            traverse( macroPlans, Elements, macroPlan ) {
              this.CapacityAndSaleBudgeChartElement( relnew, 
                                                     TimeStringAndScenarioName := [String]year.YearNo() + "年-第" + monthNoString + "月-" + macroPlan.ScenarioName(),
                                                     BusinessTypeOrPlaceOfProductionOfArray := businessType, 
                                                     Quantity := ifexpr( saleOrCapacity = "销售额",
                                                                         Forecast::GetFulfilledBalanceByMonth( productCodeList, macroPlan, year.YearNo(), month.MonthNo() ) ,
                                                                         Product_MP::GetNewSupplyByMonth( productCodeList, macroPlan, year.YearNo(), month.MonthNo() )
                                                                         )
                                                     ); 
            }            
          }
    //      debuginfo( "process month end : " + [String]month.MonthNo() );
        }
      }
    //  debuginfo( "process year end : " + [String]year.YearNo() )
    }
    //info( "CapacityAndSaleBudgeChartElement : " + [String]selectset( this, CapacityAndSaleBudgeChartElement, item, true ).Size() );
    //traverse( this, CapacityAndSaleBudgeChartRow, row ) {
    //  info( "==↓==" );
    //  info( row.BusinessType() );
    //  info( row.PlaceOfProductionOfArray() );
    //  elements := selectset( row, CapacityAndSaleBudgeChartRowProduct, cell, true );
    //  info( elements.Size() );
    //  info( row.GetProductCodes().Concatenate( " | " ) );
    //  info( "==↑==" );
    //}
  *]
}