branch feature/1293-addAccountViewerTab updated (2ab9213 -> ee5abac)
This is an automated email from the git hooks/post-receive script. New change to branch feature/1293-addAccountViewerTab in repository lima. See http://git.chorem.org/lima.git discards 2ab9213 refs #1293 correction traductions discards 6ad63d4 refs #1268 déplacement de donnés liées au model de l'handler au model et suppression de listener innutils discards 95e3469 refs #1268 déplacement des models du jaxx au handler discards 0481433 refs #1293 Correction i18n discards 929d02f refs #1293 corrige exception dans le cas ou aucune periode financière existe avec la date choisie discards 96ee941 refs #1293 corrections pour le cas ou aucune données existe dans Lima discards c213b6a refs #1293 corrections et refactoring discards 9a9ae12 refs #1293 refactoring et modification du calcul du sold précédent à l'année fiscale discards 9e98c25 refs #1293 modification concernnt l'affichage des infos résumées discards 58a1819 refs #1293 correction i18n discards d9cbfd8 refs #1293 Ajout de la possibilité de choisir une consultation de compte pour un exercice, une période financière ou un interval de dates discards a8f5dec refs #1293 refactoring, modification de style discards 3802dc7 refs #1293 Traduction des dates pickers discards 2d04e68 refs #1293 Correction sur les dates pickers et la recherche de compte appliquée égallement à l'onglet Lettering discards 32dbaf1 refs #1293 Correction d'une exception survenant si un nom de compte est saisie est que aucun compte ne correspond discards f0c6fc6 refs #1293 la validation des dates des date pickers est possible au Tab discards 234fe5b refs #1241 Ajout de la possibilité de choisir entre deux modes de sélection des entrées (Manuelle ou Balancée) discards d1326c2 refs #1241 Ajout de la possibilité de choisir entre deux modes de sélection des entrées (Manuelle ou Balancée) + Ajout d'icones discards be7551f refs #1241 Ajout d'un oglet consultation de compte, travail en cours adds a47f485 refs #1182 Ajout de traductions adds 98ca966 refs #1182 Traduction des dates pickers adds e9ea36e refs #1182 rétablit le fonctionnement des datepicker sur interval adds 25b8310 Merge branch 'feature/1182-translation' into develop new a859874 refs #1241 Ajout d'un oglet consultation de compte, travail en cours new 67b47c2 refs #1241 Ajout de la possibilité de choisir entre deux modes de sélection des entrées (Manuelle ou Balancée) + Ajout d'icones new b5244af refs #1241 Ajout de la possibilité de choisir entre deux modes de sélection des entrées (Manuelle ou Balancée) new df5f528 refs #1293 la validation des dates des date pickers est possible au Tab new da320f5 refs #1293 Correction d'une exception survenant si un nom de compte est saisie est que aucun compte ne correspond new 45b2d0c refs #1293 Correction sur les dates pickers et la recherche de compte appliquée égallement à l'onglet Lettering new 147c7cf refs #1293 Traduction des dates pickers new d746f2e refs #1293 refactoring, modification de style new 367ef5f refs #1293 Ajout de la possibilité de choisir une consultation de compte pour un exercice, une période financière ou un interval de dates new 7b3c5c4 refs #1293 correction i18n new f6b8fc9 refs #1293 modification concernnt l'affichage des infos résumées new 0885bc3 refs #1293 refactoring et modification du calcul du sold précédent à l'année fiscale new 27350cb refs #1293 corrections et refactoring new 9f4bbb3 refs #1293 corrections pour le cas ou aucune données existe dans Lima new a2e5011 refs #1293 corrige exception dans le cas ou aucune periode financière existe avec la date choisie new 7ceeed6 refs #1293 Correction i18n new 59ea9a6 refs #1268 déplacement des models du jaxx au handler new e137b42 refs #1268 déplacement de donnés liées au model de l'handler au model et suppression de listener innutils new ee5abac refs #1293 correction traductions This update added new revisions after undoing existing revisions. That is to say, some revisions that were in the old version of the branch are not in the new version. This situation occurs when a user --force pushes a change and generates a repository containing something like this: * -- * -- B -- O -- O -- O (2ab9213) \ N -- N -- N refs/heads/feature/1293-addAccountViewerTab (ee5abac) You should already have received notification emails for all of the O revisions, and so the following emails describe only the N revisions from the common base, B. Any revisions marked "omits" are not gone; other references still refer to them. Any revisions marked "discards" are gone forever. The 19 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit ee5abac225ee24638091826aac1a7460eb11cf7c Author: dcosse <cosse@codelutin.com> Date: Mon Nov 30 14:13:39 2015 +0100 refs #1293 correction traductions commit e137b426c073b9b24fbcca224d770c404bf5e7a2 Author: dcosse <cosse@codelutin.com> Date: Wed Sep 30 15:30:48 2015 +0200 refs #1268 déplacement de donnés liées au model de l'handler au model et suppression de listener innutils commit 59ea9a6396f07ce8e2fabb11f3e842dc0a1322ba Author: dcosse <cosse@codelutin.com> Date: Wed Sep 30 14:49:39 2015 +0200 refs #1268 déplacement des models du jaxx au handler commit 7ceeed60dfc471af1dd7c1da4fbf0a9139dfee2d Author: dcosse <cosse@codelutin.com> Date: Fri Sep 25 13:08:29 2015 +0200 refs #1293 Correction i18n commit a2e5011e898db21f4fd3816479a87c8d4224abfb Author: dcosse <cosse@codelutin.com> Date: Fri Sep 25 13:05:56 2015 +0200 refs #1293 corrige exception dans le cas ou aucune periode financière existe avec la date choisie commit 9f4bbb3d2f8fce6ff5828f088f32a442e23be8bf Author: dcosse <cosse@codelutin.com> Date: Thu Sep 24 14:19:40 2015 +0200 refs #1293 corrections pour le cas ou aucune données existe dans Lima commit 27350cb95bc35003e593a4b87bc826fbaaf8783e Author: dcosse <cosse@codelutin.com> Date: Thu Sep 24 12:54:04 2015 +0200 refs #1293 corrections et refactoring commit 0885bc333ef6679cd4c1d4efaff519e53b076554 Author: dcosse <cosse@codelutin.com> Date: Wed Sep 23 22:05:15 2015 +0200 refs #1293 refactoring et modification du calcul du sold précédent à l'année fiscale commit f6b8fc906f1c1e7b278937a7db9f007fc73f3f04 Author: dcosse <cosse@codelutin.com> Date: Tue Sep 22 17:58:13 2015 +0200 refs #1293 modification concernnt l'affichage des infos résumées commit 7b3c5c4c771ed690e6d0b5b128c1c6a0e81c4ff1 Author: dcosse <cosse@codelutin.com> Date: Sun Sep 20 00:49:12 2015 +0200 refs #1293 correction i18n commit 367ef5f73641745d3e01ddf924c1fdbe0e64b7f5 Author: dcosse <cosse@codelutin.com> Date: Sun Sep 20 00:38:53 2015 +0200 refs #1293 Ajout de la possibilité de choisir une consultation de compte pour un exercice, une période financière ou un interval de dates commit d746f2e8189d16b4b199b3f9a9bbb49374e7e3b3 Author: dcosse <cosse@codelutin.com> Date: Fri Sep 18 10:27:41 2015 +0200 refs #1293 refactoring, modification de style commit 147c7cf1e84787f1be2104d64c1e98650e05b430 Author: dcosse <cosse@codelutin.com> Date: Wed Sep 16 22:11:13 2015 +0200 refs #1293 Traduction des dates pickers commit 45b2d0cea148f951111be8ef416340102595ae10 Author: dcosse <cosse@codelutin.com> Date: Tue Sep 15 17:18:09 2015 +0200 refs #1293 Correction sur les dates pickers et la recherche de compte appliquée égallement à l'onglet Lettering commit da320f57171272aa349278907a6fefd680b40b89 Author: dcosse <cosse@codelutin.com> Date: Tue Sep 15 16:59:42 2015 +0200 refs #1293 Correction d'une exception survenant si un nom de compte est saisie est que aucun compte ne correspond commit df5f528d4e5658e8bcc3cfad5098985a59b4c9a7 Author: dcosse <cosse@codelutin.com> Date: Tue Sep 15 16:57:35 2015 +0200 refs #1293 la validation des dates des date pickers est possible au Tab commit b5244af9b7826be056f755dc15a769b55b804f5a Author: dcosse <cosse@codelutin.com> Date: Tue Sep 15 15:56:35 2015 +0200 refs #1241 Ajout de la possibilité de choisir entre deux modes de sélection des entrées (Manuelle ou Balancée) commit 67b47c26bb7f1ed3fe261f2a42610f2e10add33a Author: dcosse <cosse@codelutin.com> Date: Tue Sep 15 15:14:19 2015 +0200 refs #1241 Ajout de la possibilité de choisir entre deux modes de sélection des entrées (Manuelle ou Balancée) + Ajout d'icones commit a859874cfbf510506da4d7ecc027db9ad92b2b71 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 Summary of changes: .../Filter/dateCondition/DateConditionHandler.java | 19 ++- .../ui/Filter/dateCondition/DateConditionView.jaxx | 5 +- .../DateIntervalConditionHandler.java | 19 ++- .../DateIntervalConditionView.jaxx | 6 +- .../ui/celleditor/DateLimaTableCellRenderer.java | 4 +- .../lima/ui/celleditor/DateTableCellEditor.java | 154 --------------------- .../chorem/lima/ui/common/AbstractLimaTable.java | 2 - .../chorem/lima/ui/lettering/LetteringView.jaxx | 9 +- .../lima/ui/lettering/LetteringViewHandler.java | 13 +- .../resources/i18n/lima-swing_en_GB.properties | 2 +- 10 files changed, 56 insertions(+), 177 deletions(-) delete mode 100644 lima-swing/src/main/java/org/chorem/lima/ui/celleditor/DateTableCellEditor.java -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
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 a859874cfbf510506da4d7ecc027db9ad92b2b71 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 | 63 +-- .../resources/i18n/lima-swing_en_GB.properties | 4 + .../resources/i18n/lima-swing_fr_FR.properties | 3 + 20 files changed, 1319 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 dedc44d..77db344 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 @@ -440,37 +440,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 @@ -656,6 +625,38 @@ 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(); + } + protected DateFormat getDateFormat() { Locale locale = LimaSwingConfig.getInstance().getLocale(); DateFormat result = DateFormat.getDateInstance(DateFormat.SHORT, locale); 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 76d6b08..4de6b2d 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>.
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 0885bc333ef6679cd4c1d4efaff519e53b076554 Author: dcosse <cosse@codelutin.com> Date: Wed Sep 23 22:05:15 2015 +0200 refs #1293 refactoring et modification du calcul du sold précédent à l'année fiscale --- .../lima/business/api/FiscalPeriodService.java | 6 + .../lima/business/ejb/FiscalPeriodServiceImpl.java | 10 + .../ui/accountViewer/AccountViewerEditModel.java | 43 +-- .../lima/ui/accountViewer/AccountViewerView.jaxx | 2 +- .../ui/accountViewer/AccountViewerViewHandler.java | 311 +++++++++++++-------- .../resources/i18n/lima-swing_en_GB.properties | 1 + .../resources/i18n/lima-swing_fr_FR.properties | 1 + 7 files changed, 221 insertions(+), 153 deletions(-) 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 4e0c812..0ba0865 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 @@ -78,6 +78,12 @@ public interface FiscalPeriodService { /** * + * @return first fiscal Period + */ + FiscalPeriod getFirstFiscalPeriod(); + + /** + * * @return last fiscal period */ FiscalPeriod getLastFiscalPeriod(); 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 40504d6..ff04a1c 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 @@ -212,6 +212,16 @@ public class FiscalPeriodServiceImpl extends AbstractLimaService implements Fisc } @Override + public FiscalPeriod getFirstFiscalPeriod() { + + FiscalPeriodTopiaDao fiscalPeriodTopiaDao = getDaoHelper().getFiscalPeriodDao(); + //get the last fiscal period + FiscalPeriod result = fiscalPeriodTopiaDao.forAll().setOrderByArguments(FiscalPeriod.PROPERTY_BEGIN_DATE + " ASC").findFirstOrNull(); + + return result; + } + + @Override public FiscalPeriod getLastFiscalPeriod() { FiscalPeriodTopiaDao fiscalPeriodTopiaDao = getDaoHelper().getFiscalPeriodDao(); diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerEditModel.java b/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerEditModel.java index 57accc3..3399584 100644 --- a/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerEditModel.java +++ b/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerEditModel.java @@ -25,7 +25,6 @@ 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> @@ -48,12 +47,6 @@ public class AccountViewerEditModel 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 BigDecimal getDebit() { return debit; } @@ -106,33 +99,6 @@ public class AccountViewerEditModel implements Serializable { 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 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) { pcs.addPropertyChangeListener(listener); } @@ -156,12 +122,5 @@ public class AccountViewerEditModel 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/AccountViewerView.jaxx b/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerView.jaxx index e394d6c..d03a614 100644 --- 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 @@ -102,7 +102,7 @@ onItemStateChanged="handler.onSelectionModeChanged(letteredSelectionMode.getSelectedItem())"/> <JButton id="refresh" - onActionPerformed="handler.updateAllEntries(null)"/> + onActionPerformed="handler.updateAllEntries()"/> </JToolBar> <JPanel layout="{new BorderLayout()}" 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 index f1450f5..2c120dd 100644 --- 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 @@ -47,6 +47,7 @@ import org.chorem.lima.util.ErrorHelper; import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.InputEvent; +import java.awt.event.ItemEvent; import java.awt.event.KeyEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; @@ -54,6 +55,7 @@ import java.math.BigDecimal; import java.text.DateFormat; import java.util.Calendar; import java.util.Date; +import java.util.Iterator; import java.util.List; import java.util.Locale; @@ -112,8 +114,7 @@ public class AccountViewerViewHandler { public void init() { filter = new AccountViewerFilter(); editModel = view.getEditModel(); - initFiscalPeriodView(); - initDefaultFinancialPeriodView(); + updateFinancialPeriodView(null); initSoldPeriodView(); editModel.addPropertyChangeListener(AccountViewerEditModel.PROPERTY_DEBIT, new PropertyChangeListener() { @@ -172,7 +173,7 @@ public class AccountViewerViewHandler { @Override public void actionPerformed(ActionEvent e) { - updateAllEntries(null); + updateAllEntries(); } }); } @@ -190,31 +191,43 @@ public class AccountViewerViewHandler { filter.setPeriodChoice(periodChoice); switch (periodChoice) { case FINANCIAL_PERIOD: - view.getFiscalPeriodComboBox().setVisible(true); - view.getFinancialPeriodComboBox().setVisible(true); - view.getBeginPeriodPicker().setVisible(false); - view.getEndPeriodPicker().setVisible(false); - initDefaultFinancialPeriodView(); + initViewForPeriodChoiceChange(true, true, false); + updateAllEntriesForFinancialPeriodChoice(); break; case FISCAL_PERIOD: - view.getFiscalPeriodComboBox().setVisible(true); - view.getFinancialPeriodComboBox().setVisible(false); - view.getBeginPeriodPicker().setVisible(false); - view.getEndPeriodPicker().setVisible(false); - initFiscalPeriodView(); + initViewForPeriodChoiceChange(true, false, false); + updateAllEntriesForFiscalPeriodChoice(); break; case DATE: - view.getFiscalPeriodComboBox().setVisible(false); - view.getFinancialPeriodComboBox().setVisible(false); - view.getBeginPeriodPicker().setVisible(true); - view.getEndPeriodPicker().setVisible(true); - initDateIntervalView(); + initViewForPeriodChoiceChange(false, false, true); + updateAllEntriesForDateIntervalChoice(); break; } - updateAllEntries(null); } } + private void initViewForPeriodChoiceChange(boolean isFiscalPeriodComboBoxVisible, boolean isFinancialPeriodComboBoxVisible, boolean isPeriodPickersVisible) { + view.getFiscalPeriodComboBox().setVisible(isFiscalPeriodComboBoxVisible); + view.getFinancialPeriodComboBox().setVisible(isFinancialPeriodComboBoxVisible); + view.getBeginPeriodPicker().setVisible(isPeriodPickersVisible); + view.getEndPeriodPicker().setVisible(isPeriodPickersVisible); + } + + private void updateAllEntriesForDateIntervalChoice() { + initDateIntervalView(); + updateAllEntries(); + } + + private void updateAllEntriesForFiscalPeriodChoice() { + initFiscalPeriodView(); + updateAllEntriesForFiscalPeriodChoice(fiscalPeriodService.getLastFiscalPeriod()); + } + + private void updateAllEntriesForFinancialPeriodChoice() { + updateFinancialPeriodView(filter.getFiscalPeriod()); + updateAllEntries(); + } + /** * Select previous value in combo box. * @@ -250,27 +263,29 @@ public class AccountViewerViewHandler { } } - protected void onFiscalPeriodChange(java.awt.event.ItemEvent event) { - FiscalPeriod fiscalPeriod = (FiscalPeriod) event.getItem(); - if (initializationComplete && filter.getFiscalPeriod() != fiscalPeriod) { - filter.setFiscalPeriod(fiscalPeriod); + protected void onFiscalPeriodChange(ItemEvent event) { + FiscalPeriod selectedFiscalPeriod = event != null && event.getItem() != null ? (FiscalPeriod) event.getItem() : null; + if (initializationComplete && selectedFiscalPeriod != null && !selectedFiscalPeriod.equals(filter.getFiscalPeriod())) { - //FISCAL_PERIOD - if (PeriodChoice.FISCAL_PERIOD.equals(view.getPeriodChoice().getSelectedItem())) { - updateAllEntriesForFiscalPeriodChange(fiscalPeriod); - } else { - //FINANCIAL_PERIOD - initDefaultFinancialPeriodView(); - } + List<FinancialPeriod> periods = financialPeriodService.getFinancialPeriodsWithBeginDateWithin(selectedFiscalPeriod.getBeginDate(), selectedFiscalPeriod.getEndDate()); + FinancialPeriod selectedFinancialPeriod = periods.get(0); + view.getFinancialPeriodComboBoxModel().setObjects(periods); + view.getFinancialPeriodComboBoxModel().setSelectedItem(selectedFinancialPeriod); + + filter.setDateStart(selectedFinancialPeriod.getBeginDate()); + filter.setDateEnd(selectedFinancialPeriod.getEndDate()); + filter.setFiscalPeriod(selectedFiscalPeriod); + filter.setFinancialPeriod(selectedFinancialPeriod); + filter.setPeriodChoice(PeriodChoice.FINANCIAL_PERIOD); + updateAllEntries(); } } - protected void onFinancialPeriodChange(java.awt.event.ItemEvent event) { FinancialPeriod financialPeriod = (FinancialPeriod) event.getItem(); - if (initializationComplete && filter.getFinancialPeriod() != financialPeriod) { + if (initializationComplete && !filter.getFinancialPeriod().equals(financialPeriod)) { filter.setFinancialPeriod(financialPeriod); - updateAllEntriesForFinancialPeriodChange(financialPeriod); + updateAllEntriesForFinancialPeriodChoice(financialPeriod); } } @@ -278,9 +293,10 @@ public class AccountViewerViewHandler { if (initializationComplete) { if (date != null && !DateUtils.isSameDay(date, filter.getDateStart())) { filter.setDateStart(date); + if (filter.getDateEnd().before(date)) { - filter.setDateEnd(filter.getDateEnd().before(date) ? date : filter.getDateEnd()); - view.getEndPeriodPicker().setDate(filter.getDateEnd()); + filter.setDateEnd(date); + view.getEndPeriodPicker().setDate(date); } updateAllEntriesForDateChange(); } @@ -291,6 +307,10 @@ public class AccountViewerViewHandler { if (initializationComplete) { if (date != null && !DateUtils.isSameDay(date, filter.getDateEnd())) { filter.setDateEnd(date); + if (filter.getDateStart().after(date)) { + filter.setDateStart(date); + view.getBeginPeriodPicker().setDate(date); + } updateAllEntriesForDateChange(); } } @@ -320,52 +340,132 @@ public class AccountViewerViewHandler { } - public void updateAllEntriesForFiscalPeriodChange(FiscalPeriod fiscalPeriod) { - if (!DateUtils.isSameDay(fiscalPeriod.getBeginDate(), filter.getDateStart()) || - !DateUtils.isSameDay(fiscalPeriod.getEndDate(), filter.getDateEnd())) { - filter.setDateStart(fiscalPeriod.getBeginDate()); - filter.setDateEnd(fiscalPeriod.getEndDate()); - - updateAllEntries(fiscalPeriod); - } + public void updateAllEntriesForFiscalPeriodChoice(FiscalPeriod fiscalPeriod) { + filter.setFiscalPeriod(fiscalPeriod); + filter.setDateStart(fiscalPeriod.getBeginDate()); + filter.setDateEnd(fiscalPeriod.getEndDate()); + filter.setPeriodChoice(PeriodChoice.FISCAL_PERIOD); + updateAllEntries(); } - public void updateAllEntriesForFinancialPeriodChange(FinancialPeriod financialPeriod) { - if (!DateUtils.isSameDay(financialPeriod.getBeginDate(), filter.getDateStart()) || - !DateUtils.isSameDay(financialPeriod.getEndDate(), filter.getDateEnd())) { - filter.setDateStart(financialPeriod.getBeginDate()); - filter.setDateEnd(financialPeriod.getEndDate()); + public void updateAllEntriesForFinancialPeriodChoice(FinancialPeriod financialPeriod) { + filter.setDateStart(financialPeriod.getBeginDate()); + filter.setDateEnd(financialPeriod.getEndDate()); + filter.setPeriodChoice(PeriodChoice.FINANCIAL_PERIOD); + updateAllEntries(); - updateAllEntries(null); - } } public void updateAllEntriesForDateChange() { - updateAllEntries(null); + filter.setPeriodChoice(PeriodChoice.DATE); + filter.setFiscalPeriod(fiscalPeriodService.getFiscalPeriodForDate(filter.getDateStart())); + updateAllEntries(); } - public void updateAllEntries(FiscalPeriod fiscalPeriod) { + public void updateAllEntries() { if (initializationComplete && filter.getAccount() != null && filter.getDateStart() != null && filter.getDateEnd() != null) { List<Entry> entries = financialTransactionService.getAllEntrieByDatesAndAccountAndLettering(filter); - fiscalPeriod = fiscalPeriod == null ? fiscalPeriodService.getFiscalPeriodForDate(filter.getDateStart()) : fiscalPeriod; - LetteringFilter previousPeriodFilter = computePreviousPeriodFilter(fiscalPeriod); - LetteringFilter actualPeriodFilter = computeActualPeriodFilter(fiscalPeriod); - setViewPreviousSold(previousPeriodFilter); - setViewActualSold(fiscalPeriod, actualPeriodFilter); - view.getTableModel().setValues(entries); + + updateSummary(); } onBalanceChanged(null); } + protected void updateSummary() { + PeriodChoice periodChoice = filter.getPeriodChoice(); + LetteringFilter previousPeriodFilter = computePreviousPeriodFilter(periodChoice); + LetteringFilter actualPeriodFilter = computeActualPeriodFilter(periodChoice); + setViewPreviousSold(previousPeriodFilter); + setViewActualSold(actualPeriodFilter); + } + + protected LetteringFilter computePreviousPeriodFilter(PeriodChoice periodChoice) { + LetteringFilter previousPeriodFilter = null; + FiscalPeriod previousFiscalPeriod; + Date dateStart = null, dateEnd = null; + switch (periodChoice) { + case FINANCIAL_PERIOD: + Date financialPeriodDate = filter.getFinancialPeriod().getBeginDate(); + FiscalPeriod fiscalPeriodFiscalPeriod = fiscalPeriodService.getFiscalPeriodForDate(financialPeriodDate); + dateStart = fiscalPeriodFiscalPeriod.getBeginDate(); + dateEnd = getDayMinus1Calendar(financialPeriodDate).getTime(); + break; + case FISCAL_PERIOD: + previousFiscalPeriod = fiscalPeriodService.getFiscalPeriodForDate(getDayMinus1Calendar(filter.getFiscalPeriod().getBeginDate()).getTime()); + if (previousFiscalPeriod != null) { + dateStart = previousFiscalPeriod.getBeginDate(); + dateEnd = previousFiscalPeriod.getEndDate(); + } + break; + case DATE: + previousFiscalPeriod = filter.getFiscalPeriod(); + + if (previousFiscalPeriod != null && DateUtils.isSameDay(previousFiscalPeriod.getBeginDate(), filter.getDateStart())) { + previousFiscalPeriod = fiscalPeriodService.getFiscalPeriodForDate(getDayMinus1Calendar(filter.getDateStart()).getTime()); + } + + if (previousFiscalPeriod == null) { + FiscalPeriod lastFiscalPeriod = fiscalPeriodService.getLastFiscalPeriod(); + previousFiscalPeriod = lastFiscalPeriod != null && lastFiscalPeriod.getEndDate().before(filter.getDateStart()) ? lastFiscalPeriod : null; + } + + if (previousFiscalPeriod != null) { + dateStart = previousFiscalPeriod.getBeginDate(); + dateEnd = getDayMinus1Calendar(filter.getDateStart()).getTime(); + } + break; + } + + if (dateStart != null && dateEnd != null) { + previousPeriodFilter = new LetteringFilterImpl(); + previousPeriodFilter.setDateStart(dateStart); + previousPeriodFilter.setDateEnd(dateEnd); + previousPeriodFilter.setAccount(filter.getAccount()); + } + + return previousPeriodFilter; + } + + private LetteringFilter computeActualPeriodFilter(PeriodChoice choice) { + LetteringFilter actualPeriodFilter = null; + Date dateStart = null, dateEnd = null; + switch (choice) { + case FINANCIAL_PERIOD: + if (filter.getFinancialPeriod() != null) { + Date financialPeriodDate = filter.getFinancialPeriod().getBeginDate(); + FiscalPeriod fiscalPeriodFiscalPeriod = fiscalPeriodService.getFiscalPeriodForDate(financialPeriodDate); + dateStart = fiscalPeriodFiscalPeriod.getBeginDate(); + dateEnd = filter.getFinancialPeriod().getEndDate(); + } + break; + case FISCAL_PERIOD: + dateStart = filter.getFiscalPeriod() == null ? null : filter.getFiscalPeriod().getBeginDate(); + dateEnd = filter.getFiscalPeriod() == null ? null : filter.getFiscalPeriod().getEndDate(); + break; + case DATE: + dateStart = filter.getFiscalPeriod() == null ? filter.getDateStart() : filter.getFiscalPeriod().getBeginDate(); + dateEnd = filter.getDateEnd(); + break; + } + if (dateStart != null && dateEnd != null) { + actualPeriodFilter = new LetteringFilterImpl(); + actualPeriodFilter.setDateStart(dateStart); + actualPeriodFilter.setDateEnd(dateEnd); + actualPeriodFilter.setAccount(filter.getAccount()); + } + return actualPeriodFilter; + } + public void initFiscalPeriodView() { List<FiscalPeriod> fiscalPeriods = fiscalPeriodService.getAllFiscalPeriods(); view.getFiscalPeriodComboBoxModel().setObjects(fiscalPeriods); + filter.setPeriodChoice(PeriodChoice.FISCAL_PERIOD); FiscalPeriod fiscalPeriod = fiscalPeriodService.getLastFiscalPeriod(); if (fiscalPeriod != null) { filter.setFiscalPeriod(fiscalPeriod); @@ -393,23 +493,24 @@ public class AccountViewerViewHandler { } } - public void initDefaultFinancialPeriodView() { - FiscalPeriod fiscalPeriod = (FiscalPeriod) view.getFiscalPeriodComboBox().getSelectedItem(); + public void updateFinancialPeriodView(FiscalPeriod fiscalPeriodO) { + FiscalPeriod fiscalPeriod = fiscalPeriodO == null ? fiscalPeriodService.getLastFiscalPeriod() : fiscalPeriodO; FinancialPeriod defaultFinancialPeriod = null; if (fiscalPeriod != null) { List<FinancialPeriod> financialPeriods = financialPeriodService.getFinancialPeriodsWithBeginDateWithin(fiscalPeriod.getBeginDate(), fiscalPeriod.getEndDate()); view.getFinancialPeriodComboBoxModel().setObjects(financialPeriods); - - boolean isCurrentDatePartOfSelectedFiscalPeriod; Date today = new Date(); - isCurrentDatePartOfSelectedFiscalPeriod = fiscalPeriod.getBeginDate().before(today) && (fiscalPeriod.getEndDate().after(today)); - if (isCurrentDatePartOfSelectedFiscalPeriod) { - defaultFinancialPeriod = financialPeriodService.getFinancialForDate(today); - } else if (!financialPeriods.isEmpty()) { - defaultFinancialPeriod = financialPeriods.get(financialPeriods.size() - 1); + + Iterator<FinancialPeriod> financialPeriodIterator = financialPeriods.iterator(); + while (financialPeriodIterator.hasNext() && defaultFinancialPeriod == null) { + FinancialPeriod financialPeriod = financialPeriodIterator.next(); + defaultFinancialPeriod = financialPeriod.getBeginDate().before(today) && financialPeriod.getEndDate().after(today) ? financialPeriod : null; } + defaultFinancialPeriod = defaultFinancialPeriod != null ? defaultFinancialPeriod : financialPeriods.get(financialPeriods.size() - 1); view.getFinancialPeriodComboBoxModel().setSelectedItem(defaultFinancialPeriod); + + initFiscalPeriodCombo(); } Date defaultDateBegin, defaultDateEnd; @@ -421,41 +522,50 @@ public class AccountViewerViewHandler { filter.setDateStart(defaultDateBegin); filter.setDateEnd(defaultDateEnd); + filter.setFiscalPeriod(fiscalPeriod); + filter.setFinancialPeriod(defaultFinancialPeriod); + filter.setPeriodChoice(PeriodChoice.FINANCIAL_PERIOD); + } - editModel.setFiscalPeriodBeginDate(defaultFinancialPeriod != null ? defaultFinancialPeriod.getBeginDate() : defaultDateBegin); + protected void initFiscalPeriodCombo() { + List<FiscalPeriod> fiscalPeriods = fiscalPeriodService.getAllFiscalPeriods(); + view.getFiscalPeriodComboBoxModel().setObjects(fiscalPeriods); + view.getFiscalPeriodComboBox().setSelectedItem(fiscalPeriods.get(fiscalPeriods.size()-1)); + view.getFiscalPeriodComboBox().setVisible(true); } protected void initSoldPeriodView() { - view.getBeginPeriodSummary().setText(String.format("Pour la période du %s au %s,", getDateFormat().format(editModel.getFiscalPeriodBeginDate()), getDateFormat().format(filter.getDateEnd()))); + view.getBeginPeriodSummary().setText(String.format(t("lima.accountingView.summaryLabel"), getDateFormat().format(filter.getFiscalPeriod().getBeginDate()), getDateFormat().format(getDayMinus1Calendar(filter.getFinancialPeriod().getBeginDate()).getTime()))); view.getBeginDebit().setText(BigDecimalToString.format(BigDecimal.ZERO)); view.getBeginCredit().setText(BigDecimalToString.format(BigDecimal.ZERO)); view.getBeginSold().setText(BigDecimalToString.format(BigDecimal.ZERO)); - view.getEndPeriodSummary().setText(String.format("Pour la période du %s au %s,", getDateFormat().format(editModel.getFiscalPeriodBeginDate()), getDateFormat().format(filter.getDateEnd()))); + view.getEndPeriodSummary().setText(String.format(t("lima.accountingView.summaryLabel"), getDateFormat().format(filter.getFiscalPeriod().getBeginDate()), getDateFormat().format(filter.getFinancialPeriod().getEndDate()))); view.getEndDebit().setText(BigDecimalToString.format(BigDecimal.ZERO)); view.getEndCredit().setText(BigDecimalToString.format(BigDecimal.ZERO)); view.getEndSold().setText(BigDecimalToString.format(BigDecimal.ZERO)); } - protected void addFiscalPeriodBeginDate(FiscalPeriod fiscalPeriod) { - if (fiscalPeriod != null) { - editModel.setFiscalPeriodBeginDate(fiscalPeriod.getBeginDate()); + protected void setViewPreviousSold(LetteringFilter previousPeriodFilter) { + if (previousPeriodFilter != null) { + List<Object[]> initialDebitCredit = financialTransactionService.getAccountEntriesDebitCreditFromIncludingToExcludingPeriod(previousPeriodFilter); + DebitCreditSold debitCreditSold = new DebitCreditSold().invoke(initialDebitCredit); + view.getBeginPeriodSummary().setText(String.format(t("lima.accountingView.summaryLabel"), getDateFormat().format(previousPeriodFilter.getDateStart()), getDateFormat().format(previousPeriodFilter.getDateEnd()))); + view.getBeginDebit().setText(BigDecimalToString.format(debitCreditSold.getDebit())); + view.getBeginCredit().setText(BigDecimalToString.format(debitCreditSold.getCredit())); + view.getBeginSold().setText(BigDecimalToString.format(debitCreditSold.getSold())); + } else { + view.getBeginPeriodSummary().setText("Pas de période précédente,"); + view.getBeginDebit().setText(BigDecimalToString.format(BigDecimal.ZERO)); + view.getBeginCredit().setText(BigDecimalToString.format(BigDecimal.ZERO)); + view.getBeginSold().setText(BigDecimalToString.format(BigDecimal.ZERO)); } - } - protected void setViewPreviousSold(LetteringFilter previousPeriodFilter) { - List<Object[]> initialDebitCredit = financialTransactionService.getAccountEntriesDebitCreditFromIncludingToExcludingPeriod(previousPeriodFilter); - DebitCreditSold debitCreditSold = new DebitCreditSold().invoke(initialDebitCredit); - view.getBeginPeriodSummary().setText(String.format("Pour la période du %s au %s,", getDateFormat().format(previousPeriodFilter.getDateStart()), getDateFormat().format(previousPeriodFilter.getDateEnd()))); - view.getBeginDebit().setText(BigDecimalToString.format(debitCreditSold.getDebit())); - view.getBeginCredit().setText(BigDecimalToString.format(debitCreditSold.getCredit())); - view.getBeginSold().setText(BigDecimalToString.format(debitCreditSold.getSold())); } - protected void setViewActualSold(FiscalPeriod fiscalPeriod, LetteringFilter actualPeriodFilter) { - addFiscalPeriodBeginDate(fiscalPeriod); + protected void setViewActualSold(LetteringFilter actualPeriodFilter) { List<Object[]> initialDebitCredit = financialTransactionService.getAccountEntriesDebitCreditFromIncludingToIncludingPeriod(actualPeriodFilter); DebitCreditSold debitCreditSold = new DebitCreditSold().invoke(initialDebitCredit); - view.getEndPeriodSummary().setText(String.format("Pour la période du %s au %s,", getDateFormat().format(actualPeriodFilter.getDateStart()), getDateFormat().format(actualPeriodFilter.getDateEnd()))); + view.getEndPeriodSummary().setText(String.format(t("lima.accountingView.summaryLabel"), getDateFormat().format(actualPeriodFilter.getDateStart()), getDateFormat().format(actualPeriodFilter.getDateEnd()))); view.getEndDebit().setText(BigDecimalToString.format(debitCreditSold.getDebit())); view.getEndCredit().setText(BigDecimalToString.format(debitCreditSold.getCredit())); view.getEndSold().setText(BigDecimalToString.format(debitCreditSold.getSold())); @@ -504,7 +614,7 @@ public class AccountViewerViewHandler { editModel.setDebit(BigDecimal.ZERO); editModel.setSold(BigDecimal.ZERO, false); } else { - balanceCalculation(balance.getAmount(), balance.isDebit()); + selectedEntriesBalanceCalculation(balance.getAmount(), balance.isDebit()); } } @@ -512,7 +622,7 @@ public class AccountViewerViewHandler { * @param amount debit or credit * @param debit it indicate if amount is debit or not * */ - public void balanceCalculation(BigDecimal amount, boolean debit){ + public void selectedEntriesBalanceCalculation(BigDecimal amount, boolean debit){ BigDecimal debitVal = debit ? amount : BigDecimal.ZERO; BigDecimal creditVal = debit ? BigDecimal.ZERO : amount; @@ -524,36 +634,17 @@ public class AccountViewerViewHandler { if (debitVal.equals(BigDecimal.ZERO)){ if (!creditVal.equals(BigDecimal.ZERO)){ - editModel.setCredit(creditVal); editModel.setSold(creditVal, true); } - }else if (creditVal.equals(BigDecimal.ZERO)){ + } else if (creditVal.equals(BigDecimal.ZERO)){ editModel.setDebit(debitVal); editModel.setSold(debitVal, false); - }else{ + } else{ onBalanceChanged(null); } } - protected LetteringFilter computePreviousPeriodFilter(FiscalPeriod fiscalPeriod) { - LetteringFilter previousPeriodFilter = new LetteringFilterImpl(); - previousPeriodFilter.setDateStart(fiscalPeriod == null ? filter.getDateStart() : fiscalPeriod.getBeginDate()); - previousPeriodFilter.setDateEnd(filter.getDateStart()); - previousPeriodFilter.setAccount(filter.getAccount()); - - return previousPeriodFilter; - } - - private LetteringFilter computeActualPeriodFilter(FiscalPeriod fiscalPeriod) { - LetteringFilter actualPeriodFilter = new LetteringFilterImpl(); - actualPeriodFilter.setDateStart(fiscalPeriod == null ? filter.getDateStart() : fiscalPeriod.getBeginDate()); - actualPeriodFilter.setDateEnd(filter.getDateEnd()); - actualPeriodFilter.setAccount(filter.getAccount()); - - return actualPeriodFilter; - } - protected class DebitCreditSold { private BigDecimal debit; private BigDecimal credit; @@ -597,7 +688,7 @@ public class AccountViewerViewHandler { public void setAccount(Account account) { if (filter != null) { filter.setAccount(account); - updateAllEntries(null); + updateAllEntries(); } } @@ -609,9 +700,9 @@ public class AccountViewerViewHandler { return account; } - protected Calendar getDayMinus1Calendar(LetteringFilter previousPeriodFilter) { + protected Calendar getDayMinus1Calendar(Date date) { Calendar cal = Calendar.getInstance(); - cal.setTime(previousPeriodFilter.getDateEnd()); + cal.setTime(date); cal.add(Calendar.DATE, -1); return cal; } 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 d35494e..3e2bafa 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 @@ -16,6 +16,7 @@ lima.account.update.error.invalidAccountNumber=Invalid account number\: %1$s lima.account.update.form=Update account lima.accountViewer.previousSold=<html><b>On %s the sold was</b></html> lima.accountViewer.selectionDescription=For selected entries, +lima.accountingView.summaryLabel=Period from %s to %s, lima.accounts=Accounts lima.action.commandline.help=Show help in console lima.balance=Balance 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 7a76b10..4a87599 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 @@ -19,6 +19,7 @@ lima.account.update.error.invalidAccountNumber=Le numéro du compte %1$s n'est p lima.account.update.form=Modification d'un compte lima.accountViewer.previousSold=<html><b>Solde au %s</b></html> lima.accountViewer.selectionDescription=Pour la sélection, +lima.accountingView.summaryLabel=Pour la période du %s au %s, lima.accounts=Comptes lima.action.commandline.help=Afficher l'aide en console lima.balance=Équilibrer -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
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 27350cb95bc35003e593a4b87bc826fbaaf8783e Author: dcosse <cosse@codelutin.com> Date: Thu Sep 24 12:54:04 2015 +0200 refs #1293 corrections et refactoring --- .../ui/accountViewer/AccountViewerViewHandler.java | 137 ++++++++++++--------- .../resources/i18n/lima-swing_en_GB.properties | 3 + .../resources/i18n/lima-swing_fr_FR.properties | 3 + 3 files changed, 87 insertions(+), 56 deletions(-) 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 index 2c120dd..fd53279 100644 --- 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 @@ -53,6 +53,7 @@ import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.math.BigDecimal; import java.text.DateFormat; +import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.Iterator; @@ -92,6 +93,7 @@ public class AccountViewerViewHandler { private static final Log log = LogFactory.getLog(AccountViewerViewHandler.class); protected boolean initializationComplete; + public static final SimpleDateFormat YYYY = new SimpleDateFormat("yyyy"); public AccountViewerViewHandler(AccountViewerView view) { @@ -114,7 +116,7 @@ public class AccountViewerViewHandler { public void init() { filter = new AccountViewerFilter(); editModel = view.getEditModel(); - updateFinancialPeriodView(null); + updateFinancialPeriodView(); initSoldPeriodView(); editModel.addPropertyChangeListener(AccountViewerEditModel.PROPERTY_DEBIT, new PropertyChangeListener() { @@ -224,7 +226,7 @@ public class AccountViewerViewHandler { } private void updateAllEntriesForFinancialPeriodChoice() { - updateFinancialPeriodView(filter.getFiscalPeriod()); + updateFinancialPeriodView(); updateAllEntries(); } @@ -266,25 +268,23 @@ public class AccountViewerViewHandler { protected void onFiscalPeriodChange(ItemEvent event) { FiscalPeriod selectedFiscalPeriod = event != null && event.getItem() != null ? (FiscalPeriod) event.getItem() : null; if (initializationComplete && selectedFiscalPeriod != null && !selectedFiscalPeriod.equals(filter.getFiscalPeriod())) { - - List<FinancialPeriod> periods = financialPeriodService.getFinancialPeriodsWithBeginDateWithin(selectedFiscalPeriod.getBeginDate(), selectedFiscalPeriod.getEndDate()); - FinancialPeriod selectedFinancialPeriod = periods.get(0); - view.getFinancialPeriodComboBoxModel().setObjects(periods); - view.getFinancialPeriodComboBoxModel().setSelectedItem(selectedFinancialPeriod); - - filter.setDateStart(selectedFinancialPeriod.getBeginDate()); - filter.setDateEnd(selectedFinancialPeriod.getEndDate()); - filter.setFiscalPeriod(selectedFiscalPeriod); - filter.setFinancialPeriod(selectedFinancialPeriod); - filter.setPeriodChoice(PeriodChoice.FINANCIAL_PERIOD); + if (PeriodChoice.FINANCIAL_PERIOD.equals(filter.getPeriodChoice())) { + List<FinancialPeriod> periods = financialPeriodService.getFinancialPeriodsWithBeginDateWithin(selectedFiscalPeriod.getBeginDate(), selectedFiscalPeriod.getEndDate()); + FinancialPeriod selectedFinancialPeriod = periods.get(0); + view.getFinancialPeriodComboBoxModel().setObjects(periods); + view.getFinancialPeriodComboBoxModel().setSelectedItem(selectedFinancialPeriod); + + setFilter(selectedFiscalPeriod, selectedFinancialPeriod, selectedFinancialPeriod.getBeginDate(), selectedFinancialPeriod.getEndDate(), PeriodChoice.FINANCIAL_PERIOD); + } else { + setFilter(selectedFiscalPeriod, null, selectedFiscalPeriod.getBeginDate(), selectedFiscalPeriod.getEndDate(), PeriodChoice.FISCAL_PERIOD); + } updateAllEntries(); } } protected void onFinancialPeriodChange(java.awt.event.ItemEvent event) { FinancialPeriod financialPeriod = (FinancialPeriod) event.getItem(); - if (initializationComplete && !filter.getFinancialPeriod().equals(financialPeriod)) { - filter.setFinancialPeriod(financialPeriod); + if (initializationComplete && filter.getFinancialPeriod() == null || !filter.getFinancialPeriod().equals(financialPeriod)) { updateAllEntriesForFinancialPeriodChoice(financialPeriod); } } @@ -341,24 +341,25 @@ public class AccountViewerViewHandler { public void updateAllEntriesForFiscalPeriodChoice(FiscalPeriod fiscalPeriod) { - filter.setFiscalPeriod(fiscalPeriod); - filter.setDateStart(fiscalPeriod.getBeginDate()); - filter.setDateEnd(fiscalPeriod.getEndDate()); - filter.setPeriodChoice(PeriodChoice.FISCAL_PERIOD); + setFilter(fiscalPeriod, null, fiscalPeriod.getBeginDate(), fiscalPeriod.getEndDate(), PeriodChoice.FISCAL_PERIOD); updateAllEntries(); } public void updateAllEntriesForFinancialPeriodChoice(FinancialPeriod financialPeriod) { - filter.setDateStart(financialPeriod.getBeginDate()); - filter.setDateEnd(financialPeriod.getEndDate()); - filter.setPeriodChoice(PeriodChoice.FINANCIAL_PERIOD); + setFilter(null, financialPeriod, financialPeriod.getBeginDate(), financialPeriod.getEndDate(), PeriodChoice.FINANCIAL_PERIOD); updateAllEntries(); + } + protected void setFilter(FiscalPeriod fiscalPeriod, FinancialPeriod financialPeriod, Date dateStart, Date dateEnd, PeriodChoice periodChoice) { + filter.setFiscalPeriod(fiscalPeriod); + filter.setFinancialPeriod(financialPeriod); + filter.setDateStart(dateStart); + filter.setDateEnd(dateEnd); + filter.setPeriodChoice(periodChoice); } public void updateAllEntriesForDateChange() { filter.setPeriodChoice(PeriodChoice.DATE); - filter.setFiscalPeriod(fiscalPeriodService.getFiscalPeriodForDate(filter.getDateStart())); updateAllEntries(); } @@ -377,22 +378,26 @@ public class AccountViewerViewHandler { } protected void updateSummary() { - PeriodChoice periodChoice = filter.getPeriodChoice(); - LetteringFilter previousPeriodFilter = computePreviousPeriodFilter(periodChoice); - LetteringFilter actualPeriodFilter = computeActualPeriodFilter(periodChoice); + LetteringFilter previousPeriodFilter = computePreviousPeriodFilter(); + LetteringFilter actualPeriodFilter = computeActualPeriodFilter(); setViewPreviousSold(previousPeriodFilter); setViewActualSold(actualPeriodFilter); } - protected LetteringFilter computePreviousPeriodFilter(PeriodChoice periodChoice) { + protected LetteringFilter computePreviousPeriodFilter() { LetteringFilter previousPeriodFilter = null; FiscalPeriod previousFiscalPeriod; Date dateStart = null, dateEnd = null; - switch (periodChoice) { + switch (filter.getPeriodChoice()) { case FINANCIAL_PERIOD: Date financialPeriodDate = filter.getFinancialPeriod().getBeginDate(); FiscalPeriod fiscalPeriodFiscalPeriod = fiscalPeriodService.getFiscalPeriodForDate(financialPeriodDate); - dateStart = fiscalPeriodFiscalPeriod.getBeginDate(); + + if (DateUtils.isSameDay(financialPeriodDate, fiscalPeriodFiscalPeriod.getBeginDate())) { + fiscalPeriodFiscalPeriod = fiscalPeriodService.getFiscalPeriodForDate(getDayMinus1Calendar(financialPeriodDate).getTime()); + } + + dateStart = fiscalPeriodFiscalPeriod != null ? fiscalPeriodFiscalPeriod.getBeginDate() : null; dateEnd = getDayMinus1Calendar(financialPeriodDate).getTime(); break; case FISCAL_PERIOD: @@ -403,12 +408,14 @@ public class AccountViewerViewHandler { } break; case DATE: - previousFiscalPeriod = filter.getFiscalPeriod(); + previousFiscalPeriod = fiscalPeriodService.getFiscalPeriodForDate(filter.getDateStart()); + // case of starting date is same as current fiscal period one, so we look for previous fiscal period if (previousFiscalPeriod != null && DateUtils.isSameDay(previousFiscalPeriod.getBeginDate(), filter.getDateStart())) { previousFiscalPeriod = fiscalPeriodService.getFiscalPeriodForDate(getDayMinus1Calendar(filter.getDateStart()).getTime()); } + // case of selected date is upper the last fiscal period we look for the last fiscal period if (previousFiscalPeriod == null) { FiscalPeriod lastFiscalPeriod = fiscalPeriodService.getLastFiscalPeriod(); previousFiscalPeriod = lastFiscalPeriod != null && lastFiscalPeriod.getEndDate().before(filter.getDateStart()) ? lastFiscalPeriod : null; @@ -431,10 +438,10 @@ public class AccountViewerViewHandler { return previousPeriodFilter; } - private LetteringFilter computeActualPeriodFilter(PeriodChoice choice) { + private LetteringFilter computeActualPeriodFilter() { LetteringFilter actualPeriodFilter = null; Date dateStart = null, dateEnd = null; - switch (choice) { + switch (filter.getPeriodChoice()) { case FINANCIAL_PERIOD: if (filter.getFinancialPeriod() != null) { Date financialPeriodDate = filter.getFinancialPeriod().getBeginDate(); @@ -465,13 +472,10 @@ public class AccountViewerViewHandler { List<FiscalPeriod> fiscalPeriods = fiscalPeriodService.getAllFiscalPeriods(); view.getFiscalPeriodComboBoxModel().setObjects(fiscalPeriods); - filter.setPeriodChoice(PeriodChoice.FISCAL_PERIOD); FiscalPeriod fiscalPeriod = fiscalPeriodService.getLastFiscalPeriod(); if (fiscalPeriod != null) { - filter.setFiscalPeriod(fiscalPeriod); - filter.setDateStart(fiscalPeriod.getBeginDate()); - filter.setDateEnd(fiscalPeriod.getEndDate()); - view.getFiscalPeriodComboBox().setSelectedItem(fiscalPeriod); + setFilter(fiscalPeriod, null, fiscalPeriod.getBeginDate(), fiscalPeriod.getEndDate(), PeriodChoice.FINANCIAL_PERIOD); + view.getFiscalPeriodComboBoxModel().setSelectedItem(fiscalPeriod); view.getFiscalPeriodComboBox().setVisible(true); } } @@ -486,31 +490,30 @@ public class AccountViewerViewHandler { if (defaultFinancialPeriod == null) { defaultFinancialPeriod = financialPeriodService.getFinancialForDate(fiscalPeriod.getEndDate()); } - filter.setDateStart(defaultFinancialPeriod.getBeginDate()); - filter.setDateEnd(defaultFinancialPeriod.getEndDate()); + setFilter(null, null, defaultFinancialPeriod.getBeginDate(), defaultFinancialPeriod.getEndDate(), PeriodChoice.DATE); view.getBeginPeriodPicker().setDate(defaultFinancialPeriod.getBeginDate()); view.getEndPeriodPicker().setDate(defaultFinancialPeriod.getEndDate()); } } - public void updateFinancialPeriodView(FiscalPeriod fiscalPeriodO) { - FiscalPeriod fiscalPeriod = fiscalPeriodO == null ? fiscalPeriodService.getLastFiscalPeriod() : fiscalPeriodO; - + public void updateFinancialPeriodView() { + FiscalPeriod fiscalPeriod = fiscalPeriodService.getLastFiscalPeriod(); FinancialPeriod defaultFinancialPeriod = null; + List<FinancialPeriod> financialPeriods = null; if (fiscalPeriod != null) { - List<FinancialPeriod> financialPeriods = financialPeriodService.getFinancialPeriodsWithBeginDateWithin(fiscalPeriod.getBeginDate(), fiscalPeriod.getEndDate()); - view.getFinancialPeriodComboBoxModel().setObjects(financialPeriods); - Date today = new Date(); + view.getFinancialPeriodComboBoxModel().removeAllElements(); + + financialPeriods = financialPeriodService.getFinancialPeriodsWithBeginDateWithin(fiscalPeriod.getBeginDate(), fiscalPeriod.getEndDate()); + Date today = new Date(); Iterator<FinancialPeriod> financialPeriodIterator = financialPeriods.iterator(); while (financialPeriodIterator.hasNext() && defaultFinancialPeriod == null) { FinancialPeriod financialPeriod = financialPeriodIterator.next(); defaultFinancialPeriod = financialPeriod.getBeginDate().before(today) && financialPeriod.getEndDate().after(today) ? financialPeriod : null; } + defaultFinancialPeriod = defaultFinancialPeriod != null ? defaultFinancialPeriod : financialPeriods.get(financialPeriods.size() - 1); - view.getFinancialPeriodComboBoxModel().setSelectedItem(defaultFinancialPeriod); - initFiscalPeriodCombo(); } Date defaultDateBegin, defaultDateEnd; @@ -520,17 +523,24 @@ public class AccountViewerViewHandler { defaultDateBegin = defaultFinancialPeriod == null ? DateUtils.setDays(new Date(), firstCurrentMonthDay) : defaultFinancialPeriod.getBeginDate(); defaultDateEnd = defaultFinancialPeriod == null ? DateUtils.setDays(new Date(), lastCurrentMonthDay) : defaultFinancialPeriod.getEndDate(); - filter.setDateStart(defaultDateBegin); - filter.setDateEnd(defaultDateEnd); - filter.setFiscalPeriod(fiscalPeriod); - filter.setFinancialPeriod(defaultFinancialPeriod); - filter.setPeriodChoice(PeriodChoice.FINANCIAL_PERIOD); + setFilter(fiscalPeriod, defaultFinancialPeriod, defaultDateBegin, defaultDateEnd, PeriodChoice.FINANCIAL_PERIOD); + + initFiscalPeriodCombo(); + updateFinancialPeriodCombo(defaultFinancialPeriod, financialPeriods); + + } + + protected void updateFinancialPeriodCombo(FinancialPeriod defaultFinancialPeriod, List<FinancialPeriod> financialPeriods) { + view.getFinancialPeriodComboBoxModel().setObjects(financialPeriods); + if (defaultFinancialPeriod != null) { + view.getFinancialPeriodComboBoxModel().setSelectedItem(defaultFinancialPeriod); + } } protected void initFiscalPeriodCombo() { List<FiscalPeriod> fiscalPeriods = fiscalPeriodService.getAllFiscalPeriods(); view.getFiscalPeriodComboBoxModel().setObjects(fiscalPeriods); - view.getFiscalPeriodComboBox().setSelectedItem(fiscalPeriods.get(fiscalPeriods.size()-1)); + view.getFiscalPeriodComboBoxModel().setSelectedItem(fiscalPeriods.get(fiscalPeriods.size() - 1)); view.getFiscalPeriodComboBox().setVisible(true); } @@ -547,14 +557,22 @@ public class AccountViewerViewHandler { protected void setViewPreviousSold(LetteringFilter previousPeriodFilter) { if (previousPeriodFilter != null) { + if (filter.getPeriodChoice().equals(PeriodChoice.FISCAL_PERIOD)) { + String summaryLabel = t("lima.accountingView.summaryFiscalPeriodLabel"); + view.getBeginPeriodSummary().setText(String.format(t(summaryLabel), YYYY.format(previousPeriodFilter.getDateStart()))); + } else { + String summaryLabel = t("lima.accountingView.summaryLabel"); + view.getBeginPeriodSummary().setText(String.format(t(summaryLabel), getDateFormat().format(previousPeriodFilter.getDateStart()), getDateFormat().format(getDayMinus1Calendar(previousPeriodFilter.getDateEnd()).getTime()))); + } + List<Object[]> initialDebitCredit = financialTransactionService.getAccountEntriesDebitCreditFromIncludingToExcludingPeriod(previousPeriodFilter); DebitCreditSold debitCreditSold = new DebitCreditSold().invoke(initialDebitCredit); - view.getBeginPeriodSummary().setText(String.format(t("lima.accountingView.summaryLabel"), getDateFormat().format(previousPeriodFilter.getDateStart()), getDateFormat().format(previousPeriodFilter.getDateEnd()))); view.getBeginDebit().setText(BigDecimalToString.format(debitCreditSold.getDebit())); view.getBeginCredit().setText(BigDecimalToString.format(debitCreditSold.getCredit())); view.getBeginSold().setText(BigDecimalToString.format(debitCreditSold.getSold())); } else { - view.getBeginPeriodSummary().setText("Pas de période précédente,"); + String summaryLabel = filter.getPeriodChoice().equals(PeriodChoice.FISCAL_PERIOD) ? t("lima.accountingView.summaryNoFiscalPeriodLabel") : t("lima.accountingView.summaryNoPeriodLabel"); + view.getBeginPeriodSummary().setText(summaryLabel); view.getBeginDebit().setText(BigDecimalToString.format(BigDecimal.ZERO)); view.getBeginCredit().setText(BigDecimalToString.format(BigDecimal.ZERO)); view.getBeginSold().setText(BigDecimalToString.format(BigDecimal.ZERO)); @@ -563,9 +581,16 @@ public class AccountViewerViewHandler { } protected void setViewActualSold(LetteringFilter actualPeriodFilter) { + if (filter.getPeriodChoice().equals(PeriodChoice.FISCAL_PERIOD)) { + String summaryLabel = t("lima.accountingView.summaryFiscalPeriodLabel"); + view.getEndPeriodSummary().setText(String.format(t(summaryLabel), YYYY.format(actualPeriodFilter.getDateEnd()))); + } else { + String summaryLabel = t("lima.accountingView.summaryLabel"); + view.getEndPeriodSummary().setText(String.format(t(summaryLabel), getDateFormat().format(actualPeriodFilter.getDateStart()), getDateFormat().format(actualPeriodFilter.getDateEnd()))); + } + List<Object[]> initialDebitCredit = financialTransactionService.getAccountEntriesDebitCreditFromIncludingToIncludingPeriod(actualPeriodFilter); DebitCreditSold debitCreditSold = new DebitCreditSold().invoke(initialDebitCredit); - view.getEndPeriodSummary().setText(String.format(t("lima.accountingView.summaryLabel"), getDateFormat().format(actualPeriodFilter.getDateStart()), getDateFormat().format(actualPeriodFilter.getDateEnd()))); view.getEndDebit().setText(BigDecimalToString.format(debitCreditSold.getDebit())); view.getEndCredit().setText(BigDecimalToString.format(debitCreditSold.getCredit())); view.getEndSold().setText(BigDecimalToString.format(debitCreditSold.getSold())); 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 3e2bafa..bef1571 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 @@ -16,7 +16,10 @@ lima.account.update.error.invalidAccountNumber=Invalid account number\: %1$s lima.account.update.form=Update account lima.accountViewer.previousSold=<html><b>On %s the sold was</b></html> lima.accountViewer.selectionDescription=For selected entries, +lima.accountingView.summaryFiscalPeriodLabel=For %s fiscal period, lima.accountingView.summaryLabel=Period from %s to %s, +lima.accountingView.summaryNoFiscalPeriodLabel=No previous fiscal period, +lima.accountingView.summaryNoPeriodLabel=No previous period, lima.accounts=Accounts lima.action.commandline.help=Show help in console lima.balance=Balance 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 4a87599..d714e7c 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 @@ -19,7 +19,10 @@ lima.account.update.error.invalidAccountNumber=Le numéro du compte %1$s n'est p lima.account.update.form=Modification d'un compte lima.accountViewer.previousSold=<html><b>Solde au %s</b></html> lima.accountViewer.selectionDescription=Pour la sélection, +lima.accountingView.summaryFiscalPeriodLabel=Pour l'exercice %s, lima.accountingView.summaryLabel=Pour la période du %s au %s, +lima.accountingView.summaryNoFiscalPeriodLabel=Pas d'exercice précédent, +lima.accountingView.summaryNoPeriodLabel=Pas de période précédente, lima.accounts=Comptes lima.action.commandline.help=Afficher l'aide en console lima.balance=Équilibrer -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
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 9f4bbb3d2f8fce6ff5828f088f32a442e23be8bf Author: dcosse <cosse@codelutin.com> Date: Thu Sep 24 14:19:40 2015 +0200 refs #1293 corrections pour le cas ou aucune données existe dans Lima --- .../ui/accountViewer/AccountViewerViewHandler.java | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) 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 index fd53279..be14b20 100644 --- 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 @@ -341,8 +341,10 @@ public class AccountViewerViewHandler { public void updateAllEntriesForFiscalPeriodChoice(FiscalPeriod fiscalPeriod) { - setFilter(fiscalPeriod, null, fiscalPeriod.getBeginDate(), fiscalPeriod.getEndDate(), PeriodChoice.FISCAL_PERIOD); - updateAllEntries(); + if (fiscalPeriod != null) { + setFilter(fiscalPeriod, null, fiscalPeriod.getBeginDate(), fiscalPeriod.getEndDate(), PeriodChoice.FISCAL_PERIOD); + updateAllEntries(); + } } public void updateAllEntriesForFinancialPeriodChoice(FinancialPeriod financialPeriod) { @@ -531,8 +533,8 @@ public class AccountViewerViewHandler { } protected void updateFinancialPeriodCombo(FinancialPeriod defaultFinancialPeriod, List<FinancialPeriod> financialPeriods) { - view.getFinancialPeriodComboBoxModel().setObjects(financialPeriods); - if (defaultFinancialPeriod != null) { + if (CollectionUtils.isNotEmpty(financialPeriods)) { + view.getFinancialPeriodComboBoxModel().setObjects(financialPeriods); view.getFinancialPeriodComboBoxModel().setSelectedItem(defaultFinancialPeriod); } } @@ -540,16 +542,22 @@ public class AccountViewerViewHandler { protected void initFiscalPeriodCombo() { List<FiscalPeriod> fiscalPeriods = fiscalPeriodService.getAllFiscalPeriods(); view.getFiscalPeriodComboBoxModel().setObjects(fiscalPeriods); - view.getFiscalPeriodComboBoxModel().setSelectedItem(fiscalPeriods.get(fiscalPeriods.size() - 1)); + if (CollectionUtils.isNotEmpty(fiscalPeriods)) { + view.getFiscalPeriodComboBoxModel().setSelectedItem(fiscalPeriods.get(fiscalPeriods.size() - 1)); + } view.getFiscalPeriodComboBox().setVisible(true); } protected void initSoldPeriodView() { - view.getBeginPeriodSummary().setText(String.format(t("lima.accountingView.summaryLabel"), getDateFormat().format(filter.getFiscalPeriod().getBeginDate()), getDateFormat().format(getDayMinus1Calendar(filter.getFinancialPeriod().getBeginDate()).getTime()))); + Date ppbd = filter.getFiscalPeriod() != null ? filter.getFiscalPeriod().getBeginDate() : new Date(); + Date pped = filter.getFinancialPeriod() != null ? getDayMinus1Calendar(filter.getFinancialPeriod().getBeginDate()).getTime() : new Date(); + view.getBeginPeriodSummary().setText(String.format(t("lima.accountingView.summaryLabel"), getDateFormat().format(ppbd), getDateFormat().format(pped))); view.getBeginDebit().setText(BigDecimalToString.format(BigDecimal.ZERO)); view.getBeginCredit().setText(BigDecimalToString.format(BigDecimal.ZERO)); view.getBeginSold().setText(BigDecimalToString.format(BigDecimal.ZERO)); - view.getEndPeriodSummary().setText(String.format(t("lima.accountingView.summaryLabel"), getDateFormat().format(filter.getFiscalPeriod().getBeginDate()), getDateFormat().format(filter.getFinancialPeriod().getEndDate()))); + + Date aped = filter.getFinancialPeriod() != null ? filter.getFinancialPeriod().getEndDate() : new Date(); + view.getEndPeriodSummary().setText(String.format(t("lima.accountingView.summaryLabel"), getDateFormat().format(ppbd), getDateFormat().format(aped))); view.getEndDebit().setText(BigDecimalToString.format(BigDecimal.ZERO)); view.getEndCredit().setText(BigDecimalToString.format(BigDecimal.ZERO)); view.getEndSold().setText(BigDecimalToString.format(BigDecimal.ZERO)); -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
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 a2e5011e898db21f4fd3816479a87c8d4224abfb Author: dcosse <cosse@codelutin.com> Date: Fri Sep 25 13:05:56 2015 +0200 refs #1293 corrige exception dans le cas ou aucune periode financière existe avec la date choisie --- .../org/chorem/lima/business/api/FinancialPeriodService.java | 2 ++ .../chorem/lima/business/ejb/FinancialPeriodServiceImpl.java | 8 ++++++++ .../java/org/chorem/lima/entity/FinancialPeriodTopiaDao.java | 10 ++++++++++ .../chorem/lima/ui/accountViewer/AccountViewerViewHandler.java | 2 +- 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialPeriodService.java b/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialPeriodService.java index 4ed0a10..d164f4e 100644 --- a/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialPeriodService.java +++ b/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialPeriodService.java @@ -60,6 +60,8 @@ public interface FinancialPeriodService { FinancialPeriod getFinancialForDate(Date date); + FinancialPeriod getFinancialPeriodIfExistsByDate(Date date); + List<FinancialPeriod> getFinancialPeriodsWithBeginDateWithin(Date beginDateFirst, Date endDateLast); } diff --git a/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java b/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java index 02c2df2..86551c9 100644 --- a/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java +++ b/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java @@ -71,6 +71,14 @@ public class FinancialPeriodServiceImpl extends AbstractLimaService implements F return result; } + @Override + public FinancialPeriod getFinancialPeriodIfExistsByDate(Date date) { + FinancialPeriodTopiaDao financialPeriodTopiaDao = getDaoHelper().getFinancialPeriodDao(); + FinancialPeriod result = financialPeriodTopiaDao.findByDateIfExists(date); + + return result; + } + /** @return all financial period from a fiscal period */ @Override public List<FinancialPeriod> getFinancialPeriodsWithBeginDateWithin(Date beginDateFirst, Date endDateLast) { diff --git a/lima-business/src/main/java/org/chorem/lima/entity/FinancialPeriodTopiaDao.java b/lima-business/src/main/java/org/chorem/lima/entity/FinancialPeriodTopiaDao.java index 9d9a77d..f2139bb 100644 --- a/lima-business/src/main/java/org/chorem/lima/entity/FinancialPeriodTopiaDao.java +++ b/lima-business/src/main/java/org/chorem/lima/entity/FinancialPeriodTopiaDao.java @@ -45,6 +45,16 @@ public class FinancialPeriodTopiaDao extends AbstractFinancialPeriodTopiaDao<Fin FinancialPeriod financialPeriod = findUnique(builder.getHql(), builder.getHqlParameters()); return financialPeriod; } + + public FinancialPeriod findByDateIfExists(Date date) { + + HqlAndParametersBuilder<FinancialPeriod> builder = newHqlAndParametersBuilder(); + builder.addLowerOrEquals(FinancialPeriod.PROPERTY_BEGIN_DATE, date); + builder.addGreaterOrEquals(FinancialPeriod.PROPERTY_END_DATE, date); + + FinancialPeriod financialPeriod = findUniqueOrNull(builder.getHql(), builder.getHqlParameters()); + return financialPeriod; + } /** * Return all FinancialPeriod with begin date between two given dates. 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 index be14b20..c425164 100644 --- 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 @@ -487,7 +487,7 @@ public class AccountViewerViewHandler { FinancialPeriod defaultFinancialPeriod; if (fiscalPeriod != null) { Date today = new Date(); - defaultFinancialPeriod = financialPeriodService.getFinancialForDate(today); + defaultFinancialPeriod = financialPeriodService.getFinancialPeriodIfExistsByDate(today); if (defaultFinancialPeriod == null) { defaultFinancialPeriod = financialPeriodService.getFinancialForDate(fiscalPeriod.getEndDate()); -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
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 7ceeed60dfc471af1dd7c1da4fbf0a9139dfee2d Author: dcosse <cosse@codelutin.com> Date: Fri Sep 25 13:08:29 2015 +0200 refs #1293 Correction i18n --- lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 d714e7c..e60cd61 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 @@ -243,7 +243,7 @@ lima.filter.condition.delete=Supprimer la condition lima.filter.condition.one=Valide au moins une condition lima.filter.condition.periodChoice.date=Interval de Dates lima.filter.condition.periodChoice.financialPeriod=Période Financière -lima.filter.condition.periodChoice.fiscalPeriod=Execrice +lima.filter.condition.periodChoice.fiscalPeriod=Exercice lima.filter.condition.selectionMode=Sélection des écritures lettrées lima.filter.condition.selectionMode.lettered=Lettré lima.filter.condition.selectionMode.manual=Manuelle -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
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 59ea9a6396f07ce8e2fabb11f3e842dc0a1322ba Author: dcosse <cosse@codelutin.com> Date: Wed Sep 30 14:49:39 2015 +0200 refs #1268 déplacement des models du jaxx au handler --- .../lima/ui/accountViewer/AccountViewerView.jaxx | 22 +--- .../ui/accountViewer/AccountViewerViewHandler.java | 120 +++++++++++++++------ 2 files changed, 89 insertions(+), 53 deletions(-) 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 index d03a614..a1c21f0 100644 --- 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 @@ -24,22 +24,12 @@ java.awt.FlowLayout 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 - org.chorem.lima.ui.LimaRendererUtil - org.chorem.lima.entity.FinancialPeriod </import> <AccountViewerViewHandler id="handler" constructorParams="this"/> - <AccountViewerEditModel id='editModel'/> - <script> <![CDATA[ void $afterCompleteSetup() { @@ -72,14 +62,10 @@ <JLabel id="beginPeriodLabel"/> - <org.chorem.lima.ui.common.FiscalPeriodComboBoxModel id="fiscalPeriodComboBoxModel"/> <JComboBox id="fiscalPeriodComboBox" - model="{fiscalPeriodComboBoxModel}" onItemStateChanged="handler.onFiscalPeriodChange(event)"/> - <org.chorem.lima.ui.common.FinancialPeriodComboBoxModel id="financialPeriodComboBoxModel"/> <JComboBox id="financialPeriodComboBox" - model="{financialPeriodComboBoxModel}" onItemStateChanged="handler.onFinancialPeriodChange(event)"/> <JAXXDatePicker id="beginPeriodPicker" @@ -119,14 +105,8 @@ </JPanel> <JScrollPane constraints="BorderLayout.CENTER"> - <AccountViewerTableModel id="tableModel"/> - <AccountViewerSelectionModel id='accountViewerSelectionModel' constructorParams='tableModel' - onValueChanged="handler.balanceAndActions()"/> - <AccountViewerTable id="table" - constructorParams="handler" - model="{tableModel}" - selectionModel="{accountViewerSelectionModel}"/> + constructorParams="handler"/> </JScrollPane> <JPanel constraints="BorderLayout.SOUTH" layout="{new BorderLayout()}"> 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 index c425164..d79fbdc 100644 --- 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 @@ -41,10 +41,14 @@ import org.chorem.lima.entity.Entry; import org.chorem.lima.entity.FinancialPeriod; import org.chorem.lima.entity.FiscalPeriod; import org.chorem.lima.ui.combobox.AccountComboBox; +import org.chorem.lima.ui.common.FinancialPeriodComboBoxModel; +import org.chorem.lima.ui.common.FiscalPeriodComboBoxModel; import org.chorem.lima.util.BigDecimalToString; import org.chorem.lima.util.ErrorHelper; import javax.swing.*; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; import java.awt.event.ActionEvent; import java.awt.event.InputEvent; import java.awt.event.ItemEvent; @@ -84,7 +88,11 @@ public class AccountViewerViewHandler { protected AccountViewerFilter filter; + protected AccountViewerTableModel accountViewerTableModel; + protected AccountViewerSelectionModel accountViewerSelectionModel; protected AccountViewerEditModel editModel; + protected FinancialPeriodComboBoxModel financialPeriodComboBoxModel; + protected FiscalPeriodComboBoxModel fiscalPeriodComboBoxModel; protected ErrorHelper errorHelper; @@ -115,10 +123,50 @@ public class AccountViewerViewHandler { */ public void init() { filter = new AccountViewerFilter(); - editModel = view.getEditModel(); - updateFinancialPeriodView(); + + createComponentsModels(); + + addModelsToComponents(); + + initAccountTableView(); + + addListeners(); + + initFinancialPeriodDefaultComponent(); + initSoldPeriodView(); + initializationComplete = true; + + updateSoldStatus(); + } + + protected void createComponentsModels() { + editModel = new AccountViewerEditModel(); + financialPeriodComboBoxModel = new FinancialPeriodComboBoxModel(); + fiscalPeriodComboBoxModel = new FiscalPeriodComboBoxModel(); + accountViewerTableModel = new AccountViewerTableModel(); + accountViewerSelectionModel = new AccountViewerSelectionModel(accountViewerTableModel); + } + + protected void addModelsToComponents() { + view.getFinancialPeriodComboBox().setModel(financialPeriodComboBoxModel); + view.getFiscalPeriodComboBox().setModel(fiscalPeriodComboBoxModel); + AccountViewerTable accountViewerTable = view.getTable(); + accountViewerTable.setModel(accountViewerTableModel); + accountViewerTable.setSelectionModel(accountViewerSelectionModel); + } + + protected void addListeners() { + accountViewerSelectionModel.addListSelectionListener(new ListSelectionListener() { + @Override + public void valueChanged(ListSelectionEvent e) { + if (!e.getValueIsAdjusting()) { + view.getHandler().balanceAndActions(); + } + } + }); + editModel.addPropertyChangeListener(AccountViewerEditModel.PROPERTY_DEBIT, new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { @@ -146,16 +194,19 @@ public class AccountViewerViewHandler { updateSoldStatus(); } }); + } - onSelectionModeChanged(selectionMode); - - SwingUtil.fixTableColumnWidth(view.getTable(), 0, 100); - SwingUtil.fixTableColumnWidth(view.getTable(), 1, 60); - SwingUtil.fixTableColumnWidth(view.getTable(), 2, 80); - SwingUtil.fixTableColumnWidth(view.getTable(), 4, 50); + protected void initAccountTableView() { + AccountViewerTable accountViewerTable = view.getTable(); + SwingUtil.fixTableColumnWidth(accountViewerTable, 0, 100); + SwingUtil.fixTableColumnWidth(accountViewerTable, 1, 60); + SwingUtil.fixTableColumnWidth(accountViewerTable, 2, 80); + SwingUtil.fixTableColumnWidth(accountViewerTable, 4, 50); + } - initializationComplete = true; - updateSoldStatus(); + protected void initFinancialPeriodDefaultComponent() { + updateFinancialPeriodView(); + onSelectionModeChanged(selectionMode); } protected void initShortCuts() { @@ -243,7 +294,7 @@ public class AccountViewerViewHandler { if (row > 0) { comboBox.setSelectedIndex(row - 1); } - view.getAccountViewerSelectionModel().clearSelection(); + view.getTable().getSelectionModel().clearSelection(); } } @@ -261,7 +312,7 @@ public class AccountViewerViewHandler { if (row < size - 1) { comboBox.setSelectedIndex(row + 1); } - view.getAccountViewerSelectionModel().clearSelection(); + view.getTable().getSelectionModel().clearSelection(); } } @@ -271,8 +322,8 @@ public class AccountViewerViewHandler { if (PeriodChoice.FINANCIAL_PERIOD.equals(filter.getPeriodChoice())) { List<FinancialPeriod> periods = financialPeriodService.getFinancialPeriodsWithBeginDateWithin(selectedFiscalPeriod.getBeginDate(), selectedFiscalPeriod.getEndDate()); FinancialPeriod selectedFinancialPeriod = periods.get(0); - view.getFinancialPeriodComboBoxModel().setObjects(periods); - view.getFinancialPeriodComboBoxModel().setSelectedItem(selectedFinancialPeriod); + financialPeriodComboBoxModel.setObjects(periods); + financialPeriodComboBoxModel.setSelectedItem(selectedFinancialPeriod); setFilter(selectedFiscalPeriod, selectedFinancialPeriod, selectedFinancialPeriod.getBeginDate(), selectedFinancialPeriod.getEndDate(), PeriodChoice.FINANCIAL_PERIOD); } else { @@ -282,7 +333,7 @@ public class AccountViewerViewHandler { } } - protected void onFinancialPeriodChange(java.awt.event.ItemEvent event) { + protected void onFinancialPeriodChange(ItemEvent event) { FinancialPeriod financialPeriod = (FinancialPeriod) event.getItem(); if (initializationComplete && filter.getFinancialPeriod() == null || !filter.getFinancialPeriod().equals(financialPeriod)) { updateAllEntriesForFinancialPeriodChoice(financialPeriod); @@ -317,16 +368,17 @@ public class AccountViewerViewHandler { } public void onSelectionModeChanged(SelectionMode selectionMode) { + AccountViewerSelectionModel accountViewerSelectionModel = (AccountViewerSelectionModel) view.getTable().getSelectionModel(); switch (selectionMode) { case LETTERED: - view.getAccountViewerSelectionModel().setLetteredSelectionMode(true); + accountViewerSelectionModel.setLetteredSelectionMode(true); break; case MANUAL: - view.getAccountViewerSelectionModel().setLetteredSelectionMode(false); + accountViewerSelectionModel.setLetteredSelectionMode(false); break; default: - view.getAccountViewerSelectionModel().setLetteredSelectionMode(true); + accountViewerSelectionModel.setLetteredSelectionMode(true); } } @@ -371,7 +423,8 @@ public class AccountViewerViewHandler { && filter.getDateStart() != null && filter.getDateEnd() != null) { List<Entry> entries = financialTransactionService.getAllEntrieByDatesAndAccountAndLettering(filter); - view.getTableModel().setValues(entries); + AccountViewerTableModel accountViewerTableModel = (AccountViewerTableModel) view.getTable().getModel(); + accountViewerTableModel.setValues(entries); updateSummary(); } @@ -472,12 +525,12 @@ public class AccountViewerViewHandler { public void initFiscalPeriodView() { List<FiscalPeriod> fiscalPeriods = fiscalPeriodService.getAllFiscalPeriods(); - view.getFiscalPeriodComboBoxModel().setObjects(fiscalPeriods); + fiscalPeriodComboBoxModel.setObjects(fiscalPeriods); FiscalPeriod fiscalPeriod = fiscalPeriodService.getLastFiscalPeriod(); if (fiscalPeriod != null) { setFilter(fiscalPeriod, null, fiscalPeriod.getBeginDate(), fiscalPeriod.getEndDate(), PeriodChoice.FINANCIAL_PERIOD); - view.getFiscalPeriodComboBoxModel().setSelectedItem(fiscalPeriod); + fiscalPeriodComboBoxModel.setSelectedItem(fiscalPeriod); view.getFiscalPeriodComboBox().setVisible(true); } } @@ -503,7 +556,7 @@ public class AccountViewerViewHandler { FinancialPeriod defaultFinancialPeriod = null; List<FinancialPeriod> financialPeriods = null; if (fiscalPeriod != null) { - view.getFinancialPeriodComboBoxModel().removeAllElements(); + financialPeriodComboBoxModel.removeAllElements(); financialPeriods = financialPeriodService.getFinancialPeriodsWithBeginDateWithin(fiscalPeriod.getBeginDate(), fiscalPeriod.getEndDate()); @@ -534,16 +587,16 @@ public class AccountViewerViewHandler { protected void updateFinancialPeriodCombo(FinancialPeriod defaultFinancialPeriod, List<FinancialPeriod> financialPeriods) { if (CollectionUtils.isNotEmpty(financialPeriods)) { - view.getFinancialPeriodComboBoxModel().setObjects(financialPeriods); - view.getFinancialPeriodComboBoxModel().setSelectedItem(defaultFinancialPeriod); + financialPeriodComboBoxModel.setObjects(financialPeriods); + financialPeriodComboBoxModel.setSelectedItem(defaultFinancialPeriod); } } protected void initFiscalPeriodCombo() { List<FiscalPeriod> fiscalPeriods = fiscalPeriodService.getAllFiscalPeriods(); - view.getFiscalPeriodComboBoxModel().setObjects(fiscalPeriods); + fiscalPeriodComboBoxModel.setObjects(fiscalPeriods); if (CollectionUtils.isNotEmpty(fiscalPeriods)) { - view.getFiscalPeriodComboBoxModel().setSelectedItem(fiscalPeriods.get(fiscalPeriods.size() - 1)); + fiscalPeriodComboBoxModel.setSelectedItem(fiscalPeriods.get(fiscalPeriods.size() - 1)); } view.getFiscalPeriodComboBox().setVisible(true); } @@ -609,8 +662,9 @@ public class AccountViewerViewHandler { log.debug("balanceAndActions"); } onBalanceChanged(null); + AccountViewerSelectionModel accountViewerSelectionModel = (AccountViewerSelectionModel) view.getTable().getSelectionModel(); if (view.getTable().getSelectedRows().length > 0 && !letteringNotExist(view.getTable().getSelectedRow()) || - view.getTable().getSelectedRows().length > 0 && !view.getAccountViewerSelectionModel().isSelectionEmpty()) { + view.getTable().getSelectedRows().length > 0 && !accountViewerSelectionModel.isSelectionEmpty()) { setValuesForSelectedEntries(); } } @@ -622,7 +676,8 @@ public class AccountViewerViewHandler { public boolean letteringNotExist(int row){ boolean emptyOrNull = false; if (row != -1) { - Entry entry = view.getTableModel().get(row); + AccountViewerTableModel accountViewerTableModel = (AccountViewerTableModel) view.getTable().getModel(); + Entry entry = accountViewerTableModel.get(row); String lettering = entry.getLettering(); emptyOrNull = (lettering==null||lettering.isEmpty()); } @@ -631,10 +686,11 @@ public class AccountViewerViewHandler { 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); + AccountViewerTableModel accountViewerTableModel = (AccountViewerTableModel) view.getTable().getModel(); + AccountViewerSelectionModel accountViewerSelectionModel = (AccountViewerSelectionModel) view.getTable().getSelectionModel(); + for (int i = 0; i < accountViewerTableModel.getRowCount(); i ++){ + if (accountViewerSelectionModel.isSelectedIndex(i)){ + selectedEntry = accountViewerTableModel.get(i); //Set values for calculation (By AccountViewerEditModel) of balance onBalanceChanged(selectedEntry); } -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
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 e137b426c073b9b24fbcca224d770c404bf5e7a2 Author: dcosse <cosse@codelutin.com> Date: Wed Sep 30 15:30:48 2015 +0200 refs #1268 déplacement de donnés liées au model de l'handler au model et suppression de listener innutils --- .../ui/accountViewer/AccountViewerEditModel.java | 68 +++++++-- .../lima/ui/accountViewer/AccountViewerFilter.java | 41 ------ .../ui/accountViewer/AccountViewerViewHandler.java | 163 +++++++++------------ 3 files changed, 120 insertions(+), 152 deletions(-) diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerEditModel.java b/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerEditModel.java index 3399584..239c34c 100644 --- a/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerEditModel.java +++ b/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerEditModel.java @@ -21,10 +21,14 @@ */ package org.chorem.lima.ui.accountViewer; -import java.beans.PropertyChangeListener; +import org.chorem.lima.entity.Account; +import org.chorem.lima.entity.FinancialPeriod; +import org.chorem.lima.entity.FiscalPeriod; + import java.beans.PropertyChangeSupport; import java.io.Serializable; import java.math.BigDecimal; +import java.util.Date; /** * @author sletellier <letellier@codelutin.com> @@ -32,12 +36,15 @@ import java.math.BigDecimal; public class AccountViewerEditModel implements Serializable { public static final String PROPERTY_DEBIT = "debit"; - public static final String PROPERTY_CREDIT = "credit"; - public static final String PROPERTY_SOLD = "sold"; - public static final String PROPERTY_GLOBAL_SOLD = "globalSold"; + protected PeriodChoice periodChoice = PeriodChoice.FINANCIAL_PERIOD; + protected FinancialPeriod financialPeriod; + protected FiscalPeriod fiscalPeriod; + protected Account account; + protected Date dateStart; + protected Date dateEnd; protected final PropertyChangeSupport pcs = new PropertyChangeSupport(this); @@ -99,28 +106,57 @@ public class AccountViewerEditModel implements Serializable { firePropertyChange(PROPERTY_SOLD, oldSold, this.sold); } - public void addPropertyChangeListener(PropertyChangeListener listener) { - pcs.addPropertyChangeListener(listener); + + protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) { + pcs.firePropertyChange(propertyName, oldValue, newValue); } - public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { - pcs.addPropertyChangeListener(propertyName, listener); + public PeriodChoice getPeriodChoice() { + return periodChoice; } - public void removePropertyChangeListener(PropertyChangeListener listener) { - pcs.removePropertyChangeListener(listener); + public void setPeriodChoice(PeriodChoice periodChoice) { + this.periodChoice = periodChoice; } - public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) { - pcs.removePropertyChangeListener(propertyName, listener); + public FinancialPeriod getFinancialPeriod() { + return financialPeriod; } - protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) { - pcs.firePropertyChange(propertyName, oldValue, newValue); + public void setFinancialPeriod(FinancialPeriod financialPeriod) { + this.financialPeriod = financialPeriod; + } + + public FiscalPeriod getFiscalPeriod() { + return fiscalPeriod; + } + + public void setFiscalPeriod(FiscalPeriod fiscalPeriod) { + this.fiscalPeriod = fiscalPeriod; + } + + public Account getAccount() { + return account; + } + + public void setAccount(Account account) { + this.account = account; + } + + public Date getDateStart() { + return dateStart; + } + + public void setDateStart(Date dateStart) { + this.dateStart = dateStart; + } + + public Date getDateEnd() { + return dateEnd; } - protected void firePropertyChange(String propertyName, Object newValue) { - firePropertyChange(propertyName, null, newValue); + public void setDateEnd(Date dateEnd) { + this.dateEnd = dateEnd; } } diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerFilter.java b/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerFilter.java deleted file mode 100644 index 362cf69..0000000 --- a/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerFilter.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.chorem.lima.ui.accountViewer; - -import org.chorem.lima.beans.LetteringFilterImpl; -import org.chorem.lima.entity.FinancialPeriod; -import org.chorem.lima.entity.FiscalPeriod; - -/** - * Created by davidcosse on 21/09/15. - */ -public class AccountViewerFilter extends LetteringFilterImpl { - - protected PeriodChoice periodChoice = PeriodChoice.FINANCIAL_PERIOD; - - protected FinancialPeriod financialPeriod; - - protected FiscalPeriod fiscalPeriod; - - public PeriodChoice getPeriodChoice() { - return periodChoice; - } - - public void setPeriodChoice(PeriodChoice periodChoice) { - this.periodChoice = periodChoice; - } - - public FinancialPeriod getFinancialPeriod() { - return financialPeriod; - } - - public void setFinancialPeriod(FinancialPeriod financialPeriod) { - this.financialPeriod = financialPeriod; - } - - public FiscalPeriod getFiscalPeriod() { - return fiscalPeriod; - } - - public void setFiscalPeriod(FiscalPeriod fiscalPeriod) { - this.fiscalPeriod = fiscalPeriod; - } -} 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 index d79fbdc..a281089 100644 --- 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 @@ -54,7 +54,6 @@ import java.awt.event.InputEvent; import java.awt.event.ItemEvent; import java.awt.event.KeyEvent; import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; import java.math.BigDecimal; import java.text.DateFormat; import java.text.SimpleDateFormat; @@ -86,8 +85,6 @@ public class AccountViewerViewHandler { protected FinancialTransactionService financialTransactionService; protected FiscalPeriodService fiscalPeriodService; - protected AccountViewerFilter filter; - protected AccountViewerTableModel accountViewerTableModel; protected AccountViewerSelectionModel accountViewerSelectionModel; protected AccountViewerEditModel editModel; @@ -122,7 +119,6 @@ public class AccountViewerViewHandler { * Init all combo box in view. */ public void init() { - filter = new AccountViewerFilter(); createComponentsModels(); @@ -163,37 +159,10 @@ public class AccountViewerViewHandler { public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { view.getHandler().balanceAndActions(); + updateSoldStatus(); } } }); - - 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(); - } - }); } protected void initAccountTableView() { @@ -240,21 +209,21 @@ public class AccountViewerViewHandler { } protected void onPeriodChoiceChanged(PeriodChoice periodChoice) { - if (initializationComplete && !filter.getPeriodChoice().equals(periodChoice)) { - filter.setPeriodChoice(periodChoice); - switch (periodChoice) { - case FINANCIAL_PERIOD: - initViewForPeriodChoiceChange(true, true, false); - updateAllEntriesForFinancialPeriodChoice(); - break; - case FISCAL_PERIOD: - initViewForPeriodChoiceChange(true, false, false); - updateAllEntriesForFiscalPeriodChoice(); - break; - case DATE: - initViewForPeriodChoiceChange(false, false, true); - updateAllEntriesForDateIntervalChoice(); - break; + if (initializationComplete && !editModel.getPeriodChoice().equals(periodChoice)) { + editModel.setPeriodChoice(periodChoice); + switch (periodChoice) { + case FINANCIAL_PERIOD: + initViewForPeriodChoiceChange(true, true, false); + updateAllEntriesForFinancialPeriodChoice(); + break; + case FISCAL_PERIOD: + initViewForPeriodChoiceChange(true, false, false); + updateAllEntriesForFiscalPeriodChoice(); + break; + case DATE: + initViewForPeriodChoiceChange(false, false, true); + updateAllEntriesForDateIntervalChoice(); + break; } } } @@ -318,8 +287,8 @@ public class AccountViewerViewHandler { protected void onFiscalPeriodChange(ItemEvent event) { FiscalPeriod selectedFiscalPeriod = event != null && event.getItem() != null ? (FiscalPeriod) event.getItem() : null; - if (initializationComplete && selectedFiscalPeriod != null && !selectedFiscalPeriod.equals(filter.getFiscalPeriod())) { - if (PeriodChoice.FINANCIAL_PERIOD.equals(filter.getPeriodChoice())) { + if (initializationComplete && selectedFiscalPeriod != null && !selectedFiscalPeriod.equals(editModel.getFiscalPeriod())) { + if (PeriodChoice.FINANCIAL_PERIOD.equals(editModel.getPeriodChoice())) { List<FinancialPeriod> periods = financialPeriodService.getFinancialPeriodsWithBeginDateWithin(selectedFiscalPeriod.getBeginDate(), selectedFiscalPeriod.getEndDate()); FinancialPeriod selectedFinancialPeriod = periods.get(0); financialPeriodComboBoxModel.setObjects(periods); @@ -335,18 +304,18 @@ public class AccountViewerViewHandler { protected void onFinancialPeriodChange(ItemEvent event) { FinancialPeriod financialPeriod = (FinancialPeriod) event.getItem(); - if (initializationComplete && filter.getFinancialPeriod() == null || !filter.getFinancialPeriod().equals(financialPeriod)) { + if (initializationComplete && editModel.getFinancialPeriod() == null || !editModel.getFinancialPeriod().equals(financialPeriod)) { updateAllEntriesForFinancialPeriodChoice(financialPeriod); } } public void onDateStartChange(Date date) { if (initializationComplete) { - if (date != null && !DateUtils.isSameDay(date, filter.getDateStart())) { - filter.setDateStart(date); + if (date != null && !DateUtils.isSameDay(date, editModel.getDateStart())) { + editModel.setDateStart(date); - if (filter.getDateEnd().before(date)) { - filter.setDateEnd(date); + if (editModel.getDateEnd().before(date)) { + editModel.setDateEnd(date); view.getEndPeriodPicker().setDate(date); } updateAllEntriesForDateChange(); @@ -356,10 +325,10 @@ public class AccountViewerViewHandler { public void onDateEndChange(Date date) { if (initializationComplete) { - if (date != null && !DateUtils.isSameDay(date, filter.getDateEnd())) { - filter.setDateEnd(date); - if (filter.getDateStart().after(date)) { - filter.setDateStart(date); + if (date != null && !DateUtils.isSameDay(date, editModel.getDateEnd())) { + editModel.setDateEnd(date); + if (editModel.getDateStart().after(date)) { + editModel.setDateStart(date); view.getBeginPeriodPicker().setDate(date); } updateAllEntriesForDateChange(); @@ -405,23 +374,27 @@ public class AccountViewerViewHandler { } protected void setFilter(FiscalPeriod fiscalPeriod, FinancialPeriod financialPeriod, Date dateStart, Date dateEnd, PeriodChoice periodChoice) { - filter.setFiscalPeriod(fiscalPeriod); - filter.setFinancialPeriod(financialPeriod); - filter.setDateStart(dateStart); - filter.setDateEnd(dateEnd); - filter.setPeriodChoice(periodChoice); + editModel.setFiscalPeriod(fiscalPeriod); + editModel.setFinancialPeriod(financialPeriod); + editModel.setDateStart(dateStart); + editModel.setDateEnd(dateEnd); + editModel.setPeriodChoice(periodChoice); } public void updateAllEntriesForDateChange() { - filter.setPeriodChoice(PeriodChoice.DATE); + editModel.setPeriodChoice(PeriodChoice.DATE); updateAllEntries(); } public void updateAllEntries() { if (initializationComplete - && filter.getAccount() != null - && filter.getDateStart() != null - && filter.getDateEnd() != null) { + && editModel.getAccount() != null + && editModel.getDateStart() != null + && editModel.getDateEnd() != null) { + LetteringFilter filter = new LetteringFilterImpl(); + filter.setAccount(editModel.getAccount()); + filter.setDateStart(editModel.getDateStart()); + filter.setDateEnd(editModel.getDateEnd()); List<Entry> entries = financialTransactionService.getAllEntrieByDatesAndAccountAndLettering(filter); AccountViewerTableModel accountViewerTableModel = (AccountViewerTableModel) view.getTable().getModel(); accountViewerTableModel.setValues(entries); @@ -443,9 +416,9 @@ public class AccountViewerViewHandler { LetteringFilter previousPeriodFilter = null; FiscalPeriod previousFiscalPeriod; Date dateStart = null, dateEnd = null; - switch (filter.getPeriodChoice()) { + switch (editModel.getPeriodChoice()) { case FINANCIAL_PERIOD: - Date financialPeriodDate = filter.getFinancialPeriod().getBeginDate(); + Date financialPeriodDate = editModel.getFinancialPeriod().getBeginDate(); FiscalPeriod fiscalPeriodFiscalPeriod = fiscalPeriodService.getFiscalPeriodForDate(financialPeriodDate); if (DateUtils.isSameDay(financialPeriodDate, fiscalPeriodFiscalPeriod.getBeginDate())) { @@ -456,29 +429,29 @@ public class AccountViewerViewHandler { dateEnd = getDayMinus1Calendar(financialPeriodDate).getTime(); break; case FISCAL_PERIOD: - previousFiscalPeriod = fiscalPeriodService.getFiscalPeriodForDate(getDayMinus1Calendar(filter.getFiscalPeriod().getBeginDate()).getTime()); + previousFiscalPeriod = fiscalPeriodService.getFiscalPeriodForDate(getDayMinus1Calendar(editModel.getFiscalPeriod().getBeginDate()).getTime()); if (previousFiscalPeriod != null) { dateStart = previousFiscalPeriod.getBeginDate(); dateEnd = previousFiscalPeriod.getEndDate(); } break; case DATE: - previousFiscalPeriod = fiscalPeriodService.getFiscalPeriodForDate(filter.getDateStart()); + previousFiscalPeriod = fiscalPeriodService.getFiscalPeriodForDate(editModel.getDateStart()); // case of starting date is same as current fiscal period one, so we look for previous fiscal period - if (previousFiscalPeriod != null && DateUtils.isSameDay(previousFiscalPeriod.getBeginDate(), filter.getDateStart())) { - previousFiscalPeriod = fiscalPeriodService.getFiscalPeriodForDate(getDayMinus1Calendar(filter.getDateStart()).getTime()); + if (previousFiscalPeriod != null && DateUtils.isSameDay(previousFiscalPeriod.getBeginDate(), editModel.getDateStart())) { + previousFiscalPeriod = fiscalPeriodService.getFiscalPeriodForDate(getDayMinus1Calendar(editModel.getDateStart()).getTime()); } // case of selected date is upper the last fiscal period we look for the last fiscal period if (previousFiscalPeriod == null) { FiscalPeriod lastFiscalPeriod = fiscalPeriodService.getLastFiscalPeriod(); - previousFiscalPeriod = lastFiscalPeriod != null && lastFiscalPeriod.getEndDate().before(filter.getDateStart()) ? lastFiscalPeriod : null; + previousFiscalPeriod = lastFiscalPeriod != null && lastFiscalPeriod.getEndDate().before(editModel.getDateStart()) ? lastFiscalPeriod : null; } if (previousFiscalPeriod != null) { dateStart = previousFiscalPeriod.getBeginDate(); - dateEnd = getDayMinus1Calendar(filter.getDateStart()).getTime(); + dateEnd = getDayMinus1Calendar(editModel.getDateStart()).getTime(); } break; } @@ -487,7 +460,7 @@ public class AccountViewerViewHandler { previousPeriodFilter = new LetteringFilterImpl(); previousPeriodFilter.setDateStart(dateStart); previousPeriodFilter.setDateEnd(dateEnd); - previousPeriodFilter.setAccount(filter.getAccount()); + previousPeriodFilter.setAccount(editModel.getAccount()); } return previousPeriodFilter; @@ -496,29 +469,29 @@ public class AccountViewerViewHandler { private LetteringFilter computeActualPeriodFilter() { LetteringFilter actualPeriodFilter = null; Date dateStart = null, dateEnd = null; - switch (filter.getPeriodChoice()) { + switch (editModel.getPeriodChoice()) { case FINANCIAL_PERIOD: - if (filter.getFinancialPeriod() != null) { - Date financialPeriodDate = filter.getFinancialPeriod().getBeginDate(); + if (editModel.getFinancialPeriod() != null) { + Date financialPeriodDate = editModel.getFinancialPeriod().getBeginDate(); FiscalPeriod fiscalPeriodFiscalPeriod = fiscalPeriodService.getFiscalPeriodForDate(financialPeriodDate); dateStart = fiscalPeriodFiscalPeriod.getBeginDate(); - dateEnd = filter.getFinancialPeriod().getEndDate(); + dateEnd = editModel.getFinancialPeriod().getEndDate(); } break; case FISCAL_PERIOD: - dateStart = filter.getFiscalPeriod() == null ? null : filter.getFiscalPeriod().getBeginDate(); - dateEnd = filter.getFiscalPeriod() == null ? null : filter.getFiscalPeriod().getEndDate(); + dateStart = editModel.getFiscalPeriod() == null ? null : editModel.getFiscalPeriod().getBeginDate(); + dateEnd = editModel.getFiscalPeriod() == null ? null : editModel.getFiscalPeriod().getEndDate(); break; case DATE: - dateStart = filter.getFiscalPeriod() == null ? filter.getDateStart() : filter.getFiscalPeriod().getBeginDate(); - dateEnd = filter.getDateEnd(); + dateStart = editModel.getFiscalPeriod() == null ? editModel.getDateStart() : editModel.getFiscalPeriod().getBeginDate(); + dateEnd = editModel.getDateEnd(); break; } if (dateStart != null && dateEnd != null) { actualPeriodFilter = new LetteringFilterImpl(); actualPeriodFilter.setDateStart(dateStart); actualPeriodFilter.setDateEnd(dateEnd); - actualPeriodFilter.setAccount(filter.getAccount()); + actualPeriodFilter.setAccount(editModel.getAccount()); } return actualPeriodFilter; } @@ -602,14 +575,14 @@ public class AccountViewerViewHandler { } protected void initSoldPeriodView() { - Date ppbd = filter.getFiscalPeriod() != null ? filter.getFiscalPeriod().getBeginDate() : new Date(); - Date pped = filter.getFinancialPeriod() != null ? getDayMinus1Calendar(filter.getFinancialPeriod().getBeginDate()).getTime() : new Date(); + Date ppbd = editModel.getFiscalPeriod() != null ? editModel.getFiscalPeriod().getBeginDate() : new Date(); + Date pped = editModel.getFinancialPeriod() != null ? getDayMinus1Calendar(editModel.getFinancialPeriod().getBeginDate()).getTime() : new Date(); view.getBeginPeriodSummary().setText(String.format(t("lima.accountingView.summaryLabel"), getDateFormat().format(ppbd), getDateFormat().format(pped))); view.getBeginDebit().setText(BigDecimalToString.format(BigDecimal.ZERO)); view.getBeginCredit().setText(BigDecimalToString.format(BigDecimal.ZERO)); view.getBeginSold().setText(BigDecimalToString.format(BigDecimal.ZERO)); - Date aped = filter.getFinancialPeriod() != null ? filter.getFinancialPeriod().getEndDate() : new Date(); + Date aped = editModel.getFinancialPeriod() != null ? editModel.getFinancialPeriod().getEndDate() : new Date(); view.getEndPeriodSummary().setText(String.format(t("lima.accountingView.summaryLabel"), getDateFormat().format(ppbd), getDateFormat().format(aped))); view.getEndDebit().setText(BigDecimalToString.format(BigDecimal.ZERO)); view.getEndCredit().setText(BigDecimalToString.format(BigDecimal.ZERO)); @@ -618,7 +591,7 @@ public class AccountViewerViewHandler { protected void setViewPreviousSold(LetteringFilter previousPeriodFilter) { if (previousPeriodFilter != null) { - if (filter.getPeriodChoice().equals(PeriodChoice.FISCAL_PERIOD)) { + if (editModel.getPeriodChoice().equals(PeriodChoice.FISCAL_PERIOD)) { String summaryLabel = t("lima.accountingView.summaryFiscalPeriodLabel"); view.getBeginPeriodSummary().setText(String.format(t(summaryLabel), YYYY.format(previousPeriodFilter.getDateStart()))); } else { @@ -632,7 +605,7 @@ public class AccountViewerViewHandler { view.getBeginCredit().setText(BigDecimalToString.format(debitCreditSold.getCredit())); view.getBeginSold().setText(BigDecimalToString.format(debitCreditSold.getSold())); } else { - String summaryLabel = filter.getPeriodChoice().equals(PeriodChoice.FISCAL_PERIOD) ? t("lima.accountingView.summaryNoFiscalPeriodLabel") : t("lima.accountingView.summaryNoPeriodLabel"); + String summaryLabel = editModel.getPeriodChoice().equals(PeriodChoice.FISCAL_PERIOD) ? t("lima.accountingView.summaryNoFiscalPeriodLabel") : t("lima.accountingView.summaryNoPeriodLabel"); view.getBeginPeriodSummary().setText(summaryLabel); view.getBeginDebit().setText(BigDecimalToString.format(BigDecimal.ZERO)); view.getBeginCredit().setText(BigDecimalToString.format(BigDecimal.ZERO)); @@ -642,7 +615,7 @@ public class AccountViewerViewHandler { } protected void setViewActualSold(LetteringFilter actualPeriodFilter) { - if (filter.getPeriodChoice().equals(PeriodChoice.FISCAL_PERIOD)) { + if (editModel.getPeriodChoice().equals(PeriodChoice.FISCAL_PERIOD)) { String summaryLabel = t("lima.accountingView.summaryFiscalPeriodLabel"); view.getEndPeriodSummary().setText(String.format(t(summaryLabel), YYYY.format(actualPeriodFilter.getDateEnd()))); } else { @@ -775,16 +748,16 @@ public class AccountViewerViewHandler { } public void setAccount(Account account) { - if (filter != null) { - filter.setAccount(account); + if (editModel != null) { + editModel.setAccount(account); updateAllEntries(); } } public Account getAccount() { Account account = null; - if (filter != null) { - account = filter.getAccount(); + if (editModel != null) { + account = editModel.getAccount(); } return account; } -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
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 ee5abac225ee24638091826aac1a7460eb11cf7c Author: dcosse <cosse@codelutin.com> Date: Mon Nov 30 14:13:39 2015 +0100 refs #1293 correction traductions --- lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties | 1 - 1 file changed, 1 deletion(-) 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 bef1571..29d8443 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 @@ -463,7 +463,6 @@ lima.lettering.account.aAll=All lima.lettering.account.back=← lima.lettering.account.next=→ lima.lettering.accountViewerBalanceStatus=<html>From %s to %s\: Sold is\: <b>%s - %s \= %s</b> - Selected entries sold\: <b>%s - %s \= %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 -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm