OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 132 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 132 Rev 182
Line 1... Line 1...
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
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
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
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.
9
 * language governing permissions and limitations under the License.
Line 13... Line 13...
13
 
13
 
14
 package org.openconcerto.erp.core.finance.accounting.ui;
14
 package org.openconcerto.erp.core.finance.accounting.ui;
15
 
15
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
17
import org.openconcerto.erp.config.Gestion;
17
import org.openconcerto.erp.config.Gestion;
18
import org.openconcerto.erp.core.finance.accounting.report.GrandLivreSheet;
18
import org.openconcerto.erp.core.finance.accounting.report.GrandLivrePDF;
19
import org.openconcerto.erp.core.finance.accounting.report.GrandLivreSheetXML;
19
import org.openconcerto.erp.core.finance.accounting.report.GrandLivreSheetXML;
20
import org.openconcerto.erp.generationDoc.SpreadSheetGeneratorListener;
20
import org.openconcerto.erp.generationDoc.SpreadSheetGeneratorListener;
21
import org.openconcerto.erp.preferences.DefaultNXProps;
21
import org.openconcerto.erp.preferences.DefaultNXProps;
22
import org.openconcerto.sql.Configuration;
22
import org.openconcerto.sql.Configuration;
23
import org.openconcerto.sql.model.SQLRow;
23
import org.openconcerto.sql.model.SQLRow;
24
import org.openconcerto.sql.sqlobject.ElementComboBox;
24
import org.openconcerto.sql.sqlobject.ElementComboBox;
25
import org.openconcerto.ui.DefaultGridBagConstraints;
25
import org.openconcerto.ui.DefaultGridBagConstraints;
26
import org.openconcerto.ui.JDate;
26
import org.openconcerto.ui.JDate;
27
import org.openconcerto.ui.JLabelBold;
27
import org.openconcerto.ui.JLabelBold;
-
 
28
import org.openconcerto.utils.ExceptionHandler;
-
 
29
import org.openconcerto.utils.FileUtils;
28
 
30
 
29
import java.awt.FlowLayout;
31
import java.awt.FlowLayout;
30
import java.awt.GridBagConstraints;
32
import java.awt.GridBagConstraints;
31
import java.awt.GridBagLayout;
33
import java.awt.GridBagLayout;
32
import java.awt.event.ActionEvent;
34
import java.awt.event.ActionEvent;
33
import java.awt.event.ActionListener;
35
import java.awt.event.ActionListener;
34
import java.beans.PropertyChangeEvent;
36
import java.beans.PropertyChangeEvent;
35
import java.beans.PropertyChangeListener;
37
import java.beans.PropertyChangeListener;
-
 
38
import java.io.File;
-
 
39
import java.io.IOException;
-
 
40
import java.text.SimpleDateFormat;
36
import java.util.Date;
41
import java.util.Date;
37
import java.util.concurrent.ExecutionException;
-
 
38
 
42
 
39
import javax.swing.AbstractAction;
43
import javax.swing.AbstractAction;
40
import javax.swing.ButtonGroup;
44
import javax.swing.ButtonGroup;
41
import javax.swing.JButton;
45
import javax.swing.JButton;
42
import javax.swing.JCheckBox;
46
import javax.swing.JCheckBox;
-
 
47
import javax.swing.JFileChooser;
43
import javax.swing.JFrame;
48
import javax.swing.JFrame;
44
import javax.swing.JLabel;
49
import javax.swing.JLabel;
45
import javax.swing.JOptionPane;
-
 
46
import javax.swing.JPanel;
50
import javax.swing.JPanel;
47
import javax.swing.JProgressBar;
51
import javax.swing.JProgressBar;
48
import javax.swing.JRadioButton;
52
import javax.swing.JRadioButton;
49
import javax.swing.JTextField;
53
import javax.swing.JTextField;
50
import javax.swing.SwingConstants;
54
import javax.swing.SwingConstants;
Line 52... Line 56...
52
import javax.swing.event.DocumentEvent;
56
import javax.swing.event.DocumentEvent;
53
import javax.swing.event.DocumentListener;
57
import javax.swing.event.DocumentListener;
54
 
58
 
