OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 181 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 181 Rev 183
Line 6... Line 6...
6
import java.awt.GridBagLayout;
6
import java.awt.GridBagLayout;
7
import java.awt.event.ActionEvent;
7
import java.awt.event.ActionEvent;
8
import java.awt.event.ActionListener;
8
import java.awt.event.ActionListener;
9
import java.awt.event.ItemEvent;
9
import java.awt.event.ItemEvent;
10
import java.awt.event.ItemListener;
10
import java.awt.event.ItemListener;
-
 
11
import java.math.BigDecimal;
11
import java.util.ArrayList;
12
import java.util.ArrayList;
12
import java.util.Collections;
13
import java.util.Collections;
13
import java.util.Comparator;
14
import java.util.Comparator;
-
 
15
import java.util.HashSet;
14
import java.util.List;
16
import java.util.List;
15
import java.util.Set;
17
import java.util.Set;
16
 
18
 
17
import javax.swing.DefaultListCellRenderer;
19
import javax.swing.DefaultListCellRenderer;
18
import javax.swing.JButton;
20
import javax.swing.JButton;
Line 25... Line 27...
25
import javax.swing.SwingWorker;
27
import javax.swing.SwingWorker;
26
 
28
 
27
import org.openconcerto.sql.element.SQLElementDirectory;
29
import org.openconcerto.sql.element.SQLElementDirectory;
28
import org.openconcerto.sql.model.SQLField;
30
import org.openconcerto.sql.model.SQLField;
29
import org.openconcerto.sql.model.SQLRow;
31
import org.openconcerto.sql.model.SQLRow;
-
 
32
import org.openconcerto.sql.model.SQLRowAccessor;
30
import org.openconcerto.sql.model.SQLRowListRSH;
33
import org.openconcerto.sql.model.SQLRowListRSH;
31
import org.openconcerto.sql.model.SQLRowValues;
-
 
32
import org.openconcerto.sql.model.SQLSelect;
34
import org.openconcerto.sql.model.SQLSelect;
33
import org.openconcerto.sql.model.SQLTable;
35
import org.openconcerto.sql.model.SQLTable;
-
 
36
import org.openconcerto.sql.model.Where;
34
import org.openconcerto.sql.request.SQLFieldTranslator;
37
import org.openconcerto.sql.request.SQLFieldTranslator;
35
import org.openconcerto.ui.DefaultGridBagConstraints;
38
import org.openconcerto.ui.DefaultGridBagConstraints;
36
import org.openconcerto.ui.JLabelBold;
39
import org.openconcerto.ui.JLabelBold;
37
import org.openconcerto.ui.ReloadPanel;
40
import org.openconcerto.ui.ReloadPanel;
38
import org.openconcerto.utils.ExceptionHandler;
41
import org.openconcerto.utils.ExceptionHandler;
39
 
42
 
