FR [3132033] - Make payment export class configurable per bank

https://sourceforge.net/tracker/?func=detail&aid=3132033&group_id=176962&atid=879335
This commit is contained in:
Carlos Ruiz 2011-03-25 20:54:47 -05:00
parent f3f4881409
commit 29c30b7df0
11 changed files with 448 additions and 227 deletions

View File

@ -0,0 +1,33 @@
-- Dec 7, 2010 11:24:40 PM COT
-- FR3132033-Make payment export class configurable per bank
INSERT INTO AD_Element (AD_Client_ID,AD_Element_ID,AD_Org_ID,ColumnName,Created,CreatedBy,EntityType,IsActive,Name,PrintName,Updated,UpdatedBy) VALUES (0,54389,0,'PaymentExportClass',TO_DATE('2010-12-07 23:24:39','YYYY-MM-DD HH24:MI:SS'),100,'D','Y','Payment Export Class','Payment Export Class',TO_DATE('2010-12-07 23:24:39','YYYY-MM-DD HH24:MI:SS'),100)
;
-- Dec 7, 2010 11:24:40 PM COT
INSERT INTO AD_Element_Trl (AD_Language,AD_Element_ID, Description,Help,Name,PO_Description,PO_Help,PO_Name,PO_PrintName,PrintName, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Element_ID, t.Description,t.Help,t.Name,t.PO_Description,t.PO_Help,t.PO_Name,t.PO_PrintName,t.PrintName, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Element t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Element_ID=54389 AND NOT EXISTS (SELECT * FROM AD_Element_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Element_ID=t.AD_Element_ID)
;
-- Dec 7, 2010 11:24:56 PM COT
UPDATE AD_Element_Trl SET IsTranslated='Y',Name='Clase Exporta Pagos',PrintName='Clase Exporta Pagos',Updated=TO_DATE('2010-12-07 23:24:56','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Element_ID=54389 AND AD_Language LIKE 'es_%'
;
-- Dec 7, 2010 11:27:52 PM COT
INSERT INTO AD_Column (AD_Client_ID,AD_Column_ID,AD_Element_ID,AD_Org_ID,AD_Reference_ID,AD_Table_ID,ColumnName,Created,CreatedBy,EntityType,FieldLength,IsActive,IsAllowLogging,IsAlwaysUpdateable,IsAutocomplete,IsEncrypted,IsIdentifier,IsKey,IsMandatory,IsParent,IsSelectionColumn,IsSyncDatabase,IsTranslated,IsUpdateable,Name,SeqNo,Updated,UpdatedBy,Version) VALUES (0,60133,54389,0,10,297,'PaymentExportClass',TO_DATE('2010-12-07 23:27:51','YYYY-MM-DD HH24:MI:SS'),100,'D',60,'Y','Y','N','N','N','N','N','N','N','N','N','N','Y','Payment Export Class',0,TO_DATE('2010-12-07 23:27:51','YYYY-MM-DD HH24:MI:SS'),100,0)
;
-- Dec 7, 2010 11:27:52 PM COT
INSERT INTO AD_Column_Trl (AD_Language,AD_Column_ID, Name, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Column_ID, t.Name, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Column t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Column_ID=60133 AND NOT EXISTS (SELECT * FROM AD_Column_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Column_ID=t.AD_Column_ID)
;
-- Dec 7, 2010 11:27:55 PM COT
ALTER TABLE C_BankAccount ADD PaymentExportClass NVARCHAR2(60) DEFAULT NULL
;
-- Dec 7, 2010 11:28:27 PM COT
INSERT INTO AD_Field (AD_Client_ID,AD_Column_ID,AD_Field_ID,AD_Org_ID,AD_Tab_ID,Created,CreatedBy,DisplayLength,EntityType,IsActive,IsCentrallyMaintained,IsDisplayed,IsEncrypted,IsFieldOnly,IsHeading,IsReadOnly,IsSameLine,Name,SeqNo,SortNo,Updated,UpdatedBy) VALUES (0,60133,60881,0,228,TO_DATE('2010-12-07 23:28:27','YYYY-MM-DD HH24:MI:SS'),100,60,'U','Y','Y','Y','N','N','N','N','N','Payment Export Class',140,0,TO_DATE('2010-12-07 23:28:27','YYYY-MM-DD HH24:MI:SS'),100)
;
-- Dec 7, 2010 11:28:27 PM COT
INSERT INTO AD_Field_Trl (AD_Language,AD_Field_ID, Description,Help,Name, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Field_ID, t.Description,t.Help,t.Name, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Field t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Field_ID=60881 AND NOT EXISTS (SELECT * FROM AD_Field_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Field_ID=t.AD_Field_ID)
;

View File

@ -0,0 +1,33 @@
-- Dec 7, 2010 11:24:40 PM COT
-- FR3132033-Make payment export class configurable per bank
INSERT INTO AD_Element (AD_Client_ID,AD_Element_ID,AD_Org_ID,ColumnName,Created,CreatedBy,EntityType,IsActive,Name,PrintName,Updated,UpdatedBy) VALUES (0,54389,0,'PaymentExportClass',TO_TIMESTAMP('2010-12-07 23:24:39','YYYY-MM-DD HH24:MI:SS'),100,'D','Y','Payment Export Class','Payment Export Class',TO_TIMESTAMP('2010-12-07 23:24:39','YYYY-MM-DD HH24:MI:SS'),100)
;
-- Dec 7, 2010 11:24:40 PM COT
INSERT INTO AD_Element_Trl (AD_Language,AD_Element_ID, Description,Help,Name,PO_Description,PO_Help,PO_Name,PO_PrintName,PrintName, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Element_ID, t.Description,t.Help,t.Name,t.PO_Description,t.PO_Help,t.PO_Name,t.PO_PrintName,t.PrintName, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Element t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Element_ID=54389 AND NOT EXISTS (SELECT * FROM AD_Element_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Element_ID=t.AD_Element_ID)
;
-- Dec 7, 2010 11:24:56 PM COT
UPDATE AD_Element_Trl SET IsTranslated='Y',Name='Clase Exporta Pagos',PrintName='Clase Exporta Pagos',Updated=TO_TIMESTAMP('2010-12-07 23:24:56','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Element_ID=54389 AND AD_Language LIKE 'es_%'
;
-- Dec 7, 2010 11:27:52 PM COT
INSERT INTO AD_Column (AD_Client_ID,AD_Column_ID,AD_Element_ID,AD_Org_ID,AD_Reference_ID,AD_Table_ID,ColumnName,Created,CreatedBy,EntityType,FieldLength,IsActive,IsAllowLogging,IsAlwaysUpdateable,IsAutocomplete,IsEncrypted,IsIdentifier,IsKey,IsMandatory,IsParent,IsSelectionColumn,IsSyncDatabase,IsTranslated,IsUpdateable,Name,SeqNo,Updated,UpdatedBy,Version) VALUES (0,60133,54389,0,10,297,'PaymentExportClass',TO_TIMESTAMP('2010-12-07 23:27:51','YYYY-MM-DD HH24:MI:SS'),100,'D',60,'Y','Y','N','N','N','N','N','N','N','N','N','N','Y','Payment Export Class',0,TO_TIMESTAMP('2010-12-07 23:27:51','YYYY-MM-DD HH24:MI:SS'),100,0)
;
-- Dec 7, 2010 11:27:52 PM COT
INSERT INTO AD_Column_Trl (AD_Language,AD_Column_ID, Name, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Column_ID, t.Name, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Column t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Column_ID=60133 AND NOT EXISTS (SELECT * FROM AD_Column_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Column_ID=t.AD_Column_ID)
;
-- Dec 7, 2010 11:27:55 PM COT
ALTER TABLE C_BankAccount ADD COLUMN PaymentExportClass VARCHAR(60) DEFAULT NULL
;
-- Dec 7, 2010 11:28:27 PM COT
INSERT INTO AD_Field (AD_Client_ID,AD_Column_ID,AD_Field_ID,AD_Org_ID,AD_Tab_ID,Created,CreatedBy,DisplayLength,EntityType,IsActive,IsCentrallyMaintained,IsDisplayed,IsEncrypted,IsFieldOnly,IsHeading,IsReadOnly,IsSameLine,Name,SeqNo,SortNo,Updated,UpdatedBy) VALUES (0,60133,60881,0,228,TO_TIMESTAMP('2010-12-07 23:28:27','YYYY-MM-DD HH24:MI:SS'),100,60,'U','Y','Y','Y','N','N','N','N','N','Payment Export Class',140,0,TO_TIMESTAMP('2010-12-07 23:28:27','YYYY-MM-DD HH24:MI:SS'),100)
;
-- Dec 7, 2010 11:28:27 PM COT
INSERT INTO AD_Field_Trl (AD_Language,AD_Field_ID, Description,Help,Name, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Field_ID, t.Description,t.Help,t.Name, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Field t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Field_ID=60881 AND NOT EXISTS (SELECT * FROM AD_Field_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Field_ID=t.AD_Field_ID)
;

View File

@ -31,7 +31,7 @@ public interface I_C_Bank
public static final String Table_Name = "C_Bank";
/** AD_Table_ID=296 */
public static final int Table_ID = MTable.getTable_ID(Table_Name);
public static final int Table_ID = 296;
KeyNamePair Model = new KeyNamePair(Table_ID, Table_Name);

View File

@ -16,8 +16,6 @@
*****************************************************************************/
package org.compiere.model;
import java.io.File;
import java.io.FileWriter;
import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@ -43,8 +41,7 @@ public final class MPaySelectionCheck extends X_C_PaySelectionCheck
/**
*
*/
private static final long serialVersionUID = 1059335268247781843L;
private static final long serialVersionUID = -5890511999934551763L;
/**
* Get Check for Payment
@ -246,184 +243,6 @@ public final class MPaySelectionCheck extends X_C_PaySelectionCheck
} // get
/**************************************************************************
* Export to File
* @param checks array of checks
* @param file file to export checks
* @return number of lines
*/
public static int exportToFile (MPaySelectionCheck[] checks, File file)
{
if (checks == null || checks.length == 0)
return 0;
// Must be a file
if (file.isDirectory())
{
s_log.log(Level.WARNING, "File is directory - " + file.getAbsolutePath());
return 0;
}
// delete if exists
try
{
if (file.exists())
file.delete();
}
catch (Exception e)
{
s_log.log(Level.WARNING, "Could not delete - " + file.getAbsolutePath(), e);
}
char x = '"'; // ease
int noLines = 0;
StringBuffer line = null;
try
{
FileWriter fw = new FileWriter(file);
// write header
line = new StringBuffer();
line.append(x).append("Value").append(x).append(",")
.append(x).append("Name").append(x).append(",")
.append(x).append("Contact").append(x).append(",")
.append(x).append("Addr1").append(x).append(",")
.append(x).append("Addr2").append(x).append(",")
.append(x).append("City").append(x).append(",")
.append(x).append("State").append(x).append(",")
.append(x).append("ZIP").append(x).append(",")
.append(x).append("Country").append(x).append(",")
.append(x).append("ReferenceNo").append(x).append(",")
.append(x).append("DocumentNo").append(x).append(",")
.append(x).append("PayDate").append(x).append(",")
.append(x).append("Currency").append(x).append(",")
.append(x).append("PayAmount").append(x).append(",")
.append(x).append("Comment").append(x)
.append(Env.NL);
fw.write(line.toString());
noLines++;
// write lines
for (int i = 0; i < checks.length; i++)
{
MPaySelectionCheck mpp = checks[i];
if (mpp == null)
continue;
// BPartner Info
String bp[] = getBPartnerInfo(mpp.getC_BPartner_ID());
// Comment - list of invoice document no
StringBuffer comment = new StringBuffer();
MPaySelectionLine[] psls = mpp.getPaySelectionLines(false);
for (int l = 0; l < psls.length; l++)
{
if (l > 0)
comment.append(", ");
comment.append(psls[l].getInvoice().getDocumentNo());
}
line = new StringBuffer();
line.append(x).append(bp[BP_VALUE]).append(x).append(",") // Value
.append(x).append(bp[BP_NAME]).append(x).append(",") // Name
.append(x).append(bp[BP_CONTACT]).append(x).append(",") // Contact
.append(x).append(bp[BP_ADDR1]).append(x).append(",") // Addr1
.append(x).append(bp[BP_ADDR2]).append(x).append(",") // Addr2
.append(x).append(bp[BP_CITY]).append(x).append(",") // City
.append(x).append(bp[BP_REGION]).append(x).append(",") // State
.append(x).append(bp[BP_POSTAL]).append(x).append(",") // ZIP
.append(x).append(bp[BP_COUNTRY]).append(x).append(",") // Country
.append(x).append(bp[BP_REFNO]).append(x).append(",") // ReferenceNo
// Payment Info
.append(x).append(mpp.getDocumentNo()).append(x).append(",") // DocumentNo
.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(comment.toString()).append(x) // Comment
.append(Env.NL);
fw.write(line.toString());
noLines++;
} // write line
fw.flush();
fw.close();
}
catch (Exception e)
{
s_log.log(Level.SEVERE, "", e);
}
return noLines;
} // exportToFile
/**
* Get Customer/Vendor Info.
* Based on BP_ static variables
* @param C_BPartner_ID BPartner
* @return info array
*/
private static String[] getBPartnerInfo (int C_BPartner_ID)
{
String[] bp = new String[10];
String sql = "SELECT bp.Value, bp.Name, c.Name AS Contact, "
+ "a.Address1, a.Address2, a.City, r.Name AS Region, a.Postal, "
+ "cc.Name AS Country, bp.ReferenceNo "
+ "FROM C_BPartner bp, AD_User c, C_BPartner_Location l, C_Location a, C_Region r, C_Country cc "
+ "WHERE bp.C_BPartner_ID=?" // #1
+ " AND bp.C_BPartner_ID=c.C_BPartner_ID(+)"
+ " AND bp.C_BPartner_ID=l.C_BPartner_ID"
+ " AND l.C_Location_ID=a.C_Location_ID"
+ " AND a.C_Region_ID=r.C_Region_ID(+)"
+ " AND a.C_Country_ID=cc.C_Country_ID "
+ "ORDER BY l.IsBillTo DESC";
try
{
PreparedStatement pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, C_BPartner_ID);
ResultSet rs = pstmt.executeQuery();
//
if (rs.next())
{
bp[BP_VALUE] = rs.getString(1);
if (bp[BP_VALUE] == null)
bp[BP_VALUE] = "";
bp[BP_NAME] = rs.getString(2);
if (bp[BP_NAME] == null)
bp[BP_NAME] = "";
bp[BP_CONTACT] = rs.getString(3);
if (bp[BP_CONTACT] == null)
bp[BP_CONTACT] = "";
bp[BP_ADDR1] = rs.getString(4);
if (bp[BP_ADDR1] == null)
bp[BP_ADDR1] = "";
bp[BP_ADDR2] = rs.getString(5);
if (bp[BP_ADDR2] == null)
bp[BP_ADDR2] = "";
bp[BP_CITY] = rs.getString(6);
if (bp[BP_CITY] == null)
bp[BP_CITY] = "";
bp[BP_REGION] = rs.getString(7);
if (bp[BP_REGION] == null)
bp[BP_REGION] = "";
bp[BP_POSTAL] = rs.getString(8);
if (bp[BP_POSTAL] == null)
bp[BP_POSTAL] = "";
bp[BP_COUNTRY] = rs.getString(9);
if (bp[BP_COUNTRY] == null)
bp[BP_COUNTRY] = "";
bp[BP_REFNO] = rs.getString(10);
if (bp[BP_REFNO] == null)
bp[BP_REFNO] = "";
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
s_log.log(Level.SEVERE, sql, e);
}
return bp;
} // getBPartnerInfo
/**************************************************************************
* Confirm Print.
* Create Payments the first time
@ -538,28 +357,6 @@ public final class MPaySelectionCheck extends X_C_PaySelectionCheck
/** Logger */
static private CLogger s_log = CLogger.getCLogger (MPaySelectionCheck.class);
/** BPartner Info Index for Value */
private static final int BP_VALUE = 0;
/** BPartner Info Index for Name */
private static final int BP_NAME = 1;
/** BPartner Info Index for Contact Name */
private static final int BP_CONTACT = 2;
/** BPartner Info Index for Address 1 */
private static final int BP_ADDR1 = 3;
/** BPartner Info Index for Address 2 */
private static final int BP_ADDR2 = 4;
/** BPartner Info Index for City */
private static final int BP_CITY = 5;
/** BPartner Info Index for Region */
private static final int BP_REGION = 6;
/** BPartner Info Index for Postal Code */
private static final int BP_POSTAL = 7;
/** BPartner Info Index for Country */
private static final int BP_COUNTRY = 8;
/** BPartner Info Index for Reference No */
private static final int BP_REFNO = 9;
/**************************************************************************
* Constructor
* @param ctx context

View File

@ -271,6 +271,7 @@ public final class MPayment extends X_C_Payment
MBPBankAccount ba = new MBPBankAccount (preparedPayment.getCtx(), C_BP_BankAccount_ID, null);
setRoutingNo(ba.getRoutingNo());
setAccountNo(ba.getAccountNo());
setDescription(preparedPayment.getC_PaySelection().getName());
setIsReceipt (X_C_Order.PAYMENTRULE_DirectDebit.equals // AR only
(preparedPayment.getPaymentRule()));
if ( MPaySelectionCheck.PAYMENTRULE_DirectDebit.equals(preparedPayment.getPaymentRule()) )
@ -1014,7 +1015,8 @@ public final class MPayment extends X_C_Payment
*/
public void setRoutingNo(String RoutingNo)
{
super.setRoutingNo (MPaymentValidate.checkNumeric(RoutingNo));
// super.setRoutingNo (MPaymentValidate.checkNumeric(RoutingNo));
super.setRoutingNo (RoutingNo);
} // setBankRoutingNo

View File

@ -30,7 +30,7 @@ public class X_C_Bank extends PO implements I_C_Bank, I_Persistent
/**
*
*/
private static final long serialVersionUID = 20100614L;
private static final long serialVersionUID = 20110325L;
/** Standard Constructor */
public X_C_Bank (Properties ctx, int C_Bank_ID, String trxName)

View File

@ -0,0 +1,247 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* 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. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.util;
import java.io.File;
import java.io.FileWriter;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import org.compiere.model.MCurrency;
import org.compiere.model.MPaySelectionCheck;
import org.compiere.model.MPaySelectionLine;
/**
* Generic Payment Export
* Sample implementation of Payment Export Interface - brought here from MPaySelectionCheck
*
* @author Jorg Janke
*
* Contributors:
* Carlos Ruiz - GlobalQSS - FR 3132033 - Make payment export class configurable per bank
*/
public class GenericPaymentExport implements PaymentExport
{
/** Logger */
static private CLogger s_log = CLogger.getCLogger (GenericPaymentExport.class);
/** BPartner Info Index for Value */
private static final int BP_VALUE = 0;
/** BPartner Info Index for Name */
private static final int BP_NAME = 1;
/** BPartner Info Index for Contact Name */
private static final int BP_CONTACT = 2;
/** BPartner Info Index for Address 1 */
private static final int BP_ADDR1 = 3;
/** BPartner Info Index for Address 2 */
private static final int BP_ADDR2 = 4;
/** BPartner Info Index for City */
private static final int BP_CITY = 5;
/** BPartner Info Index for Region */
private static final int BP_REGION = 6;
/** BPartner Info Index for Postal Code */
private static final int BP_POSTAL = 7;
/** BPartner Info Index for Country */
private static final int BP_COUNTRY = 8;
/** BPartner Info Index for Reference No */
private static final int BP_REFNO = 9;
/**************************************************************************
* Export to File
* @param checks array of checks
* @param file file to export checks
* @return number of lines
*/
public int exportToFile (MPaySelectionCheck[] checks, File file, StringBuffer err)
{
if (checks == null || checks.length == 0)
return 0;
// Must be a file
if (file.isDirectory())
{
err.append("No se puede escribir, el archivo seleccionado es un directorio - " + file.getAbsolutePath());
s_log.log(Level.SEVERE, err.toString());
return -1;
}
// delete if exists
try
{
if (file.exists())
file.delete();
}
catch (Exception e)
{
s_log.log(Level.WARNING, "Could not delete - " + file.getAbsolutePath(), e);
}
char x = '"'; // ease
int noLines = 0;
StringBuffer line = null;
try
{
FileWriter fw = new FileWriter(file);
// write header
line = new StringBuffer();
line.append(x).append("Value").append(x).append(",")
.append(x).append("Name").append(x).append(",")
.append(x).append("Contact").append(x).append(",")
.append(x).append("Addr1").append(x).append(",")
.append(x).append("Addr2").append(x).append(",")
.append(x).append("City").append(x).append(",")
.append(x).append("State").append(x).append(",")
.append(x).append("ZIP").append(x).append(",")
.append(x).append("Country").append(x).append(",")
.append(x).append("ReferenceNo").append(x).append(",")
.append(x).append("DocumentNo").append(x).append(",")
.append(x).append("PayDate").append(x).append(",")
.append(x).append("Currency").append(x).append(",")
.append(x).append("PayAmount").append(x).append(",")
.append(x).append("Comment").append(x)
.append(Env.NL);
fw.write(line.toString());
noLines++;
// write lines
for (int i = 0; i < checks.length; i++)
{
MPaySelectionCheck mpp = checks[i];
if (mpp == null)
continue;
// BPartner Info
String bp[] = getBPartnerInfo(mpp.getC_BPartner_ID());
// Comment - list of invoice document no
StringBuffer comment = new StringBuffer();
MPaySelectionLine[] psls = mpp.getPaySelectionLines(false);
for (int l = 0; l < psls.length; l++)
{
if (l > 0)
comment.append(", ");
comment.append(psls[l].getInvoice().getDocumentNo());
}
line = new StringBuffer();
line.append(x).append(bp[BP_VALUE]).append(x).append(",") // Value
.append(x).append(bp[BP_NAME]).append(x).append(",") // Name
.append(x).append(bp[BP_CONTACT]).append(x).append(",") // Contact
.append(x).append(bp[BP_ADDR1]).append(x).append(",") // Addr1
.append(x).append(bp[BP_ADDR2]).append(x).append(",") // Addr2
.append(x).append(bp[BP_CITY]).append(x).append(",") // City
.append(x).append(bp[BP_REGION]).append(x).append(",") // State
.append(x).append(bp[BP_POSTAL]).append(x).append(",") // ZIP
.append(x).append(bp[BP_COUNTRY]).append(x).append(",") // Country
.append(x).append(bp[BP_REFNO]).append(x).append(",") // ReferenceNo
// Payment Info
.append(x).append(mpp.getDocumentNo()).append(x).append(",") // DocumentNo
.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(comment.toString()).append(x) // Comment
.append(Env.NL);
fw.write(line.toString());
noLines++;
} // write line
fw.flush();
fw.close();
}
catch (Exception e)
{
err.append(e.toString());
s_log.log(Level.SEVERE, "", e);
return -1;
}
return noLines;
} // exportToFile
/**
* Get Customer/Vendor Info.
* Based on BP_ static variables
* @param C_BPartner_ID BPartner
* @return info array
*/
private static String[] getBPartnerInfo (int C_BPartner_ID)
{
String[] bp = new String[10];
String sql = "SELECT bp.Value, bp.Name, c.Name AS Contact, "
+ "a.Address1, a.Address2, a.City, r.Name AS Region, a.Postal, "
+ "cc.Name AS Country, bp.ReferenceNo "
+ "FROM C_BPartner bp, AD_User c, C_BPartner_Location l, C_Location a, C_Region r, C_Country cc "
+ "WHERE bp.C_BPartner_ID=?" // #1
+ " AND bp.C_BPartner_ID=c.C_BPartner_ID(+)"
+ " AND bp.C_BPartner_ID=l.C_BPartner_ID"
+ " AND l.C_Location_ID=a.C_Location_ID"
+ " AND a.C_Region_ID=r.C_Region_ID(+)"
+ " AND a.C_Country_ID=cc.C_Country_ID "
+ "ORDER BY l.IsBillTo DESC";
try
{
PreparedStatement pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, C_BPartner_ID);
ResultSet rs = pstmt.executeQuery();
//
if (rs.next())
{
bp[BP_VALUE] = rs.getString(1);
if (bp[BP_VALUE] == null)
bp[BP_VALUE] = "";
bp[BP_NAME] = rs.getString(2);
if (bp[BP_NAME] == null)
bp[BP_NAME] = "";
bp[BP_CONTACT] = rs.getString(3);
if (bp[BP_CONTACT] == null)
bp[BP_CONTACT] = "";
bp[BP_ADDR1] = rs.getString(4);
if (bp[BP_ADDR1] == null)
bp[BP_ADDR1] = "";
bp[BP_ADDR2] = rs.getString(5);
if (bp[BP_ADDR2] == null)
bp[BP_ADDR2] = "";
bp[BP_CITY] = rs.getString(6);
if (bp[BP_CITY] == null)
bp[BP_CITY] = "";
bp[BP_REGION] = rs.getString(7);
if (bp[BP_REGION] == null)
bp[BP_REGION] = "";
bp[BP_POSTAL] = rs.getString(8);
if (bp[BP_POSTAL] == null)
bp[BP_POSTAL] = "";
bp[BP_COUNTRY] = rs.getString(9);
if (bp[BP_COUNTRY] == null)
bp[BP_COUNTRY] = "";
bp[BP_REFNO] = rs.getString(10);
if (bp[BP_REFNO] == null)
bp[BP_REFNO] = "";
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
s_log.log(Level.SEVERE, sql, e);
}
return bp;
} // getBPartnerInfo
} // PaymentExport

View File

@ -0,0 +1,40 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* 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. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.util;
import java.io.File;
import org.compiere.model.MPaySelectionCheck;
/**
* Custom Payment Export Interface
*
* @author Carlos Ruiz - GlobalQSS
* @version PaymentExport.java
*/
public interface PaymentExport
{
/**************************************************************************
* Export to File
* @param checks array of checks
* @param file file to export checks
* @return number of lines
*/
public int exportToFile (MPaySelectionCheck[] checks, File file, StringBuffer err);
} // PaymentExport

View File

@ -48,6 +48,7 @@ import org.compiere.util.Env;
import org.compiere.util.Ini;
import org.compiere.util.KeyNamePair;
import org.compiere.util.Msg;
import org.compiere.util.PaymentExport;
import org.compiere.util.ValueNamePair;
/**
@ -55,6 +56,9 @@ import org.compiere.util.ValueNamePair;
*
* @author Jorg Janke
* @version $Id: VPayPrint.java,v 1.2 2006/07/30 00:51:28 jjanke Exp $
*
* Contributors:
* Carlos Ruiz - GlobalQSS - FR 3132033 - Make payment export class configurable per bank
*/
public class VPayPrint extends PayPrint implements FormPanel, ActionListener
{
@ -345,16 +349,44 @@ public class VPayPrint extends PayPrint implements FormPanel, ActionListener
return;
// Create File
int no = MPaySelectionCheck.exportToFile(m_checks, fc.getSelectedFile());
ADialog.info(m_WindowNo, panel, "Saved",
fc.getSelectedFile().getAbsolutePath() + "\n"
+ Msg.getMsg(Env.getCtx(), "NoOfLines") + "=" + no);
if (ADialog.ask(m_WindowNo, panel, "VPayPrintSuccess?"))
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
{
// int lastDocumentNo =
MPaySelectionCheck.confirmPrint (m_checks, m_batch);
// document No not updated
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);
}
if (no >= 0) {
ADialog.info(m_WindowNo, panel, "Saved",
fc.getSelectedFile().getAbsolutePath() + "\n"
+ Msg.getMsg(Env.getCtx(), "NoOfLines") + "=" + no);
if (ADialog.ask(m_WindowNo, panel, "VPayPrintSuccess?"))
{
// int lastDocumentNo =
MPaySelectionCheck.confirmPrint (m_checks, m_batch);
// document No not updated
}
} else {
ADialog.error(m_WindowNo, panel, "Error", err.toString());
}
dispose();
} // cmd_export

View File

@ -49,6 +49,7 @@ import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.KeyNamePair;
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;
@ -62,14 +63,12 @@ import org.zkoss.zul.Filedownload;
*
* @author Jorg Janke
* @version $Id: VPayPrint.java,v 1.2 2006/07/30 00:51:28 jjanke Exp $
*/
*
* Contributors:
* Carlos Ruiz - GlobalQSS - FR 3132033 - Make payment export class configurable per bank
*/
public class WPayPrint extends PayPrint implements IFormController, EventListener
{
/**
*
*/
private static final long serialVersionUID = -3005095685182033400L;
private CustomForm form = new CustomForm();
/**
@ -344,15 +343,45 @@ public class WPayPrint extends PayPrint implements IFormController, EventListene
File tempFile = File.createTempFile("paymentExport", ".txt");
// Create File
MPaySelectionCheck.exportToFile(m_checks, tempFile);
Filedownload.save(new FileInputStream(tempFile), "plain/text", "paymentExport.txt");
if (FDialog.ask(m_WindowNo, form, "VPayPrintSuccess?"))
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
{
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);
}
if (no >= 0) {
Filedownload.save(new FileInputStream(tempFile), "plain/text", "paymentExport.txt");
FDialog.info(m_WindowNo, form, "Saved",
Msg.getMsg(Env.getCtx(), "NoOfLines") + "=" + no);
if (FDialog.ask(m_WindowNo, form, "VPayPrintSuccess?"))
{
// int lastDocumentNo =
MPaySelectionCheck.confirmPrint (m_checks, m_batch);
// document No not updated
}
} else {
FDialog.error(m_WindowNo, form, "Error", err.toString());
}
dispose();
}
catch (Exception e)

View File

@ -10,6 +10,10 @@
* 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. *
* *
* Contributors: *
* Carlos Ruiz - GlobalQSS: *
* FR 3132033 - Make payment export class configurable per bank *
*****************************************************************************/
package org.compiere.apps.form;
@ -37,6 +41,8 @@ public class PayPrint {
public int m_WindowNo = 0;
/** Used Bank Account */
public int m_C_BankAccount_ID = -1;
/** Export Class for Bank Account */
public String m_PaymentExportClass = null;
/** Payment Information */
public MPaySelectionCheck[] m_checks = null;
@ -90,7 +96,7 @@ public class PayPrint {
// load Banks from PaySelectLine
m_C_BankAccount_ID = -1;
String sql = "SELECT ps.C_BankAccount_ID, b.Name || ' ' || ba.AccountNo," // 1..2
+ " c.ISO_Code, CurrentBalance " // 3..4
+ " c.ISO_Code, CurrentBalance, ba.PaymentExportClass " // 3..5
+ "FROM C_PaySelection ps"
+ " INNER JOIN C_BankAccount ba ON (ps.C_BankAccount_ID=ba.C_BankAccount_ID)"
+ " INNER JOIN C_Bank b ON (ba.C_Bank_ID=b.C_Bank_ID)"
@ -107,6 +113,7 @@ public class PayPrint {
bank = rs.getString(2);
currency = rs.getString(3);
balance = rs.getBigDecimal(4);
m_PaymentExportClass = rs.getString(5);
}
else
{
@ -114,6 +121,7 @@ public class PayPrint {
bank = "";
currency = "";
balance = Env.ZERO;
m_PaymentExportClass = null;
log.log(Level.SEVERE, "No active BankAccount for C_PaySelection_ID=" + C_PaySelection_ID);
}
rs.close();