IDEMPIERE-5316 Refactoring of Payment Allocation Form (#1364)

This commit is contained in:
hengsin 2022-06-14 20:20:06 +08:00 committed by GitHub
parent 5bd585c522
commit c53fb6430e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 1292 additions and 343 deletions

View File

@ -28,6 +28,7 @@ import java.util.Arrays;
import java.util.Hashtable;
import java.util.List;
import java.util.Properties;
import java.util.Vector;
import java.util.logging.Level;
import org.adempiere.base.Core;
@ -46,6 +47,7 @@ import org.compiere.process.ServerProcessCtl;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.KeyNamePair;
import org.compiere.util.Msg;
import org.compiere.util.TimeUtil;
import org.eevolution.model.MPPProductBOM;
@ -2892,4 +2894,151 @@ public class MInvoice extends X_C_Invoice implements DocAction, IDocsPostProcess
return getC_DocType_ID() > 0 ? getC_DocType_ID() : getC_DocTypeTarget_ID();
}
/**
* Index constant for Vector<Object> record return by getUnpaidInvoiceData.
* Use MULTI_CURRENCY index if isMultiCurrency=true.
* Use SINGLE_CURRENCY index if isMultiCurrency=false.
*/
//selected row, boolean
public static final int UNPAID_INVOICE_SELECTED = 0;
//transaction date, timestamp
public static final int UNPAID_INVOICE_TRX_DATE = 1;
//KeyNamePair, DocumentNo and C_Invoice_ID
public static final int UNPAID_INVOICE_DOCUMENT_KEY_NAME_PAIR = 2;
//multi currency record, invoice currency iso code
public static final int UNPAID_INVOICE_MULTI_CURRENCY_ISO = 3;
//multi currency record, invoice amount
public static final int UNPAID_INVOICE_MULTI_CURRENCY_INVOICE_AMT = 4;
//multi currency record, invoice amount converted to base currency
public static final int UNPAID_INVOICE_MULTI_CURRENCY_CONVERTED_AMT = 5;
//multi currency record, open invoice amount
public static final int UNPAID_INVOICE_MULTI_CURRENCY_OPEN_AMT = 6;
//multi currency record, discount amount converted to base currency
public static final int UNPAID_INVOICE_MULTI_CURRENCY_CONVERTED_DISCOUNT_AMT = 7;
//multi currency record, write off amount
public static final int UNPAID_INVOICE_MULTI_CURRENCY_WRITE_OFF_AMT = 8;
//multi currency record, invoice applied amount
public static final int UNPAID_INVOICE_MULTI_CURRENCY_APPLIED_AMT = 9;
//multi currency record, over or under applied amount
public static final int UNPAID_INVOICE_MULTI_CURRENCY_OVER_UNDER_AMT = 10;
//single currency record, invoice amount
public static final int UNPAID_INVOICE_SINGLE_CURRENCY_INVOICE_AMT = 3;
//single currency record, open invoice amount
public static final int UNPAID_INVOICE_SINGLE_CURRENCY_OPEN_AMT = 4;
//single currency record, discount amount
public static final int UNPAID_INVOICE_SINGLE_CURRENCY_DISCOUNT_AMT = 5;
//single currency record, write off amount
public static final int UNPAID_INVOICE_SINGLE_CURRENCY_WRITE_OFF_AMT = 6;
//single currency record, invoice applied amount
public static final int UNPAID_INVOICE_SINGLE_CURRENCY_APPLIED_AMT = 7;
//single currency record, over or under applied amount
public static final int UNPAID_INVOICE_SINGLE_CURRENCY_OVER_UNDER_AMT = 8;
/**
*
* @param isMultiCurrency false to apply currency filter
* @param date invoice open amount as at date
* @param AD_Org_ID 0 for all orgs
* @param C_Currency_ID mandatory, use as invoice document filter if isMultiCurrency is false
* @param C_BPartner_ID mandatory bpartner filter
* @param trxName optional trx name
* @return list of unpaid invoice data
*/
public static Vector<Vector<Object>> getUnpaidInvoiceData(boolean isMultiCurrency, Timestamp date, int AD_Org_ID, int C_Currency_ID,
int C_BPartner_ID, String trxName)
{
/********************************
* Load unpaid Invoices
* 1-TrxDate, 2-Value, (3-Currency, 4-InvAmt,)
* 5-ConvAmt, 6-ConvOpen, 7-ConvDisc, 8-WriteOff, 9-Applied
*
SELECT i.DateInvoiced,i.DocumentNo,i.C_Invoice_ID,c.ISO_Code,
i.GrandTotal*i.MultiplierAP "GrandTotal",
currencyConvert(i.GrandTotal*i.MultiplierAP,i.C_Currency_ID,i.C_Currency_ID,i.DateInvoiced,i.C_ConversionType_ID,i.AD_Client_ID,i.AD_Org_ID) "GrandTotal $",
invoiceOpen(C_Invoice_ID,C_InvoicePaySchedule_ID) "Open",
currencyConvert(invoiceOpen(C_Invoice_ID,C_InvoicePaySchedule_ID),i.C_Currency_ID,i.C_Currency_ID,i.DateInvoiced,i.C_ConversionType_ID,i.AD_Client_ID,i.AD_Org_ID)*i.MultiplierAP "Open $",
invoiceDiscount(i.C_Invoice_ID,getDate(),C_InvoicePaySchedule_ID) "Discount",
currencyConvert(invoiceDiscount(i.C_Invoice_ID,getDate(),C_InvoicePaySchedule_ID),i.C_Currency_ID,i.C_Currency_ID,i.DateInvoiced,i.C_ConversionType_ID,i.AD_Client_ID,i.AD_Org_ID)*i.Multiplier*i.MultiplierAP "Discount $",
i.MultiplierAP, i.Multiplier
FROM C_Invoice_v i INNER JOIN C_Currency c ON (i.C_Currency_ID=c.C_Currency_ID)
WHERE -- i.IsPaid='N' AND i.Processed='Y' AND i.C_BPartner_ID=1000001
*/
Vector<Vector<Object>> data = new Vector<Vector<Object>>();
StringBuilder sql = new StringBuilder("SELECT i.DateInvoiced,i.DocumentNo,i.C_Invoice_ID," // 1..3
+ "c.ISO_Code,i.GrandTotal*i.MultiplierAP, " // 4..5 Orig Currency
+ "currencyConvertInvoice(i.C_Invoice_ID,?,i.GrandTotal*i.MultiplierAP,?), " // 6 #1 Converted, #2 Date
+ "currencyConvertInvoice(i.C_Invoice_ID,?,invoiceOpen(C_Invoice_ID,C_InvoicePaySchedule_ID),?)*i.MultiplierAP, " // 7 #3, #4 Converted Open
+ "currencyConvertInvoice(i.C_Invoice_ID" // 8 AllowedDiscount
+ ",?,invoiceDiscount(i.C_Invoice_ID,?,C_InvoicePaySchedule_ID),i.DateInvoiced)*i.Multiplier*i.MultiplierAP," // #5, #6
+ "i.MultiplierAP "
+ "FROM C_Invoice_v i" // corrected for CM/Split
+ " INNER JOIN C_Currency c ON (i.C_Currency_ID=c.C_Currency_ID) "
+ "WHERE i.IsPaid='N' AND i.Processed='Y'"
+ " AND i.C_BPartner_ID=?"); // #7
if (!isMultiCurrency)
sql.append(" AND i.C_Currency_ID=?"); // #8
if (AD_Org_ID != 0 )
sql.append(" AND i.AD_Org_ID=" + AD_Org_ID);
sql.append(" ORDER BY i.DateInvoiced, i.DocumentNo");
if (s_log.isLoggable(Level.FINE)) s_log.fine("InvSQL=" + sql.toString());
// role security
sql = new StringBuilder( MRole.getDefault(Env.getCtx(), false).addAccessSQL( sql.toString(), "i", MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO ) );
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql.toString(), trxName);
pstmt.setInt(1, C_Currency_ID);
pstmt.setTimestamp(2, date);
pstmt.setInt(3, C_Currency_ID);
pstmt.setTimestamp(4, date);
pstmt.setInt(5, C_Currency_ID);
pstmt.setTimestamp(6, date);
pstmt.setInt(7, C_BPartner_ID);
if (!isMultiCurrency)
pstmt.setInt(8, C_Currency_ID);
rs = pstmt.executeQuery();
while (rs.next())
{
Vector<Object> line = new Vector<Object>();
line.add(Boolean.FALSE); // 0-Selection
line.add(rs.getTimestamp(1)); // 1-TrxDate
KeyNamePair pp = new KeyNamePair(rs.getInt(3), rs.getString(2));
line.add(pp); // 2-Value
if (isMultiCurrency)
{
line.add(rs.getString(4)); // 3-Currency
line.add(rs.getBigDecimal(5)); // 4-Orig Amount
}
line.add(rs.getBigDecimal(6)); // 3/5-ConvAmt
BigDecimal open = rs.getBigDecimal(7);
if (open == null) // no conversion rate
open = Env.ZERO;
line.add(open); // 4/6-ConvOpen
BigDecimal discount = rs.getBigDecimal(8);
if (discount == null) // no concersion rate
discount = Env.ZERO;
line.add(discount); // 5/7-ConvAllowedDisc
line.add(Env.ZERO); // 6/8-WriteOff
line.add(Env.ZERO); // 7/9-Applied
line.add(open); // 8/10-OverUnder
// Add when open <> 0 (i.e. not if no conversion rate)
if (Env.ZERO.compareTo(open) != 0)
data.add(line);
}
}
catch (SQLException e)
{
s_log.log(Level.SEVERE, sql.toString(), e);
}
finally
{
DB.close(rs, pstmt);
}
return data;
}
} // MInvoice

View File

@ -26,6 +26,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Properties;
import java.util.Vector;
import java.util.logging.Level;
import org.adempiere.exceptions.AdempiereException;
@ -41,6 +42,7 @@ import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.IBAN;
import org.compiere.util.KeyNamePair;
import org.compiere.util.Msg;
import org.compiere.util.TimeUtil;
import org.compiere.util.Trx;
@ -3126,4 +3128,120 @@ public class MPayment extends X_C_Payment
return m_justCreatedAllocInv;
}
/**
* Index constants for Vector<Object> record return by getUnAllocatedPaymentData.
* Use MULTI_CURRENCY index if isMultiCurrency=true.
* Use SINGLE_CURRENCY index if isMultiCurrency=false;
*/
//selected row, boolean
public static final int UNALLOCATED_PAYMENT_SELECTED=0;
//transaction date, timestamp
public static final int UNALLOCATED_PAYMENT_TRX_DATE=1;
//KeyNamePair, DocumentNo and C_Payment_ID
public static final int UNALLOCATED_PAYMENT_DOCUMENT_KEY_NAME_PAIR=2;
//multi currency record, currency iso code
public static final int UNALLOCATED_PAYMENT_MULTI_CURRENCY_ISO=3;
//multi currency record, payment amount
public static final int UNALLOCATED_PAYMENT_MULTI_CURRENCY_PAYMENT_AMT=4;
//multi currency record, payment amount converted to base currency
public static final int UNALLOCATED_PAYMENT_MULTI_CURRENCY_CONVERTED_AMT=5;
//multi currency record, open payment amount
public static final int UNALLOCATED_PAYMENT_MULTI_CURRENCY_OPEN_AMT=6;
//multi currency record, payment applied amount
public static final int UNALLOCATED_PAYMENT_MULTI_CURRENCY_APPLIED_AMT=7;
//single currency record, payment amount
public static final int UNALLOCATED_PAYMENT_SINGLE_CURRENCY_AMT=3;
//single currency record, open payment amount
public static final int UNALLOCATED_PAYMENT_SINGLE_CURRENCY_OPEN_AMT=4;
//single currency record, payment applied amount
public static final int UNALLOCATED_PAYMENT_SINGLE_CURRENCY_APPLIED_AMT=5;
/**
*
* @param C_BPartner_ID mandatory bpartner filter
* @param C_Currency_ID 0 to use login currency. use for payment filter if isMultiCurrency=false
* @param isMultiCurrency false to apply currency filter
* @param date payment allocation as at date
* @param AD_Org_ID 0 for all org
* @param trxName optional transaction name
* @return list of unallocated payment records
*/
public static Vector<Vector<Object>> getUnAllocatedPaymentData(int C_BPartner_ID, int C_Currency_ID, boolean isMultiCurrency,
Timestamp date, int AD_Org_ID, String trxName)
{
if (C_Currency_ID==0)
C_Currency_ID = Env.getContextAsInt(Env.getCtx(), Env.C_CURRENCY_ID); // default
/********************************
* Load unallocated Payments
* 1-TrxDate, 2-DocumentNo, (3-Currency, 4-PayAmt,)
* 5-ConvAmt, 6-ConvOpen, 7-Allocated
*/
Vector<Vector<Object>> data = new Vector<Vector<Object>>();
StringBuilder sql = new StringBuilder("SELECT p.DateTrx,p.DocumentNo,p.C_Payment_ID," // 1..3
+ "c.ISO_Code,p.PayAmt," // 4..5
+ "currencyConvertPayment(p.C_Payment_ID,?,null,?),"// 6 #1, #2
+ "currencyConvertPayment(p.C_Payment_ID,?,paymentAvailable(p.C_Payment_ID),?)," // 7 #3, #4
+ "p.MultiplierAP "
+ "FROM C_Payment_v p" // Corrected for AP/AR
+ " INNER JOIN C_Currency c ON (p.C_Currency_ID=c.C_Currency_ID) "
+ "WHERE p.IsAllocated='N' AND p.Processed='Y'"
+ " AND p.C_Charge_ID IS NULL" // Prepayments OK
+ " AND p.C_BPartner_ID=?"); // #5
if (!isMultiCurrency)
sql.append(" AND p.C_Currency_ID=?"); // #6
if (AD_Org_ID != 0 )
sql.append(" AND p.AD_Org_ID=" + AD_Org_ID);
sql.append(" ORDER BY p.DateTrx,p.DocumentNo");
// role security
sql = new StringBuilder( MRole.getDefault(Env.getCtx(), false).addAccessSQL( sql.toString(), "p", MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO ) );
if (s_log.isLoggable(Level.FINE)) s_log.fine("PaySQL=" + sql.toString());
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql.toString(), trxName);
pstmt.setInt(1, C_Currency_ID);
pstmt.setTimestamp(2, (Timestamp)date);
pstmt.setInt(3, C_Currency_ID);
pstmt.setTimestamp(4, (Timestamp)date);
pstmt.setInt(5, C_BPartner_ID);
if (!isMultiCurrency)
pstmt.setInt(6, C_Currency_ID);
rs = pstmt.executeQuery();
while (rs.next())
{
Vector<Object> line = new Vector<Object>();
line.add(Boolean.FALSE); // 0-Selection
line.add(rs.getTimestamp(1)); // 1-TrxDate
KeyNamePair pp = new KeyNamePair(rs.getInt(3), rs.getString(2));
line.add(pp); // 2-DocumentNo
if (isMultiCurrency)
{
line.add(rs.getString(4)); // 3-Currency
line.add(rs.getBigDecimal(5)); // 4-PayAmt
}
line.add(rs.getBigDecimal(6)); // 3/5-ConvAmt
BigDecimal available = rs.getBigDecimal(7);
if (available == null || available.signum() == 0) // nothing available
continue;
line.add(available); // 4/6-ConvOpen/Available
line.add(Env.ZERO); // 5/7-Applied
//
data.add(line);
}
}
catch (SQLException e)
{
s_log.log(Level.SEVERE, sql.toString(), e);
}
finally
{
DB.close(rs, pstmt);
}
return data;
}
} // MPayment

