📄 tax.java
字号:
/******************************************************************************
* The contents of this file are subject to the Compiere License Version 1.1
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the License at http://www.compiere.org/license.html
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Original Code is Compiere ERP & CRM Business Solution
* The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
* Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
* created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.model;
import java.sql.*;
import java.util.Properties;
import org.apache.log4j.Logger;
import org.compiere.util.*;
/**
* Tax Handling
*
* @author Jorg Janke
* @version $Id: Tax.java,v 1.10 2003/04/13 05:52:22 jjanke Exp $
*/
public class Tax
{
/** Logger */
static private Logger s_log = Logger.getLogger (Tax.class);
/*************************************************************************/
/**
* Get Tax ID - converts parameters to call Get Tax.
* <pre>
* M_Product_ID/C_Charge_ID -> C_TaxCategory_ID
* billDate, shipDate -> billDate, shipDate
* AD_Org_ID -> billFromC_Location_ID
* M_Warehouse_ID -> shipFromC_Location_ID
* billC_BPartner_Location_ID -> billToC_Location_ID
* shipC_BPartner_Location_ID -> shipToC_Location_ID
*
* if IsSOTrx is false, bill and ship are reversed
* </pre>
* @param ctx context
* @param M_Product_ID product
* @param C_Charge_ID product
* @param billDate invoice date
* @param shipDate ship date
* @param AD_Org_ID org
* @param M_Warehouse_ID warehouse
* @param billC_BPartner_Location_ID invoice location
* @param shipC_BPartner_Location_ID ship location
* @param IsSOTrx is a sales trx
* @return C_Tax_ID
* If error it returns 0 and sets error log (TaxCriteriaNotFound)
*/
public static int get (Properties ctx, int M_Product_ID, int C_Charge_ID,
Timestamp billDate, Timestamp shipDate,
int AD_Org_ID, int M_Warehouse_ID,
int billC_BPartner_Location_ID, int shipC_BPartner_Location_ID,
boolean IsSOTrx)
{
if (M_Product_ID != 0)
return getProduct (ctx, M_Product_ID, billDate, shipDate, AD_Org_ID, M_Warehouse_ID,
billC_BPartner_Location_ID, shipC_BPartner_Location_ID, IsSOTrx);
else if (C_Charge_ID != 0)
return getCharge (ctx, C_Charge_ID, billDate, shipDate, AD_Org_ID, M_Warehouse_ID,
billC_BPartner_Location_ID, shipC_BPartner_Location_ID, IsSOTrx);
else
return getExemptTax (ctx, AD_Org_ID);
} // get
/**
* Get Tax ID - converts parameters to call Get Tax.
* <pre>
* C_Charge_ID -> C_TaxCategory_ID
* billDate, shipDate -> billDate, shipDate
* AD_Org_ID -> billFromC_Location_ID
* M_Warehouse_ID -> shipFromC_Location_ID
* billC_BPartner_Location_ID -> billToC_Location_ID
* shipC_BPartner_Location_ID -> shipToC_Location_ID
*
* if IsSOTrx is false, bill and ship are reversed
* </pre>
* @param ctx context
* @param C_Charge_ID product
* @param billDate invoice date
* @param shipDate ship date
* @param AD_Org_ID org
* @param M_Warehouse_ID warehouse
* @param billC_BPartner_Location_ID invoice location
* @param shipC_BPartner_Location_ID ship location
* @param IsSOTrx is a sales trx
* @return C_Tax_ID
* If error it returns 0 and sets error log (TaxCriteriaNotFound)
*/
public static int getCharge (Properties ctx, int C_Charge_ID,
Timestamp billDate, Timestamp shipDate,
int AD_Org_ID, int M_Warehouse_ID,
int billC_BPartner_Location_ID, int shipC_BPartner_Location_ID,
boolean IsSOTrx)
{
String variable = "";
int C_TaxCategory_ID = 0;
int shipFromC_Location_ID = 0;
int shipToC_Location_ID = 0;
int billFromC_Location_ID = 0;
int billToC_Location_ID = 0;
String IsTaxExempt = null;
try
{
// Get all at once
String sql = "SELECT c.C_TaxCategory_ID, o.C_Location_ID, il.C_Location_ID, b.IsTaxExempt,"
+ " w.C_Location_ID, sl.C_Location_ID "
+ "FROM C_Charge c, AD_OrgInfo o,"
+ " C_BPartner_Location il INNER JOIN C_BPartner b ON (il.C_BPartner_ID=b.C_BPartner_ID),"
+ " M_Warehouse w, C_BPartner_Location sl "
+ "WHERE c.C_Charge_ID=?"
+ " AND o.AD_Org_ID=?"
+ " AND il.C_BPartner_Location_ID=?"
+ " AND w.M_Warehouse_ID=?"
+ " AND sl.C_BPartner_Location_ID=?";
PreparedStatement pstmt = DB.prepareStatement (sql);
pstmt.setInt (1, C_Charge_ID);
pstmt.setInt (2, AD_Org_ID);
pstmt.setInt (3, billC_BPartner_Location_ID);
pstmt.setInt (4, M_Warehouse_ID);
pstmt.setInt (5, shipC_BPartner_Location_ID);
ResultSet rs = pstmt.executeQuery ();
boolean found = false;
if (rs.next ())
{
C_TaxCategory_ID = rs.getInt (1);
billFromC_Location_ID = rs.getInt (2);
billToC_Location_ID = rs.getInt (3);
IsTaxExempt = rs.getString (4);
shipFromC_Location_ID = rs.getInt (5);
shipToC_Location_ID = rs.getInt (6);
found = true;
}
rs.close ();
pstmt.close ();
//
if (!found)
{
s_log.error("getCharge - Not found - C_Charge_ID=" + C_Charge_ID);
return 0;
}
else if ("Y".equals (IsTaxExempt))
return getExemptTax (ctx, AD_Org_ID);
}
catch (Exception e)
{
s_log.error("getCharge", e);
return 0;
}
// Reverese for PO
if (!IsSOTrx)
{
int temp = billFromC_Location_ID;
billFromC_Location_ID = billToC_Location_ID;
billToC_Location_ID = temp;
temp = shipFromC_Location_ID;
shipFromC_Location_ID = shipToC_Location_ID;
shipToC_Location_ID = temp;
}
//
s_log.debug ("C_TaxCategory_ID=" + C_TaxCategory_ID
+ ", billFromC_Location_ID=" + billFromC_Location_ID
+ ", billToC_Location_ID=" + billToC_Location_ID
+ ", shipFromC_Location_ID=" + shipFromC_Location_ID
+ ", shipToC_Location_ID=" + shipToC_Location_ID);
return get (C_TaxCategory_ID,
shipDate, shipFromC_Location_ID, shipToC_Location_ID,
billDate, billFromC_Location_ID, billToC_Location_ID);
} // getCharge
/**
* Get Tax ID - converts parameters to call Get Tax.
* <pre>
* M_Product_ID -> C_TaxCategory_ID
* billDate, shipDate -> billDate, shipDate
* AD_Org_ID -> billFromC_Location_ID
* M_Warehouse_ID -> shipFromC_Location_ID
* billC_BPartner_Location_ID -> billToC_Location_ID
* shipC_BPartner_Location_ID -> shipToC_Location_ID
*
* if IsSOTrx is false, bill and ship are reversed
* </pre>
* @param ctx context
* @param M_Product_ID product
* @param billDate invoice date
* @param shipDate ship date
* @param AD_Org_ID org
* @param M_Warehouse_ID warehouse
* @param billC_BPartner_Location_ID invoice location
* @param shipC_BPartner_Location_ID ship location
* @param IsSOTrx is a sales trx
* @return C_Tax_ID
* If error it returns 0 and sets error log (TaxCriteriaNotFound)
*/
public static int getProduct (Properties ctx, int M_Product_ID,
Timestamp billDate, Timestamp shipDate,
int AD_Org_ID, int M_Warehouse_ID,
int billC_BPartner_Location_ID, int shipC_BPartner_Location_ID,
boolean IsSOTrx)
{
String variable = "";
int C_TaxCategory_ID = 0;
int shipFromC_Location_ID = 0;
int shipToC_Location_ID = 0;
int billFromC_Location_ID = 0;
int billToC_Location_ID = 0;
String IsTaxExempt = null;
try
{
// Get all at once
String sql = "SELECT p.C_TaxCategory_ID, o.C_Location_ID, il.C_Location_ID, b.IsTaxExempt,"
+ " w.C_Location_ID, sl.C_Location_ID "
+ "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),"
+ " M_Warehouse w, C_BPartner_Location sl "
+ "WHERE p.M_Product_ID=?"
+ " AND o.AD_Org_ID=?"
+ " AND il.C_BPartner_Location_ID=?"
+ " AND w.M_Warehouse_ID=?"
+ " AND sl.C_BPartner_Location_ID=?";
PreparedStatement pstmt = DB.prepareStatement(sql);
pstmt.setInt(1, M_Product_ID);
pstmt.setInt(2, AD_Org_ID);
pstmt.setInt(3, billC_BPartner_Location_ID);
pstmt.setInt(4, M_Warehouse_ID);
pstmt.setInt(5, shipC_BPartner_Location_ID);
ResultSet rs = pstmt.executeQuery();
boolean found = false;
if (rs.next())
{
C_TaxCategory_ID = rs.getInt(1);
billFromC_Location_ID = rs.getInt(2);
billToC_Location_ID = rs.getInt(3);
IsTaxExempt = rs.getString(4);
shipFromC_Location_ID = rs.getInt(5);
shipToC_Location_ID = rs.getInt(6);
found = true;
}
rs.close();
pstmt.close();
//
if (found && "Y".equals(IsTaxExempt))
return getExemptTax(ctx, AD_Org_ID);
else if (found)
{
if (!IsSOTrx)
{
int temp = billFromC_Location_ID;
billFromC_Location_ID = billToC_Location_ID;
billToC_Location_ID = temp;
temp = shipFromC_Location_ID;
shipFromC_Location_ID = shipToC_Location_ID;
shipToC_Location_ID = temp;
}
s_log.debug("C_TaxCategory_ID=" + C_TaxCategory_ID
+ ", billFromC_Location_ID=" + billFromC_Location_ID
+ ", billToC_Location_ID=" + billToC_Location_ID
+ ", shipFromC_Location_ID=" + shipFromC_Location_ID
+ ", shipToC_Location_ID=" + shipToC_Location_ID);
return get(C_TaxCategory_ID,
shipDate, shipFromC_Location_ID, shipToC_Location_ID,
billDate, billFromC_Location_ID, billToC_Location_ID);
}
// ----------------------------------------------------------------
// Detail for error isolation
// M_Product_ID -> C_TaxCategory_ID
sql = "SELECT C_TaxCategory_ID FROM M_Product "
+ "WHERE M_Product_ID=?";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -