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:
Elaine Tan 2014-03-13 12:24:15 +08:00
parent 63c57b944c
commit db3a14f6da
2 changed files with 158 additions and 112 deletions

View File

@ -189,26 +189,23 @@ public class MPaySelectionCheck extends X_C_PaySelectionCheck
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);
} }
} }
@ -244,18 +238,36 @@ public class MPaySelectionCheck extends X_C_PaySelectionCheck
/************************************************************************** /**************************************************************************
* Confirm Print. * Get Checks of Payment Selection
* Create Payments the first time *
* @param checks checks * @param C_PaySelection_ID Payment Selection
* @param batch batch * @param PaymentRule Payment Rule
* @return last Document number or 0 if nothing printed * @param startDocumentNo start document no
* @param trxName transaction
* @return array of checks
*/ */
public static int confirmPrint (MPaySelectionCheck[] checks, MPaymentBatch batch) static public MPaySelectionCheck[] get (int C_PaySelection_ID,
String PaymentRule, int startDocumentNo, String trxName)
{ {
int lastDocumentNo = 0; MPaySelectionCheck[] checks = get(C_PaySelection_ID, PaymentRule, trxName);
for (int i = 0; i < checks.length; i++) 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)
{ {
MPaySelectionCheck check = checks[i];
MPayment payment = new MPayment(check.getCtx(), check.getC_Payment_ID(), check.get_TrxName()); MPayment payment = new MPayment(check.getCtx(), check.getC_Payment_ID(), check.get_TrxName());
// Existing Payment // Existing Payment
if (check.getC_Payment_ID() != 0) if (check.getC_Payment_ID() != 0)
@ -283,7 +295,7 @@ public class MPaySelectionCheck extends X_C_PaySelectionCheck
else else
{ {
s_log.log(Level.SEVERE, "Unsupported Payment Rule=" + check.getPaymentRule()); s_log.log(Level.SEVERE, "Unsupported Payment Rule=" + check.getPaymentRule());
continue; return;
} }
payment.setTrxType(X_C_Payment.TRXTYPE_CreditPayment); payment.setTrxType(X_C_Payment.TRXTYPE_CreditPayment);
payment.setAmount(check.getParent().getC_Currency_ID(), check.getPayAmt()); payment.setAmount(check.getParent().getC_Currency_ID(), check.getPayAmt());
@ -335,6 +347,27 @@ public class MPaySelectionCheck extends X_C_PaySelectionCheck
} }
} // new Payment } // new Payment
check.setIsPrinted(true);
check.setProcessed(true);
if (!check.save ())
s_log.log(Level.SEVERE, "Check not saved: " + check);
} // confirmPrint
/**************************************************************************
* Confirm Print.
* Create Payments the first time
* @param checks checks
* @param batch batch
* @return last Document number or 0 if nothing printed
*/
public static int confirmPrint (MPaySelectionCheck[] checks, MPaymentBatch batch)
{
int lastDocumentNo = 0;
for (int i = 0; i < checks.length; i++)
{
MPaySelectionCheck check = checks[i];
confirmPrint(check, batch);
// 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);

View File

@ -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
} }
@ -419,19 +420,30 @@ public class WPayPrint extends PayPrint implements IFormController, EventListene
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());
@ -439,13 +451,20 @@ public class WPayPrint extends PayPrint implements IFormController, EventListene
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();
if (log.isLoggable(Level.CONFIG)) log.config("C_PaySelection_ID=" + m_C_PaySelection_ID + ", PaymentRule=" + PaymentRule + ", DocumentNo=" + startDocumentNo); // get payment selection checks without check no assignment
// 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)