Search in sources :

Example 6 with AdempiereException

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();
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException)

Example 7 with AdempiereException

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");
}
Also used : BigDecimal(java.math.BigDecimal) AdempiereException(org.adempiere.exceptions.AdempiereException)

Example 8 with AdempiereException

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;
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException) BigDecimal(java.math.BigDecimal)

Example 9 with AdempiereException

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);
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException)

Example 10 with AdempiereException

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();
    }
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException) DecimalFormat(java.text.DecimalFormat) BigDecimal(java.math.BigDecimal)

Aggregations

AdempiereException (org.adempiere.exceptions.AdempiereException)216 BigDecimal (java.math.BigDecimal)64 SQLException (java.sql.SQLException)42 ResultSet (java.sql.ResultSet)29 PreparedStatement (java.sql.PreparedStatement)28 MProduct (org.compiere.model.MProduct)28 ArrayList (java.util.ArrayList)27 Timestamp (java.sql.Timestamp)23 Query (org.compiere.model.Query)19 PO (org.compiere.model.PO)16 MBPartner (org.compiere.model.MBPartner)14 Properties (java.util.Properties)13 File (java.io.File)12 List (java.util.List)12 ProcessInfo (org.compiere.process.ProcessInfo)12 Arrays (java.util.Arrays)10 Env (org.compiere.util.Env)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 MMovement (org.compiere.model.MMovement)9 Date (java.util.Date)8