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 be7551f6e7856258a874b227f953828366efcca8 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 | 16 +- .../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} | 111 ++-- .../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 ++++ .../ui/accountViewer/AccountViewerViewHandler.java | 588 +++++++++++++++++++++ .../lima/ui/lettering/LetteringEditModel.java | 2 +- .../lima/ui/lettering/LetteringViewHandler.java | 64 +-- .../resources/i18n/lima-swing_en_GB.properties | 4 + .../resources/i18n/lima-swing_fr_FR.properties | 3 + 20 files changed, 1320 insertions(+), 90 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 d46ef99..d653bc8 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 @@ -133,6 +133,22 @@ public interface FinancialTransactionService { List<Entry> getAllUnlockEntriesByFilter(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 9dedbfb..71f5d0d 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 @@ -414,7 +414,7 @@ public class FinancialTransactionServiceImpl extends AbstractLimaService impleme public List<FinancialTransaction> getAllFinancialTransactions(FinancialPeriod financialPeriod, EntryBook entryBook) { List<FinancialTransaction> financialTransactions; - // ici + FinancialTransactionTopiaDao transactionTopiaDao = getDaoHelper().getFinancialTransactionDao(); if (entryBook != null) { @@ -486,6 +486,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 9f5aeef..4f23613 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.HashMap; import java.util.List; @@ -298,6 +299,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 01e22b2..91d18ba 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; @@ -495,6 +496,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 61% 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 ddb2448..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,19 +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 static final String PROPERTY_EDITABLE = "editable"; +public class AccountViewerEditModel implements Serializable { public static final String PROPERTY_DEBIT = "debit"; @@ -39,26 +38,29 @@ public class LetteringEditModel implements Serializable { public static final String PROPERTY_SOLD = "sold"; - public static final String PROPERTY_LETTERED = "lettered"; + public static final String PROPERTY_GLOBAL_SOLD = "globalSold"; + + public static final String PROPERTY_LETTRED = "lettred"; - public static final String PROPERTY_UNLETTERED = "unLettered"; + public static final String PROPERTY_UNLETTRED = "unLettred"; public static final String PROPERTY_EQUALIZED = "equalized"; protected final PropertyChangeSupport pcs = new PropertyChangeSupport(this); - protected LetteringTableModel model; - protected boolean lettered; - protected boolean unLettered; + protected AccountViewerTableModel model; + protected boolean lettred; + protected boolean unLettred; protected boolean equalized; - protected boolean editable; protected BigDecimal debit = BigDecimal.ZERO; protected BigDecimal credit = BigDecimal.ZERO; protected BigDecimal sold = BigDecimal.ZERO; - protected BigDecimal tableDebit = BigDecimal.ZERO; - protected BigDecimal tableCredit = BigDecimal.ZERO; - protected BigDecimal tableSold = 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; @@ -70,24 +72,24 @@ public class LetteringEditModel implements Serializable { firePropertyChange(PROPERTY_EQUALIZED, oldEqualized, this.equalized); } - public boolean isLettered() { - return lettered; + public boolean isLettred() { + return lettred; } - - public void setLettered(boolean lettered) { - boolean oldLettrer = isLettered(); - this.lettered = lettered && (BigDecimal.ZERO.equals(sold) || sold.doubleValue() == 0) && lettered; - firePropertyChange(PROPERTY_LETTERED, oldLettrer, this.lettered); + + 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 isUnLettered() { - return unLettered; + public boolean isUnLettred() { + return unLettred; } - public void setUnLettered(boolean unLettered) { - boolean oldDeletterer = isUnLettered(); - this.unLettered = unLettered; - firePropertyChange(PROPERTY_UNLETTERED, oldDeletterer, this.unLettered); + public void setUnLettred(boolean unLettred) { + boolean oldDeleter = isUnLettred(); + this.unLettred = unLettred; + firePropertyChange(PROPERTY_UNLETTRED, oldDeleter, this.unLettred); } public BigDecimal getDebit() { @@ -99,7 +101,7 @@ public class LetteringEditModel implements Serializable { if (!BigDecimal.ZERO.equals(debit)){ this.debit = debit.add(oldDebit); - } else { + }else{ this.debit = BigDecimal.ZERO; } @@ -115,7 +117,7 @@ public class LetteringEditModel implements Serializable { if (!BigDecimal.ZERO.equals(credit)){ this.credit = credit.add(oldCredit); - } else { + }else{ this.credit=BigDecimal.ZERO; } @@ -126,50 +128,47 @@ public class LetteringEditModel implements Serializable { return sold; } - public void setSold(BigDecimal solde, boolean credit) { + public void setSold(BigDecimal sold, boolean credit) { BigDecimal oldSold = getSold(); - if (!BigDecimal.ZERO.equals(solde)){ + if (!BigDecimal.ZERO.equals(sold)){ if (credit){ - this.sold = oldSold.subtract(solde); - } else { - this.sold = oldSold.add(solde); + this.sold = oldSold.subtract(sold); + }else{ + this.sold = oldSold.add(sold); } - } else { + }else{ this.sold =BigDecimal.ZERO; } firePropertyChange(PROPERTY_SOLD, oldSold, this.sold); } - public BigDecimal getTableDebit() { - return tableDebit; + public BigDecimal getGlobalSold() { + return globalSold; } - public void setTableDebit(BigDecimal tableDebit) { - this.tableDebit = tableDebit; - } + public void setGlobalSold(BigDecimal globalSold) { + BigDecimal oldSold = getGlobalSold(); - public BigDecimal getTableCredit() { - return tableCredit; + this.globalSold = globalSold; + firePropertyChange(PROPERTY_GLOBAL_SOLD, oldSold, this.globalSold); } - public void setTableCredit(BigDecimal tableCredit) { - this.tableCredit = tableCredit; + public BigDecimal getGlobalDebit() { + return globalDebit; } - public BigDecimal getTableSold() { - return tableSold; + public void setGlobalDebit(BigDecimal globalDebit) { + this.globalDebit = globalDebit; } - public void setTableSold(BigDecimal tableSold) { - this.tableSold = tableSold; + public BigDecimal getGlobalCredit() { + return globalCredit; } - public void resetDebitCreditBalance(){ - setDebit(BigDecimal.ZERO); - setCredit(BigDecimal.ZERO); - setSold(BigDecimal.ZERO, false); + public void setGlobalCredit(BigDecimal globalCredit) { + this.globalCredit = globalCredit; } public void addPropertyChangeListener(PropertyChangeListener listener) { @@ -196,13 +195,11 @@ public class LetteringEditModel implements Serializable { firePropertyChange(propertyName, null, newValue); } - public boolean isEditable() { - return editable; + public Date getFiscalPeriodBeginDate() { + return fiscalPeriodBeginDate; } - public void setEditable(boolean editable) { - boolean oldEditable = this.editable; - this.editable = editable; - firePropertyChange(PROPERTY_EDITABLE, oldEditable, this.editable); + 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/accountViewer/AccountViewerViewHandler.java b/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerViewHandler.java new file mode 100644 index 0000000..bf37cb0 --- /dev/null +++ b/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerViewHandler.java @@ -0,0 +1,588 @@ +/* + * #%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 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; +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.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.*; +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; + +import static org.nuiton.i18n.I18n.t; + + +/** + * Handler associated with financial transaction view. + * + * @author chatellier + * @version $Revision$ + * <p/> + * Last update : $Date$ + * By : $Author$ + */ +public class AccountViewerViewHandler { + + // 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; + protected FinancialPeriodService financialPeriodService; + protected AccountService accountService; + protected FinancialTransactionService financialTransactionService; + protected EntryBookService entryBookService; + + protected LetteringFilterImpl filter; + + protected BigDecimal debit = BigDecimal.ZERO; + protected BigDecimal credit = BigDecimal.ZERO; + protected AccountViewerEditModel editModel; + + protected ErrorHelper errorHelper; + + protected enum ButtonMode {DELETTRED, LETTRED, EQUALIZED, ALL} + + protected SimpleDateFormat dateFormatter = new SimpleDateFormat(DATE_FORMAT); + + private static final Log log = LogFactory.getLog(AccountViewerViewHandler.class); + + + protected boolean initializationComplete; + + public AccountViewerViewHandler(AccountViewerView view) { + initializationComplete = false; + this.view = view; + initShortCuts(); + financialPeriodService = LimaServiceFactory.getService(FinancialPeriodService.class); + fiscalPeriodService = LimaServiceFactory.getService(FiscalPeriodService.class); + accountService = LimaServiceFactory.getService(AccountService.class); + financialTransactionService = LimaServiceFactory.getService(FinancialTransactionService.class); + entryBookService = LimaServiceFactory.getService(EntryBookService.class); + errorHelper = new ErrorHelper(LimaSwingConfig.getInstance()); + } + + /** + * Init all combo box in view. + */ + public void init() { + filter = new LetteringFilterImpl(); + editModel = view.getEditModel(); + //lettringSelectionModel = view.getLetteringSelectionModel(); + loadComboAndRows(); + + editModel.addPropertyChangeListener(AccountViewerEditModel.PROPERTY_DEBIT, new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + updateSoldStatus(); + } + }); + + editModel.addPropertyChangeListener(AccountViewerEditModel.PROPERTY_CREDIT, new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + updateSoldStatus(); + } + }); + + 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(); + } + }); + + initializationComplete = true; + updateAllEntries(); + updateSoldStatus(); + } + + public void updateSoldStatus() { + 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); + ActionMap actionMap = view.getActionMap(); + Object binding; + + //To block reaction of the dual key 'ctrl+a' (Selection of all lines) + inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.CTRL_MASK), "none"); + + + // refresh + binding = "refresh"; + inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0), binding); + actionMap.put(binding, new AbstractAction() { + private static final long serialVersionUID = -7192846839712951680L; + + @Override + public void actionPerformed(ActionEvent e) { + updateAllEntries(); + } + }); + } + + 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 fiscal period + FiscalPeriod fiscalPeriod = fiscalPeriodService.getLastFiscalPeriod(); + Date defaultDateBegFiscalPeriod, defaultDateEndCurrent; + + Calendar calendar = Calendar.getInstance(); + int lastCurrentMonthDay = calendar.getActualMaximum(Calendar.DATE); + int firstCurrentMonthDay = calendar.getActualMinimum(Calendar.DATE); + + if (fiscalPeriod != null){ + defaultDateBegFiscalPeriod = fiscalPeriod.getBeginDate(); + defaultDateEndCurrent = fiscalPeriod.getEndDate(); + } else{ + defaultDateBegFiscalPeriod = DateUtils.setDays(new Date(), firstCurrentMonthDay); + defaultDateEndCurrent = DateUtils.setDays(new Date(), lastCurrentMonthDay); + } + + view.getBeginPeriodPicker().setDate(defaultDateBegFiscalPeriod); + view.getEndPeriodPicker().setDate(defaultDateEndCurrent); + + 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"); + } + if (view.getTable().getSelectedRows().length == 0) { + onButtonModeChanged(ButtonMode.ALL); + onBalanceChanged(null); + } else if (!letteringNotExist(view.getTable().getSelectedRow())) { + + //lettred entries + onBalanceChanged(null); + setValuesForSelectedEntries(); + + //For U.I. buttons (Lettering and unlettering) + onButtonModeChanged(ButtonMode.DELETTRED); + } else { + if (log.isDebugEnabled()) { + log.debug("unlettred entries"); + } + int[] selectedRows = view.getTable().getSelectedRows(); + if (selectedRows.length == 2) { + if (log.isDebugEnabled()) { + log.debug("2 rows selected"); + } + /*Treatment only if one of values contains decimals*/ + AccountViewerTableModel tableModel = view.getTableModel(); + Entry firstSelectedEntry = tableModel.get(selectedRows[0]); + Entry secondSelectedEntry = tableModel.get(selectedRows[1]); + + /*Get decimals*/ + BigDecimal firstSelectedEntryAmount = firstSelectedEntry.getAmount(); + BigDecimal secondSelectedEntryAmount = secondSelectedEntry.getAmount(); + + if ( secondSelectedEntry.isDebit() != firstSelectedEntry.isDebit() + && (firstSelectedEntryAmount.subtract(secondSelectedEntryAmount).abs().compareTo(BigDecimal.ZERO) >0 + && firstSelectedEntryAmount.subtract(secondSelectedEntryAmount).abs().compareTo(BigDecimal.ONE) <0) ) { + onButtonModeChanged(ButtonMode.EQUALIZED); + } + }else { + if (log.isDebugEnabled()) { + log.debug("!2 rows selected"); + } + onButtonModeChanged(ButtonMode.ALL); + } + + //Unlettred entries + onBalanceChanged(null); + //treatment unuseful if no rows are selected + if (!view.getAccountViewerSelectionModel().isSelectionEmpty()) { + if (log.isDebugEnabled()) { + log.debug("Rows selected"); + } + setValuesForSelectedEntries(); + onButtonModeChanged(ButtonMode.LETTRED); + } else { + if (log.isDebugEnabled()) { + log.debug("No Rows selected"); + } + onButtonModeChanged(ButtonMode.ALL); + } + } + } + + /**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 = false; + if (row != -1) { + Entry entry = view.getTableModel().get(row); + String lettering = entry.getLettering(); + emptyOrNull = (lettering==null||lettering.isEmpty()); + } + return emptyOrNull; + } + + public void onButtonModeChanged(ButtonMode buttonMode) { + + switch (buttonMode) { + case DELETTRED : + editModel.setLettred(false); + editModel.setUnLettred(true); + break; + case LETTRED: + editModel.setUnLettred(false); + editModel.setLettred(true); + break; + case EQUALIZED: + editModel.setEqualized(true); + break; + default: + editModel.setLettred(false); + editModel.setUnLettred(false); + editModel.setEqualized(false); + } + } + + public void setValuesForSelectedEntries() { + Entry selectedEntry; + AccountViewerTableModel tableModel = view.getTableModel(); + for (int i = 0; i < tableModel.getRowCount(); i ++){ + if (view.getAccountViewerSelectionModel().isSelectedIndex(i)){ + selectedEntry = tableModel.get(i); + //Set values for calculation (By AccountViewerEditModel) of balance + onBalanceChanged(selectedEntry); + } + } + } + + public void onBalanceChanged(Entry balance) { + if (balance == null) { + editModel.setCredit(BigDecimal.ZERO); + editModel.setDebit(BigDecimal.ZERO); + editModel.setSold(BigDecimal.ZERO, false); + } else { + balanceCalculation(balance.getAmount(), balance.isDebit()); + } + } + + /**Allow to add / subtract credit / debit and balance + * @param amount debit or credit + * @param debit it indicate if amount is debit or not + * */ + public void balanceCalculation(BigDecimal amount, boolean debit){ + + BigDecimal debitVal = debit ? amount : BigDecimal.ZERO; + BigDecimal creditVal = debit ? BigDecimal.ZERO : amount; + + if (log.isDebugEnabled()) { + log.debug("balance calculation"); + } + + if (debitVal.equals(BigDecimal.ZERO)){ + + if (!creditVal.equals(BigDecimal.ZERO)){ + + editModel.setCredit(creditVal); + editModel.setSold(creditVal, true); + } + }else if (creditVal.equals(BigDecimal.ZERO)){ + editModel.setDebit(debitVal); + editModel.setSold(debitVal, false); + }else{ + onBalanceChanged(null); + } + } + + protected Calendar getDayMinus1Calendar(LetteringFilter previousPeriodFilter) { + Calendar cal = Calendar.getInstance(); + cal.setTime(previousPeriodFilter.getDateEnd()); + cal.add(Calendar.DATE, -1); + return cal; + } + + protected LetteringFilter computePreviousPeriodFilter(FiscalPeriod fiscalPeriod) { + LetteringFilter previousPeriodFilter = null; + + if (fiscalPeriod != null) { + previousPeriodFilter = new LetteringFilterImpl(); + previousPeriodFilter.setDateStart(fiscalPeriod.getBeginDate()); + previousPeriodFilter.setDateEnd(filter.getDateStart()); + previousPeriodFilter.setAccount(filter.getAccount()); + } + + return previousPeriodFilter; + } + + private LetteringFilter computeActualPeriodFilter(FiscalPeriod fiscalPeriod) { + LetteringFilter actualPeriodFilter = null; + + if (fiscalPeriod != null) { + actualPeriodFilter = new LetteringFilterImpl(); + actualPeriodFilter.setDateStart(fiscalPeriod.getBeginDate()); + actualPeriodFilter.setDateEnd(filter.getDateEnd()); + actualPeriodFilter.setAccount(filter.getAccount()); + } + + return actualPeriodFilter; + } + + public void accountComboBoxChange(PropertyChangeEvent event) { + if (event.getPropertyName().equals(AccountComboBox.PROPERTY_SELECTED_ITEM)) { + if (event.getNewValue() != null && event.getNewValue() instanceof Account) { + setAccount((Account) event.getNewValue()); + } + } + } + + /** + * Select previous value in combo box. + * + * @param accountComboBox account combo box + */ + public void back(AccountComboBox accountComboBox) { + JComboBox comboBox = accountComboBox.getCombobox(); + int row = comboBox.getSelectedIndex(); + + if (row > 0) { + comboBox.setSelectedIndex(row - 1); + } + view.getAccountViewerSelectionModel().clearSelection(); + } + + /** + * Select next value in combo box. + * + * @param accountComboBox combo box + */ + public void next(AccountComboBox accountComboBox) { + JComboBox comboBox = accountComboBox.getCombobox(); + int size = comboBox.getItemCount(); + int row = comboBox.getSelectedIndex(); + + if (row < size - 1) { + comboBox.setSelectedIndex(row + 1); + } + view.getAccountViewerSelectionModel().clearSelection(); + } + + private class DebitCreditSold { + private BigDecimal debit; + private BigDecimal credit; + private BigDecimal sold; + + public BigDecimal getDebit() { + return debit; + } + + public BigDecimal getCredit() { + return credit; + } + + public BigDecimal getSold() { + return sold; + } + + 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]; + } + } + } + + sold = debit.subtract(credit); + return this; + } + } + + 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; + } + +} 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 ddb2448..d75c09c 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 @@ -73,7 +73,7 @@ public class LetteringEditModel implements Serializable { public boolean isLettered() { return lettered; } - + public void setLettered(boolean lettered) { boolean oldLettrer = isLettered(); this.lettered = lettered && (BigDecimal.ZERO.equals(sold) || sold.doubleValue() == 0) && lettered; 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 9ea521d..a4ce176 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 @@ -79,6 +79,7 @@ import static org.nuiton.i18n.I18n.t; public class LetteringViewHandler{ protected LetteringView view; + protected LetteringTable table; /** Transaction service. */ protected FiscalPeriodService fiscalPeriodService; @@ -438,37 +439,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 @@ -654,4 +624,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 8a40152..2dfea3c 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 @@ -14,6 +14,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 @@ -133,6 +134,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 @@ -449,6 +451,8 @@ 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.balanceStatus=<html>Debit\: <b>%s</b> - Credit\: <b>%s</b> - Sold\: <b>%s</b>. Selected entries\: Debit\: <b>%s</b> - Credit\: <b>%s</b> - Sold\: <b>%s</b> 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 133a4af..a9baa5b 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 @@ -17,6 +17,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 @@ -149,6 +150,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. @@ -461,6 +463,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>. Entrées sélectionnées\: 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>.