OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 149 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
80 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
10
 *
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
13
 
14
 package org.openconcerto.erp.panel.compta;
15
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
17
import org.openconcerto.erp.core.finance.accounting.element.JournalSQLElement;
18
import org.openconcerto.sql.Configuration;
19
import org.openconcerto.sql.element.SQLElement;
20
import org.openconcerto.sql.model.DBRoot;
21
import org.openconcerto.sql.request.ComboSQLRequest;
22
import org.openconcerto.sql.sqlobject.ElementComboBox;
23
import org.openconcerto.ui.DefaultGridBagConstraints;
90 ilm 24
import org.openconcerto.ui.ISpinnerIntegerModel;
80 ilm 25
import org.openconcerto.ui.JDate;
26
import org.openconcerto.ui.JLabelBold;
90 ilm 27
import org.openconcerto.ui.TitledSeparator;
80 ilm 28
import org.openconcerto.utils.ExceptionHandler;
29
import org.openconcerto.utils.Tuple2;
30
 
31
import java.awt.Component;
32
import java.awt.GridBagConstraints;
33
import java.awt.GridBagLayout;
34
import java.awt.event.ActionEvent;
35
import java.awt.event.ActionListener;
36
import java.io.File;
37
import java.io.FileNotFoundException;
38
 
39
import javax.swing.DefaultListCellRenderer;
40
import javax.swing.JButton;
41
import javax.swing.JCheckBox;
42
import javax.swing.JComboBox;
43
import javax.swing.JFileChooser;
44
import javax.swing.JLabel;
45
import javax.swing.JList;
46
import javax.swing.JOptionPane;
47
import javax.swing.JPanel;
90 ilm 48
import javax.swing.JSpinner;
80 ilm 49
import javax.swing.JTextField;
50
import javax.swing.SwingUtilities;
51
 
52
public class ExportPanel extends JPanel {
53
    static enum ExportType {
132 ilm 54
        FEC("Fichier des écritures comptables pour exercice clôturé(FEC norme DGFIP)") {
80 ilm 55
            @Override
56
            public AbstractExport createExport(DBRoot root) {
132 ilm 57
                return new ExportFEC(root, true);
80 ilm 58
            }
59
        },
132 ilm 60
        FEC_NON_CLOTURE("Fichier des écritures comptables intermédiaire pour l'exercice courant") {
61
            @Override
62
            public AbstractExport createExport(DBRoot root) {
63
                return new ExportFEC(root, false);
64
            }
65
        },
80 ilm 66
        RelationExpert("Relation expert (Coala)") {
67
            @Override
68
            public AbstractExport createExport(DBRoot root) {
69
                return new ExportRelationExpertPanel(root);
70
            }
71
        },
72
        EBP_OL("EBP Open Line") {
73
            @Override
74
            public AbstractExport createExport(DBRoot root) {
75
                return new ExportEBP_OL(root);
76
            }
77
        },
78
        EBP("EBP Compta Pro") {
79
            @Override
80
            public AbstractExport createExport(DBRoot root) {
81
                return new ExportEBP_ComptaPro(root);
82
            }
149 ilm 83
        },
84
        SAGE("Sage Ximport") {
85
            @Override
86
            public AbstractExport createExport(DBRoot root) {
87
                return new ExportSageXimport(root);
88
            }
89
        },
174 ilm 90
        SAGE_ETENDU("Sage Etendu") {
91
            @Override
92
            public AbstractExport createExport(DBRoot root) {
93
                return new ExportSageEtendu(root);
94
            }
95
        },
149 ilm 96
        CCMX("Cegid CCMX") {
97
            @Override
98
            public AbstractExport createExport(DBRoot root) {
99
                return new ExportCCMX(root);
100
            }
80 ilm 101
        };
102
 
103
        private final String label;
104
 
105
        private ExportType(final String label) {
106
            this.label = label;
107
        }
108
 
109
        public final String getLabel() {
110
            return this.label;
111
        }
112
 
113
        public abstract AbstractExport createExport(final DBRoot root);
114
    }
115
 
116
    private final JDate du, au;
117
    private final JButton buttonGen = new JButton("Exporter");
118
    private final JFileChooser fileChooser = new JFileChooser();
119
    private final JTextField textDestination = new JTextField();
120
    private final ElementComboBox boxJournal = new ElementComboBox(true);
121
    private final JCheckBox boxExport = new JCheckBox("Seulement les nouvelles ecritures");
90 ilm 122
    private final JCheckBox boxReplaceLib = new JCheckBox("Remplacer le libellé par le nom du client");
123
    private JSpinner spinNbChar = new JSpinner(new ISpinnerIntegerModel(0, 20, 0));
124
    private JSpinner spinNbCharLimit = new JSpinner(new ISpinnerIntegerModel(0, 20, 0));
80 ilm 125
 
126
    public ExportPanel() {
127
        super(new GridBagLayout());
128
        final GridBagConstraints c = new DefaultGridBagConstraints();
129
 
130
        c.gridwidth = 4;
131
        this.add(new JLabelBold("Export des écritures comptables"), c);
132
 
133
        // Fichier de destination
134
        final JPanel panelFichier = new JPanel(new GridBagLayout());
135
        final GridBagConstraints cFic = new DefaultGridBagConstraints();
136
        cFic.insets.left = 0;
137
        cFic.insets.bottom = 0;
138
        cFic.gridx++;
139
        cFic.weightx = 1;
140
        panelFichier.add(this.textDestination, cFic);
141
 
142
        final JButton buttonChoose = new JButton("...");
143
        cFic.gridx++;
144
        cFic.weightx = 0;
145
        cFic.fill = GridBagConstraints.NONE;
146
        panelFichier.add(buttonChoose, cFic);
147
 
148
        this.buttonGen.setEnabled(false);
149
        this.textDestination.setEditable(false);
150
 
151
        this.fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
152
        buttonChoose.addActionListener(new ActionListener() {
153
            @Override
154
            public void actionPerformed(final ActionEvent e) {
155
                final int answer = ExportPanel.this.fileChooser.showSaveDialog(ExportPanel.this);
156
                if (answer == JFileChooser.APPROVE_OPTION) {
157
                    ExportPanel.this.textDestination.setText(ExportPanel.this.fileChooser.getSelectedFile().getAbsolutePath());
158
                }
159
                ExportPanel.this.buttonGen.setEnabled(answer == JFileChooser.APPROVE_OPTION);
160
            }
161
        });
162
        c.gridy++;
163
        c.gridx = 0;
164
        c.gridwidth = 1;
165
        this.add(new JLabel("Dossier de destination", SwingUtilities.RIGHT), c);
166
        c.gridx++;
167
        c.weightx = 1;
168
        c.gridwidth = 4;
169
        this.add(panelFichier, c);
170
 
171
        c.gridx = 0;
172
        c.gridwidth = 1;
173
        c.gridy++;
174
        c.weightx = 0;
175
        c.anchor = GridBagConstraints.EAST;
176
        this.add(new JLabel("Période du", SwingUtilities.RIGHT), c);
177
 
178
        c.gridx++;
179
        c.anchor = GridBagConstraints.WEST;
180
        c.fill = GridBagConstraints.NONE;
181
        this.du = new JDate(true);
182
        this.add(this.du, c);
183
 
184
        c.gridx++;
185
        this.add(new JLabel("au"), c);
186
 
187
        c.gridx++;
188
        this.au = new JDate(true);
189
        this.add(this.au, c);
190
 
191
        this.boxExport.setSelected(true);
192
        c.gridy++;
193
        c.gridx = 0;
194
        c.gridwidth = 3;
195
        this.add(this.boxExport, c);
196
 
197
        final SQLElement elt = Configuration.getInstance().getDirectory().getElement(JournalSQLElement.class);
198
        final ComboSQLRequest comboRequest = elt.getComboRequest(true);
199
        comboRequest.setUndefLabel("Tous");
200
        this.boxJournal.init(elt, comboRequest);
201
        c.gridy++;
202
        c.gridx = 0;
203
        c.weightx = 0;
204
        c.gridwidth = 1;
205
        c.fill = GridBagConstraints.HORIZONTAL;
206
        this.add(new JLabel("Ecritures du journal", SwingUtilities.RIGHT), c);
207
        c.gridx++;
208
        c.weightx = 1;
209
        c.gridwidth = 4;
210
        c.fill = GridBagConstraints.NONE;
211
        this.boxJournal.setValue(JournalSQLElement.VENTES);
212
        this.add(this.boxJournal, c);
213
 
214
        c.gridy++;
215
        c.gridx = 0;
216
        c.weightx = 0;
217
        c.gridwidth = 1;
218
        c.fill = GridBagConstraints.HORIZONTAL;
219
        this.add(new JLabel("Type d'export", SwingUtilities.RIGHT), c);
220
        c.gridx++;
221
        c.weightx = 1;
222
        c.gridwidth = 4;
223
        final JComboBox comboType = new JComboBox(ExportType.values());
224
        comboType.setRenderer(new DefaultListCellRenderer() {
225
            @Override
226
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
227
                return super.getListCellRendererComponent(list, ((ExportType) value).getLabel(), index, isSelected, cellHasFocus);
228
            }
229
        });
230
        c.fill = GridBagConstraints.NONE;
231
        comboType.setSelectedIndex(0);
232
        this.add(comboType, c);
233
 
90 ilm 234
        final JPanel p = new JPanel(new GridBagLayout());
235
        GridBagConstraints c2 = new DefaultGridBagConstraints();
236
        c2.gridx = 0;
237
        c2.weightx = 1;
238
        c2.gridwidth = GridBagConstraints.REMAINDER;
239
        c2.fill = GridBagConstraints.HORIZONTAL;
240
        p.add(new TitledSeparator("Option export relation expert", true), c2);
241
 
242
        c2.gridy++;
243
        c2.gridx = 0;
244
        c2.weightx = 0;
245
        c2.gridwidth = 3;
246
        c2.fill = GridBagConstraints.HORIZONTAL;
247
        p.add(new JLabel("Formater les numéros de compte suivant le nombre de caractères suivants", SwingUtilities.RIGHT), c2);
248
        c2.gridx += 3;
249
        c2.weightx = 1;
250
        c2.gridwidth = 1;
251
 
252
        p.add(this.spinNbChar, c2);
253
 
254
        c2.gridy++;
255
        c2.gridx = 0;
256
        c2.weightx = 0;
257
        c2.gridwidth = 3;
258
        c2.fill = GridBagConstraints.HORIZONTAL;
259
        p.add(new JLabel("Limiter le nombre de caractéres des numéros compte à", SwingUtilities.RIGHT), c2);
260
        c2.gridx += 3;
261
        c2.weightx = 1;
262
        c2.gridwidth = 1;
263
        p.add(this.spinNbCharLimit, c2);
264
 
80 ilm 265
        c.gridy++;
90 ilm 266
        c.gridx = 0;
80 ilm 267
        c.weightx = 1;
90 ilm 268
        c.weighty = 1;
269
        c.gridwidth = GridBagConstraints.REMAINDER;
270
        c.fill = GridBagConstraints.HORIZONTAL;
271
        this.add(p, c);
272
 
273
        c.gridy++;
274
        c.weightx = 1;
80 ilm 275
        c.gridx = 0;
276
        c.gridwidth = 1;
277
        final JPanel panelButton = new JPanel();
278
        panelButton.add(this.buttonGen);
279
        c.gridwidth = GridBagConstraints.REMAINDER;
280
        c.fill = GridBagConstraints.NONE;
281
        c.anchor = GridBagConstraints.SOUTHEAST;
282
        c.weightx = 0;
283
        c.weighty = 1;
284
        this.add(panelButton, c);
285
        this.buttonGen.addActionListener(new ActionListener() {
286
            @Override
287
            public void actionPerformed(ActionEvent e) {
288
                export((ExportType) comboType.getSelectedItem());
289
            }
290
        });
90 ilm 291
        p.setVisible(false);
292
        comboType.addActionListener(new ActionListener() {
293
 
294
            @Override
295
            public void actionPerformed(ActionEvent e) {
296
                p.setVisible((ExportType) comboType.getSelectedItem() == ExportType.RelationExpert);
297
 
298
            }
299
        });
80 ilm 300
    }
