OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 151 Rev 156
Line 77... Line 77...
77
import javax.swing.JOptionPane;
77
import javax.swing.JOptionPane;
78
import javax.swing.SwingUtilities;
78
import javax.swing.SwingUtilities;
79
 
79
 
80
import org.jdom2.Document;
80
import org.jdom2.Document;
81
import org.jdom2.Element;
81
import org.jdom2.Element;
-
 
82
import org.jdom2.JDOMException;
82
import org.jdom2.input.SAXBuilder;
83
import org.jdom2.input.SAXBuilder;
83
import org.jdom2.output.Format;
84
import org.jdom2.output.Format;
84
import org.jdom2.output.XMLOutputter;
85
import org.jdom2.output.XMLOutputter;
85
 
86
 
86
public class POSConfiguration {
87
public class POSConfiguration {
Line 115... Line 116...
115
    private String LCDType = "serial";
116
    private String LCDType = "serial";
116
    private String LCDPort = "";
117
    private String LCDPort = "";
117
    private String LCDLine1 = "Bienvenue";
118
    private String LCDLine1 = "Bienvenue";
118
    private String LCDLine2 = "ILM Informatique";
119
    private String LCDLine2 = "ILM Informatique";
119
 
120
 
-
 
121
    public static POSConfiguration createInstance() throws JDOMException, IOException {
-
 
122
        POSConfiguration res = new POSConfiguration(getConfigFile(new File(".")));
-
 
123
        res.loadConfiguration();
-
 
124
        return res;
-
 
125
    }
-
 
126
 
-
 
127
    @Deprecated
120
    public static synchronized POSConfiguration getInstance() {
128
    public static synchronized POSConfiguration setInstance() throws JDOMException, IOException {
121
        if (instance == null) {
129
        if (instance == null) {
122
            instance = new POSConfiguration(getConfigFile(new File(".")));
130
            instance = createInstance();
-
 
131
        } else {
123
            instance.loadConfiguration();
132
            throw new IllegalStateException("already set");
124
        }
133
        }
125
        return instance;
134
        return instance;
126
    }
135
    }
127
 
136
 
-
 
137
    @Deprecated
-
 
138
    public static synchronized POSConfiguration getInstance() {
-
 
139
        return instance;
-
 
140
    }
-
 
141
 
128
    private POSConfiguration(final File confFile) {
142
    private POSConfiguration(final File confFile) {
129
        this.confFile = confFile;
143
        this.confFile = confFile;
130
        ticketPrinterConf1 = new TicketPrinterConfiguration();
144
        ticketPrinterConf1 = new TicketPrinterConfiguration();
131
        ticketPrinterConf2 = new TicketPrinterConfiguration();
145
        ticketPrinterConf2 = new TicketPrinterConfiguration();
132
        // Desactivate second printer by default
146
        // Desactivate second printer by default
Line 339... Line 353...
339
                }
353
                }
340
                int idClient = ticket.getClient().getId();
354
                int idClient = ticket.getClient().getId();
341
                if (idClient <= 0) {
355
                if (idClient <= 0) {
342
                    idClient = defaultIDClient;
356
                    idClient = defaultIDClient;
343
                }
357
                }
-
 
358
 
-
 
359
                // TODO fusionner TotalCalculator avec Ticket.GetTotalCalcutor
344
                TotalCalculator calc = new TotalCalculator("T_PA_HT", "T_PV_HT", null);
360
                TotalCalculator calc = new TotalCalculator("T_PA_HT", "T_PV_HT", null, null);
345
 
361
 
346
                String val = DefaultNXProps.getInstance().getStringProperty("ArticleService");
362
                String val = DefaultNXProps.getInstance().getStringProperty("ArticleService");
347
                Boolean bServiceActive = Boolean.valueOf(val);
363
                Boolean bServiceActive = Boolean.valueOf(val);
348
                calc.setServiceActive(bServiceActive != null && bServiceActive);
364
                calc.setServiceActive(bServiceActive != null && bServiceActive);
349
 
365
 
Line 393... Line 409...
393
 
409
 
394
                        rowValsElt.put("ID_MODE_REGLEMENT", rowValsEltMode);
410
                        rowValsElt.put("ID_MODE_REGLEMENT", rowValsEltMode);
395
                        rowValsElt.put("ID_CLIENT", idClient);
411
                        rowValsElt.put("ID_CLIENT", idClient);
396
 
412
 
397
                        long montant = Long.valueOf(paiement.getMontantInCents());
413
                        long montant = Long.valueOf(paiement.getMontantInCents());
-
 
414
                        // Check si montant especes > especes données alors montant especes =
-
 
415
                        // montant donné - montant rendu
-
 
416
                        // TODO gérer ce cas si paiement multiple
398
                        if (ticket.getPaiements().size() == 1 && paiement.getType() == Paiement.ESPECES) {
417
                        if (ticket.getPaiements().size() == 1 && paiement.getType() == Paiement.ESPECES) {
399
                            montant = longValueTotal;
418
                            montant = longValueTotal;
400
                        }
419
                        }
401
                        rowValsElt.put("MONTANT", montant);
420
                        rowValsElt.put("MONTANT", montant);
402
                        rowValsElt.put("NOM", "Ticket " + ticket.getCode());
421
                        rowValsElt.put("NOM", "Ticket " + ticket.getCode());
Line 495... Line 514...
495
        StockItemsUpdater stockUpdater = new StockItemsUpdater(new StockLabel() {
514
        StockItemsUpdater stockUpdater = new StockItemsUpdater(new StockLabel() {
496
            @Override
515
            @Override
497
            public String getLabel(SQLRowAccessor rowOrigin, SQLRowAccessor rowElt) {
516
            public String getLabel(SQLRowAccessor rowOrigin, SQLRowAccessor rowElt) {
498
                return "Ticket N°" + rowOrigin.getString("NUMERO");
517
                return "Ticket N°" + rowOrigin.getString("NUMERO");
499
            }
518
            }
500
        }, row, row.getReferentRows(getClientCaisse().getTable().getTable("SAISIE_VENTE_FACTURE_ELEMENT")), TypeStockUpdate.REAL_DELIVER);
519
        }, row, row.getReferentRows(getClientCaisse().getTable().getTable("SAISIE_VENTE_FACTURE_ELEMENT")), TypeStockUpdate.REAL_VIRTUAL_DELIVER);
501
        stockUpdater.update();
520
        stockUpdater.update();
502
    }
521
    }
