OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 177 | 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
        },
177 ilm 72
        EBP_PIVOT("EBP Pivot") {
73
            @Override
74
            public AbstractExport createExport(DBRoot root) {
75
                return new ExportEBPPivot(root);
76
            }
77
        },
80 ilm 78
        EBP_OL("EBP Open Line") {
79
            @Override
80
            public AbstractExport createExport(DBRoot root) {
81
                return new ExportEBP_OL(root);
82
            }
83
        },
84
        EBP("EBP Compta Pro") {
85
            @Override
86
            public AbstractExport createExport(DBRoot root) {
87
                return new ExportEBP_ComptaPro(root);
88
            }
149 ilm 89
        },
90
        SAGE("Sage Ximport") {
91
            @Override
92
            public AbstractExport createExport(DBRoot root) {
93
                return new ExportSageXimport(root);
94
            }
95
        },
174 ilm 96
        SAGE_ETENDU("Sage Etendu") {
97
            @Override
98
            public AbstractExport createExport(DBRoot root) {
99
                return new ExportSageEtendu(root);
100
            }
101
        },
180 ilm 102
        QUADRACOMPTA("Quadratus : Export des écritures vers QuadraCompta") {
103
            @Override
104
            public AbstractExport createExport(DBRoot root) {
105
                return new ExportToQuadraCompta(root);
106
            }
107
        },
149 ilm 108
        CCMX("Cegid CCMX") {
109
            @Override
110
            public AbstractExport createExport(DBRoot root) {
111
                return new ExportCCMX(root);
112
            }
80 ilm 113
        };
114
 
115
        private final String label;
116
 
117
        private ExportType(final String label) {
118
            this.label = label;
119
        }
120
 
121
        public final String getLabel() {
122
            return this.label;
123
        }
124
 
125
        public abstract AbstractExport createExport(final DBRoot root);
126
    }
127
 
128
    private final JDate du, au;
129
    private final JButton buttonGen = new JButton("Exporter");
130
    private final JFileChooser fileChooser = new JFileChooser();
131
    private final JTextField textDestination = new JTextField();
132
    private final ElementComboBox boxJournal = new ElementComboBox(true);
133
    private final JCheckBox boxExport = new JCheckBox("Seulement les nouvelles ecritures");
90 ilm 134
    private final JCheckBox boxReplaceLib = new JCheckBox("Remplacer le libellé par le nom du client");
135
    private JSpinner spinNbChar = new JSpinner(new ISpinnerIntegerModel(0, 20, 0));
136
    private JSpinner spinNbCharLimit = new JSpinner(new ISpinnerIntegerModel(0, 20, 0));
80 ilm 137
 
138
    public ExportPanel() {
139
        super(new GridBagLayout());
140
        final GridBagConstraints c = new DefaultGridBagConstraints();
141
 
142
        c.gridwidth = 4;
143
        this.add(new JLabelBold("Export des écritures comptables"), c);
144
 
145
        // Fichier de destination
146
        final JPanel panelFichier = new JPanel(new GridBagLayout());
147
        final GridBagConstraints cFic = new DefaultGridBagConstraints();
148
        cFic.insets.left = 0;
149
        cFic.insets.bottom = 0;
150
        cFic.gridx++;
151
        cFic.weightx = 1;
152
        panelFichier.add(this.textDestination, cFic);
153
 
154
        final JButton buttonChoose = new JButton("...");
155
        cFic.gridx++;
156
        cFic.weightx = 0;
157
        cFic.fill = GridBagConstraints.NONE;
158
        panelFichier.add(buttonChoose, cFic);
159
 
160
        this.buttonGen.setEnabled(false);
161
        this.textDestination.setEditable(false);
162
 
163
        this.fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
164
        buttonChoose.addActionListener(new ActionListener() {
165
            @Override
166
            public void actionPerformed(final ActionEvent e) {
167
                final int answer = ExportPanel.this.fileChooser.showSaveDialog(ExportPanel.this);
168
                if (answer == JFileChooser.APPROVE_OPTION) {
169
                    ExportPanel.this.textDestination.setText(ExportPanel.this.fileChooser.getSelectedFile().getAbsolutePath());
170
                }
171
                ExportPanel.this.buttonGen.setEnabled(answer == JFileChooser.APPROVE_OPTION);
172
            }
173
        });
174
        c.gridy++;
175
        c.gridx = 0;
176
        c.gridwidth = 1;
177
        this.add(new JLabel("Dossier de destination", SwingUtilities.RIGHT), c);
178
        c.gridx++;
179
        c.weightx = 1;
180
        c.gridwidth = 4;
181
        this.add(panelFichier, c);
182
 
183
        c.gridx = 0;
184
        c.gridwidth = 1;
185
        c.gridy++;
186
        c.weightx = 0;
187
        c.anchor = GridBagConstraints.EAST;
188
        this.add(new JLabel("Période du", SwingUtilities.RIGHT), c);
189
 
190
        c.gridx++;
191
        c.anchor = GridBagConstraints.WEST;
192
        c.fill = GridBagConstraints.NONE;
193
        this.du = new JDate(true);
194
        this.add(this.du, c);
195
 
196
        c.gridx++;
197
        this.add(new JLabel("au"), c);
198
 
199
        c.gridx++;
200
        this.au = new JDate(true);
201
        this.add(this.au, c);
202
 
203
        this.boxExport.setSelected(true);
204
        c.gridy++;
205
        c.gridx = 0;
206
        c.gridwidth = 3;
207
        this.add(this.boxExport, c);
208
 
209
        final SQLElement elt = Configuration.getInstance().getDirectory().getElement(JournalSQLElement.class);
210
        final ComboSQLRequest comboRequest = elt.getComboRequest(true);
211
        comboRequest.setUndefLabel("Tous");
212
        this.boxJournal.init(elt, comboRequest);
213
        c.gridy++;
214
        c.gridx = 0;
215
        c.weightx = 0;
216
        c.gridwidth = 1;
217
        c.fill = GridBagConstraints.HORIZONTAL;
218
        this.add(new JLabel("Ecritures du journal", SwingUtilities.RIGHT), c);
219
        c.gridx++;
220
        c.weightx = 1;
221
        c.gridwidth = 4;
222
        c.fill = GridBagConstraints.NONE;
223
        this.boxJournal.setValue(JournalSQLElement.VENTES);
224
        this.add(this.boxJournal, c);
225
 
226
        c.gridy++;
227
        c.gridx = 0;
228
        c.weightx = 0;
229
        c.gridwidth = 1;
230
        c.fill = GridBagConstraints.HORIZONTAL;
231
        this.add(new JLabel("Type d'export", SwingUtilities.RIGHT), c);
232
        c.gridx++;
233
        c.weightx = 1;
234
        c.gridwidth = 4;
235
        final JComboBox comboType = new JComboBox(ExportType.values());
236
        comboType.setRenderer(new DefaultListCellRenderer() {
237
            @Override
238
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
239
                return super.getListCellRendererComponent(list, ((ExportType) value).getLabel(), index, isSelected, cellHasFocus);
240
            }
241
        });
