Author: dcosse Date: 2014-08-01 16:20:36 +0200 (Fri, 01 Aug 2014) New Revision: 3888 Url: http://forge.chorem.org/projects/lima/repository/revisions/3888 Log: refs #1032 nouvelle impl?\195?\169mentation des imports export EBP Added: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ebp/AccountEBPModel.java Removed: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ExportService.java trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ExportServiceLocal.java trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ImportService.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java trunk/lima-business/src/test/java/org/chorem/lima/business/ImportServiceImplTest.java Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/NewExportService.java trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/NewImportService.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewExportServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewImportServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/AbstractLimaModel.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ebp/EntryEBPModel.java trunk/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java trunk/lima-business/src/test/java/org/chorem/lima/business/NewImportExportServiceTest.java trunk/lima-business/src/test/java/org/chorem/lima/business/accountingrules/ImportServiceRuleFrTest.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/AccountComboBoxModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/EntryBookComboBoxModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/FinancialPeriodComboBoxModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/FiscalPeriodComboBoxModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/LeafAccountComboBoxModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/AccountsPane.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/EntryBooksPane.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/FinancialTransactionsPane.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/FiscalYearsPane.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartViewHandler.java Deleted: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.java 2014-07-31 19:50:37 UTC (rev 3887) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.java 2014-08-01 14:20:36 UTC (rev 3888) @@ -1,702 +0,0 @@ -/* - * #%L - * Lima business - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2008 - 2012 CodeLutin, Chatellier Eric - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * 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, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.lima.business.ejb; - -import au.com.bytecode.opencsv.CSVWriter; -import org.apache.commons.lang3.StringUtils; -import org.chorem.lima.FinancialStatementWayEnum; -import org.chorem.lima.LimaTechnicalException; -import org.chorem.lima.business.LimaException; -import org.chorem.lima.business.api.EntryBookService; -import org.chorem.lima.business.api.ExportService; -import org.chorem.lima.business.api.ExportServiceLocal; -import org.chorem.lima.business.utils.ImportExportEntityEnum; -import org.chorem.lima.entity.Account; -import org.chorem.lima.entity.AccountTopiaDao; -import org.chorem.lima.entity.ClosedPeriodicEntryBook; -import org.chorem.lima.entity.ClosedPeriodicEntryBookTopiaDao; -import org.chorem.lima.entity.Entry; -import org.chorem.lima.entity.EntryBook; -import org.chorem.lima.entity.EntryBookTopiaDao; -import org.chorem.lima.entity.FinancialStatement; -import org.chorem.lima.entity.FinancialStatementTopiaDao; -import org.chorem.lima.entity.FinancialTransaction; -import org.chorem.lima.entity.FinancialTransactionTopiaDao; -import org.chorem.lima.entity.FiscalPeriod; -import org.chorem.lima.entity.FiscalPeriodTopiaDao; -import org.chorem.lima.entity.Identity; -import org.chorem.lima.entity.IdentityTopiaDao; -import org.chorem.lima.entity.VatStatement; -import org.chorem.lima.entity.VatStatementTopiaDao; - -import javax.ejb.EJB; -import javax.ejb.Local; -import javax.ejb.Remote; -import javax.ejb.Stateless; -import javax.ejb.TransactionAttribute; -import java.io.IOException; -import java.io.StringWriter; -import java.text.SimpleDateFormat; -import java.util.List; - -/** - * CSV import export service. - * - * @version $Revision$ - * <p/> - * Last update : $Date$ - * By : $Author$ - */ -@Stateless -@Remote(ExportService.class) -@Local(ExportServiceLocal.class) -@TransactionAttribute -public class ExportServiceImpl extends AbstractLimaService implements ExportService, ExportServiceLocal { - - private static final SimpleDateFormat SDATEFORMAT = - new SimpleDateFormat("dd,MM,yyyy HH:mm:ss"); - - protected final String DATE_PATTERN = "dd/MM/yyyy"; - - @EJB - private EntryBookService entryBookService; - - //############## EXPORT EBP - - /** - * Export entries to EBP - * Structure example : DatEcr,Journal,Compte,Libelle,Piece,Debit,Credit,Lettre - * 01/01/2013,AN,101,Capital,1,0,100000.00,C - */ - @Override - public String exportEntriesAsEBP() { - SimpleDateFormat epbDateFormat = new SimpleDateFormat(DATE_PATTERN); - StringWriter out = new StringWriter(); - CSVWriter csvWriter = null; - - try { - csvWriter = new CSVWriter(out, - CSVWriter.DEFAULT_SEPARATOR, - CSVWriter.NO_QUOTE_CHARACTER); - - //export entries - FinancialTransactionTopiaDao financialTransactionTopiaDao = - getDaoHelper().getFinancialTransactionDao(); - List<FinancialTransaction> listFinancialTransaction = - financialTransactionTopiaDao.findAll(); - - String[] nextLine = new String[8]; - - // Add the header line - if (!listFinancialTransaction.isEmpty()) { - nextLine[0] = "DatEcr"; - nextLine[1] = "Journal"; - nextLine[2] = "Compte"; - nextLine[3] = "Libelle"; - nextLine[4] = "Piece"; - nextLine[5] = "Debit"; - nextLine[6] = "Credit"; - nextLine[7] = "Lettre"; - // Ajoute la ligne au fichier - csvWriter.writeNext(nextLine); - } - - String date, debitcredit, debit, credit, entrybookCode, accountNumber; - EntryBook entryBook; - Account account; - - // For all financialTransaction - for (FinancialTransaction financialTransaction : listFinancialTransaction) { - date = epbDateFormat.format(financialTransaction.getTransactionDate()); - - entryBook = financialTransaction.getEntryBook(); - - entrybookCode = entryBook == null ? "" : entryBook.getCode(); - - for (Entry entry : financialTransaction.getEntry()) { - account = entry.getAccount(); - - if (account != null) { - accountNumber = entry.getAccount().getAccountNumber(); - } else { - accountNumber = ""; - } - - debit = "0"; - credit = "0"; - if (entry.isDebit()) { - debitcredit = "D"; - debit = entry.getAmount().toString(); - } else { - debitcredit = "C"; - credit = entry.getAmount().toString(); - } - - nextLine[0] = date; - nextLine[1] = entrybookCode; - nextLine[2] = accountNumber; - nextLine[3] = StringUtils.remove(entry.getDescription(), ","); - nextLine[4] = entry.getVoucher(); - nextLine[5] = debit; - nextLine[6] = credit; - nextLine[7] = debitcredit; - - // Ajoute la ligne au fichier - csvWriter.writeNext(nextLine); - } - } - // Write cache in string - csvWriter.flush(); - } catch (IOException e) { - throw new LimaTechnicalException(e); - } finally { - if (csvWriter != null) { - try { - csvWriter.close(); - out.close(); - } catch (IOException e) { - // nothing to do - } - } - } - return out.getBuffer().toString(); - } - - /** - * Export accounts chart to EBP - * Structure ebp - example : - * 411DUPOND,DUPOND,,21 rue du bois, 78120, Rambouillet, France,,0135698475,0135698475 - */ - @Override - public String exportAccountsAsEBP() { - StringWriter out = new StringWriter(); - CSVWriter csvWriter = null; - - try { - csvWriter = new CSVWriter(out, - CSVWriter.DEFAULT_SEPARATOR, - CSVWriter.NO_QUOTE_CHARACTER); - //export accounts - //Numero,Intitule,Type,bLetManuel,bLetAuto,bLetAppro,bCentPhysique,bCentJournal,bCentGLivre,bGeleDebit,bGeleCredit,bNoEchAna,TypeRel,Categorie,CodeTVA,TypeTVA,Lettrage,Encours,Seuil,Remise,Escompte,Devise,RIB0NomBanque,RIB0AdrBanque,RIB0Agence,RIB0Guichet,RIB0Compte,RIB0CleRIB,RIB1NomBanque,RIB1AdrBanque,RIB1Agence,RIB1Guichet,RIB1Compte,RIB1CleRIB,RIB2NomBanque,RIB2AdrBanque,RIB2Agence,RIB2Guichet,RIB2Compte,RIB2CleRIB,AdresseCivilite,AdresseRaiSoc,AdresseAdresse,AdresseCodePostal,AdresseVille,AdressePays,NII,Contact0Interloc,Contact0Fonction,Contact0TelNumTel,Contact0TelNumFax,Contact0Infos,Contact1Interloc,Contact1Fonction,Contact1TelNumTel,Contact1TelNumFax,Contact1Infos,Contact2Interloc,Contact2Fonction,Contact2TelNumTel,Contact2TelNumFax,Contact2Infos,Contact3Interloc,Contact3Fonction,Contact3TelNumTel,Contact3TelNumFax,Contact3Infos,Contact4Interloc,Contact4Fonction,Contact4TelNumTel,Contact4TelNumFax,Contact4Infos,CodeRegle,NbJours,TypeJours,Limite,Grille1,Grille2,Grille3,SectGeo,SectAct,ObjCA,TailleCA,NbEmpl,Commercial,JoursMois,CptTva,CptCharge,bDecouvertAutorise,MntDecouvertAutorise,EMailTiers,WebSiteTiers,NatAchat,NatVente,NatDepense,NatRecette,NumCptBqCH,NumClearing,NumIBAN,LetPart,TypeAchatTVA,IBAN0Pays,IBAN0Controle,IBAN0Contenu,IBAN1Pays,IBAN1Controle,IBAN1Contenu,IBAN2Pays,IBAN2Controle,IBAN2Contenu,BIC0Banque,BIC0Pays,BIC0Localisation,BIC0Branche,BIC1Banque,BIC1Pays,BIC1Localisation,BIC1Branche,BIC2Banque,BIC2Pays,BIC2Localisation,BIC2Branche,LibBIC0,LibBIC1,LibBIC2 - - String[] nextLine = new String[2]; - // Add the header line - nextLine[0] = "Numero"; - nextLine[1] = "Intitule"; - csvWriter.writeNext(nextLine); - - // Récupère tous les comptes - AccountTopiaDao accountTopiaDao = getDaoHelper().getAccountDao(); - List<Account> listAccount = accountTopiaDao.findAll(); - // Pour tous les comptes - for (Account account : listAccount) { - nextLine[0] = account.getAccountNumber(); - nextLine[1] = StringUtils.remove(account.getLabel(), ","); - // Ajoute la ligne au fichier - csvWriter.writeNext(nextLine); - } - // Write cache in string - csvWriter.flush(); - csvWriter.close(); - } catch (IOException e) { - throw new LimaTechnicalException(e); - } finally { - if (csvWriter != null) { - try { - csvWriter.close(); - out.close(); - } catch (IOException e) { - // nothing to do - } - } - } - return out.getBuffer().toString(); - } - - @Override - public String exportEntryBooksAsEBP() { - StringWriter out = new StringWriter(); - CSVWriter csvWriter = null; - - try { - csvWriter = new CSVWriter(out, - CSVWriter.DEFAULT_SEPARATOR, - CSVWriter.NO_QUOTE_CHARACTER); - - //entryBooks to export - List<EntryBook> entryBooks = entryBookService.getAllEntryBooks(); - - //Code,Type,Libelle,TypePiece,NextPiece,CpteType,CpteCompte,Contact,RIBNomBanque,RIBAdrBanque,RIBAgence,RIBGuichet,RIBCompte,RIBCleRIB,Lcr,Preleve,MemoDateCreat,MemoDateModif,Devise,CompteTP,NumCptBqCH,NumClearing,bSaisieKM - String[] nextLine = new String[2]; - // Add the header line - nextLine[0] = "Code"; - nextLine[1] = "Libelle"; - // Ajoute la ligne au fichier - csvWriter.writeNext(nextLine); - - if (entryBooks != null && !entryBooks.isEmpty()) { - for (EntryBook entryBook:entryBooks) { - nextLine[0] = entryBook.getCode(); - nextLine[1] = StringUtils.remove(entryBook.getLabel(), ","); - // Ajoute la ligne au fichier - csvWriter.writeNext(nextLine); - } - } - - // Write cache in string - csvWriter.flush(); - - } catch (IOException e) { - throw new LimaTechnicalException(e); - } finally { - if (csvWriter != null) { - try { - csvWriter.close(); - out.close(); - } catch (IOException e) { - // nothing to do - } - } - } - return out.getBuffer().toString(); - } - - - //############## EXPORT CSV - - /** Export integrality of database in CSV */ - @Override - public String exportAsCSV() { - StringWriter out = new StringWriter(); - CSVWriter csvWriter = null; - - try { - csvWriter = new CSVWriter(out, ';'); - exportAccountsChartAsCSV(csvWriter); - exportEntryBookChartAsCSV(csvWriter); - exportFinancialStatementChartAsCSV(csvWriter); - exportFiscalPeriodAsCSV(csvWriter); - exportClosedPeriodicEntryBooksAsCSV(csvWriter); - exportFinancialTransactionsAndEntriesAsCSV(csvWriter); - exportIdentityAsCSV(csvWriter); - // Write cache in string - csvWriter.flush(); - } catch (IOException e) { - throw new LimaTechnicalException(e); - } finally { - if (csvWriter != null) { - try { - csvWriter.close(); - out.close(); - } catch (IOException e) { - // nothing to do - } - } - } - return out.getBuffer().toString(); - } - - - /** Remote methode call from UI. */ - @Override - public String exportFinancialStatementChartAsCSV() { - - StringWriter out = new StringWriter(); - CSVWriter csvWriter = null; - - try { - csvWriter = new CSVWriter(out, ';'); - exportFinancialStatementChartAsCSV(csvWriter); - // Write cache in file - csvWriter.flush(); - - } catch (IOException e) { - throw new LimaTechnicalException(e); - } finally { - if (csvWriter != null) { - try { - csvWriter.close(); - out.close(); - } catch (IOException e) { - // nothing to do - } - } - } - return out.getBuffer().toString(); - } - - - /** - * Local methode, export financialstatements from database - * structure : TYPE | Label | Header | Accounts | DebitAccounts - * | CreditAccounts | ProvisionDeprecationAccounts | SubAmount - * | HeaderAmount | MasterFinancialStatement - * - * @param csvWriter - * @throws LimaException - */ - public void exportFinancialStatementChartAsCSV(CSVWriter csvWriter) { - String[] nextLine = new String[12]; - // Get all Financialstatements - FinancialStatementTopiaDao financialStatementTopiaDao = - getDaoHelper().getFinancialStatementDao(); - - List<FinancialStatement> listFinancialStatements = - financialStatementTopiaDao.findAllOrderedByCreateDate(); - - // For all Financialstatements - for (FinancialStatement financialStatement : listFinancialStatements) { - nextLine[0] = ImportExportEntityEnum.FINANCIALSTATEMENT.getLabel(); - nextLine[1] = financialStatement.getLabel(); - nextLine[2] = Boolean.toString( - financialStatement.isHeader()); - nextLine[3] = financialStatement.getAccounts(); - nextLine[4] = financialStatement.getDebitAccounts(); - nextLine[5] = financialStatement.getCreditAccounts(); - nextLine[6] = financialStatement. - getProvisionDeprecationAccounts(); - nextLine[7] = Boolean.toString( - financialStatement.isSubAmount()); - nextLine[8] = Boolean.toString( - financialStatement.isHeaderAmount()); - FinancialStatement masterFinancialStatement = - financialStatement.getMasterFinancialStatement(); - String masterFinancialStatementString = masterFinancialStatement == null ? "" : StringUtils.remove(masterFinancialStatement.getLabel(), ";"); - nextLine[9] = masterFinancialStatementString; - FinancialStatementWayEnum financialStatementWayEnum = financialStatement.getWay(); - String financialStatementWay = ""; - if (financialStatementWayEnum != null) { - financialStatementWay = financialStatementWayEnum.name(); - } - nextLine[10] = financialStatementWay; - // Add line in file - csvWriter.writeNext(nextLine); - } - } - - /** Remote method call from UI. */ - @Override - public String exportVatStatementChartAsCSV() { - - StringWriter out = new StringWriter(); - CSVWriter csvWriter = null; - - try { - csvWriter = new CSVWriter(out, ';'); - exportVatStatementChartAsCSV(csvWriter); - // Write cache in file - csvWriter.flush(); - } catch (IOException e) { - throw new LimaTechnicalException(e); - } finally { - if (csvWriter != null) { - try { - csvWriter.close(); - out.close(); - } catch (IOException e) { - // nothing to do - } - } - } - return out.getBuffer().toString(); - - } - - /** - * Local methode, export vatstatements from database - * vatstatement Structure : TYPE | boxName | label | header - * | accounts | masterVatStatement - * - * @param csvWriter - * @throws LimaException - */ - public void exportVatStatementChartAsCSV(CSVWriter csvWriter) { - String[] nextLine = new String[6]; - // Get all Vatstatements - VatStatementTopiaDao vatStatementTopiaDao = getDaoHelper().getVatStatementDao(); - - List<VatStatement> listVatStatements = - vatStatementTopiaDao.findAllOrderedByCreateDate(); - - // For all Vatstatements - for (VatStatement vatStatement : listVatStatements) { - nextLine[0] = ImportExportEntityEnum.VATSTATEMENT.getLabel(); - nextLine[1] = vatStatement.getBoxName(); - nextLine[2] = vatStatement.getLabel(); - nextLine[3] = Boolean.toString( - vatStatement.isHeader()); - nextLine[4] = vatStatement.getAccounts(); - VatStatement masterVatStatement = - vatStatement.getMasterVatStatement(); - String masterVatStatementString = ""; - if (masterVatStatement != null) { - masterVatStatementString = - masterVatStatement.getLabel(); - } - nextLine[5] = masterVatStatementString; - - csvWriter.writeNext(nextLine); - } - } - - - /** Remote methode call from UI. */ - @Override - public String exportEntryBookChartAsCSV() { - - StringWriter out = new StringWriter(); - CSVWriter csvWriter = null; - - try { - csvWriter = new CSVWriter(out, ';'); - exportEntryBookChartAsCSV(csvWriter); - // Write cache in file - csvWriter.flush(); - } catch (IOException e) { - throw new LimaTechnicalException(e); - } finally { - if (csvWriter != null) { - try { - csvWriter.close(); - out.close(); - } catch (IOException e) { - // nothing to do - } - } - } - return out.getBuffer().toString(); - } - - - /** - * Local methode, export entrybooks from database - * Structure : TYPE | Code | Label | Type - * - * @param csvWriter - * @throws LimaException - */ - public void exportEntryBookChartAsCSV(CSVWriter csvWriter) { - - String[] nextLine = new String[3]; - // Get all entrybook - EntryBookTopiaDao entryBookTopiaDao = getDaoHelper().getEntryBookDao(); - List<EntryBook> listEntryBook = entryBookTopiaDao.findAll(); - // For all EntryBook - for (EntryBook entryBook : listEntryBook) { - nextLine[0] = ImportExportEntityEnum.ENTRYBOOK.getLabel(); - nextLine[1] = entryBook.getCode(); - nextLine[2] = StringUtils.remove(entryBook.getLabel(), ";"); - // Ajoute la ligne au fichier - csvWriter.writeNext(nextLine); - } - } - - - /** Remote methode call from UI. */ - @Override - public String exportAccountsChartAsCSV() { - StringWriter out = new StringWriter(); - CSVWriter csvWriter = null; - - try { - csvWriter = new CSVWriter(out, ';'); - exportAccountsChartAsCSV(csvWriter); - // Write cache in file - csvWriter.flush(); - } catch (IOException e) { - throw new LimaTechnicalException(e); - } finally { - if (csvWriter != null) { - try { - csvWriter.close(); - out.close(); - } catch (IOException e) { - // nothing to do - } - } - } - return out.getBuffer().toString(); - } - - - /** - * Local methode, export accounts from database - * Structure : TYPE | AccountNumber | Label | ThirdParty | MasterAccount | GeneralLedger - * - * @param csvWriter - * @throws LimaException - */ - public void exportAccountsChartAsCSV(CSVWriter csvWriter) { - String[] nextLine = new String[6]; - // Récupère tous les comptes - AccountTopiaDao accountTopiaDao = - getDaoHelper().getAccountDao(); - List<Account> listAccount = accountTopiaDao.findAll(); - // Pour tous les comptes - for (Account account : listAccount) { - nextLine[0] = ImportExportEntityEnum.ACCOUNT.getLabel(); - nextLine[1] = account.getAccountNumber(); - nextLine[2] = StringUtils.remove(account.getLabel(), ";"); - nextLine[3] = account.getThirdParty(); - - // Ajoute la ligne au fichier - csvWriter.writeNext(nextLine); - } - } - - - /** - * Local methode, export financialtransactions from database - * Structure : TYPE | TransactionDate | AmountDebit | AmountCredit - * | FinancialPeriod BeginDate | FinancialPeriod EndDate | EntryBook Code - * - * @param csvWriter - * @throws LimaException - */ - public void exportFinancialTransactionsAndEntriesAsCSV(CSVWriter csvWriter) { - int numTransaction = 0; - // Get all financialtransactions - - FinancialTransactionTopiaDao financialTransactionTopiaDao = - getDaoHelper().getFinancialTransactionDao(); - List<FinancialTransaction> listFinancialTransaction = - financialTransactionTopiaDao.findAll(); - // For all financialTransaction - for (FinancialTransaction financialTransaction : listFinancialTransaction) { - String[] nextLine = new String[8]; - nextLine[0] = ImportExportEntityEnum.FINANCIALTRANSACTION.getLabel(); - nextLine[1] = String.valueOf(numTransaction); - nextLine[2] = SDATEFORMAT.format(financialTransaction.getTransactionDate()); - nextLine[3] = financialTransaction.getAmountDebit().toString(); - nextLine[4] = financialTransaction.getAmountCredit().toString(); - EntryBook entryBook = financialTransaction.getEntryBook(); - if (entryBook != null) { - nextLine[5] = entryBook.getCode(); - } - // Ajoute la ligne au fichier - csvWriter.writeNext(nextLine); - - nextLine = new String[10]; - for (Entry entry : financialTransaction.getEntry()) { - nextLine[0] = ImportExportEntityEnum.ENTRY.getLabel(); - nextLine[1] = String.valueOf(numTransaction); - nextLine[2] = entry.getDescription(); - nextLine[3] = entry.getAmount().toString(); - nextLine[4] = Boolean.toString(entry.isDebit()); - nextLine[5] = entry.getLettering(); - nextLine[6] = entry.getDetail(); - nextLine[7] = entry.getVoucher(); - nextLine[8] = entry.getPosition(); - nextLine[9] = entry.getAccount().getAccountNumber(); - // Ajoute la ligne au fichier - csvWriter.writeNext(nextLine); - } - numTransaction++; - } - } - - - /** - * Local methode, export fiscalperiods from database - * Structure : TYPE | BeginDate | EndDate | Locked - * - * @param csvWriter - * @throws LimaException - */ - public void exportFiscalPeriodAsCSV(CSVWriter csvWriter) { - String[] nextLine = new String[4]; - // Get all fiscalperiod - FiscalPeriodTopiaDao fiscalPeriodTopiaDao = - getDaoHelper().getFiscalPeriodDao(); - List<FiscalPeriod> listFiscalPeriod = - fiscalPeriodTopiaDao.findAll(); - // For all Entry - for (FiscalPeriod fiscalPeriod : listFiscalPeriod) { - nextLine[0] = ImportExportEntityEnum.FISCALPERIOD.getLabel(); - nextLine[1] = SDATEFORMAT.format(fiscalPeriod.getBeginDate()); - nextLine[2] = SDATEFORMAT.format(fiscalPeriod.getEndDate()); - nextLine[3] = Boolean.toString(fiscalPeriod.isLocked()); - // Ajoute la ligne au fichier - csvWriter.writeNext(nextLine); - } - } - - /** - * Local methode, export ClosedPeriodicEntryBooks from database - * Structure : TYPE | Locked | FinancialPeriod beginDate | FinancialPeriod endDate | EntryBook Code - * - * @param csvWriter - * @throws LimaException - */ - public void exportClosedPeriodicEntryBooksAsCSV(CSVWriter csvWriter) { - String[] nextLine = new String[5]; - // Get all fiscalperiod - ClosedPeriodicEntryBookTopiaDao closedPeriodicEntryBookTopiaDao = - getDaoHelper().getClosedPeriodicEntryBookDao(); - List<ClosedPeriodicEntryBook> listClosedPeriodicEntryBook = - closedPeriodicEntryBookTopiaDao.findAll(); - // For all Entry - for (ClosedPeriodicEntryBook closedPeriodicEntryBook : listClosedPeriodicEntryBook) { - nextLine[0] = ImportExportEntityEnum.CLOSEDPERIODICENTRYBOOK.getLabel(); - nextLine[1] = Boolean.toString( - closedPeriodicEntryBook.isLocked()); - nextLine[2] = - SDATEFORMAT.format(closedPeriodicEntryBook.getFinancialPeriod(). - getBeginDate()); - nextLine[3] = - SDATEFORMAT.format(closedPeriodicEntryBook.getFinancialPeriod(). - getEndDate()); - nextLine[4] = closedPeriodicEntryBook.getEntryBook().getCode(); - // Ajoute la ligne au fichier - csvWriter.writeNext(nextLine); - } - } - - public void exportIdentityAsCSV(CSVWriter csvWriter) { - String[] nextLine = new String[12]; - // Get identity - IdentityTopiaDao identityTopiaDao = getDaoHelper().getIdentityDao(); - List<Identity> identities = identityTopiaDao.findAll(); - if (identities.size() != 0) { - - Identity identity = identities.get(0); - nextLine[0] = ImportExportEntityEnum.IDENTITY.getLabel(); - nextLine[1] = identity.getName(); - nextLine[2] = identity.getDescription(); - nextLine[3] = identity.getAddress(); - nextLine[4] = identity.getAddress2(); - nextLine[5] = identity.getCity(); - nextLine[6] = identity.getPhoneNumber(); - nextLine[7] = identity.getEmail(); - nextLine[8] = identity.getZipCode(); - nextLine[9] = identity.getVatNumber(); - nextLine[10] = identity.getClassificationCode(); - nextLine[11] = identity.getBusinessNumber(); - // Ajoute la ligne au fichier - csvWriter.writeNext(nextLine); - } - } -} Deleted: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java 2014-07-31 19:50:37 UTC (rev 3887) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java 2014-08-01 14:20:36 UTC (rev 3888) @@ -1,294 +0,0 @@ -/* - * #%L - * Lima business - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2008 - 2012 CodeLutin, Chatellier Eric - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * 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, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.lima.business.ejb; - -import au.com.bytecode.opencsv.CSVReader; -import com.google.common.base.Function; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.pdfbox.exceptions.COSVisitorException; -import org.apache.pdfbox.pdmodel.PDDocument; -import org.apache.pdfbox.pdmodel.interactive.form.PDField; -import org.chorem.lima.business.AlreadyExistAccountException; -import org.chorem.lima.business.ImportEbpException; -import org.chorem.lima.business.InvalidAccountNumberException; -import org.chorem.lima.business.LimaConfig; -import org.chorem.lima.business.api.AccountService; -import org.chorem.lima.business.api.ClosedPeriodicEntryBookService; -import org.chorem.lima.business.api.EntryBookService; -import org.chorem.lima.business.api.EntryService; -import org.chorem.lima.business.api.FinancialPeriodService; -import org.chorem.lima.business.api.FinancialTransactionService; -import org.chorem.lima.business.api.FiscalPeriodService; -import org.chorem.lima.business.api.IdentityService; -import org.chorem.lima.business.api.ImportService; -import org.chorem.lima.business.utils.DocumentsEnum; -import org.chorem.lima.business.utils.ImportExportEntityEnum; -import org.chorem.lima.entity.Account; -import org.chorem.lima.entity.AccountImpl; -import org.chorem.lima.entity.EntryBook; -import org.chorem.lima.entity.Identity; -import org.chorem.lima.entity.IdentityImpl; - -import javax.ejb.EJB; -import javax.ejb.Remote; -import javax.ejb.Stateless; -import javax.ejb.TransactionAttribute; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.StringReader; -import java.text.SimpleDateFormat; -import java.util.List; -import java.util.Map; - -import static org.nuiton.i18n.I18n.t; - -/** - * Import export service. - * Currently import and export as CSV and EBP. - */ -@Stateless -@Remote(ImportService.class) -@TransactionAttribute -public class ImportServiceImpl extends AbstractLimaService implements ImportService { - - private static final Log log = LogFactory.getLog(ImportServiceImpl.class); - - protected static final Function<Account, String> GET_ACCOUNT_NUMBER = new Function<Account, String>() { - @Override - public String apply(Account input) { - return input.getAccountNumber(); - } - }; - - protected static final Function<EntryBook, String> GET_ENTRY_BOOK_CODE = new Function<EntryBook, String>() { - @Override - public String apply(EntryBook input) { - return input.getCode(); - } - }; - protected final String DATE_PATTERN = "dd/MM/yyyy"; - - @EJB - private AccountService accountService; - - @EJB - private FiscalPeriodService fiscalPeriodService; - - @EJB - private FinancialPeriodService financialPeriodService; - - @EJB - private FinancialTransactionService financialTransactionService; - - @EJB - private EntryBookService entryBookService; - - @EJB - private IdentityService identityService; - - @EJB - private ClosedPeriodicEntryBookService closedPeriodicEntryBookService; - - @EJB - private EntryService entryService; - - private static final SimpleDateFormat SDATEFORMAT = new SimpleDateFormat( - "dd,MM,yyyy HH:mm:ss"); - - // ################ IMPORT THIRD PART ACCOUNTING SOFTWARE ################ - - @Override - public String importAccountsChartFromEbp(String datas) throws ImportEbpException{ - long before = System.currentTimeMillis(); - List<Account> accounts = accountService.getAllAccounts(); - if (accounts == null) { - accounts = Lists.newArrayList(); - } - Map<String, Account> indexedAccounts = Maps.newHashMap(Maps.uniqueIndex(accounts, GET_ACCOUNT_NUMBER)); - - StringBuilder result = new StringBuilder(); - CSVReader csvReader = null; - try { - csvReader = new CSVReader(new StringReader(datas)); - - // check header is valid - String[] headers = csvReader.readNext(); - String columnName; - Integer numIndex = null; - Integer intituleIndex = null; - for (int i = 0; i < headers.length; i++) { - columnName = headers[i]; - if (columnName.equalsIgnoreCase("Numero")) { - numIndex = i; - } else if (columnName.equalsIgnoreCase("Intitule")) { - intituleIndex = i; - } - } - - int nbAccountCreated = 0; - if (numIndex != null && intituleIndex != null) { - String[] line; - line = csvReader.readNext(); - while (line != null) { - String accountNumber = line[numIndex]; - String label = line[intituleIndex]; - Account account = indexedAccounts.get(accountNumber); - // an account can be created but not updated. - if (account == null) { - account = new AccountImpl(); - account.setAccountNumber(accountNumber); - account.setLabel(label); - try { - accountService.createAccount(account); - result.append(t("lima-business.import.account.added", - accountNumber, label)); - nbAccountCreated++; - } catch (AlreadyExistAccountException e) { - result.append(t("lima-business.import.account.alreadyExist", - accountNumber, label)); - } catch (InvalidAccountNumberException e) { - result.append(t("lima-business.import.account.InvalidAccountNumber", - accountNumber, label)); - } - } - line = csvReader.readNext(); - } - } else { - throw new ImportEbpException( - t("lima-business.import.noaccount")); - } - - if (log.isInfoEnabled()) { - long after = System.currentTimeMillis(); - log.info("Imported form EBP : " + nbAccountCreated + " accounts in " - + (after - before) + " ms"); - } - - } catch (IOException e) { - throw new ImportEbpException("Can't import", e); - } finally { - if (csvReader != null) { - try { - csvReader.close(); - } catch (IOException e) { - // on fait rien - } - } - } - return result.toString(); - } - - // ################ IMPORT ################ - - @Override - public String importAsPDF(String datas, - ImportExportEntityEnum importExportEntityEnum, - boolean setMode) { - - StringBuilder result = new StringBuilder(); - - PDDocument doc = null; - try { - String path = LimaConfig.getInstance().getReportsDir().getAbsolutePath(); - - String filePathDefault = path + File.separator - + DocumentsEnum.VAT.getFileName() + "_default.pdf"; - String filePathStructured = path + File.separator - + DocumentsEnum.VAT.getFileName() + "_structure.pdf"; - - InputStream reportsStream = new FileInputStream(datas); - //DocumentServiceImpl.class.getResourceAsStream("/reports/vat_form_fr.pdf"); - // load the document - doc = PDDocument.load(reportsStream); - - //save default vat document with empty boxes - if (setMode) { - doc.save(filePathDefault); - } - - //search for all PDFBox - List<PDField> FieldList = doc.getDocumentCatalog().getAcroForm().getFields(); - - //display inside each box their name - for (PDField pdField : FieldList) { - pdField.setValue(pdField.getFullyQualifiedName()); - } - - // save the structured document - doc.save(filePathStructured); - - //sets the new pdf url to be used as pdf document edited for reports - if (setMode) { - LimaConfig.getInstance().setVatPDFUrl(datas); - } - } catch (IOException ex) { - log.error("Can't read vat pdf", ex); - result.append("Can't read vat pdf"); - } catch (COSVisitorException ex) { - log.error("Can't save vat pdf", ex); - result.append("Can't save vat pdf"); - } finally { - try { - if (doc != null) { - doc.close(); - } - } catch (Exception e) { - // Nothing to do - } - } - return result.toString(); - } - - protected String importIdentity(String[] nextLine) { - StringBuilder result = new StringBuilder(); - - Identity identity = new IdentityImpl(); - nextLine[0] = ImportExportEntityEnum.IDENTITY.getLabel(); - identity.setName(nextLine[1]); - identity.setDescription(nextLine[2]); - identity.setAddress(nextLine[3]); - identity.setAddress2(nextLine[4]); - identity.setCity(nextLine[5]); - identity.setPhoneNumber(nextLine[6]); - identity.setEmail(nextLine[7]); - identity.setZipCode(nextLine[8]); - identity.setVatNumber(nextLine[9]); - identity.setClassificationCode(nextLine[10]); - identity.setBusinessNumber(nextLine[11]); - - identityService.updateIdentity(identity); - // create it - result.append(t("lima-business.import.identityadded", identity.getName())); - - return result.toString(); - } - -} Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewExportServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewExportServiceImpl.java 2014-07-31 19:50:37 UTC (rev 3887) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewExportServiceImpl.java 2014-08-01 14:20:36 UTC (rev 3888) @@ -45,6 +45,8 @@ import org.chorem.lima.business.ejb.csv.FiscalPeriodModel; import org.chorem.lima.business.ejb.csv.IdentityModel; import org.chorem.lima.business.ejb.csv.VatStatementModel; +import org.chorem.lima.business.ejb.ebp.AccountEBPModel; +import org.chorem.lima.business.ejb.ebp.EntryEBPModel; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.AccountTopiaDao; import org.chorem.lima.entity.Entry; @@ -107,46 +109,6 @@ public static final String JAVA_IO_TMPDIR = "java.io.tmpdir"; - @Override - public String exportBackup(String charset) { - ByteArrayOutputStream rstBao = new ByteArrayOutputStream(); - ZipOutputStream export = null; - try { - List<File> files = Lists.newArrayList(); - files.add(exportAccountsFile(charset)); - files.add(exportEntryBooksFile(charset)); - files.add(exportFiscalPeriodFile(charset)); - files.add(exportFinancialTransactionsFile(charset)); - files.add(exportEntriesFile(charset, false)); - files.add(exportIdentity(charset)); - - export = new ZipOutputStream(rstBao); - - for (File file : files) { - if (file != null) { - ZipEntry ze= new ZipEntry(file.getName()); - export.putNextEntry(ze); - int len; - byte[] buffer = new byte[1024]; - FileInputStream stream = new FileInputStream(file); - while ((len = stream.read(buffer)) > 0) { - export.write(buffer, 0, len); - } - stream.close(); - FileUtils.forceDelete(file); - } - } - export.flush(); - - } catch (Exception e) { - throw new LimaTechnicalException(e); - } finally { - IOUtils.closeQuietly(export); - } - byte[] bytes = rstBao.toByteArray(); - return Base64.encodeBase64String(bytes); - } - protected File exportAccountsFile(String charset) throws Exception { AccountTopiaDao accountTopiaDao = getDaoHelper().getAccountDao(); List<Account> entities = accountTopiaDao.findAll(); @@ -270,22 +232,6 @@ return result; } - protected File exportIdentity(String charset) throws Exception { - File result = null; - - Identity identity = identityService.getIdentity(); - if (identity != null) { - List<Identity> identities = new ArrayList<>(); - identities.add(identity); - - String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/"; - result = new File(tmpDir + "identity.csv"); - IdentityModel model = new IdentityModel(); - Export.exportToFile(model, identities, result, Charset.forName(charset)); - } - return result; - } - @Override public String exportEntriesAsCSV(String charset, Boolean humanReadable) { String result = null; @@ -301,6 +247,16 @@ return result; } + protected List<FinancialStatement> getAllSubFinancialStatements(List<FinancialStatement> result, Collection<FinancialStatement> subFinancialStatements) { + if (subFinancialStatements != null) { + for (FinancialStatement subFinancialStatement : subFinancialStatements) { + result.add(subFinancialStatement); + getAllSubFinancialStatements(result, subFinancialStatement.getSubFinancialStatements()); + } + } + return result; + } + @Override public String exportFinancialStatements(String charset) throws Exception { String stResult = null; @@ -320,11 +276,11 @@ return stResult; } - public List<FinancialStatement> getAllSubFinancialStatements(List<FinancialStatement> result, Collection<FinancialStatement> subFinancialStatements) { - if (subFinancialStatements != null) { - for (FinancialStatement subFinancialStatement : subFinancialStatements) { - result.add(subFinancialStatement); - getAllSubFinancialStatements(result, subFinancialStatement.getSubFinancialStatements()); + protected List<VatStatement> getAllSubVATStatements(List<VatStatement> result, Collection<VatStatement> subVATStatements) { + if (subVATStatements != null) { + for (VatStatement subVATStatement : subVATStatements) { + result.add(subVATStatement); + getAllSubVATStatements(result, subVATStatement.getSubVatStatements()); } } return result; @@ -349,13 +305,120 @@ return stResult; } - public List<VatStatement> getAllSubVATStatements(List<VatStatement> result, Collection<VatStatement> subVATStatements) { - if (subVATStatements != null) { - for (VatStatement subVATStatement : subVATStatements) { - result.add(subVATStatement); - getAllSubVATStatements(result, subVATStatement.getSubVatStatements()); - } + protected File exportIdentity(String charset) throws Exception { + File result = null; + + Identity identity = identityService.getIdentity(); + if (identity != null) { + List<Identity> identities = new ArrayList<>(); + identities.add(identity); + + String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/"; + result = new File(tmpDir + "identity.csv"); + IdentityModel model = new IdentityModel(); + Export.exportToFile(model, identities, result, Charset.forName(charset)); } return result; } + + @Override + public String exportBackup(String charset) { + ByteArrayOutputStream rstBao = new ByteArrayOutputStream(); + ZipOutputStream export = null; + try { + List<File> files = Lists.newArrayList(); + files.add(exportAccountsFile(charset)); + files.add(exportEntryBooksFile(charset)); + files.add(exportFiscalPeriodFile(charset)); + files.add(exportFinancialTransactionsFile(charset)); + files.add(exportEntriesFile(charset, false)); + files.add(exportIdentity(charset)); + + export = new ZipOutputStream(rstBao); + + for (File file : files) { + if (file != null) { + ZipEntry ze= new ZipEntry(file.getName()); + export.putNextEntry(ze); + int len; + byte[] buffer = new byte[1024]; + FileInputStream stream = new FileInputStream(file); + while ((len = stream.read(buffer)) > 0) { + export.write(buffer, 0, len); + } + stream.close(); + FileUtils.forceDelete(file); + } + } + export.flush(); + + } catch (Exception e) { + throw new LimaTechnicalException(e); + } finally { + IOUtils.closeQuietly(export); + } + byte[] bytes = rstBao.toByteArray(); + return Base64.encodeBase64String(bytes); + } + + //####################################### EBP ############################################## + + @Override + public String exportAccountAsEbp(String charset) throws Exception { + String stResult = null; + File result; + + List<Account> accounts = accountService.getAllAccounts(); + if (accounts != null && !accounts.isEmpty()) { + + String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/"; + result = new File(tmpDir + "accounts.csv"); + AccountEBPModel model = new AccountEBPModel(); + Export.exportToFile(model, accounts, result, Charset.forName(charset)); + FileInputStream inputStream = new FileInputStream(result); + stResult = IOUtils.toString(inputStream); + + } + return stResult; + } + + @Override + public String exportEntriesAsEbp(String charset) throws Exception { + String stResult = null; + File result; + + List<Entry> entries = getDaoHelper().getEntryDao().findAll(); + + if (entries != null && !entries.isEmpty()) { + + String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/"; + result = new File(tmpDir + "entries.csv"); + EntryEBPModel model = new EntryEBPModel(); + Export.exportToFile(model, entries, result, Charset.forName(charset)); + FileInputStream inputStream = new FileInputStream(result); + stResult = IOUtils.toString(inputStream); + + } + return stResult; + } + + @Override + public String exportEntryBookAsEbp(String charset) throws Exception { + String stResult = null; + File result; + + List<EntryBook> entryBooks = entryBookService.getAllEntryBooks(); + + if (entryBooks != null && !entryBooks.isEmpty()) { + + String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/"; + result = new File(tmpDir + "entryBooks.csv"); + EntryBookModel model = new EntryBookModel(); + Export.exportToFile(model, entryBooks, result, Charset.forName(charset)); + FileInputStream inputStream = new FileInputStream(result); + stResult = IOUtils.toString(inputStream); + + } + return stResult; + } } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewImportServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewImportServiceImpl.java 2014-07-31 19:50:37 UTC (rev 3887) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewImportServiceImpl.java 2014-08-01 14:20:36 UTC (rev 3888) @@ -58,6 +58,7 @@ import org.chorem.lima.business.ejb.csv.FiscalPeriodModel; import org.chorem.lima.business.ejb.csv.IdentityModel; import org.chorem.lima.business.ejb.csv.VatStatementModel; +import org.chorem.lima.business.ejb.ebp.AccountEBPModel; import org.chorem.lima.business.ejb.ebp.EntryBookEBPModel; import org.chorem.lima.business.ejb.ebp.EntryEBPModel; import org.chorem.lima.business.utils.EntryEBPComparator; @@ -301,7 +302,7 @@ } } - // + // the target financialStatement has not been created yet so we create it now. if (targetedFinancialStatement == null) { // not found, we need to create it targetedFinancialStatement = financialStatementService.newFinancialStatement(); @@ -591,7 +592,37 @@ return results; } + //####################################### EBP ############################################## + + @Override + public ImportResult importAccountFromEbp(String datas) { + ImportResult result = new ImportResult(); + + ImportModel<Account> model = new AccountEBPModel(); + + InputStream contentStream = IOUtils.toInputStream(datas); + Import<Account> accounts = Import.newImport(model, contentStream); + + int lineIndex = 0; + for (Account account : accounts) { + boolean updated = false; + try { + updated = accountService.createOrUbdateAccount(account); + lineIndex++; + } catch (InvalidAccountNumberException e) { + result.getException().addException(lineIndex, e); + } + if (updated) { + result.increaseUpdated(); + } else { + result.increaseCreated(); + } + } + return result; + } + + @Override public ImportResult importEntriesFromEbp(String datas) { ImportResult result = new ImportResult(); @@ -621,13 +652,13 @@ ImportModel<EntryEBP> model = new EntryEBPModel(); - Import<EntryEBP> entryEBPs = Import.newImport(model, contentStream); - List<EntryEBP> list = new ArrayList<>(); - for (EntryEBP entryEBP : entryEBPs) { - list.add(entryEBP); + Import<EntryEBP> importedEntryEBPs = Import.newImport(model, contentStream); + List<EntryEBP> entryEBPs = new ArrayList<>(); + for (EntryEBP entryEBP : importedEntryEBPs) { + entryEBPs.add(entryEBP); } - Collections.sort(list, new EntryEBPComparator()); + Collections.sort(entryEBPs, new EntryEBPComparator()); // Get all the valid fiscalPeriods Ordered by date. List<FiscalPeriod> fiscalPeriods = fiscalPeriodService @@ -657,20 +688,23 @@ // the entry entity is created and the association with it's dependant entites (Account are FinancialTransaction) are created int lineIndex = 0; - for (EntryEBP entryEBP : list) { + for (EntryEBP entryEBP : entryEBPs) { dateEcr = entryEBP.getDatEcr(); // account loading account = indexedAccounts.get(entryEBP.getCompte()); // if entry date have fiscalperiod open - if (dateEcr.compareTo(fiscalPeriods.get(0).getBeginDate()) < 0 - || dateEcr.compareTo(fiscalPeriods.get(fiscalPeriods.size() - 1).getEndDate()) > 0) { + FiscalPeriod firstFiscalPeriod = fiscalPeriods.get(0); + FiscalPeriod lastFiscalPeriod = fiscalPeriods.get(fiscalPeriods.size() - 1); + Date fiscalPeriodsBiginDate = firstFiscalPeriod.getBeginDate(); + Date fiscalPeriodsEndingDate = lastFiscalPeriod.getEndDate(); + if (dateEcr.compareTo(fiscalPeriodsBiginDate) < 0 + || dateEcr.compareTo(fiscalPeriodsEndingDate) > 0) { result.getException().addException(lineIndex, new ImportEbpException(t("lima-business.import.entriesoutofdatesrange", dateEcr))); lineIndex++; continue; } - // if account not exist not export -> exception else if (account == null) { result.getException().addException(lineIndex, new ImportEbpException(t("lima-business.import.ebpmissingaccount", entryEBP.getCompte()))); @@ -681,6 +715,13 @@ // create entry else { + // find financial transactions for entry period. + List<FinancialTransaction> financialTransactions = financialTransactionService.getAllFinancialTransactions(fiscalPeriodsBiginDate, fiscalPeriodsEndingDate); + Map<Date, FinancialTransaction> financialTransactionsByDate = new HashMap<>(); + for (FinancialTransaction transaction : financialTransactions) { + financialTransactionsByDate.put(transaction.getTransactionDate(), transaction); + } + // creation of the entry // initialisation of this attributs @@ -689,7 +730,7 @@ // the entry has one amount witch can be Debit or Credit // regarding the value of the boolean:debit debit = entryEBP.getDebit(); - if (BigDecimal.ZERO.compareTo(debit)==0) { + if (debit == null || BigDecimal.ZERO.compareTo(debit)==0) { entry.setDebit(false); entry.setAmount(entryEBP.getCredit()); } else { @@ -724,8 +765,8 @@ indexedEntryBooks.put(entryBook.getCode(), entryBook); } try { - // create transaction + financialTransaction = financialTransactionsByDate.get(dateEcr); if (financialTransaction == null || !(dateEcr.equals(financialTransaction .getTransactionDate()) && entryBook @@ -756,7 +797,7 @@ if (log.isInfoEnabled()) { long after = System.currentTimeMillis(); - log.info("Imported form EBP : " + list.size() + " entries in " + log.info("Imported form EBP : " + entryEBPs.size() + " entries in " + (after - before) + " ms"); } } finally { @@ -784,4 +825,65 @@ } return result; } + + //####################################################################################################### + +// @Override +// public String importAsPDF(String datas, +// ImportExportEntityEnum importExportEntityEnum, +// boolean setMode) { +// +// StringBuilder result = new StringBuilder(); +// +// PDDocument doc = null; +// try { +// String path = LimaConfig.getInstance().getReportsDir().getAbsolutePath(); +// +// String filePathDefault = path + File.separator +// + DocumentsEnum.VAT.getFileName() + "_default.pdf"; +// String filePathStructured = path + File.separator +// + DocumentsEnum.VAT.getFileName() + "_structure.pdf"; +// +// InputStream reportsStream = new FileInputStream(datas); +// //DocumentServiceImpl.class.getResourceAsStream("/reports/vat_form_fr.pdf"); +// // load the document +// doc = PDDocument.load(reportsStream); +// +// //save default vat document with empty boxes +// if (setMode) { +// doc.save(filePathDefault); +// } +// +// //search for all PDFBox +// List<PDField> FieldList = doc.getDocumentCatalog().getAcroForm().getFields(); +// +// //display inside each box their name +// for (PDField pdField : FieldList) { +// pdField.setValue(pdField.getFullyQualifiedName()); +// } +// +// // save the structured document +// doc.save(filePathStructured); +// +// //sets the new pdf url to be used as pdf document edited for reports +// if (setMode) { +// LimaConfig.getInstance().setVatPDFUrl(datas); +// } +// } catch (IOException ex) { +// log.error("Can't read vat pdf", ex); +// result.append("Can't read vat pdf"); +// } catch (COSVisitorException ex) { +// log.error("Can't save vat pdf", ex); +// result.append("Can't save vat pdf"); +// } finally { +// try { +// if (doc != null) { +// doc.close(); +// } +// } catch (Exception e) { +// // Nothing to do +// } +// } +// return result.toString(); +// } } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/AbstractLimaModel.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/AbstractLimaModel.java 2014-07-31 19:50:37 UTC (rev 3887) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/AbstractLimaModel.java 2014-08-01 14:20:36 UTC (rev 3888) @@ -30,11 +30,13 @@ import org.chorem.lima.business.api.EntryBookService; import org.chorem.lima.business.api.FinancialTransactionService; import org.chorem.lima.entity.Account; +import org.chorem.lima.entity.Entry; import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.FinancialStatement; import org.chorem.lima.entity.FinancialTransaction; import org.chorem.lima.entity.VatStatement; import org.nuiton.csv.ValueFormatter; +import org.nuiton.csv.ValueGetter; import org.nuiton.csv.ValueParser; import org.nuiton.csv.ext.AbstractImportModel; @@ -193,8 +195,7 @@ public String format(Date value) { String result; if (value != null) { - SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy"); - result = format.format(value); + result = simpleDateFormat.format(value); } else { result = ""; } @@ -210,8 +211,7 @@ public Date parse(String value) throws ParseException { Date result = null; if (!Strings.isNullOrEmpty(value)) { - SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy"); - result = format.parse(value); + result = simpleDateFormat.parse(value); } return result; } @@ -383,4 +383,46 @@ return result; } }; + + protected static final ValueFormatter<FinancialTransaction> FINANCIAL_TRANSACTION_TO_ENTRY_BOOK_FORMATTER = new ValueFormatter<FinancialTransaction>() { + @Override + public String format(FinancialTransaction value) { + String result; + if (value != null) { + result = value.getEntryBook().getCode(); + } else { + result = ""; + } + return result; + } + }; + + protected static final ValueFormatter<FinancialTransaction> FINANCIAL_TRANSACTION_TO_TRANSACTION_DATE_FORMATTER = new ValueFormatter<FinancialTransaction>() { + @Override + public String format(FinancialTransaction value) { + String result; + if (value != null) { + result = simpleDateFormat.format(value.getTransactionDate()); + } else { + result = ""; + } + return result; + } + }; + + protected static final ValueGetter<Entry, String> ENTRY_DEBIT_GETTER = new ValueGetter<Entry, String>() { + @Override + public String get(Entry entry) throws Exception { + String result = entry.isDebit() ? String.valueOf(entry.getAmount()) : ""; + return result; + } + }; + + protected static final ValueGetter<Entry, String> ENTRY_CREDIT_GETTER = new ValueGetter<Entry, String>() { + @Override + public String get(Entry entry) throws Exception { + String result = entry.isDebit() ? "" : String.valueOf(entry.getAmount()); + return result; + } + }; } Added: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ebp/AccountEBPModel.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ebp/AccountEBPModel.java (rev 0) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ebp/AccountEBPModel.java 2014-08-01 14:20:36 UTC (rev 3888) @@ -0,0 +1,132 @@ +package org.chorem.lima.business.ejb.ebp; + +import org.chorem.lima.business.ejb.csv.AbstractLimaModel; +import org.chorem.lima.entity.Account; +import org.chorem.lima.entity.AccountImpl; +import org.nuiton.csv.ExportModel; +import org.nuiton.csv.ExportableColumn; +import org.nuiton.csv.ModelBuilder; + +/** + * Created by davidcosse on 01/08/14. + */ +public class AccountEBPModel extends AbstractLimaModel<Account> implements ExportModel<Account> { + + + public AccountEBPModel() { + super(','); + newMandatoryColumn("Numero", Account.PROPERTY_ACCOUNT_NUMBER); + newOptionalColumn("Intitule", Account.PROPERTY_LABEL); + newIgnoredColumn("Type"); + newIgnoredColumn("bLetManuel"); + newIgnoredColumn("bLetAuto"); + newIgnoredColumn("bLetAppro"); + newIgnoredColumn("bCentPhysique"); + newIgnoredColumn("bCentJournal"); + newIgnoredColumn("bCentGLivre"); + newIgnoredColumn("bGeleDebit"); + newIgnoredColumn("bGeleCredit"); + newIgnoredColumn("bNoEchAna"); + newIgnoredColumn("TypeRel"); + newIgnoredColumn("Categorie"); + newIgnoredColumn("CodeTVA"); + newIgnoredColumn("TypeTVA"); + newIgnoredColumn("Lettrage"); + newIgnoredColumn("Encours"); + newIgnoredColumn("Seuil"); + newIgnoredColumn("Remise"); + newIgnoredColumn("Escompte"); + newIgnoredColumn("Devise"); + newIgnoredColumn("RIB0NomBanque"); + newIgnoredColumn("RIB0AdrBanque"); + newIgnoredColumn("RIB0Agence"); + newIgnoredColumn("RIB0Guichet"); + newIgnoredColumn("RIB0Compte"); + newIgnoredColumn("RIB0CleRIB"); + newIgnoredColumn("RIB1NomBanque"); + newIgnoredColumn("RIB1AdrBanque"); + newIgnoredColumn("RIB1Agence"); + newIgnoredColumn("RIB1Guichet"); + newIgnoredColumn("RIB1Compte"); + newIgnoredColumn("RIB1CleRIB"); + newIgnoredColumn("RIB2NomBanque"); + newIgnoredColumn("RIB2AdrBanque"); + newIgnoredColumn("RIB2Agence"); + newIgnoredColumn("RIB2Guichet"); + newIgnoredColumn("RIB2Compte"); + newIgnoredColumn("RIB2CleRIB"); + newIgnoredColumn("AdresseCivilite"); + newIgnoredColumn("AdresseRaiSoc"); + newIgnoredColumn("AdresseAdresse"); + newIgnoredColumn("AdresseCodePostal"); + newIgnoredColumn("AdresseVille"); + newIgnoredColumn("AdressePays"); + newIgnoredColumn("NII"); + newIgnoredColumn("Contact0Interloc"); + newIgnoredColumn("Contact0Fonction"); + newIgnoredColumn("Contact0TelNumTel"); + newIgnoredColumn("Contact0TelNumFax"); + newIgnoredColumn("Contact0Infos"); + newIgnoredColumn("Contact1Interloc"); + newIgnoredColumn("Contact1Fonction"); + newIgnoredColumn("Contact1TelNumTel"); + newIgnoredColumn("Contact1TelNumFax"); + newIgnoredColumn("Contact1Infos"); + newIgnoredColumn("Contact2Interloc"); + newIgnoredColumn("Contact2Fonction"); + newIgnoredColumn("Contact2TelNumTel"); + newIgnoredColumn("Contact2TelNumFax"); + newIgnoredColumn("Contact2Infos"); + newIgnoredColumn("Contact3Interloc"); + newIgnoredColumn("Contact3Fonction"); + newIgnoredColumn("Contact3TelNumTel"); + newIgnoredColumn("Contact3TelNumFax"); + newIgnoredColumn("Contact3Infos"); + newIgnoredColumn("Contact4Interloc"); + newIgnoredColumn("Contact4Fonction"); + newIgnoredColumn("Contact4TelNumTel"); + newIgnoredColumn("Contact4TelNumFax"); + newIgnoredColumn("Contact4Infos"); + newIgnoredColumn("CodeRegle"); + newIgnoredColumn("NbJours"); + newIgnoredColumn("TypeJours"); + newIgnoredColumn("Limite"); + newIgnoredColumn("Grille1"); + newIgnoredColumn("Grille2"); + newIgnoredColumn("Grille3"); + newIgnoredColumn("SectGeo"); + newIgnoredColumn("SectAct"); + newIgnoredColumn("ObjCA"); + newIgnoredColumn("TailleCA"); + newIgnoredColumn("NbEmpl"); + newIgnoredColumn("Commercial"); + newIgnoredColumn("JoursMois"); + newIgnoredColumn("CptTva"); + newIgnoredColumn("CptCharge"); + newIgnoredColumn("bDecouvertAutorise"); + newIgnoredColumn("MntDecouvertAutorise"); + newIgnoredColumn("EMailTiers"); + newIgnoredColumn("WebSiteTiers"); + newIgnoredColumn("NatAchat"); + newIgnoredColumn("NatVente"); + newIgnoredColumn("NatDepense"); + newIgnoredColumn("NatRecette"); + newIgnoredColumn("NumCptBqCH"); + newIgnoredColumn("NumClearing"); + newIgnoredColumn("NumIBAN"); + newIgnoredColumn("LetPart"); + } + + @Override + public Iterable<ExportableColumn<Account, Object>> getColumnsForExport() { + ModelBuilder<Account> modelBuilder = new ModelBuilder<>(); + modelBuilder.newColumnForExport("Numero", Account.PROPERTY_ACCOUNT_NUMBER); + modelBuilder.newColumnForExport("Intitule", Account.PROPERTY_LABEL); + return (Iterable) modelBuilder.getColumnsForExport(); + } + + @Override + public Account newEmptyInstance() { + return new AccountImpl(); + } +} Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ebp/EntryEBPModel.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ebp/EntryEBPModel.java 2014-07-31 19:50:37 UTC (rev 3887) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ebp/EntryEBPModel.java 2014-08-01 14:20:36 UTC (rev 3888) @@ -25,6 +25,7 @@ import org.chorem.lima.beans.EntryEBP; import org.chorem.lima.beans.EntryEBPImpl; import org.chorem.lima.business.ejb.csv.AbstractLimaModel; +import org.chorem.lima.entity.Entry; import org.nuiton.csv.ExportModel; import org.nuiton.csv.ExportableColumn; import org.nuiton.csv.ModelBuilder; @@ -32,7 +33,7 @@ /** * Created by davidcosse on 03/06/14. */ -public class EntryEBPModel extends AbstractLimaModel<EntryEBP> implements ExportModel<EntryEBP> { +public class EntryEBPModel extends AbstractLimaModel<EntryEBP> implements ExportModel<Entry> { public EntryEBPModel() { super(','); @@ -73,16 +74,16 @@ } @Override - public Iterable<ExportableColumn<EntryEBP, Object>> getColumnsForExport() { - ModelBuilder<EntryEBP> modelBuilder = new ModelBuilder<>(); - modelBuilder.newColumnForExport("Journal", EntryEBP.PROPERTY_JOURNAL); - modelBuilder.newColumnForExport("Compte", EntryEBP.PROPERTY_COMPTE, ACCOUNT_TO_ACCOUNT_NUMBER_FORMATTER); - modelBuilder.newColumnForExport("DatEcr", EntryEBP.PROPERTY_DAT_ECR, DATE_FORMATTER); - modelBuilder.newColumnForExport("Piece", EntryEBP.PROPERTY_PIECE); - modelBuilder.newColumnForExport("Libelle", EntryEBP.PROPERTY_LIBELLE); - modelBuilder.newColumnForExport("Debit", EntryEBP.PROPERTY_DEBIT, BIG_DECIMAL_FORMATTER); - modelBuilder.newColumnForExport("Credit", EntryEBP.PROPERTY_CREDIT, BIG_DECIMAL_FORMATTER); - modelBuilder.newColumnForExport("Lettre", EntryEBP.PROPERTY_LETTRE); + public Iterable<ExportableColumn<Entry, Object>> getColumnsForExport() { + ModelBuilder<Entry> modelBuilder = new ModelBuilder<>(); + modelBuilder.newColumnForExport("Journal", Entry.PROPERTY_FINANCIAL_TRANSACTION, FINANCIAL_TRANSACTION_TO_ENTRY_BOOK_FORMATTER); + modelBuilder.newColumnForExport("Compte", Entry.PROPERTY_ACCOUNT, ACCOUNT_TO_ACCOUNT_NUMBER_FORMATTER); + modelBuilder.newColumnForExport("DatEcr", Entry.PROPERTY_FINANCIAL_TRANSACTION, FINANCIAL_TRANSACTION_TO_TRANSACTION_DATE_FORMATTER); + modelBuilder.newColumnForExport("Piece", Entry.PROPERTY_VOUCHER); + modelBuilder.newColumnForExport("Libelle", Entry.PROPERTY_DESCRIPTION); + modelBuilder.newColumnForExport("Debit", ENTRY_DEBIT_GETTER); + modelBuilder.newColumnForExport("Credit", ENTRY_CREDIT_GETTER); + modelBuilder.newColumnForExport("Lettre", Entry.PROPERTY_LETTERING); return (Iterable) modelBuilder.getColumnsForExport(); } Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java 2014-07-31 19:50:37 UTC (rev 3887) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java 2014-08-01 14:20:36 UTC (rev 3888) @@ -36,7 +36,6 @@ import org.chorem.lima.business.api.FinancialTransactionService; import org.chorem.lima.business.api.FiscalPeriodService; import org.chorem.lima.business.api.IdentityService; -import org.chorem.lima.business.api.ImportService; import org.chorem.lima.business.api.NewExportService; import org.chorem.lima.business.api.NewImportService; import org.chorem.lima.business.api.ReportService; @@ -96,7 +95,6 @@ protected FinancialTransactionService financialTransactionService; protected FiscalPeriodService fiscalPeriodService; protected ReportService reportService; - protected ImportService importService; protected EntryService entryService; protected NewImportService newImportService; protected NewExportService newExportService; @@ -138,7 +136,6 @@ financialTransactionService = LimaServiceFactory.getService(FinancialTransactionService.class); fiscalPeriodService = LimaServiceFactory.getService(FiscalPeriodService.class); reportService = LimaServiceFactory.getService(ReportService.class); - importService = LimaServiceFactory.getService(ImportService.class); entryService = LimaServiceFactory.getService(EntryService.class); financialStatementService = LimaServiceFactory.getService(FinancialStatementService.class); vatStatementService = LimaServiceFactory.getService(VatStatementService.class); Deleted: trunk/lima-business/src/test/java/org/chorem/lima/business/ImportServiceImplTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/ImportServiceImplTest.java 2014-07-31 19:50:37 UTC (rev 3887) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/ImportServiceImplTest.java 2014-08-01 14:20:36 UTC (rev 3888) @@ -1,113 +0,0 @@ -/* - * #%L - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 Codelutin, Chatellier Eric - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * 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, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.lima.business; - -import org.apache.commons.io.IOUtils; -import org.chorem.lima.entity.Account; -import org.chorem.lima.entity.FiscalPeriod; -import org.chorem.lima.entity.FiscalPeriodImpl; -import org.junit.Assert; -import org.junit.Test; - -import java.io.IOException; -import java.io.InputStream; -import java.text.ParseException; - -/** - * Test du service d'import en faisant des import/export EBP et xml. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class ImportServiceImplTest extends AbstractLimaTest { - - /** - * Import files available in src/test/resources/ebp. - * - * @throws IOException - * @throws ParseException - * @throws BeginAfterEndFiscalPeriodException - * @throws NotBeginNextDayOfLastFiscalPeriodException - * @throws MoreOneUnlockFiscalPeriodException - * @throws ImportEbpException - */ - protected void importEBPData() throws IOException, ParseException, BeginAfterEndFiscalPeriodException, - NotBeginNextDayOfLastFiscalPeriodException, MoreOneUnlockFiscalPeriodException, ImportEbpException { - - // create fiscal period (mandatory for import) - FiscalPeriod fiscalPeriod = new FiscalPeriodImpl(); - fiscalPeriod.setBeginDate(df.parse("January 1, 2012")); - fiscalPeriod.setEndDate(df.parse("December 31, 2012")); - fiscalPeriodService.createFiscalPeriod(fiscalPeriod); - - // import files - InputStream accountStream = null; - try { - accountStream = ImportServiceImplTest.class.getResourceAsStream("/ebp/comptes.txt"); - String accountData = IOUtils.toString(accountStream, "ISO-8859-1"); - importService.importAccountsChartFromEbp(accountData); - accountStream.close(); - } - finally { - IOUtils.closeQuietly(accountStream); - } - } - - /** - * Do some test on imported accounts. - * - * @throws Exception - */ - @Test - public void testImportAccountsEBP() throws Exception { - importEBPData(); - - Assert.assertEquals(571, accountService.getAllAccounts().size()); - Assert.assertEquals("Créances", accountService.getAccountByNumber("78174000").getLabel()); - - // test employe and client - Assert.assertNotNull(accountService.getAccountByNumber("401TEEMP")); - Assert.assertNotNull(accountService.getAccountByNumber("411TECLI")); - } - - /** - * Test que les comptes tiers sont correctement rattachés à l'arbre du - * plan comptable. - * - * @throws Exception - */ - @Test - public void testImportCreateIntermediaiteAccount() throws Exception { - importEBPData(); - - Account compteTiers = accountService.getAccountByNumber("4"); - Account employeAccount = accountService.getAccountByNumber("401TEEMP"); - Assert.assertNotNull(compteTiers); - Assert.assertNotNull(employeAccount); - } - -} Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/NewImportExportServiceTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/NewImportExportServiceTest.java 2014-07-31 19:50:37 UTC (rev 3887) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/NewImportExportServiceTest.java 2014-08-01 14:20:36 UTC (rev 3888) @@ -46,6 +46,7 @@ import java.io.IOException; import java.io.InputStream; import java.nio.charset.Charset; +import java.text.ParseException; import java.util.Collection; import java.util.List; import java.util.zip.ZipEntry; @@ -344,7 +345,7 @@ @Test public void testImportFiscalStatementsAsCSV() throws Exception { // not ordered csv import file - String bcr_developed = IOUtils.toString(ImportServiceImplTest.class.getResourceAsStream("/import/bcr_developed.csv")); + String bcr_developed = IOUtils.toString(NewImportExportServiceTest.class.getResourceAsStream("/import/bcr_developed.csv")); ImportResult result; @@ -365,7 +366,7 @@ @Test public void testImportVATStatementsAsCSV() throws Exception { // not ordered csv import file - String bcr_developed = IOUtils.toString(ImportServiceImplTest.class.getResourceAsStream("/import/vat_shortened.csv")); + String bcr_developed = IOUtils.toString(NewImportExportServiceTest.class.getResourceAsStream("/import/vat_shortened.csv")); ImportResult result; @@ -419,4 +420,125 @@ EntryBook updatedEntryBook = entryBookService.getEntryBookByCode("AC"); Assert.assertEquals("Achats de marchandises", updatedEntryBook.getLabel()); } + + @Test + public void testExportImportEntriesEbp() throws Exception { + initTestWithFinancialTransaction(); + + List<FinancialTransaction> financialTransactions = financialTransactionService.getAllFinancialTransactions(df.parse("April 4, 2012"),df.parse("December 31, 2012")); + List<Entry> entries = Lists.newArrayList(); + Assert.assertFalse(financialTransactions.isEmpty()); + for (FinancialTransaction financialTransaction : financialTransactions) { + entries.addAll(financialTransaction.getEntry()); + } + Assert.assertTrue(!entries.isEmpty()); + int nbEntities = entries.size(); + + //test export + String tmpDir = System.getProperty("java.io.tmpdir")+"/"; + String export = newExportService.exportEntriesAsEbp(Charset.defaultCharset().name()); + InputStream stream = IOUtils.toInputStream(export); + FileOutputStream res = new FileOutputStream(tmpDir + "export-entries-EBP.csv"); + IOUtils.copy(stream, res); + + for (Entry entry : entries) { + FinancialTransaction financialTransaction = entry.getFinancialTransaction(); + financialTransactionService.removeEntry(entry); + financialTransactionService.updateFinancialTransaction(financialTransaction); + } + + // ake sure all entries have been cleared + entries.clear();// + + financialTransactions = financialTransactionService.getAllFinancialTransactions(df.parse("April 4, 2012"),df.parse("December 31, 2012")); + for (FinancialTransaction financialTransaction : financialTransactions) { + entries.addAll(financialTransaction.getEntry()); + } + Assert.assertTrue(entries.isEmpty()); + + // test import + FileInputStream contentStream = null; + ImportResult result; + try { + contentStream = new FileInputStream(tmpDir + "export-entries-EBP.csv"); + String inputStream = IOUtils.toString(contentStream); + result = newImportService.importEntriesFromEbp(inputStream); + } finally { + IOUtils.closeQuietly(contentStream); + } + + // valid import + financialTransactions = financialTransactionService.getAllFinancialTransactions(df.parse("April 4, 2012"),df.parse("December 31, 2012")); + Assert.assertEquals(1, financialTransactions.size()); + for (FinancialTransaction financialTransaction : financialTransactions) { + entries.addAll(financialTransaction.getEntry()); + } + + Assert.assertEquals(nbEntities, entries.size()); + Assert.assertEquals(nbEntities, result.getNbCreated()); + Assert.assertTrue(result.getException().getAllExceptionsByLine().isEmpty()); + for (Entry entry : entries) { + Assert.assertTrue(42.0 == entry.getAmount().doubleValue()); + } + } + + protected void importEBPData() throws IOException, ParseException, BeginAfterEndFiscalPeriodException, + NotBeginNextDayOfLastFiscalPeriodException, MoreOneUnlockFiscalPeriodException, ImportEbpException { + + // create fiscal period (mandatory for import) + FiscalPeriod fiscalPeriod = new FiscalPeriodImpl(); + fiscalPeriod.setBeginDate(df.parse("January 1, 2012")); + fiscalPeriod.setEndDate(df.parse("December 31, 2012")); + fiscalPeriodService.createFiscalPeriod(fiscalPeriod); + + // import files + InputStream accountStream = null, entryBookStream = null, entriesStream = null; + try { + accountStream = NewImportExportServiceTest.class.getResourceAsStream("/ebp/comptes.txt"); + entryBookStream = NewImportExportServiceTest.class.getResourceAsStream("/ebp/journaux.txt"); + entriesStream = NewImportExportServiceTest.class.getResourceAsStream("/ebp/ecritures.txt"); + + newImportService.importAccountFromEbp(IOUtils.toString(accountStream, "ISO-8859-1")); + newImportService.importEntryBookFromEbp(IOUtils.toString(entryBookStream, "ISO-8859-1")); + newImportService.importEntriesFromEbp(IOUtils.toString(entriesStream, "ISO-8859-1")); + } + finally { + IOUtils.closeQuietly(accountStream); + IOUtils.closeQuietly(entryBookStream); + IOUtils.closeQuietly(entriesStream); + } + } + + /** + * Do some test on imported accounts. + * + * @throws Exception + */ + @Test + public void testImportAccountsEBP() throws Exception { + importEBPData(); + + Assert.assertEquals(571, accountService.getAllAccounts().size()); + Assert.assertEquals("Créances", accountService.getAccountByNumber("78174000").getLabel()); + + // test employe and client + Assert.assertNotNull(accountService.getAccountByNumber("401TEEMP")); + Assert.assertNotNull(accountService.getAccountByNumber("411TECLI")); + } + + /** + * Test que les comptes tiers sont correctement rattachés à l'arbre du + * plan comptable. + * + * @throws Exception + */ + @Test + public void testImportCreateIntermediateAccount() throws Exception { + importEBPData(); + + Account compteTiers = accountService.getAccountByNumber("4"); + Account employeAccount = accountService.getAccountByNumber("401TEEMP"); + Assert.assertNotNull(compteTiers); + Assert.assertNotNull(employeAccount); + } } Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/accountingrules/ImportServiceRuleFrTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/accountingrules/ImportServiceRuleFrTest.java 2014-07-31 19:50:37 UTC (rev 3887) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/accountingrules/ImportServiceRuleFrTest.java 2014-08-01 14:20:36 UTC (rev 3888) @@ -24,8 +24,8 @@ package org.chorem.lima.business.accountingrules; import org.chorem.lima.business.AccountingRules; -import org.chorem.lima.business.ImportServiceImplTest; import org.chorem.lima.business.LimaConfig; +import org.chorem.lima.business.NewImportExportServiceTest; import org.junit.Assert; import org.junit.Test; @@ -44,7 +44,7 @@ * Last update : $Date$ * By : $Author$ */ -public class ImportServiceRuleFrTest extends ImportServiceImplTest { +public class ImportServiceRuleFrTest extends NewImportExportServiceTest { protected Properties getTestConfiguration() { Properties config = super.getTestConfiguration(); Deleted: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ExportService.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ExportService.java 2014-07-31 19:50:37 UTC (rev 3887) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ExportService.java 2014-08-01 14:20:36 UTC (rev 3888) @@ -1,88 +0,0 @@ -/* - * #%L - * Lima business - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2008 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * 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, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.lima.business.api; - -import org.chorem.lima.business.LimaException; - -/** - * Import export service. - * <p/> - * Currently import and export as XML. - * - * @author chatellier - * @version $Revision$ - * <p/> - * Last update : $Date$ - * By : $Author$ - */ -public interface ExportService { - - - /** - * Get database export as CSV; - * - * @return export as byte array - * @throws LimaException - */ - String exportAsCSV(); - - /** - * export entrybook chart as CSV. - */ - String exportEntryBookChartAsCSV(); - - /** - * export financialstatement chart as CSV. - */ - String exportFinancialStatementChartAsCSV(); - - /** - * export vatstatement chart as CSV - */ - String exportVatStatementChartAsCSV(); - - /** - * export accounts chart as CSV. - */ - String exportAccountsChartAsCSV(); - - /** - * export entries as EBP - */ - String exportEntriesAsEBP(); - - /** - * export accounts as EBP - */ - String exportAccountsAsEBP(); - - /** - * export entryBooks as EBP - * @return - * @throws LimaException - */ - String exportEntryBooksAsEBP(); -} Deleted: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ExportServiceLocal.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ExportServiceLocal.java 2014-07-31 19:50:37 UTC (rev 3887) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ExportServiceLocal.java 2014-08-01 14:20:36 UTC (rev 3888) @@ -1,41 +0,0 @@ -/* - * #%L - * Lima business - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2008 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * 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, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.lima.business.api; - -/** - * Import export service. - * <p/> - * Currently import and export as XML. - * - * @author chatellier - * @version $Revision$ - * <p/> - * Last update : $Date$ - * By : $Author$ - */ -public interface ExportServiceLocal extends ExportService { - -} Deleted: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ImportService.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ImportService.java 2014-07-31 19:50:37 UTC (rev 3887) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ImportService.java 2014-08-01 14:20:36 UTC (rev 3888) @@ -1,56 +0,0 @@ -/* - * #%L - * Lima business - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2008 - 2012 CodeLutin, Chatellier Eric - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * 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, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.lima.business.api; - -import org.chorem.lima.business.ImportEbpException; -import org.chorem.lima.business.LimaException; -import org.chorem.lima.business.utils.ImportExportEntityEnum; - -/** - * Import export service. - * Currently import and export as CSV and EBP. - */ -public interface ImportService { - - /** - * Import accounts as EBP import. - * - * @param data import file content as string (remote service can't take File) - * @return result log - * @throws LimaException - */ - String importAccountsChartFromEbp(String data) throws ImportEbpException; - - /** - * @deprecated import file (local, can't be used in remote mode) - * and wrong place for this method - */ - String importAsPDF(String data, - ImportExportEntityEnum importExportEntityEnum, - boolean saveMode); - - -} Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/NewExportService.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/NewExportService.java 2014-07-31 19:50:37 UTC (rev 3887) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/NewExportService.java 2014-08-01 14:20:36 UTC (rev 3888) @@ -38,7 +38,7 @@ */ public interface NewExportService { - String exportBackup(String charset); + //####################################### CSV ############################################## String exportAccountsAsCSV(String charset); @@ -51,4 +51,14 @@ String exportFinancialStatements(String charset) throws Exception; String exportVatStatements(String charset) throws Exception; + + String exportBackup(String charset); + + //####################################### EBP ############################################## + + String exportAccountAsEbp(String charset) throws Exception; + + String exportEntriesAsEbp(String charset) throws Exception; + + String exportEntryBookAsEbp(String charset) throws Exception; } Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/NewImportService.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/NewImportService.java 2014-07-31 19:50:37 UTC (rev 3887) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/NewImportService.java 2014-08-01 14:20:36 UTC (rev 3888) @@ -33,6 +33,8 @@ */ public interface NewImportService { + //####################################### CSV ############################################## + ImportResult importAccountAsCSV(String contents); ImportResult importEntryBooksAsCSV(String contents); @@ -47,7 +49,15 @@ List<ImportResult> importBackup(String entryBooks, String transactions, String fiscalPeriods, String accounts, String entries, String identity) throws AlreadyExistAccountException, InvalidAccountNumberException; + //####################################### EBP ############################################## + + ImportResult importAccountFromEbp(String datas); + ImportResult importEntriesFromEbp(String datas); ImportResult importEntryBookFromEbp(String datas); + +// String importAsPDF(String data, +// ImportExportEntityEnum importExportEntityEnum, +// boolean saveMode); } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java 2014-07-31 19:50:37 UTC (rev 3887) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java 2014-08-01 14:20:36 UTC (rev 3888) @@ -33,7 +33,7 @@ import org.chorem.lima.business.ServiceListener; import org.chorem.lima.business.UsedAccountException; import org.chorem.lima.business.api.AccountService; -import org.chorem.lima.business.api.ImportService; +import org.chorem.lima.business.api.NewImportService; import org.chorem.lima.entity.Account; import org.chorem.lima.enums.AccountsChartEnum; import org.chorem.lima.enums.ImportExportEnum; @@ -46,12 +46,7 @@ import org.jdesktop.swingx.treetable.MutableTreeTableNode; import org.jdesktop.swingx.treetable.TreeTableNode; -import javax.swing.AbstractAction; -import javax.swing.ActionMap; -import javax.swing.InputMap; -import javax.swing.JComponent; -import javax.swing.JOptionPane; -import javax.swing.KeyStroke; +import javax.swing.*; import javax.swing.tree.TreePath; import java.awt.event.ActionEvent; import java.awt.event.InputEvent; @@ -122,7 +117,7 @@ public AccountViewHandler(AccountView view) { this.view = view; // Gets factory service - LimaServiceFactory.addServiceListener(ImportService.class, this); + LimaServiceFactory.addServiceListener(NewImportService.class, this); accountService = LimaServiceFactory.getService(AccountService.class); errorHelper = new ErrorHelper(LimaConfig.getInstance()); } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/AccountComboBoxModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/AccountComboBoxModel.java 2014-07-31 19:50:37 UTC (rev 3887) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/AccountComboBoxModel.java 2014-08-01 14:20:36 UTC (rev 3888) @@ -29,12 +29,11 @@ import org.apache.commons.logging.LogFactory; import org.chorem.lima.business.ServiceListener; import org.chorem.lima.business.api.AccountService; -import org.chorem.lima.business.api.ImportService; +import org.chorem.lima.business.api.NewImportService; import org.chorem.lima.entity.Account; import org.chorem.lima.service.LimaServiceFactory; -import javax.swing.AbstractListModel; -import javax.swing.ComboBoxModel; +import javax.swing.*; import java.util.List; /** Account combo box model. */ @@ -57,7 +56,7 @@ LimaServiceFactory.getService( AccountService.class); LimaServiceFactory.addServiceListener(AccountService.class, this); - LimaServiceFactory.addServiceListener(ImportService.class, this); + LimaServiceFactory.addServiceListener(NewImportService.class, this); datasCache = getDataList(); } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/EntryBookComboBoxModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/EntryBookComboBoxModel.java 2014-07-31 19:50:37 UTC (rev 3887) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/EntryBookComboBoxModel.java 2014-08-01 14:20:36 UTC (rev 3888) @@ -29,12 +29,11 @@ import org.apache.commons.logging.LogFactory; import org.chorem.lima.business.ServiceListener; import org.chorem.lima.business.api.EntryBookService; -import org.chorem.lima.business.api.ImportService; +import org.chorem.lima.business.api.NewImportService; import org.chorem.lima.entity.EntryBook; import org.chorem.lima.service.LimaServiceFactory; -import javax.swing.AbstractListModel; -import javax.swing.ComboBoxModel; +import javax.swing.*; import java.util.List; /** @@ -63,7 +62,7 @@ entryBookService = LimaServiceFactory.getService(EntryBookService.class); LimaServiceFactory.addServiceListener(EntryBookService.class, this); - LimaServiceFactory.addServiceListener(ImportService.class, this); + LimaServiceFactory.addServiceListener(NewImportService.class, this); cacheDatas = getDataList(); } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/FinancialPeriodComboBoxModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/FinancialPeriodComboBoxModel.java 2014-07-31 19:50:37 UTC (rev 3887) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/FinancialPeriodComboBoxModel.java 2014-08-01 14:20:36 UTC (rev 3888) @@ -30,13 +30,12 @@ import org.chorem.lima.business.ServiceListener; import org.chorem.lima.business.api.FinancialPeriodService; import org.chorem.lima.business.api.FiscalPeriodService; -import org.chorem.lima.business.api.ImportService; +import org.chorem.lima.business.api.NewImportService; import org.chorem.lima.entity.FinancialPeriod; import org.chorem.lima.entity.FiscalPeriod; import org.chorem.lima.service.LimaServiceFactory; -import javax.swing.AbstractListModel; -import javax.swing.ComboBoxModel; +import javax.swing.*; import java.util.List; /** @@ -85,7 +84,7 @@ FinancialPeriodService.class); LimaServiceFactory.addServiceListener(FinancialPeriodService.class, this); LimaServiceFactory.addServiceListener(FiscalPeriodService.class, this); - LimaServiceFactory.addServiceListener(ImportService.class, this); + LimaServiceFactory.addServiceListener(NewImportService.class, this); if (displayAllPeriods) { datasCache = getAllDataList(); } else { Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/FiscalPeriodComboBoxModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/FiscalPeriodComboBoxModel.java 2014-07-31 19:50:37 UTC (rev 3887) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/FiscalPeriodComboBoxModel.java 2014-08-01 14:20:36 UTC (rev 3888) @@ -29,12 +29,11 @@ import org.apache.commons.logging.LogFactory; import org.chorem.lima.business.ServiceListener; import org.chorem.lima.business.api.FiscalPeriodService; -import org.chorem.lima.business.api.ImportService; +import org.chorem.lima.business.api.NewImportService; import org.chorem.lima.entity.FiscalPeriod; import org.chorem.lima.service.LimaServiceFactory; -import javax.swing.AbstractListModel; -import javax.swing.ComboBoxModel; +import javax.swing.*; import java.util.List; public class FiscalPeriodComboBoxModel extends AbstractListModel implements ComboBoxModel, ServiceListener { @@ -55,7 +54,7 @@ LimaServiceFactory.getService( FiscalPeriodService.class); LimaServiceFactory.addServiceListener(FiscalPeriodService.class, this); - LimaServiceFactory.addServiceListener(ImportService.class, this); + LimaServiceFactory.addServiceListener(NewImportService.class, this); datasCache = getDataList(); if (log.isDebugEnabled()) { @@ -70,7 +69,7 @@ LimaServiceFactory.getService( FiscalPeriodService.class); LimaServiceFactory.addServiceListener(FiscalPeriodService.class, this); - LimaServiceFactory.addServiceListener(ImportService.class, this); + LimaServiceFactory.addServiceListener(NewImportService.class, this); datasCache = getAllDataList(); } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/LeafAccountComboBoxModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/LeafAccountComboBoxModel.java 2014-07-31 19:50:37 UTC (rev 3887) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/LeafAccountComboBoxModel.java 2014-08-01 14:20:36 UTC (rev 3888) @@ -29,13 +29,12 @@ import org.apache.commons.logging.LogFactory; import org.chorem.lima.business.ServiceListener; import org.chorem.lima.business.api.AccountService; -import org.chorem.lima.business.api.ImportService; +import org.chorem.lima.business.api.NewImportService; import org.chorem.lima.business.utils.AccountComparator; import org.chorem.lima.entity.Account; import org.chorem.lima.service.LimaServiceFactory; -import javax.swing.AbstractListModel; -import javax.swing.ComboBoxModel; +import javax.swing.*; import java.util.Collections; import java.util.List; @@ -58,7 +57,7 @@ accountService = LimaServiceFactory.getService(AccountService.class); LimaServiceFactory.addServiceListener(AccountService.class, this); - LimaServiceFactory.addServiceListener(ImportService.class, this); + LimaServiceFactory.addServiceListener(NewImportService.class, this); datasCache = getDataList(); } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookViewHandler.java 2014-07-31 19:50:37 UTC (rev 3887) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookViewHandler.java 2014-08-01 14:20:36 UTC (rev 3888) @@ -28,10 +28,10 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.LimaConfig; -import org.chorem.lima.business.UsedEntryBookException; import org.chorem.lima.business.ServiceListener; +import org.chorem.lima.business.UsedEntryBookException; import org.chorem.lima.business.api.EntryBookService; -import org.chorem.lima.business.api.ImportService; +import org.chorem.lima.business.api.NewImportService; import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.EntryBookImpl; import org.chorem.lima.enums.EntryBooksChartEnum; @@ -41,12 +41,7 @@ import org.chorem.lima.util.ErrorHelper; import org.jdesktop.swingx.JXTable; -import javax.swing.AbstractAction; -import javax.swing.ActionMap; -import javax.swing.InputMap; -import javax.swing.JComponent; -import javax.swing.JOptionPane; -import javax.swing.KeyStroke; +import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; @@ -77,7 +72,7 @@ public EntryBookViewHandler(EntryBookView view) { this.view = view; entryBookService = LimaServiceFactory.getService(EntryBookService.class); - LimaServiceFactory.addServiceListener(ImportService.class, this); + LimaServiceFactory.addServiceListener(NewImportService.class, this); errorHelper = new ErrorHelper(LimaConfig.getInstance()); } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodViewHandler.java 2014-07-31 19:50:37 UTC (rev 3887) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodViewHandler.java 2014-08-01 14:20:36 UTC (rev 3888) @@ -36,7 +36,7 @@ import org.chorem.lima.business.WithoutEntryBookFinancialTransactionsException; import org.chorem.lima.business.api.FinancialPeriodService; import org.chorem.lima.business.api.FiscalPeriodService; -import org.chorem.lima.business.api.ImportService; +import org.chorem.lima.business.api.NewImportService; import org.chorem.lima.business.utils.FinancialPeriodComparator; import org.chorem.lima.entity.ClosedPeriodicEntryBook; import org.chorem.lima.entity.Entry; @@ -46,12 +46,7 @@ import org.chorem.lima.util.ErrorHelper; import org.jdesktop.swingx.JXTable; -import javax.swing.AbstractAction; -import javax.swing.ActionMap; -import javax.swing.InputMap; -import javax.swing.JComponent; -import javax.swing.JOptionPane; -import javax.swing.KeyStroke; +import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; import java.util.Collections; @@ -82,7 +77,7 @@ this.view = view; financialPeriodService = LimaServiceFactory.getService(FinancialPeriodService.class); - LimaServiceFactory.addServiceListener(ImportService.class, this); + LimaServiceFactory.addServiceListener(NewImportService.class, this); LimaServiceFactory.addServiceListener(FiscalPeriodService.class, this); errorHelper = new ErrorHelper(LimaConfig.getInstance()); } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartViewHandler.java 2014-07-31 19:50:37 UTC (rev 3887) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartViewHandler.java 2014-08-01 14:20:36 UTC (rev 3888) @@ -29,7 +29,7 @@ import org.apache.commons.logging.LogFactory; import org.chorem.lima.business.ServiceListener; import org.chorem.lima.business.api.FinancialStatementService; -import org.chorem.lima.business.api.ImportService; +import org.chorem.lima.business.api.NewImportService; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.FinancialStatement; import org.chorem.lima.entity.FinancialStatementImpl; @@ -41,15 +41,9 @@ import org.jdesktop.swingx.JXTreeTable; import org.nuiton.util.Resource; -import javax.swing.AbstractAction; -import javax.swing.ActionMap; -import javax.swing.InputMap; -import javax.swing.JComponent; -import javax.swing.JOptionPane; -import javax.swing.JTextArea; -import javax.swing.KeyStroke; +import javax.swing.*; import javax.swing.tree.TreePath; -import java.awt.Component; +import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.InputEvent; import java.awt.event.KeyEvent; @@ -80,7 +74,7 @@ financialStatementService = LimaServiceFactory.getService( FinancialStatementService.class); - LimaServiceFactory.addServiceListener(ImportService.class, this); + LimaServiceFactory.addServiceListener(NewImportService.class, this); init(); } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java 2014-07-31 19:50:37 UTC (rev 3887) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java 2014-08-01 14:20:36 UTC (rev 3888) @@ -39,7 +39,7 @@ import org.chorem.lima.business.api.FinancialPeriodService; import org.chorem.lima.business.api.FinancialTransactionService; import org.chorem.lima.business.api.FiscalPeriodService; -import org.chorem.lima.business.api.ImportService; +import org.chorem.lima.business.api.NewImportService; import org.chorem.lima.entity.Entry; import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.EntryImpl; @@ -51,14 +51,7 @@ import org.chorem.lima.ui.common.FinancialTransactionTableModel; import org.chorem.lima.util.ErrorHelper; -import javax.swing.AbstractAction; -import javax.swing.ActionMap; -import javax.swing.InputMap; -import javax.swing.JComboBox; -import javax.swing.JComponent; -import javax.swing.JOptionPane; -import javax.swing.KeyStroke; -import javax.swing.ListSelectionModel; +import javax.swing.*; import javax.swing.event.ChangeEvent; import javax.swing.event.ListSelectionEvent; import javax.swing.event.TableColumnModelEvent; @@ -112,7 +105,7 @@ financialTransactionService = LimaServiceFactory.getService(FinancialTransactionService.class); LimaServiceFactory.addServiceListener(FinancialPeriodService.class, this); LimaServiceFactory.addServiceListener(FiscalPeriodService.class, this); - LimaServiceFactory.addServiceListener(ImportService.class, this); + LimaServiceFactory.addServiceListener(NewImportService.class, this); errorHelper = new ErrorHelper(LimaConfig.getInstance()); initShortCuts(); } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/AccountsPane.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/AccountsPane.java 2014-07-31 19:50:37 UTC (rev 3887) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/AccountsPane.java 2014-08-01 14:20:36 UTC (rev 3888) @@ -30,7 +30,7 @@ import org.chorem.lima.LimaContext; import org.chorem.lima.business.ServiceListener; import org.chorem.lima.business.api.AccountService; -import org.chorem.lima.business.api.ImportService; +import org.chorem.lima.business.api.NewImportService; import org.chorem.lima.service.LimaServiceFactory; import org.chorem.lima.ui.MainView; @@ -60,7 +60,7 @@ accountService = LimaServiceFactory.getService(AccountService.class); LimaServiceFactory.addServiceListener(AccountService.class, this); - LimaServiceFactory.addServiceListener(ImportService.class, this); + LimaServiceFactory.addServiceListener(NewImportService.class, this); refresh(); } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/EntryBooksPane.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/EntryBooksPane.java 2014-07-31 19:50:37 UTC (rev 3887) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/EntryBooksPane.java 2014-08-01 14:20:36 UTC (rev 3888) @@ -30,7 +30,7 @@ import org.chorem.lima.LimaContext; import org.chorem.lima.business.ServiceListener; import org.chorem.lima.business.api.EntryBookService; -import org.chorem.lima.business.api.ImportService; +import org.chorem.lima.business.api.NewImportService; import org.chorem.lima.entity.EntryBook; import org.chorem.lima.service.LimaServiceFactory; import org.chorem.lima.ui.MainView; @@ -62,7 +62,7 @@ entryBookService = LimaServiceFactory.getService(EntryBookService.class); LimaServiceFactory.addServiceListener(EntryBookService.class, this); - LimaServiceFactory.addServiceListener(ImportService.class, this); + LimaServiceFactory.addServiceListener(NewImportService.class, this); refresh(); } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/FinancialTransactionsPane.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/FinancialTransactionsPane.java 2014-07-31 19:50:37 UTC (rev 3887) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/FinancialTransactionsPane.java 2014-08-01 14:20:36 UTC (rev 3888) @@ -32,7 +32,7 @@ import org.chorem.lima.business.api.EntryBookService; import org.chorem.lima.business.api.FinancialTransactionService; import org.chorem.lima.business.api.FiscalPeriodService; -import org.chorem.lima.business.api.ImportService; +import org.chorem.lima.business.api.NewImportService; import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.FinancialTransaction; import org.chorem.lima.entity.FiscalPeriod; @@ -73,7 +73,7 @@ entryBookService = LimaServiceFactory.getService(EntryBookService.class); LimaServiceFactory.addServiceListener(FinancialTransactionService.class, this); LimaServiceFactory.addServiceListener(FiscalPeriodService.class, this); - LimaServiceFactory.addServiceListener(ImportService.class, this); + LimaServiceFactory.addServiceListener(NewImportService.class, this); refresh(); } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/FiscalYearsPane.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/FiscalYearsPane.java 2014-07-31 19:50:37 UTC (rev 3887) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/FiscalYearsPane.java 2014-08-01 14:20:36 UTC (rev 3888) @@ -30,7 +30,7 @@ import org.chorem.lima.LimaContext; import org.chorem.lima.business.ServiceListener; import org.chorem.lima.business.api.FiscalPeriodService; -import org.chorem.lima.business.api.ImportService; +import org.chorem.lima.business.api.NewImportService; import org.chorem.lima.entity.FiscalPeriod; import org.chorem.lima.service.LimaServiceFactory; import org.chorem.lima.ui.MainView; @@ -68,7 +68,7 @@ fiscalPeriodService = LimaServiceFactory.getService(FiscalPeriodService.class); LimaServiceFactory.addServiceListener(FiscalPeriodService.class, this); - LimaServiceFactory.addServiceListener(ImportService.class, this); + LimaServiceFactory.addServiceListener(NewImportService.class, this); refresh(); } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java 2014-07-31 19:50:37 UTC (rev 3887) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java 2014-08-01 14:20:36 UTC (rev 3888) @@ -35,11 +35,8 @@ import org.chorem.lima.LimaTechnicalException; import org.chorem.lima.business.ImportEbpException; import org.chorem.lima.business.ImportResult; -import org.chorem.lima.business.api.ExportService; -import org.chorem.lima.business.api.ImportService; import org.chorem.lima.business.api.NewExportService; import org.chorem.lima.business.api.NewImportService; -import org.chorem.lima.business.utils.ImportExportEntityEnum; import org.chorem.lima.enums.EncodingEnum; import org.chorem.lima.enums.ImportExportEnum; import org.chorem.lima.service.LimaServiceFactory; @@ -85,10 +82,10 @@ */ protected EncodingEnum encodingEnum; - protected ImportService importService; + protected NewImportService importService; @Deprecated - protected ExportService exportService; + protected NewExportService exportService; protected NewImportService newImportService; @@ -102,8 +99,6 @@ viewComponent = view; //services - importService = LimaServiceFactory.getService(ImportService.class); - exportService = LimaServiceFactory.getService(ExportService.class); newImportService = LimaServiceFactory.getService(NewImportService.class); newExportService = LimaServiceFactory.getService(NewExportService.class); @@ -143,101 +138,91 @@ ImportResult importResult; try { switch (importExportMethodeF) { - case CSV_ALL_EXPORT: - datas = newExportService.exportBackup(charset.name()); - createZipFile(filePath, datas); - break; + //####################################### CSV ############################################## + case CSV_ACCOUNTCHARTS_EXPORT: datas = newExportService.exportAccountsAsCSV(charset.name()); createFile(filePath, charset.name(), datas); break; + + case CSV_ACCOUNTCHARTS_IMPORT: + datas = extractFile(filePath, charset.name()); + importResult = newImportService.importAccountAsCSV(datas); + // TODO DCossé 24/07/14 change result + result = "SUCCESS"; + break; + case CSV_ENTRYBOOKS_EXPORT: datas = newExportService.exportEntryBooksAsCSV(charset.name()); createFile(filePath, charset.name(), datas); break; + case CSV_ENTRYBOOKS_IMPORT: + datas = extractFile(filePath, charset.name()); + importResult = newImportService.importEntryBooksAsCSV(datas); + // TODO DCossé 24/07/14 change result + result = "SUCCESS"; + break; case CSV_ENTRIES_EXPORT: datas = newExportService.exportEntriesAsCSV(charset.name(), true); createFile(filePath, charset.name(), datas); break; - case CSV_FINANCIALSTATEMENTS_EXPORT: - try { - datas = newExportService.exportFinancialStatements(charset.name()); - createFile(filePath, charset.name(), datas); - } catch (Exception e) { - e.printStackTrace(); - } + case CSV_ENTRIES_IMPORT: + datas = extractFile(filePath, charset.name()); + importResult = newImportService.importEntriesAsCSV(datas); + // TODO DCossé 24/07/14 change result + result = "SUCCESS"; break; - case CSV_VAT_EXPORT: - try { - datas = newExportService.exportVatStatements(charset.name()); - createFile(filePath, charset.name(), datas); - } catch (Exception e) { - e.printStackTrace(); - } + + case CSV_ALL_EXPORT: + datas = newExportService.exportBackup(charset.name()); + createZipFile(filePath, datas); break; - case EBP_ACCOUNTCHARTS_EXPORT: - //For windows ebp - datas = exportService.exportAccountsAsEBP(); - createFile(filePath, EncodingEnum.ISOLATIN1.getEncoding(), datas); - break; - case EBP_ENTRIES_EXPORT: - //For windows ebp - datas = exportService.exportEntriesAsEBP(); - createFile(filePath, EncodingEnum.ISOLATIN1.getEncoding(), datas); - break; case CSV_ALL_IMPORT: List<ImportResult> allResults = importAllFromZipFile(filePath); // TODO DCossé 24/07/14 change result result = "SUCCESS"; break; - case CSV_ACCOUNTCHARTS_IMPORT: - datas = extractFile(filePath, charset.name()); - importResult = newImportService.importAccountAsCSV(datas); - // TODO DCossé 24/07/14 change result - result = "SUCCESS"; + + case CSV_VAT_EXPORT: + datas = newExportService.exportVatStatements(charset.name()); + createFile(filePath, charset.name(), datas); break; - case CSV_ENTRYBOOKS_IMPORT: + case CSV_VAT_IMPORT: datas = extractFile(filePath, charset.name()); - importResult = newImportService.importEntryBooksAsCSV(datas); + importResult = newImportService.importVATStatementsAsCSV(datas); // TODO DCossé 24/07/14 change result result = "SUCCESS"; break; + + case CSV_FINANCIALSTATEMENTS_EXPORT: + datas = newExportService.exportFinancialStatements(charset.name()); + createFile(filePath, charset.name(), datas); + break; case CSV_FINANCIALSTATEMENTS_IMPORT: datas = extractFile(filePath, charset.name()); importResult = newImportService.importFinancialStatementsAsCSV(datas); // TODO DCossé 24/07/14 change result result = "SUCCESS"; break; - case CSV_ENTRIES_IMPORT: - datas = extractFile(filePath, charset.name()); - importResult = newImportService.importEntriesAsCSV(datas); - // TODO DCossé 24/07/14 change result - result = "SUCCESS"; + + //####################################### EBP ############################################## + + case EBP_ACCOUNTCHARTS_EXPORT: + //For windows ebp + datas = newExportService.exportAccountAsEbp(charset.name()); + createFile(filePath, EncodingEnum.ISOLATIN1.getEncoding(), datas); break; - case CSV_VAT_IMPORT: - datas = extractFile(filePath, charset.name()); - importResult = newImportService.importVATStatementsAsCSV(datas); - // TODO DCossé 24/07/14 change result - result = "SUCCESS"; - break; - case PDF_VAT_IMPORT: - int response = JOptionPane.showConfirmDialog(waitView, - t("lima.importexport.usevatpdf"), - t("lima.common.confirmation"), JOptionPane.YES_NO_OPTION); - extractFile(filePath, charset.name()); - result = importService.importAsPDF(filePath, ImportExportEntityEnum.VATPDF, response == JOptionPane.YES_OPTION); - break; case EBP_ACCOUNTCHARTS_IMPORT: //For windows ebp datas = extractFile(filePath, EncodingEnum.ISOLATIN1.getEncoding()); - result = importService.importAccountsChartFromEbp(datas); + importResult = newImportService.importAccountFromEbp(datas); // TODO DCossé 24/07/14 change result result = "SUCCESS"; break; - case EBP_ENTRIES_IMPORT: - //For windows ebp - datas = extractFile(filePath, EncodingEnum.ISOLATIN1.getEncoding()); - importResult = newImportService.importEntriesFromEbp(datas); + + case EBP_ENTRYBOOKS_EXPORT: + datas = newExportService.exportEntryBookAsEbp(charset.name()); + createFile(filePath, EncodingEnum.ISOLATIN1.getEncoding(), datas); break; case EBP_ENTRYBOOKS_IMPORT: datas = extractFile(filePath, EncodingEnum.ISOLATIN1.getEncoding()); @@ -245,13 +230,23 @@ // TODO DCossé 24/07/14 change result result = "SUCCESS"; break; - case EBP_ENTRYBOOKS_EXPORT: - datas = exportService.exportEntryBooksAsEBP(); + + case EBP_ENTRIES_EXPORT: + //For windows ebp + datas = newExportService.exportEntriesAsEbp(charset.name()); createFile(filePath, EncodingEnum.ISOLATIN1.getEncoding(), datas); break; + case EBP_ENTRIES_IMPORT: + //For windows ebp + datas = extractFile(filePath, EncodingEnum.ISOLATIN1.getEncoding()); + importResult = newImportService.importEntriesFromEbp(datas); + break; } } catch (ImportEbpException e) { errorHelper.showErrorMessage(t(e.getMessage())); + } catch (Exception e) { + // TODO DCossé 01/08/14 it should be an other exception + e.printStackTrace(); } return result; } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartViewHandler.java 2014-07-31 19:50:37 UTC (rev 3887) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartViewHandler.java 2014-08-01 14:20:36 UTC (rev 3888) @@ -27,7 +27,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.business.ServiceListener; -import org.chorem.lima.business.api.ImportService; +import org.chorem.lima.business.api.NewImportService; import org.chorem.lima.business.api.VatStatementService; import org.chorem.lima.entity.VatStatement; import org.chorem.lima.entity.VatStatementImpl; @@ -35,15 +35,9 @@ import org.chorem.lima.enums.VatStatementsChartEnum; import org.chorem.lima.service.LimaServiceFactory; import org.chorem.lima.ui.importexport.ImportExport; -import org.chorem.lima.util.ErrorHelper; import org.jdesktop.swingx.JXTreeTable; -import javax.swing.AbstractAction; -import javax.swing.ActionMap; -import javax.swing.InputMap; -import javax.swing.JComponent; -import javax.swing.JOptionPane; -import javax.swing.KeyStroke; +import javax.swing.*; import javax.swing.tree.TreePath; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; @@ -65,7 +59,7 @@ vatStatementService = LimaServiceFactory.getService( VatStatementService.class); - LimaServiceFactory.addServiceListener(ImportService.class, this); + LimaServiceFactory.addServiceListener(NewImportService.class, this); init(); }