OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 156 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 156 Rev 182
Line 1... Line 1...
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-2019 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.
Line 12... Line 12...
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.erp.core.sales.product.element;
14
 package org.openconcerto.erp.core.sales.product.element;
15
 
15
 
16
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
16
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
-
 
17
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
17
import org.openconcerto.sql.element.BaseSQLComponent;
18
import org.openconcerto.sql.element.BaseSQLComponent;
18
import org.openconcerto.sql.element.SQLComponent;
19
import org.openconcerto.sql.element.SQLComponent;
-
 
20
import org.openconcerto.sql.model.SQLRow;
-
 
21
import org.openconcerto.sql.model.SQLRowAccessor;
-
 
22
import org.openconcerto.sql.model.SQLRowValues;
-
 
23
import org.openconcerto.sql.sqlobject.SQLRequestComboBox;
19
import org.openconcerto.ui.DefaultGridBagConstraints;
24
import org.openconcerto.ui.DefaultGridBagConstraints;
-
 
25
import org.openconcerto.utils.DecimalUtils;
-
 
26
import org.openconcerto.utils.StringUtils;
20
 
27
 
21
import java.awt.GridBagConstraints;
28
import java.awt.GridBagConstraints;
22
import java.awt.GridBagLayout;
29
import java.awt.GridBagLayout;
-
 
30
import java.math.BigDecimal;
-
 
31
import java.math.RoundingMode;
23
import java.util.ArrayList;
32
import java.util.ArrayList;
-
 
33
import java.util.HashSet;
24
import java.util.List;
34
import java.util.List;
-
 
35
import java.util.Set;
25
 
36
 
26
import javax.swing.JLabel;
37
import javax.swing.JLabel;
27
import javax.swing.JTextField;
38
import javax.swing.JTextField;
-
 
39
import javax.swing.event.DocumentEvent;
28
 
40
 
29
public class ArticleTarifSQLElement extends ComptaSQLConfElement {
41
public class ArticleTarifSQLElement extends ComptaSQLConfElement {
30
 
42
 
31
    public ArticleTarifSQLElement() {
43
    public ArticleTarifSQLElement() {
32
        super("ARTICLE_TARIF", "un tarif d'article", "tarifs d'article");
44
        super("ARTICLE_TARIF", "un tarif d'article", "tarifs d'article");
33
    }
45
    }
34
 
46
 
35
    protected List<String> getListFields() {
47
    protected List<String> getListFields() {
36
        final List<String> l = new ArrayList<String>();
48
        final List<String> l = new ArrayList<String>();
-
 
49
        l.add("ID_TARIF");
-
 
50
        l.add("ID_ARTICLE");
-
 
51
        l.add("QTE");
-
 
52
        l.add("PV_HT");
37
        l.add("PV_TTC");
53
        l.add("PV_TTC");
38
        return l;
54
        return l;
39
    }
55
    }
40
 
56
 
41
    protected List<String> getComboFields() {
57
    protected List<String> getComboFields() {
42
        final List<String> l = new ArrayList<String>();
58
        final List<String> l = new ArrayList<String>();
-
 
59
        l.add("ID_TARIF");
-
 
60
        l.add("ID_ARTICLE");
43
        l.add("PV_TTC");
61
        l.add("PV_TTC");
44
        return l;
62
        return l;
45
    }
63
    }
46
 
64
 
47
    @Override
65
    @Override
48
    protected String getParentFFName() {
66
    protected String getParentFFName() {
49
        return "ID_ARTICLE";
67
        return "ID_ARTICLE";
50
    }
68
    }
51
 
69
 
-
 
70
    @Override
-
 
71
    public Set<String> getInsertOnlyFields() {
-
 
72
        Set<String> req = new HashSet<>();
-
 
73
        req.add("ID_TARIF");
-
 
74
        req.add("ID_ARTICLE");
-
 
75
        return req;
-
 
76
    }
-
 
77
 
-
 
78
    @Override
-
 
79
    public Set<String> getReadOnlyFields() {
-
 
80
        Set<String> ro = new HashSet<>();
-
 
81
        ro.add("PV_HT");
-
 
82
        ro.add("PV_TTC");
-
 
83
        return ro;
-
 
84
    }
-
 
85
 
52
    public SQLComponent createComponent() {
86
    public SQLComponent createComponent() {
53
        return new BaseSQLComponent(this) {
87
        return new BaseSQLComponent(this) {
54
 
88
 
55
            public void addViews() {
89
            public void addViews() {
56
                this.setLayout(new GridBagLayout());
90
                this.setLayout(new GridBagLayout());
57
                final GridBagConstraints c = new DefaultGridBagConstraints();
91
                final GridBagConstraints c = new DefaultGridBagConstraints();
58
 
92
 
-
 
93
                c.gridx = 0;
-
 
94
                c.weightx = 0;
59
                // Nom
95
                // Nom
60
                JLabel labelNom = new JLabel("PV_TTC");
96
                this.add(new JLabel(getLabelFor("ID_TARIF")), c);
-
 
97
                c.gridx++;
-
 
98
                c.weightx = 1;
-
 
99
                final SQLRequestComboBox tarifCombo = new SQLRequestComboBox();
-
 
100
                this.add(tarifCombo, c);
-
 
101
                this.addRequiredSQLObject(tarifCombo, "ID_TARIF");
-
 
102
 
-
 
103
                c.gridy++;
-
 
104
                c.gridx = 0;
-
 
105
                c.weightx = 0;
-
 
106
                this.add(new JLabel(getLabelFor("ID_ARTICLE")), c);
-
 
107
                c.gridx++;
-
 
108
                c.weightx = 1;
-
 
109
                final SQLRequestComboBox artCombo = new SQLRequestComboBox();
61
                JTextField textNom = new JTextField();
110
                this.add(artCombo, c);
-
 
111
                this.addRequiredSQLObject(artCombo, "ID_ARTICLE");
62
 
112
 
-
 
113
                c.gridy++;
-
 
114
                c.gridx = 0;
-
 
115
                c.weightx = 0;
-
 
116
                JLabel labelQTE = new JLabel(getLabelFor("QTE"));
-
 
117
                JTextField textQTE = new JTextField();
63
                this.add(labelNom, c);
118
                this.add(labelQTE, c);
64
                c.gridx++;
119
                c.gridx++;
-
 
120
                c.weightx = 1;
-
 
121
                this.add(textQTE, c);
-
 
122
                this.addRequiredSQLObject(textQTE, "QTE");
-
 
123
 
-
 
124
                c.gridy++;
-
 
125
                c.gridx = 0;
-
 
126
                c.weightx = 0;
-
 
127
                JLabel labelRemise = new JLabel(getLabelFor("POURCENT_REMISE"));
-
 
128
                JTextField textRemise = new JTextField();
-
 
129
                this.add(labelRemise, c);
-
 
130
                c.gridx++;
-
 
131
                c.weightx = 1;
-
 
132
                this.add(textRemise, c);
-
 
133
                this.addSQLObject(textRemise, "POURCENT_REMISE");
-
 
134
 
-
 
135
                c.gridy++;
-
 
136
                c.gridx = 0;
-
 
137
                c.weightx = 0;
-
 
138
                // Nom
-
 
139
                JLabel labelPVM = new JLabel(getLabelFor("PRIX_METRIQUE_VT_1"));
-
 
140
                JTextField textPVM = new JTextField();
-
 
141
                this.add(labelPVM, c);
-
 
142
                c.gridx++;
-
 
143
                c.weightx = 1;
-
 
144
                this.add(textPVM, c);
-
 
145
                this.addSQLObject(textPVM, "PRIX_METRIQUE_VT_1");
-
 
146
 
-
 
147
                c.gridy++;
-
 
148
                c.gridx = 0;
-
 
149
                c.weightx = 0;
-
 
150
                JLabel labelPV = new JLabel(getLabelFor("PV_HT"));
-
 
151
                final JTextField textPV = new JTextField();
-
 
152
                this.add(labelPV, c);
-
 
153
                c.gridx++;
-
 
154
                c.weightx = 1;
-
 
155
                this.add(textPV, c);
-
 
156
                this.addSQLObject(textPV, "PV_HT");
-
 
157
 
-
 
158
                c.gridy++;
-
 
159
                c.gridx = 0;
-
 
160
                c.weightx = 0;
-
 
161
                this.add(new JLabel(getLabelFor("ID_TAXE")), c);
-
 
162
                c.gridx++;
-
 
163
                c.weightx = 1;
-
 
164
                final SQLRequestComboBox taxeCombo = new SQLRequestComboBox();
-
 
165
                this.add(taxeCombo, c);
-
 
166
                this.addSQLObject(taxeCombo, "ID_TAXE");
-
 
167
 
-
 
168
                c.gridy++;
-
 
169
                c.gridx = 0;
-
 
170
                c.weightx = 0;
-
 
171
                // Nom
-
 
172
                JLabel labelPVTTC = new JLabel(getLabelFor("PV_TTC"));
-
 
173
                final JTextField textTTC = new JTextField();
-
 
174
                this.add(labelPVTTC, c);
-
 
175
                c.gridx++;
-
 
176
                c.weightx = 1;
65
                this.add(textNom, c);
177
                this.add(textTTC, c);
-
 
178
                this.addSQLObject(textTTC, "PV_TTC");
-
 
179
 
-
 
180
                textPVM.getDocument().addDocumentListener(new org.openconcerto.utils.text.SimpleDocumentListener() {
-
 
181
                    @Override
-
 
182
                    public void update(DocumentEvent e) {
-
 
183
 
-
 
184
                        final BigDecimal ht = StringUtils.getBigDecimalFromUserText(textPVM.getText());
66
 
185
 
-
 
186
                        if (ht != null) {
-
 
187
 
-
 
188
                            SQLRowAccessor rTaxe = taxeCombo.getSelectedRowAccessor();
-
 
189
                            if (rTaxe == null || rTaxe.isUndefined()) {
-
 
190
                                SQLRowAccessor a = artCombo.getSelectedRowAccessor();
-
 
191
                                if (a != null && !a.isUndefined()) {
-
 
192
                                    rTaxe = a.asRow().fetchNewRow().getForeignRow("ID_TAXE");
-
 
193
                                }
-
 
194
                                if (rTaxe == null || rTaxe.isUndefined()) {
-
 
195
                                    rTaxe = TaxeCache.getCache().getFirstTaxe();
-
 
196
                                }
-
 
197
                            }
-
 
198
 
-
 
199
                            Float resultTaux = TaxeCache.getCache().getTauxFromId(rTaxe.getID());
-
 
200
 
-
 
201
                            if (resultTaux == null) {
-
 
202
                                final SQLRow i = TaxeCache.getCache().getFirstTaxe();
-
 
203
                                resultTaux = i.getFloat("TAUX");
-
 
204
                            }
-
 
205
 
-
 
206
                            float taux = (resultTaux == null) ? 0.0F : resultTaux.floatValue();
-
 
207
 
-
 
208
                            BigDecimal r = ht.multiply(BigDecimal.valueOf(taux).divide(BigDecimal.valueOf(100)).add(BigDecimal.ONE), DecimalUtils.HIGH_PRECISION);
67
                this.addRequiredSQLObject(textNom, "PV_TTC");
209
                            textPV.setText(textPVM.getText());
-
 
210
                            textTTC.setText(r.setScale(2, RoundingMode.HALF_UP).toString());
-
 
211
                        } else {
-
 
212
                            textPV.setText("");
-
 
213
                            textTTC.setText("");
-
 
214
                        }
-
 
215
                    }
-
 
216
                });
68
 
217
 
69
            }
218
            }
70
        };
219
        };
71
    }
220
    }
72
 
221
 
73
    @Override
222
    @Override
-
 
223
    public SQLRowValues createDefaultRowValues(String token) {
-
 
224
 
-
 
225
        SQLRowValues rowVals = super.createDefaultRowValues(token);
-
 
226
        rowVals.put("QTE", 1);
-
 
227
        return rowVals;
-
 
228
    }
-
 
229
 
-
 
230
    @Override
74
    protected String createCode() {
231
    protected String createCode() {
75
        return createCodeOfPackage() + ".price";
232
        return createCodeOfPackage() + ".price";
76
    }
233
    }
77
}
234
}