📄 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 Smart Business Solution. The Initial
* Developer of the Original Code is Jorg Janke. Portions created by Jorg Janke
* are Copyright (C) 1999-2005 Jorg Janke.
* All parts are Copyright (C) 1999-2005 ComPiere, Inc. All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.model;
import java.sql.*;
import java.util.*;
import java.util.logging.*;
import org.compiere.util.*;
/**
* Tax Handling
*
* @author Jorg Janke
* @version $Id: Tax.java,v 1.21 2005/12/17 19:55:33 jjanke Exp $
*/
public class Tax
{
/** Logger */
static private CLogger log = CLogger.getCLogger (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)
{
if (M_Warehouse_ID == 0)
M_Warehouse_ID = Env.getContextAsInt(ctx, "M_Warehouse_ID");
if (M_Warehouse_ID == 0)
{
log.warning("No Warehouse - C_Charge_ID=" + C_Charge_ID);
return 0;
}
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;
// 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=?";
try
{
PreparedStatement pstmt = DB.prepareStatement (sql, null);
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)
{
log.warning("Not found for C_Charge_ID=" + C_Charge_ID
+ ", AD_Org_ID=" + AD_Org_ID + ", M_Warehouse_ID=" + M_Warehouse_ID
+ ", C_BPartner_Location_ID=" + billC_BPartner_Location_ID
+ "/" + shipC_BPartner_Location_ID);
return 0;
}
else if ("Y".equals (IsTaxExempt))
return getExemptTax (ctx, AD_Org_ID);
}
catch (Exception e)
{
log.log(Level.SEVERE, sql, 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;
}
//
log.fine("getCharge - 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 (ctx, C_TaxCategory_ID, IsSOTrx,
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, null);
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))
{
log.fine("getProduct - Business Partner is Tax exempt");
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;
}
log.fine("getProduct - 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(ctx, C_TaxCategory_ID, IsSOTrx,
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=?";
variable = "M_Product_ID";
pstmt = DB.prepareStatement(sql, null);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -