r3210 - in trunk: lima-business/src/main/java/org/chorem/lima/business/ejb lima-swing/src/main/java/org/chorem/lima/ui
Author: vsalaun Date: 2011-07-11 16:24:55 +0200 (Mon, 11 Jul 2011) New Revision: 3210 Url: http://chorem.org/repositories/revision/lima/3210 Log: block vat access for release Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/VatStatementServiceImpl.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainView.jaxx Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/VatStatementServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/VatStatementServiceImpl.java 2011-07-11 13:36:42 UTC (rev 3209) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/VatStatementServiceImpl.java 2011-07-11 14:24:55 UTC (rev 3210) @@ -1,15 +1,53 @@ +/* + * #%L + * Lima :: business + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2008 - 2011 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 3 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, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ package org.chorem.lima.business.ejb; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Date; import java.util.List; +import java.util.StringTokenizer; +import javax.ejb.EJB; import javax.ejb.Stateless; +import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.lima.beans.Amounts; +import org.chorem.lima.beans.AmountsImpl; +import org.chorem.lima.beans.ReportsDatas; import org.chorem.lima.business.LimaConfig; import org.chorem.lima.business.LimaException; +import org.chorem.lima.business.ejbinterface.ReportServiceLocal; import org.chorem.lima.business.ejbinterface.VatStatementService; import org.chorem.lima.business.ejbinterface.VatStatementServiceLocal; +import org.chorem.lima.entity.Account; +import org.chorem.lima.entity.AccountDAO; +import org.chorem.lima.entity.FinancialStatement; +import org.chorem.lima.entity.FinancialStatementDAO; import org.chorem.lima.entity.LimaCallaoDAOHelper; import org.chorem.lima.entity.VatStatement; import org.chorem.lima.entity.VatStatementDAO; @@ -18,6 +56,7 @@ import org.nuiton.topia.TopiaException; import org.nuiton.topia.TopiaNotFoundException; import org.nuiton.topia.framework.TopiaQuery; +import org.nuiton.topia.framework.TopiaQuery.Op; /** * Permet d'implémenter le plan de la déclaration de TVA @@ -32,6 +71,9 @@ LogFactory.getLog(VatStatementServiceImpl.class); private TopiaContext rootContext; + + @EJB + private ReportServiceLocal reportServiceLocal; public VatStatementServiceImpl() { LimaConfig config = LimaConfig.getInstance(); @@ -177,7 +219,123 @@ doFinally(transaction, log); } } + + public Amounts amountFromAccountList(String accountsNumberList, Date selectedBeginDate, Date selectedEndDate, TopiaContext topiaContext) throws LimaException{ + Amounts amounts = new AmountsImpl(); + BigDecimal debit = new BigDecimal(0); + BigDecimal credit = new BigDecimal(0); + Boolean substract = false; + try { + AccountDAO accountDAO = LimaCallaoDAOHelper.getAccountDAO(topiaContext); + //Remove Spaces + String result = StringUtils.deleteWhitespace(accountsNumberList); + StringTokenizer stQuote = new StringTokenizer(result, ","); + while (stQuote.hasMoreTokens()) { + String s = stQuote.nextToken(); + List<Account> accountsList = accountDAO.stringToListAccounts(s, false); + BigDecimal debitTemp = new BigDecimal(0); + BigDecimal creditTemp = new BigDecimal(0); + for (Account account : accountsList) { + ReportsDatas reportsDatas = reportServiceLocal. + generateAccountReportsWithTransaction(account, true, + selectedBeginDate, selectedEndDate, topiaContext); + if (reportsDatas.getSoldeDebit()){ + debitTemp = debitTemp.add(reportsDatas.getAmountSolde()); + } + else { + creditTemp = creditTemp.add(reportsDatas.getAmountSolde()); + } + } + if (!substract){ + debit = debitTemp; + credit = creditTemp; + } + //compte(s) précédé du signe - + else { + debit = debit.subtract(debitTemp); + credit = credit.subtract(creditTemp); + } + substract = true; + } + amounts.setCredit(credit); + amounts.setDebit(debit); + } catch (TopiaException e) { + doCatch(topiaContext, e, log); + } + return amounts; + } + + /** + * Gives the list of account numbers from a VatStatement + * @param vatStatement + * @return accountNumbersList + * @throws LimaException + */ + public String findAccountNumberByVatStatement(VatStatement vatStatement, TopiaContext topiaContext) throws LimaException { + + String accountNumbersList = null; + + try { + VatStatementDAO vatStatementDAO = + LimaCallaoDAOHelper.getVatStatementDAO(topiaContext); + TopiaQuery query = vatStatementDAO.createQuery(); + + String labelProperty = + TopiaQuery.getProperty(VatStatement.LABEL); + + query.addWhere(labelProperty + " " + Op.LIKE + " '%" + + vatStatement.getLabel() + "%'"); + //query.addWhere(label, operator, paramValue) + query.setMaxResults(1); + log.debug("query to find account by VAT " + query); + + List<VatStatement> vatStatementsList = vatStatementDAO.findAllByQuery(query); + + if (vatStatementsList.size() > 0) { + accountNumbersList = vatStatementsList.get(0).getAccounts(); + } + } + catch (TopiaException e) { + doCatch(topiaContext, e, log); + } + return accountNumbersList; + } + + @Override + public BigDecimal vatStatementAmounts(VatStatement vatStatement, Date selectedBeginDate, Date selectedEndDate) throws LimaException, TopiaException { + + BigDecimal debitTemp = new BigDecimal(0); + BigDecimal creditTemp = new BigDecimal(0); + + TopiaContext transaction = null; + try { + transaction = beginTransaction(); + + String accountNumbersList = findAccountNumberByVatStatement(vatStatement, transaction); + + AccountDAO accountDAO = LimaCallaoDAOHelper.getAccountDAO(transaction); + List<Account> accountsList = accountDAO.stringToListAccounts(accountNumbersList, false); + + for (Account account : accountsList) { + ReportsDatas reportsDatas = reportServiceLocal. + generateAccountReportsWithTransaction(account, true, + selectedBeginDate, selectedEndDate, transaction); + if (reportsDatas.getSoldeDebit()){ + debitTemp = debitTemp.add(reportsDatas.getAmountSolde()); + } + else { + creditTemp = creditTemp.add(reportsDatas.getAmountSolde()); + } + } + } + catch (TopiaException e) { + doCatch(transaction, e, log); + } + + return debitTemp.subtract(creditTemp).abs(); + } + protected TopiaContext beginTransaction() throws TopiaException { // basic check done, make check in database Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainView.jaxx 2011-07-11 13:36:42 UTC (rev 3209) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainView.jaxx 2011-07-11 14:24:55 UTC (rev 3210) @@ -168,8 +168,6 @@ actionIcon='charts-financialperiod'/> <JMenuItem text="lima.charts.financialstatement" onActionPerformed='getHandler().showFinancialStatementView(this)' actionIcon='charts-financialstatements'/> - <JMenuItem text="lima.charts.vat" onActionPerformed='getHandler().showVatChartView(this)' - actionIcon='charts-financialstatements'/> </JMenu> <JMenu text="lima.entries" mnemonic="{'E'}"> @@ -193,8 +191,6 @@ actionIcon='reports-ledger'/> <JMenuItem text="lima.reports.financialstatement" onActionPerformed='getHandler().showFinancialStatementReportsView(this)' actionIcon='reports-financialstatement'/> - <JMenuItem text="lima.reports.vat" onActionPerformed='getHandler().showVatReportView(this)' - actionIcon='reports-financialstatement'/> </JMenu>
participants (1)
-
vsalaun@users.chorem.org