Author: sbavencoff Date: 2014-02-28 11:04:45 +0100 (Fri, 28 Feb 2014) New Revision: 3749 Url: http://chorem.org/projects/lima/repository/revisions/3749 Log: fixes #667 : P?\195?\169riode d'exercice trop contraignante Added: trunk/lima-swing/src/main/resources/icons/action-fiscalPeriod-edit.png 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/ejb/FiscalPeriodServiceImpl.java trunk/lima-callao/src/main/xmi/accounting.properties trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/AddPeriod.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodView.jaxx 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 2014-02-19 09:14:15 UTC (rev 3748) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java 2014-02-28 10:04:45 UTC (rev 3749) @@ -25,22 +25,6 @@ package org.chorem.lima.business.ejb; -import static org.nuiton.i18n.I18n._; - -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.Iterator; -import java.util.List; - -import javax.ejb.EJB; -import javax.ejb.Remote; -import javax.ejb.Stateless; -import javax.ejb.TransactionAttribute; - import org.apache.commons.lang3.time.DateUtils; import org.chorem.lima.beans.BalanceTrial; import org.chorem.lima.beans.ReportsDatas; @@ -69,6 +53,21 @@ import org.chorem.lima.entity.FiscalPeriodDAO; import org.nuiton.topia.TopiaException; +import javax.ejb.EJB; +import javax.ejb.Remote; +import javax.ejb.Stateless; +import javax.ejb.TransactionAttribute; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.Iterator; +import java.util.List; + +import static org.nuiton.i18n.I18n._; + /** * Gestion des exercices. * Un exercice ne peut être supprimé et débloqué après cloture. @@ -277,6 +276,29 @@ } @Override + public FiscalPeriod updateEndDate(FiscalPeriod fiscalPeriod) throws LimaException { + + FiscalPeriod result; + + try { + FiscalPeriodDAO fiscalPeriodDAO = getDaoHelper().getFiscalPeriodDAO(); + + String topiaId = fiscalPeriod.getTopiaId(); + FiscalPeriod fiscalPeriodOld = fiscalPeriodDAO.findByTopiaId(topiaId); + + Date endDate = fiscalPeriod.getEndDate(); + fiscalPeriodOld.setEndDate(endDate); + + result = fiscalPeriodDAO.update(fiscalPeriodOld); + + } catch (TopiaException e) { + throw new LimaException("Can't update period", e); + } + + return result; + } + + @Override public FiscalPeriod retainedEarningsAndBlockFiscalPeriod(FiscalPeriod fiscalPeriod, EntryBook entryBook, boolean retainedEarnings) throws LimaException { 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 2014-02-19 09:14:15 UTC (rev 3748) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FiscalPeriodService.java 2014-02-28 10:04:45 UTC (rev 3749) @@ -25,12 +25,12 @@ package org.chorem.lima.business.api; -import java.util.List; - import org.chorem.lima.business.LimaException; import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.FiscalPeriod; +import java.util.List; + /** * Fiscal period service. * @@ -73,4 +73,6 @@ * @return true if retained earnings are possible * */ boolean isRetainedEarnings(FiscalPeriod fiscalPeriod) throws LimaException; + + FiscalPeriod updateEndDate(FiscalPeriod fiscalPeriod) throws LimaException; } Modified: trunk/lima-callao/src/main/xmi/accounting.properties =================================================================== --- trunk/lima-callao/src/main/xmi/accounting.properties 2014-02-19 09:14:15 UTC (rev 3748) +++ trunk/lima-callao/src/main/xmi/accounting.properties 2014-02-28 10:04:45 UTC (rev 3749) @@ -40,7 +40,7 @@ org.chorem.lima.entity.FinancialPeriod.attribute.endDate.tagvalue.naturalId=true org.chorem.lima.entity.FinancialPeriod.attribute.endDate.tagvalue.notNull=true -org.chorem.lima.entity.FiscalPeriod.class.tagvalue.naturalIdMutable=false +org.chorem.lima.entity.FiscalPeriod.class.tagvalue.naturalIdMutable=true org.chorem.lima.entity.FiscalPeriod.attribute.beginDate.tagvalue.naturalId=true org.chorem.lima.entity.FiscalPeriod.attribute.beginDate.tagvalue.notNull=true org.chorem.lima.entity.FiscalPeriod.attribute.endDate.tagvalue.naturalId=true Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/AddPeriod.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/AddPeriod.jaxx 2014-02-19 09:14:15 UTC (rev 3748) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/AddPeriod.jaxx 2014-02-28 10:04:45 UTC (rev 3749) @@ -22,31 +22,25 @@ <http://www.gnu.org/licenses/gpl-3.0.html>. #L% --> -<JDialog title="lima.ui.fiscalperiod.addfiscalperiodtitle" modal="true" +<JDialog modal="true" defaultCloseOperation="{JDialog.DO_NOTHING_ON_CLOSE}" onWindowClosing="performCancel();"> - <import> - org.chorem.lima.entity.FiscalPeriod - </import> - <FiscalPeriodViewHandler id='handler' initializer='getContextValue(FiscalPeriodView.class,JAXXUtil.PARENT).getHandler()'/> + <Boolean id="modifyPeriod" javaBean="false"/> - <FiscalPeriod id="period" javaBean="new org.chorem.lima.entity.FiscalPeriodImpl()"/> + <Boolean id="validate" javaBean="false"/> <script> <![CDATA[ - public void $afterCompleteSetup() { - getHandler().init(this); - } + getRootPane().setDefaultButton(okButton); protected void performOk() { - getPeriod().setBeginDate(beginDatePicker.getDate()); - getPeriod().setEndDate(endDatePicker.getDate()); + setValidate(true); dispose(); } protected void performCancel() { - setPeriod(null); + setValidate(false); dispose(); } ]]></script> @@ -57,7 +51,8 @@ <JLabel text="lima.common.begindate"/> </cell> <cell> - <org.jdesktop.swingx.JXDatePicker id="beginDatePicker"/> + <org.jdesktop.swingx.JXDatePicker id="beginDatePicker" + enabled="{!isModifyPeriod()}"/> </cell> </row> <row> @@ -65,7 +60,7 @@ <JLabel text="lima.common.enddate"/> </cell> <cell> - <org.jdesktop.swingx.JXDatePicker id="endDatePicker"/> + <org.jdesktop.swingx.JXDatePicker id="endDatePicker" /> </cell> </row> <row> Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodView.jaxx 2014-02-19 09:14:15 UTC (rev 3748) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodView.jaxx 2014-02-28 10:04:45 UTC (rev 3749) @@ -51,6 +51,12 @@ actionIcon='fiscalPeriod-new' onActionPerformed="handler.addFiscalPeriod()"/> + <JButton id="updateButton" + toolTipText="{ _("lima.charts.fiscalperiod.update") + " (Ctrl+M)"}" + actionIcon='fiscalPeriod-edit' + onActionPerformed="handler.updateFiscalPeriod()" + enabled="{isDeleteEnabled()}" /> + <JButton id="blockButton" toolTipText="{ _("lima.charts.fiscalperiod.block") + " (Ctrl+B)"}" actionIcon='fiscalPeriod-close' 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 2014-02-19 09:14:15 UTC (rev 3748) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodViewHandler.java 2014-02-28 10:04:45 UTC (rev 3749) @@ -36,6 +36,7 @@ import org.chorem.lima.entity.EntryBookImpl; import org.chorem.lima.entity.FinancialTransaction; import org.chorem.lima.entity.FiscalPeriod; +import org.chorem.lima.entity.FiscalPeriodImpl; import org.chorem.lima.service.LimaServiceFactory; import org.nuiton.util.DateUtil; @@ -98,6 +99,16 @@ } }); + // add action on Ctrl + M + binding = "update-FiscalPeriod"; + inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_M, KeyEvent.CTRL_DOWN_MASK), binding); + actionMap.put(binding, new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + updateFiscalPeriod(); + } + }); + // add action on Delete binding = "remove-FiscalPeriod"; inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), binding); @@ -137,30 +148,112 @@ */ public void addFiscalPeriod() { - FiscalPeriodTable table = view.getFiscalPeriodTable(); FiscalPeriodTableModel tableModel = view.getFiscalPeriodTableModel(); + // set begin date picker + Date beginDate = null; + Date endDate; + try { + FiscalPeriod result = fiscalPeriodService.getLastFiscalPeriod(); + if (result != null){ + beginDate = DateUtils.addDays(result.getEndDate(), 1); + } + } + catch (LimaException eee){ + if(log.isDebugEnabled()){ + log.debug("Can't get last fiscal period", eee); + } + + } + if (beginDate == null) { + Calendar calendarBegin = Calendar.getInstance(); + // set begindate to JAN 1 - 0:00.000 of this years + beginDate = calendarBegin.getTime(); + beginDate = DateUtils.truncate(beginDate, Calendar.YEAR); + } + + // get end date + endDate = DateUtils.addYears(beginDate, 1); + endDate = DateUtils.addDays(endDate, -1); + + AddPeriod addPeriodDialog = new AddPeriod(view); + addPeriodDialog.setTitle(_("lima.ui.fiscalperiod.addfiscalperiodtitle")); + addPeriodDialog.getBeginDatePicker().setDate(beginDate); + addPeriodDialog.getEndDatePicker().setDate(endDate); addPeriodDialog.setLocationRelativeTo(view); addPeriodDialog.setVisible(true); - FiscalPeriod fiscalPeriod = addPeriodDialog.getPeriod(); - if (fiscalPeriod != null) { - + if (checkFiscalPeriod(addPeriodDialog)) { + FiscalPeriod fiscalPeriod = new FiscalPeriodImpl(); + fiscalPeriod.setBeginDate(addPeriodDialog.getBeginDatePicker().getDate()); + fiscalPeriod.setEndDate(addPeriodDialog.getEndDatePicker().getDate()); + fiscalPeriod = fiscalPeriodService.createFiscalPeriod(fiscalPeriod); + tableModel.addValue(fiscalPeriod); + } + } + + protected boolean checkFiscalPeriod(AddPeriod addPeriodDialog) { + Date beginDate = addPeriodDialog.getBeginDatePicker().getDate(); + Date endDate = addPeriodDialog.getEndDatePicker().getDate(); + + String title = addPeriodDialog.getTitle(); + + if (!addPeriodDialog.isValidate()) { + return false; + } else if (endDate.before(beginDate)) { + JOptionPane.showMessageDialog(view, + _("lima.ui.fiscalperiod.addfiscalperiod.endAfterBegin"), + title, + JOptionPane.ERROR_MESSAGE); + return false; + } else { //check if fiscalperiod have 12 months, ask a confirmation - int nbMonth = DateUtil.getDifferenceInMonths(fiscalPeriod.getBeginDate(), - fiscalPeriod.getEndDate()); + int nbMonth = DateUtil.getDifferenceInMonths(beginDate, endDate); int response = JOptionPane.YES_OPTION; if (nbMonth != 12) { response = JOptionPane.showConfirmDialog(view, - _("lima.ui.fiscalperiod.addfiscalperiod.morethan12"), - _("lima.ui.fiscalperiod.addfiscalperiodtitle"), - JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); + _("lima.ui.fiscalperiod.addfiscalperiod.morethan12"), + title, + JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); } + return (response == JOptionPane.YES_OPTION); - if (response == JOptionPane.YES_OPTION) { - fiscalPeriod = fiscalPeriodService.createFiscalPeriod(fiscalPeriod); - tableModel.addValue(fiscalPeriod); + + } + + + } + + /** + * Display add period form and perform add. + */ + public void updateFiscalPeriod() { + + FiscalPeriodTable table = view.getFiscalPeriodTable(); + FiscalPeriodTableModel tableModel = view.getFiscalPeriodTableModel(); + + int selectedRow = table.getSelectedRow(); + + if (selectedRow >=0 ) { + + FiscalPeriod selectedFiscalPeriod = tableModel.get(selectedRow); + + if (!selectedFiscalPeriod.isLocked()) { + + AddPeriod addPeriodDialog = new AddPeriod(view); + addPeriodDialog.setTitle(_("lima.ui.fiscalperiod.modifyfiscalperiodtitle")); + addPeriodDialog.getBeginDatePicker().setDate(selectedFiscalPeriod.getBeginDate()); + addPeriodDialog.getEndDatePicker().setDate(selectedFiscalPeriod.getEndDate()); + addPeriodDialog.setModifyPeriod(true); + addPeriodDialog.setLocationRelativeTo(view); + addPeriodDialog.setVisible(true); + + if (checkFiscalPeriod(addPeriodDialog)) { + selectedFiscalPeriod.setEndDate(addPeriodDialog.getEndDatePicker().getDate()); + fiscalPeriodService.updateEndDate(selectedFiscalPeriod); + tableModel.fireTableRowsUpdated(selectedRow, selectedRow); + } } } } @@ -200,40 +293,6 @@ } /** - * Init add period view. - * - * @param addPeriod view to init - */ - public void init(AddPeriod addPeriod) { - addPeriod.getRootPane().setDefaultButton(addPeriod.getOkButton()); - - // set begin date picker - Date endDate = null; - 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); - try { - FiscalPeriod result = fiscalPeriodService.getLastFiscalPeriod(); - if (result != null){ - beginDate = result.getEndDate(); - } - } - catch (LimaException eee){ - if(log.isDebugEnabled()){ - log.debug("Can't get last fiscal period", eee); - } - } - beginDate = DateUtils.addDays(beginDate, 1); - addPeriod.getBeginDatePicker().setDate(beginDate); - - // get end date - endDate = DateUtils.addYears(beginDate, 1); - endDate = DateUtils.addDays(endDate, -1); - addPeriod.getEndDatePicker().setDate(endDate); - } - - /** * Block selected fiscal period, * and make new fiscal period and retained earnings * after user confirmations 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-02-19 09:14:15 UTC (rev 3748) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties 2014-02-28 10:04:45 UTC (rev 3749) @@ -40,6 +40,7 @@ lima.charts.fiscalperiod.block=Block fiscalperiod lima.charts.fiscalperiod.create=Create fiscalperiod lima.charts.fiscalperiod.delete=Delete fiscalperiod +lima.charts.fiscalperiod.update= lima.charts.fiscalyear=Fiscal Years lima.charts.vatpdf=PDF structure lima.charts.vatstatement=VAT statement chart @@ -346,6 +347,8 @@ lima.ui.financialtransaction.voucher= lima.ui.fiscalPeriod.buttonback= lima.ui.fiscalPeriod.buttonnext= +lima.ui.fiscalperiod.addfiscalperiod.addfiscalperiodtitle= +lima.ui.fiscalperiod.addfiscalperiod.endAfterBegin= lima.ui.fiscalperiod.addfiscalperiod.morethan12= lima.ui.fiscalperiod.addfiscalperiodtitle= lima.ui.fiscalperiod.begin= @@ -366,6 +369,7 @@ lima.ui.fiscalperiod.fiscalperiod.begin= lima.ui.fiscalperiod.fiscalperiod.end= lima.ui.fiscalperiod.fiscalperiod.status= +lima.ui.fiscalperiod.modifyfiscalperiodtitle= lima.ui.fiscalperiod.open= lima.ui.fiscalperiod.status= lima.ui.fullscreen= 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-02-19 09:14:15 UTC (rev 3748) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties 2014-02-28 10:04:45 UTC (rev 3749) @@ -30,6 +30,7 @@ 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.delete=Supprimer un exercice +lima.charts.fiscalperiod.update=Modifier la date de fin de l'exercice lima.charts.fiscalyear=Exercices lima.charts.vatpdf=Import du pdf lima.charts.vatstatement=Plan TVA @@ -329,6 +330,7 @@ lima.ui.financialtransaction.voucher=Pièce comptable lima.ui.fiscalPeriod.buttonback= lima.ui.fiscalPeriod.buttonnext= +lima.ui.fiscalperiod.addfiscalperiod.endAfterBegin=Le date de fin de l'exercice doit être postérieur à la date de début lima.ui.fiscalperiod.addfiscalperiod.morethan12=La période sélectionnée n'est pas de 12 mois, voulez-vous continuer ? lima.ui.fiscalperiod.addfiscalperiodtitle=Nouvel exercice lima.ui.fiscalperiod.begin=Début @@ -346,6 +348,7 @@ lima.ui.fiscalperiod.end=Fin lima.ui.fiscalperiod.entrybooks.create=Création d'un nouveau journal lima.ui.fiscalperiod.fiscalperiod=Exercice +lima.ui.fiscalperiod.modifyfiscalperiodtitle=Modification de l'exercice lima.ui.fiscalperiod.open=Ouvert lima.ui.fiscalperiod.status=Statut lima.ui.home.account=Plan comptable Copied: trunk/lima-swing/src/main/resources/icons/action-fiscalPeriod-edit.png (from rev 3744, trunk/lima-swing/src/main/resources/icons/action-entryBook-edit.png) =================================================================== (Binary files differ)