Author: jpepin Date: 2010-04-26 18:22:31 +0200 (Mon, 26 Apr 2010) New Revision: 2875 Log: Modification r?\195?\168gles clot?\195?\187re d'exercice, affichage des ?\195?\169critures, ajout d'une transaction Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/FinancialPeriodService.java trunk/lima-business/src/main/java/org/chorem/lima/business/FinancialTransactionService.java trunk/lima-business/src/main/java/org/chorem/lima/business/FiscalPeriodService.java trunk/lima-business/src/main/java/org/chorem/lima/business/LimaConfig.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java trunk/lima-business/src/test/java/org/chorem/lima/business/FiscalPeriodServiceImplTest.java trunk/lima-business/src/test/java/org/chorem/lima/business/LimaConfigTest.java trunk/lima-callao/src/main/xmi/accounting.properties trunk/lima-callao/src/main/xmi/accounting.zargo trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/model/FiscalPeriodTableModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/FinancialTransactionViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/TransactionView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/model/FinancialPeriodComboBoxModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/model/FinancialPeriodComboBoxRenderer.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/model/FiscalPeriodComboBoxModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/model/FiscalPeriodComboBoxRenderer.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/table/FinancialTransactionTableModel.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/FinancialPeriodService.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/FinancialPeriodService.java 2010-04-26 07:51:56 UTC (rev 2874) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/FinancialPeriodService.java 2010-04-26 16:22:31 UTC (rev 2875) @@ -22,6 +22,7 @@ import java.util.List; import org.chorem.lima.entity.FinancialPeriod; +import org.chorem.lima.entity.FiscalPeriod; /** * Financial period service. @@ -35,8 +36,10 @@ public interface FinancialPeriodService { List<FinancialPeriod> getAllFinancialPeriods() throws LimaException; + + List<FinancialPeriod> getUnblockedFinancialPeriods() throws LimaException; - List<FinancialPeriod> getNonLockedFinancialPeriods() throws LimaException; + List<FinancialPeriod> getUnblockedFinancialPeriodWithFiscalPeriod(FiscalPeriod selectedFiscalPeriod) throws LimaException; void createFinancialPeriod(FinancialPeriod financialPeriod) throws LimaException; Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/FinancialTransactionService.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/FinancialTransactionService.java 2010-04-26 07:51:56 UTC (rev 2874) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/FinancialTransactionService.java 2010-04-26 16:22:31 UTC (rev 2875) @@ -61,8 +61,12 @@ * @return all transaction for entry book and period * @throws LimaException */ - List<FinancialTransaction> getAllFinancialTransactionsForEntryBookAndFinancialPeriod(EntryBook entryBook, FinancialPeriod period) throws LimaException; + List<FinancialTransaction> getAllFinancialTransactionsForFinancialPeriod( + FinancialPeriod period) throws LimaException; + List<FinancialTransaction> getAllFinancialTransactionsForEntryBookAndFinancialPeriod( + EntryBook entryBook, FinancialPeriod period) throws LimaException; + void createFinancialTransaction(FinancialTransaction financialtransaction) throws LimaException; void updateFinancialTransaction(FinancialTransaction financialtransaction) throws LimaException; 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-26 07:51:56 UTC (rev 2874) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/FiscalPeriodService.java 2010-04-26 16:22:31 UTC (rev 2875) @@ -35,6 +35,8 @@ public interface FiscalPeriodService { List<FiscalPeriod> getAllFiscalPeriods() throws LimaException; + + List<FiscalPeriod> getAllUnblockedFiscalPeriods() throws LimaException; void createFiscalPeriod(FiscalPeriod fiscalPeriod) throws LimaException; Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/LimaConfig.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/LimaConfig.java 2010-04-26 07:51:56 UTC (rev 2874) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/LimaConfig.java 2010-04-26 16:22:31 UTC (rev 2875) @@ -42,11 +42,10 @@ protected static LimaConfig instance; - protected LimaConfig() { - - } + private static final String configFile = "lima.properties"; public static LimaConfig getInstance() { + /* if (instance == null) { instance = new LimaConfig(); instance.setConfigFileName("lima.properties"); @@ -60,8 +59,25 @@ // FIXME put this in another place instance.setOption("topia.persistence.classes", LimaCallaoDAOHelper.getImplementationClassesAsString()); + }*/ + if (instance == null) { + instance = new LimaConfig(); + instance.loadConfiguration(configFile); } - return instance; } + + protected void loadConfiguration(String configFileName){ + + instance.setConfigFileName(configFileName); + try { + instance.parse(new String[0]); + } catch (ArgumentsParserException ex) { + if (log.isErrorEnabled()) { + log.error("Can't read configuration", ex); + } + } + instance.setOption("topia.persistence.classes", LimaCallaoDAOHelper.getImplementationClassesAsString()); + } + } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java 2010-04-26 07:51:56 UTC (rev 2874) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java 2010-04-26 16:22:31 UTC (rev 2875) @@ -19,6 +19,8 @@ package org.chorem.lima.business.ejb; +import java.util.ArrayList; +import java.util.Collection; import java.util.List; import javax.ejb.Stateless; @@ -30,11 +32,14 @@ import org.chorem.lima.business.LimaException; import org.chorem.lima.entity.FinancialPeriod; import org.chorem.lima.entity.FinancialPeriodDAO; +import org.chorem.lima.entity.FiscalPeriod; import org.chorem.lima.entity.LimaCallaoDAOHelper; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaContextFactory; import org.nuiton.topia.TopiaException; import org.nuiton.topia.TopiaNotFoundException; +import org.nuiton.topia.framework.TopiaQuery; +import org.nuiton.topia.framework.TopiaQuery.Op; /** * Gestion des périodes intermédiaires durant l'exercice. @@ -174,7 +179,7 @@ } @Override - public List<FinancialPeriod> getNonLockedFinancialPeriods() throws LimaException { + public List<FinancialPeriod> getUnblockedFinancialPeriods() throws LimaException { List<FinancialPeriod> result = null; @@ -199,6 +204,17 @@ return result; } + + @Override + public List<FinancialPeriod> getUnblockedFinancialPeriodWithFiscalPeriod(FiscalPeriod selectedFiscalPeriod) throws LimaException { + + Collection<FinancialPeriod> temp = selectedFiscalPeriod.getFinancialPeriod(); + + List result = new ArrayList<FinancialPeriod>(temp); + log.debug("result : "+result); + + return result; + } /* * Permet de trouver un timespan directement avec une date. La date peut Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java 2010-04-26 07:51:56 UTC (rev 2874) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java 2010-04-26 16:22:31 UTC (rev 2875) @@ -295,7 +295,8 @@ } @Override - public List<FinancialTransaction> getAllFinancialTransactionsForEntryBook(EntryBook entryBook) throws LimaException { + public List<FinancialTransaction> getAllFinancialTransactionsForEntryBook( + EntryBook entryBook) throws LimaException { // find all with null period filter @@ -303,6 +304,13 @@ } @Override + public List<FinancialTransaction> getAllFinancialTransactionsForFinancialPeriod( + FinancialPeriod period) throws LimaException { + // TODO Auto-generated method stub + return getAllFinancialTransactionsForEntryBookAndFinancialPeriod(null, period); + } + + @Override public List<FinancialTransaction> getAllFinancialTransactionsForEntryBookAndFinancialPeriod(EntryBook entryBook, FinancialPeriod financialPeriod) throws LimaException { List<FinancialTransaction> transactions = null; @@ -465,6 +473,8 @@ } + + /* * Permet d'ajouter une entrée comptable pour une transaction donnée. * ATTENTION : la transaction doit être NON bloquée. 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-26 07:51:56 UTC (rev 2874) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java 2010-04-26 16:22:31 UTC (rev 2875) @@ -51,6 +51,7 @@ import org.nuiton.topia.framework.TopiaContextImplementor; import org.nuiton.topia.framework.TopiaQuery; import org.nuiton.topia.framework.TopiaQuery.Op; +import org.nuiton.topia.persistence.TopiaEntity; import org.apache.commons.lang.time.DateUtils; /** @@ -283,6 +284,33 @@ return result; } + public List<FiscalPeriod> getAllUnblockedFiscalPeriods() throws LimaException { + + List<FiscalPeriod> result = null; + + TopiaContext transaction = null; + try { + // basic check done, make check in database + // TODO move it into JTA + transaction = rootContext.beginTransaction(); + + FiscalPeriodDAO fiscalPeriodDAO = + LimaCallaoDAOHelper.getFiscalPeriodDAO(transaction); + result = fiscalPeriodDAO.findAllByLocked(false); + + // commit + transaction.commitTransaction(); + } + catch (TopiaException ex) { + doCatch(transaction, ex, log); + } + finally { + doFinally(transaction, log); + } + + return result; + } + @Override public void blockFiscalPeriod(FiscalPeriod fiscalPeriod) throws LimaException { TopiaContext transaction = null; @@ -292,8 +320,6 @@ 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); @@ -302,19 +328,30 @@ fiscalPeriodDAO.findAllByQuery(query); query.add(FiscalPeriod.LOCKED, Op.EQ, false); query.addOrder(FiscalPeriod.END_DATE); + // query.add(TopiaEntity.TOPIA_ID, fiscalPeriod.getTopiaId()); + //int oldestblocked = query.executeCount(); + FiscalPeriod oldestUnBlockedFiscalPeriod = fiscalPeriodDAO.findByQuery(query); - log.debug("oldestUnBlockedFiscalPeriod : "+oldestUnBlockedFiscalPeriod); + //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 + oldestUnBlockedFiscalPeriod.setLocked(true); + + // locked all financialperiod of the fiscalperiod + for ( FinancialPeriod financialPeriod : oldestUnBlockedFiscalPeriod.getFinancialPeriod()) { + financialPeriod.setLocked(true); + } + + + /* //FIXME JP 23/04/2010 code à changer pour ne pas dépendre de l'impl TopiaContextImpl topiaContextImpl = (TopiaContextImpl) transaction; - topiaContextImpl.getHibernate().evict(oldestUnBlockedFiscalPeriod); + topiaContextImpl.getHibernate().evict(oldestUnBlockedFiscalPeriod);*/ // update account - fiscalPeriodDAO.update(fiscalPeriod); + fiscalPeriodDAO.update(oldestUnBlockedFiscalPeriod); // commit transaction.commitTransaction(); Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/FiscalPeriodServiceImplTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/FiscalPeriodServiceImplTest.java 2010-04-26 07:51:56 UTC (rev 2874) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/FiscalPeriodServiceImplTest.java 2010-04-26 16:22:31 UTC (rev 2875) @@ -1,11 +1,27 @@ package org.chorem.lima.business; +import java.util.Calendar; +import java.util.Date; + +import javax.transaction.Transaction; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.ejb.FinancialPeriodServiceImpl; import org.chorem.lima.business.ejb.FiscalPeriodServiceImpl; +import org.chorem.lima.entity.FinancialPeriod; +import org.chorem.lima.entity.FinancialPeriodImpl; +import org.chorem.lima.entity.FiscalPeriod; +import org.chorem.lima.entity.FiscalPeriodDAO; +import org.chorem.lima.entity.FiscalPeriodImpl; +import org.chorem.lima.entity.LimaCallaoDAOHelper; import org.junit.AfterClass; +import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaContextFactory; +import org.nuiton.topia.TopiaNotFoundException; /** * Tests pour la gestion des périodes @@ -45,6 +61,76 @@ instance.removePeriod(periodDTO);*/ } + + + @Test + public void blockFiscalPeriodTest() throws Exception { + + TopiaContext rootcontext; + TopiaContext transaction=null; + rootcontext = TopiaContextFactory.getContext(LimaConfigTest.getInstance().getOptions()); + FiscalPeriod recentFiscalPeriod = new FiscalPeriodImpl(); + FiscalPeriod oldestFiscalPeriod = new FiscalPeriodImpl(); + + try { + + transaction = rootcontext.beginTransaction(); + + FiscalPeriodDAO fiscalPeriodDAO = + LimaCallaoDAOHelper.getFiscalPeriodDAO(transaction); + + FinancialPeriodServiceImpl financialPeriodService = + new FinancialPeriodServiceImpl(); + + //On crée deux période, une récente + + FinancialPeriod financialPeriod = new FinancialPeriodImpl(); + Calendar beginCalendar = Calendar.getInstance(); + recentFiscalPeriod.setBeginDate(beginCalendar.getTime()); + Calendar endCalendar = beginCalendar; + endCalendar.add(Calendar.MONTH, 12); + recentFiscalPeriod.setEndDate(endCalendar.getTime()); + fiscalPeriodDAO.create(recentFiscalPeriod); + recentFiscalPeriod.addFinancialPeriod(financialPeriod); + financialPeriodService.createFinancialPeriod(financialPeriod); + + + //une plus ancienne + beginCalendar.add(Calendar.YEAR, -2); + oldestFiscalPeriod.setBeginDate(beginCalendar.getTime()); + endCalendar.add(Calendar.YEAR, -2); + oldestFiscalPeriod.setEndDate(endCalendar.getTime()); + fiscalPeriodDAO.create(oldestFiscalPeriod); + oldestFiscalPeriod.addFinancialPeriod(financialPeriod); + + transaction.commitTransaction(); + + } finally { + transaction.closeContext(); + } + + + Assert.assertNotSame(recentFiscalPeriod.getTopiaId(), + oldestFiscalPeriod.getTopiaId()); + + FiscalPeriodService fiscalPeriodService = new FiscalPeriodServiceImpl(); + + + try{ + + + fiscalPeriodService.blockFiscalPeriod(oldestFiscalPeriod); + } catch (Exception ex){ + log.debug("Error test block Period", ex); + Assert.assertEquals(LimaBusinessException.class, ex.getClass()); + } + try { + fiscalPeriodService.blockFiscalPeriod(recentFiscalPeriod); + } catch (Exception ex){ + log.debug("Error test block Period", ex); + Assert.assertEquals(LimaBusinessException.class, ex.getClass()); + } + } /** * Permet de tester l'ajout d'une période. */ Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/LimaConfigTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/LimaConfigTest.java 2010-04-26 07:51:56 UTC (rev 2874) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/LimaConfigTest.java 2010-04-26 16:22:31 UTC (rev 2875) @@ -20,6 +20,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.lima.entity.LimaCallaoDAOHelper; import org.junit.Ignore; import org.nuiton.util.ArgumentsParserException; @@ -37,9 +38,18 @@ private static final Log log = LogFactory.getLog(LimaConfig.class); + private static final String configFile = "lima_test.properties"; + public static LimaConfig getInstance() { + if (instance == null) { instance = new LimaConfig(); + instance.loadConfiguration(configFile); + } + return instance; + + /*if (instance == null) { + instance = new LimaConfig(); instance.setConfigFileName("lima_test.properties"); try { instance.parse(new String[0]); @@ -48,8 +58,8 @@ log.error("Can't read configuration", ex); } } - } + instance.setOption("topia.persistence.classes", LimaCallaoDAOHelper.getImplementationClassesAsString()); - return instance; + }*/ } } Modified: trunk/lima-callao/src/main/xmi/accounting.properties =================================================================== --- trunk/lima-callao/src/main/xmi/accounting.properties 2010-04-26 07:51:56 UTC (rev 2874) +++ trunk/lima-callao/src/main/xmi/accounting.properties 2010-04-26 16:22:31 UTC (rev 2875) @@ -4,5 +4,6 @@ org.chorem.lima.entity.Account.attribute.subLedgers.tagvalue.lazy=false org.chorem.lima.entity.FinancialTransaction.attribute.entry.tagvalue.lazy=false org.chorem.lima.entity.Account.attribute.identity.tagvalue.lazy=false +org.chorem.lima.entity.FiscalPeriod.attribute.financialPeriod.tagvalue.lazy=false #model.tagvalue.dbSchema=Callao model.tagvalue.String=text \ No newline at end of file Modified: trunk/lima-callao/src/main/xmi/accounting.zargo =================================================================== (Binary files differ) 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-26 07:51:56 UTC (rev 2874) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/model/FiscalPeriodTableModel.java 2010-04-26 16:22:31 UTC (rev 2875) @@ -20,8 +20,11 @@ import static org.nuiton.i18n.I18n._; +import java.util.Calendar; +import java.util.Date; import java.util.List; +import javax.swing.JLabel; import javax.swing.table.AbstractTableModel; import org.apache.commons.logging.Log; @@ -29,6 +32,7 @@ import org.chorem.lima.business.FiscalPeriodService; import org.chorem.lima.business.LimaException; import org.chorem.lima.entity.EntryBook; +import org.chorem.lima.entity.FinancialPeriod; import org.chorem.lima.entity.FiscalPeriod; import org.chorem.lima.service.LimaServiceFactory; @@ -130,16 +134,39 @@ periods = fiscalPeriodService.getAllFiscalPeriods(); FiscalPeriod fiscalPeriod = periods.get(rowIndex); - switch (columnIndex) { - case 0: - result = fiscalPeriod.getBeginDate() - + " - " + fiscalPeriod.getEndDate(); - break; - case 1: - result = fiscalPeriod.getLocked(); - break; + + String[] monthName = {_("lima.date.january"), _("lima.date.february"), + _("lima.date.march"), _("lima.date.april"), _("lima.date.may"), + _("lima.date.june"), _("lima.date.july"), _("lima.date.august"), + _("lima.date.september"), _("lima.date.october"), + _("lima.date.november"), _("lima.date.december")}; + + if (fiscalPeriod != null){ + Date date = fiscalPeriod.getBeginDate(); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + String formatBeginDate = monthName[calendar.get(Calendar.MONTH)] + +" "+String.valueOf(calendar.get(Calendar.YEAR)); + date = fiscalPeriod.getEndDate(); + calendar.setTime(date); + String formatEndDate = monthName[calendar.get(Calendar.MONTH)] + +" "+String.valueOf(calendar.get(Calendar.YEAR)); + date = fiscalPeriod.getEndDate(); + + + switch (columnIndex) { + case 0: + result = formatBeginDate + + " - " + formatEndDate; + break; + case 1: + result = fiscalPeriod.getLocked(); + break; + } } + + } catch (LimaException e) { // TODO Auto-generated catch block e.printStackTrace(); Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/FinancialTransactionViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/FinancialTransactionViewHandler.java 2010-04-26 07:51:56 UTC (rev 2874) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/FinancialTransactionViewHandler.java 2010-04-26 16:22:31 UTC (rev 2875) @@ -43,7 +43,8 @@ public class FinancialTransactionViewHandler { /** log. */ - private static final Log log = LogFactory.getLog(FinancialTransactionViewHandler.class); + private static final Log log = + LogFactory.getLog(FinancialTransactionViewHandler.class); protected TransactionView view; @@ -53,8 +54,10 @@ //add a new transaction protected void addFinancialTransaction() { - FinancialTransactionTable table = (FinancialTransactionTable)view.getFinancialTransactionTable(); - FinancialTransactionTableModel model = (FinancialTransactionTableModel)table.getModel(); + FinancialTransactionTable table = + (FinancialTransactionTable)view.getFinancialTransactionTable(); + FinancialTransactionTableModel model = + (FinancialTransactionTableModel)table.getModel(); try { model.addFinancialTransaction(); @@ -68,8 +71,10 @@ //add a new entry to the selected transaction public void addEmptyEntry(){ - FinancialTransactionTable table = (FinancialTransactionTable)view.getFinancialTransactionTable(); - FinancialTransactionTableModel model = (FinancialTransactionTableModel)table.getModel(); + FinancialTransactionTable table = + (FinancialTransactionTable)view.getFinancialTransactionTable(); + FinancialTransactionTableModel model = + (FinancialTransactionTableModel)table.getModel(); int indexSelectedRow = table.getSelectedRow(); if (indexSelectedRow != -1) { @@ -91,8 +96,10 @@ */ public void deleteSelectedRow(){ - FinancialTransactionTable table = (FinancialTransactionTable)view.getFinancialTransactionTable(); - FinancialTransactionTableModel model = (FinancialTransactionTableModel)table.getModel(); + FinancialTransactionTable table = + (FinancialTransactionTable)view.getFinancialTransactionTable(); + FinancialTransactionTableModel model = + (FinancialTransactionTableModel)table.getModel(); int indexSelectedRow = table.getSelectedRow(); if (indexSelectedRow != -1) { Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/TransactionView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/TransactionView.jaxx 2010-04-26 07:51:56 UTC (rev 2874) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/TransactionView.jaxx 2010-04-26 16:22:31 UTC (rev 2875) @@ -18,12 +18,15 @@ <Table> <FinancialTransactionViewHandler id="handler" javaBean="new FinancialTransactionViewHandler(this)" /> <Boolean id="selectedRow" javaBean="false" /> - + <org.chorem.lima.ui.transaction.model.FinancialPeriodComboBoxModel id="modelFinancialPeriod"/> <script> <![CDATA[ import org.chorem.lima.entity.EntryBook; + import org.chorem.lima.entity.FiscalPeriod; + import org.chorem.lima.entity.FinancialPeriod; + ]]> </script> @@ -44,6 +47,7 @@ <JComboBox id="fiscalPeriodComboBox" model="{new org.chorem.lima.ui.transaction.model.FiscalPeriodComboBoxModel()}" renderer="{new org.chorem.lima.ui.transaction.model.FiscalPeriodComboBoxRenderer()}" + onItemStateChanged="getModelFinancialPeriod().setFiscalPeriod( (FiscalPeriod) event.getItem())" editable="false"/> </cell> <cell> @@ -52,8 +56,9 @@ </cell> <cell> <JComboBox id="financialPeriodComboBox" - model="{new org.chorem.lima.ui.transaction.model.FinancialPeriodComboBoxModel()}" + model="{getModelFinancialPeriod()}" renderer="{new org.chorem.lima.ui.transaction.model.FinancialPeriodComboBoxRenderer()}" + onItemStateChanged="getFinancialTransactionTableModel().setFinancialPeriod((FinancialPeriod) event.getItem())" editable="false" /> </cell> @@ -80,7 +85,7 @@ highlighters="{org.jdesktop.swingx.decorator.HighlighterFactory.createAlternateStriping(Color.WHITE,new Color(250,250,250))}" /> <javax.swing.ListSelectionModel javaBean="getFinancialTransactionTable().getSelectionModel()" onValueChanged="setSelectedRow(financialTransactionTable.getSelectedRow() != -1)"/> - </JScrollPane> + </JScrollPane> </cell> <cell> <JButton text="lima.add.transaction" Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/model/FinancialPeriodComboBoxModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/model/FinancialPeriodComboBoxModel.java 2010-04-26 07:51:56 UTC (rev 2874) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/model/FinancialPeriodComboBoxModel.java 2010-04-26 16:22:31 UTC (rev 2875) @@ -23,6 +23,7 @@ import org.chorem.lima.business.FinancialPeriodService; import org.chorem.lima.business.LimaException; +import org.chorem.lima.entity.FiscalPeriod; import org.chorem.lima.service.LimaServiceFactory; /** @@ -39,11 +40,17 @@ protected Object selectedFinancialPeriod; protected FinancialPeriodService financialPeriodService; + + protected FiscalPeriod selectedFiscalPeriod; public FinancialPeriodComboBoxModel() { financialPeriodService = LimaServiceFactory.getInstance().getFinancialPeriodService(); } + public void setFiscalPeriod(FiscalPeriod fiscalPeriod){ + selectedFiscalPeriod=fiscalPeriod; + } + /* * @see javax.swing.ListModel#getSize() */ @@ -52,7 +59,15 @@ int result = 0; // TODO add cache try { - result = financialPeriodService.getNonLockedFinancialPeriods().size(); + if (selectedFiscalPeriod != null){ + result = financialPeriodService. + getUnblockedFinancialPeriodWithFiscalPeriod( + selectedFiscalPeriod).size(); + } + else { + result = financialPeriodService. + getUnblockedFinancialPeriods().size(); + } } catch (LimaException ex) { // TODO Auto-generated catch block @@ -69,7 +84,15 @@ Object result = null; // TODO add cache try { - result = financialPeriodService.getNonLockedFinancialPeriods().get(index); + if (selectedFiscalPeriod != null){ + result = financialPeriodService. + getUnblockedFinancialPeriodWithFiscalPeriod( + selectedFiscalPeriod).get(index); + } + else { + result = financialPeriodService.getUnblockedFinancialPeriods(). + get(index); + } } catch (LimaException ex) { // TODO Auto-generated catch block Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/model/FinancialPeriodComboBoxRenderer.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/model/FinancialPeriodComboBoxRenderer.java 2010-04-26 07:51:56 UTC (rev 2874) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/model/FinancialPeriodComboBoxRenderer.java 2010-04-26 16:22:31 UTC (rev 2875) @@ -18,8 +18,11 @@ package org.chorem.lima.ui.transaction.model; +import static org.nuiton.i18n.I18n._; + import java.awt.Component; import java.text.SimpleDateFormat; +import java.util.Calendar; import java.util.Date; import javax.swing.DefaultListCellRenderer; @@ -39,13 +42,20 @@ boolean cellHasFocus) { // TODO Auto-generated method stub + String[] monthName = {_("lima.date.january"), _("lima.date.february"), + _("lima.date.march"), _("lima.date.april"), _("lima.date.may"), + _("lima.date.june"), _("lima.date.july"), _("lima.date.august"), + _("lima.date.september"), _("lima.date.october"), + _("lima.date.november"), _("lima.date.december")}; + JLabel label = new JLabel(); FinancialPeriod financialperiod = (FinancialPeriod) value; if (financialperiod != null){ - //Date d = financialperiod.getBeginDate(); - //String date = d.getMonth() + " " + (d.getYear() + 1900); - //label.setText(date); - label.setText(financialperiod.getBeginDate().toString()); + Date d = financialperiod.getBeginDate(); + Calendar beginDate = Calendar.getInstance(); + beginDate.setTime(d); + int year = beginDate.get(Calendar.YEAR); + label.setText(monthName[beginDate.get(Calendar.MONTH)]+" "+String.valueOf(year)); } return label; } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/model/FiscalPeriodComboBoxModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/model/FiscalPeriodComboBoxModel.java 2010-04-26 07:51:56 UTC (rev 2874) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/model/FiscalPeriodComboBoxModel.java 2010-04-26 16:22:31 UTC (rev 2875) @@ -23,6 +23,8 @@ import org.chorem.lima.business.FiscalPeriodService; import org.chorem.lima.business.LimaException; +import org.chorem.lima.entity.FiscalPeriodDAO; +import org.chorem.lima.entity.LimaCallaoDAOHelper; import org.chorem.lima.service.LimaServiceFactory; public class FiscalPeriodComboBoxModel implements ComboBoxModel{ @@ -30,7 +32,7 @@ protected Object selectedFiscalPeriod; protected FiscalPeriodService fiscalPeriodService; - + public FiscalPeriodComboBoxModel(){ fiscalPeriodService = LimaServiceFactory.getInstance().getFiscalPeriodService(); } @@ -43,7 +45,7 @@ int result = 0; // TODO add cache try { - result = fiscalPeriodService.getAllFiscalPeriods().size(); + result = fiscalPeriodService.getAllUnblockedFiscalPeriods().size(); } catch (LimaException ex) { // TODO Auto-generated catch block @@ -59,7 +61,7 @@ public Object getElementAt(int index) { Object result = null; try { - result = fiscalPeriodService.getAllFiscalPeriods().get(index); + result = fiscalPeriodService.getAllUnblockedFiscalPeriods().get(index); } catch (LimaException ex) { ex.printStackTrace(); Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/model/FiscalPeriodComboBoxRenderer.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/model/FiscalPeriodComboBoxRenderer.java 2010-04-26 07:51:56 UTC (rev 2874) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/model/FiscalPeriodComboBoxRenderer.java 2010-04-26 16:22:31 UTC (rev 2875) @@ -19,6 +19,8 @@ package org.chorem.lima.ui.transaction.model; import java.awt.Component; +import java.util.Calendar; +import java.util.Date; import javax.swing.DefaultListCellRenderer; import javax.swing.JLabel; @@ -39,11 +41,12 @@ JLabel label = new JLabel(); FiscalPeriod fiscalPeriod = (FiscalPeriod) value; - if (fiscalPeriod != null){ - //Date d = financialperiod.getBeginDate(); - //String date = d.getMonth() + " " + (d.getYear() + 1900); - //label.setText(date); - label.setText(fiscalPeriod.getBeginDate().toString()); + if (fiscalPeriod != null){ + Date d = fiscalPeriod.getBeginDate(); + Calendar beginDate = Calendar.getInstance(); + beginDate.setTime(d); + int date = beginDate.get(Calendar.YEAR); + label.setText(String.valueOf(date)); } return label; } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/table/FinancialTransactionTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/table/FinancialTransactionTableModel.java 2010-04-26 07:51:56 UTC (rev 2874) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/table/FinancialTransactionTableModel.java 2010-04-26 16:22:31 UTC (rev 2875) @@ -21,12 +21,14 @@ import static org.nuiton.i18n.I18n._; import java.util.ArrayList; +import java.util.Calendar; import java.util.Date; import java.util.List; import javax.swing.JOptionPane; import javax.swing.table.AbstractTableModel; +import org.apache.commons.lang.time.DateUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.business.LimaBusinessException; @@ -36,7 +38,10 @@ import org.chorem.lima.entity.Account; import org.chorem.lima.entity.Entry; import org.chorem.lima.entity.EntryBook; +import org.chorem.lima.entity.EntryImpl; import org.chorem.lima.entity.FinancialPeriod; +import org.chorem.lima.entity.FinancialTransactionImpl; +import org.chorem.lima.entity.FiscalPeriod; import org.chorem.lima.entity.LimaCallaoDAOHelper; import org.chorem.lima.entity.FinancialTransaction; import org.chorem.lima.service.LimaServiceFactory; @@ -80,7 +85,7 @@ protected EntryBook selectedEntryBook; protected FinancialPeriod selectedFinancialPeriod; - + /** * Model constructor. * @@ -102,8 +107,6 @@ */ protected List<Object> getDataList() { - log.debug("getDatalist"); - List<Object> results = new ArrayList<Object>(); try { @@ -217,15 +220,15 @@ @Override public int getRowCount() { int result = 0; - + // just prevent too much result - if (selectedEntryBook != null) { + if (selectedFinancialPeriod != null) { List<Object> datas = getDataList(); result = datas.size(); } else { if (log.isDebugEnabled()) { - log.debug("No entry book selected skip table model update"); + log.debug("No fiscalPeriod selected skip table model update"); } } @@ -237,8 +240,7 @@ Object result = null; // just prevent too much result - System.out.println("OK2"); - if (selectedEntryBook != null) { + if (selectedFinancialPeriod != null) { // TODO EC-20100407 remove this ugly code List<Object> datas = getDataList(); result = datas.get(row); @@ -268,7 +270,8 @@ result = FinancialTransactionHelper.getCredit(currentRow); break; case 7: - result = FinancialTransactionHelper.getDebit(currentRow) - FinancialTransactionHelper.getCredit(currentRow); + result = FinancialTransactionHelper.getDebit(currentRow) + - FinancialTransactionHelper.getCredit(currentRow); break; case 8: result = currentRow.getDescription(); @@ -316,19 +319,24 @@ } else { if (log.isDebugEnabled()) { - log.debug("No entry book selected skip table model update"); + log.debug("No fiscalPeriod selected skip table model update"); } } return result; } + + + public void setFinancialPeriod(FinancialPeriod financialPeriod){ + + selectedFinancialPeriod = financialPeriod; + fireTableDataChanged(); + } - public void setEntryBook(EntryBook entryBook){ - - System.out.println("OK"); - selectedEntryBook = entryBook; - fireTableDataChanged(); + + selectedEntryBook = entryBook; + fireTableDataChanged(); } /** @@ -337,21 +345,28 @@ public void addFinancialTransaction() throws LimaException{ /* Calling transaction service */ //TODO transaction = currentdate, current periode, current journal - FinancialTransaction financialtransaction =null; + FinancialTransaction financialTransaction = new FinancialTransactionImpl(); //if a period and an entrybook is selected - if (selectedEntryBook != null && selectedFinancialPeriod != null){ - financialtransaction.setFinancialPeriod(selectedFinancialPeriod); - financialtransaction.setEntryBook(selectedEntryBook); - //financialransaction.setDescription(description); + if (selectedFinancialPeriod != null && selectedEntryBook!=null){ + financialTransaction.setFinancialPeriod(selectedFinancialPeriod); + financialTransaction.setEntryBook(selectedEntryBook); + // get today + Calendar actualCalendar = Calendar.getInstance(); + // get the financial period date + Date transactionDate = selectedFinancialPeriod.getBeginDate(); + //change the day + transactionDate = DateUtils.setDays(transactionDate, actualCalendar.get(Calendar.DAY_OF_MONTH)); + //set date to the financial transaction + financialTransaction.setTransactionDate(transactionDate); //create it - transactionService.createFinancialTransaction(financialtransaction); - int row = getDataList().indexOf(financialtransaction); + transactionService.createFinancialTransaction(financialTransaction); + int row = getDataList().indexOf(financialTransaction); //int row = transactionService.getAllTransactions().indexOf(transaction); log.debug(row); fireTableRowsInserted(row, row); } else { - throw new LimaBusinessException("No financialperiod or no entrybook selected"); + throw new LimaBusinessException("No financial period and bookentry selected"); } } @@ -365,7 +380,7 @@ //TODO transaction = currentdate, current periode, current journal List<Object> datas = getDataList(); Object currentRow = datas.get(row); - Entry entry=null; + Entry entry = new EntryImpl(); if (currentRow instanceof FinancialTransaction) { FinancialTransaction currentTransaction = (FinancialTransaction)currentRow; currentTransaction.addEntry(entry); @@ -382,7 +397,7 @@ public void setValueAt(Object value, int row, int column) { // just prevent too much result - if (selectedEntryBook != null) { + if (selectedFinancialPeriod != null) { // TODO EC-20100407 remove this ugly code List<Object> datas = getDataList(); Object currentRow = datas.get(row); @@ -477,7 +492,7 @@ } else { if (log.isDebugEnabled()) { - log.debug("No entry book selected skip table model update"); + log.debug("No fiscalPeriod selected skip table model update"); } } } 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-26 07:51:56 UTC (rev 2874) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing-en_GB.properties 2010-04-26 16:22:31 UTC (rev 2875) @@ -260,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.blocked= 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 ? 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-26 07:51:56 UTC (rev 2874) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing-fr_FR.properties 2010-04-26 16:22:31 UTC (rev 2875) @@ -245,8 +245,8 @@ 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.blocked=\u00C8tes vous s\u00FBre de vouloir cl\u00F4turer cette exercice ? Cette action est irr\u00E9versible \! 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? @@ -296,7 +296,7 @@ lima.transaction.column.account=Compte lima.transaction.column.balance=Balance lima.transaction.column.credit=Cr\u00E9dit -lima.transaction.column.date=Date +lima.transaction.column.date=Jour lima.transaction.column.debit=D\u00E9bit lima.transaction.column.description=Description lima.transaction.column.document=Document @@ -317,6 +317,6 @@ lima.view=Vue lima.view.flatten=Vue aplatie lima.voucher=Document -lima.warning.financialtransaction.noselect=journal et/ou p\u00E9riode non s\u00E9lectionn\u00E9 +lima.warning.financialtransaction.noselect=Aucune p\u00E9riode et/ou aucun journal s\u00E9lectionn\u00E9 lima.warning.nimbus.landf=Le look and feel nymbus n'a pas \u00E9t\u00E9 trouv\u00E9 lima.warning.no.ui=Aucun environnement graphique d\u00E9tect\u00E9.