OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 177 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 12... Line 12...
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.erp.core.sales.pos.ui;
14
 package org.openconcerto.erp.core.sales.pos.ui;
15
 
15
 
16
import org.openconcerto.erp.core.sales.pos.model.Article;
16
import org.openconcerto.erp.core.sales.pos.model.Article;
-
 
17
import org.openconcerto.erp.core.sales.pos.model.ArticleCache;
17
import org.openconcerto.erp.core.sales.pos.model.Categorie;
18
import org.openconcerto.erp.core.sales.pos.model.Categorie;
18
import org.openconcerto.erp.core.sales.pos.model.RegisterFiles.DifferentDayException;
19
import org.openconcerto.erp.core.sales.pos.model.RegisterFiles.DifferentDayException;
-
 
20
import org.openconcerto.erp.core.sales.pos.model.TarifQuantite;
19
import org.openconcerto.erp.core.sales.pos.model.Ticket;
21
import org.openconcerto.erp.core.sales.pos.model.Ticket;
-
 
22
import org.openconcerto.erp.core.sales.pos.model.TicketItem;
-
 
23
import org.openconcerto.erp.core.supplychain.stock.element.StockSQLElement;
-
 
24
import org.openconcerto.erp.preferences.TemplateNXProps;
20
import org.openconcerto.sql.element.SQLElement;
25
import org.openconcerto.sql.element.SQLElement;
21
import org.openconcerto.sql.element.SQLElementDirectory;
26
import org.openconcerto.sql.element.SQLElementDirectory;
-
 
27
import org.openconcerto.sql.model.SQLField;
22
import org.openconcerto.sql.model.SQLRow;
28
import org.openconcerto.sql.model.SQLRow;
23
import org.openconcerto.sql.model.SQLRowAccessor;
-
 
24
import org.openconcerto.sql.model.SQLRowListRSH;
29
import org.openconcerto.sql.model.SQLRowListRSH;
25
import org.openconcerto.sql.model.SQLRowValues;
30
import org.openconcerto.sql.model.SQLRowValues;
26
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
31
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
27
import org.openconcerto.sql.model.SQLSelect;
32
import org.openconcerto.sql.model.SQLSelect;
28
import org.openconcerto.sql.model.SQLTable;
33
import org.openconcerto.sql.model.SQLTable;
29
import org.openconcerto.sql.model.SQLTable.VirtualFields;
34
import org.openconcerto.sql.model.SQLTable.VirtualFields;
30
import org.openconcerto.sql.model.Where;
35
import org.openconcerto.sql.model.Where;
31
import org.openconcerto.utils.ExceptionHandler;
36
import org.openconcerto.utils.ExceptionHandler;
-
 
37
import org.openconcerto.utils.FileUtils;
32
import org.openconcerto.utils.StringUtils;
38
import org.openconcerto.utils.StringUtils;
-
 
39
import org.openconcerto.utils.cc.ITransformer;
33
 
40
 
34
import java.awt.Color;
41
import java.awt.Color;
35
import java.awt.Font;
42
import java.awt.Font;
36
import java.awt.Graphics;
43
import java.awt.Graphics;
37
import java.awt.Graphics2D;
44
import java.awt.Graphics2D;
Line 40... Line 47...
40
import java.awt.Insets;
47
import java.awt.Insets;
41
import java.awt.RenderingHints;
48
import java.awt.RenderingHints;
42
import java.awt.event.ActionEvent;
49
import java.awt.event.ActionEvent;
43
import java.awt.event.ActionListener;
50
import java.awt.event.ActionListener;
44
import java.awt.geom.Rectangle2D;
51
import java.awt.geom.Rectangle2D;
-
 
52
import java.io.File;
-
 
53
import java.io.FileOutputStream;
-
 
54
import java.io.IOException;
-
 
55
import java.math.BigDecimal;
45
import java.text.DecimalFormat;
56
import java.text.DecimalFormat;
46
import java.util.ArrayList;
57
import java.util.ArrayList;
47
import java.util.Arrays;
58
import java.util.Arrays;
-
 
