Skip to content

Commit

Permalink
Revert "Merge branch 'master' of https://github.com/metasfresh/metasf…
Browse files Browse the repository at this point in the history
…resh"

This reverts commit 8b92b1b, reversing
changes made to 5621f71.
  • Loading branch information
metas-rc committed Mar 26, 2019
1 parent 8b92b1b commit b9a25f4
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 323 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ else if (countPayments == 0 && countInvoices > 0)

// reset line info
setBPartnerId(null);

return facts;
} // createFact

Expand Down Expand Up @@ -380,7 +380,7 @@ private boolean isReversedPaymentAllocation()
}

final List<DocLine_Allocation> lines = getDocLines();

// note: the p_lines are not each others' counter doc lines, i.e. DocLine_Allocation.getCounterDocLine() == null and getCounter_AllocationLine_ID == 0
final I_C_Payment firstPayment = lines.get(0).getC_Payment();
final I_C_Payment secondPayment = lines.get(1).getC_Payment();
Expand Down Expand Up @@ -495,7 +495,7 @@ private AmountSourceAndAcct createPaymentFacts(final Fact fact, final DocLine_Al
{
final AcctSchema as = fact.getAcctSchema();

final BigDecimal paymentAllocatedAmt = line.getAllocatedAmt();
final BigDecimal paymentAllocatedAmt = line.getAllocatedAmt_CMAdjusted();
if (paymentAllocatedAmt.signum() == 0)
{
// no amount to be allocated on payment
Expand All @@ -518,25 +518,11 @@ private AmountSourceAndAcct createPaymentFacts(final Fact fact, final DocLine_Al

if (line.isSOTrxInvoice())
{
if (line.isCreditMemoInvoice())
{
factLineBuilder.setAmtSource(null, paymentAllocatedAmt.negate());
}
else
{
factLineBuilder.setAmtSource(paymentAllocatedAmt, null);
}
factLineBuilder.setAmtSource(paymentAllocatedAmt, null);
}
else
{
if (line.isCreditMemoInvoice())
{
factLineBuilder.setAmtSource(paymentAllocatedAmt, null);
}
else
{
factLineBuilder.setAmtSource(null, paymentAllocatedAmt.negate());
}
factLineBuilder.setAmtSource(null, paymentAllocatedAmt.negate());
}

final FactLine factLine = factLineBuilder.buildAndAdd();
Expand Down Expand Up @@ -710,20 +696,21 @@ private static final MAccount getTaxDiscountAccount(final int taxId, final boole
{
return getTaxDiscountAccount(taxId, isDiscountExpense, as.getId());
}

static MAccount getTaxDiscountAccount(final int taxId, final boolean isDiscountExpense, final AcctSchemaId acctSchemaId)
{
if (taxId <= 0)
{
return null;
}

String sql = "SELECT T_PayDiscount_Exp_Acct FROM C_Tax_Acct WHERE C_Tax_ID=? AND C_AcctSchema_ID=?";
if (!isDiscountExpense)
if(!isDiscountExpense)
{
sql = "SELECT T_PayDiscount_Rev_Acct FROM C_Tax_Acct WHERE C_Tax_ID=? AND C_AcctSchema_ID=?";
}



final int Account_ID = DB.getSQLValueEx(ITrx.TRXNAME_None, sql, taxId, acctSchemaId);
// No account
if (Account_ID <= 0)
Expand All @@ -737,6 +724,7 @@ static MAccount getTaxDiscountAccount(final int taxId, final boolean isDiscountE
return acct;
}


/**
* Creates the {@link FactLine} to book the invoice write off.
*
Expand All @@ -746,7 +734,7 @@ static MAccount getTaxDiscountAccount(final int taxId, final boolean isDiscountE
*/
private final AmountSourceAndAcct createInvoiceWriteOffFacts(final Fact fact, final DocLine_Allocation line)
{
final BigDecimal writeOffAmt = line.getWriteOffAmt();
final BigDecimal writeOffAmt = line.getWriteOffAmt_CMAdjusted();
if (writeOffAmt.signum() == 0)
{
return AmountSourceAndAcct.ZERO;
Expand All @@ -762,25 +750,11 @@ private final AmountSourceAndAcct createInvoiceWriteOffFacts(final Fact fact, fi

if (line.isSOTrxInvoice())
{
if (line.isCreditMemoInvoice())
{
factLineBuilder.setAmtSource(null, writeOffAmt.negate());
}
else
{
factLineBuilder.setAmtSource(writeOffAmt, null);
}
factLineBuilder.setAmtSource(writeOffAmt, null);
}
else
{
if (line.isCreditMemoInvoice())
{
factLineBuilder.setAmtSource(writeOffAmt, null);
}
else
{
factLineBuilder.setAmtSource(null, writeOffAmt.negate());
}
factLineBuilder.setAmtSource(null, writeOffAmt.negate());
}

final FactLine factLine = factLineBuilder.buildAndAdd();
Expand Down Expand Up @@ -1308,13 +1282,8 @@ public List<Fact> createEntries(
if (taxFactAcct.getAmtSourceDr().signum() != 0)
{
final BigDecimal invoiceTaxAmt = taxFactAcct.getAmtSourceDr();
final BigDecimal amountCMAdjusted = calcAmount(
invoiceTaxAmt,
invoiceGrandTotalAmt,
m_DiscountAmt,
precision,
line.isCreditMemoInvoice());
if (amountCMAdjusted.signum() != 0)
final BigDecimal amount = calcAmount(invoiceTaxAmt, invoiceGrandTotalAmt, m_DiscountAmt, precision);
if (amount.signum() != 0)
{
final String description = "Invoice TaxAmt/GrandTotal=" + invoiceTaxAmt + "/" + invoiceGrandTotalAmt + ", Alloc Discount=" + m_DiscountAmt;

Expand All @@ -1324,17 +1293,17 @@ public List<Fact> createEntries(
// Discount expense
if (isDiscountExpense)
{
final FactLine flDR = fact.createLine(line, discountAcct, as.getCurrencyId(), amountCMAdjusted, null);
final FactLine flDR = fact.createLine(line, discountAcct, as.getCurrencyId(), amount, null);
updateFactLine(flDR, taxId, description);
final FactLine flCR = fact.createLine(line, taxAcct, as.getCurrencyId(), null, amountCMAdjusted);
final FactLine flCR = fact.createLine(line, taxAcct, as.getCurrencyId(), null, amount);
updateFactLine(flCR, taxId, description);
}
// Discount revenue
else
{
final FactLine flDR = fact.createLine(line, discountAcct, as.getCurrencyId(), amountCMAdjusted.negate(), null);
final FactLine flDR = fact.createLine(line, discountAcct, as.getCurrencyId(), amount.negate(), null);
updateFactLine(flDR, taxId, description);
final FactLine flCR = fact.createLine(line, taxAcct, as.getCurrencyId(), null, amountCMAdjusted.negate());
final FactLine flCR = fact.createLine(line, taxAcct, as.getCurrencyId(), null, amount.negate());
updateFactLine(flCR, taxId, description);
}

Expand All @@ -1344,13 +1313,8 @@ public List<Fact> createEntries(
else
{
final BigDecimal invoiceTaxAmt = taxFactAcct.getAmtSourceCr();
final BigDecimal amountCMAdjusted = calcAmount(
invoiceTaxAmt,
invoiceGrandTotalAmt,
m_DiscountAmt,
precision,
line.isCreditMemoInvoice());
if (amountCMAdjusted.signum() != 0)
final BigDecimal amount = calcAmount(invoiceTaxAmt, invoiceGrandTotalAmt, m_DiscountAmt, precision);
if (amount.signum() != 0)
{
final String description = "Invoice TaxAmt/GrandTotal=" + invoiceTaxAmt + "/" + invoiceGrandTotalAmt + ", Alloc Discount=" + m_DiscountAmt;

Expand All @@ -1360,17 +1324,17 @@ public List<Fact> createEntries(
// Discount expense
if (isDiscountExpense)
{
final FactLine flDR = fact.createLine(line, taxAcct, as.getCurrencyId(), amountCMAdjusted, null);
final FactLine flDR = fact.createLine(line, taxAcct, as.getCurrencyId(), amount, null);
updateFactLine(flDR, taxId, description);
final FactLine flCR = fact.createLine(line, discountAcct, as.getCurrencyId(), null, amountCMAdjusted);
final FactLine flCR = fact.createLine(line, discountAcct, as.getCurrencyId(), null, amount);
updateFactLine(flCR, taxId, description);
}
// Discount revenue
else
{
final FactLine flDR = fact.createLine(line, taxAcct, as.getCurrencyId(), amountCMAdjusted.negate(), null);
final FactLine flDR = fact.createLine(line, taxAcct, as.getCurrencyId(), amount.negate(), null);
updateFactLine(flDR, taxId, description);
final FactLine flCR = fact.createLine(line, discountAcct, as.getCurrencyId(), null, amountCMAdjusted.negate());
final FactLine flCR = fact.createLine(line, discountAcct, as.getCurrencyId(), null, amount.negate());
updateFactLine(flCR, taxId, description);
}
}
Expand All @@ -1385,35 +1349,35 @@ public List<Fact> createEntries(
if (taxFactAcct.getAmtSourceDr().signum() != 0)
{
final BigDecimal invoiceTaxAmt = taxFactAcct.getAmtSourceDr();
final BigDecimal amountCMAdjusted = calcAmount(invoiceTaxAmt, invoiceGrandTotalAmt, m_WriteOffAmt, precision, line.isCreditMemoInvoice());
if (amountCMAdjusted.signum() != 0)
final BigDecimal amount = calcAmount(invoiceTaxAmt, invoiceGrandTotalAmt, m_WriteOffAmt, precision);
if (amount.signum() != 0)
{
final String description = "Invoice TaxAmt/GrandTotal=" + invoiceTaxAmt + "/" + invoiceGrandTotalAmt + ", Alloc WriteOff=" + m_WriteOffAmt;

final Fact fact = createEmptyFact(as);
result.add(fact);

final FactLine flDR = fact.createLine(line, m_WriteOffAccount, as.getCurrencyId(), amountCMAdjusted, null);
final FactLine flDR = fact.createLine(line, m_WriteOffAccount, as.getCurrencyId(), amount, null);
updateFactLine(flDR, taxId, description);
final FactLine flCR = fact.createLine(line, taxAcct, as.getCurrencyId(), null, amountCMAdjusted);
final FactLine flCR = fact.createLine(line, taxAcct, as.getCurrencyId(), null, amount);
updateFactLine(flCR, taxId, description);
}
}
// Original Tax is CR - need to correct it DR
else
{
final BigDecimal invoiceTaxAmt = taxFactAcct.getAmtSourceCr();
final BigDecimal amountCMAdjusted = calcAmount(invoiceTaxAmt, invoiceGrandTotalAmt, m_WriteOffAmt, precision, line.isCreditMemoInvoice());
if (amountCMAdjusted.signum() != 0)
final BigDecimal amount = calcAmount(invoiceTaxAmt, invoiceGrandTotalAmt, m_WriteOffAmt, precision);
if (amount.signum() != 0)
{
final String description = "Invoice TaxAmt/GrandTotal=" + invoiceTaxAmt + "/" + invoiceGrandTotalAmt + ", Alloc WriteOff=" + m_WriteOffAmt;

final Fact fact = createEmptyFact(as);
result.add(fact);

final FactLine flDR = fact.createLine(line, taxAcct, as.getCurrencyId(), amountCMAdjusted, null);
final FactLine flDR = fact.createLine(line, taxAcct, as.getCurrencyId(), amount, null);
updateFactLine(flDR, taxId, description);
final FactLine flCR = fact.createLine(line, m_WriteOffAccount, as.getCurrencyId(), null, amountCMAdjusted);
final FactLine flCR = fact.createLine(line, m_WriteOffAccount, as.getCurrencyId(), null, amount);
updateFactLine(flCR, taxId, description);
}
}
Expand All @@ -1437,12 +1401,7 @@ private Fact createEmptyFact(final AcctSchema as)
* @param precision precision
* @return (taxAmt / invoice grand total amount) * taxAmt
*/
private static final BigDecimal calcAmount(
final BigDecimal taxAmt,
final BigDecimal invoiceGrandTotalAmt,
final BigDecimal discountAmt,
final CurrencyPrecision precision,
final boolean isCreditMemoInvoice)
private static final BigDecimal calcAmount(final BigDecimal taxAmt, final BigDecimal invoiceGrandTotalAmt, final BigDecimal discountAmt, final CurrencyPrecision precision)
{
if (log.isDebugEnabled())
{
Expand All @@ -1465,9 +1424,7 @@ private static final BigDecimal calcAmount(
{
log.debug(taxAmtPart + " (Mult=" + multiplier + "(Prec=" + precision + ")");
}

final BigDecimal taxAmtPartCMAdjusted = isCreditMemoInvoice ? taxAmtPart.negate() : taxAmtPart;
return taxAmtPartCMAdjusted;
return taxAmtPart;
} // calcAmount

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ public interface I_AD_Tab
public static final String COLUMNNAME_AD_Window_ID = "AD_Window_ID";

/**
* Set Schnelleingabe einschalten.
* Set Schnelleingabe abschalten.
*
* <br>Type: YesNo
* <br>Mandatory: true
Expand All @@ -364,7 +364,7 @@ public interface I_AD_Tab
public void setAllowQuickInput (boolean AllowQuickInput);

/**
* Get Schnelleingabe einschalten.
* Get Schnelleingabe abschalten.
*
* <br>Type: YesNo
* <br>Mandatory: true
Expand Down Expand Up @@ -884,29 +884,6 @@ public interface I_AD_Tab
/** Column name IsRefreshAllOnActivate */
public static final String COLUMNNAME_IsRefreshAllOnActivate = "IsRefreshAllOnActivate";

/**
* Set Refresh view on change events.
*
* <br>Type: YesNo
* <br>Mandatory: true
* <br>Virtual Column: false
*/
public void setIsRefreshViewOnChangeEvents (boolean IsRefreshViewOnChangeEvents);

/**
* Get Refresh view on change events.
*
* <br>Type: YesNo
* <br>Mandatory: true
* <br>Virtual Column: false
*/
public boolean isRefreshViewOnChangeEvents();

/** Column definition for IsRefreshViewOnChangeEvents */
public static final org.adempiere.model.ModelColumn<I_AD_Tab, Object> COLUMN_IsRefreshViewOnChangeEvents = new org.adempiere.model.ModelColumn<I_AD_Tab, Object>(I_AD_Tab.class, "IsRefreshViewOnChangeEvents", null);
/** Column name IsRefreshViewOnChangeEvents */
public static final String COLUMNNAME_IsRefreshViewOnChangeEvents = "IsRefreshViewOnChangeEvents";

/**
* Set Search Active.
* This mark activates the search button from toolbar
Expand Down Expand Up @@ -1057,6 +1034,7 @@ public interface I_AD_Tab

/**
* Set Name.
* Alphanumeric identifier of the entity
*
* <br>Type: String
* <br>Mandatory: true
Expand All @@ -1066,6 +1044,7 @@ public interface I_AD_Tab

/**
* Get Name.
* Alphanumeric identifier of the entity
*
* <br>Type: String
* <br>Mandatory: true
Expand Down
Loading

0 comments on commit b9a25f4

Please sign in to comment.