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)
{
fLines[i].setLocationFromBPartner(getC_BPartner_Location_ID(), true); // from Loc
fLines[i].setLocationFromOrg(fLines[i].getAD_Org_ID(), false); // to Loc
}
}
// 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);
//
updateProductPO(as); // Only API
updateProductInfo (as.getC_AcctSchema_ID()); // only API
}
// APC
else 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 = fact.createLine (null, m_taxes[i].getAccount(m_taxes[i].getAPTaxType(), as),
getC_Currency_ID(), null, m_taxes[i].getAmount());
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,