xiaoding721
2024-09-10 f8f5f77c1504d85a9b87e69249f2309e42c6fa44
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
Quintiq file version 2.0
#parent: #root
StaticMethod GenerateData (
  MacroPlan macroplan,
  RecycleBin recycle,
  const Archive archive
)
{
  Description: '生成可以下发的客户需求(PPA+IDS)数据'
  TextBody:
  [*
    // 甄兰鸽 Aug-20-2024 (created)
    macroplan.CustomerDemandIDS( relflush );
    macroplan.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 := '客户需求' );
    binaryValue           := TemplateManager::GetIDSFullTable( archive, Date::ActualDate().Year() );
    source                := GeneralExcelImportAndExportDataSource::Upload( recycle, binaryValue, OS::TempPath() + "template.xlsx" );
    source.ReadStructure();
    Transaction::Transaction().Propagate( attribute( GeneralExcelImportAndExportDataColumn, ColumnIndex ) );
    cnv2 := StringToDate::StandardConverter();
    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() ) );
    }
    periods               := idsdates.Union( ppadates );
    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() );
        traverse( row, GeneralExcelImportAndExportDataCell, cell, cell.GeneralExcelImportAndExportDataColumn().ColumnIndex() > 2 ){
          period          := cnv2.Convert( cell.GeneralExcelImportAndExportDataColumn().Name() );
          daycolumn       := idstable.GetColumnByTimeUnit( Translations::MP_GlobalParameters_Day(), period );
          weekcolumn      := idstable.GetColumnByTimeUnit( Translations::MP_GlobalParameters_Week(), period );
          monthcolumn     := idstable.GetColumnByTimeUnit( Translations::MP_GlobalParameters_Month(), period );
          idsrow.SetCellValue( daycolumn, [Number]cell.Value() );
          idsrow.SetCellValue( weekcolumn, [Number]cell.Value() );
          idsrow.SetCellValue( monthcolumn, [Number]cell.Value() );
        }
      }
    }
    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() );
      }
    }
    
    source.Delete();
  *]
}