View File

@ -435,7 +435,7 @@ public class WAllocation extends Allocation
int AD_Column_ID = COLUMN_C_INVOICE_C_CURRENCY_ID; // C_Invoice.C_Currency_ID
MLookup lookupCur = MLookupFactory.get (Env.getCtx(), form.getWindowNo(), 0, AD_Column_ID, DisplayType.TableDir);
currencyPick = new WTableDirEditor("C_Currency_ID", true, false, true, lookupCur);
currencyPick.setValue(Integer.valueOf(m_C_Currency_ID));
currencyPick.setValue(getC_Currency_ID());
currencyPick.addValueChangeListener(this);
// Organization filter selection
@ -465,19 +465,18 @@ public class WAllocation extends Allocation
dateField.setValue(new Timestamp(cal.getTimeInMillis()));
dateField.addValueChangeListener(this);
// Charge
AD_Column_ID = 61804; // C_AllocationLine.C_Charge_ID
MLookup lookupCharge = MLookupFactory.get (Env.getCtx(), form.getWindowNo(), 0, AD_Column_ID, DisplayType.TableDir);
chargePick = new WTableDirEditor("C_Charge_ID", false, false, true, lookupCharge);
chargePick.setValue(Integer.valueOf(m_C_Charge_ID));
chargePick.setValue(getC_Charge_ID());
chargePick.addValueChangeListener(this);
// Charge
AD_Column_ID = 212213; // C_AllocationLine.C_Charge_ID
// Doc Type
AD_Column_ID = 212213; // C_AllocationLine.C_DocType_ID
MLookup lookupDocType = MLookupFactory.get (Env.getCtx(), form.getWindowNo(), 0, AD_Column_ID, DisplayType.TableDir);
DocTypePick = new WTableDirEditor("C_DocType_ID", false, false, true, lookupDocType);
DocTypePick.setValue(Integer.valueOf(m_C_DocType_ID));
DocTypePick.setValue(getC_DocType_ID());
DocTypePick.addValueChangeListener(this);
} // dynInit
@ -540,7 +539,7 @@ public class WAllocation extends Allocation
{
loadBPartner();
}
} // actionPerformed
}
/**
* Table Model Listener.
@ -596,35 +595,34 @@ public class WAllocation extends Allocation
// Organization
if (name.equals("AD_Org_ID"))
{
m_AD_Org_ID = ((Integer) value).intValue();
setAD_Org_ID((int) value);
loadBPartner();
}
// Charge
else if (name.equals("C_Charge_ID") )
{
m_C_Charge_ID = value!=null? ((Integer) value).intValue() : 0;
setC_Charge_ID(value!=null? ((Integer) value).intValue() : 0);
setAllocateButton();
}
else if (name.equals("C_DocType_ID") )
{
m_C_DocType_ID = value!=null? ((Integer) value).intValue() : 0;
setC_DocType_ID(value!=null? ((Integer) value).intValue() : 0);
}
// BPartner
if (name.equals("C_BPartner_ID"))
{
bpartnerSearch.setValue(value);
m_C_BPartner_ID = ((Integer)value).intValue();
setC_BPartner_ID((int) value);
loadBPartner();
}
// Currency
else if (name.equals("C_Currency_ID"))
{
m_C_Currency_ID = ((Integer)value).intValue();
setC_Currency_ID((int) value);
loadBPartner();
}
// Date for Multi-Currency
@ -633,22 +631,22 @@ public class WAllocation extends Allocation
} // vetoableChange
private void setAllocateButton() {
if (totalDiff.signum() == 0 ^ m_C_Charge_ID > 0 )
if (isOkToAllocate() )
{
allocateButton.setEnabled(true);
// chargePick.setValue(m_C_Charge_ID);
}
else
{
allocateButton.setEnabled(false);
}
if ( totalDiff.signum() == 0 )
if ( getTotalDifference().signum() == 0 )
{
chargePick.setValue(null);
m_C_Charge_ID = 0;
setC_Charge_ID(0);
}
}
/**
* Load Business Partner Info
* - Payments
@ -658,7 +656,7 @@ public class WAllocation extends Allocation
{
checkBPartner();
Vector<Vector<Object>> data = getPaymentData(multiCurrency.isSelected(), dateField.getValue(), paymentTable);
Vector<Vector<Object>> data = getPaymentData(multiCurrency.isSelected(), dateField.getValue(), (String)null);
Vector<String> columnNames = getPaymentColumnNames(multiCurrency.isSelected());
paymentTable.clear();
@ -673,7 +671,7 @@ public class WAllocation extends Allocation
setPaymentColumnClass(paymentTable, multiCurrency.isSelected());
//
data = getInvoiceData(multiCurrency.isSelected(), dateField.getValue(), invoiceTable);
data = getInvoiceData(multiCurrency.isSelected(), dateField.getValue(), (String)null);
columnNames = getInvoiceColumnNames(multiCurrency.isSelected());
invoiceTable.clear();
@ -688,20 +686,22 @@ public class WAllocation extends Allocation
setInvoiceColumnClass(invoiceTable, multiCurrency.isSelected());
//
calculate(multiCurrency.isSelected());
// Calculate Totals
calculate();
statusBar.getChildren().clear();
} // loadBPartner
/**
* perform allocation calculation
*/
public void calculate()
{
allocDate = null;
calculate(paymentTable, invoiceTable, multiCurrency.isSelected());
paymentInfo.setText(calculatePayment(paymentTable, multiCurrency.isSelected()));
invoiceInfo.setText(calculateInvoice(invoiceTable, multiCurrency.isSelected()));
paymentInfo.setText(getPaymentInfoText());
invoiceInfo.setText(getInvoiceInfoText());
differenceField.setText(format.format(getTotalDifference()));
// Set AllocationDate
if (allocDate != null) {
@ -713,9 +713,6 @@ public class WAllocation extends Allocation
// Set Allocation Currency
allocCurrencyLabel.setText(currencyPick.getDisplay());
// Difference
totalDiff = totalPay.subtract(totalInv);
differenceField.setText(format.format(totalDiff));
setAllocateButton();
}
@ -725,8 +722,8 @@ public class WAllocation extends Allocation
*/
private MAllocationHdr saveData()
{
if (m_AD_Org_ID > 0)
Env.setContext(Env.getCtx(), form.getWindowNo(), "AD_Org_ID", m_AD_Org_ID);
if (getAD_Org_ID() > 0)
Env.setContext(Env.getCtx(), form.getWindowNo(), "AD_Org_ID", getAD_Org_ID());
else
Env.setContext(Env.getCtx(), form.getWindowNo(), "AD_Org_ID", "");
try
@ -753,7 +750,7 @@ public class WAllocation extends Allocation
/**
* Called by org.adempiere.webui.panel.ADForm.openForm(int)
* @return
* @return {@link ADForm}
*/
public ADForm getForm()
{

View File

@ -155,7 +155,7 @@ public class WDateEditor extends WEditor implements ContextMenuListener
}
@Override
public Object getValue()
public Timestamp getValue()
{
// Elaine 2008/07/25
if(getComponent().getValue() == null) return null;

View File

@ -14,9 +14,6 @@
package org.compiere.apps.form;
import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.DecimalFormat;
import java.util.ArrayList;
@ -30,7 +27,6 @@ import org.compiere.model.MAllocationLine;
import org.compiere.model.MDocType;
import org.compiere.model.MInvoice;
import org.compiere.model.MPayment;
import org.compiere.model.MRole;
import org.compiere.model.MSysConfig;
import org.compiere.process.DocAction;
import org.compiere.util.CLogger;
@ -42,25 +38,30 @@ import org.compiere.util.Msg;
import org.compiere.util.TimeUtil;
import org.compiere.util.Util;
/**
*
* @author hengsin
*
*/
public class Allocation
{
public DecimalFormat format = DisplayType.getNumberFormat(DisplayType.Amount);
protected DecimalFormat format = DisplayType.getNumberFormat(DisplayType.Amount);
/** Logger */
public static final CLogger log = CLogger.getCLogger(Allocation.class);
protected static final CLogger log = CLogger.getCLogger(Allocation.class);
private boolean m_calculating = false;
public int m_C_Currency_ID = 0;
public int m_C_Charge_ID = 0;
public int m_C_DocType_ID = 0;
public int m_C_BPartner_ID = 0;
protected int m_C_Currency_ID = 0;
protected int m_C_Charge_ID = 0;
protected int m_C_DocType_ID = 0;
protected int m_C_BPartner_ID = 0;
private int m_noInvoices = 0;
private int m_noPayments = 0;
public BigDecimal totalInv = Env.ZERO;
public BigDecimal totalPay = Env.ZERO;
public BigDecimal totalDiff = Env.ZERO;
protected BigDecimal totalInv = Env.ZERO;
protected BigDecimal totalPay = Env.ZERO;
protected BigDecimal totalDiff = Env.ZERO;
public Timestamp allocDate = null;
protected Timestamp allocDate = null;
// Index changed if multi-currency
private int i_payment = 7;
@ -70,20 +71,19 @@ public class Allocation
private int i_writeOff = 8;
private int i_applied = 9;
private int i_overUnder = 10;
// private int i_multiplier = 10;
public int m_AD_Org_ID = 0;
protected int m_AD_Org_ID = 0;
private ArrayList<Integer> m_bpartnerCheck = new ArrayList<Integer>();
public void dynInit() throws Exception
protected void dynInit() throws Exception
{
m_C_Currency_ID = Env.getContextAsInt(Env.getCtx(), Env.C_CURRENCY_ID); // default
//
if (log.isLoggable(Level.INFO)) log.info("Currency=" + m_C_Currency_ID);
m_AD_Org_ID = Env.getAD_Org_ID(Env.getCtx());
m_C_DocType_ID= MDocType.getDocType("CMA");
m_C_DocType_ID= MDocType.getDocType(MDocType.DOCBASETYPE_PaymentAllocation);
}
@ -115,82 +115,35 @@ public class Allocation
}
}
/**
* @deprecated
* @param isMultiCurrency
* @param date
* @param paymentTable not used
* @return list of payment record
*/
public Vector<Vector<Object>> getPaymentData(boolean isMultiCurrency, Object date, IMiniTable paymentTable)
{
/********************************
* Load unallocated Payments
* 1-TrxDate, 2-DocumentNo, (3-Currency, 4-PayAmt,)
* 5-ConvAmt, 6-ConvOpen, 7-Allocated
return getPaymentData(isMultiCurrency, (Timestamp) date, (String)null);
}
/**
*
* @param isMultiCurrency
* @param date
* @param trxName optional trx name
* @return list of payment record
*/
Vector<Vector<Object>> data = new Vector<Vector<Object>>();
StringBuilder sql = new StringBuilder("SELECT p.DateTrx,p.DocumentNo,p.C_Payment_ID," // 1..3
+ "c.ISO_Code,p.PayAmt," // 4..5
+ "currencyConvertPayment(p.C_Payment_ID,?,null,?),"// 6 #1, #2
+ "currencyConvertPayment(p.C_Payment_ID,?,paymentAvailable(p.C_Payment_ID),?)," // 7 #3, #4
+ "p.MultiplierAP "
+ "FROM C_Payment_v p" // Corrected for AP/AR
+ " INNER JOIN C_Currency c ON (p.C_Currency_ID=c.C_Currency_ID) "
+ "WHERE p.IsAllocated='N' AND p.Processed='Y'"
+ " AND p.C_Charge_ID IS NULL" // Prepayments OK
+ " AND p.C_BPartner_ID=?"); // #5
if (!isMultiCurrency)
sql.append(" AND p.C_Currency_ID=?"); // #6
if (m_AD_Org_ID != 0 )
sql.append(" AND p.AD_Org_ID=" + m_AD_Org_ID);
sql.append(" ORDER BY p.DateTrx,p.DocumentNo");
// role security
sql = new StringBuilder( MRole.getDefault(Env.getCtx(), false).addAccessSQL( sql.toString(), "p", MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO ) );
if (log.isLoggable(Level.FINE)) log.fine("PaySQL=" + sql.toString());
PreparedStatement pstmt = null;
ResultSet rs = null;
try
public Vector<Vector<Object>> getPaymentData(boolean isMultiCurrency, Timestamp date, String trxName)
{
pstmt = DB.prepareStatement(sql.toString(), null);
pstmt.setInt(1, m_C_Currency_ID);
pstmt.setTimestamp(2, (Timestamp)date);
pstmt.setInt(3, m_C_Currency_ID);
pstmt.setTimestamp(4, (Timestamp)date);
pstmt.setInt(5, m_C_BPartner_ID);
if (!isMultiCurrency)
pstmt.setInt(6, m_C_Currency_ID);
rs = pstmt.executeQuery();
while (rs.next())
{
Vector<Object> line = new Vector<Object>();
line.add(Boolean.FALSE); // 0-Selection
line.add(rs.getTimestamp(1)); // 1-TrxDate
KeyNamePair pp = new KeyNamePair(rs.getInt(3), rs.getString(2));
line.add(pp); // 2-DocumentNo
if (isMultiCurrency)
{
line.add(rs.getString(4)); // 3-Currency
line.add(rs.getBigDecimal(5)); // 4-PayAmt
}
line.add(rs.getBigDecimal(6)); // 3/5-ConvAmt
BigDecimal available = rs.getBigDecimal(7);
if (available == null || available.signum() == 0) // nothing available
continue;
line.add(available); // 4/6-ConvOpen/Available
line.add(Env.ZERO); // 5/7-Payment
// line.add(rs.getBigDecimal(8)); // 6/8-Multiplier
//
data.add(line);
}
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql.toString(), e);
}
finally
{
DB.close(rs, pstmt);
}
return data;
return MPayment.getUnAllocatedPaymentData(m_C_BPartner_ID, m_C_Currency_ID, isMultiCurrency, date, m_AD_Org_ID, trxName);
}
/**
*
* @param isMultiCurrency
* @return column name list for payment data
*/
public Vector<String> getPaymentColumnNames(boolean isMultiCurrency)
{
// Header Info
@ -206,11 +159,15 @@ public class Allocation
columnNames.add(Msg.getMsg(Env.getCtx(), "ConvertedAmount"));
columnNames.add(Msg.getMsg(Env.getCtx(), "OpenAmt"));
columnNames.add(Msg.getMsg(Env.getCtx(), "AppliedAmt"));
// columnNames.add(" "); // Multiplier
return columnNames;
}
/**
*
* @param paymentTable
* @param isMultiCurrency
*/
public void setPaymentColumnClass(IMiniTable paymentTable, boolean isMultiCurrency)
{
int i = 0;
@ -225,8 +182,6 @@ public class Allocation
paymentTable.setColumnClass(i++, BigDecimal.class, true); // 5-ConvAmt
paymentTable.setColumnClass(i++, BigDecimal.class, true); // 6-ConvOpen
paymentTable.setColumnClass(i++, BigDecimal.class, false); // 7-Allocated
// paymentTable.setColumnClass(i++, BigDecimal.class, true); // 8-Multiplier
//
i_payment = isMultiCurrency ? 7 : 5;
@ -235,104 +190,35 @@ public class Allocation
paymentTable.autoSize();
}
/**
* @deprecated
* @param isMultiCurrency
* @param date
* @param invoiceTable not use
* @return list of unpaid invoice data
*/
public Vector<Vector<Object>> getInvoiceData(boolean isMultiCurrency, Object date, IMiniTable invoiceTable)
{
/********************************
* Load unpaid Invoices
* 1-TrxDate, 2-Value, (3-Currency, 4-InvAmt,)
* 5-ConvAmt, 6-ConvOpen, 7-ConvDisc, 8-WriteOff, 9-Applied
return getInvoiceData(isMultiCurrency, (Timestamp) date, (String)null);
}
/**
*
SELECT i.DateInvoiced,i.DocumentNo,i.C_Invoice_ID,c.ISO_Code,
i.GrandTotal*i.MultiplierAP "GrandTotal",
currencyConvert(i.GrandTotal*i.MultiplierAP,i.C_Currency_ID,i.C_Currency_ID,i.DateInvoiced,i.C_ConversionType_ID,i.AD_Client_ID,i.AD_Org_ID) "GrandTotal $",
invoiceOpen(C_Invoice_ID,C_InvoicePaySchedule_ID) "Open",
currencyConvert(invoiceOpen(C_Invoice_ID,C_InvoicePaySchedule_ID),i.C_Currency_ID,i.C_Currency_ID,i.DateInvoiced,i.C_ConversionType_ID,i.AD_Client_ID,i.AD_Org_ID)*i.MultiplierAP "Open $",
invoiceDiscount(i.C_Invoice_ID,getDate(),C_InvoicePaySchedule_ID) "Discount",
currencyConvert(invoiceDiscount(i.C_Invoice_ID,getDate(),C_InvoicePaySchedule_ID),i.C_Currency_ID,i.C_Currency_ID,i.DateInvoiced,i.C_ConversionType_ID,i.AD_Client_ID,i.AD_Org_ID)*i.Multiplier*i.MultiplierAP "Discount $",
i.MultiplierAP, i.Multiplier
FROM C_Invoice_v i INNER JOIN C_Currency c ON (i.C_Currency_ID=c.C_Currency_ID)
WHERE -- i.IsPaid='N' AND i.Processed='Y' AND i.C_BPartner_ID=1000001
* @param isMultiCurrency
* @param date
* @param trxName optional trx name
* @return list of unpaid invoice data
*/
Vector<Vector<Object>> data = new Vector<Vector<Object>>();
StringBuilder sql = new StringBuilder("SELECT i.DateInvoiced,i.DocumentNo,i.C_Invoice_ID," // 1..3
+ "c.ISO_Code,i.GrandTotal*i.MultiplierAP, " // 4..5 Orig Currency
+ "currencyConvertInvoice(i.C_Invoice_ID,?,i.GrandTotal*i.MultiplierAP,?), " // 6 #1 Converted, #2 Date
+ "currencyConvertInvoice(i.C_Invoice_ID,?,invoiceOpen(C_Invoice_ID,C_InvoicePaySchedule_ID),?)*i.MultiplierAP, " // 7 #3, #4 Converted Open
+ "currencyConvertInvoice(i.C_Invoice_ID" // 8 AllowedDiscount
+ ",?,invoiceDiscount(i.C_Invoice_ID,?,C_InvoicePaySchedule_ID),i.DateInvoiced)*i.Multiplier*i.MultiplierAP," // #5, #6
+ "i.MultiplierAP "
+ "FROM C_Invoice_v i" // corrected for CM/Split
+ " INNER JOIN C_Currency c ON (i.C_Currency_ID=c.C_Currency_ID) "
+ "WHERE i.IsPaid='N' AND i.Processed='Y'"
+ " AND i.C_BPartner_ID=?"); // #7
if (!isMultiCurrency)
sql.append(" AND i.C_Currency_ID=?"); // #8
if (m_AD_Org_ID != 0 )
sql.append(" AND i.AD_Org_ID=" + m_AD_Org_ID);
sql.append(" ORDER BY i.DateInvoiced, i.DocumentNo");
if (log.isLoggable(Level.FINE)) log.fine("InvSQL=" + sql.toString());
// role security
sql = new StringBuilder( MRole.getDefault(Env.getCtx(), false).addAccessSQL( sql.toString(), "i", MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO ) );
PreparedStatement pstmt = null;
ResultSet rs = null;
try
public Vector<Vector<Object>> getInvoiceData(boolean isMultiCurrency, Timestamp date, String trxName)
{
pstmt = DB.prepareStatement(sql.toString(), null);
pstmt.setInt(1, m_C_Currency_ID);
pstmt.setTimestamp(2, (Timestamp)date);
pstmt.setInt(3, m_C_Currency_ID);
pstmt.setTimestamp(4, (Timestamp)date);
pstmt.setInt(5, m_C_Currency_ID);
pstmt.setTimestamp(6, (Timestamp)date);
pstmt.setInt(7, m_C_BPartner_ID);
if (!isMultiCurrency)
pstmt.setInt(8, m_C_Currency_ID);
rs = pstmt.executeQuery();
while (rs.next())
{
Vector<Object> line = new Vector<Object>();
line.add(Boolean.FALSE); // 0-Selection
line.add(rs.getTimestamp(1)); // 1-TrxDate
KeyNamePair pp = new KeyNamePair(rs.getInt(3), rs.getString(2));
line.add(pp); // 2-Value
if (isMultiCurrency)
{
line.add(rs.getString(4)); // 3-Currency
line.add(rs.getBigDecimal(5)); // 4-Orig Amount
}
line.add(rs.getBigDecimal(6)); // 3/5-ConvAmt
BigDecimal open = rs.getBigDecimal(7);
if (open == null) // no conversion rate
open = Env.ZERO;
line.add(open); // 4/6-ConvOpen
BigDecimal discount = rs.getBigDecimal(8);
if (discount == null) // no concersion rate
discount = Env.ZERO;
line.add(discount); // 5/7-ConvAllowedDisc
line.add(Env.ZERO); // 6/8-WriteOff
line.add(Env.ZERO); // 7/9-Applied
line.add(open); // 8/10-OverUnder
// line.add(rs.getBigDecimal(9)); // 8/10-Multiplier
// Add when open <> 0 (i.e. not if no conversion rate)
if (Env.ZERO.compareTo(open) != 0)
data.add(line);
}
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql.toString(), e);
}
finally
{
DB.close(rs, pstmt);
}
return data;
return MInvoice.getUnpaidInvoiceData(isMultiCurrency, date, m_AD_Org_ID, m_C_Currency_ID, m_C_BPartner_ID, trxName);
}
/**
*
* @param isMultiCurrency
* @return list of column name/header
*/
public Vector<String> getInvoiceColumnNames(boolean isMultiCurrency)
{
// Header Info
@ -351,11 +237,15 @@ public class Allocation
columnNames.add(Msg.getMsg(Env.getCtx(), "WriteOff"));
columnNames.add(Msg.getMsg(Env.getCtx(), "AppliedAmt"));
columnNames.add(Msg.getMsg(Env.getCtx(), "OverUnderAmt"));
// columnNames.add(" "); // Multiplier
return columnNames;
}
/**
* set class type for each column
* @param invoiceTable
* @param isMultiCurrency
*/
public void setInvoiceColumnClass(IMiniTable invoiceTable, boolean isMultiCurrency)
{
int i = 0;
@ -373,21 +263,33 @@ public class Allocation
invoiceTable.setColumnClass(i++, BigDecimal.class, false); // 8-Conv WriteOff
invoiceTable.setColumnClass(i++, BigDecimal.class, false); // 9-Conv OverUnder
invoiceTable.setColumnClass(i++, BigDecimal.class, true); // 10-Conv Applied
// invoiceTable.setColumnClass(i++, BigDecimal.class, true); // 10-Multiplier
// Table UI
invoiceTable.autoSize();
}
public void calculate(boolean isMultiCurrency)
/**
* set column index for single or multi currency
* @param isMultiCurrency
*/
protected void prepareForCalculate(boolean isMultiCurrency)
{
i_open = isMultiCurrency ? 6 : 4;
i_discount = isMultiCurrency ? 7 : 5;
i_writeOff = isMultiCurrency ? 8 : 6;
i_applied = isMultiCurrency ? 9 : 7;
i_overUnder = isMultiCurrency ? 10 : 8;
// i_multiplier = isMultiCurrency ? 10 : 8;
} // loadBPartner
/**
* update payment or invoice applied and write off amount
* @param row row to update
* @param col change is trigger by selected or applied column
* @param isInvoice update invoice or payment applied amount
* @param payment
* @param invoice
* @param isAutoWriteOff true to write off difference, false to use over/under for difference
* @return warning message (if any)
*/
public String writeOff(int row, int col, boolean isInvoice, IMiniTable payment, IMiniTable invoice, boolean isAutoWriteOff)
{
String msg = "";
@ -548,11 +450,29 @@ public class Allocation
}
/**
* Calculate Allocation info
* perform allocation calculation
* @param paymentTable
* @param invoiceTable
* @param isMultiCurrency
*/
public void calculate(IMiniTable paymentTable, IMiniTable invoiceTable, boolean isMultiCurrency)
{
allocDate = null;
prepareForCalculate(isMultiCurrency);
calculatePayment(paymentTable, isMultiCurrency);
calculateInvoice(invoiceTable, isMultiCurrency);
calculateDifference();
}
/**
* Calculate selected payment total
* @param payment
* @param isMultiCurrency
* @return payment summary
*/
public String calculatePayment(IMiniTable payment, boolean isMultiCurrency)
{
log.config("");
if (log.isLoggable(Level.CONFIG)) log.config("");
// Payment
totalPay = Env.ZERO;
@ -571,10 +491,24 @@ public class Allocation
if (log.isLoggable(Level.FINE)) log.fine("Payment_" + i + " = " + bd + " - Total=" + totalPay);
}
}
return getPaymentInfoText();
}
/**
*
* @return summary info for payment selected and total applied
*/
public String getPaymentInfoText() {
return String.valueOf(m_noPayments) + " - "
+ Msg.getMsg(Env.getCtx(), "Sum") + " " + format.format(totalPay) + " ";
}
/**
* calculate selected invoice total
* @param invoice
* @param isMultiCurrency
* @return invoice summary
*/
public String calculateInvoice(IMiniTable invoice, boolean isMultiCurrency)
{
// Invoices
@ -595,14 +529,28 @@ public class Allocation
if (log.isLoggable(Level.FINE)) log.fine("Invoice_" + i + " = " + bd + " - Total=" + totalPay);
}
}
return getInvoiceInfoText();
}
/**
*
* @return summary info for invoice selected and total applied
*/
public String getInvoiceInfoText() {
return String.valueOf(m_noInvoices) + " - "
+ Msg.getMsg(Env.getCtx(), "Sum") + " " + format.format(totalInv) + " ";
}
/**************************************************************************
* Save Data
/**
* Save allocation data
* @param m_WindowNo
* @param dateTrx
* @param payment
* @param invoice
* @param trxName
* @return {@link MAllocationHdr}
*/
public MAllocationHdr saveData(int m_WindowNo, Object date, IMiniTable payment, IMiniTable invoice, String trxName)
public MAllocationHdr saveData(int m_WindowNo, Timestamp dateTrx, IMiniTable payment, IMiniTable invoice, String trxName)
{
if (m_noInvoices + m_noPayments == 0)
return null;
@ -613,7 +561,6 @@ public class Allocation
int C_BPartner_ID = m_C_BPartner_ID;
int C_Order_ID = 0;
int C_CashLine_ID = 0;
Timestamp DateTrx = (Timestamp)date;
int C_Currency_ID = m_C_Currency_ID; // the allocation currency
//
if (AD_Org_ID == 0)
@ -623,7 +570,7 @@ public class Allocation
}
//
if (log.isLoggable(Level.CONFIG)) log.config("Client=" + AD_Client_ID + ", Org=" + AD_Org_ID
+ ", BPartner=" + C_BPartner_ID + ", Date=" + DateTrx);
+ ", BPartner=" + C_BPartner_ID + ", Date=" + dateTrx);
// Payment - Loop and add them to paymentList/amountList
int pRows = payment.getRowCount();
@ -656,7 +603,7 @@ public class Allocation
// Create Allocation
MAllocationHdr alloc = new MAllocationHdr (Env.getCtx(), true, // manual
DateTrx, C_Currency_ID, Env.getContext(Env.getCtx(), Env.AD_USER_NAME), trxName);
dateTrx, C_Currency_ID, Env.getContext(Env.getCtx(), Env.AD_USER_NAME), trxName);
alloc.setAD_Org_ID(AD_Org_ID);
alloc.setC_DocType_ID(m_C_DocType_ID);
alloc.setDescription(alloc.getDescriptionForManualAllocation(m_C_BPartner_ID, trxName));
@ -812,4 +759,139 @@ public class Allocation
return alloc;
} // saveData
/**
*
* @return C_BPartner_ID
*/
public int getC_BPartner_ID() {
return m_C_BPartner_ID;
}
/**
*
* @param C_BPartner_ID
*/
public void setC_BPartner_ID(int C_BPartner_ID) {
this.m_C_BPartner_ID = C_BPartner_ID;
}
/**
*
* @return C_Currency_ID
*/
public int getC_Currency_ID() {
return m_C_Currency_ID;
}
/**
*
* @param C_Currency_ID
*/
public void setC_Currency_ID(int C_Currency_ID) {
this.m_C_Currency_ID = C_Currency_ID;
}
/**
*
* @return C_DocType_ID
*/
public int getC_DocType_ID() {
return m_C_DocType_ID;
}
/**
*
* @param C_DocType_ID
*/
public void setC_DocType_ID(int C_DocType_ID) {
this.m_C_DocType_ID = C_DocType_ID;
}
/**
*
* @return C_Charge_ID
*/
public int getC_Charge_ID() {
return m_C_Charge_ID;
}
/**
*
* @param C_Charge_ID
*/
public void setC_Charge_ID(int C_Charge_ID) {
this.m_C_Charge_ID = C_Charge_ID;
}
/**
*
* @return AD_Org_ID
*/
public int getAD_Org_ID() {
return m_AD_Org_ID;
}
/**
*
* @param AD_Org_ID
*/
public void setAD_Org_ID(int AD_Org_ID) {
this.m_AD_Org_ID = AD_Org_ID;
}
/**
*
* @return number of selected invoice
*/
public int getSelectedInvoiceCount() {
return m_noInvoices;
}
/**
*
* @return number of selected payment
*/
public int getSelectedPaymentCount() {
return m_noPayments;
}
/**
*
* @return total of invoice applied amount
*/
public BigDecimal getInvoiceAppliedTotal() {
return totalInv;
}
/**
*
* @return total of payment applied amount
*/
public BigDecimal getPaymentAppliedTotal() {
return totalPay;
}
/**
*
* @return true if all condition is meet to proceed with allocation
*/
public boolean isOkToAllocate() {
return totalDiff.signum() == 0 || getC_Charge_ID() > 0;
}
/**
*
* @return difference between invoice and payment applied amount
*/
public BigDecimal getTotalDifference() {
return totalDiff;
}
/**
* calculate difference between invoice and payment applied amount
*/
public void calculateDifference() {
totalDiff = totalPay.subtract(totalInv);
}
}

View File

@ -1,57 +1,202 @@
/***********************************************************************
* This file is part of iDempiere ERP Open Source *
* http://www.idempiere.org *
* *
* Copyright (C) Contributors *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, *
* MA 02110-1301, USA. *
* *
* Contributors: *
* - hengsin *
* - carlos *
* - richard morales *
**********************************************************************/
package org.compiere.minigrid;
import java.sql.ResultSet;
import org.compiere.model.PO;
/**
*
* @author hengsin
*
*/
public interface IMiniTable
{
/**
*
* @param row
* @param column
* @return true if column is editable
*/
public boolean isCellEditable(int row, int column);
/**
*
* @param row
* @param column
* @return value at row and column
*/
public Object getValueAt(int row, int column);
/**
* set value at row and column
* @param value
* @param row
* @param column
*/
public void setValueAt(Object value, int row, int column);
/**
*
* @param viewColumnIndex
* @return corresponding index at underlying model
*/
public int convertColumnIndexToModel(int viewColumnIndex);
/**
* change readonly attribute of a column
* @param index
* @param readOnly
*/
public void setColumnReadOnly (int index, boolean readOnly);
/**
* Prepare Table and return SQL required to get resultset to populate table
* @param layout
* @param from
* @param where
* @param multiSelection
* @param tableName
* @return sql
*/
public String prepareTable(ColumnInfo[] layout, String from, String where, boolean multiSelection, String tableName);
/**
* add column with header
* @param header
*/
public void addColumn (String header);
/**
* set column class type
* @param index
* @param classType
* @param readOnly
* @param header
*/
public void setColumnClass (int index, Class<?> classType, boolean readOnly, String header);
/**
* set column class type
* @param index
* @param classType
* @param readOnly
*/
public void setColumnClass (int index, Class<?> classType, boolean readOnly);
/**
* populate table
* @param rs
*/
public void loadTable(ResultSet rs);
/**
* populate table
* @param pos
*/
public void loadTable(PO[] pos);
/**
*
* @return row key
*/
public Integer getSelectedRowKey();
/**
*
* @return selected row index or -1 if no selected row
*/
public int getSelectedRow();
/**
* ensure table has >= rowCount rows.
* i.e to grow a table by 1 row, call table.setRowCount(table.getRowCount()+1)
* @param rowCount
*/
public void setRowCount (int rowCount);
/**
* get table layout
* @return array of {@link ColumnInfo}
*/
public ColumnInfo[] getLayoutInfo();
/**
*
* @return number of columns
*/
public int getColumnCount();
/**
*
* @return number of rows
*/
public int getRowCount();
/**
* change multi selection attribute of table
* @param multiSelection
*/
public void setMultiSelection(boolean multiSelection);
/**
*
* @return true if multi selection is turn on
*/
public boolean isMultiSelection();
/**
*
* @param row
* @return color code
*/
public int getColorCode (int row);
/**
*
* @param dataCompare
*/
public void setColorCompare (Object dataCompare);
/**
* redraw the whole table
*/
public void repaint();
/**
* auto size column width
*/
public void autoSize();
/**
* change show total attribute of table
* @param show
*/
public void setShowTotals(boolean show);
}

View File

@ -0,0 +1,158 @@
/***********************************************************************
* This file is part of iDempiere ERP Open Source *
* http://www.idempiere.org *
* *
* Copyright (C) Contributors *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, *
* MA 02110-1301, USA. *
* *
* Contributors: *
* - hengsin *
**********************************************************************/
package org.idempiere.test;
/**
*
* @author hengsin
*
*/
public final class DictionaryIDs {
private DictionaryIDs() {
}
public enum C_BankAccount {
ACCOUNT_1234(100),
ACCOUNT_5678(101),
HQ_POS_CASH(200000);
public final int id;
private C_BankAccount(int id) {
this.id = id;
}
}
public enum C_BPartner {
STANDARD(112),
TREE_FARM(114),
C_AND_W(117),
JOE_BLOCK(118),
SEED_FARM(120),
PATIO(121);
public final int id;
private C_BPartner(int id) {
this.id = id;
}
}
public enum C_Charge {
BANK(100),
COMMISSIONS(101),
FREIGHT(200000);
public final int id;
private C_Charge(int id) {
this.id = id;
}
}
public enum C_ConversionType {
SPOT(114),
PERIOD_END(115),
AVERAGE(200),
COMPANY(201);
public final int id;
private C_ConversionType(int id) {
this.id = id;
}
}
public enum C_Currency {
USD(100),
EUR(102);
public final int id;
private C_Currency(int id) {
this.id = id;
}
}
public enum C_DocType {
GL_JOURNAL(115),
AR_INVOICE(116),
AR_CREDIT_MEMO(118),
AR_RECEIPT(119),
MM_SHIPMENT(120),
MM_RECEIPT(122),
AP_INVOICE(123),
AP_CREDIT_MEMO(124),
AP_PAYMENT(125);
public final int id;
private C_DocType(int id) {
this.id = id;
}
}
public enum C_PaymentTerm {
NET_30(100),
IMMEDIATE(105),
TWO_PERCENT_10_NET_30(106), //2%10 Net 30
FIFTY_IMMEDIATE_FIFTY_30DAYS(108); //50% Immediate - 50% in 30 days
public final int id;
private C_PaymentTerm(int id) {
this.id = id;
}
}
public enum C_Tax {
STANDARD(104),
CT_SALES(105),
GST(106),
PST(107),
GST_PST(108),
EXEMPT(109);
public final int id;
private C_Tax(int id) {
this.id = id;
}
}
public enum M_PriceList {
STANDARD(101),
PURCHASE(102),
EXPORT(103),
IMPORT(200000);
public final int id;
private M_PriceList(int id) {
this.id = id;
}
}
}

View File

