yanyuan
2023-11-01 c673b37d38537c136cd488b8430146573975d5e3
_Main/BL/Type_GlobalOTDSOP/Method_CapacityAndSaleBudgeChart.qbl
@@ -15,73 +15,47 @@
  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() );
    //}
    info( "产能/销售额:", saleOrCapacity, "    时间分组:", groupBy, "    基地/事业部:", byBusinessTypeOrByOrgCode );
    // 年份不选时全选
    if( years.Size() = 0 ) {
      years := selectsortedset( this, CapacityAndSaleBudgeFilterYear, item, true, item.YearNo() );
    if ( years.Size() = 0 ) {
      years := selectset( this, CapacityAndSaleBudgeFilterYear, tempCASBFY, tempCASBFY.YearNo() = Date::ActualDate().Year() );
    }
    //traverse( years, Elements, year ) {
    //  debuginfo( "yearNo : " + [String]year.YearNo() );
    //}
    // 月份不选时全选
    if( months.Size() = 0 ) {
    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 ) {
    targeGlobal_MappingAnnualBudgetDatas := selectset( otdTable, Global_MappingAnnualBudgetData, tempGMABD, true );
    if ( businessTypes.Size() > 0 ) {
      businessTypeStrings := selectuniquevalues( businessTypes, Elements, item, true, item.BusinessType() );
      historyData := selectset( historyData, Elements, item, businessTypeStrings.Find( item.BusinessType() ) > -1 );
      targeGlobal_MappingAnnualBudgetDatas := selectset( targeGlobal_MappingAnnualBudgetDatas, Elements, item, businessTypeStrings.Find( item.BusinessType() ) > -1 );
    }
    if( placeOfProductionOfArrays.Size() > 0 ) {
    if ( placeOfProductionOfArrays.Size() > 0 ) {
      placeOfProductionOfArrayStrings := selectuniquevalues( placeOfProductionOfArrays, Elements, item, true, item.PlaceOfProductionOfArray() );
      historyData := selectset( historyData, Elements, item, placeOfProductionOfArrayStrings.Find( item.OrgCodeFromBom() ) > -1 );
      targeGlobal_MappingAnnualBudgetDatas := selectset( targeGlobal_MappingAnnualBudgetDatas, Elements, item, placeOfProductionOfArrayStrings.Find( item.OrganCode() ) > -1 );
    }
    //info( "historyData : " + [String]historyData.Size() );
    traverse( historyData, Elements, item ) {
      row := CapacityAndSaleBudgeChartRow::CreateIfNotExist( this, item.BusinessType(), item.OrgCodeFromBom() );
    info( "选中的个数:", targeGlobal_MappingAnnualBudgetDatas.Size() );
    traverse ( targeGlobal_MappingAnnualBudgetDatas, Elements, gmabd ) {
      row := CapacityAndSaleBudgeChartRow::CreateIfNotExist( this, gmabd.BusinessType(), gmabd.OrganCode() );
      // 记录每行包含哪些product
      CapacityAndSaleBudgeChartRowProduct::CreateIfNotExist( row, item.ProductID() );
      CapacityAndSaleBudgeChartRowProduct::CreateIfNotExist( row, gmabd.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 );
    //}
    placeOfProductionOfArrayList := selectuniquevalues( targeGlobal_MappingAnnualBudgetDatas, Elements, tempGMABD, tempGMABD.OrganCode() );
    businessTypeList := selectuniquevalues( targeGlobal_MappingAnnualBudgetDatas, Elements, tempGMABD, tempGMABD.BusinessType() );
    // 生成图表元素
    traverse( years, Elements, year ) {
    //  debuginfo( "process year start : " + [String]year.YearNo() );
      if( byBusinessTypeOrByOrgCode = "面板基地" and groupBy = "年" ) {
    traverse ( years, Elements, year ) {
      if ( byBusinessTypeOrByOrgCode = "面板基地" and groupBy = "年" ) {
        // 目标
        traverse( placeOfProductionOfArrayList, Elements, placeOfProductionOfArray ) {
        traverse ( placeOfProductionOfArrayList, Elements, placeOfProductionOfArray ) {
          productCodeList := CapacityAndSaleBudgeChartRow::GetProductCodesByPlaceOfProductionOfArray( rows, placeOfProductionOfArray );
          this.CapacityAndSaleBudgeChartElement( relnew, 
                                                 TimeStringAndScenarioName := [String]year.YearNo() + "年-目标",
@@ -89,9 +63,9 @@
                                                 Quantity := ifexpr( saleOrCapacity = "销售额",
                                                                     Global_MappingAnnualBudgetData::GetSaleByYear( productCodeList, otdTable, year.YearNo() ),
                                                                     Global_MappingForecast::GetQuantityByYear( productCodeList, otdTable, year.YearNo() ) )
                                                 );
                                                );
          // S&OP
          traverse( macroPlans, Elements, macroPlan ) {
          traverse ( macroPlans, Elements, macroPlan ) {
            this.CapacityAndSaleBudgeChartElement( relnew, 
                                                   TimeStringAndScenarioName := [String]year.YearNo() + "年-" + macroPlan.ScenarioName(),
                                                   BusinessTypeOrPlaceOfProductionOfArray := placeOfProductionOfArray, 
@@ -286,17 +260,16 @@
    //      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( "==↑==" );
    //}
    ////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( "==↑==" );
    ////}
  *]
}