Search in sources :

Example 36 with MAccount

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

the class Doc_Order method getCommitmentSalesRelease.

//	getCommitmentsSales
/**
	 * 	Get Commitment Sales Release.
	 * 	Called from InOut
	 *	@param as accounting schema
	 *	@param doc doc
	 *	@param Qty qty invoiced/matched
	 *	@param C_OrderLine_ID line
	 *	@param multiplier 1 for accrual
	 *	@return Fact
	 */
protected static Fact getCommitmentSalesRelease(MAcctSchema as, Doc doc, BigDecimal Qty, int M_InOutLine_ID, BigDecimal multiplier) {
    Fact fact = new Fact(doc, as, Fact.POST_Commitment);
    DocLine[] commitments = Doc_Order.getCommitmentsSales(doc, Qty, M_InOutLine_ID);
    BigDecimal total = Env.ZERO;
    FactLine fl = null;
    int C_Currency_ID = -1;
    for (int i = 0; i < commitments.length; i++) {
        DocLine line = commitments[i];
        if (C_Currency_ID == -1)
            C_Currency_ID = line.getC_Currency_ID();
        else if (C_Currency_ID != line.getC_Currency_ID()) {
            doc.p_Error = "Different Currencies of Order Lines";
            s_log.log(Level.SEVERE, doc.p_Error);
            return null;
        }
        BigDecimal cost = line.getAmtSource().multiply(multiplier);
        total = total.add(cost);
        //	Account
        MAccount revenue = line.getAccount(ProductCost.ACCTTYPE_P_Revenue, as);
        fl = fact.createLine(line, revenue, C_Currency_ID, cost, null);
    }
    //	Offset
    MAccount offset = doc.getAccount(ACCTTYPE_CommitmentOffsetSales, as);
    if (offset == null) {
        doc.p_Error = "@NotFound@ @CommitmentOffsetSales_Acct@";
        s_log.log(Level.SEVERE, doc.p_Error);
        return null;
    }
    fact.createLine(null, offset, C_Currency_ID, null, total);
    return fact;
}
Also used : MAccount(org.compiere.model.MAccount) BigDecimal(java.math.BigDecimal)

Example 37 with MAccount

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

the class Doc_Order method getCommitmentRelease.

//	getCommitments
/**
	 * 	Get Commitment Release.
	 * 	Called from MatchInv for accrual and Allocation for Cash Based
	 *	@param as accounting schema
	 *	@param doc doc
	 *	@param Qty qty invoiced/matched
	 *	@param C_InvoiceLine_ID line
	 *	@param multiplier 1 for accrual
	 *	@return Fact
	 */
protected static Fact getCommitmentRelease(MAcctSchema as, Doc doc, BigDecimal Qty, int C_InvoiceLine_ID, BigDecimal multiplier) {
    Fact fact = new Fact(doc, as, Fact.POST_Commitment);
    DocLine[] commitments = Doc_Order.getCommitments(doc, Qty, C_InvoiceLine_ID);
    BigDecimal total = Env.ZERO;
    FactLine fl = null;
    int C_Currency_ID = -1;
    for (int i = 0; i < commitments.length; i++) {
        DocLine line = commitments[i];
        if (C_Currency_ID == -1)
            C_Currency_ID = line.getC_Currency_ID();
        else if (C_Currency_ID != line.getC_Currency_ID()) {
            doc.p_Error = "Different Currencies of Order Lines";
            s_log.log(Level.SEVERE, doc.p_Error);
            return null;
        }
        BigDecimal cost = line.getAmtSource().multiply(multiplier);
        total = total.add(cost);
        //	Account
        MAccount expense = line.getAccount(ProductCost.ACCTTYPE_P_Expense, as);
        fl = fact.createLine(line, expense, C_Currency_ID, null, cost);
    }
    //	Offset
    MAccount offset = doc.getAccount(ACCTTYPE_CommitmentOffset, as);
    if (offset == null) {
        doc.p_Error = "@NotFound@ @CommitmentOffset_Acct@";
        s_log.log(Level.SEVERE, doc.p_Error);
        return null;
    }
    fact.createLine(null, offset, C_Currency_ID, total, null);
    return fact;
}
Also used : MAccount(org.compiere.model.MAccount) BigDecimal(java.math.BigDecimal)

Example 38 with MAccount

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

the class Doc_Order method createFacts.

//  getBalance
/*************************************************************************
	 *  Create Facts (the accounting logic) for
	 *  SOO, POO.
	 *  <pre>
	 *  Reservation (release)
	 * 		Expense			DR
	 * 		Offset					CR
	 *  Commitment
	 *  (to be released by Invoice Matching)
	 * 		Expense					CR
	 * 		Offset			DR
	 *  </pre>
	 *  @param as accounting schema
	 *  @return Fact
	 */