59
import java.util.Calendar;
48
import java.util.HashMap;
60
import java.util.HashMap;
-
 
61
import java.util.HashSet;
49
import java.util.List;
62
import java.util.List;
50
import java.util.Map;
63
import java.util.Map;
51
import java.util.Set;
64
import java.util.Set;
52
 
65
 
53
import javax.swing.JOptionPane;
66
import javax.swing.JOptionPane;
Line 63... Line 76...
63
    private StatusBar st;
76
    private StatusBar st;
64
    private ArticleSelectorPanel articleSelectorPanel;
77
    private ArticleSelectorPanel articleSelectorPanel;
65
    private ArticleSearchPanel articleSearchPanel;
78
    private ArticleSearchPanel articleSearchPanel;
66
 
79
 
67
    private JPanel selector;
80
    private JPanel selector;
-
 
81
    final SQLElementDirectory dir;
68
 
82
 
69
    public CaissePanel(final CaisseFrame caisseFrame) throws Exception {
83
    public CaissePanel(final CaisseFrame caisseFrame) throws Exception {
70
        final SQLElementDirectory dir = caisseFrame.getConf().getDirectory();
84
        this.dir = caisseFrame.getConf().getDirectory();
71
 
-
 
-
 
85
        loadArticles(this.dir);
72
        this.setLayout(new GridBagLayout());
86
        this.setLayout(new GridBagLayout());
73
        this.setBackground(Color.WHITE);
87
        this.setBackground(Color.WHITE);
74
        this.setOpaque(isOpaque());
88
        this.setOpaque(isOpaque());
75
        GridBagConstraints c = new GridBagConstraints();
89
        GridBagConstraints c = new GridBagConstraints();
76
 
90
 
Line 83... Line 97...
83
        c.fill = GridBagConstraints.HORIZONTAL;
97
        c.fill = GridBagConstraints.HORIZONTAL;
84
        this.st = createStatusBar(caisseFrame);
98
        this.st = createStatusBar(caisseFrame);
85
        this.add(this.st, c);
99
        this.add(this.st, c);
86
 
100
 
87
        TicketPanel t = new TicketPanel(this.controler);
101
        TicketPanel t = new TicketPanel(this.controler);
88
        loadArticles(dir);
-
 
-
 
102
 
89
        c.gridy++;
103
        c.gridy++;
90
        c.weighty = 1;
104
        c.weighty = 1;
91
        c.gridwidth = 1;
105
        c.gridwidth = 1;
92
        c.anchor = GridBagConstraints.SOUTHWEST;
106
        c.anchor = GridBagConstraints.SOUTHWEST;
93
        c.fill = GridBagConstraints.NONE;
107
        c.fill = GridBagConstraints.NONE;
Line 140... Line 154...
140
        s.add(bMenu, c);
154
        s.add(bMenu, c);
141
        bValidate.addActionListener(new ActionListener() {
155
        bValidate.addActionListener(new ActionListener() {
142
 
156
 
143
            @Override
157
            @Override
144
            public void actionPerformed(ActionEvent e) {
158
            public void actionPerformed(ActionEvent e) {
145
                final Ticket savedReceipt;
-
 
146
                try {
-
 
147
                    savedReceipt = CaissePanel.this.controler.saveAndClearTicket(caisseFrame.getFiles(), caisseFrame.getConf().getDirectory());
-
 
148
                } catch (DifferentDayException ex) {
159
                checkStock(getControler().getPOSConf().getDepotID(), new Runnable() {
149
                    JOptionPane.showMessageDialog(CaissePanel.this, "Impossible de laisser la caisse ouverte plusieurs jours. Veuillez la clôturer pour pouvoir faire de nouveaux tickets.", "Erreur",
-
 
150
                            JOptionPane.ERROR_MESSAGE);
-
 
-
 
160
 
151
                    return;
161
                    @Override
152
                } catch (Throwable ex) {
162
                    public void run() {
153
                    ExceptionHandler.handle(CaissePanel.this, "Erreur de sauvegarde des informations du ticket", ex);
-
 
154
                    return;
-
 
155
                }
-
 
156
                if (savedReceipt != null) {
163
                        if (caisseFrame.getPOSConf().askPostalCode()) {
157
                    // Valider
-
 
158
                    CaissePanel.this.controler.setLCD("Impression de", "votre ticket...", 0);
164
                            caisseFrame.showPostalCodeFrame(CaissePanel.this);
159
                    try {
165
                        } else {
160
                        caisseFrame.getPOSConf().print(savedReceipt, (savedReceipt.isAdditionnalCopyRequested() ? 1 : 0));
-
 
161
                    } catch (UnsatisfiedLinkError ex) {
-
 
162
                        JOptionPane.showMessageDialog(CaissePanel.this, "Erreur de configuration de la liaison à l'imprimante");
-
 
163
                    } catch (Throwable ex) {
-
 
164
                        ex.printStackTrace();
166
                            validateTicket(caisseFrame);
165
                        JOptionPane.showMessageDialog(CaissePanel.this, "Erreur d'impression du ticket");
-
 
166
                    }
167
                        }
167
 
168
 
168
                    CaissePanel.this.controler.setLCDDefaultDisplay(2);
-
 
169
                }
169
                    }
-
 
170
                });
170
 
171
 
171
            }
172
            }
172
        });
173
        });
173
        bClients.addActionListener(new ActionListener() {
174
        bClients.addActionListener(new ActionListener() {
174
 
175
 
Line 199... Line 200...
199
        });
200
        });
200
 
201
 
201
        return s;
202
        return s;
202
    }
203
    }
203
 
204
 
-
 
205
    protected void checkStock(int idDepot, Runnable runnable) {
-
 
206
        final List<TicketItem> items = this.controler.getItems();
-
 
207
        final List<Integer> articleIds = new ArrayList<>();
-
 
208
        final Map<Integer, TicketItem> mapTicketItem = new HashMap<>();
-
 
209
        for (TicketItem item : items) {
-
 
210
            articleIds.add(item.getArticle().getId());
-
 
211
            mapTicketItem.put(item.getArticle().getId(), item);
-
 
212
        }
-
 
213
 
-
 
214
        final SQLTable stockTable = this.dir.getElement(StockSQLElement.class).getTable();
-
 
215
 
-
 
216
        final SQLSelect selStock = new SQLSelect();
-
 
217
        selStock.addSelect(stockTable.getField("ID"));
-
 
218
        selStock.addSelect(stockTable.getField("ID_DEPOT_STOCK"));
-
 
219
        selStock.addSelect(stockTable.getField("QTE_REEL"));
-
 
220
        selStock.addSelect(stockTable.getField("ID_ARTICLE"));
-
 
221
        selStock.setWhere(Where.inValues(stockTable.getField("ID_ARTICLE"), articleIds).and(new Where(stockTable.getField("ID_DEPOT_STOCK"), "=", idDepot)));
-
 
222
        Map<TicketItem, Integer> missingQty = new HashMap<>();
-
 
223
        for (SQLRow row : SQLRowListRSH.execute(selStock)) {
-
 
224
            int idArticle = row.getInt("ID_ARTICLE");
-
 
225
            int qte = (int) Math.round(row.getFloat("QTE_REEL"));
-
 
226
            TicketItem item = mapTicketItem.get(idArticle);
-
 
227
            if (item == null) {
-
 
228
                System.err.println("Pas d'entrée dans STOCK pour l'article " + idArticle);
-
 
229
            } else {
-
 
230
                if (qte < item.getQty().intValue()) {
-
 
231
                    int delta = item.getQty().intValue() - qte;
-
 
232
                    missingQty.put(item, delta);
-
 
233
                }
-
 
234
            }
-
 
235
 
-
 
236
        }
-
 
237
        if (missingQty.isEmpty()) {
-
 
238
            runnable.run();
-
 
239
        } else {
-
 
240
            // Transfert de stock, Annulation ou bypass
-
 
241
            getControler().openStockErrorPanel(missingQty, runnable);
-
 
242
        }
-
 
243
    }
-
 
244
 
-
 
245
    public Set<Integer> loadFavoriteProductsIds() {
-
 
246
        final TemplateNXProps nxprops = (TemplateNXProps) TemplateNXProps.getInstance();
-
 
247
        final File f = new File(nxprops.getDefaultStringValue(), "favorites.txt");
-
 
248
        System.out.println("CaisseControler.saveFavoriteProductsIds() loading favorites from " + f.getAbsolutePath());
-
 
249
        final Set<Integer> result = new HashSet<>();
-
 
250
        if (f.exists()) {
-
 
251
            try {
-
 
252
                String s = FileUtils.read(f);
-
 
253
                List<String> sIds = StringUtils.fastSplit(s, ',');
-
 
254
                for (String string : sIds) {
-
 
255
                    if (!string.isEmpty()) {
-
 
256
                        result.add(Integer.parseInt(string));
-
 
257
                    }
-
 
258
                }
-
 
259
            } catch (IOException e) {
-
 
260
                e.printStackTrace();
-
 
261
            }
-
 
262
        }
-
 
263
        return result;
-
 
264
    }
-
 
265
 
-
 
266
    public void saveFavoriteProductsIds(List<Article> products) {
-
 
267
        final TemplateNXProps nxprops = (TemplateNXProps) TemplateNXProps.getInstance();
-
 
268
        final File f = new File(nxprops.getDefaultStringValue(), "favorites.txt");
-
 
269
        System.out.println("CaisseControler.saveFavoriteProductsIds() saving favorites to " + f.getAbsolutePath());
-
 
270
        try (FileOutputStream fOut = new FileOutputStream(f);) {
-
 
271
            for (Article product : products) {
-
 
272
                fOut.write(String.valueOf(product.getId()).getBytes());
-
 
273
                fOut.write(',');
-
 
274
            }
-
 
275
            fOut.flush();
-
 
276
        } catch (IOException e) {
-
 
277
            e.printStackTrace();
-
 
278
        }
-
 
279
    }
-
 
280
 
204
    private void loadArticles(final SQLElementDirectory dir) {
281
    private List<Article> loadArticles(final SQLElementDirectory dir) {
-
 
282
        long t1 = System.currentTimeMillis();
205
        final SQLSelect selUniteVente = new SQLSelect();
283
        final SQLSelect selUniteVente = new SQLSelect();
206
        selUniteVente.addSelectStar(dir.getElement("UNITE_VENTE").getTable());
284
        final SQLTable tableUniteVente = dir.getElement("UNITE_VENTE").getTable();
-
 
285
        selUniteVente.addSelect(tableUniteVente.getKey());
-
 
286
        selUniteVente.addSelect(tableUniteVente.getField("CODE"));
207
        final Map<Integer, String> mapUniteVenteName = new HashMap<>();
287
        final Map<Integer, String> mapUniteVenteName = new HashMap<>();
208
        for (SQLRow row : SQLRowListRSH.execute(selUniteVente)) {
288
        for (SQLRow row : SQLRowListRSH.execute(selUniteVente)) {
209
            mapUniteVenteName.put(row.getID(), row.getString("CODE"));
289
            mapUniteVenteName.put(row.getID(), row.getString("CODE"));
210
        }
290
        }
211
 
291
 
212
        final Set<Integer> favoriteProductsIds = this.controler.loadFavoriteProductsIds();
292
        final Set<Integer> favoriteProductsIds = loadFavoriteProductsIds();
213
        final List<Article> favoriteProducts = new ArrayList<>();
293
        final List<Article> favoriteProducts = new ArrayList<>();
214
 
294
 
215
        final Map<Integer, Categorie> categoriesMap = new HashMap<>();
295
        final Map<Integer, Categorie> categoriesMap = new HashMap<>();
216
 
296
 
217
        SQLElement eltFam = dir.getElement("FAMILLE_ARTICLE");
297
        SQLElement eltFam = dir.getElement("FAMILLE_ARTICLE");
Line 236... Line 316...
236
        }
316
        }
237
 
317
 
238
        final SQLSelect selArticle = new SQLSelect();
318
        final SQLSelect selArticle = new SQLSelect();
239
        final SQLTable tableArticle = eltArticle.getTable();
319
        final SQLTable tableArticle = eltArticle.getTable();
240
        selArticle.addAllSelect(tableArticle.getFields(VirtualFields.PRIMARY_KEY.union(VirtualFields.ARCHIVE)));
320
        selArticle.addAllSelect(tableArticle.getFields(VirtualFields.PRIMARY_KEY.union(VirtualFields.ARCHIVE)));
-
 
321
        selArticle.addAllSelect(tableArticle,
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"));
322
                Arrays.asList("ID_FAMILLE_ARTICLE", "NOM", "CODE", "CODE_BARRE", "ID_TAXE", "PV_HT", "PV_TTC", "ADDITIONAL_TICKET_COPY", "ID_UNITE_VENTE", "ID_ECO_CONTRIBUTION"));
242
        selArticle.setWhere(new Where(tableArticle.getField("OBSOLETE"), "=", Boolean.FALSE).and(new Where(tableArticle.getField("MASQUE_CAISSE"), "=", Boolean.FALSE)));
323
        selArticle.setWhere(new Where(tableArticle.getField("OBSOLETE"), "=", Boolean.FALSE).and(new Where(tableArticle.getField("MASQUE_CAISSE"), "=", Boolean.FALSE)));
-
 
324
        selArticle.andWhere(new Where(tableArticle.getField("VIRTUEL"), "=", Boolean.FALSE));
-
 
325
 
-
 
326
        List<String> tablesDeclinaisons = new ArrayList<>();
-
 
327
        List<String> declinaisonsFieldNames = new ArrayList<>();
-
 
328
        for (SQLField f : tableArticle.getFields()) {
-
 
329
            if (f.getName().startsWith("ID_ARTICLE_DECLINAISON_")) {
-
 
330
                selArticle.addSelect(f);
-
 
331
                declinaisonsFieldNames.add(f.getName());
-
 
332
                tablesDeclinaisons.add(f.getName().substring("ID_".length()));
-
 
333
            }
-
 
334
        }
243
 
335
 
244
        final Categorie cUnclassified = new Categorie("Non classés", true);
336
        final Categorie cUnclassified = new Categorie("Non classés", true);
245
        cUnclassified.setUnknown();
337
        cUnclassified.setUnknown();
-
 
338
 
-
 
339
        // Fetch des declinaisons :
-
 
340
        // "ID_ARTICLE_DECLINAISON_COULEUR" : { {3 , "noir"] } ,
-
 
341
        // "ID_ARTICLE_DECLINAISON_TAILLE" : { {2 ,"XL"},{3,"XXL"}};
-
 
342
        Map<String, Map<Integer, String>> mapDeclinaisons = new HashMap<>();
-
 
343
        for (String table : tablesDeclinaisons) {
-
 
344
            SQLTable t = eltArticle.getTable().getTable(table);
-
 
345
            final SQLSelect selDecl = new SQLSelect();
-
 
346
            selDecl.addSelect(t.getKey());
-
 
347
            selDecl.addSelect(t.getField("NOM"));
-
 
348
            Map<Integer, String> m = new HashMap<>();
-
 
349
            mapDeclinaisons.put("ID_" + table, m);
246
        for (SQLRow row : SQLRowListRSH.execute(selArticle)) {
350
            for (SQLRow row : SQLRowListRSH.execute(selDecl)) {
-
 
351
                m.put(row.getID(), row.getString("NOM"));
-
 
352
            }
-
 
353
        }
-
 
354
        // Fetch des articles
-
 
355
        final List<SQLRow> rArticles = SQLRowListRSH.execute(selArticle);
-
 
356
        List<Integer> idsArticles = new ArrayList<>(rArticles.size());
-
 
357
        for (SQLRow r : rArticles) {
-
 
358
            idsArticles.add(r.getID());
-
 
359
        }
-
 
360
 
-
 
361
        // Recuperation des promos
-
 
362
        final SQLTable tableArticleTairdPromotion = tableArticle.getTable("ARTICLE_TARIF_PROMOTION");
-
 
363
        final SQLTable tableTarifPromotion = tableArticle.getTable("TARIF_PROMOTION");
-
 
364
        SQLRowValues rTarifPromotion = new SQLRowValues(tableArticleTairdPromotion);
-
 
365
        rTarifPromotion.putNulls(tableArticleTairdPromotion.getFieldsName());
-
 
366
        rTarifPromotion.putRowValues("ID_TARIF_PROMOTION").putNulls("START", "END");
-
 
367
        rTarifPromotion.putRowValues("ID_ARTICLE").putNulls("ID_TAXE");
-
 
368
        Where where = new Where(tableArticleTairdPromotion.getField("ID_ARTICLE"), idsArticles);
-
 
369
        Calendar today = Calendar.getInstance();
-
 
370
 
-
 
371
        final SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(rTarifPromotion);
-
 
372
        fetcher.appendSelTransf(new ITransformer<SQLSelect, SQLSelect>() {
-
 
373
 
-
 
374
            @Override
-
 
375
            public SQLSelect transformChecked(SQLSelect input) {
-
 
376
                input.andWhere(new Where(input.getAlias(tableTarifPromotion.getField("START")), "<", today));
-
 
377
                input.andWhere(new Where(input.getAlias(tableTarifPromotion.getField("END")), ">", today));
-
 
378
                return input;
-
 
379
            }
-
 
380
        });
-
 
381
        List<SQLRowValues> rPromotions = fetcher.fetch(where);
-
 
382
        long t1p = System.currentTimeMillis();
-
 
383
        // Tarifs : id article <-> liste des tarifs par quantité
-
 
384
        Map<Integer, List<TarifQuantite>> mapTarif = new HashMap<>();
-
 
385
        System.err.println("CaissePanel.loadArticles()" + rPromotions.size() + " promotions");
-
 
386
        for (SQLRowValues r : rPromotions) {
-
 
387
            final Integer foreignID = ((Integer) r.getObjectNoCheck("ID_ARTICLE"));
-
 
388
            List<TarifQuantite> list = mapTarif.get(foreignID);
-
 
389
            if (list == null) {
-
 
390
                list = new ArrayList<>();
-
 
391
                mapTarif.put(foreignID, list);
-
 
392
            }
-
 
393
            TarifQuantite t = new TarifQuantite(foreignID, r.getInt("QTE"), r.getBigDecimal("PV_HT"), r.getBigDecimal("PV_TTC"), r.getForeign("ID_ARTICLE").getInt("ID_TAXE"));
-
 
394
            list.add(t);
-
 
395
        }
-
 
396
        final List<Article> res = new ArrayList<>(rArticles.size());
-
 
397
        for (SQLRow row : rArticles) {
247
            final int idFamilleArticle = row.getInt("ID_FAMILLE_ARTICLE");
398
            final Integer idFamilleArticle = ((Integer) row.getObjectNoCheck("ID_FAMILLE_ARTICLE"));
248
            Categorie s1 = categoriesMap.get(idFamilleArticle);
399
            Categorie s1 = categoriesMap.get(idFamilleArticle);
249
            if (s1 == null) {
400
            if (s1 == null) {
250
                s1 = cUnclassified;
401
                s1 = cUnclassified;
251
                categoriesMap.put(idFamilleArticle, cUnclassified);
402
                categoriesMap.put(idFamilleArticle, cUnclassified);
252
            }
403
            }
253
            final String name = row.getString("NOM").trim();
404
            final String name = ((String) row.getObjectNoCheck("NOM")).trim();
254
            if (name.length() > 0) {
405
            if (name.length() > 0) {
255
                final Article a = new Article(s1, name, row.getID());
406
                final Article a = new Article(s1, name, row.getID());
256
                final String barcode = row.getString("CODE_BARRE");
407
                final String barcode = (String) row.getObjectNoCheck("CODE_BARRE");
257
                final String code = row.getString("CODE");
408
                final String code = (String) row.getObjectNoCheck("CODE");
258
                a.setBarCode(StringUtils.isEmpty(barcode, true) ? code : barcode);
409
                a.setBarCode(StringUtils.isEmpty(barcode, true) ? code : barcode);
259
                a.setCode(code);
410
                a.setCode(code);
260
                a.setIdTaxe(row.getInt("ID_TAXE"));
411
                a.setIdTaxe(((Integer) row.getObjectNoCheck("ID_TAXE")));
261
                a.setPriceWithoutTax(row.getBigDecimal("PV_HT"));
412
                a.setPriceWithoutTax((BigDecimal) row.getObjectNoCheck("PV_HT"));
262
                a.setPriceWithTax(row.getBigDecimal("PV_TTC"));
413
                a.setPriceWithTax((BigDecimal) row.getObjectNoCheck("PV_TTC"));
263
                a.setAdditionalCopyRequested(row.getBoolean("ADDITIONAL_TICKET_COPY"));
414
                a.setAdditionalCopyRequested((Boolean) row.getObjectNoCheck("ADDITIONAL_TICKET_COPY"));
-
 
415
                final Integer idEcoContribution = ((Integer) row.getObjectNoCheck("ID_ECO_CONTRIBUTION"));
-
 
416
                if (idEcoContribution > 1)
-
 
417
                    a.setEcoTaxe((BigDecimal) row.getForeign("ID_ECO_CONTRIBUTION").getObjectNoCheck("TAUX"));
-
 
418
                final Integer idUniteVente = ((Integer) row.getObjectNoCheck("ID_UNITE_VENTE"));
264
                if (row.getInt("ID_UNITE_VENTE") != 2) {
419
                if (idUniteVente != 2) {
265
                    a.setSalesUnit(mapUniteVenteName.get(row.getInt("ID_UNITE_VENTE")));
420
                    a.setSalesUnit(mapUniteVenteName.get(idUniteVente));
266
                }
421
                }
-
 
422
 
267
                final Integer idProduct = a.getId();
423
                final Integer idProduct = a.getId();
268
                if (favoriteProductsIds.contains(idProduct)) {
424
                if (favoriteProductsIds.contains(idProduct)) {
269
                    favoriteProducts.add(a);
425
                    favoriteProducts.add(a);
270
                }
426
                }
271
 
427
 
-
 
428
                final List<TarifQuantite> promotions = mapTarif.get(row.getID());
-
 
429
                if (promotions != null) {
-
 
430
                    a.setTarifsPromotion(promotions);
-
 
431
                    for (TarifQuantite t : promotions) {
-
 
432
                        if (t.getQuantite() == 1) {
-
 
433
                            a.setIdTaxe(t.getIdTaxe());
-
 
434
                            a.setPriceWithoutTax(t.getPrixHT());
-
 
435
                            a.setPriceWithTax(t.getPrixTTC());
-
 
436
                            break;
272
            }
437
                        }
273
        }
438
                    }
274
        Categorie.setFavoriteProducts(favoriteProducts);
-
 
275
        initCacheArticleMap(dir);
-
 
276
    }
-
 
277
 
439
 
278
    private static Map<Integer, SQLRowAccessor> cacheArticle = new HashMap<>();
440
                }
279
 
441
 
280
    public static SQLRowAccessor getArticleRowValuesFromCache(int id) {
442
                for (String f : declinaisonsFieldNames) {
-
 
443
                    Integer idArtDeclinaison = (Integer) row.getObjectNoCheck(f);
-
 
444
                    if (idArtDeclinaison != null && idArtDeclinaison > 1) {
-
 
445
                        Map<Integer, String> mm = mapDeclinaisons.get(f);
281
        return cacheArticle.get(id);
446
                        if (mm != null) {
-
 
447
                            String v = mm.get(idArtDeclinaison);
-
 
448
                            a.addDeclinaison(f.substring("ID_ARTICLE_DECLINAISON_".length()), v);
-
 
449
                        }
-
 
450
                    }
282
    }
451
                }
283
 
452
 
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());
453
                res.add(a);
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
 
