[ 2758097 ] Implement TaxNotFoundException

https://sourceforge.net/tracker/?func=detail&aid=2758097&group_id=176962&atid=879335
This commit is contained in:
teo_sarca 2009-04-13 09:59:21 +00:00
parent dd3a96f6ea
commit e2474a2fb1
5 changed files with 339 additions and 129 deletions

View File

@ -0,0 +1,45 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 2009 SC ARHIPAC SERVICE SRL. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
*****************************************************************************/
package org.adempiere.exceptions;
/**
* Throw when a tax criteria was not found
* @author Teo Sarca, www.arhipac.ro
* <li>FR [ 2758097 ] Implement TaxNotFoundException
*/
public class TaxCriteriaNotFoundException extends AdempiereException
{
/**
*
*/
private static final long serialVersionUID = -8192276006656371964L;
private static final String AD_Message = "TaxCriteriaNotFound";
public TaxCriteriaNotFoundException(String criteriaName, int criteria_ID)
{
super(buildMessage(criteriaName, criteria_ID));
}
private static final String buildMessage (String criteriaName, int criteria_ID)
{
StringBuffer msg = new StringBuffer("@").append(AD_Message).append("@");
msg.append("@").append(criteriaName).append("@");
msg.append(" (ID ").append(criteria_ID).append(")");
return msg.toString();
}
}

View File

@ -0,0 +1,56 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 2009 SC ARHIPAC SERVICE SRL. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
*****************************************************************************/
package org.adempiere.exceptions;
import org.compiere.util.Util;
/**
* Throw when tax not found for given charge
* @author Teo Sarca, www.arhipac.ro
* <li>FR [ 2758097 ] Implement TaxNotFoundException
*/
public class TaxForChangeNotFoundException extends AdempiereException
{
/**
*
*/
private static final long serialVersionUID = 6553174922970467775L;
private static final String AD_Message = "TaxForChargeNotFound"; // TODO : translate
public TaxForChangeNotFoundException(int C_Charge_ID, int AD_Org_ID, int M_Warehouse_ID,
int billC_BPartner_Location_ID, int shipC_BPartner_Location_ID, String additionalMsg)
{
super(buildMessage(C_Charge_ID, AD_Org_ID, M_Warehouse_ID,
billC_BPartner_Location_ID, shipC_BPartner_Location_ID,
additionalMsg));
}
private static final String buildMessage(int C_Charge_ID, int AD_Org_ID, int M_Warehouse_ID,
int billC_BPartner_Location_ID, int shipC_BPartner_Location_ID, String additionalMsg)
{
StringBuffer msg = new StringBuffer("@").append(AD_Message).append("@");
if (!Util.isEmpty(additionalMsg, true))
{
msg.append(" ").append(additionalMsg).append(" - ");
}
msg.append(" @C_Charge_ID@:").append(C_Charge_ID);
msg.append(", @AD_Org_ID@:").append(AD_Org_ID);
msg.append(", @M_Warehouse_ID@:").append(M_Warehouse_ID);
msg.append(", @C_BPartner_Location_ID@:").append(billC_BPartner_Location_ID)
.append("/").append(shipC_BPartner_Location_ID);
//
return msg.toString();
}
}

View File

@ -0,0 +1,60 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 2009 SC ARHIPAC SERVICE SRL. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
*****************************************************************************/
package org.adempiere.exceptions;
import org.compiere.model.MOrg;
import org.compiere.util.Env;
/**
* Throw by Tax Engine where no tax found for given criteria
* @author Teo Sarca, www.arhipac.ro
* <li>FR [ 2758097 ] Implement TaxNotFoundException
*/
public class TaxNoExemptFoundException extends AdempiereException
{
/**
*
*/
private static final long serialVersionUID = -5489066603806460132L;
private static final String AD_Message = "TaxNoExemptFound";
public TaxNoExemptFoundException(int AD_Org_ID)
{
super(buildMessage(AD_Org_ID));
}
private static final String buildMessage (int AD_Org_ID)
{
StringBuffer msg = new StringBuffer("@").append(AD_Message).append("@");
msg.append("@AD_Org_ID@:").append(getOrgString(AD_Org_ID));
//
return msg.toString();
}
private static final String getOrgString(int AD_Org_ID)
{
if (AD_Org_ID <= 0)
{
return "*";
}
MOrg org = MOrg.get(Env.getCtx(), AD_Org_ID);
if (org == null || org.get_ID() != AD_Org_ID)
{
return "?";
}
return org.getName();
}
}

View File

@ -0,0 +1,102 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 2009 SC ARHIPAC SERVICE SRL. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
*****************************************************************************/
package org.adempiere.exceptions;
import java.sql.Timestamp;
import java.text.DateFormat;
import org.compiere.model.MLocation;
import org.compiere.model.MTaxCategory;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
/**
* Throw by Tax Engine where no tax found for given criteria
* @author Teo Sarca, www.arhipac.ro
* <li>FR [ 2758097 ] Implement TaxNotFoundException
*/
public class TaxNotFoundException extends AdempiereException
{
/**
*
*/
private static final long serialVersionUID = -5471615720092096644L;
/** AD_Message code */
private static final String AD_Message = "TaxNotFound";
public TaxNotFoundException(int C_TaxCategory_ID, boolean IsSOTrx,
Timestamp shipDate, int shipFromC_Location_ID, int shipToC_Location_ID,
Timestamp billDate, int billFromC_Location_ID, int billToC_Location_ID)
{
super(buildMessage(C_TaxCategory_ID, IsSOTrx,
shipDate, shipFromC_Location_ID, shipToC_Location_ID,
billDate, billFromC_Location_ID, billToC_Location_ID));
}
private static final String buildMessage (int C_TaxCategory_ID, boolean IsSOTrx,
Timestamp shipDate, int shipFromC_Location_ID, int shipToC_Location_ID,
Timestamp billDate, int billFromC_Location_ID, int billToC_Location_ID)
{
final DateFormat df = DisplayType.getDateFormat();
StringBuffer msg = new StringBuffer("@").append(AD_Message).append("@");
//
msg.append(" - @C_TaxCategory_ID@:").append(getTaxCategoryString(C_TaxCategory_ID));
msg.append(", @IsSOTrx@:@").append(IsSOTrx ? "Y":"N").append("@");
//
msg.append(", @Shipment@ (").append(df.format(shipDate)).append(", ")
.append(getLocationString(shipFromC_Location_ID))
.append(" -> ")
.append(getLocationString(shipToC_Location_ID))
.append(")");
//
msg.append(", @Invoice@ (").append(df.format(billDate)).append(", ")
.append(getLocationString(billFromC_Location_ID))
.append(" -> ")
.append(getLocationString(billToC_Location_ID))
.append(")");
//
//
return msg.toString();
}
private static final String getTaxCategoryString(int C_TaxCategory_ID)
{
if (C_TaxCategory_ID <= 0)
{
return "?";
}
MTaxCategory cat = new MTaxCategory(Env.getCtx(), C_TaxCategory_ID, null);
if (cat.get_ID() != C_TaxCategory_ID)
{
return "?";
}
return cat.getName();
}
private static final String getLocationString(int C_Location_ID)
{
if (C_Location_ID <= 0)
{
return "?";
}
MLocation loc = MLocation.get(Env.getCtx(), C_Location_ID, null);
if (loc == null | loc.get_ID() != C_Location_ID)
{
return "?";
}
return loc.toString();
}
}

View File

@ -1,5 +1,5 @@
/****************************************************************************** /******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution * * Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it * * This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published * * under the terms version 2 of the GNU General Public License as published *
@ -21,19 +21,25 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.Properties; import java.util.Properties;
import java.util.logging.Level;
import org.adempiere.exceptions.DBException;
import org.adempiere.exceptions.TaxCriteriaNotFoundException;
import org.adempiere.exceptions.TaxForChangeNotFoundException;
import org.adempiere.exceptions.TaxNoExemptFoundException;
import org.adempiere.exceptions.TaxNotFoundException;
import org.compiere.util.CLogMgt; import org.compiere.util.CLogMgt;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.compiere.util.DB; import org.compiere.util.DB;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.compiere.util.Msg;
/** /**
* Tax Handling * Tax Handling
* *
* @author Jorg Janke * @author Jorg Janke
* @version $Id: Tax.java,v 1.3 2006/07/30 00:51:02 jjanke Exp $ * @version $Id: Tax.java,v 1.3 2006/07/30 00:51:02 jjanke Exp $
*
* @author Teo Sarca, www.arhipac.ro
* <li>FR [ 2758097 ] Implement TaxNotFoundException
*/ */
public class Tax public class Tax
{ {
@ -64,7 +70,7 @@ public class Tax
* @param shipC_BPartner_Location_ID ship location * @param shipC_BPartner_Location_ID ship location
* @param IsSOTrx is a sales trx * @param IsSOTrx is a sales trx
* @return C_Tax_ID * @return C_Tax_ID
* If error it returns 0 and sets error log (TaxCriteriaNotFound) * @throws TaxCriteriaNotFoundException if a criteria was not found
*/ */
public static int get (Properties ctx, int M_Product_ID, int C_Charge_ID, public static int get (Properties ctx, int M_Product_ID, int C_Charge_ID,
Timestamp billDate, Timestamp shipDate, Timestamp billDate, Timestamp shipDate,
@ -104,7 +110,8 @@ public class Tax
* @param shipC_BPartner_Location_ID ship location * @param shipC_BPartner_Location_ID ship location
* @param IsSOTrx is a sales trx * @param IsSOTrx is a sales trx
* @return C_Tax_ID * @return C_Tax_ID
* If error it returns 0 and sets error log (TaxCriteriaNotFound) * @throws TaxForChangeNotFoundException if criteria not found for given change
* @throws TaxCriteriaNotFoundException if a criteria was not found
*/ */
public static int getCharge (Properties ctx, int C_Charge_ID, public static int getCharge (Properties ctx, int C_Charge_ID,
Timestamp billDate, Timestamp shipDate, Timestamp billDate, Timestamp shipDate,
@ -112,12 +119,13 @@ public class Tax
int billC_BPartner_Location_ID, int shipC_BPartner_Location_ID, int billC_BPartner_Location_ID, int shipC_BPartner_Location_ID,
boolean IsSOTrx) boolean IsSOTrx)
{ {
if (M_Warehouse_ID == 0) if (M_Warehouse_ID <= 0)
M_Warehouse_ID = Env.getContextAsInt(ctx, "M_Warehouse_ID"); M_Warehouse_ID = Env.getContextAsInt(ctx, "M_Warehouse_ID");
if (M_Warehouse_ID == 0) if (M_Warehouse_ID <= 0)
{ {
log.warning("No Warehouse - C_Charge_ID=" + C_Charge_ID); throw new TaxForChangeNotFoundException(C_Charge_ID, AD_Org_ID, M_Warehouse_ID,
return 0; billC_BPartner_Location_ID, shipC_BPartner_Location_ID,
"@NotFound@ @M_Warehouse_ID@");
} }
int C_TaxCategory_ID = 0; int C_TaxCategory_ID = 0;
int shipFromC_Location_ID = 0; int shipFromC_Location_ID = 0;
@ -163,21 +171,21 @@ public class Tax
// //
if (!found) if (!found)
{ {
log.warning("Not found for C_Charge_ID=" + C_Charge_ID throw new TaxForChangeNotFoundException(C_Charge_ID, AD_Org_ID, M_Warehouse_ID,
+ ", AD_Org_ID=" + AD_Org_ID + ", M_Warehouse_ID=" + M_Warehouse_ID billC_BPartner_Location_ID, shipC_BPartner_Location_ID,
+ ", C_BPartner_Location_ID=" + billC_BPartner_Location_ID null);
+ "/" + shipC_BPartner_Location_ID);
return 0;
} }
else if ("Y".equals (IsTaxExempt)) else if ("Y".equals (IsTaxExempt))
{
return getExemptTax (ctx, AD_Org_ID); return getExemptTax (ctx, AD_Org_ID);
}
} }
catch (Exception e) catch (SQLException e)
{ {
log.log(Level.SEVERE, sql, e); throw new DBException(e);
return 0;
} }
finally { finally
{
DB.close(rs, pstmt); DB.close(rs, pstmt);
rs = null; pstmt = null; rs = null; pstmt = null;
} }
@ -242,12 +250,13 @@ public class Tax
int billToC_Location_ID = 0; int billToC_Location_ID = 0;
String IsTaxExempt = null; String IsTaxExempt = null;
PreparedStatement pstmt = null; String sql = null;
PreparedStatement pstmt = null;
ResultSet rs = null; ResultSet rs = null;
try try
{ {
// Get all at once // Get all at once
String sql = "SELECT p.C_TaxCategory_ID, o.C_Location_ID, il.C_Location_ID, b.IsTaxExempt," sql = "SELECT p.C_TaxCategory_ID, o.C_Location_ID, il.C_Location_ID, b.IsTaxExempt,"
+ " w.C_Location_ID, sl.C_Location_ID " + " w.C_Location_ID, sl.C_Location_ID "
+ "FROM M_Product p, AD_OrgInfo o," + "FROM M_Product p, AD_OrgInfo o,"
+ " C_BPartner_Location il INNER JOIN C_BPartner b ON (il.C_BPartner_ID=b.C_BPartner_ID)," + " C_BPartner_Location il INNER JOIN C_BPartner b ON (il.C_BPartner_ID=b.C_BPartner_ID),"
@ -308,53 +317,32 @@ public class Tax
// Detail for error isolation // Detail for error isolation
// M_Product_ID -> C_TaxCategory_ID // M_Product_ID -> C_TaxCategory_ID
sql = "SELECT C_TaxCategory_ID FROM M_Product "
+ "WHERE M_Product_ID=?";
variable = "M_Product_ID"; variable = "M_Product_ID";
pstmt = DB.prepareStatement(sql, null); sql = "SELECT C_TaxCategory_ID FROM M_Product WHERE M_Product_ID=?";
pstmt.setInt(1, M_Product_ID); C_TaxCategory_ID = DB.getSQLValueEx(null, sql, M_Product_ID);
rs = pstmt.executeQuery(); found = C_TaxCategory_ID != -1;
found = false; if (C_TaxCategory_ID <= 0)
if (rs.next())
{ {
C_TaxCategory_ID = rs.getInt(1); throw new TaxCriteriaNotFoundException(variable, M_Product_ID);
found = true;
}
DB.close(rs, pstmt);
if (C_TaxCategory_ID == 0)
{
log.saveError("TaxCriteriaNotFound", Msg.translate(ctx, variable)
+ (found ? "" : " (Product=" + M_Product_ID + " not found)"));
return 0;
} }
log.fine("getProduct - C_TaxCategory_ID=" + C_TaxCategory_ID); log.fine("getProduct - C_TaxCategory_ID=" + C_TaxCategory_ID);
// AD_Org_ID -> billFromC_Location_ID // AD_Org_ID -> billFromC_Location_ID
sql = "SELECT C_Location_ID FROM AD_OrgInfo "
+ "WHERE AD_Org_ID=?";
variable = "AD_Org_ID"; variable = "AD_Org_ID";
pstmt = DB.prepareStatement(sql, null); sql = "SELECT C_Location_ID FROM AD_OrgInfo WHERE AD_Org_ID=?";
pstmt.setInt(1, AD_Org_ID); billFromC_Location_ID = DB.getSQLValueEx(null, sql, AD_Org_ID);
rs = pstmt.executeQuery(); found = billFromC_Location_ID != -1;
found = false; if (billFromC_Location_ID <= 0)
if (rs.next())
{ {
billFromC_Location_ID = rs.getInt (1); throw new TaxCriteriaNotFoundException(variable, AD_Org_ID);
found = true;
}
DB.close(rs, pstmt);
if (billFromC_Location_ID == 0)
{
log.saveError("TaxCriteriaNotFound", Msg.translate(Env.getAD_Language(ctx), variable)
+ (found ? "" : " (Info/Org=" + AD_Org_ID + " not found)"));
return 0;
} }
// billC_BPartner_Location_ID -> billToC_Location_ID // billC_BPartner_Location_ID -> billToC_Location_ID
sql = "SELECT l.C_Location_ID, b.IsTaxExempt "
+ "FROM C_BPartner_Location l INNER JOIN C_BPartner b ON (l.C_BPartner_ID=b.C_BPartner_ID) "
+ "WHERE C_BPartner_Location_ID=?";
variable = "BillTo_ID"; variable = "BillTo_ID";
sql = "SELECT l.C_Location_ID, b.IsTaxExempt "
+ " FROM C_BPartner_Location l"
+ " INNER JOIN C_BPartner b ON (l.C_BPartner_ID=b.C_BPartner_ID) "
+ " WHERE C_BPartner_Location_ID=?";
pstmt = DB.prepareStatement(sql, null); pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, billC_BPartner_Location_ID); pstmt.setInt(1, billC_BPartner_Location_ID);
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
@ -366,11 +354,9 @@ public class Tax
found = true; found = true;
} }
DB.close(rs, pstmt); DB.close(rs, pstmt);
if (billToC_Location_ID == 0) if (billToC_Location_ID <= 0)
{ {
log.saveError("TaxCriteriaNotFound", Msg.translate(Env.getAD_Language(ctx), variable) throw new TaxCriteriaNotFoundException(variable, billC_BPartner_Location_ID);
+ (found ? "" : " (BPLocation=" + billC_BPartner_Location_ID + " not found)"));
return 0;
} }
if ("Y".equals(IsTaxExempt)) if ("Y".equals(IsTaxExempt))
return getExemptTax(ctx, AD_Org_ID); return getExemptTax(ctx, AD_Org_ID);
@ -388,45 +374,23 @@ public class Tax
//----------------------------------------------------------------- //-----------------------------------------------------------------
// M_Warehouse_ID -> shipFromC_Location_ID // M_Warehouse_ID -> shipFromC_Location_ID
sql = "SELECT C_Location_ID FROM M_Warehouse "
+ "WHERE M_Warehouse_ID=?";
variable = "M_Warehouse_ID"; variable = "M_Warehouse_ID";
pstmt = DB.prepareStatement(sql, null); sql = "SELECT C_Location_ID FROM M_Warehouse WHERE M_Warehouse_ID=?";
pstmt.setInt(1, M_Warehouse_ID); shipFromC_Location_ID = DB.getSQLValueEx(null, sql, M_Warehouse_ID);
rs = pstmt.executeQuery(); found = shipFromC_Location_ID != -1;
found = false; if (shipFromC_Location_ID <= 0)
if (rs.next())
{ {
shipFromC_Location_ID = rs.getInt (1); throw new TaxCriteriaNotFoundException(variable, M_Warehouse_ID);
found = true;
}
DB.close(rs, pstmt);
if (shipFromC_Location_ID == 0)
{
log.saveError("TaxCriteriaNotFound", Msg.translate(Env.getAD_Language(ctx), variable)
+ (found ? "" : " (Warehouse=" + M_Warehouse_ID + " not found)"));
return 0;
} }
// shipC_BPartner_Location_ID -> shipToC_Location_ID // shipC_BPartner_Location_ID -> shipToC_Location_ID
sql = "SELECT C_Location_ID FROM C_BPartner_Location "
+ "WHERE C_BPartner_Location_ID=?";
variable = "C_BPartner_Location_ID"; variable = "C_BPartner_Location_ID";
pstmt = DB.prepareStatement(sql, null); sql = "SELECT C_Location_ID FROM C_BPartner_Location WHERE C_BPartner_Location_ID=?";
pstmt.setInt(1, shipC_BPartner_Location_ID); shipToC_Location_ID = DB.getSQLValueEx(null, sql, shipC_BPartner_Location_ID);
rs = pstmt.executeQuery(); found = shipToC_Location_ID != -1;
found = false; if (shipToC_Location_ID <= 0)
if (rs.next())
{ {
shipToC_Location_ID = rs.getInt (1); throw new TaxCriteriaNotFoundException(variable, shipC_BPartner_Location_ID);
found = true;
}
DB.close(rs, pstmt);
if (shipToC_Location_ID == 0)
{
log.saveError("TaxCriteriaNotFound", Msg.translate(Env.getAD_Language(ctx), variable)
+ (found ? "" : " (BPLocation=" + shipC_BPartner_Location_ID + " not found)"));
return 0;
} }
// Reverse for PO // Reverse for PO
@ -441,12 +405,11 @@ public class Tax
} }
catch (SQLException e) catch (SQLException e)
{ {
log.log(Level.SEVERE, "getProduct (" + variable + ")", e); throw new DBException(e, sql);
} }
finally finally
{ {
DB.close(rs); DB.close(rs, pstmt);
DB.close(pstmt);
rs = null; pstmt = null; rs = null; pstmt = null;
} }
@ -456,52 +419,34 @@ public class Tax
} // getProduct } // getProduct
/** /**
* Get Exempt Tax Code * Get Exempt Tax Code
* @param ctx context * @param ctx context
* @param AD_Org_ID org to find client * @param AD_Org_ID org to find client
* @return C_Tax_ID * @return C_Tax_ID
* @throws TaxNoExemptFoundException if no tax exempt found
*/ */
private static int getExemptTax (Properties ctx, int AD_Org_ID) private static int getExemptTax (Properties ctx, int AD_Org_ID)
{ {
int C_Tax_ID = 0; final String sql = "SELECT t.C_Tax_ID "
String sql = "SELECT t.C_Tax_ID "
+ "FROM C_Tax t" + "FROM C_Tax t"
+ " INNER JOIN AD_Org o ON (t.AD_Client_ID=o.AD_Client_ID) " + " INNER JOIN AD_Org o ON (t.AD_Client_ID=o.AD_Client_ID) "
+ "WHERE t.IsTaxExempt='Y' AND o.AD_Org_ID=? " + "WHERE t.IsTaxExempt='Y' AND o.AD_Org_ID=? "
+ "ORDER BY t.Rate DESC"; + "ORDER BY t.Rate DESC";
boolean found = false; int C_Tax_ID = DB.getSQLValueEx(null, sql, AD_Org_ID);
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, AD_Org_ID);
rs = pstmt.executeQuery();
if (rs.next())
{
C_Tax_ID = rs.getInt (1);
found = true;
}
}
catch (SQLException e)
{
log.log(Level.SEVERE, "getExemptTax", e);
}
finally {
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
log.fine("getExemptTax - TaxExempt=Y - C_Tax_ID=" + C_Tax_ID); log.fine("getExemptTax - TaxExempt=Y - C_Tax_ID=" + C_Tax_ID);
if (C_Tax_ID == 0) if (C_Tax_ID <= 0)
log.saveError("TaxCriteriaNotFound", Msg.getMsg(ctx, "TaxNoExemptFound") {
+ (found ? "" : " (Tax/Org=" + AD_Org_ID + " not found)")); throw new TaxNoExemptFoundException(AD_Org_ID);
return C_Tax_ID; }
else
{
return C_Tax_ID;
}
} // getExemptTax } // getExemptTax
/************************************************************************** /**************************************************************************
* Get Tax ID (Detail). * Get Tax ID (Detail).
* If error return 0 and set error log (TaxNotFound)
* @param ctx context * @param ctx context
* @param C_TaxCategory_ID tax category * @param C_TaxCategory_ID tax category
* @param IsSOTrx Sales Order Trx * @param IsSOTrx Sales Order Trx
@ -512,6 +457,7 @@ public class Tax
* @param billFromC_Location_ID invoice from * @param billFromC_Location_ID invoice from
* @param billToC_Location_ID invoice to * @param billToC_Location_ID invoice to
* @return C_Tax_ID * @return C_Tax_ID
* @throws TaxNotFoundException if no tax found for given criteria
*/ */
protected static int get (Properties ctx, protected static int get (Properties ctx,
int C_TaxCategory_ID, boolean IsSOTrx, int C_TaxCategory_ID, boolean IsSOTrx,
@ -610,8 +556,9 @@ public class Tax
return tax.getC_Tax_ID(); return tax.getC_Tax_ID();
} // for all taxes } // for all taxes
log.saveError("TaxNotFound", ""); throw new TaxNotFoundException(C_TaxCategory_ID, IsSOTrx,
return 0; shipDate, shipFromC_Locction_ID, shipToC_Location_ID,
billDate, billFromC_Location_ID, billToC_Location_ID);
} // get } // get
} // Tax } // Tax