Author: vsalaun Date: 2011-07-01 15:58:36 +0200 (Fri, 01 Jul 2011) New Revision: 3194 Url: http://chorem.org/repositories/revision/lima/3194 Log: Service refactoring (\ /) (O.o) (> <) Bunny approves these changes. Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/FinancialTransactionService.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/FinancialTransactionServiceLocal.java 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 2011-07-01 13:50:35 UTC (rev 3193) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java 2011-07-01 13:58:36 UTC (rev 3194) @@ -29,8 +29,6 @@ import java.math.BigDecimal; import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collections; import java.util.Date; import java.util.List; @@ -41,9 +39,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.FinancialStatementWayEnum; -import org.chorem.lima.beans.BalanceTrial; import org.chorem.lima.beans.FinancialTransactionSearch; -import org.chorem.lima.beans.ReportsDatas; import org.chorem.lima.business.AccountingRules; import org.chorem.lima.business.LimaConfig; import org.chorem.lima.business.LimaException; @@ -53,17 +49,13 @@ import org.chorem.lima.business.ejbinterface.FinancialTransactionServiceLocal; import org.chorem.lima.business.ejbinterface.ReportService; import org.chorem.lima.business.ejbinterface.OptionsService; -import org.chorem.lima.business.utils.FinancialPeriodComparator; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.AccountDAO; -import org.chorem.lima.entity.ClosedPeriodicEntryBook; import org.chorem.lima.entity.Entry; import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.EntryDAO; -import org.chorem.lima.entity.EntryImpl; import org.chorem.lima.entity.FinancialPeriod; import org.chorem.lima.entity.FinancialPeriodDAO; -import org.chorem.lima.entity.FinancialTransactionImpl; import org.chorem.lima.entity.FiscalPeriod; import org.chorem.lima.entity.Letter; import org.chorem.lima.entity.LetterDAO; @@ -470,12 +462,9 @@ } - @Override public Entry createEntryWithTransaction(Entry entry, - TopiaContext topiaContext) throws LimaException { + TopiaContext topiaContext) throws LimaException, TopiaException { Entry newEntry = null; - try { - //check if the financial period is blocked accountingRules.checkFinancialPeriodBlockedWithFinancialTransaction( entry.getFinancialTransaction(), topiaContext); @@ -518,11 +507,7 @@ financialTransaction, topiaContext); - commitTransaction(topiaContext); - } - catch (TopiaException ex) { - doCatch(topiaContext, ex, log); - } + //commitTransaction(topiaContext); return newEntry; } @@ -540,7 +525,11 @@ try { topiaContext = beginTransaction(); - return createEntryWithTransaction(entry, topiaContext); + Entry newEntry = createEntryWithTransaction(entry, topiaContext); + + commitTransaction(topiaContext); + + return newEntry; } catch (TopiaException ex) { doCatch(topiaContext, ex, log); @@ -687,135 +676,6 @@ } } - @Override - public void addRetainedEarnings(FiscalPeriod previousFiscalPeriod, FiscalPeriod fiscalPeriod, EntryBook entryBook, Date date) throws LimaException { - TopiaContext topiaContext = null; - try { - - - BalanceTrial results = reportService.generateBalanceTrial(previousFiscalPeriod.getBeginDate(), previousFiscalPeriod.getEndDate(), null, false, false); - - List<ReportsDatas> reportsDatasList = (List<ReportsDatas>) results.getReportsDatas(); - - topiaContext = beginTransaction(); - - //Sets entryBook - //search for the entryBook to use using param - boolean found = false; - List<EntryBook> entryBooksList = entryBookService.getAllEntryBooks(); - for (EntryBook entry : entryBooksList) { - if (!found && entry.getCode().equals(entryBook.getCode()) && entry.getLabel().equals(entryBook.getLabel())) { - entryBook = entry; - found = true; - } - } - //if entrybook is not found - //then create it - if (!found) { - entryBookService.createEntryBook(entryBook); - entryBooksList = entryBookService.getAllEntryBooks(); - for (EntryBook entry : entryBooksList) { - if (!found && entry.getCode().equals(entryBook.getCode()) && entry.getLabel().equals(entryBook.getLabel())) { - entryBook = entry; - found = true; - } - } - } - - //Sets the financialTransaction - FinancialTransaction financialTransaction = new FinancialTransactionImpl(); - financialTransaction.setAmountDebit(BigDecimal.ZERO); - financialTransaction.setAmountCredit(BigDecimal.ZERO); - financialTransaction.setEntryBook(entryBook); - - FinancialPeriod financialPeriod = null; - - //Sets date for description - Calendar calendar = Calendar.getInstance(); - calendar.setTime(previousFiscalPeriod.getEndDate()); - - - found = false; - - //look for the first financial period on the current fiscal year with is unlocked - List<ClosedPeriodicEntryBook> resultsArray = - new ArrayList<ClosedPeriodicEntryBook>(); - List<ClosedPeriodicEntryBook> closedPeriodicEntryBook = - financialPeriodService.getAllClosedPeriodicEntryBooksFromUnblockedFiscalPeriod(); - Collections.sort(closedPeriodicEntryBook, new FinancialPeriodComparator()); - resultsArray.addAll(closedPeriodicEntryBook); - - for (ClosedPeriodicEntryBook cPeriodicEntryBook : resultsArray) { - if (!found && (cPeriodicEntryBook.getFinancialPeriod().getBeginDate().compareTo(date) <= 0) - && (cPeriodicEntryBook.getFinancialPeriod().getEndDate().compareTo(date) >= 1)) { - if (cPeriodicEntryBook.getFinancialPeriod().getLocked() || cPeriodicEntryBook.getLocked()) { - throw new LimaException("Can't set financialPeriod"); - } - if (cPeriodicEntryBook.getEntryBook().getCode().equals(entryBook.getCode()) - && cPeriodicEntryBook.getEntryBook().getLabel().equals(entryBook.getLabel())) { - found = true; - financialPeriod = cPeriodicEntryBook.getFinancialPeriod(); - } - } - } - if (!found) { - throw new LimaException("Can't set financialPeriod"); - } - financialTransaction.setFinancialPeriod(financialPeriod); - financialTransaction.setTransactionDate(date); - // create it - createFinancialTransactionWithTransaction(financialTransaction, topiaContext); - commitTransaction(topiaContext); - - //Sets entries - Entry entry = null; - - - - for (ReportsDatas report : reportsDatasList) { - //Account class from 1 to 7 - if (Integer.valueOf(report.getAccount().getAccountNumber().substring(0, 1)) < 8) { - if (report.getSoldeDebit()){ - if (!report.getAmountDebit().equals(BigDecimal.ZERO)) { - entry = new EntryImpl(); - entry.setDescription(_("lima-business.financialtransaction.retainedearnings.description") + " (" + calendar.get(Calendar.YEAR) + ")"); - entry.setVoucher(_("lima-business.financialtransaction.retainedearnings.voucher")); - entry.setFinancialTransaction(financialTransaction); - entry.setAccount(report.getAccount()); - entry.setAmount(report.getAmountDebit().abs()); - entry.setDebit(true); - topiaContext = beginTransaction(); - createEntryWithTransaction(entry, topiaContext); - commitTransaction(topiaContext); - } - } - if (!report.getSoldeDebit()){ - if (!report.getAmountCredit().equals(BigDecimal.ZERO)) { - entry = new EntryImpl(); - entry.setDescription(_("lima-business.financialtransaction.retainedearnings.description") + " (" + calendar.get(Calendar.YEAR) + ")"); - entry.setVoucher(_("lima-business.financialtransaction.retainedearnings.voucher")); - entry.setFinancialTransaction(financialTransaction); - entry.setAccount(report.getAccount()); - entry.setAmount(report.getAmountCredit().abs()); - entry.setDebit(false); - topiaContext = beginTransaction(); - createEntryWithTransaction(entry, topiaContext); - commitTransaction(topiaContext); - } - } - } - } - - //commit - commitTransaction(topiaContext); - } - catch (TopiaException ex) { - doCatch(topiaContext, ex, log); - } - finally { - doFinally(topiaContext, log); - } - } /** Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/FinancialTransactionService.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/FinancialTransactionService.java 2011-07-01 13:50:35 UTC (rev 3193) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/FinancialTransactionService.java 2011-07-01 13:58:36 UTC (rev 3194) @@ -91,18 +91,9 @@ void updateEntry(Entry entry) throws LimaException; - void removeEntry(Entry entry) throws LimaException; + void removeEntry(Entry entry) throws LimaException; /** - * Methods for report retained earnings - * @param previousFiscalPeriod, fiscalPeriod, entryBook - * @throws LimaException - */ - - void addRetainedEarnings(FiscalPeriod previousFiscalPeriod, FiscalPeriod fiscalPeriod, EntryBook entryBook, Date date) throws LimaException; - - - /** * Methods for create, update and remove the letter * @param entry * @throws LimaException Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/FinancialTransactionServiceLocal.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/FinancialTransactionServiceLocal.java 2011-07-01 13:50:35 UTC (rev 3193) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/FinancialTransactionServiceLocal.java 2011-07-01 13:58:36 UTC (rev 3194) @@ -30,6 +30,7 @@ import org.chorem.lima.entity.Entry; import org.chorem.lima.entity.FinancialTransaction; import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaException; /** * Transaction service. @@ -48,6 +49,8 @@ void updateFinancialTransactionWithTransaction(FinancialTransaction financialtransaction, TopiaContext topiaContext) throws LimaException; - Entry createEntryWithTransaction(Entry entry, TopiaContext topiaContext) throws LimaException; + Entry createEntryWithTransaction(Entry entry, TopiaContext topiaContext) throws LimaException, TopiaException; + + }