OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 156 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 156 Rev 174
Line 28... Line 28...
28
import org.openconcerto.erp.core.sales.pos.model.Paiement;
28
import org.openconcerto.erp.core.sales.pos.model.Paiement;
29
import org.openconcerto.erp.core.sales.pos.model.ReceiptCode;
29
import org.openconcerto.erp.core.sales.pos.model.ReceiptCode;
30
import org.openconcerto.erp.core.sales.pos.model.RegisterFiles.HashMode;
30
import org.openconcerto.erp.core.sales.pos.model.RegisterFiles.HashMode;
31
import org.openconcerto.erp.core.sales.pos.model.RegisterLogEntry.ReceiptEntry;
31
import org.openconcerto.erp.core.sales.pos.model.RegisterLogEntry.ReceiptEntry;
32
import org.openconcerto.erp.core.sales.pos.model.Ticket;
32
import org.openconcerto.erp.core.sales.pos.model.Ticket;
-
 
33
import org.openconcerto.erp.core.sales.pos.model.TicketItem;
33
import org.openconcerto.erp.core.sales.pos.model.TicketLine;
34
import org.openconcerto.erp.core.sales.pos.model.TicketLine;
34
import org.openconcerto.erp.core.supplychain.stock.element.StockItemsUpdater;
35
import org.openconcerto.erp.core.supplychain.stock.element.StockItemsUpdater;
35
import org.openconcerto.erp.core.supplychain.stock.element.StockItemsUpdater.TypeStockUpdate;
36
import org.openconcerto.erp.core.supplychain.stock.element.StockItemsUpdater.TypeStockUpdate;
36
import org.openconcerto.erp.core.supplychain.stock.element.StockLabel;
37
import org.openconcerto.erp.core.supplychain.stock.element.StockLabel;
37
import org.openconcerto.erp.generationEcritures.GenerationMvtTicketCaisse;
38
import org.openconcerto.erp.generationEcritures.GenerationMvtTicketCaisse;
Line 39... Line 40...
39
import org.openconcerto.erp.generationEcritures.GenerationReglementVenteNG;
40
import org.openconcerto.erp.generationEcritures.GenerationReglementVenteNG;
40
import org.openconcerto.erp.model.PrixTTC;
41
import org.openconcerto.erp.model.PrixTTC;
41
import org.openconcerto.erp.preferences.DefaultNXProps;
42
import org.openconcerto.erp.preferences.DefaultNXProps;
42
import org.openconcerto.sql.Configuration;
43
import org.openconcerto.sql.Configuration;
43
import org.openconcerto.sql.element.SQLElement;
44
import org.openconcerto.sql.element.SQLElement;
-
 
45
import org.openconcerto.sql.element.SQLElementDirectory;
44
import org.openconcerto.sql.model.SQLBase;
46
import org.openconcerto.sql.model.SQLBase;
45
import org.openconcerto.sql.model.SQLDataSource;
47
import org.openconcerto.sql.model.SQLDataSource;
46
import org.openconcerto.sql.model.SQLRow;
48
import org.openconcerto.sql.model.SQLRow;
47
import org.openconcerto.sql.model.SQLRowAccessor;
49
import org.openconcerto.sql.model.SQLRowAccessor;
-
 
50
import org.openconcerto.sql.model.SQLRowListRSH;
48
import org.openconcerto.sql.model.SQLRowValues;
51
import org.openconcerto.sql.model.SQLRowValues;
49
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
52
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
50
import org.openconcerto.sql.model.SQLSelect;
53
import org.openconcerto.sql.model.SQLSelect;
51
import org.openconcerto.sql.model.SQLSelectHandlerBuilder;
54
import org.openconcerto.sql.model.SQLSelectHandlerBuilder;
52
import org.openconcerto.sql.model.SQLTable;
55
import org.openconcerto.sql.model.SQLTable;
53
import org.openconcerto.sql.model.Where;
56
import org.openconcerto.sql.model.Where;
54
import org.openconcerto.sql.utils.SQLUtils;
57
import org.openconcerto.sql.utils.SQLUtils;
55
import org.openconcerto.utils.BaseDirs;
58
import org.openconcerto.utils.BaseDirs;
56
import org.openconcerto.utils.DecimalUtils;
59
import org.openconcerto.utils.DecimalUtils;
57
import org.openconcerto.utils.ExceptionHandler;
60
import org.openconcerto.utils.ExceptionHandler;
58
import org.openconcerto.utils.Pair;
-
 
