1#=====================================================================
2# SQL-Ledger Accounting
3# Copyright (C) 2001
4#
5#  Author: Dieter Simader
6#   Email: dsimader@sql-ledger.org
7#     Web: http://www.sql-ledger.org
8#  Modified by: Medgyesi Aniko
9#  **********************************
10#  *#MEA1 * Hungarian version       *
11#  **********************************
12#  Contributors:
13#
14# This program is free software; you can redistribute it and/or modify
15# it under the terms of the GNU General Public License as published by
16# the Free Software Foundation; either version 2 of the License, or
17# (at your option) any later version.
18#
19# This program is distributed in the hope that it will be useful,
20# but WITHOUT ANY WARRANTY; without even the implied warranty of
21# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22# GNU General Public License for more details.
23# You should have received a copy of the GNU General Public License
24# along with this program; if not, write to the Free Software
25# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26#=====================================================================
27#
28# this is the default code for the Check package
29#
30#=====================================================================
31
32sub init {
33  my $self = shift;
34#MEA1 English number ignored
35#   %{ $self->{numbername} } =
36#      (0 => 'Zero',
37#       1 => 'One',
38#       2 => 'Two',
39#	      3 => 'Three',
40#		    4 => 'Four',
41#		    5 => 'Five',
42#		    6 => 'Six',
43#		    7 => 'Seven',
44#		    8 => 'Eight',
45#		    9 => 'Nine',
46#		   10 => 'Ten',
47#		   11 => 'Eleven',
48#		   12 => 'Twelve',
49#		   13 => 'Thirteen',
50#		   14 => 'Fourteen',
51#		   15 => 'Fifteen',
52#		   16 => 'Sixteen',
53#		   17 => 'Seventeen',
54#		   18 => 'Eighteen',
55#		   19 => 'Nineteen',
56#		   20 => 'Twenty',
57#		   30 => 'Thirty',
58#		   40 => 'Forty',
59#		   50 => 'Fifty',
60#		   60 => 'Sixty',
61#		   70 => 'Seventy',
62#		   80 => 'Eighty',
63#		   90 => 'Ninety',
64#   10**2 => 'Hundred',
65#   10**3 => 'Thousand',
66#		10**6 => 'Million',
67#		10**9 => 'Billion',
68#   10**12 => 'Trillion',
69# );
70#MEA1BEG Hungarian numbers
71  %{ $self->{numbername} } =
72           (0 => 'Nulla',
73            1 => 'egy',
74            2 => 'kettő',
75	        3 => 'három',
76		    4 => 'négy',
77		    5 => 'öt',
78		    6 => 'hat',
79		    7 => 'hét',
80		    8 => 'nyolc',
81		    9 => 'kilenc',
82		   10 => 'tíz',
83		   11 => 'tizenegy',
84		   12 => 'tizenkettő',
85		   13 => 'tizenhárom',
86		   14 => 'tizennégy',
87		   15 => 'tizenöt',
88		   16 => 'tizenhat',
89		   17 => 'tizenhét',
90		   18 => 'tizennyolc',
91		   19 => 'tizenkilenc',
92		   20 => 'húsz',
93		   21 => 'huszonegy',
94		   22 => 'huszonkettő',
95		   23 => 'huszonhárom',
96		   24 => 'huszonnégy',
97		   25 => 'huszonöt',
98		   26 => 'huszonhat',
99		   27 => 'huszonhét',
100		   28 => 'huszonnyolc',
101		   29 => 'huszonkilenc',
102		   30 => 'harminc',
103		   40 => 'negyven',
104		   50 => 'ötven',
105		   60 => 'hatvan',
106		   70 => 'hetven',
107		   80 => 'nyolcvan',
108		   90 => 'kilencven',
109        10**2 => 'száz',
110        10**3 => 'ezer',
111		10**6 => 'millió',
112		10**9 => 'milliárd',
113	    10**12 => 'billió',
114		);
115#MEA1END
116
117}
118
119
120sub num2text {
121  my ($self, $amount) = @_;
122
123  return $self->{numbername}{0} unless $amount;
124
125  my @textnumber = ();
126
127  # split amount into chunks of 3
128  my @num = reverse split //, abs($amount);
129  my @numblock = ();
130  my @a;
131  my $i;
132#MEA1BEG
133  my $res;
134#MEA1END
135  while (@num) {
136    @a = ();
137    for (1 .. 3) {
138      push @a, shift @num;
139    }
140    push @numblock, join / /, reverse @a;
141  }
142  while (@numblock) {
143    $i = $#numblock;
144    @num = split //, $numblock[$i];
145
146    if ($numblock[$i] == 0) {
147      pop @numblock;
148      next;
149    }
150    if ($numblock[$i] > 99) {
151      push @textnumber, $self->{numbername}{$num[0]};
152
153      # add hundred designation
154      push @textnumber, $self->{numbername}{10**2};
155
156      # reduce numblock
157      $numblock[$i] -= $num[0] * 100;
158
159    }
160
161    $numblock[$i] *= 1;
162    if ($numblock[$i] > 9) {
163      # tens
164      push @textnumber, $self->format_ten($numblock[$i]);
165    } elsif ($numblock[$i] > 0) {
166      # ones
167      push @textnumber, $self->{numbername}{$numblock[$i]};
168    }
169
170    # add thousand, million
171    if ($i) {
172#MEA1BEG above 2000 need hyphen between treegroups
173#    if ($numblock[$i] > 9) {
174#       push @textnumber, $self->format_ten($numblock[$i]);
175#     } elsif ($numblock[$i] > 0) {
176#       push @textnumber, $self->{numbername}{$numblock[$i]};
177#     }
178      if ($i==1 && $amount < 2000){
179
180        $num = 10**($i * 3);
181        push @textnumber, $self->{numbername}{$num};
182      } else  {
183
184          $num = 10**($i * 3);
185          push @textnumber, $self->{numbername}{$num}."-";
186      }
187#MEA1END
188    }
189
190    pop @numblock;
191
192  }
193#MEA1BEG First charachter is uppercase
194# join '', @textnumber;
195  $res=ucfirst join '', @textnumber;
196#MEA1END
197#MEA1BEG  remove last hyphen
198  $res=~s/(\-)$//;
199  return $res;
200#MEA1END
201
202
203}
204
205
206sub format_ten {
207  my ($self, $amount) = @_;
208
209  my $textnumber = "";
210  my @num = split //, $amount;
211#MEA1BEG above 30 not above 20
212# if ($amount > 30) {
213  if ($amount > 30) {
214#MEA1END
215    $textnumber = $self->{numbername}{$num[0]*10};
216    $amount = $num[1];
217  } else {
218    $textnumber = $self->{numbername}{$amount};
219    $amount = 0;
220  }
221
222  $textnumber .= "".$self->{numbername}{$amount} if $amount;
223
224  $textnumber;
225
226}
227
228
2291;
230
231
232
233