Search in sources :

Example 1 with TaxForChangeNotFoundException

use of org.adempiere.exceptions.TaxForChangeNotFoundException in project adempiere by adempiere.

the class Tax method getCharge.

//	get
/**
	 *	Get Tax ID - converts parameters to call Get Tax.
	 *  <pre>
	 *		C_Charge_ID					->	C_TaxCategory_ID
	 *		billDate					->	billDate
	 *		shipDate					->	shipDate (ignored)
	 *		AD_Org_ID					->	billFromC_Location_ID
	 *		M_Warehouse_ID				->	shipFromC_Location_ID (ignored)
	 *		billC_BPartner_Location_ID  ->	billToC_Location_ID
	 *		shipC_BPartner_Location_ID 	->	shipToC_Location_ID (ignored)
	 *
	 *  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 (ignored)
	 * 	@param AD_Org_ID org
	 * 	@param M_Warehouse_ID warehouse (ignored)
	 * 	@param billC_BPartner_Location_ID invoice location
	 * 	@param shipC_BPartner_Location_ID ship location (ignored)
	 * 	@param IsSOTrx is a sales trx
	 * 	@return C_Tax_ID
	 *  @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, Timestamp billDate, Timestamp shipDate, int AD_Org_ID, int M_Warehouse_ID, int billC_BPartner_Location_ID, int shipC_BPartner_Location_ID, boolean IsSOTrx) {
    /* ship location from warehouse is plainly ignored below */
    // if (M_Warehouse_ID <= 0)
    // M_Warehouse_ID = Env.getContextAsInt(ctx, "M_Warehouse_ID");
    // if (M_Warehouse_ID <= 0)
    // {
    // throw new TaxForChangeNotFoundException(C_Charge_ID, AD_Org_ID, M_Warehouse_ID,
    // billC_BPartner_Location_ID, shipC_BPartner_Location_ID,
    // "@NotFound@ @M_Warehouse_ID@");
    // }
    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;
    String IsSOTaxExempt = null;
    String IsPOTaxExempt = null;
    //	Get all at once
    String sql = "SELECT c.C_TaxCategory_ID, o.C_Location_ID, il.C_Location_ID, b.IsTaxExempt, b.IsPOTaxExempt," + " 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) " + " LEFT OUTER JOIN M_Warehouse w ON (w.M_Warehouse_ID=?), C_BPartner_Location sl " + "WHERE c.C_Charge_ID=?" + " AND o.AD_Org_ID=?" + " AND il.C_BPartner_Location_ID=?" + " AND sl.C_BPartner_Location_ID=?";
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sql, null);
        pstmt.setInt(1, M_Warehouse_ID);
        pstmt.setInt(2, C_Charge_ID);
        pstmt.setInt(3, AD_Org_ID);
        pstmt.setInt(4, billC_BPartner_Location_ID);
        pstmt.setInt(5, shipC_BPartner_Location_ID);
        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);
            IsSOTaxExempt = rs.getString(4);
            IsPOTaxExempt = rs.getString(5);
            IsTaxExempt = IsSOTrx ? IsSOTaxExempt : IsPOTaxExempt;
            shipFromC_Location_ID = rs.getInt(6);
            shipToC_Location_ID = rs.getInt(7);
            found = true;
        }
        DB.close(rs, pstmt);
        //
        if (!found) {
            throw new TaxForChangeNotFoundException(C_Charge_ID, AD_Org_ID, M_Warehouse_ID, billC_BPartner_Location_ID, shipC_BPartner_Location_ID, null);
        } else if ("Y".equals(IsTaxExempt)) {
            return getExemptTax(ctx, AD_Org_ID);
        }
    } catch (SQLException e) {
        throw new DBException(e, sql);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    //	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);
}
Also used : DBException(org.adempiere.exceptions.DBException) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) TaxForChangeNotFoundException(org.adempiere.exceptions.TaxForChangeNotFoundException)

Aggregations

PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 DBException (org.adempiere.exceptions.DBException)1 TaxForChangeNotFoundException (org.adempiere.exceptions.TaxForChangeNotFoundException)1