OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 142 Rev 156
Line 20... Line 20...
20
import org.openconcerto.erp.core.sales.product.ui.FamilleArticlePanel;
20
import org.openconcerto.erp.core.sales.product.ui.FamilleArticlePanel;
21
import org.openconcerto.erp.panel.ITreeSelection;
21
import org.openconcerto.erp.panel.ITreeSelection;
22
import org.openconcerto.sql.Configuration;
22
import org.openconcerto.sql.Configuration;
23
import org.openconcerto.sql.element.SQLElement;
23
import org.openconcerto.sql.element.SQLElement;
24
import org.openconcerto.sql.model.FieldPath;
24
import org.openconcerto.sql.model.FieldPath;
25
import org.openconcerto.sql.model.SQLRow;
-
 
26
import org.openconcerto.sql.model.SQLRowAccessor;
25
import org.openconcerto.sql.model.SQLRowAccessor;
27
import org.openconcerto.sql.model.SQLRowValues;
26
import org.openconcerto.sql.model.SQLRowValues;
-
 
27
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
28
import org.openconcerto.sql.model.SQLSelect;
28
import org.openconcerto.sql.model.SQLSelect;
29
import org.openconcerto.sql.model.SQLTable;
29
import org.openconcerto.sql.model.SQLTable;
30
import org.openconcerto.sql.model.Where;
30
import org.openconcerto.sql.model.Where;
31
import org.openconcerto.sql.model.graph.Path;
31
import org.openconcerto.sql.model.graph.Path;
-
 
32
import org.openconcerto.sql.preferences.SQLPreferences;
32
import org.openconcerto.sql.request.ListSQLRequest;
33
import org.openconcerto.sql.request.ListSQLRequest;
33
import org.openconcerto.sql.request.UpdateBuilder;
34
import org.openconcerto.sql.request.UpdateBuilder;
34
import org.openconcerto.sql.view.ListeAddPanel;
35
import org.openconcerto.sql.view.ListeAddPanel;
35
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn;
36
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn;
36
import org.openconcerto.sql.view.list.IListe;
37
import org.openconcerto.sql.view.list.IListe;
Line 50... Line 51...
50
import java.awt.event.ActionListener;
51
import java.awt.event.ActionListener;
51
import java.beans.PropertyChangeEvent;
52
import java.beans.PropertyChangeEvent;
52
import java.beans.PropertyChangeListener;
53
import java.beans.PropertyChangeListener;
53
import java.math.BigDecimal;
54
import java.math.BigDecimal;
54
import java.util.ArrayList;
55
import java.util.ArrayList;
-
 
56
import java.util.HashSet;
55
import java.util.List;
57
import java.util.List;
56
import java.util.Set;
58
import java.util.Set;
57
 
59
 
58
import javax.swing.Action;
60
import javax.swing.Action;
59
import javax.swing.JButton;
61
import javax.swing.JButton;
Line 80... Line 82...
80
    public JFrame createFrame() {
82
    public JFrame createFrame() {
81
        final SQLElement elt = Configuration.getInstance().getDirectory().getElement(this.sqlTableArticle);
83
        final SQLElement elt = Configuration.getInstance().getDirectory().getElement(this.sqlTableArticle);
82
        final FamilleArticlePanel panelFam = new FamilleArticlePanel(elt.getForeignElement("ID_FAMILLE_ARTICLE"));
84
        final FamilleArticlePanel panelFam = new FamilleArticlePanel(elt.getForeignElement("ID_FAMILLE_ARTICLE"));
83
 
85
 
84
        final SQLTableModelSourceOnline createTableSource = elt.createTableSource();
86
        final SQLTableModelSourceOnline createTableSource = elt.createTableSource();
-
 
87
        SQLPreferences prefs = SQLPreferences.getMemCached(elt.getTable().getDBRoot());
85
 
88
 
86
        SQLTableModelColumn colStock;
89
        SQLTableModelColumn colStock = null;
-
 
90
        // if (!prefs.getBoolean(GestionArticleGlobalPreferencePanel.STOCK_MULTI_DEPOT, false)) {
87
        if (elt.getTable().getDBRoot().contains("ARTICLE_PRIX_REVIENT")) {
91
        if (elt.getTable().getDBRoot().contains("ARTICLE_PRIX_REVIENT")) {
88
            colStock = createTableSource.getColumn(createTableSource.getColumns().size() - 2);
92
            colStock = createTableSource.getColumn(createTableSource.getColumns().size() - 2);
89
        } else {
93
        } else {
90
 
94
 
91
            colStock = new BaseSQLTableModelColumn("Valeur HT du stock", BigDecimal.class) {
95
            colStock = new BaseSQLTableModelColumn("Valeur HT du stock", BigDecimal.class) {
Line 118... Line 122...
118
                }
122
                }
119
            };
123
            };
120
            colStock.setRenderer(ComptaSQLConfElement.CURRENCY_RENDERER);
124
            colStock.setRenderer(ComptaSQLConfElement.CURRENCY_RENDERER);
121
            createTableSource.getColumns().add(colStock);
125
            createTableSource.getColumns().add(colStock);
122
        }
126
        }