@ -0,0 +1,306 @@
/***********************************************************************
* This file is part of iDempiere ERP Open Source *
* http://www.idempiere.org *
* *
* Copyright (C) Contributors *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, *
* MA 02110-1301, USA. *
* *
* Contributors: *
* - hengsin *
**********************************************************************/
package org.idempiere.test.form;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.sql.Timestamp;
import java.util.Vector;
import org.compiere.apps.form.Allocation;
import org.compiere.minigrid.IMiniTable;
import org.compiere.model.MAllocationHdr;
import org.compiere.model.MBPartner;
import org.compiere.model.MBankAccount;
import org.compiere.model.MCurrency;
import org.compiere.model.MDocType;
import org.compiere.model.MInvoice;
import org.compiere.model.MInvoiceLine;
import org.compiere.model.MPayment;
import org.compiere.model.Query;
import org.compiere.process.DocAction;
import org.compiere.process.ProcessInfo;
import org.compiere.util.Env;
import org.compiere.util.KeyNamePair;
import org.compiere.util.TimeUtil;
import org.compiere.wf.MWorkflow;
import org.idempiere.test.AbstractTestCase;
import org.idempiere.test.DictionaryIDs;
import org.idempiere.test.ui.MiniTableImpl;
import org.junit.jupiter.api.Test;
/**
* @author hengsin
*
*/
public class AllocationFormTest extends AbstractTestCase {
/**
* default constructor
*/
public AllocationFormTest() {
}
@Test
/**
* test basic invoice allocation with multi currency and auto writeoff off.
*/
public void testInvoiceAllocation1() {
MBPartner bpartner = MBPartner.get(Env.getCtx(), DictionaryIDs.C_BPartner.JOE_BLOCK.id);
Timestamp today = TimeUtil.getDay(System.currentTimeMillis());
MInvoice invoice = createCustomerInvoice(today, today,
bpartner.getC_BPartner_ID(), DictionaryIDs.C_PaymentTerm.IMMEDIATE.id, DictionaryIDs.C_Tax.EXEMPT.id, Env.ONEHUNDRED);
ProcessInfo pi = MWorkflow.runDocumentActionWorkflow(invoice, DocAction.ACTION_Complete);
assertFalse(pi.isError(), pi.getSummary());
MCurrency usd = MCurrency.get(DictionaryIDs.C_Currency.USD.id);
String whereClause = "AD_Org_ID=? AND C_Currency_ID=?";
MBankAccount ba = new Query(Env.getCtx(),MBankAccount.Table_Name, whereClause, getTrxName())
.setParameters(Env.getAD_Org_ID(Env.getCtx()), usd.getC_Currency_ID())
.setOrderBy("IsDefault DESC")
.first();
assertTrue(ba != null, "@NoAccountOrgCurrency@");
MPayment payment = createReceiptPayment(bpartner.getC_BPartner_ID(), ba.getC_BankAccount_ID(), today, usd.getC_Currency_ID(), 0, Env.ONEHUNDRED);
pi = MWorkflow.runDocumentActionWorkflow(payment, DocAction.ACTION_Complete);
assertFalse(pi.isError(), pi.getSummary());
IMiniTable paymentTable = new MiniTableImpl();
IMiniTable invoiceTable = new MiniTableImpl();
boolean multiCurrency = false;
Allocation allocation = new Allocation();
allocation.setC_BPartner_ID(bpartner.get_ID());
allocation.setC_Currency_ID(usd.get_ID());
Vector<String> paymentColumns = allocation.getPaymentColumnNames(multiCurrency);
for(String column : paymentColumns) {
paymentTable.addColumn(column);
}
allocation.setPaymentColumnClass(paymentTable, multiCurrency);
Vector<String> invoiceColumns = allocation.getInvoiceColumnNames(multiCurrency);
for(String column : invoiceColumns) {
invoiceTable.addColumn(column);
}
allocation.setInvoiceColumnClass(invoiceTable, multiCurrency);
//load payment table
Vector<Vector<Object>> paymentDatas = allocation.getPaymentData(multiCurrency, today, getTrxName());
loadTable(paymentTable, paymentDatas);
assertTrue(paymentTable.getRowCount() >= 1, "Failed to retrieve unallocated payment data");
//load invoice table
Vector<Vector<Object>> invoiceDatas = allocation.getInvoiceData(multiCurrency, today, getTrxName());
loadTable(invoiceTable, invoiceDatas);
assertTrue(invoiceTable.getRowCount() >= 1, "Failed to retrieve unpaided invoice data");
allocation.calculate(paymentTable, invoiceTable, multiCurrency);
for (int i = 0; i < paymentTable.getRowCount(); i++) {
KeyNamePair knp = (KeyNamePair) paymentTable.getValueAt(i, MPayment.UNALLOCATED_PAYMENT_DOCUMENT_KEY_NAME_PAIR);
if (knp.getKey() == payment.get_ID()) {
paymentTable.setValueAt(Boolean.TRUE, i, MPayment.UNALLOCATED_PAYMENT_SELECTED);
((MiniTableImpl)paymentTable).setSelectedRow(i);
break;
}
}
assertTrue(paymentTable.getSelectedRow() >= 0, "Failed to locate open payment created");
allocation.writeOff(paymentTable.getSelectedRow(), 0, false, paymentTable, invoiceTable, false);
allocation.calculate(paymentTable, invoiceTable, multiCurrency);
assertEquals(payment.getPayAmt().setScale(2, RoundingMode.HALF_UP), allocation.getPaymentAppliedTotal().setScale(2, RoundingMode.HALF_UP), "Unexpected Payment Applied Total");
assertEquals(payment.getPayAmt().setScale(2, RoundingMode.HALF_UP), allocation.getTotalDifference().setScale(2, RoundingMode.HALF_UP), "Unexpected Total Applied Difference");
for (int i = 0; i < invoiceTable.getRowCount(); i++) {
KeyNamePair knp = (KeyNamePair) invoiceTable.getValueAt(i, MInvoice.UNPAID_INVOICE_DOCUMENT_KEY_NAME_PAIR);
if (knp.getKey() == invoice.get_ID()) {
invoiceTable.setValueAt(Boolean.TRUE, i, MInvoice.UNPAID_INVOICE_SELECTED);
((MiniTableImpl)invoiceTable).setSelectedRow(i);
invoiceTable.setValueAt(new BigDecimal("0.00"), i, MInvoice.UNPAID_INVOICE_SINGLE_CURRENCY_DISCOUNT_AMT);
break;
}
}
assertTrue(invoiceTable.getSelectedRow() >= 0, "Failed to locate open invoice created");
allocation.writeOff(invoiceTable.getSelectedRow(), 0, true, paymentTable, invoiceTable, false);
allocation.calculate(paymentTable, invoiceTable, multiCurrency);
assertEquals(invoice.getGrandTotal().setScale(2, RoundingMode.HALF_UP), allocation.getInvoiceAppliedTotal().setScale(2, RoundingMode.HALF_UP), "Unexpected Invoice Applied Total");
assertEquals(new BigDecimal("0.00"), allocation.getTotalDifference().setScale(2, RoundingMode.HALF_UP), "Unexpected Total Applied Difference");
assertTrue(allocation.isOkToAllocate(), "Invoice and payment applied total is different: " + allocation.getTotalDifference().toPlainString());
MAllocationHdr allocationHdr = allocation.saveData(0, today, paymentTable, invoiceTable, getTrxName());
assertNotNull(allocationHdr, "Failed to create allocation header");
}
@Test
/**
* test basic invoice allocation with multi currency on and auto writeoff off.
*/
public void testInvoiceAllocation2() {
MBPartner bpartner = MBPartner.get(Env.getCtx(), DictionaryIDs.C_BPartner.JOE_BLOCK.id);
Timestamp today = TimeUtil.getDay(System.currentTimeMillis());
MInvoice invoice = createCustomerInvoice(today, today,
bpartner.getC_BPartner_ID(), DictionaryIDs.C_PaymentTerm.IMMEDIATE.id, DictionaryIDs.C_Tax.EXEMPT.id, Env.ONEHUNDRED);
ProcessInfo pi = MWorkflow.runDocumentActionWorkflow(invoice, DocAction.ACTION_Complete);
assertFalse(pi.isError(), pi.getSummary());
MCurrency usd = MCurrency.get(DictionaryIDs.C_Currency.USD.id);
String whereClause = "AD_Org_ID=? AND C_Currency_ID=?";
MBankAccount ba = new Query(Env.getCtx(),MBankAccount.Table_Name, whereClause, getTrxName())
.setParameters(Env.getAD_Org_ID(Env.getCtx()), usd.getC_Currency_ID())
.setOrderBy("IsDefault DESC")
.first();
assertTrue(ba != null, "@NoAccountOrgCurrency@");
MPayment payment = createReceiptPayment(bpartner.getC_BPartner_ID(), ba.getC_BankAccount_ID(), today, usd.getC_Currency_ID(), 0, Env.ONEHUNDRED);
pi = MWorkflow.runDocumentActionWorkflow(payment, DocAction.ACTION_Complete);
assertFalse(pi.isError(), pi.getSummary());
IMiniTable paymentTable = new MiniTableImpl();
IMiniTable invoiceTable = new MiniTableImpl();
boolean multiCurrency = true;
Allocation allocation = new Allocation();
allocation.setC_BPartner_ID(bpartner.get_ID());
allocation.setC_Currency_ID(usd.get_ID());
Vector<String> paymentColumns = allocation.getPaymentColumnNames(multiCurrency);
for(String column : paymentColumns) {
paymentTable.addColumn(column);
}
allocation.setPaymentColumnClass(paymentTable, multiCurrency);
Vector<String> invoiceColumns = allocation.getInvoiceColumnNames(multiCurrency);
for(String column : invoiceColumns) {
invoiceTable.addColumn(column);
}
allocation.setInvoiceColumnClass(invoiceTable, multiCurrency);
//load payment table
Vector<Vector<Object>> paymentDatas = allocation.getPaymentData(multiCurrency, today, getTrxName());
loadTable(paymentTable, paymentDatas);
assertTrue(paymentTable.getRowCount() >= 1, "Failed to retrieve unallocated payment data");
//load invoice table
Vector<Vector<Object>> invoiceDatas = allocation.getInvoiceData(multiCurrency, today, getTrxName());
loadTable(invoiceTable, invoiceDatas);
assertTrue(invoiceTable.getRowCount() >= 1, "Failed to retrieve unpaided invoice data");
allocation.calculate(paymentTable, invoiceTable, multiCurrency);
for (int i = 0; i < paymentTable.getRowCount(); i++) {
KeyNamePair knp = (KeyNamePair) paymentTable.getValueAt(i, MPayment.UNALLOCATED_PAYMENT_DOCUMENT_KEY_NAME_PAIR);
if (knp.getKey() == payment.get_ID()) {
paymentTable.setValueAt(Boolean.TRUE, i, MPayment.UNALLOCATED_PAYMENT_SELECTED);
((MiniTableImpl)paymentTable).setSelectedRow(i);
break;
}
}
assertTrue(paymentTable.getSelectedRow() >= 0, "Failed to locate open payment created");
allocation.writeOff(paymentTable.getSelectedRow(), 0, false, paymentTable, invoiceTable, false);
allocation.calculate(paymentTable, invoiceTable, multiCurrency);
assertEquals(payment.getPayAmt().setScale(2, RoundingMode.HALF_UP), allocation.getPaymentAppliedTotal().setScale(2, RoundingMode.HALF_UP), "Unexpected Payment Applied Total");
assertEquals(payment.getPayAmt().setScale(2, RoundingMode.HALF_UP), allocation.getTotalDifference().setScale(2, RoundingMode.HALF_UP), "Unexpected Total Applied Difference");
for (int i = 0; i < invoiceTable.getRowCount(); i++) {
KeyNamePair knp = (KeyNamePair) invoiceTable.getValueAt(i, MInvoice.UNPAID_INVOICE_DOCUMENT_KEY_NAME_PAIR);
if (knp.getKey() == invoice.get_ID()) {
invoiceTable.setValueAt(Boolean.TRUE, i, MInvoice.UNPAID_INVOICE_SELECTED);
((MiniTableImpl)invoiceTable).setSelectedRow(i);
invoiceTable.setValueAt(new BigDecimal("0.00"), i, MInvoice.UNPAID_INVOICE_MULTI_CURRENCY_CONVERTED_DISCOUNT_AMT);
break;
}
}
assertTrue(invoiceTable.getSelectedRow() >= 0, "Failed to locate open invoice created");
allocation.writeOff(invoiceTable.getSelectedRow(), 0, true, paymentTable, invoiceTable, false);
allocation.calculate(paymentTable, invoiceTable, multiCurrency);
assertEquals(invoice.getGrandTotal().setScale(2, RoundingMode.HALF_UP), allocation.getInvoiceAppliedTotal().setScale(2, RoundingMode.HALF_UP), "Unexpected Invoice Applied Total");
assertEquals(new BigDecimal("0.00"), allocation.getTotalDifference().setScale(2, RoundingMode.HALF_UP), "Unexpected Total Applied Difference");
assertTrue(allocation.isOkToAllocate(), "Invoice and payment applied total is different: " + allocation.getTotalDifference().toPlainString());
MAllocationHdr allocationHdr = allocation.saveData(0, today, paymentTable, invoiceTable, getTrxName());
assertNotNull(allocationHdr, "Failed to create allocation header");
}
private void loadTable(IMiniTable miniTable, Vector<Vector<Object>> datas) {
int row=0;
for(Vector<Object> data : datas) {
miniTable.setRowCount(row+1);
int column = 0;
for(Object value : data) {
miniTable.setValueAt(value, row, column);
column++;
}
row++;
}
}
private MPayment createReceiptPayment(int C_BPartner_ID, int C_BankAccount_ID, Timestamp date, int C_Currency_ID, int C_ConversionType_ID, BigDecimal payAmt) {
MPayment payment = new MPayment(Env.getCtx(), 0, getTrxName());
payment.setC_BankAccount_ID(C_BankAccount_ID);
payment.setC_DocType_ID(true);
payment.setDateTrx(date);
payment.setDateAcct(date);
payment.setC_BPartner_ID(C_BPartner_ID);
payment.setPayAmt(payAmt);
payment.setC_Currency_ID(C_Currency_ID);
payment.setC_ConversionType_ID(C_ConversionType_ID);
payment.setTenderType(MPayment.TENDERTYPE_Check);
payment.setDocStatus(DocAction.STATUS_Drafted);
payment.setDocAction(DocAction.ACTION_Complete);
payment.saveEx();
return payment;
}
private MInvoice createCustomerInvoice(Timestamp dateinvoiced, Timestamp dateacct,
int bpartnerid, int payterm, int taxid, BigDecimal totallines) {
MInvoice invoice = new MInvoice(Env.getCtx(), 0, getTrxName());
invoice.setC_DocType_ID(DictionaryIDs.C_DocType.AR_INVOICE.id); //AR Invoice
invoice.setC_DocTypeTarget_ID(MDocType.DOCBASETYPE_ARInvoice);
invoice.setC_BPartner_ID(bpartnerid);
invoice.setDateInvoiced(dateinvoiced);
invoice.setDateAcct(dateacct);
invoice.setC_PaymentTerm_ID(payterm);
invoice.setDocStatus(DocAction.STATUS_Drafted);
invoice.setDocAction(DocAction.ACTION_Complete);
invoice.saveEx();
MInvoiceLine line1 = new MInvoiceLine(invoice);
line1.setLine(10);
line1.setC_Charge_ID(DictionaryIDs.C_Charge.FREIGHT.id);
line1.setQty(new BigDecimal("1"));
line1.setPrice(totallines);
line1.setC_Tax_ID(taxid);
line1.saveEx();
return invoice;
}
}

