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 11... Line 11...
11
 * When distributing the software, include this License Header Notice in each file.
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
12
 */
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.finance.payment.element.TypeReglementSQLElement;
-
 
17
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
-
 
18
import org.openconcerto.erp.core.sales.pos.POSConfiguration;
16
import org.openconcerto.erp.core.sales.pos.POSConfiguration;
19
import org.openconcerto.erp.core.sales.pos.model.Article;
-
 
20
import org.openconcerto.erp.core.sales.pos.model.Categorie;
-
 
21
import org.openconcerto.erp.core.sales.pos.model.Paiement;
17
import org.openconcerto.erp.core.sales.pos.element.TicketCaisseSQLElement;
22
import org.openconcerto.erp.core.sales.pos.model.ReceiptCode;
-
 
23
import org.openconcerto.erp.core.sales.pos.model.Ticket;
18
import org.openconcerto.erp.core.sales.pos.model.Ticket;
24
import org.openconcerto.sql.Configuration;
-
 
25
import org.openconcerto.sql.element.SQLElement;
-
 
26
import org.openconcerto.sql.element.SQLElementDirectory;
-
 
27
import org.openconcerto.sql.model.SQLRow;
19
import org.openconcerto.sql.model.SQLRow;
28
import org.openconcerto.sql.model.SQLRowListRSH;
-
 
29
import org.openconcerto.sql.model.SQLSelect;
-
 
30
import org.openconcerto.ui.DefaultGridBagConstraints;
20
import org.openconcerto.ui.DefaultGridBagConstraints;
31
import org.openconcerto.utils.DecimalUtils;
-
 
32
 
21
 
33
import java.awt.GridBagConstraints;
22
import java.awt.GridBagConstraints;
34
import java.awt.GridBagLayout;
23
import java.awt.GridBagLayout;
35
import java.awt.event.ActionEvent;
24
import java.awt.event.ActionEvent;
36
import java.awt.event.ActionListener;
25
import java.awt.event.ActionListener;
37
import java.math.BigDecimal;
-
 
38
import java.text.ParseException;
-
 
39
import java.util.HashMap;
-
 
40
import java.util.List;
-
 
41
import java.util.Map;
-
 
42
 
26
 
43
import javax.swing.JButton;
27
import javax.swing.JButton;
44
import javax.swing.JPanel;
28
import javax.swing.JPanel;
45
import javax.swing.JSeparator;
29
import javax.swing.JSeparator;
46
 
30
 
