This is an automated email from the git hooks/post-receive script. New commit to branch feature/1293-addAccountViewerTab in repository lima. See http://git.chorem.org/lima.git commit 47945fb651bed6182b8576b64e247ea07e829f75 Author: dcosse <cosse@codelutin.com> Date: Mon Sep 14 18:30:15 2015 +0200 refs #1241 Ajout d'un oglet consultation de compte, travail en cours --- .../business/api/FinancialTransactionService.java | 16 + .../lima/business/api/FiscalPeriodService.java | 8 + .../ejb/FinancialTransactionServiceImpl.java | 14 + .../lima/business/ejb/FiscalPeriodServiceImpl.java | 10 + .../java/org/chorem/lima/entity/EntryTopiaDao.java | 42 ++ .../chorem/lima/entity/FiscalPeriodTopiaDao.java | 20 + .../src/main/java/org/chorem/lima/ui/MainView.css | 5 + .../src/main/java/org/chorem/lima/ui/MainView.jaxx | 2 + .../java/org/chorem/lima/ui/MainViewHandler.java | 8 + .../AccountViewerEditModel.java} | 84 ++-- .../accountViewer/AccountViewerSelectionModel.java | 158 +++++++ .../lima/ui/accountViewer/AccountViewerTable.java | 42 ++ .../ui/accountViewer/AccountViewerTableModel.java | 144 ++++++ .../lima/ui/accountViewer/AccountViewerView.css | 73 +++ .../lima/ui/accountViewer/AccountViewerView.jaxx | 94 ++++ .../AccountViewerViewHandler.java} | 498 ++++++++++----------- .../lima/ui/lettering/LetteringEditModel.java | 13 +- .../lima/ui/lettering/LetteringViewHandler.java | 65 +-- .../resources/i18n/lima-swing_en_GB.properties | 3 + .../resources/i18n/lima-swing_fr_FR.properties | 3 + 20 files changed, 977 insertions(+), 325 deletions(-) diff --git a/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialTransactionService.java b/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialTransactionService.java index d268005..d34f445 100644 --- a/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialTransactionService.java +++ b/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialTransactionService.java @@ -126,6 +126,22 @@ public interface FinancialTransactionService { List<Entry> getAllEntrieByDatesAndAccountAndLettering(LetteringFilter filter); /** + * Retourne la somme des débits credits des entrées associées à une action pour une prériode définie + * La période est défine entre DateStart inclus et DateEnd exclus + * @param filter sur le filter doit être définie la période et le compte cible. + * @return + */ + List<Object[]> getAccountEntriesDebitCreditFromIncludingToExcludingPeriod(LetteringFilter filter); + + /** + * Retourne la somme des débits credits des entrées associées à une action pour une prériode définie + * La période est défine entre DateStart inclus et DateEnd inclus + * @param filter sur le filter doit être définie la période et le compte cible. + * @return + */ + List<Object[]> getAccountEntriesDebitCreditFromIncludingToIncludingPeriod(LetteringFilter filter); + + /** * Retourne la dernière entrée d'une transaction * @param financialTransaction transaction sur laquelle la derniere entree est selectionnee * */ diff --git a/lima-business-api/src/main/java/org/chorem/lima/business/api/FiscalPeriodService.java b/lima-business-api/src/main/java/org/chorem/lima/business/api/FiscalPeriodService.java index 2ce8af4..4e0c812 100644 --- a/lima-business-api/src/main/java/org/chorem/lima/business/api/FiscalPeriodService.java +++ b/lima-business-api/src/main/java/org/chorem/lima/business/api/FiscalPeriodService.java @@ -44,6 +44,7 @@ import org.chorem.lima.business.exceptions.WithoutEntryBookFinancialTransactions import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.FiscalPeriod; +import java.util.Date; import java.util.List; /** @@ -141,4 +142,11 @@ public interface FiscalPeriodService { */ FiscalPeriod updateEndDate(FiscalPeriod fiscalPeriod); + /** + * Return the FiscalPeriod for the given date + * + * @param date fiscal period for this given date + * @return the FiscalPeriod for {@code date} + */ + FiscalPeriod getFiscalPeriodForDate(Date date); } diff --git a/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java b/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java index 274781a..13cba58 100644 --- a/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java +++ b/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java @@ -474,6 +474,20 @@ public class FinancialTransactionServiceImpl extends AbstractLimaService impleme } @Override + public List<Object[]> getAccountEntriesDebitCreditFromIncludingToExcludingPeriod(LetteringFilter filter) { + EntryTopiaDao entryTopiaDao = getDaoHelper().getEntryDao(); + List<Object[]> result = entryTopiaDao.getAccountEntriesDebitCreditFromIncludingToExcludingPeriod(filter); + return result; + } + + @Override + public List<Object[]> getAccountEntriesDebitCreditFromIncludingToIncludingPeriod(LetteringFilter filter) { + EntryTopiaDao entryTopiaDao = getDaoHelper().getEntryDao(); + List<Object[]> result = entryTopiaDao.getAccountEntriesDebitCreditFromIncludingToIncludingPeriod(filter); + return result; + } + + @Override public Entry getLastEntry(FinancialTransaction financialTransaction) { EntryTopiaDao entryTopiaDao = getDaoHelper().getEntryDao(); diff --git a/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java b/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java index 64b2346..40504d6 100644 --- a/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java +++ b/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java @@ -524,4 +524,14 @@ public class FiscalPeriodServiceImpl extends AbstractLimaService implements Fisc fiscalPeriodTopiaDao.delete(localFiscalPeriod); } + + @Override + public FiscalPeriod getFiscalPeriodForDate(Date date) { + + FiscalPeriodTopiaDao fiscalPeriodTopiaDao = getDaoHelper().getFiscalPeriodDao(); + //get the last fiscal period + FiscalPeriod result = fiscalPeriodTopiaDao.findForDate(date); + + return result; + } } diff --git a/lima-business/src/main/java/org/chorem/lima/entity/EntryTopiaDao.java b/lima-business/src/main/java/org/chorem/lima/entity/EntryTopiaDao.java index 4c44ba6..254a2d1 100644 --- a/lima-business/src/main/java/org/chorem/lima/entity/EntryTopiaDao.java +++ b/lima-business/src/main/java/org/chorem/lima/entity/EntryTopiaDao.java @@ -28,6 +28,7 @@ import org.apache.commons.logging.LogFactory; import org.chorem.lima.beans.LetteringFilter; import org.nuiton.topia.persistence.HqlAndParametersBuilder; +import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -272,6 +273,47 @@ public class EntryTopiaDao extends AbstractEntryTopiaDao<Entry> { return result; } + public List<Object[]> getAccountEntriesDebitCreditFromIncludingToExcludingPeriod(LetteringFilter filter) { + List<Object[]> result; + if (filter != null) { + result = getAccountEntriesDebitCreditFromIncludingToExcludingPeriod(filter.getAccount(), filter.getDateStart(), filter.getDateEnd(), false); + } else { + result = new ArrayList<>(); + } + return result; + } + + public List<Object[]> getAccountEntriesDebitCreditFromIncludingToIncludingPeriod(LetteringFilter filter) { + List<Object[]> result; + if (filter != null) { + result = getAccountEntriesDebitCreditFromIncludingToExcludingPeriod(filter.getAccount(), filter.getDateStart(), filter.getDateEnd(), true); + } else { + result = new ArrayList<>(); + } + return result; + } + + protected List<Object[]> getAccountEntriesDebitCreditFromIncludingToExcludingPeriod(Account account, Date beginDate, Date endDate, boolean includeEndDate) { + + HqlAndParametersBuilder<Entry> builder = newHqlAndParametersBuilder(); + builder.addGreaterOrEquals(PROPERTY_TRANSACTION_DATE, beginDate); + builder.addEquals(Entry.PROPERTY_ACCOUNT, account); + + if (includeEndDate) { + builder.addLowerOrEquals(PROPERTY_TRANSACTION_DATE, endDate); + } else { + builder.addLowerThan(PROPERTY_TRANSACTION_DATE, endDate); + } + + String query = "SELECT " + builder.getAlias() + "." + Entry.PROPERTY_DEBIT + ", " + + "SUM(" + builder.getAlias() + "." + Entry.PROPERTY_AMOUNT + ") " + + builder.getHql() + + " GROUP BY " + builder.getAlias() + "." + Entry.PROPERTY_DEBIT ; + + List<Object[]> result = findAll(query, builder.getHqlParameters()); + return result; + } + public List<Entry> getAllEntriesByDatesForEntryBook(EntryBook entryBook, Date beginDate, Date endDate) { HqlAndParametersBuilder<Entry> builder = newHqlAndParametersBuilder(); diff --git a/lima-business/src/main/java/org/chorem/lima/entity/FiscalPeriodTopiaDao.java b/lima-business/src/main/java/org/chorem/lima/entity/FiscalPeriodTopiaDao.java index 25777aa..d413ec7 100644 --- a/lima-business/src/main/java/org/chorem/lima/entity/FiscalPeriodTopiaDao.java +++ b/lima-business/src/main/java/org/chorem/lima/entity/FiscalPeriodTopiaDao.java @@ -22,6 +22,10 @@ package org.chorem.lima.entity; +import org.nuiton.topia.persistence.HqlAndParametersBuilder; + +import java.util.Date; + /** * Fiscal period entity DAO. * @@ -73,4 +77,20 @@ public class FiscalPeriodTopiaDao extends AbstractFiscalPeriodTopiaDao<FiscalPer return result; } + + /** + * Return the FiscalPeriod for the given date + * + * @param date fiscal period for this given date + * @return the FiscalPeriod for {@code date} + */ + public FiscalPeriod findForDate(Date date) { + + HqlAndParametersBuilder<FiscalPeriod> builder = newHqlAndParametersBuilder(); + builder.addLowerOrEquals(FiscalPeriod.PROPERTY_BEGIN_DATE, date); + builder.addGreaterOrEquals(FiscalPeriod.PROPERTY_END_DATE, date); + + FiscalPeriod fiscalPeriod = findUniqueOrNull(builder.getHql(), builder.getHqlParameters()); + return fiscalPeriod; + } } diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/MainView.css b/lima-swing/src/main/java/org/chorem/lima/ui/MainView.css index dbf81c5..177cf8b 100644 --- a/lima-swing/src/main/java/org/chorem/lima/ui/MainView.css +++ b/lima-swing/src/main/java/org/chorem/lima/ui/MainView.css @@ -236,6 +236,11 @@ actionIcon : "lettering"; } +#accountViewer { + text : "lima.entries.accountViewer"; + actionIcon : "lettering"; +} + #help { text : "lima.help"; mnemonic : "H"; diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/MainView.jaxx b/lima-swing/src/main/java/org/chorem/lima/ui/MainView.jaxx index 0363a97..5203d08 100644 --- a/lima-swing/src/main/java/org/chorem/lima/ui/MainView.jaxx +++ b/lima-swing/src/main/java/org/chorem/lima/ui/MainView.jaxx @@ -144,6 +144,8 @@ onActionPerformed="getHandler().showTransactionSearchView(this)"/> <JMenuItem id="lettering" onActionPerformed="getHandler().showLetteringView(this)"/> + <JMenuItem id="accountViewer" + onActionPerformed="getHandler().showAccountViewerView(this)"/> </JMenu> <JMenu id="help"> diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.java b/lima-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.java index 8b53397..f2f693b 100644 --- a/lima-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.java +++ b/lima-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.java @@ -34,6 +34,7 @@ import org.chorem.lima.business.LimaServiceFactory; import org.chorem.lima.business.api.OptionsService; import org.chorem.lima.enums.ImportExportEnum; import org.chorem.lima.ui.account.AccountView; +import org.chorem.lima.ui.accountViewer.AccountViewerView; import org.chorem.lima.ui.celleditor.NumberSeparatorCellRenderer; import org.chorem.lima.ui.celleditor.NumberSeparatorTableCellRenderer; import org.chorem.lima.ui.entrybook.EntryBookView; @@ -497,6 +498,13 @@ public class MainViewHandler { swingSession.add(letteringView); } + public void showAccountViewerView(JAXXContext rootContext) { + MainView mainView = getUI(rootContext); + AccountViewerView accountViewerView = new AccountViewerView(mainView); + showTab(mainView, t("lima.entries.accountViewer"), accountViewerView); + swingSession.add(accountViewerView); + } + public void showImportExportView(JAXXContext rootContext, ImportExportEnum type) { MainView mainView = getUI(rootContext); diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringEditModel.java b/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerEditModel.java similarity index 65% copy from lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringEditModel.java copy to lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerEditModel.java index c400009..0c9b98c 100644 --- a/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringEditModel.java +++ b/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerEditModel.java @@ -19,17 +19,18 @@ * <http://www.gnu.org/licenses/gpl-3.0.html>. * #L% */ -package org.chorem.lima.ui.lettering; +package org.chorem.lima.ui.accountViewer; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.io.Serializable; import java.math.BigDecimal; +import java.util.Date; /** * @author sletellier <letellier@codelutin.com> */ -public class LetteringEditModel implements Serializable { +public class AccountViewerEditModel implements Serializable { public static final String PROPERTY_DEBIT = "debit"; @@ -37,6 +38,8 @@ public class LetteringEditModel implements Serializable { public static final String PROPERTY_SOLD = "sold"; + public static final String PROPERTY_GLOBAL_SOLD = "globalSold"; + public static final String PROPERTY_LETTRED = "lettred"; public static final String PROPERTY_UNLETTRED = "unLettred"; @@ -45,7 +48,7 @@ public class LetteringEditModel implements Serializable { protected final PropertyChangeSupport pcs = new PropertyChangeSupport(this); - protected LetteringTableModel model; + protected AccountViewerTableModel model; protected boolean lettred; protected boolean unLettred; protected boolean equalized; @@ -53,6 +56,12 @@ public class LetteringEditModel implements Serializable { protected BigDecimal credit = BigDecimal.ZERO; protected BigDecimal sold = BigDecimal.ZERO; + protected BigDecimal globalDebit = BigDecimal.ZERO; + protected BigDecimal globalCredit = BigDecimal.ZERO; + protected BigDecimal globalSold = BigDecimal.ZERO; + + protected Date fiscalPeriodBeginDate; + public boolean isEqualized() { return equalized; } @@ -67,14 +76,10 @@ public class LetteringEditModel implements Serializable { return lettred; } - public void setLettred(boolean lettred) { - boolean oldLettrer = isLettred(); - if(lettred && (sold == BigDecimal.ZERO || sold.doubleValue() == 0)){ - this.lettred = lettred; - }else{ - this.lettred = false; - } - firePropertyChange(PROPERTY_LETTRED, oldLettrer, this.lettred); + public void setLettred(boolean lettered) { + boolean oldLetter = isLettred(); + this.lettred = lettered && (BigDecimal.ZERO.equals(sold) || sold.doubleValue() == 0); + firePropertyChange(PROPERTY_LETTRED, oldLetter, this.lettred); } public boolean isUnLettred() { @@ -82,9 +87,9 @@ public class LetteringEditModel implements Serializable { } public void setUnLettred(boolean unLettred) { - boolean oldDelettrer = isUnLettred(); + boolean oldDeleter = isUnLettred(); this.unLettred = unLettred; - firePropertyChange(PROPERTY_UNLETTRED, oldDelettrer, this.unLettred); + firePropertyChange(PROPERTY_UNLETTRED, oldDeleter, this.unLettred); } public BigDecimal getDebit() { @@ -94,7 +99,7 @@ public class LetteringEditModel implements Serializable { public void setDebit(BigDecimal debit) { BigDecimal oldDebit = getDebit(); - if (debit != BigDecimal.ZERO){ + if (!BigDecimal.ZERO.equals(debit)){ this.debit = debit.add(oldDebit); }else{ this.debit = BigDecimal.ZERO; @@ -110,7 +115,7 @@ public class LetteringEditModel implements Serializable { public void setCredit(BigDecimal credit) { BigDecimal oldCredit = getCredit(); - if (credit != BigDecimal.ZERO){ + if (!BigDecimal.ZERO.equals(credit)){ this.credit = credit.add(oldCredit); }else{ this.credit=BigDecimal.ZERO; @@ -123,26 +128,47 @@ public class LetteringEditModel implements Serializable { return sold; } - public void setSolde(BigDecimal solde, boolean credit) { - BigDecimal oldSolde = getSold(); + public void setSold(BigDecimal sold, boolean credit) { + BigDecimal oldSold = getSold(); - if (solde != BigDecimal.ZERO){ + if (!BigDecimal.ZERO.equals(sold)){ if (credit){ - this.sold = oldSolde.subtract(solde); + this.sold = oldSold.subtract(sold); }else{ - this.sold = oldSolde.add(solde); + this.sold = oldSold.add(sold); } }else{ this.sold =BigDecimal.ZERO; } - firePropertyChange(PROPERTY_SOLD, oldSolde, this.sold); + firePropertyChange(PROPERTY_SOLD, oldSold, this.sold); + } + + public BigDecimal getGlobalSold() { + return globalSold; + } + + public void setGlobalSold(BigDecimal globalSold) { + BigDecimal oldSold = getGlobalSold(); + + this.globalSold = globalSold; + firePropertyChange(PROPERTY_GLOBAL_SOLD, oldSold, this.globalSold); } - public void resetDebitCreditBalance(){ - setDebit(BigDecimal.ZERO); - setCredit(BigDecimal.ZERO); - setSolde(BigDecimal.ZERO, false); + public BigDecimal getGlobalDebit() { + return globalDebit; + } + + public void setGlobalDebit(BigDecimal globalDebit) { + this.globalDebit = globalDebit; + } + + public BigDecimal getGlobalCredit() { + return globalCredit; + } + + public void setGlobalCredit(BigDecimal globalCredit) { + this.globalCredit = globalCredit; } public void addPropertyChangeListener(PropertyChangeListener listener) { @@ -168,4 +194,12 @@ public class LetteringEditModel implements Serializable { protected void firePropertyChange(String propertyName, Object newValue) { firePropertyChange(propertyName, null, newValue); } + + public Date getFiscalPeriodBeginDate() { + return fiscalPeriodBeginDate; + } + + public void setFiscalPeriodBeginDate(Date fiscalPeriodStartingDate) { + this.fiscalPeriodBeginDate = fiscalPeriodStartingDate; + } } diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerSelectionModel.java b/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerSelectionModel.java new file mode 100644 index 0000000..fa1fea5 --- /dev/null +++ b/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerSelectionModel.java @@ -0,0 +1,158 @@ +package org.chorem.lima.ui.accountViewer; +/* + * #%L + * Lima :: Swing + * %% + * Copyright (C) 2012 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% + */ + +import org.apache.commons.lang3.StringUtils; +import org.chorem.lima.entity.Entry; + +import javax.swing.*; +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import java.util.List; + +/** + * @author sletellier <letellier@codelutin.com> + */ +public class AccountViewerSelectionModel extends DefaultListSelectionModel{ + + protected AccountViewerTableModel letteringTableModel; + protected Entry entry; + protected int lineSelected; + protected final PropertyChangeSupport pcs = new PropertyChangeSupport(this); + + public AccountViewerSelectionModel(AccountViewerTableModel letteringTableModel){ + this.letteringTableModel = letteringTableModel; + } + + @Override + public void addSelectionInterval(int row, int column) { + setSelectionInterval(row, column); + } + + @Override + public void setSelectionInterval(int row, int column) { + if (!letteringNotExist(row)) { + + //lettred entries + if ( isSelectionEmpty() || !isSelectedIndex(row)){ + clearSelection(); + lineSelected = row; + String currentLettring = getCurrentLettring(); + + //select entries with the same letter of the selected entry + for(Entry entry : getEntries()){ + if (StringUtils.isNotBlank(entry.getLettering())){ + if (entry.getLettering().equals(currentLettring)){ + int entryToSelect = letteringTableModel.indexOf(entry); + super.addSelectionInterval(entryToSelect, entryToSelect); + } + } + } + } + } + else { + + //unlettred entries + //To clear the selection when it changes from lettered entry to unlettered + for(Entry entry : getEntries()){ + if (!StringUtils.isBlank(entry.getLettering())) { + int entryToSelect = letteringTableModel.indexOf(entry); + super.removeSelectionInterval(entryToSelect, entryToSelect); + } + } + + if (isSelectionEmpty() || !isSelectedIndex(row)){ + super.addSelectionInterval(row, column); + }else { + super.removeSelectionInterval(row, column); + } + + } + } + + /**return true if lettering is null, or not null but empty + * @param row index of the line to test + * @return boolean + * */ + public boolean letteringNotExist(int row){ + boolean emptyOrNull; + entry = letteringTableModel.get(row); + String lettering = entry.getLettering(); + emptyOrNull = (lettering==null||lettering.isEmpty()); + return emptyOrNull; + } + + public List<Entry> getEntries(){ + return letteringTableModel.getValues(); + } + + public String getCurrentLettring(){ + return getCurrentEntrySelected().getLettering(); + } + + public Entry getCurrentEntrySelected(){ + return letteringTableModel.get(lineSelected); + } + +// /**After rounding one of two entries, selection of its, and of the new entry, +// * resulting of rounding*/ +// public void selectRoundedAndNewEntries(int indexFirstRoundedEntry, int indexSecondRoundedEntry, Entry newResultRoundedEntry) { +// if (!isSelectedIndex(indexFirstRoundedEntry)) { +// addSelectionInterval(indexFirstRoundedEntry, indexFirstRoundedEntry); +// } +// if (!isSelectedIndex(indexSecondRoundedEntry)) { +// addSelectionInterval(indexSecondRoundedEntry, indexSecondRoundedEntry); +// } +// /*New entry*/ +// int newEntryIndex = letteringTableModel.indexOf(newResultRoundedEntry); +// addSelectionInterval(newEntryIndex, newEntryIndex); +// } + + @Override + public int getSelectionMode() { + return MULTIPLE_INTERVAL_SELECTION; + } + + public void addPropertyChangeListener(PropertyChangeListener listener) { + pcs.addPropertyChangeListener(listener); + } + + public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { + pcs.addPropertyChangeListener(propertyName, listener); + } + + public void removePropertyChangeListener(PropertyChangeListener listener) { + pcs.removePropertyChangeListener(listener); + } + + public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) { + pcs.removePropertyChangeListener(propertyName, listener); + } + + protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) { + pcs.firePropertyChange(propertyName, oldValue, newValue); + } + + protected void firePropertyChange(String propertyName, Object newValue) { + firePropertyChange(propertyName, null, newValue); + } +} diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerTable.java b/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerTable.java new file mode 100644 index 0000000..2266311 --- /dev/null +++ b/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerTable.java @@ -0,0 +1,42 @@ +/* + * #%L + * 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 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.ui.accountViewer; + +import org.chorem.lima.ui.common.AbstractLimaTable; + + +/** + * Table des transaction qui ajoute des comportement (keys). + * + * @author jpepin + */ +public class AccountViewerTable extends AbstractLimaTable<AccountViewerViewHandler> { + + /** serialVersionUID. */ + private static final long serialVersionUID = 3133690382049594727L; + + public AccountViewerTable(AccountViewerViewHandler handler) { + super(handler); + + } +} diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerTableModel.java b/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerTableModel.java new file mode 100644 index 0000000..e6a3a5a --- /dev/null +++ b/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerTableModel.java @@ -0,0 +1,144 @@ +/* + * #%L + * Lima :: Swing + * %% + * Copyright (C) 2008 - 2012 CodeLutin, Chatellier Eric + * %% + * 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.ui.accountViewer; + +import org.chorem.lima.entity.Account; +import org.chorem.lima.entity.Entry; +import org.chorem.lima.entity.EntryBook; +import org.chorem.lima.ui.common.AbstractColumn; +import org.chorem.lima.ui.common.AbstractLimaTableModel; + +import java.math.BigDecimal; +import java.util.Date; + +import static org.nuiton.i18n.I18n.t; + +/** + * Basic transaction table model. + * <p/> + * + * @author ore + * @author chatellier + */ +public class AccountViewerTableModel extends AbstractLimaTableModel<Entry> { + + /** serialVersionUID. */ + private static final long serialVersionUID = 1L; + + public BigDecimal getPreviousPeriodSold() { + return previousPeriodSold; + } + + protected BigDecimal previousPeriodSold; + + @Override + protected void initColumn() { + addColumn(new AbstractColumn<AccountViewerTableModel>(Date.class, t("lima.table.date"), false) { + @Override + public Object getValueAt(int row) { + Entry entry = tableModel.get(row); + return entry.getFinancialTransaction().getTransactionDate(); + } + }); + + addColumn(new AbstractColumn<AccountViewerTableModel>(EntryBook.class, t("lima.table.entryBook"), false) { + @Override + public Object getValueAt(int row) { + Entry entry = tableModel.get(row); + return entry.getFinancialTransaction().getEntryBook(); + } + }); + + addColumn(new AbstractColumn<AccountViewerTableModel>(Account.class, t("lima.table.account"), false) { + @Override + public Object getValueAt(int row) { + Entry entry = tableModel.get(row); + return entry.getAccount(); + } + }); + + addColumn(new AbstractColumn<AccountViewerTableModel>(String.class, t("lima.table.voucher"), false) { + @Override + public Object getValueAt(int row) { + Entry entry = tableModel.get(row); + return entry.getVoucher(); + } + }); + + addColumn(new AbstractColumn<AccountViewerTableModel>(String.class, t("lima.table.description"), false) { + @Override + public Object getValueAt(int row) { + Entry entry = tableModel.get(row); + return entry.getDescription(); + } + }); + + addColumn(new AbstractColumn<AccountViewerTableModel>(String.class, t("lima.table.letter"), false) { + @Override + public Object getValueAt(int row) { + Entry entry = tableModel.get(row); + return entry.getLettering(); + } + }); + + addColumn(new AbstractColumn<AccountViewerTableModel>(BigDecimal.class, t("lima.table.debit"), false) { + @Override + public Object getValueAt(int row) { + Entry entry = tableModel.get(row); + return entry.isDebit() ? entry.getAmount() : BigDecimal.ZERO; + } + }); + + addColumn(new AbstractColumn<AccountViewerTableModel>(BigDecimal.class, t("lima.table.credit"), false) { + @Override + public Object getValueAt(int row) { + Entry entry = tableModel.get(row); + return entry.isDebit() ? BigDecimal.ZERO : entry.getAmount(); + } + }); + + addColumn(new AbstractColumn<AccountViewerTableModel>(BigDecimal.class, t("lima.table.balance"), false) { + @Override + public Object getValueAt(int row) { + Entry currentEntry = tableModel.get(row); + BigDecimal result = BigDecimal.ZERO; + result = currentEntry.isDebit() ? result.add(currentEntry.getAmount()) : result.subtract(currentEntry.getAmount()); + if (row > 0) { + int i = 1; + while (row - i >= 0) { + Entry prevEntry = tableModel.get(row - i); + result = prevEntry.isDebit() ? result.add(prevEntry.getAmount()) : result.subtract(prevEntry.getAmount()); + i++; + } + + } + return result; + } + }); + + } + + public void setPreviousPeriodSold(BigDecimal previousPeriodSold) { + this.previousPeriodSold = previousPeriodSold; + } +} diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerView.css b/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerView.css new file mode 100644 index 0000000..f0bd618 --- /dev/null +++ b/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerView.css @@ -0,0 +1,73 @@ +/* + * #%L + * Lima :: Swing + * %% + * Copyright (C) 2008 - 2014 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% + */ +.toolbar { + floatable : false; +} + +#accountLabel { + actionIcon : "choose-account"; + labelFor : {accountComboBox}; +} + +#accountComboBox { + toolTipText : "lima.lettering.account"; + showDecorator : false; + selectedItem : {getHandler().getAccount()}; + minimumSize : {new Dimension(300,10)}; + preferredSize : {new Dimension(400,25)}; + maximumSize : {new Dimension(500,40)}; +} + +#back { + toolTipText : "lima.lettering.account.back"; + actionIcon : "previous"; +} + +#next { + toolTipText : "lima.lettering.account.next"; + actionIcon : "next"; +} + +#beginPeriodLabel { + text : "lima.lettering.period.begin"; + labelFor : {beginPeriodPicker}; +} + +#endPeriodLabel { + text : "lima.lettering.period.end"; + labelFor : {endPeriodPicker}; +} + +#refresh { + toolTipText : "lima.lettering.refresh"; + actionIcon : "refresh"; +} + +#table { + sortable : false; + rowHeight : 22; +} + +#balanceStatusLabel { + horizontalTextPosition:{JLabel.RIGHT}; + border: {BorderFactory.createEmptyBorder(0, 0, 0, 20)} +} diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerView.jaxx b/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerView.jaxx new file mode 100644 index 0000000..25a1066 --- /dev/null +++ b/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerView.jaxx @@ -0,0 +1,94 @@ +<!-- + #%L + 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 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% + --> + +<JPanel layout="{new BorderLayout()}"> + + <import> + java.awt.Dimension + org.chorem.lima.util.WrapToolBarLayout + org.chorem.lima.ui.common.FinancialPeriodComboBoxModel + org.chorem.lima.util.BigDecimalToString + org.chorem.lima.ui.lettering.TypeEntry + org.chorem.lima.entity.Account + javax.swing.ListSelectionModel + org.jdesktop.swingx.JXDatePicker + static org.nuiton.i18n.I18n.t + org.chorem.lima.ui.combobox.AccountComboBox + </import> + + <AccountViewerViewHandler id="handler" constructorParams="this"/> + + <AccountViewerEditModel id='editModel'/> + + <script> + <![CDATA[ + void $afterCompleteSetup() { + handler.init(); + } + ]]> + </script> + + <JToolBar styleClass="toolbar" + constraints="BorderLayout.PAGE_START" + layout="{new WrapToolBarLayout()}"> + + <JLabel id="accountLabel"/> + <AccountComboBox id="accountComboBox" + constraints="BorderLayout.CENTER" + onPropertyChange="{getHandler().accountComboBoxChange(event);}"/> + <JButton id="back" + onActionPerformed="handler.back(accountComboBox)"/> + <JButton id="next" + onActionPerformed="handler.next(accountComboBox)"/> + + <JToolBar.Separator/> + + <JLabel id="beginPeriodLabel"/> + <JAXXDatePicker id="beginPeriodPicker" + patternLayout="dd/MM/yyy" + onActionPerformed="handler.setDateStart(beginPeriodPicker.getDate())"/> + + <JLabel id="endPeriodLabel"/> + <JAXXDatePicker id="endPeriodPicker" + patternLayout="dd/MM/yyy" + onActionPerformed="handler.setDateEnd(endPeriodPicker.getDate())"/> + + <JToolBar.Separator/> + + <JButton id="refresh" + onActionPerformed="handler.updateAllEntries()"/> + + </JToolBar> + <JScrollPane constraints="BorderLayout.CENTER"> + <AccountViewerTableModel id="tableModel"/> + <AccountViewerSelectionModel id='accountViewerSelectionModel' constructorParams='tableModel' + onValueChanged="handler.balanceAndActions()"/> + + <AccountViewerTable id="table" + constructorParams="handler" + model="{tableModel}" + selectionModel="{accountViewerSelectionModel}"/> + </JScrollPane> + + <JPanel constraints="BorderLayout.SOUTH" layout="{new BorderLayout()}"> + <JLabel id='balanceStatusLabel' constraints="BorderLayout.EAST"/> + </JPanel> + +</JPanel> \ No newline at end of file diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringViewHandler.java b/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerViewHandler.java similarity index 55% copy from lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringViewHandler.java copy to lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerViewHandler.java index fd77b1a..bf37cb0 100644 --- a/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringViewHandler.java +++ b/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerViewHandler.java @@ -20,15 +20,15 @@ * #L% */ -package org.chorem.lima.ui.lettering; +package org.chorem.lima.ui.accountViewer; -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; import com.google.common.collect.Lists; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.LimaSwingConfig; +import org.chorem.lima.beans.LetteringFilter; import org.chorem.lima.beans.LetteringFilterImpl; import org.chorem.lima.business.LimaServiceFactory; import org.chorem.lima.business.api.AccountService; @@ -36,28 +36,26 @@ import org.chorem.lima.business.api.EntryBookService; import org.chorem.lima.business.api.FinancialPeriodService; import org.chorem.lima.business.api.FinancialTransactionService; import org.chorem.lima.business.api.FiscalPeriodService; -import org.chorem.lima.business.exceptions.LockedEntryBookException; -import org.chorem.lima.business.exceptions.LockedFinancialPeriodException; -import org.chorem.lima.business.exceptions.UnbalancedEntriesException; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.Entry; +import org.chorem.lima.entity.EntryImpl; +import org.chorem.lima.entity.FinancialTransaction; +import org.chorem.lima.entity.FinancialTransactionImpl; import org.chorem.lima.entity.FiscalPeriod; import org.chorem.lima.ui.combobox.AccountComboBox; import org.chorem.lima.util.BigDecimalToString; import org.chorem.lima.util.ErrorHelper; +import org.nuiton.util.beans.Binder; +import org.nuiton.util.beans.BinderFactory; -import javax.swing.AbstractAction; -import javax.swing.ActionMap; -import javax.swing.InputMap; -import javax.swing.JComboBox; -import javax.swing.JComponent; -import javax.swing.KeyStroke; +import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.InputEvent; import java.awt.event.KeyEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.math.BigDecimal; +import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.List; @@ -74,10 +72,13 @@ import static org.nuiton.i18n.I18n.t; * Last update : $Date$ * By : $Author$ */ -public class LetteringViewHandler{ +public class AccountViewerViewHandler { - protected LetteringView view; - protected LetteringTable table; + // fixme Date format should be app parameters + protected static String DATE_FORMAT = "dd/MM/yyyy"; + + protected AccountViewerView view; + protected AccountViewerTable table; /** Transaction service. */ protected FiscalPeriodService fiscalPeriodService; @@ -90,19 +91,20 @@ public class LetteringViewHandler{ protected BigDecimal debit = BigDecimal.ZERO; protected BigDecimal credit = BigDecimal.ZERO; - protected BigDecimal solde = BigDecimal.ZERO; - protected LettringSelectionModel lettringSelectionModel; - protected LetteringEditModel editModel; + protected AccountViewerEditModel editModel; protected ErrorHelper errorHelper; protected enum ButtonMode {DELETTRED, LETTRED, EQUALIZED, ALL} - private static final Log log = LogFactory.getLog(LetteringViewHandler.class); + + protected SimpleDateFormat dateFormatter = new SimpleDateFormat(DATE_FORMAT); + + private static final Log log = LogFactory.getLog(AccountViewerViewHandler.class); protected boolean initializationComplete; - public LetteringViewHandler(LetteringView view) { + public AccountViewerViewHandler(AccountViewerView view) { initializationComplete = false; this.view = view; initShortCuts(); @@ -120,24 +122,31 @@ public class LetteringViewHandler{ public void init() { filter = new LetteringFilterImpl(); editModel = view.getEditModel(); - lettringSelectionModel = view.getLetteringSelectionModel(); + //lettringSelectionModel = view.getLetteringSelectionModel(); loadComboAndRows(); - editModel.addPropertyChangeListener(LetteringEditModel.PROPERTY_DEBIT, new PropertyChangeListener() { + editModel.addPropertyChangeListener(AccountViewerEditModel.PROPERTY_DEBIT, new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { updateSoldStatus(); } }); - editModel.addPropertyChangeListener(LetteringEditModel.PROPERTY_CREDIT, new PropertyChangeListener() { + editModel.addPropertyChangeListener(AccountViewerEditModel.PROPERTY_CREDIT, new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { updateSoldStatus(); } }); - editModel.addPropertyChangeListener(LetteringEditModel.PROPERTY_SOLD, new PropertyChangeListener() { + editModel.addPropertyChangeListener(AccountViewerEditModel.PROPERTY_SOLD, new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + updateSoldStatus(); + } + }); + + editModel.addPropertyChangeListener(AccountViewerEditModel.PROPERTY_GLOBAL_SOLD, new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { updateSoldStatus(); @@ -145,19 +154,27 @@ public class LetteringViewHandler{ }); initializationComplete = true; - updateSoldStatus(); updateAllEntries(); - - + updateSoldStatus(); } public void updateSoldStatus() { - view.getBalanceStatusLabel().setText(t("lima.lettering.balanceStatus", - BigDecimalToString.format(editModel.getDebit()), - BigDecimalToString.format(editModel.getCredit()), - BigDecimalToString.format(editModel.getSold()))); + if (initializationComplete) { + view.getBalanceStatusLabel().setText(t("lima.lettering.accountViewerBalanceStatus", + dateFormatter.format(editModel.getFiscalPeriodBeginDate()), + dateFormatter.format(filter.getDateEnd()), + + BigDecimalToString.format(editModel.getGlobalDebit()), + BigDecimalToString.format(editModel.getGlobalCredit()), + BigDecimalToString.format(editModel.getGlobalSold()), + + BigDecimalToString.format(editModel.getDebit()), + BigDecimalToString.format(editModel.getCredit()), + BigDecimalToString.format(editModel.getSold()))); + } } + protected void initShortCuts() { InputMap inputMap= view.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); @@ -167,55 +184,122 @@ public class LetteringViewHandler{ //To block reaction of the dual key 'ctrl+a' (Selection of all lines) inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.CTRL_MASK), "none"); - // add action on Ctrl + L - binding = "lettering"; - inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_L, KeyEvent.CTRL_DOWN_MASK), binding); + + // refresh + binding = "refresh"; + inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0), binding); actionMap.put(binding, new AbstractAction() { - private static final long serialVersionUID = 397305388204489988L; + private static final long serialVersionUID = -7192846839712951680L; @Override public void actionPerformed(ActionEvent e) { - addLetter(); + updateAllEntries(); } }); + } - // add action on Ctrl + Delete - binding = "un-lettering"; - inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), binding); - actionMap.put(binding, new AbstractAction() { - private static final long serialVersionUID = 6493175994438339351L; + public void loadComboAndRows(){ - @Override - public void actionPerformed(ActionEvent e) { - removeLetter(); - } - }); + //By default, we have the beginning of the fiscal period (Or of current + //date if no fiscal period) and the end of the current fiscal period + FiscalPeriod fiscalPeriod = fiscalPeriodService.getLastFiscalPeriod(); + Date defaultDateBegFiscalPeriod, defaultDateEndCurrent; - // add action on Ctrl + B - binding = "balance"; - inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_B, KeyEvent.CTRL_DOWN_MASK), binding); - actionMap.put(binding, new AbstractAction() { - private static final long serialVersionUID = 5997811877503911744L; + Calendar calendar = Calendar.getInstance(); + int lastCurrentMonthDay = calendar.getActualMaximum(Calendar.DATE); + int firstCurrentMonthDay = calendar.getActualMinimum(Calendar.DATE); - @Override - public void actionPerformed(ActionEvent e) { - roundAndCreateEntry(); - } - }); + if (fiscalPeriod != null){ + defaultDateBegFiscalPeriod = fiscalPeriod.getBeginDate(); + defaultDateEndCurrent = fiscalPeriod.getEndDate(); + } else{ + defaultDateBegFiscalPeriod = DateUtils.setDays(new Date(), firstCurrentMonthDay); + defaultDateEndCurrent = DateUtils.setDays(new Date(), lastCurrentMonthDay); + } - // refresh - binding = "refresh"; - inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0), binding); - actionMap.put(binding, new AbstractAction() { - private static final long serialVersionUID = -7192846839712951680L; + view.getBeginPeriodPicker().setDate(defaultDateBegFiscalPeriod); + view.getEndPeriodPicker().setDate(defaultDateEndCurrent); - @Override - public void actionPerformed(ActionEvent e) { - updateAllEntries(); + editModel.setFiscalPeriodBeginDate(defaultDateBegFiscalPeriod); + + filter.setDateStart(defaultDateBegFiscalPeriod); + filter.setDateEnd(defaultDateEndCurrent); + } + + public void updateAllEntries() { + + if (initializationComplete + && filter.getAccount() != null + && filter.getDateStart() != null + && filter.getDateEnd() != null) { + + List<Entry> entriesAndResume = Lists.newArrayList(); + + List<Entry> entries = financialTransactionService.getAllEntrieByDatesAndAccountAndLettering(filter); + FiscalPeriod fiscalPeriod = fiscalPeriodService.getFiscalPeriodForDate(filter.getDateStart()); + + LetteringFilter previousPeriodFilter = computePreviousPeriodFilter(fiscalPeriod); + LetteringFilter actualPeriodFilter = computeActualPeriodFilter(fiscalPeriod); + setPreviousSold(previousPeriodFilter); + setActualSold(fiscalPeriod, actualPeriodFilter); + + // no previous sold to add if selected starting date is same as fiscal period one + if (!DateUtils.isSameDay(filter.getDateStart(), previousPeriodFilter.getDateStart()) && CollectionUtils.isNotEmpty(entries)) { + entriesAndResume.add(getFirstLinePreviousSoldEntry(entries, previousPeriodFilter)); } - }); + + entriesAndResume.addAll(entries); + view.getTableModel().setValues(entriesAndResume); + } + + onBalanceChanged(null); + } + + protected void addFiscalPeriodBeginDate(FiscalPeriod fiscalPeriod) { + if (fiscalPeriod != null) { + editModel.setFiscalPeriodBeginDate(fiscalPeriod.getBeginDate()); + } } + protected Entry getFirstLinePreviousSoldEntry(List<Entry> entries, LetteringFilter previousPeriodFilter) { + Entry firstEntry = entries.get(0); + FinancialTransaction firstTransaction = firstEntry.getFinancialTransaction(); + FinancialTransaction firstLineTransaction = new FinancialTransactionImpl(); + Binder<FinancialTransaction, FinancialTransaction> binder = BinderFactory.newBinder(FinancialTransaction.class); + binder.copyExcluding(firstTransaction, firstLineTransaction, FinancialTransaction.PROPERTY_TOPIA_ID); + Date previousSoldEndDate = getDayMinus1Calendar(previousPeriodFilter).getTime(); + firstLineTransaction.setTransactionDate(previousSoldEndDate); + + Entry resumeEntry = new EntryImpl(); + resumeEntry.setDescription(String.format(t("lima.accountViewer.previousSold"), dateFormatter.format(previousSoldEndDate))); + resumeEntry.setAmount(view.getTableModel().getPreviousPeriodSold().abs()); + resumeEntry.setDebit(BigDecimal.ZERO.compareTo(view.getTableModel().getPreviousPeriodSold()) < 0); + resumeEntry.setFinancialTransaction(firstLineTransaction); + return resumeEntry; + } + + protected void setPreviousSold(LetteringFilter previousPeriodFilter) { + BigDecimal previousSold; + if (previousPeriodFilter == null) { + previousSold = BigDecimal.ZERO; + } else { + List<Object[]> initialDebitCredit = financialTransactionService.getAccountEntriesDebitCreditFromIncludingToExcludingPeriod(previousPeriodFilter); + DebitCreditSold debitCreditSold = new DebitCreditSold().invoke(initialDebitCredit); + previousSold = debitCreditSold.getSold(); + } + view.getTableModel().setPreviousPeriodSold(previousSold); + } + + protected void setActualSold(FiscalPeriod fiscalPeriod, LetteringFilter actualPeriodFilter) { + addFiscalPeriodBeginDate(fiscalPeriod); + List<Object[]> initialDebitCredit = financialTransactionService.getAccountEntriesDebitCreditFromIncludingToIncludingPeriod(actualPeriodFilter); + DebitCreditSold debitCreditSold = new DebitCreditSold().invoke(initialDebitCredit); + editModel.setGlobalDebit(debitCreditSold.getDebit()); + editModel.setGlobalCredit(debitCreditSold.getCredit()); + editModel.setGlobalSold(debitCreditSold.getSold()); + } + + public void balanceAndActions() { if (log.isDebugEnabled()) { log.debug("balanceAndActions"); @@ -241,7 +325,7 @@ public class LetteringViewHandler{ log.debug("2 rows selected"); } /*Treatment only if one of values contains decimals*/ - LetteringTableModel tableModel = view.getTableModel(); + AccountViewerTableModel tableModel = view.getTableModel(); Entry firstSelectedEntry = tableModel.get(selectedRows[0]); Entry secondSelectedEntry = tableModel.get(selectedRows[1]); @@ -264,7 +348,7 @@ public class LetteringViewHandler{ //Unlettred entries onBalanceChanged(null); //treatment unuseful if no rows are selected - if (!view.getLetteringSelectionModel().isSelectionEmpty()) { + if (!view.getAccountViewerSelectionModel().isSelectionEmpty()) { if (log.isDebugEnabled()) { log.debug("Rows selected"); } @@ -316,11 +400,11 @@ public class LetteringViewHandler{ public void setValuesForSelectedEntries() { Entry selectedEntry; - LetteringTableModel tableModel = view.getTableModel(); + AccountViewerTableModel tableModel = view.getTableModel(); for (int i = 0; i < tableModel.getRowCount(); i ++){ - if (view.getLetteringSelectionModel().isSelectedIndex(i)){ + if (view.getAccountViewerSelectionModel().isSelectedIndex(i)){ selectedEntry = tableModel.get(i); - //Set values for calculation (By LetteringEditModel) of balance + //Set values for calculation (By AccountViewerEditModel) of balance onBalanceChanged(selectedEntry); } } @@ -330,7 +414,7 @@ public class LetteringViewHandler{ if (balance == null) { editModel.setCredit(BigDecimal.ZERO); editModel.setDebit(BigDecimal.ZERO); - editModel.setSolde(BigDecimal.ZERO, false); + editModel.setSold(BigDecimal.ZERO, false); } else { balanceCalculation(balance.getAmount(), balance.isDebit()); } @@ -354,136 +438,54 @@ public class LetteringViewHandler{ if (!creditVal.equals(BigDecimal.ZERO)){ editModel.setCredit(creditVal); - editModel.setSolde(creditVal, true); + editModel.setSold(creditVal, true); } }else if (creditVal.equals(BigDecimal.ZERO)){ editModel.setDebit(debitVal); - editModel.setSolde(debitVal, false); + editModel.setSold(debitVal, false); }else{ onBalanceChanged(null); } } - public void loadComboAndRows(){ - - //By default, we have the beginning of the fiscal period (Or of current - //date if no fiscal period) and the end of the current date - FiscalPeriod fiscalPeriod = fiscalPeriodService.getLastFiscalPeriod(); - Date defaultDateBegFiscalPeriod; - - Calendar calendar = Calendar.getInstance(); - int dernierJourMoisCourant = calendar.getActualMaximum(Calendar.DATE); - int premierJourMoisCourant = calendar.getActualMinimum(Calendar.DATE); - - if (fiscalPeriod != null){ - defaultDateBegFiscalPeriod = fiscalPeriod.getBeginDate(); - } else{ - defaultDateBegFiscalPeriod = DateUtils.setDays(new Date(), premierJourMoisCourant); - } - - Date defaultDateEndCurrent = DateUtils.setDays(new Date(), dernierJourMoisCourant); - - - view.getBeginPeriodPicker().setDate(defaultDateBegFiscalPeriod); - view.getEndPeriodPicker().setDate(defaultDateEndCurrent); - - filter.setDateStart(defaultDateBegFiscalPeriod); - filter.setDateEnd(defaultDateEndCurrent); - - TypeEntry type = view.getLetteredEntryComboBox().getSelectedItem(); - setTypeEntry(type); + protected Calendar getDayMinus1Calendar(LetteringFilter previousPeriodFilter) { + Calendar cal = Calendar.getInstance(); + cal.setTime(previousPeriodFilter.getDateEnd()); + cal.add(Calendar.DATE, -1); + return cal; } - public void setDateStart(Date date) { - filter.setDateStart(date); - updateAllEntries(); - } + protected LetteringFilter computePreviousPeriodFilter(FiscalPeriod fiscalPeriod) { + LetteringFilter previousPeriodFilter = null; - public void setDateEnd(Date date) { - filter.setDateEnd(date); - updateAllEntries(); - } - - public void setAccount(Account account) { - if (filter != null) { - filter.setAccount(account); - updateAllEntries(); + if (fiscalPeriod != null) { + previousPeriodFilter = new LetteringFilterImpl(); + previousPeriodFilter.setDateStart(fiscalPeriod.getBeginDate()); + previousPeriodFilter.setDateEnd(filter.getDateStart()); + previousPeriodFilter.setAccount(filter.getAccount()); } - } - public Account getAccount() { - Account account = null; - if (filter != null) { - account = filter.getAccount(); - } - return account; + return previousPeriodFilter; } - public void setTypeEntry(TypeEntry typeEntry) { - filter.setDisplayLettered(typeEntry.isLettered()); - filter.setDisplayUnlettred(typeEntry.isNoLettered()); - updateAllEntries(); - } - - public void updateAllEntries() { - - if (initializationComplete - && filter.getAccount() != null - && filter.getDateStart() != null - && filter.getDateEnd() != null) { + private LetteringFilter computeActualPeriodFilter(FiscalPeriod fiscalPeriod) { + LetteringFilter actualPeriodFilter = null; - List<Entry> entries = financialTransactionService.getAllEntrieByDatesAndAccountAndLettering(filter); - - view.getTableModel().setValues(entries); + if (fiscalPeriod != null) { + actualPeriodFilter = new LetteringFilterImpl(); + actualPeriodFilter.setDateStart(fiscalPeriod.getBeginDate()); + actualPeriodFilter.setDateEnd(filter.getDateEnd()); + actualPeriodFilter.setAccount(filter.getAccount()); } - onBalanceChanged(null); - } - - /**To make the difference between two selected entries and - * create a new entry with the result (debit or credit). - * It allow to letter somme entries with different debit and credit - * */ - public void roundAndCreateEntry() { - - LetteringTableModel tableModel = view.getTableModel(); - - int[] selectedRows = view.getTable().getSelectedRows(); - if (editModel.isEqualized() && selectedRows.length == 2) { - try { - /*Treatment only if one of values contains decimals*/ - Entry firstSelectedEntry = tableModel.get(selectedRows[0]); - Entry secondSelectedEntry = tableModel.get(selectedRows[1]); - - Entry[] newEntriesFormEqualizing = financialTransactionService.getEntriesFromEqualizing(firstSelectedEntry, secondSelectedEntry); - - /*Add new entries to the model and the table*/ - Entry newSameAccountEntry = newEntriesFormEqualizing[0]; - Entry newCostOrProductEntry = newEntriesFormEqualizing[1]; - tableModel.addValue(newSameAccountEntry); - tableModel.addValue(newCostOrProductEntry); - - /*Re-select the two entries (firstSelectedEntry and secondSelectedEntry) - * and the new sameAccountEntry - * */ - view.getLetteringSelectionModel().selectRoundedAndNewEntries(selectedRows[0], selectedRows[1], newSameAccountEntry); - } catch (LockedFinancialPeriodException e) { - errorHelper.showErrorMessage(t("lima.lettering.roundAndCreateEntry.error.lockedFinancialPeriod", - e.getFinancialPeriod().getBeginDate(), - e.getFinancialPeriod().getEndDate())); - } catch (LockedEntryBookException e) { - errorHelper.showErrorMessage(t("lima.lettering.roundAndCreateEntry.error.lockedEntryBook", - e.getClosedPeriodicEntryBook().getEntryBook().getCode(), - e.getClosedPeriodicEntryBook().getEntryBook().getLabel(), - e.getClosedPeriodicEntryBook().getFinancialPeriod().getBeginDate(), - e.getClosedPeriodicEntryBook().getFinancialPeriod().getEndDate())); - } - } + return actualPeriodFilter; } public void accountComboBoxChange(PropertyChangeEvent event) { if (event.getPropertyName().equals(AccountComboBox.PROPERTY_SELECTED_ITEM)) { - setAccount((Account) event.getNewValue()); + if (event.getNewValue() != null && event.getNewValue() instanceof Account) { + setAccount((Account) event.getNewValue()); + } } } @@ -493,13 +495,13 @@ public class LetteringViewHandler{ * @param accountComboBox account combo box */ public void back(AccountComboBox accountComboBox) { - JComboBox combobox = accountComboBox.getCombobox(); - int row = combobox.getSelectedIndex(); + JComboBox comboBox = accountComboBox.getCombobox(); + int row = comboBox.getSelectedIndex(); if (row > 0) { - combobox.setSelectedIndex(row - 1); + comboBox.setSelectedIndex(row - 1); } - view.getLetteringSelectionModel().clearSelection(); + view.getAccountViewerSelectionModel().clearSelection(); } /** @@ -508,103 +510,79 @@ public class LetteringViewHandler{ * @param accountComboBox combo box */ public void next(AccountComboBox accountComboBox) { - JComboBox combobox = accountComboBox.getCombobox(); - int size = combobox.getItemCount(); - int row = combobox.getSelectedIndex(); + JComboBox comboBox = accountComboBox.getCombobox(); + int size = comboBox.getItemCount(); + int row = comboBox.getSelectedIndex(); if (row < size - 1) { - combobox.setSelectedIndex(row + 1); + comboBox.setSelectedIndex(row + 1); } - view.getLetteringSelectionModel().clearSelection(); + view.getAccountViewerSelectionModel().clearSelection(); } - /**Add a group of three letters to n entries*/ - public void addLetter() { - if (editModel.isLettred()) { - int[] entrieSelected = view.getTable().getSelectedRows(); + private class DebitCreditSold { + private BigDecimal debit; + private BigDecimal credit; + private BigDecimal sold; - LetteringTableModel tableModel = view.getTableModel(); - - List<Entry> entries = Lists.newLinkedList(); - - for (int indexEntry : entrieSelected) { - - Entry entry = tableModel.get(indexEntry); - - entries.add(entry); - } - - try { + public BigDecimal getDebit() { + return debit; + } - if (!entries.isEmpty()) { + public BigDecimal getCredit() { + return credit; + } - entries = financialTransactionService.addLetter(entries); + public BigDecimal getSold() { + return sold; + } - updateEntries(entries); + public DebitCreditSold invoke(List<Object[]> initialDebitCredit) { + debit = BigDecimal.ZERO; + credit = BigDecimal.ZERO; + if (CollectionUtils.isNotEmpty(initialDebitCredit)) { + int nbAmount = initialDebitCredit.size(); + if (nbAmount == 2) { + debit = (BigDecimal) initialDebitCredit.get(0)[1]; + credit = (BigDecimal) initialDebitCredit.get(1)[1]; + } + if (nbAmount == 1) { + if ((Boolean) initialDebitCredit.get(0)[0]) { + debit = (BigDecimal) initialDebitCredit.get(0)[1]; + } else { + credit = (BigDecimal) initialDebitCredit.get(0)[1]; + } } - - } catch (LockedEntryBookException e) { - - errorHelper.showErrorMessage(t("lima.entries.letter.closed.entryBook.error", - e.getClosedPeriodicEntryBook().getEntryBook().getCode(), - e.getClosedPeriodicEntryBook().getEntryBook().getLabel(), - e.getClosedPeriodicEntryBook().getFinancialPeriod().getBeginDate(), - e.getClosedPeriodicEntryBook().getFinancialPeriod().getEndDate())); - - } catch (UnbalancedEntriesException e) { - - errorHelper.showErrorMessage(t("lima.entries.letter.unbalanced.error")); - } - onButtonModeChanged(ButtonMode.DELETTRED); + + sold = debit.subtract(credit); + return this; } } - /**Remove a group of three letters to n entries*/ - public void removeLetter() { - if (editModel.isUnLettred()) { - - int[] entrieSelected = view.getTable().getSelectedRows(); - - LetteringTableModel tableModel = view.getTableModel(); - - if (entrieSelected.length > 0) { - - Entry firstEntry = tableModel.get(entrieSelected[0]); - - String letter = firstEntry.getLettering(); - - List<Entry> entries = financialTransactionService.removeLetter(letter); + public void setDateStart(Date date) { + filter.setDateStart(date); + updateAllEntries(); + } - updateEntries(entries); - } + public void setDateEnd(Date date) { + filter.setDateEnd(date); + updateAllEntries(); + } - onButtonModeChanged(ButtonMode.LETTRED); + public void setAccount(Account account) { + if (filter != null) { + filter.setAccount(account); + updateAllEntries(); } } - - protected void updateEntries(List<Entry> entries) { - - LetteringTableModel tableModel = view.getTableModel(); - - for (final Entry entry : entries) { - - Entry oldEntry = Iterables.find( - tableModel.getValues(), - new Predicate<Entry>() { - @Override - public boolean apply(Entry input) { - return input.getTopiaId().equals(entry.getTopiaId()); - } - }, - null); - - if (oldEntry != null) { - int indexEntry = tableModel.indexOf(oldEntry); - tableModel.setValue(indexEntry, entry); - } + public Account getAccount() { + Account account = null; + if (filter != null) { + account = filter.getAccount(); } + return account; } } diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringEditModel.java b/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringEditModel.java index c400009..57de461 100644 --- a/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringEditModel.java +++ b/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringEditModel.java @@ -25,6 +25,7 @@ import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.io.Serializable; import java.math.BigDecimal; +import java.util.Objects; /** * @author sletellier <letellier@codelutin.com> @@ -69,11 +70,7 @@ public class LetteringEditModel implements Serializable { public void setLettred(boolean lettred) { boolean oldLettrer = isLettred(); - if(lettred && (sold == BigDecimal.ZERO || sold.doubleValue() == 0)){ - this.lettred = lettred; - }else{ - this.lettred = false; - } + this.lettred = lettred && (BigDecimal.ZERO.equals(sold) || sold.doubleValue() == 0); firePropertyChange(PROPERTY_LETTRED, oldLettrer, this.lettred); } @@ -94,7 +91,7 @@ public class LetteringEditModel implements Serializable { public void setDebit(BigDecimal debit) { BigDecimal oldDebit = getDebit(); - if (debit != BigDecimal.ZERO){ + if (!BigDecimal.ZERO.equals(debit)){ this.debit = debit.add(oldDebit); }else{ this.debit = BigDecimal.ZERO; @@ -110,7 +107,7 @@ public class LetteringEditModel implements Serializable { public void setCredit(BigDecimal credit) { BigDecimal oldCredit = getCredit(); - if (credit != BigDecimal.ZERO){ + if (!BigDecimal.ZERO.equals(credit)){ this.credit = credit.add(oldCredit); }else{ this.credit=BigDecimal.ZERO; @@ -126,7 +123,7 @@ public class LetteringEditModel implements Serializable { public void setSolde(BigDecimal solde, boolean credit) { BigDecimal oldSolde = getSold(); - if (solde != BigDecimal.ZERO){ + if (!BigDecimal.ZERO.equals(solde)){ if (credit){ this.sold = oldSolde.subtract(solde); }else{ diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringViewHandler.java b/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringViewHandler.java index fd77b1a..ac264d3 100644 --- a/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringViewHandler.java +++ b/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringViewHandler.java @@ -320,7 +320,7 @@ public class LetteringViewHandler{ for (int i = 0; i < tableModel.getRowCount(); i ++){ if (view.getLetteringSelectionModel().isSelectedIndex(i)){ selectedEntry = tableModel.get(i); - //Set values for calculation (By LetteringEditModel) of balance + //Set values for calculation (By AccountViewerEditModel) of balance onBalanceChanged(selectedEntry); } } @@ -394,37 +394,6 @@ public class LetteringViewHandler{ setTypeEntry(type); } - public void setDateStart(Date date) { - filter.setDateStart(date); - updateAllEntries(); - } - - public void setDateEnd(Date date) { - filter.setDateEnd(date); - updateAllEntries(); - } - - public void setAccount(Account account) { - if (filter != null) { - filter.setAccount(account); - updateAllEntries(); - } - } - - public Account getAccount() { - Account account = null; - if (filter != null) { - account = filter.getAccount(); - } - return account; - } - - public void setTypeEntry(TypeEntry typeEntry) { - filter.setDisplayLettered(typeEntry.isLettered()); - filter.setDisplayUnlettred(typeEntry.isNoLettered()); - updateAllEntries(); - } - public void updateAllEntries() { if (initializationComplete @@ -607,4 +576,36 @@ public class LetteringViewHandler{ } } + + public void setDateStart(Date date) { + filter.setDateStart(date); + updateAllEntries(); + } + + public void setDateEnd(Date date) { + filter.setDateEnd(date); + updateAllEntries(); + } + + public void setAccount(Account account) { + if (filter != null) { + filter.setAccount(account); + updateAllEntries(); + } + } + + public Account getAccount() { + Account account = null; + if (filter != null) { + account = filter.getAccount(); + } + return account; + } + + public void setTypeEntry(TypeEntry typeEntry) { + filter.setDisplayLettered(typeEntry.isLettered()); + filter.setDisplayUnlettred(typeEntry.isNoLettered()); + updateAllEntries(); + } + } diff --git a/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties b/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties index 1bfb522..001c82c 100644 --- a/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties +++ b/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties @@ -13,6 +13,7 @@ lima.account.remove.confirm.title=Delete account lima.account.remove.error.usedAccount=There are financial statement on this account lima.account.update.error.invalidAccountNumber=Invalid account number\: %1$s lima.account.update.form=Update account +lima.accountViewer.previousSold=Solde au %s lima.accounts=Accounts lima.action.commandline.help=Show help in console lima.balance=Balance @@ -132,6 +133,7 @@ lima.documents=Documents… lima.email.support.description=Mail for support lima.email.support.label=support lima.entries=Entries +lima.entries.accountViewer=Account viewer lima.entries.add.entry.error.afterLastFiscalPeriod=Add entry failed, financial transaction date is after last fiscal period date lima.entries.add.entry.error.beforeFirstFiscalPeriod=Add entry failed, financial transaction date is before first fiscal period date lima.entries.add.entry.error.lockedEntryBook=Add entry failed, closed entry book @@ -442,6 +444,7 @@ lima.lettering.account=Accounts lima.lettering.account.aAll=All lima.lettering.account.back=← lima.lettering.account.next=→ +lima.lettering.accountViewerBalanceStatus=<html>From %s to %s\: D\: <b>%s</b> - C\: <b>%s</b> - S\: <b>%s</b> - Selected entries\: D\: <b>%s</b> - C\: <b>%s</b> - S\: <b>%s</b> lima.lettering.balanceStatus= lima.lettering.checkAll=All lima.lettering.checkLettredEntry=Lettered diff --git a/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties b/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties index 54a9304..b3139f1 100644 --- a/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties +++ b/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties @@ -15,6 +15,7 @@ lima.account.remove.confirm.title=Suppression d'un compte lima.account.remove.error.usedAccount=Il exist des transactions sur ce compte lima.account.update.error.invalidAccountNumber=Le numéro du compte %1$s n'est pas valide lima.account.update.form=Modification d'un compte +lima.accountViewer.previousSold=Solde au %s lima.accounts=Comptes lima.action.commandline.help=Afficher l'aide en console lima.balance=Équilibrer @@ -147,6 +148,7 @@ lima.documents=Documents… lima.email.support.description=Adresse email de support lima.email.support.label=support lima.entries=Écritures +lima.entries.accountViewer=Consultation de compte lima.entries.add.entry.error.afterLastFiscalPeriod=Impossible d'ajouter une écriture car la date de la transaction est après le %1$te %1$tB %1$tY fin du dernier exercice. lima.entries.add.entry.error.beforeFirstFiscalPeriod=Impossible d'ajouter une écriture car la date de la transaction est avant le %1$te %1$tB %1$tY début du premier exercice. lima.entries.add.entry.error.lockedEntryBook=Impossible d'ajouter une écriture car le jounal %2$s (%1$s) est cloturé pour la période du %3$te %3$tB %3$tY au %4$te %4$tB %4$tY. @@ -453,6 +455,7 @@ lima.lettering.account=Comptes lima.lettering.account.aAll=TOUS lima.lettering.account.back=← lima.lettering.account.next=→ +lima.lettering.accountViewerBalanceStatus=<html>Pour la période du %s au %s\: D\: <b>%s</b> - C\: <b>%s</b> - S\: <b>%s</b> - Pour la sélection\: D\: <b>%s</b> - C\: <b>%s</b> - S\: <b>%s</b> lima.lettering.balanceStatus=<html>Débit\: <b>%s</b> - Crédit\: <b>%s</b> - Solde\: <b>%s</b> lima.lettering.checkAll=Toutes lima.lettering.checkLettredEntry=Lettrées -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.