@@ -0,0 +1,303 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2007 ComPiere, Inc. 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. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package ar.com.ergio.model;

import java.math.BigDecimal;
import java.sql.Timestamp;
import org.compiere.model.*;
import org.compiere.util.KeyNamePair;

/** Generated Interface for LAR_WithholdingCertificate
* @author Adempiere (generated)
* @version 3.6.0LTS+P20110709
*/
public interface I_LAR_WithholdingCertificate
{

/** TableName=LAR_WithholdingCertificate */
public static final String Table_Name = "LAR_WithholdingCertificate";

/** AD_Table_ID=1000043 */
public static final int Table_ID = MTable.getTable_ID(Table_Name);

KeyNamePair Model = new KeyNamePair(Table_ID, Table_Name);

/** AccessLevel = 7 - System - Client - Org
*/
BigDecimal accessLevel = BigDecimal.valueOf(7);

/** Load Meta Data */

/** Column name AD_Client_ID */
public static final String COLUMNNAME_AD_Client_ID = "AD_Client_ID";

/** Get Client.
* Client/Tenant for this installation.
*/
public int getAD_Client_ID();

/** Column name Address1 */
public static final String COLUMNNAME_Address1 = "Address1";

/** Set Address 1.
* Address line 1 for this location
*/
public void setAddress1 (String Address1);

/** Get Address 1.
* Address line 1 for this location
*/
public String getAddress1();

/** Column name AD_Org_ID */
public static final String COLUMNNAME_AD_Org_ID = "AD_Org_ID";

/** Set Organization.
* Organizational entity within client
*/
public void setAD_Org_ID (int AD_Org_ID);

/** Get Organization.
* Organizational entity within client
*/
public int getAD_Org_ID();

/** Column name BPName */
public static final String COLUMNNAME_BPName = "BPName";

/** Set BP Name */
public void setBPName (String BPName);

/** Get BP Name */
public String getBPName();

/** Column name C_DocType_ID */
public static final String COLUMNNAME_C_DocType_ID = "C_DocType_ID";

/** Set Document Type.
* Document type or rules
*/
public void setC_DocType_ID (int C_DocType_ID);

/** Get Document Type.
* Document type or rules
*/
public int getC_DocType_ID();

public I_C_DocType getC_DocType() throws RuntimeException;

/** Column name C_DocTypeTarget_ID */
public static final String COLUMNNAME_C_DocTypeTarget_ID = "C_DocTypeTarget_ID";

/** Set Target Document Type.
* Target document type for conversing documents
*/
public void setC_DocTypeTarget_ID (int C_DocTypeTarget_ID);

/** Get Target Document Type.
* Target document type for conversing documents
*/
public int getC_DocTypeTarget_ID();

/** Column name C_Invoice_ID */
public static final String COLUMNNAME_C_Invoice_ID = "C_Invoice_ID";

/** Set Invoice.
* Invoice Identifier
*/
public void setC_Invoice_ID (int C_Invoice_ID);

/** Get Invoice.
* Invoice Identifier
*/
public int getC_Invoice_ID();

public I_C_Invoice getC_Invoice() throws RuntimeException;

/** Column name City */
public static final String COLUMNNAME_City = "City";

/** Set City.
* Identifies a City
*/
public void setCity (String City);

/** Get City.
* Identifies a City
*/
public String getCity();

/** Column name C_Payment_ID */
public static final String COLUMNNAME_C_Payment_ID = "C_Payment_ID";

/** Set Payment.
* Payment identifier
*/
public void setC_Payment_ID (int C_Payment_ID);

/** Get Payment.
* Payment identifier
*/
public int getC_Payment_ID();

public I_C_Payment getC_Payment() throws RuntimeException;

/** Column name Created */
public static final String COLUMNNAME_Created = "Created";

/** Get Created.
* Date this record was created
*/
public Timestamp getCreated();

/** Column name CreatedBy */
public static final String COLUMNNAME_CreatedBy = "CreatedBy";

/** Get Created By.
* User who created this records
*/
public int getCreatedBy();

/** Column name DocumentNo */
public static final String COLUMNNAME_DocumentNo = "DocumentNo";

/** Set Document No.
* Document sequence number of the document
*/
public void setDocumentNo (String DocumentNo);

/** Get Document No.
* Document sequence number of the document
*/
public String getDocumentNo();

/** Column name IsActive */
public static final String COLUMNNAME_IsActive = "IsActive";

/** Set Active.
* The record is active in the system
*/
public void setIsActive (boolean IsActive);

/** Get Active.
* The record is active in the system
*/
public boolean isActive();

/** Column name LAR_WithholdingCertificate_ID */
public static final String COLUMNNAME_LAR_WithholdingCertificate_ID = "LAR_WithholdingCertificate_ID";

/** Set LAR_WithholdingCertificate */
public void setLAR_WithholdingCertificate_ID (int LAR_WithholdingCertificate_ID);

/** Get LAR_WithholdingCertificate */
public int getLAR_WithholdingCertificate_ID();

/** Column name NAICS */
public static final String COLUMNNAME_NAICS = "NAICS";

/** Set NAICS/SIC.
* Standard Industry Code or its successor NAIC - http://www.osha.gov/oshstats/sicser.html
*/
public void setNAICS (String NAICS);

/** Get NAICS/SIC.
* Standard Industry Code or its successor NAIC - http://www.osha.gov/oshstats/sicser.html
*/
public String getNAICS();

/** Column name Percent */
public static final String COLUMNNAME_Percent = "Percent";

/** Set Percent.
* Percentage
*/
public void setPercent (BigDecimal Percent);

/** Get Percent.
* Percentage
*/
public BigDecimal getPercent();

/** Column name Postal */
public static final String COLUMNNAME_Postal = "Postal";

/** Set ZIP.
* Postal code
*/
public void setPostal (String Postal);

/** Get ZIP.
* Postal code
*/
public String getPostal();

/** Column name RegionName */
public static final String COLUMNNAME_RegionName = "RegionName";

/** Set Region.
* Name of the Region
*/
public void setRegionName (String RegionName);

/** Get Region.
* Name of the Region
*/
public String getRegionName();

/** Column name TaxAmt */
public static final String COLUMNNAME_TaxAmt = "TaxAmt";

/** Set Tax Amount.
* Tax Amount for a document
*/
public void setTaxAmt (BigDecimal TaxAmt);

/** Get Tax Amount.
* Tax Amount for a document
*/
public BigDecimal getTaxAmt();

/** Column name TaxID */
public static final String COLUMNNAME_TaxID = "TaxID";

/** Set Tax ID.
* Tax Identification
*/
public void setTaxID (String TaxID);

/** Get Tax ID.
* Tax Identification
*/
public String getTaxID();

/** Column name Updated */
public static final String COLUMNNAME_Updated = "Updated";

/** Get Updated.
* Date this record was updated
*/
public Timestamp getUpdated();

/** Column name UpdatedBy */
public static final String COLUMNNAME_UpdatedBy = "UpdatedBy";

/** Get Updated By.
* User who updated this records
*/
public int getUpdatedBy();
}
@@ -21,11 +21,13 @@
import java.sql.ResultSet;
import java.util.logging.Level;

