IDEMPIERE-1814 Payment check no and stock check number do not match when using Payment Selection and Payment Print/Export
This commit is contained in:
parent
63c57b944c
commit
db3a14f6da
|
@ -188,27 +188,24 @@ public class MPaySelectionCheck extends X_C_PaySelectionCheck
|
||||||
ps.saveEx();
|
ps.saveEx();
|
||||||
return psc;
|
return psc;
|
||||||
} // createForPayment
|
} // createForPayment
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* Get Checks of Payment Selection
|
* Get Checks of Payment Selection without check no assignment
|
||||||
*
|
*
|
||||||
* @param C_PaySelection_ID Payment Selection
|
* @param C_PaySelection_ID Payment Selection
|
||||||
* @param PaymentRule Payment Rule
|
* @param PaymentRule Payment Rule
|
||||||
* @param startDocumentNo start document no
|
|
||||||
* @param trxName transaction
|
* @param trxName transaction
|
||||||
* @return array of checks
|
* @return array of checks
|
||||||
*/
|
*/
|
||||||
static public MPaySelectionCheck[] get (int C_PaySelection_ID,
|
public static MPaySelectionCheck[] get (int C_PaySelection_ID, String PaymentRule, String trxName)
|
||||||
String PaymentRule, int startDocumentNo, String trxName)
|
|
||||||
{
|
{
|
||||||
if (s_log.isLoggable(Level.FINE)) s_log.fine("C_PaySelection_ID=" + C_PaySelection_ID
|
if (s_log.isLoggable(Level.FINE)) s_log.fine("C_PaySelection_ID=" + C_PaySelection_ID
|
||||||
+ ", PaymentRule=" + PaymentRule + ", startDocumentNo=" + startDocumentNo);
|
+ ", PaymentRule=" + PaymentRule);
|
||||||
ArrayList<MPaySelectionCheck> list = new ArrayList<MPaySelectionCheck>();
|
ArrayList<MPaySelectionCheck> list = new ArrayList<MPaySelectionCheck>();
|
||||||
|
|
||||||
int docNo = startDocumentNo;
|
|
||||||
String sql = "SELECT * FROM C_PaySelectionCheck "
|
String sql = "SELECT * FROM C_PaySelectionCheck "
|
||||||
+ "WHERE C_PaySelection_ID=? AND PaymentRule=?";
|
+ "WHERE C_PaySelection_ID=? AND PaymentRule=? "
|
||||||
|
+ "ORDER BY C_PaySelectionCheck_ID"; // order by the C_PaySelectionCheck_ID
|
||||||
PreparedStatement pstmt = null;
|
PreparedStatement pstmt = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try
|
try
|
||||||
|
@ -220,9 +217,6 @@ public class MPaySelectionCheck extends X_C_PaySelectionCheck
|
||||||
while (rs.next())
|
while (rs.next())
|
||||||
{
|
{
|
||||||
MPaySelectionCheck check = new MPaySelectionCheck (Env.getCtx(), rs, trxName);
|
MPaySelectionCheck check = new MPaySelectionCheck (Env.getCtx(), rs, trxName);
|
||||||
// Set new Check Document No
|
|
||||||
check.setDocumentNo(String.valueOf(docNo++));
|
|
||||||
check.saveEx();
|
|
||||||
list.add(check);
|
list.add(check);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -243,6 +237,122 @@ public class MPaySelectionCheck extends X_C_PaySelectionCheck
|
||||||
} // get
|
} // get
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
* Get Checks of Payment Selection
|
||||||
|
*
|
||||||
|
* @param C_PaySelection_ID Payment Selection
|
||||||
|
* @param PaymentRule Payment Rule
|
||||||
|
* @param startDocumentNo start document no
|
||||||
|
* @param trxName transaction
|
||||||
|
* @return array of checks
|
||||||
|
*/
|
||||||
|
static public MPaySelectionCheck[] get (int C_PaySelection_ID,
|
||||||
|
String PaymentRule, int startDocumentNo, String trxName)
|
||||||
|
{
|
||||||
|
MPaySelectionCheck[] checks = get(C_PaySelection_ID, PaymentRule, trxName);
|
||||||
|
int docNo = startDocumentNo;
|
||||||
|
for (MPaySelectionCheck check : checks)
|
||||||
|
{
|
||||||
|
// Set new Check Document No
|
||||||
|
check.setDocumentNo(String.valueOf(docNo++));
|
||||||
|
check.saveEx();
|
||||||
|
}
|
||||||
|
return checks;
|
||||||
|
} // get
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
* Confirm Print for a payment selection check
|
||||||
|
* Create Payment the first time
|
||||||
|
* @param check check
|
||||||
|
* @param batch batch
|
||||||
|
*/
|
||||||
|
public static void confirmPrint (MPaySelectionCheck check, MPaymentBatch batch)
|
||||||
|
{
|
||||||
|
MPayment payment = new MPayment(check.getCtx(), check.getC_Payment_ID(), check.get_TrxName());
|
||||||
|
// Existing Payment
|
||||||
|
if (check.getC_Payment_ID() != 0)
|
||||||
|
{
|
||||||
|
// Update check number
|
||||||
|
if (check.getPaymentRule().equals(PAYMENTRULE_Check))
|
||||||
|
{
|
||||||
|
payment.setCheckNo(check.getDocumentNo());
|
||||||
|
if (!payment.save())
|
||||||
|
s_log.log(Level.SEVERE, "Payment not saved: " + payment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else // New Payment
|
||||||
|
{
|
||||||
|
payment = new MPayment(check.getCtx(), 0, check.get_TrxName());
|
||||||
|
payment.setAD_Org_ID(check.getAD_Org_ID());
|
||||||
|
//
|
||||||
|
if (check.getPaymentRule().equals(PAYMENTRULE_Check))
|
||||||
|
payment.setBankCheck (check.getParent().getC_BankAccount_ID(), false, check.getDocumentNo());
|
||||||
|
else if (check.getPaymentRule().equals(PAYMENTRULE_CreditCard))
|
||||||
|
payment.setTenderType(X_C_Payment.TENDERTYPE_CreditCard);
|
||||||
|
else if (check.getPaymentRule().equals(PAYMENTRULE_DirectDeposit)
|
||||||
|
|| check.getPaymentRule().equals(PAYMENTRULE_DirectDebit))
|
||||||
|
payment.setBankACH(check);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
s_log.log(Level.SEVERE, "Unsupported Payment Rule=" + check.getPaymentRule());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
payment.setTrxType(X_C_Payment.TRXTYPE_CreditPayment);
|
||||||
|
payment.setAmount(check.getParent().getC_Currency_ID(), check.getPayAmt());
|
||||||
|
payment.setDiscountAmt(check.getDiscountAmt());
|
||||||
|
payment.setDateTrx(check.getParent().getPayDate());
|
||||||
|
payment.setDateAcct(payment.getDateTrx()); // globalqss [ 2030685 ]
|
||||||
|
payment.setC_BPartner_ID(check.getC_BPartner_ID());
|
||||||
|
// Link to Batch
|
||||||
|
if (batch != null)
|
||||||
|
{
|
||||||
|
if (batch.getC_PaymentBatch_ID() == 0)
|
||||||
|
batch.saveEx(); // new
|
||||||
|
payment.setC_PaymentBatch_ID(batch.getC_PaymentBatch_ID());
|
||||||
|
}
|
||||||
|
// Link to Invoice
|
||||||
|
MPaySelectionLine[] psls = check.getPaySelectionLines(false);
|
||||||
|
if (s_log.isLoggable(Level.FINE)) s_log.fine("confirmPrint - " + check + " (#SelectionLines=" + psls.length + ")");
|
||||||
|
if (check.getQty() == 1 && psls != null && psls.length == 1)
|
||||||
|
{
|
||||||
|
MPaySelectionLine psl = psls[0];
|
||||||
|
if (s_log.isLoggable(Level.FINE)) s_log.fine("Map to Invoice " + psl);
|
||||||
|
//
|
||||||
|
payment.setC_Invoice_ID (psl.getC_Invoice_ID());
|
||||||
|
payment.setDiscountAmt (psl.getDiscountAmt());
|
||||||
|
payment.setWriteOffAmt(psl.getDifferenceAmt());
|
||||||
|
BigDecimal overUnder = psl.getOpenAmt().subtract(psl.getPayAmt())
|
||||||
|
.subtract(psl.getDiscountAmt()).subtract(psl.getDifferenceAmt());
|
||||||
|
payment.setOverUnderAmt(overUnder);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
payment.setDiscountAmt(Env.ZERO);
|
||||||
|
payment.setWriteOffAmt(Env.ZERO);
|
||||||
|
if (!payment.save())
|
||||||
|
s_log.log(Level.SEVERE, "Payment not saved: " + payment);
|
||||||
|
//
|
||||||
|
int C_Payment_ID = payment.get_ID();
|
||||||
|
if (C_Payment_ID < 1)
|
||||||
|
s_log.log(Level.SEVERE, "Payment not created=" + check);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
check.setC_Payment_ID (C_Payment_ID);
|
||||||
|
check.saveEx(); // Payment process needs it
|
||||||
|
// added AdempiereException by zuhri
|
||||||
|
if (!payment.processIt(DocAction.ACTION_Complete))
|
||||||
|
throw new AdempiereException("Failed when processing document - " + payment.getProcessMsg());
|
||||||
|
// end added
|
||||||
|
if (!payment.save())
|
||||||
|
s_log.log(Level.SEVERE, "Payment not saved: " + payment);
|
||||||
|
}
|
||||||
|
} // new Payment
|
||||||
|
|
||||||
|
check.setIsPrinted(true);
|
||||||
|
check.setProcessed(true);
|
||||||
|
if (!check.save ())
|
||||||
|
s_log.log(Level.SEVERE, "Check not saved: " + check);
|
||||||
|
} // confirmPrint
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* Confirm Print.
|
* Confirm Print.
|
||||||
* Create Payments the first time
|
* Create Payments the first time
|
||||||
|
@ -256,85 +366,8 @@ public class MPaySelectionCheck extends X_C_PaySelectionCheck
|
||||||
for (int i = 0; i < checks.length; i++)
|
for (int i = 0; i < checks.length; i++)
|
||||||
{
|
{
|
||||||
MPaySelectionCheck check = checks[i];
|
MPaySelectionCheck check = checks[i];
|
||||||
MPayment payment = new MPayment(check.getCtx(), check.getC_Payment_ID(), check.get_TrxName());
|
confirmPrint(check, batch);
|
||||||
// Existing Payment
|
|
||||||
if (check.getC_Payment_ID() != 0)
|
|
||||||
{
|
|
||||||
// Update check number
|
|
||||||
if (check.getPaymentRule().equals(PAYMENTRULE_Check))
|
|
||||||
{
|
|
||||||
payment.setCheckNo(check.getDocumentNo());
|
|
||||||
if (!payment.save())
|
|
||||||
s_log.log(Level.SEVERE, "Payment not saved: " + payment);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else // New Payment
|
|
||||||
{
|
|
||||||
payment = new MPayment(check.getCtx(), 0, check.get_TrxName());
|
|
||||||
payment.setAD_Org_ID(check.getAD_Org_ID());
|
|
||||||
//
|
|
||||||
if (check.getPaymentRule().equals(PAYMENTRULE_Check))
|
|
||||||
payment.setBankCheck (check.getParent().getC_BankAccount_ID(), false, check.getDocumentNo());
|
|
||||||
else if (check.getPaymentRule().equals(PAYMENTRULE_CreditCard))
|
|
||||||
payment.setTenderType(X_C_Payment.TENDERTYPE_CreditCard);
|
|
||||||
else if (check.getPaymentRule().equals(PAYMENTRULE_DirectDeposit)
|
|
||||||
|| check.getPaymentRule().equals(PAYMENTRULE_DirectDebit))
|
|
||||||
payment.setBankACH(check);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
s_log.log(Level.SEVERE, "Unsupported Payment Rule=" + check.getPaymentRule());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
payment.setTrxType(X_C_Payment.TRXTYPE_CreditPayment);
|
|
||||||
payment.setAmount(check.getParent().getC_Currency_ID(), check.getPayAmt());
|
|
||||||
payment.setDiscountAmt(check.getDiscountAmt());
|
|
||||||
payment.setDateTrx(check.getParent().getPayDate());
|
|
||||||
payment.setDateAcct(payment.getDateTrx()); // globalqss [ 2030685 ]
|
|
||||||
payment.setC_BPartner_ID(check.getC_BPartner_ID());
|
|
||||||
// Link to Batch
|
|
||||||
if (batch != null)
|
|
||||||
{
|
|
||||||
if (batch.getC_PaymentBatch_ID() == 0)
|
|
||||||
batch.saveEx(); // new
|
|
||||||
payment.setC_PaymentBatch_ID(batch.getC_PaymentBatch_ID());
|
|
||||||
}
|
|
||||||
// Link to Invoice
|
|
||||||
MPaySelectionLine[] psls = check.getPaySelectionLines(false);
|
|
||||||
if (s_log.isLoggable(Level.FINE)) s_log.fine("confirmPrint - " + check + " (#SelectionLines=" + psls.length + ")");
|
|
||||||
if (check.getQty() == 1 && psls != null && psls.length == 1)
|
|
||||||
{
|
|
||||||
MPaySelectionLine psl = psls[0];
|
|
||||||
if (s_log.isLoggable(Level.FINE)) s_log.fine("Map to Invoice " + psl);
|
|
||||||
//
|
|
||||||
payment.setC_Invoice_ID (psl.getC_Invoice_ID());
|
|
||||||
payment.setDiscountAmt (psl.getDiscountAmt());
|
|
||||||
payment.setWriteOffAmt(psl.getDifferenceAmt());
|
|
||||||
BigDecimal overUnder = psl.getOpenAmt().subtract(psl.getPayAmt())
|
|
||||||
.subtract(psl.getDiscountAmt()).subtract(psl.getDifferenceAmt());
|
|
||||||
payment.setOverUnderAmt(overUnder);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
payment.setDiscountAmt(Env.ZERO);
|
|
||||||
payment.setWriteOffAmt(Env.ZERO);
|
|
||||||
if (!payment.save())
|
|
||||||
s_log.log(Level.SEVERE, "Payment not saved: " + payment);
|
|
||||||
//
|
|
||||||
int C_Payment_ID = payment.get_ID();
|
|
||||||
if (C_Payment_ID < 1)
|
|
||||||
s_log.log(Level.SEVERE, "Payment not created=" + check);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
check.setC_Payment_ID (C_Payment_ID);
|
|
||||||
check.saveEx(); // Payment process needs it
|
|
||||||
// added AdempiereException by zuhri
|
|
||||||
if (!payment.processIt(DocAction.ACTION_Complete))
|
|
||||||
throw new AdempiereException("Failed when processing document - " + payment.getProcessMsg());
|
|
||||||
// end added
|
|
||||||
if (!payment.save())
|
|
||||||
s_log.log(Level.SEVERE, "Payment not saved: " + payment);
|
|
||||||
}
|
|
||||||
} // new Payment
|
|
||||||
|
|
||||||
// Get Check Document No
|
// Get Check Document No
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -346,10 +379,6 @@ public class MPaySelectionCheck extends X_C_PaySelectionCheck
|
||||||
{
|
{
|
||||||
s_log.log(Level.SEVERE, "DocumentNo=" + check.getDocumentNo(), ex);
|
s_log.log(Level.SEVERE, "DocumentNo=" + check.getDocumentNo(), ex);
|
||||||
}
|
}
|
||||||
check.setIsPrinted(true);
|
|
||||||
check.setProcessed(true);
|
|
||||||
if (!check.save ())
|
|
||||||
s_log.log(Level.SEVERE, "Check not saved: " + check);
|
|
||||||
} // all checks
|
} // all checks
|
||||||
|
|
||||||
if (s_log.isLoggable(Level.FINE)) s_log.fine("Last Document No = " + lastDocumentNo);
|
if (s_log.isLoggable(Level.FINE)) s_log.fine("Last Document No = " + lastDocumentNo);
|
||||||
|
|
|
@ -69,6 +69,8 @@ import org.zkoss.zul.Center;
|
||||||
import org.zkoss.zul.Filedownload;
|
import org.zkoss.zul.Filedownload;
|
||||||
import org.zkoss.zul.South;
|
import org.zkoss.zul.South;
|
||||||
|
|
||||||
|
import com.lowagie.text.pdf.PdfReader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Payment Print & Export
|
* Payment Print & Export
|
||||||
*
|
*
|
||||||
|
@ -379,7 +381,6 @@ public class WPayPrint extends PayPrint implements IFormController, EventListene
|
||||||
{
|
{
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
// int lastDocumentNo =
|
|
||||||
MPaySelectionCheck.confirmPrint (m_checks, m_batch);
|
MPaySelectionCheck.confirmPrint (m_checks, m_batch);
|
||||||
// document No not updated
|
// document No not updated
|
||||||
}
|
}
|
||||||
|
@ -418,34 +419,52 @@ public class WPayPrint extends PayPrint implements IFormController, EventListene
|
||||||
log.info(PaymentRule);
|
log.info(PaymentRule);
|
||||||
if (!getChecks(PaymentRule))
|
if (!getChecks(PaymentRule))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Update BankAccountDoc
|
// get document no
|
||||||
int lastDocumentNo = MPaySelectionCheck.confirmPrint (m_checks, m_batch);
|
int startDocumentNo = ((Number)fDocumentNo.getValue()).intValue();
|
||||||
|
if (log.isLoggable(Level.CONFIG)) log.config("DocumentNo=" + startDocumentNo);
|
||||||
|
|
||||||
// for all checks
|
// for all checks
|
||||||
List<File> pdfList = new ArrayList<File>();
|
List<File> pdfList = new ArrayList<File>();
|
||||||
|
int lastDocumentNo = startDocumentNo;
|
||||||
for (int i = 0; i < m_checks.length; i++)
|
for (int i = 0; i < m_checks.length; i++)
|
||||||
{
|
{
|
||||||
MPaySelectionCheck check = m_checks[i];
|
MPaySelectionCheck check = m_checks[i];
|
||||||
|
|
||||||
|
// Set new Check Document No
|
||||||
|
check.setDocumentNo(String.valueOf(lastDocumentNo));
|
||||||
|
check.saveEx();
|
||||||
|
|
||||||
|
// Update BankAccountDoc
|
||||||
|
MPaySelectionCheck.confirmPrint(m_checks[i], m_batch);
|
||||||
|
|
||||||
// ReportCtrl will check BankAccountDoc for PrintFormat
|
// ReportCtrl will check BankAccountDoc for PrintFormat
|
||||||
ReportEngine re = ReportEngine.get(Env.getCtx(), ReportEngine.CHECK, check.get_ID());
|
ReportEngine re = ReportEngine.get(Env.getCtx(), ReportEngine.CHECK, check.get_ID());
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
MPrintFormat format = re.getPrintFormat();
|
MPrintFormat format = re.getPrintFormat();
|
||||||
|
File pdfFile = null;
|
||||||
if (format.getJasperProcess_ID() > 0)
|
if (format.getJasperProcess_ID() > 0)
|
||||||
{
|
{
|
||||||
ProcessInfo pi = new ProcessInfo("", format.getJasperProcess_ID());
|
ProcessInfo pi = new ProcessInfo("", format.getJasperProcess_ID());
|
||||||
pi.setRecord_ID(check.get_ID());
|
pi.setRecord_ID(check.get_ID());
|
||||||
pi.setIsBatch(true);
|
pi.setIsBatch(true);
|
||||||
|
|
||||||
ServerProcessCtl.process(pi, null);
|
ServerProcessCtl.process(pi, null);
|
||||||
pdfList.add(pi.getPDFReport());
|
pdfFile = pi.getPDFReport();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
File file = File.createTempFile("WPayPrint", null);
|
pdfFile = File.createTempFile("WPayPrint", null);
|
||||||
re.getPDF(file);
|
re.getPDF(pdfFile);
|
||||||
pdfList.add(file);
|
}
|
||||||
|
|
||||||
|
if (pdfFile != null)
|
||||||
|
{
|
||||||
|
// increase the check document no by the number of pages of the generated pdf file
|
||||||
|
PdfReader document = new PdfReader(pdfFile.getAbsolutePath());
|
||||||
|
lastDocumentNo += document.getNumberOfPages();
|
||||||
|
pdfList.add(pdfFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
@ -471,10 +490,11 @@ public class WPayPrint extends PayPrint implements IFormController, EventListene
|
||||||
}
|
}
|
||||||
final SimplePDFViewer chequeViewerRef = chequeViewer;
|
final SimplePDFViewer chequeViewerRef = chequeViewer;
|
||||||
|
|
||||||
if (lastDocumentNo != 0)
|
// Update Check Next Document No
|
||||||
|
if (startDocumentNo != lastDocumentNo)
|
||||||
{
|
{
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append("UPDATE C_BankAccountDoc SET CurrentNext=").append(++lastDocumentNo)
|
sb.append("UPDATE C_BankAccountDoc SET CurrentNext=").append(lastDocumentNo)
|
||||||
.append(" WHERE C_BankAccount_ID=").append(m_C_BankAccount_ID)
|
.append(" WHERE C_BankAccount_ID=").append(m_C_BankAccount_ID)
|
||||||
.append(" AND PaymentRule='").append(PaymentRule).append("'");
|
.append(" AND PaymentRule='").append(PaymentRule).append("'");
|
||||||
DB.executeUpdate(sb.toString(), null);
|
DB.executeUpdate(sb.toString(), null);
|
||||||
|
@ -561,13 +581,10 @@ public class WPayPrint extends PayPrint implements IFormController, EventListene
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get data
|
if (log.isLoggable(Level.CONFIG)) log.config("C_PaySelection_ID=" + m_C_PaySelection_ID + ", PaymentRule=" + PaymentRule);
|
||||||
int startDocumentNo = ((Number)fDocumentNo.getValue()).intValue();
|
|
||||||
|
// get payment selection checks without check no assignment
|
||||||
if (log.isLoggable(Level.CONFIG)) log.config("C_PaySelection_ID=" + m_C_PaySelection_ID + ", PaymentRule=" + PaymentRule + ", DocumentNo=" + startDocumentNo);
|
m_checks = MPaySelectionCheck.get(m_C_PaySelection_ID, PaymentRule, null);
|
||||||
//
|
|
||||||
// get Slecetions
|
|
||||||
m_checks = MPaySelectionCheck.get(m_C_PaySelection_ID, PaymentRule, startDocumentNo, null);
|
|
||||||
|
|
||||||
//
|
//
|
||||||
if (m_checks == null || m_checks.length == 0)
|
if (m_checks == null || m_checks.length == 0)
|
||||||
|
|
Loading…
Reference in New Issue