18 |
ilm |
1 |
/*
|
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
|
|
3 |
*
|
|
|
4 |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
|
|
|
5 |
*
|
|
|
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
|
|
|
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.
|
|
|
10 |
*
|
|
|
11 |
* When distributing the software, include this License Header Notice in each file.
|
|
|
12 |
*/
|
|
|
13 |
|
|
|
14 |
package org.openconcerto.erp.core.sales.pos.ui;
|
|
|
15 |
|
|
|
16 |
import org.openconcerto.erp.core.finance.payment.element.TypeReglementSQLElement;
|
61 |
ilm |
17 |
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
|
132 |
ilm |
18 |
import org.openconcerto.erp.core.sales.pos.POSConfiguration;
|
18 |
ilm |
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;
|
144 |
ilm |
22 |
import org.openconcerto.erp.core.sales.pos.model.ReceiptCode;
|
18 |
ilm |
23 |
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.model.SQLRow;
|
|
|
27 |
import org.openconcerto.ui.DefaultGridBagConstraints;
|
90 |
ilm |
28 |
import org.openconcerto.utils.DecimalUtils;
|
18 |
ilm |
29 |
|
|
|
30 |
import java.awt.GridBagConstraints;
|
|
|
31 |
import java.awt.GridBagLayout;
|
|
|
32 |
import java.awt.event.ActionEvent;
|
|
|
33 |
import java.awt.event.ActionListener;
|
67 |
ilm |
34 |
import java.math.BigDecimal;
|
144 |
ilm |
35 |
import java.text.ParseException;
|
18 |
ilm |
36 |
import java.util.List;
|
|
|
37 |
|
|
|
38 |
import javax.swing.JButton;
|
|
|
39 |
import javax.swing.JPanel;
|
|
|
40 |
import javax.swing.JSeparator;
|
|
|
41 |
|
|
|
42 |
public class TextAreaTicketPanel extends JPanel {
|
|
|
43 |
|
156 |
ilm |
44 |
public TextAreaTicketPanel(final POSConfiguration conf, SQLRow row) {
|
18 |
ilm |
45 |
super(new GridBagLayout());
|
|
|
46 |
GridBagConstraints c = new DefaultGridBagConstraints();
|
|
|
47 |
c.fill = GridBagConstraints.BOTH;
|
|
|
48 |
c.weightx = 0;
|
|
|
49 |
c.weighty = 0;
|
|
|
50 |
|
|
|
51 |
final Ticket ticket = createTicket(row);
|
|
|
52 |
|
|
|
53 |
JButton button = new JButton("Imprimer");
|
|
|
54 |
button.addActionListener(new ActionListener() {
|
|
|
55 |
@Override
|
|
|
56 |
public void actionPerformed(ActionEvent e) {
|
156 |
ilm |
57 |
conf.print(ticket);
|
18 |
ilm |
58 |
}
|
|
|
59 |
});
|
|
|
60 |
|
|
|
61 |
c.fill = GridBagConstraints.NONE;
|
|
|
62 |
c.anchor = GridBagConstraints.CENTER;
|
|
|
63 |
this.add(button, c);
|
|
|
64 |
|
|
|
65 |
c.anchor = GridBagConstraints.WEST;
|
|
|
66 |
c.fill = GridBagConstraints.HORIZONTAL;
|
|
|
67 |
JSeparator sep = new JSeparator();
|
|
|
68 |
c.gridy++;
|
|
|
69 |
c.weightx = 1;
|
|
|
70 |
this.add(sep, c);
|
|
|
71 |
final TextAreaTicketPrinter comp = new TextAreaTicketPrinter();
|
|
|
72 |
c.gridy++;
|
|
|
73 |
c.weighty = 1;
|
|
|
74 |
this.add(comp, c);
|
|
|
75 |
|
156 |
ilm |
76 |
ticket.print(comp, conf.getTicketPrinterConfiguration1().getTicketWidth());
|
18 |
ilm |
77 |
}
|
|
|
78 |
|
|
|
79 |
private Ticket createTicket(SQLRow row) {
|
144 |
ilm |
80 |
final Ticket t;
|
|
|
81 |
try {
|
|
|
82 |
t = new Ticket(new ReceiptCode(row.getString("NUMERO")), row.getDate("DATE"), row.getString("FILE_HASH_PREVIOUS"));
|
|
|
83 |
} catch (ParseException e) {
|
|
|
84 |
throw new IllegalStateException("Couldn't parse " + row, e);
|
|
|
85 |
}
|
18 |
ilm |
86 |
|
|
|
87 |
SQLElement eltEncaisser = Configuration.getInstance().getDirectory().getElement("ENCAISSER_MONTANT");
|
|
|
88 |
List<SQLRow> l = row.getReferentRows(eltEncaisser.getTable());
|
|
|
89 |
for (SQLRow row2 : l) {
|
|
|
90 |
long montant = row2.getLong("MONTANT");
|
|
|
91 |
SQLRow rowMode = row2.getForeign("ID_MODE_REGLEMENT");
|
|
|
92 |
int type = Paiement.CB;
|
|
|
93 |
if (rowMode.getInt("ID_TYPE_REGLEMENT") == TypeReglementSQLElement.CB) {
|
|
|
94 |
type = Paiement.CB;
|
|
|
95 |
} else {
|
|
|
96 |
if (rowMode.getInt("ID_TYPE_REGLEMENT") == TypeReglementSQLElement.CHEQUE) {
|
|
|
97 |
type = Paiement.CHEQUE;
|
|
|
98 |
} else {
|
|
|
99 |
if (rowMode.getInt("ID_TYPE_REGLEMENT") == TypeReglementSQLElement.ESPECE) {
|
|
|
100 |
type = Paiement.ESPECES;
|
|
|
101 |
}
|
|
|
102 |
}
|
|
|
103 |
}
|
|
|
104 |
Paiement p = new Paiement(type);
|
|
|
105 |
p.setMontantInCents((int) montant);
|
|
|
106 |
t.addPaiement(p);
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
SQLElement eltArticle = Configuration.getInstance().getDirectory().getElement("SAISIE_VENTE_FACTURE_ELEMENT");
|
|
|
110 |
List<SQLRow> l2 = row.getReferentRows(eltArticle.getTable());
|
|
|
111 |
Categorie c = new Categorie("");
|
|
|
112 |
for (SQLRow row2 : l2) {
|
61 |
ilm |
113 |
Article a = new Article(c, row2.getString("NOM"), row2.getInt("ID_ARTICLE"));
|
67 |
ilm |
114 |
BigDecimal ht = (BigDecimal) row2.getObject("PV_HT");
|
132 |
ilm |
115 |
a.setPriceWithoutTax(ht);
|
67 |
ilm |
116 |
int idTaxe = row2.getInt("ID_TAXE");
|
|
|
117 |
float tva = TaxeCache.getCache().getTauxFromId(idTaxe);
|
132 |
ilm |
118 |
a.setPriceWithTax(ht.multiply(new BigDecimal(1.0 + (tva / 100.0D)), DecimalUtils.HIGH_PRECISION));
|
67 |
ilm |
119 |
a.setIdTaxe(idTaxe);
|
18 |
ilm |
120 |
t.addArticle(a);
|
|
|
121 |
t.setArticleCount(a, row2.getInt("QTE"));
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
return t;
|
|
|
125 |
}
|
|
|
126 |
}
|