import org.adempiere.exceptions.AdempiereException;
import org.compiere.model.MBPartner;
import org.compiere.model.MClient;
import org.compiere.model.MOrder;
import org.compiere.model.MOrderLine;
import org.compiere.model.MOrderTax;
import org.compiere.model.MPayment;
import org.compiere.model.ModelValidationEngine;
import org.compiere.model.ModelValidator;
import org.compiere.model.PO;
@@ -42,6 +44,9 @@
* @version $Id: LAR_Validator.java,v 1.0 2011/11/04 egonzalez Exp $
*/
public class LAR_Validator implements ModelValidator {
// TODO - try to avoid this hardcode value
private static final int PERCEPCION_ID = 1000002; // Perception Tax Category
private static final int RETENCION_ID = 1000003; // Withholding Tax Category

/**
* Constructor.
@@ -77,6 +82,10 @@ public void initialize (ModelValidationEngine engine, MClient client)
engine.addModelChange(MBPartner.Table_Name, this);
engine.addModelChange(MOrderLine.Table_Name, this);
engine.addModelChange(MOrder.Table_Name, this);
engine.addModelChange(MPayment.Table_Name, this);

// Documents to be monitored
engine.addDocValidate(MPayment.Table_Name, this);

} // initialize

@@ -93,12 +102,13 @@ public void initialize (ModelValidationEngine engine, MClient client)
* @exception Exception
* if the recipient wishes the change to be not accept.
*/
public String modelChange (PO po, int type) throws Exception
public String modelChange(final PO po, int type) throws Exception
{
log.info(po.get_TableName() + " Type: " + type);
String msg;
// Changes on BPartners
if (po.get_TableName().equals(MBPartner.Table_Name) && type == ModelValidator.TYPE_BEFORE_CHANGE) {
if (po.get_TableName().equals(MBPartner.Table_Name) && type == TYPE_BEFORE_CHANGE)
{
MBPartner bp = (MBPartner) po;
LAR_TaxPayerType taxPayerType = LAR_TaxPayerType.getTaxPayerType(bp);
if (!taxPayerType.equals(LAR_TaxPayerType.CONSUMIDOR_FINAL)) {
@@ -117,10 +127,7 @@ public String modelChange (PO po, int type) throws Exception
}
// Changes on OrderLines
if (po.get_TableName().equals(MOrderLine.Table_Name) &&
(type == ModelValidator.TYPE_AFTER_NEW
|| type == ModelValidator.TYPE_AFTER_DELETE
|| type == ModelValidator.TYPE_AFTER_CHANGE)
)
(type == TYPE_AFTER_NEW || type == TYPE_AFTER_DELETE || type == TYPE_AFTER_CHANGE))
{
MOrderLine ol = (MOrderLine) po;

@@ -132,13 +139,36 @@ public String modelChange (PO po, int type) throws Exception
}
}
// Changes on Order
if (po.get_TableName().equals(MOrder.Table_Name) && type == ModelValidator.TYPE_BEFORE_DELETE) {
if (po.get_TableName().equals(MOrder.Table_Name) && type == TYPE_BEFORE_DELETE)
{
MOrder order = (MOrder) po;
msg = deletePerceptionLine(order);
if (msg != null) {
return msg;
}
}
// Creates withholding on payments
if (po.get_TableName().equals(MPayment.Table_Name)
&& (type == TYPE_AFTER_NEW || type == TYPE_AFTER_CHANGE))
{
MPayment payment = (MPayment) po;
int c_BPartner_ID = payment.getC_BPartner_ID();
MBPartner bp = new MBPartner(payment.getCtx(), c_BPartner_ID, payment.get_TrxName());
msg = calculateWithholdingOnPayment(bp, payment, type);
if (msg != null) {
return msg;
}
}
// Delete withholding related to deleted payment
if (po.get_TableName().equals(MPayment.Table_Name) && type == TYPE_BEFORE_DELETE)
{
MPayment payment = (MPayment) po;
msg = deleteWithholdingOnPayment(payment);
if (msg != null) {
return msg;
}
}

return null;
}

@@ -151,9 +181,31 @@ public String modelChange (PO po, int type) throws Exception
* @param timing see TIMING_ constants
* @return error message or null
*/
public String docValidate (PO po, int timing)
public String docValidate(final PO po, int timing)
{
log.info(po.get_TableName() + " Timing: "+timing);
String msg;

// create withholding certificate on complete payment
if (po.get_TableName().equals(MPayment.Table_Name) && timing == TIMING_AFTER_COMPLETE)
{
MPayment payment = (MPayment) po;
msg = createWithholdingCertificate(payment, timing);
if (msg != null) {
return msg;
}
}
// deactivate the withholding and its certificate when payment is voided
if (po.get_TableName().equals(MPayment.Table_Name)
&& (timing == TIMING_AFTER_VOID || timing == TIMING_AFTER_REVERSECORRECT))
{
MPayment payment = (MPayment) po;
msg = deactivateWithholding(payment, timing);
if (msg != null) {
return msg;
}
}

return null;
} // docValidate

@@ -199,9 +251,8 @@ private String checkIIBBNumber(final MBPartner bp)

private String calculatePerceptionLine(final MBPartner bp, final MOrderLine line, int type)
{
if (type == ModelValidator.TYPE_AFTER_NEW
|| type == ModelValidator.TYPE_AFTER_DELETE
|| (type == ModelValidator.TYPE_AFTER_CHANGE
if (type == TYPE_AFTER_NEW || type == TYPE_AFTER_DELETE
|| (type == TYPE_AFTER_CHANGE
&& (line.is_ValueChanged("LineNetAmt")
|| line.is_ValueChanged("M_Product_ID")
|| line.is_ValueChanged("IsActive")
@@ -211,7 +262,7 @@ private String calculatePerceptionLine(final MBPartner bp, final MOrderLine line
)
{
MOrder order = line.getParent();
final WithholdingConfig wc = new WithholdingConfig(bp);
final WithholdingConfig wc = new WithholdingConfig(bp, PERCEPCION_ID);
log.info("Withholding conf >> " + wc);

// Calculates subtotal and perception amounts
@@ -268,15 +319,142 @@ private String deletePerceptionLine(final MOrder order)
return null;
}

private String deleteWithholdingOnPayment(final MPayment payment)
{
int c_Payment_ID = payment.get_ID();
log.info("Delete withholding for payment " + c_Payment_ID);
String sql = "DELETE FROM LAR_PaymentWithholding WHERE C_Payment_ID=?";
PreparedStatement pstmt = null;
try {
pstmt = DB.prepareStatement(sql, payment.get_TrxName());
pstmt.setInt(1, c_Payment_ID);
pstmt.executeUpdate();
} catch (Exception e) {
log.log(Level.SEVERE, sql, e);
return e.getMessage();
} finally {
DB.close(pstmt);
pstmt = null;
}
return null;
}

private String calculateWithholdingOnPayment(MBPartner bp, MPayment payment, int type)
{
// TODO - improve this way to avoid process reversal payments
if ((type == TYPE_AFTER_NEW && !payment.getDescription().contains("{->"))
|| (type == TYPE_AFTER_CHANGE) && payment.is_ValueChanged("PayAmt"))
{
final WithholdingConfig wc = new WithholdingConfig(bp, RETENCION_ID);
log.info("Withholding conf >> " + wc);

// if payment amt is greater than the limit, create a withholding
if (wc.isCalcFromPayment())
{
if (payment.getPayAmt().compareTo(wc.getPaymentThresholdMin()) >= 0)
{
// create withholding
BigDecimal taxAmt = payment.getPayAmt().multiply(wc.getAliquot())
.setScale(2, BigDecimal.ROUND_HALF_EVEN);

MLARPaymentWithholding pwh = MLARPaymentWithholding.get(payment);
pwh.setC_Payment_ID(payment.get_ID());
pwh.setC_Invoice_ID(payment.getC_Invoice_ID());
pwh.setLCO_WithholdingRule_ID(wc.getWithholdingRule_ID());
pwh.setLCO_WithholdingType_ID(wc.getWithholdingType_ID());
pwh.setDateAcct(payment.getDateAcct());
pwh.setDateTrx(payment.getDateTrx());
pwh.setPercent(wc.getAliquot());
pwh.setProcessed(false);
pwh.setTaxAmt(taxAmt);
pwh.setTaxBaseAmt(payment.getPayAmt());
if (!pwh.save()) {
return "Can not create withholding on payment";
}

// update payment amounts (with sql in order to avoid circular events)
// TODO - Review WriteOffAmt for withholding on invoices (IVA)
String sql = "UPDATE C_Payment"
+ " SET WriteOffAmt=?"
+ " , WithholdingAmt=?"
+ " , WithholdingPercent=?"
+ " WHERE C_Payment_ID=?";

PreparedStatement pstmt = null;
try {
pstmt = DB.prepareStatement(sql, payment.get_TrxName());
pstmt.setBigDecimal(1, taxAmt);
pstmt.setBigDecimal(2, taxAmt);
pstmt.setBigDecimal(3, wc.getAliquot());
pstmt.setInt(4, payment.get_ID());
pstmt.executeUpdate();
} catch (Exception e) {
log.log(Level.SEVERE, sql, e);
return e.getMessage();
} finally {
DB.close(pstmt);
pstmt = null;
}
} else {
// if exists a withholding, deleted
deleteWithholdingOnPayment(payment);
}
}
}
return null;
}

private String createWithholdingCertificate(final MPayment payment, int timing)
{
// TODO - improve this way to avoid process reversal payments
if (timing == TIMING_AFTER_COMPLETE && !payment.getDescription().contains("{->"))
{
log.info("Payment: " + payment.get_ID());

X_LAR_WithholdingCertificate whc = new X_LAR_WithholdingCertificate(payment.getCtx(),
0, payment.get_TrxName());
whc.setC_DocType_ID(payment.getC_DocType_ID());
whc.setC_Payment_ID(payment.get_ID());
whc.setC_Invoice_ID(payment.getC_Invoice_ID());
whc.setC_DocTypeTarget_ID(payment.getC_DocType_ID());
whc.setDocumentNo(payment.getDocumentNo());
if (!whc.save()) {
return "Can not create a withholding certificate";
}
}
return null;
}

private String deactivateWithholding(final MPayment payment, int timing)
{
// TODO - improve this way to avoid process reversal payments
if (timing == TIMING_AFTER_COMPLETE && !payment.getDescription().contains("{->"))
{
MLARPaymentWithholding pwh = MLARPaymentWithholding.get(payment);
pwh.setIsActive(false);
if (!pwh.save()) {
return "Can not deactivate payment withholding";
}
MLARWithholdingCertificate whc = MLARWithholdingCertificate.get(payment);
whc.setIsActive(false);
if (!whc.save()) {
return "Can not deactivate payment withholding";
}
}
return null;
}

/**
* Encapsulates configuration parameters for withholdings
*/
// TODO - Allow retrive individual configuration, depending withholding type
// and using config values defined into lco tables (see LCO_Validator)
private class WithholdingConfig
{
// TODO - try to avoid this hardcode value
private final int C_TAXCATEGORY_ID = 1000002; // Perception Tax Category

private int c_TaxCategory_ID;
private boolean isCalcFromPayment;
private BigDecimal aliquot = BigDecimal.ZERO;
private BigDecimal paymentThresholdMin = BigDecimal.ZERO;
private int lco_WithholdingRule_ID;
private int lco_WithholdingType_ID;
private int c_Tax_ID;
@@ -286,6 +464,8 @@ private String deletePerceptionLine(final MOrder order)
+ " , r.lco_withholdingrule_id "
+ " , c.lco_withholdingtype_id"
+ " , x.c_tax_id "
+ " , c.iscalcfrompayment"
+ " , c.paymentthresholdmin"
+ " FROM C_BPartner bp "
+ " JOIN LCO_WithholdingRule r ON r.lco_bp_isic_id = bp.lco_isic_id "
+ " AND r.lco_bp_taxpayertype_id = bp.lco_taxpayertype_id"
@@ -294,8 +474,9 @@ private String deletePerceptionLine(final MOrder order)
+ " AND x.c_taxcategory_id = ?";


private WithholdingConfig(final MBPartner bp)
private WithholdingConfig(final MBPartner bp, int c_TaxCategory_ID)
{
this.c_TaxCategory_ID = c_TaxCategory_ID;
retrieveConfig(bp);
}

@@ -316,7 +497,18 @@ private int getTax_ID()

private BigDecimal getAliquot()
{
return aliquot;
// TODO - Review the way to calculate aliquot
return c_TaxCategory_ID == PERCEPCION_ID ? aliquot.negate() : aliquot;
}

private BigDecimal getPaymentThresholdMin()
{
return paymentThresholdMin;
}

private boolean isCalcFromPayment()
{
return isCalcFromPayment;
}

/**
@@ -331,13 +523,17 @@ private void retrieveConfig(final MBPartner bp)
try {
pstmt = DB.prepareStatement(sql, bp.get_TrxName());
pstmt.setInt(1, bp.getC_BPartner_ID());
pstmt.setInt(2, C_TAXCATEGORY_ID);
pstmt.setInt(2, c_TaxCategory_ID);
rs = pstmt.executeQuery();
if (rs.next()) {
aliquot = rs.getBigDecimal(1).negate();
aliquot = rs.getBigDecimal(1).setScale(4, BigDecimal.ROUND_HALF_EVEN);
lco_WithholdingRule_ID = rs.getInt(2);
lco_WithholdingType_ID = rs.getInt(3);
c_Tax_ID = rs.getInt(4);
isCalcFromPayment = rs.getString(5).equals("Y");
paymentThresholdMin = rs.getBigDecimal(6);
} else {
throw new AdempiereException("Withholding configuration not found");
}
} catch (Exception e) {
log.log(Level.SEVERE, sql, e);
@@ -0,0 +1,96 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2007 ComPiere, Inc. 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. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package ar.com.ergio.model;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;
import java.util.logging.Level;

import org.compiere.model.MPayment;
import org.compiere.util.CLogger;
import org.compiere.util.DB;

/**
* Payment Withholding Model
*
* @author Emiliano Pereyra - http://www.ergio.com.ar
*
*/
public class MLARPaymentWithholding extends X_LAR_PaymentWithholding
{
private static final long serialVersionUID = 2402696932419765632L;

/** Logger */
private static CLogger log = CLogger.getCLogger(MLARPaymentWithholding.class);

public MLARPaymentWithholding(Properties ctx, int LAR_PaymentWithholding_ID, String trxName)
{
super(ctx, LAR_PaymentWithholding_ID, trxName);
// TODO Auto-generated constructor stub
}

public MLARPaymentWithholding(Properties ctx, ResultSet rs, String trxName)
{
super(ctx, rs, trxName);
}

/**
*
* @param order
* @param trxName
* @return
*/
public static MLARPaymentWithholding get(final MPayment payment)
{
MLARPaymentWithholding retValue = null;
if (payment == null || payment.getC_Payment_ID() == 0) {
log.info("No Payment");
return null;
}

String sql = "SELECT * FROM LAR_PaymentWithholding WHERE C_Payment_ID=?";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, payment.get_TrxName());
pstmt.setInt(1, payment.getC_Payment_ID());
rs = pstmt.executeQuery();
if (rs.next())
retValue = new MLARPaymentWithholding(payment.getCtx(), rs, payment.get_TrxName());
rs.close();
pstmt.close();
pstmt = null;
} catch (Exception e) {
log.log(Level.SEVERE, "No withholding for payment", e);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}

if (retValue != null) {
retValue.set_TrxName(payment.get_TrxName());
return retValue;
}

// Create new one
retValue = new MLARPaymentWithholding(payment.getCtx(), 0, payment.get_TrxName());
log.info("(new)" + retValue);
return retValue;
} // get
}
@@ -0,0 +1,96 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2007 ComPiere, Inc. 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. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package ar.com.ergio.model;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;
import java.util.logging.Level;

import org.compiere.model.MPayment;
import org.compiere.util.CLogger;
import org.compiere.util.DB;

/**
* Withholding Certificate Model
*
* @author Emiliano Pereyra - http://www.ergio.com.ar
*
*/
public class MLARWithholdingCertificate extends X_LAR_WithholdingCertificate
{

private static final long serialVersionUID = 1400526751267970390L;
/** Logger */
private static CLogger log = CLogger.getCLogger(MLARWithholdingCertificate.class);

public MLARWithholdingCertificate(Properties ctx, int LAR_WithholdingCertificate_ID, String trxName)
{
super(ctx, LAR_WithholdingCertificate_ID, trxName);
// TODO Auto-generated constructor stub
}

public MLARWithholdingCertificate(Properties ctx, ResultSet rs, String trxName)
{
super(ctx, rs, trxName);
}

/**
*
* @param order
* @param trxName
* @return
*/
public static MLARWithholdingCertificate get(final MPayment payment)
{
MLARWithholdingCertificate retValue = null;
if (payment == null || payment.getC_Payment_ID() == 0) {
log.info("No Payment");
return null;
}

String sql = "SELECT * FROM LAR_WithholdingCertificate WHERE C_Payment_ID=?";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, payment.get_TrxName());
pstmt.setInt(1, payment.getC_Payment_ID());
rs = pstmt.executeQuery();
if (rs.next())
retValue = new MLARWithholdingCertificate(payment.getCtx(), rs, payment.get_TrxName());
rs.close();
pstmt.close();
pstmt = null;
} catch (Exception e) {
log.log(Level.SEVERE, "No withholding for payment", e);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}

if (retValue != null) {
retValue.set_TrxName(payment.get_TrxName());
return retValue;
}

// Create new one
retValue = new MLARWithholdingCertificate(payment.getCtx(), 0, payment.get_TrxName());
log.info("(new)" + retValue);
return retValue;
} // get
}
@@ -0,0 +1,343 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2007 ComPiere, Inc. 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. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
/** Generated Model - DO NOT CHANGE */
package ar.com.ergio.model;

import java.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.util.Properties;
import org.compiere.model.*;
import org.compiere.util.Env;

/** Generated Model for LAR_PaymentWithholding
* @author Adempiere (generated)
* @version 3.6.0LTS+P20110709 - $Id$ */
public class X_LAR_PaymentWithholding extends PO implements I_LAR_PaymentWithholding, I_Persistent
{

/**
*
*/
private static final long serialVersionUID = 20120127L;

/** Standard Constructor */
public X_LAR_PaymentWithholding (Properties ctx, int LAR_PaymentWithholding_ID, String trxName)
{
super (ctx, LAR_PaymentWithholding_ID, trxName);
/** if (LAR_PaymentWithholding_ID == 0)
{
setC_Invoice_ID (0);
setC_Payment_ID (0);
setLAR_PaymentWithholding_ID (0);
setLCO_WithholdingType_ID (0);
setProcessed (false);
setTaxAmt (Env.ZERO);
setTaxBaseAmt (Env.ZERO);
} */
}

/** Load Constructor */
public X_LAR_PaymentWithholding (Properties ctx, ResultSet rs, String trxName)
{
super (ctx, rs, trxName);
}

/** AccessLevel
* @return 7 - System - Client - Org
*/
protected int get_AccessLevel()
{
return accessLevel.intValue();
}

/** Load Meta Data */
protected POInfo initPO (Properties ctx)
{
POInfo poi = POInfo.getPOInfo (ctx, Table_ID, get_TrxName());
return poi;
}

public String toString()
{
StringBuffer sb = new StringBuffer ("X_LAR_PaymentWithholding[")
.append(get_ID()).append("]");
return sb.toString();
}

public I_C_Invoice getC_Invoice() throws RuntimeException
{
return (I_C_Invoice)MTable.get(getCtx(), I_C_Invoice.Table_Name)
.getPO(getC_Invoice_ID(), get_TrxName()); }

/** Set Invoice.
@param C_Invoice_ID
Invoice Identifier
*/
public void setC_Invoice_ID (int C_Invoice_ID)
{
if (C_Invoice_ID < 1)
set_Value (COLUMNNAME_C_Invoice_ID, null);
else
set_Value (COLUMNNAME_C_Invoice_ID, Integer.valueOf(C_Invoice_ID));
}

/** Get Invoice.
@return Invoice Identifier
*/
public int getC_Invoice_ID ()
{
Integer ii = (Integer)get_Value(COLUMNNAME_C_Invoice_ID);
if (ii == null)
return 0;
return ii.intValue();
}

public I_C_Payment getC_Payment() throws RuntimeException
{
return (I_C_Payment)MTable.get(getCtx(), I_C_Payment.Table_Name)
.getPO(getC_Payment_ID(), get_TrxName()); }

/** Set Payment.
@param C_Payment_ID
Payment identifier
*/
public void setC_Payment_ID (int C_Payment_ID)
{
if (C_Payment_ID < 1)
set_Value (COLUMNNAME_C_Payment_ID, null);
else
set_Value (COLUMNNAME_C_Payment_ID, Integer.valueOf(C_Payment_ID));
}

/** Get Payment.
@return Payment identifier
*/
public int getC_Payment_ID ()
{
Integer ii = (Integer)get_Value(COLUMNNAME_C_Payment_ID);
if (ii == null)
return 0;
return ii.intValue();
}

public I_C_Tax getC_Tax() throws RuntimeException
{
return (I_C_Tax)MTable.get(getCtx(), I_C_Tax.Table_Name)
.getPO(getC_Tax_ID(), get_TrxName()); }

/** Set Tax.
@param C_Tax_ID
Tax identifier
*/
public void setC_Tax_ID (int C_Tax_ID)
{
if (C_Tax_ID < 1)
set_Value (COLUMNNAME_C_Tax_ID, null);
else
set_Value (COLUMNNAME_C_Tax_ID, Integer.valueOf(C_Tax_ID));
}

/** Get Tax.
@return Tax identifier
*/
public int getC_Tax_ID ()
{
Integer ii = (Integer)get_Value(COLUMNNAME_C_Tax_ID);
if (ii == null)
return 0;
return ii.intValue();
}

/** Set Account Date.
@param DateAcct
Accounting Date
*/
public void setDateAcct (Timestamp DateAcct)
{
set_Value (COLUMNNAME_DateAcct, DateAcct);
}

/** Get Account Date.
@return Accounting Date
*/
public Timestamp getDateAcct ()
{
return (Timestamp)get_Value(COLUMNNAME_DateAcct);
}

/** Set Transaction Date.
@param DateTrx
Transaction Date
*/
public void setDateTrx (Timestamp DateTrx)
{
set_Value (COLUMNNAME_DateTrx, DateTrx);
}

/** Get Transaction Date.
@return Transaction Date
*/
public Timestamp getDateTrx ()
{
return (Timestamp)get_Value(COLUMNNAME_DateTrx);
}

/** Set LAR_PaymentWithholding.
@param LAR_PaymentWithholding_ID LAR_PaymentWithholding */
public void setLAR_PaymentWithholding_ID (int LAR_PaymentWithholding_ID)
{
if (LAR_PaymentWithholding_ID < 1)
set_ValueNoCheck (COLUMNNAME_LAR_PaymentWithholding_ID, null);
else
set_ValueNoCheck (COLUMNNAME_LAR_PaymentWithholding_ID, Integer.valueOf(LAR_PaymentWithholding_ID));
}

/** Get LAR_PaymentWithholding.
@return LAR_PaymentWithholding */
public int getLAR_PaymentWithholding_ID ()
{
Integer ii = (Integer)get_Value(COLUMNNAME_LAR_PaymentWithholding_ID);
if (ii == null)
return 0;
return ii.intValue();
}

/** Set Withholding Rule.
@param LCO_WithholdingRule_ID Withholding Rule */
public void setLCO_WithholdingRule_ID (int LCO_WithholdingRule_ID)
{
if (LCO_WithholdingRule_ID < 1)
set_Value (COLUMNNAME_LCO_WithholdingRule_ID, null);
else
set_Value (COLUMNNAME_LCO_WithholdingRule_ID, Integer.valueOf(LCO_WithholdingRule_ID));
}

/** Get Withholding Rule.
@return Withholding Rule */
public int getLCO_WithholdingRule_ID ()
{
Integer ii = (Integer)get_Value(COLUMNNAME_LCO_WithholdingRule_ID);
if (ii == null)
return 0;
return ii.intValue();
}

/** Set Withholding Type.
@param LCO_WithholdingType_ID Withholding Type */
public void setLCO_WithholdingType_ID (int LCO_WithholdingType_ID)
{
if (LCO_WithholdingType_ID < 1)
set_Value (COLUMNNAME_LCO_WithholdingType_ID, null);
else
set_Value (COLUMNNAME_LCO_WithholdingType_ID, Integer.valueOf(LCO_WithholdingType_ID));
}

/** Get Withholding Type.
@return Withholding Type */
public int getLCO_WithholdingType_ID ()
{
Integer ii = (Integer)get_Value(COLUMNNAME_LCO_WithholdingType_ID);
if (ii == null)
return 0;
return ii.intValue();
}

/** Set Percent.
@param Percent
Percentage
*/
public void setPercent (BigDecimal Percent)
{
set_Value (COLUMNNAME_Percent, Percent);
}

/** Get Percent.
@return Percentage
*/
public BigDecimal getPercent ()
{
BigDecimal bd = (BigDecimal)get_Value(COLUMNNAME_Percent);
if (bd == null)
return Env.ZERO;
return bd;
}

/** Set Processed.
@param Processed
The document has been processed
*/
public void setProcessed (boolean Processed)
{
set_Value (COLUMNNAME_Processed, Boolean.valueOf(Processed));
}

/** Get Processed.
@return The document has been processed
*/
public boolean isProcessed ()
{
Object oo = get_Value(COLUMNNAME_Processed);
if (oo != null)
{
if (oo instanceof Boolean)
return ((Boolean)oo).booleanValue();
return "Y".equals(oo);
}
return false;
}

/** Set Tax Amount.
@param TaxAmt
Tax Amount for a document
*/
public void setTaxAmt (BigDecimal TaxAmt)
{
set_Value (COLUMNNAME_TaxAmt, TaxAmt);
}

/** Get Tax Amount.
@return Tax Amount for a document
*/
public BigDecimal getTaxAmt ()
{
BigDecimal bd = (BigDecimal)get_Value(COLUMNNAME_TaxAmt);
if (bd == null)
return Env.ZERO;
return bd;
}

/** Set Tax base Amount.
@param TaxBaseAmt
Base for calculating the tax amount
*/
public void setTaxBaseAmt (BigDecimal TaxBaseAmt)
{
set_Value (COLUMNNAME_TaxBaseAmt, TaxBaseAmt);
}

/** Get Tax base Amount.
@return Base for calculating the tax amount
*/
public BigDecimal getTaxBaseAmt ()
{
BigDecimal bd = (BigDecimal)get_Value(COLUMNNAME_TaxBaseAmt);
if (bd == null)
return Env.ZERO;
return bd;
}
}
@@ -0,0 +1,372 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2007 ComPiere, Inc. 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. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
/** Generated Model - DO NOT CHANGE */
package ar.com.ergio.model;

import java.math.BigDecimal;
import java.sql.ResultSet;
import java.util.Properties;
import org.compiere.model.*;
import org.compiere.util.Env;

/** Generated Model for LAR_WithholdingCertificate
* @author Adempiere (generated)
* @version 3.6.0LTS+P20110709 - $Id$ */
public class X_LAR_WithholdingCertificate extends PO implements I_LAR_WithholdingCertificate, I_Persistent
{

/**
*
*/
private static final long serialVersionUID = 20120130L;

/** Standard Constructor */
public X_LAR_WithholdingCertificate (Properties ctx, int LAR_WithholdingCertificate_ID, String trxName)
{
super (ctx, LAR_WithholdingCertificate_ID, trxName);
/** if (LAR_WithholdingCertificate_ID == 0)
{
setC_DocType_ID (0);
// 0
setC_DocTypeTarget_ID (0);
setC_Invoice_ID (0);
// 0
setC_Payment_ID (0);
setDocumentNo (null);
setLAR_WithholdingCertificate_ID (0);
} */
}

/** Load Constructor */
public X_LAR_WithholdingCertificate (Properties ctx, ResultSet rs, String trxName)
{
super (ctx, rs, trxName);
}

/** AccessLevel
* @return 7 - System - Client - Org
*/
protected int get_AccessLevel()
{
return accessLevel.intValue();
}

/** Load Meta Data */
protected POInfo initPO (Properties ctx)
{
POInfo poi = POInfo.getPOInfo (ctx, Table_ID, get_TrxName());
return poi;
}

public String toString()
{
StringBuffer sb = new StringBuffer ("X_LAR_WithholdingCertificate[")
.append(get_ID()).append("]");
return sb.toString();
}

/** Set Address 1.
@param Address1
Address line 1 for this location
*/
public void setAddress1 (String Address1)
{
throw new IllegalArgumentException ("Address1 is virtual column"); }

/** Get Address 1.
@return Address line 1 for this location
*/
public String getAddress1 ()
{
return (String)get_Value(COLUMNNAME_Address1);
}

/** Set BP Name.
@param BPName BP Name */
public void setBPName (String BPName)
{
throw new IllegalArgumentException ("BPName is virtual column"); }

/** Get BP Name.
@return BP Name */
public String getBPName ()
{
return (String)get_Value(COLUMNNAME_BPName);
}

public I_C_DocType getC_DocType() throws RuntimeException
{
return (I_C_DocType)MTable.get(getCtx(), I_C_DocType.Table_Name)
.getPO(getC_DocType_ID(), get_TrxName()); }

/** Set Document Type.
@param C_DocType_ID
Document type or rules
*/
public void setC_DocType_ID (int C_DocType_ID)
{
if (C_DocType_ID < 0)
set_Value (COLUMNNAME_C_DocType_ID, null);
else
set_Value (COLUMNNAME_C_DocType_ID, Integer.valueOf(C_DocType_ID));
}

/** Get Document Type.
@return Document type or rules
*/
public int getC_DocType_ID ()
{
Integer ii = (Integer)get_Value(COLUMNNAME_C_DocType_ID);
if (ii == null)
return 0;
return ii.intValue();
}

/** Set Target Document Type.
@param C_DocTypeTarget_ID
Target document type for conversing documents
*/
public void setC_DocTypeTarget_ID (int C_DocTypeTarget_ID)
{
if (C_DocTypeTarget_ID < 1)
set_Value (COLUMNNAME_C_DocTypeTarget_ID, null);
else
set_Value (COLUMNNAME_C_DocTypeTarget_ID, Integer.valueOf(C_DocTypeTarget_ID));
}

/** Get Target Document Type.
@return Target document type for conversing documents
*/
public int getC_DocTypeTarget_ID ()
{
Integer ii = (Integer)get_Value(COLUMNNAME_C_DocTypeTarget_ID);
if (ii == null)
return 0;
return ii.intValue();
}

public I_C_Invoice getC_Invoice() throws RuntimeException
{
return (I_C_Invoice)MTable.get(getCtx(), I_C_Invoice.Table_Name)
.getPO(getC_Invoice_ID(), get_TrxName()); }

/** Set Invoice.
@param C_Invoice_ID
Invoice Identifier
*/
public void setC_Invoice_ID (int C_Invoice_ID)
{
if (C_Invoice_ID < 1)
set_Value (COLUMNNAME_C_Invoice_ID, null);
else
set_Value (COLUMNNAME_C_Invoice_ID, Integer.valueOf(C_Invoice_ID));
}

/** Get Invoice.
@return Invoice Identifier
*/
public int getC_Invoice_ID ()
{
Integer ii = (Integer)get_Value(COLUMNNAME_C_Invoice_ID);
if (ii == null)
return 0;
return ii.intValue();
}

/** Set City.
@param City
Identifies a City
*/
public void setCity (String City)
{
throw new IllegalArgumentException ("City is virtual column"); }

/** Get City.
@return Identifies a City
*/
public String getCity ()
{
return (String)get_Value(COLUMNNAME_City);
}

public I_C_Payment getC_Payment() throws RuntimeException
{
return (I_C_Payment)MTable.get(getCtx(), I_C_Payment.Table_Name)
.getPO(getC_Payment_ID(), get_TrxName()); }

/** Set Payment.
@param C_Payment_ID
Payment identifier
*/
public void setC_Payment_ID (int C_Payment_ID)
{
if (C_Payment_ID < 1)
set_Value (COLUMNNAME_C_Payment_ID, null);
else
set_Value (COLUMNNAME_C_Payment_ID, Integer.valueOf(C_Payment_ID));
}

/** Get Payment.
@return Payment identifier
*/
public int getC_Payment_ID ()
{
Integer ii = (Integer)get_Value(COLUMNNAME_C_Payment_ID);
if (ii == null)
return 0;
return ii.intValue();
}

/** Set Document No.
@param DocumentNo
Document sequence number of the document
*/
public void setDocumentNo (String DocumentNo)
{
set_Value (COLUMNNAME_DocumentNo, DocumentNo);
}

/** Get Document No.
@return Document sequence number of the document
*/
public String getDocumentNo ()
{
return (String)get_Value(COLUMNNAME_DocumentNo);
}

/** Set LAR_WithholdingCertificate.
@param LAR_WithholdingCertificate_ID LAR_WithholdingCertificate */
public void setLAR_WithholdingCertificate_ID (int LAR_WithholdingCertificate_ID)
{
if (LAR_WithholdingCertificate_ID < 1)
set_ValueNoCheck (COLUMNNAME_LAR_WithholdingCertificate_ID, null);
else
set_ValueNoCheck (COLUMNNAME_LAR_WithholdingCertificate_ID, Integer.valueOf(LAR_WithholdingCertificate_ID));
}

/** Get LAR_WithholdingCertificate.
@return LAR_WithholdingCertificate */
public int getLAR_WithholdingCertificate_ID ()
{
Integer ii = (Integer)get_Value(COLUMNNAME_LAR_WithholdingCertificate_ID);
if (ii == null)
return 0;
return ii.intValue();
}

/** Set NAICS/SIC.
@param NAICS
Standard Industry Code or its successor NAIC - http://www.osha.gov/oshstats/sicser.html
*/
public void setNAICS (String NAICS)
{
throw new IllegalArgumentException ("NAICS is virtual column"); }

/** Get NAICS/SIC.
@return Standard Industry Code or its successor NAIC - http://www.osha.gov/oshstats/sicser.html
*/
public String getNAICS ()
{
return (String)get_Value(COLUMNNAME_NAICS);
}

/** Set Percent.
@param Percent
Percentage
*/
public void setPercent (BigDecimal Percent)
{
throw new IllegalArgumentException ("Percent is virtual column"); }

/** Get Percent.
@return Percentage
*/
public BigDecimal getPercent ()
{
BigDecimal bd = (BigDecimal)get_Value(COLUMNNAME_Percent);
if (bd == null)
return Env.ZERO;
return bd;
}

/** Set ZIP.
@param Postal
Postal code
*/
public void setPostal (String Postal)
{
throw new IllegalArgumentException ("Postal is virtual column"); }

/** Get ZIP.
@return Postal code
*/
public String getPostal ()
{
return (String)get_Value(COLUMNNAME_Postal);
}

/** Set Region.
@param RegionName
Name of the Region
*/
public void setRegionName (String RegionName)
{
throw new IllegalArgumentException ("RegionName is virtual column"); }

/** Get Region.
@return Name of the Region
*/
public String getRegionName ()
{
return (String)get_Value(COLUMNNAME_RegionName);
}

/** Set Tax Amount.
@param TaxAmt
Tax Amount for a document
*/
public void setTaxAmt (BigDecimal TaxAmt)
{
throw new IllegalArgumentException ("TaxAmt is virtual column"); }

/** Get Tax Amount.
@return Tax Amount for a document
*/
public BigDecimal getTaxAmt ()
{
BigDecimal bd = (BigDecimal)get_Value(COLUMNNAME_TaxAmt);
if (bd == null)
return Env.ZERO;
return bd;
}

/** Set Tax ID.
@param TaxID
Tax Identification
*/
public void setTaxID (String TaxID)
{
throw new IllegalArgumentException ("TaxID is virtual column"); }

/** Get Tax ID.
@return Tax Identification
*/
public String getTaxID ()
{
return (String)get_Value(COLUMNNAME_TaxID);
}
}
@@ -0,0 +1,71 @@

CREATE TABLE lar_paymentwithholding (
ad_client_id numeric(10,0) NOT NULL,
ad_org_id numeric(10,0) NOT NULL,
created timestamp NOT NULL,
createdby numeric(10,0) NOT NULL,
updated timestamp NOT NULL,
updatedby numeric(10,0) NOT NULL,
isactive char(1) NOT NULL DEFAULT 'Y'::bpchar,
lar_paymentwithholding_id numeric(10,0) NOT NULL,
c_invoice_id numeric(10,0) NOT NULL,
c_payment_id numeric(10,0) NOT NULL,
c_tax_id numeric(10,0) NULL DEFAULT NULL::numeric,
dateacct timestamp NULL,
datetrx timestamp NULL,
lco_withholdingrule_id numeric(10,0) NULL DEFAULT NULL::numeric,
lco_withholdingtype_id numeric(10,0) NOT NULL,
percent numeric NULL,
processed char(1) NOT NULL DEFAULT 'N'::bpchar,
taxamt numeric NOT NULL,
taxbaseamt numeric NOT NULL,
PRIMARY KEY(lar_paymentwithholding_id)
);

ALTER TABLE adempiere.lar_paymentwithholding
ADD CONSTRAINT lar_paymentwithholding_processed_check
CHECK (processed = ANY (ARRAY['Y'::bpchar, 'N'::bpchar]));

ALTER TABLE adempiere.lar_paymentwithholding
ADD CONSTRAINT lar_paymentwithholding_isactive_check
CHECK (isactive = ANY (ARRAY['Y'::bpchar, 'N'::bpchar]));

ALTER TABLE adempiere.lar_paymentwithholding
ADD CONSTRAINT lcowithholdingtype_larpaymentw
FOREIGN KEY(lco_withholdingtype_id)
REFERENCES adempiere.lco_withholdingtype(lco_withholdingtype_id)
MATCH SIMPLE
ON DELETE NO ACTION
ON UPDATE NO ACTION;

ALTER TABLE adempiere.lar_paymentwithholding
ADD CONSTRAINT lcowithholdingrule_larpaymentw
FOREIGN KEY(lco_withholdingrule_id)
REFERENCES adempiere.lco_withholdingrule(lco_withholdingrule_id)
MATCH SIMPLE
ON DELETE NO ACTION
ON UPDATE NO ACTION;

ALTER TABLE adempiere.lar_paymentwithholding
ADD CONSTRAINT ctax_larpaymentwithholding
FOREIGN KEY(c_tax_id)
REFERENCES adempiere.c_tax(c_tax_id)
MATCH SIMPLE
ON DELETE NO ACTION
ON UPDATE NO ACTION;

ALTER TABLE adempiere.lar_paymentwithholding
ADD CONSTRAINT cinvoice_larpaymentwithholding
FOREIGN KEY(c_invoice_id)
REFERENCES adempiere.c_invoice(c_invoice_id)
MATCH SIMPLE
ON DELETE NO ACTION
ON UPDATE NO ACTION;

ALTER TABLE adempiere.lar_paymentwithholding
ADD CONSTRAINT cpayment_larpaymentwithholding
FOREIGN KEY(c_payment_id)
REFERENCES adempiere.c_payment(c_payment_id)
MATCH SIMPLE
ON DELETE NO ACTION
ON UPDATE NO ACTION;
@@ -0,0 +1,2 @@
ALTER TABLE c_payment ADD COLUMN withholdingamt NUMERIC;
ALTER TABLE c_payment ADD COLUMN withholdingpercent NUMERIC;
@@ -0,0 +1,2 @@
ALTER TABLE lco_withholdingcalc ADD COLUMN paymentthresholdmin NUMERIC;
ALTER TABLE lco_withholdingcalc ADD COLUMN iscalcfrompayment CHARACTER(1) NOT NULL DEFAULT 'N';
@@ -0,0 +1,52 @@
CREATE TABLE adempiere.lar_withholdingcertificate (
ad_client_id numeric(10,0) NOT NULL,
ad_org_id numeric(10,0) NOT NULL,
created timestamp NOT NULL,
createdby numeric(10,0) NULL,
updated timestamp NOT NULL,
updatedby numeric(10,0) NOT NULL,
isactive char(1) NOT NULL,
lar_withholdingcertificate_id numeric(10,0) NOT NULL,
documentno varchar(30) NOT NULL,
c_invoice_id numeric(10,0) NOT NULL,
c_payment_id numeric(10,0) NOT NULL,
c_doctype_id numeric(10,0) NULL,
c_doctypetarget_id numeric(10,0) NULL,
PRIMARY KEY(lar_withholdingcertificate_id)
);

ALTER TABLE adempiere.lar_withholdingcertificate
ADD CONSTRAINT lar_withholdingcertificate_isactive_check
CHECK (isactive = ANY (ARRAY['Y'::bpchar, 'N'::bpchar]));

ALTER TABLE adempiere.lar_withholdingcertificate
ADD CONSTRAINT cpayment_larwithholdingcertificate
FOREIGN KEY(c_payment_id)
REFERENCES adempiere.c_payment(c_payment_id)
MATCH SIMPLE
ON DELETE NO ACTION
ON UPDATE NO ACTION;

ALTER TABLE adempiere.lar_withholdingcertificate
ADD CONSTRAINT cinvoice_larwithholdingcertificate
FOREIGN KEY(c_invoice_id)
REFERENCES adempiere.c_invoice(c_invoice_id)
MATCH SIMPLE
ON DELETE NO ACTION
ON UPDATE NO ACTION;

ALTER TABLE adempiere.lar_withholdingcertificate
ADD CONSTRAINT cdoctype_larwithholdingcertificate
FOREIGN KEY(c_doctype_id)
REFERENCES adempiere.c_doctype(c_doctype_id)
MATCH SIMPLE
ON DELETE NO ACTION
ON UPDATE NO ACTION;

ALTER TABLE adempiere.lar_withholdingcertificate
ADD CONSTRAINT cdoctypetarget_larwithholdingcertificate
FOREIGN KEY(c_doctypetarget_id)
REFERENCES adempiere.c_doctype(c_doctype_id)
MATCH SIMPLE
ON DELETE NO ACTION
ON UPDATE NO ACTION;