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 22... Line 22...
22
import org.openconcerto.erp.core.sales.pos.POSConfiguration;
22
import org.openconcerto.erp.core.sales.pos.POSConfiguration;
23
import org.openconcerto.erp.core.sales.pos.io.DefaultTicketPrinter;
23
import org.openconcerto.erp.core.sales.pos.io.DefaultTicketPrinter;
24
import org.openconcerto.erp.core.sales.pos.io.Printable;
24
import org.openconcerto.erp.core.sales.pos.io.Printable;
25
import org.openconcerto.erp.core.sales.pos.io.TicketPrinter;
25
import org.openconcerto.erp.core.sales.pos.io.TicketPrinter;
26
import org.openconcerto.erp.core.sales.pos.model.RegisterFiles.HashMode;
26
import org.openconcerto.erp.core.sales.pos.model.RegisterFiles.HashMode;
-
 
27
import org.openconcerto.erp.core.sales.pos.ui.CaissePanel;
27
import org.openconcerto.erp.core.sales.pos.ui.TicketCellRenderer;
28
import org.openconcerto.erp.core.sales.pos.ui.TicketCellRenderer;
28
import org.openconcerto.erp.generationEcritures.GenerationEcritures;
29
import org.openconcerto.erp.generationEcritures.GenerationEcritures;
29
import org.openconcerto.erp.generationEcritures.GenerationMvtVirement;
30
import org.openconcerto.erp.generationEcritures.GenerationMvtVirement;
30
import org.openconcerto.erp.preferences.DefaultNXProps;
31
import org.openconcerto.erp.preferences.DefaultNXProps;
31
import org.openconcerto.sql.Configuration;
32
import org.openconcerto.sql.Configuration;
32
import org.openconcerto.sql.element.SQLElementDirectory;
33
import org.openconcerto.sql.element.SQLElementDirectory;
-
 
34
import org.openconcerto.sql.model.SQLBackgroundTableCache;
-
 
35
import org.openconcerto.sql.model.SQLBackgroundTableCacheItem;
33
import org.openconcerto.sql.model.SQLRow;
36
import org.openconcerto.sql.model.SQLRow;
34
import org.openconcerto.sql.model.SQLRowAccessor;
37
import org.openconcerto.sql.model.SQLRowAccessor;
35
import org.openconcerto.sql.model.SQLRowValues;
38
import org.openconcerto.sql.model.SQLRowValues;
36
import org.openconcerto.sql.model.SQLTable;
39
import org.openconcerto.sql.model.SQLTable;
37
import org.openconcerto.sql.utils.SQLUtils;
40
import org.openconcerto.sql.utils.SQLUtils;
38
import org.openconcerto.utils.DecimalUtils;
41
import org.openconcerto.utils.DecimalUtils;
39
import org.openconcerto.utils.Pair;
-
 
40
import org.openconcerto.utils.Tuple2;
42
import org.openconcerto.utils.Tuple2;
41
import org.openconcerto.utils.XMLDateFormat;
43
import org.openconcerto.utils.XMLDateFormat;
42
 
44
 
43
import java.io.File;
45
import java.io.File;
44
import java.io.IOException;
46
import java.io.IOException;
Line 64... Line 66...
64
public class Ticket implements Printable {
66
public class Ticket implements Printable {
65
 
67
 
66
    private static final XMLDateFormat DATE_FMT = new XMLDateFormat();
68
    private static final XMLDateFormat DATE_FMT = new XMLDateFormat();
67
 
69
 
68
    // Propre a ticket
70
    // Propre a ticket
69
    private final List<Paiement> paiements = new ArrayList<Paiement>();
71
    private final List<Paiement> paiements = new ArrayList<>();
70
    private final List<Pair<Article, Integer>> items = new ArrayList<Pair<Article, Integer>>();
72
    private final List<TicketItem> items = new ArrayList<>();
71
    private Calendar creationCal;
73
    private Calendar creationCal;
72
    private Client client = Client.NONE;
74
    private Client client = Client.NONE;
73
    private final int number;
75
    private final int number;
74
    private final String previousHash;
76
    private final String previousHash;
75
    private boolean additionnalCopyRequested = false;
77
    private boolean additionnalCopyRequested = false;
76
 
-
 
-
 
78
    private String codePostal = "";
77
    // Propre à la caisse
79
    // Propre à la caisse
78
    private final int caisseNumber;
80
    private final int caisseNumber;
79
 
81
 
80
    private static final SQLTable tableArticle = Configuration.getInstance().getRoot().findTable("ARTICLE");
82
    private static final SQLTable tableArticle = Configuration.getInstance().getRoot().findTable("ARTICLE");
81
 
83
 
Line 92... Line 94...
92
        } catch (final Exception e) {
94
        } catch (final Exception e) {
93
            return null;
95
            return null;
94
        }
96
        }
