OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 151 Rev 174
Line 13... Line 13...
13
 
13
 
14
 package org.openconcerto.erp.core.sales.pos.ui;
14
 package org.openconcerto.erp.core.sales.pos.ui;
15
 
15
 
16
import org.openconcerto.erp.core.common.ui.NumericTextField;
16
import org.openconcerto.erp.core.common.ui.NumericTextField;
17
import org.openconcerto.erp.core.sales.pos.model.Article;
17
import org.openconcerto.erp.core.sales.pos.model.Article;
-
 
18
import org.openconcerto.erp.core.sales.pos.model.TicketItem;
18
 
19
 
19
import java.awt.Color;
20
import java.awt.Color;
20
import java.awt.GridBagConstraints;
21
import java.awt.GridBagConstraints;
21
import java.awt.GridBagLayout;
22
import java.awt.GridBagLayout;
22
import java.awt.GridLayout;
23
import java.awt.GridLayout;
Line 30... Line 31...
30
import javax.swing.SwingUtilities;
31
import javax.swing.SwingUtilities;
31
import javax.swing.event.DocumentEvent;
32
import javax.swing.event.DocumentEvent;
32
import javax.swing.event.DocumentListener;
33
import javax.swing.event.DocumentListener;
33
 
34
 
34
public class PriceEditorPanel extends JPanel {
35
public class PriceEditorPanel extends JPanel {
35
    private final transient Article article;
36
    private final transient TicketItem item;
36
    private final POSLabel labelPrice;
37
    private final POSLabel labelPrice;
37
    private final POSRadioButton rHT;
38
    private final POSRadioButton rHT;
38
    private final POSRadioButton rTTC;
39
    private final POSRadioButton rTTC;
39
    private final POSRadioButton rDiscountPercent;
40
    private final POSRadioButton rDiscountPercent;
40
    private final POSRadioButton rDiscount;
41
    private final POSRadioButton rDiscount;
Line 42... Line 43...
42
    private final NumericTextField ttcTextField;
43
    private final NumericTextField ttcTextField;
43
    private final NumericTextField discountPercentTextField;
44
    private final NumericTextField discountPercentTextField;
44
    private final NumericTextField discountTextField;
45
    private final NumericTextField discountTextField;
45
    private final NumericKeypadPanel keyPad;
46
    private final NumericKeypadPanel keyPad;
46
 
47
 
47
    public PriceEditorPanel(final CaisseFrame caisseFrame, final Article article) {
48
    public PriceEditorPanel(final CaisseFrame caisseFrame, final TicketItem item) {
48
        this.article = article;
49
        this.item = item;
49
        this.setBackground(Color.WHITE);
50
        this.setBackground(Color.WHITE);
50
        this.setOpaque(true);
51
        this.setOpaque(true);
51
        this.setLayout(new GridBagLayout());
52
        this.setLayout(new GridBagLayout());
52
        final GridBagConstraints c = new GridBagConstraints();
53
        final GridBagConstraints c = new GridBagConstraints();
53
        c.fill = GridBagConstraints.HORIZONTAL;
54
        c.fill = GridBagConstraints.HORIZONTAL;
Line 62... Line 63...
62
        POSLabel title = new POSLabel("Modification du prix de vente");
63
        POSLabel title = new POSLabel("Modification du prix de vente");
63
        this.add(title, c);
64
        this.add(title, c);
64
        // Line 2
65
        // Line 2
65
        c.gridy++;
66
        c.gridy++;
66
        c.gridwidth = 1;
67
        c.gridwidth = 1;
67
        rTTC = new POSRadioButton("prix TTC");
68
        this.rTTC = new POSRadioButton("prix TTC");
68
        rTTC.setSelected(true);
69
        this.rTTC.setSelected(true);
69
        c.weightx = 0;
70
        c.weightx = 0;
70
        this.add(rTTC, c);
71
        this.add(this.rTTC, c);
71
        ttcTextField = new NumericTextField();
72
        this.ttcTextField = new NumericTextField();
72
        ttcTextField.setFont(title.getFont());
73
        this.ttcTextField.setFont(title.getFont());
73
        ttcTextField.setValue(article.getPriceWithTax());
74
        this.ttcTextField.setValue(item.getArticle().getPriceWithTax());
74
        ttcTextField.requestFocusInWindow();
75
        this.ttcTextField.requestFocusInWindow();
75
        c.gridx++;
76
        c.gridx++;
76
        c.weightx = 1;
77
        c.weightx = 1;
77
        this.add(ttcTextField, c);
78
        this.add(this.ttcTextField, c);
78
        // Line 3
79
        // Line 3
79
        c.gridy++;
80
        c.gridy++;
80
        rHT = new POSRadioButton("prix HT");
81
        this.rHT = new POSRadioButton("prix HT");
81
        c.gridx = 0;
82
        c.gridx = 0;
82
        c.weightx = 0;
83
        c.weightx = 0;
83
        this.add(rHT, c);
84
        this.add(this.rHT, c);
84
        htTextField = new NumericTextField();
85
        this.htTextField = new NumericTextField();
85
        htTextField.setValue(article.getPriceWithoutTax());
86
        this.htTextField.setValue(item.getArticle().getPriceWithoutTax());
86
        htTextField.setFont(title.getFont());
87
        this.htTextField.setFont(title.getFont());
87
        c.gridx++;
88
        c.gridx++;
88
        c.weightx = 1;
89
        c.weightx = 1;
89
        this.add(htTextField, c);
90
        this.add(this.htTextField, c);
90
        // Line 4
91
        // Line 4
91
        c.gridy++;
92
        c.gridy++;
92
        rDiscountPercent = new POSRadioButton("remise en %");
93
        this.rDiscountPercent = new POSRadioButton("remise en %");
93
        c.gridx = 0;
94
        c.gridx = 0;
94
        c.weightx = 0;
95
        c.weightx = 0;
95
        this.add(rDiscountPercent, c);
96
        this.add(this.rDiscountPercent, c);
96
        discountPercentTextField = new NumericTextField();
97
        this.discountPercentTextField = new NumericTextField();
97
        discountPercentTextField.setValue(BigDecimal.ZERO);
98
        this.discountPercentTextField.setValue(BigDecimal.ZERO);
98
        discountPercentTextField.setFont(title.getFont());
99
        this.discountPercentTextField.setFont(title.getFont());
99
        c.gridx++;
100
        c.gridx++;
100
        c.weightx = 1;
101
        c.weightx = 1;
101
        this.add(discountPercentTextField, c);
102
        this.add(this.discountPercentTextField, c);
102
        // Line 5
103
        // Line 5
103
        rDiscount = new POSRadioButton("remise HT");
104
        this.rDiscount = new POSRadioButton("remise HT");
104
        c.gridx = 0;
105
        c.gridx = 0;
105
        c.weightx = 0;
106
        c.weightx = 0;
106
        c.gridy++;
107
        c.gridy++;
107
        this.add(rDiscount, c);
108
        this.add(this.rDiscount, c);
108
        discountTextField = new NumericTextField();
109
        this.discountTextField = new NumericTextField();
109
        discountTextField.setValue(BigDecimal.ZERO);
110
        this.discountTextField.setValue(BigDecimal.ZERO);
110
        discountTextField.setFont(title.getFont());
111
        this.discountTextField.setFont(title.getFont());
111
        c.gridx++;
112
        c.gridx++;
112
        c.weightx = 1;
113
        c.weightx = 1;
113
        this.add(discountTextField, c);
114
        this.add(this.discountTextField, c);
114
 
115
 
115
        final ButtonGroup group = new ButtonGroup();
116
        final ButtonGroup group = new ButtonGroup();
116
        group.add(rHT);
117
        group.add(this.rHT);
117
        group.add(rTTC);
118
        group.add(this.rTTC);
118
        group.add(rDiscountPercent);
119
        group.add(this.rDiscountPercent);
119
        group.add(rDiscount);
120
        group.add(this.rDiscount);
120
        //
121
        //
121
        //
122
        //
122
        c.gridy++;
123
        c.gridy++;
123
        c.gridx = 0;
124
        c.gridx = 0;
124
        c.gridwidth = 2;
125
        c.gridwidth = 2;
125
        final POSLabel labelPriceOld = new POSLabel("Ancien Prix : ");
126
        final POSLabel labelPriceOld = new POSLabel("Ancien Prix : ");
-
 
127
        labelPriceOld.setText(
126
        labelPriceOld.setText("Ancien Prix : " + TicketCellRenderer.toString(article.getPriceWithTax()) + "€ TTC, " + TicketCellRenderer.toString(article.getPriceWithoutTax()) + "€ HT");
128
                "Ancien Prix : " + TicketCellRenderer.toString(item.getArticle().getPriceWithTax()) + "€ TTC, " + TicketCellRenderer.toString(item.getArticle().getPriceWithoutTax()) + "€ HT");
127
        this.add(labelPriceOld, c);
129
        this.add(labelPriceOld, c);
128
 
130
 
129
        c.gridy++;
131
        c.gridy++;
130
        c.gridx = 0;
132
        c.gridx = 0;
131
        labelPrice = new POSLabel("Nouveau Prix : ");
133
        this.labelPrice = new POSLabel("Nouveau Prix : ");
132
        this.add(labelPrice, c);
134
        this.add(this.labelPrice, c);
133
 
135
 
134
        c.gridy++;
136
        c.gridy++;
135
        c.gridx = 0;
137
        c.gridx = 0;
136
        c.fill = GridBagConstraints.NONE;
138
        c.fill = GridBagConstraints.NONE;
137
        c.anchor = GridBagConstraints.SOUTHEAST;
139
        c.anchor = GridBagConstraints.SOUTHEAST;
Line 144... Line 146...
144
        buttons.add(bApply, c);
146
        buttons.add(bApply, c);
145
        bApply.addActionListener(new ActionListener() {
147
        bApply.addActionListener(new ActionListener() {
146
 
148
 
147
            @Override
149
            @Override
148
            public void actionPerformed(ActionEvent e) {
150
            public void actionPerformed(ActionEvent e) {
149
                caisseFrame.getControler().setArticleHT(article, getHTFromUI());
151
                caisseFrame.getControler().setArticleHT(item, getHTFromUI());
150
                caisseFrame.showCaisse();
152
                caisseFrame.showCaisse();
151
            }
153
            }
152
        });
154
        });
153
        bCancel.addActionListener(new ActionListener() {
155
        bCancel.addActionListener(new ActionListener() {
154
 
156
 
Line 166... Line 168...
166
        c.gridx = 3;
168
        c.gridx = 3;
167
        c.gridy = 2;
169
        c.gridy = 2;
168
        c.insets = new Insets(20, 20, 30, 20);
170
        c.insets = new Insets(20, 20, 30, 20);
169
        // Line 1
171
        // Line 1
170
        c.gridheight = 5;
172
        c.gridheight = 5;
171
        keyPad = new NumericKeypadPanel(ttcTextField);
173
        this.keyPad = new NumericKeypadPanel(this.ttcTextField);
172
        this.add(keyPad, c);
174
        this.add(this.keyPad, c);
173
 
175
 
174
        updatePrice(article.getPriceWithoutTax());
176
        updatePrice(item.getArticle().getPriceWithoutTax());
175
        updateTextFields();
177
        updateTextFields();
176
        //
178
        //
177
        final ActionListener listenerRadio = new ActionListener() {
179
        final ActionListener listenerRadio = new ActionListener() {
178
 
180
 
179
            @Override
181
            @Override
Line 224... Line 226...
224
        BigDecimal r = null;
226
        BigDecimal r = null;
225
        try {
227
        try {
226
            if (this.rHT.isSelected()) {
228
            if (this.rHT.isSelected()) {
227
                r = this.htTextField.getValue();
229
                r = this.htTextField.getValue();
228
            } else if (this.rTTC.isSelected()) {
230
            } else if (this.rTTC.isSelected()) {
229
                r = Article.computePriceWithoutTax(this.ttcTextField.getValue(), this.article.getIdTaxe());
231
                r = Article.computePriceWithoutTax(this.ttcTextField.getValue(), this.item.getArticle().getIdTaxe());
230
            } else if (this.rDiscountPercent.isSelected()) {
232
            } else if (this.rDiscountPercent.isSelected()) {
231
                r = this.article.getPriceWithoutTax().subtract(this.article.getPriceWithoutTax().multiply(this.discountPercentTextField.getValue().divide(new BigDecimal(100))));
233
                r = this.item.getArticle().getPriceWithoutTax().subtract(this.item.getArticle().getPriceWithoutTax().multiply(this.discountPercentTextField.getValue().divide(new BigDecimal(100))));
232
            } else if (this.rDiscount.isSelected()) {
234
            } else if (this.rDiscount.isSelected()) {
233
                r = this.article.getPriceWithoutTax().subtract(this.discountTextField.getValue());
235
                r = this.item.getArticle().getPriceWithoutTax().subtract(this.discountTextField.getValue());
234
            }
236
            }
235
        } catch (Exception e) {
237
        } catch (Exception e) {
236
            e.printStackTrace();
238
            e.printStackTrace();
237
        }
239
        }
238
        if (r == null) {
240
        if (r == null) {
239
            // fallback if something wrong
241
            // fallback if something wrong
240
            r = this.article.getPriceWithoutTax();
242
            r = this.item.getArticle().getPriceWithoutTax();
241
        }
243
        }
242
        return r;
244
        return r;
243
    }
245
    }
244
 
246
 
245
    private void updatePrice(BigDecimal ht) {
247
    private void updatePrice(BigDecimal ht) {
246
        BigDecimal ttc = Article.computePriceWithTax(ht, this.article.getIdTaxe());
248
        BigDecimal ttc = Article.computePriceWithTax(ht, this.item.getArticle().getIdTaxe());
247
        labelPrice.setText("Nouveau Prix : " + TicketCellRenderer.toString(ttc) + "€ TTC, " + TicketCellRenderer.toString(ht) + "€ HT");
249
        this.labelPrice.setText("Nouveau Prix : " + TicketCellRenderer.toString(ttc) + "€ TTC, " + TicketCellRenderer.toString(ht) + "€ HT");
248
    }
250
    }
249
 
251
 
250
    private void updateTextFields() {
252
    private void updateTextFields() {
251
        this.invalidate();
253
        this.invalidate();
252
        htTextField.setVisible(false);
254
        this.htTextField.setVisible(false);
253
        ttcTextField.setVisible(false);
255
        this.ttcTextField.setVisible(false);
254
        discountPercentTextField.setVisible(false);
256
        this.discountPercentTextField.setVisible(false);
255
        discountTextField.setVisible(false);
257
        this.discountTextField.setVisible(false);
256
        if (rHT.isSelected()) {
258
        if (this.rHT.isSelected()) {
257
            enableTextField(htTextField);
259
            enableTextField(this.htTextField);
258
        } else if (rTTC.isSelected()) {
260
        } else if (this.rTTC.isSelected()) {
259
            enableTextField(ttcTextField);
261
            enableTextField(this.ttcTextField);
260
        } else if (rDiscountPercent.isSelected()) {
262
        } else if (this.rDiscountPercent.isSelected()) {
261
            enableTextField(discountPercentTextField);
263
            enableTextField(this.discountPercentTextField);
262
        } else if (rDiscount.isSelected()) {
264
        } else if (this.rDiscount.isSelected()) {
263
            enableTextField(discountTextField);
265
            enableTextField(this.discountTextField);
264
        }
266
        }
265
        this.validate();
267
        this.validate();
266
        repaint();
268
        repaint();
267
    }
269
    }
268
 
270