OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 156 Rev 174
Line 19... Line 19...
19
import org.openconcerto.erp.core.sales.pos.io.BarcodeReader;
19
import org.openconcerto.erp.core.sales.pos.io.BarcodeReader;
20
import org.openconcerto.erp.core.sales.pos.ui.BarcodeListener;
20
import org.openconcerto.erp.core.sales.pos.ui.BarcodeListener;
21
import org.openconcerto.erp.core.sales.product.element.ReferenceArticleSQLElement;
21
import org.openconcerto.erp.core.sales.product.element.ReferenceArticleSQLElement;
22
import org.openconcerto.erp.core.sales.product.element.UniteVenteArticleSQLElement;
22
import org.openconcerto.erp.core.sales.product.element.UniteVenteArticleSQLElement;
23
import org.openconcerto.erp.core.sales.product.ui.CurrencyWithSymbolRenderer;
23
import org.openconcerto.erp.core.sales.product.ui.CurrencyWithSymbolRenderer;
-
 
24
import org.openconcerto.erp.core.sales.product.ui.DeliveredQtyRowValuesRenderer;
24
import org.openconcerto.erp.core.sales.product.ui.QteUnitRowValuesRenderer;
25
import org.openconcerto.erp.core.sales.product.ui.QteUnitRowValuesRenderer;
25
import org.openconcerto.erp.preferences.DefaultNXProps;
26
import org.openconcerto.erp.preferences.DefaultNXProps;
26
import org.openconcerto.erp.preferences.GestionArticleGlobalPreferencePanel;
27
import org.openconcerto.erp.preferences.GestionArticleGlobalPreferencePanel;
27
import org.openconcerto.sql.Configuration;
28
import org.openconcerto.sql.Configuration;
28
import org.openconcerto.sql.element.SQLElement;
29
import org.openconcerto.sql.element.SQLElement;
Line 47... Line 48...
47
import org.openconcerto.sql.view.list.ValidStateChecker;
48
import org.openconcerto.sql.view.list.ValidStateChecker;
48
import org.openconcerto.utils.DecimalUtils;
49
import org.openconcerto.utils.DecimalUtils;
49
import org.openconcerto.utils.Tuple3;
50
import org.openconcerto.utils.Tuple3;
50
import org.openconcerto.utils.i18n.TranslationManager;
51
import org.openconcerto.utils.i18n.TranslationManager;
51
 
52
 
-
 
53
import java.awt.Component;
52
import java.awt.event.ActionEvent;
54
import java.awt.event.ActionEvent;
53
import java.awt.event.HierarchyEvent;
55
import java.awt.event.HierarchyEvent;
54
import java.awt.event.HierarchyListener;
56
import java.awt.event.HierarchyListener;
55
import java.awt.event.KeyEvent;
57
import java.awt.event.KeyEvent;
56
import java.awt.event.MouseAdapter;
58
import java.awt.event.MouseAdapter;
Line 67... Line 69...
67
import java.util.Set;
69
import java.util.Set;
68
import java.util.Vector;
70
import java.util.Vector;
69
 
71
 
70
import javax.swing.AbstractAction;
72
import javax.swing.AbstractAction;
71
import javax.swing.JFrame;
73
import javax.swing.JFrame;
-
 
74
import javax.swing.JLabel;
72
import javax.swing.JOptionPane;
75
import javax.swing.JOptionPane;
73
import javax.swing.JPopupMenu;
76
import javax.swing.JPopupMenu;
74
import javax.swing.JTable;
77
import javax.swing.JTable;
75
import javax.swing.SwingUtilities;
78
import javax.swing.SwingUtilities;
76
import javax.swing.ToolTipManager;
79
import javax.swing.ToolTipManager;
77
import javax.swing.event.TableModelEvent;
80
import javax.swing.event.TableModelEvent;
78
import javax.swing.event.TableModelListener;
81
import javax.swing.event.TableModelListener;
-
 
82
import javax.swing.table.DefaultTableCellRenderer;
79
import javax.swing.table.TableCellRenderer;
83
import javax.swing.table.TableCellRenderer;
80
 
84
 
