Author: echatellier Date: 2012-07-06 14:04:32 +0200 (Fri, 06 Jul 2012) New Revision: 3497 Url: http://chorem.org/repositories/revision/lima/3497 Log: fixes #685 : apply provided patch Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java trunk/lima-business/src/main/resources/i18n/lima-business_en_GB.properties trunk/lima-business/src/main/resources/i18n/lima-business_fr_FR.properties 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/importexport/ImportExport.java trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties Modified: 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 2012-07-06 10:17:38 UTC (rev 3496) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java 2012-07-06 12:04:32 UTC (rev 3497) @@ -396,11 +396,11 @@ public String importAllAsCSV(String datas) throws LimaException { StringBuilder result = new StringBuilder(); - LinkedHashMap<String, ArrayList<FinancialStatementImport>> financialStatements = - new LinkedHashMap<String, ArrayList<FinancialStatementImport>>(); + Map<String, List<FinancialStatementImport>> financialStatements = + new LinkedHashMap<String, List<FinancialStatementImport>>(); - LinkedHashMap<String, ArrayList<VatStatementImport>> vatStatements = - new LinkedHashMap<String, ArrayList<VatStatementImport>>(); + Map<String, List<VatStatementImport>> vatStatements = + new LinkedHashMap<String, List<VatStatementImport>>(); List<FiscalPeriod> fiscalPeriods = new ArrayList<FiscalPeriod>(); @@ -484,21 +484,31 @@ */ @Override public String importAsCSV(String datas, - ImportExportEntityEnum importExportEntityEnum) throws LimaException { + ImportExportEntityEnum importExportEntityEnum) + throws LimaException { StringBuilder result = new StringBuilder(); // FinancialStatements - LinkedHashMap<String, ArrayList<FinancialStatementImport>> financialStatements = null; + Map<String, List<FinancialStatementImport>> financialStatements = null; // VatStatement - LinkedHashMap<String, ArrayList<VatStatementImport>> vatStatements = null; + Map<String, List<VatStatementImport>> vatStatements = null; + // Transactions and entries + Map<Integer, FinancialTransactionImport> financialTransactions = null; + Map<Integer, List<EntryImport>> entries = null; + switch (importExportEntityEnum) { case FINANCIALSTATEMENT: - financialStatements = new LinkedHashMap<String, ArrayList<FinancialStatementImport>>(); + financialStatements = new LinkedHashMap<String, List<FinancialStatementImport>>(); break; case VATSTATEMENT: - vatStatements = new LinkedHashMap<String, ArrayList<VatStatementImport>>(); + vatStatements = new LinkedHashMap<String, List<VatStatementImport>>(); break; + case FINANCIALTRANSACTION: + case ENTRY: + financialTransactions = new HashMap<Integer, FinancialTransactionImport>(); + entries = new HashMap<Integer, List<EntryImport>>(); + break; } try { @@ -507,7 +517,9 @@ CSVReader csvReader = new CSVReader(new StringReader(datas), ';'); while ((nextLine = csvReader.readNext()) != null) { - if (ImportExportEntityEnum.valueOfLabel(nextLine[0]) == importExportEntityEnum) { + if (ImportExportEntityEnum.valueOfLabel(nextLine[0]) == importExportEntityEnum + || importExportEntityEnum == ImportExportEntityEnum.FINANCIALTRANSACTION + || importExportEntityEnum == ImportExportEntityEnum.ENTRY) { switch (importExportEntityEnum) { case ENTRYBOOK: result.append(importEntryBooksChartCSV(nextLine)); @@ -523,6 +535,23 @@ result.append(importVatStatementChartCSV(nextLine, vatStatements)); break; + case FINANCIALTRANSACTION: + case ENTRY: + // Entries and transactions always go along + ImportExportEntityEnum type = + ImportExportEntityEnum.valueOfLabel(nextLine[0]); + if (type != null) { + switch (type) { + case FINANCIALTRANSACTION: + importFinancialTransactionsCSV(nextLine, + financialTransactions); + break; + case ENTRY: + importEntriesCSV(nextLine, entries); + break; + } + } + break; } } } @@ -535,6 +564,11 @@ case VATSTATEMENT: result.append(createVatStatements(vatStatements)); break; + case FINANCIALTRANSACTION: + case ENTRY: + result.append(createFinancialTransactionsAndEntries( + financialTransactions, entries)); + break; } } catch (Exception ex) { @@ -597,31 +631,36 @@ /** * Import and create accounts Structure : TYPE | accountNumber | label - * | thirdparty | masterAccountNumber | generalLedgerNumber + * | [thirdparty] * - * @param nextLine - * @param topiaContext - * @return - * @throws LimaException + * @param nextLine The line to import + * @return Success or error message + * @throws LimaException If the line format is invalid * @throws TopiaException */ protected String importAccountsChartsCSV(String[] nextLine) throws LimaException, TopiaException { - + // Check line format + if (nextLine.length < 3 + || ! nextLine[0].equals(ImportExportEntityEnum.ACCOUNT.getLabel())) { + throw new LimaException(_("lima-business.import.lineformatmismatch")); + } + StringBuilder result = new StringBuilder(); - String accountNumber = nextLine[1]; - String label = nextLine[2]; - String thirdParty = nextLine[3]; AccountDAO accountDAO = getDaoHelper().getAccountDAO(); - - // if not exist, create it + String accountNumber = nextLine[1]; + // if not exists, create it if (accountDAO.findByAccountNumber(accountNumber) == null) { Account account = new AccountImpl(); account.setAccountNumber(accountNumber); + String label = nextLine[2]; account.setLabel(label); - account.setThirdParty(thirdParty); + if (nextLine.length > 3) { + String thirdParty = nextLine[3]; + account.setThirdParty(thirdParty); + } accountDAO.create(account); result.append(_("lima-business.import.accountadded", @@ -741,7 +780,7 @@ * @throws TopiaException */ protected String importFinancialsStatementChartCSV(String[] nextLine, - LinkedHashMap<String, ArrayList<FinancialStatementImport>> financialStatements) throws LimaException, TopiaException { + Map<String, List<FinancialStatementImport>> financialStatements) throws LimaException, TopiaException { StringBuilder result = new StringBuilder(); String label = nextLine[1]; @@ -802,7 +841,7 @@ * @throws TopiaException */ protected String importVatStatementChartCSV(String[] nextLine, - Map<String, ArrayList<VatStatementImport>> vatStatements) throws LimaException, TopiaException { + Map<String, List<VatStatementImport>> vatStatements) throws LimaException, TopiaException { StringBuilder result = new StringBuilder(); @@ -842,12 +881,10 @@ /** * Import and create financialtransactions Structure : TYPE | NumTransac | - * TransactionDate | AmountDebit | AmountCredit | FinancialPeriod BeginDate - * | FinancialPeriod EndDate | EntryBook Code + * TransactionDate | AmountDebit | AmountCredit | EntryBook Code * * @param nextLine * @param financialTransactions - * @param topiaContext * @throws LimaException */ protected void importFinancialTransactionsCSV(String[] nextLine, @@ -864,13 +901,10 @@ /** * Import and create entries Structure : TYPE | NumTransac | Description | - * Amount | Debit | Lettering | Detail | Voucher | Position - * | FinancialTransaction Date | FinancialTransaction EntryBookCode | - * FinancialTransaction AmountDebit | FinancialTransaction AmountCredit + * Amount | Debit | Lettering | Detail | Voucher | Position | Account * * @param nextLine * @param entries - * @param topiaContext * @throws LimaException */ protected void importEntriesCSV(String[] nextLine, @@ -904,13 +938,13 @@ * @deprecated do only one method import without bean use (and remove beans) */ @Deprecated - protected String createFinancialStatements(Map<String, ArrayList<FinancialStatementImport>> financialStatements) throws LimaException, TopiaException { + protected String createFinancialStatements(Map<String, List<FinancialStatementImport>> financialStatements) throws LimaException, TopiaException { StringBuilder result = new StringBuilder(); FinancialStatementDAO financialStatementDAO = getDaoHelper().getFinancialStatementDAO(); while (financialStatements.size() > 0) { - for (Iterator<ArrayList<FinancialStatementImport>> itr = financialStatements + for (Iterator<List<FinancialStatementImport>> itr = financialStatements .values().iterator(); itr.hasNext(); ) { List<FinancialStatementImport> financialStatementImports = itr.next(); @@ -987,14 +1021,14 @@ * @deprecated do only one method import without bean use (and remove beans) */ @Deprecated - protected String createVatStatements(Map<String, ArrayList<VatStatementImport>> vatStatements) throws LimaException, TopiaException { + protected String createVatStatements(Map<String, List<VatStatementImport>> vatStatements) throws LimaException, TopiaException { StringBuilder result = new StringBuilder(); VatStatementDAO vatStatementDAO = getDaoHelper().getVatStatementDAO(); while (vatStatements.size() > 0) { - for (Iterator<ArrayList<VatStatementImport>> itr = vatStatements + for (Iterator<List<VatStatementImport>> itr = vatStatements .values().iterator(); itr.hasNext(); ) { List<VatStatementImport> vatStatementImports = itr.next(); @@ -1161,7 +1195,6 @@ financialTransaction.addEntry(entry); } } - return result.toString(); } Modified: trunk/lima-business/src/main/resources/i18n/lima-business_en_GB.properties =================================================================== --- trunk/lima-business/src/main/resources/i18n/lima-business_en_GB.properties 2012-07-06 10:17:38 UTC (rev 3496) +++ trunk/lima-business/src/main/resources/i18n/lima-business_en_GB.properties 2012-07-06 12:04:32 UTC (rev 3497) @@ -85,6 +85,7 @@ lima-business.import.fiscalperiodadded=SUCCESS \: The fiscalPeriod %s - %s is created \! \n lima-business.import.fiscalperiodalreadyexist=FAILED \: The fiscal period %s - %s already exists \!\n lima-business.import.identityadded=SUCCESS \: The identity %s is created \! \n +lima-business.import.lineformatmismatch=Line format is invalid. lima-business.import.noaccount=ERROR \: This file contains no account lima-business.import.nofiscalperiodopen=FAILED \: No Fiscal period open \! \n lima-business.import.transactionadded=SUCCES \: FinancialTransaction, %s - %s, added\n Modified: trunk/lima-business/src/main/resources/i18n/lima-business_fr_FR.properties =================================================================== --- trunk/lima-business/src/main/resources/i18n/lima-business_fr_FR.properties 2012-07-06 10:17:38 UTC (rev 3496) +++ trunk/lima-business/src/main/resources/i18n/lima-business_fr_FR.properties 2012-07-06 12:04:32 UTC (rev 3497) @@ -85,6 +85,7 @@ lima-business.import.fiscalperiodadded=Succès \: Exercice %s - %s ajoutée \! \n lima-business.import.fiscalperiodalreadyexist=u00C9chec \: L'exerice %s - %s existe déjà \!\n lima-business.import.identityadded=Succès \: Identité %s ajoutée \! \n +lima-business.import.lineformatmismatch=Le format de la ligne est incorrect. lima-business.import.noaccount=Erreur \: Ce fichier ne contient aucun compte. lima-business.import.nofiscalperiodopen=u00C9chec \: Aucun exercice ouvert \! \n lima-business.import.transactionadded=Succès \: Transaction, %s, %s, ajoutée\n 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 2012-07-06 10:17:38 UTC (rev 3496) +++ trunk/lima-swing/src/main/java/org/chorem/lima/enums/ImportExportEnum.java 2012-07-06 12:04:32 UTC (rev 3497) @@ -33,6 +33,7 @@ CSV_ENTRYBOOKS_EXPORT(false, true), CSV_ENTRYBOOKS_IMPORT(true, true), CSV_FINANCIALSTATEMENTS_EXPORT(false, true), CSV_FINANCIALSTATEMENTS_IMPORT(true, true), 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); 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 2012-07-06 10:17:38 UTC (rev 3496) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainView.jaxx 2012-07-06 12:04:32 UTC (rev 3497) @@ -74,6 +74,8 @@ onActionPerformed='getHandler().showImportExportView(this, ImportExportEnum.CSV_FINANCIALSTATEMENTS_IMPORT)'/> <JMenuItem text="lima.ui.importexport.vatstatements" onActionPerformed='getHandler().showImportExportView(this, ImportExportEnum.CSV_VAT_IMPORT)'/> + <JMenuItem text="lima.ui.importexport.financialtransactions" + onActionPerformed='getHandler().showImportExportView(this, ImportExportEnum.CSV_ENTRIES_IMPORT)'/> </JMenu> <JMenu text="lima.ui.importexport.export" actionIcon='export-element'> <JMenuItem text="lima.ui.importexport.all" 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 2012-07-06 10:17:38 UTC (rev 3496) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java 2012-07-06 12:04:32 UTC (rev 3497) @@ -174,6 +174,10 @@ datas = extractFile(filePath, charset.getEncoding()); result = importService.importAsCSV(datas, ImportExportEntityEnum.VATSTATEMENT); break; + case CSV_ENTRIES_IMPORT: + datas = extractFile(filePath, charset.getEncoding()); + result = importService.importAsCSV(datas, ImportExportEntityEnum.ENTRY); + break; case PDF_VAT_IMPORT: int response = JOptionPane.showConfirmDialog(waitView, _("lima.importexport.usevatpdf"), Modified: trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties =================================================================== --- trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties 2012-07-06 10:17:38 UTC (rev 3496) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties 2012-07-06 12:04:32 UTC (rev 3497) @@ -311,6 +311,7 @@ lima.ui.importexport.export=Export lima.ui.importexport.export.terminated=Export terminated lima.ui.importexport.financialstatements=FinancialStatements chart +lima.ui.importexport.financialtransactions=Moves lima.ui.importexport.import= lima.ui.importexport.import.terminated=Import terminated lima.ui.importexport.import.vatpdfimport=The PDF has been imported. It can be found inside the Lima resources directory Modified: trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties =================================================================== --- trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties 2012-07-06 10:17:38 UTC (rev 3496) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties 2012-07-06 12:04:32 UTC (rev 3497) @@ -311,6 +311,7 @@ lima.ui.importexport.export=Export lima.ui.importexport.export.terminated=Export terminé lima.ui.importexport.financialstatements=Plan BCR +lima.ui.importexport.financialtransactions=Écritures lima.ui.importexport.import=Importer lima.ui.importexport.import.terminated=Import terminé lima.ui.importexport.import.vatpdfimport=Le PDF a bien été importé dans le répertoire des ressources de Lima