OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev Author Line No. Line
41 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.supplychain.supplier.component;
15
 
16
import org.openconcerto.erp.core.supplychain.stock.element.MouvementStockSQLElement;
17
import org.openconcerto.sql.element.BaseSQLComponent;
18
import org.openconcerto.sql.element.SQLElement;
19
import org.openconcerto.sql.model.SQLRow;
94 ilm 20
import org.openconcerto.sql.model.SQLRowValues;
156 ilm 21
import org.openconcerto.sql.model.Where;
41 ilm 22
import org.openconcerto.sql.sqlobject.ElementComboBox;
156 ilm 23
import org.openconcerto.sql.sqlobject.SQLRequestComboBox;
41 ilm 24
import org.openconcerto.sql.sqlobject.SQLTextCombo;
25
import org.openconcerto.ui.DefaultGridBagConstraints;
26
import org.openconcerto.ui.JDate;
27
 
28
import java.awt.GridBagConstraints;
29
import java.awt.GridBagLayout;
156 ilm 30
import java.beans.PropertyChangeEvent;
31
import java.beans.PropertyChangeListener;
32
import java.sql.SQLException;
41 ilm 33
import java.util.Arrays;
144 ilm 34
import java.util.HashSet;
35
import java.util.Set;
41 ilm 36
 
93 ilm 37
import javax.swing.JCheckBox;
41 ilm 38
import javax.swing.JLabel;
39
import javax.swing.JPanel;
40
import javax.swing.JTextField;
41
import javax.swing.SwingConstants;
42
 
43
public class MouvementStockSQLComponent extends BaseSQLComponent {
44
 
45
    public MouvementStockSQLComponent(SQLElement element) {
46
        super(element);
47
    }
48
 
144 ilm 49
    @Override
50
    public Set<String> getPartialResetNames() {
156 ilm 51
        Set<String> s = new HashSet<>(2);
144 ilm 52
        s.add("QTE");
53
        s.add("ID_ARTICLE");
54
        return s;
55
    }
56
 
41 ilm 57
    public void addViews() {
58
        this.setLayout(new GridBagLayout());
59
        final GridBagConstraints c = new DefaultGridBagConstraints();
60
 
61
        // Libellé
156 ilm 62
        final JLabel labelLib = new JLabel(getLabelFor("NOM"), SwingConstants.RIGHT);
41 ilm 63
        this.add(labelLib, c);
64
 
65
        c.gridx++;
66
        c.weightx = 1;
156 ilm 67
        final SQLTextCombo textLib = new SQLTextCombo();
68
        this.add(textLib, c);
41 ilm 69
 
70
        // Date
71
        c.gridx++;
72
        c.weightx = 0;
73
        JLabel labelDate = new JLabel(getLabelFor("DATE"), SwingConstants.RIGHT);
74
        this.add(labelDate, c);
75
 
76
        c.gridx++;
156 ilm 77
        final JDate date = new JDate(true);
78
        this.add(date, c);
41 ilm 79
 
80
        // Article
81
        final ElementComboBox articleSelect = new ElementComboBox();
82
 
83
        c.gridx = 0;
84
        c.gridy++;
156 ilm 85
        final JLabel labelArticle = new JLabel(getLabelFor("ID_ARTICLE"), SwingConstants.RIGHT);
41 ilm 86
        this.add(labelArticle, c);
87
 
88
        c.gridx++;
89
        c.gridwidth = GridBagConstraints.REMAINDER;
90
        c.weightx = 1;
91
        this.add(articleSelect, c);
92
 
156 ilm 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
 
41 ilm 107
        // QTE
108
        c.gridwidth = 1;
109
        c.weightx = 0;
110
        c.gridy++;
111
        c.gridx = 0;
112
        c.anchor = GridBagConstraints.EAST;
156 ilm 113
        final JLabel labelQte = new JLabel(getLabelFor("QTE"), SwingConstants.RIGHT);
41 ilm 114
        this.add(labelQte, c);
115
 
116
        c.gridx++;
117
        c.fill = GridBagConstraints.NONE;
156 ilm 118
        final JTextField textQte = new JTextField(6);
41 ilm 119
        c.weighty = 0;
120
        c.anchor = GridBagConstraints.NORTHWEST;
156 ilm 121
        this.add(textQte, c);
93 ilm 122
 
123
        c.gridx++;
156 ilm 124
        final JCheckBox boxReel = new JCheckBox(getLabelFor("REEL"));
93 ilm 125
        this.add(boxReel, c);
126
        addView(boxReel, "REEL");
127
 
41 ilm 128
        c.gridy++;
129
        c.weighty = 1;
130
        final JPanel comp = new JPanel();
131
        comp.setOpaque(false);
132
        this.add(comp, c);
156 ilm 133
        DefaultGridBagConstraints.lockMinimumSize(textQte);
134
        DefaultGridBagConstraints.lockMaximumSize(textQte);
135
        this.addRequiredSQLObject(textQte, "QTE");
136
        this.addSQLObject(textLib, "NOM");
41 ilm 137
        this.addRequiredSQLObject(articleSelect, "ID_ARTICLE");
156 ilm 138
        this.addRequiredSQLObject(articleStock, "ID_STOCK");
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
 
41 ilm 150
    }
151
 
152
    @Override
94 ilm 153
    protected SQLRowValues createDefaults() {
154
        SQLRowValues rowVals = new SQLRowValues(getTable());
155
        rowVals.put("REEL", Boolean.TRUE);
156
        return rowVals;
157
    }
158
 
159
    @Override
41 ilm 160
    public int insert(SQLRow order) {
161
        int id = super.insert(order);
156 ilm 162
        try {
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
        }
41 ilm 167
        return id;
168
    }
169
 
170
    @Override
171
    public void update() {
172
        int id = getSelectedID();
156 ilm 173
        try {
174
            ((MouvementStockSQLElement) getElement()).updateStock(Arrays.asList(getTable().getRow(id)), true);
175
            super.update();
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
        }
41 ilm 180
    }
181
 
182
}