40
public class BatchEditorPanel extends JPanel {
43
public class BatchEditorPanel extends JPanel {
41
 
44
 
42
    public BatchEditorPanel(final SQLElementDirectory dir, final List<SQLRowValues> rows, FieldFilter filter) {
45
    public BatchEditorPanel(final SQLElementDirectory dir, final List<SQLRowAccessor> rows, FieldFilter filter) {
43
        SQLFieldTranslator translator = dir.getTranslator();
46
        SQLFieldTranslator translator = dir.getTranslator();
44
        Set<SQLField> fields = rows.get(0).getTable().getFields();
47
        Set<SQLField> fields = rows.get(0).getTable().getFields();
45
        List<BatchField> f = new ArrayList<BatchField>();
48
        List<BatchField> f = new ArrayList<BatchField>();
46
        for (SQLField sqlField : fields) {
49
        for (SQLField sqlField : fields) {
47
            if (ForbiddenFieldName.isAllowed(sqlField.getName()) && translator.getLabelFor(sqlField) != null) {
50
            if (ForbiddenFieldName.isAllowed(sqlField.getName()) && translator.getLabelFor(sqlField) != null) {
48
                if (filter == null || !filter.isFiltered(sqlField)) {
51
                if (filter == null || !filter.isFiltered(sqlField)) {
49
                    f.add(new BatchField(dir, sqlField, null));
52
                    f.add(new BatchField(dir, sqlField, null));
50
                }
53
                }
51
            }
54
            }
52
        }
55
        }
-
 
56
 
-
 
57
        // Tarif
53
        SQLTable tableTarif = rows.get(0).getTable().getTable("TARIF");
58
        SQLTable tableTarif = rows.get(0).getTable().getTable("TARIF");
54
        SQLTable tableArticleTarif = rows.get(0).getTable().getTable("ARTICLE_TARIF");
59
        SQLTable tableArticleTarif = rows.get(0).getTable().getTable("ARTICLE_TARIF");
55
        SQLSelect sel = new SQLSelect();
60
        SQLSelect sel = new SQLSelect();
56
        sel.addSelectStar(tableTarif);
61
        sel.addSelectStar(tableTarif);
57
        List<SQLRow> rowTarif = SQLRowListRSH.execute(sel);
62
        List<SQLRow> rowTarif = SQLRowListRSH.execute(sel);
Line 60... Line 65...
60
            if (tableArticleTarif.contains("POURCENT_REMISE")) {
65
            if (tableArticleTarif.contains("POURCENT_REMISE")) {
61
                f.add(new BatchField(dir, tableArticleTarif.getField("POURCENT_REMISE"), sqlRow));
66
                f.add(new BatchField(dir, tableArticleTarif.getField("POURCENT_REMISE"), sqlRow));
62
            }
67
            }
63
        }
68
        }
64
 
69
 
-
 
70
        // Tarif Promo
-
 
71
        SQLTable tableTarifPromo = rows.get(0).getTable().getTable("TARIF_PROMOTION");
-
 
72
        SQLTable tableArticleTarifPromo = rows.get(0).getTable().getTable("ARTICLE_TARIF_PROMOTION");
-
 
73
        SQLSelect selT = new SQLSelect();
-
 
74
        selT.addSelectStar(tableTarifPromo);
-
 
75
        List<SQLRow> rowTarifP = SQLRowListRSH.execute(selT);
-
 
76
        for (SQLRow sqlRow : rowTarifP) {
-
 
77
            f.add(new BatchField(dir, tableArticleTarifPromo.getField("PV_HT"), sqlRow));
-
 
78
        }
-
 
79
 
-
 
80
        // Tarif quantite
-
 
81
        SQLTable tableTarifQte = rows.get(0).getTable().getTable("TARIF_QUANTITE");
-
 
82
        SQLSelect selQ = new SQLSelect();
-
 
83
        selQ.addSelectStar(tableTarifQte);
-
 
84
        Where w = Where.inValues(tableTarifQte.getField("ID_" + rows.get(0).getTable().getName()), SQLRow.getIDs(rows));
-
 
85
        selQ.setWhere(w);
-
 
86
        List<SQLRow> rowTarifQ = SQLRowListRSH.execute(selQ);
-
 
87
        Set<BigDecimal> qtes = new HashSet<>();
-
 
88
        for (SQLRow sqlRow : rowTarifQ) {
-
 
89
            final BigDecimal qte = sqlRow.getBigDecimal("QUANTITE");
-
 
90
            if (!qtes.contains(qte)) {
-
 
91
                qtes.add(qte);
-
 
92
                final BatchField batchFieldQte = new BatchField(dir, sqlRow.getTable().getField("PRIX_METRIQUE_VT_1"), null);
-
 
93
                batchFieldQte.setDefaultMatchingValue(sqlRow.getTable().getField("QUANTITE"), qte);
-
 
94
                f.add(batchFieldQte);
-
 
95
                final BatchField batchFieldRemise = new BatchField(dir, sqlRow.getTable().getField("POURCENT_REMISE"), null);
-
 
96
                batchFieldRemise.setDefaultMatchingValue(sqlRow.getTable().getField("QUANTITE"), qte);
-
 
97
                f.add(batchFieldRemise);
-
 
98
            }
-
 
99
        }
-
 
100
 
-
 
101
        // Stock
-
 
102
        SQLTable tableDepotStock = rows.get(0).getTable().getTable("DEPOT_STOCK");
-
 
103
        SQLTable tableStock = tableDepotStock.getTable("STOCK");
-
 
104
        SQLSelect selDepot = new SQLSelect();
-
 
105
        selDepot.addSelectStar(tableDepotStock);
-
 
106
        List<SQLRow> rowDepot = SQLRowListRSH.execute(selDepot);
-
 
107
        for (SQLRow sqlRow : rowDepot) {
-
 
108
            f.add(new BatchField(dir, tableStock.getField("QTE_MIN"), sqlRow));
-
 
109
        }
-
 
110
 
65
        Collections.sort(f, new Comparator<BatchField>() {
111
        Collections.sort(f, new Comparator<BatchField>() {
66
 
112
 
67
            @Override
113
            @Override
68
            public int compare(BatchField o1, BatchField o2) {
114
            public int compare(BatchField o1, BatchField o2) {
69
                return o1.getComboName().compareToIgnoreCase(o2.getComboName());
115
                return o1.getComboName().compareToIgnoreCase(o2.getComboName());