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 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 63... Line 63...
63
    private int caisseId;
63
    private int caisseId;
64
    private final ServerFinderPanel serverFinderPanel;
64
    private final ServerFinderPanel serverFinderPanel;
65
    private final JComboBox comboSociete;
65
    private final JComboBox comboSociete;
66
    private final JComboBox comboCaisse;
66
    private final JComboBox comboCaisse;
67
    private final JComboBox comboUtilisateur;
67
    private final JComboBox comboUtilisateur;
-
 
68
    private final JComboBox comboDepot;
68
    private final TicketLineTable headerTable;
69
    private final TicketLineTable headerTable;
69
    private final TicketLineTable footerTable;
70
    private final TicketLineTable footerTable;
70
    private JTextField textTerminalCB;
71
    private JTextField textTerminalCB;
71
 
72
 
72
    // Ticket printers
73
    // Ticket printers
Line 75... Line 76...
75
    // LCD
76
    // LCD
76
    private JComboBox comboLCDType;
77
    private JComboBox comboLCDType;
77
    private JTextField textLCDPort;
78
    private JTextField textLCDPort;
78
    private JTextField textLCDLine1;
79
    private JTextField textLCDLine1;
79
    private JTextField textLCDLine2;
80
    private JTextField textLCDLine2;
-
 
81
    protected int depotStockId = 2;
80
 
82
 
81
    public ConfigCaissePanel(final ServerFinderPanel serverFinderPanel) {
83
    public ConfigCaissePanel(final ServerFinderPanel serverFinderPanel) {
82
        this.serverFinderPanel = serverFinderPanel;
84
        this.serverFinderPanel = serverFinderPanel;
83
        try {
85
        try {
84
            this.configuration = POSConfiguration.setInstance();
86
            this.configuration = POSConfiguration.setInstance();
Line 145... Line 147...
145
                }
147
                }
146
                return super.getListCellRendererComponent(list, label, index, isSelected, cellHasFocus);
148
                return super.getListCellRendererComponent(list, label, index, isSelected, cellHasFocus);
147
            }
149
            }
148
        });
150
        });
149
        this.add(this.comboCaisse, c);
151
        this.add(this.comboCaisse, c);
-
 
152
        // Utilisateur
150
        c.gridx = 0;
153
        c.gridx = 0;
151
        c.gridy++;
154
        c.gridy++;
152
        c.weightx = 0;
155
        c.weightx = 0;
153
        this.add(new JLabel("Utilisateur", SwingConstants.RIGHT), c);
156
        this.add(new JLabel("Utilisateur", SwingConstants.RIGHT), c);
154
        c.gridx++;
157
        c.gridx++;
Line 163... Line 166...
163
                }
166
                }
164
                return super.getListCellRendererComponent(list, label, index, isSelected, cellHasFocus);
167
                return super.getListCellRendererComponent(list, label, index, isSelected, cellHasFocus);
165
            }
168
            }
166
        });
169
        });
167
        this.add(this.comboUtilisateur, c);
170
        this.add(this.comboUtilisateur, c);
-
 
171
        // Depots
-
 
172
        c.gridx = 0;
-
 
173
        c.gridy++;
-
 
174
        c.weightx = 0;
-
 
175
        this.add(new JLabel("Dépôt de stock", SwingConstants.RIGHT), c);
-
 
176
        c.gridx++;
-
 
177
        this.comboDepot = new JComboBox();
-
 
178
        this.comboDepot.setRenderer(new DefaultListCellRenderer() {
-
 
179
            @Override
-
 
180
            public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
-
 
181
                final SQLRow r = (SQLRow) value;
-
 
182
                String label = "";
-
 
183
                if (r != null) {
-
 
184
                    label = r.getString("CODE") + "  " + r.getString("NOM") + " (" + r.getID() + ")".trim();
-
 
185
                }
-
 
186
                return super.getListCellRendererComponent(list, label, index, isSelected, cellHasFocus);
-
 
187
            }
-
 
188
        });
-
 
189
        this.add(this.comboDepot, c);
168
 
190
 
169
        // Ticket
191
        // Ticket
170
        final JLabelBold titleTicket = new JLabelBold("Ticket");
192
        final JLabelBold titleTicket = new JLabelBold("Ticket");
171
        c.gridwidth = 2;
193
        c.gridwidth = 2;
172
        c.gridx = 0;
194
        c.gridx = 0;
Line 245... Line 267...
245
                if (e.getStateChange() == ItemEvent.SELECTED) {
267
                if (e.getStateChange() == ItemEvent.SELECTED) {
246
                    ConfigCaissePanel.this.userId = ((SQLRow) e.getItem()).getID();
268
                    ConfigCaissePanel.this.userId = ((SQLRow) e.getItem()).getID();
247
                }
269
                }
248
            }
270
            }
249
        });
271
        });
-
 
272
        this.comboDepot.addItemListener(new ItemListener() {
-
 
273
            @Override
-
 
274
            public void itemStateChanged(final ItemEvent e) {
-
 
275
                if (e.getStateChange() == ItemEvent.SELECTED) {
-
 
276
                    ConfigCaissePanel.this.depotStockId = ((SQLRow) e.getItem()).getID();
-
 
277
                }
-
 
278
            }
-
 
279
        });
