use of org.compiere.model.MAccount in project adempiere by adempiere.
the class VAccountDialog method action_Save.
// action_Find
/**
* Create/Save Account
*/
private void action_Save() {
log.info("");
/**
* Check completeness (mandatory fields) ... and for duplicates
*/
StringBuffer sb = new StringBuffer();
StringBuffer sql = new StringBuffer("SELECT C_ValidCombination_ID, Alias FROM C_ValidCombination WHERE ");
Object value = null;
if (s_AcctSchema.isHasAlias()) {
value = f_Alias.getValue().toString();
if (value == null)
sb.append(Msg.translate(Env.getCtx(), "Alias")).append(", ");
}
MAcctSchemaElement[] elements = s_AcctSchema.getAcctSchemaElements();
for (int i = 0; i < elements.length; i++) {
MAcctSchemaElement ase = elements[i];
String type = ase.getElementType();
//
if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Organization)) {
value = f_AD_Org_ID.getValue();
sql.append("AD_Org_ID");
if (value == null)
sql.append(" IS NULL AND ");
else
sql.append("=").append(value).append(" AND ");
} else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Account)) {
value = f_Account_ID.getValue();
sql.append("Account_ID");
if (value == null)
sql.append(" IS NULL AND ");
else
sql.append("=").append(value).append(" AND ");
} else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_SubAccount)) {
value = f_SubAcct_ID.getValue();
sql.append("C_SubAcct_ID");
if (value == null)
sql.append(" IS NULL AND ");
else
sql.append("=").append(value).append(" AND ");
} else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Product)) {
value = f_M_Product_ID.getValue();
sql.append("M_Product_ID");
if (value == null)
sql.append(" IS NULL AND ");
else
sql.append("=").append(value).append(" AND ");
} else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_BPartner)) {
value = f_C_BPartner_ID.getValue();
sql.append("C_BPartner_ID");
if (value == null)
sql.append(" IS NULL AND ");
else
sql.append("=").append(value).append(" AND ");
} else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Campaign)) {
value = f_C_Campaign_ID.getValue();
sql.append("C_Campaign_ID");
if (value == null)
sql.append(" IS NULL AND ");
else
sql.append("=").append(value).append(" AND ");
} else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_LocationFrom)) {
value = f_C_LocFrom_ID.getValue();
sql.append("C_LocFrom_ID");
if (value == null)
sql.append(" IS NULL AND ");
else
sql.append("=").append(value).append(" AND ");
} else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_LocationTo)) {
value = f_C_LocTo_ID.getValue();
sql.append("C_LocTo_ID");
if (value == null)
sql.append(" IS NULL AND ");
else
sql.append("=").append(value).append(" AND ");
} else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Project)) {
value = f_C_Project_ID.getValue();
sql.append("C_Project_ID");
if (value == null)
sql.append(" IS NULL AND ");
else
sql.append("=").append(value).append(" AND ");
} else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_SalesRegion)) {
value = f_C_SalesRegion_ID.getValue();
sql.append("C_SalesRegion_ID");
if (value == null)
sql.append(" IS NULL AND ");
else
sql.append("=").append(value).append(" AND ");
} else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_OrgTrx)) {
value = f_AD_OrgTrx_ID.getValue();
sql.append("AD_OrgTrx_ID");
if (value == null)
sql.append(" IS NULL AND ");
else
sql.append("=").append(value).append(" AND ");
} else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Activity)) {
value = f_C_Activity_ID.getValue();
sql.append("C_Activity_ID");
if (value == null)
sql.append(" IS NULL AND ");
else
sql.append("=").append(value).append(" AND ");
} else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_UserList1)) {
value = f_User1_ID.getValue();
sql.append("User1_ID");
if (value == null)
sql.append(" IS NULL AND ");
else
sql.append("=").append(value).append(" AND ");
} else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_UserList2)) {
value = f_User2_ID.getValue();
sql.append("User2_ID");
if (value == null)
sql.append(" IS NULL AND ");
else
sql.append("=").append(value).append(" AND ");
} else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_UserList3)) {
value = f_User3_ID.getValue();
sql.append("User3_ID");
if (value == null)
sql.append(" IS NULL AND ");
else
sql.append("=").append(value).append(" AND ");
} else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_UserList4)) {
value = f_User4_ID.getValue();
sql.append("User4_ID");
if (value == null)
sql.append(" IS NULL AND ");
else
sql.append("=").append(value).append(" AND ");
}
//
if (ase.isMandatory() && value == null)
sb.append(ase.getName()).append(", ");
}
if (sb.length() != 0) {
ADialog.error(m_WindowNo, this, "FillMandatory", sb.substring(0, sb.length() - 2));
return;
}
if (f_AD_Org_ID == null || f_AD_Org_ID.getValue() == null) {
ADialog.error(m_WindowNo, this, "FillMandatory", Msg.getElement(Env.getCtx(), "AD_Org_ID"));
return;
}
if (f_Account_ID == null || f_Account_ID.getValue() == null) {
ADialog.error(m_WindowNo, this, "FillMandatory", Msg.getElement(Env.getCtx(), "Account_ID"));
return;
}
/**
* Check if already exists
*/
sql.append("AD_Client_ID=? AND C_AcctSchema_ID=?");
log.fine("Check = " + sql.toString());
int IDvalue = 0;
String Alias = null;
try {
PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null);
pstmt.setInt(1, m_AD_Client_ID);
pstmt.setInt(2, s_AcctSchema.getC_AcctSchema_ID());
ResultSet rs = pstmt.executeQuery();
if (rs.next()) {
IDvalue = rs.getInt(1);
Alias = rs.getString(2);
}
rs.close();
pstmt.close();
} catch (SQLException e) {
log.log(Level.SEVERE, sql.toString(), e);
IDvalue = 0;
}
log.fine("ID=" + IDvalue + ", Alias=" + Alias);
if (Alias == null)
Alias = "";
// We have an account like this already - check alias
if (IDvalue != 0 && s_AcctSchema.isHasAlias() && !f_Alias.getValue().toString().equals(Alias)) {
sql = new StringBuffer("UPDATE C_ValidCombination SET Alias=");
if (f_Alias.getValue().toString().length() == 0)
sql.append("NULL");
else
sql.append("'").append(f_Alias.getValue()).append("'");
sql.append(" WHERE C_ValidCombination_ID=").append(IDvalue);
int i = 0;
try {
java.sql.PreparedStatement stmt = DB.prepareStatement(sql.toString(), ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE, null);
i = stmt.executeUpdate();
stmt.close();
} catch (SQLException e) {
log.log(Level.SEVERE, sql.toString(), e);
}
if (i == 0)
ADialog.error(m_WindowNo, this, "AccountNotUpdated");
}
// load and display
if (IDvalue != 0) {
loadInfo(IDvalue, s_AcctSchema.getC_AcctSchema_ID());
action_Find(false);
return;
}
log.config("New");
Alias = null;
if (f_Alias != null)
Alias = f_Alias.getValue().toString();
int C_SubAcct_ID = 0;
if (f_SubAcct_ID != null && f_SubAcct_ID.getValue() != null)
C_SubAcct_ID = ((Integer) f_SubAcct_ID.getValue()).intValue();
int M_Product_ID = 0;
if (f_M_Product_ID != null && f_M_Product_ID.getValue() != null)
M_Product_ID = ((Integer) f_M_Product_ID.getValue()).intValue();
int C_BPartner_ID = 0;
if (f_C_BPartner_ID != null && f_C_BPartner_ID.getValue() != null)
C_BPartner_ID = ((Integer) f_C_BPartner_ID.getValue()).intValue();
int AD_OrgTrx_ID = 0;
if (f_AD_OrgTrx_ID != null && f_AD_OrgTrx_ID.getValue() != null)
AD_OrgTrx_ID = ((Integer) f_AD_OrgTrx_ID.getValue()).intValue();
int C_LocFrom_ID = 0;
if (f_C_LocFrom_ID != null && f_C_LocFrom_ID.getValue() != null)
C_LocFrom_ID = ((Integer) f_C_LocFrom_ID.getValue()).intValue();
int C_LocTo_ID = 0;
if (f_C_LocTo_ID != null && f_C_LocTo_ID.getValue() != null)
C_LocTo_ID = ((Integer) f_C_LocTo_ID.getValue()).intValue();
int C_SRegion_ID = 0;
if (f_C_SalesRegion_ID != null && f_C_SalesRegion_ID.getValue() != null)
C_SRegion_ID = ((Integer) f_C_SalesRegion_ID.getValue()).intValue();
int C_Project_ID = 0;
if (f_C_Project_ID != null && f_C_Project_ID.getValue() != null)
C_Project_ID = ((Integer) f_C_Project_ID.getValue()).intValue();
int C_Campaign_ID = 0;
if (f_C_Campaign_ID != null && f_C_Campaign_ID.getValue() != null)
C_Campaign_ID = ((Integer) f_C_Campaign_ID.getValue()).intValue();
int C_Activity_ID = 0;
if (f_C_Activity_ID != null && f_C_Activity_ID.getValue() != null)
C_Activity_ID = ((Integer) f_C_Activity_ID.getValue()).intValue();
int User1_ID = 0;
if (f_User1_ID != null && f_User1_ID.getValue() != null)
User1_ID = ((Integer) f_User1_ID.getValue()).intValue();
int User2_ID = 0;
if (f_User2_ID != null && f_User2_ID.getValue() != null)
User2_ID = ((Integer) f_User2_ID.getValue()).intValue();
int User3_ID = 0;
if (f_User3_ID != null && f_User3_ID.getValue() != null)
User3_ID = ((Integer) f_User3_ID.getValue()).intValue();
int User4_ID = 0;
if (f_User4_ID != null && f_User4_ID.getValue() != null)
User4_ID = ((Integer) f_User4_ID.getValue()).intValue();
MAccount acct = MAccount.get(Env.getCtx(), m_AD_Client_ID, ((Integer) f_AD_Org_ID.getValue()).intValue(), s_AcctSchema.getC_AcctSchema_ID(), ((Integer) f_Account_ID.getValue()).intValue(), C_SubAcct_ID, M_Product_ID, C_BPartner_ID, AD_OrgTrx_ID, C_LocFrom_ID, C_LocTo_ID, C_SRegion_ID, C_Project_ID, C_Campaign_ID, C_Activity_ID, User1_ID, User2_ID, User3_ID, User4_ID, 0, 0, null);
if (acct != null && acct.get_ID() == 0)
acct.saveEx();
// Show Info
if (acct == null || acct.get_ID() == 0)
loadInfo(0, 0);
else {
// Update Account with optional Alias
if (Alias != null && Alias.length() > 0) {
acct.setAlias(Alias);
acct.saveEx();
}
loadInfo(acct.get_ID(), s_AcctSchema.getC_AcctSchema_ID());
}
action_Find(false);
}
use of org.compiere.model.MAccount in project adempiere by adempiere.
the class AcctSchemaCopyAcct method copyDefault.
// copyGL
/**
* Copy Default
* @param targetAS target
* @throws Exception
*/
private void copyDefault(MAcctSchema targetAS) throws Exception {
MAcctSchemaDefault source = MAcctSchemaDefault.get(getCtx(), p_SourceAcctSchema_ID);
MAcctSchemaDefault target = new MAcctSchemaDefault(getCtx(), 0, get_TrxName());
target.setC_AcctSchema_ID(p_TargetAcctSchema_ID);
target.setC_AcctSchema_ID(p_TargetAcctSchema_ID);
ArrayList<KeyNamePair> list = source.getAcctInfo();
for (int i = 0; i < list.size(); i++) {
KeyNamePair pp = list.get(i);
int sourceC_ValidCombination_ID = pp.getKey();
String columnName = pp.getName();
MAccount sourceAccount = MAccount.get(getCtx(), sourceC_ValidCombination_ID);
MAccount targetAccount = createAccount(targetAS, sourceAccount);
target.setValue(columnName, new Integer(targetAccount.getC_ValidCombination_ID()));
}
if (!target.save())
throw new AdempiereSystemError("Could not Save Default");
}
use of org.compiere.model.MAccount in project adempiere by adempiere.
the class Doc method getAccount.
// getAccount_ID
/**
* Get the account for Accounting Schema
* @param AcctType see ACCTTYPE_*
* @param as accounting schema
* @return Account
*/
public final MAccount getAccount(int AcctType, MAcctSchema as) {
int C_ValidCombination_ID = getValidCombination_ID(AcctType, as);
if (C_ValidCombination_ID == 0)
return null;
// Return Account
MAccount acct = MAccount.get(as.getCtx(), C_ValidCombination_ID);
return acct;
}
use of org.compiere.model.MAccount in project adempiere by adempiere.
the class Doc_Invoice method createFacts.
// getBalance
/**
* Create Facts (the accounting logic) for
* ARI, ARC, ARF, API, APC.
* <pre>
* ARI, ARF
* Receivables DR
* Charge CR
* TaxDue CR
* Revenue CR
*
* ARC
* Receivables CR
* Charge DR
* TaxDue DR
* Revenue RR
*
* API
* Payables CR
* Charge DR
* TaxCredit DR
* Expense DR
*
* APC
* Payables DR
* Charge CR
* TaxCredit CR
* Expense CR
* </pre>
* @param as accounting schema
* @return Fact
*/
public ArrayList<Fact> createFacts(MAcctSchema as) {
//
ArrayList<Fact> facts = new ArrayList<Fact>();
// create Fact Header
Fact fact = new Fact(this, as, Fact.POST_Actual);
// Cash based accounting
if (!as.isAccrual())
return facts;
// ** ARI, ARF
if (getDocumentType().equals(DOCTYPE_ARInvoice) || getDocumentType().equals(DOCTYPE_ARProForma)) {
BigDecimal grossAmt = getAmount(Doc.AMTTYPE_Gross);
BigDecimal serviceAmt = Env.ZERO;
// Header Charge CR
BigDecimal amt = getAmount(Doc.AMTTYPE_Charge);
if (amt != null && amt.signum() != 0)
fact.createLine(null, getAccount(Doc.ACCTTYPE_Charge, as), getC_Currency_ID(), null, amt);
// TaxDue CR
for (int i = 0; i < m_taxes.length; i++) {
amt = m_taxes[i].getAmount();
if (amt != null) {
FactLine tl = fact.createLine(null, m_taxes[i].getAccount(DocTax.ACCTTYPE_TaxDue, as), getC_Currency_ID(), null, amt);
if (tl != null)
tl.setC_Tax_ID(m_taxes[i].getC_Tax_ID());
}
}
// Revenue CR
for (int i = 0; i < p_lines.length; i++) {
amt = p_lines[i].getAmtSource();
BigDecimal dAmt = null;
if (as.isTradeDiscountPosted()) {
BigDecimal discount = p_lines[i].getDiscount();
if (discount != null && discount.signum() != 0) {
amt = amt.add(discount);
dAmt = discount;
fact.createLine(p_lines[i], p_lines[i].getAccount(ProductCost.ACCTTYPE_P_TDiscountGrant, as), getC_Currency_ID(), dAmt, null);
}
}
fact.createLine(p_lines[i], p_lines[i].getAccount(ProductCost.ACCTTYPE_P_Revenue, as), getC_Currency_ID(), null, amt);
if (!p_lines[i].isItem()) {
grossAmt = grossAmt.subtract(amt);
serviceAmt = serviceAmt.add(amt);
}
}
// Set Locations
FactLine[] fLines = fact.getLines();
for (int i = 0; i < fLines.length; i++) {
if (fLines[i] != null) {
// from Loc
fLines[i].setLocationFromOrg(fLines[i].getAD_Org_ID(), true);
// to Loc
fLines[i].setLocationFromBPartner(getC_BPartner_Location_ID(), false);
}
}
// Receivables DR
int receivables_ID = getValidCombination_ID(Doc.ACCTTYPE_C_Receivable, as);
int receivablesServices_ID = getValidCombination_ID(Doc.ACCTTYPE_C_Receivable_Services, as);
if (m_allLinesItem || !as.isPostServices() || receivables_ID == receivablesServices_ID) {
grossAmt = getAmount(Doc.AMTTYPE_Gross);
serviceAmt = Env.ZERO;
} else if (m_allLinesService) {
serviceAmt = getAmount(Doc.AMTTYPE_Gross);
grossAmt = Env.ZERO;
}
if (grossAmt.signum() != 0)
fact.createLine(null, MAccount.get(getCtx(), receivables_ID), getC_Currency_ID(), grossAmt, null);
if (serviceAmt.signum() != 0)
fact.createLine(null, MAccount.get(getCtx(), receivablesServices_ID), getC_Currency_ID(), serviceAmt, null);
} else // ARC
if (getDocumentType().equals(DOCTYPE_ARCredit)) {
BigDecimal grossAmt = getAmount(Doc.AMTTYPE_Gross);
BigDecimal serviceAmt = Env.ZERO;
// Header Charge DR
BigDecimal amt = getAmount(Doc.AMTTYPE_Charge);
if (amt != null && amt.signum() != 0)
fact.createLine(null, getAccount(Doc.ACCTTYPE_Charge, as), getC_Currency_ID(), amt, null);
// TaxDue DR
for (int i = 0; i < m_taxes.length; i++) {
amt = m_taxes[i].getAmount();
if (amt != null) {
FactLine tl = fact.createLine(null, m_taxes[i].getAccount(DocTax.ACCTTYPE_TaxDue, as), getC_Currency_ID(), amt, null);
if (tl != null)
tl.setC_Tax_ID(m_taxes[i].getC_Tax_ID());
}
}
// Revenue CR
for (int i = 0; i < p_lines.length; i++) {
amt = p_lines[i].getAmtSource();
BigDecimal dAmt = null;
if (as.isTradeDiscountPosted()) {
BigDecimal discount = p_lines[i].getDiscount();
if (discount != null && discount.signum() != 0) {
amt = amt.add(discount);
dAmt = discount;
fact.createLine(p_lines[i], p_lines[i].getAccount(ProductCost.ACCTTYPE_P_TDiscountGrant, as), getC_Currency_ID(), null, dAmt);
}
}
fact.createLine(p_lines[i], p_lines[i].getAccount(ProductCost.ACCTTYPE_P_Revenue, as), getC_Currency_ID(), amt, null);
if (!p_lines[i].isItem()) {
grossAmt = grossAmt.subtract(amt);
serviceAmt = serviceAmt.add(amt);
}
}
// Set Locations
FactLine[] fLines = fact.getLines();
for (int i = 0; i < fLines.length; i++) {
if (fLines[i] != null) {
// from Loc
fLines[i].setLocationFromOrg(fLines[i].getAD_Org_ID(), true);
// to Loc
fLines[i].setLocationFromBPartner(getC_BPartner_Location_ID(), false);
}
}
// Receivables CR
int receivables_ID = getValidCombination_ID(Doc.ACCTTYPE_C_Receivable, as);
int receivablesServices_ID = getValidCombination_ID(Doc.ACCTTYPE_C_Receivable_Services, as);
if (m_allLinesItem || !as.isPostServices() || receivables_ID == receivablesServices_ID) {
grossAmt = getAmount(Doc.AMTTYPE_Gross);
serviceAmt = Env.ZERO;
} else if (m_allLinesService) {
serviceAmt = getAmount(Doc.AMTTYPE_Gross);
grossAmt = Env.ZERO;
}
if (grossAmt.signum() != 0)
fact.createLine(null, MAccount.get(getCtx(), receivables_ID), getC_Currency_ID(), null, grossAmt);
if (serviceAmt.signum() != 0)
fact.createLine(null, MAccount.get(getCtx(), receivablesServices_ID), getC_Currency_ID(), null, serviceAmt);
} else // ** API
if (getDocumentType().equals(DOCTYPE_APInvoice)) {
BigDecimal grossAmt = getAmount(Doc.AMTTYPE_Gross);
BigDecimal serviceAmt = Env.ZERO;
// Charge DR
fact.createLine(null, getAccount(Doc.ACCTTYPE_Charge, as), getC_Currency_ID(), getAmount(Doc.AMTTYPE_Charge), null);
// TaxCredit DR
for (int i = 0; i < m_taxes.length; i++) {
FactLine tl;
if (m_taxes[i].getRate().signum() >= 0)
tl = fact.createLine(null, m_taxes[i].getAccount(m_taxes[i].getAPTaxType(), as), getC_Currency_ID(), m_taxes[i].getAmount(), null);
else
tl = fact.createLine(null, m_taxes[i].getAccount(m_taxes[i].getAPTaxType(), as), getC_Currency_ID(), null, m_taxes[i].getAmount().negate());
if (tl != null)
tl.setC_Tax_ID(m_taxes[i].getC_Tax_ID());
}
// Expense DR
for (int i = 0; i < p_lines.length; i++) {
DocLine line = p_lines[i];
boolean landedCost = landedCost(as, fact, line, true);
if (landedCost && as.isExplicitCostAdjustment()) {
fact.createLine(line, line.getAccount(ProductCost.ACCTTYPE_P_Expense, as), getC_Currency_ID(), line.getAmtSource(), null);
//
FactLine fl = fact.createLine(line, line.getAccount(ProductCost.ACCTTYPE_P_Expense, as), getC_Currency_ID(), null, line.getAmtSource());
String desc = line.getDescription();
if (desc == null)
desc = "100%";
else
desc += " 100%";
fl.setDescription(desc);
}
if (!landedCost) {
MAccount expense = line.getAccount(ProductCost.ACCTTYPE_P_Expense, as);
if (line.isItem())
expense = line.getAccount(ProductCost.ACCTTYPE_P_InventoryClearing, as);
BigDecimal amt = line.getAmtSource();
BigDecimal dAmt = null;
if (as.isTradeDiscountPosted() && !line.isItem()) {
BigDecimal discount = line.getDiscount();
if (discount != null && discount.signum() != 0) {
amt = amt.add(discount);
dAmt = discount;
MAccount tradeDiscountReceived = line.getAccount(ProductCost.ACCTTYPE_P_TDiscountRec, as);
fact.createLine(line, tradeDiscountReceived, getC_Currency_ID(), null, dAmt);
}
}
fact.createLine(line, expense, getC_Currency_ID(), amt, null);
if (!line.isItem()) {
grossAmt = grossAmt.subtract(amt);
serviceAmt = serviceAmt.add(amt);
}
//
/*if (line.getM_Product_ID() != 0
&& line.getProduct().isService()) // otherwise Inv Matching
MCostDetail.createInvoice(as, line.getAD_Org_ID(),
line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(),
line.get_ID(), 0, // No Cost Element
line.getAmtSource(), line.getQty(),
line.getDescription(), getTrxName());*/
}
}
// Set Locations
FactLine[] fLines = fact.getLines();
for (int i = 0; i < fLines.length; i++) {
if (fLines[i] != null) {
// from Loc
fLines[i].setLocationFromBPartner(getC_BPartner_Location_ID(), true);
// to Loc
fLines[i].setLocationFromOrg(fLines[i].getAD_Org_ID(), false);
}
}
// Liability CR
int payables_ID = getValidCombination_ID(Doc.ACCTTYPE_V_Liability, as);
int payablesServices_ID = getValidCombination_ID(Doc.ACCTTYPE_V_Liability_Services, as);
if (m_allLinesItem || !as.isPostServices() || payables_ID == payablesServices_ID) {
grossAmt = getAmount(Doc.AMTTYPE_Gross);
serviceAmt = Env.ZERO;
} else if (m_allLinesService) {
serviceAmt = getAmount(Doc.AMTTYPE_Gross);
grossAmt = Env.ZERO;
}
if (grossAmt.signum() != 0)
fact.createLine(null, MAccount.get(getCtx(), payables_ID), getC_Currency_ID(), null, grossAmt);
if (serviceAmt.signum() != 0)
fact.createLine(null, MAccount.get(getCtx(), payablesServices_ID), getC_Currency_ID(), null, serviceAmt);
//
// Only API
updateProductPO(as);
// only API
updateProductInfo(as.getC_AcctSchema_ID());
} else // APC
if (getDocumentType().equals(DOCTYPE_APCredit)) {
BigDecimal grossAmt = getAmount(Doc.AMTTYPE_Gross);
BigDecimal serviceAmt = Env.ZERO;
// Charge CR
fact.createLine(null, getAccount(Doc.ACCTTYPE_Charge, as), getC_Currency_ID(), null, getAmount(Doc.AMTTYPE_Charge));
// TaxCredit CR
for (int i = 0; i < m_taxes.length; i++) {
FactLine tl;
if (m_taxes[i].getRate().signum() >= 0)
tl = fact.createLine(null, m_taxes[i].getAccount(m_taxes[i].getAPTaxType(), as), getC_Currency_ID(), null, m_taxes[i].getAmount());
else
tl = fact.createLine(null, m_taxes[i].getAccount(m_taxes[i].getAPTaxType(), as), getC_Currency_ID(), m_taxes[i].getAmount().negate(), null);
if (tl != null)
tl.setC_Tax_ID(m_taxes[i].getC_Tax_ID());
}
// Expense CR
for (int i = 0; i < p_lines.length; i++) {
DocLine line = p_lines[i];
boolean landedCost = landedCost(as, fact, line, false);
if (landedCost && as.isExplicitCostAdjustment()) {
fact.createLine(line, line.getAccount(ProductCost.ACCTTYPE_P_Expense, as), getC_Currency_ID(), null, line.getAmtSource());
//
FactLine fl = fact.createLine(line, line.getAccount(ProductCost.ACCTTYPE_P_Expense, as), getC_Currency_ID(), line.getAmtSource(), null);
String desc = line.getDescription();
if (desc == null)
desc = "100%";
else
desc += " 100%";
fl.setDescription(desc);
}
if (!landedCost) {
MAccount expense = line.getAccount(ProductCost.ACCTTYPE_P_Expense, as);
if (line.isItem())
expense = line.getAccount(ProductCost.ACCTTYPE_P_InventoryClearing, as);
BigDecimal amt = line.getAmtSource();
BigDecimal dAmt = null;
if (as.isTradeDiscountPosted() && !line.isItem()) {
BigDecimal discount = line.getDiscount();
if (discount != null && discount.signum() != 0) {
amt = amt.add(discount);
dAmt = discount;
MAccount tradeDiscountReceived = line.getAccount(ProductCost.ACCTTYPE_P_TDiscountRec, as);
fact.createLine(line, tradeDiscountReceived, getC_Currency_ID(), dAmt, null);
}
}
fact.createLine(line, expense, getC_Currency_ID(), null, amt);
if (!line.isItem()) {
grossAmt = grossAmt.subtract(amt);
serviceAmt = serviceAmt.add(amt);
}
//
/*if (line.getM_Product_ID() != 0
&& line.getProduct().isService()) // otherwise Inv Matching
MCostDetail.createInvoice(as, line.getAD_Org_ID(),
line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(),
line.get_ID(), 0, // No Cost Element
line.getAmtSource().negate(), line.getQty(),
line.getDescription(), getTrxName());*/
}
}
// Set Locations
FactLine[] fLines = fact.getLines();
for (int i = 0; i < fLines.length; i++) {
if (fLines[i] != null) {
// from Loc
fLines[i].setLocationFromBPartner(getC_BPartner_Location_ID(), true);
// to Loc
fLines[i].setLocationFromOrg(fLines[i].getAD_Org_ID(), false);
}
}
// Liability DR
int payables_ID = getValidCombination_ID(Doc.ACCTTYPE_V_Liability, as);
int payablesServices_ID = getValidCombination_ID(Doc.ACCTTYPE_V_Liability_Services, as);
if (m_allLinesItem || !as.isPostServices() || payables_ID == payablesServices_ID) {
grossAmt = getAmount(Doc.AMTTYPE_Gross);
serviceAmt = Env.ZERO;
} else if (m_allLinesService) {
serviceAmt = getAmount(Doc.AMTTYPE_Gross);
grossAmt = Env.ZERO;
}
if (grossAmt.signum() != 0)
fact.createLine(null, MAccount.get(getCtx(), payables_ID), getC_Currency_ID(), grossAmt, null);
if (serviceAmt.signum() != 0)
fact.createLine(null, MAccount.get(getCtx(), payablesServices_ID), getC_Currency_ID(), serviceAmt, null);
} else {
p_Error = "DocumentType unknown: " + getDocumentType();
log.log(Level.SEVERE, p_Error);
fact = null;
}
//
facts.add(fact);
return facts;
}
use of org.compiere.model.MAccount in project adempiere by adempiere.
the class Doc_Invoice method createFactCash.
// createFact
/**
* Create Fact Cash Based (i.e. only revenue/expense)
* @param as accounting schema
* @param fact fact to add lines to
* @param multiplier source amount multiplier
* @return accounted amount
*/
public BigDecimal createFactCash(MAcctSchema as, Fact fact, BigDecimal multiplier) {
boolean creditMemo = getDocumentType().equals(DOCTYPE_ARCredit) || getDocumentType().equals(DOCTYPE_APCredit);
boolean payables = getDocumentType().equals(DOCTYPE_APInvoice) || getDocumentType().equals(DOCTYPE_APCredit);
BigDecimal acctAmt = Env.ZERO;
FactLine fl = null;
// Revenue/Cost
for (int i = 0; i < p_lines.length; i++) {
DocLine line = p_lines[i];
boolean landedCost = false;
if (payables)
landedCost = landedCost(as, fact, line, false);
if (landedCost && as.isExplicitCostAdjustment()) {
fact.createLine(line, line.getAccount(ProductCost.ACCTTYPE_P_Expense, as), getC_Currency_ID(), null, line.getAmtSource());
//
fl = fact.createLine(line, line.getAccount(ProductCost.ACCTTYPE_P_Expense, as), getC_Currency_ID(), line.getAmtSource(), null);
String desc = line.getDescription();
if (desc == null)
desc = "100%";
else
desc += " 100%";
fl.setDescription(desc);
}
if (!landedCost) {
MAccount acct = line.getAccount(payables ? ProductCost.ACCTTYPE_P_Expense : ProductCost.ACCTTYPE_P_Revenue, as);
if (payables) {
// if Fixed Asset
if (line.isItem())
acct = line.getAccount(ProductCost.ACCTTYPE_P_InventoryClearing, as);
}
BigDecimal amt = line.getAmtSource().multiply(multiplier);
BigDecimal amt2 = null;
if (creditMemo) {
amt2 = amt;
amt = null;
}
if (// Vendor = DR
payables)
fl = fact.createLine(line, acct, getC_Currency_ID(), amt, amt2);
else
// Customer = CR
fl = fact.createLine(line, acct, getC_Currency_ID(), amt2, amt);
if (fl != null)
acctAmt = acctAmt.add(fl.getAcctBalance());
}
}
// Tax
for (int i = 0; i < m_taxes.length; i++) {
BigDecimal amt = m_taxes[i].getAmount();
BigDecimal amt2 = null;
if (creditMemo) {
amt2 = amt;
amt = null;
}
FactLine tl = null;
if (payables)
tl = fact.createLine(null, m_taxes[i].getAccount(m_taxes[i].getAPTaxType(), as), getC_Currency_ID(), amt, amt2);
else
tl = fact.createLine(null, m_taxes[i].getAccount(DocTax.ACCTTYPE_TaxDue, as), getC_Currency_ID(), amt2, amt);
if (tl != null)
tl.setC_Tax_ID(m_taxes[i].getC_Tax_ID());
}
// Set Locations
FactLine[] fLines = fact.getLines();
for (int i = 0; i < fLines.length; i++) {
if (fLines[i] != null) {
if (payables) {
// from Loc
fLines[i].setLocationFromBPartner(getC_BPartner_Location_ID(), true);
// to Loc
fLines[i].setLocationFromOrg(fLines[i].getAD_Org_ID(), false);
} else {
// from Loc
fLines[i].setLocationFromOrg(fLines[i].getAD_Org_ID(), true);
// to Loc
fLines[i].setLocationFromBPartner(getC_BPartner_Location_ID(), false);
}
}
}
return acctAmt;
}
Aggregations