OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
180 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.core.sales.invoice.ui;
15
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
17
import org.openconcerto.erp.core.sales.invoice.report.ReportingStockXmlSheet;
18
import org.openconcerto.erp.core.supplychain.stock.element.DepotStockSQLElement;
19
import org.openconcerto.sql.request.ComboSQLRequest;
20
import org.openconcerto.sql.sqlobject.SQLRequestComboBox;
21
import org.openconcerto.ui.component.InteractionMode;
22
import org.openconcerto.utils.ExceptionHandler;
23
 
24
import java.awt.Color;
25
import java.awt.GridBagConstraints;
26
import java.awt.GridBagLayout;
27
import java.awt.Insets;
28
import java.awt.event.ActionEvent;
29
import java.awt.event.ActionListener;
30
import java.util.ArrayList;
31
import java.util.List;
32
 
33
import javax.swing.JButton;
34
import javax.swing.JCheckBox;
35
import javax.swing.JLabel;
36
import javax.swing.JPanel;
37
import javax.swing.SwingConstants;
38
 
39
public class RapportEtatDeStockDepotSelectionPanel extends JPanel {
40
 
41
    JPanel pnlMain = new JPanel();
42
    JPanel pnlBottom = new JPanel();
43
    JLabel labDepots = new JLabel("Dépôts");
44
    JButton butReport = new JButton("Générer le rapport");
45
    JCheckBox chkTous = new JCheckBox("Séléctionner tous les dépôts");
46
 
47
    SQLRequestComboBox sqlreqDepots = new SQLRequestComboBox(false, 20);
48
 
49
    public RapportEtatDeStockDepotSelectionPanel(ComptaPropsConfiguration conf) {
50
        GridBagLayout layThis = new GridBagLayout();
51
        this.setLayout(layThis);
52
 
53
        GridBagLayout layMain = new GridBagLayout();
54
        this.pnlMain.setLayout(layMain);
55
 
56
        GridBagLayout layBottom = new GridBagLayout();
57
        this.pnlBottom.setLayout(layBottom);
58
 
59
        GridBagConstraints gbcThis = new GridBagConstraints();
60
        gbcThis.weightx = 1;
61
        gbcThis.weighty = 1;
62
        gbcThis.gridheight = 1;
63
        gbcThis.gridwidth = 1;
64
        gbcThis.fill = GridBagConstraints.BOTH;
65
 
66
        GridBagConstraints gbcBottom = new GridBagConstraints();
67
        gbcBottom.weightx = 1;
68
        gbcBottom.weighty = 1;
69
        gbcBottom.gridheight = 1;
70
        gbcBottom.gridwidth = 2;
71
        gbcBottom.fill = GridBagConstraints.BOTH;
72
 
73
        GridBagConstraints gbcDefault = new GridBagConstraints();
74
        gbcDefault.weightx = 1;
75
        gbcDefault.gridheight = 1;
76
        gbcDefault.gridwidth = 1;
77
        gbcDefault.insets = new Insets(0, 4, 4, 4);
78
        gbcDefault.fill = GridBagConstraints.HORIZONTAL;
79
 
80
        GridBagConstraints gbcButton = new GridBagConstraints();
81
        gbcButton.weightx = 1;
82
        gbcButton.weighty = 1;
83
        gbcButton.gridheight = 1;
84
        gbcButton.gridwidth = 1;
85
        gbcButton.insets = new Insets(0, 4, 4, 4);
86
        gbcButton.anchor = GridBagConstraints.SOUTHEAST;
87
 
88
        this.setBackground(Color.DARK_GRAY);
89
        this.add(this.pnlMain, gbcThis);
90
 
91
        // Label.
92
        gbcDefault.gridx = 0;
93
        gbcDefault.gridy = 0;
94
        this.pnlMain.add(this.labDepots, gbcDefault);
95
        this.labDepots.setHorizontalAlignment(SwingConstants.RIGHT);
96
 
97
        // SQLRequestComboBox.
98
        List<String> fields = new ArrayList<>();
99
        fields.add("NOM");
100
        ComboSQLRequest request = new ComboSQLRequest(conf.getDirectory().getElement("DEPOT_STOCK").getTable(), fields, null, conf.getDirectory());
101
 
102
        gbcDefault.gridx = 1;
103
        gbcDefault.gridy = 0;
104
        this.sqlreqDepots.uiInit(request);
105
        this.sqlreqDepots.setValue(DepotStockSQLElement.DEFAULT_ID);
106
        this.pnlMain.add(this.sqlreqDepots, gbcDefault);
107
 
108
        // CheckBox.
109
        gbcDefault.gridx = 1;
110
        gbcDefault.gridy = 1;
111
        this.chkTous.addActionListener(new ActionListener() {
112
            @Override
113
            public void actionPerformed(ActionEvent e) {
114
                if (RapportEtatDeStockDepotSelectionPanel.this.chkTous.isSelected()) {
115
                    RapportEtatDeStockDepotSelectionPanel.this.sqlreqDepots.setEnabled(InteractionMode.DISABLED);
116
                } else {
117
                    RapportEtatDeStockDepotSelectionPanel.this.sqlreqDepots.setEnabled(InteractionMode.READ_WRITE);
118
                }
119
            }
120
        });
121
 
122
        this.pnlMain.add(this.chkTous, gbcDefault);
123
 
124
        // Ajout du panel du bas.
125
        gbcBottom.gridx = 0;
126
        gbcBottom.gridy = 2;
127
        this.pnlMain.add(this.pnlBottom, gbcBottom);
128
 
129
        // Button.
130
        gbcButton.gridx = 0;
131
        gbcButton.gridy = 0;
132
        this.butReport.addActionListener(new ActionListener() {
133
            @Override
134
            public void actionPerformed(ActionEvent e) {
135
                Integer intIDDepot = RapportEtatDeStockDepotSelectionPanel.this.sqlreqDepots.getValue();
136
                boolean bTousLesDepots = RapportEtatDeStockDepotSelectionPanel.this.chkTous.isSelected();
137
 
138
                try {
139
                    ReportingStockXmlSheet sheet = new ReportingStockXmlSheet(conf, intIDDepot, bTousLesDepots);
140
                    sheet.createDocumentAsynchronous().get();
141
                    sheet.openDocument(false);
142
 
143
                } catch (Exception excep) {
144
                    ExceptionHandler.handle("Erreur de traitement", excep);
145
                }
146
            }
147
        });
148
 
149
        this.pnlBottom.add(this.butReport, gbcButton);
150
    }
151
 
152
}