95
    }
97
    }
96
 
98
 
-
 
99
    public String getCodePostal() {
-
 
100
        return this.codePostal;
-
 
101
    }
-
 
102
 
-
 
103
    public void setCodePostal(String codePostal) {
-
 
104
        this.codePostal = codePostal;
-
 
105
 
-
 
106
    }
-
 
107
 
97
    public void setClient(final Client client) {
108
    public void setClient(final Client client) {
98
        this.client = client;
109
        this.client = client;
99
    }
110
    }
100
 
111
 
101
    public Client getClient() {
112
    public Client getClient() {
102
        return this.client;
113
        return this.client;
103
    }
114
    }
104
 
115
 
105
    public static Ticket parseFile(final File file) {
116
    public static Ticket parseFile(final File file) throws IOException {
106
        return parseFile(file, HashMode.REQUIRED);
117
        return parseFile(file, HashMode.REQUIRED);
107
    }
118
    }
108
 
119
 
109
    public static Ticket parseFile(final File file, final HashMode hashMode) {
120
    public static Ticket parseFile(final File file, final HashMode hashMode) throws IOException {
110
        if (!file.exists()) {
-
 
111
            return null;
-
 
112
        }
-
 
113
 
-
 
114
        try {
121
        try {
115
            // XML Reading
122
            // XML Reading
116
 
123
 
117
            final Document document = RegisterFiles.parse(file.toPath(), hashMode);
124
            final Document document = RegisterFiles.parse(file.toPath(), hashMode);
118
            final Element root = document.getRootElement();
125
            final Element root = document.getRootElement();
Line 129... Line 136...
129
            }
136
            }
130
            final String client = root.getAttributeValue("clientID", "1");
137
            final String client = root.getAttributeValue("clientID", "1");
131
            final Ticket t = new Ticket(receiptCode, c, root.getAttributeValue("previousHash"));
138
            final Ticket t = new Ticket(receiptCode, c, root.getAttributeValue("previousHash"));
132
            t.setClient(new Client(Integer.parseInt(client), "", BigDecimal.ZERO));
139
            t.setClient(new Client(Integer.parseInt(client), "", BigDecimal.ZERO));
133
 
140
 
-
 
141
            t.setCodePostal(root.getAttributeValue("codePostal", ""));
-
 
142
 
134
            // article
143
            // article
135
            final List<Element> children = root.getChildren("article");
144
            final List<Element> children = root.getChildren("article");
136
            for (final Element element : children) {
145
            for (final Element element : children) {
137
                final int qte = Integer.parseInt(element.getAttributeValue("qte"));
146
                final BigDecimal qte = new BigDecimal(element.getAttributeValue("qte"));
138
                final BigDecimal prix_unitaire_cents_ht = new BigDecimal(element.getAttributeValue("prixHT"));
147
                final BigDecimal prix_unitaire_cents_ht = new BigDecimal(element.getAttributeValue("prixHT"));
139
                final int idTaxe = Integer.parseInt(element.getAttributeValue("idTaxe"));
148
                final int idTaxe = Integer.parseInt(element.getAttributeValue("idTaxe"));
140
                final BigDecimal prix_unitaire_cents = new BigDecimal(element.getAttributeValue("prix"));
149
                final BigDecimal prix_unitaire_cents = new BigDecimal(element.getAttributeValue("prix"));
141
                final String categorie = element.getAttributeValue("categorie");
150
                final String categorie = element.getAttributeValue("categorie");
142
                final String name = element.getValue();
151
                final String name = element.getValue();
143
                final String codebarre = element.getAttributeValue("codebarre");
152
                final String codebarre = element.getAttributeValue("codebarre");
144
                final String codeArt = element.getAttributeValue("code");
153
                final String codeArt = element.getAttributeValue("code");
-
 
154
                final String salesUnit = element.getAttributeValue("unit");
145
                final Categorie cat = new Categorie(categorie);
155
                final Categorie cat = new Categorie(categorie);
146
 
156
 
147
                final String valueID = element.getAttributeValue("id");
157
                final String valueID = element.getAttributeValue("id");
148
 
158
 
149
                final int id = valueID == null || valueID.trim().length() == 0 ? tableArticle.getUndefinedID() : Integer.parseInt(valueID);
159
                final int id = valueID == null || valueID.trim().length() == 0 ? tableArticle.getUndefinedID() : Integer.parseInt(valueID);
Line 151... Line 161...
151
                art.setPriceWithTax(prix_unitaire_cents);
161
                art.setPriceWithTax(prix_unitaire_cents);
152
                art.setCode(codeArt);
162
                art.setCode(codeArt);
153
                art.setPriceWithoutTax(prix_unitaire_cents_ht);
163
                art.setPriceWithoutTax(prix_unitaire_cents_ht);
154
                art.setIdTaxe(idTaxe);
164
                art.setIdTaxe(idTaxe);
155
                art.setBarCode(codebarre);
165
                art.setBarCode(codebarre);
-
 
166
                art.setSalesUnit(salesUnit);
156
                final Pair<Article, Integer> line = new Pair<Article, Integer>(art, qte);
167
                final TicketItem line = new TicketItem(art, qte);
157
                t.items.add(line);
168
                t.items.add(line);
158
 
169
 
159
            }
170
            }
160
            // paiement
171
            // paiement
161
            final List<Element> payChildren = root.getChildren("paiement");
172
            final List<Element> payChildren = root.getChildren("paiement");
Line 179... Line 190...
179
                    t.paiements.add(p);
190
                    t.paiements.add(p);
180
                }
191
                }
181
            }
192
            }
182
 
193
 
183
            return t;
194
            return t;
184
        } catch (final Exception e) {
195
        } catch (IOException e) {
185
            System.err.println("Error with ticket : " + file + " : " + e.getMessage());
-
 
186
            e.printStackTrace();
196
            throw e;
187
            return null;
197
        } catch (Exception e) {
-
 
198
            throw new IOException("Couldn't parse " + file, e);
188
        }
199
        }
189
    }
200
    }
190
 
201
 
191
    // TODO receiptCode should be immutable and the day part should be the current accounting day
202
    // TODO receiptCode should be immutable and the day part should be the current accounting day
192
    // not the day of the present time. E.g. for work day beginning at 15:00, even at 3:00 the
203
    // not the day of the present time. E.g. for work day beginning at 15:00, even at 3:00 the
Line 209... Line 220...
209
 
220
 
210
    public final String getPreviousHash() {
221
    public final String getPreviousHash() {
211
        return this.previousHash;
222
        return this.previousHash;
212
    }
223
    }
213
 
224
 
-
 
225
    public void clear() {
-
 
226
        this.client = Client.NONE;
-
 
227
        this.codePostal = "";
-
 
228
        this.paiements.clear();
-
 
229
 
-
 
230
    }
-
 
231
 
214
    public final ReceiptCode getReceiptCode() {
232
    public final ReceiptCode getReceiptCode() {
215
        // TODO replace our fields by one ReceiptCode
233
        // TODO replace our fields by one ReceiptCode
216
        return new ReceiptCode(this.getCaisseNumber(), this.getCreationCal(), this.getNumber());
234
        return new ReceiptCode(this.getCaisseNumber(), this.getCreationCal(), this.getNumber());
217
    }
235
    }
218
 
236
 
Line 250... Line 268...
250
        topLevel.setAttribute(new Attribute("code", this.getCode()));
268
        topLevel.setAttribute(new Attribute("code", this.getCode()));
251
        if (this.getPreviousHash() != null)
269
        if (this.getPreviousHash() != null)
252
            topLevel.setAttribute("previousHash", this.getPreviousHash());
270
            topLevel.setAttribute("previousHash", this.getPreviousHash());
253
        topLevel.setAttribute("creationDate", DATE_FMT.format(c.getTime()));
271
        topLevel.setAttribute("creationDate", DATE_FMT.format(c.getTime()));
254
        topLevel.setAttribute("clientID", String.valueOf(this.client.getId()));
272
        topLevel.setAttribute("clientID", String.valueOf(this.client.getId()));
-
 
273
        topLevel.setAttribute("codePostal", this.codePostal);
255
        // Articles
274
        // Articles
256
        for (final Pair<Article, Integer> item : this.items) {
275
        for (final TicketItem item : this.items) {
257
            final Element e = new Element("article");
276
            final Element e = new Element("article");
258
            e.setAttribute("qte", String.valueOf(item.getSecond()));
277
            e.setAttribute("qte", String.valueOf(item.getQty()));
259
            // Prix unitaire
278
            // Prix unitaire
-
 
279
            final Article article = item.getArticle();
260
            e.setAttribute("prix", String.valueOf(item.getFirst().getPriceWithTax()));
280
            e.setAttribute("prix", String.valueOf(article.getPriceWithTax()));
261
            e.setAttribute("prixHT", String.valueOf(item.getFirst().getPriceWithoutTax()));
281
            e.setAttribute("prixHT", String.valueOf(article.getPriceWithoutTax()));
262
            e.setAttribute("idTaxe", String.valueOf(item.getFirst().getIdTaxe()));
282
            e.setAttribute("idTaxe", String.valueOf(article.getIdTaxe()));
263
            e.setAttribute("categorie", item.getFirst().getCategorie().getName());
283
            e.setAttribute("categorie", article.getCategorie().getName());
264
            e.setAttribute("codebarre", item.getFirst().getBarCode());
284
            e.setAttribute("codebarre", article.getBarCode());
265
            e.setAttribute("code", item.getFirst().getCode());
285
            e.setAttribute("code", article.getCode());
266
            e.setAttribute("id", String.valueOf(item.getFirst().getId()));
286
            e.setAttribute("id", String.valueOf(article.getId()));
-
 
287
            if (article.getSalesUnit() != null) {
-
 
288
                e.setAttribute("unit", article.getSalesUnit());
-
 
289
            }
267
            e.setText(item.getFirst().getName());
290
            e.setText(article.getName());
268
            topLevel.addContent(e);
291
            topLevel.addContent(e);
269
        }
292
        }
270
        // Paiements
293
        // Paiements
271
        for (final Paiement paiement : this.paiements) {
294
        for (final Paiement paiement : this.paiements) {
272
            final int montantInCents = paiement.getMontantInCents();
295
            final int montantInCents = paiement.getMontantInCents();
Line 358... Line 381...
358
        // Date
381
        // Date
359
        prt.addToBuffer("");
382
        prt.addToBuffer("");
360
        final SimpleDateFormat df = new SimpleDateFormat("EEEE d MMMM yyyy à HH:mm", Locale.FRENCH);
383
        final SimpleDateFormat df = new SimpleDateFormat("EEEE d MMMM yyyy à HH:mm", Locale.FRENCH);
361
        prt.addToBuffer(DefaultTicketPrinter.formatCenter(maxWidth, "Le " + df.format(getCreationDate())));
384
        prt.addToBuffer(DefaultTicketPrinter.formatCenter(maxWidth, "Le " + df.format(getCreationDate())));
362
        prt.addToBuffer("");
385
        prt.addToBuffer("");
363
        List<Pair<Article, Integer>> itemsToPrint = new ArrayList<>(this.items);
386
        List<TicketItem> itemsToPrint = new ArrayList<>(this.items);
364
        Collections.sort(itemsToPrint, new Comparator<Pair<Article, Integer>>() {
387
        Collections.sort(itemsToPrint, new Comparator<TicketItem>() {
365
 
388
 
366
            @Override
389
            @Override
367
            public int compare(Pair<Article, Integer> o1, Pair<Article, Integer> o2) {
390
            public int compare(TicketItem o1, TicketItem o2) {
368
                final Article p1 = o1.getFirst();
391
                final Article p1 = o1.getArticle();
369
                final Article p2 = o2.getFirst();
392
                final Article p2 = o2.getArticle();
370
                final Categorie c1 = p1.getCategorie();
393
                final Categorie c1 = p1.getCategorie();
371
                final Categorie c2 = p2.getCategorie();
394
                final Categorie c2 = p2.getCategorie();
372
                if (c1.equals(c2)) {
395
                if (c1.equals(c2)) {
373
                    return p1.getName().compareTo(p2.getName());
396
                    return p1.getName().compareTo(p2.getName());
374
                }
397
                }
Line 382... Line 405...
382
                // Sort by name
405
                // Sort by name
383
                return c1.getName().compareTo(c2.getName());
406
                return c1.getName().compareTo(c2.getName());
384
            }
407
            }
385
        });
408
        });
386
        Categorie currentCategorie = null;
409
        Categorie currentCategorie = null;
387
        for (final Pair<Article, Integer> item : this.items) {
410
        for (final TicketItem item : this.items) {
388
            final Article article = item.getFirst();
411
            final Article article = item.getArticle();
-
 
412
            System.err.println("Ticket.print()" + item);
389
            if (currentCategorie == null || !currentCategorie.getName().equals(article.getCategorie().getName())) {
413
            if (currentCategorie == null || !currentCategorie.getName().equals(article.getCategorie().getName())) {
390
                // Print category name, except for unknown
414
                // Print category name, except for unknown
391
                currentCategorie = article.getCategorie();
415
                currentCategorie = article.getCategorie();
392
                if (!currentCategorie.isUnknown()) {
416
                if (!currentCategorie.isUnknown()) {
393
                    prt.addToBuffer(currentCategorie.getName(), TicketPrinter.BOLD);
417
                    prt.addToBuffer(currentCategorie.getName(), TicketPrinter.BOLD);
394
                }
418
                }
395
            }
419
            }
396
            final Integer nb = item.getSecond();
420
            final BigDecimal nb = item.getQty();
397
            final Float tauxFromId = TaxeCache.getCache().getTauxFromId(article.getIdTaxe());
421
            final Float tauxFromId = TaxeCache.getCache().getTauxFromId(article.getIdTaxe());
398
            final BigDecimal tauxTVA = new BigDecimal(tauxFromId).movePointLeft(2).add(BigDecimal.ONE);
422
            final BigDecimal tauxTVA = BigDecimal.valueOf(tauxFromId).movePointLeft(2).add(BigDecimal.ONE);
399
            final BigDecimal unitPrice = article.getPriceWithoutTax().multiply(tauxTVA, DecimalUtils.HIGH_PRECISION);
423
            final BigDecimal unitPrice = article.getPriceWithoutTax().multiply(tauxTVA, DecimalUtils.HIGH_PRECISION);
400
            final BigDecimal multiply = article.getPriceWithoutTax().multiply(new BigDecimal(nb), DecimalUtils.HIGH_PRECISION).multiply(tauxTVA, DecimalUtils.HIGH_PRECISION);
424
            final BigDecimal multiply = article.getPriceWithoutTax().multiply(nb, DecimalUtils.HIGH_PRECISION).multiply(tauxTVA, DecimalUtils.HIGH_PRECISION);
401
 
425
 
402
            final String qtyString = DefaultTicketPrinter.formatRight(MAX_QTE_WIDTH, String.valueOf(nb));
426
            String qtyString = DefaultTicketPrinter.formatRight(MAX_QTE_WIDTH, String.valueOf(nb));
403
            final String priceString = DefaultTicketPrinter.formatRight(MAX_PRICE_WIDTH, TicketCellRenderer.centsToString(multiply.movePointRight(2).setScale(0, RoundingMode.HALF_UP).intValue()));
427
            final String priceUnformated = TicketCellRenderer.centsToString(multiply.movePointRight(2).setScale(0, RoundingMode.HALF_UP).intValue());
-
 
428
            final String priceString = DefaultTicketPrinter.formatRight(MAX_PRICE_WIDTH, priceUnformated);
404
            String unitPriceString = "";
429
            String unitPriceString = "";
-
 
430
            if (article.getSalesUnit() == null) {
405
            if (nb != 1) {
431
                if (nb.intValue() != 1) {
406
                unitPriceString = DefaultTicketPrinter.formatRight(MAX_PRICE_WIDTH, TicketCellRenderer.centsToString(unitPrice.movePointRight(2).setScale(0, RoundingMode.HALF_UP).intValue()));
432
                    unitPriceString = DefaultTicketPrinter.formatRight(MAX_PRICE_WIDTH, TicketCellRenderer.centsToString(unitPrice.movePointRight(2).setScale(0, RoundingMode.HALF_UP).intValue()));
407
            }
433
                }
-
 
434
            } else {
-
 
435
                unitPriceString = DefaultTicketPrinter.formatRight(MAX_PRICE_WIDTH, "");
-
 
436
                if (nb.signum() >= 0) {
-
 
437
                    qtyString = DefaultTicketPrinter.formatRight(MAX_QTE_WIDTH, "1");
-
 
438
                } else {
-
 
439
                    qtyString = DefaultTicketPrinter.formatRight(MAX_QTE_WIDTH, "-1");
-
 
440
                }
408
 
441
            }
409
            if (article.getCode() != null && !article.getCode().isEmpty()) {
442
            if (article.getCode() != null && !article.getCode().isEmpty() && !article.getCode().equalsIgnoreCase(article.getName())) {
410
                // 2 lines
443
                // 2 lines
411
                final String codeString = DefaultTicketPrinter.formatLeft(maxWidth - 2 - MAX_PRICE_WIDTH - MAX_QTE_WIDTH - 1 - unitPriceString.length(), article.getCode());
444
                final String codeString = DefaultTicketPrinter.formatLeft(maxWidth - 2 - MAX_PRICE_WIDTH - MAX_QTE_WIDTH - 1 - unitPriceString.length(), article.getCode());
412
                prt.addToBuffer(qtyString + " " + codeString + " " + unitPriceString + " " + priceString);
445
                prt.addToBuffer(qtyString + " " + codeString + " " + unitPriceString + " " + priceString);
413
                final String nameString = DefaultTicketPrinter.formatLeft(maxWidth - MAX_QTE_WIDTH - 1, article.getName());
446
                final String nameString = DefaultTicketPrinter.formatLeft(maxWidth - MAX_QTE_WIDTH - 1, article.getName());
414
                prt.addToBuffer("      " + nameString);
447
                prt.addToBuffer("      " + nameString);
415
            } else {
448
            } else {
416
                // 1 line
449
                // 1 line
417
                final String nameString = DefaultTicketPrinter.formatLeft(maxWidth - 2 - MAX_PRICE_WIDTH - MAX_QTE_WIDTH - 1 - unitPriceString.length(), article.getName());
450
                final String nameString = DefaultTicketPrinter.formatLeft(maxWidth - 2 - MAX_PRICE_WIDTH - MAX_QTE_WIDTH - 1 - unitPriceString.length(), article.getName());
418
                prt.addToBuffer(qtyString + " " + nameString + " " + unitPriceString + " " + priceString);
451
                prt.addToBuffer(qtyString + " " + nameString + " " + unitPriceString + " " + priceString);
419
            }
452
            }
-
 
453
            if (article.getSalesUnit() != null) {
-
 
454
                prt.addToBuffer(
-
 
455
                        "      (" + nb.abs() + " " + article.getSalesUnit() + " x " + TicketCellRenderer.centsToString(unitPrice.movePointRight(2).setScale(0, RoundingMode.HALF_UP).intValue()) + ")");
420
 
456
            }
421
        }
457
        }
422
 
458
 
423
        final StringBuilder spacer = new StringBuilder();
459
        final StringBuilder spacer = new StringBuilder();
424
        for (int i = 0; i <= MAX_QTE_WIDTH; i++) {
460
        for (int i = 0; i <= MAX_QTE_WIDTH; i++) {
425
            spacer.append(' ');
461
            spacer.append(' ');
Line 458... Line 494...
458
                    type = "Paiement ";
494
                    type = "Paiement ";
459
                } else {
495
                } else {
460
                    type = "Remboursement ";
496
                    type = "Remboursement ";
461
                }
497
                }
462
                if (paiement.getType() == Paiement.CB) {
498
                if (paiement.getType() == Paiement.CB) {
463
                    type = "CB";
499
                    type += "CB";
464
                } else if (paiement.getType() == Paiement.CHEQUE) {
500
                } else if (paiement.getType() == Paiement.CHEQUE) {
465
                    type = "par chèque";
501
                    type += "par chèque";
466
                } else if (paiement.getType() == Paiement.ESPECES) {
502
                } else if (paiement.getType() == Paiement.ESPECES) {
467
                    type = "en espèces";
503
                    type += "en espèces";
468
                } else if (paiement.getType() == Paiement.SOLDE) {
504
                } else if (paiement.getType() == Paiement.SOLDE) {
469
                    type = "depuis solde";
505
                    type += "depuis solde";
470
                }
506
                }
-
 
507
                if (montantInCents > 0) {
471
                type += " de " + TicketCellRenderer.centsToString(montantInCents);
508
                    type += " de " + TicketCellRenderer.centsToString(montantInCents);
-
 
509
                } else {
-
 
510
                    type += " de " + TicketCellRenderer.centsToString(-montantInCents);
-
 
511
                }
472
                if (montantInCents > 100) {
512
                if (Math.abs(montantInCents) > 100) {
473
                    type += " euros";
513
                    type += " euros";
474
                } else {
514
                } else {
475
                    type += " euro";
515
                    type += " euro";
476
                }
516
                }
477
                prt.addToBuffer(type);
517
                prt.addToBuffer(type);
Line 479... Line 519...
479
        }
519
        }
