Requisition Tax and Create From Requisition
--HG-- branch : DEV-MMU
This commit is contained in:
parent
18708c5aa7
commit
9edbdc9bff
|
|
@ -361,7 +361,7 @@ public class MID_CreateFromOrder extends CreateFrom {
|
||||||
qtyOrdered = Env.ZERO;
|
qtyOrdered = Env.ZERO;
|
||||||
}
|
}
|
||||||
|
|
||||||
BigDecimal Qty = reqLine.getQty();
|
BigDecimal Qty = qty;
|
||||||
boolean IsSOTrx = order.isSOTrx();
|
boolean IsSOTrx = order.isSOTrx();
|
||||||
MProductPricing pricing = new MProductPricing (reqLine.getM_Product_ID(), order.getC_BPartner_ID(), Qty, IsSOTrx);
|
MProductPricing pricing = new MProductPricing (reqLine.getM_Product_ID(), order.getC_BPartner_ID(), Qty, IsSOTrx);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ public class MID_MRequisition extends MRequisition implements DocOptions{
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 3588447351218719946L;
|
private static final long serialVersionUID = 3588447351218719946L;
|
||||||
|
|
||||||
public MID_MRequisition(Properties ctx, int M_Requisition_ID, String trxName) {
|
public MID_MRequisition(Properties ctx, int M_Requisition_ID, String trxName) {
|
||||||
super(ctx, M_Requisition_ID, trxName);
|
super(ctx, M_Requisition_ID, trxName);
|
||||||
// TODO Auto-generated constructor stub
|
// TODO Auto-generated constructor stub
|
||||||
|
|
@ -33,8 +34,12 @@ public class MID_MRequisition extends MRequisition implements DocOptions{
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean recalculateTax(String trxName) {
|
public boolean recalculateTax(String trxName) {
|
||||||
BigDecimal totalTaxAmt = DB.getSQLValueBD(get_TrxName(), "SELECT COALESCE(SUM(TaxAmt),0) FROM M_RequisitionLine WHERE M_Requisition_ID =?", new Object[] { getM_Requisition_ID() });
|
BigDecimal totalTaxAmt = DB.getSQLValueBD(get_TrxName(),
|
||||||
BigDecimal totalLines = DB.getSQLValueBD(get_TrxName(), "SELECT COALESCE(SUM(LineNetAmt),0) FROM M_RequisitionLine WHERE M_Requisition_ID =?", new Object[] { getM_Requisition_ID() });
|
"SELECT COALESCE(SUM(TaxAmt),0) FROM M_RequisitionLine WHERE M_Requisition_ID =?",
|
||||||
|
new Object[] { getM_Requisition_ID() });
|
||||||
|
BigDecimal totalLines = DB.getSQLValueBD(get_TrxName(),
|
||||||
|
"SELECT COALESCE(SUM(LineNetAmt),0) FROM M_RequisitionLine WHERE M_Requisition_ID =?",
|
||||||
|
new Object[] { getM_Requisition_ID() });
|
||||||
setTotalLines(totalLines);
|
setTotalLines(totalLines);
|
||||||
set_Value("TaxAmt", totalTaxAmt);
|
set_Value("TaxAmt", totalTaxAmt);
|
||||||
set_Value("GrandTotal", totalLines.add(totalTaxAmt));
|
set_Value("GrandTotal", totalLines.add(totalTaxAmt));
|
||||||
|
|
@ -49,13 +54,12 @@ public class MID_MRequisition extends MRequisition implements DocOptions{
|
||||||
setProcessed(false);
|
setProcessed(false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String prepareIt() {
|
public String prepareIt() {
|
||||||
DB.executeUpdateEx("DELETE M_RequisitionTax WHERE M_RequisitioN_ID=" + getM_Requisition_ID(), get_TrxName());
|
DB.executeUpdateEx("DELETE M_RequisitionTax WHERE M_RequisitioN_ID=" + getM_Requisition_ID(), get_TrxName());
|
||||||
if (!calculateOrderTaxTotal(this))
|
if (!calculateOrderTaxTotal(this))
|
||||||
throw new AdempiereException("Failed in the end");
|
throw new AdempiereException("Failed in the end");
|
||||||
|
|
||||||
log.severe("TEST");
|
|
||||||
return super.prepareIt();
|
return super.prepareIt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -64,13 +68,11 @@ public class MID_MRequisition extends MRequisition implements DocOptions{
|
||||||
BigDecimal totalLines = Env.ZERO;
|
BigDecimal totalLines = Env.ZERO;
|
||||||
ArrayList<Integer> taxList = new ArrayList<Integer>();
|
ArrayList<Integer> taxList = new ArrayList<Integer>();
|
||||||
MRequisitionLine[] lines = req.getLines();
|
MRequisitionLine[] lines = req.getLines();
|
||||||
for (int i = 0; i < lines.length; i++)
|
for (int i = 0; i < lines.length; i++) {
|
||||||
{
|
|
||||||
MRequisitionLine line = lines[i];
|
MRequisitionLine line = lines[i];
|
||||||
totalLines = totalLines.add(line.getLineNetAmt());
|
totalLines = totalLines.add(line.getLineNetAmt());
|
||||||
Integer taxID = new Integer(line.get_ValueAsInt("C_Tax_ID"));
|
Integer taxID = new Integer(line.get_ValueAsInt("C_Tax_ID"));
|
||||||
if (!taxList.contains(taxID))
|
if (!taxList.contains(taxID)) {
|
||||||
{
|
|
||||||
MTax tax = new MTax(getCtx(), taxID, get_TrxName());
|
MTax tax = new MTax(getCtx(), taxID, get_TrxName());
|
||||||
if (tax.getC_TaxProvider_ID() != 0)
|
if (tax.getC_TaxProvider_ID() != 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -86,15 +88,12 @@ public class MID_MRequisition extends MRequisition implements DocOptions{
|
||||||
// Taxes
|
// Taxes
|
||||||
BigDecimal grandTotal = totalLines;
|
BigDecimal grandTotal = totalLines;
|
||||||
X_M_RequisitionTax[] taxes = getTaxes(true);
|
X_M_RequisitionTax[] taxes = getTaxes(true);
|
||||||
for (int i = 0; i < taxes.length; i++)
|
for (int i = 0; i < taxes.length; i++) {
|
||||||
{
|
|
||||||
X_M_RequisitionTax rTax = taxes[i];
|
X_M_RequisitionTax rTax = taxes[i];
|
||||||
MTax tax = new MTax(getCtx(), rTax.getC_Tax_ID(), get_TrxName());
|
MTax tax = new MTax(getCtx(), rTax.getC_Tax_ID(), get_TrxName());
|
||||||
if (tax.isSummary())
|
if (tax.isSummary()) {
|
||||||
{
|
|
||||||
MTax[] cTaxes = tax.getChildTaxes(false);
|
MTax[] cTaxes = tax.getChildTaxes(false);
|
||||||
for (int j = 0; j < cTaxes.length; j++)
|
for (int j = 0; j < cTaxes.length; j++) {
|
||||||
{
|
|
||||||
MTax cTax = cTaxes[j];
|
MTax cTax = cTaxes[j];
|
||||||
BigDecimal taxAmt = cTax.calculateTax(rTax.getTaxBaseAmt(), false, 2);
|
BigDecimal taxAmt = cTax.calculateTax(rTax.getTaxBaseAmt(), false, 2);
|
||||||
//
|
//
|
||||||
|
|
@ -109,7 +108,8 @@ public class MID_MRequisition extends MRequisition implements DocOptions{
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
if (!rTax.delete(true, get_TrxName()))
|
if (!rTax.delete(true, get_TrxName()))
|
||||||
throw new AdempiereException("Failed to Delete Requisition Tax");;
|
throw new AdempiereException("Failed to Delete Requisition Tax");
|
||||||
|
;
|
||||||
if (!rTax.save(get_TrxName()))
|
if (!rTax.save(get_TrxName()))
|
||||||
throw new AdempiereException("Failed to Save Requisition Tax");
|
throw new AdempiereException("Failed to Save Requisition Tax");
|
||||||
}
|
}
|
||||||
|
|
@ -128,9 +128,8 @@ public class MID_MRequisition extends MRequisition implements DocOptions{
|
||||||
if (m_taxes != null && !requery)
|
if (m_taxes != null && !requery)
|
||||||
return m_taxes;
|
return m_taxes;
|
||||||
//
|
//
|
||||||
List<X_M_RequisitionTax> list = new Query(getCtx(), X_M_RequisitionTax.Table_Name, "M_Requisition_ID=?", get_TrxName())
|
List<X_M_RequisitionTax> list = new Query(getCtx(), X_M_RequisitionTax.Table_Name, "M_Requisition_ID=?",
|
||||||
.setParameters(get_ID())
|
get_TrxName()).setParameters(get_ID()).list();
|
||||||
.list();
|
|
||||||
m_taxes = list.toArray(new X_M_RequisitionTax[list.size()]);
|
m_taxes = list.toArray(new X_M_RequisitionTax[list.size()]);
|
||||||
return m_taxes;
|
return m_taxes;
|
||||||
} // getTaxes
|
} // getTaxes
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,6 @@ public class MID_MRequisitionLine extends MRequisitionLine{
|
||||||
@Override
|
@Override
|
||||||
protected boolean afterSave(boolean newRecord, boolean success) {
|
protected boolean afterSave(boolean newRecord, boolean success) {
|
||||||
super.afterSave(newRecord, success);
|
super.afterSave(newRecord, success);
|
||||||
// requisition.recalculateTax(get_TrxName());
|
|
||||||
String sql = "UPDATE M_Requisition SET TaxAmt = "
|
String sql = "UPDATE M_Requisition SET TaxAmt = "
|
||||||
+ "(SELECT COALESCE(SUM(TaxAmt),0) FROM M_RequisitionLine RL WHERE RL.M_Requisition_ID = M_Requisition.M_Requisition_ID) "
|
+ "(SELECT COALESCE(SUM(TaxAmt),0) FROM M_RequisitionLine RL WHERE RL.M_Requisition_ID = M_Requisition.M_Requisition_ID) "
|
||||||
+ " WHERE M_Requisition_ID ="+getM_Requisition_ID();
|
+ " WHERE M_Requisition_ID ="+getM_Requisition_ID();
|
||||||
|
|
|
||||||
|
|
@ -124,8 +124,10 @@ public class MID_TPBUpdateOrder extends SvrProcess{
|
||||||
retValue.setC_DocTypeTarget_ID(line.getC_DocTypeTarget_ID());
|
retValue.setC_DocTypeTarget_ID(line.getC_DocTypeTarget_ID());
|
||||||
retValue.setIsSOTrx(false);
|
retValue.setIsSOTrx(false);
|
||||||
retValue.setM_PriceList_ID(line.getM_PriceList_ID());
|
retValue.setM_PriceList_ID(line.getM_PriceList_ID());
|
||||||
|
if(req.get_ValueAsInt("C_PaymentTerm_ID")>0) {
|
||||||
retValue.setPaymentRule(req.get_ValueAsString("PaymentRule"));
|
retValue.setPaymentRule(req.get_ValueAsString("PaymentRule"));
|
||||||
retValue.setC_PaymentTerm_ID(req.get_ValueAsInt("C_PaymentTerm_ID"));
|
retValue.setC_PaymentTerm_ID(req.get_ValueAsInt("C_PaymentTerm_ID"));
|
||||||
|
}
|
||||||
retValue.saveEx();
|
retValue.saveEx();
|
||||||
String message = Msg.parseTranslation(getCtx(), "@PurchaseOrderCreated@ " + retValue.getDocumentNo());
|
String message = Msg.parseTranslation(getCtx(), "@PurchaseOrderCreated@ " + retValue.getDocumentNo());
|
||||||
addBufferLog(retValue.get_ID(), retValue.getDateOrdered(), null, message,
|
addBufferLog(retValue.get_ID(), retValue.getDateOrdered(), null, message,
|
||||||
|
|
|
||||||
|
|
@ -119,8 +119,10 @@ public class MID_TPBUpdateOrderLine extends SvrProcess{
|
||||||
retValue.setC_DocTypeTarget_ID(line.getC_DocTypeTarget_ID());
|
retValue.setC_DocTypeTarget_ID(line.getC_DocTypeTarget_ID());
|
||||||
retValue.setIsSOTrx(false);
|
retValue.setIsSOTrx(false);
|
||||||
retValue.setM_PriceList_ID(line.getM_PriceList_ID());
|
retValue.setM_PriceList_ID(line.getM_PriceList_ID());
|
||||||
|
if(req.get_ValueAsInt("C_PaymentTerm_ID")>0) {
|
||||||
retValue.setPaymentRule(req.get_ValueAsString("PaymentRule"));
|
retValue.setPaymentRule(req.get_ValueAsString("PaymentRule"));
|
||||||
retValue.setC_PaymentTerm_ID(req.get_ValueAsInt("C_PaymentTerm_ID"));
|
retValue.setC_PaymentTerm_ID(req.get_ValueAsInt("C_PaymentTerm_ID"));
|
||||||
|
}
|
||||||
retValue.saveEx();
|
retValue.saveEx();
|
||||||
String message = Msg.parseTranslation(getCtx(), "@PurchaseOrderCreated@ " + retValue.getDocumentNo());
|
String message = Msg.parseTranslation(getCtx(), "@PurchaseOrderCreated@ " + retValue.getDocumentNo());
|
||||||
addBufferLog(retValue.get_ID(), retValue.getDateOrdered(), null, message,
|
addBufferLog(retValue.get_ID(), retValue.getDateOrdered(), null, message,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue