r3209 - in trunk: lima-business/src/main/java/org/chorem/lima/business/ejb lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod lima-swing/src/main/resources/i18n
Author: vsalaun Date: 2011-07-11 15:36:42 +0200 (Mon, 11 Jul 2011) New Revision: 3209 Url: http://chorem.org/repositories/revision/lima/3209 Log: #345 add checking question for user Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodViewHandler.java trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java 2011-07-11 11:08:52 UTC (rev 3208) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java 2011-07-11 13:36:42 UTC (rev 3209) @@ -476,10 +476,14 @@ List<ReportsDatas> reportsDatasList = (List<ReportsDatas>) results.getReportsDatas(); + //check if at least one transaction has been reported + boolean transaction = false; + for (ReportsDatas report : reportsDatasList) { //Account class from 1 to 5 and only non zero amount - if (report.getAccount().getAccountNumber().substring(0, 1).matches("[1-5]") + if (Integer.valueOf(report.getAccount().getAccountNumber().substring(0, 1)) < 6 && !report.getAmountSolde().equals(BigDecimal.ZERO)) { + transaction = true; //close accounts by removing amounts from all class 1 to 5 accounts beginEntry = new EntryImpl(); beginEntry.setDescription(_("lima-business.financialtransaction.retainedearnings.description") + " (" + calendar.get(Calendar.YEAR) + ")"); @@ -521,8 +525,13 @@ } } } + //if no transaction has been reported + if (!transaction) { + topiaContext.rollbackTransaction(); //if no problem appeared, commit - commitTransaction(topiaContext); + } else { + commitTransaction(topiaContext); + } } catch (TopiaException ex) { doCatch(topiaContext, ex, log); 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 2011-07-11 11:08:52 UTC (rev 3208) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodViewHandler.java 2011-07-11 13:36:42 UTC (rev 3209) @@ -27,8 +27,11 @@ import static org.nuiton.i18n.I18n._; -import java.util.Date; +import java.math.BigDecimal; +import java.util.Collection; +import java.util.List; + import javax.swing.JOptionPane; import org.jdesktop.swingx.JXTable; import org.nuiton.util.DateUtil; @@ -37,8 +40,10 @@ import org.chorem.lima.business.FinancialTransactionServiceMonitorable; import org.chorem.lima.business.FiscalPeriodServiceMonitorable; import org.chorem.lima.business.LimaException; +import org.chorem.lima.entity.Entry; import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.EntryBookImpl; +import org.chorem.lima.entity.FinancialTransaction; import org.chorem.lima.entity.FiscalPeriod; import org.chorem.lima.service.LimaServiceFactory; import org.chorem.lima.ui.fiscalperiod.AddPeriod; @@ -67,12 +72,18 @@ /** Service. */ protected FiscalPeriodServiceMonitorable fiscalPeriodService; + protected FinancialTransactionServiceMonitorable financialTransactionService; + protected FiscalPeriodViewHandler(FiscalPeriodView view) { this.view=view; fiscalPeriodService = LimaServiceFactory.getInstance().getService( FiscalPeriodServiceMonitorable.class); + + financialTransactionService = + LimaServiceFactory.getInstance().getService( + FinancialTransactionServiceMonitorable.class); } public void addFiscalPeriod() { @@ -135,7 +146,7 @@ if (model.getRowCount()-1 != selectedRow) { newyear = true; //two are open } else { - //check if the user want to create a new fiscal year + //check if the user wants to create a new fiscal year response = JOptionPane.showConfirmDialog(getView(), _("lima.charts.fiscalperiod.question.newyear"), @@ -168,18 +179,50 @@ FiscalPeriodTableModel model = (FiscalPeriodTableModel)getView().getFiscalPeriodTable().getModel(); try { - //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); + boolean found = false; + List<FinancialTransaction> financialTransactionsList = + financialTransactionService.getAllFinancialTransactionsFromDateToDate( + 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; + } + } + i++; + } } + //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(getView(), + _("lima.charts.fiscalperiod.question.addretainedearnings"), + _("lima.common.question"), 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); + } + } + } } catch (LimaException eee) { if (log.isErrorEnabled()) { log.error("Can't set net income", eee); 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 2011-07-11 11:08:52 UTC (rev 3208) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties 2011-07-11 13:36:42 UTC (rev 3209) @@ -27,10 +27,10 @@ lima.charts.financialtransaction.question.removeentry=Do you really remove this entry ? lima.charts.financialtransaction.question.removetransaction=Do you really remove this transaction ? lima.charts.fiscalperiod.add=Add fiscalperiod -lima.charts.fiscalperiod.addretainedearnings=Report retained earnings lima.charts.fiscalperiod.block=Block fiscalperiod lima.charts.fiscalperiod.create=Create fiscalperiod -lima.charts.fiscalperiod.question.blocked=Block fiscalperiod +lima.charts.fiscalperiod.question.addretainedearnings=Report retained earnings ? +lima.charts.fiscalperiod.question.blocked=Block fiscalperiod ? lima.charts.fiscalperiod.question.morethan12=This period is longer than 12 months. Do you really create this ? lima.charts.fiscalperiod.question.newyear=Do you want to create a new fiscal year ? lima.charts.fiscalyear=Fiscal Years 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 2011-07-11 11:08:52 UTC (rev 3208) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties 2011-07-11 13:36:42 UTC (rev 3209) @@ -27,9 +27,9 @@ lima.charts.financialtransaction.question.removeentry=Voulez-vous supprimer cette ligne de transaction? lima.charts.financialtransaction.question.removetransaction=Voulez-vous supprimer cette transaction? lima.charts.fiscalperiod.add=Nouvel exercice -lima.charts.fiscalperiod.addretainedearnings=Reporter à nouveau lima.charts.fiscalperiod.block=Cloturer un exercice lima.charts.fiscalperiod.create=Choisissez la date de début et de fin du nouvel exercice +lima.charts.fiscalperiod.question.addretainedearnings=Reporter à nouveau? lima.charts.fiscalperiod.question.blocked=Ètes vous sûre de vouloir clôturer cette exercice ? Cette action est irréversible \! lima.charts.fiscalperiod.question.morethan12=La période sélectionnée n'est pas de 12 mois, voulez-vous continuer ? lima.charts.fiscalperiod.question.newyear=Voulez vous créer un nouvel exercice?
participants (1)
-
vsalaun@users.chorem.org