Author: vsalaun Date: 2011-07-01 16:31:21 +0200 (Fri, 01 Jul 2011) New Revision: 3196 Url: http://chorem.org/repositories/revision/lima/3196 Log: block document edition when the fiscal isn't closed Removed: trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/RetainedEarningsDateForm.jaxx Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodViewHandler.java 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-01 14:03:16 UTC (rev 3195) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java 2011-07-01 14:31:21 UTC (rev 3196) @@ -441,7 +441,6 @@ //holds entries of all closing transactions FinancialTransaction endfinancialTransaction = new FinancialTransactionImpl(); if (lastFPeriod != null) { - System.out.println("not null"); //Sets the endfinancialTransaction endfinancialTransaction.setAmountDebit(BigDecimal.ZERO); endfinancialTransaction.setAmountCredit(BigDecimal.ZERO); Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceViewHandler.java 2011-07-01 14:03:16 UTC (rev 3195) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceViewHandler.java 2011-07-01 14:31:21 UTC (rev 3196) @@ -32,12 +32,18 @@ import java.net.URI; import java.net.URISyntaxException; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Date; +import java.util.List; + +import javax.swing.JOptionPane; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.LimaConfig; import org.chorem.lima.beans.BalanceTrial; import org.chorem.lima.business.FinancialTransactionServiceMonitorable; +import org.chorem.lima.business.FiscalPeriodServiceMonitorable; import org.chorem.lima.business.HttpServerServiceMonitorable; import org.chorem.lima.business.ImportServiceMonitorable; import org.chorem.lima.business.LimaException; @@ -45,6 +51,7 @@ import org.chorem.lima.business.ServiceListener; import org.chorem.lima.business.utils.DocumentsEnum; import org.chorem.lima.business.utils.FormatsEnum; +import org.chorem.lima.entity.FiscalPeriod; import org.chorem.lima.service.LimaServiceFactory; import org.chorem.lima.util.ErrorHelper; @@ -63,6 +70,7 @@ /** Services. */ protected ReportServiceMonitorable reportService; protected HttpServerServiceMonitorable httpServerServiceMonitorable; + protected FiscalPeriodServiceMonitorable fiscalPeriodService; /** DatePicker Begin Date. */ protected Date selectedBeginDate; @@ -90,10 +98,14 @@ ReportServiceMonitorable.class); port = LimaServiceFactory.getInstance().getService( HttpServerServiceMonitorable.class).getHttpPort(); + fiscalPeriodService = + LimaServiceFactory.getInstance().getService( + FiscalPeriodServiceMonitorable.class); LimaServiceFactory.getInstance().getService( ImportServiceMonitorable.class).addListener(this); LimaServiceFactory.getInstance().getService( FinancialTransactionServiceMonitorable.class).addListener(this); + } public void setBeginDate(Date date){ @@ -172,21 +184,55 @@ public void createDocument() { if (selectedBeginDate != null & selectedEndDate != null){ - FormatsEnum selectedEnum = (FormatsEnum) view.getDocumentEditor().getSelectedItem(); - String address = LimaConfig.getInstance().getHostAdress(); + //looks for all blocked fiscal periods + List<FiscalPeriod> blockedFiscalPeriods = new ArrayList<FiscalPeriod>(); try { - String url = "http://"+address+":"+port+"/?beginDate=" - +dateFormat.format(selectedBeginDate) - +"&endDate="+dateFormat.format(selectedEndDate)+"&format=" - +selectedEnum.getExtension()+"&model=" - + DocumentsEnum.BALANCE.getFileName(); - Desktop.getDesktop().browse(new URI(url)); - } catch (IOException e) { - log.error("Can't open browser", e); - } catch (URISyntaxException e) { - log.error("Can't create news URI", e); + blockedFiscalPeriods = fiscalPeriodService.getAllBlockedFiscalPeriods(); + }catch (LimaException eee) { + if (log.isErrorEnabled()) { + log.debug("Enable to create document ", eee); + } + ErrorHelper.showErrorDialog("Enable to create document ", eee); } + + //tells if the fiscaPeriod as been found and is blocked + boolean error = true; + + for (FiscalPeriod blockedFiscalPeriod : blockedFiscalPeriods) { + if (blockedFiscalPeriod.getBeginDate().equals(selectedBeginDate) + && blockedFiscalPeriod.getEndDate().equals(selectedEndDate) + && blockedFiscalPeriod.getLocked()) { + error = false; + } + } + + //shows error message to user if the fiscalPeriod is unblocked + if (error) { + JOptionPane.showMessageDialog( + view, + "Can't create document on an open fiscal year", + _("lima.common.error"), + JOptionPane.ERROR_MESSAGE); + } else { + + FormatsEnum selectedEnum = + (FormatsEnum) view.getDocumentEditor().getSelectedItem(); + String address = LimaConfig.getInstance().getHostAdress(); + + try { + String url = "http://"+address+":"+port+"/?beginDate=" + +dateFormat.format(selectedBeginDate) + +"&endDate="+dateFormat.format(selectedEndDate)+"&format=" + +selectedEnum.getExtension()+"&model=" + + DocumentsEnum.BALANCE.getFileName(); + Desktop.getDesktop().browse(new URI(url)); + } catch (IOException e) { + log.error("Can't open browser", e); + } catch (URISyntaxException e) { + log.error("Can't create news URI", e); + } + } } } 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-01 14:03:16 UTC (rev 3195) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodViewHandler.java 2011-07-01 14:31:21 UTC (rev 3196) @@ -118,7 +118,6 @@ int selectedRow = fiscalPeriodeTable.getSelectedRow(); FiscalPeriodTableModel model = (FiscalPeriodTableModel)getView().getFiscalPeriodTable().getModel(); - System.out.println(fiscalPeriodeTable.getRowCount() + " " + selectedRow); // blocked it try { FiscalPeriod selectedFiscalPeriod = @@ -149,7 +148,7 @@ } } addRetainedEarnings(selectedFiscalPeriod, newyear); - //model.blockFiscalPeriod(selectedFiscalPeriod); + model.blockFiscalPeriod(selectedFiscalPeriod); } } catch (LimaException eee) { if (log.isErrorEnabled()) { @@ -179,9 +178,6 @@ // null == cancel action EntryBook entryBook = entryBookForm.getEntryBook(); if (entryBook != null) { - System.out.println(selectedFiscalPeriod); - System.out.println(newyear); - System.out.println(entryBook); fiscalPeriodService.addRetainedEarnings(selectedFiscalPeriod, newyear, entryBook); } } catch (LimaException eee) { Deleted: trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/RetainedEarningsDateForm.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/RetainedEarningsDateForm.jaxx 2011-07-01 14:03:16 UTC (rev 3195) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/RetainedEarningsDateForm.jaxx 2011-07-01 14:31:21 UTC (rev 3196) @@ -1,47 +0,0 @@ -<JDialog modal="true" - defaultCloseOperation="{JDialog.DO_NOTHING_ON_CLOSE}" - onWindowClosing="performCancel();"> - - <script> - <![CDATA[ - - getRootPane().setDefaultButton(okButton); - - import org.apache.commons.lang.time.DateUtils; - - // set begin date picker - Calendar calendarBegin = Calendar.getInstance(); - // set begindate to JAN 1 - 0:00.000 of this years - Date beginDate = calendarBegin.getTime(); - beginDate = DateUtils.truncate(beginDate, Calendar.DATE); - getBeginDatePicker().setDate(beginDate); - - /** - * Sets null to Date and closes JDialog - */ - protected void performCancel() { - getBeginDatePicker().setDate(null); - dispose(); - } - ]]> - </script> - - <Table> - <row> - <cell anchor="center"> - <JLabel text="lima.table.date"/> - </cell> - <cell anchor="west"> - <org.jdesktop.swingx.JXDatePicker id="beginDatePicker"/> - </cell> - </row> - <row> - <cell anchor="center"> - <JButton id="cancelButton" text="lima.common.cancel" onActionPerformed="performCancel()"/> - </cell> - <cell anchor="center"> - <JButton id="okButton" text="lima.common.ok" onActionPerformed="dispose()"/> - </cell> - </row> - </Table> -</JDialog> \ No newline at end of file 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-01 14:03:16 UTC (rev 3195) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties 2011-07-01 14:31:21 UTC (rev 3196) @@ -32,6 +32,7 @@ lima.charts.fiscalperiod.create=Choisissez la date de d\u00E9but et de fin du nouvel exercice lima.charts.fiscalperiod.question.blocked=\u00C8tes vous s\u00FBre de vouloir cl\u00F4turer cette exercice ? Cette action est irr\u00E9versible \! lima.charts.fiscalperiod.question.morethan12=La p\u00E9riode s\u00E9lectionn\u00E9e n'est pas de 12 mois, voulez-vous continuer ? +lima.charts.fiscalperiod.question.newyear=Voulez vous cr\u00E9er un nouvel exercice? lima.charts.fiscalyear=Exercices lima.common.account=Compte lima.common.amount=Montant @@ -82,6 +83,7 @@ lima.config.ui.fullscreen.description=Plein \u00E9cran lima.daily=Quotidien lima.documents=Documents\u2026 +lima.documents.error=Impossible de cr\u00E9er un document lorsque l'exercice est ouvert lima.entries=Traitement lima.entries.addEntry=Ajouter entr\u00E9e lima.entries.addTransaction=Ajouter transaction @@ -213,6 +215,8 @@ lima.tab.home=Accueil lima.table.account=Compte lima.table.balance=Balance +lima.table.begin.credit=Reprise cr\u00E8dit +lima.table.begin.debit=Reprise d\u00E9bit lima.table.closure=Cloture lima.table.code=Code lima.table.collectedvat=TVA collect\u00E9e @@ -250,3 +254,4 @@ lima.tooltip.lettering=<html>Pour ajouter une lettre \u00E0 plusieurs \u00E9critures <br/>S\u00E9lectionner plusieurs lignes avec la combinaison ctrl + click</html> lima.warning.nimbus.landf=Le look and feel nymbus n'a pas \u00E9t\u00E9 trouv\u00E9 limma.config.thousandseparator.description= +nuitonutil.error.applicationconfig.save=