Search in sources :

Example 1 with MAssetAddition

use of org.compiere.model.MAssetAddition in project adempiere by adempiere.

the class Doc_AssetAddition method createFacts.

/**
	 * Produce inregistrarea:
	 * <pre>
	 *	20.., 21..[A_Asset_Acct]			=	23..[P_Asset_Acct/Project Acct]
	 * </pre>
	 */
public ArrayList<Fact> createFacts(MAcctSchema as) {
    MAssetAddition assetAdd = getAssetAddition();
    ArrayList<Fact> facts = new ArrayList<Fact>();
    Fact fact = new Fact(this, as, assetAdd.getPostingType());
    facts.add(fact);
    //
    if (MAssetAddition.A_SOURCETYPE_Imported.equals(assetAdd.getA_SourceType()) || //@win prevent create journal if expense addition
    MAssetAddition.A_CAPVSEXP_Expense.equals(assetAdd.getA_CapvsExp())) {
        // no accounting if is imported record
        return facts;
    }
    //
    BigDecimal assetValueAmt = assetAdd.getAssetValueAmt();
    FactLine[] fls = FactUtil.createSimpleOperation(fact, null, getA_Asset_Acct(), getP_Asset_Acct(as), as.getC_Currency_ID(), assetValueAmt, false);
    // Set BPartner and C_Project dimension for "Imobilizari in curs / Property Being"
    final int invoiceBP_ID = getInvoicePartner_ID();
    final int invoiceProject_ID = getInvoiceProject_ID();
    if (invoiceBP_ID > 0) {
        fls[1].setC_BPartner_ID(invoiceBP_ID);
    }
    if (invoiceProject_ID > 0) {
        fls[1].setC_Project_ID(invoiceProject_ID);
    }
    //
    return facts;
}
Also used : MAssetAddition(org.compiere.model.MAssetAddition) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal)

Example 2 with MAssetAddition

use of org.compiere.model.MAssetAddition in project adempiere by adempiere.

the class Doc_AssetAddition method getA_Asset_Acct.

private MAccount getA_Asset_Acct() {
    MAssetAddition assetAdd = getAssetAddition();
    int acct_id = MAssetAcct.forA_Asset_ID(getCtx(), assetAdd.getA_Asset_ID(), assetAdd.getPostingType(), assetAdd.getDateAcct(), null).getA_Asset_Acct();
    return MAccount.get(getCtx(), acct_id);
}
Also used : MAssetAddition(org.compiere.model.MAssetAddition)

Example 3 with MAssetAddition

use of org.compiere.model.MAssetAddition in project adempiere by adempiere.

the class Doc_AssetAddition method getP_Asset_Acct.

private MAccount getP_Asset_Acct(MAcctSchema as) {
    MAssetAddition assetAdd = getAssetAddition();
    // Source Account
    MAccount pAssetAcct = null;
    if (MAssetAddition.A_SOURCETYPE_Project.equals(assetAdd.getA_SourceType())) {
        I_C_Project prj = assetAdd.getC_Project();
        return getProjectAcct(prj, as);
    } else if (MAssetAddition.A_SOURCETYPE_Manual.equals(assetAdd.getA_SourceType()) && // backward compatibility: only if charge defined; if not fallback to product account 
    getC_Charge_ID() > 0) {
        pAssetAcct = MCharge.getAccount(getC_Charge_ID(), as, null);
        return pAssetAcct;
    } else if (MAssetAddition.A_SOURCETYPE_Invoice.equals(assetAdd.getA_SourceType()) && assetAdd.getC_InvoiceLine().getC_Project_ID() > 0) {
        I_C_Project prj = assetAdd.getC_InvoiceLine().getC_Project();
        return getProjectAcct(prj, as);
    } else {
        pAssetAcct = getP_Expense_Acct(assetAdd.getM_Product_ID(), as);
    }
    //
    return pAssetAcct;
}
Also used : MAssetAddition(org.compiere.model.MAssetAddition) MAccount(org.compiere.model.MAccount) I_C_Project(org.compiere.model.I_C_Project)