454
 
300
        SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(rowValsArt);
-
 
301
        List<SQLRowValues> res = fetcher.fetch();
-
 
302
        for (SQLRowValues sqlRowValues : res) {
455
            }
303
            cacheArticle.put(sqlRowValues.getID(), sqlRowValues);
-
 
304
        }
456
        }
-
 
457
        long t2p = System.currentTimeMillis();
305
 
458
 
-
 
459
        Categorie.setFavoriteProducts(favoriteProducts);
-
 
460
        ArticleCache.initCache(dir);
-
 
461
        ArticleCache.getInstance().preloadCacheArticleMap(new ArrayList<>(favoriteProductsIds));
-
 
462
        long t2 = System.currentTimeMillis();
-
 
463
        System.err.println("CaissePanel.loadArticles() " + res.size() + " in " + (t2 - t1) + " ms : process: " + (t2p - t1p) + " ms");
-
 
464
        return res;
306
    }
465
    }
307
 
466
 
308
    @Override
467
    @Override
309
    public void paint(Graphics g) {
468
    public void paint(Graphics g) {
310
        System.err.println("CaissePanel.paint()" + this.getWidth() + " x " + this.getHeight());
469
        System.err.println("CaissePanel.paint()" + this.getWidth() + " x " + this.getHeight());
Line 457... Line 616...
457
            // Valider
616
            // Valider
458
            CaissePanel.this.controler.setLCD("Impression de", "votre ticket...", 0);
617
            CaissePanel.this.controler.setLCD("Impression de", "votre ticket...", 0);
459
            try {
618
            try {
460
                caisseFrame.getPOSConf().print(savedReceipt, (savedReceipt.isAdditionnalCopyRequested() ? 1 : 0));
619
                caisseFrame.getPOSConf().print(savedReceipt, (savedReceipt.isAdditionnalCopyRequested() ? 1 : 0));
461
            } catch (UnsatisfiedLinkError ex) {
620
            } catch (UnsatisfiedLinkError ex) {
462
                JOptionPane.showMessageDialog(CaissePanel.this, "Erreur de configuration de la liaison à l'imprimante");
621
                JOptionPane.showMessageDialog(CaissePanel.this, "Erreur de configuration de la liaison à l'imprimante");
463
            } catch (Throwable ex) {
622
            } catch (Throwable ex) {
464
                ex.printStackTrace();
623
                ex.printStackTrace();
465
                JOptionPane.showMessageDialog(CaissePanel.this, "Erreur d'impression du ticket");
624
                JOptionPane.showMessageDialog(CaissePanel.this, "Erreur d'impression du ticket");
466
            }
625
            }
467
 
626
 
468
            CaissePanel.this.controler.setLCDDefaultDisplay(2);
627
            CaissePanel.this.controler.setLCDDefaultDisplay(2);
469
        } else {
628
        } else {
470
            System.err.println("CaissePanel.validateTicket() ticket non sauvé");
629
            System.err.println("CaissePanel.validateTicket() ticket non sauvé");
471
        }
630
        }
472
    }
631
    }
473
}
632
}