55
public class ImpressionGrandLivrePanel extends JPanel implements SpreadSheetGeneratorListener {
59
public class ImpressionGrandLivrePanel extends JPanel implements SpreadSheetGeneratorListener {
56
 
60
 
-
 
61
    private final JDate dateDeb;
57
    private final JDate dateDeb, dateEnd;
62
    private final JDate dateEnd;
-
 
63
    private JButton validPDF;
58
    private JButton valid;
64
    private JButton validODS;
59
    private JButton annul;
65
    private JButton annul;
60
    private JCheckBox checkImpr;
66
    private JCheckBox checkImpr;
61
    private JCheckBox checkVisu;
67
    private JCheckBox checkVisu;
62
    private JTextField compteDeb, compteEnd;
68
    private JTextField compteDeb, compteEnd;
63
    private int mode = GrandLivreSheet.MODEALL;
69
    private int mode = GrandLivrePDF.MODEALL;
64
    private JProgressBar bar = new JProgressBar(0, 3);
70
    private JProgressBar bar = new JProgressBar(0, 3);
65
 
71
 
66
    public ImpressionGrandLivrePanel() {
72
    public ImpressionGrandLivrePanel() {
67
        this.setLayout(new GridBagLayout());
73
        this.setLayout(new GridBagLayout());
68
        final GridBagConstraints c = new DefaultGridBagConstraints();
74
        final GridBagConstraints c = new DefaultGridBagConstraints();
69
 
75
 
-
 
76
        final ComptaPropsConfiguration comptaPropsConfiguration = (ComptaPropsConfiguration) Configuration.getInstance();
70
        SQLRow rowSociete = ((ComptaPropsConfiguration) Configuration.getInstance()).getRowSociete();
77
        SQLRow rowSociete = comptaPropsConfiguration.getRowSociete();
71
        SQLRow rowExercice = Configuration.getInstance().getBase().getTable("EXERCICE_COMMON").getRow(rowSociete.getInt("ID_EXERCICE_COMMON"));
78
        SQLRow rowExercice = comptaPropsConfiguration.getBase().getTable("EXERCICE_COMMON").getRow(rowSociete.getInt("ID_EXERCICE_COMMON"));
72
 
79
 
73
        this.dateDeb = new JDate();
80
        this.dateDeb = new JDate();
74
        this.dateEnd = new JDate();
81
        this.dateEnd = new JDate();
75
 
82
 
76
        // Période
83
        // Période
77
        c.weightx = 0;
84
        c.weightx = 0;
78
        this.add(new JLabel("Période du", SwingConstants.RIGHT), c);
85
        this.add(new JLabel("Période du", SwingConstants.RIGHT), c);
79
        c.gridx++;
86
        c.gridx++;
80
        c.weightx = 1;
87
        c.weightx = 0;
81
        this.add(this.dateDeb, c);
88
        this.add(this.dateDeb, c);
82
        // Chargement des valeurs par défaut
89
        // Chargement des valeurs par défaut
83
        String valueDateDeb = DefaultNXProps.getInstance().getStringProperty("GrandLivreDateDeb");
90
        String valueDateDeb = DefaultNXProps.getInstance().getStringProperty("GrandLivreDateDeb");
84
        if (valueDateDeb.trim().length() > 0) {
91
        if (valueDateDeb.trim().length() > 0) {
85
            Long l = new Long(valueDateDeb);
92
            Long l = new Long(valueDateDeb);
Line 162... Line 169...
162
        this.add(comboJrnl, c);
169
        this.add(comboJrnl, c);
163
 
170
 
164
        // Radio mode
171
        // Radio mode
165
        JRadioButton radioAll = new JRadioButton(new AbstractAction("Toutes") {
172
        JRadioButton radioAll = new JRadioButton(new AbstractAction("Toutes") {
166
            public void actionPerformed(ActionEvent e) {
173
            public void actionPerformed(ActionEvent e) {
167
                mode = GrandLivreSheet.MODEALL;
174
                mode = GrandLivrePDF.MODEALL;
168
            }
175
            }
169
        });
176
        });
170
 
177
 
171
        JRadioButton radioLettree = new JRadioButton(new AbstractAction("Lettrées") {
178
        JRadioButton radioLettree = new JRadioButton(new AbstractAction("Lettrées") {
172
            public void actionPerformed(ActionEvent e) {
179
            public void actionPerformed(ActionEvent e) {
173
                mode = GrandLivreSheet.MODELETTREE;
180
                mode = GrandLivrePDF.MODELETTREE;
174
            }
181
            }
175
        });
182
        });
176
 
183
 
177
        JRadioButton radioNonLettree = new JRadioButton(new AbstractAction("Non lettrées") {
184
        JRadioButton radioNonLettree = new JRadioButton(new AbstractAction("Non lettrées") {
178
            public void actionPerformed(ActionEvent e) {
185
            public void actionPerformed(ActionEvent e) {
179
                mode = GrandLivreSheet.MODENONLETTREE_ALL;
186
                mode = GrandLivrePDF.MODENONLETTREE_ALL;
180
            }
187
            }
181
        });
188
        });
182
 
189
 
183
        JRadioButton radioNonLettreePeridod = new JRadioButton(new AbstractAction("Non lettrées sur la période") {
190
        JRadioButton radioNonLettreePeridod = new JRadioButton(new AbstractAction("Non lettrées sur la période") {
184
            public void actionPerformed(ActionEvent e) {
191
            public void actionPerformed(ActionEvent e) {
185
                mode = GrandLivreSheet.MODENONLETTREE_PERIODE;
192
                mode = GrandLivrePDF.MODENONLETTREE_PERIODE;
186
            }
193
            }
187
        });
194
        });
188
 
195
 
189
        c.gridy++;
196
        c.gridy++;
190
        c.gridx = 0;
197
        c.gridx = 0;
Line 223... Line 230...
223
        this.add(new JLabelBold("Progression de la creation du grand livre"), c);
230
        this.add(new JLabelBold("Progression de la creation du grand livre"), c);
224
        c.gridy++;
231
        c.gridy++;
225
        this.bar.setStringPainted(true);
232
        this.bar.setStringPainted(true);
226
        this.add(this.bar, c);
233
        this.add(this.bar, c);
227
 
234
 
-
 
235
        this.validPDF = new JButton("PDF");
228
        this.valid = new JButton("Valider");
236
        this.validODS = new JButton("Tableur");
-
 
237
 
229
        this.annul = new JButton("Fermer");
238
        this.annul = new JButton("Fermer");
230
        this.checkImpr = new JCheckBox("Impression");
-
 
231
        this.checkVisu = new JCheckBox("Visualisation");
-
 
232
 
239
 
233
        // Print & View
240
        // OK, Cancel
234
        final JPanel panelPrintView = new JPanel(new FlowLayout(FlowLayout.LEADING, 2, 0));
-
 
235
 
241
 
236
        panelPrintView.add(this.checkImpr);
-
 
237
        panelPrintView.add(this.checkVisu);
-
 
238
        this.checkImpr.setSelected(true);
-
 
239
        c.gridx = 0;
242
        c.gridx = 0;
240
        c.gridy++;
243
        c.gridy++;
241
        c.gridwidth = 4;
244
        c.gridwidth = 4;
242
        c.weightx = 1;
245
        c.weightx = 1;
243
        c.weighty = 1;
246
        c.weighty = 1;
244
        c.fill = GridBagConstraints.NONE;
247
        c.fill = GridBagConstraints.NONE;
245
        c.anchor = GridBagConstraints.SOUTHEAST;
248
        c.anchor = GridBagConstraints.SOUTHEAST;
246
        this.add(panelPrintView, c);
-
 
247
 
249
 
248
        // OK, Cancel
-
 
249
        c.gridy++;
-
 
250
        c.weightx = 0;
-
 
251
        c.weighty = 0;
-
 
252
        JPanel panelOkCancel = new JPanel();
250
        JPanel panelOkCancel = new JPanel();
-
 
251
        panelOkCancel.add(this.validODS);
253
        panelOkCancel.add(this.valid);
252
        panelOkCancel.add(this.validPDF);
-
 
253
 
254
        panelOkCancel.add(this.annul);
254
        panelOkCancel.add(this.annul);
255
        this.add(panelOkCancel, c);
255
        this.add(panelOkCancel, c);
256
        this.checkValidity();
256
        this.checkValidity();
257
        this.valid.addActionListener(new ActionListener() {
257
        this.validPDF.addActionListener(new ActionListener() {
258
            public void actionPerformed(ActionEvent e) {
258
            public void actionPerformed(ActionEvent e) {
-
 
259
                JFileChooser chooser = new JFileChooser();
-
 
260
                SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy");
-
 
261
                chooser.setSelectedFile(new File("Grand livre " + df.format(new Date()) + ".pdf"));
-
 
262
                int r = chooser.showSaveDialog(ImpressionGrandLivrePanel.this);
-
 
263
                if (r == JFileChooser.APPROVE_OPTION) {
-
 
264
                    validPDF.setEnabled(false);
259
                valid.setEnabled(false);
265
                    validODS.setEnabled(false);
260
                bar.setString(null);
266
                    bar.setString(null);
261
                bar.setValue(1);
267
                    bar.setValue(0);
-
 
268
                    // un fichier a été choisi (sortie par OK)
-
 
269
                    // nom du fichier choisi
-
 
270
                    final File file = chooser.getSelectedFile();
262
                new Thread(new Runnable() {
271
                    new Thread(new Runnable() {
263
                    public void run() {
272
                        public void run() {
264
                        final GrandLivreSheetXML bSheet = new GrandLivreSheetXML(dateDeb.getDate(), dateEnd.getDate(), compteDeb.getText().trim(), compteEnd.getText().trim(), mode,
-
 
265
                                boxCumulsAnts.isSelected(), !boxCompteSolde.isSelected(), boxCentralClient.isSelected(), boxCentralFourn.isSelected(), comboJrnl.getSelectedId());
-
 
266
                        try {
273
                            try {
267
                            bSheet.createDocument();
-
 
268
 
-
 
269
                            if (bSheet.getSize() == 0) {
274
                                final GrandLivrePDF bSheet = new GrandLivrePDF(comptaPropsConfiguration, dateDeb.getDate(), dateEnd.getDate(), compteDeb.getText().trim(), compteEnd.getText().trim(),
270
                                JOptionPane.showMessageDialog(ImpressionGrandLivrePanel.this, "Aucune écriture trouvée");
275
                                        mode, boxCumulsAnts.isSelected(), !boxCompteSolde.isSelected(), boxCentralClient.isSelected(), boxCentralFourn.isSelected(), comboJrnl.getSelectedId());
271
 
-
 
272
                            } else {
276
                                bar.setValue(1);
273
 
-
 
274
                                SwingUtilities.invokeLater(new Runnable() {
277
                                bSheet.getGeneratedPDFFile(file);
275
                                    public void run() {
-
 
276
                                        bar.setValue(2);
278
                                bar.setValue(2);
277
                                        // bSheet.showPrintAndExport(false, false, true, true);
279
                                SwingUtilities.invokeLater(new Runnable() {
278
 
280
 
-
 
281
                                    @Override
-
 
282
                                    public void run() {
-
 
283
                                        Gestion.openPDF(file);
279
                                    }
284
                                    }
280
                                });
285
                                });
281
 
286
 
282
                                try {
-
 
283
                                    // bSheet.getOrCreatePDFDocumentFile(true);
-
 
284
                                    bSheet.getOrCreatePDFDocumentFile(true, true);
-
 
285
                                        Gestion.openPDF(bSheet.getGeneratedPDFFile());
-
 
286
                                } catch (Exception exn) {
287
                            } catch (Exception exn) {
287
                                    // TODO Bloc catch auto-généré
288
                                ExceptionHandler.handle("Erreur de génération du grand livre", exn);
288
                                    exn.printStackTrace();
289
                                exn.printStackTrace();
-
 
290
                            } finally {
-
 
291
                                taskEnd();
-
 
292
                            }
-
 
293
                        }
-
 
294
                    }).start();
289
                                }
295
                }
-
 
296
 
290
                            }
297
            }
-
 
298
        });
-
 
299
        this.validODS.addActionListener(new ActionListener() {
-
 
300
            public void actionPerformed(ActionEvent e) {
291
 
301
 
-
 
302
                validPDF.setEnabled(false);
-
 
303
                validODS.setEnabled(false);
-
 
304
                bar.setString(null);
-
 
305
                bar.setValue(0);
-
 
306
                // un fichier a été choisi (sortie par OK)
-
 
307
                // nom du fichier choisi
-
 
308
                new Thread(new Runnable() {
-
 
309
                    public void run() {
-
 
310
                        try {
-
 
311
                            final GrandLivreSheetXML bSheet = new GrandLivreSheetXML(dateDeb.getDate(), dateEnd.getDate(), compteDeb.getText().trim(), compteEnd.getText().trim(), mode,
-
 
312
                                    boxCumulsAnts.isSelected(), !boxCompteSolde.isSelected(), boxCentralClient.isSelected(), boxCentralFourn.isSelected(), comboJrnl.getSelectedId());
-
 
313
                            bar.setValue(1);
-
 
314
                            final File file = bSheet.getOrCreateDocumentFile();
-
 
315
                            bar.setValue(2);
-
 
316
                            SwingUtilities.invokeLater(new Runnable() {
-
 
317
 
-
 
318
                                @Override
292
                        } catch (InterruptedException exn) {
319
                                public void run() {
-
 
320
                                    try {
-
 
321
                                        FileUtils.openFile(file);
293
                            // TODO Bloc catch auto-généré
322
                                    } catch (IOException e) {
-
 
323
                                        ExceptionHandler.handle("Erreur lors de l'ouverture du grand livre.", e);
-
 
324
                                    }
-
 
325
                                }
294
                            exn.printStackTrace();
326
                            });
-
 
327
 
295
                        } catch (ExecutionException exn) {
328
                        } catch (Exception exn) {
296
                            // TODO Bloc catch auto-généré
329
                            ExceptionHandler.handle("Erreur de génération du grand livre", exn);
297
                            exn.printStackTrace();
330
                            exn.printStackTrace();
298
                        } finally {
331
                        } finally {
299
 
-
 
300
                            taskEnd();
332
                            taskEnd();
301
                        }
333
                        }
302
                    }
334
                    }
303
                }).start();
335
                }).start();
304
 
-
 
305
            }
336
            }
-
 
337
 
306
        });
338
        });
307
        this.annul.addActionListener(new ActionListener() {
339
        this.annul.addActionListener(new ActionListener() {
-
 
340
 
308
            public void actionPerformed(ActionEvent e) {
341
            public void actionPerformed(ActionEvent e) {
309
                ((JFrame) SwingUtilities.getRoot(ImpressionGrandLivrePanel.this)).dispose();
342
                ((JFrame) SwingUtilities.getRoot(ImpressionGrandLivrePanel.this)).dispose();
310
            }
343
            }
311
        });
344
        });
312
 
345
 
Line 360... Line 393...
360
    private void checkValidity() {
393
    private void checkValidity() {
361
 
394
 
362
        Date beginDate = this.dateDeb.getDate();
395
        Date beginDate = this.dateDeb.getDate();
363
        Date endDate = this.dateEnd.getDate();
396
        Date endDate = this.dateEnd.getDate();
364
 
397
 
365
        // System.err.println("Check validity between ");
398
        this.validODS.setEnabled(true);
366
        this.valid.setEnabled(true);
399
        this.validPDF.setEnabled(true);
367
        if (beginDate == null || endDate == null) {
400
        if (beginDate == null || endDate == null) {
-
 
401
            this.validODS.setEnabled(false);
368
            this.valid.setEnabled(false);
402
            this.validPDF.setEnabled(false);
369
        } else {
403
        } else {
370
            if (this.compteDeb.getText().trim().length() == 0 || this.compteEnd.getText().trim().length() == 0) {
404
            if (this.compteDeb.getText().trim().length() == 0 || this.compteEnd.getText().trim().length() == 0) {
-
 
405
                this.validODS.setEnabled(false);
371
                this.valid.setEnabled(false);
406
                this.validPDF.setEnabled(false);
372
            } else {
407
            } else {
373
                if (this.compteDeb.getText().trim().compareToIgnoreCase(this.compteEnd.getText().trim()) > 0) {
408
                if (this.compteDeb.getText().trim().compareToIgnoreCase(this.compteEnd.getText().trim()) > 0) {
-
 
409
                    this.validODS.setEnabled(false);
374
                    this.valid.setEnabled(false);
410
                    this.validPDF.setEnabled(false);
375
                } else {
411
                } else {
376
                    if (beginDate.after(endDate)) {
412
                    if (beginDate.after(endDate)) {
-
 
413
                        this.validODS.setEnabled(false);
377
                        this.valid.setEnabled(false);
414
                        this.validPDF.setEnabled(false);
378
                    }
415
                    }
379
                }
416
                }
380
            }
417
            }
381
        }
418
        }
382
    }
419
    }
Line 402... Line 439...
402
    }
439
    }
403
 
440
 
404
    public void taskEnd() {
441
    public void taskEnd() {
405
        bar.setValue(3);
442
        bar.setValue(3);
406
        bar.setString("Terminée");
443
        bar.setString("Terminée");
-
 
444
        validPDF.setEnabled(true);
407
        valid.setEnabled(true);
445
        validODS.setEnabled(true);
408
    }
446
    }
409
}
447
}