r3905 - in trunk: lima-business/src/main/java/org/chorem/lima/business/accountingrules lima-business/src/main/java/org/chorem/lima/business/ejb lima-business-api/src/main/java/org/chorem/lima/business lima-swing/src/main/java/org/chorem/lima/ui/importexport lima-swing/src/main/resources/i18n
Author: dcosse Date: 2014-08-07 22:17:41 +0200 (Thu, 07 Aug 2014) New Revision: 3905 Url: http://forge.chorem.org/projects/lima/repository/revisions/3905 Log: refactoring Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/ImportResult.java trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialStatementServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/VatStatementServiceImpl.java 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/accountingrules/DefaultAccountingRules.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java 2014-08-07 16:17:17 UTC (rev 3904) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java 2014-08-07 20:17:41 UTC (rev 3905) @@ -240,7 +240,7 @@ ClosedPeriodicEntryBookTopiaDao closedPeriodicEntryBookTopiaDao = getDaoHelper().getClosedPeriodicEntryBookDao(); FinancialPeriodTopiaDao financialPeriodTopiaDao = getDaoHelper().getFinancialPeriodDao(); - BigDecimal balance = new BigDecimal(0); + BigDecimal balance = BigDecimal.ZERO; for (Entry entry : oldEntries) { Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java 2014-08-07 16:17:17 UTC (rev 3904) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java 2014-08-07 20:17:41 UTC (rev 3905) @@ -176,12 +176,12 @@ BigDecimal grossAmount = financialStatementAmount.getGrossAmount(); if (grossAmount == null) { - grossAmount = new BigDecimal(0); + grossAmount = BigDecimal.ZERO; } BigDecimal provisionDeprecationAmount = financialStatementAmount.getProvisionDeprecationAmount(); if (provisionDeprecationAmount == null) { - provisionDeprecationAmount = new BigDecimal(0); + provisionDeprecationAmount =BigDecimal.ZERO; } if (label == null) { @@ -278,8 +278,8 @@ int n = list.size(); boolean even = true; - BigDecimal currentAmountDebit = new BigDecimal(0); - BigDecimal currentAmountCredit = new BigDecimal(0); + BigDecimal currentAmountDebit =BigDecimal.ZERO; + BigDecimal currentAmountCredit =BigDecimal.ZERO; while (i < n) { @@ -326,8 +326,8 @@ if (entryBook != null) { entryBookCode = entryBook.getCode(); } - BigDecimal amountDebit = new BigDecimal(0), - amountCredit = new BigDecimal(0); + BigDecimal amountDebit = BigDecimal.ZERO, + amountCredit = BigDecimal.ZERO; if (entry.isDebit()) { amountDebit = entry.getAmount(); } else { @@ -498,10 +498,10 @@ if (beginDate != null && endDate != null) { try{ - BigDecimal currentAmountDebit = new BigDecimal(0); - BigDecimal currentAmountCredit = new BigDecimal(0); - BigDecimal currentSoldeDebit = new BigDecimal(0); - BigDecimal currentSoldeCredit = new BigDecimal(0); + BigDecimal currentAmountDebit = BigDecimal.ZERO; + BigDecimal currentAmountCredit = BigDecimal.ZERO; + BigDecimal currentSoldeDebit = BigDecimal.ZERO; + BigDecimal currentSoldeCredit = BigDecimal.ZERO; //create pages int i = 0; @@ -589,15 +589,15 @@ financialPeriodTopiaDao.findByDates(beginDate, endDate); List<GeneralEntryBooksDatas> list = new ArrayList<GeneralEntryBooksDatas>(); - BigDecimal amountDebit = new BigDecimal(0); - BigDecimal amountCredit = new BigDecimal(0); + BigDecimal amountDebit = BigDecimal.ZERO; + BigDecimal amountCredit = BigDecimal.ZERO; for (FinancialPeriod financialPeriod : financialPeriods) { List<ClosedPeriodicEntryBook> closedPeriodicEntryBookList = closedPeriodicEntryBookTopiaDao.findAllByDates( financialPeriod.getBeginDate(), financialPeriod.getEndDate()); - BigDecimal subAmountDebit = new BigDecimal(0); - BigDecimal subAmountCredit = new BigDecimal(0); + BigDecimal subAmountDebit = BigDecimal.ZERO; + BigDecimal subAmountCredit = BigDecimal.ZERO; for (ClosedPeriodicEntryBook closedPeriodicEntryBook : closedPeriodicEntryBookList) { BigDecimal debit = BigDecimal.ZERO; Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialStatementServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialStatementServiceImpl.java 2014-08-07 16:17:17 UTC (rev 3904) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialStatementServiceImpl.java 2014-08-07 20:17:41 UTC (rev 3905) @@ -241,8 +241,8 @@ financialStatements = financialStatement.getSubFinancialStatements(); } - BigDecimal grossAmount = new BigDecimal(0), - provisionDeprecationAmount = new BigDecimal(0); + BigDecimal grossAmount = BigDecimal.ZERO, + provisionDeprecationAmount = BigDecimal.ZERO; List<FinancialStatementAmounts> subResult = new ArrayList<FinancialStatementAmounts>(); for (FinancialStatement subFinancialStatement : financialStatements) { @@ -343,16 +343,14 @@ Date selectedEndDate) { FinancialStatementAmounts financialStatementAmounts = new FinancialStatementAmountsImpl(); - BigDecimal amount = new BigDecimal(0); - BigDecimal debitAmount = new BigDecimal(0); - BigDecimal creditAmount = new BigDecimal(0); - BigDecimal provisionDeprecationAmount = new BigDecimal(0); + BigDecimal amount = BigDecimal.ZERO; + BigDecimal debitAmount = BigDecimal.ZERO; + BigDecimal creditAmount = BigDecimal.ZERO; + BigDecimal provisionDeprecationAmount = BigDecimal.ZERO; + FinancialStatement masterFinancialStatement = financialStatement.getMasterFinancialStatement(); - FinancialStatementWayEnum financialStatementWayEnum = FinancialStatementWayEnum.BOTH; - if (masterFinancialStatement != null) { - financialStatementWayEnum = masterFinancialStatement.getWay(); - } + FinancialStatementWayEnum financialStatementWayEnum = masterFinancialStatement == null ? FinancialStatementWayEnum.BOTH : masterFinancialStatement.getWay(); // DEBIT & CREDIT ACCOUNTS LIST Amounts amounts; @@ -381,6 +379,17 @@ provisionDeprecationAmount = provisionDeprecationAmount.add(amounts.getCredit()); provisionDeprecationAmount = provisionDeprecationAmount.subtract(amounts.getDebit()); } + amount = computeAmount(amount, debitAmount, creditAmount, financialStatementWayEnum); + + financialStatementAmounts.setGrossAmount(amount); + financialStatementAmounts.setLabel(financialStatement.getLabel()); + financialStatementAmounts.setProvisionDeprecationAmount(provisionDeprecationAmount); + financialStatementAmounts.setLevel(financialStatement.getLevel()); + + return financialStatementAmounts; + } + + private BigDecimal computeAmount(BigDecimal amount, BigDecimal debitAmount, BigDecimal creditAmount, FinancialStatementWayEnum financialStatementWayEnum) { switch (financialStatementWayEnum) { case BOTH: amount = amount.add(debitAmount); @@ -395,21 +404,15 @@ amount = amount.add(debitAmount); amount = amount.subtract(creditAmount); } - - financialStatementAmounts.setGrossAmount(amount); - financialStatementAmounts.setLabel(financialStatement.getLabel()); - financialStatementAmounts.setProvisionDeprecationAmount(provisionDeprecationAmount); - financialStatementAmounts.setLevel(financialStatement.getLevel()); - - return financialStatementAmounts; + return amount; } protected Amounts amountFromAccountList(String accountsNumberList, Date selectedBeginDate, Date selectedEndDate) { Amounts amounts = new AmountsImpl(); - BigDecimal debit = new BigDecimal(0); - BigDecimal credit = new BigDecimal(0); + BigDecimal debit = BigDecimal.ZERO; + BigDecimal credit = BigDecimal.ZERO; Boolean substract = false; //Remove Spaces @@ -418,8 +421,8 @@ while (stQuote.hasMoreTokens()) { String s = stQuote.nextToken(); List<Account> accountsList = accountService.stringToListAccounts(s); - BigDecimal debitTemp = new BigDecimal(0); - BigDecimal creditTemp = new BigDecimal(0); + BigDecimal debitTemp = BigDecimal.ZERO; + BigDecimal creditTemp = BigDecimal.ZERO; for (Account account : accountsList) { ReportsDatas reportsDatas = reportService.generateAccountsReports( Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java 2014-08-07 16:17:17 UTC (rev 3904) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java 2014-08-07 20:17:41 UTC (rev 3905) @@ -37,8 +37,10 @@ import org.chorem.lima.business.api.FinancialTransactionService; import org.chorem.lima.business.api.FiscalPeriodService; import org.chorem.lima.business.api.ReportService; +import org.chorem.lima.business.exceptions.AlreadyExistAccountException; import org.chorem.lima.business.exceptions.AlreadyLockedFiscalPeriodException; import org.chorem.lima.business.exceptions.BeginAfterEndFiscalPeriodException; +import org.chorem.lima.business.exceptions.InvalidAccountNumberException; import org.chorem.lima.business.exceptions.LastUnlockedFiscalPeriodException; import org.chorem.lima.business.exceptions.LimaException; import org.chorem.lima.business.exceptions.LockedEntryBookException; @@ -46,7 +48,9 @@ import org.chorem.lima.business.exceptions.MoreOneUnlockFiscalPeriodException; import org.chorem.lima.business.exceptions.NoEmptyFiscalPeriodException; import org.chorem.lima.business.exceptions.NoFoundFinancialPeriodException; +import org.chorem.lima.business.exceptions.NotAllowedLabelException; import org.chorem.lima.business.exceptions.NotBeginNextDayOfLastFiscalPeriodException; +import org.chorem.lima.business.exceptions.NotNumberAccountNumberException; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.AccountImpl; import org.chorem.lima.entity.ClosedPeriodicEntryBook; @@ -307,72 +311,28 @@ // -> 89 BILAN // -> 890 Bilan d'ouverture // -> 891 Bilan de cloture + Account endRetainedAccount = createRelated89TreeAccounts(); - //89 BILAN - Account accountMaster = accountService.getAccountByNumber("89"); - if (accountMaster == null) { - accountMaster = new AccountImpl(); - accountMaster.setAccountNumber("89"); - accountMaster.setLabel("BILAN"); - accountService.createAccount(accountMaster); - } - //890 Bilan d'ouverture - Account beginRetainedAccount = accountService.getAccountByNumber("890"); - if (beginRetainedAccount == null) { - beginRetainedAccount = new AccountImpl(); - beginRetainedAccount.setAccountNumber("890"); - beginRetainedAccount.setLabel("Bilan d'ouverture"); - accountService.createAccount(beginRetainedAccount); - } - - //891 Bilan de cloture - Account endRetainedAccount = accountService.getAccountByNumber("891"); - if (endRetainedAccount == null) { - endRetainedAccount = new AccountImpl(); - endRetainedAccount.setAccountNumber("891"); - endRetainedAccount.setLabel("Bilan de clôture"); - endRetainedAccount = accountService.createAccount(endRetainedAccount); - } - //look for the last financial period from the previous fiscal year //check if the last financial period isn't blocked - Collection<FinancialPeriod> fperiod = localFiscalPeriod.getFinancialPeriod(); - Iterator<FinancialPeriod> itr = fperiod.iterator(); FinancialPeriod lastFPeriod = null; - while (itr.hasNext()) { - lastFPeriod = itr.next(); - } + lastFPeriod = getLastFinancialPeriodFromPreviousYear(localFiscalPeriod, lastFPeriod); - Date beginDateNextFiscalPeriod = DateUtils.addDays(localFiscalPeriod.getEndDate(), 1); FinancialPeriodTopiaDao financialPeriodDao = getDaoHelper().getFinancialPeriodDao(); - FinancialPeriod beginfinancialPeriod = null; - try { - beginfinancialPeriod = financialPeriodDao.findByDate(beginDateNextFiscalPeriod); - } catch (TopiaNoResultException e) { - throw new NoFoundFinancialPeriodException(beginDateNextFiscalPeriod, e); - } + FinancialPeriod beginFinancialPeriod = findBeginFinancialPeriod(beginDateNextFiscalPeriod, financialPeriodDao); - if (beginfinancialPeriod.isLocked()) { - throw new LockedFinancialPeriodException(beginfinancialPeriod); - } + validClosedPeriodicEntryBookNotLocked(entryBook, beginFinancialPeriod); - ClosedPeriodicEntryBookTopiaDao closedPeriodicEntryBookDao = getDaoHelper().getClosedPeriodicEntryBookDao(); - ClosedPeriodicEntryBook closedPeriodicEntryBook = closedPeriodicEntryBookDao.findByEntryBookAndFinancialPeriod(entryBook, beginfinancialPeriod); - - if (closedPeriodicEntryBook.isLocked()) { - throw new LockedEntryBookException(closedPeriodicEntryBook); - } - //holds entries of all closing transactions - FinancialTransaction endfinancialTransaction = new FinancialTransactionImpl(); - if (lastFPeriod != null) { + FinancialTransaction endFinancialTransaction = new FinancialTransactionImpl(); + if (lastFPeriod != null) {// TODO DCossé 07/08/14 if null endFinancialTransaction has no EntryBook and it's not valid //Sets the endfinancialTransaction - endfinancialTransaction.setEntryBook(entryBook); - endfinancialTransaction.setTransactionDate(localFiscalPeriod.getEndDate()); - endfinancialTransaction = financialTransactionService.createFinancialTransaction(endfinancialTransaction); + endFinancialTransaction.setEntryBook(entryBook); + endFinancialTransaction.setTransactionDate(localFiscalPeriod.getEndDate()); + endFinancialTransaction = financialTransactionService.createFinancialTransaction(endFinancialTransaction); } //holds entries of all opening transactions @@ -380,7 +340,7 @@ //Sets the endfinancialTransaction beginfinancialTransaction.setEntryBook(entryBook); - beginfinancialTransaction.setTransactionDate(beginfinancialPeriod.getBeginDate()); + beginfinancialTransaction.setTransactionDate(beginFinancialPeriod.getBeginDate()); beginfinancialTransaction = financialTransactionService.createFinancialTransaction(beginfinancialTransaction); @@ -394,51 +354,7 @@ List<ReportsDatas> reportsDatasList = (List<ReportsDatas>) results.getReportsDatas(); for (ReportsDatas report : reportsDatasList) { - - //Account class from 1 to 5 and only non zero amount - if (Integer.valueOf(report.getAccount().getAccountNumber().substring(0, 1)) < 6 - && !report.getAmountSolde().equals(BigDecimal.ZERO)) { - - //close accounts by removing amounts from all class 1 to 5 accounts - Entry beginEntry = new EntryImpl(); - beginEntry.setDescription(t("lima-business.financialtransaction.retainedearnings.description") + " (" + calendar.get(Calendar.YEAR) + ")"); - beginEntry.setVoucher(t("lima-business.financialtransaction.retainedearnings.voucher")); - beginEntry.setFinancialTransaction(endfinancialTransaction); - beginEntry.setAccount(report.getAccount()); - beginEntry.setAmount(report.getAmountSolde().abs()); - beginEntry.setDebit(!report.isSoldeDebit()); - financialTransactionService.createEntry(beginEntry); - - //save amounts inside account number 891 - beginEntry = new EntryImpl(); - beginEntry.setDescription(t("lima-business.financialtransaction.retainedearnings.description") + " (" + calendar.get(Calendar.YEAR) + ")"); - beginEntry.setVoucher(t("lima-business.financialtransaction.retainedearnings.voucher")); - beginEntry.setFinancialTransaction(endfinancialTransaction); - beginEntry.setAccount(endRetainedAccount); - beginEntry.setAmount(report.getAmountSolde().abs()); - beginEntry.setDebit(report.isSoldeDebit()); - financialTransactionService.createEntry(beginEntry); - - //open new year accounts if new year exists and a date has been found for the transaction - //give back amounts from class 1 to 5 accounts - beginEntry = new EntryImpl(); - beginEntry.setDescription(t("lima-business.financialtransaction.retainedearnings.description") + " (" + calendar.get(Calendar.YEAR) + ")"); - beginEntry.setVoucher(t("lima-business.financialtransaction.retainedearnings.voucher")); - beginEntry.setFinancialTransaction(beginfinancialTransaction); - beginEntry.setAccount(report.getAccount()); - beginEntry.setAmount(report.getAmountSolde().abs()); - beginEntry.setDebit(report.isSoldeDebit()); - financialTransactionService.createEntry(beginEntry); - //close account by removing amount from account number 890 - beginEntry = new EntryImpl(); - beginEntry.setDescription(t("lima-business.financialtransaction.retainedearnings.description") + " (" + calendar.get(Calendar.YEAR) + ")"); - beginEntry.setVoucher(t("lima-business.financialtransaction.retainedearnings.voucher")); - beginEntry.setFinancialTransaction(beginfinancialTransaction); - beginEntry.setAccount(endRetainedAccount); - beginEntry.setAmount(report.getAmountSolde().abs()); - beginEntry.setDebit(!report.isSoldeDebit()); - financialTransactionService.createEntry(beginEntry); - } + processReport(endRetainedAccount, endFinancialTransaction, beginfinancialTransaction, calendar, report); } } @@ -447,6 +363,124 @@ return fiscalPeriodBlocked; } + protected void processReport(Account endRetainedAccount, FinancialTransaction endFinancialTransaction, FinancialTransaction beginfinancialTransaction, Calendar calendar, ReportsDatas report) throws LockedFinancialPeriodException, LockedEntryBookException { + //Account class from 1 to 5 and only non zero amount + if (Integer.valueOf(report.getAccount().getAccountNumber().substring(0, 1)) < 6 + && !report.getAmountSolde().equals(BigDecimal.ZERO)) { + + //close accounts by removing amounts from all class 1 to 5 accounts + Entry beginEntry = new EntryImpl(); + beginEntry.setDescription(t("lima-business.financialtransaction.retainedearnings.description") + " (" + calendar.get(Calendar.YEAR) + ")"); + beginEntry.setVoucher(t("lima-business.financialtransaction.retainedearnings.voucher")); + beginEntry.setFinancialTransaction(endFinancialTransaction); + beginEntry.setAccount(report.getAccount()); + beginEntry.setAmount(report.getAmountSolde().abs()); + beginEntry.setDebit(!report.isSoldeDebit()); + financialTransactionService.createEntry(beginEntry); + + //save amounts inside account number 891 + beginEntry = new EntryImpl(); + beginEntry.setDescription(t("lima-business.financialtransaction.retainedearnings.description") + " (" + calendar.get(Calendar.YEAR) + ")"); + beginEntry.setVoucher(t("lima-business.financialtransaction.retainedearnings.voucher")); + beginEntry.setFinancialTransaction(endFinancialTransaction); + beginEntry.setAccount(endRetainedAccount); + beginEntry.setAmount(report.getAmountSolde().abs()); + beginEntry.setDebit(report.isSoldeDebit()); + financialTransactionService.createEntry(beginEntry); + + //open new year accounts if new year exists and a date has been found for the transaction + //give back amounts from class 1 to 5 accounts + beginEntry = new EntryImpl(); + beginEntry.setDescription(t("lima-business.financialtransaction.retainedearnings.description") + " (" + calendar.get(Calendar.YEAR) + ")"); + beginEntry.setVoucher(t("lima-business.financialtransaction.retainedearnings.voucher")); + beginEntry.setFinancialTransaction(beginfinancialTransaction); + beginEntry.setAccount(report.getAccount()); + beginEntry.setAmount(report.getAmountSolde().abs()); + beginEntry.setDebit(report.isSoldeDebit()); + financialTransactionService.createEntry(beginEntry); + //close account by removing amount from account number 890 + beginEntry = new EntryImpl(); + beginEntry.setDescription(t("lima-business.financialtransaction.retainedearnings.description") + " (" + calendar.get(Calendar.YEAR) + ")"); + beginEntry.setVoucher(t("lima-business.financialtransaction.retainedearnings.voucher")); + beginEntry.setFinancialTransaction(beginfinancialTransaction); + beginEntry.setAccount(endRetainedAccount); + beginEntry.setAmount(report.getAmountSolde().abs()); + beginEntry.setDebit(!report.isSoldeDebit()); + financialTransactionService.createEntry(beginEntry); + } + } + + protected FinancialTransaction createFinancialTransaction(EntryBook entryBook, Date transactionDate) throws LockedFinancialPeriodException, LockedEntryBookException { + FinancialTransaction endFinancialTransaction = financialTransactionService.createNewFinancialTransaction(); + //Sets the endfinancialTransaction + endFinancialTransaction.setEntryBook(entryBook); + endFinancialTransaction.setTransactionDate(transactionDate); + endFinancialTransaction = financialTransactionService.createFinancialTransaction(endFinancialTransaction); + + return endFinancialTransaction; + } + + protected void validClosedPeriodicEntryBookNotLocked(EntryBook entryBook, FinancialPeriod beginFinancialPeriod) throws LockedEntryBookException { + ClosedPeriodicEntryBookTopiaDao closedPeriodicEntryBookDao = getDaoHelper().getClosedPeriodicEntryBookDao(); + ClosedPeriodicEntryBook closedPeriodicEntryBook = closedPeriodicEntryBookDao.findByEntryBookAndFinancialPeriod(entryBook, beginFinancialPeriod); + if (closedPeriodicEntryBook.isLocked()) { + throw new LockedEntryBookException(closedPeriodicEntryBook); + } + } + + protected FinancialPeriod findBeginFinancialPeriod(Date beginDateNextFiscalPeriod, FinancialPeriodTopiaDao financialPeriodDao) throws NoFoundFinancialPeriodException, LockedFinancialPeriodException { + FinancialPeriod beginFinancialPeriod; + try { + beginFinancialPeriod = financialPeriodDao.findByDate(beginDateNextFiscalPeriod); + } catch (TopiaNoResultException e) { + throw new NoFoundFinancialPeriodException(beginDateNextFiscalPeriod, e); + } + + if (beginFinancialPeriod.isLocked()) { + throw new LockedFinancialPeriodException(beginFinancialPeriod); + } + return beginFinancialPeriod; + } + + protected FinancialPeriod getLastFinancialPeriodFromPreviousYear(FiscalPeriod localFiscalPeriod, FinancialPeriod lastFPeriod) { + Collection<FinancialPeriod> fperiod = localFiscalPeriod.getFinancialPeriod(); + Iterator<FinancialPeriod> itr = fperiod.iterator(); + while (itr.hasNext()) { + lastFPeriod = itr.next(); + } + return lastFPeriod; + } + + protected Account createRelated89TreeAccounts() throws AlreadyExistAccountException, InvalidAccountNumberException, NotNumberAccountNumberException, NotAllowedLabelException { + //89 BILAN + Account accountMaster = accountService.getAccountByNumber("89"); + if (accountMaster == null) { + createAccount("89", "BILAN"); + } + + //890 Bilan d'ouverture + Account beginRetainedAccount = accountService.getAccountByNumber("890"); + if (beginRetainedAccount == null) { + createAccount("890", "Bilan d'ouverture"); + } + + //891 Bilan de cloture + Account endRetainedAccount = accountService.getAccountByNumber("891"); + if (endRetainedAccount == null) { + endRetainedAccount = createAccount("891", "Bilan de clôture"); + } + return endRetainedAccount; + } + + protected Account createAccount(String accountNumber, String label) throws AlreadyExistAccountException, InvalidAccountNumberException, NotNumberAccountNumberException, NotAllowedLabelException { + Account endRetainedAccount; + endRetainedAccount = new AccountImpl(); + endRetainedAccount.setAccountNumber(accountNumber); + endRetainedAccount.setLabel(label); + endRetainedAccount = accountService.createAccount(endRetainedAccount); + return endRetainedAccount; + } + /** * to delete a fiscal period * <p/> 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 2014-08-07 16:17:17 UTC (rev 3904) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java 2014-08-07 20:17:41 UTC (rev 3905) @@ -391,94 +391,122 @@ } for (FinancialStatementImport financialStatementBean : financialStatementImports) { - Binder<FinancialStatementImport, FinancialStatement> binder = BinderFactory.newBinder(FinancialStatementImport.class, FinancialStatement.class); - FinancialStatement financialStatement = financialStatementService.newFinancialStatement(); - binder.copyExcluding(financialStatementBean, financialStatement, FinancialStatement.PROPERTY_MASTER_FINANCIAL_STATEMENT); + processFinancialStatementImport(result, orderedFinancialStatements, financialStatementBean); + } - try{ - // full path to master - String masterPath = financialStatementBean.getMasterFinancialStatement(); + } catch (ImportRuntimeException e) { + result.addInitException(new ImportFileException(e.getMessage())); + } finally { + IOUtils.closeQuietly(contentStream); + } + } - if (StringUtils.isBlank(masterPath)) { - // case of financialStatement is root - // look if root exists - // It can not have several FinancialStatement with the same from same path - FinancialStatement rootFinancialStatement = orderedFinancialStatements.get(financialStatementBean.getLabel()); + return results; + } - if (rootFinancialStatement == null) { - rootFinancialStatement = financialStatement; - rootFinancialStatement = financialStatementService.createFinancialStatement(null, rootFinancialStatement); - } else { - // in case it exist (not ordered import and previously created) values are bind to the previously created one excepted - // the sub financial statements - Binder<FinancialStatement, FinancialStatement> rootBinder = BinderFactory.newBinder(FinancialStatement.class, FinancialStatement.class); - rootBinder.copyExcluding(financialStatement, rootFinancialStatement, FinancialStatement.PROPERTY_SUB_FINANCIAL_STATEMENTS); - } - orderedFinancialStatements.put(rootFinancialStatement.getLabel(), rootFinancialStatement); - } else { - String[] masterNames = masterPath.split("/"); - String rootMasterName = masterNames[0]; + protected void processFinancialStatementImport(ImportResult result, Map<String, FinancialStatement> orderedFinancialStatements, FinancialStatementImport financialStatementBean) { + Binder<FinancialStatementImport, FinancialStatement> binder = BinderFactory.newBinder(FinancialStatementImport.class, FinancialStatement.class); + FinancialStatement financialStatement = financialStatementService.newFinancialStatement(); + binder.copyExcluding(financialStatementBean, financialStatement, FinancialStatement.PROPERTY_MASTER_FINANCIAL_STATEMENT); - FinancialStatement rootFinancialStatement = orderedFinancialStatements.get(rootMasterName); + try{ + // full path to master + String masterPath = financialStatementBean.getMasterFinancialStatement(); - // case of not ordered import and subFinancialStatement is looking for it's master that has not been created yet - if (rootFinancialStatement == null) { - rootFinancialStatement = financialStatementService.newFinancialStatement(); - rootFinancialStatement.setLabel(rootMasterName); - rootFinancialStatement = financialStatementService.createFinancialStatement(null, rootFinancialStatement); - orderedFinancialStatements.put(rootMasterName, rootFinancialStatement); - } + if (StringUtils.isBlank(masterPath)) { + // case of financialStatement is root + // look if root exists + // It can not have several FinancialStatement with the same from same path + FinancialStatement rootFinancialStatement = getRootFinancialStatement(orderedFinancialStatements, financialStatementBean, financialStatement); + orderedFinancialStatements.put(rootFinancialStatement.getLabel(), rootFinancialStatement); + } else { + String[] masterNames = masterPath.split("/"); + String rootMasterName = masterNames[0]; - // explore branches to find the financialStatement's master one - FinancialStatement branchesFinancialStatement = rootFinancialStatement; - for (int i = 1; i < masterNames.length; i++) {// 0 is root - String masterName = masterNames[i]; - branchesFinancialStatement = returnFinancialStatement(branchesFinancialStatement, masterName); - } + FinancialStatement rootFinancialStatement = orderedFinancialStatements.get(rootMasterName); - // in case it exist (not ordered import and previously created) values are bind to the previously created one excepted - // the sub financial statements - boolean alreadyCreated = false; - if (branchesFinancialStatement != null && branchesFinancialStatement.getSubFinancialStatements() != null) { - for (FinancialStatement bfs : branchesFinancialStatement.getSubFinancialStatements()) { - if (bfs.getLabel().equals(financialStatement.getLabel())){ - Binder<FinancialStatement, FinancialStatement> rootBinder = BinderFactory.newBinder(FinancialStatement.class, FinancialStatement.class); - rootBinder.copyExcluding(bfs, financialStatement, FinancialStatement.PROPERTY_SUB_FINANCIAL_STATEMENTS); - alreadyCreated = true; - break; - } - } - } + // case of not ordered import and subFinancialStatement is looking for it's master that has not been created yet + rootFinancialStatement = createRootFinancialStatement(orderedFinancialStatements, rootMasterName, rootFinancialStatement); - // if necessary financial statement is created - if (!alreadyCreated) { - // if the master finacial statement has been modified then the current one is replace by the new one. - financialStatement = financialStatementService.createFinancialStatement(branchesFinancialStatement, financialStatement); - FinancialStatement targetedRootFinancialStatement = returnRootFinancialStatement(financialStatement); + // explore branches to find the financialStatement's master one + FinancialStatement branchesFinancialStatement = rootFinancialStatement; + branchesFinancialStatement = getBrancheFinancialStatement(masterNames, branchesFinancialStatement); - // replace modified root financial statement with new one - if (orderedFinancialStatements.get(targetedRootFinancialStatement.getLabel()) != null) { - orderedFinancialStatements.put(targetedRootFinancialStatement.getLabel(), targetedRootFinancialStatement); - } - } + // in case it exist (not ordered import and previously created) values are bind to the previously created one excepted + // the sub financial statements + boolean alreadyCreated = false; + alreadyCreated = propagetChangesToExistingFinancialStatement(financialStatement, branchesFinancialStatement, alreadyCreated); - } - result.increaseCreated(); - } catch (AlreadyExistFinancialStatement | NotAllowedLabelException e) { - result.addException(e); - } + // if necessary financial statement is created + if (!alreadyCreated) { + createRootFinancialStatement(orderedFinancialStatements, financialStatement, branchesFinancialStatement); } - } catch (ImportRuntimeException e) { - result.addInitException(new ImportFileException(e.getMessage())); - } finally { - IOUtils.closeQuietly(contentStream); } + result.increaseCreated(); + } catch (AlreadyExistFinancialStatement | NotAllowedLabelException e) { + result.addException(e); } + } - return results; + private FinancialStatement getRootFinancialStatement(Map<String, FinancialStatement> orderedFinancialStatements, FinancialStatementImport financialStatementBean, FinancialStatement financialStatement) throws AlreadyExistFinancialStatement, NotAllowedLabelException { + FinancialStatement rootFinancialStatement = orderedFinancialStatements.get(financialStatementBean.getLabel()); + + if (rootFinancialStatement == null) { + rootFinancialStatement = financialStatement; + rootFinancialStatement = financialStatementService.createFinancialStatement(null, rootFinancialStatement); + } else { + // in case it exist (not ordered import and previously created) values are bind to the previously created one excepted + // the sub financial statements + Binder<FinancialStatement, FinancialStatement> rootBinder = BinderFactory.newBinder(FinancialStatement.class, FinancialStatement.class); + rootBinder.copyExcluding(financialStatement, rootFinancialStatement, FinancialStatement.PROPERTY_SUB_FINANCIAL_STATEMENTS); + } + return rootFinancialStatement; } + private FinancialStatement getBrancheFinancialStatement(String[] masterNames, FinancialStatement branchesFinancialStatement) throws AlreadyExistFinancialStatement, NotAllowedLabelException { + for (int i = 1; i < masterNames.length; i++) {// 0 is root + String masterName = masterNames[i]; + branchesFinancialStatement = returnFinancialStatement(branchesFinancialStatement, masterName); + } + return branchesFinancialStatement; + } + + protected void createRootFinancialStatement(Map<String, FinancialStatement> orderedFinancialStatements, FinancialStatement financialStatement, FinancialStatement branchesFinancialStatement) throws AlreadyExistFinancialStatement, NotAllowedLabelException { + // if the master finacial statement has been modified then the current one is replace by the new one. + financialStatement = financialStatementService.createFinancialStatement(branchesFinancialStatement, financialStatement); + FinancialStatement targetedRootFinancialStatement = returnRootFinancialStatement(financialStatement); + + // replace modified root financial statement with new one + if (orderedFinancialStatements.get(targetedRootFinancialStatement.getLabel()) != null) { + orderedFinancialStatements.put(targetedRootFinancialStatement.getLabel(), targetedRootFinancialStatement); + } + } + + protected boolean propagetChangesToExistingFinancialStatement(FinancialStatement financialStatement, FinancialStatement branchesFinancialStatement, boolean alreadyCreated) { + if (branchesFinancialStatement != null && branchesFinancialStatement.getSubFinancialStatements() != null) { + for (FinancialStatement bfs : branchesFinancialStatement.getSubFinancialStatements()) { + if (bfs.getLabel().equals(financialStatement.getLabel())){ + Binder<FinancialStatement, FinancialStatement> rootBinder = BinderFactory.newBinder(FinancialStatement.class, FinancialStatement.class); + rootBinder.copyExcluding(bfs, financialStatement, FinancialStatement.PROPERTY_SUB_FINANCIAL_STATEMENTS); + alreadyCreated = true; + break; + } + } + } + return alreadyCreated; + } + + protected FinancialStatement createRootFinancialStatement(Map<String, FinancialStatement> orderedFinancialStatements, String rootMasterName, FinancialStatement rootFinancialStatement) throws AlreadyExistFinancialStatement, NotAllowedLabelException { + if (rootFinancialStatement == null) { + rootFinancialStatement = financialStatementService.newFinancialStatement(); + rootFinancialStatement.setLabel(rootMasterName); + rootFinancialStatement = financialStatementService.createFinancialStatement(null, rootFinancialStatement); + orderedFinancialStatements.put(rootMasterName, rootFinancialStatement); + } + return rootFinancialStatement; + } + protected VatStatement returnVATStatement (VatStatement rootVATStatement, String subVATStatementLabel) throws AlreadyExistVatStatementException, NotAllowedLabelException { Collection<VatStatement> subVatStatements = rootVATStatement.getSubVatStatements(); VatStatement targetedVATStatement = null; @@ -535,99 +563,132 @@ // path, vatStatement Map<String, VatStatement> orderedVATStatements = new HashMap<>(); - List<VatStatement> rootVatStatements = vatStatementService.getRootVatStatements(); - for (VatStatement vatStatement : rootVatStatements) { - orderedVATStatements.put(vatStatement.getLabel(), vatStatement); - } + orderVATStatements(orderedVATStatements); for (VatStatementImport vatStatementBean : vatStatementImports) { - Binder<VatStatementImport, VatStatement> binder = BinderFactory.newBinder(VatStatementImport.class, VatStatement.class); - VatStatement vatStatement = vatStatementService.newVatStatement(); - binder.copyExcluding(vatStatementBean, vatStatement, VatStatement.PROPERTY_MASTER_VAT_STATEMENT); + importVatStatement(result, orderedVATStatements, vatStatementBean); + } - try{ - // full path to master - String masterPath = vatStatementBean.getMasterVatStatement(); + } catch (ImportRuntimeException e) { + result.addInitException(new ImportFileException(e.getMessage())); + } finally { + IOUtils.closeQuietly(contentStream); + } + } + return results; + } - if (StringUtils.isBlank(masterPath)) { - // case of vatStatement is root - // look if root exists - // It can not have several vatStatement with the same from same path - VatStatement rootVATStatement = orderedVATStatements.get(vatStatementBean.getLabel()); + protected void importVatStatement(ImportResult result, Map<String, VatStatement> orderedVATStatements, VatStatementImport vatStatementBean) { + Binder<VatStatementImport, VatStatement> binder = BinderFactory.newBinder(VatStatementImport.class, VatStatement.class); + VatStatement vatStatement = vatStatementService.newVatStatement(); + binder.copyExcluding(vatStatementBean, vatStatement, VatStatement.PROPERTY_MASTER_VAT_STATEMENT); - if (rootVATStatement == null) { - rootVATStatement = vatStatement; - rootVATStatement = vatStatementService.createVatStatement(null, rootVATStatement); - } else { - // in case it exist (not ordered import and previously created) values are bind to the previously created one excepted - // the sub vatStatements - Binder<VatStatement, VatStatement> rootBinder = BinderFactory.newBinder(VatStatement.class, VatStatement.class); - rootBinder.copyExcluding(vatStatement, rootVATStatement, VatStatement.PROPERTY_SUB_VAT_STATEMENTS); - } - orderedVATStatements.put(rootVATStatement.getLabel(), rootVATStatement); - } else { - String[] masterNames = masterPath.split("/"); - String rootMasterName = masterNames[0]; + try{ + // full path to master + String masterPath = vatStatementBean.getMasterVatStatement(); - VatStatement rootVATStatement = orderedVATStatements.get(rootMasterName); + if (StringUtils.isBlank(masterPath)) { + // case of vatStatement is root + // look if root exists + // It can not have several vatStatement with the same from same path + VatStatement rootVATStatement = getRootVatStatement(orderedVATStatements, vatStatementBean, vatStatement); + orderedVATStatements.put(rootVATStatement.getLabel(), rootVATStatement); + } else { + String[] masterNames = masterPath.split("/"); + String rootMasterName = masterNames[0]; - // case of not ordered import and subVATStatement is looking for it's master that has not been created yet - if (rootVATStatement == null) { - rootVATStatement = vatStatementService.newVatStatement(); - rootVATStatement.setLabel(rootMasterName); - rootVATStatement = vatStatementService.createVatStatement(null, rootVATStatement); - orderedVATStatements.put(rootMasterName, rootVATStatement); - } + VatStatement rootVATStatement = orderedVATStatements.get(rootMasterName); - // explore branches to find the vatStatement's master one - VatStatement branchesVATStatement = rootVATStatement; - for (int i = 1; i < masterNames.length; i++) {// 0 is root - String masterName = masterNames[i]; - branchesVATStatement = returnVATStatement(branchesVATStatement, masterName); - } + // case of not ordered import and subVATStatement is looking for it's master that has not been created yet + rootVATStatement = createRootVATStatement(orderedVATStatements, rootMasterName, rootVATStatement); - // in case it exist (not ordered import and previously created) values are bind to the previously created one excepted - // the sub vatStatements - boolean alreadyCreated = false; - if (branchesVATStatement != null && branchesVATStatement.getSubVatStatements() != null) { - for (VatStatement bfs : branchesVATStatement.getSubVatStatements()) { - if (bfs.getLabel().equals(vatStatement.getLabel())){ - Binder<VatStatement, VatStatement> rootBinder = BinderFactory.newBinder(VatStatement.class, VatStatement.class); - rootBinder.copyExcluding(bfs, vatStatement, VatStatement.PROPERTY_SUB_VAT_STATEMENTS); - alreadyCreated = true; - break; - } - } - } + // explore branches to find the vatStatement's master one + VatStatement branchesVATStatement = rootVATStatement; + branchesVATStatement = getBrancheVatStatement(masterNames, branchesVATStatement); - // if necessary vatStatement is created - if (!alreadyCreated) { - // if the master vatStatement has been modified then the current one is replace by the new one. - vatStatement = vatStatementService.createVatStatement(branchesVATStatement, vatStatement); - VatStatement targetedRootVATStatement = returnRootVATStatement(vatStatement); + // in case it exist (not ordered import and previously created) values are bind to the previously created one excepted + // the sub vatStatements + boolean alreadyCreated = false; + alreadyCreated = propagateVATChangeToBranche(vatStatement, branchesVATStatement, alreadyCreated); - // replace modified root vatStatement with new one - if (orderedVATStatements.get(targetedRootVATStatement.getLabel()) != null) { - orderedVATStatements.put(targetedRootVATStatement.getLabel(), targetedRootVATStatement); - } - } + // if necessary vatStatement is created + if (!alreadyCreated) { + refreshMasterVATStatement(orderedVATStatements, vatStatement, branchesVATStatement); - } - result.increaseCreated(); - } catch (AlreadyExistVatStatementException | NotAllowedLabelException e) { - result.addException(e); - } } - } catch (ImportRuntimeException e) { - result.addInitException(new ImportFileException(e.getMessage())); - } finally { - IOUtils.closeQuietly(contentStream); } + result.increaseCreated(); + } catch (AlreadyExistVatStatementException | NotAllowedLabelException e) { + result.addException(e); } - return results; } + private void refreshMasterVATStatement(Map<String, VatStatement> orderedVATStatements, VatStatement vatStatement, VatStatement branchesVATStatement) throws AlreadyExistVatStatementException, NotAllowedLabelException { + // if the master vatStatement has been modified then the current one is replace by the new one. + vatStatement = vatStatementService.createVatStatement(branchesVATStatement, vatStatement); + VatStatement targetedRootVATStatement = returnRootVATStatement(vatStatement); + + // replace modified root vatStatement with new one + if (orderedVATStatements.get(targetedRootVATStatement.getLabel()) != null) { + orderedVATStatements.put(targetedRootVATStatement.getLabel(), targetedRootVATStatement); + } + } + + private boolean propagateVATChangeToBranche(VatStatement vatStatement, VatStatement branchesVATStatement, boolean alreadyCreated) { + if (branchesVATStatement != null && branchesVATStatement.getSubVatStatements() != null) { + for (VatStatement bfs : branchesVATStatement.getSubVatStatements()) { + if (bfs.getLabel().equals(vatStatement.getLabel())){ + Binder<VatStatement, VatStatement> rootBinder = BinderFactory.newBinder(VatStatement.class, VatStatement.class); + rootBinder.copyExcluding(bfs, vatStatement, VatStatement.PROPERTY_SUB_VAT_STATEMENTS); + alreadyCreated = true; + break; + } + } + } + return alreadyCreated; + } + + private VatStatement getBrancheVatStatement(String[] masterNames, VatStatement branchesVATStatement) throws AlreadyExistVatStatementException, NotAllowedLabelException { + for (int i = 1; i < masterNames.length; i++) {// 0 is root + String masterName = masterNames[i]; + branchesVATStatement = returnVATStatement(branchesVATStatement, masterName); + } + return branchesVATStatement; + } + + private VatStatement createRootVATStatement(Map<String, VatStatement> orderedVATStatements, String rootMasterName, VatStatement rootVATStatement) throws AlreadyExistVatStatementException, NotAllowedLabelException { + if (rootVATStatement == null) { + rootVATStatement = vatStatementService.newVatStatement(); + rootVATStatement.setLabel(rootMasterName); + rootVATStatement = vatStatementService.createVatStatement(null, rootVATStatement); + orderedVATStatements.put(rootMasterName, rootVATStatement); + } + return rootVATStatement; + } + + private VatStatement getRootVatStatement(Map<String, VatStatement> orderedVATStatements, VatStatementImport vatStatementBean, VatStatement vatStatement) throws AlreadyExistVatStatementException, NotAllowedLabelException { + VatStatement rootVATStatement = orderedVATStatements.get(vatStatementBean.getLabel()); + + if (rootVATStatement == null) { + rootVATStatement = vatStatement; + rootVATStatement = vatStatementService.createVatStatement(null, rootVATStatement); + } else { + // in case it exist (not ordered import and previously created) values are bind to the previously created one excepted + // the sub vatStatements + Binder<VatStatement, VatStatement> rootBinder = BinderFactory.newBinder(VatStatement.class, VatStatement.class); + rootBinder.copyExcluding(vatStatement, rootVATStatement, VatStatement.PROPERTY_SUB_VAT_STATEMENTS); + } + return rootVATStatement; + } + + protected void orderVATStatements(Map<String, VatStatement> orderedVATStatements) { + List<VatStatement> rootVatStatements = vatStatementService.getRootVatStatements(); + for (VatStatement vatStatement : rootVatStatements) { + orderedVATStatements.put(vatStatement.getLabel(), vatStatement); + } + } + @Override public ImportExportResults importBackup(String entryBooks, String financialTransactions, String fiscalPeriods, String accounts, String entries, String identity) throws AlreadyExistAccountException, InvalidAccountNumberException { Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java 2014-08-07 16:17:17 UTC (rev 3904) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java 2014-08-07 20:17:41 UTC (rev 3905) @@ -82,9 +82,9 @@ public ReportsDatas generateAccountsReports(Account account, Boolean thirdPartAccountsMode, Date beginDate, Date endDate) { - BigDecimal credit = new BigDecimal(0); - BigDecimal debit = new BigDecimal(0); - BigDecimal solde = new BigDecimal(0); + BigDecimal credit = BigDecimal.ZERO; + BigDecimal debit = BigDecimal.ZERO; + BigDecimal solde = BigDecimal.ZERO; List<Entry> entries = new ArrayList<Entry>(); ReportsDatas reportsDatas = generateSubAccountReports(account, @@ -133,9 +133,9 @@ protected ReportsDatas generateSubAccountReports(Account account, Date beginDate, Date endDate) { ReportsDatas reportsDatas = new ReportsDatasImpl(); - BigDecimal credit = new BigDecimal(0); - BigDecimal debit = new BigDecimal(0); - BigDecimal solde = new BigDecimal(0); + BigDecimal credit = BigDecimal.ZERO; + BigDecimal debit = BigDecimal.ZERO; + BigDecimal solde = BigDecimal.ZERO; EntryTopiaDao entryTopiaDao = getDaoHelper().getEntryDao(); @@ -184,9 +184,9 @@ public ReportsDatas generateSubAccountBalance(Account account, Date beginDate, Date endDate, Boolean getEntries) { ReportsDatas reportsDatas = new ReportsDatasImpl(); - BigDecimal credit = new BigDecimal(0); - BigDecimal debit = new BigDecimal(0); - BigDecimal solde = new BigDecimal(0); + BigDecimal credit = BigDecimal.ZERO; + BigDecimal debit = BigDecimal.ZERO; + BigDecimal solde = BigDecimal.ZERO; EntryTopiaDao entryTopiaDao = getDaoHelper().getEntryDao(); @@ -238,9 +238,9 @@ public ReportsDatas generateEntryBooksReports(EntryBook entryBook, Date beginDate, Date endDate) { ReportsDatas reportsDatas = new ReportsDatasImpl(); - BigDecimal credit = new BigDecimal(0); - BigDecimal debit = new BigDecimal(0); - BigDecimal solde = new BigDecimal(0); + BigDecimal credit = BigDecimal.ZERO; + BigDecimal debit = BigDecimal.ZERO; + BigDecimal solde = BigDecimal.ZERO; // Get all entries with a topia query EntryTopiaDao entryTopiaDao = getDaoHelper().getEntryDao(); @@ -296,9 +296,9 @@ Boolean movementedFilter) { BalanceTrial balanceTrial = new BalanceTrialImpl(); balanceTrial.setReportsDatas(new ArrayList<ReportsDatas>()); - BigDecimal credit = new BigDecimal(0); - BigDecimal debit = new BigDecimal(0); - BigDecimal solde = new BigDecimal(0); + BigDecimal credit = BigDecimal.ZERO; + BigDecimal debit = BigDecimal.ZERO; + BigDecimal solde = BigDecimal.ZERO; AccountTopiaDao accountTopiaDao = getDaoHelper().getAccountDao(); //for each account create a balance sheet with a ReportsDatas @@ -326,7 +326,7 @@ reportsDatas.setAccount(account); BigDecimal amount = reportsDatas.getAmountSolde(); if (amount == null) { - amount = new BigDecimal(0); + amount = BigDecimal.ZERO; } if (movementedFilter) { if (!reportsDatas.getAmountCredit().equals(BigDecimal.ZERO) Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/VatStatementServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/VatStatementServiceImpl.java 2014-08-07 16:17:17 UTC (rev 3904) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/VatStatementServiceImpl.java 2014-08-07 20:17:41 UTC (rev 3905) @@ -205,8 +205,8 @@ Date selectedEndDate) { VatStatementAmounts vatStatementAmounts = new VatStatementAmountsImpl(); - BigDecimal debitTemp = new BigDecimal(0); - BigDecimal creditTemp = new BigDecimal(0); + BigDecimal debitTemp = BigDecimal.ZERO; + BigDecimal creditTemp = BigDecimal.ZERO; String accountNumbersList = findAccountNumberByVatStatement(vatStatement); @@ -260,7 +260,7 @@ List<VatStatement> vatStatements = getChildrenVatStatement(vatStatement); - BigDecimal amount = new BigDecimal(0); + BigDecimal amount = BigDecimal.ZERO; List<VatStatementAmounts> subResult = new ArrayList<VatStatementAmounts>(); for (VatStatement subVatStatement : vatStatements) { Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/ImportResult.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/ImportResult.java 2014-08-07 16:17:17 UTC (rev 3904) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/ImportResult.java 2014-08-07 20:17:41 UTC (rev 3905) @@ -96,6 +96,10 @@ return allExceptions; } + /** + * + * @return the class of the targeted entities + */ public Class getFromSource() { return fromSource; } 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-08-07 16:17:17 UTC (rev 3904) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java 2014-08-07 20:17:41 UTC (rev 3905) @@ -29,6 +29,7 @@ import com.google.common.base.Strings; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.LimaConfig; @@ -81,7 +82,6 @@ import java.util.Date; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -134,18 +134,23 @@ * Call the appropriate method in business service. * * @param importExportMethode - * @param file + * @param path * @param verbose */ - public void importExport(ImportExportEnum importExportMethode, String file, boolean verbose) { + public void importExport(ImportExportEnum importExportMethode, String path, boolean verbose) { final ImportExportEnum importExportMethodeF = importExportMethode; final Charset defaultCharset = Charsets.UTF_8; - if (Strings.isNullOrEmpty(file)) { - file = chooseFile(importExportMethode.getImportMode(), importExportMethode); + String filePath = path; + if (Strings.isNullOrEmpty(filePath)) { + filePath = chooseFile(importExportMethode.getImportMode(), importExportMethode); } + processImport(importExportMethode, verbose, importExportMethodeF, defaultCharset, filePath); + + } + + protected void processImport(ImportExportEnum importExportMethode, boolean verbose, final ImportExportEnum importExportMethod, final Charset defaultCharset, final String filePath) { //if export cancel - if (!Strings.isNullOrEmpty(file)) { - final String filePath = file; + if (!Strings.isNullOrEmpty(filePath)) { final Boolean verboseMode = verbose; final Boolean importMode = importExportMethode.getImportMode(); @@ -154,7 +159,7 @@ @Override protected ImportExportResults doInBackground() { ImportExportResults results = new ImportExportResults(); - switch (importExportMethodeF) { + switch (importExportMethod) { //####################################### CSV ############################################## case CSV_ACCOUNTCHARTS_EXPORT: @@ -237,6 +242,8 @@ content = loadFile(filePath, EncodingEnum.ISOLATIN1.getEncoding()); results.pushImportResults(importService.importEntriesFromEbp(content)); break; + default: + break; } return results; } @@ -261,86 +268,15 @@ } else { if (importMode) { - List<ImportResult> resultList = results.getImportResults(); - if (resultList != null) { - if (log.isDebugEnabled()) { - log.debug("importMode"); - log.debug("importExportMethodeF : " + importExportMethodeF); - for (ImportResult result : resultList) { - String importedEntity = result.getFromSource() == null ? "BACKUP" : result.getFromSource().getSimpleName(); - log.debug(importedEntity + " nbCreated: " + result.getNbCreated()); - log.debug(importedEntity + " nbUpdated: " + result.getNbUpdated()); - log.debug(importedEntity + " nbIgnored: " + result.getNbIgnored()); - Map<Integer, LimaException> exceptions = result.getAllExceptionsByLine(); - if (exceptions != null) { - for (LimaException exception : exceptions.values()) { - log.warn(exception.getCause()); - log.warn(exception.getStackTrace()); - } - } - } - } - if (log.isDebugEnabled()) { - log.debug("import.terminated"); - } - - String message = t("lima.ui.importexport.import.terminated")+"\n"; - for (ImportResult result : resultList) { - Class fromSource = result.getFromSource(); - message += "Import " + getFromSourceMessage(fromSource); - message += t("lima.ui.importexport.import.nbCreated", result.getNbCreated())+"\n"; - message += t("lima.ui.importexport.import.nbUpdated", result.getNbUpdated())+"\n"; - message += t("lima.ui.importexport.import.nbIgnored", result.getNbIgnored())+"\n"; - Map<Integer, LimaException> exceptionsByLine = result.getAllExceptionsByLine(); - message = displayErrorMessage(message, exceptionsByLine); - // message is null if import failed - if (message == null) { - break; - } - } - - if (message != null) { - JOptionPane.showMessageDialog( - waitView, - message, - t("lima.ui.importexport.import"), - JOptionPane.INFORMATION_MESSAGE); - } + List<ImportResult> importResults = results.getImportResults(); + if (importResults != null) { + ComputeImportResultMessage(importResults); } } else { List<ExportResult> exportResults = results.getExportResults(); if (exportResults != null) { - if (log.isDebugEnabled()) { - log.debug("export.terminated"); - - } - String message =""; - for (ExportResult result : exportResults) { - Class fromSource = result.getFromSource(); - message += "Export " + getFromSourceMessage(fromSource); - List<ExportException> exportExceptions = result.getExportExceptions(); - if (exportExceptions != null && !exportExceptions.isEmpty()) { - message += t("lima.ui.importexport.export.exception")+"\n"; - if (log.isErrorEnabled()) { - for (ExportException exportException : exportExceptions) { - log.error(exportException.getMessage()); - } - } - } - } - - JOptionPane.showMessageDialog( - waitView, - t("lima.ui.importexport.export.terminated"), - message, - JOptionPane.INFORMATION_MESSAGE); - } else { - if (log.isDebugEnabled()) { - log.debug("export.terminated"); - log.debug(t("lima.ui.importexport.no.result")); - } + ComputeExportResultMessage(exportResults); } - } } } @@ -355,52 +291,120 @@ } } - private String displayErrorMessage(String message, Map<Integer, LimaException> exceptionsByLine) { + private void ComputeExportResultMessage(List<ExportResult> exportResults) { + StringBuilder message = new StringBuilder(); + for (ExportResult result : exportResults) { + Class fromSource = result.getFromSource(); + String messageFromSource = getFromSourceMessage(fromSource); + message.append("Export "); + message.append(messageFromSource); + + List<ExportException> exportExceptions = result.getExportExceptions(); + if (exportExceptions != null && !exportExceptions.isEmpty()) { + message.append(t("lima.ui.importexport.export.exceptions")); + } + } + + DisplayImportExportResultMessage(message, false); + } + + private void ComputeImportResultMessage(List<ImportResult> resultList) { + StringBuilder message = new StringBuilder(); + message.append(t("lima.ui.importexport.import.terminated")); + StringBuilder errorMessage = null; + for (ImportResult result : resultList) { + Class fromSource = result.getFromSource(); + message.append("Import "); + message.append(getFromSourceMessage(fromSource)); + message.append(t("lima.ui.importexport.import.nbCreated", result.getNbCreated())); + message.append(t("lima.ui.importexport.import.nbUpdated", result.getNbUpdated())); + message.append(t("lima.ui.importexport.import.nbIgnored", result.getNbIgnored())); + + Map<Integer, LimaException> exceptionsByLine = result.getAllExceptionsByLine(); + errorMessage = displayErrorMessage(exceptionsByLine); + // message is null if import failed + if (errorMessage == null) { + break; + } else { + message.append(errorMessage.toString()); + } + } + + if (errorMessage != null) { + DisplayImportExportResultMessage(message, true); + } + } + + private void DisplayImportExportResultMessage(StringBuilder message, Boolean importMode) { + if (log.isDebugEnabled()){ + log.debug(message.toString()); + } + + String title = importMode ? t("lima.ui.importexport.import.terminated") : t("lima.ui.importexport.export.terminated"); + JOptionPane.showMessageDialog( + waitView, + message.toString(), + title, + JOptionPane.INFORMATION_MESSAGE); + } + + private StringBuilder displayErrorMessage(Map<Integer, LimaException> exceptionsByLine) { + StringBuilder result = new StringBuilder(); if (exceptionsByLine != null) { - Set<Integer> lines = exceptionsByLine.keySet(); - for (Integer line : lines) { - LimaException importException = exceptionsByLine.get(line); - message = message + t("lima.ui.importexport.import.line", line); + for (Map.Entry<Integer, LimaException> e:exceptionsByLine.entrySet()) { + result.append(t("lima.ui.importexport.import.line", e.getKey())); + LimaException importException = e.getValue(); if (importException instanceof InvalidAccountNumberException) { - message += t("lima.fiscalPeriod.franceAccountingRules.invalidAccountNumberException", ((InvalidAccountNumberException) importException).getAccountNumber())+"\n"; + result.append(t("lima.fiscalPeriod.franceAccountingRules.invalidAccountNumberException", ((InvalidAccountNumberException) importException).getAccountNumber())); } else if (importException instanceof NotNumberAccountNumberException) { - message += t("lima.fiscalPeriod.franceAccountingRules.notNumberAccountNumberException", ((NotNumberAccountNumberException) importException).getAccountNumber())+"\n"; + result.append(t("lima.fiscalPeriod.franceAccountingRules.notNumberAccountNumberException", ((NotNumberAccountNumberException) importException).getAccountNumber())); } else if (importException instanceof NotAllowedLabelException) { - message += t("lima.all.NotAllowedLabel", ((NotAllowedLabelException) importException).getLabel())+"\n"; + result.append(t("lima.all.NotAllowedLabel", ((NotAllowedLabelException) importException).getLabel())); } else if (importException instanceof MoreOneUnlockFiscalPeriodException) { - message += t("lima.fiscalPeriod.franceAccountingRules.moreOneUnlockFiscalPeriodException", ((MoreOneUnlockFiscalPeriodException) importException).getBeginDate(), ((MoreOneUnlockFiscalPeriodException) importException).getEndDate())+"\n"; + result.append(t("lima.fiscalPeriod.franceAccountingRules.moreOneUnlockFiscalPeriodException", ((MoreOneUnlockFiscalPeriodException) importException).getBeginDate(), ((MoreOneUnlockFiscalPeriodException) importException).getEndDate())); } else if (importException instanceof BeginAfterEndFiscalPeriodException) { - message += t("lima.fiscalPeriod.defaultAccountingRules.beginAfterEndFiscalPeriodException", ((BeginAfterEndFiscalPeriodException) importException).getFiscalPeriod().getBeginDate(), ((BeginAfterEndFiscalPeriodException) importException).getFiscalPeriod().getEndDate())+"\n"; + result.append(t("lima.fiscalPeriod.defaultAccountingRules.beginAfterEndFiscalPeriodException", ((BeginAfterEndFiscalPeriodException) importException).getFiscalPeriod().getBeginDate(), ((BeginAfterEndFiscalPeriodException) importException).getFiscalPeriod().getEndDate())); } else if (importException instanceof NotBeginNextDayOfLastFiscalPeriodException) { - message += t("lima.fiscalPeriod.franceAccountingRules.notBeginNextDayOfLastFiscalPeriodException", ((NotBeginNextDayOfLastFiscalPeriodException) importException).getFiscalPeriod().getBeginDate(), ((NotBeginNextDayOfLastFiscalPeriodException) importException).getFiscalPeriod().getEndDate())+"\n"; + result.append(t("lima.fiscalPeriod.franceAccountingRules.notBeginNextDayOfLastFiscalPeriodException", ((NotBeginNextDayOfLastFiscalPeriodException) importException).getFiscalPeriod().getBeginDate(), ((NotBeginNextDayOfLastFiscalPeriodException) importException).getFiscalPeriod().getEndDate())); } else if (importException instanceof LockedFinancialPeriodException) { - message += t("lima.financialTransaction.lockedFinancialPeriodException")+"\n"; + result.append(t("lima.financialTransaction.lockedFinancialPeriodException")); } else if (importException instanceof LockedEntryBookException) { - message += t("lima.financialTransaction.lockedEntryBookException", ((LockedEntryBookException) importException).getClosedPeriodicEntryBook().getFinancialPeriod().getBeginDate(), ((LockedEntryBookException) importException).getClosedPeriodicEntryBook().getFinancialPeriod().getEndDate())+"\n"; + result.append(t("lima.financialTransaction.lockedEntryBookException", ((LockedEntryBookException) importException).getClosedPeriodicEntryBook().getFinancialPeriod().getBeginDate(), ((LockedEntryBookException) importException).getClosedPeriodicEntryBook().getFinancialPeriod().getEndDate())); } else if (importException instanceof AlreadyExistFinancialStatement) { - message += t("lima.financialStatement.alreadyExistFinancialStatement", ((AlreadyExistFinancialStatement) importException).getFinancialStatementLabel())+"\n"; + result.append(t("lima.financialStatement.alreadyExistFinancialStatement", ((AlreadyExistFinancialStatement) importException).getFinancialStatementLabel())); } else if (importException instanceof AlreadyExistVatStatementException) { - message += t("lima.vatStatement.alreadyExistVatStatement", ((AlreadyExistVatStatementException) importException).getVatStatementLabel())+"\n"; + result.append(t("lima.vatStatement.alreadyExistVatStatement", ((AlreadyExistVatStatementException) importException).getVatStatementLabel())); } else if (importException instanceof NoFiscalPeriodFoundException) { - message += t("lima.import.entries.noFiscalPeriodFoundException")+"\n"; + result.append(t("lima.import.entries.noFiscalPeriodFoundException")); } else if (importException instanceof NoDataToImportException) { errorHelper.showErrorMessage(t("lima.import.noDataToImportException")); - return null; + log.warn(t("lima.import.noDataToImportException")); + result = null; + break; } else if (importException instanceof ImportFileException){ errorHelper.showErrorMessage(((ImportFileException) importException).getDetailMessage()); - return null; + log.warn(((ImportFileException) importException).getDetailMessage()); + result = null; + break; } else { - message +=t("lima.import.unknownError"); + result.append(t("lima.import.unknownError")); } - //message += t("lima.ui.importexport.import.exceptions", (line))+"\n"; - if (log.isErrorEnabled()) { - log.error(importException.getMessage()); + try { + throw importException; + } catch (LimaException ex) { + log.error(ex); } + } } - return message; + return result; } + /** + * Return with entities have been imported/exported. + * @param fromSource The imported target class + * @return the name of the imported/exported entities class. + */ private String getFromSourceMessage(Class fromSource) { String message; if (fromSource == null) { @@ -432,18 +436,18 @@ * open choose file dialog with appropriate file mode view * folders for export or folders+files for import * - * @param importMode - * @param importExportMethode - * @return + * @param importMode true = import mode false = export + * @param importExportMethod Inport/export to process + * @return the targeted file path */ - public String chooseFile(Boolean importMode, ImportExportEnum importExportMethode) { + public String chooseFile(Boolean importMode, ImportExportEnum importExportMethod) { String filePath = ""; JFileChooser chooser = new JFileChooser(); //Encoding option - JComboBox comboBox = new JComboBox(EncodingEnum.descriptions()); + JComboBox comboBox = new JComboBox<String>(EncodingEnum.descriptions()); - if (importExportMethode.getEncodingOption()) { + if (importExportMethod.getEncodingOption()) { JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); panel.add(new JLabel(t("lima.importexport.choiceencoding")), BorderLayout.WEST); @@ -457,7 +461,7 @@ approveButtonText = t("lima.ui.importexport.import"); chooser.setDialogTitle(approveButtonText); chooser.setApproveButtonText(approveButtonText); - } else if (importExportMethode.equals(ImportExportEnum.CSV_ALL_EXPORT)) { + } else if (importExportMethod.equals(ImportExportEnum.CSV_ALL_EXPORT)) { approveButtonText = t("lima.ui.importexport.export"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setDialogTitle(approveButtonText); @@ -479,16 +483,16 @@ /** * Get csv datas in string and write file. * - * @param filePath - * @param charset - * @param datas + * @param filePath path to file + * @param charset charset to use + * @param data data to write on file */ - protected File createFile(String filePath, String charset, String datas) { + protected File createFile(String filePath, String charset, String data) { File file = new File(filePath); BufferedWriter out = null; try { out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), charset)); - out.write(datas); + out.write(data); out.flush(); out.close(); } catch (IOException eee) { @@ -502,11 +506,11 @@ } /** - * Open csv file and get his datas on a string. + * Open csv file and get his data on a string. * - * @param filePath - * @param charset - * @return + * @param filePath path to targeted file + * @param charset charset to use for import + * @return file contents */ protected String loadFile(String filePath, String charset) { String result = null; @@ -527,46 +531,63 @@ } protected ImportExportResults exportBackup(String path, String charset){ - ImportExportResults results = exportService.exportBackup(charset); + ImportExportResults streamData = exportService.exportBackup(charset); ZipOutputStream export = null; + FileOutputStream result = null; try { SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); - FileOutputStream fos = new FileOutputStream(path + "/LIMA-BACKUP-"+ dateFormat.format(new Date())); - export = new ZipOutputStream(fos); - for (ExportResult result : results.getExportResults()) { - File file = createFile(JAVA_IO_TMPDIR + result.getFromSource().getSimpleName(), charset, result.getExportData()); - 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); + result = new FileOutputStream(path + "/LIMA-BACKUP-"+ dateFormat.format(new Date())); + export = new ZipOutputStream(result); + for (ExportResult exportedData : streamData.getExportResults()) { + if (exportedData != null && StringUtils.isNotBlank(exportedData.getExportData())) { + String data = exportedData.getExportData(); + File file = createFile(JAVA_IO_TMPDIR + exportedData.getFromSource().getSimpleName(), charset, data); + 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); + } + IOUtils.closeQuietly(stream); + FileUtils.forceDelete(file); } - stream.close(); - FileUtils.forceDelete(file); + } else { + // export failed + break; } } export.flush(); + } catch (IOException e) { - e.printStackTrace(); + errorHelper.showErrorMessage(t("lima.ui.importexport.export.failed")); + log.error(t("lima.ui.importexport.export.failed"), e); } finally { IOUtils.closeQuietly(export); + IOUtils.closeQuietly(result); } + return streamData; + } + + protected ImportExportResults importAllFromZipFile(String filePath) { + + String tmpDir = System.getProperty("java.io.tmpdir")+"/"; + String determinant = String.valueOf(new Date().getTime()); + ImportResult result = extractZipFile(filePath, tmpDir, determinant); + ImportExportResults results = processBackup(result, tmpDir, determinant); return results; } - protected ImportExportResults importAllFromZipFile(String filePath) { + protected ImportResult extractZipFile(String filePath, String tmpDir, String determinant) { ImportExportResults results = new ImportExportResults(); ImportResult result = results.createAddAndGetImportResult(null); ZipInputStream zipInputStream = null; - String tmpDir = System.getProperty("java.io.tmpdir")+"/"; FileInputStream inputStream = null; // use to be sure to not load old streams. - String date = String.valueOf(new Date().getTime()); try { inputStream = new FileInputStream(filePath); @@ -576,7 +597,8 @@ while ((entry = zipInputStream.getNextEntry()) != null) { byte[] buffer = new byte[2048]; - FileOutputStream fileoutputstream = new FileOutputStream(tmpDir + entry.getName() + "-" + date +".csv"); + String targetFileName= tmpDir + entry.getName() + "-" + determinant +".csv"; + FileOutputStream fileoutputstream = new FileOutputStream(targetFileName); int n; while ((n = zipInputStream.read(buffer, 0, 2048)) > -1) { @@ -588,45 +610,57 @@ } } catch (Exception e) { result.addInitException(new ImportFileException(t("lima.ui.importexport.import.extractFileError"))); + log.error(e.getStackTrace()); } finally { IOUtils.closeQuietly(zipInputStream); IOUtils.closeQuietly(inputStream); } - InputStream transactionsStream, entryBooksStream, fiscalPeriodsStream, entriesStream, accountsStream, identityStream; + return result; + } + protected ImportExportResults processBackup(ImportResult result, String tmpDir, String determinant) { + ImportExportResults results = null; + InputStream entryBooksStream = null, transactionsStream = null, fiscalPeriodsStream = null, accountsStream = null, entriesStream = null, identityStream = null; if (result.getAllExceptionsByLine() == null || result.getAllExceptionsByLine().isEmpty()) { try { - entryBooksStream = new FileInputStream(tmpDir + EntryBook.class.getSimpleName() + "-" + date + ".csv"); + entryBooksStream = new FileInputStream(tmpDir + EntryBook.class.getSimpleName() + "-" + determinant + ".csv"); String entryBooksStreamString = IOUtils.toString(entryBooksStream); IOUtils.closeQuietly(entryBooksStream); // import - transactionsStream = new FileInputStream(tmpDir + FinancialTransaction.class.getSimpleName() + "-" + date + ".csv"); + transactionsStream = new FileInputStream(tmpDir + FinancialTransaction.class.getSimpleName() + "-" + determinant + ".csv"); String transactionsStreamString = IOUtils.toString(transactionsStream); IOUtils.closeQuietly(transactionsStream); - fiscalPeriodsStream = new FileInputStream(tmpDir + FiscalPeriod.class.getSimpleName() + "-" + date + ".csv"); + fiscalPeriodsStream = new FileInputStream(tmpDir + FiscalPeriod.class.getSimpleName() + "-" + determinant + ".csv"); String fiscalPeriodsStreamString = IOUtils.toString(fiscalPeriodsStream); IOUtils.closeQuietly(fiscalPeriodsStream); - accountsStream = new FileInputStream(tmpDir + Account.class.getSimpleName() + "-" + date + ".csv"); + accountsStream = new FileInputStream(tmpDir + Account.class.getSimpleName() + "-" + determinant + ".csv"); String accountsStreamString = IOUtils.toString(accountsStream); IOUtils.closeQuietly(accountsStream); - entriesStream = new FileInputStream(tmpDir + Entry.class.getSimpleName() + "-" + date + ".csv"); + entriesStream = new FileInputStream(tmpDir + Entry.class.getSimpleName() + "-" + determinant + ".csv"); String entriesStreamString = IOUtils.toString(entriesStream); IOUtils.closeQuietly(entriesStream); - identityStream = new FileInputStream(tmpDir + Identity.class.getSimpleName() + "-" + date + ".csv"); + identityStream = new FileInputStream(tmpDir + Identity.class.getSimpleName() + "-" + determinant + ".csv"); String identityStreamString = IOUtils.toString(identityStream); IOUtils.closeQuietly(identityStream); - results= importService.importBackup(entryBooksStreamString, transactionsStreamString, fiscalPeriodsStreamString, accountsStreamString, entriesStreamString, identityStreamString); + results = importService.importBackup(entryBooksStreamString, transactionsStreamString, fiscalPeriodsStreamString, accountsStreamString, entriesStreamString, identityStreamString); } catch (Exception ex) { if(log.isInfoEnabled()) { log.info(ex); } result.addInitException(new ImportFileException(t("lima.ui.importexport.import.extractFileError"))); + } finally { + IOUtils.closeQuietly(entryBooksStream); + IOUtils.closeQuietly(transactionsStream); + IOUtils.closeQuietly(fiscalPeriodsStream); + IOUtils.closeQuietly(accountsStream); + IOUtils.closeQuietly(entriesStream); + IOUtils.closeQuietly(identityStream); } } return results; 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 2014-08-07 16:17:17 UTC (rev 3904) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties 2014-08-07 20:17:41 UTC (rev 3905) @@ -260,7 +260,7 @@ lima.financialStatements.check= lima.financialStatements.check.nothing= lima.financialStatements.check.warn= -lima.financialTransaction.lockedEntryBookException=Entry can not be added as entry book is locked for period from %1$tm/%1$te/%1$tY to %1$tm/%1$te/%1$tY. +lima.financialTransaction.lockedEntryBookException=Entry can not be added as entry book is locked for period from %1$tm/%1$te/%1$tY to %1$tm/%1$te/%1$tY.\n lima.financialTransaction.lockedFinancialPeriodException=locked financial transaction lima.financialstatement.accounts=Account list on debit and on credit lima.financialstatement.addfinancialStatementHeadererror=Can't add financialStatementHeader @@ -276,13 +276,13 @@ lima.financialstatement.provisiondeprecationaccounts=Provisions and deprecations accounts list lima.financialstatement.subamount=Calculate a subamount lima.financialstatementreport.listerror=Can't get entries list -lima.fiscalPeriod.defaultAccountingRules.beginAfterEndFiscalPeriodException=Fiscal period ending date must be after the begining one, begin\: %1$tm/%1$te/%1$tY end\: %1$tm/%1$te/%1$tY. -lima.fiscalPeriod.franceAccountingRules.invalidAccountNumberException=Master account is not a digit between 1 to 8 \: %s" + account.getAccountNumber() +lima.fiscalPeriod.defaultAccountingRules.beginAfterEndFiscalPeriodException=Fiscal period ending date must be after the begining one, begin\: %1$tm/%1$te/%1$tY end\: %1$tm/%1$te/%1$tY.\n +lima.fiscalPeriod.franceAccountingRules.invalidAccountNumberException=Master account is not a digit between 1 to 8 \: %s"\n lima.fiscalPeriod.franceAccountingRules.lastUnlockedFiscalPeriodException=Current fiscal period must not be closed. -lima.fiscalPeriod.franceAccountingRules.moreOneUnlockFiscalPeriodException=The ante fiscal period is not locked\: concerned fiscal period from %1$tm/%1$te/%1$tY to %1$tm/%1$te/%1$tY. +lima.fiscalPeriod.franceAccountingRules.moreOneUnlockFiscalPeriodException=The ante fiscal period is not locked\: concerned fiscal period from %1$tm/%1$te/%1$tY to %1$tm/%1$te/%1$tY.\n lima.fiscalPeriod.franceAccountingRules.noEmptyFiscalPeriodException=The fiscal period is not empty \! -lima.fiscalPeriod.franceAccountingRules.notBeginNextDayOfLastFiscalPeriodException=The new fiscal period must adjoining the last\: concerned fiscal period from %1$tm/%1$te/%1$tY to %1$tm/%1$te/%1$tY. -lima.fiscalPeriod.franceAccountingRules.notNumberAccountNumberException=Account Number that doesn't start with 4 have to be numeric\: %s" + account.getAccountNumber() +lima.fiscalPeriod.franceAccountingRules.notBeginNextDayOfLastFiscalPeriodException=The new fiscal period must adjoining the last\: concerned fiscal period from %1$tm/%1$te/%1$tY to %1$tm/%1$te/%1$tY.\n +lima.fiscalPeriod.franceAccountingRules.notNumberAccountNumberException=Account Number that doesn't start with 4 have to be numeric\: %s"\n lima.fiscalYears= lima.fiscalperiod.unbalancedtransactions=Fiscal Period has unbalanced transactions lima.help= @@ -358,7 +358,7 @@ lima.identity.phoneNumber=Phone number lima.identity.vatNumber=VAT number lima.identity.zipCode=Zip code -lima.import.entries.noFiscalPeriodFoundException=No fiscal period found. +lima.import.entries.noFiscalPeriodFoundException=No fiscal period found.\n lima.import.noDataToImportException=No data to import. lima.import.unknownError=Unknown error. lima.importexport.all= @@ -368,9 +368,9 @@ lima.importexport.export= lima.importexport.export.terminated= lima.importexport.import= -lima.importexport.import.alreadyExistFinancialStatement=Category with name %s exists for parent %s. -lima.importexport.import.alreadyExistVatStatement=VAT statement with name %s exists for parents %s. -lima.importexport.import.notAllowedLabel=Not allowed char in label\: %s. +lima.importexport.import.alreadyExistFinancialStatement=Category with name %s exists for parent %s.\n +lima.importexport.import.alreadyExistVatStatement=VAT statement with name %s exists for parents %s.\n +lima.importexport.import.notAllowedLabel=Not allowed char in label\: %s.\n lima.importexport.usevatpdf= lima.init.closed=Lima closed at %1$s lima.init.errorclosing=Error during Lima close @@ -605,8 +605,8 @@ lima.ui.importexport.entrybook=Entry books import completed. lima.ui.importexport.entrybooks=Entry books lima.ui.importexport.export=Export -lima.ui.importexport.export.exception= -lima.ui.importexport.export.exceptions=Export failed. +lima.ui.importexport.export.exceptions=Export failed.\n +lima.ui.importexport.export.failed=Export failed \! lima.ui.importexport.export.import.exceptions=Export has failed. lima.ui.importexport.export.terminated=Export terminated lima.ui.importexport.financialStatement=Financial transactions import completed. @@ -619,10 +619,10 @@ lima.ui.importexport.import.backupException=could not import backup. lima.ui.importexport.import.extractFileError=Could not extract file. lima.ui.importexport.import.line=Line %d\: -lima.ui.importexport.import.nbCreated=%d created -lima.ui.importexport.import.nbIgnored=%d ignored -lima.ui.importexport.import.nbUpdated=%d updated -lima.ui.importexport.import.terminated=Import terminated +lima.ui.importexport.import.nbCreated=%d created\n +lima.ui.importexport.import.nbIgnored=%d ignored\n +lima.ui.importexport.import.nbUpdated=%d updated\n +lima.ui.importexport.import.terminated=Import terminated\n lima.ui.importexport.import.vatpdfimport=The PDF has been imported. It can be found inside the Lima resources directory lima.ui.importexport.importcsv= lima.ui.importexport.importebp= 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 2014-08-07 16:17:17 UTC (rev 3904) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties 2014-08-07 20:17:41 UTC (rev 3905) @@ -243,8 +243,8 @@ lima.financialStatements.check=Vérification des comptes aux postes lima.financialStatements.check.nothing=Introuvable \: %s - %s \n lima.financialStatements.check.warn=Attention cette fonctionnalité n'est qu'une aide utilisateur.\n Certains comptes ne doivent pas être présent au bilan et compte de résultat.\n Il est donc normal que des comptes sont marqués comme introuvable.\n\n -lima.financialTransaction.lockedEntryBookException=Impossible d'ajouter une entré car le jounal %2$s (%1$s) est cloturé pour la période du %3$te %3$tB %3$tY au %4$te %4$tB %4$tY. -lima.financialTransaction.lockedFinancialPeriodException=La période financière est bloquée +lima.financialTransaction.lockedEntryBookException=Impossible d'ajouter une entré car le jounal %2$s (%1$s) est cloturé pour la période du %3$te %3$tB %3$tY au %4$te %4$tB %4$tY.\n +lima.financialTransaction.lockedFinancialPeriodException=La période financière est bloquée\n lima.financialstatement.accounts=Liste de comptes au crédit et au débit lima.financialstatement.addfinancialStatementHeadererror=Erreur lors de l'ajout de l'entête sur la déclaration financière lima.financialstatement.check= @@ -259,13 +259,13 @@ lima.financialstatement.provisiondeprecationaccounts=Liste de comptes d'amortissement et provisions lima.financialstatement.subamount=Calculer un sous-total lima.financialstatementreport.listerror=Erreur lors de la récupération des données de la liste -lima.fiscalPeriod.defaultAccountingRules.beginAfterEndFiscalPeriodException=La date de début doit être avant la date de fin, debut\: %1$te/%1$tm/%1$tY fin\: %1$te/%1$tm/%1$tY. -lima.fiscalPeriod.franceAccountingRules.invalidAccountNumberException=Le numéro du compte général n'est pas compris entre 1 et 8 \: %s +lima.fiscalPeriod.defaultAccountingRules.beginAfterEndFiscalPeriodException=La date de début doit être avant la date de fin, debut\: %1$te/%1$tm/%1$tY fin\: %1$te/%1$tm/%1$tY.\n +lima.fiscalPeriod.franceAccountingRules.invalidAccountNumberException=Le numéro du compte général n'est pas compris entre 1 et 8 \: %s\n lima.fiscalPeriod.franceAccountingRules.lastUnlockedFiscalPeriodException=Impossible de clore la dernière période fiscale ouverte. -lima.fiscalPeriod.franceAccountingRules.moreOneUnlockFiscalPeriodException=Le nombre maximal d'exercices ouverts est déjà ateint\: periode fiscale concernée du %1$te/%1$tm/%1$tY au %1$te/%1$tm/%1$tY. +lima.fiscalPeriod.franceAccountingRules.moreOneUnlockFiscalPeriodException=Le nombre maximal d'exercices ouverts est déjà ateint\: periode fiscale concernée du %1$te/%1$tm/%1$tY au %1$te/%1$tm/%1$tY.\n lima.fiscalPeriod.franceAccountingRules.noEmptyFiscalPeriodException=La période fiscale à supprimer n'est pas vide \! -lima.fiscalPeriod.franceAccountingRules.notBeginNextDayOfLastFiscalPeriodException=La nouvelle période fiscale doit suivre la précédente\: periode fiscale concernée du %1$te/%1$tm/%1$tY au %1$te/%1$tm/%1$tY. -lima.fiscalPeriod.franceAccountingRules.notNumberAccountNumberException=Un numéro de compte ne commençant pas par 4 doit être numérique \: %s +lima.fiscalPeriod.franceAccountingRules.notBeginNextDayOfLastFiscalPeriodException=La nouvelle période fiscale doit suivre la précédente\: periode fiscale concernée du %1$te/%1$tm/%1$tY au %1$te/%1$tm/%1$tY.\n +lima.fiscalPeriod.franceAccountingRules.notNumberAccountNumberException=Un numéro de compte ne commençant pas par 4 doit être numérique \: %s\n lima.fiscalYears=Exercices lima.fiscalperiod.unbalancedtransactions=La période fiscale contient des transactions non équilibrées lima.help=Aide @@ -316,7 +316,7 @@ lima.identity.phoneNumber=n° Tel lima.identity.vatNumber=n° TVA lima.identity.zipCode=Code Postal -lima.import.entries.noFiscalPeriodFoundException=Aucune periode fiscale trouvée. +lima.import.entries.noFiscalPeriodFoundException=Aucune periode fiscale trouvée.\n lima.import.noDataToImportException=Aucune donnée à importer. lima.import.unknownError=Erreur inconnue. lima.importexport.all=Tout @@ -326,9 +326,9 @@ lima.importexport.export=Exporter lima.importexport.export.terminated=Export terminé lima.importexport.import=Importer -lima.importexport.import.alreadyExistFinancialStatement=La transaction financière %s existe déjà sur le parent %s. -lima.importexport.import.alreadyExistVatStatement=La transaction de TVA %s existe déjà sur le parent %s. -lima.importexport.import.notAllowedLabel=Label non contenant un caractère interdit %s. +lima.importexport.import.alreadyExistFinancialStatement=La transaction financière %s existe déjà sur le parent %s.\n +lima.importexport.import.alreadyExistVatStatement=La transaction de TVA %s existe déjà sur le parent %s.\n +lima.importexport.import.notAllowedLabel=Label non contenant un caractère interdit %s.\n lima.importexport.usevatpdf=Êtes-vous sûr de vouloir utiliser ce pdf pour la déclaration de TVA ? lima.init.closed=Lima fermé à %1$s lima.init.errorclosing=Erreur lors de la fermeture @@ -526,9 +526,9 @@ lima.ui.importexport.entrybooks=Journaux lima.ui.importexport.export=Exporter lima.ui.importexport.export.action=Export -lima.ui.importexport.export.exception= -lima.ui.importexport.export.exceptions=Echec de l'export. -lima.ui.importexport.export.terminated=Export terminé +lima.ui.importexport.export.exceptions=Echec de l'export.\n +lima.ui.importexport.export.failed=Echec de l'export \! +lima.ui.importexport.export.terminated=Export terminé\n lima.ui.importexport.financialStatement=des déclaration financière terminé. lima.ui.importexport.financialTransaction=des transaction financière terminé. lima.ui.importexport.fiscalPeriod=des periodes fiscales terminé. @@ -538,10 +538,10 @@ lima.ui.importexport.import.backupException=Echec de l'import du backup. lima.ui.importexport.import.extractFileError=Le fichier n'est correct lima.ui.importexport.import.line=Ligne %d\: -lima.ui.importexport.import.nbCreated=%d créés -lima.ui.importexport.import.nbIgnored=%d ignorés -lima.ui.importexport.import.nbUpdated=%d mis à jours -lima.ui.importexport.import.terminated=Import terminé +lima.ui.importexport.import.nbCreated=%d créés\n +lima.ui.importexport.import.nbIgnored=%d ignorés\n +lima.ui.importexport.import.nbUpdated=%d mis à jours\n +lima.ui.importexport.import.terminated=Import terminé\n lima.ui.importexport.import.vatpdfimport=Le PDF a bien été importé dans le répertoire des ressources de Lima lima.ui.importexport.importcsv=Import/Export CSV lima.ui.importexport.importebp=Import/Export EBP
participants (1)
-
dcosse@users.chorem.org