Search in sources :

Example 1 with AssetCheckDocumentException

use of org.compiere.FA.exceptions.AssetCheckDocumentException in project adempiere by adempiere.

the class MAssetAddition method prepareIt.

//	invalidateIt
public String prepareIt() {
    if (log.isLoggable(Level.INFO))
        log.info(toString());
    // Call model validators
    m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_BEFORE_PREPARE);
    if (m_processMsg != null) {
        return DocAction.STATUS_Invalid;
    }
    //Goodwill - new asset doctype
    MPeriod.testPeriodOpen(getCtx(), getDateAcct(), "FAA", getAD_Org_ID());
    // Goodwill - setting Create Asset checkbox
    setA_CreateAsset();
    // Check AssetValueAmt != 0
    if (getAssetValueAmt().signum() == 0) {
        m_processMsg = "@Invalid@ @AssetValueAmt@=0";
        return DocAction.STATUS_Invalid;
    }
    MAsset asset = getA_Asset(true);
    MDepreciationWorkfile assetwk = MDepreciationWorkfile.get(getCtx(), getA_Asset_ID(), getPostingType(), get_TrxName());
    // Goodwill - Check asset disposal status
    if (MAsset.A_ASSET_STATUS_Disposed.equals(asset.getA_Asset_Status())) {
        m_processMsg = "Asset aldready disposed";
        return DocAction.STATUS_Invalid;
    }
    // Goodwill - Check if asset already depreciated 
    if (!MAsset.A_ASSET_STATUS_New.equals(asset.getA_Asset_Status()) && assetwk != null && assetwk.getDateAcct() != null && assetwk.isDepreciated(getDateAcct())) {
        m_processMsg = "Asset already depreciated for this period";
        return DocAction.STATUS_Invalid;
    }
    // Goodwill - Validation on Asset Addition Date
    if (getDateDoc().before(asset.getA_Asset_CreateDate())) {
        throw new AssetCheckDocumentException("Document is date older than Asset Create Date");
    } else if (asset.getAssetServiceDate() != null && getDateDoc().before(asset.getAssetServiceDate())) {
        throw new AssetCheckDocumentException("Document is date older than Asset Service Date");
    }
    // If new assets (not renewals) must have nonzero values
    if (isA_CreateAsset() && hasZeroValues()) {
        throw new AssetException("New document must have non-zero values");
    }
    // Goodwill - can add asset value without adding asset usable life
    if (!isA_CreateAsset() && getDeltaUseLifeYears() < 0) {
        throw new AssetException("Delta Use Life Years cannot be negative values");
    }
    // Goodwill - Validation on Depreciated Asset
    if (MAsset.A_ASSET_STATUS_Depreciated.equals(asset.getA_Asset_Status())) {
        throw new AssetException("Asset is fully depreciated");
    }
    // Only New assets can be activated
    if (isA_CreateAsset() && !MAsset.A_ASSET_STATUS_New.equals(asset.getA_Asset_Status())) {
        throw new AssetException("Only new assets can be activated");
    }
    // Validate Source - Invoice
    if (A_SOURCETYPE_Invoice.equals(getA_SourceType())) {
        int C_Invoice_ID = getC_Invoice_ID();
        MInvoice invoice = new MInvoice(getCtx(), C_Invoice_ID, get_TrxName());
        if (MInvoice.DOCSTATUS_Voided.equals(invoice.getDocStatus())) {
            throw new AssetException("You cannot add asset from voided document(s)");
        }
    }
    // Validate Source - Project
    if (A_SOURCETYPE_Project.equals(getA_SourceType())) {
        if (getC_Project_ID() <= 0) {
            throw new FillMandatoryException(COLUMNNAME_C_Project_ID);
        }
        final String whereClause = COLUMNNAME_C_Project_ID + "=?" + " AND DocStatus IN ('IP','CO','CL')" + " AND " + COLUMNNAME_A_Asset_Addition_ID + "<>?";
        List<MAssetAddition> list = new Query(getCtx(), Table_Name, whereClause, get_TrxName()).setParameters(new Object[] { getC_Project_ID(), get_ID() }).list();
        if (list.size() > 0) {
            StringBuilder sb = new StringBuilder("You can not create project for this asset," + " Project already has assets. View: ");
            for (MAssetAddition aa : list) {
                sb.append(aa.getDocumentInfo()).append("; ");
            }
            throw new AssetException(sb.toString());
        }
    }
    // Call model validators
    m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_AFTER_PREPARE);
    if (m_processMsg != null) {
        return DocAction.STATUS_Invalid;
    }
    //	Done
    m_justPrepared = true;
    if (!DOCACTION_Complete.equals(getDocAction()))
        setDocAction(DOCACTION_Complete);
    return DocAction.STATUS_InProgress;
}
Also used : AssetCheckDocumentException(org.compiere.FA.exceptions.AssetCheckDocumentException) AssetException(org.compiere.FA.exceptions.AssetException) FillMandatoryException(org.adempiere.exceptions.FillMandatoryException)

Aggregations

FillMandatoryException (org.adempiere.exceptions.FillMandatoryException)1 AssetCheckDocumentException (org.compiere.FA.exceptions.AssetCheckDocumentException)1 AssetException (org.compiere.FA.exceptions.AssetException)1