Search in sources :

Example 1 with MDepreciationExp

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

the class A_Depreciation_Exp_Check method fixDepreciation.

private void fixDepreciation(int A_Asset_ID) {
    MAsset asset = MAsset.get(getCtx(), A_Asset_ID, get_TrxName());
    List<MDepreciationExp> depreciations = getDepreciation(asset);
    // if exist depreciations with period 0 
    if (depreciations.get(0).getA_Period() == 0) {
        fixDepreciationExp(depreciations.get(0), TimeUtil.getMonthLastDay(asset.getAssetServiceDate()));
        Timestamp tms = depreciations.get(0).getDateAcct();
        for (int i = 1; i < depreciations.size(); i++) {
            fixDepreciationExp(depreciations.get(i), TimeUtil.getMonthLastDay(TimeUtil.addMonths(tms, 1)));
            tms = depreciations.get(i).getDateAcct();
        }
    } else {
        fixDepreciationExp(depreciations.get(0), TimeUtil.getMonthLastDay(TimeUtil.addMonths(asset.getAssetServiceDate(), 1)));
        Timestamp tms = depreciations.get(0).getDateAcct();
        for (int i = 1; i < depreciations.size(); i++) {
            fixDepreciationExp(depreciations.get(i), TimeUtil.getMonthLastDay(TimeUtil.addMonths(tms, 1)));
            tms = depreciations.get(i).getDateAcct();
        }
    }
    //
    for (MDepreciationWorkfile wk : MDepreciationWorkfile.forA_Asset_ID(getCtx(), A_Asset_ID, get_TrxName())) {
        wk.setA_Current_Period();
        wk.saveEx();
        addLog("" + wk + ": Period=" + wk.getA_Current_Period() + ", DateAcct=" + wk.getDateAcct());
    }
}
Also used : MDepreciationWorkfile(org.compiere.model.MDepreciationWorkfile) MDepreciationExp(org.compiere.model.MDepreciationExp) MAsset(org.compiere.model.MAsset) Timestamp(java.sql.Timestamp)

Example 2 with MDepreciationExp

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

the class A_Depreciation_Exp_Process method doIt.

protected String doIt() throws Exception {
    MDepreciationExp depexp = new MDepreciationExp(getCtx(), getRecord_ID(), get_TrxName());
    depexp.process();
    return "@Processed@";
}
Also used : MDepreciationExp(org.compiere.model.MDepreciationExp)

Example 3 with MDepreciationExp

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

the class Doc_DepreciationEntry method createFacts.

//  getBalance
public ArrayList<Fact> createFacts(MAcctSchema as) {
    ArrayList<Fact> facts = new ArrayList<Fact>();
    //	Other Acct Schema
    if (as.getC_AcctSchema_ID() != m_C_AcctSchema_ID)
        return facts;
    //  create Fact Header
    Fact fact = new Fact(this, as, m_PostingType);
    MDepreciationEntry entry = (MDepreciationEntry) getPO();
    Iterator<MDepreciationExp> it = entry.getLinesIterator(false);
    while (it.hasNext()) {
        MDepreciationExp depexp = it.next();
        DocLine line = createLine(depexp);
        BigDecimal expenseAmt = depexp.getExpense();
        //
        MAccount dr_acct = MAccount.get(getCtx(), depexp.getDR_Account_ID());
        MAccount cr_acct = MAccount.get(getCtx(), depexp.getCR_Account_ID());
        FactUtil.createSimpleOperation(fact, line, dr_acct, cr_acct, as.getC_Currency_ID(), expenseAmt, false);
    }
    //
    facts.add(fact);
    return facts;
}
Also used : MDepreciationEntry(org.compiere.model.MDepreciationEntry) MAccount(org.compiere.model.MAccount) ArrayList(java.util.ArrayList) MDepreciationExp(org.compiere.model.MDepreciationExp) BigDecimal(java.math.BigDecimal)

Example 4 with MDepreciationExp

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

the class A_Depreciation_Exp_Modify method doIt.

protected String doIt() throws Exception {
    //
    if (p_A_Depreciation_Exp_ID <= 0) {
        throw new FillMandatoryException("A_Depreciation_Exp_ID");
    }
    //
    MDepreciationExp exp = new MDepreciationExp(getCtx(), p_A_Depreciation_Exp_ID, get_TrxName());
    if (exp.get_ID() != p_A_Depreciation_Exp_ID) {
        throw new AdempiereException("@NotFound@ @A_Depreciation_Exp_ID@ = " + p_A_Depreciation_Exp_ID);
    }
    //
    MDepreciationEntry.deleteFacts(exp);
    exp.setDR_Account_ID(p_DR_Account_ID);
    exp.setCR_Account_ID(p_CR_Account_ID);
    exp.saveEx();
    //
    if (p_IsTest) {
        rollback();
    }
    //
    return "Ok";
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException) MDepreciationExp(org.compiere.model.MDepreciationExp) FillMandatoryException(org.adempiere.exceptions.FillMandatoryException)

Aggregations

MDepreciationExp (org.compiere.model.MDepreciationExp)4 BigDecimal (java.math.BigDecimal)1 Timestamp (java.sql.Timestamp)1 ArrayList (java.util.ArrayList)1 AdempiereException (org.adempiere.exceptions.AdempiereException)1 FillMandatoryException (org.adempiere.exceptions.FillMandatoryException)1 MAccount (org.compiere.model.MAccount)1 MAsset (org.compiere.model.MAsset)1 MDepreciationEntry (org.compiere.model.MDepreciationEntry)1 MDepreciationWorkfile (org.compiere.model.MDepreciationWorkfile)1