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 18... Line 18...
18
import org.openconcerto.erp.core.sales.pos.model.RegisterFiles.DifferentDayException;
18
import org.openconcerto.erp.core.sales.pos.model.RegisterFiles.DifferentDayException;
19
import org.openconcerto.erp.core.sales.pos.model.Ticket;
19
import org.openconcerto.erp.core.sales.pos.model.Ticket;
20
import org.openconcerto.sql.element.SQLElement;
20
import org.openconcerto.sql.element.SQLElement;
21
import org.openconcerto.sql.element.SQLElementDirectory;
21
import org.openconcerto.sql.element.SQLElementDirectory;
22
import org.openconcerto.sql.model.SQLRow;
22
import org.openconcerto.sql.model.SQLRow;
-
 
23
import org.openconcerto.sql.model.SQLRowAccessor;
23
import org.openconcerto.sql.model.SQLRowListRSH;
24
import org.openconcerto.sql.model.SQLRowListRSH;
-
 
25
import org.openconcerto.sql.model.SQLRowValues;
-
 
26
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
24
import org.openconcerto.sql.model.SQLSelect;
27
import org.openconcerto.sql.model.SQLSelect;
25
import org.openconcerto.sql.model.SQLTable;
28
import org.openconcerto.sql.model.SQLTable;
26
import org.openconcerto.sql.model.SQLTable.VirtualFields;
29
import org.openconcerto.sql.model.SQLTable.VirtualFields;
27
import org.openconcerto.sql.model.Where;
30
import org.openconcerto.sql.model.Where;
28
import org.openconcerto.utils.ExceptionHandler;
31
import org.openconcerto.utils.ExceptionHandler;
Line 59... Line 62...
59
 
62
 
60
    private StatusBar st;
63
    private StatusBar st;
61
    private ArticleSelectorPanel articleSelectorPanel;
64
    private ArticleSelectorPanel articleSelectorPanel;
62
    private ArticleSearchPanel articleSearchPanel;
65
    private ArticleSearchPanel articleSearchPanel;
63
 
66
 
64
    private JPanel articleSelector;
67
    private JPanel selector;
65
 
68
 
66
    public CaissePanel(final CaisseFrame caisseFrame) throws Exception {
69
    public CaissePanel(final CaisseFrame caisseFrame) throws Exception {
67
        final SQLElementDirectory dir = caisseFrame.getConf().getDirectory();
70
        final SQLElementDirectory dir = caisseFrame.getConf().getDirectory();
68
 
71
 
69
        this.setLayout(new GridBagLayout());
72
        this.setLayout(new GridBagLayout());
70
        this.setBackground(Color.WHITE);
73
        this.setBackground(Color.WHITE);
71
        this.setOpaque(isOpaque());
74
        this.setOpaque(isOpaque());
72
        GridBagConstraints c = new GridBagConstraints();
75
        GridBagConstraints c = new GridBagConstraints();
-
 
76
 
-
 
77
        // Column 1
73
        c.gridx = 0;
78
        c.gridx = 0;
74
        c.gridy = 0;
79
        c.gridy = 0;
75
        c.weightx = 0;
80
        c.weightx = 0;
76
        c.weighty = 0;
81
        c.weighty = 0;
77
 
-
 
78
        this.controler = new CaisseControler(caisseFrame);
82
        this.controler = new CaisseControler(caisseFrame);
79
 
-
 
80
        c.fill = GridBagConstraints.HORIZONTAL;
83
        c.fill = GridBagConstraints.HORIZONTAL;
81
        this.st = createStatusBar(caisseFrame);
84
        this.st = createStatusBar(caisseFrame);
82
 
-
 
83
        this.add(this.st, c);
85
        this.add(this.st, c);
84
 
86
 
85
        TicketPanel t = new TicketPanel(this.controler);
87
        TicketPanel t = new TicketPanel(this.controler);
86
        // fillExampleArticle();
-
 
87
        loadArticles(dir);
88
        loadArticles(dir);
88
        c.gridx = 0;
-
 
89
        c.gridy++;
89
        c.gridy++;
90
        c.weightx = 0;
-
 
91
        c.weighty = 1;
90
        c.weighty = 1;
92
        c.gridwidth = 1;
91
        c.gridwidth = 1;
93
        c.anchor = GridBagConstraints.SOUTHWEST;
92
        c.anchor = GridBagConstraints.SOUTHWEST;
94
        c.fill = GridBagConstraints.NONE;
93
        c.fill = GridBagConstraints.NONE;
95
        this.add(t, c);
94
        this.add(t, c);
96
 
-
 
-
 
95
        // Column 2
97
        c.fill = GridBagConstraints.BOTH;
96
        c.fill = GridBagConstraints.BOTH;
98
        c.gridx++;
97
        c.gridx++;
-
 
98
        c.gridy = 0;
99
        c.weightx = 1;
99
        c.weightx = 1;
100
        c.gridy--;
-
 
101
        c.gridheight = 2;
100
        c.gridheight = 2;
102
        articleSelectorPanel = new ArticleSelectorPanel(this.controler);
101
        this.articleSelectorPanel = new ArticleSelectorPanel(this.controler);
103
        articleSearchPanel = new ArticleSearchPanel(this.controler);
102
        this.articleSearchPanel = new ArticleSearchPanel(this.controler);
104
        articleSelector = articleSelectorPanel;
103
        this.selector = this.articleSelectorPanel;
105
        this.add(articleSelector, c);
104
        this.add(this.selector, c);
106
 
-
 
-
 
105
        // Column 3
107
        c.gridx++;
106
        c.gridx++;
108
        c.weightx = 0;
107
        c.weightx = 0;
109
        this.add(new PaiementPanel(this.controler), c);
108
        this.add(new PaiementPanel(this.controler), c);
110
        this.controler.addCaisseListener(this);
109
        this.controler.addCaisseListener(this);
111
    }
110
    }
