OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 144 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 144 Rev 156
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 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.
10
 * 
10
 * 
11
 * When distributing the software, include this License Header Notice in each file.
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.erp.core.supplychain.supplier.component;
14
 package org.openconcerto.erp.core.supplychain.supplier.component;
15
 
15
 
16
import org.openconcerto.erp.core.supplychain.stock.element.MouvementStockSQLElement;
16
import org.openconcerto.erp.core.supplychain.stock.element.MouvementStockSQLElement;
17
import org.openconcerto.sql.element.BaseSQLComponent;
17
import org.openconcerto.sql.element.BaseSQLComponent;
18
import org.openconcerto.sql.element.SQLElement;
18
import org.openconcerto.sql.element.SQLElement;
19
import org.openconcerto.sql.model.SQLRow;
19
import org.openconcerto.sql.model.SQLRow;
20
import org.openconcerto.sql.model.SQLRowValues;
20
import org.openconcerto.sql.model.SQLRowValues;
-
 
21
import org.openconcerto.sql.model.Where;
21
import org.openconcerto.sql.sqlobject.ElementComboBox;
22
import org.openconcerto.sql.sqlobject.ElementComboBox;
-
 
23
import org.openconcerto.sql.sqlobject.SQLRequestComboBox;
22
import org.openconcerto.sql.sqlobject.SQLTextCombo;
24
import org.openconcerto.sql.sqlobject.SQLTextCombo;
23
import org.openconcerto.ui.DefaultGridBagConstraints;
25
import org.openconcerto.ui.DefaultGridBagConstraints;
24
import org.openconcerto.ui.JDate;
26
import org.openconcerto.ui.JDate;
25
 
27
 
26
import java.awt.GridBagConstraints;
28
import java.awt.GridBagConstraints;
27
import java.awt.GridBagLayout;
29
import java.awt.GridBagLayout;
-
 
30
import java.beans.PropertyChangeEvent;
-
 
31
import java.beans.PropertyChangeListener;
-
 
32
import java.sql.SQLException;
28
import java.util.Arrays;
33
import java.util.Arrays;
29
import java.util.HashSet;
34
import java.util.HashSet;
30
import java.util.Set;
35
import java.util.Set;
31
 
36
 
32
import javax.swing.JCheckBox;
37
import javax.swing.JCheckBox;
33
import javax.swing.JLabel;
38
import javax.swing.JLabel;
34
import javax.swing.JPanel;
39
import javax.swing.JPanel;
35
import javax.swing.JTextField;
40
import javax.swing.JTextField;
36
import javax.swing.SwingConstants;
41
import javax.swing.SwingConstants;
37
 
42
 
