Author: mallon Date: 2012-08-14 15:05:05 +0200 (Tue, 14 Aug 2012) New Revision: 3606 Url: http://chorem.org/repositories/revision/lima/3606 Log: refs #768 Correction sur la methode permettant le report a nouveau et la cloture de la periode fiscal selectionnee Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FiscalPeriodService.java trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/FranceAccountingRules.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodTableModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringTableModel.java trunk/lima-swing/src/main/resources/log4j.properties Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/FranceAccountingRules.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/FranceAccountingRules.java 2012-08-14 07:58:24 UTC (rev 3605) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/FranceAccountingRules.java 2012-08-14 13:05:05 UTC (rev 3606) @@ -187,7 +187,7 @@ fiscalPeriodDAO.getLastUnlockedFiscalPeriod(); //Check if the fiscal period to block is the oldest - if (!oldestUnBlockedFiscalPeriod.equals(fiscalPeriod)) { + if (oldestUnBlockedFiscalPeriod.equals(fiscalPeriod)) { throw new LimaBusinessException(_("lima-business.franceaccountingrules.antefiscalperiodnotblocked")); } } catch (TopiaException ex) { 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 2012-08-14 07:58:24 UTC (rev 3605) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java 2012-08-14 13:05:05 UTC (rev 3606) @@ -220,7 +220,7 @@ AccountingRules accountingRules = LimaConfig.getInstance().getAccountingRules(); - FiscalPeriod result = null; + FiscalPeriod result; try { if (fiscalPeriod.getLocked()) { @@ -252,97 +252,113 @@ } @Override - public void addRetainedEarnings(FiscalPeriod fiscalPeriod, boolean newyear, - EntryBook entryBook) throws LimaException { - - // re-attach entities to current session - FiscalPeriod localFiscalPeriod = null; - try { - FiscalPeriodDAO fiscalPeriodDAO = getDaoHelper().getFiscalPeriodDAO(); - localFiscalPeriod = fiscalPeriodDAO.findByTopiaId(fiscalPeriod.getTopiaId()); - } catch (TopiaException ex) { - throw new LimaException("Can't find fiscal period", ex); + public boolean isRetainedEarnings(FiscalPeriod fiscalPeriod) throws LimaException{ + boolean found = false; + List<FinancialTransaction> financialTransactionsList = + financialTransactionService.getAllFinancialTransactions( + fiscalPeriod.getBeginDate(), fiscalPeriod.getEndDate()); + //check if they are at least one transaction to be report + if (!financialTransactionsList.isEmpty()) { + int i = 0; + while (i < financialTransactionsList.size() && !found) { + Collection<Entry> entryList = financialTransactionsList.get(i).getEntry(); + for (Entry entry : entryList) { + if (entry.getAccount() != null) { + if (Integer.valueOf(entry.getAccount().getAccountNumber().substring(0, 1)) < 6 + && !entry.getAmount().equals(BigDecimal.ZERO)) { + found = true; + } + } + } + i++; + } } + return found; + } - //sets dates - // - endRetainedEarnings: last day of the closing year - // - beginRetainedEarnings: first open day of the following year - // Date endRetainedEarnings = fiscalPeriod.getBeginDate(); - // Date beginRetainedEarnings = null; + @Override + public FiscalPeriod retainedEarningsAndBlockFiscalPeriod(FiscalPeriod fiscalPeriod, EntryBook entryBook, + boolean retainedEarnings) throws LimaException { - //Sets entryBook - //search for the entryBook to use using param - boolean found = false; - List<EntryBook> entryBooksList = entryBookService.getAllEntryBooks(); - for (EntryBook entry : entryBooksList) { - if (!found && entry.getCode().equals(entryBook.getCode())) { - entryBook = entry; - found = true; + if (entryBook != null && retainedEarnings) { + + // re-attach entities to current session + FiscalPeriod localFiscalPeriod; + try { + FiscalPeriodDAO fiscalPeriodDAO = getDaoHelper().getFiscalPeriodDAO(); + localFiscalPeriod = fiscalPeriodDAO.findByTopiaId(fiscalPeriod.getTopiaId()); + } catch (TopiaException ex) { + throw new LimaException("Can't find fiscal period", ex); } - } - //if entrybook isn't found - //then create it - if (!found) { - entryBookService.createEntryBook(entryBook); - entryBooksList = entryBookService.getAllEntryBooks(); + //Sets entryBook + //search for the entryBook to use using param + boolean found = false; + List<EntryBook> entryBooksList = entryBookService.getAllEntryBooks(); for (EntryBook entry : entryBooksList) { if (!found && entry.getCode().equals(entryBook.getCode())) { entryBook = entry; found = true; } } - } - //Sets accounts, check if they exist, if not create them - //-> 8 COMPTES SPECIAUX - // -> 89 BILAN - // -> 890 Bilan d'ouverture - // -> 891 Bilan de cloture + //if entrybook isn't found + //then create it + if (!found) { + entryBookService.createEntryBook(entryBook); + entryBooksList = entryBookService.getAllEntryBooks(); + for (EntryBook entry : entryBooksList) { + if (!found && entry.getCode().equals(entryBook.getCode())) { + entryBook = entry; + found = true; + } + } + } - //89 BILAN - Account accountMaster = accountService.getAccountByNumber("89"); - if (accountMaster == null) { - accountMaster = new AccountImpl(); - accountMaster.setAccountNumber("89"); - accountMaster.setLabel("BILAN"); - accountMaster = accountService.createAccount(accountMaster); - } + //Sets accounts, check if they exist, if not create them + //-> 8 COMPTES SPECIAUX + // -> 89 BILAN + // -> 890 Bilan d'ouverture + // -> 891 Bilan de cloture - //890 Bilan d'ouverture - Account beginRetainedAccount = accountService.getAccountByNumber("890"); - if (beginRetainedAccount == null) { - beginRetainedAccount = new AccountImpl(); - beginRetainedAccount.setAccountNumber("890"); - beginRetainedAccount.setLabel("Bilan d'ouverture"); - beginRetainedAccount = accountService.createAccount(beginRetainedAccount); - } + //89 BILAN + Account accountMaster = accountService.getAccountByNumber("89"); + if (accountMaster == null) { + accountMaster = new AccountImpl(); + accountMaster.setAccountNumber("89"); + accountMaster.setLabel("BILAN"); + accountService.createAccount(accountMaster); + } - //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); - } + //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); + } - //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(); - } + //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); + } - if (lastFPeriod.getLocked()) { - throw new LimaBusinessException(_("lima-business.fiscalperiod.previousfiscalperiodalreadyblocked")); - } + //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(); + } - FinancialPeriod beginfinancialPeriod = null; - //settings to be done only if a new year exists - if (newyear) { + FinancialPeriod beginfinancialPeriod = null; + //look for the first financial period on the new fiscal year which is unlocked found = false; List<ClosedPeriodicEntryBook> resultsArray = @@ -352,6 +368,7 @@ Collections.sort(closedPeriodicEntryBook, new FinancialPeriodComparator()); resultsArray.addAll(closedPeriodicEntryBook); for (ClosedPeriodicEntryBook cPeriodicEntryBook : resultsArray) { + //check for - unlocked financial period // - date after the closing fiscal year // - unlocked entrybook @@ -368,83 +385,89 @@ if (!found) { throw new LimaBusinessException(_("lima-business.fiscalperiod.newfinancialperioderror")); } - } - //holds entries of all closing transactions - FinancialTransaction endfinancialTransaction = new FinancialTransactionImpl(); - if (lastFPeriod != null) { - //Sets the endfinancialTransaction - endfinancialTransaction.setEntryBook(entryBook); - endfinancialTransaction.setTransactionDate(localFiscalPeriod.getEndDate()); - endfinancialTransaction = financialTransactionService.createFinancialTransaction(endfinancialTransaction); - } + //holds entries of all closing transactions + FinancialTransaction endfinancialTransaction = new FinancialTransactionImpl(); + if (lastFPeriod != null) { + //Sets the endfinancialTransaction + endfinancialTransaction.setEntryBook(entryBook); + endfinancialTransaction.setTransactionDate(localFiscalPeriod.getEndDate()); + endfinancialTransaction = financialTransactionService.createFinancialTransaction(endfinancialTransaction); + } - //holds entries of all opening transactions - FinancialTransaction beginfinancialTransaction = new FinancialTransactionImpl(); - if (newyear) { + //holds entries of all opening transactions + FinancialTransaction beginfinancialTransaction = new FinancialTransactionImpl(); if (found) { //Sets the endfinancialTransaction beginfinancialTransaction.setEntryBook(entryBook); beginfinancialTransaction.setTransactionDate(beginfinancialPeriod.getBeginDate()); beginfinancialTransaction = financialTransactionService.createFinancialTransaction(beginfinancialTransaction); } - } - //Sets date for description, e.g: Report à nouveau (DATE) - Calendar calendar = Calendar.getInstance(); - calendar.setTime(fiscalPeriod.getEndDate()); + //Sets date for description, e.g: Report à nouveau (DATE) + Calendar calendar = Calendar.getInstance(); + calendar.setTime(fiscalPeriod.getEndDate()); - //Sets entries - BalanceTrial results = reportService.generateBalanceTrial(localFiscalPeriod.getBeginDate(), - localFiscalPeriod.getEndDate(), null, false, false); + //Sets entries + BalanceTrial results = reportService.generateBalanceTrial(localFiscalPeriod.getBeginDate(), + localFiscalPeriod.getEndDate(), null, false, false); - List<ReportsDatas> reportsDatasList = (List<ReportsDatas>) results.getReportsDatas(); + 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(_("lima-business.financialtransaction.retainedearnings.description") + " (" + calendar.get(Calendar.YEAR) + ")"); - beginEntry.setVoucher(_("lima-business.financialtransaction.retainedearnings.voucher")); - beginEntry.setFinancialTransaction(endfinancialTransaction); - beginEntry.setAccount(report.getAccount()); - beginEntry.setAmount(report.getAmountSolde().abs()); - beginEntry.setDebit(!report.getSoldeDebit()); - financialTransactionService.createEntry(beginEntry); - //save amounts inside account number 891 - beginEntry = new EntryImpl(); - beginEntry.setDescription(_("lima-business.financialtransaction.retainedearnings.description") + " (" + calendar.get(Calendar.YEAR) + ")"); - beginEntry.setVoucher(_("lima-business.financialtransaction.retainedearnings.voucher")); - beginEntry.setFinancialTransaction(endfinancialTransaction); - beginEntry.setAccount(endRetainedAccount); - beginEntry.setAmount(report.getAmountSolde().abs()); - beginEntry.setDebit(report.getSoldeDebit()); - financialTransactionService.createEntry(beginEntry); - //open new year accounts if new year exists and a date has been found for the transaction - if (newyear && found) { - //give back amounts from class 1 to 5 accounts - beginEntry = new EntryImpl(); + 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(_("lima-business.financialtransaction.retainedearnings.description") + " (" + calendar.get(Calendar.YEAR) + ")"); beginEntry.setVoucher(_("lima-business.financialtransaction.retainedearnings.voucher")); - beginEntry.setFinancialTransaction(beginfinancialTransaction); + beginEntry.setFinancialTransaction(endfinancialTransaction); beginEntry.setAccount(report.getAccount()); beginEntry.setAmount(report.getAmountSolde().abs()); - beginEntry.setDebit(report.getSoldeDebit()); + beginEntry.setDebit(!report.getSoldeDebit()); financialTransactionService.createEntry(beginEntry); - //close account by removing amount from account number 890 + + //save amounts inside account number 891 beginEntry = new EntryImpl(); beginEntry.setDescription(_("lima-business.financialtransaction.retainedearnings.description") + " (" + calendar.get(Calendar.YEAR) + ")"); beginEntry.setVoucher(_("lima-business.financialtransaction.retainedearnings.voucher")); - beginEntry.setFinancialTransaction(beginfinancialTransaction); + beginEntry.setFinancialTransaction(endfinancialTransaction); beginEntry.setAccount(endRetainedAccount); beginEntry.setAmount(report.getAmountSolde().abs()); - beginEntry.setDebit(!report.getSoldeDebit()); + beginEntry.setDebit(report.getSoldeDebit()); financialTransactionService.createEntry(beginEntry); + + //open new year accounts if new year exists and a date has been found for the transaction + if (found) { + //give back amounts from class 1 to 5 accounts + beginEntry = new EntryImpl(); + beginEntry.setDescription(_("lima-business.financialtransaction.retainedearnings.description") + " (" + calendar.get(Calendar.YEAR) + ")"); + beginEntry.setVoucher(_("lima-business.financialtransaction.retainedearnings.voucher")); + beginEntry.setFinancialTransaction(beginfinancialTransaction); + beginEntry.setAccount(report.getAccount()); + beginEntry.setAmount(report.getAmountSolde().abs()); + beginEntry.setDebit(report.getSoldeDebit()); + financialTransactionService.createEntry(beginEntry); + //close account by removing amount from account number 890 + beginEntry = new EntryImpl(); + beginEntry.setDescription(_("lima-business.financialtransaction.retainedearnings.description") + " (" + calendar.get(Calendar.YEAR) + ")"); + beginEntry.setVoucher(_("lima-business.financialtransaction.retainedearnings.voucher")); + beginEntry.setFinancialTransaction(beginfinancialTransaction); + beginEntry.setAccount(endRetainedAccount); + beginEntry.setAmount(report.getAmountSolde().abs()); + beginEntry.setDebit(!report.getSoldeDebit()); + financialTransactionService.createEntry(beginEntry); + } } } } + + /*block the antepenultimate fiscalPeriod */ + FiscalPeriod fiscalPeriodBlocked = blockFiscalPeriod(fiscalPeriod); + return fiscalPeriodBlocked; } /** Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FiscalPeriodService.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FiscalPeriodService.java 2012-08-14 07:58:24 UTC (rev 3605) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FiscalPeriodService.java 2012-08-14 13:05:05 UTC (rev 3606) @@ -56,7 +56,21 @@ void deleteFiscalPeriod(FiscalPeriod fiscalPeriod) throws LimaException; - void addRetainedEarnings(FiscalPeriod fiscalPeriod, - boolean newyear, - EntryBook entryBook) throws LimaException; + /** + * Eventually add retained earnings on last unclosed fiscal period, + * and in any case, block fiscal period + * @param fiscalPeriod fiscal period selected, and to block + * @param entryBook entry book where entries will be save in new fiscal period + * @param retainedEarnings to know if user want retained earnings + * @return fiscal period blocked + * */ + FiscalPeriod retainedEarningsAndBlockFiscalPeriod(FiscalPeriod fiscalPeriod, EntryBook entryBook, + boolean retainedEarnings) throws LimaException; + + /** + * Test if we have retained earnings on a fiscal period + * @param fiscalPeriod + * @return true if retained earnings are possible + * */ + boolean isRetainedEarnings(FiscalPeriod fiscalPeriod) throws LimaException; } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodTableModel.java 2012-08-14 07:58:24 UTC (rev 3605) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodTableModel.java 2012-08-14 13:05:05 UTC (rev 3606) @@ -32,6 +32,8 @@ import javax.swing.table.AbstractTableModel; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.chorem.lima.business.LimaException; import org.chorem.lima.entity.FiscalPeriod; @@ -49,6 +51,8 @@ /** serialVersionUID. */ private static final long serialVersionUID = 77027335135838258L; + private static final Log log = LogFactory.getLog(FiscalPeriodTableModel.class); + protected List<FiscalPeriod> fiscalPeriods; public void setFiscalPeriods(List<FiscalPeriod> fiscalPeriods) { @@ -147,7 +151,12 @@ public void updateFiscalPeriod(FiscalPeriod fiscalPeriod) throws LimaException { int row = fiscalPeriods.indexOf(fiscalPeriod); + + if (log.isDebugEnabled()) { + log.debug("Selected row : " + row); + } + fiscalPeriods.set(row, fiscalPeriod); - fireTableRowsInserted(row, row); + fireTableRowsUpdated(row, row); } } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodViewHandler.java 2012-08-14 07:58:24 UTC (rev 3605) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodViewHandler.java 2012-08-14 13:05:05 UTC (rev 3606) @@ -27,11 +27,7 @@ import static org.nuiton.i18n.I18n._; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.math.BigDecimal; import java.util.Calendar; -import java.util.Collection; import java.util.Date; import java.util.List; @@ -46,7 +42,6 @@ import org.chorem.lima.business.ServiceListener; import org.chorem.lima.business.api.FinancialTransactionService; import org.chorem.lima.business.api.FiscalPeriodService; -import org.chorem.lima.entity.Entry; import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.EntryBookImpl; import org.chorem.lima.entity.FinancialTransaction; @@ -194,106 +189,72 @@ } /** - * Block selected fiscal period after user confirmation. + * Block selected fiscal period, + * and make new fiscal period and retained earnings + * after user confirmations */ public void blockFiscalPeriod() { JXTable fiscalPeriodeTable = view.getFiscalPeriodTable(); - FiscalPeriodTableModel model = (FiscalPeriodTableModel) view.getFiscalPeriodTableModel(); + FiscalPeriodTableModel model = view.getFiscalPeriodTableModel(); int selectedRow = fiscalPeriodeTable.getSelectedRow(); FiscalPeriod selectedFiscalPeriod = model.getFiscalPeriodAt(selectedRow); //check if the user want to block the fiscal year - int response = JOptionPane.showConfirmDialog(view, + int answerBlock = JOptionPane.showConfirmDialog(view, _("lima.ui.fiscalperiod.block.confirmation"), _("lima.ui.fiscalperiod.block.title"), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); - if (response == JOptionPane.YES_OPTION) { - // FIXME report a nouveau et bloquage en une seule opération - // transactionnelle - selectedFiscalPeriod = fiscalPeriodService.blockFiscalPeriod(selectedFiscalPeriod); - model.updateFiscalPeriod(selectedFiscalPeriod); + if (answerBlock == JOptionPane.YES_OPTION) { + boolean retainedEarnings = false; + EntryBook entryBook = null; - //use to tell if the user wants to create a new fiscal year - boolean newyear = false; - //check if two fiscal periods are open - if (model.getRowCount() - 1 != selectedRow) { - newyear = true; //two are open - } else { - //check if the user wants to create a new fiscal year - response = JOptionPane.showConfirmDialog(view, - _("lima.ui.fiscalperiod.block.newyear"), - _("lima.ui.fiscalperiod.block.title"), JOptionPane.YES_NO_OPTION, - JOptionPane.QUESTION_MESSAGE); - // create a new fiscal year - if (response == JOptionPane.YES_OPTION) { - addFiscalPeriod(); - newyear = true; - } - } + //check if the user wants to create a new fiscal year + int answerCreate = JOptionPane.showConfirmDialog(view, + _("lima.ui.fiscalperiod.block.newyear"), + _("lima.ui.fiscalperiod.block.title"), JOptionPane.YES_NO_OPTION, + JOptionPane.QUESTION_MESSAGE); - addRetainedEarnings(selectedFiscalPeriod, newyear); - view.getModel().setBlockEnabled(false); - view.getModel().setDeleteEnabled(false); - } - } + // create a new fiscal year + if (answerCreate == JOptionPane.YES_OPTION) { + addFiscalPeriod(); - /** - * Report à nouveau. - * - * @deprecated a déplacer en partie en metier - * @param selectedFiscalPeriod - * @param newyear - */ - @Deprecated - public void addRetainedEarnings(FiscalPeriod selectedFiscalPeriod, boolean newyear) { + //report if they are at least one transaction to be report + if (fiscalPeriodService.isRetainedEarnings(selectedFiscalPeriod)) { - boolean found = false; - List<FinancialTransaction> financialTransactionsList = - financialTransactionService.getAllFinancialTransactions( - selectedFiscalPeriod.getBeginDate(), selectedFiscalPeriod.getEndDate()); - //check if they are at least one transaction to be report - if (!financialTransactionsList.isEmpty()) { - int i = 0; - while (i < financialTransactionsList.size() && !found) { - Collection<Entry> entryList = financialTransactionsList.get(i).getEntry(); - for (Entry entry : entryList) { - if (Integer.valueOf(entry.getAccount().getAccountNumber().substring(0, 1)) < 6 - && !entry.getAmount().equals(BigDecimal.ZERO)) { - found = true; + //check if the user wants to report datas + int answerRetainedEarnings = JOptionPane.showConfirmDialog(view, + _("lima.ui.fiscalperiod.block.addretainedearnings"), + _("lima.ui.fiscalperiod.block.title"), JOptionPane.YES_NO_OPTION, + JOptionPane.QUESTION_MESSAGE); + + //ask user for the entrybook to use for retained earnings + if (answerRetainedEarnings == JOptionPane.YES_OPTION) { + retainedEarnings = true; + + //Sets EntryBook + EntryBook newEntryBook = new EntryBookImpl(); + RetainedEarningsEntryBookForm entryBookForm = + new RetainedEarningsEntryBookForm(view); + entryBookForm.setEntryBook(newEntryBook); + + // jaxx constructor don't call super() ? + entryBookForm.setLocationRelativeTo(view); + entryBookForm.setVisible(true); + entryBook = entryBookForm.getEntryBook(); } } - i++; } + + FiscalPeriod fiscalPeriodBlocked = fiscalPeriodService.retainedEarningsAndBlockFiscalPeriod(selectedFiscalPeriod, entryBook, retainedEarnings); + model.updateFiscalPeriod(fiscalPeriodBlocked); + + view.getModel().setBlockEnabled(false); + view.getModel().setDeleteEnabled(false); } - //report if they are at least one transaction to be report - if (found) { - //check if the user wants to report datas - int response = JOptionPane.showConfirmDialog(view, - _("lima.ui.fiscalperiod.block.addretainedearnings"), - _("lima.ui.fiscalperiod.block.title"), JOptionPane.YES_NO_OPTION, - JOptionPane.QUESTION_MESSAGE); - //ask user for the entrybook to use for retained earnings - if (response == JOptionPane.YES_OPTION) { - //Sets EntryBook - EntryBook newEntryBook = new EntryBookImpl(); - RetainedEarningsEntryBookForm entryBookForm = - new RetainedEarningsEntryBookForm(view); - entryBookForm.setEntryBook(newEntryBook); - // jaxx constructor don't call super() ? - entryBookForm.setLocationRelativeTo(view); - entryBookForm.setVisible(true); - // null == cancel action - EntryBook entryBook = entryBookForm.getEntryBook(); - if (entryBook != null) { - fiscalPeriodService.addRetainedEarnings( - selectedFiscalPeriod, newyear, entryBook); - } - } - } } - + @Override public void notifyMethod(String serviceName, String methodeName) { //refresh on import datas @@ -340,12 +301,7 @@ enableBlock = true; //only an empty and open fiscal period may be deleted - if (financialTransactionList.size() <= 0){ - enableDelete = true; - - }else{ - enableDelete = false; - } + enableDelete = financialTransactionList.size() <= 0; } } view.getModel().setBlockEnabled(enableBlock); Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringTableModel.java 2012-08-14 07:58:24 UTC (rev 3605) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringTableModel.java 2012-08-14 13:05:05 UTC (rev 3606) @@ -237,19 +237,6 @@ getEntryAt(rowEntry).setLettering(letters); fireTableRowsUpdated(rowEntry, rowEntry); } -// fireTableDataChanged(); } - /**Copy parametrised entry, without amount*/ - /*public Entry copyEntryWithoutAmount(Entry entryToCopy) { - Entry copiedEntry = new EntryImpl(); - - copiedEntry.setAccount(entryToCopy.getAccount()); - copiedEntry.setDescription(entryToCopy.getDescription()); - copiedEntry.setDetail(entryToCopy.getDetail()); - copiedEntry.setFinancialTransaction(entryToCopy.getFinancialTransaction()); - copiedEntry.setVoucher(entryToCopy.getVoucher()); - - return copiedEntry; - }*/ } Modified: trunk/lima-swing/src/main/resources/log4j.properties =================================================================== --- trunk/lima-swing/src/main/resources/log4j.properties 2012-08-14 07:58:24 UTC (rev 3605) +++ trunk/lima-swing/src/main/resources/log4j.properties 2012-08-14 13:05:05 UTC (rev 3606) @@ -54,4 +54,5 @@ log4j.logger.org.chorem.lima.ui.combobox.FiscalPeriodComboBoxModel=DEBUG log4j.logger.org.chorem.lima.ui.financialtransactionsearch.FinancialTransactionPeriodSearchPanel=DEBUG log4j.logger.org.chorem.lima.ui.financialtransactionsearch.FinancialTransactionSearchViewHandler=DEBUG -log4j.logger.org.chorem.lima.ui.fiscalperiod.FiscalPeriodViewHandler=DEBUG \ No newline at end of file +log4j.logger.org.chorem.lima.ui.fiscalperiod.FiscalPeriodViewHandler=DEBUG +log4j.logger.org.chorem.lima.ui.fiscalperiod.FiscalPeriodTableModel=DEBUG \ No newline at end of file