OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 174 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 40... Line 40...
40
    private final POSRadioButton rDiscountPercent;
40
    private final POSRadioButton rDiscountPercent;
41
    private final POSRadioButton rDiscount;
41
    private final POSRadioButton rDiscount;
42
    private final NumericTextField htTextField;
42
    private final NumericTextField htTextField;
43
    private final NumericTextField ttcTextField;
43
    private final NumericTextField ttcTextField;
44
    private final NumericTextField discountPercentTextField;
44
    private final NumericTextField discountPercentTextField;
-
 
45
    // Remise HT
45
    private final NumericTextField discountTextField;
46
    private final NumericTextField discountTextField;
46
    private final NumericKeypadPanel keyPad;
47
    private final NumericKeypadPanel keyPad;
47
 
48
 
48
    public PriceEditorPanel(final CaisseFrame caisseFrame, final TicketItem item) {
49
    public PriceEditorPanel(final CaisseFrame caisseFrame, final TicketItem item) {
49
        this.item = item;
50
        this.item = item;
Line 69... Line 70...
69
        this.rTTC.setSelected(true);
70
        this.rTTC.setSelected(true);
70
        c.weightx = 0;
71
        c.weightx = 0;
71
        this.add(this.rTTC, c);
72
        this.add(this.rTTC, c);
72
        this.ttcTextField = new NumericTextField();
73
        this.ttcTextField = new NumericTextField();
73
        this.ttcTextField.setFont(title.getFont());
74
        this.ttcTextField.setFont(title.getFont());
74
        this.ttcTextField.setValue(item.getArticle().getPriceWithTax());
75
        this.ttcTextField.setValue(item.getArticle().getPriceWithTax(BigDecimal.ONE, false));
75
        this.ttcTextField.requestFocusInWindow();
76
        this.ttcTextField.requestFocusInWindow();
76
        c.gridx++;
77
        c.gridx++;
77
        c.weightx = 1;
78
        c.weightx = 1;
78
        this.add(this.ttcTextField, c);
79
        this.add(this.ttcTextField, c);
79
        // Line 3
80
        // Line 3
Line 81... Line 82...
81
        this.rHT = new POSRadioButton("prix HT");
82
        this.rHT = new POSRadioButton("prix HT");
82
        c.gridx = 0;
83
        c.gridx = 0;
83
        c.weightx = 0;
84
        c.weightx = 0;
84
        this.add(this.rHT, c);
85
        this.add(this.rHT, c);
85
        this.htTextField = new NumericTextField();
86
        this.htTextField = new NumericTextField();
86
        this.htTextField.setValue(item.getArticle().getPriceWithoutTax());
87
        this.htTextField.setValue(item.getArticle().getPriceWithoutTax(BigDecimal.ONE));
87
        this.htTextField.setFont(title.getFont());
88
        this.htTextField.setFont(title.getFont());
88
        c.gridx++;
89
        c.gridx++;
89
        c.weightx = 1;
90
        c.weightx = 1;
90
        this.add(this.htTextField, c);
91
        this.add(this.htTextField, c);
91
        // Line 4
92
        // Line 4
Line 122... Line 123...
122
        //
123
        //
123
        c.gridy++;
124
        c.gridy++;
124
        c.gridx = 0;
125
        c.gridx = 0;
125
        c.gridwidth = 2;
126
        c.gridwidth = 2;
126
        final POSLabel labelPriceOld = new POSLabel("Ancien Prix : ");
127
        final POSLabel labelPriceOld = new POSLabel("Ancien Prix : ");
127
        labelPriceOld.setText(
128
        labelPriceOld.setText("Ancien Prix : " + TicketCellRenderer.toString(item.getArticle().getPriceWithTax(BigDecimal.ONE)) + "€ TTC, "
128
                "Ancien Prix : " + TicketCellRenderer.toString(item.getArticle().getPriceWithTax()) + "€ TTC, " + TicketCellRenderer.toString(item.getArticle().getPriceWithoutTax()) + "€ HT");
129
                + TicketCellRenderer.toString(item.getArticle().getPriceWithoutTax(BigDecimal.ONE)) + "€ HT");
129
        this.add(labelPriceOld, c);
130
        this.add(labelPriceOld, c);
130
 
131
 
131
        c.gridy++;
132
        c.gridy++;
132
        c.gridx = 0;
133
        c.gridx = 0;
133
        this.labelPrice = new POSLabel("Nouveau Prix : ");
134
        this.labelPrice = new POSLabel("Nouveau Prix : ");
Line 146... Line 147...
146
        buttons.add(bApply, c);
147
        buttons.add(bApply, c);
147
        bApply.addActionListener(new ActionListener() {
148
        bApply.addActionListener(new ActionListener() {
148
 
149
 
149
            @Override
150
            @Override
150
            public void actionPerformed(ActionEvent e) {
151
            public void actionPerformed(ActionEvent e) {
-
 
152
                if (rHT.isSelected() || rTTC.isSelected()) {
151
                caisseFrame.getControler().setArticleHT(item, getHTFromUI());
153
                    caisseFrame.getControler().setArticleHT(item, getHTFromUI());
-
 
154
                } else if (rDiscountPercent.isSelected()) {
-
 
155
                    item.getArticle().setDiscountPct(discountPercentTextField.getValue().divide(new BigDecimal(100)));
-
 
156
                } else if (rDiscount.isSelected()) {
-
 
157
                    // Remise HT
-
 
158
                    final BigDecimal priceWithoutTax = item.getArticle().getPriceWithoutTax(BigDecimal.ONE, false);
-
 
159
                    BigDecimal pct = BigDecimal.ONE.subtract((priceWithoutTax.subtract(discountTextField.getValue())).divide(priceWithoutTax));
-
 
160
                    item.getArticle().setDiscountPct(pct);
-
 
161
                }
152
                caisseFrame.showCaisse();
162
                caisseFrame.showCaisse();
153
            }
163
            }
154
        });
164
        });
155
        bCancel.addActionListener(new ActionListener() {
165
        bCancel.addActionListener(new ActionListener() {
156
 
166
 
Line 171... Line 181...
171
        // Line 1
181
        // Line 1
172
        c.gridheight = 5;
182
        c.gridheight = 5;
173
        this.keyPad = new NumericKeypadPanel(this.ttcTextField);
183
        this.keyPad = new NumericKeypadPanel(this.ttcTextField);
174
        this.add(this.keyPad, c);
184
        this.add(this.keyPad, c);
175
 
185
 
176
        updatePrice(item.getArticle().getPriceWithoutTax());
186
        updatePrice(item.getArticle().getPriceWithoutTax(BigDecimal.ONE));
177
        updateTextFields();
187
        updateTextFields();
178
        //
188
        //
179
        final ActionListener listenerRadio = new ActionListener() {
189
        final ActionListener listenerRadio = new ActionListener() {
180
 
190
 
181
            @Override
191
            @Override
Line 228... Line 238...
228
            if (this.rHT.isSelected()) {
238
            if (this.rHT.isSelected()) {
229
                r = this.htTextField.getValue();
239
                r = this.htTextField.getValue();
230
            } else if (this.rTTC.isSelected()) {
240
            } else if (this.rTTC.isSelected()) {
231
                r = Article.computePriceWithoutTax(this.ttcTextField.getValue(), this.item.getArticle().getIdTaxe());
241
                r = Article.computePriceWithoutTax(this.ttcTextField.getValue(), this.item.getArticle().getIdTaxe());
232
            } else if (this.rDiscountPercent.isSelected()) {
242
            } else if (this.rDiscountPercent.isSelected()) {
-
 
243
                r = this.item.getArticle().getPriceWithoutTax(BigDecimal.ONE, false)
233
                r = this.item.getArticle().getPriceWithoutTax().subtract(this.item.getArticle().getPriceWithoutTax().multiply(this.discountPercentTextField.getValue().divide(new BigDecimal(100))));
244
                        .subtract(this.item.getArticle().getPriceWithoutTax(BigDecimal.ONE).multiply(this.discountPercentTextField.getValue().divide(new BigDecimal(100))));
234
            } else if (this.rDiscount.isSelected()) {
245
            } else if (this.rDiscount.isSelected()) {
235
                r = this.item.getArticle().getPriceWithoutTax().subtract(this.discountTextField.getValue());
246
                r = this.item.getArticle().getPriceWithoutTax(BigDecimal.ONE, false).subtract(this.discountTextField.getValue());
236
            }
247
            }
237
        } catch (Exception e) {
248
        } catch (Exception e) {
238
            e.printStackTrace();
249
            e.printStackTrace();
239
        }
250
        }
240
        if (r == null) {
251
        if (r == null) {
241
            // fallback if something wrong
252
            // fallback if something wrong
242
            r = this.item.getArticle().getPriceWithoutTax();
253
            r = this.item.getArticle().getPriceWithoutTax(BigDecimal.ONE);
243
        }
254
        }
244
        return r;
255
        return r;
245
    }
256
    }
246
 
257
 
247
    private void updatePrice(BigDecimal ht) {
258
    private void updatePrice(BigDecimal ht) {