IDEMPIERE-1546 There is no OSGi interface for a PaymentExport / thanks to Markus Bozem

This commit is contained in:
Carlos Ruiz 2017-10-17 18:29:34 +02:00
parent 4e1f52c9ca
commit 1616e7a95b
9 changed files with 555 additions and 98 deletions

View File

@ -45,6 +45,7 @@ import org.compiere.model.PaymentProcessor;
import org.compiere.model.StandardTaxProvider;
import org.compiere.process.ProcessCall;
import org.compiere.util.CLogger;
import org.compiere.util.PaymentExport;
import org.compiere.util.ReplenishInterface;
import org.osgi.framework.FrameworkUtil;
@ -415,4 +416,38 @@ public class Core {
return engine;
}
/**
* get PaymentExporter instance
*
* @param className
* @return instance of the PaymentExporterInterface or null
*/
public static PaymentExport getPaymentExporter (String className){
if (className == null || className.length() == 0) {
s_log.log(Level.SEVERE, "No PaymentExporter class name");
return null;
}
PaymentExport myPaymentExporter = null;
List<IPaymentExporterFactory> factoryList =
Service.locator().list(IPaymentExporterFactory.class).getServices();
if (factoryList != null) {
for(IPaymentExporterFactory factory : factoryList) {
PaymentExport exporter = factory.newPaymentExporterInstance(className);
if (exporter != null) {
myPaymentExporter = exporter;
break;
}
}
}
if (myPaymentExporter == null) {
s_log.log(Level.CONFIG, className + " not found in service/extension registry and classpath");
return null;
}
return myPaymentExporter;
}
}

View File

@ -0,0 +1,58 @@
/******************************************************************************
* Product: iDempiere Business Suite ERP/CRM/SCM *
* Copyright (C) 2017 Markus Bozem *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. 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., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * *
*****************************************************************************/
package org.adempiere.base;
import java.util.logging.Level;
import org.adempiere.base.equinox.EquinoxExtensionLocator;
import org.compiere.util.CLogger;
import org.compiere.util.PaymentExport;
/**
* @author mbozem
*
*/
public class DefaultPaymentExporterFactory implements IPaymentExporterFactory {
private final static CLogger s_log = CLogger.getCLogger(DefaultPaymentExporterFactory.class);
/**
* default constructor
*/
public DefaultPaymentExporterFactory() {
}
@Override
public PaymentExport newPaymentExporterInstance(String className) {
PaymentExport myExporter = null;
myExporter = EquinoxExtensionLocator.instance().locate(PaymentExport.class, className, null).getExtension();
if (myExporter == null) {
//fall back to dynamic java class loadup
try {
Class<?> peClass = Class.forName(className);
if (peClass != null)
myExporter = (PaymentExport)peClass.newInstance();
} catch (Error e1) { // NoClassDefFound
s_log.log(Level.SEVERE, className + " - Error=" + e1.getMessage());
return null;
} catch (Exception e2) {
s_log.log(Level.SEVERE, className, e2);
return null;
}
}
return myExporter;
}
}

View File

@ -0,0 +1,29 @@
/******************************************************************************
* Product: iDempiere Business Suite ERP/CRM/SCM *
* Copyright (C) 2017 Markus Bozem *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. 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., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * *
*****************************************************************************/
package org.adempiere.base;
import org.compiere.util.PaymentExport;
/**
* PaymentExporter factory interface.
* @author mbozem
*/
public interface IPaymentExporterFactory {
/**
* @param className
* @return payment exporter instance
*/
public PaymentExport newPaymentExporterInstance(String className);
}

View File

