OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 132 | 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
 *
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.product.element;
15
 
16
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
17
import org.openconcerto.sql.element.BaseSQLComponent;
18
import org.openconcerto.sql.element.SQLComponent;
19
import org.openconcerto.sql.model.SQLRow;
20
import org.openconcerto.sql.model.SQLRowValues;
21
import org.openconcerto.sql.sqlobject.ElementComboBox;
22
import org.openconcerto.ui.DefaultGridBagConstraints;
28 ilm 23
import org.openconcerto.ui.FormLayouter;
132 ilm 24
import org.openconcerto.utils.ListMap;
18 ilm 25
 
26
import java.awt.GridBagConstraints;
27
import java.awt.GridBagLayout;
28
import java.sql.SQLException;
29
import java.util.ArrayList;
30
import java.util.List;
31
 
32
import javax.swing.JLabel;
28 ilm 33
import javax.swing.JPanel;
18 ilm 34
import javax.swing.JTextField;
35
import javax.swing.SwingConstants;
36
 
37
public class FamilleArticleSQLElement extends ComptaSQLConfElement {
38
 
39
    public FamilleArticleSQLElement() {
40
        super("FAMILLE_ARTICLE", "une famille d'article", "familles d'articles");
41
    }
42
 
43
    protected List<String> getListFields() {
44
        final List<String> l = new ArrayList<String>();
45
        l.add("NOM");
46
        return l;
47
    }
48
 
49
    protected List<String> getComboFields() {
50
        final List<String> l = new ArrayList<String>();
51
        l.add("NOM");
52
        return l;
53
    }
54
 
83 ilm 55
    @Override
132 ilm 56
    public ListMap<String, String> getShowAs() {
57
        final ListMap<String, String> res = new ListMap<String, String>();
58
        res.putCollection(null, "NOM");
83 ilm 59
        return res;
60
    }
61
 
18 ilm 62
    /*
63
     * (non-Javadoc)
64
     *
65
     * @see org.openconcerto.devis.SQLElement#getComponent()
66
     */
67
    public SQLComponent createComponent() {
68
        return new BaseSQLComponent(this) {
69
            public void addViews() {
70
                this.setLayout(new GridBagLayout());
71
                final GridBagConstraints c = new DefaultGridBagConstraints();
72
 
73
                // Nom
74
                final JLabel labelNom = new JLabel(getLabelFor("NOM"), SwingConstants.RIGHT);
75
                c.gridx = 0;
76
                c.weightx = 0;
77
                this.add(labelNom, c);
78
 
79
                final JTextField textNom = new JTextField(15);
80
                c.gridx++;
81
                c.weightx = 1;
82
                DefaultGridBagConstraints.lockMinimumSize(textNom);
83
                this.add(textNom, c);
84
                this.addRequiredSQLObject(textNom, "NOM");
85
 
86
                // Famille père
87
                final JLabel labelFamille = new JLabel(getLabelFor("ID_FAMILLE_ARTICLE_PERE"), SwingConstants.RIGHT);
88
                c.gridx = 0;
89
                c.gridy++;
90
                c.weightx = 0;
91
                this.add(labelFamille, c);
92
 
93
                final ElementComboBox familleBox = new ElementComboBox(true, 25);
94
                DefaultGridBagConstraints.lockMinimumSize(familleBox);
95
                c.gridx++;
96
                c.weightx = 1;
97
                this.add(familleBox, c);
98
 
99
                this.addSQLObject(familleBox, "ID_FAMILLE_ARTICLE_PERE");
28 ilm 100
 
67 ilm 101
                // Compte associée
102
                final JLabel labelCompte = new JLabel(getLabelFor("ID_COMPTE_PCE"), SwingConstants.RIGHT);
103
                c.gridx = 0;
104
                c.gridy++;
105
                c.weightx = 0;
106
                this.add(labelCompte, c);
107
                final ElementComboBox compteBox = new ElementComboBox(true, 25);
108
                DefaultGridBagConstraints.lockMinimumSize(compteBox);
109
                c.gridx++;
110
                c.weightx = 1;
111
                this.add(compteBox, c);
112
 
113
                this.addSQLObject(compteBox, "ID_COMPTE_PCE");
114
 
115
                // Compte associée
116
                final JLabel labelCompteAchat = new JLabel(getLabelFor("ID_COMPTE_PCE_ACHAT"), SwingConstants.RIGHT);
117
                c.gridx = 0;
118
                c.gridy++;
119
                c.weightx = 0;
120
                this.add(labelCompteAchat, c);
121
                final ElementComboBox compteBoxAchat = new ElementComboBox(true, 25);
122
                DefaultGridBagConstraints.lockMinimumSize(compteBoxAchat);
123
                c.gridx++;
124
                c.weightx = 1;
125
                this.add(compteBoxAchat, c);
126
 
127
                this.addSQLObject(compteBoxAchat, "ID_COMPTE_PCE_ACHAT");
128
 
28 ilm 129
                // Champ Module
130
                c.gridx = 0;
131
                c.gridy++;
132
                c.gridwidth = GridBagConstraints.REMAINDER;
63 ilm 133
                final JPanel addP = ComptaSQLConfElement.createAdditionalPanel();
28 ilm 134
 
135
                this.setAdditionalFieldsPanel(new FormLayouter(addP, 2));
136
                c.fill = GridBagConstraints.HORIZONTAL;
137
                c.weightx = 1;
138
                this.add(addP, c);
139
 
18 ilm 140
            }
141
 
142
            @Override
143
            public void update() {
144
                // TODO Auto-generated method stub
145
                super.update();
146
 
147
                SQLRow row = this.getTable().getRow(getSelectedID());
148
                int idPere = row.getInt("ID_FAMILLE_ARTICLE_PERE");
149
 
150
                // Création du code de famille --> permet de faciliter le filtre de recherche
151
                StringBuffer code = new StringBuffer();
152
                if (idPere > 1) {
153
                    SQLRow rowPere = this.getTable().getRow(idPere);
154
                    code.append(rowPere.getString("CODE"));
155
                } else {
156
                    code.append('1');
157
                }
158
                code.append("." + getSelectedID());
159
 
160
                SQLRowValues rowVals = new SQLRowValues(this.getTable());
161
                rowVals.put("CODE", code.toString());
162
 
163
                try {
164
                    rowVals.update(getSelectedID());
165
                } catch (SQLException e) {
166
                    e.printStackTrace();
167
                }
168
 
169
            }
170
 
171
            @Override
172
            public int insert(SQLRow order) {
173
 
174
                int id = super.insert(order);
175
                SQLRow row = this.getTable().getRow(id);
176
                int idPere = row.getInt("ID_FAMILLE_ARTICLE_PERE");
177
 
178
                // Création du code de famille --> permet de faciliter le filtre de recherche
179
                StringBuffer code = new StringBuffer();
180
                if (idPere > 1) {
181
                    SQLRow rowPere = this.getTable().getRow(idPere);
182
                    code.append(rowPere.getString("CODE"));
183
                } else {
184
                    code.append('1');
185
                }
186
                code.append("." + id);
187
 
188
                SQLRowValues rowVals = new SQLRowValues(this.getTable());
189
                rowVals.put("CODE", code.toString());
190
 
191
                try {
192
                    rowVals.update(id);
193
                } catch (SQLException e) {
194
                    e.printStackTrace();
195
                }
196
 
197
                return id;
198
            }
199
        };
200
    }
201
 
57 ilm 202
    @Override
203
    protected String createCode() {
156 ilm 204
        return createCodeOfPackage() + ".family";
57 ilm 205
    }
18 ilm 206
}