admin
2025-01-22 7e31442f0e9b07764e9c6a9680d3d4aeba5fe1de
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
Quintiq file version 2.0
#parent: #root
StaticMethod GenerateData (
  InterfaceDataset interface,
  MacroPlan macroplan,
  RecycleBin recycle,
  const Archive archive
)
{
  Description: '生成可以下发的客户需求(PPA+IDS)数据'
  TextBody:
  [*
    // 甄兰鸽 Aug-20-2024 (created)
    //interface.CustomerDemandIDS( relflush );
    //interface.CustomerDemandIDSSearch( relflush );
    info( '-------------------------Start---------------------');
    allunit               := CustomerDemandIDS::GetDefaultAllUnit();//search                := 
    interface.CustomerDemandIDSSearch( relnew, Product := allunit, StartDate := Date::MinDate(), EndDate := Date::MaxDate(), Unit := allunit );
    name                  := '客户需求';
    idstable              := selectobject( interface, CustomerDemandIDS, idstable, idstable.ID() = name );
    if( isnull( idstable ) ){
      idstable            := interface.CustomerDemandIDS( relnew, ID := name, Name := name );
    }
    //showtable             := selectobject( interface, CustomerDemandIDS, version, version.IsShow() );
    //if( isnull( showtable ) ){
    //  showtable           := interface.CustomerDemandIDS( relnew, ID := name + 'Show', Name := name, IsShow := true );
    //}
    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              := selectuniquevalues( macroplan, SalesDemand.astype( Forecast ), forecast, forecast.Origin() = 'PPA', forecast.StartDate() );
    periods               := idsdates.Union( ppadates );
    periods               := selectuniquevalues( periods, Elements, e, not exists( idstable, Column, column, column.StartDate() = e ), e );
    if( periods.Size() > 0 ){
      idstable.GenerateColumn( periods.Sort(), false );
    }
    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 );
        unitname          := ifexpr( factorycell.Value().StartsWith( '长春' ), FinancialProductionReport::GetDefaultCCUnit(), FinancialProductionReport::GetDefaultDLUnit() );
        idsrow            := idstable.GetRowByUnit( productcell.Value(), unitname );
        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, not isnull( forecast.Product_MP() ) and forecast.Origin() = 'PPA' ){
      
      unitname              := ifexpr( forecast.StockingPointID().StartsWith( '长春' ) , FinancialProductionReport::GetDefaultCCUnit(), FinancialProductionReport::GetDefaultDLUnit() );/*ifexpr( forecast.SalesSegment_MP().Name().StartsWith( 'Changchun' ) 
                                       or exists( forecast.SalesSegment_MP().GetAllParent(), Elements, psalessegment, psalessegment.Name().StartsWith( 'Changchun' ) )
                                       , FinancialProductionReport::GetDefaultCCUnit()
                                       , FinancialProductionReport::GetDefaultDLUnit() );*/
      traverse( forecast, PlanningSalesDemandInPeriod, sdip ){
        idsrow              := idstable.GetRowByUnit( forecast.ProductID(), unitname );
        daycolumn           := idstable.GetColumnByTimeUnit( Translations::MP_GlobalParameters_Day(), sdip.StartDate() );
    //    weekcolumn          := idstable.GetColumnByTimeUnit( Translations::MP_GlobalParameters_Week(), sdip.StartDate() );
    //    monthcolumn         := idstable.GetColumnByTimeUnit( Translations::MP_GlobalParameters_Month(), sdip.StartDate() );
    //    info( '-----------------', isnull( idsrow ), isnull( daycolumn ), isnull( weekcolumn ), isnull( monthcolumn ), sdip.StartDate() );
        idsrow.SetCellValue( daycolumn, [Number]sdip.Quantity() );
    //    idsrow.SetCellValue( weekcolumn, [Number]sdip.Quantity() );
    //    idsrow.SetCellValue( monthcolumn, [Number]sdip.Quantity() );
      }
    }
    
    source.Delete();
    info( '-------------------------End---------------------');
    //productids             := selectuniquevalues( idstable, Row, row, row.Name() );
    //showtable.Generate( search, productids );
  *]
}