@ -20,11 +20,14 @@ import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.Properties;
import java.util.logging.Level;
import org.adempiere.exceptions.AdempiereException;
import org.compiere.acct.Doc;
import org.compiere.process.DocAction;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
@ -43,7 +46,7 @@ public class MPaySelectionCheck extends X_C_PaySelectionCheck
/**
*
*/
private static final long serialVersionUID = -5752888482207479355L;
private static final long serialVersionUID = 2130445794890189020L;
/**
* Get Check for Payment
@ -385,60 +388,127 @@ public class MPaySelectionCheck extends X_C_PaySelectionCheck
* Create Payments the first time
* @param checks checks
* @param batch batch
* @param createDeposit create deposit batch
* @return last Document number or 0 if nothing printed
*/
public static int confirmPrint (MPaySelectionCheck[] checks, MPaymentBatch batch)
public static int confirmPrint (MPaySelectionCheck[] checks, MPaymentBatch batch, boolean createDepositBatch)
{
boolean localTrx = false;
String trxName = null;
if (checks.length > 0)
trxName = checks[0].get_TrxName();
Trx trx = null;
if (trxName == null) {
localTrx = true;
trxName = Trx.createTrxName("ConfirmPrintMulti");
trx = Trx.get(trxName, true);
trx.setDisplayName(MPaySelectionCheck.class.getName()+"_confirmPrints");
}
int lastDocumentNo = 0;
try {
for (int i = 0; i < checks.length; i++)
if (checks.length > 0)
{
trxName = checks[0].get_TrxName();
Properties ctx = checks[0].getCtx();
int c_BankAccount_ID = checks[0].getC_PaySelection().getC_BankAccount_ID() ;
String paymentRule = checks[0].getPaymentRule() ;
Boolean isDebit ;
if (MInvoice.PAYMENTRULE_DirectDeposit.compareTo(paymentRule) == 0
|| MInvoice.PAYMENTRULE_Check.compareTo(paymentRule) == 0
|| MInvoice.PAYMENTRULE_OnCredit.compareTo(paymentRule) == 0)
{
MPaySelectionCheck check = checks[i];
if (localTrx)
check.set_TrxName(trxName);
confirmPrint(check, batch);
// Get Check Document No
try
{
int no = Integer.parseInt(check.getDocumentNo());
if (lastDocumentNo < no)
lastDocumentNo = no;
}
catch (NumberFormatException ex)
{
s_log.log(Level.SEVERE, "DocumentNo=" + check.getDocumentNo(), ex);
}
} // all checks
} catch (Exception e) {
if (localTrx && trx != null) {
trx.rollback();
trx.close();
trx = null;
isDebit = false ;
}
throw new AdempiereException(e);
} finally {
if (localTrx && trx != null) {
trx.commit();
trx.close();
else if (MInvoice.PAYMENTRULE_DirectDebit.compareTo(paymentRule) == 0)
{
isDebit = true ;
}
else
{
isDebit = false ;
createDepositBatch = false ;
}
Trx trx = null;
if (trxName == null) {
localTrx = true;
trxName = Trx.createTrxName("ConfirmPrintMulti");
trx = Trx.get(trxName, true);
}
try {
MDepositBatch depositBatch = null;
if (createDepositBatch)
{
depositBatch = new MDepositBatch(ctx, 0, trxName) ;
depositBatch.setC_BankAccount_ID(c_BankAccount_ID);
if (isDebit)
{
depositBatch.setC_DocType_ID(MDocType.getDocType(Doc.DOCTYPE_ARReceipt));
}
else
{
depositBatch.setC_DocType_ID(MDocType.getDocType(Doc.DOCTYPE_APPayment));
}
depositBatch.setDateDeposit(new Timestamp((new Date()).getTime()));
depositBatch.setDateDoc(new Timestamp((new Date()).getTime()));
depositBatch.saveEx();
}
for (int i = 0; i < checks.length; i++)
{
MPaySelectionCheck check = checks[i];
if (localTrx)
check.set_TrxName(trxName);
confirmPrint(check, batch);
if (createDepositBatch)
{
MDepositBatchLine depositBatchLine = new MDepositBatchLine(depositBatch) ;
depositBatchLine.setC_Payment_ID(check.getC_Payment_ID());
depositBatchLine.setProcessed(true);
depositBatchLine.saveEx();
}
// Get Check Document No
try
{
int no = Integer.parseInt(check.getDocumentNo());
if (lastDocumentNo < no)
lastDocumentNo = no;
}
catch (NumberFormatException ex)
{
s_log.log(Level.SEVERE, "DocumentNo=" + check.getDocumentNo(), ex);
}
} // all checks
if (createDepositBatch)
{
depositBatch.setProcessed(true);
depositBatch.saveEx();
}
} catch (Exception e) {
if (localTrx && trx != null) {
trx.rollback();
trx.close();
trx = null;
}
throw new AdempiereException(e);
} finally {
if (localTrx && trx != null) {
trx.commit();
trx.close();
}
}
}
if (s_log.isLoggable(Level.FINE)) s_log.fine("Last Document No = " + lastDocumentNo);
return lastDocumentNo;
} // 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)
{
return confirmPrint (checks,batch,false) ;
} // confirmPrint
/** Logger */
static private CLogger s_log = CLogger.getCLogger (MPaySelectionCheck.class);

View File

@ -21,6 +21,7 @@ import java.io.FileWriter;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.logging.Level;
import org.compiere.model.MCurrency;
@ -67,11 +68,13 @@ public class GenericPaymentExport implements PaymentExport
/**************************************************************************
* Export to File
* @param checks array of checks
* @param depositBatch book the payments as single position
* @param paymentRule selected payment rule
* @param file file to export checks
* @return number of lines
*/
public int exportToFile (MPaySelectionCheck[] checks, File file, StringBuffer err)
{
public int exportToFile(MPaySelectionCheck[] checks, boolean depositBatch, String paymentRule, File file,
StringBuffer err) {
if (checks == null || checks.length == 0)
return 0;
// Must be a file
@ -115,6 +118,7 @@ public class GenericPaymentExport implements PaymentExport
.append(x).append("PayDate").append(x).append(",")
.append(x).append("Currency").append(x).append(",")
.append(x).append("PayAmount").append(x).append(",")
.append(x).append("DepositBatch").append(x).append(",")
.append(x).append("Comment").append(x)
.append(Env.NL);
fw.write(line.toString());
@ -154,6 +158,7 @@ public class GenericPaymentExport implements PaymentExport
.append(mpp.getParent().getPayDate()).append(",") // PayDate
.append(x).append(MCurrency.getISO_Code(Env.getCtx(), mpp.getParent().getC_Currency_ID())).append(x).append(",") // Currency
.append(mpp.getPayAmt()).append(",") // PayAmount
.append(x).append(depositBatch).append(x).append(",")
.append(x).append(comment.toString()).append(x) // Comment
.append(Env.NL);
fw.write(line.toString());
@ -249,5 +254,35 @@ public class GenericPaymentExport implements PaymentExport
return bp;
} // getBPartnerInfo
@Override
public String getFilenamePrefix() {
String creationDate = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(System.currentTimeMillis()) ;
return "payments-" + creationDate ;
}
@Override
public String getFilenameSuffix() {
return ".csv";
}
@Override
public String getContentType() {
return "text/csv";
}
@Override
public boolean supportsDepositBatch() {
return true;
}
@Override
public boolean supportsSeparateBooking() {
return true;
}
@Override
public boolean getDefaultDepositBatch() {
return false;
}
} // PaymentExport
} // PaymentExporterInterface

View File

@ -24,6 +24,10 @@ import org.compiere.model.MPaySelectionCheck;
* Custom Payment Export Interface
*
* @author Carlos Ruiz - GlobalQSS
*
* Contributors:
* Markus Bozem - IDEMPIERE-1546 / IDEMPIERE-3286
*
* @version PaymentExport.java
*/
public interface PaymentExport
@ -34,7 +38,74 @@ public interface PaymentExport
* @param checks array of checks
* @param file file to export checks
* @return number of lines
*
* This method is preserved for backward compatibility (old non-OSGi way via fragment),
* new interfaces can leave this method unimplemented and must implement the other methods
*/
public int exportToFile (MPaySelectionCheck[] checks, File file, StringBuffer err);
public default int exportToFile (MPaySelectionCheck[] checks, File file, StringBuffer err) {
return exportToFile (checks, false, (String)null, file, err);
}
/**************************************************************************
* Export to file
* @param checks array of checks
* @param depositBatch create deposit batch
* @param file file to export checks
* @return number of lines
*/
public default int exportToFile (MPaySelectionCheck[] checks, boolean depositBatch, String paymentRule, File file, StringBuffer err) {
return exportToFile (checks, file, err);
}
/**
* Get the filename prefix from plugin
* e.g. "SEPA-Credit-Transfer-"
* @return prefix for filename
*/
public default String getFilenamePrefix() {
return "paymentExport";
}
/**
* Get the filename suffix from plugin
* e.g. ".xml"
* @return suffix for filename
*/
public default String getFilenameSuffix() {
return ".txt";
}
/**
* Get the content type from plugin
* e.g. "text/xml" or "text/csv"
* @return content type delivered to browser
*/
public default String getContentType() {
return "text/plain";
}
/**
* Plugin supports deposit batch
* @return true if supported
*/
public default boolean supportsDepositBatch() {
return false;
}
/**
* Plugin supports booking payments separate on bank statement (no deposit batch)
* @return true if supported
*/
public default boolean supportsSeparateBooking() {
return false;
}
/**
* Default if supportsDepositBatch is true and supportsSeparateBooking is true
* @return true if deposit batch should be selected on default, false if deposit batch should not be selected
*/
public default boolean getDefaultDepositBatch() {
return false;
}
} // PaymentExport

