lazhen
2024-09-13 b343b593893e2f3278f2695d1411f3aacaeedfc8
_Main/BL/Type_CustomerDemandIDS/StaticMethod_GenerateData.qbl
@@ -1,7 +1,7 @@
Quintiq file version 2.0
#parent: #root
StaticMethod GenerateData (
  MacroPlan macroplan,
  InterfaceDataset interface,
  RecycleBin recycle,
  const Archive archive
)
@@ -10,11 +10,11 @@
  TextBody:
  [*
    // 甄兰鸽 Aug-20-2024 (created)
    macroplan.CustomerDemandIDS( relflush );
    macroplan.CustomerDemandIDSSearch( relflush );
    interface.CustomerDemandIDS( relflush );
    interface.CustomerDemandIDSSearch( relflush );
    allunit               := CustomerDemandIDS::GetDefaultAllUnit();
    macroplan.CustomerDemandIDSSearch( relnew, Generation := allunit, MqbMlb := allunit, Power := allunit, TimeUnit := Translations::MP_GlobalParameters_Day(), Unit := allunit );
    idstable              := macroplan.CustomerDemandIDS( relnew, ID := '客户需求', Name := '客户需求' );
    interface.CustomerDemandIDSSearch( relnew, Generation := allunit, MqbMlb := allunit, Power := allunit, TimeUnit := Translations::MP_GlobalParameters_Day(), Unit := allunit );
    idstable              := interface.CustomerDemandIDS( relnew, ID := '客户需求', Name := '客户需求' );
    binaryValue           := TemplateManager::GetIDSFullTable( archive, Date::ActualDate().Year() );
    source                := GeneralExcelImportAndExportDataSource::Upload( recycle, binaryValue, OS::TempPath() + "template.xlsx" );
    source.ReadStructure();
@@ -23,18 +23,19 @@
    cnv2.SetCustomConversion();
    cnv2.CustomFormatString( "yyyy/MM/dd" );
    idsdates              := selectuniquevalues( source, GeneralExcelImportAndExportDataTable.GeneralExcelImportAndExportDataColumn, column, column.ColumnIndex() > 2, cnv2.Convert( column.Name() ) );
    ppadates              := construct( Dates );
    traverse( macroplan, SalesDemand.astype( Forecast ), forecast, forecast.Origin() = 'PPA' ){
      ppadates            := ppadates.Union( selectuniquevalues( forecast, PlanningSalesDemandInPeriod, salesdemand, salesdemand.StartDate() ) );
    }
    ppadates              := selectuniquevalues( interface, InterfaceForecast, forecast, forecast.Origin() = 'PPA', forecast.Date() );
    //ppadates              := construct( Dates );
    //traverse( macroplan, SalesDemand.astype( Forecast ), forecast, forecast.Origin() = 'PPA' ){
    //  ppadates            := ppadates.Union( selectuniquevalues( forecast, PlanningSalesDemandInPeriod, salesdemand, salesdemand.StartDate() ) );
    //}
    periods               := idsdates.Union( ppadates );
    periods               := selectuniquevalues( periods, Elements, e, e );
    idstable.GenerateColumn( periods.Sort() );
    traverse( recycle, GeneralExcelImportAndExportDataSource.GeneralExcelImportAndExportDataTable, table ){
      traverse( table, GeneralExcelImportAndExportDataRow, row ){
        productcell       := selectobject( row, GeneralExcelImportAndExportDataCell, cell, cell.GeneralExcelImportAndExportDataColumn().ColumnIndex() = 2 );
        factorycell       := selectobject( row, GeneralExcelImportAndExportDataCell, cell, cell.GeneralExcelImportAndExportDataColumn().ColumnIndex() = 0 );
        product           := selectobject( macroplan, Product_MP, product, product.ID() = productcell.Value() );
        idsrow            := idstable.GetRowByUnit( product, factorycell.Value() );
        idsrow            := idstable.GetRowByUnit( productcell.Value(), factorycell.Value() );
        traverse( row, GeneralExcelImportAndExportDataCell, cell, cell.GeneralExcelImportAndExportDataColumn().ColumnIndex() > 2 ){
          period          := cnv2.Convert( cell.GeneralExcelImportAndExportDataColumn().Name() );
          daycolumn       := idstable.GetColumnByTimeUnit( Translations::MP_GlobalParameters_Day(), period );
@@ -46,17 +47,14 @@
        }
      }
    }
    traverse( macroplan, SalesDemand.astype( Forecast ), forecast, forecast.Origin() = 'PPA' ){
      product             := forecast.Product_MP();
      idsrow              := idstable.GetRowByUnit( product, forecast.SalesSegmentName() );
      traverse( forecast, PlanningSalesDemandInPeriod, salesdemand ){
        daycolumn         := idstable.GetColumnByTimeUnit( Translations::MP_GlobalParameters_Day(), salesdemand.StartDate() );
        weekcolumn        := idstable.GetColumnByTimeUnit( Translations::MP_GlobalParameters_Week(), salesdemand.StartDate() );
        monthcolumn       := idstable.GetColumnByTimeUnit( Translations::MP_GlobalParameters_Month(), salesdemand.StartDate() );
        idsrow.SetCellValue( daycolumn, [Number]salesdemand.Quantity() );
        idsrow.SetCellValue( weekcolumn, [Number]salesdemand.Quantity() );
        idsrow.SetCellValue( monthcolumn, [Number]salesdemand.Quantity() );
      }
    traverse( interface, InterfaceForecast, forecast, forecast.Origin() = 'PPA' ){
      idsrow              := idstable.GetRowByUnit( forecast.PartNumber(), forecast.Factory() );
      daycolumn           := idstable.GetColumnByTimeUnit( Translations::MP_GlobalParameters_Day(), forecast.Date() );
      weekcolumn          := idstable.GetColumnByTimeUnit( Translations::MP_GlobalParameters_Week(), forecast.Date() );
      monthcolumn         := idstable.GetColumnByTimeUnit( Translations::MP_GlobalParameters_Month(), forecast.Date() );
      idsrow.SetCellValue( daycolumn, [Number]forecast.Quantity() );
      idsrow.SetCellValue( weekcolumn, [Number]forecast.Quantity() );
      idsrow.SetCellValue( monthcolumn, [Number]forecast.Quantity() );
    }
    
    source.Delete();