OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 174 Rev 182
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.
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.supplychain.stock.element;
14
 package org.openconcerto.erp.core.supplychain.stock.element;
15
 
15
 
-
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
16
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
17
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
17
import org.openconcerto.erp.core.common.ui.PanelFrame;
18
import org.openconcerto.erp.core.common.ui.PanelFrame;
18
import org.openconcerto.erp.core.sales.product.action.InventairePanel;
19
import org.openconcerto.erp.core.sales.product.action.InventairePanel;
19
import org.openconcerto.erp.generationDoc.gestcomm.FicheArticleXmlSheet;
20
import org.openconcerto.erp.generationDoc.gestcomm.FicheArticleXmlSheet;
20
import org.openconcerto.erp.model.MouseSheetXmlListeListener;
21
import org.openconcerto.erp.model.MouseSheetXmlListeListener;
21
import org.openconcerto.sql.element.BaseSQLComponent;
22
import org.openconcerto.sql.element.BaseSQLComponent;
22
import org.openconcerto.sql.element.SQLComponent;
23
import org.openconcerto.sql.element.SQLComponent;
-
 
24
import org.openconcerto.sql.element.SQLElement;
-
 
25
import org.openconcerto.sql.model.DBRoot;
-
 
26
import org.openconcerto.sql.model.SQLInjector;
23
import org.openconcerto.sql.model.SQLRow;
27
import org.openconcerto.sql.model.SQLRow;
24
import org.openconcerto.sql.model.SQLRowAccessor;
28
import org.openconcerto.sql.model.SQLRowAccessor;
25
import org.openconcerto.sql.model.SQLRowValues;
29
import org.openconcerto.sql.model.SQLRowValues;
26
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
30
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
-
 
31
import org.openconcerto.sql.model.SQLSelect;
27
import org.openconcerto.sql.model.SQLTable;
32
import org.openconcerto.sql.model.SQLTable;
28
import org.openconcerto.sql.model.Where;
33
import org.openconcerto.sql.model.Where;
29
import org.openconcerto.sql.sqlobject.ElementComboBox;
34
import org.openconcerto.sql.sqlobject.ElementComboBox;
-
 
35
import org.openconcerto.sql.users.rights.UserRightsManager;
30
import org.openconcerto.sql.view.list.IListe;
36
import org.openconcerto.sql.view.list.IListe;
31
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
37
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
32
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
38
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
33
import org.openconcerto.ui.DefaultGridBagConstraints;
39
import org.openconcerto.ui.DefaultGridBagConstraints;
34
import org.openconcerto.ui.FrameUtil;
40
import org.openconcerto.ui.FrameUtil;
35
import org.openconcerto.utils.ExceptionHandler;
41
import org.openconcerto.utils.DecimalUtils;
36
import org.openconcerto.utils.ListMap;
42
import org.openconcerto.utils.ListMap;
37
 
43
 
38
import java.awt.GridBagConstraints;
44
import java.awt.GridBagConstraints;
39
import java.awt.GridBagLayout;
45
import java.awt.GridBagLayout;
40
import java.awt.event.ActionEvent;
46
import java.awt.event.ActionEvent;
-
 
47
import java.math.BigDecimal;
41
import java.sql.SQLException;
48
import java.sql.SQLException;
42
import java.util.Arrays;
49
import java.util.Arrays;
43
import java.util.Collection;
50
import java.util.Collection;
44
import java.util.HashSet;
51
import java.util.HashSet;
45
import java.util.List;
52
import java.util.List;
46
import java.util.Set;
53
import java.util.Set;
47
 
54
 
48
import javax.swing.AbstractAction;
55
import javax.swing.AbstractAction;
49
import javax.swing.JLabel;
56
import javax.swing.JLabel;
-
 
57
import javax.swing.JOptionPane;
50
import javax.swing.JTextField;
58
import javax.swing.JTextField;
51
 
59
 
52
public class StockSQLElement extends ComptaSQLConfElement {
60
public class StockSQLElement extends ComptaSQLConfElement {
53
 
61
 
54
    public StockSQLElement() {
62
    public StockSQLElement() {
55
        super("STOCK", "un stock", "stocks");
63
        super("STOCK", "un stock", "stocks");
56
        getRowActions().addAll(new MouseSheetXmlListeListener(FicheArticleXmlSheet.class).getRowActions());
64
        getRowActions().addAll(new MouseSheetXmlListeListener(this, FicheArticleXmlSheet.class).getRowActions());
57
        PredicateRowAction stock = new PredicateRowAction(new AbstractAction("Mettre à jour les stocks") {
65
        PredicateRowAction stock = new PredicateRowAction(new AbstractAction("Mettre à jour les stocks") {
58
 
66
 
59
            @Override
67
            @Override
60
            public void actionPerformed(ActionEvent e) {
68
            public void actionPerformed(ActionEvent e) {
61
 
-
 
-
 
69
                if (UserRightsManager.getCurrentUserRights().canAdd(getTable().getDBRoot().getTable("STOCK"))) {
62
                PanelFrame p = new PanelFrame(new InventairePanel(IListe.get(e), IListe.get(e).getSelectedRows()), "Mise à jour des stocks");
70
                    final PanelFrame p = new PanelFrame(new InventairePanel(IListe.get(e), IListe.get(e).getSelectedRows()), "Mise à jour des stocks");
63
                FrameUtil.show(p);
71
                    FrameUtil.show(p);
64
 
-
 
-
 
72
                } else {
-
 
73
                    JOptionPane.showMessageDialog(null, "Vous n'avez les droits suffisants pour modifier manuellement les stocks!");
-
 
74
                }
65
            }
75
            }
66
        }, true, false);
76
        }, true, false);
67
        stock.setPredicate(IListeEvent.getNonEmptySelectionPredicate());
77
        stock.setPredicate(IListeEvent.getNonEmptySelectionPredicate());
68
        getRowActions().add(stock);
78
        getRowActions().add(stock);
-
 
79
 
-
 
80
        PredicateRowAction cmd = new PredicateRowAction(new AbstractAction("Passer une commande") {
-
 
81
 
-
 
82
            @Override
-
 
83
            public void actionPerformed(ActionEvent e) {
-
 
84
 
-
 
85
                transfertCommande(IListe.get(e).getSelectedRowAccessors());
-
 
86
 
-
 
87
            }
-
 
88
        }, true, false);
-
 
89
        cmd.setPredicate(IListeEvent.getNonEmptySelectionPredicate());
-
 
90
        getRowActions().add(cmd);
69
    }
91
    }
70
 
92
 
71
    protected List<String> getListFields() {
93
    protected List<String> getListFields() {
72
        return Arrays.asList("ID_ARTICLE", "QTE_MIN", "QTE_TH", "QTE_REEL", "QTE_LIV_ATTENTE", "QTE_RECEPT_ATTENTE", "ID_DEPOT_STOCK");
94
        return Arrays.asList("ID_ARTICLE", "QTE_MIN", "QTE_TH", "QTE_REEL", "QTE_LIV_ATTENTE", "QTE_RECEPT_ATTENTE", "ID_DEPOT_STOCK");
73
    }
95
    }
74
 
96
 
75
    @Override
97
    @Override
76
    public Set<String> getReadOnlyFields() {
98
    public Set<String> getReadOnlyFields() {
77
        Set<String> s = new HashSet<>();
99
        Set<String> s = new HashSet<>();
78
        if (getTable().contains("ID_ARTICLE")) {
100
        if (getTable().contains("ID_ARTICLE")) {
79
            s.add("ID_ARTICLE");
101
            s.add("ID_ARTICLE");
80
        }
102
        }
81
        s.add("QTE_TH");
103
        s.add("QTE_TH");
82
        s.add("QTE_REEL");
104
        s.add("QTE_REEL");
83
        s.add("QTE_LIV_ATTENTE");
105
        s.add("QTE_LIV_ATTENTE");
84
        s.add("QTE_RECEPT_ATTENTE");
106
        s.add("QTE_RECEPT_ATTENTE");
85
        if (getTable().contains("ID_DEPOT_STOCK")) {
107
        if (getTable().contains("ID_DEPOT_STOCK")) {
86
            s.add("ID_DEPOT_STOCK");
108
            s.add("ID_DEPOT_STOCK");
87
        }
109
        }
88
        return s;
110
        return s;
89
    }
111
    }
90
 
112
 
91
    @Override
113
    @Override
92
    protected List<String> getComboFields() {
114
    protected List<String> getComboFields() {
93
        return Arrays.asList("ID_DEPOT_STOCK", "QTE_REEL");
115
        return Arrays.asList("ID_DEPOT_STOCK", "QTE_REEL");
94
    }
116
    }
95
 
117
 
96
    @Override
118
    @Override
97
    protected String getParentFFName() {
119
    protected String getParentFFName() {
98
        return "ID_ARTICLE";
120
        return "ID_ARTICLE";
99
    }
121
    }
100
 
122
 
101
    @Override
123
    @Override
102
    public ListMap<String, String> getShowAs() {
124
    public ListMap<String, String> getShowAs() {
103
        if (getTable().contains("ID_DEPOT_STOCK")) {
125
        if (getTable().contains("ID_DEPOT_STOCK")) {
104
            return ListMap.singleton(null, "QTE_TH", "QTE_REEL", "QTE_MIN", "QTE_LIV_ATTENTE", "QTE_RECEPT_ATTENTE", "ID_DEPOT_STOCK");
126
            return ListMap.singleton(null, "QTE_TH", "QTE_REEL", "QTE_MIN", "QTE_LIV_ATTENTE", "QTE_RECEPT_ATTENTE", "ID_DEPOT_STOCK");
105
        } else {
127
        } else {
106
            return ListMap.singleton(null, "QTE_TH", "QTE_REEL", "QTE_LIV_ATTENTE", "QTE_RECEPT_ATTENTE");
128
            return ListMap.singleton(null, "QTE_TH", "QTE_REEL", "QTE_LIV_ATTENTE", "QTE_RECEPT_ATTENTE");
107
        }
129
        }
108
    }
130
    }
109
 
131
 
110
    public static SQLRowAccessor getStockFetched(SQLRowAccessor rowValsSource) {
132
    public static SQLRowAccessor getStockFetched(SQLRowAccessor rowValsSource) {
111
        SQLRowAccessor rowStock = null;
133
        SQLRowAccessor rowStock = null;
112
        final int idDepot;
134
        final int idDepot;
113
        if (rowValsSource.getForeign("ID_DEPOT_STOCK") != null && !rowValsSource.isForeignEmpty("ID_DEPOT_STOCK")) {
135
        if (rowValsSource.getForeign("ID_DEPOT_STOCK") != null && !rowValsSource.isForeignEmpty("ID_DEPOT_STOCK")) {
114
            idDepot = rowValsSource.getForeignID("ID_DEPOT_STOCK");
136
            idDepot = rowValsSource.getForeignID("ID_DEPOT_STOCK");
115
        } else {
137
        } else {
116
            idDepot = rowValsSource.getForeign("ID_ARTICLE").getForeignID("ID_DEPOT_STOCK");
138
            idDepot = rowValsSource.getForeign("ID_ARTICLE").getForeignID("ID_DEPOT_STOCK");
117
        }
139
        }
118
        SQLTable stockTable = rowValsSource.getTable().getTable("STOCK");
140
        SQLTable stockTable = rowValsSource.getTable().getTable("STOCK");
119
 
141
 
120
        Collection<? extends SQLRowAccessor> rows = rowValsSource.getForeign("ID_ARTICLE").getReferentRows(stockTable);
142
        Collection<? extends SQLRowAccessor> rows = rowValsSource.getForeign("ID_ARTICLE").getReferentRows(stockTable);
121
        for (SQLRowAccessor sqlRowAccessor : rows) {
143
        for (SQLRowAccessor sqlRowAccessor : rows) {
122
            if (sqlRowAccessor.getForeignID("ID_DEPOT_STOCK") == idDepot) {
144
            if (sqlRowAccessor.getForeignID("ID_DEPOT_STOCK") == idDepot) {
123
                rowStock = sqlRowAccessor;
145
                rowStock = sqlRowAccessor;
124
                break;
146
                break;
125
            }
147
            }
126
        }
148
        }
127
 
149
 
128
        return rowStock;
150
        return rowStock;
129
    }
151
    }
130
 
152
 
131
    public static SQLRowAccessor getStock(SQLRowAccessor rowValsSource) {
153
    public static SQLRowAccessor getStock(SQLRowAccessor rowValsSource) throws SQLException {
132
 
154
 
133
        SQLRowAccessor rowStock = null;
155
        SQLRowAccessor rowStock = null;
134
        final int idDepot;
156
        final int idDepot;
135
        if (rowValsSource.getForeign("ID_DEPOT_STOCK") != null && !rowValsSource.isForeignEmpty("ID_DEPOT_STOCK")) {
157
        if (rowValsSource.getForeign("ID_DEPOT_STOCK") != null && !rowValsSource.isForeignEmpty("ID_DEPOT_STOCK")) {
136
            idDepot = rowValsSource.getForeignID("ID_DEPOT_STOCK");
158
            idDepot = rowValsSource.getForeignID("ID_DEPOT_STOCK");
137
        } else {
159
        } else {
138
            SQLRowAccessor rowValsArt = rowValsSource.getForeign("ID_ARTICLE");
160
            SQLRowAccessor rowValsArt = rowValsSource.getForeign("ID_ARTICLE");
139
            if (rowValsArt.getObject("ID_DEPOT_STOCK") == null) {
161
            if (rowValsArt.getObject("ID_DEPOT_STOCK") == null) {
140
                rowValsArt = rowValsArt.asRow();
162
                rowValsArt = rowValsArt.asRow();
141
                ((SQLRow) rowValsArt).fetchValues();
163
                ((SQLRow) rowValsArt).fetchValues();
142
                System.err.println("REFETCH ARTICLE");
164
                System.err.println("REFETCH ARTICLE");
143
                Thread.dumpStack();
165
                Thread.dumpStack();
144
            }
166
            }
145
            idDepot = rowValsArt.getForeignID("ID_DEPOT_STOCK");
167
            idDepot = rowValsArt.getForeignID("ID_DEPOT_STOCK");
146
        }
168
        }
-
 
169
        final int idArticle = rowValsSource.getForeignID("ID_ARTICLE");
-
 
170
        DBRoot root = rowValsSource.getTable().getDBRoot();
-
 
171
 
147
        SQLTable stockTable = rowValsSource.getTable().getTable("STOCK");
172
        SQLTable stockTable = root.getTable("STOCK");
148
        SQLRowValues putRowValuesStock = new SQLRowValues(stockTable);
173
        SQLRowValues putRowValuesStock = new SQLRowValues(stockTable);
149
        putRowValuesStock.putNulls(stockTable.getTable().getFieldsName());
174
        putRowValuesStock.putNulls(stockTable.getTable().getFieldsName());
150
 
175
 
151
        SQLRowValuesListFetcher fetch = SQLRowValuesListFetcher.create(putRowValuesStock);
176
        SQLRowValuesListFetcher fetch = SQLRowValuesListFetcher.create(putRowValuesStock);
152
        Where w = new Where(putRowValuesStock.getTable().getField("ID_DEPOT_STOCK"), "=", idDepot);
177
        Where w = new Where(stockTable.getField("ID_DEPOT_STOCK"), "=", idDepot);
-
 
178
 
153
        Where w2 = new Where(putRowValuesStock.getTable().getField("ID_ARTICLE"), "=", rowValsSource.getForeignID("ID_ARTICLE"));
179
        Where w2 = new Where(stockTable.getField("ID_ARTICLE"), "=", idArticle);
154
        Collection<SQLRowValues> rowValsResult = fetch.fetch(w.and(w2));
180
        Collection<SQLRowValues> rowValsResult = fetch.fetch(w.and(w2));
155
        if (rowValsResult.isEmpty()) {
181
        if (rowValsResult.isEmpty()) {
156
            SQLRowValues rowValsStock = new SQLRowValues(stockTable);
182
            SQLRowValues rowValsStock = new SQLRowValues(stockTable);
157
            rowValsStock.put("ID_ARTICLE", rowValsSource.getForeignID("ID_ARTICLE"));
183
            rowValsStock.put("ID_ARTICLE", idArticle);
158
            rowValsStock.put("ID_DEPOT_STOCK", idDepot);
184
            rowValsStock.put("ID_DEPOT_STOCK", idDepot);
159
            rowValsStock.put("QTE_TH", 0F);
185
            rowValsStock.put("QTE_TH", 0F);
160
            rowValsStock.put("QTE_REEL", 0F);
186
            rowValsStock.put("QTE_REEL", 0F);
161
            rowValsStock.put("QTE_RECEPT_ATTENTE", 0F);
187
            rowValsStock.put("QTE_RECEPT_ATTENTE", 0F);
162
            rowValsStock.put("QTE_LIV_ATTENTE", 0F);
188
            rowValsStock.put("QTE_LIV_ATTENTE", 0F);
163
            try {
-
 
-
 
189
 
164
                rowStock = rowValsStock.insert();
190
            rowStock = rowValsStock.insert();
165
                if (idDepot == DepotStockSQLElement.DEFAULT_ID) {
191
            if (idDepot == DepotStockSQLElement.DEFAULT_ID) {
166
                    rowValsSource.getForeign("ID_ARTICLE").createEmptyUpdateRow().put("ID_STOCK", rowStock.getID()).commit();
192
                rowValsSource.getForeign("ID_ARTICLE").createEmptyUpdateRow().put("ID_STOCK", rowStock.getID()).commit();
167
                }
193
            }
168
            } catch (SQLException e) {
-
 
169
                ExceptionHandler.handle("Erreur lors la création du stock!", e);
-
 
170
            }
194
 
171
        } else if (rowValsResult.size() == 1) {
195
        } else if (rowValsResult.size() == 1) {
172
            rowStock = rowValsResult.iterator().next();
196
            rowStock = rowValsResult.iterator().next();
173
        } else if (rowValsResult.size() > 1) {
197
        } else if (rowValsResult.size() > 1) {
174
            throw new IllegalStateException("2 lignes de stocks pour le même dépôt! Article " + rowValsSource.getForeign("ID_ARTICLE").getID() + " Depot " + idDepot);
198
            throw new IllegalStateException("2 lignes de stocks pour le même dépôt! Article " + rowValsSource.getForeign("ID_ARTICLE").getID() + " Depot " + idDepot);
175
        }
199
        }
176
        return rowStock;
200
        return rowStock;
177
    }
201
    }
178
 
202
 
-
 
203
    /**
-
 
204
     * Stock d'un article dans un dépôt donné
-
 
205
     * 
-
 
206
     * @param idDepot dépôt
-
 
207
     * @param idArticle article
-
 
208
     * @param createIfMissing initialisation du stock à 0 si n'existe pas
-
 
209
     * @return le stock (null si createIfMissing à false et que que le stock n'existe pas)
-
 
210
     */
-
 
211
    public SQLRow getStock(int idDepot, int idArticle, boolean createIfMissing) throws SQLException {
-
 
212
        final SQLTable stockTable = getTable();
-
 
213
        final SQLRowValues putRowValuesStock = new SQLRowValues(stockTable);
-
 
214
        putRowValuesStock.putNulls(stockTable.getFieldsName());
-
 
215
        final SQLRowValuesListFetcher fetch = SQLRowValuesListFetcher.create(putRowValuesStock);
-
 
216
        final Where w = new Where(stockTable.getField("ID_DEPOT_STOCK"), "=", idDepot);
-
 
217
        final Where w2 = new Where(stockTable.getField("ID_ARTICLE"), "=", idArticle);
-
 
218
        final Collection<SQLRowValues> rowValsResult = fetch.fetch(w.and(w2));
-
 
219
        SQLRow result;
-
 
220
        if (rowValsResult.isEmpty()) {
-
 
221
            if (!createIfMissing) {
-
 
222
                return null;
-
 
223
            }
-
 
224
            final SQLRowValues rowValsStock = new SQLRowValues(stockTable);
-
 
225
            rowValsStock.put("ID_ARTICLE", idArticle);
-
 
226
            rowValsStock.put("ID_DEPOT_STOCK", idDepot);
-
 
227
            rowValsStock.put("QTE_TH", 0F);
-
 
228
            rowValsStock.put("QTE_REEL", 0F);
-
 
229
            rowValsStock.put("QTE_RECEPT_ATTENTE", 0F);
-
 
230
            rowValsStock.put("QTE_LIV_ATTENTE", 0F);
-
 
231
            result = rowValsStock.insert();
-
 
232
 
-
 
233
        } else if (rowValsResult.size() == 1) {
-
 
234
            result = rowValsResult.iterator().next().asRow();
-
 
235
        } else {
-
 
236
            throw new IllegalStateException("2 lignes de stocks pour le même dépôt! Article " + idArticle + " Depot " + idDepot);
-
 
237
        }
-
 
238
        return result;
-
 
239
    }
-
 
240
 
179
    /*
241
    /*
180
     * (non-Javadoc)
242
     * (non-Javadoc)
181
     * 
243
     * 
182
     * @see org.openconcerto.devis.SQLElement#getComponent()
244
     * @see org.openconcerto.devis.SQLElement#getComponent()
183
     */
245
     */
184
    public SQLComponent createComponent() {
246
    public SQLComponent createComponent() {
185
 
247
 
186
        return new BaseSQLComponent(this) {
248
        return new BaseSQLComponent(this) {
187
 
249
 
188
            public void addViews() {
250
            public void addViews() {
189
                this.setLayout(new GridBagLayout());
251
                this.setLayout(new GridBagLayout());
190
                final GridBagConstraints c = new DefaultGridBagConstraints();
252
                final GridBagConstraints c = new DefaultGridBagConstraints();
191
 
253
 
192
                // Article
254
                // Article
193
                JLabel labelA = new JLabel(getLabelFor("ID_ARTICLE"));
255
                JLabel labelA = new JLabel(getLabelFor("ID_ARTICLE"));
194
                c.weightx = 0;
256
                c.weightx = 0;
195
                this.add(labelA, c);
257
                this.add(labelA, c);
196
 
258
 
197
                c.gridx++;
259
                c.gridx++;
198
                ElementComboBox boxA = new ElementComboBox();
260
                ElementComboBox boxA = new ElementComboBox();
199
                this.add(boxA, c);
261
                this.add(boxA, c);
200
 
262
 
201
                // Depot
263
                // Depot
202
                JLabel labelD = new JLabel(getLabelFor("ID_DEPOT_STOCK"));
264
                JLabel labelD = new JLabel(getLabelFor("ID_DEPOT_STOCK"));
203
                c.gridx++;
265
                c.gridx++;
204
                c.weightx = 0;
266
                c.weightx = 0;
205
                this.add(labelD, c);
267
                this.add(labelD, c);
206
 
268
 
207
                c.gridx++;
269
                c.gridx++;
208
                ElementComboBox boxD = new ElementComboBox();
270
                ElementComboBox boxD = new ElementComboBox();
209
                this.add(boxD, c);
271
                this.add(boxD, c);
210
 
272
 
211
                // Qté Réelle
273
                // Qté Réelle
212
                JLabel labelQteR = new JLabel(getLabelFor("QTE_REEL"));
274
                JLabel labelQteR = new JLabel(getLabelFor("QTE_REEL"));
213
                c.gridx = 0;
275
                c.gridx = 0;
214
                c.gridy++;
276
                c.gridy++;
215
                c.weightx = 0;
277
                c.weightx = 0;
216
                this.add(labelQteR, c);
278
                this.add(labelQteR, c);
217
 
279
 
218
                c.gridx++;
280
                c.gridx++;
219
                JTextField textQteReel = new JTextField(6);
281
                JTextField textQteReel = new JTextField(6);
220
                this.add(textQteReel, c);
282
                this.add(textQteReel, c);
221
 
283
 
222
                // Qté Réelle
284
                // Qté Réelle
223
                JLabel labelQteT = new JLabel(getLabelFor("QTE_TH"));
285
                JLabel labelQteT = new JLabel(getLabelFor("QTE_TH"));
224
                c.gridx++;
286
                c.gridx++;
225
                c.weightx = 0;
287
                c.weightx = 0;
226
                this.add(labelQteT, c);
288
                this.add(labelQteT, c);
227
 
289
 
228
                c.gridx++;
290
                c.gridx++;
229
                JTextField textQteT = new JTextField(6);
291
                JTextField textQteT = new JTextField(6);
230
                this.add(textQteT, c);
292
                this.add(textQteT, c);
231
 
293
 
232
                // Qté Réelle
294
                // Qté Réelle
233
                JLabel labelQteRe = new JLabel(getLabelFor("QTE_RECEPT_ATTENTE"));
295
                JLabel labelQteRe = new JLabel(getLabelFor("QTE_RECEPT_ATTENTE"));
234
                c.gridx = 0;
296
                c.gridx = 0;
235
                c.gridy++;
297
                c.gridy++;
236
                c.weightx = 0;
298
                c.weightx = 0;
237
                this.add(labelQteRe, c);
299
                this.add(labelQteRe, c);
238
 
300
 
239
                c.gridx++;
301
                c.gridx++;
240
                JTextField textQteRe = new JTextField(6);
302
                JTextField textQteRe = new JTextField(6);
241
                this.add(textQteRe, c);
303
                this.add(textQteRe, c);
242
 
304
 
243
                JLabel labelQteL = new JLabel(getLabelFor("QTE_LIV_ATTENTE"));
305
                JLabel labelQteL = new JLabel(getLabelFor("QTE_LIV_ATTENTE"));
244
                c.gridx++;
306
                c.gridx++;
245
                c.weightx = 0;
307
                c.weightx = 0;
246
                this.add(labelQteL, c);
308
                this.add(labelQteL, c);
247
 
309
 
248
                c.gridx++;
310
                c.gridx++;
249
                JTextField textQteL = new JTextField(6);
311
                JTextField textQteL = new JTextField(6);
250
                this.add(textQteL, c);
312
                this.add(textQteL, c);
251
 
313
 
252
                // Qté Min
314
                // Qté Min
253
                JLabel labelQteTMin = new JLabel(getLabelFor("QTE_MIN"));
315
                JLabel labelQteTMin = new JLabel(getLabelFor("QTE_MIN"));
254
                c.gridx = 0;
316
                c.gridx = 0;
255
                c.gridy++;
317
                c.gridy++;
256
                c.weightx = 0;
318
                c.weightx = 0;
257
                this.add(labelQteTMin, c);
319
                this.add(labelQteTMin, c);
258
 
320
 
259
                c.gridx++;
321
                c.gridx++;
260
                JTextField textQteMin = new JTextField(6);
322
                JTextField textQteMin = new JTextField(6);
261
                this.add(textQteMin, c);
323
                this.add(textQteMin, c);
262
 
324
 
263
                this.addSQLObject(textQteReel, "QTE_REEL");
325
                this.addSQLObject(textQteReel, "QTE_REEL");
264
                this.addSQLObject(textQteT, "QTE_TH");
326
                this.addSQLObject(textQteT, "QTE_TH");
265
                this.addSQLObject(textQteMin, "QTE_MIN");
327
                this.addSQLObject(textQteMin, "QTE_MIN");
266
                this.addSQLObject(textQteL, "QTE_LIV_ATTENTE");
328
                this.addSQLObject(textQteL, "QTE_LIV_ATTENTE");
267
                this.addSQLObject(textQteRe, "QTE_RECEPT_ATTENTE");
329
                this.addSQLObject(textQteRe, "QTE_RECEPT_ATTENTE");
268
                this.addSQLObject(boxA, "ID_ARTICLE");
330
                this.addSQLObject(boxA, "ID_ARTICLE");
269
                this.addSQLObject(boxD, "ID_DEPOT_STOCK");
331
                this.addSQLObject(boxD, "ID_DEPOT_STOCK");
270
            }
332
            }
271
        };
333
        };
272
    }
334
    }
-
 
335
 
-
 
336
    /**
-
 
337
     * Transfert d'une commande en commande fournisseur
-
 
338
     * 
-
 
339
     * @param commandeID
-
 
340
     */
-
 
341
    public void transfertCommande(List<SQLRowAccessor> rows) {
-
 
342
 
-
 
343
        ComptaPropsConfiguration.getInstanceCompta().getNonInteractiveSQLExecutor().execute(new Runnable() {
-
 
344
 
-
 
345
            @Override
-
 
346
            public void run() {
-
 
347
 
-
 
348
                SQLTable tableCmdElt = getDirectory().getElement("COMMANDE_ELEMENT").getTable();
-
 
349
                SQLElement eltArticle = getDirectory().getElement("ARTICLE");
-
 
350
 
-
 
351
                final ListMap<SQLRow, SQLRowValues> map = new ListMap<SQLRow, SQLRowValues>();
-
 
352
 
-
 
353
                for (SQLRowAccessor sqlRow : rows) {
-
 
354
 
-
 
355
                    SQLRowAccessor rowArticleFind = sqlRow.getForeign("ID_ARTICLE");
-
 
356
                    int qte = 1;
-
 
357
                    BigDecimal qteUV = BigDecimal.ONE;
-
 
358
 
-
 
359
                    qte = -Math.round(sqlRow.getFloat("QTE_TH") - sqlRow.getFloat("QTE_MIN"));
-
 
360
 
-
 
361
                    SQLInjector inj = SQLInjector.getInjector(eltArticle.getTable(), tableCmdElt);
-
 
362
                    SQLRowValues rowValsElt = new SQLRowValues(inj.createRowValuesFrom(rowArticleFind.asRow()));
-
 
363
                    rowValsElt.put("ID_DEPOT_STOCK", sqlRow.getForeignID("ID_DEPOT_STOCK"));
-
 
364
                    rowValsElt.put("QTE", qte);
-
 
365
                    rowValsElt.put("QTE_UNITAIRE", qteUV);
-
 
366
 
-
 
367
                    rowValsElt.put("T_POIDS", rowValsElt.getLong("POIDS") * rowValsElt.getInt("QTE"));
-
 
368
                    // TODO récupérer le prix depuis les tarifs d'achat
-
 
369
                    rowValsElt.put("T_PA_HT", ((BigDecimal) rowValsElt.getObject("PA_HT")).multiply(new BigDecimal(rowValsElt.getInt("QTE")), DecimalUtils.HIGH_PRECISION));
-
 
370
                    rowValsElt.put("T_PA_TTC",
-
 
371
                            ((BigDecimal) rowValsElt.getObject("T_PA_HT")).multiply(new BigDecimal((rowValsElt.getForeign("ID_TAXE").getFloat("TAUX") / 100.0 + 1.0)), DecimalUtils.HIGH_PRECISION));
-
 
372
                    final SQLRow fournisseur = rowArticleFind.asRow().getForeignRow("ID_FOURNISSEUR");
-
 
373
                    if (fournisseur != null && !fournisseur.isUndefined() && !rowArticleFind.isUndefined()) {
-
 
374
                        SQLRowValues rowValsCode = new SQLRowValues(tableCmdElt.getForeignTable("ID_CODE_FOURNISSEUR"));
-
 
375
                        rowValsCode.putNulls("ID");
-
 
376
                        final Where w = new Where(rowValsCode.getTable().getField("ID_ARTICLE"), "=", rowArticleFind.getID())
-
 
377
                                .and(new Where(rowValsCode.getTable().getField("ID_FOURNISSEUR"), "=", fournisseur.getID()));
-
 
378
                        final List<SQLRowValues> fetch = SQLRowValuesListFetcher.create(rowValsCode).fetch(w);
-
 
379
                        for (SQLRowValues sqlRowAccessor : fetch) {
-
 
380
                            rowValsElt.put("ID_CODE_FOURNISSEUR", sqlRowAccessor.getID());
-
 
381
                        }
-
 
382
                    }
-
 
383
                    map.add(fournisseur, rowValsElt);
-
 
384
                }
-
 
385
 
-
 
386
                MouvementStockSQLElement.createCommandeF(map, null, "");
-
 
387
            }
-
 
388
        });
-
 
389
 
-
 
390
    }
273
 
391
 
274
    @Override
392
    @Override
275
    protected String createCode() {
393
    protected String createCode() {
276
        return "supplychain.stock";
394
        return "supplychain.stock";
277
    }
395
    }
278
}
396
}