yypsybs
2023-09-20 2237ad24deb34ca1aeaf659ea1d4f523d708cd26
_Main/BL/Type_ScenarioManager/Method_CapacityAndSaleBudgeChart.qbl
@@ -4,9 +4,9 @@
  MacroPlans macroPlans,
  Boolean isCapacity,
  String groupBy,
  String byBusinessTypeOrByOrgCodde,
  String businessType,
  String orgCode,
  String byBusinessTypeOrByOrgCode,
  String businessTypeChosen,
  String placeOfProductionOfArrayChosen,
  String year,
  MPSync mpSync,
  GlobalOTDTable otdTable,
@@ -17,13 +17,226 @@
  TextBody:
  [*
    // yypsybs Sep-19-2023 (created)
    // true, false
    info( isCapacity );
    // 月;季度;半年;年
    info( groupBy );
    // 面板基地;事业部
    info( byBusinessTypeOrByOrgCode );
    info( businessTypeChosen );
    info( placeOfProductionOfArrayChosen );
    info( year );
    // ====清理旧数据====
    this.CapacityAndSaleBudgeChartRow( relflush );
    this.CapacityAndSaleBudgeChartElement( relflush );
    
    info( isCapacity );
    info( groupBy );
    info( byBusinessTypeOrByOrgCodde );
    info( businessType );
    info( orgCode );
    info( year );
    // ====按面板基地和事业部对产品进行筛选分组====
    historyData := selectset( otdTable, CapacityAndSaleBudge, item, true );
    if( placeOfProductionOfArrayChosen <> "" ) {
      historyData := selectset( historyData, Elements, item, item.PlaceOfProductionOfArray() = placeOfProductionOfArrayChosen );
    }
    if( businessTypeChosen <> "" ) {
      historyData := selectset( historyData, Elements, item, item.BusinessType() = businessTypeChosen );
    }
    traverse( historyData, Elements, item ) {
      row := CapacityAndSaleBudgeChartRow::CreateIfNotExist( this, item.BusinessType(), item.PlaceOfProductionOfArray() );
      // 记录每行包含哪些product
      CapacityAndSaleBudgeChartRowProduct::CreateIfNotExist( row, item.ProductCode() );
    }
    rows := selectset( this, CapacityAndSaleBudgeChartRow, item, true );
    placeOfProductionOfArrayList := selectuniquevalues( historyData, Elements, item, item.PlaceOfProductionOfArray() );
    businessTypeList := selectuniquevalues( historyData, Elements, item, item.BusinessType() );
    // 生成图表元素
    if( byBusinessTypeOrByOrgCode = "面板基地" and groupBy = "年" ) {
      // 目标
      traverse( placeOfProductionOfArrayList, Elements, placeOfProductionOfArray ) {
        productCodeList := CapacityAndSaleBudgeChartRow::GetProductCodesByPlaceOfProductionOfArray( rows, placeOfProductionOfArray );
        this.CapacityAndSaleBudgeChartElement( relnew,
                                               TimeStringAndScenarioName := [String]year + "年-目标",
                                               BusinessTypeOrOrgCode := placeOfProductionOfArray,
                                               Quantity := ifexpr( isCapacity,
                                                                   CapacityAndSaleBudge::GetSheetByYear( productCodeList, otdTable, [Number]year ),
                                                                   MappingForecast::GetQuantityByYear( productCodeList, mappingParent, [Number]year ) )
                                               );
          // S&OP
        traverse( macroPlans, Elements, macroPlan ) {
          this.CapacityAndSaleBudgeChartElement( relnew,
                                                 TimeStringAndScenarioName := [String]year + "年-" + macroPlan.ScenarioName(),
                                                 BusinessTypeOrOrgCode := placeOfProductionOfArray,
                                                 Quantity := ifexpr( isCapacity,
                                                                     Product_MP::GetNewSupplyByYear( productCodeList, macroPlan, [Number]year ),
                                                                     0.0 )
                                                 );
        }
      }
    }
    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 + "年-" + ifexpr( halfNo = 1, "上", "下" ) + "半年-目标",
                                                 BusinessTypeOrOrgCode := placeOfProductionOfArray,
                                                 Quantity := ifexpr( isCapacity,
                                                                     CapacityAndSaleBudge::GetSheetByHalfYear( productCodeList, otdTable, [Number]year, halfNo ),
                                                                     MappingForecast::GetQuantityByHalfYear( productCodeList, mappingParent, [Number]year, halfNo ) )
                                                 );
            // S&OP
          traverse( macroPlans, Elements, macroPlan ) {
            this.CapacityAndSaleBudgeChartElement( relnew,
                                                   TimeStringAndScenarioName := [String]year + "年-" + ifexpr( halfNo = 1, "上", "下" ) + "半年-" + macroPlan.ScenarioName(),
                                                   BusinessTypeOrOrgCode := placeOfProductionOfArray,
                                                   Quantity := ifexpr( isCapacity,
                                                                       Product_MP::GetNewSupplyByHalfYear( productCodeList, macroPlan, [Number]year, halfNo ),
                                                                       0.0 )
                                                   );
          }
        }
      }
    }
    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 + "年-第" + [String]seasonNo + "季度-目标",
                                                 BusinessTypeOrOrgCode := placeOfProductionOfArray,
                                                 Quantity := ifexpr( isCapacity,
                                                                     CapacityAndSaleBudge::GetSheetBySeason( productCodeList, otdTable, [Number]year, seasonNo ),
                                                                     MappingForecast::GetQuantityBySeason( productCodeList, mappingParent, [Number]year, seasonNo ) )
                                                 );
            // S&OP
          traverse( macroPlans, Elements, macroPlan ) {
            this.CapacityAndSaleBudgeChartElement( relnew,
                                                   TimeStringAndScenarioName := [String]year + "年-第" + [String]seasonNo + "季度-" + macroPlan.ScenarioName(),
                                                   BusinessTypeOrOrgCode := placeOfProductionOfArray,
                                                   Quantity := ifexpr( isCapacity,
                                                                       Product_MP::GetNewSupplyBySeason( productCodeList, macroPlan, [Number]year, seasonNo ),
                                                                       0.0 )
                                                   );
          }
        }
      }
    }
    if ( byBusinessTypeOrByOrgCode = "面板基地" and groupBy = "月" ) {
      for( monthNo := 1; monthNo <= 12; monthNo := monthNo + 1 ) {
        traverse( placeOfProductionOfArrayList, Elements, placeOfProductionOfArray ) {
          productCodeList := CapacityAndSaleBudgeChartRow::GetProductCodesByPlaceOfProductionOfArray( rows, placeOfProductionOfArray );
          this.CapacityAndSaleBudgeChartElement( relnew,
                                                 TimeStringAndScenarioName := [String]year + "年-第" + [String]monthNo + "月-目标",
                                                 BusinessTypeOrOrgCode := placeOfProductionOfArray,
                                                 Quantity := ifexpr( isCapacity,
                                                                     CapacityAndSaleBudge::GetSheetByMonth( productCodeList, otdTable, [Number]year, monthNo ),
                                                                     MappingForecast::GetQuantityByMonth( productCodeList, mappingParent, [Number]year, monthNo ) )
                                                 );
            // S&OP
          traverse( macroPlans, Elements, macroPlan ) {
            this.CapacityAndSaleBudgeChartElement( relnew,
                                                   TimeStringAndScenarioName := [String]year + "年-第" + [String]monthNo + "月-" + macroPlan.ScenarioName(),
                                                   BusinessTypeOrOrgCode := placeOfProductionOfArray,
                                                   Quantity := ifexpr( isCapacity,
                                                                       Product_MP::GetNewSupplyByMonth( productCodeList, macroPlan, [Number]year, monthNo ),
                                                                       0.0 )
                                                   );
          }
        }
      }
    }
    if( byBusinessTypeOrByOrgCode = "事业部" and groupBy = "年" ) {
      // 目标
      traverse( businessTypeList, Elements, businessType ) {
        productCodeList := CapacityAndSaleBudgeChartRow::GetProductCodesByBusinessType( rows, businessType );
        this.CapacityAndSaleBudgeChartElement( relnew,
                                               TimeStringAndScenarioName := [String]year + "年-目标",
                                               BusinessTypeOrOrgCode := businessType,
                                               Quantity := ifexpr( isCapacity,
                                                                   CapacityAndSaleBudge::GetSheetByYear( productCodeList, otdTable, [Number]year ),
                                                                   MappingForecast::GetQuantityByYear( productCodeList, mappingParent, [Number]year ) )
                                               );
          // S&OP
        traverse( macroPlans, Elements, macroPlan ) {
          this.CapacityAndSaleBudgeChartElement( relnew,
                                                 TimeStringAndScenarioName := [String]year + "年-" + macroPlan.ScenarioName(),
                                                 BusinessTypeOrOrgCode := businessType,
                                                 Quantity := ifexpr( isCapacity,
                                                                     Product_MP::GetNewSupplyByYear( productCodeList, macroPlan, [Number]year ),
                                                                     0.0 )
                                                 );
        }
      }
    }
    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 + "年-" + ifexpr( halfNo = 1, "上", "下" ) + "半年-目标",
                                                 BusinessTypeOrOrgCode := businessType,
                                                 Quantity := ifexpr( isCapacity,
                                                                     CapacityAndSaleBudge::GetSheetByHalfYear( productCodeList, otdTable, [Number]year, halfNo ),
                                                                     MappingForecast::GetQuantityByHalfYear( productCodeList, mappingParent, [Number]year, halfNo ) )
                                                 );
            // S&OP
          traverse( macroPlans, Elements, macroPlan ) {
            this.CapacityAndSaleBudgeChartElement( relnew,
                                                   TimeStringAndScenarioName := [String]year + "年-" + ifexpr( halfNo = 1, "上", "下" ) + "半年-" + macroPlan.ScenarioName(),
                                                   BusinessTypeOrOrgCode := businessType,
                                                   Quantity := ifexpr( isCapacity,
                                                                       Product_MP::GetNewSupplyByHalfYear( productCodeList, macroPlan, [Number]year, halfNo ),
                                                                       0.0 )
                                                   );
          }
        }
      }
    }
    if ( byBusinessTypeOrByOrgCode = "事业部" and groupBy = "季度" ) {
      for( seasonNo := 1; seasonNo <= 4; seasonNo := seasonNo + 1 ) {
        traverse( businessTypeList, Elements, businessType ) {
          productCodeList := CapacityAndSaleBudgeChartRow::GetProductCodesByBusinessType( rows, businessType );
          this.CapacityAndSaleBudgeChartElement( relnew,
                                                 TimeStringAndScenarioName := [String]year + "年-第" + [String]seasonNo + "季度-目标",
                                                 BusinessTypeOrOrgCode := businessType,
                                                 Quantity := ifexpr( isCapacity,
                                                                     CapacityAndSaleBudge::GetSheetBySeason( productCodeList, otdTable, [Number]year, seasonNo ),
                                                                     MappingForecast::GetQuantityBySeason( productCodeList, mappingParent, [Number]year, seasonNo ) )
                                                 );
            // S&OP
          traverse( macroPlans, Elements, macroPlan ) {
            this.CapacityAndSaleBudgeChartElement( relnew,
                                                   TimeStringAndScenarioName := [String]year + "年-第" + [String]seasonNo + "季度-" + macroPlan.ScenarioName(),
                                                   BusinessTypeOrOrgCode := businessType,
                                                   Quantity := ifexpr( isCapacity,
                                                                       Product_MP::GetNewSupplyBySeason( productCodeList, macroPlan, [Number]year, seasonNo ),
                                                                       0.0 )
                                                   );
          }
        }
      }
    }
    if ( byBusinessTypeOrByOrgCode = "事业部" and groupBy = "月" ) {
      for( monthNo := 1; monthNo <= 12; monthNo := monthNo + 1 ) {
        traverse( businessTypeList, Elements, businessType ) {
          productCodeList := CapacityAndSaleBudgeChartRow::GetProductCodesByBusinessType( rows, businessType );
          this.CapacityAndSaleBudgeChartElement( relnew,
                                                 TimeStringAndScenarioName := [String]year + "年-第" + [String]monthNo + "月-目标",
                                                 BusinessTypeOrOrgCode := businessType,
                                                 Quantity := ifexpr( isCapacity,
                                                                     CapacityAndSaleBudge::GetSheetByMonth( productCodeList, otdTable, [Number]year, monthNo ),
                                                                     MappingForecast::GetQuantityByMonth( productCodeList, mappingParent, [Number]year, monthNo ) )
                                                 );
            // S&OP
          traverse( macroPlans, Elements, macroPlan ) {
            this.CapacityAndSaleBudgeChartElement( relnew,
                                                   TimeStringAndScenarioName := [String]year + "年-第" + [String]monthNo + "月-" + macroPlan.ScenarioName(),
                                                   BusinessTypeOrOrgCode := businessType,
                                                   Quantity := ifexpr( isCapacity,
                                                                       Product_MP::GetNewSupplyByMonth( productCodeList, macroPlan, [Number]year, monthNo ),
                                                                       0.0 )
                                                   );
          }
        }
      }
    }
  *]
}