Example 4 with MAssetAddition

use of org.compiere.model.MAssetAddition in project adempiere by adempiere.

the class ModelValidator method afterVoid.

//	beforeReverseCorrect	
/**
	 *  After Void Invoice
	 *  @param invoice
     *	@return error message or null
	 */
private String afterVoid(MInvoice invoice) {
    // Goodwill - check if invoice is for fixed asset
    if (invoice.get_ValueAsBoolean("IsFixedAssetInvoice")) {
        final String sql = "SELECT A_Asset_Addition_ID " + "FROM A_Asset_Addition WHERE C_Invoice_ID=? ";
        int A_Asset_Addition_ID = DB.getSQLValueEx(invoice.get_TrxName(), sql, invoice.get_ID());
        MAssetAddition assetAdd = new MAssetAddition(invoice.getCtx(), A_Asset_Addition_ID, invoice.get_TrxName());
        // Void asset addition if it's not completed
        if (MAssetAddition.DOCSTATUS_Drafted.equals(assetAdd.getDocStatus()) || MAssetAddition.DOCSTATUS_InProgress.equals(assetAdd.getDocStatus()) || MAssetAddition.DOCSTATUS_Invalid.equals(assetAdd.getDocStatus()) || MAssetAddition.DOCSTATUS_Approved.equals(assetAdd.getDocStatus()) || MAssetAddition.DOCSTATUS_NotApproved.equals(assetAdd.getDocStatus())) {
            if (!assetAdd.processIt(MAssetAddition.DOCACTION_Void)) {
                log.warning("Asset Addition Process Failed: " + assetAdd + " - " + assetAdd.getProcessMsg());
                throw new IllegalStateException("Asset Addition Process Failed: " + assetAdd + " - " + assetAdd.getProcessMsg());
            }
            assetAdd.saveEx();
        }
    }
    return null;
}
Also used : MAssetAddition(org.compiere.model.MAssetAddition)

Example 5 with MAssetAddition

use of org.compiere.model.MAssetAddition in project adempiere by adempiere.

the class ModelValidator method beforeReverseCorrect.

/**
	 * 	Before Reverse Correct Invoice
	 * 	@param invoice
	 *	@return error message or null 
	 */
private String beforeReverseCorrect(MInvoice invoice) {
    // Goodwill - Check Asset Addition's status
    if (invoice.get_ValueAsBoolean("IsFixedAssetInvoice")) {
        final String sql = "SELECT A_Asset_Addition_ID " + "FROM A_Asset_Addition WHERE C_Invoice_ID=? ";
        int A_Asset_Addition_ID = DB.getSQLValueEx(invoice.get_TrxName(), sql, invoice.get_ID());
        MAssetAddition assetAdd = new MAssetAddition(invoice.getCtx(), A_Asset_Addition_ID, invoice.get_TrxName());
        if (assetAdd.getDocStatus().equals(MAssetAddition.DOCSTATUS_Completed) || assetAdd.getDocStatus().equals(MAssetAddition.DOCSTATUS_Closed)) {
            return "Can't Void or Reverse Invoice with Completed Asset Addition";
        }
    }
    // End Check	
    return null;
}
Also used : MAssetAddition(org.compiere.model.MAssetAddition)

Aggregations

MAssetAddition (org.compiere.model.MAssetAddition)9 BigDecimal (java.math.BigDecimal)2 Query (org.compiere.model.Query)2 ArrayList (java.util.ArrayList)1 AssetException (org.compiere.FA.exceptions.AssetException)1 I_C_Project (org.compiere.model.I_C_Project)1 MAccount (org.compiere.model.MAccount)1 MAsset (org.compiere.model.MAsset)1 MIFixedAsset (org.compiere.model.MIFixedAsset)1 MMatchInv (org.compiere.model.MMatchInv)1 MProduct (org.compiere.model.MProduct)1 MProductCategory (org.compiere.model.MProductCategory)1 MProject (org.compiere.model.MProject)1 X_I_FixedAsset (org.compiere.model.X_I_FixedAsset)1