use of org.compiere.model.MAccount in project adempiere by adempiere.
the class Doc_PPCostCollector method createActivityControl.
/**
* Feedback Labor and Burden absorbed
* Debit Work in Process Account for each Labor or Burden using the current cost rate
* Create a fact line for labor or burden
* Labor(Resources)
* Burden
* Credit Labor Absorbed or Burden Absorbed Account
* Create a fact line for labor or burden
* Labor Absorbed
* Burden Absorbed
*/
protected List<Fact> createActivityControl(MAcctSchema acctSchema) {
final ArrayList<Fact> facts = new ArrayList<Fact>();
final Fact fact = new Fact(this, acctSchema, Fact.POST_Actual);
facts.add(fact);
final MProduct product = costCollector.getM_Product();
MAccount workInProcessAccount = docLineCostCollector.getAccount(ProductCost.ACCTTYPE_P_WorkInProcess, acctSchema);
for (MCostDetail costDetail : getCostDetailsActivityControl()) {
BigDecimal absoluteCost = costDetail.getTotalCost(costDetail, acctSchema);
if (absoluteCost.signum() == 0)
continue;
BigDecimal cost = costDetail.getQty().signum() < 0 ? absoluteCost.negate() : absoluteCost;
MCostElement costElement = MCostElement.get(getCtx(), costDetail.getM_CostElement_ID());
MAccount creditCostAccount = docLineCostCollector.getAccount(acctSchema, costElement);
createLines(costElement, acctSchema, fact, product, workInProcessAccount, creditCostAccount, cost, costCollector.getMovementQty());
}
//
return facts;
}
use of org.compiere.model.MAccount in project adempiere by adempiere.
the class Doc_MatchInv method createFacts.
// getBalance
/**
* Create Facts (the accounting logic) for
* MXI.
* (single line)
* <pre>
* NotInvoicedReceipts DR (Receipt Org)
* InventoryClearing CR
* InvoicePV DR CR (difference)
* Commitment
* Expense CR
* Offset DR
* </pre>
* @param as accounting schema
* @return Fact
*/
public ArrayList<Fact> createFacts(MAcctSchema as) {
ArrayList<Fact> facts = new ArrayList<Fact>();
// Nothing to do
if (// no Product
getM_Product_ID() == 0 || getQty().signum() == 0 || // Qty = 0
m_receiptLine.getMovementQty().signum() == 0) {
log.fine("No Product/Qty - M_Product_ID=" + getM_Product_ID() + ",Qty=" + getQty() + ",InOutQty=" + m_receiptLine.getMovementQty());
return facts;
}
MCostType ct = MCostType.get(as, getM_Product_ID(), getAD_Org_ID());
// create Fact Header
Fact fact = new Fact(this, as, Fact.POST_Actual);
setC_Currency_ID(as.getC_Currency_ID());
boolean isInterOrg = isInterOrg(as);
/** Needs to be handeled in PO Matching as no Receipt info
if (m_pc.isService())
{
log.fine("Service - skipped");
return fact;
}
**/
if (!m_receiptLine.getM_Product().isStocked())
return facts;
// NotInvoicedReceipt DR
// From Receipt
BigDecimal multiplier = getQty().divide(m_receiptLine.getMovementQty(), 12, BigDecimal.ROUND_HALF_UP).abs();
FactLine dr = fact.createLine(null, getAccount(Doc.ACCTTYPE_NotInvoicedReceipts, as), as.getC_Currency_ID(), Env.ONE, // updated below
null);
if (dr == null) {
p_Error = "No Product Costs";
return null;
}
dr.setM_Product_ID(m_receiptLine.getM_Product_ID());
String documentBaseTypeReceipt = DB.getSQLValueString(m_receiptLine.get_TrxName(), "SELECT DocBaseType FROM C_DocType WHERE C_DocType_ID=?", m_receiptLine.getParent().getC_DocType_ID());
BigDecimal quantityReceipt = MDocType.DOCBASETYPE_MaterialReceipt.equals(documentBaseTypeReceipt) ? getQty() : getQty().negate();
dr.setQty(quantityReceipt);
BigDecimal temp = dr.getAcctBalance();
// Set AmtAcctCr/Dr from Receipt (sets also Project)
if (!// Amt updated
dr.updateReverseLine(// Amt updated
MInOut.Table_ID, m_receiptLine.getM_InOut_ID(), m_receiptLine.getM_InOutLine_ID(), quantityReceipt, multiplier)) {
p_Error = "Mat.Receipt not posted yet";
return null;
}
log.fine("CR - Amt(" + temp + "->" + dr.getAcctBalance() + ") - " + dr.toString());
// InventoryClearing CR
// From Invoice
MAccount expense = m_pc.getAccount(ProductCost.ACCTTYPE_P_InventoryClearing, as);
if (m_pc.isService())
expense = m_pc.getAccount(ProductCost.ACCTTYPE_P_Expense, as);
BigDecimal LineNetAmt = m_invoiceLine.getLineNetAmt();
multiplier = getQty().divide(m_invoiceLine.getQtyInvoiced(), 12, BigDecimal.ROUND_HALF_UP).abs();
if (multiplier.compareTo(Env.ONE) != 0)
LineNetAmt = LineNetAmt.multiply(multiplier);
if (m_pc.isService())
// book out exact receipt amt
LineNetAmt = dr.getAcctBalance();
FactLine cr = null;
if (as.isAccrual()) {
cr = fact.createLine(null, expense, as.getC_Currency_ID(), null, // updated below
LineNetAmt);
if (cr == null) {
log.fine("Line Net Amt=0 - M_Product_ID=" + getM_Product_ID() + ",Qty=" + getQty() + ",InOutQty=" + m_receiptLine.getMovementQty());
// Invoice Price Variance
BigDecimal ipv = dr.getSourceBalance().negate();
if (ipv.signum() != 0) {
BigDecimal costs = MCostDetail.getByDocLineMatchInv(m_invoiceLine, m_receiptLine, as.getC_AcctSchema_ID(), as.getM_CostType_ID());
int ACCTTYPE_P = 0;
if (MCostType.COSTINGMETHOD_StandardCosting.equals(ct.getCostingMethod()) || MCostType.COSTINGMETHOD_AverageInvoice.equals(ct.getCostingMethod()))
ACCTTYPE_P = ProductCost.ACCTTYPE_P_IPV;
else
ACCTTYPE_P = ProductCost.ACCTTYPE_P_Asset;
BigDecimal diff = ipv.subtract(costs);
MInvoice m_invoice = m_invoiceLine.getParent();
int C_Currency_ID = m_invoice.getC_Currency_ID();
FactLine pv = fact.createLine(null, m_pc.getAccount(ACCTTYPE_P, as), C_Currency_ID, ipv);
pv.setC_Activity_ID(m_invoiceLine.getC_Activity_ID());
pv.setC_Campaign_ID(m_invoiceLine.getC_Campaign_ID());
pv.setC_Project_ID(m_invoiceLine.getC_Project_ID());
pv.setC_ProjectPhase_ID(m_invoiceLine.getC_ProjectPhase_ID());
pv.setC_ProjectTask_ID(m_invoiceLine.getC_ProjectTask_ID());
pv.setC_UOM_ID(m_invoiceLine.getC_UOM_ID());
pv.setUser1_ID(m_invoiceLine.getUser1_ID());
pv.setUser2_ID(m_invoiceLine.getUser2_ID());
pv.setUser3_ID(m_invoiceLine.getUser3_ID());
pv.setUser4_ID(m_invoiceLine.getUser4_ID());
if (diff.compareTo(Env.ZERO) != 0 && MCostType.COSTINGMETHOD_AverageInvoice.equals(ct.getCostingMethod())) {
FactLine diffline = fact.createLine(null, m_pc.getAccount(ProductCost.ACCTTYPE_P_CostAdjustment, as), C_Currency_ID, diff.negate());
diffline.setC_Activity_ID(m_invoiceLine.getC_Activity_ID());
diffline.setC_Project_ID(m_invoiceLine.getC_Project_ID());
diffline.setC_ProjectPhase_ID(m_invoiceLine.getC_ProjectPhase_ID());
diffline.setC_ProjectTask_ID(m_invoiceLine.getC_ProjectTask_ID());
diffline.setC_UOM_ID(m_invoiceLine.getC_UOM_ID());
diffline.setUser1_ID(m_invoiceLine.getUser1_ID());
diffline.setUser2_ID(m_invoiceLine.getUser2_ID());
diffline.setUser3_ID(m_invoiceLine.getUser3_ID());
diffline.setUser4_ID(m_invoiceLine.getUser4_ID());
}
}
log.fine("IPV=" + ipv + "; Balance=" + fact.getSourceBalance());
facts.add(fact);
return facts;
}
cr.setM_Product_ID(m_invoiceLine.getM_Product_ID());
temp = cr.getAcctBalance();
String documentBaseTypeInvoice = DB.getSQLValueString(m_invoiceLine.get_TrxName(), "SELECT DocBaseType FROM C_DocType WHERE C_DocType_ID=?", m_invoiceLine.getParent().getC_DocType_ID());
BigDecimal quantityInvoice = MDocType.DOCBASETYPE_APInvoice.equals(documentBaseTypeInvoice) ? getQty().negate() : getQty();
cr.setQty(quantityInvoice);
// Set AmtAcctCr/Dr from Invoice (sets also Project)
if (as.isAccrual() && !// Amt updated
cr.updateReverseLine(// Amt updated
MInvoice.Table_ID, m_invoiceLine.getC_Invoice_ID(), m_invoiceLine.getC_InvoiceLine_ID(), quantityInvoice, multiplier)) {
p_Error = "Invoice not posted yet";
return null;
}
log.fine("DR - Amt(" + temp + "->" + cr.getAcctBalance() + ") - " + cr.toString());
} else // Cash Acct
{
MInvoice invoice = m_invoiceLine.getParent();
if (as.getC_Currency_ID() != invoice.getC_Currency_ID())
LineNetAmt = MConversionRate.convert(getCtx(), LineNetAmt, invoice.getC_Currency_ID(), as.getC_Currency_ID(), invoice.getDateAcct(), invoice.getC_ConversionType_ID(), invoice.getAD_Client_ID(), invoice.getAD_Org_ID());
cr = fact.createLine(null, expense, as.getC_Currency_ID(), null, LineNetAmt);
cr.setQty(getQty().multiply(multiplier).negate());
}
cr.setC_Activity_ID(m_invoiceLine.getC_Activity_ID());
cr.setC_Campaign_ID(m_invoiceLine.getC_Campaign_ID());
cr.setC_Project_ID(m_invoiceLine.getC_Project_ID());
cr.setC_ProjectPhase_ID(m_invoiceLine.getC_ProjectPhase_ID());
cr.setC_ProjectTask_ID(m_invoiceLine.getC_ProjectTask_ID());
cr.setC_UOM_ID(m_invoiceLine.getC_UOM_ID());
cr.setUser1_ID(m_invoiceLine.getUser1_ID());
cr.setUser2_ID(m_invoiceLine.getUser2_ID());
cr.setUser3_ID(m_invoiceLine.getUser3_ID());
cr.setUser4_ID(m_invoiceLine.getUser4_ID());
//see also Fact.java: checking for isMultiCurrency()
if (dr.getC_Currency_ID() != cr.getC_Currency_ID())
setIsMultiCurrency(true);
//end AZ
// Avoid usage of clearing accounts
// If both accounts Not Invoiced Receipts and Inventory Clearing are equal
// then remove the posting
// not_invoiced_receipts
MAccount acct_db = dr.getAccount();
// inventory_clearing
MAccount acct_cr = cr.getAccount();
if ((!as.isPostIfClearingEqual()) && acct_db.equals(acct_cr) && (!isInterOrg)) {
BigDecimal debit = dr.getAmtSourceDr();
BigDecimal credit = cr.getAmtSourceCr();
if (debit.compareTo(credit) == 0) {
fact.remove(dr);
fact.remove(cr);
}
}
// End Avoid usage of clearing accounts
// Invoice Price Variance difference
BigDecimal ipv = cr.getAcctBalance().add(dr.getAcctBalance()).negate();
if (ipv.compareTo(Env.ZERO) == 0) {
facts.add(fact);
return facts;
}
if (!MCostType.COSTINGMETHOD_AverageInvoice.equals(ct.getCostingMethod())) {
int ACCTTYPE_P = 0;
if (MCostType.COSTINGMETHOD_StandardCosting.equals(ct.getCostingMethod()) || MCostType.COSTINGMETHOD_AverageInvoice.equals(ct.getCostingMethod()))
ACCTTYPE_P = ProductCost.ACCTTYPE_P_IPV;
else
ACCTTYPE_P = ProductCost.ACCTTYPE_P_Asset;
FactLine pv = fact.createLine(null, m_pc.getAccount(ACCTTYPE_P, as), as.getC_Currency_ID(), ipv);
pv.setC_Activity_ID(m_invoiceLine.getC_Activity_ID());
pv.setC_Campaign_ID(m_invoiceLine.getC_Campaign_ID());
pv.setC_Project_ID(m_invoiceLine.getC_Project_ID());
pv.setC_ProjectPhase_ID(m_invoiceLine.getC_ProjectPhase_ID());
pv.setC_ProjectTask_ID(m_invoiceLine.getC_ProjectTask_ID());
pv.setC_UOM_ID(m_invoiceLine.getC_UOM_ID());
pv.setUser1_ID(m_invoiceLine.getUser1_ID());
pv.setUser2_ID(m_invoiceLine.getUser2_ID());
pv.setUser3_ID(m_invoiceLine.getUser3_ID());
pv.setUser4_ID(m_invoiceLine.getUser4_ID());
//
} else {
BigDecimal costs = MCostDetail.getByDocLineMatchInv(m_invoiceLine, m_receiptLine, as.getC_AcctSchema_ID(), as.getM_CostType_ID());
FactLine pv = fact.createLine(null, m_pc.getAccount(ProductCost.ACCTTYPE_P_Asset, as), as.getC_Currency_ID(), costs);
if (pv != null) {
pv.setC_Activity_ID(m_invoiceLine.getC_Activity_ID());
pv.setC_Campaign_ID(m_invoiceLine.getC_Campaign_ID());
pv.setC_Project_ID(m_invoiceLine.getC_Project_ID());
pv.setC_ProjectPhase_ID(m_invoiceLine.getC_ProjectPhase_ID());
pv.setC_ProjectTask_ID(m_invoiceLine.getC_ProjectTask_ID());
pv.setC_UOM_ID(m_invoiceLine.getC_UOM_ID());
pv.setUser1_ID(m_invoiceLine.getUser1_ID());
pv.setUser2_ID(m_invoiceLine.getUser2_ID());
pv.setUser3_ID(m_invoiceLine.getUser3_ID());
pv.setUser4_ID(m_invoiceLine.getUser4_ID());
}
BigDecimal diff = ipv.subtract(costs);
MInvoice m_invoice = m_invoiceLine.getParent();
if (diff.compareTo(Env.ZERO) != 0) {
FactLine diffline = fact.createLine(null, m_pc.getAccount(ProductCost.ACCTTYPE_P_CostAdjustment, as), as.getC_Currency_ID(), diff);
if (diffline != null) {
diffline.setC_Activity_ID(m_invoiceLine.getC_Activity_ID());
diffline.setC_Project_ID(m_invoiceLine.getC_Project_ID());
diffline.setC_ProjectPhase_ID(m_invoiceLine.getC_ProjectPhase_ID());
diffline.setC_ProjectTask_ID(m_invoiceLine.getC_ProjectTask_ID());
diffline.setC_UOM_ID(m_invoiceLine.getC_UOM_ID());
diffline.setUser1_ID(m_invoiceLine.getUser1_ID());
diffline.setUser2_ID(m_invoiceLine.getUser2_ID());
diffline.setUser3_ID(m_invoiceLine.getUser3_ID());
diffline.setUser4_ID(m_invoiceLine.getUser4_ID());
}
}
}
log.fine("IPV=" + ipv + "; Balance=" + fact.getSourceBalance());
facts.add(fact);
/** Commitment release ****/
if (as.isAccrual() && as.isCreatePOCommitment()) {
fact = Doc_Order.getCommitmentRelease(as, this, getQty(), m_invoiceLine.getC_InvoiceLine_ID(), Env.ONE);
if (fact == null)
return null;
facts.add(fact);
}
return facts;
}
use of org.compiere.model.MAccount in project adempiere by adempiere.
the class Doc_AllocationTax method createRealizedGainLoss.
// getCashAcct
/**************************************************************************
* Create Realized Gain & Loss.
* Compares the Accounted Amount of the Invoice to the
* Accounted Amount of the Allocation
* @param as accounting schema
* @param fact fact
* @param acct account
* @param invoice invoice
* @param allocationSource source amt
* @param allocationAccounted acct amt
* @return Error Message or null if OK
*/
private String createRealizedGainLoss(DocLine line, MAcctSchema as, Fact fact, MAccount acct, MInvoice invoice, BigDecimal allocationSource, BigDecimal allocationAccounted) {
BigDecimal invoiceSource = null;
BigDecimal invoiceAccounted = null;
//
String sql = "SELECT " + (invoice.isSOTrx() ? // so
"SUM(AmtSourceDr), SUM(AmtAcctDr)" : // po
"SUM(AmtSourceCr), SUM(AmtAcctCr)") + " FROM Fact_Acct " + // Invoice
"WHERE AD_Table_ID=318 AND Record_ID=?" + " AND C_AcctSchema_ID=?" + " AND PostingType='A'";
//AND C_Currency_ID=102
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, getTrxName());
pstmt.setInt(1, invoice.getC_Invoice_ID());
pstmt.setInt(2, as.getC_AcctSchema_ID());
rs = pstmt.executeQuery();
if (rs.next()) {
invoiceSource = rs.getBigDecimal(1);
invoiceAccounted = rs.getBigDecimal(2);
}
} catch (Exception e) {
log.log(Level.SEVERE, sql, e);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
// Requires that Invoice is Posted
if (invoiceSource == null || invoiceAccounted == null)
return "Gain/Loss - Invoice not posted yet";
//
String description = "Invoice=(" + invoice.getC_Currency_ID() + ")" + invoiceSource + "/" + invoiceAccounted + " - Allocation=(" + getC_Currency_ID() + ")" + allocationSource + "/" + allocationAccounted;
log.fine(description);
// Allocation not Invoice Currency
if (getC_Currency_ID() != invoice.getC_Currency_ID()) {
BigDecimal allocationSourceNew = MConversionRate.convert(getCtx(), allocationSource, getC_Currency_ID(), invoice.getC_Currency_ID(), getDateAcct(), invoice.getC_ConversionType_ID(), invoice.getAD_Client_ID(), invoice.getAD_Org_ID());
if (allocationSourceNew == null)
return "Gain/Loss - No Conversion from Allocation->Invoice";
String d2 = "Allocation=(" + getC_Currency_ID() + ")" + allocationSource + "->(" + invoice.getC_Currency_ID() + ")" + allocationSourceNew;
log.fine(d2);
description += " - " + d2;
allocationSource = allocationSourceNew;
}
// gain is negative
BigDecimal acctDifference = null;
// Full Payment in currency
if (allocationSource.compareTo(invoiceSource) == 0) {
// gain is negative
acctDifference = invoiceAccounted.subtract(allocationAccounted);
String d2 = "(full) = " + acctDifference;
log.fine(d2);
description += " - " + d2;
} else // partial or MC
{
// percent of total payment
double multiplier = allocationSource.doubleValue() / invoiceSource.doubleValue();
// Reduce Orig Invoice Accounted
invoiceAccounted = invoiceAccounted.multiply(new BigDecimal(multiplier));
// Difference based on percentage of Orig Invoice
// gain is negative
acctDifference = invoiceAccounted.subtract(allocationAccounted);
// ignore Tolerance
if (acctDifference.abs().compareTo(TOLERANCE) < 0)
acctDifference = Env.ZERO;
// Round
int precision = as.getStdPrecision();
if (acctDifference.scale() > precision)
acctDifference = acctDifference.setScale(precision, BigDecimal.ROUND_HALF_UP);
String d2 = "(partial) = " + acctDifference + " - Multiplier=" + multiplier;
log.fine(d2);
description += " - " + d2;
}
if (acctDifference.signum() == 0) {
log.fine("No Difference");
return null;
}
MAccount gain = MAccount.get(as.getCtx(), as.getAcctSchemaDefault().getRealizedGain_Acct());
MAccount loss = MAccount.get(as.getCtx(), as.getAcctSchemaDefault().getRealizedLoss_Acct());
//
if (invoice.isSOTrx()) {
FactLine fl = fact.createLine(line, loss, gain, as.getC_Currency_ID(), acctDifference);
fl.setDescription(description);
fact.createLine(line, acct, as.getC_Currency_ID(), acctDifference.negate());
fl.setDescription(description);
} else {
fact.createLine(line, acct, as.getC_Currency_ID(), acctDifference);
FactLine fl = fact.createLine(line, loss, gain, as.getC_Currency_ID(), acctDifference.negate());
}
return null;
}
use of org.compiere.model.MAccount in project adempiere by adempiere.
the class Doc_BankStatement method createFacts.
// getBalance
/**
* Create Facts (the accounting logic) for
* CMB.
* <pre>
* BankAsset DR CR (Statement)
* BankInTransit DR CR (Payment)
* Charge DR (Charge)
* Interest DR CR (Interest)
* </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);
// boolean isInterOrg = isInterOrg(as);
// Header -- there may be different currency amounts
FactLine fl = null;
// Bank Account Org
int AD_Org_ID = getBank_Org_ID();
// Lines
for (int i = 0; i < p_lines.length; i++) {
DocLine_Bank line = (DocLine_Bank) p_lines[i];
int C_BPartner_ID = line.getC_BPartner_ID();
// Avoid usage of clearing accounts
// If both accounts BankAsset and BankInTransit are equal
// then remove the posting
MAccount acct_bank_asset = getAccount(Doc.ACCTTYPE_BankAsset, as);
MAccount acct_bank_in_transit = getAccount(Doc.ACCTTYPE_BankInTransit, as);
// don't validate interorg on banks for this - normally banks are balanced by orgs
if ((!as.isPostIfClearingEqual()) && acct_bank_asset.equals(acct_bank_in_transit)) {
// Not using clearing accounts
// just post the difference (if any)
BigDecimal amt_stmt_minus_trx = line.getStmtAmt().subtract(line.getTrxAmt());
if (amt_stmt_minus_trx.compareTo(Env.ZERO) != 0) {
// BankAsset DR CR (Statement minus Payment)
fl = fact.createLine(line, getAccount(Doc.ACCTTYPE_BankAsset, as), line.getC_Currency_ID(), amt_stmt_minus_trx);
if (fl != null && AD_Org_ID != 0)
fl.setAD_Org_ID(AD_Org_ID);
if (fl != null && C_BPartner_ID != 0)
fl.setC_BPartner_ID(C_BPartner_ID);
}
} else {
// Normal Adempiere behavior -- unchanged if using clearing accounts
// BankAsset DR CR (Statement)
fl = fact.createLine(line, getAccount(Doc.ACCTTYPE_BankAsset, as), line.getC_Currency_ID(), line.getStmtAmt());
if (fl != null && AD_Org_ID != 0)
fl.setAD_Org_ID(AD_Org_ID);
if (fl != null && C_BPartner_ID != 0)
fl.setC_BPartner_ID(C_BPartner_ID);
// BankInTransit DR CR (Payment)
fl = fact.createLine(line, getAccount(Doc.ACCTTYPE_BankInTransit, as), line.getC_Currency_ID(), line.getTrxAmt().negate());
if (fl != null) {
if (C_BPartner_ID != 0)
fl.setC_BPartner_ID(C_BPartner_ID);
if (AD_Org_ID != 0)
fl.setAD_Org_ID(AD_Org_ID);
else
// from payment
fl.setAD_Org_ID(line.getAD_Org_ID(true));
}
}
// Charge DR (Charge)
if (line.getChargeAmt().compareTo(Env.ZERO) > 0) {
fl = fact.createLine(line, line.getChargeAccount(as, line.getChargeAmt().negate()), line.getC_Currency_ID(), null, line.getChargeAmt());
} else {
fl = fact.createLine(line, line.getChargeAccount(as, line.getChargeAmt().negate()), line.getC_Currency_ID(), line.getChargeAmt().negate(), null);
}
if (fl != null && C_BPartner_ID != 0)
fl.setC_BPartner_ID(C_BPartner_ID);
// Interest DR CR (Interest)
if (line.getInterestAmt().signum() < 0)
fl = fact.createLine(line, getAccount(Doc.ACCTTYPE_InterestExp, as), getAccount(Doc.ACCTTYPE_InterestExp, as), line.getC_Currency_ID(), line.getInterestAmt().negate());
else
fl = fact.createLine(line, getAccount(Doc.ACCTTYPE_InterestRev, as), getAccount(Doc.ACCTTYPE_InterestRev, as), line.getC_Currency_ID(), line.getInterestAmt().negate());
if (fl != null && C_BPartner_ID != 0)
fl.setC_BPartner_ID(C_BPartner_ID);
//
// fact.createTaxCorrection();
}
//
ArrayList<Fact> facts = new ArrayList<Fact>();
facts.add(fact);
return facts;
}
use of org.compiere.model.MAccount in project adempiere by adempiere.
the class Doc_AllocationTax method createEntries.
// getLineCount
/**
* Create Accounting Entries
* @param as account schema
* @param fact fact to add lines
* @param line line
* @return true if created
*/
public boolean createEntries(MAcctSchema as, Fact fact, DocLine line) {
// get total index (the Receivables/Liabilities line)
BigDecimal total = Env.ZERO;
for (int i = 0; i < m_facts.size(); i++) {
MFactAcct factAcct = (MFactAcct) m_facts.get(i);
if (factAcct.getAmtSourceDr().compareTo(total) > 0) {
total = factAcct.getAmtSourceDr();
m_totalIndex = i;
}
if (factAcct.getAmtSourceCr().compareTo(total) > 0) {
total = factAcct.getAmtSourceCr();
m_totalIndex = i;
}
}
MFactAcct factAcct = (MFactAcct) m_facts.get(m_totalIndex);
log.info("Total Invoice = " + total + " - " + factAcct);
int precision = as.getStdPrecision();
for (int i = 0; i < m_facts.size(); i++) {
// No Tax Line
if (i == m_totalIndex)
continue;
factAcct = (MFactAcct) m_facts.get(i);
log.info(i + ": " + factAcct);
// Create Tax Account
MAccount taxAcct = factAcct.getMAccount();
if (taxAcct == null || taxAcct.get_ID() == 0) {
log.severe("Tax Account not found/created");
return false;
}
// Discount Amount
if (m_DiscountAmt.signum() != 0) {
// Original Tax is DR - need to correct it CR
if (Env.ZERO.compareTo(factAcct.getAmtSourceDr()) != 0) {
BigDecimal amount = calcAmount(factAcct.getAmtSourceDr(), total, m_DiscountAmt, precision);
if (amount.signum() != 0) {
//for sales actions
if (m_IsSOTrx) {
fact.createLine(line, m_DiscountAccount, as.getC_Currency_ID(), amount, null);
fact.createLine(line, taxAcct, as.getC_Currency_ID(), null, amount);
} else {
//for purchase actions
fact.createLine(line, m_DiscountAccount, as.getC_Currency_ID(), amount.negate(), null);
fact.createLine(line, taxAcct, as.getC_Currency_ID(), null, amount.negate());
}
}
} else // Original Tax is CR - need to correct it DR
{
BigDecimal amount = calcAmount(factAcct.getAmtSourceCr(), total, m_DiscountAmt, precision);
if (amount.signum() != 0) {
// for sales actions
if (m_IsSOTrx) {
fact.createLine(line, taxAcct, as.getC_Currency_ID(), amount, null);
fact.createLine(line, m_DiscountAccount, as.getC_Currency_ID(), null, amount);
} else {
fact.createLine(line, taxAcct, as.getC_Currency_ID(), amount.negate(), null);
fact.createLine(line, m_DiscountAccount, as.getC_Currency_ID(), null, amount.negate());
}
}
}
}
// WriteOff Amount
if (m_WriteOffAmt.signum() != 0) {
// Original Tax is DR - need to correct it CR
if (Env.ZERO.compareTo(factAcct.getAmtSourceDr()) != 0) {
BigDecimal amount = calcAmount(factAcct.getAmtSourceDr(), total, m_WriteOffAmt, precision);
if (amount.signum() != 0) {
fact.createLine(line, m_WriteOffAccount, as.getC_Currency_ID(), amount, null);
fact.createLine(line, taxAcct, as.getC_Currency_ID(), null, amount);
}
} else // Original Tax is CR - need to correct it DR
{
BigDecimal amount = calcAmount(factAcct.getAmtSourceCr(), total, m_WriteOffAmt, precision);
if (amount.signum() != 0) {
fact.createLine(line, taxAcct, as.getC_Currency_ID(), amount, null);
fact.createLine(line, m_WriteOffAccount, as.getC_Currency_ID(), null, amount);
}
}
}
// WriteOff
}
// for all lines
return true;
}
Aggregations