use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.
the class MPaySelection method voidIt.
/**
* Void Document.
* Same as Close.
* @return true if success
*/
public boolean voidIt() {
log.info("voidIt - " + toString());
// Valid if is used
if (isUsed())
throw new AdempiereException("@C_PaySelection_ID@ @Processed@");
// Valid if is paid
if (isPaid())
throw new AdempiereException("@C_PaySelection_ID@ @IsPaid@");
//
setProcessed(true);
setDocAction(DOCACTION_None);
setDocStatus(DOCSTATUS_Voided);
return closeIt();
}
use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.
the class MProduct method beforeDelete.
// afterSave
@Override
protected boolean beforeDelete() {
if (PRODUCTTYPE_Resource.equals(getProductType()) && getS_Resource_ID() > 0) {
throw new AdempiereException("@S_Resource_ID@<>0");
}
// Check Storage
if (isStocked() || PRODUCTTYPE_Item.equals(getProductType())) {
MStorage[] storages = MStorage.getOfProduct(getCtx(), get_ID(), get_TrxName());
BigDecimal OnHand = Env.ZERO;
BigDecimal Ordered = Env.ZERO;
BigDecimal Reserved = Env.ZERO;
for (int i = 0; i < storages.length; i++) {
OnHand = OnHand.add(storages[i].getQtyOnHand());
Ordered = OnHand.add(storages[i].getQtyOrdered());
Reserved = OnHand.add(storages[i].getQtyReserved());
}
String errMsg = "";
if (OnHand.signum() != 0)
errMsg = "@QtyOnHand@ = " + OnHand;
if (Ordered.signum() != 0)
errMsg += " - @QtyOrdered@ = " + Ordered;
if (Reserved.signum() != 0)
errMsg += " - @QtyReserved@" + Reserved;
if (errMsg.length() > 0) {
log.saveError("Error", Msg.parseTranslation(getCtx(), errMsg));
return false;
}
}
// delete costing
MProductCosting[] costings = MProductCosting.getOfProduct(getCtx(), get_ID(), get_TrxName());
for (int i = 0; i < costings.length; i++) costings[i].delete(true, get_TrxName());
MCost.delete(this);
// [ 1674225 ] Delete Product: Costing deletion error
/*MAcctSchema[] mass = MAcctSchema.getClientAcctSchema(getCtx(),getAD_Client_ID(), get_TrxName());
for(int i=0; i<mass.length; i++)
{
// Get Cost Elements
MCostElement[] ces = MCostElement.getMaterialWithCostingMethods(this);
MCostElement ce = null;
for(int j=0; j<ces.length; j++)
{
if(MCostElement.COSTINGMETHOD_StandardCosting.equals(ces[i].getCostingMethod()))
{
ce = ces[i];
break;
}
}
if(ce == null)
continue;
MCost mcost = MCost.get(this, 0, mass[i], 0, ce.getM_CostElement_ID());
mcost.delete(true, get_TrxName());
}*/
// @Trifon Delete Product UOM Conversion
final String whereClause = MProduct.COLUMNNAME_M_Product_ID + "=?";
List<MUOMConversion> conversions = new Query(getCtx(), I_C_UOM_Conversion.Table_Name, whereClause, get_TrxName()).setClient_ID().setParameters(get_ID()).setOnlyActiveRecords(false).list();
for (MUOMConversion conversion : conversions) {
conversion.deleteEx(true);
}
// @Trifon Delete Product Downloads
List<MProductDownload> downloads = new Query(getCtx(), I_M_ProductDownload.Table_Name, whereClause, get_TrxName()).setClient_ID().setParameters(get_ID()).setOnlyActiveRecords(false).list();
for (MProductDownload download : downloads) {
download.deleteEx(true);
}
// @Trifon Delete Product Memo
List<MMemo> memos = new Query(getCtx(), I_AD_Memo.Table_Name, whereClause, get_TrxName()).setClient_ID().setParameters(get_ID()).setOnlyActiveRecords(false).list();
for (MMemo memo : memos) {
memo.deleteEx(true);
}
//
return delete_Accounting("M_Product_Acct");
}
use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.
the class MProduct method beforeSave.
// toString
@Override
protected boolean beforeSave(boolean newRecord) {
// Check Storage
if (//
!newRecord && (// now not active
(is_ValueChanged("IsActive") && !isActive()) || // now not stocked
(is_ValueChanged("IsStocked") && !isStocked()) || (// from Item
is_ValueChanged("ProductType") && PRODUCTTYPE_Item.equals(get_ValueOld("ProductType"))))) {
MStorage[] storages = MStorage.getOfProduct(getCtx(), get_ID(), get_TrxName());
BigDecimal OnHand = Env.ZERO;
BigDecimal Ordered = Env.ZERO;
BigDecimal Reserved = Env.ZERO;
for (int i = 0; i < storages.length; i++) {
OnHand = OnHand.add(storages[i].getQtyOnHand());
Ordered = Ordered.add(storages[i].getQtyOrdered());
Reserved = Reserved.add(storages[i].getQtyReserved());
}
String errMsg = "";
if (OnHand.signum() != 0)
errMsg = "@QtyOnHand@ = " + OnHand;
if (Ordered.signum() != 0)
errMsg += " - @QtyOrdered@ = " + Ordered;
if (Reserved.signum() != 0)
errMsg += " - @QtyReserved@" + Reserved;
if (errMsg.length() > 0) {
log.saveError("Error", Msg.parseTranslation(getCtx(), errMsg));
return false;
}
}
// it checks if UOM has been changed , if so disallow the change if the condition is true.
if ((!newRecord) && is_ValueChanged("C_UOM_ID") && hasInventoryOrCost()) {
log.saveError("Error", Msg.getMsg(getCtx(), "SaveUomError"));
return false;
}
//if (isStocked() && !PRODUCTTYPE_Item.equals(getProductType()))
if (!PRODUCTTYPE_Item.equals(getProductType()))
setIsStocked(false);
// UOM reset
if (m_precision != null && is_ValueChanged("C_UOM_ID"))
m_precision = null;
// AttributeSetInstance reset
if (is_ValueChanged(COLUMNNAME_M_AttributeSet_ID)) {
MAttributeSetInstance asi = new MAttributeSetInstance(getCtx(), getM_AttributeSetInstance_ID(), get_TrxName());
setM_AttributeSetInstance_ID(0);
// Delete the old m_attributesetinstance
try {
asi.deleteEx(true, get_TrxName());
} catch (AdempiereException ex) {
log.saveError("Error", "Error deleting the AttributeSetInstance");
return false;
}
}
return true;
}
use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.
the class MPayment method deAllocate.
// allocatePaySelection
/**
* De-allocate Payment.
* Unkink Invoices and Orders and delete Allocations
*/
private void deAllocate() {
if (getC_Order_ID() != 0)
setC_Order_ID(0);
// if (getC_Invoice_ID() == 0)
// return;
// De-Allocate all
MAllocationHdr[] allocations = MAllocationHdr.getOfPayment(getCtx(), getC_Payment_ID(), get_TrxName());
log.fine("#" + allocations.length);
for (int i = 0; i < allocations.length; i++) {
allocations[i].set_TrxName(get_TrxName());
allocations[i].setDocAction(DocAction.ACTION_Reverse_Correct);
if (!allocations[i].processIt(DocAction.ACTION_Reverse_Correct))
throw new AdempiereException(allocations[i].getProcessMsg());
allocations[i].saveEx();
}
// Unlink (in case allocation did not get it)
if (getC_Invoice_ID() != 0) {
// Invoice
String sql = "UPDATE C_Invoice " + "SET C_Payment_ID = NULL, IsPaid='N' " + "WHERE C_Invoice_ID=" + getC_Invoice_ID() + " AND C_Payment_ID=" + getC_Payment_ID();
int no = DB.executeUpdate(sql, get_TrxName());
if (no != 0)
log.fine("Unlink Invoice #" + no);
// Order
sql = "UPDATE C_Order o " + "SET C_Payment_ID = NULL " + "WHERE EXISTS (SELECT * FROM C_Invoice i " + "WHERE o.C_Order_ID=i.C_Order_ID AND i.C_Invoice_ID=" + getC_Invoice_ID() + ")" + " AND C_Payment_ID=" + getC_Payment_ID();
no = DB.executeUpdate(sql, get_TrxName());
if (no != 0)
log.fine("Unlink Order #" + no);
}
//
setC_Invoice_ID(0);
setIsAllocated(false);
}
use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.
the class MProduction method createLines.
// checkMaterialPolicy
/**
* Create Lines from batch
*/
private void createLines() {
// If it already created then ignore
if (isCreated())
return;
isBOM(getM_Product_ID());
// Recalculate
recalculate();
// Check batch having production planned Qty.
BigDecimal cntQty = Env.ZERO;
MProductionBatch pBatch = (MProductionBatch) getM_ProductionBatch();
for (MProduction p : pBatch.getProductionArray(true)) {
if (p.getM_Production_ID() != getM_Production_ID())
cntQty = cntQty.add(p.getProductionQty());
}
BigDecimal maxPlanQty = pBatch.getTargetQty().subtract(cntQty);
if (getProductionQty().compareTo(maxPlanQty) > 0) {
DecimalFormat format = DisplayType.getNumberFormat(DisplayType.Quantity);
throw new AdempiereException("@Total@ @ProductionQty@ > @TargetQty@ [@TargetQty@ = " + format.format(pBatch.getTargetQty()) + " @Total@ @ProductionQty@ = " + format.format(cntQty) + " @Max@ = " + format.format(maxPlanQty));
}
// Delete before process
deleteLines();
createLines(isMustBeStocked());
// Set flag created
setIsCreated(true);
saveEx();
//jobrian - update Production Batch
MProductionBatch batch = getParent();
if (batch != null) {
batch.setQtyOrdered(getProductionQty());
batch.saveEx();
}
}
Aggregations