OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 180 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
174 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.
174 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.sales.product.action;
15
 
16
import org.openconcerto.erp.core.common.ui.NumericTextField;
182 ilm 17
import org.openconcerto.erp.core.sales.product.element.ReferenceArticleSQLElement;
174 ilm 18
import org.openconcerto.sql.Configuration;
19
import org.openconcerto.sql.element.SQLElement;
20
import org.openconcerto.sql.sqlobject.SQLRequestComboBox;
21
import org.openconcerto.ui.DefaultGridBagConstraints;
22
import org.openconcerto.ui.JDate;
23
import org.openconcerto.utils.text.SimpleDocumentListener;
182 ilm 24
import org.openconcerto.utils.Tuple2;
174 ilm 25
 
26
import java.awt.GridBagConstraints;
27
import java.awt.GridBagLayout;
28
import java.awt.event.ActionEvent;
29
import java.awt.event.ActionListener;
30
import java.beans.PropertyChangeEvent;
31
import java.beans.PropertyChangeListener;
32
import java.math.BigDecimal;
182 ilm 33
import java.util.Arrays;
174 ilm 34
 
35
import javax.swing.JButton;
36
import javax.swing.JFrame;
37
import javax.swing.JLabel;
38
import javax.swing.JPanel;
39
import javax.swing.JTextField;
40
import javax.swing.SwingConstants;
41
import javax.swing.SwingUtilities;
42
import javax.swing.event.DocumentEvent;
43
 
44
public class TransfertStockPanel extends JPanel {
45
 
46
    private static String defaultLabel = "Transfert de stock";
47
 
48
    public TransfertStockPanel(Configuration instance) {
49
        super(new GridBagLayout());
50
 
51
        final JButton buttonUpdate = new JButton("Mettre à jour");
52
 
182 ilm 53
        final ReferenceArticleSQLElement articleElt = instance.getDirectory().getElement(ReferenceArticleSQLElement.class);
174 ilm 54
 
55
        final SQLRequestComboBox comboArticle = new SQLRequestComboBox();
56
        comboArticle.uiInit(articleElt.createComboRequest());
57
 
58
        final SQLElement stockElt = instance.getDirectory().getElement("DEPOT_STOCK");
59
        final SQLRequestComboBox comboStockDepart = new SQLRequestComboBox();
60
        comboStockDepart.uiInit(stockElt.createComboRequest());
61
 
62
        final SQLRequestComboBox comboStockArrive = new SQLRequestComboBox();
63
        comboStockArrive.uiInit(stockElt.createComboRequest());
64
 
65
        final NumericTextField fieldReel = new NumericTextField();
66
 
67
        fieldReel.getDocument().addDocumentListener(new SimpleDocumentListener() {
68
 
69
            @Override
70
            public void update(DocumentEvent e) {
180 ilm 71
                updateButtons(buttonUpdate, comboArticle, comboStockDepart, comboStockArrive, fieldReel);
174 ilm 72
            }
73
        });
74
 
75
        comboArticle.addModelListener("wantedID", new PropertyChangeListener() {
76
 
77
            @Override
78
            public void propertyChange(PropertyChangeEvent evt) {
180 ilm 79
                updateButtons(buttonUpdate, comboArticle, comboStockDepart, comboStockArrive, fieldReel);
174 ilm 80
            }
81
        });
82
 
83
        comboStockArrive.addModelListener("wantedID", new PropertyChangeListener() {
84
 
85
            @Override
86
            public void propertyChange(PropertyChangeEvent evt) {
180 ilm 87
                updateButtons(buttonUpdate, comboArticle, comboStockDepart, comboStockArrive, fieldReel);
174 ilm 88
            }
89
        });
90
 
91
        comboStockDepart.addModelListener("wantedID", new PropertyChangeListener() {
92
 
93
            @Override
94
            public void propertyChange(PropertyChangeEvent evt) {
180 ilm 95
                updateButtons(buttonUpdate, comboArticle, comboStockDepart, comboStockArrive, fieldReel);
174 ilm 96
            }
97
        });
98
 
99
        GridBagConstraints c = new DefaultGridBagConstraints();
180 ilm 100
        c.gridx = 0;
174 ilm 101
        this.add(new JLabel("Intitulé"), c);
102
        final JTextField label = new JTextField();
103
        c.gridx++;
180 ilm 104
        c.gridwidth = 1;
174 ilm 105
        c.weightx = 1;
106
        this.add(label, c);
107
        label.setText(defaultLabel);
108
 
109
        c.gridy++;
110
        c.gridx = 0;
111
        c.weightx = 0;
112
        this.add(new JLabel("Date", SwingConstants.RIGHT), c);
113
        final JDate date = new JDate(true);
114
        c.gridx++;
115
        this.add(date, c);
116
 
117
        c.gridy++;
118
        c.gridx = 0;
119
        c.weightx = 0;
120
        this.add(new JLabel("Article", SwingConstants.RIGHT), c);
180 ilm 121
        c.gridx++;
174 ilm 122
        this.add(comboArticle, c);
123
 
124
        c.gridy++;
125
        c.gridx = 0;
126
        c.weightx = 0;
127
        this.add(new JLabel("Départ", SwingConstants.RIGHT), c);
180 ilm 128
        c.gridx++;
174 ilm 129
        this.add(comboStockDepart, c);
130
 
131
        c.gridy++;
132
        c.gridx = 0;
133
        c.weightx = 0;
180 ilm 134
 
174 ilm 135
        this.add(new JLabel("Arrivée", SwingConstants.RIGHT), c);
180 ilm 136
        c.gridx++;
174 ilm 137
        this.add(comboStockArrive, c);
138
 
139
        c.gridy++;
140
        c.gridx = 0;
141
        c.weightx = 0;
180 ilm 142
        this.add(new JLabel("Quantité", SwingConstants.RIGHT), c);
143
        c.gridx++;
174 ilm 144
        this.add(fieldReel, c);
145
 
146
        c.gridy++;
147
        c.gridx = 0;
148
        JButton buttonCancel = new JButton("Annuler");
149
        JPanel pButton = new JPanel();
150
        pButton.add(buttonCancel);
151
        pButton.add(buttonUpdate);
180 ilm 152
        c.gridwidth = 2;
153
        c.anchor = GridBagConstraints.SOUTHEAST;
174 ilm 154
        c.weightx = 0;
155
        c.fill = GridBagConstraints.NONE;
156
        this.add(pButton, c);
157
        buttonCancel.addActionListener(new ActionListener() {
158
 
159
            @Override
160
            public void actionPerformed(ActionEvent e) {
161
                ((JFrame) SwingUtilities.getRoot(TransfertStockPanel.this)).dispose();
162
            }
163
        });
164
        buttonUpdate.addActionListener(new ActionListener() {
165
 
166
            @Override
167
            public void actionPerformed(ActionEvent e) {
168
                buttonUpdate.setEnabled(false);
169
                BigDecimal qteReel = fieldReel.getValue();
170
 
182 ilm 171
                articleElt.transfert(Arrays.asList(Tuple2.create(comboArticle.getSelectedRow(), qteReel)), comboStockDepart.getSelectedRow(), comboStockArrive.getSelectedRow(), label.getText(),
172
                        date.getValue());
174 ilm 173
 
174
                ((JFrame) SwingUtilities.getRoot(TransfertStockPanel.this)).dispose();
175
            }
182 ilm 176
 
174 ilm 177
        });
178
    }
179
 
180 ilm 180
    private void updateButtons(final JButton buttonUpdate, final SQLRequestComboBox comboArticle, final SQLRequestComboBox comboStockDepart, final SQLRequestComboBox comboStockArrive,
181
            final NumericTextField fieldReel) {
182
        buttonUpdate.setEnabled(fieldReel.getText().trim().length() > 0 && comboArticle.getSelectedRow() != null && comboStockArrive.getSelectedRow() != null
183
                && comboStockDepart.getSelectedRow() != null && comboStockArrive.getSelectedRow().getID() != comboStockDepart.getSelectedRow().getID());
184
    }
182 ilm 185
 
174 ilm 186
}