Author: mallon Date: 2012-07-06 12:17:38 +0200 (Fri, 06 Jul 2012) New Revision: 3496 Url: http://chorem.org/repositories/revision/lima/3496 Log: Correction et optimisation sur le filtrage par comptes, p?\195?\169riode et lettrage : cr?\195?\169ation et utilisation d'une nouvelle requ?\195?\170te de s?\195?\169lection. fixes #683 Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialTransactionService.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/EntryDAOImpl.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialTransactionDAOImpl.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/common/AccountComboBoxModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringViewHandler.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java 2012-07-06 07:57:01 UTC (rev 3495) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java 2012-07-06 10:17:38 UTC (rev 3496) @@ -25,25 +25,21 @@ package org.chorem.lima.business.ejb; -import static org.nuiton.i18n.I18n._; - -import java.awt.Color; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.InputStream; -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.List; - -import javax.ejb.EJB; -import javax.ejb.Remote; -import javax.ejb.Stateless; -import javax.ejb.TransactionAttribute; - +import com.lowagie.text.BadElementException; +import com.lowagie.text.Cell; +import com.lowagie.text.Chapter; +import com.lowagie.text.DocWriter; +import com.lowagie.text.Document; +import com.lowagie.text.DocumentException; +import com.lowagie.text.Element; +import com.lowagie.text.Font; +import com.lowagie.text.PageSize; +import com.lowagie.text.Paragraph; +import com.lowagie.text.Phrase; +import com.lowagie.text.Rectangle; +import com.lowagie.text.Table; +import com.lowagie.text.html.HtmlWriter; +import com.lowagie.text.pdf.PdfWriter; import org.apache.pdfbox.examples.fdf.SetField; import org.apache.pdfbox.pdmodel.PDDocument; import org.chorem.lima.beans.BalanceTrial; @@ -72,22 +68,24 @@ import org.chorem.lima.entity.Identity; import org.chorem.lima.entity.VatStatement; -import com.lowagie.text.BadElementException; -import com.lowagie.text.Cell; -import com.lowagie.text.Chapter; -import com.lowagie.text.DocWriter; -import com.lowagie.text.Document; -import com.lowagie.text.DocumentException; -import com.lowagie.text.Element; -import com.lowagie.text.Font; -import com.lowagie.text.PageSize; -import com.lowagie.text.Paragraph; -import com.lowagie.text.Phrase; -import com.lowagie.text.Rectangle; -import com.lowagie.text.Table; -import com.lowagie.text.html.HtmlWriter; -import com.lowagie.text.pdf.PdfWriter; +import javax.ejb.EJB; +import javax.ejb.Remote; +import javax.ejb.Stateless; +import javax.ejb.TransactionAttribute; +import java.awt.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.List; +import static org.nuiton.i18n.I18n._; + @Stateless @Remote(DocumentService.class) @TransactionAttribute @@ -750,7 +748,7 @@ // TODO echatellier 20120509, was not about only // balanced transaction here, normal ? - List<Entry> entries = entryDAO.findAllEntryOfTransaction(closedPeriodicEntryBook.getEntryBook(), + List<Entry> entries = entryDAO.findAllEntryByDateForEntryBook(closedPeriodicEntryBook.getEntryBook(), closedPeriodicEntryBook.getFinancialPeriod().getBeginDate(), closedPeriodicEntryBook.getFinancialPeriod().getEndDate()); 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 2012-07-06 07:57:01 UTC (rev 3495) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java 2012-07-06 10:17:38 UTC (rev 3496) @@ -260,6 +260,41 @@ } /** + * Get all entries by dates, account and lettering + * @param beginDate begin date + * @param endDate end date + * @param account acount + * @param filtreLettre lettering + * */ + @Override + public List<Entry> getAllEntrieByDatesAndAccountAndLettering(Date beginDate, Date endDate, Account account, String filtreLettre) throws LimaException { + List<FinancialTransaction> financialTransactions = null; + List<Entry> entries = new ArrayList<Entry>(); + + try{ + FinancialTransactionDAO transactionDAO = getDaoHelper().getFinancialTransactionDAO(); + financialTransactions = transactionDAO.findAllByDates(beginDate, endDate); + }catch (Exception ex){ + throw new LimaException("Can't get financial transactions", ex); + } + + try { + EntryDAO entryDAO = getDaoHelper().getEntryDAO(); + for (FinancialTransaction financialTransaction : financialTransactions){ + entries.addAll(entryDAO.findAllEntryByAccountAndLettering(financialTransaction, account, filtreLettre)); + } + } catch (Exception ex) { + throw new LimaException("Can't get entries", ex); + } + + if (log.isInfoEnabled()) { + log.info("Entries size : " + entries.size()); + } + + return entries; + } + + /** * Method used by update entry and remove entry for update amounts. */ @Override Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialTransactionService.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialTransactionService.java 2012-07-06 07:57:01 UTC (rev 3495) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialTransactionService.java 2012-07-06 10:17:38 UTC (rev 3496) @@ -25,17 +25,18 @@ package org.chorem.lima.business.api; -import java.util.Date; -import java.util.List; - import org.chorem.lima.beans.FinancialTransactionSearch; 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.FinancialPeriod; import org.chorem.lima.entity.FinancialTransaction; import org.chorem.lima.entity.FiscalPeriod; +import java.util.Date; +import java.util.List; + /** * Transaction service. * @@ -76,4 +77,6 @@ void removeEntry(Entry entry) throws LimaException; String getNewLetters() throws LimaException; + + List<Entry> getAllEntrieByDatesAndAccountAndLettering(Date beginDate, Date endDate, Account account, String filtreLettre) throws LimaException; } Modified: trunk/lima-callao/src/main/java/org/chorem/lima/entity/EntryDAOImpl.java =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/EntryDAOImpl.java 2012-07-06 07:57:01 UTC (rev 3495) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/EntryDAOImpl.java 2012-07-06 10:17:38 UTC (rev 3496) @@ -161,8 +161,8 @@ * @param endDate end date * @throws TopiaException */ - public List<Entry> findAllEntryOfTransaction(EntryBook entryBook, Date beginDate, - Date endDate) throws TopiaException { + public List<Entry> findAllEntryByDateForEntryBook(EntryBook entryBook, Date beginDate, + Date endDate) throws TopiaException { String query = "FROM " + Entry.class.getName() + " E" + // entre les 2 dates " WHERE :beginDate <= E.financialTransaction.transactionDate" + @@ -176,6 +176,31 @@ } /** + * Retourne toutes les entrées d'une transaction + * pour un compte et un lettrage + * + * @param financialTransaction transaction sur laquelle les entrées sont filtrées + * @param account compte sur lequel les entrées sont filtrées + * @param filtreLettre toutes (all), non-lettrées ("null") ou lettrées ("notNull") + * @throws TopiaException + * */ + public List<Entry> findAllEntryByAccountAndLettering(FinancialTransaction financialTransaction, Account account, String filtreLettre) throws TopiaException { + List<Entry> entries = null; + + String query = "from " + Entry.class.getName() + " E " + + " where E.financialTransaction = :financialTransaction" + + " and E.account = :account "; + if (filtreLettre.equals("null")){ + query += " and E.lettering is null"; + }else if (filtreLettre.equals("notNull")){ + query += " and E.lettering is not null"; + } + + entries = context.findAll(query, "financialTransaction", financialTransaction, "account", account); + return entries; + } + + /** * Retourne la somme des entrées des transaction entre * deux dates pour un journal donné. * Modified: trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialTransactionDAOImpl.java =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialTransactionDAOImpl.java 2012-07-06 07:57:01 UTC (rev 3495) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialTransactionDAOImpl.java 2012-07-06 10:17:38 UTC (rev 3496) @@ -25,17 +25,17 @@ package org.chorem.lima.entity; -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - import org.apache.commons.collections.CollectionUtils; import org.chorem.lima.FinancialStatementWayEnum; import org.chorem.lima.beans.FinancialTransactionSearch; import org.hibernate.HibernateException; import org.nuiton.topia.TopiaException; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + /** * Ajout de requetes specifiques aux financial transaction sur le DAO. * @@ -261,7 +261,7 @@ return result; } - + /** * Search financial transaction. * Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/common/AccountComboBoxModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/common/AccountComboBoxModel.java 2012-07-06 07:57:01 UTC (rev 3495) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/common/AccountComboBoxModel.java 2012-07-06 10:17:38 UTC (rev 3496) @@ -40,7 +40,7 @@ /*By default, selection of the account 4*/ @Override - public Object getElementAt(int index) { + public Account getElementAt(int index) { if (getSelectedItem() == null){ int indexAccountFour = 0; for (Account compte : objects){ Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringView.jaxx 2012-07-06 07:57:01 UTC (rev 3495) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringView.jaxx 2012-07-06 10:17:38 UTC (rev 3496) @@ -28,8 +28,7 @@ <import> org.chorem.lima.ui.common.AccountComboBoxModel org.chorem.lima.ui.common.FinancialPeriodComboBoxModel - org.chorem.lima.entity.FiscalPeriod - org.chorem.lima.entity.FinancialPeriod + org.chorem.lima.entity.Account javax.swing.ListSelectionModel org.jdesktop.swingx.JXDatePicker; </import> @@ -65,7 +64,7 @@ <org.chorem.lima.ui.common.AccountComboBoxModel id="accountComboBoxModel"/> <JComboBox id="accountComboBox" model="{accountComboBoxModel}" renderer="{new org.chorem.lima.ui.common.AccountListRenderer()}" - onActionPerformed="handler.updateAllEntries(pickerDebut.getDate(), pickerFin.getDate(), accountComboBox.getSelectedItem(), letteredCheckGroup.getSelectedButton().getName())"/> + onActionPerformed="handler.updateAllEntries(pickerDebut.getDate(), pickerFin.getDate(), (Account)accountComboBox.getSelectedItem(), (String)letteredCheckGroup.getSelectedValue())"/> <JButton id="backCount" text="lima.ui.account.buttonback" onActionPerformed="handler.back(accountComboBox)"/> <JButton id="nextCount" text="lima.ui.account.buttonnext" @@ -81,7 +80,7 @@ </cell> <cell> <JXDatePicker id="pickerDebut" - onActionPerformed="handler.updateAllEntries(pickerDebut.getDate(), pickerFin.getDate(), accountComboBox.getSelectedItem(), letteredCheckGroup.getSelectedButton().getName())"/> + onActionPerformed="handler.updateAllEntries(pickerDebut.getDate(), pickerFin.getDate(), (Account)accountComboBox.getSelectedItem(), (String)letteredCheckGroup.getSelectedValue())"/> </cell> </row> <row> @@ -90,7 +89,7 @@ </cell> <cell> <JXDatePicker id="pickerFin" - onActionPerformed="handler.updateAllEntries(pickerDebut.getDate(), pickerFin.getDate(), accountComboBox.getSelectedItem(), letteredCheckGroup.getSelectedButton().getName())"/> + onActionPerformed="handler.updateAllEntries(pickerDebut.getDate(), pickerFin.getDate(), (Account)accountComboBox.getSelectedItem(), (String)letteredCheckGroup.getSelectedValue())"/> </cell> </row> </Table> @@ -101,8 +100,8 @@ <Table> <row> <cell> - <JRadioButton id="lettredEntryCheckBox" buttonGroup="letteredCheckGroup" - onActionPerformed="handler.updateAllEntries(pickerDebut.getDate(), pickerFin.getDate(), accountComboBox.getSelectedItem(), letteredCheckGroup.getSelectedButton().getName())"/> + <JRadioButton id="lettredEntryCheckBox" buttonGroup="letteredCheckGroup" value="notNull" + onActionPerformed="handler.updateAllEntries(pickerDebut.getDate(), pickerFin.getDate(), (Account)accountComboBox.getSelectedItem(), (String)letteredCheckGroup.getSelectedValue())"/> </cell> <cell> <JLabel text="lima.ui.lettering.checkLettredEntry"/> @@ -110,8 +109,8 @@ </row> <row> <cell> - <JRadioButton id="noLettredEntryCheckBox" selected="true" buttonGroup="letteredCheckGroup" - onActionPerformed="handler.updateAllEntries(pickerDebut.getDate(), pickerFin.getDate(), accountComboBox.getSelectedItem(), letteredCheckGroup.getSelectedButton().getName())"/> + <JRadioButton id="noLettredEntryCheckBox" selected="true" buttonGroup="letteredCheckGroup" value="null" + onActionPerformed="handler.updateAllEntries(pickerDebut.getDate(), pickerFin.getDate(), (Account)accountComboBox.getSelectedItem(), (String)letteredCheckGroup.getSelectedValue())"/> </cell> <cell> <JLabel text="lima.ui.lettering.checkNoLettredEntry"/> @@ -119,8 +118,8 @@ </row> <row> <cell> - <JRadioButton id="allCheckBox" buttonGroup="letteredCheckGroup" - onActionPerformed="handler.updateAllEntries(pickerDebut.getDate(), pickerFin.getDate(), accountComboBox.getSelectedItem(), letteredCheckGroup.getSelectedButton().getName())"/> + <JRadioButton id="allCheckBox" buttonGroup="letteredCheckGroup" value="all" + onActionPerformed="handler.updateAllEntries(pickerDebut.getDate(), pickerFin.getDate(), (Account)accountComboBox.getSelectedItem(), (String)letteredCheckGroup.getSelectedValue())"/> </cell> <cell> <JLabel text="lima.ui.lettering.checkAll"/> Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringViewHandler.java 2012-07-06 07:57:01 UTC (rev 3495) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringViewHandler.java 2012-07-06 10:17:38 UTC (rev 3496) @@ -36,7 +36,6 @@ import org.chorem.lima.business.api.FiscalPeriodService; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.Entry; -import org.chorem.lima.entity.FinancialTransaction; import org.chorem.lima.entity.FiscalPeriod; import org.chorem.lima.service.LimaServiceFactory; @@ -132,40 +131,25 @@ log.debug("Val select letter : " + view.getLetteredCheckGroup().getSelectedButton().getName()); //Load entry with the default dates, default account 4 and with no letter - updateAllEntries(defaultDateBegFiscalPeriod, defaultDateEndCurrent, view.getAccountComboBoxModel().getSelectedItem(), view.getLetteredCheckGroup().getSelectedButton().getName()); + updateAllEntries(defaultDateBegFiscalPeriod, defaultDateEndCurrent, (Account)view.getAccountComboBoxModel().getSelectedItem(), (String)view.getLetteredCheckGroup().getSelectedValue()); if (log.isInfoEnabled()) { log.info("Nb entries model (After update all entries) : " + view.getTableModel().getNumberOfEntries()); } } - protected List<Entry> findAllEntries(Date selectedBeginDate, Date selectedEndDate, Object compte, String filtreLettre){ - - List<Entry> entries = new ArrayList<Entry>(); - List<Entry> entriesAccount = new ArrayList<Entry>(); + protected List<Entry> findAllEntries(Date selectedBeginDate, Date selectedEndDate, Account compte, String filtreLettre){ if (selectedBeginDate != null && selectedEndDate != null) { - List<FinancialTransaction> financialtransactions = - financialTransactionService.getAllFinancialTransactions(selectedBeginDate, selectedEndDate); - for (FinancialTransaction financialtransaction : financialtransactions) { - entries = (List<Entry>) financialtransaction.getEntry(); + if (log.isInfoEnabled()) { + log.info("FiltreLettre : " + filtreLettre); } - if (compte != null){ - for(Entry entry : entries){ - log.debug("entry.getLettering() : " + entry.getLettering()); - log.debug("name radioButton : " + filtreLettre); - //0 for lettered, 1 for no-lettered and 2 for all entries - if (compte.equals(entry.getAccount()) && ( (filtreLettre.equals("noLettredEntryCheckBox") & entry.getLettering() == null)) - || (filtreLettre.equals("lettredEntryCheckBox") & entry.getLettering() != null) || filtreLettre.equals("allCheckBox")){ - entriesAccount.add(entry); - } - } - log.debug("entriesAccount size : " + entriesAccount.size()); - return entriesAccount; - } + List<Entry> entries = + financialTransactionService.getAllEntrieByDatesAndAccountAndLettering(selectedBeginDate, selectedEndDate, compte, filtreLettre); + return entries; } - return entries; + return null; } - public void updateAllEntries(Date selectedBeginDate, Date selectedEndDate, Object compte, String filtreLettre) { + public void updateAllEntries(Date selectedBeginDate, Date selectedEndDate, Account compte, String filtreLettre) { if (selectedBeginDate != null && selectedEndDate != null){ log.debug("updateAllEntries");