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;
} // createForPayment
/**************************************************************************
* Get Checks of Payment Selection
* Get Checks of Payment Selection without check no assignment
*
* @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)
public static MPaySelectionCheck[] get (int C_PaySelection_ID, String PaymentRule, String trxName)
{
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>();
int docNo = startDocumentNo;
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;
ResultSet rs = null;
try
@ -220,9 +217,6 @@ public class MPaySelectionCheck extends X_C_PaySelectionCheck
while (rs.next())
{
MPaySelectionCheck check = new MPaySelectionCheck (Env.getCtx(), rs, trxName);
// Set new Check Document No
check.setDocumentNo(String.valueOf(docNo++));
check.saveEx();
list.add(check);
}
}
@ -244,18 +238,36 @@ public class MPaySelectionCheck extends X_C_PaySelectionCheck
/**************************************************************************
* Confirm Print.
* Create Payments the first time
* @param checks checks
* @param batch batch
* @return last Document number or 0 if nothing printed
* 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
*/
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;
for (int i = 0; i < checks.length; i++)
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)
{
MPaySelectionCheck check = checks[i];
MPayment payment = new MPayment(check.getCtx(), check.getC_Payment_ID(), check.get_TrxName());
// Existing Payment
if (check.getC_Payment_ID() != 0)
@ -283,7 +295,7 @@ public class MPaySelectionCheck extends X_C_PaySelectionCheck
else
{
s_log.log(Level.SEVERE, "Unsupported Payment Rule=" + check.getPaymentRule());
continue;
return;
}
payment.setTrxType(X_C_Payment.TRXTYPE_CreditPayment);
payment.setAmount(check.getParent().getC_Currency_ID(), check.getPayAmt());
@ -335,6 +347,27 @@ public class MPaySelectionCheck extends X_C_PaySelectionCheck
}
} // 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
try
{
@ -346,10 +379,6 @@ public class MPaySelectionCheck extends X_C_PaySelectionCheck
{
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
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.South;
import com.lowagie.text.pdf.PdfReader;
/**
* Payment Print & Export
*
@ -379,7 +381,6 @@ public class WPayPrint extends PayPrint implements IFormController, EventListene
{
if (result)
{
// int lastDocumentNo =
MPaySelectionCheck.confirmPrint (m_checks, m_batch);
// document No not updated
}
@ -419,19 +420,30 @@ public class WPayPrint extends PayPrint implements IFormController, EventListene
if (!getChecks(PaymentRule))
return;
// Update BankAccountDoc
int lastDocumentNo = MPaySelectionCheck.confirmPrint (m_checks, m_batch);
// get document no
int startDocumentNo = ((Number)fDocumentNo.getValue()).intValue();
if (log.isLoggable(Level.CONFIG)) log.config("DocumentNo=" + startDocumentNo);
// for all checks
List<File> pdfList = new ArrayList<File>();
int lastDocumentNo = startDocumentNo;
for (int i = 0; i < m_checks.length; 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
ReportEngine re = ReportEngine.get(Env.getCtx(), ReportEngine.CHECK, check.get_ID());
try
{
MPrintFormat format = re.getPrintFormat();
File pdfFile = null;
if (format.getJasperProcess_ID() > 0)
{
ProcessInfo pi = new ProcessInfo("", format.getJasperProcess_ID());
@ -439,13 +451,20 @@ public class WPayPrint extends PayPrint implements IFormController, EventListene
pi.setIsBatch(true);
ServerProcessCtl.process(pi, null);
pdfList.add(pi.getPDFReport());
pdfFile = pi.getPDFReport();
}
else
{
File file = File.createTempFile("WPayPrint", null);
re.getPDF(file);
pdfList.add(file);
pdfFile = File.createTempFile("WPayPrint", null);
re.getPDF(pdfFile);
}
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)
@ -471,10 +490,11 @@ public class WPayPrint extends PayPrint implements IFormController, EventListene
}
final SimplePDFViewer chequeViewerRef = chequeViewer;
if (lastDocumentNo != 0)
// Update Check Next Document No
if (startDocumentNo != lastDocumentNo)
{
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(" AND PaymentRule='").append(PaymentRule).append("'");
DB.executeUpdate(sb.toString(), null);
@ -561,13 +581,10 @@ public class WPayPrint extends PayPrint implements IFormController, EventListene
return false;
}
// get data
int startDocumentNo = ((Number)fDocumentNo.getValue()).intValue();
if (log.isLoggable(Level.CONFIG)) log.config("C_PaySelection_ID=" + m_C_PaySelection_ID + ", PaymentRule=" + PaymentRule);
if (log.isLoggable(Level.CONFIG)) log.config("C_PaySelection_ID=" + m_C_PaySelection_ID + ", PaymentRule=" + PaymentRule + ", DocumentNo=" + startDocumentNo);
//
// get Slecetions
m_checks = MPaySelectionCheck.get(m_C_PaySelection_ID, PaymentRule, startDocumentNo, null);
// get payment selection checks without check no assignment
m_checks = MPaySelectionCheck.get(m_C_PaySelection_ID, PaymentRule, null);
//
if (m_checks == null || m_checks.length == 0)