112
 
111
 
113
    private StatusBar createStatusBar(final CaisseFrame caisseFrame) {
112
    private StatusBar createStatusBar(final CaisseFrame caisseFrame) {
114
        final StatusBar s = new StatusBar();
113
        final StatusBar s = new StatusBar();
115
        s.setLayout(new GridBagLayout());
114
        s.setLayout(new GridBagLayout());
116
        final GridBagConstraints c = new GridBagConstraints();
115
        final GridBagConstraints c = new GridBagConstraints();
-
 
116
        if (this.controler.getPOSConf().getScreenWidth() < 1280) {
-
 
117
            c.insets = new Insets(0, 2, 0, 2);
-
 
118
        } else {
117
        c.insets = new Insets(0, 10, 0, 10);
119
            c.insets = new Insets(0, 10, 0, 10);
-
 
120
        }
118
        c.gridx = 0;
121
        c.gridx = 0;
119
        c.gridy = 0;
122
        c.gridy = 0;
120
        c.fill = GridBagConstraints.NONE;
123
        c.fill = GridBagConstraints.NONE;
121
        c.anchor = GridBagConstraints.CENTER;
124
        c.anchor = GridBagConstraints.CENTER;
122
        c.weightx = 0;
125
        c.weightx = 0;
Line 197... Line 200...
197
 
200
 
198
        return s;
201
        return s;
199
    }
202
    }
200
 
203
 
201
    private void loadArticles(final SQLElementDirectory dir) {
204
    private void loadArticles(final SQLElementDirectory dir) {
-
 
205
        final SQLSelect selUniteVente = new SQLSelect();
-
 
206
        selUniteVente.addSelectStar(dir.getElement("UNITE_VENTE").getTable());
-
 
207
        final Map<Integer, String> mapUniteVenteName = new HashMap<>();
-
 
208
        for (SQLRow row : SQLRowListRSH.execute(selUniteVente)) {
-
 
209
            mapUniteVenteName.put(row.getID(), row.getString("CODE"));
-
 
210
        }
202
 
211
 
203
        final Set<Integer> favoriteProductsIds = controler.loadFavoriteProductsIds();
212
        final Set<Integer> favoriteProductsIds = this.controler.loadFavoriteProductsIds();
204
        final List<Article> favoriteProducts = new ArrayList<>();
213
        final List<Article> favoriteProducts = new ArrayList<>();
205
 
214
 
206
        final Map<Integer, Categorie> categoriesMap = new HashMap<Integer, Categorie>();
215
        final Map<Integer, Categorie> categoriesMap = new HashMap<>();
207
 
216
 
208
        SQLElement eltFam = dir.getElement("FAMILLE_ARTICLE");
217
        SQLElement eltFam = dir.getElement("FAMILLE_ARTICLE");
209
        SQLElement eltArticle = dir.getElement("ARTICLE");
218
        SQLElement eltArticle = dir.getElement("ARTICLE");
210
 
219
 
211
        final SQLSelect selFamille = new SQLSelect();
220
        final SQLSelect selFamille = new SQLSelect();
Line 227... Line 236...
227
        }
236
        }