503
 
522
 
504
    public List<Ticket> allTickets() {
523
    public List<Ticket> allTickets() {
505
        final List<Ticket> l = new ArrayList<Ticket>();
524
        final List<Ticket> l = new ArrayList<Ticket>();
Line 527... Line 546...
527
 
546
 
528
    public void setFooterLines(List<TicketLine> footerLines) {
547
    public void setFooterLines(List<TicketLine> footerLines) {
529
        this.footerLines = footerLines;
548
        this.footerLines = footerLines;
530
    }
549
    }
531
 
550
 
532
    private void loadConfiguration() {
551
    private void loadConfiguration() throws JDOMException, IOException {
533
        if (!isConfigurationFileCreated()) {
552
        if (!isConfigurationFileCreated()) {
534
            System.err.println("POSConfiguration.loadConfigurationFromXML() configuration not loaded. " + getConfigFile().getAbsolutePath() + " missing.");
553
            System.err.println("POSConfiguration.loadConfigurationFromXML() configuration not loaded. " + getConfigFile().getAbsolutePath() + " missing.");
535
            return;
554
            return;
536
        }
555
        }
537
 
556
 
538
        final SAXBuilder builder = new SAXBuilder();
557
        final SAXBuilder builder = new SAXBuilder();
539
        File file = getConfigFile();
558
        File file = getConfigFile();
540
 
559
 
541
        try {
-
 
542
            System.out.println("POSConfiguration.loadConfigurationFromXML() loading " + file.getAbsolutePath());
560
        System.out.println("POSConfiguration.loadConfigurationFromXML() loading " + file.getAbsolutePath());
543
            Document document = builder.build(file);
561
        Document document = builder.build(file);
544
            // config
562
        // config
545
            final Element rootElement = document.getRootElement();
563
        final Element rootElement = document.getRootElement();
546
            setUserID(Integer.valueOf(rootElement.getAttributeValue("userID", "2")));
564
        setUserID(Integer.valueOf(rootElement.getAttributeValue("userID", "2")));
Line 593... Line 611...
593
                configureTicketPrinter(this.ticketPrinterConf1, printers.get(0));
611
            configureTicketPrinter(this.ticketPrinterConf1, printers.get(0));
594
            }
612
        }
595
            if (printers.size() > 1) {
613
        if (printers.size() > 1) {
596
                configureTicketPrinter(this.ticketPrinterConf2, printers.get(1));
614
            configureTicketPrinter(this.ticketPrinterConf2, printers.get(1));
597
            }
615
        }
598
        } catch (Exception e) {
-
 
599
            e.printStackTrace();
-
 
600
        }
-
 
601
 
-
 
602
    }
616
    }
603
 
617
 
604
    private void configureTicketPrinter(TicketPrinterConfiguration conf, Element element) {
618
    private void configureTicketPrinter(TicketPrinterConfiguration conf, Element element) {
605
        conf.setType(element.getAttributeValue("type"));
619
        conf.setType(element.getAttributeValue("type"));
606
        conf.setName(element.getAttributeValue("name"));
620
        conf.setName(element.getAttributeValue("name"));