59
import org.openconcerto.utils.i18n.TranslationManager;
61
import org.openconcerto.utils.i18n.TranslationManager;
60
 
62
 
61
import java.io.File;
63
import java.io.File;
62
import java.io.FileOutputStream;
64
import java.io.FileOutputStream;
63
import java.io.IOException;
65
import java.io.IOException;
Line 67... Line 69...
67
import java.sql.SQLException;
69
import java.sql.SQLException;
68
import java.util.ArrayList;
70
import java.util.ArrayList;
69
import java.util.Collections;
71
import java.util.Collections;
70
import java.util.Comparator;
72
import java.util.Comparator;
71
import java.util.Date;
73
import java.util.Date;
-
 
74
import java.util.HashMap;
72
import java.util.Iterator;
75
import java.util.Iterator;
73
import java.util.List;
76
import java.util.List;
74
import java.util.Locale;
77
import java.util.Locale;
-
 
78
import java.util.Map;
75
import java.util.logging.Logger;
79
import java.util.logging.Logger;
76
 
80
 
77
import javax.swing.JOptionPane;
81
import javax.swing.JOptionPane;
78
import javax.swing.SwingUtilities;
82
import javax.swing.SwingUtilities;
79
 
83
 
Line 116... Line 120...
116
    private String LCDType = "serial";
120
    private String LCDType = "serial";
117
    private String LCDPort = "";
121
    private String LCDPort = "";
118
    private String LCDLine1 = "Bienvenue";
122
    private String LCDLine1 = "Bienvenue";
119
    private String LCDLine2 = "ILM Informatique";
123
    private String LCDLine2 = "ILM Informatique";
120
 
124
 
-
 
125
    private boolean askPostalCode = false;
-
 
126
 
121
    public static POSConfiguration createInstance() throws JDOMException, IOException {
127
    public static POSConfiguration createInstance() throws JDOMException, IOException {
122
        POSConfiguration res = new POSConfiguration(getConfigFile(new File(".")));
128
        POSConfiguration res = new POSConfiguration(getConfigFile(new File(".")));
123
        res.loadConfiguration();
129
        res.loadConfiguration();
124
        return res;
130
        return res;
125
    }
131
    }
Line 253... Line 259...
253
            JOptionPane.showMessageDialog(null, "Impossible de configurer la connexion à la base de donnée.\n ID société: " + getCompanyID() + " \n ID utilisateur: " + getUserID());
259
            JOptionPane.showMessageDialog(null, "Impossible de configurer la connexion à la base de donnée.\n ID société: " + getCompanyID() + " \n ID utilisateur: " + getUserID());
254
            e.printStackTrace();
260
            e.printStackTrace();
255
            System.exit(2);
261
            System.exit(2);
256
        }
262
        }
257
 
263
 
258
        NouvelleConnexionAction.initCache(conf);
264
        NouvelleConnexionAction.initCache(conf, -1);
259
 
-
 
-
 
265
        TaxeCache.getCache();
260
        return conf;
266
        return conf;
261
    }
267
    }
262
 
268
 
263
    public final Path getRootDir() throws IOException {
269
    public final Path getRootDir() throws IOException {
264
        return Configuration.getInstance().getBaseDirs().getAppDataFolderToWrite().toPath();
270
        return Configuration.getInstance().getBaseDirs().getAppDataFolderToWrite().toPath();
Line 315... Line 321...
315
    public final int importReceipts(final List<Ticket> tickets, final List<ReceiptEntry> entries) throws SQLException {
321
    public final int importReceipts(final List<Ticket> tickets, final List<ReceiptEntry> entries) throws SQLException {
316
        if (entries != null && entries.size() != tickets.size())
322
        if (entries != null && entries.size() != tickets.size())
317
            throw new IllegalArgumentException("Size mismatch");
323
            throw new IllegalArgumentException("Size mismatch");
318
 
324
 
319
        final int defaultIDClient = getClientCaisse().getID();
325
        final int defaultIDClient = getClientCaisse().getID();
-
 
326
        final SQLElementDirectory directory = Configuration.getInstance().getDirectory();
320
        SQLElement elt = Configuration.getInstance().getDirectory().getElement("TICKET_CAISSE");
327
        SQLElement elt = directory.getElement("TICKET_CAISSE");
321
        SQLElement eltFact = Configuration.getInstance().getDirectory().getElement("SAISIE_VENTE_FACTURE_ELEMENT");
328
        SQLElement eltFact = directory.getElement("SAISIE_VENTE_FACTURE_ELEMENT");
322
        SQLElement eltEnc = Configuration.getInstance().getDirectory().getElement("ENCAISSER_MONTANT");
329
        SQLElement eltEnc = directory.getElement("ENCAISSER_MONTANT");
323
        SQLElement eltMode = Configuration.getInstance().getDirectory().getElement("MODE_REGLEMENT");
330
        SQLElement eltMode = directory.getElement("MODE_REGLEMENT");
324
        SQLElement eltArticle = Configuration.getInstance().getDirectory().getElement("ARTICLE");
331
        SQLElement eltArticle = directory.getElement("ARTICLE");
325
        final SQLDataSource ds = elt.getTable().getDBSystemRoot().getDataSource();
332
        final SQLDataSource ds = elt.getTable().getDBSystemRoot().getDataSource();
326
        int imported = 0;
333
        int imported = 0;
327
 
334
 
-
 
335
        //
-
 
336
        final SQLSelect selUniteVente = new SQLSelect();
-
 
337
        selUniteVente.addSelectStar(directory.getElement("UNITE_VENTE").getTable());
-
 
338
        final Map<String, Integer> mapUniteVenteName = new HashMap<>();
-
 
339
        for (SQLRow row : SQLRowListRSH.execute(selUniteVente)) {
-
 
340
            mapUniteVenteName.put(row.getString("CODE"), row.getID());
-
 
341
        }
-
 
342
 
328
        final Iterator<ReceiptEntry> entriesIter = entries == null ? null : entries.iterator();
343
        final Iterator<ReceiptEntry> entriesIter = entries == null ? null : entries.iterator();
329
        for (Ticket ticket : tickets) {
344
        for (Ticket ticket : tickets) {
330
            SQLSelect sel = new SQLSelect();
345
            SQLSelect sel = new SQLSelect();
331
            sel.addSelectFunctionStar("COUNT");
346
            sel.addSelectFunctionStar("COUNT");
332
            sel.setWhere(new Where(elt.getTable().getField("NUMERO"), "=", ticket.getCode()));
347
            sel.setWhere(new Where(elt.getTable().getField("NUMERO"), "=", ticket.getCode()));
Line 345... Line 360...
345
 
360
 
346
                SQLRowValues rowVals = new SQLRowValues(elt.getTable());
361
                SQLRowValues rowVals = new SQLRowValues(elt.getTable());
347
                rowVals.put("NUMERO", ticket.getCode());
362
                rowVals.put("NUMERO", ticket.getCode());
348
                rowVals.put("DATE", ticket.getCreationDate());
363
                rowVals.put("DATE", ticket.getCreationDate());
349
                rowVals.put("ID_CAISSE", getPosID());
364
                rowVals.put("ID_CAISSE", getPosID());
-
 
365
                if (elt.getTable().contains("CODE_POSTAL")) {
-
 
366
                    rowVals.put("CODE_POSTAL", ticket.getCodePostal());
-
 
367
                }
350
                if (entry != null) {
368
                if (entry != null) {
351
                    rowVals.put("FILE_HASH", entry.getFileHash());
369
                    rowVals.put("FILE_HASH", entry.getFileHash());
352
                    rowVals.put("FILE_HASH_PREVIOUS", ticket.getPreviousHash());
370
                    rowVals.put("FILE_HASH_PREVIOUS", ticket.getPreviousHash());
353
                }
371
                }
354
                int idClient = ticket.getClient().getId();
372
                int idClient = ticket.getClient().getId();
Line 362... Line 380...
362
                String val = DefaultNXProps.getInstance().getStringProperty("ArticleService");
380
                String val = DefaultNXProps.getInstance().getStringProperty("ArticleService");
363
                Boolean bServiceActive = Boolean.valueOf(val);
381
                Boolean bServiceActive = Boolean.valueOf(val);
364
                calc.setServiceActive(bServiceActive != null && bServiceActive);
382
                calc.setServiceActive(bServiceActive != null && bServiceActive);
365
 
383
 
366
                // Articles
384
                // Articles
367
                for (Pair<Article, Integer> item : ticket.getArticles()) {
385
                for (TicketItem item : ticket.getItems()) {
368
                    SQLRowValues rowValsElt = new SQLRowValues(eltFact.getTable());
386
                    SQLRowValues rowValsElt = new SQLRowValues(eltFact.getTable());
369
                    final Article article = item.getFirst();
387
                    final Article article = item.getArticle();
370
                    final Integer nb = item.getSecond();
388
                    final BigDecimal nb = item.getQty();
-
 
389
                    if (article.getSalesUnit() == null) {
-
 
390
                        rowValsElt.put("QTE", nb.intValue());
-
 
391
                    } else {
371
                    rowValsElt.put("QTE", nb);
392
                        rowValsElt.put("QTE", 1);
-
 
393
                        rowValsElt.put("QTE_UNITAIRE", nb);
-
 
394
                    }
372
                    rowValsElt.put("PV_HT", article.getPriceWithoutTax());
395
                    rowValsElt.put("PV_HT", article.getPriceWithoutTax());
373
                    Float tauxFromId = TaxeCache.getCache().getTauxFromId(article.getIdTaxe());
396
                    Float tauxFromId = TaxeCache.getCache().getTauxFromId(article.getIdTaxe());
374
                    BigDecimal tauxTVA = new BigDecimal(tauxFromId).movePointLeft(2).add(BigDecimal.ONE);
397
                    BigDecimal tauxTVA = BigDecimal.valueOf(tauxFromId).movePointLeft(2).add(BigDecimal.ONE);
375
 
-
 
376
                    final BigDecimal valueHT = article.getPriceWithoutTax().multiply(new BigDecimal(nb), DecimalUtils.HIGH_PRECISION);
-
 
377
 
398
 
-
 
399
                    final BigDecimal valueHT = article.getPriceWithoutTax().multiply(nb, DecimalUtils.HIGH_PRECISION);
-
 
400
                    if (article.getSalesUnit() != null) {
-
 
401
                        rowValsElt.put("ID_UNITE_VENTE", mapUniteVenteName.get(article.getSalesUnit()));
-
 
402
                    }
378
                    rowValsElt.put("T_PV_HT", valueHT);
403
                    rowValsElt.put("T_PV_HT", valueHT);
379
                    rowValsElt.put("T_PV_TTC", valueHT.multiply(tauxTVA, DecimalUtils.HIGH_PRECISION));
404
                    rowValsElt.put("T_PV_TTC", valueHT.multiply(tauxTVA, DecimalUtils.HIGH_PRECISION));
380
                    rowValsElt.put("ID_TAXE", article.getIdTaxe());
405
                    rowValsElt.put("ID_TAXE", article.getIdTaxe());
381
                    rowValsElt.put("CODE", article.getCode());
406
                    rowValsElt.put("CODE", article.getCode());
382
                    rowValsElt.put("NOM", article.getName());
407
                    rowValsElt.put("NOM", article.getName());
Line 447... Line 472...
447
                                "Règlement " + sqlRow.getForeignRow("ID_MODE_REGLEMENT").getForeignRow("ID_TYPE_REGLEMENT").getString("NOM") + " Ticket " + rowFinal.getString("NUMERO"),
472
                                "Règlement " + sqlRow.getForeignRow("ID_MODE_REGLEMENT").getForeignRow("ID_TYPE_REGLEMENT").getString("NOM") + " Ticket " + rowFinal.getString("NUMERO"),
448
                                sqlRow.getForeign("ID_CLIENT"), ttc, sqlRow.getDate("DATE").getTime(), sqlRow.getForeignRow("ID_MODE_REGLEMENT"), rowFinal, rowFinal.getForeignRow("ID_MOUVEMENT"),
473
                                sqlRow.getForeign("ID_CLIENT"), ttc, sqlRow.getDate("DATE").getTime(), sqlRow.getForeignRow("ID_MODE_REGLEMENT"), rowFinal, rowFinal.getForeignRow("ID_MOUVEMENT"),
449
                                false);
474
                                false);
450
                    }
475
                    }
451
                    if (totalEnc > longValueTotal) {
476
                    if (totalEnc > longValueTotal) {
452
                        final SQLTable table = Configuration.getInstance().getDirectory().getElement("TYPE_REGLEMENT").getTable();
477
                        final SQLTable table = directory.getElement("TYPE_REGLEMENT").getTable();
453
                        int idComptePceCaisse = table.getRow(TypeReglementSQLElement.ESPECE).getInt("ID_COMPTE_PCE_CLIENT");
478
                        int idComptePceCaisse = table.getRow(TypeReglementSQLElement.ESPECE).getInt("ID_COMPTE_PCE_CLIENT");
454
                        if (idComptePceCaisse == table.getUndefinedID()) {
479
                        if (idComptePceCaisse == table.getUndefinedID()) {
455
                            idComptePceCaisse = ComptePCESQLElement.getId(ComptePCESQLElement.getComptePceDefault("VenteEspece"));
480
                            idComptePceCaisse = ComptePCESQLElement.getId(ComptePCESQLElement.getComptePceDefault("VenteEspece"));
456
                        }
481
                        }
457
                        new GenerationMvtVirement(idComptePceCaisse, rowFinal.getForeign("ID_CLIENT").getInt("ID_COMPTE_PCE"), 0, totalEnc - longValueTotal,
482
                        new GenerationMvtVirement(idComptePceCaisse, rowFinal.getForeign("ID_CLIENT").getInt("ID_COMPTE_PCE"), 0, totalEnc - longValueTotal,
Line 518... Line 543...
518
            }
543
            }
519
        }, row, row.getReferentRows(getClientCaisse().getTable().getTable("SAISIE_VENTE_FACTURE_ELEMENT")), TypeStockUpdate.REAL_VIRTUAL_DELIVER);
544
        }, row, row.getReferentRows(getClientCaisse().getTable().getTable("SAISIE_VENTE_FACTURE_ELEMENT")), TypeStockUpdate.REAL_VIRTUAL_DELIVER);
520
        stockUpdater.update();
545
        stockUpdater.update();
521
    }
546
    }
522
 
547
 
523
    public List<Ticket> allTickets() {
548
    public List<Ticket> allTickets() throws IOException {
524
        final List<Ticket> l = new ArrayList<Ticket>();
549
        final List<Ticket> l = new ArrayList<Ticket>();
525
        for (final File f : ReceiptCode.getReceiptsToImport(getPosID())) {
550
        for (final File f : ReceiptCode.getReceiptsToImport(getPosID())) {
526
            // old receipts have no hash files
551
            // old receipts have no hash files
527
            final Ticket ticket = Ticket.parseFile(f, HashMode.NOT_REQUIRED);
552
            final Ticket ticket = Ticket.parseFile(f, HashMode.NOT_REQUIRED);
528
            if (ticket != null) {
-
 
529
                l.add(ticket);
553
            l.add(ticket);
530
            }
554
        }
531
        }
-
 
532
        return l;
555
        return l;
533
    }
556
    }
534
 
557
 
535
    public List<TicketLine> getHeaderLines() {
558
    public List<TicketLine> getHeaderLines() {
536
        return headerLines;
559
        return headerLines;
Line 563... Line 586...
563
        final Element rootElement = document.getRootElement();
586
        final Element rootElement = document.getRootElement();
564
        setUserID(Integer.valueOf(rootElement.getAttributeValue("userID", "2")));
587
        setUserID(Integer.valueOf(rootElement.getAttributeValue("userID", "2")));
565
        setCompanyID(Integer.valueOf(rootElement.getAttributeValue("societeID", "42")));
588
        setCompanyID(Integer.valueOf(rootElement.getAttributeValue("societeID", "42")));
566
        setPosID(Integer.valueOf(rootElement.getAttributeValue("caisseID", "2")));
589
        setPosID(Integer.valueOf(rootElement.getAttributeValue("caisseID", "2")));
567
        setScanDelay(Integer.valueOf(rootElement.getAttributeValue("scanDelay", "80")));
590
        setScanDelay(Integer.valueOf(rootElement.getAttributeValue("scanDelay", "80")));
-
 
591
        setAskPostalCode(rootElement.getAttributeValue("askPostalCode", "false").equals("true"));
-
 
592
 
568
        // screen
593
        // screen
569
        final List<Element> children = rootElement.getChildren("screen");
594
        final List<Element> children = rootElement.getChildren("screen");
570
        if (children != null) {
595
        if (children != null) {
571
            for (Element e : children) {
596
            for (Element e : children) {
572
                this.screenWidth = Integer.valueOf(e.getAttributeValue("width", "0"));
597
                this.screenWidth = Integer.valueOf(e.getAttributeValue("width", "0"));
Line 605... Line 630...
605
                this.footerLines.add(new TicketLine(header.getValue(), header.getAttributeValue("style")));
630
                this.footerLines.add(new TicketLine(header.getValue(), header.getAttributeValue("style")));
606
            }
631
            }
607
        }
632
        }
608
        // ticket printers
633
        // ticket printers
609
        final List<Element> printers = rootElement.getChildren("ticketPrinter");
634
        final List<Element> printers = rootElement.getChildren("ticketPrinter");
610
        if (printers.size() > 0) {
635
        if (!printers.isEmpty()) {
611
            configureTicketPrinter(this.ticketPrinterConf1, printers.get(0));
636
            configureTicketPrinter(this.ticketPrinterConf1, printers.get(0));
612
        }
637
        }
613
        if (printers.size() > 1) {
638
        if (printers.size() > 1) {
614
            configureTicketPrinter(this.ticketPrinterConf2, printers.get(1));
639
            configureTicketPrinter(this.ticketPrinterConf2, printers.get(1));
615
        }
640
        }
Line 647... Line 672...
647
            final Element configElement = new Element("config");
672
            final Element configElement = new Element("config");
648
            configElement.setAttribute("userID", String.valueOf(this.userID));
673
            configElement.setAttribute("userID", String.valueOf(this.userID));
649
            configElement.setAttribute("societeID", String.valueOf(this.companyID));
674
            configElement.setAttribute("societeID", String.valueOf(this.companyID));
650
            configElement.setAttribute("caisseID", String.valueOf(this.posID));
675
            configElement.setAttribute("caisseID", String.valueOf(this.posID));
651
            configElement.setAttribute("scanDelay", String.valueOf(this.scanDelay));
676
            configElement.setAttribute("scanDelay", String.valueOf(this.scanDelay));
-
 
677
            configElement.setAttribute("askPostalCode", this.askPostalCode ? "true" : "false");
652
            doc.addContent(configElement);
678
            doc.addContent(configElement);
653
            // screen size
679
            // screen size
654
            final Element screenElement = new Element("screen");
680
            final Element screenElement = new Element("screen");
655
            screenElement.setAttribute("width", String.valueOf(this.screenWidth));
681
            screenElement.setAttribute("width", String.valueOf(this.screenWidth));
656
            screenElement.setAttribute("height", String.valueOf(this.screenHeight));
682
            screenElement.setAttribute("height", String.valueOf(this.screenHeight));
Line 797... Line 823...
797
    }
823
    }
798
 
824
 
799
    public String getLCDType() {
825
    public String getLCDType() {
800
        return this.LCDType;
826
        return this.LCDType;
801
    }
827
    }
-
 
828
 
-
 
829
    public boolean askPostalCode() {
-
 
830
        return this.askPostalCode;
-
 
831
    }
-
 
832
 
-
 
833
    public void setAskPostalCode(boolean askPostalCode) {
-
 
834
        this.askPostalCode = askPostalCode;
-
 
835
    }
802
}
836
}