38
public class MouvementStockSQLComponent extends BaseSQLComponent {
43
public class MouvementStockSQLComponent extends BaseSQLComponent {
39
 
44
 
40
    private SQLTextCombo textLib;
-
 
41
    private JTextField textQte;
-
 
42
    private JDate date;
-
 
43
 
-
 
44
    public MouvementStockSQLComponent(SQLElement element) {
45
    public MouvementStockSQLComponent(SQLElement element) {
45
        super(element);
46
        super(element);
46
    }
47
    }
47
 
48
 
48
    @Override
49
    @Override
49
    public Set<String> getPartialResetNames() {
50
    public Set<String> getPartialResetNames() {
50
        Set<String> s = new HashSet<String>();
51
        Set<String> s = new HashSet<>(2);
51
        s.add("QTE");
52
        s.add("QTE");
52
        s.add("ID_ARTICLE");
53
        s.add("ID_ARTICLE");
53
        return s;
54
        return s;
54
    }
55
    }
55
 
56
 
56
    public void addViews() {
57
    public void addViews() {
57
        this.setLayout(new GridBagLayout());
58
        this.setLayout(new GridBagLayout());
58
        final GridBagConstraints c = new DefaultGridBagConstraints();
59
        final GridBagConstraints c = new DefaultGridBagConstraints();
59
 
60
 
60
        // Libellé
61
        // Libellé
61
        JLabel labelLib = new JLabel(getLabelFor("NOM"), SwingConstants.RIGHT);
62
        final JLabel labelLib = new JLabel(getLabelFor("NOM"), SwingConstants.RIGHT);
62
        this.add(labelLib, c);
63
        this.add(labelLib, c);
63
 
64
 
64
        c.gridx++;
65
        c.gridx++;
65
        c.weightx = 1;
66
        c.weightx = 1;
66
        this.textLib = new SQLTextCombo();
67
        final SQLTextCombo textLib = new SQLTextCombo();
67
        this.add(this.textLib, c);
68
        this.add(textLib, c);
68
 
69
 
69
        // Date
70
        // Date
70
        c.gridx++;
71
        c.gridx++;
71
        c.weightx = 0;
72
        c.weightx = 0;
72
        JLabel labelDate = new JLabel(getLabelFor("DATE"), SwingConstants.RIGHT);
73
        JLabel labelDate = new JLabel(getLabelFor("DATE"), SwingConstants.RIGHT);
73
        this.add(labelDate, c);
74
        this.add(labelDate, c);
74
 
75
 
75
        c.gridx++;
76
        c.gridx++;
76
        this.date = new JDate(true);
77
        final JDate date = new JDate(true);
77
        this.add(this.date, c);
78
        this.add(date, c);
78
 
79
 
79
        // Article
80
        // Article
80
        final ElementComboBox articleSelect = new ElementComboBox();
81
        final ElementComboBox articleSelect = new ElementComboBox();
81
 
82
 
82
        c.gridx = 0;
83
        c.gridx = 0;
83
        c.gridy++;
84
        c.gridy++;
84
        JLabel labelArticle = new JLabel(getLabelFor("ID_ARTICLE"), SwingConstants.RIGHT);
85
        final JLabel labelArticle = new JLabel(getLabelFor("ID_ARTICLE"), SwingConstants.RIGHT);
85
        this.add(labelArticle, c);
86
        this.add(labelArticle, c);
86
 
87
 
87
        c.gridx++;
88
        c.gridx++;
88
        c.gridwidth = GridBagConstraints.REMAINDER;
89
        c.gridwidth = GridBagConstraints.REMAINDER;
89
        c.weightx = 1;
90
        c.weightx = 1;
90
        this.add(articleSelect, c);
91
        this.add(articleSelect, c);
91
 
92
 
-
 
93
        // Article
-
 
94
        final SQLRequestComboBox articleStock = new SQLRequestComboBox();
-
 
95
        c.gridwidth = 1;
-
 
96
        c.weightx = 0;
-
 
97
        c.gridx = 0;
-
 
98
        c.gridy++;
-
 
99
        final JLabel labelStock = new JLabel(getLabelFor("ID_STOCK"), SwingConstants.RIGHT);
-
 
100
        this.add(labelStock, c);
-
 
101
 
-
 
102
        c.gridx++;
-
 
103
        c.gridwidth = GridBagConstraints.REMAINDER;
-
 
104
        c.weightx = 1;
-
 
105
        this.add(articleStock, c);
-
 
106
 
92
        // QTE
107
        // QTE
93
        c.gridwidth = 1;
108
        c.gridwidth = 1;
94
        c.weightx = 0;
109
        c.weightx = 0;
95
        c.gridy++;
110
        c.gridy++;
96
        c.gridx = 0;
111
        c.gridx = 0;
97
        c.anchor = GridBagConstraints.EAST;
112
        c.anchor = GridBagConstraints.EAST;
98
        JLabel labelQte = new JLabel(getLabelFor("QTE"), SwingConstants.RIGHT);
113
        final JLabel labelQte = new JLabel(getLabelFor("QTE"), SwingConstants.RIGHT);
99
        this.add(labelQte, c);
114
        this.add(labelQte, c);
100
 
115
 
101
        c.gridx++;
116
        c.gridx++;
102
        c.fill = GridBagConstraints.NONE;
117
        c.fill = GridBagConstraints.NONE;
103
        this.textQte = new JTextField(6);
118
        final JTextField textQte = new JTextField(6);
104
        c.weighty = 0;
119
        c.weighty = 0;
105
        c.anchor = GridBagConstraints.NORTHWEST;
120
        c.anchor = GridBagConstraints.NORTHWEST;
106
        this.add(this.textQte, c);
121
        this.add(textQte, c);
107
 
122
 
108
        c.gridx++;
123
        c.gridx++;
109
        JCheckBox boxReel = new JCheckBox(getLabelFor("REEL"));
124
        final JCheckBox boxReel = new JCheckBox(getLabelFor("REEL"));
110
        this.add(boxReel, c);
125
        this.add(boxReel, c);
111
        addView(boxReel, "REEL");
126
        addView(boxReel, "REEL");
112
 
127
 
113
        c.gridy++;
128
        c.gridy++;
114
        c.weighty = 1;
129
        c.weighty = 1;
115
        final JPanel comp = new JPanel();
130
        final JPanel comp = new JPanel();
116
        comp.setOpaque(false);
131
        comp.setOpaque(false);
117
        this.add(comp, c);
132
        this.add(comp, c);
118
        DefaultGridBagConstraints.lockMinimumSize(this.textQte);
133
        DefaultGridBagConstraints.lockMinimumSize(textQte);
119
        DefaultGridBagConstraints.lockMaximumSize(this.textQte);
134
        DefaultGridBagConstraints.lockMaximumSize(textQte);
120
        this.addRequiredSQLObject(this.textQte, "QTE");
135
        this.addRequiredSQLObject(textQte, "QTE");
121
        this.addSQLObject(this.textLib, "NOM");
136
        this.addSQLObject(textLib, "NOM");
122
        this.addRequiredSQLObject(articleSelect, "ID_ARTICLE");
137
        this.addRequiredSQLObject(articleSelect, "ID_ARTICLE");
-
 
138
        this.addRequiredSQLObject(articleStock, "ID_STOCK");
123
        this.addRequiredSQLObject(this.date, "DATE");
139
        this.addRequiredSQLObject(date, "DATE");
-
 
140
 
-
 
141
        articleStock.getRequest().setWhere(Where.FALSE);
-
 
142
        articleSelect.addModelListener("wantedID", new PropertyChangeListener() {
-
 
143
 
-
 
144
            @Override
-
 
145
            public void propertyChange(PropertyChangeEvent evt) {
-
 
146
                articleStock.getRequest().setWhere(new Where(articleStock.getRequest().getPrimaryTable().getField("ID_ARTICLE"), "=", articleSelect.getWantedID()));
-
 
147
            }
-
 
148
        });
-
 
149
 
124
    }
150
    }
125
 
151
 
126
    @Override
152
    @Override
127
    protected SQLRowValues createDefaults() {
153
    protected SQLRowValues createDefaults() {
128
        SQLRowValues rowVals = new SQLRowValues(getTable());
154
        SQLRowValues rowVals = new SQLRowValues(getTable());
129
        rowVals.put("REEL", Boolean.TRUE);
155
        rowVals.put("REEL", Boolean.TRUE);
130
        return rowVals;
156
        return rowVals;
131
    }
157
    }
132
 
158
 
133
    @Override
159
    @Override
134
    public int insert(SQLRow order) {
160
    public int insert(SQLRow order) {
135
        int id = super.insert(order);
161
        int id = super.insert(order);
-
 
162
        try {
136
        ((MouvementStockSQLElement) getElement()).updateStock(Arrays.asList(getTable().getRow(id)), false);
163
            ((MouvementStockSQLElement) getElement()).updateStock(Arrays.asList(getTable().getRow(id)), false);
-
 
164
        } catch (SQLException e) {
-
 
165
            throw new IllegalStateException("Impossible de metter à jour les stocks pour l'id " + id, e);
-
 
166
        }
137
        return id;
167
        return id;
138
    }
168
    }
139
 
169
 
140
    @Override
170
    @Override
141
    public void update() {
171
    public void update() {
142
        int id = getSelectedID();
172
        int id = getSelectedID();
-
 
173
        try {
143
        ((MouvementStockSQLElement) getElement()).updateStock(Arrays.asList(getTable().getRow(id)), true);
174
            ((MouvementStockSQLElement) getElement()).updateStock(Arrays.asList(getTable().getRow(id)), true);
144
        super.update();
175
            super.update();
145
        ((MouvementStockSQLElement) getElement()).updateStock(Arrays.asList(getTable().getRow(id)), false);
176
            ((MouvementStockSQLElement) getElement()).updateStock(Arrays.asList(getTable().getRow(id)), false);
-
 
177
        } catch (SQLException e) {
-
 
178
            throw new IllegalStateException("Impossible de metter à jour les stocks pour l'id " + id, e);
-
 
179
        }
146
    }
180
    }
147
 
181
 
148
}
182
}