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;
|
||||
}
|
||||
|
||||
BigDecimal Qty = reqLine.getQty();
|
||||
BigDecimal Qty = qty;
|
||||
boolean IsSOTrx = order.isSOTrx();
|
||||
MProductPricing pricing = new MProductPricing (reqLine.getM_Product_ID(), order.getC_BPartner_ID(), Qty, IsSOTrx);
|
||||
|
||||
|
|
|
|||
|
|
@ -16,31 +16,36 @@ import org.compiere.process.DocOptions;
|
|||
import org.compiere.util.DB;
|
||||
import org.compiere.util.Env;
|
||||
|
||||
public class MID_MRequisition extends MRequisition implements DocOptions{
|
||||
public class MID_MRequisition extends MRequisition implements DocOptions {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 3588447351218719946L;
|
||||
|
||||
public MID_MRequisition(Properties ctx, int M_Requisition_ID, String trxName) {
|
||||
super(ctx, M_Requisition_ID, trxName);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
|
||||
public MID_MRequisition(Properties ctx, ResultSet rs, String trxName) {
|
||||
super(ctx, rs, trxName);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
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 totalLines = DB.getSQLValueBD(get_TrxName(), "SELECT COALESCE(SUM(LineNetAmt),0) FROM M_RequisitionLine WHERE M_Requisition_ID =?", new Object[] { getM_Requisition_ID() });
|
||||
BigDecimal totalTaxAmt = DB.getSQLValueBD(get_TrxName(),
|
||||
"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);
|
||||
set_Value("TaxAmt", totalTaxAmt);
|
||||
set_Value("GrandTotal", totalLines.add(totalTaxAmt));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean reActivateIt() {
|
||||
set_ValueNoCheck("IsReactivate", "Y");
|
||||
|
|
@ -49,32 +54,29 @@ public class MID_MRequisition extends MRequisition implements DocOptions{
|
|||
setProcessed(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String prepareIt() {
|
||||
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");
|
||||
|
||||
log.severe("TEST");
|
||||
return super.prepareIt();
|
||||
}
|
||||
|
||||
|
||||
public boolean calculateOrderTaxTotal(MRequisition req) {
|
||||
// Lines
|
||||
// Lines
|
||||
BigDecimal totalLines = Env.ZERO;
|
||||
ArrayList<Integer> taxList = new ArrayList<Integer>();
|
||||
MRequisitionLine[] lines = req.getLines();
|
||||
for (int i = 0; i < lines.length; i++)
|
||||
{
|
||||
for (int i = 0; i < lines.length; i++) {
|
||||
MRequisitionLine line = lines[i];
|
||||
totalLines = totalLines.add(line.getLineNetAmt());
|
||||
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());
|
||||
if (tax.getC_TaxProvider_ID() != 0)
|
||||
continue;
|
||||
X_M_RequisitionTax rTax = X_M_RequisitionTax.get (line, 2, false, get_TrxName()); // current Tax
|
||||
X_M_RequisitionTax rTax = X_M_RequisitionTax.get(line, 2, false, get_TrxName()); // current Tax
|
||||
if (!rTax.calculateTaxFromLines())
|
||||
throw new AdempiereException("Failed to Claculate Tax");
|
||||
if (!rTax.save(get_TrxName()))
|
||||
|
|
@ -82,19 +84,16 @@ public class MID_MRequisition extends MRequisition implements DocOptions{
|
|||
taxList.add(taxID);
|
||||
}
|
||||
}
|
||||
|
||||
// Taxes
|
||||
|
||||
// Taxes
|
||||
BigDecimal grandTotal = totalLines;
|
||||
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];
|
||||
MTax tax = new MTax(getCtx(), rTax.getC_Tax_ID(), get_TrxName());
|
||||
if (tax.isSummary())
|
||||
{
|
||||
if (tax.isSummary()) {
|
||||
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];
|
||||
BigDecimal taxAmt = cTax.calculateTax(rTax.getTaxBaseAmt(), false, 2);
|
||||
//
|
||||
|
|
@ -109,33 +108,33 @@ public class MID_MRequisition extends MRequisition implements DocOptions{
|
|||
//
|
||||
}
|
||||
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()))
|
||||
throw new AdempiereException("Failed to Save Requisition Tax");
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
setTotalLines(totalLines);
|
||||
set_ValueNoCheck("GrandTotal", grandTotal);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private X_M_RequisitionTax[] m_taxes;
|
||||
|
||||
|
||||
public X_M_RequisitionTax[] getTaxes(boolean requery)
|
||||
{
|
||||
if (m_taxes != null && !requery)
|
||||
return m_taxes;
|
||||
//
|
||||
List<X_M_RequisitionTax> list = new Query(getCtx(), X_M_RequisitionTax.Table_Name, "M_Requisition_ID=?", get_TrxName())
|
||||
.setParameters(get_ID())
|
||||
.list();
|
||||
List<X_M_RequisitionTax> list = new Query(getCtx(), X_M_RequisitionTax.Table_Name, "M_Requisition_ID=?",
|
||||
get_TrxName()).setParameters(get_ID()).list();
|
||||
m_taxes = list.toArray(new X_M_RequisitionTax[list.size()]);
|
||||
return m_taxes;
|
||||
} // getTaxes
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public int customizeValidActions(String docStatus, Object processing, String orderType, String isSOTrx,
|
||||
int AD_Table_ID, String[] docAction, String[] options, int index) {
|
||||
|
|
@ -153,7 +152,7 @@ public class MID_MRequisition extends MRequisition implements DocOptions{
|
|||
options[index++] = DocAction.ACTION_Void;
|
||||
} else if (docStatus.equals(DocAction.STATUS_Completed)) {
|
||||
options[index++] = DocAction.ACTION_Close;
|
||||
// options[index++] = DocAction.ACTION_ReActivate;
|
||||
// options[index++] = DocAction.ACTION_ReActivate;
|
||||
options[index++] = DocAction.ACTION_Void;
|
||||
} else if (docStatus.equals(DocAction.STATUS_Invalid)) {
|
||||
options[index++] = DocAction.ACTION_Complete;
|
||||
|
|
@ -162,6 +161,6 @@ public class MID_MRequisition extends MRequisition implements DocOptions{
|
|||
return index;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,7 +55,6 @@ public class MID_MRequisitionLine extends MRequisitionLine{
|
|||
@Override
|
||||
protected boolean afterSave(boolean newRecord, boolean success) {
|
||||
super.afterSave(newRecord, success);
|
||||
// requisition.recalculateTax(get_TrxName());
|
||||
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) "
|
||||
+ " 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.setIsSOTrx(false);
|
||||
retValue.setM_PriceList_ID(line.getM_PriceList_ID());
|
||||
retValue.setPaymentRule(req.get_ValueAsString("PaymentRule"));
|
||||
retValue.setC_PaymentTerm_ID(req.get_ValueAsInt("C_PaymentTerm_ID"));
|
||||
if(req.get_ValueAsInt("C_PaymentTerm_ID")>0) {
|
||||
retValue.setPaymentRule(req.get_ValueAsString("PaymentRule"));
|
||||
retValue.setC_PaymentTerm_ID(req.get_ValueAsInt("C_PaymentTerm_ID"));
|
||||
}
|
||||
retValue.saveEx();
|
||||
String message = Msg.parseTranslation(getCtx(), "@PurchaseOrderCreated@ " + retValue.getDocumentNo());
|
||||
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.setIsSOTrx(false);
|
||||
retValue.setM_PriceList_ID(line.getM_PriceList_ID());
|
||||
retValue.setPaymentRule(req.get_ValueAsString("PaymentRule"));
|
||||
retValue.setC_PaymentTerm_ID(req.get_ValueAsInt("C_PaymentTerm_ID"));
|
||||
if(req.get_ValueAsInt("C_PaymentTerm_ID")>0) {
|
||||
retValue.setPaymentRule(req.get_ValueAsString("PaymentRule"));
|
||||
retValue.setC_PaymentTerm_ID(req.get_ValueAsInt("C_PaymentTerm_ID"));
|
||||
}
|
||||
retValue.saveEx();
|
||||
String message = Msg.parseTranslation(getCtx(), "@PurchaseOrderCreated@ " + retValue.getDocumentNo());
|
||||
addBufferLog(retValue.get_ID(), retValue.getDateOrdered(), null, message,
|
||||
|
|
|
|||
Loading…
Reference in New Issue