yanyuan
2023-08-30 eb958a9c253061d89ea524fe124b326369678557
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
Quintiq file version 2.0
#parent: #root
StaticMethod CreateFromJson (
  MacroPlan macroPlan,
  JSON json
) as CurrencyRate_MP
{
  TextBody:
  [*
    // yypsybs Aug-14-2023 (created)
    
    if( not json.Has( "CurrencyID" ) or not json.Has( "Rate" ) or not json.Has( "Start" ) ){
      error( "illegal currency rate data" );  
    }
    
    currencyID := json.Get("CurrencyID").GetString();
    rate := json.Get("Rate").GetReal();
    startStr := json.Get("Start").GetString();
    
    cnv := StringToDateTime::StandardConverter();
    cnv.SetCustomConversion();
    cnv.CustomFormatString( "yyyy/MM/dd" );
    
    start := DateTime::MinDateTime();
    
    try {
      start := cnv.Convert( startStr );
    } onerror {
      error( "wrong date format" )
    }
    
    parent := Currency_MP::FindById( macroPlan, currencyID );
    
    if( isnull( parent ) ) {
      error( "currency not found with id : " + currencyID );
    }
    
    result := parent.CurrencyRate_MP( relnew, CurrencyID := currencyID, Rate := rate, Start := start.Date() );
    
    return result;
  *]
}