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 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;
-
 
28
import org.openconcerto.erp.core.sales.pos.ui.TicketCellRenderer;
27
import org.openconcerto.erp.core.sales.pos.ui.TicketCellRenderer;
29
import org.openconcerto.erp.generationEcritures.GenerationEcritures;
28
import org.openconcerto.erp.generationEcritures.GenerationEcritures;
30
import org.openconcerto.erp.generationEcritures.GenerationMvtVirement;
29
import org.openconcerto.erp.generationEcritures.GenerationMvtVirement;
31
import org.openconcerto.erp.preferences.DefaultNXProps;
30
import org.openconcerto.erp.preferences.DefaultNXProps;
32
import org.openconcerto.sql.Configuration;
31
import org.openconcerto.sql.Configuration;
33
import org.openconcerto.sql.element.SQLElementDirectory;
32
import org.openconcerto.sql.element.SQLElementDirectory;
34
import org.openconcerto.sql.model.SQLBackgroundTableCache;
-
 
35
import org.openconcerto.sql.model.SQLBackgroundTableCacheItem;
-
 
36
import org.openconcerto.sql.model.SQLRow;
33
import org.openconcerto.sql.model.SQLRow;
37
import org.openconcerto.sql.model.SQLRowAccessor;
34
import org.openconcerto.sql.model.SQLRowAccessor;
38
import org.openconcerto.sql.model.SQLRowValues;
35
import org.openconcerto.sql.model.SQLRowValues;
39
import org.openconcerto.sql.model.SQLTable;
36
import org.openconcerto.sql.model.SQLTable;
40
import org.openconcerto.sql.utils.SQLUtils;
37
import org.openconcerto.sql.utils.SQLUtils;
Line 53... Line 50...
53
import java.util.ArrayList;
50
import java.util.ArrayList;
54
import java.util.Calendar;
51
import java.util.Calendar;
55
import java.util.Collections;
52
import java.util.Collections;
56
import java.util.Comparator;
53
import java.util.Comparator;
57
import java.util.Date;
54
import java.util.Date;
-
 
55
import java.util.HashSet;
58
import java.util.List;
56
import java.util.List;
59
import java.util.Locale;
57
import java.util.Locale;
60
import java.util.Map;
58
import java.util.Map;
-
 
59
import java.util.Set;
61
 
60
 
62
import org.jdom2.Attribute;
61
import org.jdom2.Attribute;
63
import org.jdom2.Document;
62
import org.jdom2.Document;
64
import org.jdom2.Element;
63
import org.jdom2.Element;
65
 
64
 
Line 150... Line 149...
150
                final String categorie = element.getAttributeValue("categorie");
149
                final String categorie = element.getAttributeValue("categorie");
151
                final String name = element.getValue();
150
                final String name = element.getValue();
152
                final String codebarre = element.getAttributeValue("codebarre");
151
                final String codebarre = element.getAttributeValue("codebarre");
153
                final String codeArt = element.getAttributeValue("code");
152
                final String codeArt = element.getAttributeValue("code");
154
                final String salesUnit = element.getAttributeValue("unit");
153
                final String salesUnit = element.getAttributeValue("unit");
-
 
154
                final String declinaison = element.getAttributeValue("declinaison");
155
                final Categorie cat = new Categorie(categorie);
155
                final Categorie cat = new Categorie(categorie);
156
 
156
 
-
 
157
                final BigDecimal discount_pct = new BigDecimal(element.getAttributeValue("discount_pct", "0.00"));
-
 
158
                final BigDecimal ecotaxe = new BigDecimal(element.getAttributeValue("ecotaxe", "0.00"));
-
 
159
 
157
                final String valueID = element.getAttributeValue("id");
160
                final String valueID = element.getAttributeValue("id");
158
 
161
 
159
                final int id = valueID == null || valueID.trim().length() == 0 ? tableArticle.getUndefinedID() : Integer.parseInt(valueID);
162
                final int id = valueID == null || valueID.trim().length() == 0 ? tableArticle.getUndefinedID() : Integer.parseInt(valueID);
160
                final Article art = new Article(cat, name, id);
163
                final Article art = new Article(cat, name, id);
161
                art.setPriceWithTax(prix_unitaire_cents);
164
                art.setPriceWithTax(prix_unitaire_cents);
162
                art.setCode(codeArt);
165
                art.setCode(codeArt);
163
                art.setPriceWithoutTax(prix_unitaire_cents_ht);
166
                art.setPriceWithoutTax(prix_unitaire_cents_ht);
164
                art.setIdTaxe(idTaxe);
167
                art.setIdTaxe(idTaxe);
165
                art.setBarCode(codebarre);
168
                art.setBarCode(codebarre);
166
                art.setSalesUnit(salesUnit);
169
                art.setSalesUnit(salesUnit);
-
 
170
                art.setDeclinaison(declinaison);
-
 
171
 
-
 
172
                art.setDiscountPct(discount_pct);
-
 
173
                art.setEcoTaxe(ecotaxe);
-
 
174
 
167
                final TicketItem line = new TicketItem(art, qte);
175
                final TicketItem line = new TicketItem(art, qte);
168
                t.items.add(line);
176
                t.items.add(line);
169
 
177
 
170
            }
178
            }
171
            // paiement
179
            // paiement
Line 197... Line 205...
197
        } catch (Exception e) {
205
        } catch (Exception e) {
198
            throw new IOException("Couldn't parse " + file, e);
206
            throw new IOException("Couldn't parse " + file, e);
199
        }
207
        }
200
    }
208
    }
201
 
209
 
202
    // TODO receiptCode should be immutable and the day part should be the current accounting day
210
    // TODO receiptCode should be immutable and the day part should be the current
-
 
211
    // accounting day
203
    // not the day of the present time. E.g. for work day beginning at 15:00, even at 3:00 the
212
    // not the day of the present time. E.g. for work day beginning at 15:00, even
-
 
213
    // at 3:00 the
204
    // receipt code should contain the previous day.
214
    // receipt code should contain the previous day.
205
    // The creationCal should only be set once the ticket is done (i.e. no further modifications
215
    // The creationCal should only be set once the ticket is done (i.e. no further
-
 
216
    // modifications
206
    // should be allowed)
217
    // should be allowed)
207
 
218
 
208
    // create new ticket, i.e. null creationDate since it's not done
219
    // create new ticket, i.e. null creationDate since it's not done
209
    public Ticket(final int caisse, final int number, final String previousHash) {
220
    public Ticket(final int caisse, final int number, final String previousHash) {
210
        this(new ReceiptCode(caisse, Calendar.getInstance(), number), null, previousHash);
221
        this(new ReceiptCode(caisse, Calendar.getInstance(), number), null, previousHash);
Line 275... Line 286...
275
        for (final TicketItem item : this.items) {
286
        for (final TicketItem item : this.items) {
276
            final Element e = new Element("article");
287
            final Element e = new Element("article");
277
            e.setAttribute("qte", String.valueOf(item.getQty()));
288
            e.setAttribute("qte", String.valueOf(item.getQty()));
278
            // Prix unitaire
289
            // Prix unitaire
279
            final Article article = item.getArticle();
290
            final Article article = item.getArticle();
-
 
291
 
280
            e.setAttribute("prix", String.valueOf(article.getPriceWithTax()));
292
            e.setAttribute("prix", String.valueOf(article.getPriceWithTax(item.getQty(), false)));
281
            e.setAttribute("prixHT", String.valueOf(article.getPriceWithoutTax()));
293
            e.setAttribute("prixHT", String.valueOf(article.getPriceWithoutTax(item.getQty(), false)));
-
 
294
 
282
            e.setAttribute("idTaxe", String.valueOf(article.getIdTaxe()));
295
            e.setAttribute("idTaxe", String.valueOf(article.getIdTaxe()));
283
            e.setAttribute("categorie", article.getCategorie().getName());
296
            e.setAttribute("categorie", article.getCategorie().getName());
284
            e.setAttribute("codebarre", article.getBarCode());
297
            e.setAttribute("codebarre", article.getBarCode());
285
            e.setAttribute("code", article.getCode());
298
            e.setAttribute("code", article.getCode());
286
            e.setAttribute("id", String.valueOf(article.getId()));
299
            e.setAttribute("id", String.valueOf(article.getId()));
-
 
300
            e.setAttribute("ecotaxe", String.valueOf(article.getEcoTaxe()));
-
 
301
            e.setAttribute("discount_pct", String.valueOf(article.getDiscountPct()));
287
            if (article.getSalesUnit() != null) {
302
            if (article.getSalesUnit() != null) {
288
                e.setAttribute("unit", article.getSalesUnit());
303
                e.setAttribute("unit", article.getSalesUnit());
289
            }
304
            }
-
 
305
            if (article.getDeclinaison() != null) {
-
 
306
                e.setAttribute("declinaison", article.getDeclinaison());
-
 
307
            }
290
            e.setText(article.getName());
308
            e.setText(article.getName());
291
            topLevel.addContent(e);
309
            topLevel.addContent(e);
292
        }
310
        }
293
        // Paiements
311
        // Paiements
294
        for (final Paiement paiement : this.paiements) {
312
        for (final Paiement paiement : this.paiements) {
Line 418... Line 436...
418
                }
436
                }
419
            }
437
            }