View File

@ -46,6 +46,7 @@ import static org.compiere.model.SystemIDs.*;
import org.compiere.plaf.CompiereColor;
import org.compiere.print.ReportCtl;
import org.compiere.print.ReportEngine;
import org.compiere.swing.CCheckBox;
import org.compiere.swing.CComboBox;
import org.compiere.swing.CLabel;
import org.compiere.swing.CPanel;
@ -54,7 +55,6 @@ import org.compiere.util.DisplayType;
import org.compiere.util.Env;
import org.compiere.util.Ini;
import org.compiere.util.Msg;
import org.compiere.util.PaymentExport;
import org.compiere.util.ValueNamePair;
/**
@ -65,6 +65,7 @@ import org.compiere.util.ValueNamePair;
*
* Contributors:
* Carlos Ruiz - GlobalQSS - FR 3132033 - Make payment export class configurable per bank
* Markus Bozem: IDEMPIERE-1546 / IDEMPIERE-3286
*/
public class VPayPrint extends PayPrint implements FormPanel, ActionListener, VetoableChangeListener
{
@ -120,7 +121,10 @@ public class VPayPrint extends PayPrint implements FormPanel, ActionListener, Ve
private VNumber fBalance = new VNumber();
private CLabel lCurrency = new CLabel();
private CLabel fCurrency = new CLabel();
private CLabel lDepositBatch = new CLabel();
private CCheckBox fDepositBatch = new CCheckBox();
private CLabel lSumPayments = new CLabel();
private VNumber fSumPayments = new VNumber();
/**
* Static Init
* @throws Exception
@ -133,6 +137,8 @@ public class VPayPrint extends PayPrint implements FormPanel, ActionListener, Ve
southLayout.setAlignment(FlowLayout.RIGHT);
centerPanel.setLayout(centerLayout);
//
bPrint.setEnabled(false);
bExport.setEnabled(false);
bPrint.addActionListener(this);
bExport.addActionListener(this);
bCancel.addActionListener(this);
@ -156,6 +162,10 @@ public class VPayPrint extends PayPrint implements FormPanel, ActionListener, Ve
fBalance.setReadWrite(false);
fBalance.setDisplayType(DisplayType.Amount);
lCurrency.setText(Msg.translate(Env.getCtx(), "C_Currency_ID"));
lDepositBatch.setText(Msg.translate(Env.getCtx(), "C_DepositBatch_ID"));
lSumPayments.setText(Msg.getMsg(Env.getCtx(), "Sum"));
fSumPayments.setReadWrite(false);
fSumPayments.setDisplayType(DisplayType.Amount);
//
southPanel.add(bCancel, null);
southPanel.add(bExport, null);
@ -190,6 +200,15 @@ public class VPayPrint extends PayPrint implements FormPanel, ActionListener, Ve
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 12, 12, 5), 0, 0));
centerPanel.add(fCurrency, new GridBagConstraints(3, 2, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 12, 12), 0, 0));
centerPanel.add(lDepositBatch, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 12, 5, 5), 0, 0));
centerPanel.add(fDepositBatch, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 12), 0, 0));
centerPanel.add(lSumPayments, new GridBagConstraints(2, 4, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 12, 5, 5), 0, 0));
centerPanel.add(fSumPayments, new GridBagConstraints(3, 4, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 12), 0, 0));
} // VPayPrint
/**
@ -311,6 +330,9 @@ public class VPayPrint extends PayPrint implements FormPanel, ActionListener, Ve
if(noPayments != null)
fNoPayments.setText(noPayments);
if(sumPayments != null)
fSumPayments.setValue(sumPayments);
bProcess.setEnabled(PaymentRule.equals("T"));
if(documentNo != null)
@ -318,9 +340,44 @@ public class VPayPrint extends PayPrint implements FormPanel, ActionListener, Ve
if(msg != null && msg.length() > 0)
ADialog.error(m_WindowNo, panel, msg);
getPluginFeatures();
} // loadPaymentRuleInfo
protected void getPluginFeatures()
{
if (m_C_PaySelection_ID!=0)
{
if (loadPaymentExportClass (null)>=0)
{
bExport.setEnabled(true);
fDepositBatch.setValue(m_PaymentExport.getDefaultDepositBatch());
if (m_PaymentExport.supportsDepositBatch() && m_PaymentExport.supportsSeparateBooking())
{
fDepositBatch.setReadWrite(true);
}
else
{
fDepositBatch.setReadWrite(false);
}
}
else
{
bExport.setEnabled(false);
}
if (printFormatId!=null && printFormatId!=0)
{
bPrint.setEnabled(true);
}
else
{
bPrint.setEnabled(false);
}
}
} // getPluginFeatures
/**************************************************************************
* Export payments to file
*/
@ -339,7 +396,8 @@ public class VPayPrint extends PayPrint implements FormPanel, ActionListener, Ve
fc.setDialogTitle(Msg.getMsg(Env.getCtx(), "Export"));
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
fc.setMultiSelectionEnabled(false);
fc.setSelectedFile(new java.io.File("paymentExport.txt"));
String filename = m_PaymentExport.getFilenamePrefix() + m_PaymentExport.getFilenameSuffix();
fc.setSelectedFile(new java.io.File(filename));
if (fc.showSaveDialog(panel) != JFileChooser.APPROVE_OPTION)
return;
@ -349,26 +407,14 @@ public class VPayPrint extends PayPrint implements FormPanel, ActionListener, Ve
if (m_PaymentExportClass == null || m_PaymentExportClass.trim().length() == 0) {
m_PaymentExportClass = "org.compiere.util.GenericPaymentExport";
}
// Get Payment Export Class
PaymentExport custom = null;
try
no = loadPaymentExportClass(err) ;
if (no >= 0)
{
Class<?> clazz = Class.forName(m_PaymentExportClass);
custom = (PaymentExport)clazz.newInstance();
no = custom.exportToFile(m_checks, fc.getSelectedFile(), err);
}
catch (ClassNotFoundException e)
{
no = -1;
err.append("No custom PaymentExport class " + m_PaymentExportClass + " - " + e.toString());
log.log(Level.SEVERE, err.toString(), e);
}
catch (Exception e)
{
no = -1;
err.append("Error in " + m_PaymentExportClass + " check log, " + e.toString());
log.log(Level.SEVERE, err.toString(), e);
no = m_PaymentExport.exportToFile(m_checks,(Boolean) fDepositBatch.getValue(),PaymentRule, fc.getSelectedFile(), err);
}
if (no >= 0) {
ADialog.info(m_WindowNo, panel, "Saved",
fc.getSelectedFile().getAbsolutePath() + "\n"
@ -377,7 +423,7 @@ public class VPayPrint extends PayPrint implements FormPanel, ActionListener, Ve
if (ADialog.ask(m_WindowNo, panel, "VPayPrintSuccess?"))
{
// int lastDocumentNo =
MPaySelectionCheck.confirmPrint (m_checks, m_batch);
MPaySelectionCheck.confirmPrint (m_checks, m_batch, (Boolean) fDepositBatch.getValue());
// document No not updated
}
} else {

View File

@ -39,6 +39,7 @@ import org.adempiere.webui.component.Rows;
import org.adempiere.webui.component.Window;
import org.adempiere.webui.editor.WNumberEditor;
import org.adempiere.webui.editor.WSearchEditor;
import org.adempiere.webui.editor.WYesNoEditor;
import org.adempiere.webui.event.ValueChangeEvent;
import org.adempiere.webui.event.ValueChangeListener;
import org.adempiere.webui.panel.ADForm;
@ -61,7 +62,6 @@ import org.compiere.util.DB;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
import org.compiere.util.Msg;
import org.compiere.util.PaymentExport;
import org.compiere.util.ValueNamePair;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
@ -80,6 +80,7 @@ import com.itextpdf.text.pdf.PdfReader;
*
* Contributors:
* Carlos Ruiz - GlobalQSS - FR 3132033 - Make payment export class configurable per bank
* Markus Bozem: IDEMPIERE-1546 / IDEMPIERE-3286
*/
public class WPayPrint extends PayPrint implements IFormController, EventListener<Event>, ValueChangeListener
{
@ -136,7 +137,12 @@ public class WPayPrint extends PayPrint implements IFormController, EventListene
protected WNumberEditor fBalance = new WNumberEditor();
protected Label lCurrency = new Label();
protected Label fCurrency = new Label();
protected Label lDepositBatch = new Label();
protected WYesNoEditor fDepositBatch = new WYesNoEditor("", "", "Book as one post", false, false, true) ;
protected Label lSumPayments = new Label();
protected WNumberEditor fSumPayments = new WNumberEditor();
/**
* Static Init
* @throws Exception
@ -168,6 +174,10 @@ public class WPayPrint extends PayPrint implements IFormController, EventListene
fBalance.setReadWrite(false);
fBalance.getComponent().setIntegral(false);
lCurrency.setText(Msg.translate(Env.getCtx(), "C_Currency_ID"));
lDepositBatch.setText(Msg.translate(Env.getCtx(), "C_DepositBatch_ID"));
lSumPayments.setText(Msg.getMsg(Env.getCtx(), "Sum"));
fSumPayments.setReadWrite(false);
fSumPayments.getComponent().setIntegral(false);
//
southPanel.addButton(bExport);
southPanel.addButton(bPrint);
@ -195,8 +205,18 @@ public class WPayPrint extends PayPrint implements IFormController, EventListene
row.appendChild(fDocumentNo.getComponent());
row.appendChild(lNoPayments.rightAlign());
row.appendChild(fNoPayments);
row = rows.newRow();
row.appendChild(lDepositBatch.rightAlign()) ;
row.appendChild(fDepositBatch.getComponent()) ;
row.appendChild(lSumPayments.rightAlign()) ;
row.appendChild(fSumPayments.getComponent()) ;
southPanel.getButton(ConfirmPanel.A_OK).setVisible(false);
bExport.setDisabled(true);
bPrint.setDisabled(true);
fDepositBatch.setReadWrite(false);
fDocumentNo.setReadWrite(false);
} // VPayPrint
/**
@ -318,6 +338,9 @@ public class WPayPrint extends PayPrint implements IFormController, EventListene
if(noPayments != null)
fNoPayments.setText(noPayments);
if(sumPayments != null)
fSumPayments.setValue(sumPayments);
bProcess.setEnabled(PaymentRule.equals("T"));
@ -326,9 +349,45 @@ public class WPayPrint extends PayPrint implements IFormController, EventListene
if(msg != null && msg.length() > 0)
FDialog.error(m_WindowNo, form, msg);
getPluginFeatures();
} // loadPaymentRuleInfo
protected void getPluginFeatures()
{
if (m_C_PaySelection_ID!=0)
{
if (loadPaymentExportClass (null)>=0)
{
bExport.setDisabled(false);
fDepositBatch.setValue(m_PaymentExport.getDefaultDepositBatch());
if (m_PaymentExport.supportsDepositBatch() && m_PaymentExport.supportsSeparateBooking())
{
fDepositBatch.setReadWrite(true);
}
else
{
fDepositBatch.setReadWrite(false);
}
}
else
{
bExport.setDisabled(true);
}
if (printFormatId!=null && printFormatId!=0)
{
bPrint.setEnabled(true);
}
else
{
bPrint.setEnabled(false);
}
}
} // getPluginFeatures
/**************************************************************************
* Export payments to file
*/
@ -343,37 +402,28 @@ public class WPayPrint extends PayPrint implements IFormController, EventListene
try
{
// Get File Info
File tempFile = File.createTempFile("paymentExport", ".txt");
// Create File
int no = 0;
StringBuffer err = new StringBuffer("");
if (m_PaymentExportClass == null || m_PaymentExportClass.trim().length() == 0) {
m_PaymentExportClass = "org.compiere.util.GenericPaymentExport";
}
// Get Payment Export Class
PaymentExport custom = null;
try
File tempFile = null;
String filenameForDownload = "";
no = loadPaymentExportClass(err) ;
if (no >= 0)
{
Class<?> clazz = Class.forName(m_PaymentExportClass);
custom = (PaymentExport)clazz.newInstance();
no = custom.exportToFile(m_checks, tempFile, err);
}
catch (ClassNotFoundException e)
{
no = -1;
err.append("No custom PaymentExport class " + m_PaymentExportClass + " - " + e.toString());
log.log(Level.SEVERE, err.toString(), e);
}
catch (Exception e)
{
no = -1;
err.append("Error in " + m_PaymentExportClass + " check log, " + e.toString());
log.log(Level.SEVERE, err.toString(), e);
// Get File Info
tempFile = File.createTempFile(m_PaymentExport.getFilenamePrefix(), m_PaymentExport.getFilenameSuffix());
filenameForDownload = m_PaymentExport.getFilenamePrefix() + m_PaymentExport.getFilenameSuffix();
no = m_PaymentExport.exportToFile(m_checks,(Boolean) fDepositBatch.getValue(),PaymentRule, tempFile, err);
}
if (no >= 0) {
Filedownload.save(new FileInputStream(tempFile), "plain/text", "paymentExport.txt");
Filedownload.save(new FileInputStream(tempFile), m_PaymentExport.getContentType(), filenameForDownload);
FDialog.info(m_WindowNo, form, "Saved",
Msg.getMsg(Env.getCtx(), "NoOfLines") + "=" + no);
@ -384,7 +434,7 @@ public class WPayPrint extends PayPrint implements IFormController, EventListene
{
if (result)
{
MPaySelectionCheck.confirmPrint (m_checks, m_batch);
MPaySelectionCheck.confirmPrint (m_checks, m_batch, (Boolean) fDepositBatch.getValue());
// document No not updated
}

View File

@ -13,7 +13,8 @@
* *
* Contributors: *
* Carlos Ruiz - GlobalQSS: *
* FR 3132033 - Make payment export class configurable per bank *
* FR 3132033 - Make payment export class configurable per bank
* Markus Bozem: IDEMPIERE-1546 / IDEMPIERE-3286 *
*****************************************************************************/
package org.compiere.apps.form;
@ -24,8 +25,11 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import org.adempiere.base.IPaymentExporterFactory;
import org.adempiere.base.Service;
import org.compiere.model.MLookupFactory;
import org.compiere.model.MLookupInfo;
import org.compiere.model.MPaySelectionCheck;
@ -34,6 +38,7 @@ import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Language;
import org.compiere.util.PaymentExport;
import org.compiere.util.ValueNamePair;
public class PayPrint {
@ -57,6 +62,7 @@ public class PayPrint {
public String bank;
public String currency;
public BigDecimal balance;
protected PaymentExport m_PaymentExport;
/**
* PaySelect changed - load Bank
@ -157,7 +163,8 @@ public class PayPrint {
public String noPayments;
public Integer documentNo;
public Double sumPayments;
public Integer printFormatId;
/**
* PaymentRule changed - load DocumentNo, NoPayments,
@ -167,19 +174,23 @@ public class PayPrint {
{
String msg = null;
String sql = "SELECT COUNT(*) "
String sql = "SELECT COUNT(*),SUM(payamt) "
+ "FROM C_PaySelectionCheck "
+ "WHERE C_PaySelection_ID=?";
+ "WHERE C_PaySelection_ID=? AND PaymentRule=?";
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, C_PaySelection_ID);
pstmt.setString(2, PaymentRule);
rs = pstmt.executeQuery();
//
if (rs.next())
{
noPayments = String.valueOf(rs.getInt(1));
sumPayments = rs.getDouble(2);
}
}
catch (SQLException e)
{
@ -192,8 +203,11 @@ public class PayPrint {
pstmt = null;
}
printFormatId = null;
documentNo = null;
// DocumentNo
sql = "SELECT CurrentNext "
sql = "SELECT CurrentNext, Check_PrintFormat_ID "
+ "FROM C_BankAccountDoc "
+ "WHERE C_BankAccount_ID=? AND PaymentRule=? AND IsActive='Y'";
try
@ -204,7 +218,10 @@ public class PayPrint {
rs = pstmt.executeQuery();
//
if (rs.next())
{
documentNo = new Integer(rs.getInt(1));
printFormatId = new Integer(rs.getInt(2));
}
else
{
log.log(Level.SEVERE, "VPayPrint.loadPaymentRuleInfo - No active BankAccountDoc for C_BankAccount_ID="
@ -225,4 +242,50 @@ public class PayPrint {
return msg;
} // loadPaymentRuleInfo
protected int loadPaymentExportClass (StringBuffer err)
{
m_PaymentExport = null ;
if (m_PaymentExportClass == null || m_PaymentExportClass.trim().length() == 0) {
m_PaymentExportClass = "org.compiere.util.GenericPaymentExport";
}
try
{
List<IPaymentExporterFactory> factories = Service.locator().list(IPaymentExporterFactory.class).getServices();
if (factories != null && !factories.isEmpty()) {
for(IPaymentExporterFactory factory : factories) {
m_PaymentExport = factory.newPaymentExporterInstance(m_PaymentExportClass);
if (m_PaymentExport != null)
break;
}
}
if (m_PaymentExport == null)
{
Class<?> clazz = Class.forName (m_PaymentExportClass);
m_PaymentExport = (PaymentExport)clazz.newInstance();
}
}
catch (ClassNotFoundException e)
{
if (err!=null)
{
err.append("No custom PaymentExport class " + m_PaymentExportClass + " - " + e.toString());
log.log(Level.SEVERE, err.toString(), e);
}
return -1;
}
catch (Exception e)
{
if (err!=null)
{
err.append("Error in " + m_PaymentExportClass + " check log, " + e.toString());
log.log(Level.SEVERE, err.toString(), e);
}
return -1;
}
return 0 ;
} // loadPaymentExportClass
}