228
 
237
 
229
        final SQLSelect selArticle = new SQLSelect();
238
        final SQLSelect selArticle = new SQLSelect();
230
        final SQLTable tableArticle = eltArticle.getTable();
239
        final SQLTable tableArticle = eltArticle.getTable();
231
        selArticle.addAllSelect(tableArticle.getFields(VirtualFields.PRIMARY_KEY.union(VirtualFields.ARCHIVE)));
240
        selArticle.addAllSelect(tableArticle.getFields(VirtualFields.PRIMARY_KEY.union(VirtualFields.ARCHIVE)));
232
        selArticle.addAllSelect(tableArticle, Arrays.asList("ID_FAMILLE_ARTICLE", "NOM", "CODE", "CODE_BARRE", "ID_TAXE", "PV_HT", "PV_TTC", "ADDITIONAL_TICKET_COPY"));
241
        selArticle.addAllSelect(tableArticle, Arrays.asList("ID_FAMILLE_ARTICLE", "NOM", "CODE", "CODE_BARRE", "ID_TAXE", "PV_HT", "PV_TTC", "ADDITIONAL_TICKET_COPY", "ID_UNITE_VENTE"));
233
        selArticle.setWhere(new Where(tableArticle.getField("OBSOLETE"), "=", Boolean.FALSE).and(new Where(tableArticle.getField("MASQUE_CAISSE"), "=", Boolean.FALSE)));
242
        selArticle.setWhere(new Where(tableArticle.getField("OBSOLETE"), "=", Boolean.FALSE).and(new Where(tableArticle.getField("MASQUE_CAISSE"), "=", Boolean.FALSE)));
234
 
243
 
235
        final Categorie cUnclassified = new Categorie("Non classés", true);
244
        final Categorie cUnclassified = new Categorie("Non classés", true);
236
        cUnclassified.setUnknown();
245
        cUnclassified.setUnknown();
237
        for (SQLRow row : SQLRowListRSH.execute(selArticle)) {
246
        for (SQLRow row : SQLRowListRSH.execute(selArticle)) {
Line 250... Line 259...
250
                a.setCode(code);
259
                a.setCode(code);
251
                a.setIdTaxe(row.getInt("ID_TAXE"));
260
                a.setIdTaxe(row.getInt("ID_TAXE"));
252
                a.setPriceWithoutTax(row.getBigDecimal("PV_HT"));
261
                a.setPriceWithoutTax(row.getBigDecimal("PV_HT"));
253
                a.setPriceWithTax(row.getBigDecimal("PV_TTC"));
262
                a.setPriceWithTax(row.getBigDecimal("PV_TTC"));
254
                a.setAdditionalCopyRequested(row.getBoolean("ADDITIONAL_TICKET_COPY"));
263
                a.setAdditionalCopyRequested(row.getBoolean("ADDITIONAL_TICKET_COPY"));
-
 
264
                if (row.getInt("ID_UNITE_VENTE") != 2) {
-
 
265
                    a.setSalesUnit(mapUniteVenteName.get(row.getInt("ID_UNITE_VENTE")));
-
 
266
                }
255
                final Integer idProduct = a.getId();
267
                final Integer idProduct = a.getId();
256
                if (favoriteProductsIds.contains(idProduct)) {
268
                if (favoriteProductsIds.contains(idProduct)) {
257
                    favoriteProducts.add(a);
269
                    favoriteProducts.add(a);
258
                }
270
                }
259
 
271
 
260
            }
272
            }
261
        }
273
        }
262
        Categorie.setFavoriteProducts(favoriteProducts);
274
        Categorie.setFavoriteProducts(favoriteProducts);
-
 
275
        initCacheArticleMap(dir);
-
 
276
    }
-
 
277
 
-
 
278
    private static Map<Integer, SQLRowAccessor> cacheArticle = new HashMap<>();
-
 
279
 
-
 
280
    public static SQLRowAccessor getArticleRowValuesFromCache(int id) {
-
 
281
        return cacheArticle.get(id);
-
 
282
    }
-
 
283
 
-
 
