Quintiq file version 2.0 
 | 
#parent: #root 
 | 
Method CapacityAndSaleBudgeCompare ( 
 | 
  MacroPlans macroPlans, 
 | 
  CapacityAndSaleBudgeFilterItems items, 
 | 
  CapacityAndSaleBudgeFilterYears years, 
 | 
  CapacityAndSaleBudgeFilterMonths months, 
 | 
  MPSync mpSync, 
 | 
  GlobalOTDTable otdTable, 
 | 
  MacroPlan mappingParent 
 | 
) 
 | 
{ 
 | 
  Description: 'todo : mappingParent改为mpSync, random删了' 
 | 
  TextBody: 
 | 
  [* 
 | 
    // yypsybs Sep-18-2023 (created) 
 | 
    // ====不选时默认全选==== 
 | 
    if( years.Size() = 0 ) { 
 | 
      years := selectsortedset( this, CapacityAndSaleBudgeFilterYear, item, item.YearNo() ); 
 | 
    } 
 | 
    if( months.Size() = 0 ) { 
 | 
      months := selectsortedset( this, CapacityAndSaleBudgeFilterMonth, item, item.MonthNo() ); 
 | 
    } 
 | 
    traverse( macroPlans, Elements, item ) { 
 | 
      info( "scenario : " + item.ScenarioName() ); 
 | 
    } 
 | 
    traverse( items, Elements, item ) { 
 | 
      info( "item : " + item.ItemName() ); 
 | 
    } 
 | 
    traverse( years, Elements, item ) { 
 | 
      info( "year : " + [String]item.YearNo() ); 
 | 
    } 
 | 
    traverse( months, Elements, item ) { 
 | 
      info( "month : " + [String]item.MonthNo() ); 
 | 
    } 
 | 
    // ====清理旧数据==== 
 | 
    this.CapacityAndSaleBudgeCompareItemRow( relflush ); 
 | 
    this.CapacityAndSaleBudgeCompareItemColumn( relflush ); 
 | 
    // ====汇总所有出现的产品==== 
 | 
    historyData := selectset( mpSync, MappingCapacityAndSaleBudge, item, true ); 
 | 
    info( "historyData : " + [String]historyData.Size() ) 
 | 
    traverse( historyData, Elements, one ) { 
 | 
      productCode := one.ProductCode(); 
 | 
      MappingBOM::CreateTestData( mappingParent, "事业部" + [String](productCode.Length() mod 3), [String](productCode.Length() mod 4), productCode ); 
 | 
      boms := selectset( mappingParent, MappingBOM, bom, bom.ProductCode() = productCode ); 
 | 
      if( boms.Size() > 0 ) { 
 | 
        bom := boms.First(); 
 | 
        businessType := bom.BusinessType(); 
 | 
        placeOfProductionOfArray := one.PlaceOfProductionOfArray(); 
 | 
        // 相同面板基地和事业部的放一行 
 | 
        row := CapacityAndSaleBudgeCompareItemRow::CreateIfNotExist( this, businessType, placeOfProductionOfArray ); 
 | 
        // 记录每行包含哪些product 
 | 
        CapacityAndSaleBudgeCompareItemRowProduct::CreateIfNotExist( row, productCode ); 
 | 
      } else { 
 | 
        info( "no boms for product : " + productCode ); 
 | 
      } 
 | 
    } 
 | 
    info( "CapacityAndSaleBudgeCompareItemRow : " + [String]selectset( this, CapacityAndSaleBudgeCompareItemRow, item, true ).Size() ); 
 | 
    // ====从左向右生成列头与内容==== 
 | 
    // 事业部,组织 
 | 
    info( "dealing businessType and placeOfProductionOfArray" ) 
 | 
    columnBusinessType := CapacityAndSaleBudgeCompareItemColumn::CreateIfNotExist( this, "事业部" ); 
 | 
    columnPlaceOfProductionOfArray := CapacityAndSaleBudgeCompareItemColumn::CreateIfNotExist( this, "面板基地" ); 
 | 
    traverse( this, CapacityAndSaleBudgeCompareItemRow, row ) { 
 | 
      cell := columnBusinessType.CapacityAndSaleBudgeCompareItemCell( relnew, CellContent := row.BusinessType() ); 
 | 
      cell.CapacityAndSaleBudgeCompareItemRow( relset, row ); 
 | 
      cell := columnPlaceOfProductionOfArray.CapacityAndSaleBudgeCompareItemCell( relnew, CellContent := row.PlaceOfProductionOfArray() ); 
 | 
      cell.CapacityAndSaleBudgeCompareItemRow( relset, row ); 
 | 
    } 
 | 
    // 面板分配量 - 年度预算 (sheets) 
 | 
    // 格式: 面板分配量 - 年 - 月(1-12 & total) - 年度预算/scenarioName 
 | 
    info( "dealing 面板分配量" ) 
 | 
    if( CapacityAndSaleBudgeFilterItem::Contains( items, "面板分配量" ) ) { 
 | 
      traverse( years, Elements, year ) { 
 | 
        info( "面板分配量" + [String]year.YearNo() + "年" ); 
 | 
        // 历史数据 
 | 
        info( "面板分配量" + [String]year.YearNo() + "年历史数据" ); 
 | 
        traverse( months, Elements, month ) { 
 | 
          columnMonth := CapacityAndSaleBudgeCompareItemColumn::CreateIfNotExist( this, "面板分配量-" + [String]year.YearNo() + "年-" + [String]month.MonthNo() + "月-年度预算" ); 
 | 
          traverse( this, CapacityAndSaleBudgeCompareItemRow, row ) { 
 | 
            cellReal := MappingCapacityAndSaleBudge::GetSheetByMonth( row.GetProductCodes(), mpSync, DateTime::Now().Year(), month.MonthNo() ); 
 | 
            cell := columnMonth.CapacityAndSaleBudgeCompareItemCell( relnew, CellContent := [String]cellReal ); 
 | 
            cell.CapacityAndSaleBudgeCompareItemRow( relset, row ); 
 | 
          } 
 | 
        } 
 | 
        columnYear := CapacityAndSaleBudgeCompareItemColumn::CreateIfNotExist( this, "面板分配量-" + [String]year.YearNo() + "年-total-年度预算" ); 
 | 
        traverse( this, CapacityAndSaleBudgeCompareItemRow, row ) { 
 | 
          cellReal := MappingCapacityAndSaleBudge::GetSheetByYear( row.GetProductCodes(), mpSync, year.YearNo() ); 
 | 
          cell := columnYear.CapacityAndSaleBudgeCompareItemCell( relnew, CellContent := [String]cellReal ); 
 | 
          cell.CapacityAndSaleBudgeCompareItemRow( relset, row ); 
 | 
        } 
 | 
        info( "面板分配量" + [String]year.YearNo() + "年S&OP数据" ); 
 | 
        // S&OP数据 
 | 
        traverse( macroPlans, Elements, macroPlan ) { 
 | 
          traverse( months, Elements, month ) { 
 | 
            columnMonth := CapacityAndSaleBudgeCompareItemColumn::CreateIfNotExist( this,  
 | 
                                                                                    "面板分配量-" + [String]year.YearNo() + "年-" + [String]month.MonthNo() + "月-" + macroPlan.ScenarioName() ); 
 | 
            traverse( this, CapacityAndSaleBudgeCompareItemRow, row ) { 
 | 
              cellReal := Product_MP::GetNewSupplyByMonth( row.GetProductCodes(), macroPlan, year.YearNo(), month.MonthNo() ); 
 | 
              cell := columnMonth.CapacityAndSaleBudgeCompareItemCell( relnew, CellContent := [String]cellReal ); 
 | 
              cell.CapacityAndSaleBudgeCompareItemRow( relset, row ); 
 | 
            } 
 | 
          } 
 | 
          columnYear := CapacityAndSaleBudgeCompareItemColumn::CreateIfNotExist( this,  
 | 
                                                                                 "面板分配量-" + [String]year.YearNo() + "年-total-" + macroPlan.ScenarioName() ); 
 | 
          traverse( this, CapacityAndSaleBudgeCompareItemRow, row ) { 
 | 
            cellReal := Product_MP::GetNewSupplyByYear( row.GetProductCodes(), macroPlan, year.YearNo() ); 
 | 
            cell := columnYear.CapacityAndSaleBudgeCompareItemCell( relnew, CellContent := [String]cellReal ); 
 | 
            cell.CapacityAndSaleBudgeCompareItemRow( relset, row ); 
 | 
          } 
 | 
        } 
 | 
      } 
 | 
    } 
 | 
    // 年度销售额 
 | 
    info( "dealing 销售额" ) 
 | 
    if( CapacityAndSaleBudgeFilterItem::Contains( items, "销售额" ) ) { 
 | 
      traverse( years, Elements, year ) { 
 | 
        info( "销售额" + [String]year.YearNo() + "年" ); 
 | 
        // 历史数据 
 | 
        info( "销售额" + [String]year.YearNo() + "年历史数据" ); 
 | 
        traverse( months, Elements, month ) { 
 | 
          columnMonth := CapacityAndSaleBudgeCompareItemColumn::CreateIfNotExist( this, "对外销售额-" + [String]year.YearNo() + "年-" + [String]month.MonthNo() + "月-年度预算" ); 
 | 
          traverse( this, CapacityAndSaleBudgeCompareItemRow, row ) { 
 | 
            cellReal := MappingCapacityAndSaleBudge::GetSaleByMonth( row.GetProductCodes(), mpSync, year.YearNo(), month.MonthNo() ); 
 | 
            cell := columnMonth.CapacityAndSaleBudgeCompareItemCell( relnew, CellContent := [String]cellReal ); 
 | 
            cell.CapacityAndSaleBudgeCompareItemRow( relset, row ); 
 | 
          } 
 | 
        } 
 | 
        columnYear := CapacityAndSaleBudgeCompareItemColumn::CreateIfNotExist( this, "对外销售额-" + [String]year.YearNo() + "年-年度预算" ); 
 | 
        traverse( this, CapacityAndSaleBudgeCompareItemRow, row ) { 
 | 
          cellReal := MappingCapacityAndSaleBudge::GetSaleByYear( row.GetProductCodes(), mpSync, year.YearNo() ); 
 | 
          cell := columnYear.CapacityAndSaleBudgeCompareItemCell( relnew, CellContent := [String]cellReal ); 
 | 
          cell.CapacityAndSaleBudgeCompareItemRow( relset, row ); 
 | 
        } 
 | 
        info( "销售额" + [String]year.YearNo() + "年历史数据S&OP数据" ); 
 | 
        // S&OP数据 
 | 
        traverse( macroPlans, Elements, macroPlan ) { 
 | 
          traverse( months, Elements, month ) { 
 | 
            columnMonth := CapacityAndSaleBudgeCompareItemColumn::CreateIfNotExist( this, "对外销售额-" + [String]year.YearNo() + "年-" + [String]month.MonthNo() + "月-" + macroPlan.ScenarioName() ); 
 | 
            traverse( this, CapacityAndSaleBudgeCompareItemRow, row ) { 
 | 
              cellReal := MappingAnnualBudget::GetSaleByMonth( row.GetProductCodes(), mpSync, year.YearNo(), month.MonthNo() ); 
 | 
              cell := columnMonth.CapacityAndSaleBudgeCompareItemCell( relnew, CellContent := [String]cellReal ); 
 | 
              cell.CapacityAndSaleBudgeCompareItemRow( relset, row ); 
 | 
            } 
 | 
          } 
 | 
          columnYear := CapacityAndSaleBudgeCompareItemColumn::CreateIfNotExist( this, "对外销售额-" + [String]year.YearNo() + "年-total-" + macroPlan.ScenarioName() ); 
 | 
          traverse( this, CapacityAndSaleBudgeCompareItemRow, row ) { 
 | 
            // QID 23 
 | 
            cellReal := MappingAnnualBudget::GetSaleByYear( row.GetProductCodes(), mpSync, year.YearNo() ); 
 | 
            cell := columnYear.CapacityAndSaleBudgeCompareItemCell( relnew, CellContent := [String]cellReal ); 
 | 
            cell.CapacityAndSaleBudgeCompareItemRow( relset, row ); 
 | 
          } 
 | 
        } 
 | 
      } 
 | 
    } 
 | 
    // 大张盈利额 
 | 
    info( "dealing 大张盈利额" ) 
 | 
    traverse( years, Elements, year ) { 
 | 
      // 历史数据 
 | 
      columnYear := CapacityAndSaleBudgeCompareItemColumn::CreateIfNotExist( this, "大张盈利额-" + [String]year.YearNo() + "年-年度预算" ); 
 | 
      traverse( this, CapacityAndSaleBudgeCompareItemRow, row ) { 
 | 
        // todo  
 | 
        // QID 23 
 | 
        cell := columnYear.CapacityAndSaleBudgeCompareItemCell( relnew, CellContent := [String]Number::Random( 0, 0 ) ); 
 | 
        cell.CapacityAndSaleBudgeCompareItemRow( relset, row ); 
 | 
      } 
 | 
      // S&OP数据 
 | 
      traverse( macroPlans, Elements, macroPlan ) { 
 | 
        columnYear := CapacityAndSaleBudgeCompareItemColumn::CreateIfNotExist( this, "大张盈利额-" + [String]year.YearNo() + "年-" + macroPlan.ScenarioName() ); 
 | 
        traverse( this, CapacityAndSaleBudgeCompareItemRow, row ) { 
 | 
          cell := columnYear.CapacityAndSaleBudgeCompareItemCell( relnew, CellContent := [String]Number::Random( 0, 0 ) ); 
 | 
          cell.CapacityAndSaleBudgeCompareItemRow( relset, row ); 
 | 
        } 
 | 
      } 
 | 
    } 
 | 
    // 产品盈利额 
 | 
    info( "dealing 产品盈利额" ) 
 | 
    traverse( years, Elements, year ) { 
 | 
      // 历史数据 
 | 
      columnYear := CapacityAndSaleBudgeCompareItemColumn::CreateIfNotExist( this, "产品盈利额-" + [String]year.YearNo() + "年-年度预算" ); 
 | 
      traverse( this, CapacityAndSaleBudgeCompareItemRow, row ) { 
 | 
        // todo 
 | 
        cell := columnYear.CapacityAndSaleBudgeCompareItemCell( relnew, CellContent := [String]Number::Random( 0, 0 ) ); 
 | 
        cell.CapacityAndSaleBudgeCompareItemRow( relset, row ); 
 | 
      } 
 | 
      // S&OP数据 
 | 
      traverse( macroPlans, Elements, macroPlan ) { 
 | 
        columnYear := CapacityAndSaleBudgeCompareItemColumn::CreateIfNotExist( this, "产品盈利额-" + [String]year.YearNo() + "年-" + macroPlan.ScenarioName() ); 
 | 
        traverse( this, CapacityAndSaleBudgeCompareItemRow, row ) { 
 | 
          // todo 
 | 
          cell := columnYear.CapacityAndSaleBudgeCompareItemCell( relnew, CellContent := [String]Number::Random( 0, 0 ) ); 
 | 
          cell.CapacityAndSaleBudgeCompareItemRow( relset, row ); 
 | 
        } 
 | 
      } 
 | 
    } 
 | 
     
 | 
    // 设置rowNo和columnNo 
 | 
    info( "set rowNo and columnNo" ); 
 | 
    rowNo := 1; 
 | 
    rowSorted := selectsortedset( this, CapacityAndSaleBudgeCompareItemRow, item, item.PlaceOfProductionOfArray() + "_" + item.BusinessType() ); 
 | 
    traverse( rowSorted, Elements, item ) { 
 | 
      item.RowNo( rowNo ); 
 | 
      rowNo := rowNo + 1; 
 | 
    } 
 | 
    columnNo := 1; 
 | 
    traverse( this, CapacityAndSaleBudgeCompareItemColumn, item ) { 
 | 
      item.ColumnNo( columnNo ); 
 | 
      columnNo := columnNo + 1; 
 | 
    } 
 | 
    info( "done" ); 
 | 
  *] 
 | 
} 
 |