OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev Author Line No. Line
18 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
182 ilm 4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
18 ilm 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.core.finance.accounting.ui;
15
 
16
import org.openconcerto.erp.generationDoc.gestcomm.PointageXmlSheet;
17
import org.openconcerto.sql.Configuration;
18
import org.openconcerto.sql.element.SQLElement;
19
import org.openconcerto.sql.request.ComboSQLRequest;
20
import org.openconcerto.sql.sqlobject.SQLRequestComboBox;
21
import org.openconcerto.ui.DefaultGridBagConstraints;
22
 
23
import java.awt.GridBagConstraints;
24
import java.awt.GridBagLayout;
25
import java.awt.event.ActionEvent;
26
import java.awt.event.ActionListener;
27
import java.beans.PropertyChangeEvent;
28
import java.beans.PropertyChangeListener;
29
import java.util.Calendar;
182 ilm 30
import java.util.Collections;
18 ilm 31
 
32
import javax.swing.JButton;
33
import javax.swing.JFrame;
34
import javax.swing.JLabel;
35
import javax.swing.JPanel;
36
import javax.swing.JSpinner;
37
import javax.swing.JTextArea;
38
import javax.swing.SpinnerModel;
39
import javax.swing.SpinnerNumberModel;
40
import javax.swing.SwingUtilities;
41
 
42
public class GenerationPointagePanel extends JPanel implements ActionListener {
43
    private final JButton gen = new JButton("Générer");
44
    private final JButton close = new JButton("Fermer");
45
    private final SQLRequestComboBox combo = new SQLRequestComboBox(false);
46
 
47
    private final int currentYear = Calendar.getInstance().get(Calendar.YEAR);
48
    private final SpinnerModel model = new SpinnerNumberModel(this.currentYear, this.currentYear - 5, this.currentYear + 5, 1);
49
    private final JSpinner spinYear = new JSpinner(this.model);
50
 
51
    final JTextArea infos = new JTextArea();
52
 
53
    public GenerationPointagePanel() {
54
        super(new GridBagLayout());
55
        GridBagConstraints c = new DefaultGridBagConstraints();
56
        SQLElement moisElt = Configuration.getInstance().getDirectory().getElement("MOIS");
57
 
58
        // Mois
59
        this.add(new JLabel("Mois"), c);
60
        c.gridx++;
61
 
65 ilm 62
        ComboSQLRequest comboReq = moisElt.getComboRequest(true);
18 ilm 63
        this.combo.uiInit(comboReq);
64
        this.add(this.combo, c);
65
 
66
        // Annee
67
        this.add(new JLabel("Année"), c);
68
        c.gridx++;
69
 
70
        this.add(this.spinYear, c);
71
 
72
        JPanel panelButton = new JPanel();
73
        panelButton.add(this.gen);
74
        panelButton.add(this.close);
75
        this.gen.setEnabled(false);
76
 
77
        c.fill = GridBagConstraints.NONE;
78
        c.weightx = 0;
79
        c.anchor = GridBagConstraints.EAST;
80
        c.weighty = 0;
81
        c.gridy++;
82
        this.add(panelButton, c);
83
 
84
        this.combo.addValueListener(new PropertyChangeListener() {
85
            @Override
86
            public void propertyChange(PropertyChangeEvent evt) {
87
                gen.setEnabled(combo.getSelectedRow() != null);
88
            }
89
        });
90
 
91
        this.gen.addActionListener(this);
92
        this.close.addActionListener(this);
93
    }
94
 
95
    @Override
96
    public void actionPerformed(ActionEvent e) {
97
        if (e.getSource() == this.gen) {
98
 
99
            int mois = this.combo.getValue() - 2;
100
            int year = Integer.valueOf(this.spinYear.getValue().toString());
101
            PointageXmlSheet sheet = new PointageXmlSheet(mois, year);
25 ilm 102
            sheet.createDocumentAsynchronous();
182 ilm 103
            sheet.showPrintAndExportAsynchronous(true, false, true, Collections.emptyList());
18 ilm 104
        } else {
105
            if (e.getSource() == this.close) {
106
                ((JFrame) SwingUtilities.getRoot(this)).dispose();
107
            }
108
        }
109
    }
110
}