420
            final BigDecimal nb = item.getQty();
438
            final BigDecimal nb = item.getQty();
421
            final Float tauxFromId = TaxeCache.getCache().getTauxFromId(article.getIdTaxe());
439
            final Float tauxFromId = TaxeCache.getCache().getTauxFromId(article.getIdTaxe());
422
            final BigDecimal tauxTVA = BigDecimal.valueOf(tauxFromId).movePointLeft(2).add(BigDecimal.ONE);
440
            final BigDecimal tauxTVA = BigDecimal.valueOf(tauxFromId).movePointLeft(2).add(BigDecimal.ONE);
-
 
441
 
423
            final BigDecimal unitPrice = article.getPriceWithoutTax().multiply(tauxTVA, DecimalUtils.HIGH_PRECISION);
442
            final BigDecimal unitPrice = article.getPriceWithoutTax(nb, false).multiply(tauxTVA, DecimalUtils.HIGH_PRECISION);
424
            final BigDecimal multiply = article.getPriceWithoutTax().multiply(nb, DecimalUtils.HIGH_PRECISION).multiply(tauxTVA, DecimalUtils.HIGH_PRECISION);
443
            final BigDecimal multiply = article.getPriceWithoutTax(nb, false).multiply(nb, DecimalUtils.HIGH_PRECISION).multiply(tauxTVA, DecimalUtils.HIGH_PRECISION);
425
 
444
 
426
            String qtyString = DefaultTicketPrinter.formatRight(MAX_QTE_WIDTH, String.valueOf(nb));
445
            String qtyString = DefaultTicketPrinter.formatRight(MAX_QTE_WIDTH, String.valueOf(nb));
427
            final String priceUnformated = TicketCellRenderer.centsToString(multiply.movePointRight(2).setScale(0, RoundingMode.HALF_UP).intValue());
446
            final String priceUnformated = TicketCellRenderer.centsToString(multiply.movePointRight(2).setScale(0, RoundingMode.HALF_UP).intValue());
428
            final String priceString = DefaultTicketPrinter.formatRight(MAX_PRICE_WIDTH, priceUnformated);
447
            final String priceString = DefaultTicketPrinter.formatRight(MAX_PRICE_WIDTH, priceUnformated);
429
            String unitPriceString = "";
448
            String unitPriceString = "";
Line 448... Line 467...
448
            } else {
467
            } else {
449
                // 1 line
468
                // 1 line
450
                final String nameString = DefaultTicketPrinter.formatLeft(maxWidth - 2 - MAX_PRICE_WIDTH - MAX_QTE_WIDTH - 1 - unitPriceString.length(), article.getName());
469
                final String nameString = DefaultTicketPrinter.formatLeft(maxWidth - 2 - MAX_PRICE_WIDTH - MAX_QTE_WIDTH - 1 - unitPriceString.length(), article.getName());
451
                prt.addToBuffer(qtyString + " " + nameString + " " + unitPriceString + " " + priceString);
470
                prt.addToBuffer(qtyString + " " + nameString + " " + unitPriceString + " " + priceString);
452
            }
471
            }
-
 
472
            if (article.getDeclinaison() != null) {
-
 
473
                prt.addToBuffer("      " + article.getDeclinaison());
-
 
474
            }
-
 
475
 
453
            if (article.getSalesUnit() != null) {
476
            if (article.getSalesUnit() != null) {
454
                prt.addToBuffer(
477
                prt.addToBuffer(
455
                        "      (" + nb.abs() + " " + article.getSalesUnit() + " x " + TicketCellRenderer.centsToString(unitPrice.movePointRight(2).setScale(0, RoundingMode.HALF_UP).intValue()) + ")");
478
                        "      (" + nb.abs() + " " + article.getSalesUnit() + " x " + TicketCellRenderer.centsToString(unitPrice.movePointRight(2).setScale(0, RoundingMode.HALF_UP).intValue()) + ")");
456
            }
479
            }
-
 
480
 
-
 
481
            if (article.getEcoTaxe().compareTo(BigDecimal.ZERO) != 0) {
-
 
482
                final String nameString = "       * dont eco-part.:";
-
 
483
                BigDecimal eco = article.getEcoTaxe().movePointRight(2).setScale(0, RoundingMode.HALF_UP);
-
 
484
                final String ecoString = DefaultTicketPrinter.formatRight(MAX_PRICE_WIDTH, TicketCellRenderer.centsToString(eco.intValue()));
-
 
485
                prt.addToBuffer(nameString + ecoString);
-
 
486
            }
-
 
487
 
-
 
488
            if (article.getDiscountPct().compareTo(BigDecimal.ZERO) != 0) {
-
 
489
                final String nameString = DefaultTicketPrinter.formatLeft(maxWidth - 2 - MAX_PRICE_WIDTH - 1, " * Remise");
-
 
490
                BigDecimal discount = multiply.movePointRight(2).multiply(article.getDiscountPct()).negate().setScale(0, RoundingMode.HALF_UP);
-
 
491
                final String discountString = DefaultTicketPrinter.formatRight(MAX_PRICE_WIDTH, TicketCellRenderer.centsToString(discount.intValue()));
-
 
492
                prt.addToBuffer(" " + nameString + " " + " " + discountString);
-
 
493
            }
-
 
494
 
457
        }
495
        }
458
 
496
 
459
        final StringBuilder spacer = new StringBuilder();
497
        final StringBuilder spacer = new StringBuilder();
460
        for (int i = 0; i <= MAX_QTE_WIDTH; i++) {
498
        for (int i = 0; i <= MAX_QTE_WIDTH; i++) {
461
            spacer.append(' ');
499
            spacer.append(' ');
Line 589... Line 627...
589
 
627
 
590
    }
628
    }
591
 
629
 
592
    public void incrementArticle(final Article a) {
630
    public void incrementArticle(final Article a) {
593
        System.err.println("Ticket.incrementArticle()" + a.getName());
631
        System.err.println("Ticket.incrementArticle()" + a.getName());
594
 
-
 
-
 
632
        TicketItem ticketLine;
595
        boolean alreadyExist = false;
633
        boolean alreadyExist = false;
596
        if (a.getSalesUnit() == null) {
634
        if (a.getSalesUnit() == null) {
597
            for (final TicketItem line : this.items) {
635
            for (final TicketItem line : this.items) {
598
                if (line.getArticle().equals(a)) {
636
                if (line.getArticle().equals(a)) {
599
                    alreadyExist = true;
637
                    alreadyExist = true;
-
 
638
                    ticketLine = line;
600
                    line.setQty(line.getQty().add(BigDecimal.ONE));
639
                    ticketLine.setQty(line.getQty().add(BigDecimal.ONE));
601
                    break;
640
                    break;
602
                }
641
                }
603
            }
642
            }
604
        }
643
        }
605
        if (!alreadyExist) {
644
        if (!alreadyExist) {
606
            final TicketItem line = new TicketItem(a, BigDecimal.ONE);
645
            ticketLine = new TicketItem(a, BigDecimal.ONE);
607
            this.items.add(line);
646
            this.items.add(ticketLine);
608
        }
647
        }
609
 
-
 
610
    }
648
    }