480
        // Montant Rendu
520
        // Montant Rendu
481
        if (getTotalInCents() < getPaidTotal()) {
521
        if (getTotalInCents() < getPaidTotal()) {
482
            final int montantInCents = getPaidTotal() - getTotalInCents();
522
            final int montantInCents = getPaidTotal() - getTotalInCents();
483
            String type = "Rendu : " + TicketCellRenderer.centsToString(montantInCents);
523
            String type = "Rendu : " + TicketCellRenderer.centsToString(montantInCents);
484
            if (montantInCents > 100) {
524
            if (Math.abs(montantInCents) > 100) {
485
                type += " euros";
525
                type += " euros";
486
            } else {
526
            } else {
487
                type += " euro";
527
                type += " euro";
488
            }
528
            }
489
            prt.addToBuffer(type);
529
            prt.addToBuffer(type);
Line 523... Line 563...
523
        this.paiements.add(p1);
563
        this.paiements.add(p1);
524
 
564
 
525
    }
565
    }
526
 
566
 
527
    public boolean isAdditionnalCopyRequested() {
567
    public boolean isAdditionnalCopyRequested() {
528
        return additionnalCopyRequested;
568
        return this.additionnalCopyRequested;
529
    }
569
    }
530
 
570
 
531
    public void addArticle(final Article a) {
571
    public void addArticle(final Article a) {
-
 
572
        System.err.println("Ticket.addArticle()" + a);
532
        boolean alreadyExist = false;
573
        boolean alreadyExist = false;
533
        if (a.isAdditionalCopyRequested()) {
574
        if (a.isAdditionalCopyRequested()) {
534
            this.additionnalCopyRequested = true;
575
            this.additionnalCopyRequested = true;
535
        }
576
        }
-
 
577
        if (a.getSalesUnit() == null) {
536
        for (final Pair<Article, Integer> line : this.items) {
578
            for (final TicketItem line : this.items) {
537
            if (line.getFirst().equals(a)) {
579
                if (line.getArticle().equals(a)) {
538
                alreadyExist = true;
580
                    alreadyExist = true;
539
                break;
581
                    break;
540
            }
582
                }
541
        }
583
            }
542
 
584
        }
543
        if (!alreadyExist) {
585
        if (!alreadyExist) {
544
            final Pair<Article, Integer> line = new Pair<Article, Integer>(new Article(a), 1);
586
            final TicketItem line = new TicketItem(new Article(a), BigDecimal.ONE);
545
            this.items.add(line);
587
            this.items.add(line);
546
        }
588
        }
547
 
589
 
548
    }
590
    }
549
 
591
 
550
    public void incrementArticle(final Article a) {
592
    public void incrementArticle(final Article a) {
-
 
593
        System.err.println("Ticket.incrementArticle()" + a.getName());
-
 
594
 
551
        boolean alreadyExist = false;
595
        boolean alreadyExist = false;
-
 
596
        if (a.getSalesUnit() == null) {
552
        for (final Pair<Article, Integer> line : this.items) {
597
            for (final TicketItem line : this.items) {
553
            if (line.getFirst().equals(a)) {
598
                if (line.getArticle().equals(a)) {
554
                alreadyExist = true;
599
                    alreadyExist = true;
555
                line.setSecond(line.getSecond() + 1);
600
                    line.setQty(line.getQty().add(BigDecimal.ONE));
556
                break;
601
                    break;
557
            }
602
                }
558
        }
603
            }
-
 
604
        }
559
        if (!alreadyExist) {
605
        if (!alreadyExist) {
560
            final Pair<Article, Integer> line = new Pair<Article, Integer>(a, 1);
606
            final TicketItem line = new TicketItem(a, BigDecimal.ONE);
561
            this.items.add(line);
607
            this.items.add(line);
562
        }
608
        }
563
 
609
 
564
    }
610
    }
565
 
611
 
-
 
612
    public void addItem(TicketItem item) {
-
 
613
        this.items.add(item);
-
 
614
    }
-
 
615
 
566
    public List<Paiement> getPaiements() {
616
    public List<Paiement> getPaiements() {
567
        return this.paiements;
617
        return this.paiements;
568
    }
618
    }
569
 
619
 
570
    public int getTotalInCents() {
620
    public int getTotalInCents() {
Line 579... Line 629...
579
        final String val = DefaultNXProps.getInstance().getStringProperty("ArticleService");
629
        final String val = DefaultNXProps.getInstance().getStringProperty("ArticleService");
580
        final Boolean bServiceActive = Boolean.valueOf(val);
630
        final Boolean bServiceActive = Boolean.valueOf(val);
581
        calc.setServiceActive(bServiceActive != null && bServiceActive);
631
        calc.setServiceActive(bServiceActive != null && bServiceActive);
582
        final int size = this.items.size();
632
        final int size = this.items.size();
583
        for (int i = 0; i < size; i++) {
633
        for (int i = 0; i < size; i++) {
584
            final Pair<Article, Integer> line = this.items.get(i);
634
            final TicketItem line = this.items.get(i);
585
            final int count = line.getSecond();
635
            final BigDecimal count = line.getQty();
586
            final Article art = line.getFirst();
636
            final Article art = line.getArticle();
587
            final SQLRowValues rowVals = new SQLRowValues(tableElt);
637
            final SQLRowValues rowVals = new SQLRowValues(tableElt);
588
            rowVals.put("T_PV_HT", art.getPriceWithoutTax().multiply(new BigDecimal(count)));
638
            rowVals.put("T_PV_HT", art.getPriceWithoutTax().multiply(count));
-
 
639
            if (art.getSalesUnit() != null) {
589
            rowVals.put("QTE", count);
640
                rowVals.put("QTE_UNITAIRE", count);
-
 
641
                rowVals.put("QTE", BigDecimal.ONE);
-
 
642
            } else {
-
 
643
                rowVals.put("QTE", count.intValue());
-
 
644
            }
590
            rowVals.put("ID_TAXE", art.getIdTaxe());
645
            rowVals.put("ID_TAXE", art.getIdTaxe());
591
            calc.addLine(rowVals, tableArticle.getRow(art.getId()), i, false);
646
            calc.addLine(rowVals, CaissePanel.getArticleRowValuesFromCache(art.getId()), i, false);
592
 
647
 
593
        }
648
        }
594
        calc.checkResult();
649
        calc.checkResult();
595
        return calc;
650
        return calc;
596
    }
651
    }
597
 
652
 
598
    public List<Pair<Article, Integer>> getArticles() {
653
    public List<TicketItem> getItems() {
599
        return this.items;
654
        return this.items;
600
    }
655
    }
601
 
656
 
602
    public void clearArticle(final Article article) {
657
    public void clearArticle(final Article article) {
603
        Pair<Article, Integer> toRemove = null;
658
        TicketItem toRemove = null;
604
        for (final Pair<Article, Integer> line : this.items) {
659
        for (final TicketItem line : this.items) {
605
            if (line.getFirst().equals(article)) {
660
            if (line.getArticle().equals(article)) {
-
 
661
                toRemove = line;
-
 
662
                break;
-
 
663
            }
-
 
664
        }
-
 
665
        if (toRemove != null) {
-
 
666
            this.items.remove(toRemove);
-
 
667
        }
-
 
668
    }
-
 
669
 
-
 
670
    public void removeTicketItem(TicketItem item) {
-
 
671
        TicketItem toRemove = null;
-
 
672
        for (final TicketItem line : this.items) {
-
 
673
            if (line.equals(item)) {
606
                toRemove = line;
674
                toRemove = line;
607
                break;
675
                break;
608
            }
676
            }
609
        }
677
        }
610
        if (toRemove != null) {
678
        if (toRemove != null) {
611
            this.items.remove(toRemove);
679
            this.items.remove(toRemove);
612
        }
680
        }
-
 
681
 
613
    }
682
    }
614
 
683
 
615
    public void setArticleCount(final Article article, final int count) {
684
    public void setArticleCount(final Article article, final BigDecimal count) {
616
        // TODO Allow only if annulation?
685
        // TODO Allow only if annulation?
617
        // if (count <= 0) {
686
        // if (count <= 0) {
618
        // this.clearArticle(article);
687
        // this.clearArticle(article);
619
        // return;
688
        // return;
620
        // }
689
        // }
621
        Pair<Article, Integer> toModify = null;
690
        TicketItem toModify = null;
622
        for (final Pair<Article, Integer> line : this.items) {
691
        for (final TicketItem line : this.items) {
623
            if (line.getFirst().equals(article)) {
692
            if (line.getArticle().equals(article)) {
624
                toModify = line;
693
                toModify = line;
625
                break;
694
                break;
626
            }
695
            }
627
        }
696
        }
628
        if (toModify != null) {
697
        if (toModify != null) {
629
            toModify.setSecond(count);
698
            toModify.setQty(count);
630
        }
699
        }
631
 
700
 
632
    }
701
    }
633
 
702
 
634
    public int getItemCount(final Article article) {
703
    public BigDecimal getItemCount(final Article article) {
635
        for (final Pair<Article, Integer> line : this.items) {
704
        for (final TicketItem line : this.items) {
636
            if (line.getFirst().equals(article)) {
705
            if (line.getArticle().equals(article)) {
637
                return line.getSecond();
706
                return line.getQty();
638
            }
707
            }
639
        }
708
        }
640
        return 0;
709
        return BigDecimal.ZERO;
641
    }
710
    }
642
 
711
 
643
    public int getPaidTotal() {
712
    public int getPaidTotal() {
644
        int paid = 0;
713
        int paid = 0;
645
        for (final Paiement p : this.paiements) {
714
        for (final Paiement p : this.paiements) {
Line 647... Line 716...
647
        }
716
        }
648
        return paid;
717
        return paid;
649
    }
718
    }
650
 
719
 
651
    public void removeArticle(final Article a) {
720
    public void removeArticle(final Article a) {
652
        Pair<Article, Integer> lineToDelete = null;
721
        TicketItem lineToDelete = null;
653
        for (final Pair<Article, Integer> line : this.items) {
722
        for (final TicketItem line : this.items) {
654
            if (line.getFirst().equals(a)) {
723
            if (line.getArticle().equals(a)) {
655
                final int count = line.getSecond() + 1;
724
                final BigDecimal count = line.getQty().add(BigDecimal.ONE);
656
                if (count <= 0) {
725
                if (count.signum() <= 0) {
657
                    lineToDelete = line;
726
                    lineToDelete = line;
658
                }
727
                }
659
                line.setSecond(count);
728
                line.setQty(count);
660
                break;
729
                break;
661
            }
730
            }
662
        }
731
        }
663
        if (lineToDelete != null) {
732
        if (lineToDelete != null) {
664
            this.items.remove(lineToDelete);
733
            this.items.remove(lineToDelete);
Line 749... Line 818...
749
            }
818
            }
750
        }
819
        }
751
 
820
 
752
        getReceiptCode().markDeleted();
821
        getReceiptCode().markDeleted();
753
    }
822
    }
-
 
823
 
754
}
824
}