This is an automated email from the git hooks/post-receive script. New commit to branch feature/1208 in repository lima. See http://git.chorem.org/lima.git commit 5d95df95d82d7f348074cba7a9237b143aa9d0fb Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Wed May 13 16:39:10 2015 +0200 refs #1199 : ajout de l'export du fichier des écritures comptables --- .../chorem/lima/business/api/ExportService.java | 9 + .../lima/business/ejb/ExportServiceImpl.java | 46 +++++ .../business/ejb/csv/FiscalControlExportModel.java | 153 +++++++++++++++ .../java/org/chorem/lima/entity/EntryTopiaDao.java | 18 ++ .../src/main/java/org/chorem/lima/ui/MainView.css | 9 +- .../src/main/java/org/chorem/lima/ui/MainView.jaxx | 2 + .../java/org/chorem/lima/ui/MainViewHandler.java | 9 + .../FiscalControlExportView.css | 40 ++++ .../FiscalControlExportView.jaxx | 85 +++++++++ .../FiscalControlExportViewHandler.java | 205 +++++++++++++++++++++ .../resources/i18n/lima-swing_en_GB.properties | 25 +++ .../resources/i18n/lima-swing_fr_FR.properties | 17 ++ .../resources/icons/action-fiscalControlExport.png | Bin 0 -> 1244 bytes lima-swing/src/main/resources/icons/warning.png | Bin 0 -> 965 bytes 14 files changed, 616 insertions(+), 2 deletions(-) diff --git a/lima-business-api/src/main/java/org/chorem/lima/business/api/ExportService.java b/lima-business-api/src/main/java/org/chorem/lima/business/api/ExportService.java index 9d2ebef..bebba6c 100644 --- a/lima-business-api/src/main/java/org/chorem/lima/business/api/ExportService.java +++ b/lima-business-api/src/main/java/org/chorem/lima/business/api/ExportService.java @@ -22,7 +22,10 @@ package org.chorem.lima.business.api; +import org.chorem.lima.business.ExportResult; import org.chorem.lima.business.ImportExportResults; +import org.chorem.lima.entity.EntryBook; +import org.chorem.lima.entity.FiscalPeriod; /** * Import export service. @@ -60,4 +63,10 @@ public interface ExportService { ImportExportResults exportEntriesAsEbp(String charset); ImportExportResults exportEntryBookAsEbp(String charset); + + //########## Fichier des écritures comptable en cas de contrôle fiscal ##################### + + ExportResult exportFiscalControl(FiscalPeriod period, EntryBook entryBookAtNew, String charset); + + String getFiscalControlFileName(FiscalPeriod fiscalPeriod); } diff --git a/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.java b/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.java index 2c9e119..a6e6f69 100644 --- a/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.java +++ b/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.java @@ -22,6 +22,8 @@ package org.chorem.lima.business.ejb; +import com.google.common.collect.Lists; +import org.apache.commons.lang3.StringUtils; import org.chorem.lima.business.ExportResult; import org.chorem.lima.business.ImportExportResults; import org.chorem.lima.business.api.AccountService; @@ -38,6 +40,7 @@ import org.chorem.lima.business.ejb.csv.EntryBookModel; import org.chorem.lima.business.ejb.csv.EntryModel; import org.chorem.lima.business.ejb.csv.FinancialStatementModel; import org.chorem.lima.business.ejb.csv.FinancialTransactionModel; +import org.chorem.lima.business.ejb.csv.FiscalControlExportModel; import org.chorem.lima.business.ejb.csv.FiscalPeriodModel; import org.chorem.lima.business.ejb.csv.IdentityModel; import org.chorem.lima.business.ejb.csv.VatStatementModel; @@ -343,4 +346,47 @@ public class ExportServiceImpl extends AbstractLimaService implements ExportServ } return results; } + + @Override + public ExportResult exportFiscalControl(FiscalPeriod period, EntryBook entryBookAtNew, String charset) { + ExportResult exportResult = new ExportResult(Entry.class); + + EntryTopiaDao dao = getDaoHelper().getEntryDao(); + List<Entry> entities = dao.findAllEntryByDate(period.getBeginDate(), period.getEndDate()); + + // on place les écritures de report a nouveau au debut + List<Entry> entriesAtNew = dao.findAllEntryByDateForEntryBook(entryBookAtNew, period.getBeginDate(), period.getBeginDate()); + List<Entry> entries = Lists.newArrayListWithCapacity(entities.size()); + entities.removeAll(entriesAtNew); + entries.addAll(entriesAtNew); + entries.addAll(entities); + + if (!entries.isEmpty()) { + FiscalControlExportModel model = new FiscalControlExportModel(); + try { + exportResult.setExportData(Export.exportToString(model, entries, Charset.forName(charset), true)); + } catch (Exception e) { + exportResult.addException(new ExportException("Could not export entries.", e)); + } + } + + return exportResult; + } + + @Override + public String getFiscalControlFileName(FiscalPeriod fiscalPeriod) { + /* cf : http://www.legifrance.gouv.fr/affichCodeArticle.do?idArticle=LEGIARTI000027804775&cidTexte=LEGITEXT000006069583&dateTexte=20130802&oldAction=rechCodeArticle + ** section IX + */ + + Identity identity = identityService.getIdentity(); + String siret= identity.getBusinessNumber(); + String siren = ""; + if (StringUtils.isNotBlank(siret)) { + siret = siret.replace(" ", ""); + siren = siret.substring(0, 9); + } + + return String.format("%1$sFEC%2$tY%2$tm%2$td", siren, fiscalPeriod.getEndDate()); + } } diff --git a/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/FiscalControlExportModel.java b/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/FiscalControlExportModel.java new file mode 100644 index 0000000..241cae1 --- /dev/null +++ b/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/FiscalControlExportModel.java @@ -0,0 +1,153 @@ +package org.chorem.lima.business.ejb.csv; + +/* + * #%L + * Lima :: business + * %% + * 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% + */ + +import com.google.common.collect.Maps; +import org.chorem.lima.beans.Account; +import org.chorem.lima.entity.Entry; +import org.chorem.lima.entity.EntryBook; +import org.chorem.lima.entity.FinancialTransaction; +import org.nuiton.csv.ExportModel; +import org.nuiton.csv.ExportableColumn; +import org.nuiton.csv.ModelBuilder; +import org.nuiton.csv.ValueFormatter; +import org.nuiton.csv.ValueGetter; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Map; + +/** + * @author Sylvain Bavencoff - bavencoff@codelutin.com + * + * cf : http://www.legifrance.gouv.fr/affichCodeArticle.do?idArticle=LEGIARTI000027804775&cidTexte=LEGITEXT000006069583&dateTexte=20130802&oldAction=rechCodeArticle + */ +public class FiscalControlExportModel implements ExportModel<Entry> { + + protected static String PROPERTY_ENTRY_BOOK_CODE = Entry.PROPERTY_FINANCIAL_TRANSACTION + "." + FinancialTransaction.PROPERTY_ENTRY_BOOK + "." + EntryBook.PROPERTY_CODE; + protected static String PROPERTY_ENTRY_BOOK_LABEL = Entry.PROPERTY_FINANCIAL_TRANSACTION + "." + FinancialTransaction.PROPERTY_ENTRY_BOOK + "." + EntryBook.PROPERTY_LABEL; + protected static String PROPERTY_DATE = Entry.PROPERTY_FINANCIAL_TRANSACTION + "." + FinancialTransaction.PROPERTY_TRANSACTION_DATE; + protected static String PROPERTY_ACCOUNT_NUMBER = Entry.PROPERTY_ACCOUNT + "." + Account.PROPERTY_ACCOUNT_NUMBER; + protected static String PROPERTY_ACCOUNT_LABEL = Entry.PROPERTY_ACCOUNT + "." + Account.PROPERTY_LABEL; + + + protected static ValueGetter<Entry, String> EMPTY_GETTER = new ValueGetter<Entry, String>() { + @Override + public String get(Entry object) throws Exception { + return ""; + } + }; + + protected static final ValueFormatter<Boolean> D_C_FORMATTER = new ValueFormatter<Boolean>() { + @Override + public String format(Boolean value) { + String result = value ? "D" : "C"; + return result; + } + }; + + protected static final ValueFormatter<Date> DATE_FORMATTER = new ValueFormatter<Date>() { + @Override + public String format(Date value) { + String result; + if (value != null) { + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd"); + result = simpleDateFormat.format(value); + } else { + result = ""; + } + return result; + } + }; + + protected static ValueGetter<Entry, String> DEBIT_GETTER = new ValueGetter<Entry, String>() { + @Override + public String get(Entry entry) throws Exception { + String result = ""; + if (entry != null && entry.isDebit()) { + result = String.valueOf(entry.getAmount()); + } + return result; + } + }; + + protected static ValueGetter<Entry, String> CREDIT_GETTER = new ValueGetter<Entry, String>() { + @Override + public String get(Entry entry) throws Exception { + String result = ""; + if (entry != null && !entry.isDebit()) { + result = String.valueOf(entry.getAmount()); + } + return result; + } + }; + + + @Override + public char getSeparator() { + return '|'; + } + + @Override + public Iterable<ExportableColumn<Entry, Object>> getColumnsForExport() { + ModelBuilder<Entry> modelBuilder = new ModelBuilder<>(); + modelBuilder.newColumnForExport("JournalCode", PROPERTY_ENTRY_BOOK_CODE); + modelBuilder.newColumnForExport("JournalLib ", PROPERTY_ENTRY_BOOK_LABEL); + modelBuilder.newColumnForExport("EcritureNum ", Entry.PROPERTY_FINANCIAL_TRANSACTION, new FinancialTransactionFormatter()); + modelBuilder.newColumnForExport("EcritureDate ", PROPERTY_DATE, DATE_FORMATTER); + modelBuilder.newColumnForExport("CompteNum", PROPERTY_ACCOUNT_NUMBER); + modelBuilder.newColumnForExport("CompteLib", PROPERTY_ACCOUNT_LABEL); + modelBuilder.newColumnForExport("CompAuxNum", EMPTY_GETTER); + modelBuilder.newColumnForExport("CompAuxLib", EMPTY_GETTER); + modelBuilder.newColumnForExport("PieceRef", Entry.PROPERTY_VOUCHER); + modelBuilder.newColumnForExport("PieceDate", PROPERTY_DATE, DATE_FORMATTER); + modelBuilder.newColumnForExport("EcritureLib", Entry.PROPERTY_DESCRIPTION); + modelBuilder.newColumnForExport("Debit ", DEBIT_GETTER); + modelBuilder.newColumnForExport("Credit ", CREDIT_GETTER); + modelBuilder.newColumnForExport("EcritureLet", Entry.PROPERTY_LETTERING); + modelBuilder.newColumnForExport("DateLet", EMPTY_GETTER); + modelBuilder.newColumnForExport("ValidDate", PROPERTY_DATE, DATE_FORMATTER); + modelBuilder.newColumnForExport("Montantdevise", EMPTY_GETTER); + modelBuilder.newColumnForExport("Idevise", EMPTY_GETTER); + + return (Iterable) modelBuilder.getColumnsForExport(); + } + + + + protected class FinancialTransactionFormatter implements ValueFormatter<FinancialTransaction> { + + Map<FinancialTransaction, Integer> numByTransactions = Maps.newHashMap(); + int nextNum = 0; + + @Override + public String format(FinancialTransaction value) { + Integer num = numByTransactions.get(value); + if (num == null) { + num = nextNum++; + numByTransactions.put(value, num); + } + return Integer.toString(num); + } + } +} 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 8dcc557..7369610 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 @@ -173,12 +173,30 @@ public class EntryTopiaDao extends AbstractEntryTopiaDao<Entry> { builder.addEquals(PROPERTY_ENTRY_BOOK, entryBook); builder.addGreaterOrEquals(PROPERTY_TRANSACTION_DATE, beginDate); builder.addLowerOrEquals(PROPERTY_TRANSACTION_DATE, endDate); + builder.setOrderByArguments(PROPERTY_TRANSACTION_DATE, Entry.PROPERTY_FINANCIAL_TRANSACTION); List<Entry> entries = findAll(builder.getHql(), builder.getHqlParameters()); return entries; } /** + * Retourne les entrees des transaction entre deux dates. + * + * @param beginDate begin date + * @param endDate end date + */ + public List<Entry> findAllEntryByDate(Date beginDate, Date endDate) { + HqlAndParametersBuilder<Entry> builder = newHqlAndParametersBuilder(); + builder.addGreaterOrEquals(PROPERTY_TRANSACTION_DATE, beginDate); + builder.addLowerOrEquals(PROPERTY_TRANSACTION_DATE, endDate); + builder.setOrderByArguments(PROPERTY_TRANSACTION_DATE, Entry.PROPERTY_FINANCIAL_TRANSACTION); + + List<Entry> entries = findAll(builder.getHql(), builder.getHqlParameters()); + return entries; + } + + + /** * Retourne toutes les entrées d'une transaction * 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 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 d08d492..186f683 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 @@ -104,7 +104,7 @@ #csvExportEntries { text : "lima.entries"; - actionIcon : "entries" + actionIcon : "entries"; } #ebp { @@ -128,7 +128,7 @@ #ebpImportEntries { text : "lima.entries"; - actionIcon : "entries" + actionIcon : "entries"; } #ebpExport { @@ -151,6 +151,11 @@ actionIcon : "entries" } +#fiscalControlExport { + text : "lima.fiscalControlExport"; + actionIcon : "fiscalControlExport"; +} + #documents { text : "lima.documents" } 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 1a01d00..48f7721 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 @@ -105,6 +105,8 @@ onActionPerformed="getHandler().showImportExportView(this, ImportExportEnum.EBP_ENTRIES_EXPORT)"/> </JMenu> </JMenu> + <JMenuItem id="fiscalControlExport" + onActionPerformed="getHandler().showFiscalControlExport(this)"/> <JSeparator/> <JMenuItem id="documents" onActionPerformed="getHandler().openLimaHttpUi(this)"/> 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 9211f1f..8b53397 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 @@ -42,6 +42,7 @@ import org.chorem.lima.ui.financialstatementchart.FinancialStatementChartView; import org.chorem.lima.ui.financialtransaction.FinancialTransactionView; import org.chorem.lima.ui.financialtransactionsearch.FinancialTransactionSearchView; import org.chorem.lima.ui.financialtransactionunbalanced.FinancialTransactionUnbalancedView; +import org.chorem.lima.ui.fiscalControlExport.FiscalControlExportView; import org.chorem.lima.ui.fiscalperiod.FiscalPeriodView; import org.chorem.lima.ui.home.HomeView; import org.chorem.lima.ui.identity.IdentityForm; @@ -589,6 +590,14 @@ public class MainViewHandler { showTab(ui, name, container, true); } + public void showFiscalControlExport(JAXXContext rootContext) { + MainView mainView = getUI(rootContext); + FiscalControlExportView fiscalControlExportView = new FiscalControlExportView((JAXXContext) mainView); + fiscalControlExportView.setLocationRelativeTo(mainView); + fiscalControlExportView.setVisible(true); + + } + protected static class OnTabChangeListener implements ChangeListener { protected final HomeView homeView; diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/fiscalControlExport/FiscalControlExportView.css b/lima-swing/src/main/java/org/chorem/lima/ui/fiscalControlExport/FiscalControlExportView.css new file mode 100644 index 0000000..f3106ac --- /dev/null +++ b/lima-swing/src/main/java/org/chorem/lima/ui/fiscalControlExport/FiscalControlExportView.css @@ -0,0 +1,40 @@ +#fiscalControlExportFormDialog { + title : "lima.fiscalControlExport.form"; + +} + +#fiscalPeriodLabel { + text : "lima.fiscalControlExport.fiscalPeriod"; + labelFor : "{fiscalPeriodComboBox}"; +} + +#fiscalPeriodComboBox { + renderer : "{new org.chorem.lima.ui.common.FiscalPeriodListRenderer()}"; +} + + + +#entryBookAtNewLabel { + text : "lima.fiscalControlExport.entryBookAtNew"; + labelFor : "{entryBookAtNewComboBox}"; +} + +#entryBookAtNewComboBox { + toolTipText : "lima.fiscalControlExport.entryBookAtNew.toolTip"; + renderer : "{new org.chorem.lima.ui.common.EntryBookListRenderer()}"; +} + +#sirenWarnLabel { + icon : "warning.png"; + text : "lima.fiscalControlExport.sirenMissing"; +} + +#cancel { + text : "lima.cancel"; + actionIcon : cancel; +} + +#export { + text : "lima.fiscalControlExport.export"; + actionIcon : export; +} \ No newline at end of file diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/fiscalControlExport/FiscalControlExportView.jaxx b/lima-swing/src/main/java/org/chorem/lima/ui/fiscalControlExport/FiscalControlExportView.jaxx new file mode 100644 index 0000000..c2aefbb --- /dev/null +++ b/lima-swing/src/main/java/org/chorem/lima/ui/fiscalControlExport/FiscalControlExportView.jaxx @@ -0,0 +1,85 @@ +<!-- + #%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% + --> +<JDialog id="fiscalControlExportFormDialog" + modal="true" + defaultCloseOperation="{JDialog.DISPOSE_ON_CLOSE}" + layout="{new BorderLayout()}"> + + <import> + java.io.File + java.awt.Dimension + org.chorem.lima.entity.FiscalPeriod + </import> + + <File id="exportFile" javaBean='null'/> + + <FiscalControlExportViewHandler id="handler" constructorParams="this"/> + + <script> + <![CDATA[ + getRootPane().setDefaultButton(export); + + void $afterCompleteSetup() { + handler.init(); + } + ]]> + </script> + + <JPanel constraints="BorderLayout.CENTER" + layout="{new BorderLayout()}"> + + <Table constraints="BorderLayout.CENTER"> + <row> + <cell anchor="east"> + <JLabel id="fiscalPeriodLabel"/> + </cell> + <cell fill="both" anchor="west"> + <org.chorem.lima.ui.common.FiscalPeriodComboBoxModel id="fiscalPeriodComboBoxModel"/> + + <JComboBox id="fiscalPeriodComboBox" + model="{fiscalPeriodComboBoxModel}"/> + </cell> + </row> + <row> + <cell anchor="east"> + <JLabel id="entryBookAtNewLabel"/> + </cell> + <cell fill="both" anchor="west"> + <org.chorem.lima.ui.common.EntryBookComboBoxModel id="entryBookAtNewComboBoxModel"/> + + <JComboBox id="entryBookAtNewComboBox" + model="{entryBookAtNewComboBoxModel}"/> + </cell> + </row> + </Table> + <JLabel id="sirenWarnLabel" + constraints="BorderLayout.SOUTH"/> + </JPanel> + + <JPanel constraints="BorderLayout.SOUTH" + layout='{new GridLayout(1,0)}'> + <JButton id="cancel" + onActionPerformed="dispose()"/> + <JButton id="export" + onActionPerformed="getHandler().export()"/> + </JPanel> +</JDialog> diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/fiscalControlExport/FiscalControlExportViewHandler.java b/lima-swing/src/main/java/org/chorem/lima/ui/fiscalControlExport/FiscalControlExportViewHandler.java new file mode 100644 index 0000000..2cd6aa9 --- /dev/null +++ b/lima-swing/src/main/java/org/chorem/lima/ui/fiscalControlExport/FiscalControlExportViewHandler.java @@ -0,0 +1,205 @@ +package org.chorem.lima.ui.fiscalControlExport; + +import com.google.common.base.Charsets; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.LimaSwingConfig; +import org.chorem.lima.business.ExportResult; +import org.chorem.lima.business.LimaServiceFactory; +import org.chorem.lima.business.api.EntryBookService; +import org.chorem.lima.business.api.ExportService; +import org.chorem.lima.business.api.FiscalPeriodService; +import org.chorem.lima.business.api.IdentityService; +import org.chorem.lima.entity.EntryBook; +import org.chorem.lima.entity.FiscalPeriod; +import org.chorem.lima.entity.Identity; +import org.chorem.lima.ui.importexport.ImportExportWaitView; +import org.chorem.lima.util.ErrorHelper; +import org.jdesktop.swingx.painter.BusyPainter; + +import javax.swing.JFileChooser; +import javax.swing.JOptionPane; +import javax.swing.SwingWorker; +import java.awt.Color; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.rmi.server.ExportException; +import java.util.List; + +import static org.nuiton.i18n.I18n.t; + +/** + * @author Sylvain Bavencoff - bavencoff@codelutin.com + */ +public class FiscalControlExportViewHandler { + + private static final Log log = LogFactory.getLog(FiscalControlExportViewHandler.class); + + protected FiscalControlExportView view; + + protected FiscalPeriodService fiscalPeriodService; + + protected EntryBookService entryBookService; + + protected IdentityService identityService; + + protected ExportService exportService; + + private ImportExportWaitView waitView; + + + public FiscalControlExportViewHandler(FiscalControlExportView view) { + this.view = view; + fiscalPeriodService = LimaServiceFactory.getService(FiscalPeriodService.class); + entryBookService = LimaServiceFactory.getService(EntryBookService.class); + identityService = LimaServiceFactory.getService(IdentityService.class); + exportService = LimaServiceFactory.getService(ExportService.class); + } + + public void init() { + List<FiscalPeriod> fiscalPeriods = fiscalPeriodService.getAllBlockedFiscalPeriods(); + view.getFiscalPeriodComboBoxModel().setObjects(fiscalPeriods); + view.getFiscalPeriodComboBoxModel().setSelectedItem(fiscalPeriods.get(fiscalPeriods.size()-1)); + List<EntryBook> entryBooks = entryBookService.getAllEntryBooks(); + view.getEntryBookAtNewComboBoxModel().setObjects(entryBooks); + Identity identity = identityService.getIdentity(); + view.getSirenWarnLabel().setVisible(StringUtils.isBlank(identity.getBusinessNumber())); + } + + public void export() { + FiscalPeriod fiscalPeriod = (FiscalPeriod) view.getFiscalPeriodComboBoxModel().getSelectedItem(); + EntryBook entryBookAtNew = (EntryBook) view.getEntryBookAtNewComboBoxModel().getSelectedItem(); + if (fiscalPeriod != null && entryBookAtNew != null) { + String fileName = exportService.getFiscalControlFileName(fiscalPeriod); + File homeDirectory = new File(System.getProperty("user.home")); + File exportFile = new File(homeDirectory, fileName); + + JFileChooser chooser = new JFileChooser(); + chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); + chooser.setSelectedFile(exportFile); + String approveButtonText = t("lima.importExport.export"); + chooser.setDialogTitle(approveButtonText); + chooser.setApproveButtonText(approveButtonText); + + if (chooser.showOpenDialog(view) == JFileChooser.APPROVE_OPTION) { + exportFile = chooser.getSelectedFile(); + + boolean continueExport = true; + + if (!exportFile.getName().equals(fileName)) { + + String[] options = {t("lima.fiscalControlExport.file.nonConformanceName.continue"), t("lima.fiscalControlExport.file.nonConformanceName.cancel")}; + continueExport = 0 == JOptionPane.showOptionDialog( + view, + t("lima.fiscalControlExport.file.nonConformanceName", exportFile.getName(), fileName), + t("lima.fiscalControlExport.file.nonConformanceName.title"), + JOptionPane.OK_CANCEL_OPTION, + JOptionPane.WARNING_MESSAGE, + null, + options, + options[0]); + + } + + if (continueExport && exportFile.exists()) { + + String[] options = {t("lima.fiscalControlExport.file.overwrite.continue"), t("lima.fiscalControlExport.file.overwrite.cancel")}; + continueExport = 0 == JOptionPane.showOptionDialog( + view, + t("lima.fiscalControlExport.file.overwrite", exportFile.getName()), + t("lima.fiscalControlExport.file.overwrite.title"), + JOptionPane.OK_CANCEL_OPTION, + JOptionPane.WARNING_MESSAGE, + null, + options, + options[0]); + } + + if (continueExport) { + + //create the wait dialog panel + waitView = new ImportExportWaitView(); + waitView.setLocationRelativeTo(view); + BusyPainter busyPainter = waitView.getBusylabel().getBusyPainter(); + busyPainter.setHighlightColor(new Color(44, 61, 146).darker()); + busyPainter.setBaseColor(new Color(168, 204, 241).brighter()); + + new ExportWorker(fiscalPeriod, entryBookAtNew, exportFile).execute(); + + waitView.setVisible(true); + view.dispose(); + } + } + } + } + + + protected class ExportWorker extends SwingWorker<ExportResult, Void> { + + protected FiscalPeriod fiscalPeriod; + protected EntryBook entryBookAtNew; + protected File exportFile; + + public ExportWorker(FiscalPeriod fiscalPeriod, EntryBook entryBookAtNew, File exportFile) { + this.fiscalPeriod = fiscalPeriod; + this.entryBookAtNew = entryBookAtNew; + this.exportFile = exportFile; + } + + @Override + protected ExportResult doInBackground() throws Exception { + ExportResult exportResult = exportService.exportFiscalControl(fiscalPeriod, entryBookAtNew, Charsets.UTF_8.toString()); + List<ExportException> exportExceptions = exportResult.getExportExceptions(); + if (exportExceptions == null || exportExceptions.isEmpty()) { + BufferedWriter out = null; + try { + out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(exportFile))); + out.write(exportResult.getExportData()); + out.flush(); + out.close(); + } catch (IOException eee) { + if (log.isErrorEnabled()) { + log.error("Can't write file " + exportFile, eee); + } + } finally { + IOUtils.closeQuietly(out); + } + } else { + throw exportExceptions.get(0); + } + return exportResult; + } + + @Override + protected void done() { + try { + + //hidde wait dialog panel + waitView.setVisible(false); + + // display result dialog + ExportResult exportResult = get(); + JOptionPane.showMessageDialog( + view, + t("lima.fiscalControlExport.success"), + t("lima.fiscalControlExport.success.title"), + JOptionPane.INFORMATION_MESSAGE); + + + } catch (Exception ex) { + if (log.isErrorEnabled()) { + log.error("Can't get result message", ex); + } + ErrorHelper errorHelper = new ErrorHelper(LimaSwingConfig.getInstance()); + errorHelper.showErrorDialog(null, ex.getMessage(), ex); + } + } + + } + +} 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 352e1f2..bad056f 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 @@ -151,6 +151,7 @@ lima.entries.copy.transaction=Copy transaction lima.entries.enter=Add entries lima.entries.entryBook=Entry book lima.entries.financialPeriod=Financial period +lima.entries.fiscalPeriod.toolTip= lima.entries.fiscalYear=fiscal year lima.entries.letter.closed.entryBook.error=Entry book close %2$s (%1$s) for period from %3$te %3$tB %3$tY to %4$te %4$tB %4$tY. lima.entries.letter.unbalanced.error= @@ -208,6 +209,11 @@ lima.error.notAllowedLabel= lima.export.exceptions=Export failed. lima.export.failed=Export faild \! lima.export.terminated=Successful export +lima.exportFiscalControl.export= +lima.exportFiscalControl.exportFile= +lima.exportFiscalControl.fileChooser= +lima.exportFiscalControl.fiscalPeriod= +lima.exportFiscalControl.form= lima.file=File lima.filer.condition.sensitive.case=Case sensitive lima.filter=Filter @@ -287,6 +293,25 @@ lima.financialTransaction.update.error.beforeFirstFiscalPeriod=Update financial lima.financialTransaction.update.error.lockedEntryBook=Update financial transaction failed, locked entry book. lima.financialTransaction.update.error.lockedFinancialPeriod=Update financial transaction failed, locked financial period. lima.financialTransaction.voucher=Voucher +lima.fiscalControlExport= +lima.fiscalControlExport.entryBookAtNew= +lima.fiscalControlExport.entryBookAtNew.toolTip= +lima.fiscalControlExport.export= +lima.fiscalControlExport.exportFile= +lima.fiscalControlExport.file.nonConformanceName= +lima.fiscalControlExport.file.nonConformanceName.cancel= +lima.fiscalControlExport.file.nonConformanceName.continue= +lima.fiscalControlExport.file.nonConformanceName.title= +lima.fiscalControlExport.file.overwrite= +lima.fiscalControlExport.file.overwrite.cancel= +lima.fiscalControlExport.file.overwrite.continue= +lima.fiscalControlExport.file.overwrite.title= +lima.fiscalControlExport.fileChooser= +lima.fiscalControlExport.fiscalPeriod= +lima.fiscalControlExport.form= +lima.fiscalControlExport.sirenMissing= +lima.fiscalControlExport.success= +lima.fiscalControlExport.success.title= lima.fiscalPeriod=Fiscal period lima.fiscalPeriod.add=Add fiscal period lima.fiscalPeriod.add.confirm.moreThan12=Fiscal period is not 12 month long, do you really want to continue ? 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 005494c..bff15db 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 @@ -304,6 +304,23 @@ lima.financialTransaction.update.error.beforeFirstFiscalPeriod=Impossible de dé lima.financialTransaction.update.error.lockedEntryBook=Impossible de déplacer une transaction 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. lima.financialTransaction.update.error.lockedFinancialPeriod=Impossible de deplacer une transaction car la période fiscale du %3$te %3$tB %3$tY au %4$te %4$tB %4$tY est cloturée. lima.financialTransaction.voucher=Pièce comptable +lima.fiscalControlExport=Export FEC +lima.fiscalControlExport.entryBookAtNew=Journal des reports à-nouveaux +lima.fiscalControlExport.entryBookAtNew.toolTip=Indiquez le journal correspondent aux écritures de reprise des soldes de l'exercice antérieur. +lima.fiscalControlExport.export=Exporter +lima.fiscalControlExport.file.nonConformanceName=Le non du fichier "%1$s" n'est pas conforme à celui attendu par l'administration "%2$S". \n Voulez-vous continuer l'export ? +lima.fiscalControlExport.file.nonConformanceName.cancel=Annuler +lima.fiscalControlExport.file.nonConformanceName.continue=Exporter +lima.fiscalControlExport.file.nonConformanceName.title=Nom de fichier non conforme +lima.fiscalControlExport.file.overwrite=Le fichier "%s" existe déjà. Voulez-vous le remplacer ? +lima.fiscalControlExport.file.overwrite.cancel=Annuler +lima.fiscalControlExport.file.overwrite.continue=Remplacer +lima.fiscalControlExport.file.overwrite.title=Fichier existant +lima.fiscalControlExport.fiscalPeriod=Exercice +lima.fiscalControlExport.form=Export du fichier des écritures comptables +lima.fiscalControlExport.sirenMissing=Attention \: Votre numéro de Siret n'est pas renseignié dans la fiche identité.\n +lima.fiscalControlExport.success=Export réalisé avec success +lima.fiscalControlExport.success.title=Export FEC lima.fiscalPeriod=Exercices lima.fiscalPeriod.add=Nouvel exercice (Ctrl+A) lima.fiscalPeriod.add.confirm.moreThan12=La période sélectionnée n'est pas de 12 mois, voulez-vous continuer ? diff --git a/lima-swing/src/main/resources/icons/action-fiscalControlExport.png b/lima-swing/src/main/resources/icons/action-fiscalControlExport.png new file mode 100644 index 0000000..ad87fe1 Binary files /dev/null and b/lima-swing/src/main/resources/icons/action-fiscalControlExport.png differ diff --git a/lima-swing/src/main/resources/icons/warning.png b/lima-swing/src/main/resources/icons/warning.png new file mode 100644 index 0000000..a5452e5 Binary files /dev/null and b/lima-swing/src/main/resources/icons/warning.png differ -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.