This is an automated email from the git hooks/post-receive script. New change to branch feature/1293-addAccountViewerTabWithCloseColumnAndDTO in repository lima. See http://git.chorem.org/lima.git at 71ed649 refs #1293 Ajout d'une colone Clos, est utilisation d'un DTO à la place de Entry This branch includes the following new commits: new 71ed649 refs #1293 Ajout d'une colone Clos, est utilisation d'un DTO à la place de Entry The 1 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 71ed649d62e2a645680353ee6a59701f97bb3162 Author: dcosse <cosse@codelutin.com> Date: Thu Sep 17 19:03:11 2015 +0200 refs #1293 Ajout d'une colone Clos, est utilisation d'un DTO à la place de Entry -- 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-addAccountViewerTabWithCloseColumnAndDTO in repository lima. See http://git.chorem.org/lima.git commit 71ed649d62e2a645680353ee6a59701f97bb3162 Author: dcosse <cosse@codelutin.com> Date: Thu Sep 17 19:03:11 2015 +0200 refs #1293 Ajout d'une colone Clos, est utilisation d'un DTO à la place de Entry --- .../api/ClosedPeriodicEntryBookService.java | 2 + .../business/api/FinancialTransactionService.java | 2 +- .../ejb/ClosedPeriodicEntryBookServiceImpl.java | 7 + .../ejb/FinancialTransactionServiceImpl.java | 2 +- .../entity/ClosedPeriodicEntryBookTopiaDao.java | 20 ++- .../java/org/chorem/lima/entity/EntryTopiaDao.java | 3 + .../ui/accountViewer/AccountViewerEntryDto.java | 133 +++++++++++++++++ .../accountViewer/AccountViewerSelectionModel.java | 11 +- .../ui/accountViewer/AccountViewerTableModel.java | 77 +++++----- .../ui/accountViewer/AccountViewerViewHandler.java | 162 ++++++++++++--------- .../lima/ui/accountViewer/SelectionMode.java | 6 +- .../ui/fiscalperiod/FiscalPeriodTableModel.java | 2 +- .../lima/ui/lettering/LetteringViewHandler.java | 2 +- .../resources/i18n/lima-swing_en_GB.properties | 5 +- .../resources/i18n/lima-swing_fr_FR.properties | 9 +- .../icons/action-financialPeriod-close.png | Bin 715 -> 452 bytes .../resources/icons/action-fiscalPeriod-close.png | Bin 715 -> 452 bytes 17 files changed, 312 insertions(+), 131 deletions(-) diff --git a/lima-business-api/src/main/java/org/chorem/lima/business/api/ClosedPeriodicEntryBookService.java b/lima-business-api/src/main/java/org/chorem/lima/business/api/ClosedPeriodicEntryBookService.java index 5a06347..77b94bf 100644 --- a/lima-business-api/src/main/java/org/chorem/lima/business/api/ClosedPeriodicEntryBookService.java +++ b/lima-business-api/src/main/java/org/chorem/lima/business/api/ClosedPeriodicEntryBookService.java @@ -38,5 +38,7 @@ public interface ClosedPeriodicEntryBookService { List<ClosedPeriodicEntryBook> getAllByDates(Date beginDate, Date endDate); + List<String> getAllLockedEntryBookIdsFrom(Date beginDate); + List<ClosedPeriodicEntryBook> getAllByEntryBookAndDates(EntryBook entryBook, Date beginDate, Date endDate); } 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 d34f445..516c234 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 @@ -123,7 +123,7 @@ public interface FinancialTransactionService { * pour un compte et la présence d'un lettrage ou (xor) non * @param filter filtre sur les entrees, selon le compte, les dates de debut et de fin, et le lettrage * */ - List<Entry> getAllEntrieByDatesAndAccountAndLettering(LetteringFilter filter); + List<Entry> getAllEntriesByDatesAndAccountAndLettering(LetteringFilter filter); /** * Retourne la somme des débits credits des entrées associées à une action pour une prériode définie diff --git a/lima-business/src/main/java/org/chorem/lima/business/ejb/ClosedPeriodicEntryBookServiceImpl.java b/lima-business/src/main/java/org/chorem/lima/business/ejb/ClosedPeriodicEntryBookServiceImpl.java index 19230bf..842ebc8 100644 --- a/lima-business/src/main/java/org/chorem/lima/business/ejb/ClosedPeriodicEntryBookServiceImpl.java +++ b/lima-business/src/main/java/org/chorem/lima/business/ejb/ClosedPeriodicEntryBookServiceImpl.java @@ -60,6 +60,13 @@ public class ClosedPeriodicEntryBookServiceImpl extends AbstractLimaService impl } @Override + public List<String> getAllLockedEntryBookIdsFrom(Date beginDate) { + ClosedPeriodicEntryBookTopiaDao closedPeriodicEntryBookTopiaDao = getDaoHelper().getClosedPeriodicEntryBookDao(); + List<String> result = closedPeriodicEntryBookTopiaDao.findAllLockedEntryBookIdsFrom(beginDate); + return result; + } + + @Override public List<ClosedPeriodicEntryBook> getAllByEntryBookAndDates(EntryBook entryBook, Date beginDate, Date endDate) { ClosedPeriodicEntryBookTopiaDao closedPeriodicEntryBookTopiaDao = getDaoHelper().getClosedPeriodicEntryBookDao(); List<ClosedPeriodicEntryBook> result = 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 13cba58..36677f3 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 @@ -461,7 +461,7 @@ public class FinancialTransactionServiceImpl extends AbstractLimaService impleme } @Override - public List<Entry> getAllEntrieByDatesAndAccountAndLettering(LetteringFilter filter) { + public List<Entry> getAllEntriesByDatesAndAccountAndLettering(LetteringFilter filter) { EntryTopiaDao entryTopiaDao = getDaoHelper().getEntryDao(); List<Entry> entries = entryTopiaDao.findAllEntryByFilter(filter); diff --git a/lima-business/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookTopiaDao.java b/lima-business/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookTopiaDao.java index 6abae2d..1e1b5e8 100644 --- a/lima-business/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookTopiaDao.java +++ b/lima-business/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookTopiaDao.java @@ -23,6 +23,7 @@ package org.chorem.lima.entity; import org.nuiton.topia.persistence.HqlAndParametersBuilder; +import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.TopiaQueryBuilderAddCriteriaOrRunQueryStep; import java.util.Date; @@ -83,7 +84,7 @@ public class ClosedPeriodicEntryBookTopiaDao extends AbstractClosedPeriodicEntry HqlAndParametersBuilder<ClosedPeriodicEntryBook> builder = newHqlAndParametersBuilder(); builder.addGreaterOrEquals(PROPERTY_BEGIN_DATE, beginDate); - builder.addGreaterOrEquals(PROPERTY_END_DATE, endDate); + builder.addLowerOrEquals(PROPERTY_END_DATE, endDate); builder.setOrderByArguments(ClosedPeriodicEntryBook.PROPERTY_ENTRY_BOOK + "." + EntryBook.PROPERTY_CODE); List<ClosedPeriodicEntryBook> closedPeriodicEntryBooks = findAll(builder.getHql(), builder.getHqlParameters()); @@ -104,7 +105,7 @@ public class ClosedPeriodicEntryBookTopiaDao extends AbstractClosedPeriodicEntry HqlAndParametersBuilder<ClosedPeriodicEntryBook> builder = newHqlAndParametersBuilder(); builder.addGreaterOrEquals(PROPERTY_BEGIN_DATE, beginDate); - builder.addGreaterOrEquals(PROPERTY_END_DATE, endDate); + builder.addLowerOrEquals(PROPERTY_END_DATE, endDate); builder.addEquals(ClosedPeriodicEntryBook.PROPERTY_ENTRY_BOOK, entryBook); List<ClosedPeriodicEntryBook> closedPeriodicEntryBooks = findAll(builder.getHql(), builder.getHqlParameters()); @@ -125,7 +126,7 @@ public class ClosedPeriodicEntryBookTopiaDao extends AbstractClosedPeriodicEntry HqlAndParametersBuilder<ClosedPeriodicEntryBook> builder = newHqlAndParametersBuilder(); builder.addGreaterOrEquals(PROPERTY_BEGIN_DATE, beginDate); - builder.addGreaterOrEquals(PROPERTY_END_DATE, endDate); + builder.addLowerOrEquals(PROPERTY_END_DATE, endDate); builder.addEquals(ClosedPeriodicEntryBook.PROPERTY_ENTRY_BOOK, entryBook); builder.addEquals(ClosedPeriodicEntryBook.PROPERTY_LOCKED, true); @@ -179,4 +180,17 @@ public class ClosedPeriodicEntryBookTopiaDao extends AbstractClosedPeriodicEntry return closedPeriodicEntryBooks; } + + public List<String> findAllLockedEntryBookIdsFrom(Date beginDate) { + + HqlAndParametersBuilder<ClosedPeriodicEntryBook> builder = newHqlAndParametersBuilder(); + builder.addGreaterOrEquals(PROPERTY_BEGIN_DATE, beginDate); + builder.addEquals(ClosedPeriodicEntryBook.PROPERTY_LOCKED, true); + + String query = "SELECT DISTINCT " + builder.getAlias() + "." + ClosedPeriodicEntryBook.PROPERTY_ENTRY_BOOK + "." + TopiaEntity.PROPERTY_TOPIA_ID + " " + + builder.getHql(); + + List<String> closedPeriodicEntryBooks = findAll(query, builder.getHqlParameters()); + return closedPeriodicEntryBooks; + } } 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 254a2d1..c5e0118 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 @@ -226,6 +226,9 @@ public class EntryTopiaDao extends AbstractEntryTopiaDao<Entry> { "OR " + alias + "." + Entry.PROPERTY_LETTERING + " != ''"); } + + builder.setOrderByArguments(Entry.PROPERTY_FINANCIAL_TRANSACTION + "." + FinancialTransaction.PROPERTY_TRANSACTION_DATE); + List<Entry> entries = findAll(builder.getHql(), builder.getHqlParameters()); return entries; diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerEntryDto.java b/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerEntryDto.java new file mode 100644 index 0000000..69ebdf8 --- /dev/null +++ b/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerEntryDto.java @@ -0,0 +1,133 @@ +package org.chorem.lima.ui.accountViewer; + +import org.chorem.lima.entity.Entry; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * Created by davidcosse on 17/09/15. + */ +public class AccountViewerEntryDto{ + protected boolean isInitialSold; + protected boolean isGlobalSold; + + protected boolean locked; + protected Date transactionDate; + protected String entryBookCode; + protected String voucher; + protected String description; + protected String lettering; + protected BigDecimal debit; + protected BigDecimal credit; + protected BigDecimal sold; + + public AccountViewerEntryDto() { + } + + public AccountViewerEntryDto(Entry entry, BigDecimal previousSold, boolean locked) { + setEntry(entry, previousSold, locked); + } + + public void setEntry (Entry entry, BigDecimal previousSold, boolean locked) { + transactionDate = entry.getFinancialTransaction().getTransactionDate(); + entryBookCode = entry.getFinancialTransaction().getEntryBook().getCode(); + voucher = entry.getVoucher(); + description = entry.getDescription(); + lettering = entry.getLettering(); + debit = entry.isDebit() ? entry.getAmount().abs() : BigDecimal.ZERO; + credit = entry.isDebit() ? BigDecimal.ZERO : entry.getAmount().abs(); + previousSold = previousSold.add(debit); + previousSold = previousSold.subtract(credit); + sold = previousSold; + this.locked = locked; + } + + public boolean isInitialSold() { + return isInitialSold; + } + + public void setIsInitialSold(boolean isInitialSold) { + this.isInitialSold = isInitialSold; + } + + public boolean isGlobalSold() { + return isGlobalSold; + } + + public void setIsGlobalSold(boolean isGlobalSold) { + this.isGlobalSold = isGlobalSold; + } + + public boolean isLocked() { + return locked; + } + + public void setIsLocked(boolean isLocked) { + this.locked = isLocked; + } + + public Date getTransactionDate() { + return transactionDate; + } + + public void setTransactionDate(Date transactionDate) { + this.transactionDate = transactionDate; + } + + public String getEntryBookCode() { + return entryBookCode; + } + + public void setEntryBookCode(String entryBookCode) { + this.entryBookCode = entryBookCode; + } + + public String getVoucher() { + return voucher; + } + + public void setVoucher(String voucher) { + this.voucher = voucher; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getLettering() { + return lettering; + } + + public void setLettering(String lettering) { + this.lettering = lettering; + } + + public BigDecimal getDebit() { + return debit; + } + + public void setDebit(BigDecimal debit) { + this.debit = debit; + } + + public BigDecimal getCredit() { + return credit; + } + + public void setCredit(BigDecimal credit) { + this.credit = credit; + } + + public BigDecimal getSold() { + return sold; + } + + public void setSold(BigDecimal sold) { + this.sold = sold; + } +} 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 index 5199a0b..3d31858 100644 --- 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 @@ -22,7 +22,6 @@ package org.chorem.lima.ui.accountViewer; */ import org.apache.commons.lang3.StringUtils; -import org.chorem.lima.entity.Entry; import javax.swing.*; import java.beans.PropertyChangeListener; @@ -35,7 +34,7 @@ import java.util.List; public class AccountViewerSelectionModel extends DefaultListSelectionModel{ protected AccountViewerTableModel letteringTableModel; - protected Entry entry; + protected AccountViewerEntryDto entry; protected int lineSelected; protected boolean balancedSelectionMode; @@ -62,7 +61,7 @@ public class AccountViewerSelectionModel extends DefaultListSelectionModel{ String currentLettring = getCurrentLettring(); //select entries with the same letter of the selected entry - for(Entry entry : getEntries()){ + for(AccountViewerEntryDto entry : getEntries()){ if (StringUtils.isNotBlank(entry.getLettering())){ if (entry.getLettering().equals(currentLettring)){ int entryToSelect = letteringTableModel.indexOf(entry); @@ -76,7 +75,7 @@ public class AccountViewerSelectionModel extends DefaultListSelectionModel{ //unlettred entries //To clear the selection when it changes from lettered entry to unlettered - for(Entry entry : getEntries()){ + for(AccountViewerEntryDto entry : getEntries()){ if (!StringUtils.isBlank(entry.getLettering())) { int entryToSelect = letteringTableModel.indexOf(entry); super.removeSelectionInterval(entryToSelect, entryToSelect); @@ -114,7 +113,7 @@ public class AccountViewerSelectionModel extends DefaultListSelectionModel{ return emptyOrNull; } - public List<Entry> getEntries(){ + public List<AccountViewerEntryDto> getEntries(){ return letteringTableModel.getValues(); } @@ -122,7 +121,7 @@ public class AccountViewerSelectionModel extends DefaultListSelectionModel{ return getCurrentEntrySelected().getLettering(); } - public Entry getCurrentEntrySelected(){ + public AccountViewerEntryDto getCurrentEntrySelected(){ return letteringTableModel.get(lineSelected); } 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 index e6a3a5a..0a17692 100644 --- 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 @@ -22,12 +22,14 @@ 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 javax.imageio.ImageIO; +import javax.swing.*; +import java.awt.*; +import java.io.IOException; +import java.io.InputStream; import java.math.BigDecimal; import java.util.Date; @@ -40,47 +42,44 @@ import static org.nuiton.i18n.I18n.t; * @author ore * @author chatellier */ -public class AccountViewerTableModel extends AbstractLimaTableModel<Entry> { +public class AccountViewerTableModel extends AbstractLimaTableModel<AccountViewerEntryDto> { /** serialVersionUID. */ private static final long serialVersionUID = 1L; - public BigDecimal getPreviousPeriodSold() { - return previousPeriodSold; - } - - protected BigDecimal previousPeriodSold; + protected ImageIcon lockedImageIcon; @Override protected void initColumn() { - addColumn(new AbstractColumn<AccountViewerTableModel>(Date.class, t("lima.table.date"), false) { + addColumn(new AbstractColumn<AccountViewerTableModel>(ImageIcon.class, t("lima.table.locked"), false) { @Override public Object getValueAt(int row) { - Entry entry = tableModel.get(row); - return entry.getFinancialTransaction().getTransactionDate(); + AccountViewerEntryDto entry = tableModel.get(row); + ImageIcon imageIcon = entry.isLocked() ? getLockedImageIcon() : null; + return imageIcon; } }); - addColumn(new AbstractColumn<AccountViewerTableModel>(EntryBook.class, t("lima.table.entryBook"), false) { + 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().getEntryBook(); + AccountViewerEntryDto entry = tableModel.get(row); + return entry.getTransactionDate(); } }); - addColumn(new AbstractColumn<AccountViewerTableModel>(Account.class, t("lima.table.account"), false) { + addColumn(new AbstractColumn<AccountViewerTableModel>(String.class, t("lima.table.entryBook"), false) { @Override public Object getValueAt(int row) { - Entry entry = tableModel.get(row); - return entry.getAccount(); + AccountViewerEntryDto entry = tableModel.get(row); + return entry.getEntryBookCode(); } }); addColumn(new AbstractColumn<AccountViewerTableModel>(String.class, t("lima.table.voucher"), false) { @Override public Object getValueAt(int row) { - Entry entry = tableModel.get(row); + AccountViewerEntryDto entry = tableModel.get(row); return entry.getVoucher(); } }); @@ -88,7 +87,7 @@ public class AccountViewerTableModel extends AbstractLimaTableModel<Entry> { addColumn(new AbstractColumn<AccountViewerTableModel>(String.class, t("lima.table.description"), false) { @Override public Object getValueAt(int row) { - Entry entry = tableModel.get(row); + AccountViewerEntryDto entry = tableModel.get(row); return entry.getDescription(); } }); @@ -96,7 +95,7 @@ public class AccountViewerTableModel extends AbstractLimaTableModel<Entry> { addColumn(new AbstractColumn<AccountViewerTableModel>(String.class, t("lima.table.letter"), false) { @Override public Object getValueAt(int row) { - Entry entry = tableModel.get(row); + AccountViewerEntryDto entry = tableModel.get(row); return entry.getLettering(); } }); @@ -104,41 +103,41 @@ public class AccountViewerTableModel extends AbstractLimaTableModel<Entry> { 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; + AccountViewerEntryDto entry = tableModel.get(row); + return entry.getDebit(); } }); 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(); + AccountViewerEntryDto entry = tableModel.get(row); + return entry.getCredit(); } }); 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++; - } - - } + AccountViewerEntryDto currentEntry = tableModel.get(row); + BigDecimal result = currentEntry.getSold(); return result; } }); } - public void setPreviousPeriodSold(BigDecimal previousPeriodSold) { - this.previousPeriodSold = previousPeriodSold; + protected ImageIcon getLockedImageIcon() { + if (lockedImageIcon == null) { + InputStream stream = AccountViewerTableModel.class.getResourceAsStream("/icons/action-financialPeriod-close.png"); + Image lockedIcon; + try { + lockedIcon = ImageIO.read(stream); + lockedImageIcon = new ImageIcon(lockedIcon); + } catch (IOException e) { + e.printStackTrace(); + } + } + return lockedImageIcon; } } 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 569d1a6..a72fca3 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 @@ -23,6 +23,7 @@ package org.chorem.lima.ui.accountViewer; import com.google.common.collect.Lists; +import jaxx.runtime.SwingUtil; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.logging.Log; @@ -32,21 +33,17 @@ 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.ClosedPeriodicEntryBookService; 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; @@ -75,17 +72,14 @@ import static org.nuiton.i18n.I18n.t; */ public class AccountViewerViewHandler { - // fixme Date format should be app parameters - protected static String DATE_FORMAT = t("lima.ui.dateFormat"); - protected AccountViewerView view; - protected AccountViewerTable table; - protected FiscalPeriodService fiscalPeriodService; - protected FinancialPeriodService financialPeriodService; protected AccountService accountService; - protected FinancialTransactionService financialTransactionService; + protected ClosedPeriodicEntryBookService closedPeriodicEntryBookService; protected EntryBookService entryBookService; + protected FinancialPeriodService financialPeriodService; + protected FinancialTransactionService financialTransactionService; + protected FiscalPeriodService fiscalPeriodService; protected LetteringFilterImpl filter; @@ -93,22 +87,24 @@ public class AccountViewerViewHandler { protected ErrorHelper errorHelper; - protected SelectionMode selectionMode = SelectionMode.BALANCED; + protected SelectionMode selectionMode = SelectionMode.LETTERED; 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); + closedPeriodicEntryBookService = LimaServiceFactory.getService(ClosedPeriodicEntryBookService.class); entryBookService = LimaServiceFactory.getService(EntryBookService.class); + financialPeriodService = LimaServiceFactory.getService(FinancialPeriodService.class); + financialTransactionService = LimaServiceFactory.getService(FinancialTransactionService.class); + fiscalPeriodService = LimaServiceFactory.getService(FiscalPeriodService.class); + errorHelper = new ErrorHelper(LimaSwingConfig.getInstance()); } @@ -150,6 +146,10 @@ public class AccountViewerViewHandler { onSelectionModeChanged(selectionMode); + SwingUtil.fixTableColumnWidth(view.getTable(), 0, 50); + SwingUtil.fixTableColumnWidth(view.getTable(), 2, 50); + SwingUtil.fixTableColumnWidth(view.getTable(), 5, 50); + initializationComplete = true; updateAllEntries(); updateSoldStatus(); @@ -230,56 +230,83 @@ public class AccountViewerViewHandler { && filter.getDateStart() != null && filter.getDateEnd() != null) { - List<Entry> entriesAndResume = Lists.newArrayList(); - - List<Entry> entries = financialTransactionService.getAllEntrieByDatesAndAccountAndLettering(filter); - FiscalPeriod fiscalPeriod = fiscalPeriodService.getFiscalPeriodForDate(filter.getDateStart()); + List<Entry> entries = financialTransactionService.getAllEntriesByDatesAndAccountAndLettering(filter); + List<AccountViewerEntryDto> result = Lists.newArrayListWithExpectedSize(entries.size()); if (CollectionUtils.isNotEmpty(entries)) { - // can be null if there are no fiscal period for the begin date - if (fiscalPeriod != null) { - 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)); - } - } + + FiscalPeriod fiscalPeriod = fiscalPeriodService.getFiscalPeriodForDate(filter.getDateStart()); + + addActualFiscalPeriodSoldInfo(fiscalPeriod); + + addPreviousFiscalPeriodSoldInfo(fiscalPeriod, result); + + transformEntryToDto(entries, result, fiscalPeriod); } - entriesAndResume.addAll(entries); - view.getTableModel().setValues(entriesAndResume); + view.getTableModel().setValues(result); } onBalanceChanged(null); } - protected void addFiscalPeriodBeginDate(FiscalPeriod fiscalPeriod) { + protected void transformEntryToDto(List<Entry> entries, List<AccountViewerEntryDto> result, FiscalPeriod fiscalPeriod) { + List<String> entryBookLockedStatus = getLockedEntryBookIds(fiscalPeriod); + + BigDecimal previousSold = result.isEmpty() ? BigDecimal.ZERO : result.get(0).getSold(); + + for (Entry entry : entries) { + boolean isLocked = entryBookLockedStatus.contains(entry.getFinancialTransaction().getEntryBook().getTopiaId()); + + AccountViewerEntryDto accountViewerEntryDto = new AccountViewerEntryDto(entry, previousSold, isLocked); + + result.add(accountViewerEntryDto); + + previousSold = accountViewerEntryDto.getSold(); + } + } + + protected List<String> getLockedEntryBookIds(FiscalPeriod fiscalPeriod) { + Date periodStart = (fiscalPeriod == null ? filter.getDateStart() : (filter.getDateStart().before(fiscalPeriod.getBeginDate()) ? filter.getDateStart() : fiscalPeriod.getBeginDate())); + return closedPeriodicEntryBookService.getAllLockedEntryBookIdsFrom(periodStart); + } + + protected void addActualFiscalPeriodSoldInfo(FiscalPeriod fiscalPeriod) { + if (fiscalPeriod != null) { + LetteringFilter actualPeriodFilter = computeActualPeriodFilter(fiscalPeriod); + addGlobalActualInfoToModel(fiscalPeriod, actualPeriodFilter); + } + } + + protected void addPreviousFiscalPeriodSoldInfo(FiscalPeriod fiscalPeriod, List<AccountViewerEntryDto> entriesDtos) { + AccountViewerEntryDto result; if (fiscalPeriod != null) { - editModel.setFiscalPeriodBeginDate(fiscalPeriod.getBeginDate()); + LetteringFilter previousPeriodFilter = computePreviousPeriodFilter(fiscalPeriod); + // no previous sold to add if selected starting date is same as fiscal period one + if (!DateUtils.isSameDay(filter.getDateStart(), previousPeriodFilter.getDateStart())) { + BigDecimal previousSold = getPreviousSold(previousPeriodFilter); + result = getFirstLinePreviousSoldEntry(previousPeriodFilter, previousSold); + entriesDtos.add(result); + } } } - 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); + protected AccountViewerEntryDto getFirstLinePreviousSoldEntry(LetteringFilter previousPeriodFilter, BigDecimal previousSold) { + Date previousSoldEndDate = getDayMinus1Calendar(previousPeriodFilter.getDateEnd()).getTime(); + AccountViewerEntryDto result = new AccountViewerEntryDto(); + result.setTransactionDate(previousSoldEndDate); + result.setDescription(String.format(t("lima.accountViewer.previousSold"), getDateFormat().format(previousSoldEndDate))); + + boolean isDebit = BigDecimal.ZERO.compareTo(previousSold) < 0; + result.setDebit(isDebit ? previousSold : BigDecimal.ZERO); + result.setCredit(isDebit ? BigDecimal.ZERO : previousSold); + result.setSold(previousSold); + + result.setIsInitialSold(true); - Entry resumeEntry = new EntryImpl(); - resumeEntry.setDescription(String.format(t("lima.accountViewer.previousSold"), getDateFormat().format(previousSoldEndDate))); - resumeEntry.setAmount(view.getTableModel().getPreviousPeriodSold().abs()); - resumeEntry.setDebit(BigDecimal.ZERO.compareTo(view.getTableModel().getPreviousPeriodSold()) < 0); - resumeEntry.setFinancialTransaction(firstLineTransaction); - return resumeEntry; + return result; } - protected void setPreviousSold(LetteringFilter previousPeriodFilter) { + protected BigDecimal getPreviousSold(LetteringFilter previousPeriodFilter) { BigDecimal previousSold; if (previousPeriodFilter == null) { previousSold = BigDecimal.ZERO; @@ -288,16 +315,16 @@ public class AccountViewerViewHandler { DebitCreditSold debitCreditSold = new DebitCreditSold().invoke(initialDebitCredit); previousSold = debitCreditSold.getSold(); } - view.getTableModel().setPreviousPeriodSold(previousSold); + return previousSold; } - protected void setActualSold(FiscalPeriod fiscalPeriod, LetteringFilter actualPeriodFilter) { - addFiscalPeriodBeginDate(fiscalPeriod); + protected void addGlobalActualInfoToModel(FiscalPeriod fiscalPeriod, LetteringFilter actualPeriodFilter) { List<Object[]> initialDebitCredit = financialTransactionService.getAccountEntriesDebitCreditFromIncludingToIncludingPeriod(actualPeriodFilter); DebitCreditSold debitCreditSold = new DebitCreditSold().invoke(initialDebitCredit); editModel.setGlobalDebit(debitCreditSold.getDebit()); editModel.setGlobalCredit(debitCreditSold.getCredit()); editModel.setGlobalSold(debitCreditSold.getSold()); + editModel.setFiscalPeriodBeginDate(fiscalPeriod.getBeginDate()); } @@ -319,15 +346,15 @@ public class AccountViewerViewHandler { public boolean letteringNotExist(int row){ boolean emptyOrNull = false; if (row != -1) { - Entry entry = view.getTableModel().get(row); + AccountViewerEntryDto entry = view.getTableModel().get(row); String lettering = entry.getLettering(); - emptyOrNull = (lettering==null||lettering.isEmpty()); + emptyOrNull = (lettering == null || lettering.isEmpty()); } return emptyOrNull; } public void setValuesForSelectedEntries() { - Entry selectedEntry; + AccountViewerEntryDto selectedEntry; AccountViewerTableModel tableModel = view.getTableModel(); for (int i = 0; i < tableModel.getRowCount(); i ++){ if (view.getAccountViewerSelectionModel().isSelectedIndex(i)){ @@ -338,25 +365,20 @@ public class AccountViewerViewHandler { } } - public void onBalanceChanged(Entry balance) { + public void onBalanceChanged(AccountViewerEntryDto balance) { if (balance == null) { editModel.setCredit(BigDecimal.ZERO); editModel.setDebit(BigDecimal.ZERO); editModel.setSold(BigDecimal.ZERO, false); } else { - balanceCalculation(balance.getAmount(), balance.isDebit()); + balanceCalculation(balance.getDebit(), balance.getCredit()); } } /**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; - + public void balanceCalculation(BigDecimal debitVal, BigDecimal creditVal) + { if (log.isDebugEnabled()) { log.debug("balance calculation"); } @@ -376,9 +398,9 @@ public class AccountViewerViewHandler { } } - 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; } @@ -478,7 +500,7 @@ public class AccountViewerViewHandler { public void onSelectionModeChanged(SelectionMode selectionMode) { switch (selectionMode) { - case BALANCED: + case LETTERED: view.getAccountViewerSelectionModel().setBalancedSelectionMode(true); break; case MANUAL: diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/SelectionMode.java b/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/SelectionMode.java index 8d69868..e2f112f 100644 --- a/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/SelectionMode.java +++ b/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/SelectionMode.java @@ -7,7 +7,7 @@ import static org.nuiton.i18n.I18n.t; */ public enum SelectionMode { - BALANCED, MANUAL; + LETTERED, MANUAL; @Override public String toString() { @@ -18,8 +18,8 @@ public enum SelectionMode { case MANUAL: result = t("lima.filter.condition.selectionMode.manual"); break; - case BALANCED: - result = t("lima.filter.condition.selectionMode.balanced"); + case LETTERED: + result = t("lima.filter.condition.selectionMode.lettered"); break; } diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodTableModel.java b/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodTableModel.java index 60887dd..3cdcea3 100644 --- a/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodTableModel.java +++ b/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodTableModel.java @@ -73,7 +73,7 @@ public class FiscalPeriodTableModel extends AbstractLimaTableModel<FiscalPeriod> FiscalPeriod fiscalPeriod = tableModel.get(row); String status = t("lima.fiscalPeriod.open"); if (fiscalPeriod.isLocked()) { - status = t("lima.fiscalPeriod.closed"); + status = t("lima.fiscalPeriod.locked"); } return status; } 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 360d557..82528ab 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 @@ -403,7 +403,7 @@ public class LetteringViewHandler{ && filter.getDateStart() != null && filter.getDateEnd() != null) { - List<Entry> entries = financialTransactionService.getAllEntrieByDatesAndAccountAndLettering(filter); + List<Entry> entries = financialTransactionService.getAllEntriesByDatesAndAccountAndLettering(filter); view.getTableModel().setValues(entries); } 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 f7ee250..5f970d4 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 @@ -225,7 +225,7 @@ lima.filter.account=Add account filter lima.filter.condition.all=Valid all criteria lima.filter.condition.one=Valid at least one criteria lima.filter.condition.selectionMode=Balance entry selection -lima.filter.condition.selectionMode.balanced=Balanced +lima.filter.condition.selectionMode.lettered=Lettered lima.filter.condition.selectionMode.manual=Manual lima.filter.credit=Add filter on credit lima.filter.date.interval=Filter on date range @@ -347,7 +347,6 @@ lima.fiscalPeriod.block.error.withoutEntryBook.transaction= lima.fiscalPeriod.block.newYear=Do you want to create new fiscal year lima.fiscalPeriod.block.retainedEarnings=Push next lima.fiscalPeriod.block.title=Close fiscal period -lima.fiscalPeriod.closed=Close lima.fiscalPeriod.delete=Delete fiscal period (Del) lima.fiscalPeriod.delete.confirmation=Do you really want to remove fiscal period ? lima.fiscalPeriod.delete.error.noEmptyFiscalPeriod=Failed to remove fiscal period with financial transactions (%1$s). @@ -359,6 +358,7 @@ lima.fiscalPeriod.error.lockedFinancialPeriod= lima.fiscalPeriod.error.moreOneUnlockFiscalPeriod= lima.fiscalPeriod.error.notBeginNextDayOfLastFiscalPeriod= lima.fiscalPeriod.form=Fiscal period +lima.fiscalPeriod.locked=Locked lima.fiscalPeriod.open=Open lima.fiscalPeriod.status=Status lima.fiscalPeriod.update=Update ending date (Ctrl+M) @@ -502,6 +502,7 @@ lima.table.description=Description lima.table.entryBook=Entry book lima.table.label=Label lima.table.letter=Letter +lima.table.locked=Locked lima.table.number=Account Number lima.table.provisionDeprecation=Provision Deprecation lima.table.voucher=Voucher 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 7c5c9a4..0715d79 100644 --- a/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties +++ b/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties @@ -15,7 +15,7 @@ lima.account.remove.confirm.title=Suppression d'un compte lima.account.remove.error.usedAccount=Il exist des transactions sur ce compte lima.account.update.error.invalidAccountNumber=Le numéro du compte %1$s n'est pas valide lima.account.update.form=Modification d'un compte -lima.accountViewer.previousSold=Solde au %s +lima.accountViewer.previousSold=<html><b>Solde au %s</b></html> lima.accounts=Comptes lima.action.commandline.help=Afficher l'aide en console lima.balance=Équilibrer @@ -234,7 +234,7 @@ lima.filter.condition.all=Valide toutes les conditions lima.filter.condition.delete=Supprimer la condition lima.filter.condition.one=Valide au moins une condition lima.filter.condition.selectionMode=Sélection des écritures balancées -lima.filter.condition.selectionMode.balanced=Balancée +lima.filter.condition.selectionMode.lettered=Lettré lima.filter.condition.selectionMode.manual=Manuelle lima.filter.credit=Ajouter un filtre sur les crédits lima.filter.date=Ajouter un filtre sur les dates @@ -356,7 +356,6 @@ lima.fiscalPeriod.block.error.withoutEntryBook.transaction=transaction du %1$te/ lima.fiscalPeriod.block.newYear=Voulez vous créer un nouvel exercice? lima.fiscalPeriod.block.retainedEarnings=Report à nouveau lima.fiscalPeriod.block.title=Cloture de l'exercice -lima.fiscalPeriod.closed=Cloturé lima.fiscalPeriod.create=Choisissez la date de début et de fin du nouvel exercice lima.fiscalPeriod.delete=Supprimer un exercice (Suppr) lima.fiscalPeriod.delete.confirmation=Ètes vous sûre de vouloir supprimer cette période ? Cette action est irréversible \! @@ -369,6 +368,7 @@ lima.fiscalPeriod.error.lockedFinancialPeriod=La période financière est bloqu lima.fiscalPeriod.error.moreOneUnlockFiscalPeriod=Le nombre maximal d'exercices ouverts est déjà ateint\: periode fiscale concernée du %1$te/%1$tm/%1$tY au %1$te/%1$tm/%1$tY. lima.fiscalPeriod.error.notBeginNextDayOfLastFiscalPeriod=La nouvelle période fiscale doit suivre la précédente\: periode fiscale concernée du %1$te/%1$tm/%1$tY au %1$te/%1$tm/%1$tY. lima.fiscalPeriod.form=Exercice +lima.fiscalPeriod.locked=Cloturé lima.fiscalPeriod.open=Ouvert lima.fiscalPeriod.status=Statut lima.fiscalPeriod.update=Modifier la date de fin de l'exercice (Ctrl+M) @@ -458,7 +458,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.accountViewerBalanceStatus=<html>Pour la période du %s au %s le solde est\:<b>%s</b> - <b>%s</b> \= <b>%s</b> - Pour la sélection le solde est\: <b>%s</b> - <b>%s</b> \= <b>%s</b> lima.lettering.balanceStatus=<html>Débit\: <b>%s</b> - Crédit\: <b>%s</b> - Solde\: <b>%s</b> lima.lettering.checkAll=Toutes lima.lettering.checkLettredEntry=Lettrées @@ -509,6 +509,7 @@ lima.table.description=Description lima.table.entryBook=Journal lima.table.label=Libellé lima.table.letter=Lettre +lima.table.locked=Clos lima.table.number=Numéro de compte lima.table.provisionDeprecation=Amortissements et provisions lima.table.voucher=Pièce comptable diff --git a/lima-swing/src/main/resources/icons/action-financialPeriod-close.png b/lima-swing/src/main/resources/icons/action-financialPeriod-close.png index 08f2493..ac2fd6f 100644 Binary files a/lima-swing/src/main/resources/icons/action-financialPeriod-close.png and b/lima-swing/src/main/resources/icons/action-financialPeriod-close.png differ diff --git a/lima-swing/src/main/resources/icons/action-fiscalPeriod-close.png b/lima-swing/src/main/resources/icons/action-fiscalPeriod-close.png index 08f2493..ac2fd6f 100644 Binary files a/lima-swing/src/main/resources/icons/action-fiscalPeriod-close.png and b/lima-swing/src/main/resources/icons/action-fiscalPeriod-close.png differ -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm