OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 174 | Go to most recent revision | 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 14... Line 14...
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.sales.pos.model.Article;
16
import org.openconcerto.erp.core.sales.pos.model.Article;
17
import org.openconcerto.erp.core.sales.pos.model.TicketItem;
17
import org.openconcerto.erp.core.sales.pos.model.TicketItem;
18
import org.openconcerto.ui.touch.ScrollableList;
18
import org.openconcerto.ui.touch.ScrollableList;
-
 
19
import org.openconcerto.utils.QuickOrderedMap;
19
 
20
 
20
import java.awt.Color;
21
import java.awt.Color;
21
import java.awt.Component;
22
import java.awt.Component;
22
import java.awt.Font;
23
import java.awt.Font;
23
import java.awt.Graphics;
24
import java.awt.Graphics;
Line 56... Line 57...
56
        final JLabel l2 = new JLabel(article.getName().toUpperCase(), SwingConstants.LEFT);
57
        final JLabel l2 = new JLabel(article.getName().toUpperCase(), SwingConstants.LEFT);
57
        p.add(l2, c);
58
        p.add(l2, c);
58
        c.gridx++;
59
        c.gridx++;
59
        c.weightx = 0;
60
        c.weightx = 0;
60
 
61
 
61
        final BigDecimal priceWithTax = article.getPriceWithTax();
62
        final BigDecimal priceWithTax = article.getPriceWithTax(item.getQty());
62
        final JLabel l3 = new JLabel(toString(priceWithTax), SwingConstants.RIGHT);
63
        final JLabel l3 = new JLabel(toString(priceWithTax), SwingConstants.RIGHT);
63
        p.add(l3, c);
64
        p.add(l3, c);
64
 
65
 
65
        //
66
        //
66
        l1.setOpaque(false);
67
        l1.setOpaque(false);
Line 106... Line 107...
106
        final int width1 = (int) g.getFontMetrics().getStringBounds("1999kg ", g).getWidth() + inset * 2;
107
        final int width1 = (int) g.getFontMetrics().getStringBounds("1999kg ", g).getWidth() + inset * 2;
107
 
108
 
108
        String s2 = article.getName().toUpperCase().trim();
109
        String s2 = article.getName().toUpperCase().trim();
109
 
110
 
110
        final int maxLength = 15;
111
        final int maxLength = 15;
111
        if (s2.length() > maxLength)
112
        if (s2.length() > maxLength) {
112
            s2 = s2.substring(0, maxLength + 1) + '…';
113
            s2 = s2.substring(0, maxLength + 1) + '…';
-
 
114
        }
-
 
115
        QuickOrderedMap<String, String> decls = article.getDeclinaisons();
113
        g.drawString(s2, width1 + inset, height);
116
        String textDeclinaisons = null;
-
 
117
        if (decls != null && !decls.isEmpty()) {
-
 
118
            StringBuilder declinaisons = new StringBuilder();
-
 
119
            for (int i = 0; i < decls.size(); i++) {
-
 
120
                declinaisons.append(decls.getValue(i));
-
 
121
                declinaisons.append("  ");
-
 
122
            }
-
 
123
 
-
 
124
            textDeclinaisons = declinaisons.toString().trim();
-
 
125
 
-
 
126
        }
114
 
127
 
-
 
128
        g.drawString(s2, width1 + inset, height - 6);
-
 
129
 
115
        final String s3 = centsToString(article.getPriceWithTax().multiply(qty).movePointRight(2).setScale(0, RoundingMode.HALF_UP).intValue()) + "€";
130
        final String s3 = centsToString(article.getPriceWithTax(qty, true).multiply(qty).movePointRight(2).setScale(0, RoundingMode.HALF_UP).intValue()) + "€";
116
        final int width3 = (int) g.getFontMetrics().getStringBounds(s3, g).getWidth() + +inset;
131
        final int width3 = (int) g.getFontMetrics().getStringBounds(s3, g).getWidth() + +inset;
117
        g.drawString(s3, list.getWidth() - width3, height - 4);
132
        g.drawString(s3, list.getWidth() - width3, height - 4);
118
 
133
 
119
        g.setFont(g.getFont().deriveFont(12f));
134
        g.setFont(g.getFont().deriveFont(12f));
120
        final String s4 = qty.toPlainString() + " x " + centsToString(article.getPriceWithTax().movePointRight(2).setScale(0, RoundingMode.HALF_UP).intValue());
135
        final String s4 = qty.toPlainString() + " x " + centsToString(article.getPriceWithTax(qty).movePointRight(2).setScale(0, RoundingMode.HALF_UP).intValue());
121
 
136
 
122
        final int width4 = (int) g.getFontMetrics().getStringBounds(s4, g).getWidth() + +inset;
137
        final int width4 = (int) g.getFontMetrics().getStringBounds(s4, g).getWidth() + +inset;
123
        g.drawString(s4, list.getWidth() - width4, height + 11);
138
        g.drawString(s4, list.getWidth() - width4, height + 11);
-
 
139
        if (textDeclinaisons != null) {
-
 
140
            g.drawString(textDeclinaisons, width1 + inset, height + 11);
-
 
141
        }
-
 
142
 
-
 
143
        if (!article.getDiscountPct().equals(BigDecimal.ZERO)) {
-
 
144
            g.setFont(g.getFont().deriveFont(Font.ITALIC));
-
 
145
            g.drawString("Remise: " + article.getDiscountPct().movePointRight(2).setScale(2, BigDecimal.ROUND_HALF_UP) + " %", inset * 2 + 140, height + 12);
-
 
146
        }
124
 
147
 
125
    }
148
    }
126
 
149
 
127
    public static String centsToString(int cents) {
150
    public static String centsToString(int cents) {
128
        final int c = Math.abs(cents) % 100;
151
        final int c = Math.abs(cents) % 100;