OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 156 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 156 Rev 174
Line 21... Line 21...
21
import org.openconcerto.erp.core.sales.pos.model.Paiement;
21
import org.openconcerto.erp.core.sales.pos.model.Paiement;
22
import org.openconcerto.erp.core.sales.pos.model.ReceiptCode;
22
import org.openconcerto.erp.core.sales.pos.model.ReceiptCode;
23
import org.openconcerto.erp.core.sales.pos.model.Ticket;
23
import org.openconcerto.erp.core.sales.pos.model.Ticket;
24
import org.openconcerto.sql.Configuration;
24
import org.openconcerto.sql.Configuration;
25
import org.openconcerto.sql.element.SQLElement;
25
import org.openconcerto.sql.element.SQLElement;
-
 
26
import org.openconcerto.sql.element.SQLElementDirectory;
26
import org.openconcerto.sql.model.SQLRow;
27
import org.openconcerto.sql.model.SQLRow;
-
 
28
import org.openconcerto.sql.model.SQLRowListRSH;
-
 
29
import org.openconcerto.sql.model.SQLSelect;
27
import org.openconcerto.ui.DefaultGridBagConstraints;
30
import org.openconcerto.ui.DefaultGridBagConstraints;
28
import org.openconcerto.utils.DecimalUtils;
31
import org.openconcerto.utils.DecimalUtils;
29
 
32
 
30
import java.awt.GridBagConstraints;
33
import java.awt.GridBagConstraints;
31
import java.awt.GridBagLayout;
34
import java.awt.GridBagLayout;
32
import java.awt.event.ActionEvent;
35
import java.awt.event.ActionEvent;
33
import java.awt.event.ActionListener;
36
import java.awt.event.ActionListener;
34
import java.math.BigDecimal;
37
import java.math.BigDecimal;
35
import java.text.ParseException;
38
import java.text.ParseException;
-
 
39
import java.util.HashMap;
36
import java.util.List;
40
import java.util.List;
-
 
41
import java.util.Map;
37
 
42
 
38
import javax.swing.JButton;
43
import javax.swing.JButton;
39
import javax.swing.JPanel;
44
import javax.swing.JPanel;
40
import javax.swing.JSeparator;
45
import javax.swing.JSeparator;
41
 
46
 
Line 75... Line 80...
75
 
80
 
76
        ticket.print(comp, conf.getTicketPrinterConfiguration1().getTicketWidth());
81
        ticket.print(comp, conf.getTicketPrinterConfiguration1().getTicketWidth());
77
    }
82
    }
78
 
83
 
79
    private Ticket createTicket(SQLRow row) {
84
    private Ticket createTicket(SQLRow row) {
-
 
85
        // TODO merger ce code avec CaissepPanel.loadArticles si possible
80
        final Ticket t;
86
        final Ticket t;
81
        try {
87
        try {
82
            t = new Ticket(new ReceiptCode(row.getString("NUMERO")), row.getDate("DATE"), row.getString("FILE_HASH_PREVIOUS"));
88
            t = new Ticket(new ReceiptCode(row.getString("NUMERO")), row.getDate("DATE"), row.getString("FILE_HASH_PREVIOUS"));
83
        } catch (ParseException e) {
89
        } catch (ParseException e) {
84
            throw new IllegalStateException("Couldn't parse " + row, e);
90
            throw new IllegalStateException("Couldn't parse " + row, e);
85
        }
91
        }
86
 
92
 
-
 
93
        final SQLElementDirectory directory = Configuration.getInstance().getDirectory();
87
        SQLElement eltEncaisser = Configuration.getInstance().getDirectory().getElement("ENCAISSER_MONTANT");
94
        SQLElement eltEncaisser = directory.getElement("ENCAISSER_MONTANT");
88
        List<SQLRow> l = row.getReferentRows(eltEncaisser.getTable());
95
        List<SQLRow> l = row.getReferentRows(eltEncaisser.getTable());
89
        for (SQLRow row2 : l) {
96
        for (SQLRow row2 : l) {
90
            long montant = row2.getLong("MONTANT");
97
            long montant = row2.getLong("MONTANT");
91
            SQLRow rowMode = row2.getForeign("ID_MODE_REGLEMENT");
98
            SQLRow rowMode = row2.getForeign("ID_MODE_REGLEMENT");
92
            int type = Paiement.CB;
99
            int type = Paiement.CB;
Line 104... Line 111...
104
            Paiement p = new Paiement(type);
111
            Paiement p = new Paiement(type);
105
            p.setMontantInCents((int) montant);
112
            p.setMontantInCents((int) montant);
106
            t.addPaiement(p);
113
            t.addPaiement(p);
107
        }
114
        }
108
 
115
 
109
        SQLElement eltArticle = Configuration.getInstance().getDirectory().getElement("SAISIE_VENTE_FACTURE_ELEMENT");
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
 
110
        List<SQLRow> l2 = row.getReferentRows(eltArticle.getTable());
125
        List<SQLRow> l2 = row.getReferentRows(eltArticle.getTable());
111
        Categorie c = new Categorie("");
126
        Categorie c = new Categorie("");
112
        for (SQLRow row2 : l2) {
127
        for (SQLRow row2 : l2) {
113
            Article a = new Article(c, row2.getString("NOM"), row2.getInt("ID_ARTICLE"));
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
            }
114
            BigDecimal ht = (BigDecimal) row2.getObject("PV_HT");
132
            BigDecimal ht = (BigDecimal) row2.getObject("PV_HT");
115
            a.setPriceWithoutTax(ht);
133
            a.setPriceWithoutTax(ht);
116
            int idTaxe = row2.getInt("ID_TAXE");
134
            int idTaxe = row2.getInt("ID_TAXE");
117
            float tva = TaxeCache.getCache().getTauxFromId(idTaxe);
135
            float tva = TaxeCache.getCache().getTauxFromId(idTaxe);
118
            a.setPriceWithTax(ht.multiply(new BigDecimal(1.0 + (tva / 100.0D)), DecimalUtils.HIGH_PRECISION));
136
            a.setPriceWithTax(ht.multiply(BigDecimal.valueOf(1.0 + (tva / 100.0D)), DecimalUtils.HIGH_PRECISION));
119
            a.setIdTaxe(idTaxe);
137
            a.setIdTaxe(idTaxe);
120
            t.addArticle(a);
138
            t.addArticle(a);
-
 
139
            if (a.getSalesUnit() == null) {
121
            t.setArticleCount(a, row2.getInt("QTE"));
140
                t.setArticleCount(a, new BigDecimal(row2.getInt("QTE")));
-
 
141
            } else {
-
 
142
                t.setArticleCount(a, row2.getBigDecimal("QTE_UNITAIRE"));
-
 
143
            }
122
        }
144
        }
123
 
145
 
124
        return t;
146
        return t;
125
    }
147
    }
126
}
148
}