BF [ 1894716 ] CalloutPayment.amounts calculates wrong amts.
Patch provided by Mario Calderon and Tobias Schöneberg. Please review.
This commit is contained in:
parent
56cac23117
commit
9ca8c4b2d3
|
@ -1,19 +1,18 @@
|
||||||
/******************************************************************************
|
/*******************************************************************************
|
||||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
* Product: Adempiere ERP & CRM Smart Business Solution * Copyright (C)
|
||||||
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
|
* 1999-2006 ComPiere, Inc. All Rights Reserved. * This program is free
|
||||||
* This program is free software; you can redistribute it and/or modify it *
|
* software; you can redistribute it and/or modify it * under the terms version
|
||||||
* under the terms version 2 of the GNU General Public License as published *
|
* 2 of the GNU General Public License as published * by the Free Software
|
||||||
* by the Free Software Foundation. This program is distributed in the hope *
|
* Foundation. This program is distributed in the hope * that it will be useful,
|
||||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
|
* but WITHOUT ANY WARRANTY; without even the implied * warranty of
|
||||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General
|
||||||
* See the GNU General Public License for more details. *
|
* Public License for more details. * You should have received a copy of the GNU
|
||||||
* You should have received a copy of the GNU General Public License along *
|
* General Public License along * with this program; if not, write to the Free
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc., *
|
* Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA
|
||||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
* 02111-1307 USA. * For the text or an alternative of this public license, you
|
||||||
* For the text or an alternative of this public license, you may reach us *
|
* may reach us * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA
|
||||||
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
|
* 95054, USA * or via info@compiere.org or http://www.compiere.org/license.html *
|
||||||
* or via info@compiere.org or http://www.compiere.org/license.html *
|
******************************************************************************/
|
||||||
*****************************************************************************/
|
|
||||||
package org.compiere.model;
|
package org.compiere.model;
|
||||||
|
|
||||||
import java.math.*;
|
import java.math.*;
|
||||||
|
@ -23,25 +22,19 @@ import java.util.logging.*;
|
||||||
import org.compiere.util.*;
|
import org.compiere.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Payment Callouts.
|
* Payment Callouts. org.compiere.model.CalloutPayment.*
|
||||||
* org.compiere.model.CalloutPayment.*
|
|
||||||
*
|
|
||||||
* @author Jorg Janke
|
* @author Jorg Janke
|
||||||
* @version $Id: CalloutPayment.java,v 1.3 2006/07/30 00:51:03 jjanke Exp $
|
* @version $Id: CalloutPayment.java,v 1.3 2006/07/30 00:51:03 jjanke Exp $
|
||||||
*
|
|
||||||
* @author Teo Sarca, SC ARHIPAC SERVICE SRL
|
* @author Teo Sarca, SC ARHIPAC SERVICE SRL
|
||||||
* <li>BF [ 1803316 ] CalloutPayment: use C_Order.Bill_BPartner_ID
|
* <li>BF [ 1803316 ] CalloutPayment: use C_Order.Bill_BPartner_ID
|
||||||
*/
|
*/
|
||||||
public class CalloutPayment extends CalloutEngine
|
public class CalloutPayment extends CalloutEngine
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Payment_Invoice.
|
* Payment_Invoice. when Invoice selected - set C_Currency_ID -
|
||||||
* when Invoice selected
|
* C_BPartner_ID - DiscountAmt = C_Invoice_Discount (ID, DateTrx) - PayAmt =
|
||||||
* - set C_Currency_ID
|
* invoiceOpen (ID) - Discount - WriteOffAmt = 0
|
||||||
* - C_BPartner_ID
|
|
||||||
* - DiscountAmt = C_Invoice_Discount (ID, DateTrx)
|
|
||||||
* - PayAmt = invoiceOpen (ID) - Discount
|
|
||||||
* - WriteOffAmt = 0
|
|
||||||
* @param ctx context
|
* @param ctx context
|
||||||
* @param WindowNo current Window No
|
* @param WindowNo current Window No
|
||||||
* @param mTab Grid Tab
|
* @param mTab Grid Tab
|
||||||
|
@ -49,7 +42,8 @@ public class CalloutPayment extends CalloutEngine
|
||||||
* @param value New Value
|
* @param value New Value
|
||||||
* @return null or error message
|
* @return null or error message
|
||||||
*/
|
*/
|
||||||
public String invoice (Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value)
|
public String invoice(Properties ctx, int WindowNo, GridTab mTab,
|
||||||
|
GridField mField, Object value)
|
||||||
{
|
{
|
||||||
Integer C_Invoice_ID = (Integer)value;
|
Integer C_Invoice_ID = (Integer)value;
|
||||||
if (isCalloutActive () // assuming it is resetting value
|
if (isCalloutActive () // assuming it is resetting value
|
||||||
|
@ -63,12 +57,13 @@ public class CalloutPayment extends CalloutEngine
|
||||||
mTab.setValue ("WriteOffAmt", Env.ZERO);
|
mTab.setValue ("WriteOffAmt", Env.ZERO);
|
||||||
mTab.setValue ("IsOverUnderPayment", Boolean.FALSE);
|
mTab.setValue ("IsOverUnderPayment", Boolean.FALSE);
|
||||||
mTab.setValue ("OverUnderAmt", Env.ZERO);
|
mTab.setValue ("OverUnderAmt", Env.ZERO);
|
||||||
|
|
||||||
int C_InvoicePaySchedule_ID = 0;
|
int C_InvoicePaySchedule_ID = 0;
|
||||||
if (Env.getContextAsInt(ctx, Env.WINDOW_INFO, Env.TAB_INFO, "C_Invoice_ID") == C_Invoice_ID.intValue()
|
if (Env.getContextAsInt (ctx, Env.WINDOW_INFO, Env.TAB_INFO,
|
||||||
&& Env.getContextAsInt(ctx, Env.WINDOW_INFO, Env.TAB_INFO, "C_InvoicePaySchedule_ID") != 0)
|
"C_Invoice_ID") == C_Invoice_ID.intValue ()
|
||||||
C_InvoicePaySchedule_ID = Env.getContextAsInt(ctx, Env.WINDOW_INFO, Env.TAB_INFO, "C_InvoicePaySchedule_ID");
|
&& Env.getContextAsInt (ctx, Env.WINDOW_INFO, Env.TAB_INFO,
|
||||||
|
"C_InvoicePaySchedule_ID") != 0)
|
||||||
|
C_InvoicePaySchedule_ID = Env.getContextAsInt (ctx,
|
||||||
|
Env.WINDOW_INFO, Env.TAB_INFO, "C_InvoicePaySchedule_ID");
|
||||||
// Payment Date
|
// Payment Date
|
||||||
Timestamp ts = (Timestamp)mTab.getValue ("DateTrx");
|
Timestamp ts = (Timestamp)mTab.getValue ("DateTrx");
|
||||||
if (ts == null)
|
if (ts == null)
|
||||||
|
@ -94,16 +89,19 @@ public class CalloutPayment extends CalloutEngine
|
||||||
int C_Currency_ID = rs.getInt (2); // Set Invoice Currency
|
int C_Currency_ID = rs.getInt (2); // Set Invoice Currency
|
||||||
mTab.setValue ("C_Currency_ID", new Integer (C_Currency_ID));
|
mTab.setValue ("C_Currency_ID", new Integer (C_Currency_ID));
|
||||||
//
|
//
|
||||||
BigDecimal InvoiceOpen = rs.getBigDecimal(3); // Set Invoice OPen Amount
|
BigDecimal InvoiceOpen = rs.getBigDecimal (3); // Set Invoice
|
||||||
|
// OPen Amount
|
||||||
if (InvoiceOpen == null)
|
if (InvoiceOpen == null)
|
||||||
InvoiceOpen = Env.ZERO;
|
InvoiceOpen = Env.ZERO;
|
||||||
BigDecimal DiscountAmt = rs.getBigDecimal(4); // Set Discount Amt
|
BigDecimal DiscountAmt = rs.getBigDecimal (4); // Set Discount
|
||||||
|
// Amt
|
||||||
if (DiscountAmt == null)
|
if (DiscountAmt == null)
|
||||||
DiscountAmt = Env.ZERO;
|
DiscountAmt = Env.ZERO;
|
||||||
mTab.setValue ("PayAmt", InvoiceOpen.subtract (DiscountAmt));
|
mTab.setValue ("PayAmt", InvoiceOpen.subtract (DiscountAmt));
|
||||||
mTab.setValue ("DiscountAmt", DiscountAmt);
|
mTab.setValue ("DiscountAmt", DiscountAmt);
|
||||||
// reset as dependent fields get reset
|
// reset as dependent fields get reset
|
||||||
Env.setContext(ctx, WindowNo, "C_Invoice_ID", C_Invoice_ID.toString());
|
Env.setContext (ctx, WindowNo, "C_Invoice_ID", C_Invoice_ID
|
||||||
|
.toString ());
|
||||||
mTab.setValue ("C_Invoice_ID", C_Invoice_ID);
|
mTab.setValue ("C_Invoice_ID", C_Invoice_ID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,18 +114,13 @@ public class CalloutPayment extends CalloutEngine
|
||||||
{
|
{
|
||||||
DB.close (rs, pstmt);
|
DB.close (rs, pstmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
return docType (ctx, WindowNo, mTab, mField, value);
|
return docType (ctx, WindowNo, mTab, mField, value);
|
||||||
} // invoice
|
} // invoice
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Payment_Order.
|
* Payment_Order. when Waiting Payment Order selected - set C_Currency_ID -
|
||||||
* when Waiting Payment Order selected
|
* C_BPartner_ID - DiscountAmt = C_Invoice_Discount (ID, DateTrx) - PayAmt =
|
||||||
* - set C_Currency_ID
|
* invoiceOpen (ID) - Discount - WriteOffAmt = 0
|
||||||
* - C_BPartner_ID
|
|
||||||
* - DiscountAmt = C_Invoice_Discount (ID, DateTrx)
|
|
||||||
* - PayAmt = invoiceOpen (ID) - Discount
|
|
||||||
* - WriteOffAmt = 0
|
|
||||||
* @param ctx context
|
* @param ctx context
|
||||||
* @param WindowNo current Window No
|
* @param WindowNo current Window No
|
||||||
* @param mTab Grid Tab
|
* @param mTab Grid Tab
|
||||||
|
@ -135,7 +128,8 @@ public class CalloutPayment extends CalloutEngine
|
||||||
* @param value New Value
|
* @param value New Value
|
||||||
* @return null or error message
|
* @return null or error message
|
||||||
*/
|
*/
|
||||||
public String order (Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value)
|
public String order(Properties ctx, int WindowNo, GridTab mTab,
|
||||||
|
GridField mField, Object value)
|
||||||
{
|
{
|
||||||
Integer C_Order_ID = (Integer)value;
|
Integer C_Order_ID = (Integer)value;
|
||||||
if (isCalloutActive () // assuming it is resetting value
|
if (isCalloutActive () // assuming it is resetting value
|
||||||
|
@ -149,7 +143,6 @@ public class CalloutPayment extends CalloutEngine
|
||||||
mTab.setValue ("WriteOffAmt", Env.ZERO);
|
mTab.setValue ("WriteOffAmt", Env.ZERO);
|
||||||
mTab.setValue ("IsOverUnderPayment", Boolean.FALSE);
|
mTab.setValue ("IsOverUnderPayment", Boolean.FALSE);
|
||||||
mTab.setValue ("OverUnderAmt", Env.ZERO);
|
mTab.setValue ("OverUnderAmt", Env.ZERO);
|
||||||
|
|
||||||
// Payment Date
|
// Payment Date
|
||||||
Timestamp ts = (Timestamp)mTab.getValue ("DateTrx");
|
Timestamp ts = (Timestamp)mTab.getValue ("DateTrx");
|
||||||
if (ts == null)
|
if (ts == null)
|
||||||
|
@ -172,7 +165,8 @@ public class CalloutPayment extends CalloutEngine
|
||||||
int C_Currency_ID = rs.getInt (2); // Set Order Currency
|
int C_Currency_ID = rs.getInt (2); // Set Order Currency
|
||||||
mTab.setValue ("C_Currency_ID", new Integer (C_Currency_ID));
|
mTab.setValue ("C_Currency_ID", new Integer (C_Currency_ID));
|
||||||
//
|
//
|
||||||
BigDecimal GrandTotal = rs.getBigDecimal(3); // Set Pay Amount
|
BigDecimal GrandTotal = rs.getBigDecimal (3); // Set Pay
|
||||||
|
// Amount
|
||||||
if (GrandTotal == null)
|
if (GrandTotal == null)
|
||||||
GrandTotal = Env.ZERO;
|
GrandTotal = Env.ZERO;
|
||||||
mTab.setValue ("PayAmt", GrandTotal);
|
mTab.setValue ("PayAmt", GrandTotal);
|
||||||
|
@ -187,13 +181,11 @@ public class CalloutPayment extends CalloutEngine
|
||||||
{
|
{
|
||||||
DB.close (rs, pstmt);
|
DB.close (rs, pstmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
return docType (ctx, WindowNo, mTab, mField, value);
|
return docType (ctx, WindowNo, mTab, mField, value);
|
||||||
} // order
|
} // order
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Payment_Project.
|
* Payment_Project. - reset - C_BPartner_ID, Invoice, Order, Project,
|
||||||
* - reset - C_BPartner_ID, Invoice, Order, Project,
|
|
||||||
* Discount, WriteOff
|
* Discount, WriteOff
|
||||||
* @param ctx context
|
* @param ctx context
|
||||||
* @param WindowNo current Window No
|
* @param WindowNo current Window No
|
||||||
|
@ -202,7 +194,8 @@ public class CalloutPayment extends CalloutEngine
|
||||||
* @param value New Value
|
* @param value New Value
|
||||||
* @return null or error message
|
* @return null or error message
|
||||||
*/
|
*/
|
||||||
public String project (Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value)
|
public String project(Properties ctx, int WindowNo, GridTab mTab,
|
||||||
|
GridField mField, Object value)
|
||||||
{
|
{
|
||||||
Integer C_Project_ID = (Integer)value;
|
Integer C_Project_ID = (Integer)value;
|
||||||
if (isCalloutActive () // assuming it is resetting value
|
if (isCalloutActive () // assuming it is resetting value
|
||||||
|
@ -213,8 +206,7 @@ public class CalloutPayment extends CalloutEngine
|
||||||
} // project
|
} // project
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Payment_Charge.
|
* Payment_Charge. - reset - C_BPartner_ID, Invoice, Order, Project,
|
||||||
* - reset - C_BPartner_ID, Invoice, Order, Project,
|
|
||||||
* Discount, WriteOff
|
* Discount, WriteOff
|
||||||
* @param ctx context
|
* @param ctx context
|
||||||
* @param WindowNo current Window No
|
* @param WindowNo current Window No
|
||||||
|
@ -223,7 +215,8 @@ public class CalloutPayment extends CalloutEngine
|
||||||
* @param value New Value
|
* @param value New Value
|
||||||
* @return null or error message
|
* @return null or error message
|
||||||
*/
|
*/
|
||||||
public String charge (Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value)
|
public String charge(Properties ctx, int WindowNo, GridTab mTab,
|
||||||
|
GridField mField, Object value)
|
||||||
{
|
{
|
||||||
Integer C_Charge_ID = (Integer)value;
|
Integer C_Charge_ID = (Integer)value;
|
||||||
if (isCalloutActive () // assuming it is resetting value
|
if (isCalloutActive () // assuming it is resetting value
|
||||||
|
@ -242,8 +235,8 @@ public class CalloutPayment extends CalloutEngine
|
||||||
} // charge
|
} // charge
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Payment_Document Type.
|
* Payment_Document Type. Verify that Document Type (AP/AR) and Invoice
|
||||||
* Verify that Document Type (AP/AR) and Invoice (SO/PO) are in sync
|
* (SO/PO) are in sync
|
||||||
* @param ctx context
|
* @param ctx context
|
||||||
* @param WindowNo current Window No
|
* @param WindowNo current Window No
|
||||||
* @param mTab Grid Tab
|
* @param mTab Grid Tab
|
||||||
|
@ -251,17 +244,21 @@ public class CalloutPayment extends CalloutEngine
|
||||||
* @param value New Value
|
* @param value New Value
|
||||||
* @return null or error message
|
* @return null or error message
|
||||||
*/
|
*/
|
||||||
public String docType (Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value)
|
public String docType(Properties ctx, int WindowNo, GridTab mTab,
|
||||||
|
GridField mField, Object value)
|
||||||
{
|
{
|
||||||
int C_Invoice_ID = Env.getContextAsInt (ctx, WindowNo, "C_Invoice_ID");
|
int C_Invoice_ID = Env.getContextAsInt (ctx, WindowNo, "C_Invoice_ID");
|
||||||
int C_Order_ID = Env.getContextAsInt (ctx, WindowNo, "C_Order_ID");
|
int C_Order_ID = Env.getContextAsInt (ctx, WindowNo, "C_Order_ID");
|
||||||
int C_DocType_ID = Env.getContextAsInt (ctx, WindowNo, "C_DocType_ID");
|
int C_DocType_ID = Env.getContextAsInt (ctx, WindowNo, "C_DocType_ID");
|
||||||
log.fine("Payment_DocType - C_Invoice_ID=" + C_Invoice_ID + ", C_DocType_ID=" + C_DocType_ID);
|
log.fine ("Payment_DocType - C_Invoice_ID=" + C_Invoice_ID
|
||||||
|
+ ", C_DocType_ID=" + C_DocType_ID);
|
||||||
MDocType dt = null;
|
MDocType dt = null;
|
||||||
if (C_DocType_ID != 0)
|
if (C_DocType_ID != 0)
|
||||||
{
|
{
|
||||||
dt = MDocType.get (ctx, C_DocType_ID);
|
dt = MDocType.get (ctx, C_DocType_ID);
|
||||||
Env.setContext(ctx, WindowNo, "IsSOTrx", dt.isSOTrx() ? "Y" : "N");
|
Env
|
||||||
|
.setContext (ctx, WindowNo, "IsSOTrx", dt.isSOTrx () ? "Y"
|
||||||
|
: "N");
|
||||||
}
|
}
|
||||||
// Invoice
|
// Invoice
|
||||||
if (C_Invoice_ID != 0)
|
if (C_Invoice_ID != 0)
|
||||||
|
@ -273,7 +270,6 @@ public class CalloutPayment extends CalloutEngine
|
||||||
return "PaymentDocTypeInvoiceInconsistent";
|
return "PaymentDocTypeInvoiceInconsistent";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// globalqss - Allow prepayment to Purchase Orders
|
// globalqss - Allow prepayment to Purchase Orders
|
||||||
// Order Waiting Payment (can only be SO)
|
// Order Waiting Payment (can only be SO)
|
||||||
// if (C_Order_ID != 0 && dt != null && !dt.isSOTrx())
|
// if (C_Order_ID != 0 && dt != null && !dt.isSOTrx())
|
||||||
|
@ -288,18 +284,14 @@ public class CalloutPayment extends CalloutEngine
|
||||||
return "PaymentDocTypeInvoiceInconsistent";
|
return "PaymentDocTypeInvoiceInconsistent";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
} // docType
|
} // docType
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Payment_Amounts.
|
* Payment_Amounts. Change of: - IsOverUnderPayment -> set OverUnderAmt to 0 -
|
||||||
* Change of:
|
* C_Currency_ID, C_ConvesionRate_ID -> convert all - PayAmt, DiscountAmt,
|
||||||
* - IsOverUnderPayment -> set OverUnderAmt to 0
|
* WriteOffAmt, OverUnderAmt -> PayAmt make sure that add up to
|
||||||
* - C_Currency_ID, C_ConvesionRate_ID -> convert all
|
* InvoiceOpenAmt
|
||||||
* - PayAmt, DiscountAmt, WriteOffAmt, OverUnderAmt -> PayAmt
|
|
||||||
* make sure that add up to InvoiceOpenAmt
|
|
||||||
* @param ctx context
|
* @param ctx context
|
||||||
* @param WindowNo current Window No
|
* @param WindowNo current Window No
|
||||||
* @param mTab Grid Tab
|
* @param mTab Grid Tab
|
||||||
|
@ -308,7 +300,8 @@ public class CalloutPayment extends CalloutEngine
|
||||||
* @param oldValue Old Value
|
* @param oldValue Old Value
|
||||||
* @return null or error message
|
* @return null or error message
|
||||||
*/
|
*/
|
||||||
public String amounts (Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value, Object oldValue)
|
public String amounts(Properties ctx, int WindowNo, GridTab mTab,
|
||||||
|
GridField mField, Object value, Object oldValue)
|
||||||
{
|
{
|
||||||
if (isCalloutActive ()) // assuming it is resetting value
|
if (isCalloutActive ()) // assuming it is resetting value
|
||||||
return "";
|
return "";
|
||||||
|
@ -318,18 +311,20 @@ public class CalloutPayment extends CalloutEngine
|
||||||
&& Env.getContextAsInt (ctx, WindowNo, "C_BPartner_ID") == 0
|
&& Env.getContextAsInt (ctx, WindowNo, "C_BPartner_ID") == 0
|
||||||
&& C_Invoice_ID == 0)
|
&& C_Invoice_ID == 0)
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
// Changed Column
|
// Changed Column
|
||||||
String colName = mField.getColumnName ();
|
String colName = mField.getColumnName ();
|
||||||
if (colName.equals("IsOverUnderPayment") // Set Over/Under Amt to Zero
|
if (colName.equals ("IsOverUnderPayment") // Set Over/Under Amt to
|
||||||
|| !"Y".equals(Env.getContext(ctx, WindowNo, "IsOverUnderPayment")))
|
// Zero
|
||||||
|
|| !"Y".equals (Env
|
||||||
|
.getContext (ctx, WindowNo, "IsOverUnderPayment")))
|
||||||
mTab.setValue ("OverUnderAmt", Env.ZERO);
|
mTab.setValue ("OverUnderAmt", Env.ZERO);
|
||||||
|
|
||||||
int C_InvoicePaySchedule_ID = 0;
|
int C_InvoicePaySchedule_ID = 0;
|
||||||
if (Env.getContextAsInt(ctx, Env.WINDOW_INFO, Env.TAB_INFO, "C_Invoice_ID") == C_Invoice_ID
|
if (Env.getContextAsInt (ctx, Env.WINDOW_INFO, Env.TAB_INFO,
|
||||||
&& Env.getContextAsInt(ctx, Env.WINDOW_INFO, Env.TAB_INFO, "C_InvoicePaySchedule_ID") != 0)
|
"C_Invoice_ID") == C_Invoice_ID
|
||||||
C_InvoicePaySchedule_ID = Env.getContextAsInt(ctx, Env.WINDOW_INFO, Env.TAB_INFO, "C_InvoicePaySchedule_ID");
|
&& Env.getContextAsInt (ctx, Env.WINDOW_INFO, Env.TAB_INFO,
|
||||||
|
"C_InvoicePaySchedule_ID") != 0)
|
||||||
|
C_InvoicePaySchedule_ID = Env.getContextAsInt (ctx,
|
||||||
|
Env.WINDOW_INFO, Env.TAB_INFO, "C_InvoicePaySchedule_ID");
|
||||||
// Get Open Amount & Invoice Currency
|
// Get Open Amount & Invoice Currency
|
||||||
BigDecimal InvoiceOpenAmt = Env.ZERO;
|
BigDecimal InvoiceOpenAmt = Env.ZERO;
|
||||||
int C_Currency_Invoice_ID = 0;
|
int C_Currency_Invoice_ID = 0;
|
||||||
|
@ -355,7 +350,8 @@ public class CalloutPayment extends CalloutEngine
|
||||||
if (rs.next ())
|
if (rs.next ())
|
||||||
{
|
{
|
||||||
C_Currency_Invoice_ID = rs.getInt (2);
|
C_Currency_Invoice_ID = rs.getInt (2);
|
||||||
InvoiceOpenAmt = rs.getBigDecimal(3); // Set Invoice Open Amount
|
InvoiceOpenAmt = rs.getBigDecimal (3); // Set Invoice Open
|
||||||
|
// Amount
|
||||||
if (InvoiceOpenAmt == null)
|
if (InvoiceOpenAmt == null)
|
||||||
InvoiceOpenAmt = Env.ZERO;
|
InvoiceOpenAmt = Env.ZERO;
|
||||||
}
|
}
|
||||||
|
@ -368,21 +364,22 @@ public class CalloutPayment extends CalloutEngine
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
DB.close (rs, pstmt);
|
DB.close (rs, pstmt);
|
||||||
rs = null; pstmt = null;
|
rs = null;
|
||||||
|
pstmt = null;
|
||||||
}
|
}
|
||||||
} // get Invoice Info
|
} // get Invoice Info
|
||||||
log.fine ("Open=" + InvoiceOpenAmt + ", C_Invoice_ID=" + C_Invoice_ID
|
log.fine ("Open=" + InvoiceOpenAmt + ", C_Invoice_ID=" + C_Invoice_ID
|
||||||
+ ", C_Currency_ID=" + C_Currency_Invoice_ID);
|
+ ", C_Currency_ID=" + C_Currency_Invoice_ID);
|
||||||
|
|
||||||
// Get Info from Tab
|
// Get Info from Tab
|
||||||
BigDecimal PayAmt = (BigDecimal)mTab.getValue ("PayAmt");
|
BigDecimal PayAmt = (BigDecimal)mTab.getValue ("PayAmt");
|
||||||
BigDecimal DiscountAmt = (BigDecimal)mTab.getValue ("DiscountAmt");
|
BigDecimal DiscountAmt = (BigDecimal)mTab.getValue ("DiscountAmt");
|
||||||
BigDecimal WriteOffAmt = (BigDecimal)mTab.getValue ("WriteOffAmt");
|
BigDecimal WriteOffAmt = (BigDecimal)mTab.getValue ("WriteOffAmt");
|
||||||
BigDecimal OverUnderAmt = (BigDecimal)mTab.getValue ("OverUnderAmt");
|
BigDecimal OverUnderAmt = (BigDecimal)mTab.getValue ("OverUnderAmt");
|
||||||
log.fine("Pay=" + PayAmt + ", Discount=" + DiscountAmt
|
log.fine ("Pay=" + PayAmt + ", Discount=" + DiscountAmt + ", WriteOff="
|
||||||
+ ", WriteOff=" + WriteOffAmt + ", OverUnderAmt=" + OverUnderAmt);
|
+ WriteOffAmt + ", OverUnderAmt=" + OverUnderAmt);
|
||||||
// Get Currency Info
|
// Get Currency Info
|
||||||
int C_Currency_ID = ((Integer)mTab.getValue("C_Currency_ID")).intValue();
|
int C_Currency_ID = ((Integer)mTab.getValue ("C_Currency_ID"))
|
||||||
|
.intValue ();
|
||||||
MCurrency currency = MCurrency.get (ctx, C_Currency_ID);
|
MCurrency currency = MCurrency.get (ctx, C_Currency_ID);
|
||||||
Timestamp ConvDate = (Timestamp)mTab.getValue ("DateTrx");
|
Timestamp ConvDate = (Timestamp)mTab.getValue ("DateTrx");
|
||||||
int C_ConversionType_ID = 0;
|
int C_ConversionType_ID = 0;
|
||||||
|
@ -393,45 +390,47 @@ public class CalloutPayment extends CalloutEngine
|
||||||
int AD_Org_ID = Env.getContextAsInt (ctx, WindowNo, "AD_Org_ID");
|
int AD_Org_ID = Env.getContextAsInt (ctx, WindowNo, "AD_Org_ID");
|
||||||
// Get Currency Rate
|
// Get Currency Rate
|
||||||
BigDecimal CurrencyRate = Env.ONE;
|
BigDecimal CurrencyRate = Env.ONE;
|
||||||
if ((C_Currency_ID > 0 && C_Currency_Invoice_ID > 0 &&
|
if ((C_Currency_ID > 0 && C_Currency_Invoice_ID > 0 && C_Currency_ID != C_Currency_Invoice_ID)
|
||||||
C_Currency_ID != C_Currency_Invoice_ID)
|
|| colName.equals ("C_Currency_ID")
|
||||||
|| colName.equals("C_Currency_ID") || colName.equals("C_ConversionType_ID"))
|
|| colName.equals ("C_ConversionType_ID"))
|
||||||
{
|
{
|
||||||
log.fine("InvCurrency=" + C_Currency_Invoice_ID
|
log.fine ("InvCurrency=" + C_Currency_Invoice_ID + ", PayCurrency="
|
||||||
+ ", PayCurrency=" + C_Currency_ID
|
+ C_Currency_ID + ", Date=" + ConvDate + ", Type="
|
||||||
+ ", Date=" + ConvDate + ", Type=" + C_ConversionType_ID);
|
+ C_ConversionType_ID);
|
||||||
CurrencyRate = MConversionRate.getRate (C_Currency_Invoice_ID, C_Currency_ID,
|
CurrencyRate = MConversionRate.getRate (C_Currency_Invoice_ID,
|
||||||
ConvDate, C_ConversionType_ID, AD_Client_ID, AD_Org_ID);
|
C_Currency_ID, ConvDate, C_ConversionType_ID, AD_Client_ID,
|
||||||
|
AD_Org_ID);
|
||||||
if (CurrencyRate == null || CurrencyRate.compareTo (Env.ZERO) == 0)
|
if (CurrencyRate == null || CurrencyRate.compareTo (Env.ZERO) == 0)
|
||||||
{
|
{
|
||||||
// mTab.setValue("C_Currency_ID", new Integer(C_Currency_Invoice_ID)); // does not work
|
// mTab.setValue("C_Currency_ID", new
|
||||||
|
// Integer(C_Currency_Invoice_ID)); // does not work
|
||||||
if (C_Currency_Invoice_ID == 0)
|
if (C_Currency_Invoice_ID == 0)
|
||||||
return ""; // no error message when no invoice is selected
|
return ""; // no error message when no invoice is selected
|
||||||
return "NoCurrencyConversion";
|
return "NoCurrencyConversion";
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
InvoiceOpenAmt = InvoiceOpenAmt.multiply(CurrencyRate)
|
InvoiceOpenAmt = InvoiceOpenAmt.multiply (CurrencyRate).setScale (
|
||||||
.setScale(currency.getStdPrecision(), BigDecimal.ROUND_HALF_UP);
|
currency.getStdPrecision (), BigDecimal.ROUND_HALF_UP);
|
||||||
log.fine("Rate=" + CurrencyRate + ", InvoiceOpenAmt=" + InvoiceOpenAmt);
|
log.fine ("Rate=" + CurrencyRate + ", InvoiceOpenAmt="
|
||||||
|
+ InvoiceOpenAmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Currency Changed - convert all
|
// Currency Changed - convert all
|
||||||
if (colName.equals("C_Currency_ID") || colName.equals("C_ConversionType_ID"))
|
if (colName.equals ("C_Currency_ID")
|
||||||
|
|| colName.equals ("C_ConversionType_ID"))
|
||||||
{
|
{
|
||||||
PayAmt = PayAmt.multiply(CurrencyRate)
|
PayAmt = PayAmt.multiply (CurrencyRate).setScale (
|
||||||
.setScale(currency.getStdPrecision(), BigDecimal.ROUND_HALF_UP);
|
currency.getStdPrecision (), BigDecimal.ROUND_HALF_UP);
|
||||||
mTab.setValue ("PayAmt", PayAmt);
|
mTab.setValue ("PayAmt", PayAmt);
|
||||||
DiscountAmt = DiscountAmt.multiply(CurrencyRate)
|
DiscountAmt = DiscountAmt.multiply (CurrencyRate).setScale (
|
||||||
.setScale(currency.getStdPrecision(), BigDecimal.ROUND_HALF_UP);
|
currency.getStdPrecision (), BigDecimal.ROUND_HALF_UP);
|
||||||
mTab.setValue ("DiscountAmt", DiscountAmt);
|
mTab.setValue ("DiscountAmt", DiscountAmt);
|
||||||
WriteOffAmt = WriteOffAmt.multiply(CurrencyRate)
|
WriteOffAmt = WriteOffAmt.multiply (CurrencyRate).setScale (
|
||||||
.setScale(currency.getStdPrecision(), BigDecimal.ROUND_HALF_UP);
|
currency.getStdPrecision (), BigDecimal.ROUND_HALF_UP);
|
||||||
mTab.setValue ("WriteOffAmt", WriteOffAmt);
|
mTab.setValue ("WriteOffAmt", WriteOffAmt);
|
||||||
OverUnderAmt = OverUnderAmt.multiply(CurrencyRate)
|
OverUnderAmt = OverUnderAmt.multiply (CurrencyRate).setScale (
|
||||||
.setScale(currency.getStdPrecision(), BigDecimal.ROUND_HALF_UP);
|
currency.getStdPrecision (), BigDecimal.ROUND_HALF_UP);
|
||||||
mTab.setValue ("OverUnderAmt", OverUnderAmt);
|
mTab.setValue ("OverUnderAmt", OverUnderAmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
// No Invoice - Set Discount, Witeoff, Under/Over to 0
|
// No Invoice - Set Discount, Witeoff, Under/Over to 0
|
||||||
else if (C_Invoice_ID == 0)
|
else if (C_Invoice_ID == 0)
|
||||||
{
|
{
|
||||||
|
@ -444,35 +443,57 @@ public class CalloutPayment extends CalloutEngine
|
||||||
}
|
}
|
||||||
// PayAmt - calculate write off
|
// PayAmt - calculate write off
|
||||||
// Added Lines By Goodwill (02-03-2006)
|
// Added Lines By Goodwill (02-03-2006)
|
||||||
//Reason: we must make the callout is called just when docstatus is draft
|
// Reason: we must make the callout is called just when docstatus is
|
||||||
|
// draft
|
||||||
// Old Code : else if (colName.equals("PayAmt"))
|
// Old Code : else if (colName.equals("PayAmt"))
|
||||||
// New Code :
|
// New Code :
|
||||||
else if (colName.equals("PayAmt") && mTab.get_ValueAsString("DocStatus").equals("DR"))
|
else if (colName.equals ("PayAmt")
|
||||||
//End By Goodwill
|
&& mTab.get_ValueAsString ("DocStatus").equals ("DR")
|
||||||
|
&& "Y"
|
||||||
|
.equals (Env.getContext (ctx, WindowNo, "IsOverUnderPayment")))
|
||||||
{
|
{
|
||||||
WriteOffAmt = InvoiceOpenAmt.subtract(PayAmt).subtract(DiscountAmt).subtract(OverUnderAmt);
|
OverUnderAmt = InvoiceOpenAmt.subtract (PayAmt).subtract (
|
||||||
//Added Lines By Goodwill
|
DiscountAmt).subtract (WriteOffAmt);
|
||||||
//Reason: if overunderpayment is checked then the amount set to overunderamt automaticly
|
mTab.setValue ("OverUnderAmt", OverUnderAmt);
|
||||||
//Old Code:
|
}
|
||||||
//mTab.setValue("WriteOffAmt", WriteOffAmt);
|
else if (colName.equals ("PayAmt")
|
||||||
//New Code:
|
&& mTab.get_ValueAsString ("DocStatus").equals ("DR"))
|
||||||
if(!"Y".equals(Env.getContext(ctx, WindowNo, "IsOverUnderPayment")))
|
{
|
||||||
|
WriteOffAmt = InvoiceOpenAmt.subtract (PayAmt).subtract (
|
||||||
|
DiscountAmt).subtract (OverUnderAmt);
|
||||||
mTab.setValue ("WriteOffAmt", WriteOffAmt);
|
mTab.setValue ("WriteOffAmt", WriteOffAmt);
|
||||||
else
|
}
|
||||||
mTab.setValue("OverUnderAmt", WriteOffAmt);
|
else if (colName.equals ("IsOverUnderPayment")
|
||||||
//End Of Added Lines
|
&& mTab.get_ValueAsString ("DocStatus").equals ("DR"))
|
||||||
|
{
|
||||||
|
boolean overUnderPaymentActive = "Y".equals (Env.getContext (ctx,
|
||||||
|
WindowNo, "IsOverUnderPayment"));
|
||||||
|
if (overUnderPaymentActive)
|
||||||
|
{
|
||||||
|
OverUnderAmt = InvoiceOpenAmt.subtract (PayAmt).subtract (
|
||||||
|
DiscountAmt);
|
||||||
|
mTab.setValue ("WriteOffAmt", Env.ZERO);
|
||||||
|
mTab.setValue ("OverUnderAmt", OverUnderAmt);
|
||||||
|
}else{
|
||||||
|
WriteOffAmt = InvoiceOpenAmt.subtract (PayAmt).subtract (
|
||||||
|
DiscountAmt);
|
||||||
|
mTab.setValue ("WriteOffAmt", WriteOffAmt);
|
||||||
|
mTab.setValue ("OverUnderAmt", Env.ZERO);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Added Lines By Goodwill (02-03-2006)
|
// Added Lines By Goodwill (02-03-2006)
|
||||||
//Reason: we must make the callout is called just when docstatus is draft
|
// Reason: we must make the callout is called just when docstatus is
|
||||||
|
// draft
|
||||||
// Old Code : else // calculate PayAmt
|
// Old Code : else // calculate PayAmt
|
||||||
// New Code :
|
// New Code :
|
||||||
else if(mTab.get_ValueAsString("DocStatus").equals("DR")) // calculate PayAmt
|
else if (mTab.get_ValueAsString ("DocStatus").equals ("DR")) // calculate
|
||||||
|
// PayAmt
|
||||||
// End By Goodwill
|
// End By Goodwill
|
||||||
{
|
{
|
||||||
PayAmt = InvoiceOpenAmt.subtract(DiscountAmt).subtract(WriteOffAmt).subtract(OverUnderAmt);
|
PayAmt = InvoiceOpenAmt.subtract (DiscountAmt).subtract (
|
||||||
|
WriteOffAmt).subtract (OverUnderAmt);
|
||||||
mTab.setValue ("PayAmt", PayAmt);
|
mTab.setValue ("PayAmt", PayAmt);
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
} // amounts
|
} // amounts
|
||||||
|
|
||||||
} // CalloutPayment
|
} // CalloutPayment
|
||||||
|
|
Loading…
Reference in New Issue