public ArrayList<Fact> createFacts(MAcctSchema as) {
    ArrayList<Fact> facts = new ArrayList<Fact>();
    //  Purchase Order
    if (getDocumentType().equals(DOCTYPE_POrder)) {
        updateProductPO(as);
        updateProductInfo(as.getC_AcctSchema_ID());
        BigDecimal grossAmt = getAmount(Doc.AMTTYPE_Gross);
        //  Commitment
        FactLine fl = null;
        if (as.isCreatePOCommitment()) {
            Fact fact = new Fact(this, as, Fact.POST_Commitment);
            BigDecimal total = Env.ZERO;
            for (int i = 0; i < p_lines.length; i++) {
                DocLine line = p_lines[i];
                BigDecimal cost = line.getAmtSource();
                total = total.add(cost);
                //	Account
                MAccount expense = line.getAccount(ProductCost.ACCTTYPE_P_Expense, as);
                fl = fact.createLine(line, expense, getC_Currency_ID(), cost, null);
            }
            //	Offset
            MAccount offset = getAccount(ACCTTYPE_CommitmentOffset, as);
            if (offset == null) {
                p_Error = "@NotFound@ @CommitmentOffset_Acct@";
                log.log(Level.SEVERE, p_Error);
                return null;
            }
            fact.createLine(null, offset, getC_Currency_ID(), null, total);
            //
            facts.add(fact);
        }
        //  Reverse Reservation
        if (as.isCreateReservation()) {
            Fact fact = new Fact(this, as, Fact.POST_Reservation);
            BigDecimal total = Env.ZERO;
            if (m_requisitions == null)
                m_requisitions = loadRequisitions();
            for (int i = 0; i < m_requisitions.length; i++) {
                DocLine line = m_requisitions[i];
                BigDecimal cost = line.getAmtSource();
                total = total.add(cost);
                //	Account
                MAccount expense = line.getAccount(ProductCost.ACCTTYPE_P_Expense, as);
                fl = fact.createLine(line, expense, getC_Currency_ID(), null, cost);
            }
            //	Offset
            if (m_requisitions.length > 0) {
                MAccount offset = getAccount(ACCTTYPE_CommitmentOffset, as);
                if (offset == null) {
                    p_Error = "@NotFound@ @CommitmentOffset_Acct@";
                    log.log(Level.SEVERE, p_Error);
                    return null;
                }
                fact.createLine(null, offset, getC_Currency_ID(), total, null);
            }
            //
            facts.add(fact);
        }
    //	reservations
    } else //	SO
    if (getDocumentType().equals(DOCTYPE_SOrder)) {
        //  Commitment
        FactLine fl = null;
        if (as.isCreateSOCommitment()) {
            Fact fact = new Fact(this, as, Fact.POST_Commitment);
            BigDecimal total = Env.ZERO;
            for (int i = 0; i < p_lines.length; i++) {
                DocLine line = p_lines[i];
                BigDecimal cost = line.getAmtSource();
                total = total.add(cost);
                //	Account
                MAccount revenue = line.getAccount(ProductCost.ACCTTYPE_P_Revenue, as);
                fl = fact.createLine(line, revenue, getC_Currency_ID(), null, cost);
            }
            //	Offset
            MAccount offset = getAccount(ACCTTYPE_CommitmentOffsetSales, as);
            if (offset == null) {
                p_Error = "@NotFound@ @CommitmentOffsetSales_Acct@";
                log.log(Level.SEVERE, p_Error);
                return null;
            }
            fact.createLine(null, offset, getC_Currency_ID(), total, null);
            //
            facts.add(fact);
        }
    }
    return facts;
}
Also used : MAccount(org.compiere.model.MAccount) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal)

Example 39 with MAccount

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

the class Doc_Payment method createFacts.

//  getBalance
/**
	 *  Create Facts (the accounting logic) for
	 *  ARP, APP.
	 *  <pre>
	 *  ARP
	 *      BankInTransit   DR
	 *      UnallocatedCash         CR
	 *      or Charge/C_Prepayment
	 *  APP
	 *      PaymentSelect   DR
	 *      or Charge/V_Prepayment
	 *      BankInTransit           CR
	 *  CashBankTransfer
	 *      -
	 *  </pre>
	 *  @param as accounting schema
	 *  @return Fact
	 */
