KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > erpCommon > businessUtility > Tax


1 /*
2  *************************************************************************
3  * The contents of this file are subject to the Openbravo Public License
4  * Version 1.0 (the "License"), being the Mozilla Public License
5  * Version 1.1 with a permitted attribution clause; you may not use this
6  * file except in compliance with the License. You may obtain a copy of
7  * the License at http://www.openbravo.com/legal/license.html
8  * Software distributed under the License is distributed on an "AS IS"
9  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
10  * License for the specific language governing rights and limitations
11  * under the License.
12  * The Original Code is Openbravo ERP.
13  * The Initial Developer of the Original Code is Openbravo SL
14  * All portions are Copyright (C) 2001-2006 Openbravo SL
15  * All Rights Reserved.
16  * Contributor(s): ______________________________________.
17  ************************************************************************
18 */

19 package org.openbravo.erpCommon.businessUtility;
20
21 import org.openbravo.database.ConnectionProvider;
22 import java.io.*;
23 import javax.servlet.*;
24 import org.apache.log4j.Logger ;
25 import java.util.*;
26
27
28 public class Tax {
29   static Logger log4jTax = Logger.getLogger(Tax.class);
30
31   public static String JavaDoc get (ConnectionProvider conn, String JavaDoc M_Product_ID, String JavaDoc shipDate, String JavaDoc AD_Org_ID, String JavaDoc M_Warehouse_ID, String JavaDoc billC_BPartner_Location_ID, String JavaDoc shipC_BPartner_Location_ID, String JavaDoc C_Project_ID, boolean IsSOTrx) throws IOException,ServletException {
32     log4jTax.debug("Tax.get");
33     return TaxData.taxGet(conn, M_Product_ID, shipDate, AD_Org_ID, M_Warehouse_ID, billC_BPartner_Location_ID, shipC_BPartner_Location_ID, C_Project_ID, (IsSOTrx?"Y":"N"));
34 /*System.out.println("billC_BPartner_Location_ID: " + billC_BPartner_Location_ID);
35     String billFrom = TaxData.billLocation(conn, AD_Org_ID);
36     TaxData[] td = TaxData.billTo(conn, billC_BPartner_Location_ID);
37
38     if (td==null || td.length==0) return "";
39     String billTo = td[0].billtocLocationId;
40     String IsTaxExempt = (IsSOTrx?td[0].istaxexempt:"N");
41     String IsSpecialTax = (IsSOTrx?td[0].isspecialtax:"N");
42     String taxID="";
43     if (IsTaxExempt.equalsIgnoreCase("Y")) {
44       TaxData[] tdAux = TaxData.taxId(conn, AD_Org_ID);
45       if (tdAux!=null && tdAux.length >0) taxID = tdAux[0].cTaxId;
46     } else {
47       String taxCategory = TaxData.taxCategory(conn, M_Product_ID);
48       String shipFrom = TaxData.shipLocation(conn, M_Warehouse_ID);
49       String shipTo = TaxData.shipTo(conn, shipC_BPartner_Location_ID);
50 System.out.println("taxCategory: " + taxCategory);
51 System.out.println("shipFrom: " + shipFrom);
52 System.out.println("shipTo: " + shipTo);
53       if (!IsSOTrx) {
54         String strAux = billTo;
55         billTo = billFrom;
56         billFrom = strAux;
57         strAux = shipTo;
58         shipTo = shipFrom;
59         shipFrom = strAux;
60 System.out.println("shipFrom: " + shipFrom);
61 System.out.println("shipTo: " + shipTo);
62       }
63 System.out.println("taxCategory: " + taxCategory);
64 System.out.println("billFrom: " + billFrom);
65 System.out.println("shipTo: " + shipTo);
66 System.out.println("shipDate: " + shipDate);
67 System.out.println("IsSpecialTax: " + IsSpecialTax);
68       TaxData[] tdAux = TaxData.select(conn, taxCategory, billFrom, shipTo, shipDate, IsSpecialTax);
69       if (tdAux==null || tdAux.length==0) tdAux = TaxData.select2(conn, taxCategory, billFrom, shipDate, IsSpecialTax);
70       if (tdAux==null || tdAux.length==0) tdAux = TaxData.select3(conn, billFrom, shipDate);
71       if (tdAux!=null && tdAux.length!=0) taxID = tdAux[0].cTaxId;
72     }
73     System.out.println("TaxID: " + taxID);
74     return taxID;*/

75   }
76
77   public static String JavaDoc checkNumeric (String JavaDoc data){
78     if(data == null || data.length() == 0) return "";
79     StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
80     for(int i = 0; i < data.length(); i++){
81        if(Character.isDigit(data.charAt(i))) sb.append(data.charAt(i));
82     }
83     return sb.toString();
84   }
85
86   public static String JavaDoc validateRoutingNo (String JavaDoc routingNo){
87     int longitud = checkNumeric(routingNo).length();
88     if(longitud == 8 || longitud == 9){return "";}
89     else{
90       return "PaymentBankRoutingNotValid";
91     }
92   }
93
94 public static String JavaDoc validateCreditCardNumber (String JavaDoc creditCardNumber, String JavaDoc creditCardType){
95    if(creditCardNumber == null || creditCardType == null) return "CreditCardNumberError";
96    String JavaDoc ccStartList = "";
97    String JavaDoc ccLengthList = "";
98    if(creditCardType.equals("M")){
99      ccStartList = "51,52,53,54,55";
100      ccLengthList = "16";
101    }
102    else{}
103    if(creditCardType.equals("V")){
104      ccStartList = "4";
105      ccLengthList = "13,16";
106    }
107    else{}
108    if(creditCardType.equals("A")){
109      ccStartList = "34,37";
110      ccLengthList = "15";
111    }
112    else{}
113    if(creditCardType.equals("N")){
114      ccStartList = "6011";
115      ccLengthList = "16";
116    }
117    else{}
118    if(creditCardType.equals("D")){
119      ccStartList = "300,301,302,303,304,305,36,38";
120      ccLengthList = "14";
121    }
122    else{
123      ccStartList = "2014,2149";
124      ccLengthList = "15";
125      ccStartList = ccStartList + ",3088,3096,3112,3158,3337,3528";
126      ccLengthList = ccLengthList + ",16";
127      ccStartList = ccStartList + ",2131,1800";
128      ccLengthList = ccLengthList + ",15";
129    }
130    String JavaDoc ccNumber = checkNumeric(creditCardNumber);
131    int ccLength = ccNumber.length();
132    boolean ccLengthOK = false;
133    StringTokenizer st = new StringTokenizer(ccLengthList, ",", false);
134    do{
135      if(!st.hasMoreTokens() || ccLengthOK) break;
136      int l = Integer.parseInt(st.nextToken());
137      if(ccLength == l) ccLengthOK = true;
138    } while(true);
139    if(!ccLengthOK){
140      return "CreditCardNumberError";
141    }
142    boolean ccIdentified = false;
143    st = new StringTokenizer(ccStartList, ",", false);
144    do{
145      if(!st.hasMoreTokens() || ccIdentified) break;
146      if(ccNumber.startsWith(st.nextToken())) ccIdentified = true;
147    } while(true);
148    String JavaDoc check = validateCreditCardNumber(ccNumber,"");
149    if(check.length() != 0) {return check;}
150    if(!ccIdentified) {return "CreditCardNumberProblem?";}
151    else {return "";}
152  }
153
154 }
155
Popular Tags