use of org.compiere.model.MAccount in project adempiere by adempiere.
the class Doc_GLJournal method loadLines.
// loadDocumentDetails
/**
* Load Invoice Line
* @param journal journal
* @return DocLine Array
*/
private DocLine[] loadLines(MJournal journal) {
ArrayList<DocLine> list = new ArrayList<DocLine>();
MJournalLine[] lines = journal.getLines(false);
for (int i = 0; i < lines.length; i++) {
MJournalLine line = lines[i];
DocLine docLine = new DocLine(line, this);
// -- Source Amounts
docLine.setAmount(line.getAmtSourceDr(), line.getAmtSourceCr());
// -- Converted Amounts
docLine.setConvertedAmt(m_C_AcctSchema_ID, line.getAmtAcctDr(), line.getAmtAcctCr());
// -- qty
docLine.setQty(line.getQty(), false);
// -- Account
MAccount account = line.getAccount_Combi();
docLine.setAccount(account);
// -- Organization of Line was set to Org of Account
list.add(docLine);
}
// Return Array
int size = list.size();
DocLine[] dls = new DocLine[size];
list.toArray(dls);
return dls;
}
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;
}
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;
}
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;
}
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;
}
Aggregations