KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > model > MCurrency


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Smart Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2003 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.model;
15
16 import java.util.*;
17
18 import org.compiere.util.*;
19
20 /**
21  * Currency Model.
22  *
23  * @author Jorg Janke
24  * @version $Id: MCurrency.java,v 1.3 2003/08/08 16:14:35 jjanke Exp $
25  */

26 public class MCurrency extends X_C_Currency
27 {
28     /**
29      * Currency Constructor
30      * @param ctx context
31      * @param C_Currency_ID id
32      */

33     public MCurrency (Properties ctx, int C_Currency_ID)
34     {
35         super (ctx, C_Currency_ID);
36         if (C_Currency_ID == 0)
37         {
38             setIsEMUMember (false);
39             setIsEuro (false);
40             setStdPrecision (0);
41             setCostingPrecision (0);
42         }
43     } // MCurrency
44

45     /**
46      * Currency Constructor
47      * @param ctx context
48      * @param ISO_Code ISO
49      * @param Description Name
50      * @param CurSymbol symbol
51      * @param StdPrecision prec
52      * @param CostingPrecision prec
53      */

54     public MCurrency (Properties ctx, String JavaDoc ISO_Code,
55         String JavaDoc Description, String JavaDoc CurSymbol, int StdPrecision, int CostingPrecision)
56     {
57         super (ctx, 0);
58         setISO_Code(ISO_Code);
59         setDescription(Description);
60         setCurSymbol(CurSymbol);
61         setStdPrecision (StdPrecision);
62         setCostingPrecision (CostingPrecision);
63         setIsEMUMember (false);
64         setIsEuro (false);
65     } // MCurrency
66

67
68     /** Store System Currencies **/
69     private static CCache s_currencies = new CCache("currencies", 50);
70
71     /**
72      * Get Currency
73      * @param ctx Context
74      * @param C_Currency_ID currency
75      * @return ISO Code
76      */

77     public static MCurrency get (Properties ctx, int C_Currency_ID)
78     {
79         // Try Cache
80
Integer JavaDoc key = new Integer JavaDoc(C_Currency_ID);
81         MCurrency retValue = (MCurrency)s_currencies.get(key);
82         if (retValue != null)
83             return retValue;
84
85         // Create it
86
retValue = new MCurrency(ctx, C_Currency_ID);
87         // Save in System
88
if (retValue.getAD_Client_ID() == 0)
89             s_currencies.put(key, retValue);
90         return retValue;
91     } // get
92

93     /**
94      * Get Currency Iso Code.
95      * @param ctx Context
96      * @param C_Currency_ID currency
97      * @return ISO Code
98      */

99     public static String JavaDoc getISO_Code (Properties ctx, int C_Currency_ID)
100     {
101         String JavaDoc contextKey = "C_Currency_" + C_Currency_ID;
102         String JavaDoc retValue = ctx.getProperty(contextKey);
103         if (retValue != null)
104             return retValue;
105
106         // Create it
107
MCurrency c = get(ctx, C_Currency_ID);
108         retValue = c.getISO_Code();
109         ctx.setProperty(contextKey, retValue);
110         return retValue;
111     } // getISO
112

113     /**
114      * String Representation
115      * @return info
116      */

117     public String JavaDoc toString()
118     {
119         return "MCurrency[" + getC_Currency_ID()
120             + "-" + getISO_Code() + "-" + getCurSymbol()
121             + "," + getDescription()
122             + ",Precision=" + getStdPrecision() + "/" + getCostingPrecision();
123     } // toString
124

125
126     /*************************************************************************/
127
128     /**
129      * Load/link Currencies
130      * @param args args
131      *
132     public static void main (String[] args)
133     {
134         System.out.println("Currency");
135         Compiere.startupClient();
136         // Loop through
137         for (int i = 0; i < s_table.length; i++)
138         {
139             /**
140             System.out.println(s_table[i][I_Currency] + " - " + s_table[i][I_Name]);
141             int prec = Integer.parseInt(s_table[i][I_Precision]);
142             MCurrency cur = new MCurrency(Env.getCtx(), s_table[i][I_Currency],
143                 s_table[i][I_Name], s_table[i][I_Symbol], prec, prec+2);
144             cur.save();
145             System.out.println(cur);
146             **
147             String ISO = s_table[i][I_Currency];
148             String Country = s_table[i][I_Country];
149             String sql = "UPDATE C_Country SET C_Currency_ID="
150                 + "(SELECT C_Currency_ID FROM C_Currency WHERE ISO_Code='" + ISO + "') "
151                 + "WHERE CountryCode='" + Country + "'";
152             int no = DB.executeUpdate(sql);
153             System.out.println(ISO + " - " + Country + " - " + no);
154             System.out.println("");
155         }
156
157     } // main
158
159
160     static int I_Country = 0;
161     static int I_Currency = 1;
162     static int I_Precision = 2;
163     static int I_Symbol = 3;
164     static int I_DecimalPoint = 4;
165     static int I_FormatIndex = 5;
166     static int I_Name = 6;
167     static String[][] s_table = new String[][] {
168         new String[]{"US","USD","2","$",".","0", "US Dollar"},
169         new String[]{"AR","ARS","2","$",",","0", "Argentine Peso"},
170         new String[]{"AS","USD","2","$",".","0","US Dollar"},
171         new String[]{"CC","AUD","2","$",".","0","Australian Dollar"},
172         new String[]{"CK","NZD","2","$",".","0","New Zealand Dollar"},
173         new String[]{"CX","AUD","2","$",".","0","Australian Dollar"},
174         new String[]{"EC","USD","2","$",".","0","US Dollar"},
175         new String[]{"FM","USD","2","$",".","0","US Dollar"},
176         new String[]{"GU","USD","2","$",".","0","US Dollar"},
177         new String[]{"KI","AUD","2","$",".","0","Australian Dollar"},
178         new String[]{"LR","LRD","2","$",".","0","Liberian Dollar"},
179         new String[]{"MH","USD","2","$",".","0","US Dollar"},
180         new String[]{"MP","USD","2","$",".","0","US Dollar"},
181         new String[]{"MX","MXN","2","$",".","0","Mexican Peso"},
182         new String[]{"NF","AUD","2","$",".","0","Australian Dollar"},
183         new String[]{"NR","AUD","2","$",".","0","Australian Dollar"},
184         new String[]{"NU","NZD","2","$",".","0","New Zealand Dollar"},
185         new String[]{"NZ","NZD","2","$",".","0","New Zealand Dollar"},
186         new String[]{"PR","USD","2","$",".","0","US Dollar"},
187         new String[]{"PW","USD","2","$",".","0","US Dollar"},
188         new String[]{"TC","USD","2","$",".","0","US Dollar"},
189         new String[]{"TK","NZD","2","$",".","0","New Zealand Dollar"},
190         new String[]{"TV","AUD","2","$",".","0","Australian Dollar"},
191         new String[]{"VG","USD","2","$",".","0","US Dollar"},
192         new String[]{"VI","USD","2","$",".","0","US Dollar"},
193         new String[]{"UY","UYU","2","$U",",","2","Peso Uruguayo"},
194         new String[]{"AM","AMD","2","",".","0","Armenian Dram"},
195         new String[]{"AO","AOA","2","",".","0","Kwanza"},
196         new String[]{"AZ","AZM","2","",".","0","Azerbaijanian Manat"},
197         new String[]{"BO","BOB","2","",".","0","Boliviano"},
198         new String[]{"CD","CDF","2","",".","0","Franc Congolais"},
199         new String[]{"CZ","CZK","2","",",","3","Czech Koruna"},
200         new String[]{"GE","GEL","2","",".","0","Lari"},
201         new String[]{"IR","IRR","2","",".","2","Iranian Rial"},
202         new String[]{"LT","LTL","2","",",","3","Lithuanian Litus"},
203         new String[]{"MD","MDL","2","",".","0","Moldovan Leu"},
204         new String[]{"PH","PHP","2","",".","0","Philippine Peso"},
205         new String[]{"PL","PLN","2","",",","3","Zloty"},
206         new String[]{"RU","RUR","2","",",","1","Russian Ruble"},
207         new String[]{"SD","SDD","2","",".","0","Sudanese Dinar"},
208         new String[]{"TJ","TJS","2","",".","0","Somoni"},
209         new String[]{"TM","TMM","2","",".","0","Manat"},
210         new String[]{"TP","TPE","0","",".","0","Timor Escudo"},
211         new String[]{"UA","UAH","2","",",","3","Hryvnia"},
212         new String[]{"UZ","UZS","2","",".","0","Uzbekistan Sum"},
213         new String[]{"GB","GBP","2","£",".","0","Pound Sterling"},
214         new String[]{"CY","CYP","2","£C",".","0","Cyprus Pound"},
215         new String[]{"EG","EGP","2","£E",".","2","Egyptian Pound"},
216         new String[]{"FK","FKP","2","£F",".","0","Falkland Islands Pound"},
217         new String[]{"GI","GIP","2","£G",".","0","Gibraltar Pound"},
218         new String[]{"SH","SHP","2","£S",".","0","Saint Helena Pound"},
219         new String[]{"SY","SYP","2","£S",".","2","Syrian Pound"},
220         new String[]{"JP","JPY","0","₯",".","0","Yen"},
221         new String[]{"GH","GHC","2","’",".","0","Cedi"},
222         new String[]{"SV","SVC","2","’",".","0","El Salvador Colon"},
223         new String[]{"AD","EUR","2","€",".","0","euro"},
224         new String[]{"AT","EUR","2","€",",","2","euro"},
225         new String[]{"BE","EUR","2","€",",","3","euro"},
226         new String[]{"DE","EUR","2","€",",","3","euro"},
227         new String[]{"ES","EUR","2","€",",","3","euro"},
228         new String[]{"FI","EUR","2","€",",","3","euro"},
229         new String[]{"FR","EUR","2","€",",","3","euro"},
230         new String[]{"GF","EUR","2","€",".","0","euro"},
231         new String[]{"GP","EUR","2","€",".","0","euro"},
232         new String[]{"GR","EUR","2","€",",","3","euro"},
233         new String[]{"IE","EUR","2","€",".","0","euro"},
234         new String[]{"IT","EUR","2","€",",","2","euro"},
235         new String[]{"LU","EUR","2","€",",","3","euro"},
236         new String[]{"MC","EUR","2","€",".","0","euro"},
237         new String[]{"MQ","EUR","2","€",".","0","euro"},
238         new String[]{"NL","EUR","2","€",",","2","euro"},
239         new String[]{"PM","EUR","2","€",".","0","euro"},
240         new String[]{"PT","EUR","2","€","$","3","euro"},
241         new String[]{"RE","EUR","2","€",".","0","euro"},
242         new String[]{"SM","EUR","2","€",".","0","euro"},
243         new String[]{"VA","EUR","2","€",".","0","euro"},
244         new String[]{"YT","EUR","2","€",".","0","euro"},
245         new String[]{"AU","AUD","2","A$",".","0","Australian Dollar"},
246         new String[]{"AF","AFA","2","Af",".","0","Afghani"},
247         new String[]{"AW","AWG","2","Af.",".","0","Aruban Guilder"},
248         new String[]{"PA","PAB","2","B",".","0","Balboa"},
249         new String[]{"BN","BND","2","B$",".","0","Brunei Dollar"},
250         new String[]{"BS","BSD","2","B$",".","0","Bahamian Dollar"},
251         new String[]{"BH","BHD","3","BD",".","2","Bahraini Dinar"},
252         new String[]{"BM","BMD","2","Bd$",".","0","Bermudian Dollar"},
253         new String[]{"BB","BBD","2","Bds$",".","0","Barbados Dollar"},
254         new String[]{"BY","BYR","0","BR",",","3","Belarussian Ruble"},
255         new String[]{"ET","ETB","2","Br",".","0","Ethiopian Birr"},
256         new String[]{"VE","VEB","2","Bs",",","0","Bolivar"},
257         new String[]{"TH","THB","2","Bt",".","0","Baht"},
258         new String[]{"BZ","BZD","2","BZ$",".","0","Belize Dollar"},
259         new String[]{"CA","CAD","2","C$",".","0","Canadian Dollar"},
260         new String[]{"NI","NIO","2","C$",".","0","Cordoba Oro"},
261         new String[]{"CV","CVE","2","C.V.Esc.",".","0","Cape Verde Escudo"},
262         new String[]{"KM","KMF","0","CF",".","0","Comoro Franc"},
263         new String[]{"BF","XOF","0","CFAF",".","0","CFA Franc BCEAO"},
264         new String[]{"BJ","XOF","0","CFAF",".","0","CFA Franc BCEAO"},
265         new String[]{"CF","XAF","0","CFAF",".","0","CFA Franc BEAC"},
266         new String[]{"CG","XAF","0","CFAF",".","0","CFA Franc BEAC"},
267         new String[]{"CI","XOF","0","CFAF",".","0","CFA Franc BCEA"},
268         new String[]{"CM","XAF","0","CFAF",".","0","CFA Franc BEAC"},
269         new String[]{"GA","XAF","0","CFAF",".","0","CFA Franc BEAC"},
270         new String[]{"GQ","XAF","0","CFAF",".","0","CFA Franc BEAC"},
271         new String[]{"ML","XOF","0","CFAF",".","0","CFA Franc BCEAO"},
272         new String[]{"NE","XOF","0","CFAF",".","0","CFA Franc BCEAO"},
273         new String[]{"SN","XOF","0","CFAF",".","0","CFA Franc BCEAO"},
274         new String[]{"TD","XAF","0","CFAF",".","0","CFA Franc BEAC"},
275         new String[]{"TG","XOF","0","CFAF",".","0","CFA Franc BCEAO"},
276         new String[]{"NC","XPF","0","CFPF",".","0","CFP Franc"},
277         new String[]{"PF","XPF","0","CFPF",".","0","CFP Franc"},
278         new String[]{"WF","XPF","0","CFPF",".","0","CFP Franc"},
279         new String[]{"CL","CLP","0","Ch$",",","0","Chilean Peso"},
280         new String[]{"KY","KYD","2","CI$",".","0","Cayman Islands Dollar"},
281         new String[]{"CO","COP","2","Col$",".","0","Colombian Peso"},
282         new String[]{"KH","KHR","2","CR",".","0","Riel"},
283         new String[]{"CU","CUP","2","Cu$",".","0","Cuban Peso"},
284         new String[]{"GM","GMD","2","D",".","0","Dalasi"},
285         new String[]{"VN","VND","2","D",",","3","Dong"},
286         new String[]{"DZ","DZD","2","DA",".","2","Algerian Dinar"},
287         new String[]{"ST","STD","2","Db",".","0","Dobra"},
288         new String[]{"DJ","DJF","0","DF",".","0","Djibouti Franc"},
289         new String[]{"AE","AED","2","Dh",".","2","UAE Dirham"},
290         new String[]{"MA","MAD","2","DH",".","2","Moroccan Dirham"},
291         new String[]{"YU","YUM","2","Din",".","0","Yugoslavian Dinar"},
292         new String[]{"DK","DKK","2","Dkr",",","2","Danish Krone"},
293         new String[]{"FO","DKK","2","Dkr",",","2","Danish Krone"},
294         new String[]{"GL","DKK","2","Dkr",".","0","Danish Krone"},
295         new String[]{"AG","XCD","2","EC$",".","0","East Caribbean Dollar"},
296         new String[]{"AI","XCD","2","EC$",".","0","East Caribbean Dollar"},
297         new String[]{"DM","XCD","2","EC$",".","0","East Caribbean Dollar"},
298         new String[]{"GD","XCD","2","EC$",".","0","East Caribbean Dollar"},
299         new String[]{"KN","XCD","2","EC$",".","0","East Caribbean Dollar"},
300         new String[]{"LC","XCD","2","EC$",".","0","East Caribbean Dollar"},
301         new String[]{"MS","XCD","2","EC$",".","0","East Caribbean Dollar"},
302         new String[]{"VC","XCD","2","EC$",".","0","East Caribbean Dollar"},
303         new String[]{"FJ","FJD","2","F$",".","0","Fiji Dollar"},
304         new String[]{"BI","BIF","0","FBu",".","0","Burundi Franc"},
305         new String[]{"MG","MGF","0","FMG",".","0","Malagasy Franc"},
306         new String[]{"HU","HUF","2","Ft",",","3","Forint"},
307         new String[]{"HT","HTG","2","G",".","0","Gourde"},
308         new String[]{"GY","GYD","2","G$",".","0","Guyana Dollar"},
309         new String[]{"HK","HKD","2","HK$",".","0","Hong Kong Dollar"},
310         new String[]{"HR","HRK","2","HRK",",","2","Croatian Kuna"},
311         new String[]{"IQ","IQD","3","ID",".","2","Iraqi Dinar"},
312         new String[]{"IS","ISK","2","IKr",",","3","Iceland Krona"},
313         new String[]{"JM","JMD","2","J$",".","0","Jamaican Dollar"},
314         new String[]{"JO","JOD","3","JD",".","2","Jordanian Dinar"},
315         new String[]{"MM","MMK","2","K",".","0","Kyat"},
316         new String[]{"PG","PGK","2","K",".","0","Kina"},
317         new String[]{"KE","KES","2","K Sh",".","0","Kenyan Shilling"},
318         new String[]{"KW","KWD","3","KD",".","2","Kuwaiti Dinar"},
319         new String[]{"BA","BAM","2","KM",".","0","Convertible Marks"},
320         new String[]{"LA","LAK","2","KN",".","0","Kip"},
321         new String[]{"ER","ERN","2","KR",".","0","Nakfa"},
322         new String[]{"AL","ALL","2","L",",","1","Lek"},
323         new String[]{"HN","HNL","2","L",".","0","Lempira"},
324         new String[]{"RO","ROL","2","L",",","3","Leu"},
325         new String[]{"SZ","SZL","2","L",".","0","Lilangeni"},
326         new String[]{"LY","LYD","3","LD",".","2","Libyan Dinar"},
327         new String[]{"SL","SLL","2","Le",".","0","Leone"},
328         new String[]{"MT","MTL","2","Lm",".","0","Maltese Lira"},
329         new String[]{"LV","LVL","2","Ls",",","3","Latvian Lats"},
330         new String[]{"BG","BGL","2","Lv",",","3","Lev"},
331         new String[]{"MU","MUR","2","Mau Rs",".","0","Mauritius Rupee"},
332         new String[]{"MW","MWK","2","MK",".","0","Kwacha"},
333         new String[]{"MK","MKD","2","MKD",".","0","Denar"},
334         new String[]{"MZ","MZM","2","Mt",".","0","Metical"},
335         new String[]{"AN","ANG","2","NAf.",".","0","Netherlands Antillian Guilder"},
336         new String[]{"EE","EEK","2","Nfa",",","3","Kroon"},
337         new String[]{"IL","ILS","2","NIS",".","2","New Israeli Sheqel"},
338         new String[]{"NO","NOK","2","NKr",",","2","Norwegian Krone"},
339         new String[]{"NP","NPR","2","NRs",".","0","Nepalese Rupee"},
340         new String[]{"TW","TWD","2","NT$",".","0","New Taiwan Dollar"},
341         new String[]{"BW","BWP","2","P",".","0","Pula"},
342         new String[]{"MO","MOP","2","P",".","0","Pataca"},
343         new String[]{"GT","GTQ","2","Q",".","0","Quetzal"},
344         new String[]{"QA","QAR","2","QR",".","2","Qatari Rial"},
345         new String[]{"LS","ZAR","2","R",".","0","Rand"},
346         new String[]{"NA","ZAR","2","R",".","0","Rand"},
347         new String[]{"ZA","ZAR","2","R",".","2","Rand"},
348         new String[]{"BR","BRL","2","R$",",","0","Brazilian Real"},
349         new String[]{"DO","DOP","2","RD$",".","0","Dominican Peso"},
350         new String[]{"MV","MVR","2","Rf",".","0","Rufiyaa"},
351         new String[]{"RW","RWF","0","RF",".","0","Rwanda Franc"},
352         new String[]{"MY","MYR","2","RM",".","0","Malaysian Ringgit"},
353         new String[]{"OM","OMR","3","RO",".","2","Rial Omani"},
354         new String[]{"ID","IDR","2","Rp",",","0","Rupiah"},
355         new String[]{"BT","INR","2","Rs",".","0","Indian Rupee"},
356         new String[]{"IN","INR","2","Rs",".","0","Indian Rupee"},
357         new String[]{"PK","PKR","2","Rs",".","0","Pakistan Rupee"},
358         new String[]{"SG","SGD","2","S$",".","0","Singapore Dollar"},
359         new String[]{"PE","PEN","2","S/.",",","0","Nuevo Sol"},
360         new String[]{"SR","SRG","2","Sf.",".","0","Suriname Guilder"},
361         new String[]{"SB","SBD","2","SI$",".","0","Solomon Islands Dollar"},
362         new String[]{"SE","SEK","2","Sk",",","3","Swedish Krona"},
363         new String[]{"SK","SKK","2","Sk",",","3","Slovak Koruna"},
364         new String[]{"LK","LKR","2","SLRs",".","0","Sri Lanka Rupee"},
365         new String[]{"SI","SIT","2","SlT",",","3","Tolar"},
366         new String[]{"SO","SOS","2","So. Sh.",".","0","Somali Shilling"},
367         new String[]{"SC","SCR","2","SR",".","0","Seychelles Rupee"},
368         new String[]{"SA","SAR","2","SRls",".","2","Saudi Riyal"},
369         new String[]{"CH","CHF","2","SwF",".","2","Swiss Franc"},
370         new String[]{"LI","CHF","2","SwF",".","2","Swiss Franc"},
371         new String[]{"TO","TOP","2","T$",".","0","Pa’anga"},
372         new String[]{"TN","TND","3","TD",".","2","Tunisian Dinar"},
373         new String[]{"BD","BDT","2","Tk",".","0","Taka"},
374         new String[]{"TR","TRL","0","TL",",","3","Turkish Lira"},
375         new String[]{"TZ","TZS","2","TSh",".","0","Tanzanian Shilling"},
376         new String[]{"TT","TTD","2","TT$",".","0","Trinidad and Tobago Dollar"},
377         new String[]{"MN","MNT","2","Tug",".","0","Tugrik"},
378         new String[]{"MR","MRO","2","UM",".","0","Ouguiya"},
379         new String[]{"UG","UGX","2","USh",".","0","Uganda Shilling"},
380         new String[]{"VU","VUV","0","VT",".","0","Vatu"},
381         new String[]{"KR","KRW","0","W",".","0","Won"},
382         new String[]{"WS","WST","2","WS$",".","0","Tala"},
383         new String[]{"CN","CNY","2","Y",".","0","Yuan Renminbi"},
384         new String[]{"YE","YER","2","YRls",".","2","Yemeni Rial"},
385         new String[]{"ZW","ZWD","2","Z$",".","0","Zimbabwe Dollar"},
386         new String[]{"ZM","ZMK","2","ZK",".","0","Kwacha"},
387         new String[]{"CR","CRC","2","",".","0","Costa Rican Colon"},
388         new String[]{"GN","GNF","0","",".","0","Guinea Franc"},
389         new String[]{"GW","GWP","2","",".","0","Guinea-Bissau Peso"},
390         new String[]{"KG","KGS","2","",".","0","Som"},
391         new String[]{"KP","KPW","2","",".","0","North Korean Won"},
392         new String[]{"KZ","KZT","2","",".","0","Tenge"},
393         new String[]{"LB","LBP","2","",".","2","Lebanese Pound"},
394         new String[]{"NG","NGN","2","",".","0","Naira"},
395         new String[]{"PY","PYG","0","",",","0","Guarani"}
396     };
397     **/

398
399 } // MCurrency
400
Popular Tags