nilskm
unread,Apr 3, 2013, 1:24:30 PM4/3/13Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to idem...@googlegroups.com
Hi!
I'm looking at MInvoice.getOpenAmt method and it looks like it's not fully implemented.The paymentDate parameter has no functionality. I think that what it's supposed to do is to consider if any discounts should be applied in regard to the payment term and timestamp. I need this to work in a different project and I wonder if below would be a solution. And I'd be very pleased for any kind of input.
One more thing about getOpenAmt that caused me trouble earlier is that if you call the method getOpenAmt once it doesn't update the value any more (" if (m_openAmt == null)" )
This is kind of dangerous if you call the method twice and in between the two calls you e.g. have allocated a payment. Then you won't get the correct value. I think the line should be removed or the method should have one more parameter "boolean reload". What do you think?
Back to the first change I was talking about. (Maybe it shouldn't be applied on credit memos?) This should be added in getOpenAmt
if (paymentDate != null)
{
if (getC_PaymentTerm_ID()>0) {
BigDecimal discount = getDiscountAmt(paymentDate);
if (discount!=null)
m_openAmt = m_openAmt.subtract(discount);
}
}
the "getDiscountAmt" method would be something like this:
* Get discount amt depending on payment term and timestamp
* @return pos/neg amount or null
*/
public BigDecimal getDiscountAmt (Timestamp paymentDate)
{
BigDecimal retValue = null;
String sql = "SELECT "
+ " invoiceDiscount(?,?,?) ";
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, get_TrxName());
pstmt.setInt(1, getC_Invoice_ID());
pstmt.setTimestamp(2, paymentDate);
pstmt.setInt(3, getC_PaymentTerm_ID());
rs = pstmt.executeQuery();
if (rs.next())
{
retValue = rs.getBigDecimal(1);
}
rs.close();
pstmt.close();
pstmt = null;
}
catch (SQLException e)
{
throw new DBException(e, sql);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
return retValue;
} // getDiscountAmt