81
public abstract class AbstractAchatArticleItemTable extends AbstractArticleItemTable {
85
public abstract class AbstractAchatArticleItemTable extends AbstractArticleItemTable {
82
 
86
 
83
    private AutoCompletionManager m;
87
    private AutoCompletionManager m;
Line 132... Line 136...
132
        if (showDmdAchat && e.getTable().contains("ID_DEMANDE_ACHAT_ELEMENT")) {
136
        if (showDmdAchat && e.getTable().contains("ID_DEMANDE_ACHAT_ELEMENT")) {
133
            dmdElt = new SQLTableElement(e.getTable().getField("ID_DEMANDE_ACHAT_ELEMENT"));
137
            dmdElt = new SQLTableElement(e.getTable().getField("ID_DEMANDE_ACHAT_ELEMENT"));
134
            list.add(dmdElt);
138
            list.add(dmdElt);
135
        }
139
        }
136
 
140
 
-
 
141
        if (e.getTable().contains("ID_AFFAIRE")) {
-
 
142
            list.add(new SQLTableElement(e.getTable().getField("ID_AFFAIRE")));
-
 
143
        }
-
 
144
 
137
        SQLTableElement tableElementCodeFournisseur = null;
145
        SQLTableElement tableElementCodeFournisseur = null;
138
 
146
 
139
        if (e.getTable().contains("ID_CODE_FOURNISSEUR") && supplierCode) {
147
        if (e.getTable().contains("ID_CODE_FOURNISSEUR") && supplierCode) {
140
            tableElementCodeFournisseur = new SQLTableElement(e.getTable().getField("ID_CODE_FOURNISSEUR"), true, true, true);
148
            tableElementCodeFournisseur = new SQLTableElement(e.getTable().getField("ID_CODE_FOURNISSEUR"), true, true, true);
141
            list.add(tableElementCodeFournisseur);
149
            list.add(tableElementCodeFournisseur);
142
        }
150
        }
143
 
151
 
-
 
152
        if (e.getTable().contains("ID_COMPTE_PCE")) {
-
 
153
            list.add(new SQLTableElement(e.getTable().getField("ID_COMPTE_PCE")));
-
 
154
        }
-
 
155
 
144
        SQLTableElement tableElementArticle = new SQLTableElement(e.getTable().getField("ID_ARTICLE"), true, true, true) {
156
        SQLTableElement tableElementArticle = new SQLTableElement(e.getTable().getField("ID_ARTICLE"), true, true, true) {
145
            @Override
157
            @Override
146
            public boolean isCellEditable(SQLRowValues vals, int rowIndex, int columnIndex) {
158
            public boolean isCellEditable(SQLRowValues vals, int rowIndex, int columnIndex) {
147
                boolean b = super.isCellEditable(vals, rowIndex, columnIndex);
159
                boolean b = super.isCellEditable(vals, rowIndex, columnIndex);
148
                if (vals.getTable().contains("ID_COMMANDE_ELEMENT")) {
160
                if (vals.getTable().contains("ID_COMMANDE_ELEMENT")) {
Line 212... Line 224...
212
 
224
 
213
            }
225
            }
214
        };
226
        };
215
        list.add(tableElementNom);
227
        list.add(tableElementNom);
216
 
228
 
217
        SQLTableElement tableCmdElt = null;
-
 
218
        if (e.getTable().contains("ID_COMMANDE_ELEMENT")) {
-
 
219
            tableCmdElt = new SQLTableElement(e.getTable().getField("ID_COMMANDE_ELEMENT"));
-
 
220
            list.add(tableCmdElt);
-
 
221
        }
-
 
222
 
-
 
223
        if (e.getTable().getFieldsName().contains("DESCRIPTIF")) {
229
        if (e.getTable().getFieldsName().contains("DESCRIPTIF")) {
224
            final SQLTableElement tableElementDesc = new SQLTableElement(e.getTable().getField("DESCRIPTIF"));
230
            final SQLTableElement tableElementDesc = new SQLTableElement(e.getTable().getField("DESCRIPTIF"));
225
            list.add(tableElementDesc);
231
            list.add(tableElementDesc);
226
        }
232
        }
227
        if (e.getTable().getFieldsName().contains("COLORIS")) {
233
        if (e.getTable().getFieldsName().contains("COLORIS")) {
Line 291... Line 297...
291
        list.add(qteU);
297
        list.add(qteU);
292
 
298
 
293
        SQLTableElement uniteVente = new SQLTableElement(e.getTable().getField("ID_UNITE_VENTE"));
299
        SQLTableElement uniteVente = new SQLTableElement(e.getTable().getField("ID_UNITE_VENTE"));
294
        list.add(uniteVente);
300
        list.add(uniteVente);
295
 
301
 
-
 
302
        SQLTableElement tableCmdElt = null;
-
 
303
        if (e.getTable().contains("ID_COMMANDE_ELEMENT")) {
-
 
304
            tableCmdElt = new SQLTableElement(e.getTable().getField("ID_COMMANDE_ELEMENT"));
-
 
305
            tableCmdElt.setRenderer(new DefaultTableCellRenderer() {
-
 
306
                @Override
-
 
307
                public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
-
 
308
                    SQLRowValues rowVals = getRowValuesTable().getRowValuesTableModel().getRowValuesAt(row);
-
 
309
 
-
 
310
                    JLabel tableCellRendererComponent = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
-
 
311
                    tableCellRendererComponent.setText("");
-
 
312
                    if (rowVals.getObject("ID_COMMANDE_ELEMENT") != null && !rowVals.isForeignEmpty("ID_COMMANDE_ELEMENT")) {
-
 
313
                        SQLRowAccessor rowCmdItem = rowVals.getForeign("ID_COMMANDE_ELEMENT");
-
 
314
                        int qte = rowCmdItem.getInt("QTE");
-
 
315
                        BigDecimal qteU = rowCmdItem.getBigDecimal("QTE_UNITAIRE");
-
 
316
                        BigDecimal qteR = rowCmdItem.getBigDecimal("QTE_RECUE");
-
 
317
                        qteU = qteU.multiply(new BigDecimal(qte));
-
 
318
                        if (qteR != null) {
-
 
319
                            tableCellRendererComponent.setText(qteU.subtract(qteR).setScale(2, RoundingMode.HALF_UP).toString());
-
 
320
                        } else {
-
 
321
                            tableCellRendererComponent.setText(qteU.setScale(2, RoundingMode.HALF_UP).toString());
-
 
322
                        }
-
 
323
                    }
-
 
324
 
-
 
325
                    return tableCellRendererComponent;
-
 
326
                }
-
 
327
            });
-
 
328
            tableCmdElt.setEditable(false);
-
 
329
            list.add(tableCmdElt);
-
 
330
        }
-
 
331
 
296
        if (e.getTable().getFieldsName().contains("QTE_ORIGINE")) {
332
        if (e.getTable().getFieldsName().contains("QTE_ORIGINE")) {
297
            final SQLTableElement tableQteO = new SQLTableElement(e.getTable().getField("QTE_ORIGINE"));
333
            final SQLTableElement tableQteO = new SQLTableElement(e.getTable().getField("QTE_ORIGINE"));
298
            tableQteO.setEditable(false);
334
            tableQteO.setEditable(false);
299
            list.add(tableQteO);
335
            list.add(tableQteO);
300
        }
336
        }
Line 303... Line 339...
303
        final SQLTableElement qteElement = new SQLTableElement(e.getTable().getField("QTE"), Integer.class) {
339
        final SQLTableElement qteElement = new SQLTableElement(e.getTable().getField("QTE"), Integer.class) {
304
            protected Object getDefaultNullValue() {
340
            protected Object getDefaultNullValue() {
305
                return Integer.valueOf(0);
341
                return Integer.valueOf(0);
306
            }
342
            }
307
        };
343
        };
-
 
344
        if (e.getTable().getFieldsName().contains("QTE_ORIGINE")) {
-
 
345
            qteElement.setRenderer(new DeliveredQtyRowValuesRenderer(false));
-
 
346
        }
308
        list.add(qteElement);
347
        list.add(qteElement);
309
        // TVA
348
        // TVA
310
        this.tableElementTVA = new SQLTableElement(e.getTable().getField("ID_TAXE"));
349
        this.tableElementTVA = new SQLTableElement(e.getTable().getField("ID_TAXE"));
311
        list.add(this.tableElementTVA);
350
        list.add(this.tableElementTVA);
312
        // Poids piece
351
        // Poids piece
Line 326... Line 365...
326
        }
365
        }
327
 
366
 
328
        if (showDevise) {
367
        if (showDevise) {
329
            // Prix d'achat HT devise
368
            // Prix d'achat HT devise
330
            this.tableElementTotalDevise = new SQLTableElement(e.getTable().getField("PA_DEVISE_T"), BigDecimal.class);
369
            this.tableElementTotalDevise = new SQLTableElement(e.getTable().getField("PA_DEVISE_T"), BigDecimal.class);
331
            this.tableElementTotalDevise.setRenderer(new CurrencyWithSymbolRenderer(new FieldPath(p, "CODE")));
370
            CurrencyWithSymbolRenderer deviseTotalRenderer = new CurrencyWithSymbolRenderer(new FieldPath(p, "CODE"));
-
 
371
            deviseTotalRenderer.setHideZeroValue(true);
-
 
372
            this.tableElementTotalDevise.setRenderer(deviseTotalRenderer);
332
            list.add(tableElementTotalDevise);
373
            list.add(tableElementTotalDevise);
333
        }
374
        }
334
 
375
 
335
        SQLTableElement tableElementRemise = null;
376
        SQLTableElement tableElementRemise = null;
336
        if (e.getTable().contains("POURCENT_REMISE")) {
377
        if (e.getTable().contains("POURCENT_REMISE")) {
Line 343... Line 384...
343
            list.add(this.tableElementEcoTotal);
384
            list.add(this.tableElementEcoTotal);
344
        }
385
        }
345
 
386
 
346
        // Total HT
387
        // Total HT
347
        this.totalHT = new SQLTableElement(e.getTable().getField("T_PA_HT"), BigDecimal.class);
388
        this.totalHT = new SQLTableElement(e.getTable().getField("T_PA_HT"), BigDecimal.class);
-
 
389
        DeviseTableCellRenderer totalRenderer = new DeviseTableCellRenderer();
-
 
390
        totalRenderer.setHideZeroValue(true);
348
        this.totalHT.setRenderer(new DeviseTableCellRenderer());
391
        this.totalHT.setRenderer(totalRenderer);
349
        this.totalHT.setEditable(false);
392
        this.totalHT.setEditable(false);
350
        if (e.getTable().contains("POURCENT_REMISE") && tableElementRemise != null) {
393
        if (e.getTable().contains("POURCENT_REMISE") && tableElementRemise != null) {
351
            tableElementRemise.addModificationListener(this.totalHT);
394
            tableElementRemise.addModificationListener(this.totalHT);
352
        }
395
        }
353
        list.add(this.totalHT);
396
        list.add(this.totalHT);
354
        this.totalHA = this.totalHT;
397
        this.totalHA = this.totalHT;
355
        // Total TTC
398
        // Total TTC
356
        this.tableElementTotalTTC = new SQLTableElement(e.getTable().getField("T_PA_TTC"), BigDecimal.class);
399
        this.tableElementTotalTTC = new SQLTableElement(e.getTable().getField("T_PA_TTC"), BigDecimal.class);
357
        this.tableElementTotalTTC.setRenderer(new DeviseTableCellRenderer());
400
        this.tableElementTotalTTC.setRenderer(totalRenderer);
358
        list.add(this.tableElementTotalTTC);
401
        list.add(this.tableElementTotalTTC);
359
 
402
 
360
        this.defaultRowVals = new SQLRowValues(UndefinedRowValuesCache.getInstance().getDefaultRowValues(e.getTable()));
403
        this.defaultRowVals = new SQLRowValues(UndefinedRowValuesCache.getInstance().getDefaultRowValues(e.getTable()));
361
        this.defaultRowVals.put("ID_TAXE", TaxeCache.getCache().getFirstTaxe().getID());
404
        this.defaultRowVals.put("ID_TAXE", TaxeCache.getCache().getFirstTaxe().getID());
362
        this.defaultRowVals.put("CODE", "");
405
        this.defaultRowVals.put("CODE", "");
Line 918... Line 961...
918
    }
961
    }
919
 
962
 
920
    public Object tarifCompletion(SQLRow row, String field) {
963
    public Object tarifCompletion(SQLRow row, String field) {
921
        final SQLTable tTarifFournisseur = this.getSQLElement().getTable().getDBRoot().getTable("ARTICLE_TARIF_FOURNISSEUR");
964
        final SQLTable tTarifFournisseur = this.getSQLElement().getTable().getDBRoot().getTable("ARTICLE_TARIF_FOURNISSEUR");
922
 
965
 
923
        if (row != null && !row.isUndefined() && field.equalsIgnoreCase("PRIX_METRIQUE_HA_1") && tTarifFournisseur != null) {
966
        if (row != null && !row.isUndefined() && (field.equalsIgnoreCase("PRIX_METRIQUE_HA_1") || field.equalsIgnoreCase("PA_HT")) && tTarifFournisseur != null) {
924
            List<String> incoTerms;
967
            List<String> incoTerms;
925
 
968
 
926
            if (this.incoterm != null && this.incoterm.equalsIgnoreCase("CPT")) {
969
            if (this.incoterm != null && this.incoterm.equalsIgnoreCase("CPT")) {
927
                incoTerms = Arrays.asList("PRIX_ACHAT", "COEF_TRANSPORT_PORT");
970
                incoTerms = Arrays.asList("PRIX_ACHAT", "COEF_TRANSPORT_PORT");
928
            } else if (this.incoterm != null && this.incoterm.equalsIgnoreCase("DDP")) {
971
            } else if (this.incoterm != null && this.incoterm.equalsIgnoreCase("DDP")) {
Line 942... Line 985...
942
                    boolean priceFound = false;
985
                    boolean priceFound = false;
943
                    boolean tarifFound = false;
986
                    boolean tarifFound = false;
944
                    if (rowsT.size() > 0) {
987
                    if (rowsT.size() > 0) {
945
                        BigDecimal min = BigDecimal.ZERO;
988
                        BigDecimal min = BigDecimal.ZERO;
946
 
989
 
947
                        BigDecimal defaultPrice = BigDecimal.ZERO;
990
                        BigDecimal defaultPrice = sqlRow.getForeign("ID_ARTICLE").getBigDecimal("PRIX_METRIQUE_HA_1");
948
                        Calendar c = null;
991
                        Calendar c = null;
949
                        for (SQLRow sqlRowT : rowsT) {
992
                        for (SQLRow sqlRowT : rowsT) {
950
                            if (this.rowFournisseur != null && this.rowFournisseur.getID() == sqlRowT.getForeignID("ID_FOURNISSEUR")) {
993
                            if (this.rowFournisseur != null && this.rowFournisseur.getID() == sqlRowT.getForeignID("ID_FOURNISSEUR")) {
951
                                BigDecimal priceT = getPrice(sqlRowT, incoTerms);
994
                                BigDecimal priceT = getPrice(sqlRowT, incoTerms);
952
                                defaultPrice = priceT;
995
                                defaultPrice = priceT;
Line 989... Line 1032...
989
                        }
1032
                        }
990
                    });
1033
                    });
991
                }
1034
                }
992
                return price;
1035
                return price;
993
            } else if (!rows.isEmpty()) {
1036
            } else if (!rows.isEmpty()) {
-
 
1037
 
994
                BigDecimal min = BigDecimal.ZERO;
1038
                BigDecimal min = row.getBigDecimal("PRIX_METRIQUE_HA_1");
-
 
1039
 
995
                Calendar c = null;
1040
                Calendar c = null;
996
                for (SQLRow sqlRow : rows) {
1041
                for (SQLRow sqlRow : rows) {
997
                    if (this.rowFournisseur != null && this.rowFournisseur.getID() == sqlRow.getForeignID("ID_FOURNISSEUR")) {
1042
                    if (this.rowFournisseur != null && this.rowFournisseur.getID() == sqlRow.getForeignID("ID_FOURNISSEUR")) {
998
                        BigDecimal price = getPrice(sqlRow, incoTerms);
1043
                        BigDecimal price = getPrice(sqlRow, incoTerms);
999
                        final Calendar datePrice = sqlRow.getDate("DATE_PRIX");
1044
                        final Calendar datePrice = sqlRow.getDate("DATE_PRIX");