View File

@ -60,6 +60,7 @@ import org.compiere.util.Env;
import org.compiere.util.TimeUtil;
import org.compiere.wf.MWorkflow;
import org.idempiere.test.AbstractTestCase;
import org.idempiere.test.DictionaryIDs;
import org.junit.jupiter.api.Test;
/**
@ -74,14 +75,6 @@ public class AllocationTest extends AbstractTestCase {
public AllocationTest() {
}
final static int BP_C_AND_W = 117;
final static int BP_TREEFARM = 114;
final static int PAYMENT_TERM_IMMEDIATE = 105;
final static int CHARGE_FREIGHT = 200000;
final static int CURRENCY_USD = 100;
final static int BANK_ACCOUNT_1234 = 100;
/**
* https://idempiere.atlassian.net/browse/IDEMPIERE-4567
*/
@ -96,19 +89,19 @@ public class AllocationTest extends AbstractTestCase {
String trxName = getTrxName();
// Get the OpenBalance of C&W
MBPartner bpartner = new MBPartner(ctx, BP_C_AND_W, trxName);
MBPartner bpartner = new MBPartner(ctx, DictionaryIDs.C_BPartner.C_AND_W.id, trxName);
BigDecimal initialBalance = bpartner.getTotalOpenBalance();
// Pay $100
MPayment payment1 = new MPayment(ctx, 0, trxName);
payment1.setC_BPartner_ID(BP_C_AND_W);
payment1.setC_BPartner_ID(DictionaryIDs.C_BPartner.C_AND_W.id);
payment1.setC_DocType_ID(true); // Receipt
payment1.setDocStatus(DocAction.STATUS_Drafted);
payment1.setDocAction(DocAction.ACTION_Complete);
payment1.setPayAmt(Env.ONEHUNDRED);
payment1.setTenderType(MPayment.TENDERTYPE_Check);
payment1.setC_BankAccount_ID(BANK_ACCOUNT_1234);
payment1.setC_Currency_ID(CURRENCY_USD);
payment1.setC_BankAccount_ID(DictionaryIDs.C_BankAccount.ACCOUNT_1234.id);
payment1.setC_Currency_ID(DictionaryIDs.C_Currency.USD.id);
payment1.setDateTrx(TimeUtil.getDay(null));
payment1.setDateAcct(TimeUtil.getDay(null));
payment1.saveEx();
@ -125,7 +118,7 @@ public class AllocationTest extends AbstractTestCase {
// Create allocation to allocate payment to charge
MAllocationHdr alloc = new MAllocationHdr (Env.getCtx(), true, // manual
payment1.getDateTrx(), CURRENCY_USD, Env.getContext(Env.getCtx(), Env.AD_USER_NAME), trxName);
payment1.getDateTrx(), DictionaryIDs.C_Currency.USD.id, Env.getContext(Env.getCtx(), Env.AD_USER_NAME), trxName);
alloc.setAD_Org_ID(payment1.getAD_Org_ID());
int doctypeAlloc = MDocType.getDocType("CMA");
alloc.setC_DocType_ID(doctypeAlloc);
@ -134,14 +127,14 @@ public class AllocationTest extends AbstractTestCase {
MAllocationLine aLine1 = new MAllocationLine (alloc, Env.ONEHUNDRED,
Env.ZERO, Env.ZERO, Env.ZERO);
aLine1.setDocInfo(BP_C_AND_W, 0, 0);
aLine1.setDocInfo(DictionaryIDs.C_BPartner.C_AND_W.id, 0, 0);
aLine1.setPaymentInfo(payment1.getC_Payment_ID(), 0);
aLine1.saveEx();
MAllocationLine aLine2 = new MAllocationLine (alloc, Env.ONEHUNDRED.negate(),
Env.ZERO, Env.ZERO, Env.ZERO);
aLine2.setC_Charge_ID(CHARGE_FREIGHT);
aLine2.setC_BPartner_ID(BP_C_AND_W);
aLine2.setC_Charge_ID(DictionaryIDs.C_Charge.FREIGHT.id);
aLine2.setC_BPartner_ID(DictionaryIDs.C_BPartner.C_AND_W.id);
aLine2.saveEx();
assertTrue(alloc.processIt(DocAction.ACTION_Complete));
@ -183,16 +176,16 @@ public class AllocationTest extends AbstractTestCase {
String trxName = getTrxName();
// Get the OpenBalance of C&W
MBPartner bpartner = new MBPartner(ctx, BP_C_AND_W, trxName);
MBPartner bpartner = new MBPartner(ctx, DictionaryIDs.C_BPartner.C_AND_W.id, trxName);
BigDecimal initialBalance = bpartner.getTotalOpenBalance();
// Create Invoice $100
MInvoice invoice = new MInvoice(ctx, 0, trxName);
invoice.setBPartner(MBPartner.get(ctx, BP_C_AND_W));
invoice.setBPartner(MBPartner.get(ctx, DictionaryIDs.C_BPartner.C_AND_W.id));
invoice.setC_DocTypeTarget_ID(MDocType.DOCBASETYPE_ARInvoice);
invoice.setC_DocType_ID(invoice.getC_DocTypeTarget_ID()); // required to avoid runDocumentActionWorkflow exception
invoice.setPaymentRule(MInvoice.PAYMENTRULE_Check);
invoice.setC_PaymentTerm_ID(PAYMENT_TERM_IMMEDIATE); // Immediate
invoice.setC_PaymentTerm_ID(DictionaryIDs.C_PaymentTerm.IMMEDIATE.id); // Immediate
Timestamp today = TimeUtil.getDay(System.currentTimeMillis());
invoice.setDateInvoiced(today);
invoice.setDateAcct(today);
@ -202,7 +195,7 @@ public class AllocationTest extends AbstractTestCase {
MInvoiceLine line1 = new MInvoiceLine(invoice);
line1.setLine(10);
line1.setC_Charge_ID(CHARGE_FREIGHT);
line1.setC_Charge_ID(DictionaryIDs.C_Charge.FREIGHT.id);
line1.setQty(new BigDecimal("1"));
line1.setPrice(Env.ONEHUNDRED);
line1.saveEx();
@ -227,8 +220,8 @@ public class AllocationTest extends AbstractTestCase {
payment1.setDocAction(DocAction.ACTION_Complete);
payment1.setPayAmt(Env.ONEHUNDRED);
payment1.setTenderType(MPayment.TENDERTYPE_Check);
payment1.setC_BankAccount_ID(BANK_ACCOUNT_1234);
payment1.setC_Currency_ID(CURRENCY_USD);
payment1.setC_BankAccount_ID(DictionaryIDs.C_BankAccount.ACCOUNT_1234.id);
payment1.setC_Currency_ID(DictionaryIDs.C_Currency.USD.id);
payment1.setDateTrx(invoice.getDateInvoiced());
payment1.setDateAcct(invoice.getDateInvoiced());
payment1.saveEx();
@ -270,16 +263,16 @@ public class AllocationTest extends AbstractTestCase {
String trxName = getTrxName();
// Get the OpenBalance of C&W
MBPartner bpartner = new MBPartner(ctx, BP_TREEFARM, trxName);
MBPartner bpartner = new MBPartner(ctx, DictionaryIDs.C_BPartner.TREE_FARM.id, trxName);
BigDecimal initialBalance = bpartner.getTotalOpenBalance();
// Create Invoice $100
MInvoice invoice = new MInvoice(ctx, 0, trxName);
invoice.setBPartner(MBPartner.get(ctx, BP_TREEFARM));
invoice.setBPartner(MBPartner.get(ctx, DictionaryIDs.C_BPartner.TREE_FARM.id));
invoice.setC_DocTypeTarget_ID(MDocType.DOCBASETYPE_APInvoice);
invoice.setC_DocType_ID(invoice.getC_DocTypeTarget_ID()); // required to avoid runDocumentActionWorkflow exception
invoice.setPaymentRule(MInvoice.PAYMENTRULE_Check);
invoice.setC_PaymentTerm_ID(PAYMENT_TERM_IMMEDIATE); // Immediate
invoice.setC_PaymentTerm_ID(DictionaryIDs.C_PaymentTerm.IMMEDIATE.id); // Immediate
Timestamp today = TimeUtil.getDay(System.currentTimeMillis());
invoice.setDateInvoiced(today);
invoice.setDateAcct(today);
@ -289,7 +282,7 @@ public class AllocationTest extends AbstractTestCase {
MInvoiceLine line1 = new MInvoiceLine(invoice);
line1.setLine(10);
line1.setC_Charge_ID(CHARGE_FREIGHT);
line1.setC_Charge_ID(DictionaryIDs.C_Charge.FREIGHT.id);
line1.setQty(new BigDecimal("1"));
line1.setPrice(Env.ONEHUNDRED);
line1.saveEx();
@ -314,8 +307,8 @@ public class AllocationTest extends AbstractTestCase {
payment1.setDocAction(DocAction.ACTION_Complete);
payment1.setPayAmt(Env.ONEHUNDRED);
payment1.setTenderType(MPayment.TENDERTYPE_Check);
payment1.setC_BankAccount_ID(BANK_ACCOUNT_1234);
payment1.setC_Currency_ID(CURRENCY_USD);
payment1.setC_BankAccount_ID(DictionaryIDs.C_BankAccount.ACCOUNT_1234.id);
payment1.setC_Currency_ID(DictionaryIDs.C_Currency.USD.id);
payment1.setDateTrx(invoice.getDateInvoiced());
payment1.setDateAcct(invoice.getDateInvoiced());
payment1.saveEx();
@ -360,10 +353,10 @@ public class AllocationTest extends AbstractTestCase {
Timestamp date1 = new Timestamp(cal.getTimeInMillis());
Timestamp date2 = currentDate;
int C_ConversionType_ID = 201; // Company
int C_ConversionType_ID = DictionaryIDs.C_ConversionType.COMPANY.id; // Company
MCurrency usd = MCurrency.get(100); // USD
MCurrency euro = MCurrency.get("EUR"); // EUR
MCurrency usd = MCurrency.get(DictionaryIDs.C_Currency.USD.id); // USD
MCurrency euro = MCurrency.get(DictionaryIDs.C_Currency.EUR.id); // EUR
BigDecimal eurToUsd1 = new BigDecimal(30);
MConversionRate cr1 = createConversionRate(usd.getC_Currency_ID(), euro.getC_Currency_ID(), C_ConversionType_ID, date1, eurToUsd1, false);
@ -444,10 +437,10 @@ public class AllocationTest extends AbstractTestCase {
Timestamp date1 = new Timestamp(cal.getTimeInMillis());
Timestamp date2 = currentDate;
int C_ConversionType_ID = 201; // Company
int C_ConversionType_ID = DictionaryIDs.C_ConversionType.COMPANY.id; // Company
MCurrency usd = MCurrency.get(100); // USD
MCurrency euro = MCurrency.get("EUR"); // EUR
MCurrency usd = MCurrency.get(DictionaryIDs.C_Currency.USD.id); // USD
MCurrency euro = MCurrency.get(DictionaryIDs.C_Currency.EUR.id); // EUR
BigDecimal eurToUsd1 = new BigDecimal(30);
MConversionRate cr1 = createConversionRate(usd.getC_Currency_ID(), euro.getC_Currency_ID(), C_ConversionType_ID, date1, eurToUsd1, false);
@ -473,7 +466,7 @@ public class AllocationTest extends AbstractTestCase {
MAllocationHdr alloc = new MAllocationHdr(Env.getCtx(), true, date2, euro.getC_Currency_ID(), Env.getContext(Env.getCtx(), Env.AD_USER_NAME), getTrxName());
alloc.setAD_Org_ID(payment2.getAD_Org_ID());
int doctypeAlloc = MDocType.getDocType("CMA");
int doctypeAlloc = MDocType.getDocType(MDocType.DOCBASETYPE_PaymentAllocation);
alloc.setC_DocType_ID(doctypeAlloc);
alloc.setDescription(alloc.getDescriptionForManualAllocation(payment2.getC_BPartner_ID(), getTrxName()));
alloc.saveEx();
@ -639,14 +632,14 @@ public class AllocationTest extends AbstractTestCase {
// #4 Check accounts
public void testAllocatePaymentPostingWithWriteOffandDiscountARInv() {
MBPartner bpartner = MBPartner.get(Env.getCtx(), 118); // Joe Block
MBPartner bpartner = MBPartner.get(Env.getCtx(), DictionaryIDs.C_BPartner.JOE_BLOCK.id);
Timestamp currentDate = Env.getContextAsDate(Env.getCtx(), "#Date");
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(currentDate.getTime());
Timestamp date = new Timestamp(cal.getTimeInMillis());
MCurrency usd = MCurrency.get(100); // USD
MCurrency usd = MCurrency.get(DictionaryIDs.C_Currency.USD.id); // USD
try {
String whereClause = "AD_Org_ID=? AND C_Currency_ID=?";
@ -657,8 +650,8 @@ public class AllocationTest extends AbstractTestCase {
assertTrue(ba != null, "@NoAccountOrgCurrency@");
// Invoice (totallines 100, grandtotal 106)
Integer payterm = 106; //(2%10 Net 30)
Integer taxid = 105; // (CT Sales, Rate 6)
int payterm = DictionaryIDs.C_PaymentTerm.TWO_PERCENT_10_NET_30.id; //(2%10 Net 30)
int taxid = DictionaryIDs.C_Tax.CT_SALES.id; // (CT Sales, Rate 6)
MInvoice invoice = createInvoice(true,false, date, date,
bpartner.getC_BPartner_ID(), payterm, taxid, Env.ONEHUNDRED);
assertEquals(invoice.getTotalLines(), new BigDecimal("100.0"));
@ -673,7 +666,7 @@ public class AllocationTest extends AbstractTestCase {
MAllocationHdr alloc = new MAllocationHdr(Env.getCtx(), true, date, usd.getC_Currency_ID(), Env.getContext(Env.getCtx(), "#AD_User_Name"), getTrxName());
alloc.setAD_Org_ID(payment.getAD_Org_ID());
int doctypeAlloc = MDocType.getDocType("CMA");
int doctypeAlloc = MDocType.getDocType(MDocType.DOCBASETYPE_PaymentAllocation);
alloc.setC_DocType_ID(doctypeAlloc);
alloc.setDescription(alloc.getDescriptionForManualAllocation(payment.getC_BPartner_ID(), getTrxName()));
alloc.saveEx();
@ -770,14 +763,14 @@ public class AllocationTest extends AbstractTestCase {
// #4 check accounts
public void testAllocatePaymentPostingWithWriteOffandDiscountARCredMemo() {
MBPartner bpartner = MBPartner.get(Env.getCtx(), 118); // Joe Block
MBPartner bpartner = MBPartner.get(Env.getCtx(), DictionaryIDs.C_BPartner.JOE_BLOCK.id);
Timestamp currentDate = Env.getContextAsDate(Env.getCtx(), "#Date");
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(currentDate.getTime());
Timestamp date = new Timestamp(cal.getTimeInMillis());
MCurrency usd = MCurrency.get(100); // USD
MCurrency usd = MCurrency.get(DictionaryIDs.C_Currency.USD.id); // USD
try {
String whereClause = "AD_Org_ID=? AND C_Currency_ID=?";
@ -788,8 +781,8 @@ public class AllocationTest extends AbstractTestCase {
assertTrue(ba != null, "@NoAccountOrgCurrency@");
// Invoice (totallines 100, grandtotal 106)
Integer payterm = 106; //(2%10 Net 30)
Integer taxid = 105; // (CT Sales, Rate 6)
int payterm = DictionaryIDs.C_PaymentTerm.TWO_PERCENT_10_NET_30.id; //(2%10 Net 30)
int taxid = DictionaryIDs.C_Tax.CT_SALES.id; // (CT Sales, Rate 6)
MInvoice invoice = createInvoice(true, true, date, date,
bpartner.getC_BPartner_ID(), payterm, taxid, Env.ONEHUNDRED);
assertEquals(invoice.getTotalLines(), new BigDecimal("100.0"));
@ -804,7 +797,7 @@ public class AllocationTest extends AbstractTestCase {
MAllocationHdr alloc = new MAllocationHdr(Env.getCtx(), true, date, usd.getC_Currency_ID(), Env.getContext(Env.getCtx(), "#AD_User_Name"), getTrxName());
alloc.setAD_Org_ID(payment.getAD_Org_ID());
int doctypeAlloc = MDocType.getDocType("CMA");
int doctypeAlloc = MDocType.getDocType(MDocType.DOCBASETYPE_PaymentAllocation);
alloc.setC_DocType_ID(doctypeAlloc);
alloc.setDescription(alloc.getDescriptionForManualAllocation(payment.getC_BPartner_ID(), getTrxName()));
alloc.saveEx();
@ -907,7 +900,7 @@ public class AllocationTest extends AbstractTestCase {
cal.setTimeInMillis(currentDate.getTime());
Timestamp date = new Timestamp(cal.getTimeInMillis());
MCurrency usd = MCurrency.get(100); // USD
MCurrency usd = MCurrency.get(DictionaryIDs.C_Currency.USD.id); // USD
try {
String whereClause = "AD_Org_ID=? AND C_Currency_ID=?";
@ -918,8 +911,8 @@ public class AllocationTest extends AbstractTestCase {
assertTrue(ba != null, "@NoAccountOrgCurrency@");
// Invoice (totallines 100, grandtotal 106)
Integer payterm = 105; //(Immediate)
Integer taxid = 105; // (CT Sales, Rate 6)
int payterm = DictionaryIDs.C_PaymentTerm.IMMEDIATE.id; //(Immediate)
int taxid = DictionaryIDs.C_Tax.CT_SALES.id; // (CT Sales, Rate 6)
MInvoice invoice = createInvoice(false, false, date, date,
bpartner.getC_BPartner_ID(), payterm, taxid, Env.ONEHUNDRED);
assertEquals(invoice.getTotalLines(), new BigDecimal("100.0"));
@ -934,7 +927,7 @@ public class AllocationTest extends AbstractTestCase {
MAllocationHdr alloc = new MAllocationHdr(Env.getCtx(), true, date, usd.getC_Currency_ID(), Env.getContext(Env.getCtx(), "#AD_User_Name"), getTrxName());
alloc.setAD_Org_ID(payment.getAD_Org_ID());
int doctypeAlloc = MDocType.getDocType("CMA");
int doctypeAlloc = MDocType.getDocType(MDocType.DOCBASETYPE_PaymentAllocation);
alloc.setC_DocType_ID(doctypeAlloc);
alloc.setDescription(alloc.getDescriptionForManualAllocation(payment.getC_BPartner_ID(), getTrxName()));
alloc.saveEx();
@ -1037,7 +1030,7 @@ public class AllocationTest extends AbstractTestCase {
cal.setTimeInMillis(currentDate.getTime());
Timestamp date = new Timestamp(cal.getTimeInMillis());
MCurrency usd = MCurrency.get(100); // USD
MCurrency usd = MCurrency.get(DictionaryIDs.C_Currency.USD.id); // USD
try {
String whereClause = "AD_Org_ID=? AND C_Currency_ID=?";
@ -1048,8 +1041,8 @@ public class AllocationTest extends AbstractTestCase {
assertTrue(ba != null, "@NoAccountOrgCurrency@");
// Invoice (totallines 100, grandtotal 106)
Integer payterm = 105; //(Immediate)
Integer taxid = 105; // (CT Sales, Rate 6)
int payterm = DictionaryIDs.C_PaymentTerm.IMMEDIATE.id; //(Immediate)
int taxid = DictionaryIDs.C_Tax.CT_SALES.id; // (CT Sales, Rate 6)
MInvoice invoice = createInvoice(false, true, date, date,
bpartner.getC_BPartner_ID(), payterm, taxid, Env.ONEHUNDRED);
assertEquals(invoice.getTotalLines(), new BigDecimal("100.0"));
@ -1064,7 +1057,7 @@ public class AllocationTest extends AbstractTestCase {
MAllocationHdr alloc = new MAllocationHdr(Env.getCtx(), true, date, usd.getC_Currency_ID(), Env.getContext(Env.getCtx(), "#AD_User_Name"), getTrxName());
alloc.setAD_Org_ID(payment.getAD_Org_ID());
int doctypeAlloc = MDocType.getDocType("CMA");
int doctypeAlloc = MDocType.getDocType(MDocType.DOCBASETYPE_PaymentAllocation);
alloc.setC_DocType_ID(doctypeAlloc);
alloc.setDescription(alloc.getDescriptionForManualAllocation(payment.getC_BPartner_ID(), getTrxName()));
alloc.saveEx();
@ -1160,14 +1153,14 @@ public class AllocationTest extends AbstractTestCase {
// #4 check accounts
public void testPaymentPostingWithWriteOffandDiscountARInv() {
MBPartner bpartner = MBPartner.get(Env.getCtx(), 118); // Joe Block
MBPartner bpartner = MBPartner.get(Env.getCtx(), DictionaryIDs.C_BPartner.JOE_BLOCK.id);
Timestamp currentDate = Env.getContextAsDate(Env.getCtx(), "#Date");
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(currentDate.getTime());
Timestamp date = new Timestamp(cal.getTimeInMillis());
MCurrency usd = MCurrency.get(100); // USD
MCurrency usd = MCurrency.get(DictionaryIDs.C_Currency.USD.id); // USD
try {
String whereClause = "AD_Org_ID=? AND C_Currency_ID=?";
@ -1178,8 +1171,8 @@ public class AllocationTest extends AbstractTestCase {
assertTrue(ba != null, "@NoAccountOrgCurrency@");
// Invoice (totallines 100, grandtotal 106)
Integer payterm = 106; //(2%10 Net 30)
Integer taxid = 105; // (CT Sales, Rate 6)
int payterm = DictionaryIDs.C_PaymentTerm.TWO_PERCENT_10_NET_30.id; //(2%10 Net 30)
int taxid = DictionaryIDs.C_Tax.CT_SALES.id; // (CT Sales, Rate 6)
MInvoice invoice = createInvoice(true,false, date, date,
bpartner.getC_BPartner_ID(), payterm, taxid, Env.ONEHUNDRED);
assertEquals(invoice.getTotalLines(), new BigDecimal("100.0"));
@ -1292,14 +1285,14 @@ public class AllocationTest extends AbstractTestCase {
// #4 check accounts
public void testPaymentPostingWithWriteOffandDiscountARCredMemo() {
MBPartner bpartner = MBPartner.get(Env.getCtx(), 118); // Joe Block
MBPartner bpartner = MBPartner.get(Env.getCtx(), DictionaryIDs.C_BPartner.JOE_BLOCK.id);
Timestamp currentDate = Env.getContextAsDate(Env.getCtx(), "#Date");
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(currentDate.getTime());
Timestamp date = new Timestamp(cal.getTimeInMillis());
MCurrency usd = MCurrency.get(100); // USD
MCurrency usd = MCurrency.get(DictionaryIDs.C_Currency.USD.id); // USD
try {
String whereClause = "AD_Org_ID=? AND C_Currency_ID=?";
@ -1310,8 +1303,8 @@ public class AllocationTest extends AbstractTestCase {
assertTrue(ba != null, "@NoAccountOrgCurrency@");
// Invoice (totallines 100, grandtotal 106)
Integer payterm = 106; //(2%10 Net 30)
Integer taxid = 105; // (CT Sales, Rate 6)
int payterm = DictionaryIDs.C_PaymentTerm.TWO_PERCENT_10_NET_30.id; //(2%10 Net 30)
int taxid = DictionaryIDs.C_Tax.CT_SALES.id; // (CT Sales, Rate 6)
MInvoice invoice = createInvoice(true, true, date, date,
bpartner.getC_BPartner_ID(), payterm, taxid, Env.ONEHUNDRED);
assertEquals(invoice.getTotalLines(), new BigDecimal("100.0"));
@ -1430,7 +1423,7 @@ public class AllocationTest extends AbstractTestCase {
cal.setTimeInMillis(currentDate.getTime());
Timestamp date = new Timestamp(cal.getTimeInMillis());
MCurrency usd = MCurrency.get(100); // USD
MCurrency usd = MCurrency.get(DictionaryIDs.C_Currency.USD.id); // USD
try {
String whereClause = "AD_Org_ID=? AND C_Currency_ID=?";
@ -1441,8 +1434,8 @@ public class AllocationTest extends AbstractTestCase {
assertTrue(ba != null, "@NoAccountOrgCurrency@");
// Invoice (totallines 100, grandtotal 106)
Integer payterm = 105; //(Immediate)
Integer taxid = 105; // (CT Sales, Rate 6)
int payterm = DictionaryIDs.C_PaymentTerm.IMMEDIATE.id;
int taxid = DictionaryIDs.C_Tax.CT_SALES.id; // (CT Sales, Rate 6)
MInvoice invoice = createInvoice(false, false, date, date,
bpartner.getC_BPartner_ID(), payterm, taxid, Env.ONEHUNDRED);
assertEquals(invoice.getTotalLines(), new BigDecimal("100.0"));
@ -1561,7 +1554,7 @@ public class AllocationTest extends AbstractTestCase {
cal.setTimeInMillis(currentDate.getTime());
Timestamp date = new Timestamp(cal.getTimeInMillis());
MCurrency usd = MCurrency.get(100); // USD
MCurrency usd = MCurrency.get(DictionaryIDs.C_Currency.USD.id); // USD
try {
String whereClause = "AD_Org_ID=? AND C_Currency_ID=?";
@ -1572,8 +1565,8 @@ public class AllocationTest extends AbstractTestCase {
assertTrue(ba != null, "@NoAccountOrgCurrency@");
// Invoice (totallines 100, grandtotal 106)
Integer payterm = 105; //(Immediate)
Integer taxid = 105; // (CT Sales, Rate 6)
int payterm = DictionaryIDs.C_PaymentTerm.IMMEDIATE.id;
int taxid = DictionaryIDs.C_Tax.CT_SALES.id; // (CT Sales, Rate 6)
MInvoice invoice = createInvoice(false, true, date, date,
bpartner.getC_BPartner_ID(), payterm, taxid, Env.ONEHUNDRED);
assertEquals(invoice.getTotalLines(), new BigDecimal("100.0"));
@ -1685,14 +1678,14 @@ public class AllocationTest extends AbstractTestCase {
// #4 Check accounts
public void testAllocatePostingWithWriteOffandDiscountARInvARCrMe() {
MBPartner bpartner = MBPartner.get(Env.getCtx(), 118); // Joe Block
MBPartner bpartner = MBPartner.get(Env.getCtx(), DictionaryIDs.C_BPartner.JOE_BLOCK.id);
Timestamp currentDate = Env.getContextAsDate(Env.getCtx(), "#Date");
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(currentDate.getTime());
Timestamp date = new Timestamp(cal.getTimeInMillis());
MCurrency usd = MCurrency.get(100); // USD
MCurrency usd = MCurrency.get(DictionaryIDs.C_Currency.USD.id); // USD
try {
String whereClause = "AD_Org_ID=? AND C_Currency_ID=?";
@ -1703,14 +1696,14 @@ public class AllocationTest extends AbstractTestCase {
assertTrue(ba != null, "@NoAccountOrgCurrency@");
// Invoice (totallines 100, grandtotal 106)
Integer payterm = 106; //(2%10 Net 30)
Integer taxid = 105; // (CT Sales, Rate 6)
int payterm = DictionaryIDs.C_PaymentTerm.TWO_PERCENT_10_NET_30.id; //(2%10 Net 30)
int taxid = DictionaryIDs.C_Tax.CT_SALES.id; // (CT Sales, Rate 6)
MInvoice invoice = createInvoice(true,false, date, date,
bpartner.getC_BPartner_ID(), payterm, taxid, Env.ONEHUNDRED);
assertEquals(invoice.getTotalLines(), new BigDecimal("100.0"));
assertEquals(invoice.getGrandTotal(), new BigDecimal("106.00"));
Integer paytermcm = 105; //(Immediate)
int paytermcm = DictionaryIDs.C_PaymentTerm.IMMEDIATE.id;
MInvoice creditmemo = createInvoice(true,true, date, date,
bpartner.getC_BPartner_ID(), paytermcm, taxid, new BigDecimal("96.23"));
assertEquals(creditmemo.getTotalLines(), new BigDecimal("96.23"));
@ -1829,7 +1822,7 @@ public class AllocationTest extends AbstractTestCase {
cal.setTimeInMillis(currentDate.getTime());
Timestamp date = new Timestamp(cal.getTimeInMillis());
MCurrency usd = MCurrency.get(100); // USD
MCurrency usd = MCurrency.get(DictionaryIDs.C_Currency.USD.id); // USD
try {
String whereClause = "AD_Org_ID=? AND C_Currency_ID=?";
@ -1840,14 +1833,14 @@ public class AllocationTest extends AbstractTestCase {
assertTrue(ba != null, "@NoAccountOrgCurrency@");
// Invoice (totallines 100, grandtotal 106)
Integer payterm = 105; //(Immediate)
Integer taxid = 105; // (CT Sales, Rate 6)
int payterm = DictionaryIDs.C_PaymentTerm.IMMEDIATE.id;
int taxid = DictionaryIDs.C_Tax.CT_SALES.id; // (CT Sales, Rate 6)
MInvoice invoice = createInvoice(false, false, date, date,
bpartner.getC_BPartner_ID(), payterm, taxid, Env.ONEHUNDRED);
assertEquals(invoice.getTotalLines(), new BigDecimal("100.0"));
assertEquals(invoice.getGrandTotal(), new BigDecimal("106.00"));
Integer paytermcm = 105; //(Immediate)
int paytermcm = DictionaryIDs.C_PaymentTerm.IMMEDIATE.id;
MInvoice creditmemo = createInvoice(false,true, date, date,
bpartner.getC_BPartner_ID(), paytermcm, taxid, new BigDecimal("96.23"));
assertEquals(creditmemo.getTotalLines(), new BigDecimal("96.23"));
@ -1856,7 +1849,7 @@ public class AllocationTest extends AbstractTestCase {
MAllocationHdr alloc = new MAllocationHdr(Env.getCtx(), true, date, usd.getC_Currency_ID(), Env.getContext(Env.getCtx(), "#AD_User_Name"), getTrxName());
alloc.setAD_Org_ID(invoice.getAD_Org_ID());
int doctypeAlloc = MDocType.getDocType("CMA");
int doctypeAlloc = MDocType.getDocType(MDocType.DOCBASETYPE_PaymentAllocation);
alloc.setC_DocType_ID(doctypeAlloc);
alloc.setDescription(alloc.getDescriptionForManualAllocation(invoice.getC_BPartner_ID(), getTrxName()));
alloc.saveEx();
@ -1970,10 +1963,10 @@ public class AllocationTest extends AbstractTestCase {
Timestamp date2 = new Timestamp(cal.getTimeInMillis());
Timestamp date3 = currentDate;
int C_ConversionType_ID = 201; // Company
int C_ConversionType_ID = DictionaryIDs.C_ConversionType.COMPANY.id; // Company
MCurrency usd = MCurrency.get(100); // USD
MCurrency euro = MCurrency.get("EUR"); // EUR
MCurrency usd = MCurrency.get(DictionaryIDs.C_Currency.USD.id); // USD
MCurrency euro = MCurrency.get(DictionaryIDs.C_Currency.EUR.id); // EUR
BigDecimal eurToUsd1 = new BigDecimal(32.458922422202);
MConversionRate cr1 = createConversionRate(euro.getC_Currency_ID(), usd.getC_Currency_ID(), C_ConversionType_ID, date1, eurToUsd1, false);
@ -1983,7 +1976,7 @@ public class AllocationTest extends AbstractTestCase {
BigDecimal eurToUsd3 = new BigDecimal(33.27812049435);
MConversionRate cr3 = createConversionRate(euro.getC_Currency_ID(), usd.getC_Currency_ID(), C_ConversionType_ID, date3, eurToUsd3, false);
int M_PriceList_ID = 103; // Export in EUR
int M_PriceList_ID = DictionaryIDs.M_PriceList.EXPORT.id; // Export in EUR
try {
String whereClause = "AD_Org_ID=? AND C_Currency_ID=?";
@ -1994,11 +1987,11 @@ public class AllocationTest extends AbstractTestCase {
assertTrue(ba != null, "@NoAccountOrgCurrency@");
MInvoice invoice1 = new MInvoice(Env.getCtx(), 0, getTrxName());
invoice1.setC_BPartner_ID(BP_C_AND_W);
invoice1.setC_BPartner_ID(DictionaryIDs.C_BPartner.C_AND_W.id);
invoice1.setC_DocTypeTarget_ID(MDocType.DOCBASETYPE_ARInvoice);
invoice1.setC_DocType_ID(invoice1.getC_DocTypeTarget_ID());
invoice1.setPaymentRule(MInvoice.PAYMENTRULE_OnCredit);
invoice1.setC_PaymentTerm_ID(PAYMENT_TERM_IMMEDIATE);
invoice1.setC_PaymentTerm_ID(DictionaryIDs.C_PaymentTerm.IMMEDIATE.id);
invoice1.setDateInvoiced(date1);
invoice1.setDateAcct(date1);
invoice1.setM_PriceList_ID(M_PriceList_ID);
@ -2009,24 +2002,24 @@ public class AllocationTest extends AbstractTestCase {
MInvoiceLine line = new MInvoiceLine(invoice1);
line.setLine(10);
line.setC_Charge_ID(CHARGE_FREIGHT);
line.setC_Charge_ID(DictionaryIDs.C_Charge.FREIGHT.id);
line.setQty(BigDecimal.ONE);
BigDecimal invAmt = new BigDecimal(12587.48);
line.setPrice(invAmt);
line.setC_Tax_ID(104); // Standard
line.setC_Tax_ID(DictionaryIDs.C_Tax.STANDARD.id); // Standard
line.saveEx();
completeDocument(invoice1);
postDocument(invoice1);
BigDecimal payAmt = new BigDecimal(18549.52);
MPayment payment = createReceiptPayment(BP_C_AND_W, ba.getC_BankAccount_ID(), date2, euro.getC_Currency_ID(), C_ConversionType_ID, payAmt);
MPayment payment = createReceiptPayment(DictionaryIDs.C_BPartner.C_AND_W.id, ba.getC_BankAccount_ID(), date2, euro.getC_Currency_ID(), C_ConversionType_ID, payAmt);
completeDocument(payment);
postDocument(payment);
MAllocationHdr alloc1 = new MAllocationHdr(Env.getCtx(), true, date2, euro.getC_Currency_ID(), Env.getContext(Env.getCtx(), Env.AD_USER_NAME), getTrxName());
alloc1.setAD_Org_ID(payment.getAD_Org_ID());
int doctypeAlloc = MDocType.getDocType("CMA");
int doctypeAlloc = MDocType.getDocType(MDocType.DOCBASETYPE_PaymentAllocation);
alloc1.setC_DocType_ID(doctypeAlloc);
alloc1.saveEx();
@ -2071,11 +2064,11 @@ public class AllocationTest extends AbstractTestCase {
}
MInvoice invoice2 = new MInvoice(Env.getCtx(), 0, getTrxName());
invoice2.setC_BPartner_ID(BP_C_AND_W);
invoice2.setC_BPartner_ID(DictionaryIDs.C_BPartner.C_AND_W.id);
invoice2.setC_DocTypeTarget_ID(MDocType.DOCBASETYPE_ARInvoice);
invoice2.setC_DocType_ID(invoice2.getC_DocTypeTarget_ID());
invoice2.setPaymentRule(MInvoice.PAYMENTRULE_OnCredit);
invoice2.setC_PaymentTerm_ID(PAYMENT_TERM_IMMEDIATE);
invoice2.setC_PaymentTerm_ID(DictionaryIDs.C_PaymentTerm.IMMEDIATE.id);
invoice2.setDateInvoiced(date3);
invoice2.setDateAcct(date3);
invoice2.setM_PriceList_ID(M_PriceList_ID);
@ -2086,11 +2079,11 @@ public class AllocationTest extends AbstractTestCase {
line = new MInvoiceLine(invoice2);
line.setLine(10);
line.setC_Charge_ID(CHARGE_FREIGHT);
line.setC_Charge_ID(DictionaryIDs.C_Charge.FREIGHT.id);
line.setQty(BigDecimal.ONE);
invAmt = new BigDecimal(40125);
line.setPrice(invAmt);
line.setC_Tax_ID(104); // Standard
line.setC_Tax_ID(DictionaryIDs.C_Tax.STANDARD.id); // Standard
line.saveEx();
completeDocument(invoice2);
@ -2188,7 +2181,7 @@ public class AllocationTest extends AbstractTestCase {
line1.setLine(10);
line1.setC_Charge_ID(CHARGE_FREIGHT);
line1.setC_Charge_ID(DictionaryIDs.C_Charge.FREIGHT.id);
line1.setQty(new BigDecimal("1"));
line1.setPrice(totallines);
line1.setC_Tax_ID(taxid);
@ -2200,6 +2193,4 @@ public class AllocationTest extends AbstractTestCase {
return invoice;
}
}

View File

@ -55,7 +55,7 @@ public class MiniTableImpl implements IMiniTable {
private int m_keyColumnIndex;
private int m_selectedRow;
private int m_selectedRow = -1;
public MiniTableImpl() {
}
@ -277,6 +277,9 @@ public class MiniTableImpl implements IMiniTable {
@Override
public void setRowCount(int rowCount) {
while (model.size() < rowCount) {
model.add(new HashMap<String, Object>());
}
}
@Override