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 0eeda163f72109f06c459c2adf9d77ef45a6bde9 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 | 14 ++ .../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 | 22 ++- .../resources/i18n/lima-swing_en_GB.properties | 5 +- .../resources/i18n/lima-swing_fr_FR.properties | 6 +- .../resources/icons/action-fiscalPeriod-close.png | Bin 715 -> 452 bytes 15 files changed, 325 insertions(+), 126 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 1cb6954..dd7b498 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,6 +38,8 @@ public interface ClosedPeriodicEntryBookService { List<ClosedPeriodicEntryBook> getAllByDates(Date beginDate, Date endDate); + List<String> getAllLockedEntryBookIdsFrom(Date beginDate); + List<ClosedPeriodicEntryBook> getAllByEntryBookAndDates(EntryBook entryBook, Date beginDate, Date endDate); ClosedPeriodicEntryBook getByEntryBookAndFinancialPeriod(EntryBook entryBook, Date date); 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 d653bc8..f548b76 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); /** * 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 352d51e..4db8561 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 71f5d0d..a3f18a5 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 e539043..a7fe86a 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; @@ -202,4 +203,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-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 3e2e0e2..10e148c 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 @@ -670,6 +670,26 @@ public class LetteringViewHandler{ Locale locale = LimaSwingConfig.getInstance().getLocale(); return locale; } - + + public void setAccount(Account account) { + if (filter != null) { + filter.setAccount(account); + updateAllEntries(); + } + } + + public Account getAccount() { + Account account = null; + if (filter != null) { + account = filter.getAccount(); + } + return account; + } + + public void setTypeEntry(TypeEntry typeEntry) { + filter.setDisplayLettered(typeEntry.isLettered()); + filter.setDisplayUnlettred(typeEntry.isNoLettered()); + updateAllEntries(); + } } diff --git a/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties b/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties index 580a3f3..3aeaf9e 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 @@ -227,7 +227,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 @@ -366,6 +366,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) @@ -526,7 +527,7 @@ lima.table.description=Description lima.table.entryBook=Entry book lima.table.label=Label lima.table.letter=Letter -lima.table.locked=Loked +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 f69d8f9..07b9572 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,7 +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.accountViewer.previousSold=<html><b>Solde au %s</b></html> lima.accounts=Comptes lima.action.commandline.help=Afficher l'aide en console lima.balance=Équilibrer @@ -237,7 +237,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 @@ -377,6 +377,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) @@ -468,6 +469,7 @@ lima.lettering.account.back=← lima.lettering.account.next=→ 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.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 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>.