301
 
302
    protected final void export(ExportType type) {
303
        try {
90 ilm 304
            final AbstractExport createExport = type.createExport(ComptaPropsConfiguration.getInstanceCompta().getRootSociete());
305
            createExport.setNbCharCpt((Integer) this.spinNbChar.getValue());
306
            createExport.setNbCharLimitCpt((Integer) this.spinNbCharLimit.getValue());
307
            final Tuple2<File, Number> res = createExport.export(this.fileChooser.getSelectedFile(), this.du.getDate(), this.au.getDate(), this.boxJournal.getSelectedRow(),
308
                    this.boxExport.isSelected());
80 ilm 309
            if (res.get1().intValue() == 0) {
310
                JOptionPane.showMessageDialog(this, "Aucune écriture trouvée. La période est-elle correcte ?");
311
            } else {
312
                // Notify
313
                JOptionPane.showMessageDialog(this, "L'export des " + res.get1() + " écritures est terminé.\nLe fichier créé est " + res.get0().getAbsolutePath());
314
                // Close frame
315
                SwingUtilities.getWindowAncestor(this).dispose();
316
            }
317
        } catch (final FileNotFoundException ex) {
318
            JOptionPane.showMessageDialog(this, "Création du fichier impossible : " + ex.getMessage());
319
        } catch (Exception e) {
320
            ExceptionHandler.handle(this, "Erreur d'export", e);
321
        }
322
    }
323
}