Revoke and Requisition Validation Replacement
--HG-- branch : EDII
This commit is contained in:
parent
69fef3f01f
commit
12b02d878e
|
|
@ -1,5 +1,6 @@
|
|||
package andromedia.midsuit.model;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.Properties;
|
||||
|
||||
|
|
@ -11,20 +12,23 @@ import org.compiere.model.X_M_Requisition;
|
|||
import org.compiere.util.DB;
|
||||
import org.compiere.util.Msg;
|
||||
|
||||
public class MID_MRequisitionLine extends MRequisitionLine{
|
||||
public class MID_MRequisitionLine extends MRequisitionLine {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 978479235069420619L;
|
||||
|
||||
public MID_MRequisitionLine(MRequisition req) {
|
||||
super(req);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public MID_MRequisitionLine(Properties ctx, int M_RequisitionLine_ID, String trxName) {
|
||||
super(ctx, M_RequisitionLine_ID, trxName);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public MID_MRequisitionLine(Properties ctx, ResultSet rs, String trxName) {
|
||||
super(ctx, rs, trxName);
|
||||
// TODO Auto-generated constructor stub
|
||||
|
|
@ -32,62 +36,103 @@ public class MID_MRequisitionLine extends MRequisitionLine{
|
|||
|
||||
@Override
|
||||
protected boolean beforeSave(boolean newRecord) {
|
||||
if(!newRecord){
|
||||
MID_MRequisition requisition = new MID_MRequisition(getCtx(), getM_Requisition_ID(), get_TrxName());
|
||||
MID_MRequisition requisition = new MID_MRequisition(getCtx(), getM_Requisition_ID(), get_TrxName());
|
||||
if (!newRecord) {
|
||||
Boolean isReactivate = requisition.get_ValueAsBoolean("IsReactivate");
|
||||
if(isReactivate){
|
||||
if(is_ValueChanged("M_Product_ID")){
|
||||
if (isReactivate) {
|
||||
if (is_ValueChanged("M_Product_ID")) {
|
||||
throw new AdempiereException("Product cannot be changed !!!");
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.beforeSave(newRecord);
|
||||
if (newRecord && getParent().isComplete()) {
|
||||
log.saveError("ParentComplete", Msg.translate(getCtx(), "M_RequisitionLine"));
|
||||
return false;
|
||||
}
|
||||
if (getLine() == 0) {
|
||||
String sql = "SELECT COALESCE(MAX(Line),0)+10 FROM M_RequisitionLine WHERE M_Requisition_ID=?";
|
||||
int ii = DB.getSQLValueEx(get_TrxName(), sql, getM_Requisition_ID());
|
||||
setLine(ii);
|
||||
}
|
||||
// Product & ASI - Charge
|
||||
if (getM_Product_ID() != 0 && getC_Charge_ID() != 0)
|
||||
setC_Charge_ID(0);
|
||||
if (getM_AttributeSetInstance_ID() != 0 && getC_Charge_ID() != 0)
|
||||
setM_AttributeSetInstance_ID(0);
|
||||
// Product UOM
|
||||
if (getM_Product_ID() > 0 && getC_UOM_ID() <= 0) {
|
||||
setC_UOM_ID(getM_Product().getC_UOM_ID());
|
||||
}
|
||||
//
|
||||
if (getPriceActual().signum() == 0)
|
||||
setPrice();
|
||||
this.setLineNetAmt(requisition.getC_Currency_ID());
|
||||
/*
|
||||
* Carlos Ruiz - globalqss IDEMPIERE-178 Orders and Invoices must disallow
|
||||
* amount lines without product/charge
|
||||
*/
|
||||
if (getParent().getC_DocType().isChargeOrProductMandatory()) {
|
||||
if (getC_Charge_ID() == 0 && getM_Product_ID() == 0 && getPriceActual().signum() != 0) {
|
||||
log.saveError("FillMandatory", Msg.translate(getCtx(), "ChargeOrProductMandatory"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setLineNetAmt (int C_Currency_ID)
|
||||
{
|
||||
BigDecimal lineNetAmt = getQty().multiply(getPriceActual());
|
||||
int StdPrecision = DB.getSQLValue(get_TrxName(), "SELECT StdPrecision FROM C_Currency WHERE C_Currency_ID =?", new Object[] { C_Currency_ID });
|
||||
super.setLineNetAmt (lineNetAmt.setScale(StdPrecision, BigDecimal.ROUND_HALF_UP));
|
||||
} // setLineNetAmt
|
||||
|
||||
@Override
|
||||
protected boolean beforeDelete() {
|
||||
MID_MRequisition requisition = new MID_MRequisition(getCtx(), getM_Requisition_ID(), get_TrxName());
|
||||
Boolean isReactivate = requisition.get_ValueAsBoolean("IsReactivate");
|
||||
if(isReactivate){
|
||||
if (isReactivate) {
|
||||
log.saveError("DeleteError", "Line Reactivate !!! Cannot be deleted !!!");
|
||||
return false;
|
||||
}
|
||||
return super.beforeDelete();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean afterSave(boolean newRecord, boolean success) {
|
||||
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();
|
||||
|
||||
+ " WHERE M_Requisition_ID =" + getM_Requisition_ID();
|
||||
|
||||
DB.executeUpdateEx(sql, get_TrxName());
|
||||
|
||||
|
||||
sql = "UPDATE M_Requisition SET GrandTotal = "
|
||||
+ "(SELECT COALESCE(SUM(TaxAmt+LineNetAmt),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();
|
||||
|
||||
DB.executeUpdateEx(sql, get_TrxName());
|
||||
|
||||
if(newRecord || is_ValueChanged("C_Tax_ID") || is_ValueChanged("LineNetAmt")) {
|
||||
|
||||
if (newRecord || is_ValueChanged("C_Tax_ID") || is_ValueChanged("LineNetAmt")) {
|
||||
X_M_RequisitionTax tax = null;
|
||||
if(newRecord) {
|
||||
if (newRecord) {
|
||||
tax = X_M_RequisitionTax.get(this, 2, false, get_TrxName());
|
||||
tax.calculateTaxFromLines();
|
||||
if(tax.getTaxAmt().signum() != 0)
|
||||
if (tax.getTaxAmt().signum() != 0)
|
||||
tax.saveEx();
|
||||
else
|
||||
tax.delete(false, get_TrxName());
|
||||
}else {
|
||||
} else {
|
||||
tax = X_M_RequisitionTax.get(this, 2, true, get_TrxName());
|
||||
if(tax!=null) {
|
||||
if (tax != null) {
|
||||
tax.calculateTaxFromLines();
|
||||
if(tax.getTaxAmt().signum() != 0)
|
||||
if (tax.getTaxAmt().signum() != 0)
|
||||
tax.saveEx();
|
||||
else
|
||||
tax.delete(false, get_TrxName());
|
||||
}
|
||||
tax = X_M_RequisitionTax.get(this, 2, false, get_TrxName());
|
||||
tax.calculateTaxFromLines();
|
||||
if(tax.getTaxAmt().signum() != 0)
|
||||
if (tax.getTaxAmt().signum() != 0)
|
||||
tax.saveEx();
|
||||
else
|
||||
tax.delete(false, get_TrxName());
|
||||
|
|
@ -96,33 +141,32 @@ public class MID_MRequisitionLine extends MRequisitionLine{
|
|||
super.afterSave(newRecord, success);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected boolean afterDelete(boolean success) {
|
||||
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();
|
||||
|
||||
+ " WHERE M_Requisition_ID =" + getM_Requisition_ID();
|
||||
|
||||
DB.executeUpdateEx(sql, get_TrxName());
|
||||
|
||||
|
||||
sql = "UPDATE M_Requisition SET GrandTotal = "
|
||||
+ "(SELECT COALESCE(SUM(TaxAmt+LineNetAmt),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();
|
||||
|
||||
DB.executeUpdateEx(sql, get_TrxName());
|
||||
X_M_RequisitionTax tax = null;
|
||||
if(is_new())
|
||||
tax = X_M_RequisitionTax.get(this, 2, false, get_TrxName());
|
||||
if (is_new())
|
||||
tax = X_M_RequisitionTax.get(this, 2, false, get_TrxName());
|
||||
else
|
||||
tax = X_M_RequisitionTax.get(this, 2, true, get_TrxName());
|
||||
|
||||
tax = X_M_RequisitionTax.get(this, 2, true, get_TrxName());
|
||||
|
||||
tax.calculateTaxFromLines();
|
||||
if(tax.getTaxBaseAmt().signum() == 0 || tax.getTaxAmt().signum() == 0)
|
||||
if (tax.getTaxBaseAmt().signum() == 0 || tax.getTaxAmt().signum() == 0)
|
||||
tax.deleteEx(true, get_TrxName());
|
||||
else
|
||||
tax.saveEx();
|
||||
return super.afterDelete(success);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,9 +16,7 @@ public class MID_PEBRevoke extends SvrProcess {
|
|||
|
||||
@Override
|
||||
protected String doIt() throws Exception {
|
||||
pebLine.setProcessed(false);
|
||||
pebLine.setC_Order_ID(0);
|
||||
pebLine.saveEx();
|
||||
|
||||
|
||||
MID_MOrder order = new MID_MOrder(getCtx(), pebLine.getC_Order_ID(), get_TrxName());
|
||||
order.set_ValueNoCheck("RegisterDate", null);
|
||||
|
|
@ -26,7 +24,11 @@ public class MID_PEBRevoke extends SvrProcess {
|
|||
order.set_ValueNoCheck("NoAju1", null);
|
||||
order.set_ValueNoCheck("MID_AJUDocumentType_ID", null);
|
||||
order.saveEx();
|
||||
return EMPTY_STRING;
|
||||
|
||||
pebLine.setProcessed(false);
|
||||
pebLine.setC_Order_ID(0);
|
||||
pebLine.saveEx();
|
||||
return "Revoke Custom Success!";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue