haorenhui
2023-10-30 6d6cc10d9e8e242661da7fd655dec155a09d676c
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
Quintiq file version 2.0
#parent: #root
StaticMethod GetInfo (
  Number recurrenceInterval_i,
  Boolean onMonday_i,
  Boolean onTuesday_i,
  Boolean onWednesday_i,
  Boolean onThursday_i,
  Boolean onFriday_i,
  Boolean onSaturday_i,
  Boolean onSunday_i
) const declarative remote as String
{
  Description:
  [*
    Get information about the RecurrencePattern in textual format.
    Is implemented as a static method so it can also be called from the UI when there is no instance available yet.
  *]
  TextBody:
  [*
    value := "";
    days  := Translations::Pattern_Days().Tokenize( ';' );
    
    if( days.Size() = 7 )
    {
      value := "every ";
      
      if( recurrenceInterval_i > 1 )
      {
        value := value + [String]recurrenceInterval_i + " weeks on ";
      }
      
      selectedDays := construct( Strings );
      
      if( onMonday_i    ) { selectedDays.Add( days.Element( monday    - 1 ) ); }
      if( onTuesday_i   ) { selectedDays.Add( days.Element( tuesday   - 1 ) ); }
      if( onWednesday_i ) { selectedDays.Add( days.Element( wednesday - 1 ) ); }
      if( onThursday_i  ) { selectedDays.Add( days.Element( thursday  - 1 ) ); }
      if( onFriday_i    ) { selectedDays.Add( days.Element( friday    - 1 ) ); }
      if( onSaturday_i  ) { selectedDays.Add( days.Element( saturday  - 1 ) ); }
      if( onSunday_i    ) { selectedDays.Add( days.Element( sunday    - 1 ) ); }
      
      if( selectedDays.Size() = 7 )
      {
        // If the value only contains 'every ' it must be reset first.
        value := ifexpr( value = "every ", "", value ) + "every day of the week";  
      }
      else
      {
        // If there are multiple days, then replace then use 'and' instead of the last comma.
        lastDay          := "";
        nrOfSelectedDays := selectedDays.Size();
                                                   
        if( nrOfSelectedDays > 1 )
        {
          lastDay := selectedDays.Element( nrOfSelectedDays - 1 );
          selectedDays.Delete( nrOfSelectedDays - 1 );
        }
        
        daysValue := selectedDays.ToString( ', ' );
        
        if( nrOfSelectedDays > 1 )
        {
          daysValue := daysValue + " and " + lastDay;
        }
                                                   
        value := value + daysValue;
      }
    }
    else
    {
      value := [String]days.Size() + " days defined in Translations::Pattern_Days(), should be 7";
    }
    
    return value;
  *]
}