250
    }
280
    }
251
 
281
 
252
    private Component createLCDPanel() {
282
    private Component createLCDPanel() {
253
        final JPanel p = new JPanel();
283
        final JPanel p = new JPanel();
254
        p.setOpaque(false);
284
        p.setOpaque(false);
Line 418... Line 448...
418
                final String name = societe.getString("DATABASE_NAME");
448
                final String name = societe.getString("DATABASE_NAME");
419
                // Caisses
449
                // Caisses
420
                final SQLSelect sel = new SQLSelect();
450
                final SQLSelect sel = new SQLSelect();
421
                sel.addSelectStar(conf.getRootSociete().getTable("CAISSE"));
451
                sel.addSelectStar(conf.getRootSociete().getTable("CAISSE"));
422
                final List<SQLRow> caisses = SQLRowListRSH.execute(sel);
452
                final List<SQLRow> caisses = SQLRowListRSH.execute(sel);
-
 
453
                // Depots
-
 
454
                final SQLSelect sel2 = new SQLSelect();
-
 
455
                sel2.addSelectStar(conf.getRootSociete().getTable("DEPOT_STOCK"));
-
 
456
                final List<SQLRow> depots = SQLRowListRSH.execute(sel2);
-
 
457
 
423
                // Stock l'id de la caisse pour que la reslectionne soit correcte
458
                // Stock l'id de la caisse pour que la reslectionne soit correcte
424
                final int idCaisseToSelect = this.caisseId;
459
                final int idCaisseToSelect = this.caisseId;
-
 
460
                final int idDepotToSelect = this.depotStockId;
-
 
461
 
425
                SwingUtilities.invokeLater(new Runnable() {
462
                SwingUtilities.invokeLater(new Runnable() {
426
                    @Override
463
                    @Override
427
                    public void run() {
464
                    public void run() {
428
                        ConfigCaissePanel.this.caisseId = idCaisseToSelect;
465
                        ConfigCaissePanel.this.caisseId = idCaisseToSelect;
-
 
466
                        ConfigCaissePanel.this.depotStockId = idDepotToSelect;
429
                        if (caisses.isEmpty()) {
467
                        if (caisses.isEmpty()) {
430
                            JOptionPane.showMessageDialog(ConfigCaissePanel.this, "Pas de caisses définies dans la société " + name);
468
                            JOptionPane.showMessageDialog(ConfigCaissePanel.this, "Pas de caisses définies dans la société " + name);
431
                        }
469
                        }
432
                        ConfigCaissePanel.this.comboCaisse.setModel(new DefaultComboBoxModel(new Vector<SQLRow>(caisses)));
470
                        ConfigCaissePanel.this.comboCaisse.setModel(new DefaultComboBoxModel(new Vector<SQLRow>(caisses)));
-
 
471
                        ConfigCaissePanel.this.comboDepot.setModel(new DefaultComboBoxModel(new Vector<SQLRow>(depots)));
433
                        ConfigCaissePanel.this.comboUtilisateur.setEnabled(true);
472
                        ConfigCaissePanel.this.comboUtilisateur.setEnabled(true);
434
                        ConfigCaissePanel.this.comboCaisse.setEnabled(true);
473
                        ConfigCaissePanel.this.comboCaisse.setEnabled(true);
-
 
474
                        ConfigCaissePanel.this.comboDepot.setEnabled(true);
-
 
475
                        {
-
 
476
                            // Selection caisse
435
                        final ComboBoxModel model = ConfigCaissePanel.this.comboCaisse.getModel();
477
                            final ComboBoxModel model = ConfigCaissePanel.this.comboCaisse.getModel();
436
                        final int stop = model.getSize();
478
                            final int stop = model.getSize();
437
                        if (stop > 0) {
479
                            if (stop > 0) {
438
                            // Force la reselection si la valeur n'existe plus,
480
                                // Force la reselection si la valeur n'existe plus,
439
                            // nécessité de recuperer l'id
481
                                // nécessité de recuperer l'id
Line 445... Line 487...
445
                                ConfigCaissePanel.this.comboCaisse.setSelectedItem(r);
487
                                    ConfigCaissePanel.this.comboCaisse.setSelectedItem(r);
446
                                break;
488
                                    break;
447
                            }
489
                                }
448
                        }
490
                            }
449
                    }
491
                        }
-
 
492
                        {
-
 
493
                            // Selection depot
-
 
494
                            final ComboBoxModel model2 = ConfigCaissePanel.this.comboDepot.getModel();
-
 
495
                            final int stop2 = model2.getSize();
-
 
496
                            if (stop2 > 0) {
-
 
497
                                // Force la reselection si la valeur n'existe plus,
-
 
498
                                // nécessité de recuperer l'id
-
 
499
                                ConfigCaissePanel.this.depotStockId = ((SQLRow) model2.getElementAt(0)).getID();
-
 
500
                            }
-
 
501
                            for (int i = 0; i < stop2; i++) {
-
 
502
                                final SQLRow r = (SQLRow) model2.getElementAt(i);
-
 
503
                                if (r.getID() == idDepotToSelect) {
-
 
504
                                    ConfigCaissePanel.this.comboDepot.setSelectedItem(r);
-
 
505
                                    break;
-
 
506
                                }
-
 
507
                            }
-
 
508
                        }
-
 
509
                    }
450
 
510
 
451
                });
511
                });
452
            } else {
512
            } else {
453
                JOptionPane.showMessageDialog(this, "Impossible de trouver la société d'ID " + id);
513
                JOptionPane.showMessageDialog(this, "Impossible de trouver la société d'ID " + id);
454
            }
514
            }
Line 477... Line 537...
477
        this.textLCDLine2.setText(configuration.getLCDLine2());
537
        this.textLCDLine2.setText(configuration.getLCDLine2());
478
 
538
 
479
        this.userId = configuration.getUserID();
539
        this.userId = configuration.getUserID();
480
        this.societeId = configuration.getCompanyID();
540
        this.societeId = configuration.getCompanyID();
481
        this.caisseId = configuration.getPosID();
541
        this.caisseId = configuration.getPosID();
-
 
542
        this.depotStockId = configuration.getDepotID();
482
        this.headerTable.fillFrom(configuration.getHeaderLines());
543
        this.headerTable.fillFrom(configuration.getHeaderLines());
483
        this.footerTable.fillFrom(configuration.getFooterLines());
544
        this.footerTable.fillFrom(configuration.getFooterLines());
484
        this.ticketPanel1.setConfiguration(configuration.getTicketPrinterConfiguration1());
545
        this.ticketPanel1.setConfiguration(configuration.getTicketPrinterConfiguration1());
485
        this.ticketPanel2.setConfiguration(configuration.getTicketPrinterConfiguration2());
546
        this.ticketPanel2.setConfiguration(configuration.getTicketPrinterConfiguration2());
486
 
547
 
Line 504... Line 565...
504
                    @Override
565
                    @Override
505
                    public void run() {
566
                    public void run() {
506
                        ConfigCaissePanel.this.comboSociete.setEnabled(false);
567
                        ConfigCaissePanel.this.comboSociete.setEnabled(false);
507
                        ConfigCaissePanel.this.comboUtilisateur.setEnabled(false);
568
                        ConfigCaissePanel.this.comboUtilisateur.setEnabled(false);
508
                        ConfigCaissePanel.this.comboCaisse.setEnabled(false);
569
                        ConfigCaissePanel.this.comboCaisse.setEnabled(false);
-
 
570
                        ConfigCaissePanel.this.comboDepot.setEnabled(false);
509
                        final ServerFinderConfig config = ConfigCaissePanel.this.serverFinderPanel.createServerFinderConfig();
571
                        final ServerFinderConfig config = ConfigCaissePanel.this.serverFinderPanel.createServerFinderConfig();
510
                        if (!config.isOnline()) {
572
                        if (!config.isOnline()) {
511
                            JOptionPane.showMessageDialog(ConfigCaissePanel.this, "Impossible de se connecter au serveur");
573
                            JOptionPane.showMessageDialog(ConfigCaissePanel.this, "Impossible de se connecter au serveur");
512
                            return;
574
                            return;
513
                        }
575
                        }
Line 597... Line 659...
597
 
659
 
598
    public void dumpConfiguration() {
660
    public void dumpConfiguration() {
599
        System.out.println("Societe: id:" + this.societeId);
661
        System.out.println("Societe: id:" + this.societeId);
600
        System.out.println("Caisse: id:" + this.caisseId);
662
        System.out.println("Caisse: id:" + this.caisseId);
601
        System.out.println("Utilisateur:  id:" + this.userId);
663
        System.out.println("Utilisateur:  id:" + this.userId);
-
 
664
        System.out.println("Depot:  id:" + this.depotStockId);
602
    }
665
    }
603
 
666
 
604
    public void saveConfiguration() {
667
    public void saveConfiguration() {
605
        final POSConfiguration configuration = this.configuration;
668
        final POSConfiguration configuration = this.configuration;
606
        this.ticketPanel1.commitValues();
669
        this.ticketPanel1.commitValues();
607
        this.ticketPanel2.commitValues();
670
        this.ticketPanel2.commitValues();
608
        configuration.setUserID(this.userId);
671
        configuration.setUserID(this.userId);
609
        configuration.setCompanyID(this.societeId);
672
        configuration.setCompanyID(this.societeId);
610
        configuration.setPosID(this.caisseId);
673
        configuration.setPosID(this.caisseId);
-
 
674
        configuration.setDepotID(this.depotStockId);
611
        configuration.setHeaderLines(this.headerTable.getLines());
675
        configuration.setHeaderLines(this.headerTable.getLines());
612
        configuration.setFooterLines(this.footerTable.getLines());
676
        configuration.setFooterLines(this.footerTable.getLines());
613
        // Terminal CB
677
        // Terminal CB
614
        configuration.setCreditCardPort(this.textTerminalCB.getText());
678
        configuration.setCreditCardPort(this.textTerminalCB.getText());
615
        // LCD
679
        // LCD