242
        c.fill = GridBagConstraints.NONE;
243
        comboType.setSelectedIndex(0);
244
        this.add(comboType, c);
245
 
90 ilm 246
        final JPanel p = new JPanel(new GridBagLayout());
247
        GridBagConstraints c2 = new DefaultGridBagConstraints();
248
        c2.gridx = 0;
249
        c2.weightx = 1;
250
        c2.gridwidth = GridBagConstraints.REMAINDER;
251
        c2.fill = GridBagConstraints.HORIZONTAL;
252
        p.add(new TitledSeparator("Option export relation expert", true), 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("Formater les numéros de compte suivant le nombre de caractères suivants", SwingUtilities.RIGHT), c2);
260
        c2.gridx += 3;
261
        c2.weightx = 1;
262
        c2.gridwidth = 1;
263
 
264
        p.add(this.spinNbChar, c2);
265
 
266
        c2.gridy++;
267
        c2.gridx = 0;
268
        c2.weightx = 0;
269
        c2.gridwidth = 3;
270
        c2.fill = GridBagConstraints.HORIZONTAL;
271
        p.add(new JLabel("Limiter le nombre de caractéres des numéros compte à", SwingUtilities.RIGHT), c2);
272
        c2.gridx += 3;
273
        c2.weightx = 1;
274
        c2.gridwidth = 1;
275
        p.add(this.spinNbCharLimit, c2);
276
 
80 ilm 277
        c.gridy++;
90 ilm 278
        c.gridx = 0;
80 ilm 279
        c.weightx = 1;
90 ilm 280
        c.weighty = 1;
281
        c.gridwidth = GridBagConstraints.REMAINDER;
282
        c.fill = GridBagConstraints.HORIZONTAL;
283
        this.add(p, c);
284
 
285
        c.gridy++;
286
        c.weightx = 1;
80 ilm 287
        c.gridx = 0;
288
        c.gridwidth = 1;
289
        final JPanel panelButton = new JPanel();
290
        panelButton.add(this.buttonGen);
291
        c.gridwidth = GridBagConstraints.REMAINDER;
292
        c.fill = GridBagConstraints.NONE;
293
        c.anchor = GridBagConstraints.SOUTHEAST;
294
        c.weightx = 0;
295
        c.weighty = 1;
296
        this.add(panelButton, c);
297
        this.buttonGen.addActionListener(new ActionListener() {
298
            @Override
299
            public void actionPerformed(ActionEvent e) {
300
                export((ExportType) comboType.getSelectedItem());
301
            }
302
        });
90 ilm 303
        p.setVisible(false);
304
        comboType.addActionListener(new ActionListener() {
305
 
306
            @Override
307
            public void actionPerformed(ActionEvent e) {
308
                p.setVisible((ExportType) comboType.getSelectedItem() == ExportType.RelationExpert);
309
 
310
            }
311
        });
80 ilm 312
    }
313
 
314
    protected final void export(ExportType type) {
315
        try {
90 ilm 316
            final AbstractExport createExport = type.createExport(ComptaPropsConfiguration.getInstanceCompta().getRootSociete());
317
            createExport.setNbCharCpt((Integer) this.spinNbChar.getValue());
318
            createExport.setNbCharLimitCpt((Integer) this.spinNbCharLimit.getValue());
319
            final Tuple2<File, Number> res = createExport.export(this.fileChooser.getSelectedFile(), this.du.getDate(), this.au.getDate(), this.boxJournal.getSelectedRow(),
320
                    this.boxExport.isSelected());
80 ilm 321
            if (res.get1().intValue() == 0) {
322
                JOptionPane.showMessageDialog(this, "Aucune écriture trouvée. La période est-elle correcte ?");
323
            } else {
324
                // Notify
325
                JOptionPane.showMessageDialog(this, "L'export des " + res.get1() + " écritures est terminé.\nLe fichier créé est " + res.get0().getAbsolutePath());
326
                // Close frame
327
                SwingUtilities.getWindowAncestor(this).dispose();
328
            }
329
        } catch (final FileNotFoundException ex) {
330
            JOptionPane.showMessageDialog(this, "Création du fichier impossible : " + ex.getMessage());
331
        } catch (Exception e) {
332
            ExceptionHandler.handle(this, "Erreur d'export", e);
333
        }
334
    }
335
}