r2872 - in trunk: lima-business/src/main/java/org/chorem/lima/business lima-business/src/main/java/org/chorem/lima/business/ejb lima-swing/src/main/java/org/chorem/lima/ui/entrybook lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/model lima-swing/src/main/resources/i18n
Author: jpepin Date: 2010-04-23 16:40:13 +0200 (Fri, 23 Apr 2010) New Revision: 2872 Log: Ajout : Cl?\195?\180ture exercice avec r?\195?\168gles de v?\195?\169rification Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/FiscalPeriodService.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AbstractLimaService.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/model/FiscalPeriodTableModel.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/FiscalPeriodService.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/FiscalPeriodService.java 2010-04-23 09:58:20 UTC (rev 2871) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/FiscalPeriodService.java 2010-04-23 14:40:13 UTC (rev 2872) @@ -37,6 +37,8 @@ List<FiscalPeriod> getAllFiscalPeriods() throws LimaException; void createFiscalPeriod(FiscalPeriod fiscalPeriod) throws LimaException; + + void blockFiscalPeriod(FiscalPeriod fiscalPeriod) throws LimaException; //void updateFiscalPeriod(FiscalPeriod fiscalPeriod) throws LimaException; Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AbstractLimaService.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AbstractLimaService.java 2010-04-23 09:58:20 UTC (rev 2871) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AbstractLimaService.java 2010-04-23 14:40:13 UTC (rev 2872) @@ -53,7 +53,7 @@ } } if (log.isErrorEnabled()) { - log.error("Error during create account", cause); + log.error("Exception during query", cause); } throw new LimaException("Exception during query", cause); } 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 2010-04-23 09:58:20 UTC (rev 2871) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java 2010-04-23 14:40:13 UTC (rev 2872) @@ -36,6 +36,7 @@ import org.chorem.lima.business.LimaConfig; import org.chorem.lima.business.LimaException; import org.chorem.lima.entity.Account; +import org.chorem.lima.entity.AccountDAO; import org.chorem.lima.entity.FinancialPeriod; import org.chorem.lima.entity.FinancialPeriodDAO; import org.chorem.lima.entity.FinancialPeriodImpl; @@ -46,7 +47,10 @@ import org.nuiton.topia.TopiaContextFactory; import org.nuiton.topia.TopiaException; import org.nuiton.topia.TopiaNotFoundException; +import org.nuiton.topia.framework.TopiaContextImpl; +import org.nuiton.topia.framework.TopiaContextImplementor; import org.nuiton.topia.framework.TopiaQuery; +import org.nuiton.topia.framework.TopiaQuery.Op; import org.apache.commons.lang.time.DateUtils; /** @@ -62,7 +66,8 @@ private static TopiaContext rootContext; - private FinancialPeriodServiceImpl financialPeriodService = new FinancialPeriodServiceImpl(); + private FinancialPeriodServiceImpl financialPeriodService = + new FinancialPeriodServiceImpl(); public FiscalPeriodServiceImpl() { LimaConfig config = LimaConfig.getInstance(); @@ -183,7 +188,8 @@ //check if the enddate period is after the begindate period if (fiscalPeriod.getEndDate().before(fiscalPeriod.getBeginDate())){ //TODO Exception - throw new LimaBusinessException("The enddate is before the begindate"); + throw new LimaBusinessException( + "The enddate is before the begindate"); } //Checks if is not the first fiscalperiod to create @@ -199,19 +205,23 @@ //check the new fiscal period adjoining the last Date dateLastFiscalPeriod=lastFiscalPeriod.getEndDate(); - dateLastFiscalPeriod = DateUtils.addMilliseconds(dateLastFiscalPeriod, 1); + dateLastFiscalPeriod = DateUtils. + addMilliseconds(dateLastFiscalPeriod, 1); Date dateFiscalPeriod=fiscalPeriod.getBeginDate(); if(dateLastFiscalPeriod.compareTo(dateFiscalPeriod)!=0){ - throw new LimaBusinessException("The new fiscalperiod must adjoining the last"); + throw new LimaBusinessException( + "The new fiscalperiod must adjoining the last"); } //We can create a new fiscal period meantime the last fiscal period was not locked //But not the ante periodfiscal - int unblockedFiscalPeriod = fiscalPeriodDAO.findAllByLocked(false).size(); + int unblockedFiscalPeriod = + fiscalPeriodDAO.findAllByLocked(false).size(); log.debug(unblockedFiscalPeriod); if (unblockedFiscalPeriod>1){ - throw new LimaBusinessException("The ante fiscal period is not locked"); + throw new LimaBusinessException( + "The ante fiscal period is not locked"); } } @@ -272,8 +282,51 @@ return result; } + + @Override + public void blockFiscalPeriod(FiscalPeriod fiscalPeriod) throws LimaException { + TopiaContext transaction = null; + try { + transaction = rootContext.beginTransaction(); + + if (fiscalPeriod.getLocked()==true){ + throw new LimaBusinessException("Fiscal Period already blocked"); + } + //set to true + fiscalPeriod.setLocked(true); + + //TODO verifier que les exercices anterieur a l'exerice à bloquer sont bloqués + FiscalPeriodDAO fiscalPeriodDAO = LimaCallaoDAOHelper.getFiscalPeriodDAO(transaction); + + TopiaQuery query = fiscalPeriodDAO.createQuery(); + fiscalPeriodDAO.findAllByQuery(query); + query.add(FiscalPeriod.LOCKED, Op.EQ, false); + query.addOrder(FiscalPeriod.END_DATE); + FiscalPeriod oldestUnBlockedFiscalPeriod = fiscalPeriodDAO.findByQuery(query); + log.debug("oldestUnBlockedFiscalPeriod : "+oldestUnBlockedFiscalPeriod); + + //Check if the fiscal period to block is the oldest + if (!oldestUnBlockedFiscalPeriod.equals(fiscalPeriod)){ + throw new LimaBusinessException("The ante fiscal period must be blocked before this."); + } + + //FIXME PJ 23/04/2010 code à changer pour ne pas dépendre de l'impl + TopiaContextImpl topiaContextImpl = (TopiaContextImpl) transaction; + topiaContextImpl.getHibernate().evict(oldestUnBlockedFiscalPeriod); + // update account + fiscalPeriodDAO.update(fiscalPeriod); + + // commit + transaction.commitTransaction(); + + } catch (TopiaException ex) { + doCatch(transaction, ex, log); + } + finally { + doFinally(transaction, log); + } + } - public void removeAllFiscalPeriods() throws LimaException{ TopiaContext transaction = null; try { Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookViewHandler.java 2010-04-23 09:58:20 UTC (rev 2871) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookViewHandler.java 2010-04-23 14:40:13 UTC (rev 2872) @@ -53,7 +53,8 @@ public void addEntryBook() { JXTable entryBookTable = view.getEntryBooksTable(); - EntryBookTableModel entryBookTableModel = (EntryBookTableModel)entryBookTable.getModel(); + EntryBookTableModel entryBookTableModel = + (EntryBookTableModel)entryBookTable.getModel(); EntryBook newEntryBook = new EntryBookImpl(); EntryBookForm entryBookForm = new EntryBookForm(view); @@ -82,11 +83,13 @@ JXTable entryBookTable = view.getEntryBooksTable(); int selectedRow = entryBookTable.getSelectedRow(); - EntryBookTableModel entryBookTableModel = (EntryBookTableModel)entryBookTable.getModel(); + EntryBookTableModel entryBookTableModel = + (EntryBookTableModel)entryBookTable.getModel(); // add it try { - EntryBook selectedEntryBook = entryBookTableModel.getEntryBookAtRow(selectedRow); + EntryBook selectedEntryBook = + entryBookTableModel.getEntryBookAtRow(selectedRow); EntryBookForm entryBookForm = new EntryBookForm(view); entryBookForm.setEntryBook(selectedEntryBook); // jaxx constructor don't call super() ? @@ -109,14 +112,20 @@ public void deleteEntryBook() { JXTable entryBookTable = view.getEntryBooksTable(); int selectedRow = entryBookTable.getSelectedRow(); - EntryBookTableModel entryBookTableModel = (EntryBookTableModel)entryBookTable.getModel(); + EntryBookTableModel entryBookTableModel = + (EntryBookTableModel)entryBookTable.getModel(); // add it try { - EntryBook selectedEntryBook = entryBookTableModel.getEntryBookAtRow(selectedRow); + EntryBook selectedEntryBook = + entryBookTableModel.getEntryBookAtRow(selectedRow); - int response = JOptionPane.showConfirmDialog(view, _("Do you really want to delete entry book %s ?", selectedEntryBook.getLabel()), - _("Confirmation"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); + int response = + JOptionPane.showConfirmDialog(view, + _("Do you really want to delete entry book %s ?", + selectedEntryBook.getLabel()), + _("Confirmation"), JOptionPane.YES_NO_OPTION, + JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.YES_OPTION) { entryBookTableModel.removeEntryBook(selectedEntryBook); 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 2010-04-23 09:58:20 UTC (rev 2871) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodViewHandler.java 2010-04-23 14:40:13 UTC (rev 2872) @@ -26,14 +26,17 @@ import javax.swing.JOptionPane; import org.apache.commons.lang.NotImplementedException; +import org.jdesktop.swingx.JXTable; import org.nuiton.util.DateUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.business.LimaBusinessException; import org.chorem.lima.business.LimaException; +import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.FinancialPeriod; import org.chorem.lima.entity.FinancialPeriodImpl; import org.chorem.lima.entity.FiscalPeriod; +import org.chorem.lima.ui.entrybook.model.EntryBookTableModel; import org.chorem.lima.ui.fiscalperiod.model.FiscalPeriodTableModel; import org.chorem.lima.ui.fiscalperiod.AddPeriod; import org.chorem.lima.ui.fiscalperiod.FiscalPeriodView; @@ -95,8 +98,27 @@ } public void blockFiscalPeriod() { - throw new NotImplementedException("To be continued..."); - } + JXTable fiscalPeriodeTable = view.getFiscalPeriodTable(); + int selectedRow = fiscalPeriodeTable.getSelectedRow(); + FiscalPeriodTableModel model = (FiscalPeriodTableModel)view.getFiscalPeriodTable().getModel(); + + // blocked it + try { + FiscalPeriod selectedFiscalPeriod = model.getFiscalPeriodAtRow(selectedRow); + int response = JOptionPane.showConfirmDialog(view, _("lima.question.fiscalperiod.blocked"), + _("lima.question"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); + + if (response == JOptionPane.YES_OPTION) { + model.blockFiscalPeriod(selectedFiscalPeriod); + } + } catch (LimaException ex) { + if (log.isErrorEnabled()) { + log.error("Can't block fiscalperiod", ex); + } + ErrorHelper.showErrorDialog("Can't block fiscalperiod", ex); + } + } + public void removeAllFiscalPeriods(){ FiscalPeriodTableModel model = (FiscalPeriodTableModel)view.getFiscalPeriodTable().getModel(); Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/model/FiscalPeriodTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/model/FiscalPeriodTableModel.java 2010-04-23 09:58:20 UTC (rev 2871) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/model/FiscalPeriodTableModel.java 2010-04-23 14:40:13 UTC (rev 2872) @@ -28,6 +28,7 @@ import org.apache.commons.logging.LogFactory; import org.chorem.lima.business.FiscalPeriodService; import org.chorem.lima.business.LimaException; +import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.FiscalPeriod; import org.chorem.lima.service.LimaServiceFactory; @@ -131,7 +132,8 @@ switch (columnIndex) { case 0: - result = fiscalPeriod.getBeginDate() + " - " + fiscalPeriod.getEndDate(); + result = fiscalPeriod.getBeginDate() + + " - " + fiscalPeriod.getEndDate(); break; case 1: result = fiscalPeriod.getLocked(); @@ -154,6 +156,14 @@ } + + public FiscalPeriod getFiscalPeriodAtRow(int row) throws LimaException { + FiscalPeriod fiscalPeriod = null; + fiscalPeriod = fiscalPeriodService.getAllFiscalPeriods().get(row); + return fiscalPeriod; + } + + /** * @param period */ @@ -170,4 +180,9 @@ fiscalPeriodService.removeAllFiscalPeriods(); fireTableDataChanged(); } + + public void blockFiscalPeriod(FiscalPeriod fiscalPeriod) throws LimaException { + fiscalPeriodService.blockFiscalPeriod(fiscalPeriod); + fireTableDataChanged(); + } } 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 2010-04-23 09:58:20 UTC (rev 2871) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing-en_GB.properties 2010-04-23 14:40:13 UTC (rev 2872) @@ -1,6 +1,8 @@ Bloqu\u00E9e= Can't\ add\ fiscal\ period= +Can't\ delete\ all\ fiscal\ period= Confirmation= +DEBUG\ delete\ all= Do\ you\ really\ want\ to\ delete\ entry\ book\ %s\ ?= Exercice= Global\ lima\ exception= @@ -258,6 +260,7 @@ lima.progressBar.load.etape5=Loading transactions lima.question=Question lima.question.confirmremove.account=This account have subaccounts, do you want remove this account ? +lima.question.fiscalperiod.morethan12= lima.question.load.accounts=There is no existing accounts in Lima. Do you want to load default accounts ? lima.question.remove.account=Do you want to remove this account ? lima.question.remove.entry=Do you want to remove this entry ? 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 2010-04-23 09:58:20 UTC (rev 2871) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing-fr_FR.properties 2010-04-23 14:40:13 UTC (rev 2872) @@ -246,6 +246,7 @@ lima.question=Question lima.question.confirmremove.account=Ce compte poss\u00E8de des sous comptes, voulez-vous supprimer ce compte ? lima.question.fiscalperiod.morethan12=La p\u00E9riode s\u00E9lectionner n'est pas de 12 mois, voulez-vous continuer ? +lima.question.fiscalperiod.blocked=\u00C8tes vous s\u00FBre de vouloir cl\u00F4turer cette exercice ? Cette action est irr\u00E9versible ! lima.question.load.accounts=Il n'y a aucun plan comptable existant dans Lima. Voulez-vous en charger un par d\u00E9faut ? lima.question.remove.account=Voulez-vous supprimer ce compte? lima.question.remove.entry=Voulez-vous supprimer cette ligne de transaction?
participants (1)
-
jpepin@users.chorem.org