IDEMPIERE-3279 Implement configurable Write-Off in Payment Selection / multicurrency

This commit is contained in:
Carlos Ruiz 2017-01-13 19:07:26 +01:00
parent afaedf1bf6
commit 503ec9d9e2
2 changed files with 12 additions and 5 deletions

View File

@ -125,14 +125,15 @@ public class PaySelectionCreateFrom extends SvrProcess
.append(" currencyConvert(invoiceDiscount(i.C_Invoice_ID,?,i.C_InvoicePaySchedule_ID)") // ##p3 PayDate
.append(",i.C_Currency_ID, ?,?,i.C_ConversionType_ID,i.AD_Client_ID,i.AD_Org_ID) AS DiscountAmt,") // 3 ##p4/p5 Currency_To,PayDate
.append(" PaymentRule, IsSOTrx, ") // 4..5
.append(" currencyConvert(invoiceWriteOff(i.C_Invoice_ID) AS WriteOffAmt,") // 6
.append(" currencyConvert(invoiceWriteOff(i.C_Invoice_ID) ")
.append(",i.C_Currency_ID, ?,?,i.C_ConversionType_ID,i.AD_Client_ID,i.AD_Org_ID) AS WriteOffAmt ") // 6 ##p6/p7 Currency_To,PayDate
.append("FROM C_Invoice_v i WHERE ");
if (X_C_Order.PAYMENTRULE_DirectDebit.equals(p_PaymentRule))
sql.append("IsSOTrx='Y'");
else
sql.append("IsSOTrx='N'");
sql.append(" AND IsPaid='N' AND DocStatus IN ('CO','CL')")
.append(" AND AD_Client_ID=?") // ##6
.append(" AND AD_Client_ID=?") // ##p8
// Existing Payments - Will reselect Invoice if prepared but not paid
.append(" AND NOT EXISTS (SELECT * FROM C_PaySelectionLine psl")
.append(" INNER JOIN C_PaySelectionCheck psc ON (psl.C_PaySelectionCheck_ID=psc.C_PaySelectionCheck_ID)")
@ -140,7 +141,7 @@ public class PaySelectionCreateFrom extends SvrProcess
.append(" WHERE i.C_Invoice_ID=psl.C_Invoice_ID AND psl.IsActive='Y'")
.append(" AND (pmt.DocStatus IS NULL OR pmt.DocStatus NOT IN ('VO','RE')) )")
// Don't generate again invoices already on this payment selection
.append(" AND i.C_Invoice_ID NOT IN (SELECT i.C_Invoice_ID FROM C_PaySelectionLine psl WHERE psl.C_PaySelection_ID=?)"); // ##7
.append(" AND i.C_Invoice_ID NOT IN (SELECT i.C_Invoice_ID FROM C_PaySelectionLine psl WHERE psl.C_PaySelection_ID=?)"); // ##p9
// Disputed
if (!p_IncludeInDispute)
sql.append(" AND i.IsInDispute='N'");
@ -207,6 +208,8 @@ public class PaySelectionCreateFrom extends SvrProcess
pstmt.setTimestamp(index++, psel.getPayDate());
pstmt.setInt (index++, C_CurrencyTo_ID);
pstmt.setTimestamp(index++, psel.getPayDate());
pstmt.setInt (index++, C_CurrencyTo_ID);
pstmt.setTimestamp(index++, psel.getPayDate());
//
pstmt.setInt(index++, psel.getAD_Client_ID());
pstmt.setInt(index++, p_C_PaySelection_ID);

View File

@ -228,8 +228,8 @@ public class PaySelect
new ColumnInfo(Msg.translate(ctx, "C_Currency_ID"), "c.ISO_Code", KeyNamePair.class, true, false, "i.C_Currency_ID"),
// 5..10
new ColumnInfo(Msg.translate(ctx, "GrandTotal"), "i.GrandTotal", BigDecimal.class),
new ColumnInfo(Msg.translate(ctx, "DiscountAmt"), "invoiceDiscount(i.C_Invoice_ID,?,i.C_InvoicePaySchedule_ID)", BigDecimal.class),
new ColumnInfo(Msg.translate(ctx, "WriteOffAmt"), "invoiceWriteOff(i.C_Invoice_ID)", BigDecimal.class),
new ColumnInfo(Msg.translate(ctx, "DiscountAmt"), "currencyConvert(invoiceDiscount(i.C_Invoice_ID,?,i.C_InvoicePaySchedule_ID),i.C_Currency_ID, ?,?,i.C_ConversionType_ID, i.AD_Client_ID,i.AD_Org_ID)", BigDecimal.class),
new ColumnInfo(Msg.translate(ctx, "WriteOffAmt"), "currencyConvert(invoiceWriteOff(i.C_Invoice_ID),i.C_Currency_ID, ?,?,i.C_ConversionType_ID, i.AD_Client_ID,i.AD_Org_ID)", BigDecimal.class),
new ColumnInfo(Msg.getMsg(ctx, "DiscountDate"), "COALESCE((SELECT discountdate from C_InvoicePaySchedule ips WHERE ips.C_InvoicePaySchedule_ID=i.C_InvoicePaySchedule_ID),i.DateInvoiced+p.DiscountDays+p.GraceDays) AS DiscountDate", Timestamp.class),
new ColumnInfo(Msg.getMsg(ctx, "AmountDue"), "currencyConvert(invoiceOpen(i.C_Invoice_ID,i.C_InvoicePaySchedule_ID),i.C_Currency_ID, ?,?,i.C_ConversionType_ID, i.AD_Client_ID,i.AD_Org_ID) AS AmountDue", BigDecimal.class),
new ColumnInfo(Msg.getMsg(ctx, "AmountPay"), "currencyConvert(invoiceOpen(i.C_Invoice_ID,i.C_InvoicePaySchedule_ID)-invoiceDiscount(i.C_Invoice_ID,?,i.C_InvoicePaySchedule_ID)-invoiceWriteOff(i.C_Invoice_ID),i.C_Currency_ID, ?,?,i.C_ConversionType_ID, i.AD_Client_ID,i.AD_Org_ID) AS AmountPay", BigDecimal.class)
@ -340,6 +340,10 @@ public class PaySelect
int index = 1;
pstmt = DB.prepareStatement(sql, null);
pstmt.setTimestamp(index++, payDate); // DiscountAmt
pstmt.setInt(index++, bi.C_Currency_ID);
pstmt.setTimestamp(index++, payDate);
pstmt.setInt(index++, bi.C_Currency_ID); // WriteOffAmt
pstmt.setTimestamp(index++, payDate);
pstmt.setInt(index++, bi.C_Currency_ID); // DueAmt
pstmt.setTimestamp(index++, payDate);
pstmt.setTimestamp(index++, payDate); // PayAmt