611
 
649
 
612
    public void addItem(TicketItem item) {
650
    public void addItem(TicketItem item) {
613
        this.items.add(item);
651
        this.items.add(item);
614
    }
652
    }
Line 628... Line 666...
628
        final TotalCalculator calc = new TotalCalculator("T_PA_HT", "T_PV_HT", null, null);
666
        final TotalCalculator calc = new TotalCalculator("T_PA_HT", "T_PV_HT", null, null);
629
        final String val = DefaultNXProps.getInstance().getStringProperty("ArticleService");
667
        final String val = DefaultNXProps.getInstance().getStringProperty("ArticleService");
630
        final Boolean bServiceActive = Boolean.valueOf(val);
668
        final Boolean bServiceActive = Boolean.valueOf(val);
631
        calc.setServiceActive(bServiceActive != null && bServiceActive);
669
        calc.setServiceActive(bServiceActive != null && bServiceActive);
632
        final int size = this.items.size();
670
        final int size = this.items.size();
-
 
671
 
-
 
672
        Set<Integer> ids = new HashSet<>();
-
 
673
        ArticleCache cache = ArticleCache.getInstance();
-
 
674
        for (int i = 0; i < size; i++) {
-
 
675
            final TicketItem line = this.items.get(i);
-
 
676
            final Article art = line.getArticle();
-
 
677
            int id = art.getId();
-
 
678
            if (!cache.isInCache(id)) {
-
 
679
                ids.add(id);
-
 
680
            }
-
 
681
        }
-
 
682
        if (!ids.isEmpty()) {
-
 
683
            cache.preloadCacheArticleMap(new ArrayList<>(ids));
-
 
684
        }
-
 
685
 
633
        for (int i = 0; i < size; i++) {
686
        for (int i = 0; i < size; i++) {
634
            final TicketItem line = this.items.get(i);
687
            final TicketItem line = this.items.get(i);
635
            final BigDecimal count = line.getQty();
688
            final BigDecimal count = line.getQty();
636
            final Article art = line.getArticle();
689
            final Article art = line.getArticle();
637
            final SQLRowValues rowVals = new SQLRowValues(tableElt);
690
            final SQLRowValues rowVals = new SQLRowValues(tableElt);
-
 
691
 
638
            rowVals.put("T_PV_HT", art.getPriceWithoutTax().multiply(count));
692
            rowVals.put("T_PV_HT", art.getPriceWithoutTax(count, true).multiply(count));
-
 
693
 
639
            if (art.getSalesUnit() != null) {
694
            if (art.getSalesUnit() != null) {
640
                rowVals.put("QTE_UNITAIRE", count);
695
                rowVals.put("QTE_UNITAIRE", count);
641
                rowVals.put("QTE", BigDecimal.ONE);
696
                rowVals.put("QTE", BigDecimal.ONE);
642
            } else {
697
            } else {
643
                rowVals.put("QTE", count.intValue());
698
                rowVals.put("QTE", count.intValue());
644
            }
699
            }
645
            rowVals.put("ID_TAXE", art.getIdTaxe());
700
            rowVals.put("ID_TAXE", art.getIdTaxe());
-
 
701
            System.out.println("Ticket.getTotalCalculator()" + rowVals);
646
            calc.addLine(rowVals, CaissePanel.getArticleRowValuesFromCache(art.getId()), i, false);
702
            calc.addLine(rowVals, cache.getArticleRowValuesFromCache(art.getId()), i, false);
647
 
703
 
648
        }
704
        }
649
        calc.checkResult();
705
        calc.checkResult();
650
        return calc;
706
        return calc;
651
    }
707
    }