Author: jpepin Date: 2010-06-08 19:35:17 +0200 (Tue, 08 Jun 2010) New Revision: 2938 Url: http://chorem.org/repositories/revision/lima/2938 Log: Fonction de filtre dans la balance pour s?\195?\169lectionner qu'une ?\195?\169tendue de comptes (exemple : '10,21,34-38,47,53-58') Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ReportService.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-swing/src/main/java/org/chorem/lima/ui/balance/BalanceTableModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceViewHandler.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/ReportService.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ReportService.java 2010-06-08 10:14:54 UTC (rev 2937) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ReportService.java 2010-06-08 17:35:17 UTC (rev 2938) @@ -62,7 +62,7 @@ * @return la balance * @throws LimaException */ - BalanceTrial generateBalanceTrial(Date beginDate, Date endDate, Boolean getEntries) throws LimaException; + BalanceTrial generateBalanceTrial(Date beginDate, Date endDate, String selectedAccounts, Boolean getEntries) throws LimaException; /** * Generation du grand-livre 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-08 10:14:54 UTC (rev 2937) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java 2010-06-08 17:35:17 UTC (rev 2938) @@ -23,8 +23,13 @@ import java.util.Collection; import java.util.Collections; import java.util.Date; +import java.util.HashSet; import java.util.List; +import java.util.StringTokenizer; + 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.BalanceTrial; @@ -396,12 +401,14 @@ * * Calculate the amounts and the solde for all subaccounts * + * Can have string selectedAccounts in params for account filter + * * Boolean Param GetEntries is for get entries in datasreports or not : * - GetEntries = false for generate balance * - GetEntries = true for generate ledger */ @Override - public BalanceTrial generateBalanceTrial(Date beginDate, Date endDate, Boolean getEntries) throws LimaException { + public BalanceTrial generateBalanceTrial(Date beginDate, Date endDate, String selectedAccounts, Boolean getEntries) throws LimaException { BalanceTrial balanceTrial = new BalanceTrialImpl(); balanceTrial.setReportsDatas(new ArrayList<ReportsDatas>()); double credit = 0, debit = 0, solde = 0; @@ -413,7 +420,49 @@ AccountDAO accountDAO = LimaCallaoDAOHelper.getAccountDAO(topiaTransaction); //for each account create a balance sheet with a ReportsDatas - List<Account> accounts = accountDAO.findAllSubAccounts(); + + List<Account> accounts =null; + + //Remove Spaces + selectedAccounts = StringUtils.deleteWhitespace(selectedAccounts); + log.debug(selectedAccounts); + //if no filter account + if (selectedAccounts == null || selectedAccounts.equals("")){ + accounts = accountDAO.findAllSubAccounts(); + } + //build list account from selectedAccounts + else{ + accounts = new ArrayList<Account>(); + List<String> accountNumbers = new ArrayList<String>(); + //Split comma + StringTokenizer stComma = new StringTokenizer(selectedAccounts, ","); + while (stComma.hasMoreTokens()) { + String s = stComma.nextToken(); + if (s.contains("-")){ + //Split hypen + String stringHypen[] = s.split("-"); + int lowAccount=Integer.parseInt(stringHypen[0]); + int highAccount=Integer.parseInt(stringHypen[1]); + for (int i=lowAccount; i <= highAccount; i++) { + accountNumbers.add(String.valueOf(i)); + } + } + else{ + accountNumbers.add(s); + } + } + // remove duplicate numbers + HashSet<String> hashSet = new HashSet<String>(accountNumbers); + accountNumbers = new ArrayList<String>(hashSet); + + for (String accountNumber : accountNumbers) { + Account accountFilter = accountDAO.findByAccountNumber(accountNumber); + if (accountFilter != null){ + accounts.add(accountFilter); + } + } + log.debug(accounts); + } for (Account account : accounts) { ReportsDatas reportsDatas = generateSubAccountBalanceWithTransaction(account, beginDate, @@ -457,7 +506,7 @@ */ @Override public BalanceTrial generateLedger(Date beginDate, Date endDate) throws LimaException { - return generateBalanceTrial(beginDate, endDate, true); + return generateBalanceTrial(beginDate, endDate, null, true); } 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-08 10:14:54 UTC (rev 2937) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookDAOImpl.java 2010-06-08 17:35:17 UTC (rev 2938) @@ -25,7 +25,6 @@ query.addEquals(ClosedPeriodicEntryBook.FINANCIAL_PERIOD, financialPeriod); } return findByQuery(query); - } } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceTableModel.java 2010-06-08 10:14:54 UTC (rev 2937) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceTableModel.java 2010-06-08 17:35:17 UTC (rev 2938) @@ -29,6 +29,7 @@ import org.chorem.lima.beans.ReportsDatas; import org.chorem.lima.business.LimaException; import org.chorem.lima.business.ReportService; +import org.chorem.lima.entity.Account; import org.chorem.lima.service.LimaServiceFactory; import org.chorem.lima.util.ErrorHelper; @@ -53,12 +54,15 @@ /** Services. */ protected ReportService reportService; - /** Begin Date. */ + /** DatePicker Begin Date. */ protected Date selectedBeginDate; - /** EndDate. */ + /** DatePicker EndDate. */ protected Date selectedEndDate; + /** Text field Accounts */ + protected String selectedAccounts; + /** data cache */ protected BalanceTrial cacheDataList; @@ -168,6 +172,10 @@ selectedEndDate = date; } + public void setAccountFilter(String accounts) { + selectedAccounts = accounts; + } + /** * get all account fot the selected period * @return @@ -176,7 +184,7 @@ BalanceTrial results = null; try { - results = reportService.generateBalanceTrial(selectedBeginDate, selectedEndDate, false); + results = reportService.generateBalanceTrial(selectedBeginDate, selectedEndDate, selectedAccounts, false); } catch (LimaException eee) { if (log.isErrorEnabled()) { Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceView.jaxx 2010-06-08 10:14:54 UTC (rev 2937) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceView.jaxx 2010-06-08 17:35:17 UTC (rev 2938) @@ -68,9 +68,17 @@ onActionPerformed="getModelBalanceTable().setEndDate(endDatePicker.getDate()); getHandler().refresh()"/> </cell> + <cell anchor="east"> + <JTextField id="accountFilter"/> + </cell> + <cell anchor="west"> + <JButton text="lima.accountsreports.accountfilter" + onActionPerformed="getModelBalanceTable().setAccountFilter(accountFilter.getText()); + getHandler().refresh()"/> + </cell> </row> <row> - <cell fill="both" weightx="1" weighty="1" columns="6"> + <cell fill="both" weightx="1" weighty="1" columns="7"> <JScrollPane> <org.jdesktop.swingx.JXTable id="balanceTable" rowHeight="24" model="{getModelBalanceTable()}" Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceViewHandler.java 2010-06-08 10:14:54 UTC (rev 2937) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceViewHandler.java 2010-06-08 17:35:17 UTC (rev 2938) @@ -52,7 +52,6 @@ this.view = view; financialTransactionService = LimaServiceFactory.getInstance().getTransactionService(); - } public void refresh(){ 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-06-08 10:14:54 UTC (rev 2937) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing-en_GB.properties 2010-06-08 17:35:17 UTC (rev 2938) @@ -22,6 +22,7 @@ lima.account.type4= lima.accountplan=Plan de comptes lima.accounts=Accounts +lima.accountsreports.accountfilter=Filter lima.accountsreports.begincalendar= lima.accountsreports.endcalendar= lima.actif=Asset 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-06-08 10:14:54 UTC (rev 2937) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing-fr_FR.properties 2010-06-08 17:35:17 UTC (rev 2938) @@ -23,6 +23,7 @@ lima.account.type3=Produit lima.account.type4=Charge lima.accounts=Comptes +lima.accountsreports.accountfilter=Filtrer lima.accountsreports.begincalendar=Date d\u00E9but lima.accountsreports.endcalendar=Date fin lima.actif=Actif