OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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