Author: jpepin Date: 2010-04-23 11:58:20 +0200 (Fri, 23 Apr 2010) New Revision: 2871 Log: Modification du model : composition entre identity et account Ajout : cr?\195?\169ation d'un 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/AccountServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java trunk/lima-callao/pom.xml trunk/lima-callao/src/main/xmi/accounting.zargo 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/java/org/chorem/lima/ui/fiscalperiod/model/FiscalPeriodTableModel.java 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-21 16:09:27 UTC (rev 2870) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/FiscalPeriodService.java 2010-04-23 09:58:20 UTC (rev 2871) @@ -40,5 +40,5 @@ //void updateFiscalPeriod(FiscalPeriod fiscalPeriod) throws LimaException; - //void removeFiscalPeriod(FiscalPeriod fiscalPeriod) throws LimaException; + void removeAllFiscalPeriods() throws LimaException; } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java 2010-04-21 16:09:27 UTC (rev 2870) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java 2010-04-23 09:58:20 UTC (rev 2871) @@ -681,19 +681,10 @@ throw new LimaBusinessException("Account not empty"); } else { - Identity existIdentity = account.getIdentity(); // remove account AccountDAO accountDAO = LimaCallaoDAOHelper.getAccountDAO(transaction); accountDAO.delete(account); - //check if account is a subledger with identity - if (existIdentity != null) { - System.out.println(existIdentity.getAddress()); - // delete identity - IdentityDAO identityDAO = - LimaCallaoDAOHelper.getIdentityDAO(transaction); - identityDAO.delete(existIdentity); - } // commit transaction.commitTransaction(); } @@ -791,7 +782,7 @@ TopiaContext transaction = null; try { - transaction = rootContext.beginTransaction(); + transaction = rootContext.beginTransaction(); //Check if the account is a subledger Identity existIdentity = account.getIdentity(); if (existIdentity != null) { 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-21 16:09:27 UTC (rev 2870) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java 2010-04-23 09:58:20 UTC (rev 2871) @@ -21,6 +21,9 @@ import static org.nuiton.i18n.I18n._; +import java.util.Calendar; +import java.util.Date; +import java.util.Iterator; import java.util.List; import java.util.ListIterator; @@ -34,6 +37,8 @@ import org.chorem.lima.business.LimaException; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.FinancialPeriod; +import org.chorem.lima.entity.FinancialPeriodDAO; +import org.chorem.lima.entity.FinancialPeriodImpl; import org.chorem.lima.entity.FiscalPeriod; import org.chorem.lima.entity.FiscalPeriodDAO; import org.chorem.lima.entity.LimaCallaoDAOHelper; @@ -41,6 +46,8 @@ import org.nuiton.topia.TopiaContextFactory; import org.nuiton.topia.TopiaException; import org.nuiton.topia.TopiaNotFoundException; +import org.nuiton.topia.framework.TopiaQuery; +import org.apache.commons.lang.time.DateUtils; /** * Gestion des exercices. @@ -53,7 +60,7 @@ private static final Log log = LogFactory.getLog(FiscalPeriodServiceImpl.class); - private TopiaContext rootContext; + private static TopiaContext rootContext; private FinancialPeriodServiceImpl financialPeriodService = new FinancialPeriodServiceImpl(); @@ -161,62 +168,70 @@ // un exercice doit être collé au precedent - // un exercice ne peut être crée que si l'anti precedent est fermé + // un exercice ne peut être crée que si l'ante precedent est fermé // on peut creer un exercice si le precedent n'est pas fermé - + boolean valid=false; TopiaContext transaction = null; try { + // basic check done, make check in database // TODO move it into JTA transaction = rootContext.beginTransaction(); FiscalPeriodDAO fiscalPeriodDAO = LimaCallaoDAOHelper.getFiscalPeriodDAO(transaction); - + //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"); } - //check if all fiscal period is locked - if (fiscalPeriodDAO.findAll().size() == - fiscalPeriodDAO.findAllByLocked(true).size()){ - //TODO Exception - throw new LimaBusinessException("Last fiscal period is not locked"); - } - - //check if the last enddate period is before the new begindate period - FiscalPeriod lastFiscalPeriod = null; - List<FiscalPeriod> listFiscalPeriods = getAllFiscalPeriods(); - ListIterator<FiscalPeriod> itr = listFiscalPeriods.listIterator(); - while(itr.hasNext()){ - FiscalPeriod thisFiscalPeriod = itr.next(); - if (thisFiscalPeriod.getEndDate(). - after(lastFiscalPeriod.getEndDate())){ - lastFiscalPeriod=thisFiscalPeriod; + //Checks if is not the first fiscalperiod to create + if (fiscalPeriodDAO.findAll().size()!=0){ + + TopiaQuery query = fiscalPeriodDAO.createQuery(); + fiscalPeriodDAO.findAllByQuery(query); + query.addOrderDesc(FiscalPeriod.END_DATE); + + //get the last fiscal period + FiscalPeriod lastFiscalPeriod = fiscalPeriodDAO.findByQuery(query); + log.debug("lastFiscalPeriod : "+lastFiscalPeriod); + + //check the new fiscal period adjoining the last + Date dateLastFiscalPeriod=lastFiscalPeriod.getEndDate(); + dateLastFiscalPeriod = DateUtils.addMilliseconds(dateLastFiscalPeriod, 1); + Date dateFiscalPeriod=fiscalPeriod.getBeginDate(); + if(dateLastFiscalPeriod.compareTo(dateFiscalPeriod)!=0){ + 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(); + log.debug(unblockedFiscalPeriod); + if (unblockedFiscalPeriod>1){ + throw new LimaBusinessException("The ante fiscal period is not locked"); + } } - if (lastFiscalPeriod.getEndDate().before(fiscalPeriod.getBeginDate())){ - //TODO Exception - throw new LimaBusinessException - ("The begindate is before the enddate of the last fiscalperiod"); - } + + Date beginDate = fiscalPeriod.getBeginDate(); + Date endDate = fiscalPeriod.getEndDate(); - - //count the month number - int monthNumber = fiscalPeriod.getEndDate().getMonth() - -fiscalPeriod.getBeginDate().getMonth(); - - //check if fiscalperiod have 12 months, ask a confirmation - if(monthNumber!=12){ - //TODO Exception - throw new LimaBusinessException("The fiscal period has not 12 months"); + // FinancialPeriod of 1 month are created + Date loopDate = beginDate; + while (loopDate.compareTo(endDate) <= 0) { + Date loopUpperDate = DateUtils.addMonths(loopDate, 1); + Date periodEndDate = DateUtils.addMilliseconds(loopUpperDate, -1); + FinancialPeriod financialPeriod = new FinancialPeriodImpl(); + financialPeriod.setBeginDate(loopDate); + financialPeriod.setEndDate(periodEndDate); + fiscalPeriod.addFinancialPeriod(financialPeriod); + loopDate = loopUpperDate; + log.debug("financialPeriod : "+financialPeriod); + financialPeriodService.createFinancialPeriod(financialPeriod); } - - //TODO create the financialperiods, much as period as months - for (int i = 0; i < monthNumber; i++) { - } - + //create fiscalPeriodDAO.create(fiscalPeriod); // commit @@ -258,6 +273,29 @@ return result; } + + public void removeAllFiscalPeriods() throws LimaException{ + TopiaContext transaction = null; + try { + transaction = rootContext.beginTransaction(); + + FiscalPeriodDAO fiscalPeriodDAO = + LimaCallaoDAOHelper.getFiscalPeriodDAO(transaction); + for (FiscalPeriod fiscalPeriod : fiscalPeriodDAO.findAll()) { + fiscalPeriodDAO.delete(fiscalPeriod); + } + + // commit + transaction.commitTransaction(); + + } catch (TopiaException ex) { + doCatch(transaction, ex, log); + } + finally { + doFinally(transaction, log); + } + } + /* * Permet de créer une période à partir d'une période DTO. * @param periodDTO période à créer au format DTO. Modified: trunk/lima-callao/pom.xml =================================================================== --- trunk/lima-callao/pom.xml 2010-04-21 16:09:27 UTC (rev 2870) +++ trunk/lima-callao/pom.xml 2010-04-23 09:58:20 UTC (rev 2871) @@ -15,6 +15,10 @@ <artifactId>lima-callao</artifactId> <dependencies> + <dependency> + <groupId>org.nuiton</groupId> + <artifactId>nuiton-utils</artifactId> + </dependency> <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> Modified: trunk/lima-callao/src/main/xmi/accounting.zargo =================================================================== (Binary files differ) 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 2010-04-21 16:09:27 UTC (rev 2870) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/AddPeriod.jaxx 2010-04-23 09:58:20 UTC (rev 2871) @@ -22,6 +22,7 @@ import org.chorem.lima.entity.FiscalPeriodImpl; import org.chorem.lima.ui.fiscalperiod.model.FiscalPeriodMonthComboBoxModel; import org.chorem.lima.ui.fiscalperiod.model.FiscalPeriodSplinnerModel; + import org.apache.commons.lang.time.DateUtils; import java.util.Calendar; protected void performOk() { @@ -34,15 +35,26 @@ Calendar calendarBegin = Calendar.getInstance(); calendarBegin.set(Calendar.MONTH, ((MonthEnum)periodBeginMonth.getSelectedItem()).ordinal()); calendarBegin.set(Calendar.YEAR, (Integer)periodBeginYear.getValue()); - + // set begindate to 0:00.000 + Date beginDate = calendarBegin.getTime(); + beginDate = DateUtils.truncate(beginDate, Calendar.MONTH); + // get end date Calendar calendarEnd = Calendar.getInstance(); calendarEnd.set(Calendar.MONTH, ((MonthEnum)periodEndMonth.getSelectedItem()).ordinal()); calendarEnd.set(Calendar.YEAR, (Integer)periodEndYear.getValue()); + //set end date to last day of month + calendarEnd.set(Calendar.DAY_OF_MONTH, calendarEnd.getActualMaximum(Calendar.DAY_OF_MONTH)); + //set time to max 23:59.999 + Date endDate = calendarEnd.getTime(); + endDate = DateUtils.addDays(endDate, 1); + endDate = DateUtils.truncate(endDate, Calendar.MONTH); + endDate = DateUtils.addMilliseconds(endDate,-1); + + + getPeriod().setBeginDate(beginDate); + getPeriod().setEndDate(endDate); - getPeriod().setBeginDate(calendarBegin.getTime()); - getPeriod().setEndDate(calendarEnd.getTime()); - dispose(); } 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 2010-04-21 16:09:27 UTC (rev 2870) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodView.jaxx 2010-04-23 09:58:20 UTC (rev 2871) @@ -61,6 +61,12 @@ onActionPerformed="getHandler().blockFiscalPeriod()" /> </cell> </row> + <row> + <cell> + <JButton id="deleteButton" text="DEBUG delete all" + onActionPerformed="getHandler().removeAllFiscalPeriods()" /> + </cell> + </row> </Table> </cell> </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 2010-04-21 16:09:27 UTC (rev 2870) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodViewHandler.java 2010-04-23 09:58:20 UTC (rev 2871) @@ -23,10 +23,13 @@ import java.util.Calendar; import java.util.Date; +import javax.swing.JOptionPane; + import org.apache.commons.lang.NotImplementedException; -import org.apache.commons.lang.time.DateUtils; +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.FinancialPeriod; import org.chorem.lima.entity.FinancialPeriodImpl; @@ -64,35 +67,29 @@ addPeriodDialog.setLocationRelativeTo(view); addPeriodDialog.setVisible(true); - FiscalPeriod period = addPeriodDialog.getPeriod(); + FiscalPeriod fiscalPeriod = addPeriodDialog.getPeriod(); // null = cancel - if (period != null) { - - Date beginDate = period.getBeginDate(); - Date endDate = period.getEndDate(); - // set both to 0:00.000 - beginDate = DateUtils.ceiling(beginDate, Calendar.HOUR); - endDate = DateUtils.ceiling(beginDate, Calendar.HOUR); - - // on cree pour l'instant des periodes de 1mois - Date loopDate = beginDate; - while (loopDate.compareTo(endDate) < 0) { - Date loopUpperDate = DateUtils.addMonths(loopDate, 1); - Date periodEndDate = DateUtils.addMilliseconds(loopUpperDate, -1); - FinancialPeriod financialPeriod = new FinancialPeriodImpl(); - financialPeriod.setBeginDate(loopDate); - financialPeriod.setEndDate(periodEndDate); - period.addFinancialPeriod(financialPeriod); - loopDate = loopUpperDate; + if (fiscalPeriod!= null) { + System.out.println("begin : "+fiscalPeriod.getBeginDate()+" end :"+fiscalPeriod.getEndDate()); + //check if fiscalperiod have 12 months, ask a confirmation + int nbMonth = DateUtils.getDifferenceInMonths(fiscalPeriod.getBeginDate(), fiscalPeriod.getEndDate()); + int n = 0; + if(nbMonth !=12){ + n = JOptionPane.showConfirmDialog(view, + _("lima.question.fiscalperiod.morethan12"), + _("lima.question"), + JOptionPane.YES_NO_OPTION, + JOptionPane.QUESTION_MESSAGE); } - - try { - model.addFiscalPeriod(period); - } catch (LimaException ex) { - if (log.isErrorEnabled()) { - log.error("Can't add fiscal period", ex); + if (n == JOptionPane.YES_OPTION || nbMonth ==11){ + try { + model.addFiscalPeriod(fiscalPeriod); + } catch (LimaException ex) { + if (log.isErrorEnabled()) { + log.error("Can't add fiscal period", ex); + } + ErrorHelper.showErrorDialog(_("Can't add fiscal period"), ex); } - ErrorHelper.showErrorDialog(_("Can't add fiscal period"), ex); } } } @@ -100,4 +97,16 @@ public void blockFiscalPeriod() { throw new NotImplementedException("To be continued..."); } + + public void removeAllFiscalPeriods(){ + FiscalPeriodTableModel model = (FiscalPeriodTableModel)view.getFiscalPeriodTable().getModel(); + try { + model.removeAllFiscalPeriods(); + } catch (LimaException ex) { + if (log.isErrorEnabled()) { + log.error("Can't delete all fiscal period", ex); + } + ErrorHelper.showErrorDialog(_("Can't delete all fiscal period"), ex); + } + } } 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-21 16:09:27 UTC (rev 2870) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/model/FiscalPeriodTableModel.java 2010-04-23 09:58:20 UTC (rev 2871) @@ -165,4 +165,9 @@ fiscalPeriodService.createFiscalPeriod(period); fireTableRowsInserted(currentRowCount, currentRowCount); } + + public void removeAllFiscalPeriods() throws LimaException { + fiscalPeriodService.removeAllFiscalPeriods(); + fireTableDataChanged(); + } } 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-21 16:09:27 UTC (rev 2870) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing-fr_FR.properties 2010-04-23 09:58:20 UTC (rev 2871) @@ -1,5 +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\ ?= Global\ lima\ exception= Loading\ accounting...= @@ -219,8 +222,11 @@ lima.number=Num\u00E9ro lima.openejb.remotemode.description= lima.passif=Passif +lima.period= lima.period.begindate=D\u00E9but +lima.period.close= lima.period.enddate=Fin +lima.period.open= lima.preferences=Pr\u00E9f\u00E9rences lima.prefix=Pr\u00E9fixe lima.produit=Produit @@ -239,6 +245,7 @@ lima.progressBar.load.etape5=Chargement des transactions 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.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?