123
        // createTableSource.getColumns().add(colStock);
127
        // }
124
        final IListe liste = new IListe(createTableSource);
128
        final IListe liste = new IListe(createTableSource);
125
 
129
 
126
        final ListeAddPanel panel = new ListeAddPanel(elt, liste) {
130
        final ListeAddPanel panel = new ListeAddPanel(elt, liste) {
127
            @Override
131
            @Override
128
            protected void handleAction(final JButton source, final ActionEvent evt) {
132
            protected void handleAction(final JButton source, final ActionEvent evt) {
129
                if (source == this.buttonEffacer && getListe().fetchSelectedRow() != null) {
133
                if (source == this.buttonEffacer && getListe().fetchSelectedRow() != null) {
130
                    JPanel panel = new JPanel();
134
                    JPanel panel = new JPanel();
131
                    GridBagConstraints c = new DefaultGridBagConstraints();
135
                    GridBagConstraints c = new DefaultGridBagConstraints();
132
                    c.gridwidth = 2;
136
                    c.gridwidth = 2;
133
                    panel.add(new JLabel("Voulez vous supprimer ou rendre obsoléte?"), c);
137
                    panel.add(new JLabel("Voulez vous supprimer ou rendre obsoléte?"), c);
134
                    JButton buttonObs = new JButton("Obsoléte");
138
                    JButton buttonObs = new JButton("Obsolète");
135
                    JButton buttonSuppr = new JButton("Supprimer");
139
                    JButton buttonSuppr = new JButton("Supprimer");
136
                    c.gridy++;
140
                    c.gridy++;
137
                    panel.add(buttonObs, c);
141
                    panel.add(buttonObs, c);
138
                    c.gridx++;
142
                    c.gridx++;
139
                    panel.add(buttonSuppr, c);
143
                    panel.add(buttonSuppr, c);
Line 203... Line 207...
203
        // }
207
        // }
204
        // }
208
        // }
205
        // });
209
        // });
206
        // }
210
        // }
207
        // }
211
        // }
-
 
212
 
-
 
213
        if (colStock != null) {
-
 
214
            // && !prefs.getBoolean(GestionArticleGlobalPreferencePanel.STOCK_MULTI_DEPOT, false)) {
208
        List<Tuple2<? extends SQLTableModelColumn, IListTotalPanel.Type>> fields = new ArrayList<Tuple2<? extends SQLTableModelColumn, IListTotalPanel.Type>>(1);
215
            List<Tuple2<? extends SQLTableModelColumn, IListTotalPanel.Type>> fields = new ArrayList<Tuple2<? extends SQLTableModelColumn, IListTotalPanel.Type>>(1);
209
        fields.add(Tuple2.create(colStock, IListTotalPanel.Type.SOMME));
216
            fields.add(Tuple2.create(colStock, IListTotalPanel.Type.SOMME));
210
 
217
 
211
        IListTotalPanel total = new IListTotalPanel(liste, fields, null, "Total");
218
            IListTotalPanel total = new IListTotalPanel(liste, fields, null, "Total");
212
        GridBagConstraints c2 = new DefaultGridBagConstraints();
219
            GridBagConstraints c2 = new DefaultGridBagConstraints();
213
        c2.gridy = 4;
220
            c2.gridy = 4;
214
        c2.anchor = GridBagConstraints.EAST;
221
            c2.anchor = GridBagConstraints.EAST;
215
        c2.weightx = 0;
222
            c2.weightx = 0;
216
        c2.fill = GridBagConstraints.NONE;
223
            c2.fill = GridBagConstraints.NONE;
217
        panel.add(total, c2);
224
            panel.add(total, c2);
218
 
225
        }
219
        JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(panelFam), panel);
226
        JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(panelFam), panel);
220
        JPanel panelAll = new JPanel(new GridBagLayout());
227
        JPanel panelAll = new JPanel(new GridBagLayout());
221
        GridBagConstraints c = new DefaultGridBagConstraints();
228
        GridBagConstraints c = new DefaultGridBagConstraints();
222
        c.fill = GridBagConstraints.BOTH;
229
        c.fill = GridBagConstraints.BOTH;
223
        c.weightx = 1;
230
        c.weightx = 1;
Line 298... Line 305...
298
        Where w = null;
305
        Where w = null;
299
 
306
 
300
        if (panel.getCheckObsolete().isSelected()) {
307
        if (panel.getCheckObsolete().isSelected()) {
301
            w = new Where(this.sqlTableArticle.getField("OBSOLETE"), "=", Boolean.FALSE);
308
            w = new Where(this.sqlTableArticle.getField("OBSOLETE"), "=", Boolean.FALSE);
302
 
309
 
-
 
310
            // FIXME Fonctionnement avec multidepot
-
 
311
            // w = w.or(new
303
            w = w.or(new Where(request.getAlias(this.sqlTableArticle.getForeignTable("ID_STOCK").getField("QTE_REEL")), ">", 0));
312
            // Where(request.getAlias(this.sqlTableArticle.getForeignTable("ID_STOCK").getField("QTE_REEL")),
-
 
313
            // ">", 0));
304
        }
314
        }
305
 
315
 
306
        if (id > 1) {
316
        if (id > 1) {
307
            SQLRow row = this.sqlTableFamilleArticle.getRow(id);
317
            Set<Integer> idsMatch = new HashSet<>();
-
 
318
            idsMatch.add(id);
308
 
319
 
309
            Where w2 = new Where(this.sqlTableArticle.getField("ID_FAMILLE_ARTICLE"), "=", this.sqlTableFamilleArticle.getKey());
-
 
310
 
-
 
311
            String code = row.getString("CODE") + ".%";
-
 
312
            final Where w3 = new Where(this.sqlTableFamilleArticle.getField("CODE"), "LIKE", code);
-
 
313
            w2 = w2.and(w3.or(new Where(this.sqlTableFamilleArticle.getKey(), "=", id)));
320
            fillChildren(idsMatch, CollectionUtils.createSet(id));
314
 
321
 
-
 
322
            Where w2 = new Where(this.sqlTableArticle.getField("ID_FAMILLE_ARTICLE"), "=", this.sqlTableFamilleArticle.getKey());
-
 
323
            w2 = w2.and(new Where(this.sqlTableFamilleArticle.getKey(), idsMatch));
315
            if (w != null) {
324
            if (w != null) {
316
                w = w.and(w2);
325
                w = w.and(w2);
317
            } else {
326
            } else {
318
                w = w2;
327
                w = w2;
319
            }
328
            }
320
 
329
 
321
        }
330
        }
322
        return w;
331
        return w;
323
    }
332
    }
-
 
333
 
-
 
334
    private void fillChildren(Set<Integer> idsMatch, Set<Integer> father) {
-
 
335
        SQLRowValues rowVals = new SQLRowValues(this.sqlTableFamilleArticle);
-
 
336
        final String keyFieldName = rowVals.getTable().getKey().getName();
-
 
337
        rowVals.put(keyFieldName, null);
-
 
338
        SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(rowVals);
-
 
339
        List<SQLRowValues> children = fetcher.fetch(new Where(this.sqlTableFamilleArticle.getField("ID_FAMILLE_ARTICLE_PERE"), father));
-
 
340
        Set<Integer> childToCheck = new HashSet<>();
-
 
341
        for (SQLRowValues child : children) {
-
 
342
            if (!idsMatch.contains(child.getID())) {
-
 
343
                childToCheck.add(child.getID());
-
 
344
                idsMatch.add(child.getID());
-
 
345
            }
-
 
346
        }
-
 
347
        if (!childToCheck.isEmpty()) {
-
 
348
            fillChildren(idsMatch, childToCheck);
-
 
349
        }
-
 
350
 
-
 
351
    }
324
}
352
}