47
public class TextAreaTicketPanel extends JPanel {
31
public class TextAreaTicketPanel extends JPanel {
48
 
32
 
49
    public TextAreaTicketPanel(final POSConfiguration conf, SQLRow row) {
33
    public TextAreaTicketPanel(TicketCaisseSQLElement elt, final POSConfiguration conf, SQLRow row) {
50
        super(new GridBagLayout());
34
        super(new GridBagLayout());
51
        GridBagConstraints c = new DefaultGridBagConstraints();
35
        GridBagConstraints c = new DefaultGridBagConstraints();
52
        c.fill = GridBagConstraints.BOTH;
36
        c.fill = GridBagConstraints.BOTH;
53
        c.weightx = 0;
37
        c.weightx = 0;
54
        c.weighty = 0;
38
        c.weighty = 0;
55
 
39
 
56
        final Ticket ticket = createTicket(row);
40
        final Ticket ticket = elt.createTicket(row);
57
 
41
 
58
        JButton button = new JButton("Imprimer");
42
        JButton button = new JButton("Imprimer");
59
        button.addActionListener(new ActionListener() {
43
        button.addActionListener(new ActionListener() {
60
            @Override
44
            @Override
61
            public void actionPerformed(ActionEvent e) {
45
            public void actionPerformed(ActionEvent e) {
Line 79... Line 63...
79
        this.add(comp, c);
63
        this.add(comp, c);
80
 
64
 
81
        ticket.print(comp, conf.getTicketPrinterConfiguration1().getTicketWidth());
65
        ticket.print(comp, conf.getTicketPrinterConfiguration1().getTicketWidth());
82
    }
66
    }
83
 
67
 
84
    private Ticket createTicket(SQLRow row) {
-
 
85
        // TODO merger ce code avec CaissepPanel.loadArticles si possible
-
 
86
        final Ticket t;
-
 
87
        try {
-
 
88
            t = new Ticket(new ReceiptCode(row.getString("NUMERO")), row.getDate("DATE"), row.getString("FILE_HASH_PREVIOUS"));
-
 
89
        } catch (ParseException e) {
-
 
90
            throw new IllegalStateException("Couldn't parse " + row, e);
-
 
91
        }
-
 
92
 
-
 
93
        final SQLElementDirectory directory = Configuration.getInstance().getDirectory();
-
 
94
        SQLElement eltEncaisser = directory.getElement("ENCAISSER_MONTANT");
-
 
95
        List<SQLRow> l = row.getReferentRows(eltEncaisser.getTable());
-
 
96
        for (SQLRow row2 : l) {
-
 
97
            long montant = row2.getLong("MONTANT");
-
 
98
            SQLRow rowMode = row2.getForeign("ID_MODE_REGLEMENT");
-
 
99
            int type = Paiement.CB;
-
 
100
            if (rowMode.getInt("ID_TYPE_REGLEMENT") == TypeReglementSQLElement.CB) {
-
 
101
                type = Paiement.CB;
-
 
102
            } else {
-
 
103
                if (rowMode.getInt("ID_TYPE_REGLEMENT") == TypeReglementSQLElement.CHEQUE) {
-
 
104
                    type = Paiement.CHEQUE;
-
 
105
                } else {
-
 
106
                    if (rowMode.getInt("ID_TYPE_REGLEMENT") == TypeReglementSQLElement.ESPECE) {
-
 
107
                        type = Paiement.ESPECES;
-
 
108
                    }
-
 
109
                }
-
 
110
            }
-
 
111
            Paiement p = new Paiement(type);
-
 
112
            p.setMontantInCents((int) montant);
-
 
113
            t.addPaiement(p);
-
 
114
        }
-
 
115
 
-
 
116
        SQLElement eltArticle = directory.getElement("SAISIE_VENTE_FACTURE_ELEMENT");
-
 
117
 
-
 
118
        final SQLSelect selUniteVente = new SQLSelect();
-
 
119
        selUniteVente.addSelectStar(directory.getElement("UNITE_VENTE").getTable());
-
 
120
        final Map<Integer, String> mapUniteVenteName = new HashMap<>();
-
 
121
        for (SQLRow rowUniteVente : SQLRowListRSH.execute(selUniteVente)) {
-
 
122
            mapUniteVenteName.put(rowUniteVente.getID(), rowUniteVente.getString("CODE"));
-
 
123
        }
-
 
124
 
-
 
125
        List<SQLRow> l2 = row.getReferentRows(eltArticle.getTable());
-
 
126
        Categorie c = new Categorie("");
-
 
127
        for (SQLRow row2 : l2) {
-
 
128
            Article a = new Article(c, row2.getString("NOM"), row2.getInt("ID_ARTICLE"));
-
 
129
            if (row2.getInt("ID_UNITE_VENTE") != 2) {
-
 
130
                a.setSalesUnit(mapUniteVenteName.get(row2.getInt("ID_UNITE_VENTE")));
-
 
131
            }
-
 
132
            BigDecimal ht = (BigDecimal) row2.getObject("PV_HT");
-
 
133
            a.setPriceWithoutTax(ht);
-
 
134
            int idTaxe = row2.getInt("ID_TAXE");
-
 
135
            float tva = TaxeCache.getCache().getTauxFromId(idTaxe);
-
 
136
            a.setPriceWithTax(ht.multiply(BigDecimal.valueOf(1.0 + (tva / 100.0D)), DecimalUtils.HIGH_PRECISION));
-
 
137
            a.setIdTaxe(idTaxe);
-
 
138
            t.addArticle(a);
-
 
139
            if (a.getSalesUnit() == null) {
-
 
140
                t.setArticleCount(a, new BigDecimal(row2.getInt("QTE")));
-
 
141
            } else {
-
 
142
                t.setArticleCount(a, row2.getBigDecimal("QTE_UNITAIRE"));
-
 
143
            }
-
 
144
        }
-
 
145
 
-
 
146
        return t;
-
 
147
    }
-
 
148
}
68
}