284
    private void initCacheArticleMap(final SQLElementDirectory dir) {
-
 
285
        final SQLTable tableArt = dir.getElement("ARTICLE").getTable();
-
 
286
        SQLRowValues rowValsArt = new SQLRowValues(tableArt);
-
 
287
        rowValsArt.putNulls(tableArt.getFieldsName());
-
 
288
        final SQLTable tableArtCatComptable = dir.getElement("ARTICLE_CATEGORIE_COMPTABLE").getTable();
-
 
289
        SQLRowValues rowValsArtCatComptable = new SQLRowValues(tableArtCatComptable);
-
 
290
        rowValsArtCatComptable.putNulls(tableArtCatComptable.getFieldsName());
-
 
291
        rowValsArtCatComptable.put("ID_ARTICLE", rowValsArt);
-
 
292
        final SQLRowValues rowValsCaCompt = rowValsArtCatComptable.putRowValues("ID_CATEGORIE_COMPTABLE");
-
 
293
        rowValsCaCompt.putNulls(rowValsCaCompt.getTable().getFieldsName());
-
 
294
 
-
 
295
        final SQLRowValues rowValsFam = rowValsArt.putRowValues("ID_FAMILLE_ARTICLE");
-
 
296
        rowValsFam.putNulls(rowValsFam.getTable().getFieldsName());
-
 
297
        final SQLRowValues rowValuesFamP = rowValsFam.putRowValues("ID_FAMILLE_ARTICLE_PERE");
-
 
298
        rowValuesFamP.putNulls(rowValuesFamP.getTable().getFieldsName());
-
 
299
 
-
 
300
        SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(rowValsArt);
-
 
301
        List<SQLRowValues> res = fetcher.fetch();
-
 
302
        for (SQLRowValues sqlRowValues : res) {
-
 
303
            cacheArticle.put(sqlRowValues.getID(), sqlRowValues);
-
 
304
        }
-
 
305
 
263
    }
306
    }
264
 
307
 
265
    @Override
308
    @Override
266
    public void paint(Graphics g) {
309
    public void paint(Graphics g) {
267
        System.err.println("CaissePanel.paint()" + this.getWidth() + " x " + this.getHeight());
310
        System.err.println("CaissePanel.paint()" + this.getWidth() + " x " + this.getHeight());
Line 277... Line 320...
277
            g.setColor(Color.GRAY);
320
            g.setColor(Color.GRAY);
278
            g.setFont(g.getFont().deriveFont(18f));
321
            g.setFont(g.getFont().deriveFont(18f));
279
            g.drawString("Solde : " + new DecimalFormat("#0.00").format(this.controler.getClient().getSolde()), 20, 120);
322
            g.drawString("Solde : " + new DecimalFormat("#0.00").format(this.controler.getClient().getSolde()), 20, 120);
280
 
323
 
281
        }
324
        }
-
 
325
        int xPos = 300;
-
 
326
        if (this.controler.getPOSConf().getScreenWidth() < 1280) {
-
 
327
            xPos = 270;
282
 
328
        }
283
        // Prix
329
        // Prix
284
        int x = 300;
330
        int x = xPos;
285
        int y = 110;
331
        int y = 110;
286
        String euros;
332
        String euros;
287
        String cents;
333
        String cents;
288
        Rectangle2D r;
334
        Rectangle2D r;
289
        g.setColor(Color.BLACK);
335
        g.setColor(Color.BLACK);
Line 301... Line 347...
301
        g.drawString(euros, x, y);
347
        g.drawString(euros, x, y);
302
        g.setFont(g.getFont().deriveFont(40f));
348
        g.setFont(g.getFont().deriveFont(40f));
303
        g.drawString(cents, x + (int) r.getWidth(), y);
349
        g.drawString(cents, x + (int) r.getWidth(), y);
304
        // Paiement
350
        // Paiement
305
        y += 40;
351
        y += 40;
306
        x = 300;
352
        x = xPos;
307
        final int paye = this.controler.getPaidTotal();
353
        final int paye = this.controler.getPaidTotal();
308
        euros = CaisseControler.getEuros(paye) + ".";
354
        euros = CaisseControler.getEuros(paye) + ".";
309
        cents = CaisseControler.getCents(paye);
355
        cents = CaisseControler.getCents(paye);
310
 
356
 
311
        g.setFont(g.getFont().deriveFont(18f));
357
        g.setFont(g.getFont().deriveFont(18f));
Line 325... Line 371...
325
        g.drawString("Payé", x - (int) r2.getWidth() - (int) r.getWidth() - 10, y);
371
        g.drawString("Payé", x - (int) r2.getWidth() - (int) r.getWidth() - 10, y);
326
        // A rendre
372
        // A rendre
327
        final boolean minimalHeight = this.getHeight() < 750;
373
        final boolean minimalHeight = this.getHeight() < 750;
328
        if (!minimalHeight) {
374
        if (!minimalHeight) {
329
            y += 40;
375
            y += 40;
330
            x = 300;
376
            x = xPos;
331
        } else {
377
        } else {
332
            x = 140;
378
            x = 140;
333
        }
379
        }
334
        int aRendre = paye - total;
380
        int aRendre = paye - total;
335
        if (aRendre != 0) {
381
        if (aRendre != 0) {
Line 370... Line 416...
370
        repaint();
416
        repaint();
371
    }
417
    }
372
 
418
 
373
    public void switchListMode() {
419
    public void switchListMode() {
374
 
420
 
375
        GridBagConstraints c = ((GridBagLayout) this.getLayout()).getConstraints(articleSelector);
421
        GridBagConstraints c = ((GridBagLayout) this.getLayout()).getConstraints(this.selector);
376
        this.remove(articleSelector);
422
        this.remove(this.selector);
377
 
423
 
378
        if (articleSelector == this.articleSearchPanel) {
424
        if (this.selector == this.articleSearchPanel) {
379
            articleSelector = this.articleSelectorPanel;
425
            this.selector = this.articleSelectorPanel;
380
        } else {
426
        } else {
381
            articleSelector = this.articleSearchPanel;
427
            this.selector = this.articleSearchPanel;
382
        }
428
        }
-
 
429
        System.err.println("CaissePanel.switchListMode()" + this.selector.getMinimumSize() + " " + this.selector.getPreferredSize() + " " + this.selector.getMaximumSize());
383
        this.add(articleSelector, c);
430
        this.add(this.selector, c);
384
        this.validate();
431
        this.validate();
385
        this.repaint();
432
        this.repaint();
386
 
433
 
387
    }
434
    }
388
 
435
 
389
    public CaisseControler getControler() {
436
    public CaisseControler getControler() {
390
        return controler;
437
        return this.controler;
-
 
438
    }
-
 
439
 
-
 
440
    public void validateTicket(final CaisseFrame caisseFrame) {
-
 
441
        final Ticket savedReceipt;
-
 
442
        try {
-
 
443
            savedReceipt = CaissePanel.this.controler.saveAndClearTicket(caisseFrame.getFiles(), caisseFrame.getConf().getDirectory());
-
 
444
        } catch (DifferentDayException ex) {
-
 
445
            JOptionPane.showMessageDialog(CaissePanel.this, "Impossible de laisser la caisse ouverte plusieurs jours. Veuillez la clôturer pour pouvoir faire de nouveaux tickets.", "Erreur",
-
 
446
                    JOptionPane.ERROR_MESSAGE);
-
 
447
            return;
-
 
448
        } catch (Throwable ex) {
-
 
449
            ExceptionHandler.handle(CaissePanel.this, "Erreur de sauvegarde des informations du ticket", ex);
-
 
450
            return;
-
 
451
        }
-
 
452
        if (savedReceipt != null) {
-
 
453
            // Valider
-
 
454
            CaissePanel.this.controler.setLCD("Impression de", "votre ticket...", 0);
-
 
455
            try {
-
 
456
                caisseFrame.getPOSConf().print(savedReceipt, (savedReceipt.isAdditionnalCopyRequested() ? 1 : 0));
-
 
457
            } catch (UnsatisfiedLinkError ex) {
-
 
458
                JOptionPane.showMessageDialog(CaissePanel.this, "Erreur de configuration de la liaison à l'imprimante");
-
 
459
            } catch (Throwable ex) {
-
 
460
                ex.printStackTrace();
-
 
461
                JOptionPane.showMessageDialog(CaissePanel.this, "Erreur d'impression du ticket");
-
 
462
            }
-
 
463
 
-
 
464
            CaissePanel.this.controler.setLCDDefaultDisplay(2);
-
 
465
        } else {
-
 
466
            System.err.println("CaissePanel.validateTicket() ticket non sauvé");
-
 
467
        }
391
    }
468
    }
392
}
469
}