public ArrayList<Fact> createFacts(MAcctSchema as) {
    //  create Fact Header
    Fact fact = new Fact(this, as, Fact.POST_Actual);
    //	Cash Transfer
    if ("X".equals(m_TenderType) && !MSysConfig.getBooleanValue("CASH_AS_PAYMENT", true, getAD_Client_ID())) {
        ArrayList<Fact> facts = new ArrayList<Fact>();
        facts.add(fact);
        return facts;
    }
    //	Bank Account Org	
    int AD_Org_ID = getBank_Org_ID();
    if (getDocumentType().equals(DOCTYPE_ARReceipt)) {
        //	Asset
        FactLine fl = fact.createLine(null, getAccount(Doc.ACCTTYPE_BankInTransit, as), getC_Currency_ID(), getAmount(), null);
        if (fl != null && AD_Org_ID != 0)
            fl.setAD_Org_ID(AD_Org_ID);
        //	
        MAccount acct = null;
        if (getC_Charge_ID() != 0)
            acct = MCharge.getAccount(getC_Charge_ID(), as, getAmount());
        else if (m_Prepayment)
            acct = getAccount(Doc.ACCTTYPE_C_Prepayment, as);
        else
            acct = getAccount(Doc.ACCTTYPE_UnallocatedCash, as);
        fl = fact.createLine(null, acct, getC_Currency_ID(), null, getAmount());
        if (fl != null && AD_Org_ID != 0 && //	don't overwrite charge
        getC_Charge_ID() == 0)
            fl.setAD_Org_ID(AD_Org_ID);
    } else //  APP
    if (getDocumentType().equals(DOCTYPE_APPayment)) {
        MAccount acct = null;
        if (getC_Charge_ID() != 0)
            acct = MCharge.getAccount(getC_Charge_ID(), as, getAmount());
        else if (m_Prepayment)
            acct = getAccount(Doc.ACCTTYPE_V_Prepayment, as);
        else
            acct = getAccount(Doc.ACCTTYPE_PaymentSelect, as);
        FactLine fl = fact.createLine(null, acct, getC_Currency_ID(), getAmount(), null);
        if (fl != null && AD_Org_ID != 0 && //	don't overwrite charge
        getC_Charge_ID() == 0)
            fl.setAD_Org_ID(AD_Org_ID);
        //	Asset
        fl = fact.createLine(null, getAccount(Doc.ACCTTYPE_BankInTransit, as), getC_Currency_ID(), null, getAmount());
        if (fl != null && AD_Org_ID != 0)
            fl.setAD_Org_ID(AD_Org_ID);
    } else {
        p_Error = "DocumentType unknown: " + getDocumentType();
        log.log(Level.SEVERE, p_Error);
        fact = null;
    }
    //
    ArrayList<Fact> facts = new ArrayList<Fact>();
    facts.add(fact);
    return facts;
}
Also used : MAccount(org.compiere.model.MAccount) ArrayList(java.util.ArrayList)

Example 40 with MAccount

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

the class Fact method checkAccounts.

//  balanceAccounting
/**
	 * 	Check Accounts of Fact Lines
	 *	@return true if success
	 */
public boolean checkAccounts() {
    //  no lines -> nothing to distribute
    if (m_lines.size() == 0)
        return true;
    //	For all fact lines
    for (int i = 0; i < m_lines.size(); i++) {
        FactLine line = (FactLine) m_lines.get(i);
        MAccount account = line.getAccount();
        if (account == null) {
            log.warning("No Account for " + line);
            return false;
        }
        MElementValue ev = account.getAccount();
        if (ev == null) {
            log.warning("No Element Value for " + account + ": " + line);
            return false;
        }
        if (ev.isSummary()) {
            log.warning("Cannot post to Summary Account " + ev + ": " + line);
            return false;
        }
        if (!ev.isActive()) {
            log.warning("Cannot post to Inactive Account " + ev + ": " + line);
            return false;
        }
    }
    return true;
}
Also used : MElementValue(org.compiere.model.MElementValue) MAccount(org.compiere.model.MAccount)

Aggregations

MAccount (org.compiere.model.MAccount)42 BigDecimal (java.math.BigDecimal)25 ArrayList (java.util.ArrayList)16 MCostDetail (org.compiere.model.MCostDetail)8 PreparedStatement (java.sql.PreparedStatement)7 ResultSet (java.sql.ResultSet)7 MProduct (org.compiere.model.MProduct)6 SQLException (java.sql.SQLException)5 MCostElement (org.compiere.model.MCostElement)5 MJournalLine (org.compiere.model.MJournalLine)4 MCostType (org.compiere.model.MCostType)3 Timestamp (java.sql.Timestamp)2 MAcctSchemaElement (org.compiere.model.MAcctSchemaElement)2 MCharge (org.compiere.model.MCharge)2 MElementValue (org.compiere.model.MElementValue)2 MInvoice (org.compiere.model.MInvoice)2 AdempiereSystemError (org.compiere.util.AdempiereSystemError)2 TreeMap (java.util.TreeMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 I_C_Project (org.compiere.model.I_C_Project)1