r2923 - in trunk: lima-business/src/main/java/org/chorem/lima/business lima-business/src/main/java/org/chorem/lima/business/accountingrules lima-business/src/main/java/org/chorem/lima/business/ejb lima-business/src/main/java/org/chorem/lima/business/utils lima-callao/src/main/java/org/chorem/lima/entity lima-callao/src/main/xmi lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/table lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionunbalanced
Author: jpepin Date: 2010-06-02 12:30:13 +0200 (Wed, 02 Jun 2010) New Revision: 2923 Url: http://chorem.org/repositories/revision/lima/2923 Log: Ajout d'interface DAO sur account et financial period. Suppression de m?\195?\169thodes inutiles et nettoyage du code dans les services. Utilisation des nouveaux DAO. Modification de m?\195?\169thodes d?\195?\169preci?\195?\169es. Added: trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountComparator.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountDAOImpl.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialPeriodDAOImpl.java Removed: trunk/lima-business/src/main/java/org/chorem/lima/business/utils/AccountComparator.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/AccountService.java trunk/lima-business/src/main/java/org/chorem/lima/business/AccountingRules.java trunk/lima-business/src/main/java/org/chorem/lima/business/EntryBookService.java 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/accountingrules/FranceAccountingRules.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/EntryBookServiceImpl.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/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookDAOImpl.java trunk/lima-callao/src/main/xmi/accounting.zargo trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/table/FinancialTransactionTableModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionunbalanced/FinancialTransactionUnbalancedTableModel.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/AccountService.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/AccountService.java 2010-06-01 16:36:05 UTC (rev 2922) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/AccountService.java 2010-06-02 10:30:13 UTC (rev 2923) @@ -20,9 +20,7 @@ package org.chorem.lima.business; import java.util.List; - import javax.ejb.Remote; - import org.chorem.lima.entity.Account; /** Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/AccountingRules.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/AccountingRules.java 2010-06-01 16:36:05 UTC (rev 2922) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/AccountingRules.java 2010-06-02 10:30:13 UTC (rev 2923) @@ -20,8 +20,6 @@ package org.chorem.lima.business; import java.util.List; -import javax.ejb.Remote; - import org.chorem.lima.entity.Account; import org.chorem.lima.entity.ClosedPeriodicEntryBook; import org.chorem.lima.entity.Entry; Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/EntryBookService.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/EntryBookService.java 2010-06-01 16:36:05 UTC (rev 2922) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/EntryBookService.java 2010-06-02 10:30:13 UTC (rev 2923) @@ -20,9 +20,7 @@ package org.chorem.lima.business; import java.util.List; - import javax.ejb.Remote; - import org.chorem.lima.entity.EntryBook; /** 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-06-01 16:36:05 UTC (rev 2922) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/FinancialPeriodService.java 2010-06-02 10:30:13 UTC (rev 2923) @@ -19,15 +19,11 @@ package org.chorem.lima.business; -import java.util.Date; import java.util.List; - import javax.ejb.Remote; - import org.chorem.lima.entity.ClosedPeriodicEntryBook; import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.FinancialPeriod; -import org.nuiton.topia.TopiaContext; /** * Financial period service. @@ -41,23 +37,17 @@ @Remote public interface FinancialPeriodService { - - List<FinancialPeriod> getAllFinancialPeriods() throws LimaException; List<FinancialPeriod> getUnblockedFinancialPeriods() throws LimaException; void createFinancialPeriods(List<FinancialPeriod> financialPeriods) throws LimaException; - FinancialPeriod getFinancialPeriodWithDate(Date date) throws LimaException; - /** Methodes for closedperiodicentrybook */ ClosedPeriodicEntryBook getClosedPeriodicEntryBook(EntryBook entryBook, FinancialPeriod financialPeriod) throws LimaException; List<ClosedPeriodicEntryBook> getAllClosedPeriodicEntryBooksFromUnblockedFiscalPeriod() throws LimaException; - - List<ClosedPeriodicEntryBook> getAllClosedPeriodicEntryBooks() throws LimaException; - + void blockClosedPeriodicEntryBook(ClosedPeriodicEntryBook closedPeriodicEntryBook) 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-06-01 16:36:05 UTC (rev 2922) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/FinancialTransactionService.java 2010-06-02 10:30:13 UTC (rev 2923) @@ -42,24 +42,8 @@ @Remote public interface FinancialTransactionService { - /** - * Find all transaction (use carefully, can return a lot of results). - * - * @return all transaction - * @throws LimaException - */ - List<FinancialTransaction> getAllFinancialTransactions() throws LimaException; /** - * Find all transaction for an entry book. - * - * @param entryBook entry book - * @return all transaction for entry book - * @throws LimaException - */ - List<FinancialTransaction> getAllFinancialTransactionsForEntryBook(EntryBook entryBook) throws LimaException; - - /** * Find all transaction for an entry book and a financial period. * * @param entryBook entry book Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/FranceAccountingRules.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/FranceAccountingRules.java 2010-06-01 16:36:05 UTC (rev 2922) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/FranceAccountingRules.java 2010-06-02 10:30:13 UTC (rev 2923) @@ -29,7 +29,6 @@ protected static final Log log = LogFactory.getLog(DefaultAccountingRules.class); - /** * Règles de vérification de la création du PCG, appliquées à la comptabilité française * 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-06-01 16:36:05 UTC (rev 2922) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java 2010-06-02 10:30:13 UTC (rev 2923) @@ -32,7 +32,7 @@ import org.chorem.lima.business.LimaBusinessException; import org.chorem.lima.business.LimaConfig; import org.chorem.lima.business.LimaException; -import org.chorem.lima.business.utils.AccountComparator; +import org.chorem.lima.entity.AccountComparator; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.AccountDAO; import org.chorem.lima.entity.LimaCallaoDAOHelper; @@ -198,12 +198,11 @@ /** Permet d'obtenir tout les comptes feuilles - * TODO PEPIN 20100601 Move on a DAO for use this methode on report service */ @Override public List<Account> getAllSubAccounts() throws LimaException { - List<Account> accountsList = new ArrayList<Account>(); + List<Account> accountsList = null; TopiaContext transaction = null; try { @@ -211,15 +210,7 @@ AccountDAO accountDAO = LimaCallaoDAOHelper.getAccountDAO(transaction); - //FIXME use topia query - List<Account> accounts = accountDAO.findAll(); - for (Account account : accounts) { - //check if parentaccount have no subaccount and no subledgers - if (account.getSubAccounts().size() == 0 && account.getSubLedgers().size() == 0){ - accountsList.add(account); - } - } - Collections.sort(accountsList, new AccountComparator()); + accountsList = accountDAO.findAllSubAccounts(); } catch (TopiaException ex) { doCatch(transaction, ex, log); @@ -253,11 +244,11 @@ TopiaQuery query = accountDAO.createQuery(); if (masterAccount == null){ - query.add("masterAccount", masterAccount); - query.add("generalLedger", TopiaQuery.Op.EQ, null); + query.addEquals("masterAccount", masterAccount); + query.addWhere("generalLedger", TopiaQuery.Op.EQ, null); } else { - query.add("masterAccount = :value or generalLedger = :value") + query.addWhere("masterAccount = :value or generalLedger = :value") .addParam("value", masterAccount); } accountsList.addAll(accountDAO.findAllByQuery(query)); @@ -274,6 +265,9 @@ return accountsList; } + /** + * Get list of all subaccount and ledger of an account + */ @Override public List<Account> getAllChildrenAccounts(Account masterAccount, List<Account> accounts) throws LimaException { Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java 2010-06-01 16:36:05 UTC (rev 2922) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java 2010-06-02 10:30:13 UTC (rev 2923) @@ -20,20 +20,14 @@ package org.chorem.lima.business.ejb; import static org.nuiton.i18n.I18n._; - import java.util.ArrayList; import java.util.List; - -import javax.ejb.EJB; import javax.ejb.Stateless; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.business.AccountingRules; import org.chorem.lima.business.EntryBookService; import org.chorem.lima.business.EntryBookServiceLocal; -import org.chorem.lima.business.FinancialPeriodService; -import org.chorem.lima.business.FinancialTransactionService; import org.chorem.lima.business.LimaBusinessException; import org.chorem.lima.business.LimaConfig; import org.chorem.lima.business.LimaException; 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-06-01 16:36:05 UTC (rev 2922) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java 2010-06-02 10:30:13 UTC (rev 2923) @@ -19,7 +19,6 @@ package org.chorem.lima.business.ejb; -import java.util.Date; import java.util.List; import javax.ejb.Stateless; import org.apache.commons.logging.Log; @@ -36,7 +35,6 @@ import org.chorem.lima.entity.EntryBookDAO; 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.LimaCallaoDAOHelper; import org.nuiton.topia.TopiaContext; @@ -139,34 +137,6 @@ doCatch(topiaContext, ex, log); } } - - /** - * Return all financial periods - */ - @Override - public List<FinancialPeriod> getAllFinancialPeriods() throws LimaException { - - List<FinancialPeriod> result = null; - - TopiaContext transaction = null; - try { - transaction = beginTransaction(); - - FinancialPeriodDAO financialPeriodDAO = LimaCallaoDAOHelper. - getFinancialPeriodDAO(transaction); - result = financialPeriodDAO.findAll(); - - commitTransaction(transaction); - } - catch (TopiaException ex) { - doCatch(transaction, ex, log); - } - finally { - doFinally(transaction, log); - } - - return result; - } /** * Return all unblocked financial period @@ -195,38 +165,7 @@ return result; } - - @Override - public FinancialPeriod getFinancialPeriodWithDate(Date date) throws LimaException { - FinancialPeriod financialPeriod= new FinancialPeriodImpl(); - - TopiaContext transaction = null; - try { - transaction = beginTransaction(); - - FinancialPeriodDAO financialPeriodDAO = - LimaCallaoDAOHelper.getFinancialPeriodDAO(transaction); - - TopiaQuery query = financialPeriodDAO.createQuery(); - if (date != null){ - query.addWhere("beginDate <= :value") - .addWhere("endDate >= :value") - .addParam("value", date); - } - financialPeriod = financialPeriodDAO.findByQuery(query); - log.debug(financialPeriod); - } - catch (TopiaException ex) { - doCatch(transaction, ex, log); - } - finally { - doFinally(transaction, log); - } - - return financialPeriod; - } - @Override public void blockClosedPeriodicEntryBook(ClosedPeriodicEntryBook closedPeriodicEntryBook) throws LimaException { @@ -329,36 +268,6 @@ return result; } - /** - * Just for debug - *TODO REMOVE - */ - @Override - public List<ClosedPeriodicEntryBook> getAllClosedPeriodicEntryBooks() throws LimaException { - List<ClosedPeriodicEntryBook> result = null; - - TopiaContext transaction = null; - try { - transaction = beginTransaction(); - - ClosedPeriodicEntryBookDAO closedPeriodicEntryBookDAO - = LimaCallaoDAOHelper.getClosedPeriodicEntryBookDAO(transaction); - - result=closedPeriodicEntryBookDAO.findAll(); - for (ClosedPeriodicEntryBook closedPeriodicEntryBook : result) { - closedPeriodicEntryBook.getEntryBook().getLabel(); - closedPeriodicEntryBook.getFinancialPeriod().getBeginDate(); - } - commitTransaction(transaction); - } - catch (TopiaException ex) { - doCatch(transaction, ex, log); - } - finally { - doFinally(transaction, log); - } - return result; - } protected TopiaContext beginTransaction() throws TopiaException { // basic check done, make check in database 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-06-01 16:36:05 UTC (rev 2922) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java 2010-06-02 10:30:13 UTC (rev 2923) @@ -20,26 +20,21 @@ package org.chorem.lima.business.ejb; import static org.nuiton.i18n.I18n._; - import java.util.Date; import java.util.List; - -import javax.ejb.EJB; import javax.ejb.Stateless; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.business.AccountingRules; -import org.chorem.lima.business.FinancialPeriodService; import org.chorem.lima.business.FinancialTransactionService; import org.chorem.lima.business.FinancialTransactionServiceLocal; import org.chorem.lima.business.LimaConfig; import org.chorem.lima.business.LimaException; -import org.chorem.lima.entity.Account; import org.chorem.lima.entity.Entry; import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.EntryDAO; 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.chorem.lima.entity.FinancialTransaction; @@ -68,9 +63,6 @@ private TopiaContext rootContext; protected AccountingRules accountingRules; - - @EJB - FinancialPeriodService financialPeriodService; public FinancialTransactionServiceImpl() { LimaConfig config = LimaConfig.getInstance(); @@ -86,7 +78,7 @@ /** * Permet de créer une transaction comptable contenant des entrées - * @throws LimaException + * */ @Override public void createFinancialTransaction(FinancialTransaction financialtransaction) throws LimaException { @@ -113,78 +105,8 @@ doFinally(topiaContext, log); } } - - /** - * Permet de retrouver la premiere transaction associée au journal. - * - * Utilisé par entrybook service pour savoir si un journal a des transactions - * associées et empecher la suppression. - * - * @param topiaTransaction context à utiliser - * @param entryBook journal - * @throws TopiaException - */ - protected FinancialTransaction findByEntryBook(TopiaContext topiaTransaction, EntryBook entryBook) throws TopiaException { - - FinancialTransactionDAO transactionDAO = - LimaCallaoDAOHelper.getFinancialTransactionDAO(topiaTransaction); - - TopiaQuery query = transactionDAO.createQuery(); - // entryBook is not visible, but column "entryBook" - // exist in transaction table - query.addEquals("entryBook", entryBook); - - FinancialTransaction result = transactionDAO.findByQuery(query); - - return result; - } /** - * Permet de retrouver la premiere transaction associée au compte. - * - * Utilisé par account service pour savoir si un compte a des transactions - * associées et empecher la suppression. - * - * @param topiaTransaction context à utiliser - * @param account compte - * @throws TopiaException - */ - protected Entry findByAccount(TopiaContext topiaTransaction, Account account) throws TopiaException { - - EntryDAO entryDAO = LimaCallaoDAOHelper.getEntryDAO(topiaTransaction); - //TODO marche pas - TopiaQuery query = entryDAO.createQuery(); - query.addEquals("account", account); - - Entry result = entryDAO.findByQuery(query); - - return result; - } - - - /** - * Return the list of all financial transaction - */ - @Override - public List<FinancialTransaction> getAllFinancialTransactions() throws LimaException { - - // find all with null entry book filter - - return getAllFinancialTransactionsForEntryBook(null); - } - /** - * Return the list of all financial transaction of an entrybook - */ - @Override - public List<FinancialTransaction> getAllFinancialTransactionsForEntryBook( - EntryBook entryBook) throws LimaException { - - // find all with null period filter - - return getAllFinancialTransactionsForEntryBookAndFinancialPeriod(entryBook, null); - } - - /** * Return the list of all financial transaction of a financial period */ @Override @@ -241,6 +163,7 @@ } @Override + //TODO No terminated public List<FinancialTransaction> getAllFinancialTransactionsUnbalanced(FiscalPeriod fiscalPeriod) throws LimaException { TopiaContext topiaContext = null; List<FinancialTransaction> result = null; @@ -249,10 +172,8 @@ FinancialTransactionDAO financialTransactionDAO = LimaCallaoDAOHelper.getFinancialTransactionDAO(topiaContext); - TopiaQuery query = financialTransactionDAO.createQuery("E"); - query.add(FinancialTransaction.ENTRY); - result = query.execute(); - log.debug(result); + + //TODO } catch (TopiaException ex) { @@ -264,7 +185,11 @@ return result; } - + /** + * update date and amount of a financial transaction + * call accounting rules + * + */ @Override public void updateFinancialTransaction(FinancialTransaction financialtransaction) throws LimaException { @@ -284,6 +209,9 @@ } + /** + * Method used by update entry and remove entry for update amounts + */ public void updateFinancialTransactionWithTransaction(FinancialTransaction financialtransaction, TopiaContext topiaContext) throws LimaException{ try { FinancialTransactionDAO transactionDAO = @@ -302,8 +230,9 @@ if (newDate.compareTo(oldDate) != 0){ financialTransactionOld.setTransactionDate(newDate); //change financial period - FinancialPeriod financialPeriod = - financialPeriodService.getFinancialPeriodWithDate(newDate); + FinancialPeriodDAO financialPeriodDAO = + LimaCallaoDAOHelper.getFinancialPeriodDAO(topiaContext); + FinancialPeriod financialPeriod = financialPeriodDAO.findByDate(newDate); if (financialPeriod != null){ financialTransactionOld.setFinancialPeriod(financialPeriod); } @@ -322,6 +251,10 @@ } } + /** + * delete financial period + * call accounting rules + */ @Override public void removeFinancialTransaction(FinancialTransaction financialtransaction) throws LimaException { @@ -351,10 +284,16 @@ } + /** + * Create new entry + * the period mus not be blocked, call accounting rules + * + * @return + */ @Override - public void removeEntry(Entry entry) throws LimaException { - + public void createEntry(Entry entry) throws LimaException { + TopiaContext topiaContext = null; try { topiaContext = beginTransaction(); @@ -362,29 +301,11 @@ //check if the financial period is blocked accountingRules.checkFinancialPeriodBlockedWithFinancialTransaction( entry.getFinancialTransaction(), topiaContext); - - //get entry amounts - Double entryAmount = entry.getAmount(); - Boolean entryAmountBool = entry.getDebit(); - Double entryDebit = entryAmountBool ? entryAmount : 0; - Double entryCredit = entryAmountBool ? 0 : entryAmount; - - //calculate financial transaction amounts - FinancialTransaction financialTransaction = - entry.getFinancialTransaction(); - Double amountDebit = financialTransaction.getAmountDebit(); - Double amountCredit = financialTransaction.getAmountCredit(); - financialTransaction.setAmountDebit(amountDebit-entryDebit); - financialTransaction.setAmountCredit(amountCredit-entryCredit); - - //update financial transaction - updateFinancialTransactionWithTransaction( - financialTransaction, topiaContext); - + + EntryDAO entryDAO = LimaCallaoDAOHelper.getEntryDAO(topiaContext); - //delete - entryDAO.delete(entry); - //commit + entryDAO.create(entry); + commitTransaction(topiaContext); } catch (TopiaException ex) { @@ -392,9 +313,13 @@ } finally { doFinally(topiaContext, log); - } + } } - + + + /** + * update entry, calculate amount of the financial transaction + */ @Override public void updateEntry(Entry entry) throws LimaException { @@ -421,7 +346,8 @@ Double entryDebitOld = entryAmountBoolOld ? entryAmountOld : 0; Double entryCreditOld = entryAmountBoolOld ? 0 : entryAmountOld; - //TODO PEPIN 20100520 conflict object already instanciate + //FIXME PEPIN 20100520 conflict object already instanciate + // Exist best solution ? entryOld.setAccount(entry.getAccount()); entryOld.setAmount(entryAmount); entryOld.setDebit(entryAmountBool); @@ -458,16 +384,13 @@ } } + /** - * Création d'une entrée comptable. - * La période ne doit PAS être bloquée. - * - * @return + * Remove entry, update amounts for the financial transaction */ - @Override - public void createEntry(Entry entry) throws LimaException { - + public void removeEntry(Entry entry) throws LimaException { + TopiaContext topiaContext = null; try { topiaContext = beginTransaction(); @@ -475,11 +398,29 @@ //check if the financial period is blocked accountingRules.checkFinancialPeriodBlockedWithFinancialTransaction( entry.getFinancialTransaction(), topiaContext); - - + + //get entry amounts + Double entryAmount = entry.getAmount(); + Boolean entryAmountBool = entry.getDebit(); + Double entryDebit = entryAmountBool ? entryAmount : 0; + Double entryCredit = entryAmountBool ? 0 : entryAmount; + + //calculate financial transaction amounts + FinancialTransaction financialTransaction = + entry.getFinancialTransaction(); + Double amountDebit = financialTransaction.getAmountDebit(); + Double amountCredit = financialTransaction.getAmountCredit(); + financialTransaction.setAmountDebit(amountDebit-entryDebit); + financialTransaction.setAmountCredit(amountCredit-entryCredit); + + //update financial transaction + updateFinancialTransactionWithTransaction( + financialTransaction, topiaContext); + EntryDAO entryDAO = LimaCallaoDAOHelper.getEntryDAO(topiaContext); - entryDAO.create(entry); - + //delete + entryDAO.delete(entry); + //commit commitTransaction(topiaContext); } catch (TopiaException ex) { @@ -487,10 +428,11 @@ } finally { doFinally(topiaContext, log); - } + } } + protected TopiaContext beginTransaction() throws TopiaException { // basic check done, make check in database // TODO move it into JTA 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-06-01 16:36:05 UTC (rev 2922) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java 2010-06-02 10:30:13 UTC (rev 2923) @@ -20,16 +20,12 @@ package org.chorem.lima.business.ejb; import static org.nuiton.i18n.I18n._; - import java.util.List; - import javax.ejb.EJB; import javax.ejb.Stateless; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.business.AccountingRules; -import org.chorem.lima.business.FinancialPeriodService; import org.chorem.lima.business.FinancialPeriodServiceLocal; import org.chorem.lima.business.FiscalPeriodService; import org.chorem.lima.business.FiscalPeriodServiceLocal; @@ -158,6 +154,7 @@ //IMPORTANT : LOADING FINANCIAL PERIOD FOR NO LAZY EXCEPTION for (FiscalPeriod fiscalPeriod : result) { //FIXME besoin d'appeler une lecture bidon de toutes les financialperiod + //TODO make this by topiaquery ? //sinon il pete tout de même une lazy exception for (FinancialPeriod financialPeriod : fiscalPeriod.getFinancialPeriod()) { } @@ -205,15 +202,12 @@ * to block a fiscal period * * check localized rules before block it - * - * Two transaction are necessary for no object conflict - * FIXME can found best solution ?! */ @Override public void blockFiscalPeriod(FiscalPeriod fiscalPeriod) throws LimaException { TopiaContext transaction = null; - //open transaction for check + //open transaction for update try { transaction = beginTransaction(); @@ -223,28 +217,21 @@ //check rules accountingRules.blockFiscalPeriodRules(fiscalPeriod, transaction); - } catch (TopiaException ex) { - doCatch(transaction, ex, log); - } - finally { - doFinally(transaction, log); - } - - //open transaction for update - try { - transaction = beginTransaction(); - FiscalPeriodDAO fiscalPeriodDAO = LimaCallaoDAOHelper.getFiscalPeriodDAO(transaction); + // Get the old fiscal period instance for no object conflict + FiscalPeriod oldFiscalPeriod = + fiscalPeriodDAO.findByTopiaId(fiscalPeriod.getTopiaId()); + // lock fiscalperiod - fiscalPeriod.setLocked(true); + oldFiscalPeriod.setLocked(true); // locked all financialperiod of the fiscalperiod - for ( FinancialPeriod financialPeriod : fiscalPeriod.getFinancialPeriod()) { + for ( FinancialPeriod financialPeriod : oldFiscalPeriod.getFinancialPeriod()) { financialPeriod.setLocked(true); } - fiscalPeriodDAO.update(fiscalPeriod); + fiscalPeriodDAO.update(oldFiscalPeriod); commitTransaction(transaction); Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java 2010-06-01 16:36:05 UTC (rev 2922) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java 2010-06-02 10:30:13 UTC (rev 2923) @@ -22,22 +22,19 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; - -import javax.ejb.EJB; import javax.ejb.Stateless; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.beans.BalanceTrial; import org.chorem.lima.beans.BalanceTrialImpl; import org.chorem.lima.beans.ReportsDatas; import org.chorem.lima.beans.ReportsDatasImpl; -import org.chorem.lima.business.AccountService; import org.chorem.lima.business.LimaConfig; import org.chorem.lima.business.LimaException; import org.chorem.lima.business.ReportService; import org.chorem.lima.business.ReportServiceLocal; import org.chorem.lima.entity.Account; +import org.chorem.lima.entity.AccountDAO; import org.chorem.lima.entity.Entry; import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.EntryDAO; @@ -56,9 +53,6 @@ private TopiaContext rootContext; - @EJB - AccountService accountService; - public ReportServiceImpl() { LimaConfig config = LimaConfig.getInstance(); try { @@ -146,10 +140,10 @@ String transactionDateProperty = TopiaQuery.getProperty(Entry.FINANCIAL_TRANSACTION, FinancialTransaction.TRANSACTION_DATE); - query.add(transactionDateProperty+" BETWEEN :beginDate AND :endDate") + query.addWhere(transactionDateProperty+" BETWEEN :beginDate AND :endDate") .addParam("beginDate", beginDate) .addParam("endDate", endDate) - .add(Entry.ACCOUNT, account); + .addEquals(Entry.ACCOUNT, account); return query; } @@ -158,6 +152,7 @@ * Get list entries * Calculate all credit, debit and solde amounts for the accounts reports */ + @SuppressWarnings("unchecked") protected ReportsDatas generateSubAccountReportsWithTransaction(Account account, Date beginDate, Date endDate, TopiaContext topiaContext) throws LimaException { ReportsDatas reportsDatas = new ReportsDatasImpl(); double credit = 0, debit = 0, solde = 0; @@ -176,7 +171,7 @@ createEntryQuery(account, beginDate, endDate, entryDAO, queryAlias); amountsQuery.setSelect("E."+Entry.DEBIT, "SUM(E."+Entry.AMOUNT+")"); amountsQuery.addGroup("E."+Entry.DEBIT); - results = amountsQuery.execute(); + results = amountsQuery.execute(topiaContext); int nbAmount = results.size(); if(nbAmount==2){ debit = (Double)results.get(0)[1]; @@ -215,6 +210,7 @@ /** * Calculate all credit, debit and solde amounts for the balance */ + @SuppressWarnings("unchecked") protected ReportsDatas generateSubAccountBalanceWithTransaction(Account account, Date beginDate, Date endDate, TopiaContext topiaContext) throws LimaException { ReportsDatas reportsDatas = new ReportsDatasImpl(); double credit = 0, debit = 0, solde = 0; @@ -228,7 +224,7 @@ createEntryQuery(account, beginDate, endDate, entryDAO, queryAlias); amountsQuery.setSelect("E."+Entry.DEBIT, "SUM(E."+Entry.AMOUNT+")"); amountsQuery.addGroup("E."+Entry.DEBIT); - results = amountsQuery.execute(); + results = amountsQuery.execute(topiaContext); int nbAmount = results.size(); if(nbAmount==2){ debit = (Double)results.get(0)[1]; @@ -270,6 +266,7 @@ * Calculate the amounts and the solde * */ + @SuppressWarnings({ "unchecked" }) @Override public ReportsDatas generateEntryBooksReports(EntryBook entryBook, Date beginDate, Date endDate) throws LimaException { ReportsDatas reportsDatas = new ReportsDatasImpl(); @@ -299,7 +296,7 @@ query.setSelect("E."+Entry.DEBIT, "SUM(E."+Entry.AMOUNT+")"); query.addGroup("E."+Entry.DEBIT); - results = query.execute(); + results = query.execute(topiaTransaction); int nbAmount = results.size(); if(nbAmount==2){ debit = (Double)results.get(0)[1]; @@ -353,8 +350,10 @@ try { topiaTransaction = beginTransaction(); + AccountDAO accountDAO = + LimaCallaoDAOHelper.getAccountDAO(topiaTransaction); //for each account create a balance sheet with a ReportsDatas - for (Account account : accountService.getAllSubAccounts()) { + for (Account account : accountDAO.findAllSubAccounts()) { ReportsDatas reportsDatas = generateSubAccountBalanceWithTransaction(account, beginDate, endDate, topiaTransaction); Deleted: trunk/lima-business/src/main/java/org/chorem/lima/business/utils/AccountComparator.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/utils/AccountComparator.java 2010-06-01 16:36:05 UTC (rev 2922) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/utils/AccountComparator.java 2010-06-02 10:30:13 UTC (rev 2923) @@ -1,32 +0,0 @@ -/* *##% Lima Swing - * Copyright (C) 2008 - 2010 CodeLutin - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * ##%*/ - -package org.chorem.lima.business.utils; - -import java.util.Comparator; - -import org.chorem.lima.entity.Account; - -public class AccountComparator implements Comparator<Account>{ - - @Override - public int compare(Account o1, Account o2) { - return o1.getAccountNumber().compareTo(o2.getAccountNumber()); - } - -} Added: trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountComparator.java =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountComparator.java (rev 0) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountComparator.java 2010-06-02 10:30:13 UTC (rev 2923) @@ -0,0 +1,35 @@ +/* *##% Lima Swing + * Copyright (C) 2008 - 2010 CodeLutin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%*/ + +package org.chorem.lima.entity; + +import java.util.Comparator; + +import org.chorem.lima.entity.Account; + +public class AccountComparator implements Comparator<Account>{ + + /** + * sort by accout number in lexicographical order + */ + @Override + public int compare(Account o1, Account o2) { + return o1.getAccountNumber().compareTo(o2.getAccountNumber()); + } + +} Added: trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountDAOImpl.java =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountDAOImpl.java (rev 0) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountDAOImpl.java 2010-06-02 10:30:13 UTC (rev 2923) @@ -0,0 +1,32 @@ +package org.chorem.lima.entity; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.nuiton.topia.TopiaException; + +public class AccountDAOImpl <E extends Account> extends AccountDAOAbstract<E> { + + /** + * List all subaccounts (no folderaccounts) + * Sort by accout number in lexicographical order + */ + @Override + public List<Account> findAllSubAccounts() throws TopiaException { + List<Account> accountsList = new ArrayList<Account>(); + + //FIXME use topia query + List<Account> accounts = (List<Account>) findAll(); + for (Account account : accounts) { + //check if parentaccount have no subaccount and no subledgers + if (account.getSubAccounts().size() == 0 + && account.getSubLedgers().size() == 0){ + accountsList.add(account); + } + } + Collections.sort(accountsList, new AccountComparator()); + return accountsList; + } + +} Modified: trunk/lima-callao/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookDAOImpl.java =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookDAOImpl.java 2010-06-01 16:36:05 UTC (rev 2922) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookDAOImpl.java 2010-06-02 10:30:13 UTC (rev 2923) @@ -9,6 +9,9 @@ public class ClosedPeriodicEntryBookDAOImpl <E extends ClosedPeriodicEntryBook> extends ClosedPeriodicEntryBookDAOAbstract<E>{ + /** + * Return ClosedPeriodicEntryBook by EntryBook and FinancialPeriod + */ @Override public ClosedPeriodicEntryBook findbyEntryBookAndFinancialPeriod( EntryBook entryBook, FinancialPeriod financialPeriod) @@ -16,10 +19,10 @@ TopiaQuery query = createQuery(); if (entryBook != null){ - query.add(ClosedPeriodicEntryBook.ENTRY_BOOK, entryBook); + query.addEquals(ClosedPeriodicEntryBook.ENTRY_BOOK, entryBook); } if (financialPeriod != null){ - query.add(ClosedPeriodicEntryBook.FINANCIAL_PERIOD, financialPeriod); + query.addEquals(ClosedPeriodicEntryBook.FINANCIAL_PERIOD, financialPeriod); } return findByQuery(query); Added: trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialPeriodDAOImpl.java =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialPeriodDAOImpl.java (rev 0) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialPeriodDAOImpl.java 2010-06-02 10:30:13 UTC (rev 2923) @@ -0,0 +1,26 @@ +package org.chorem.lima.entity; + +import java.util.Date; + +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.framework.TopiaQuery; + +public class FinancialPeriodDAOImpl <E extends FinancialPeriod> extends FinancialPeriodDAOAbstract<E>{ + + /** + * Return FinancialPeriod by Date + * Date is include between financialperiod begin and end date + */ + @Override + public FinancialPeriod findByDate(Date date) throws TopiaException { + + TopiaQuery query = createQuery(); + if (date != null){ + query.addWhere("beginDate <= :value") + .addWhere("endDate >= :value") + .addParam("value", date); + } + return findByQuery(query); + } + +} Modified: trunk/lima-callao/src/main/xmi/accounting.zargo =================================================================== (Binary files differ) Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/table/FinancialTransactionTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/table/FinancialTransactionTableModel.java 2010-06-01 16:36:05 UTC (rev 2922) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/table/FinancialTransactionTableModel.java 2010-06-02 10:30:13 UTC (rev 2923) @@ -426,8 +426,7 @@ switch (column) { case 0: //update - currentFinancialTransaction. - setTransactionDate((Date)value); + currentFinancialTransaction.setTransactionDate((Date)value); break; } // notify service for modification Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionunbalanced/FinancialTransactionUnbalancedTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionunbalanced/FinancialTransactionUnbalancedTableModel.java 2010-06-01 16:36:05 UTC (rev 2922) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionunbalanced/FinancialTransactionUnbalancedTableModel.java 2010-06-02 10:30:13 UTC (rev 2923) @@ -388,47 +388,8 @@ (FinancialTransaction)currentRow; switch (column) { case 0: - // Truncate the date - format 01-MM-YYYY - Date dateCurrentFinancialTransaction = ((Date)value); - dateCurrentFinancialTransaction = - DateUtils.truncate( - dateCurrentFinancialTransaction, Calendar.MONTH); - - // Return the begin date of the current financial period - Date dateCurrentFinancialPeriod = - selectedFiscalPeriod.getBeginDate(); - - // Compare to the begindate of the current financial period - if (!dateCurrentFinancialPeriod.equals(dateCurrentFinancialTransaction)){ - //methode get financialperiod dans le service - FinancialPeriod newFinancialPeriod = - new FinancialPeriodImpl(); - try { - newFinancialPeriod = - financialPeriodService.getFinancialPeriodWithDate( - dateCurrentFinancialTransaction); - } catch (LimaException e) { - if (log.isDebugEnabled()){ - log.debug("Can't get new financialPeriodService"); - } - } - //if the changed financial period is unlocked - if (newFinancialPeriod != null){ - if (newFinancialPeriod.getLocked() == false){ - //update - currentFinancialTransaction. - setTransactionDate((Date)value); - currentFinancialTransaction. - setFinancialPeriod(newFinancialPeriod); - } - } - else { - if (log.isDebugEnabled()){ - log.debug("Can't update on the new date"); - } - } - } - + //update + currentFinancialTransaction.setTransactionDate((Date)value); break; } // notify service for modification
participants (1)
-
jpepin@users.chorem.org