KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > knowgate > hipergate > locale > es > TaxCalculatorEs


1 /*
2   Copyright (C) 2006 Know Gate S.L. All rights reserved.
3                       C/Oña, 107 1º2 28050 Madrid (Spain)
4
5   Redistribution and use in source and binary forms, with or without
6   modification, are permitted provided that the following conditions
7   are met:
8
9   1. Redistributions of source code must retain the above copyright
10      notice, this list of conditions and the following disclaimer.
11
12   2. The end-user documentation included with the redistribution,
13      if any, must include the following acknowledgment:
14      "This product includes software parts from hipergate
15      (http://www.hipergate.org/)."
16      Alternately, this acknowledgment may appear in the software itself,
17      if and wherever such third-party acknowledgments normally appear.
18
19   3. The name hipergate must not be used to endorse or promote products
20      derived from this software without prior written permission.
21      Products derived from this software may not be called hipergate,
22      nor may hipergate appear in their name, without prior written
23      permission.
24
25   This library is distributed in the hope that it will be useful,
26   but WITHOUT ANY WARRANTY; without even the implied warranty of
27   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
28
29   You should have received a copy of hipergate License with this code;
30   if not, visit http://www.hipergate.org or mail to info@hipergate.org
31 */

32
33 package com.knowgate.hipergate.locale.es;
34
35 import java.math.BigDecimal JavaDoc;
36
37 import com.knowgate.hipergate.locale.ITaxCalculator;
38
39 /**
40  * IVA, IGI and IPSI taxes calculator for Spain
41  * @author Sergio Montoro Ten
42  * @version 1.0
43  */

44 public class TaxCalculatorEs implements ITaxCalculator {
45
46     /**
47      * IPSI Ceuta 3%
48      */

49   public static final BigDecimal JavaDoc IPSICeuta = new BigDecimal JavaDoc("0.03");
50   /**
51    * IPSI Melilla 4%
52    */

53   public static final BigDecimal JavaDoc IPSIMelilla = new BigDecimal JavaDoc("0.04");
54   /**
55    * IGI Canarias 5%
56    */

57   public static final BigDecimal JavaDoc IGICCanarias = new BigDecimal JavaDoc("0.05");
58   /**
59    * IVA Península y Baleares 16%
60    */

61   public static final BigDecimal JavaDoc IVAPeninsula = new BigDecimal JavaDoc("0.16");
62
63   // ---------------------------------------------------------------------------
64

65   /**
66    * Get tax that applies to a given zip code.
67    * @param sCodPost String Código Postal o Nombre de Provincia
68    * @param sTipo String Tax type (currently not used)
69    * @return BigDecimal IGICCanarias if sCodPost IN
70    * {'38','35',TENERIFE','PALMAS, LAS','LAS PALMAS','GRAN CANARIA'}
71    * IPSICeuta if sCodPost IN {'51','CEUTA'}
72    * IPSIMelilla if sCodPost IN {'52','MELILLA'}
73    * else IVAPeninsula.<br>
74    * If sCodPost is <b>null</b> then IVAPeninsula is returned.
75    */

76   public static BigDecimal JavaDoc pctTasa (String JavaDoc sCodPost, String JavaDoc sTipo) {
77     if (null==sCodPost)
78       return IVAPeninsula;
79     else if (sCodPost.startsWith("38") || sCodPost.startsWith("35") ||
80              sCodPost.toUpperCase().indexOf("TENERIFE")>=0 ||
81              sCodPost.equalsIgnoreCase("PALMAS, LAS") ||
82              sCodPost.startsWith("LAS PALMAS ") ||
83              sCodPost.toUpperCase().indexOf("GRAN CANARIA")>=0)
84       return IGICCanarias;
85     else if (sCodPost.startsWith("51") || sCodPost.equalsIgnoreCase("CEUTA"))
86       return IPSICeuta;
87     else if (sCodPost.startsWith("52") || sCodPost.equalsIgnoreCase("MELILLA"))
88       return IPSIMelilla;
89     else
90       return IVAPeninsula;
91   } // pctTasa
92

93   // ---------------------------------------------------------------------------
94

95   /**
96    * @see pctTasa
97    */

98   public BigDecimal JavaDoc getTaxPct(String JavaDoc sTaxZone, String JavaDoc sItemType)
99       throws NullPointerException JavaDoc,IllegalArgumentException JavaDoc {
100     return pctTasa(sTaxZone, sItemType);
101   }
102
103   // ---------------------------------------------------------------------------
104

105   /**
106    * Get tax amount for a base price
107    * @param oBasePrice BigDecimal Base Price
108    * @param sCodPost String Código Postal o Nommbre de Provincia
109    * @param sItemType String Not used
110    * @return BigDecimal oBasePrice * getTaxPct(sCodPost, sItemType)
111    * @throws NullPointerException
112    * @throws IllegalArgumentException
113    */

114   public BigDecimal JavaDoc getTax(BigDecimal JavaDoc oBasePrice, String JavaDoc sCodPost, String JavaDoc sItemType)
115     throws NullPointerException JavaDoc,IllegalArgumentException JavaDoc {
116     return oBasePrice.multiply(pctTasa(sCodPost,sItemType));
117   }
118 }
119
Popular Tags