Author: dcosse Date: 2014-05-05 18:28:39 +0200 (Mon, 05 May 2014) New Revision: 3780 Url: http://forge.chorem.org/projects/lima/repository/revisions/3780 Log: refs #1016 ajout des imports/export des journaux. Il faut tester sous EBPCompta pour valider les exports Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ExportService.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.java trunk/lima-swing/src/main/java/org/chorem/lima/enums/ImportExportEnum.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java 2014-04-16 14:06:13 UTC (rev 3779) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java 2014-05-05 16:28:39 UTC (rev 3780) @@ -62,39 +62,39 @@ public EntryBook createEntryBook(EntryBook entryBook) throws LimaException { - EntryBook result; + EntryBook result = null; try { // check if entrybook with is name already exist EntryBookDAO entryBookDAO = getDaoHelper().getEntryBookDAO(); - EntryBook existingEntryBook = + result = entryBookDAO.findByCode(entryBook.getCode()); - if (existingEntryBook != null) { - throw new LimaBusinessException( + if (result != null) { + log.error( t("lima-business.entrybook.entrybookalreadyexist", entryBook.getCode())); - } + } else { + // creation du EntryBook + result = entryBookDAO.create(entryBook); - // creation du EntryBook - result = entryBookDAO.create(entryBook); + //create ClosedPeriodicEntryBook for all unblocked financial period + ClosedPeriodicEntryBookDAO closedPeriodicEntryBookDAO = + getDaoHelper().getClosedPeriodicEntryBookDAO(); + FinancialPeriodDAO financialPeriodDAO = + getDaoHelper().getFinancialPeriodDAO(); + // for all unblocked financialperiod + for (FinancialPeriod financialPeriod : financialPeriodDAO.findAllByLocked(false)) { - //create ClosedPeriodicEntryBook for all unblocked financial period - ClosedPeriodicEntryBookDAO closedPeriodicEntryBookDAO = - getDaoHelper().getClosedPeriodicEntryBookDAO(); - FinancialPeriodDAO financialPeriodDAO = - getDaoHelper().getFinancialPeriodDAO(); - // for all unblocked financialperiod - for (FinancialPeriod financialPeriod : financialPeriodDAO.findAllByLocked(false)) { - - //new closed periodic entrybook - ClosedPeriodicEntryBook closedPeriodicEntryBook = - new ClosedPeriodicEntryBookImpl(); - // set entrybook - closedPeriodicEntryBook.setEntryBook(entryBook); - // set financial period - closedPeriodicEntryBook.setFinancialPeriod(financialPeriod); - // create it - closedPeriodicEntryBookDAO.create(closedPeriodicEntryBook); + //new closed periodic entrybook + ClosedPeriodicEntryBook closedPeriodicEntryBook = + new ClosedPeriodicEntryBookImpl(); + // set entrybook + closedPeriodicEntryBook.setEntryBook(entryBook); + // set financial period + closedPeriodicEntryBook.setFinancialPeriod(financialPeriod); + // create it + closedPeriodicEntryBookDAO.create(closedPeriodicEntryBook); + } } } catch (TopiaException ex) { Modified: 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-04-16 14:06:13 UTC (rev 3779) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.java 2014-05-05 16:28:39 UTC (rev 3780) @@ -29,6 +29,7 @@ import org.apache.commons.lang3.StringUtils; import org.chorem.lima.FinancialStatementWayEnum; 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; @@ -51,6 +52,7 @@ import org.chorem.lima.entity.VatStatementDAO; import org.nuiton.topia.TopiaException; +import javax.ejb.EJB; import javax.ejb.Local; import javax.ejb.Remote; import javax.ejb.Stateless; @@ -80,6 +82,9 @@ protected final String DATE_PATTERN = "dd/MM/yyyy"; + @EJB + private EntryBookService entryBookService; + //############## EXPORT EBP /** @@ -200,7 +205,12 @@ CSVWriter.DEFAULT_SEPARATOR, CSVWriter.NO_QUOTE_CHARACTER); //export accounts - String[] nextLine = new String[10]; + String[] nextLine = new String[2]; + // Add the header line + nextLine[0] = "Numero"; + nextLine[1] = "Intitule"; + csvWriter.writeNext(nextLine); + // Récupère tous les comptes AccountDAO accountDAO = getDaoHelper().getAccountDAO(); List<Account> listAccount = accountDAO.findAll(); @@ -229,7 +239,55 @@ return out.getBuffer().toString(); } + @Override + public String exportEntryBooksAsEBP() throws LimaException { + 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] = entryBook.getLabel(); + // Ajoute la ligne au fichier + csvWriter.writeNext(nextLine); + } + } + + // Write cache in string + csvWriter.flush(); + + } catch (Exception ex) { + throw new LimaException("Can't export", ex); + } 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 */ Modified: 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-04-16 14:06:13 UTC (rev 3779) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ExportService.java 2014-05-05 16:28:39 UTC (rev 3780) @@ -79,5 +79,10 @@ */ String exportAccountsAsEBP() throws LimaException; - + /** + * export entryBooks as EBP + * @return + * @throws LimaException + */ + String exportEntryBooksAsEBP() throws LimaException; } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/enums/ImportExportEnum.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/enums/ImportExportEnum.java 2014-04-16 14:06:13 UTC (rev 3779) +++ trunk/lima-swing/src/main/java/org/chorem/lima/enums/ImportExportEnum.java 2014-05-05 16:28:39 UTC (rev 3780) @@ -35,8 +35,9 @@ CSV_VAT_EXPORT(false, true), CSV_VAT_IMPORT(true, true), CSV_ENTRIES_IMPORT(true, true), PDF_VAT_EXPORT(false, true), PDF_VAT_IMPORT(true, true), - EBP_ACCOUNTCHARTS_EXPORT(false, false), EBP_ENTRIES_EXPORT(false, false), - EBP_ACCOUNTCHARTS_IMPORT(true, false), EBP_ENTRIES_IMPORT(true, false); + EBP_ACCOUNTCHARTS_EXPORT(false, true), EBP_ENTRIES_EXPORT(false, true), + EBP_ACCOUNTCHARTS_IMPORT(true, true), EBP_ENTRIES_IMPORT(true, true), + EBP_ENTRYBOOKS_IMPORT(true, true),EBP_ENTRYBOOKS_EXPORT(false, true); private final Boolean importMode; Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainView.jaxx 2014-04-16 14:06:13 UTC (rev 3779) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainView.jaxx 2014-05-05 16:28:39 UTC (rev 3780) @@ -96,12 +96,16 @@ onActionPerformed='getHandler().showImportExportView(this, ImportExportEnum.EBP_ACCOUNTCHARTS_IMPORT)'/> <JMenuItem text="lima.ui.importexport.entries" onActionPerformed='getHandler().showImportExportView(this, ImportExportEnum.EBP_ENTRIES_IMPORT)'/> + <JMenuItem text="lima.ui.importexport.entrybooks" + onActionPerformed='getHandler().showImportExportView(this, ImportExportEnum.EBP_ENTRYBOOKS_IMPORT)'/> </JMenu> <JMenu text="lima.ui.importexport.export" actionIcon='export-element'> <JMenuItem text="lima.ui.importexport.accountcharts" onActionPerformed='getHandler().showImportExportView(this, ImportExportEnum.EBP_ACCOUNTCHARTS_EXPORT)'/> <JMenuItem text="lima.ui.importexport.entries" onActionPerformed='getHandler().showImportExportView(this, ImportExportEnum.EBP_ENTRIES_EXPORT)'/> + <JMenuItem text="lima.ui.importexport.entrybooks" + onActionPerformed='getHandler().showImportExportView(this, ImportExportEnum.EBP_ENTRYBOOKS_EXPORT)'/> </JMenu> </JMenu> <JSeparator/> 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-04-16 14:06:13 UTC (rev 3779) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java 2014-05-05 16:28:39 UTC (rev 3780) @@ -424,11 +424,10 @@ form.setLocationRelativeTo(view); form.setVisible(true); - ImportExport importExport = new ImportExport(view); - Object value = form.getButtonGroup().getSelectedValue(); // if action confirmed if (value != null) { + ImportExport importExport = new ImportExport(view); AccountsChartEnum defaultAccountsChartEnum = (AccountsChartEnum) value; //Import accounts chart 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-04-16 14:06:13 UTC (rev 3779) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookViewHandler.java 2014-05-05 16:28:39 UTC (rev 3780) @@ -262,6 +262,7 @@ Object value = form.getButtonGroup().getSelectedValue(); // if action confirmed if (value != null) { + EntryBooksChartEnum defaultEntryBooksEnum = (EntryBooksChartEnum) value; ImportExport importExport = new ImportExport(view); importExport.importExport(ImportExportEnum.CSV_ENTRYBOOKS_IMPORT, 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-04-16 14:06:13 UTC (rev 3779) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java 2014-05-05 16:28:39 UTC (rev 3780) @@ -186,7 +186,7 @@ int response = JOptionPane.showConfirmDialog(waitView, t("lima.importexport.usevatpdf"), t("lima.common.confirmation"), JOptionPane.YES_NO_OPTION); - datas = extractFile(filePath, charset.getEncoding()); + extractFile(filePath, charset.getEncoding()); result = importService.importAsPDF(filePath, ImportExportEntityEnum.VATPDF, response == JOptionPane.YES_OPTION); break; case EBP_ACCOUNTCHARTS_IMPORT: @@ -199,6 +199,14 @@ datas = extractFile(filePath, EncodingEnum.ISOLATIN1.getEncoding()); result = importService.importEntriesFromEbp(datas); break; + case EBP_ENTRYBOOKS_IMPORT: + datas = extractFile(filePath, EncodingEnum.ISOLATIN1.getEncoding()); + result = importService.importEntryBookFromEbp(datas); + break; + case EBP_ENTRYBOOKS_EXPORT: + datas = exportService.exportEntryBooksAsEBP(); + createFile(filePath, EncodingEnum.ISOLATIN1.getEncoding(), datas); + break; } return result; }