OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 142 | Rev 174 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 142 Rev 156
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 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.
10
 * 
10
 * 
11
 * When distributing the software, include this License Header Notice in each file.
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.erp.core.sales.order.action;
14
 package org.openconcerto.erp.core.sales.order.action;
15
 
15
 
16
import org.openconcerto.erp.action.CreateFrameAbstractAction;
16
import org.openconcerto.erp.action.CreateIListFrameAbstractAction;
-
 
17
import org.openconcerto.erp.config.ComptaPropsConfiguration;
17
import org.openconcerto.erp.core.common.ui.IListFilterDatePanel;
18
import org.openconcerto.erp.core.common.ui.IListFilterDatePanel;
18
import org.openconcerto.erp.core.common.ui.ListeViewPanel;
19
import org.openconcerto.erp.core.common.ui.ListeViewPanel;
19
import org.openconcerto.erp.core.sales.order.element.CommandeClientElementSQLElement;
20
import org.openconcerto.erp.core.sales.order.element.CommandeClientElementSQLElement;
20
import org.openconcerto.sql.Configuration;
21
import org.openconcerto.erp.core.supplychain.stock.element.StockSQLElement;
-
 
22
import org.openconcerto.erp.preferences.GestionArticleGlobalPreferencePanel;
21
import org.openconcerto.sql.element.SQLElement;
23
import org.openconcerto.sql.element.SQLElement;
22
import org.openconcerto.sql.model.FieldPath;
24
import org.openconcerto.sql.model.FieldPath;
23
import org.openconcerto.sql.model.FieldRef;
25
import org.openconcerto.sql.model.FieldRef;
24
import org.openconcerto.sql.model.SQLName;
26
import org.openconcerto.sql.model.SQLName;
25
import org.openconcerto.sql.model.SQLRowAccessor;
27
import org.openconcerto.sql.model.SQLRowAccessor;
26
import org.openconcerto.sql.model.SQLRowValues;
28
import org.openconcerto.sql.model.SQLRowValues;
27
import org.openconcerto.sql.model.SQLSelect;
29
import org.openconcerto.sql.model.SQLSelect;
28
import org.openconcerto.sql.model.SQLSelectJoin;
30
import org.openconcerto.sql.model.SQLSelectJoin;
29
import org.openconcerto.sql.model.Where;
31
import org.openconcerto.sql.model.Where;
30
import org.openconcerto.sql.model.graph.Path;
32
import org.openconcerto.sql.model.graph.Path;
-
 
33
import org.openconcerto.sql.preferences.SQLPreferences;
31
import org.openconcerto.sql.view.IListFrame;
34
import org.openconcerto.sql.view.IListFrame;
32
import org.openconcerto.sql.view.ListeAddPanel;
35
import org.openconcerto.sql.view.IListPanel;
33
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn;
36
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn;
34
import org.openconcerto.sql.view.list.IListe;
37
import org.openconcerto.sql.view.list.IListe;
35
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
38
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
36
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
39
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
-
 
40
import org.openconcerto.sql.view.list.SQLTableModelSource;
37
import org.openconcerto.sql.view.list.SQLTableModelSourceOnline;
41
import org.openconcerto.sql.view.list.SQLTableModelSourceOnline;
38
import org.openconcerto.ui.DefaultGridBagConstraints;
42
import org.openconcerto.ui.DefaultGridBagConstraints;
39
import org.openconcerto.ui.FrameUtil;
43
import org.openconcerto.ui.FrameUtil;
40
import org.openconcerto.ui.state.WindowStateManager;
-
 
41
import org.openconcerto.utils.CollectionUtils;
44
import org.openconcerto.utils.CollectionUtils;
42
import org.openconcerto.utils.DecimalUtils;
45
import org.openconcerto.utils.DecimalUtils;
43
import org.openconcerto.utils.cc.ITransformer;
46
import org.openconcerto.utils.cc.ITransformer;
44
 
47
 
45
import java.awt.GridBagConstraints;
48
import java.awt.GridBagConstraints;
46
import java.awt.GridBagLayout;
49
import java.awt.GridBagLayout;
47
import java.awt.event.ActionEvent;
50
import java.awt.event.ActionEvent;
48
import java.io.File;
-
 
49
import java.math.BigDecimal;
51
import java.math.BigDecimal;
50
import java.math.RoundingMode;
52
import java.math.RoundingMode;
51
import java.util.Collection;
53
import java.util.Collection;
52
import java.util.List;
54
import java.util.List;
53
import java.util.Set;
55
import java.util.Set;
54
 
56
 
55
import javax.swing.AbstractAction;
57
import javax.swing.AbstractAction;
56
import javax.swing.Action;
-
 
57
import javax.swing.JFrame;
-
 
58
import javax.swing.JPanel;
58
import javax.swing.JPanel;
59
 
59
 
60
public class ListeDesElementsACommanderClientAction extends CreateFrameAbstractAction {
60
public class ListeDesElementsACommanderClientAction extends CreateIListFrameAbstractAction<CommandeClientElementSQLElement> {
61
    final CommandeClientElementSQLElement eltCmd = (CommandeClientElementSQLElement) Configuration.getInstance().getDirectory().getElement("COMMANDE_CLIENT_ELEMENT");
-
 
62
 
61
 
63
    public ListeDesElementsACommanderClientAction() {
62
    public ListeDesElementsACommanderClientAction(final ComptaPropsConfiguration conf) {
64
        super();
-
 
65
        this.putValue(Action.NAME, "Liste des éléments en attente de livraison");
63
        super(conf, CommandeClientElementSQLElement.class);
66
    }
64
    }
67
 
65
 
68
    private BaseSQLTableModelColumn colAvancement;
-
 
69
 
-
 
70
    public JFrame createFrame() {
-
 
71
        final JFrame frame = new JFrame("Eléments en attente de livraison");
-
 
72
        // Actions
66
    @Override
73
 
-
 
74
        final JPanel orderPanel = createPanel();
67
    protected String getPanelVariant() {
75
 
-
 
76
        frame.getContentPane().add(orderPanel);
68
        return this.getClass().getSimpleName();
77
        FrameUtil.setBounds(frame);
-
 
78
        final File file = IListFrame.getConfigFile(eltCmd, frame.getClass());
-
 
79
        if (file != null)
-
 
80
            new WindowStateManager(frame, file).loadState();
-
 
81
        return frame;
-
 
82
    }
69
    }
83
 
70
 
-
 
71
    @Override
84
    JPanel createPanel() {
72
    protected SQLTableModelSource createTableSource() {
85
        final SQLTableModelSourceOnline tableSource = eltCmd.getTableSource(true);
73
        final SQLTableModelSource tableSource = super.createTableSource();
-
 
74
        final CommandeClientElementSQLElement eltCmd = getElem();
86
        tableSource.getReq().setSelectTransf(new ITransformer<SQLSelect, SQLSelect>() {
75
        tableSource.getReq().setSelectTransf(new ITransformer<SQLSelect, SQLSelect>() {
87
 
76
 
88
            @Override
77
            @Override
89
            public SQLSelect transformChecked(SQLSelect input) {
78
            public SQLSelect transformChecked(SQLSelect input) {
90
                // new SQLName(eltCmd.getTable().getDBRoot().getName(),
79
                // new SQLName(eltCmd.getTable().getDBRoot().getName(),
91
                // tableBLElement.getName()).quote()
80
                // tableBLElement.getName()).quote()
92
                final String quoteQteL = new SQLName(input.getAlias(eltCmd.getTable()).getAlias(), "QTE_LIVREE").quote();
81
                final String quoteQteL = new SQLName(input.getAlias(eltCmd.getTable()).getAlias(), "QTE_LIVREE").quote();
93
                final String quoteQte = new SQLName(input.getAlias(eltCmd.getTable()).getAlias(), "QTE").quote();
82
                final String quoteQte = new SQLName(input.getAlias(eltCmd.getTable()).getAlias(), "QTE").quote();
94
                final String quoteQteU = new SQLName(input.getAlias(eltCmd.getTable()).getAlias(), "QTE_UNITAIRE").quote();
83
                final String quoteQteU = new SQLName(input.getAlias(eltCmd.getTable()).getAlias(), "QTE_UNITAIRE").quote();
95
                Where w = Where.createRaw(quoteQteL + " < (" + quoteQte + "*" + quoteQteU + ")", eltCmd.getTable().getField("QTE_LIVREE"), eltCmd.getTable().getField("QTE"),
84
                Where w = Where.createRaw(quoteQteL + " < (" + quoteQte + "*" + quoteQteU + ")", eltCmd.getTable().getField("QTE_LIVREE"), eltCmd.getTable().getField("QTE"),
96
                        eltCmd.getTable().getField("QTE_UNITAIRE"));
85
                        eltCmd.getTable().getField("QTE_UNITAIRE"));
-
 
86
                w = w.and(new Where(eltCmd.getTable().getField("LIVRE_FORCED"), "=", Boolean.FALSE));
97
                input.setWhere(w);
87
                input.setWhere(w);
98
                return input;
88
                return input;
99
            }
89
            }
100
        });
90
        });
101
 
91
 
-
 
92
        SQLPreferences prefs = SQLPreferences.getMemCached(eltCmd.getTable().getDBRoot());
-
 
93
        if (prefs.getBoolean(GestionArticleGlobalPreferencePanel.STOCK_MULTI_DEPOT, false)) {
102
        BaseSQLTableModelColumn colStockR = new BaseSQLTableModelColumn("Stock Reel", Float.class) {
94
            BaseSQLTableModelColumn colStockD = new BaseSQLTableModelColumn("Dépôt", String.class) {
103
 
95
 
104
            @Override
96
                @Override
105
            protected Object show_(SQLRowAccessor r) {
97
                protected Object show_(SQLRowAccessor r) {
106
 
98
 
107
                final SQLRowAccessor foreign = r.getForeign("ID_ARTICLE");
99
                    final SQLRowAccessor foreign = r.getForeign("ID_ARTICLE");
108
                if (foreign != null && !foreign.isUndefined()) {
100
                    if (foreign != null && !foreign.isUndefined()) {
109
                    final SQLRowAccessor foreign2 = foreign.getForeign("ID_STOCK");
101
                        SQLRowAccessor foreign2 = StockSQLElement.getStockFetched(r);
110
                    if (foreign2 != null && !foreign2.isUndefined()) {
102
                        if (foreign2 != null && !foreign2.isUndefined()) {
111
                        return foreign2.getFloat("QTE_REEL");
103
                            return foreign2.getForeign("ID_DEPOT_STOCK").getString("NOM");
112
                    }
104
                        }
113
                }
105
                    }
114
                return 0F;
106
                    return "";
115
            }
107
                }
116
 
108
 
117
            @Override
109
                @Override
118
            public Set<FieldPath> getPaths() {
110
                public Set<FieldPath> getPaths() {
119
                Path p = new Path(eltCmd.getTable());
111
                    Path p = new Path(eltCmd.getTable());
120
                p = p.add(p.getLast().getField("ID_ARTICLE"));
112
                    p = p.add(p.getLast().getField("ID_ARTICLE"));
-
 
113
                    Path p2 = p.add(p.getLast().getTable("STOCK").getField("ID_ARTICLE"));
-
 
114
                    Path p3 = p2.add(p2.getLast().getField("ID_DEPOT_STOCK"));
121
                p = p.add(p.getLast().getField("ID_STOCK"));
115
                    Path p4 = p.add(p.getLast().getField("ID_DEPOT_STOCK"));
122
                return CollectionUtils.createSet(new FieldPath(p, "QTE_REEL"));
116
                    return CollectionUtils.createSet(new FieldPath(p3, "NOM"), new FieldPath(p4, "NOM"));
123
            }
117
                }
124
        };
118
            };
125
        tableSource.getColumns().add(colStockR);
119
            tableSource.getColumns().add(colStockD);
126
 
120
        }
127
        BaseSQLTableModelColumn colLiv2 = new BaseSQLTableModelColumn("Stock TH", Float.class) {
121
        BaseSQLTableModelColumn colStockR = new BaseSQLTableModelColumn("Stock Reel", Float.class) {
128
 
122
 
129
            @Override
123
            @Override
130
            protected Object show_(SQLRowAccessor r) {
124
            protected Object show_(SQLRowAccessor r) {
131
 
125
 
132
                final SQLRowAccessor foreign = r.getForeign("ID_ARTICLE");
126
                final SQLRowAccessor foreign = r.getForeign("ID_ARTICLE");
133
                if (foreign != null && !foreign.isUndefined()) {
127
                if (foreign != null && !foreign.isUndefined()) {
134
                    final SQLRowAccessor foreign2 = foreign.getForeign("ID_STOCK");
128
                    SQLRowAccessor foreign2 = StockSQLElement.getStockFetched(r);
135
                    if (foreign2 != null && !foreign2.isUndefined()) {
129
                    if (foreign2 != null && !foreign2.isUndefined()) {
136
                        return foreign2.getFloat("QTE_TH");
130
                        return foreign2.getFloat("QTE_REEL");
137
                    }
131
                    }
138
                }
132
                }
139
                return 0F;
133
                return 0F;
140
            }
134
            }
141
 
135
 
142
            @Override
136
            @Override
143
            public Set<FieldPath> getPaths() {
137
            public Set<FieldPath> getPaths() {
144
                Path p = new Path(eltCmd.getTable());
138
                Path p = new Path(eltCmd.getTable());
145
                p = p.add(p.getLast().getField("ID_ARTICLE"));
139
                p = p.add(p.getLast().getField("ID_ARTICLE"));
146
                p = p.add(p.getLast().getField("ID_STOCK"));
140
                Path p2 = p.add(p.getLast().getTable("STOCK").getField("ID_ARTICLE"));
147
                return CollectionUtils.createSet(new FieldPath(p, "QTE_TH"));
141
                return CollectionUtils.createSet(new FieldPath(p, "ID_DEPOT_STOCK"), new FieldPath(p2, "QTE_REEL"), new FieldPath(p2, "ID_DEPOT_STOCK"));
148
            }
142
            }
149
        };
143
        };
150
        tableSource.getColumns().add(colLiv2);
144
        tableSource.getColumns().add(colStockR);
151
 
145
 
152
        BaseSQLTableModelColumn colStockMin = new BaseSQLTableModelColumn("Stock Min", Integer.class) {
146
        BaseSQLTableModelColumn colLiv2 = new BaseSQLTableModelColumn("Stock TH", Float.class) {
153
 
147
 
154
            @Override
148
            @Override
155
            protected Object show_(SQLRowAccessor r) {
149
            protected Object show_(SQLRowAccessor r) {
156
 
150
 
157
                final SQLRowAccessor foreign = r.getForeign("ID_ARTICLE");
151
                final SQLRowAccessor foreign = r.getForeign("ID_ARTICLE");
-
 
152
                if (foreign != null && !foreign.isUndefined()) {
-
 
153
                    SQLRowAccessor foreign2 = StockSQLElement.getStockFetched(r);
-
 
154
                    if (foreign2 != null && !foreign2.isUndefined()) {
158
                return foreign.getInt("QTE_MIN");
155
                        return foreign2.getFloat("QTE_TH");
-
 
156
                    }
-
 
157
                }
-
 
158
                return 0F;
159
            }
159
            }
160
 
160
 
161
            @Override
161
            @Override
162
            public Set<FieldPath> getPaths() {
162
            public Set<FieldPath> getPaths() {
163
                Path p = new Path(eltCmd.getTable());
163
                Path p = new Path(eltCmd.getTable());
164
                p = p.add(p.getLast().getField("ID_ARTICLE"));
164
                p = p.add(p.getLast().getField("ID_ARTICLE"));
165
 
-
 
-
 
165
                Path p2 = p.add(p.getLast().getTable("STOCK").getField("ID_ARTICLE"));
166
                return CollectionUtils.createSet(new FieldPath(p, "QTE_MIN"));
166
                return CollectionUtils.createSet(new FieldPath(p, "ID_DEPOT_STOCK"), new FieldPath(p2, "QTE_TH"), new FieldPath(p2, "ID_DEPOT_STOCK"));
167
            }
167
            }
168
        };
168
        };
169
        tableSource.getColumns().add(colStockMin);
169
        tableSource.getColumns().add(colLiv2);
170
 
170
 
171
        BaseSQLTableModelColumn colSug = new BaseSQLTableModelColumn("Qtè à commander", Float.class) {
171
        BaseSQLTableModelColumn colStockMin = new BaseSQLTableModelColumn("Stock Min", Float.class) {
172
 
172
 
173
            @Override
173
            @Override
174
            protected Object show_(SQLRowAccessor r) {
174
            protected Object show_(SQLRowAccessor r) {
175
 
175
 
176
                // final float qteCommande = r.getBigDecimal("QTE_UNITAIRE").multiply(new
-
 
177
                // BigDecimal(r.getInt("QTE"))).subtract(r.getBigDecimal("QTE_LIVREE")).floatValue();
-
 
178
                final SQLRowAccessor foreign = r.getForeign("ID_ARTICLE");
176
                final SQLRowAccessor foreign = r.getForeign("ID_ARTICLE");
179
                if (foreign != null && !foreign.isUndefined()) {
177
                if (foreign != null && !foreign.isUndefined()) {
180
                    float qteMin = foreign.getFloat("QTE_MIN");
-
 
181
                    final SQLRowAccessor foreign2 = foreign.getForeign("ID_STOCK");
178
                    SQLRowAccessor foreign2 = StockSQLElement.getStockFetched(r);
182
                    if (foreign2 != null && !foreign2.isUndefined()) {
179
                    if (foreign2 != null && !foreign2.isUndefined()) {
183
                        float manque = foreign2.getFloat("QTE_TH") - qteMin;
180
                        return foreign2.getFloat("QTE_MIN");
184
                        if (manque < 0) {
-
 
185
                            return -manque;
-
 
186
                        }
-
 
187
                    }
181
                    }
188
                }
182
                }
189
                return 0F;
183
                return 0F;
190
            }
184
            }
191
 
185
 
192
            @Override
186
            @Override
193
            public Set<FieldPath> getPaths() {
187
            public Set<FieldPath> getPaths() {
194
                Path pA = new Path(eltCmd.getTable());
188
                Path p = new Path(eltCmd.getTable());
195
 
-
 
196
                pA = pA.add(pA.getLast().getField("ID_ARTICLE"));
189
                p = p.add(p.getLast().getField("ID_ARTICLE"));
197
                Path p = pA.add(pA.getLast().getField("ID_STOCK"));
190
                Path p2 = p.add(p.getLast().getTable("STOCK").getField("ID_ARTICLE"));
198
                return CollectionUtils.createSet(new FieldPath(pA, "QTE_MIN"), new FieldPath(p, "QTE_TH"));
191
                return CollectionUtils.createSet(new FieldPath(p, "ID_DEPOT_STOCK"), new FieldPath(p2, "QTE_MIN"), new FieldPath(p2, "ID_DEPOT_STOCK"));
199
            }
192
            }
200
        };
193
        };
201
        tableSource.getColumns().add(colSug);
194
        tableSource.getColumns().add(colStockMin);
202
        // colLiv2.setRenderer(new PercentTableCellRenderer());
-
 
203
 
-
 
204
        final ListeAddPanel panel = getPanel(eltCmd, tableSource);
-
 
205
        PredicateRowAction action = new PredicateRowAction(new AbstractAction("Calcul des besoins") {
-
 
206
 
-
 
207
            @Override
-
 
208
            public void actionPerformed(ActionEvent e) {
-
 
209
                final SQLElement artElt = eltCmd.getForeignElement("ID_ARTICLE");
-
 
210
                final SQLTableModelSourceOnline createTableSource = artElt.createTableSource();
-
 
211
                createTableSource.getReq().setSelectTransf(new ITransformer<SQLSelect, SQLSelect>() {
-
 
212
                    @Override
-
 
213
                    public SQLSelect transformChecked(SQLSelect input) {
-
 
214
                        FieldRef refStock = input.getAlias(artElt.getTable().getForeignTable("ID_STOCK").getField("QTE_TH"));
-
 
215
 
-
 
216
                        SQLSelectJoin j = input.getJoinFromField(artElt.getTable().getTable("ARTICLE_ELEMENT").getField("ID_ARTICLE_PARENT"));
-
 
217
                        Where w = new Where(refStock, "<", artElt.getTable().getField("QTE_MIN"));
-
 
218
                        w = w.and(new Where(j.getJoinedTable().getKey(), "=", (Object) null));
-
 
219
                        input.setWhere(w);
-
 
220
                        // input.setHaving(Where.createRaw("COUNT(\"" + j.getJoinedTable().getKey()
-
 
221
                        // + "\")" + " = 0", Arrays.asList(j.getJoinedTable().getKey())));
-
 
222
                        return input;
-
 
223
                    }
-
 
224
                });
-
 
225
 
195
 
226
                BaseSQLTableModelColumn colSug = new BaseSQLTableModelColumn("Qtè à commander", Float.class) {
196
        BaseSQLTableModelColumn colSug = new BaseSQLTableModelColumn("Qtè à commander", Float.class) {
227
 
197
 
228
                    @Override
198
            @Override
229
                    protected Object show_(SQLRowAccessor r) {
199
            protected Object show_(SQLRowAccessor r) {
230
 
200
 
231
                        float qteMin = r.getFloat("QTE_MIN");
201
                final SQLRowAccessor foreign = r.getForeign("ID_ARTICLE");
-
 
202
                if (foreign != null && !foreign.isUndefined()) {
232
                        final SQLRowAccessor foreign2 = r.getForeign("ID_STOCK");
203
                    SQLRowAccessor foreign2 = StockSQLElement.getStockFetched(r);
233
                        if (foreign2 != null && !foreign2.isUndefined()) {
204
                    if (foreign2 != null && !foreign2.isUndefined()) {
-
 
205
                        float qteMin = foreign2.getFloat("QTE_MIN");
234
                            float manque = foreign2.getFloat("QTE_TH") - qteMin;
206
                        float manque = foreign2.getFloat("QTE_TH") - qteMin;
235
                            if (manque < 0) {
207
                        if (manque < 0) {
236
                                return -manque;
208
                            return -manque;
237
                            }
209
                        }
238
                        }
210
                    }
239
 
-
 
-
 
211
                }
240
                        return 0F;
212
                return 0F;
-
 
213
 
241
                    }
214
            }
242
 
215
 
243
                    @Override
216
            @Override
244
                    public Set<FieldPath> getPaths() {
217
            public Set<FieldPath> getPaths() {
245
                        Path pA = new Path(artElt.getTable());
218
                Path p = new Path(eltCmd.getTable());
246
 
-
 
247
                        Path p = pA.add(pA.getLast().getField("ID_STOCK"));
219
                p = p.add(p.getLast().getField("ID_ARTICLE"));
-
 
220
                Path p2 = p.add(p.getLast().getTable("STOCK").getField("ID_ARTICLE"));
248
                        return CollectionUtils.createSet(new FieldPath(pA, "QTE_MIN"), new FieldPath(p, "QTE_TH"));
221
                return CollectionUtils.createSet(new FieldPath(p, "ID_DEPOT_STOCK"), new FieldPath(p2, "QTE_TH"), new FieldPath(p2, "QTE_MIN"), new FieldPath(p2, "ID_DEPOT_STOCK"));
249
                    }
222
            }
250
                };
223
        };
251
                createTableSource.getColumns().add(colSug);
224
        tableSource.getColumns().add(colSug);
252
 
-
 
253
                IListe listeArt = new IListe(createTableSource);
225
        // colLiv2.setRenderer(new PercentTableCellRenderer());
254
                final PredicateRowAction predicateACtion = new PredicateRowAction(new AbstractAction("Passer une commande fournisseur") {
-
 
255
 
226
 
256
                    @Override
-
 
257
                    public void actionPerformed(ActionEvent e) {
-
 
258
                        List<SQLRowValues> selectedRows = IListe.get(e).getSelectedRows();
-
 
259
                        eltCmd.createCommandeF(selectedRows);
-
 
260
                    }
-
 
261
                }, true);
-
 
262
                predicateACtion.setPredicate(IListeEvent.getNonEmptySelectionPredicate());
-
 
263
                listeArt.addIListeAction(predicateACtion);
-
 
264
                ListeViewPanel p = new ListeViewPanel(artElt, listeArt);
-
 
265
                IListFrame f = new IListFrame(p);
-
 
266
                FrameUtil.show(f);
-
 
267
            }
-
 
268
        }, true);
-
 
269
        action.setPredicate(IListeEvent.createTotalRowCountPredicate(0, Integer.MAX_VALUE));
-
 
270
        panel.getListe().addIListeAction(action);
-
 
271
        return panel;
227
        return tableSource;
272
    }
228
    }
273
 
229
 
274
    private BigDecimal getAvancementLFromBL(SQLRowAccessor r) {
230
    private BigDecimal getAvancementLFromBL(SQLRowAccessor r) {
275
        Collection<? extends SQLRowAccessor> rows = r.getReferentRows(r.getTable().getTable("COMMANDE_CLIENT_ELEMENT"));
231
        Collection<? extends SQLRowAccessor> rows = r.getReferentRows(r.getTable().getTable("COMMANDE_CLIENT_ELEMENT"));
276
        BigDecimal totalQte = BigDecimal.ZERO;
232
        BigDecimal totalQte = BigDecimal.ZERO;
277
        BigDecimal totalQteL = BigDecimal.ZERO;
233
        BigDecimal totalQteL = BigDecimal.ZERO;
278
        for (SQLRowAccessor row : rows) {
234
        for (SQLRowAccessor row : rows) {
279
            BigDecimal qte = row.getBigDecimal("QTE_UNITAIRE").multiply(new BigDecimal(row.getInt("QTE")));
235
            BigDecimal qte = row.getBigDecimal("QTE_UNITAIRE").multiply(new BigDecimal(row.getInt("QTE")));
280
            totalQte = totalQte.add(qte);
236
            totalQte = totalQte.add(qte);
281
            if (row.getBoolean("LIVRE_FORCED") || row.getBoolean("LIVRE")) {
237
            if (row.getBoolean("LIVRE_FORCED") || row.getBoolean("LIVRE")) {
282
                totalQteL = totalQteL.add(qte);
238
                totalQteL = totalQteL.add(qte);
283
            } else {
239
            } else {
284
                totalQteL = totalQteL.add(row.getBigDecimal("QTE_LIVREE"));
240
                totalQteL = totalQteL.add(row.getBigDecimal("QTE_LIVREE"));
285
            }
241
            }
286
        }
242
        }
287
        if (totalQte.signum() != 0) {
243
        if (totalQte.signum() != 0) {
288
            return totalQteL.divide(totalQte, DecimalUtils.HIGH_PRECISION).movePointRight(2).setScale(2, RoundingMode.HALF_UP);
244
            return totalQteL.divide(totalQte, DecimalUtils.HIGH_PRECISION).movePointRight(2).setScale(2, RoundingMode.HALF_UP);
289
        } else {
245
        } else {
290
            return BigDecimal.ONE.movePointRight(2);
246
            return BigDecimal.ONE.movePointRight(2);
291
        }
247
        }
292
    }
248
    }
293
 
249
 
-
 
250
    @Override
294
    private ListeAddPanel getPanel(final SQLElement eltCmd, final SQLTableModelSourceOnline tableSource) {
251
    protected IListPanel instantiateListPanel(SQLTableModelSource tableSource, String panelVariant) {
295
        final ListeAddPanel panel = new ListeAddPanel(eltCmd, new IListe(tableSource));
252
        final IListPanel panel = super.instantiateListPanel(tableSource, panelVariant);
296
 
-
 
-
 
253
        final CommandeClientElementSQLElement eltCmd = getElem();
297
        // final List<Tuple2<? extends SQLTableModelColumn, IListTotalPanel.Type>> fields = new
254
        // final List<Tuple2<? extends SQLTableModelColumn, IListTotalPanel.Type>> fields = new
298
        // ArrayList<Tuple2<? extends SQLTableModelColumn, IListTotalPanel.Type>>(2);
255
        // ArrayList<Tuple2<? extends SQLTableModelColumn, IListTotalPanel.Type>>(2);
299
        // fields.add(Tuple2.create(panel.getListe().getSource().getColumn(eltCmd.getTable().getField("T_HT")),
256
        // fields.add(Tuple2.create(panel.getListe().getSource().getColumn(eltCmd.getTable().getField("T_HT")),
300
        // IListTotalPanel.Type.SOMME));
257
        // IListTotalPanel.Type.SOMME));
301
        // fields.add(Tuple2.create(this.colAvancement, IListTotalPanel.Type.AVANCEMENT_TTC));
258
        // fields.add(Tuple2.create(this.colAvancement, IListTotalPanel.Type.AVANCEMENT_TTC));
302
        // final IListTotalPanel totalPanel = new IListTotalPanel(panel.getListe(), fields, null,
259
        // final IListTotalPanel totalPanel = new IListTotalPanel(panel.getListe(), fields, null,
303
        // "Total des commandes de la liste");
260
        // "Total des commandes de la liste");
304
 
261
 
305
        final GridBagConstraints c = new DefaultGridBagConstraints();
262
        final GridBagConstraints c = new DefaultGridBagConstraints();
306
        c.gridwidth = GridBagConstraints.REMAINDER;
263
        c.gridwidth = GridBagConstraints.REMAINDER;
307
        c.fill = GridBagConstraints.BOTH;
264
        c.fill = GridBagConstraints.BOTH;
308
        c.anchor = GridBagConstraints.EAST;
265
        c.anchor = GridBagConstraints.EAST;
309
        c.weightx = 1;
266
        c.weightx = 1;
310
        c.gridy = 4;
267
        c.gridy = 4;
311
 
268
 
312
        // Date panel
269
        // Date panel
313
        final IListFilterDatePanel datePanel = new IListFilterDatePanel(panel.getListe(), eltCmd.getTable().getForeignTable("ID_COMMANDE_CLIENT").getField("DATE"),
270
        final IListFilterDatePanel datePanel = new IListFilterDatePanel(panel.getListe(), eltCmd.getTable().getForeignTable("ID_COMMANDE_CLIENT").getField("DATE"),
314
                IListFilterDatePanel.getDefaultMap());
271
                IListFilterDatePanel.getDefaultMap());
315
 
272
 
316
        datePanel.setFilterOnDefault();
273
        datePanel.setFilterOnDefault();
317
 
274
 
318
        final JPanel bottomPanel = new JPanel();
275
        final JPanel bottomPanel = new JPanel();
319
        bottomPanel.setLayout(new GridBagLayout());
276
        bottomPanel.setLayout(new GridBagLayout());
320
        bottomPanel.setOpaque(false);
277
        bottomPanel.setOpaque(false);
321
        final GridBagConstraints c2 = new DefaultGridBagConstraints();
278
        final GridBagConstraints c2 = new DefaultGridBagConstraints();
322
        c2.fill = GridBagConstraints.NONE;
279
        c2.fill = GridBagConstraints.NONE;
323
        c2.weightx = 1;
280
        c2.weightx = 1;
324
        bottomPanel.add(datePanel, c2);
281
        bottomPanel.add(datePanel, c2);
325
 
282
 
326
        // c2.gridx++;
283
        // c2.gridx++;
327
        // c2.weightx = 0;
284
        // c2.weightx = 0;
328
        // c2.anchor = GridBagConstraints.EAST;
285
        // c2.anchor = GridBagConstraints.EAST;
329
        // bottomPanel.add(totalPanel, c2);
286
        // bottomPanel.add(totalPanel, c2);
330
 
287
 
331
        panel.add(bottomPanel, c);
288
        panel.add(bottomPanel, c);
-
 
289
 
-
 
290
        PredicateRowAction action = new PredicateRowAction(new AbstractAction("Calcul des besoins") {
-
 
291
 
-
 
292
            @Override
-
 
293
            public void actionPerformed(ActionEvent e) {
-
 
294
                final SQLElement artElt = eltCmd.getForeignElement("ID_ARTICLE");
-
 
295
                final SQLTableModelSourceOnline createTableSource = artElt.createTableSource();
-
 
296
                createTableSource.getReq().setSelectTransf(new ITransformer<SQLSelect, SQLSelect>() {
-
 
297
                    @Override
-
 
298
                    public SQLSelect transformChecked(SQLSelect input) {
-
 
299
                        FieldRef refStock = input.getAlias(artElt.getTable().getForeignTable("ID_STOCK").getField("QTE_TH"));
-
 
300
 
-
 
301
                        SQLSelectJoin j = input.getJoinFromField(artElt.getTable().getTable("ARTICLE_ELEMENT").getField("ID_ARTICLE_PARENT"));
-
 
302
                        Where w = new Where(refStock, "<", artElt.getTable().getField("QTE_MIN"));
-
 
303
                        w = w.and(new Where(j.getJoinedTable().getKey(), "=", (Object) null));
-
 
304
                        input.setWhere(w);
-
 
305
                        // input.setHaving(Where.createRaw("COUNT(\"" + j.getJoinedTable().getKey()
-
 
306
                        // + "\")" + " = 0", Arrays.asList(j.getJoinedTable().getKey())));
-
 
307
                        return input;
-
 
308
                    }
-
 
309
                });
-
 
310
 
-
 
311
                IListe listeArt = new IListe(createTableSource);
-
 
312
                final PredicateRowAction predicateACtion = new PredicateRowAction(new AbstractAction("Passer une commande fournisseur") {
-
 
313
 
-
 
314
                    @Override
-
 
315
                    public void actionPerformed(ActionEvent e) {
-
 
316
                        List<SQLRowValues> selectedRows = IListe.get(e).getSelectedRows();
-
 
317
                        eltCmd.createCommandeF(selectedRows);
-
 
318
                    }
-
 
319
                }, true);
-
 
320
                predicateACtion.setPredicate(IListeEvent.getNonEmptySelectionPredicate());
-
 
321
                listeArt.addIListeAction(predicateACtion);
-
 
322
                ListeViewPanel p = new ListeViewPanel(artElt, listeArt);
-
 
323
                IListFrame f = new IListFrame(p);
-
 
324
                FrameUtil.show(f);
-
 
325
            }
-
 
326
 
-
 
327
        }, true);
-
 
328
        action.setPredicate(IListeEvent.createTotalRowCountPredicate(0, Integer.MAX_VALUE));
-
 
329
        panel.getListe().addIListeAction(action);
-
 
330
 
332
        return panel;
331
        return panel;
333
    }
332
    }
334
 
333
 
335
}
334
}