OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 142 Rev 156
Line 15... Line 15...
15
 
15
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
17
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
17
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
18
import org.openconcerto.erp.core.sales.product.element.ReferenceArticleSQLElement;
18
import org.openconcerto.erp.core.sales.product.element.ReferenceArticleSQLElement;
19
import org.openconcerto.erp.core.supplychain.order.component.CommandeSQLComponent;
19
import org.openconcerto.erp.core.supplychain.order.component.CommandeSQLComponent;
-
 
20
import org.openconcerto.erp.core.supplychain.order.ui.CommandeItemTable;
20
import org.openconcerto.erp.core.supplychain.supplier.component.MouvementStockSQLComponent;
21
import org.openconcerto.erp.core.supplychain.supplier.component.MouvementStockSQLComponent;
21
import org.openconcerto.erp.preferences.GestionArticleGlobalPreferencePanel;
22
import org.openconcerto.erp.preferences.GestionArticleGlobalPreferencePanel;
22
import org.openconcerto.sql.Configuration;
23
import org.openconcerto.sql.Configuration;
23
import org.openconcerto.sql.element.SQLComponent;
24
import org.openconcerto.sql.element.SQLComponent;
24
import org.openconcerto.sql.element.SQLElement;
25
import org.openconcerto.sql.element.SQLElement;
Line 38... Line 39...
38
import org.openconcerto.sql.view.EditFrame;
39
import org.openconcerto.sql.view.EditFrame;
39
import org.openconcerto.sql.view.EditPanel;
40
import org.openconcerto.sql.view.EditPanel;
40
import org.openconcerto.sql.view.EditPanel.EditMode;
41
import org.openconcerto.sql.view.EditPanel.EditMode;
41
import org.openconcerto.sql.view.list.RowValuesTableModel;
42
import org.openconcerto.sql.view.list.RowValuesTableModel;
42
import org.openconcerto.ui.FrameUtil;
43
import org.openconcerto.ui.FrameUtil;
43
import org.openconcerto.utils.ExceptionHandler;
-
 
44
import org.openconcerto.utils.ListMap;
44
import org.openconcerto.utils.ListMap;
45
 
45
 
46
import java.math.BigDecimal;
46
import java.math.BigDecimal;
47
import java.sql.SQLException;
47
import java.sql.SQLException;
48
import java.util.ArrayList;
48
import java.util.ArrayList;
Line 56... Line 56...
56
 
56
 
57
    public MouvementStockSQLElement() {
57
    public MouvementStockSQLElement() {
58
        super("MOUVEMENT_STOCK", "un mouvement de stock", "mouvements de stock");
58
        super("MOUVEMENT_STOCK", "un mouvement de stock", "mouvements de stock");
59
    }
59
    }
60
 
60
 
-
 
61
    @Override
-
 
62
    public ListMap<String, String> getShowAs() {
-
 
63
        ListMap<String, String> map = new ListMap<String, String>();
-
 
64
        map.putCollection("ID_STOCK", "ID_DEPOT_STOCK");
-
 
65
        return map;
-
 
66
    }
-
 
67
 
61
    protected List<String> getListFields() {
68
    protected List<String> getListFields() {
62
        final List<String> l = new ArrayList<String>();
69
        final List<String> l = new ArrayList<String>();
-
 
70
        l.add("ID_STOCK");
63
        l.add("DATE");
71
        l.add("DATE");
64
        l.add("NOM");
72
        l.add("NOM");
65
        l.add("ID_ARTICLE");
73
        l.add("ID_ARTICLE");
66
        l.add("QTE");
74
        l.add("QTE");
67
        l.add("REEL");
75
        l.add("REEL");
Line 89... Line 97...
89
        super.archive(trees, cutLinks);
97
        super.archive(trees, cutLinks);
90
        updateStock(trees.getRows(), true);
98
        updateStock(trees.getRows(), true);
91
 
99
 
92
    }
100
    }
93
 
101
 
94
    // public CollectionMap<SQLRow, List<SQLRowValues>> updateStock(List<Integer> ids) {
-
 
95
    // return updateStock(ids, false);
-
 
96
    // }
-
 
97
 
-
 
98
    private final SQLTable sqlTableArticle = ((ComptaPropsConfiguration) Configuration.getInstance()).getRootSociete().getTable("ARTICLE");
-
 
99
 
-
 
100
    /**
102
    /**
101
     * Mise à jour des stocks ajoute la quantité si archive est à false
103
     * Mise à jour des stocks ajoute la quantité si archive est à false
102
     * 
104
     * 
103
     * @param id mouvement stock
105
     * @param id mouvement stock
104
     * @param archive
106
     * @param archive
-
 
107
     * @throws SQLException
105
     */
108
     */
106
    public ListMap<SQLRow, SQLRowValues> updateStock(Collection<SQLRow> rowsMvt, boolean archive) {
109
    public ListMap<SQLRow, SQLRowValues> updateStock(Collection<SQLRow> rowsMvt, boolean archive) throws SQLException {
107
        // FIXME: if (SwingUtilities.isEventDispatchThread()) {
110
        // FIXME: if (SwingUtilities.isEventDispatchThread()) {
108
        // throw new IllegalStateException("This method must be called outside of EDT");
111
        // throw new IllegalStateException("This method must be called outside of EDT");
109
        // }
112
        // }
110
        // Stock Reel : inc/dec QTE_REEL, inc/dec QTE_LIV_ATTENTE/inc/dec
113
        // Stock Reel : inc/dec QTE_REEL, inc/dec QTE_LIV_ATTENTE/inc/dec
111
        // QTE_RECEPT_ATTENTE
114
        // QTE_RECEPT_ATTENTE
112
        // Stock Th : inc/dec QTE_TH, inc/dec QTE_LIV_ATTENTE/inc/dec
115
        // Stock Th : inc/dec QTE_TH, inc/dec QTE_LIV_ATTENTE/inc/dec
113
        // QTE_RECEPT_ATTENTE
116
        // QTE_RECEPT_ATTENTE
114
 
117
 
115
        final ListMap<SQLRow, SQLRowValues> map = new ListMap<SQLRow, SQLRowValues>();
118
        final ListMap<SQLRow, SQLRowValues> map = new ListMap<>();
116
        SQLTable tableCmdElt = Configuration.getInstance().getBase().getTable("COMMANDE_ELEMENT");
119
        final SQLTable tableCommandeElement = Configuration.getInstance().getBase().getTable("COMMANDE_ELEMENT");
-
 
120
        final SQLElement elementStock = Configuration.getInstance().getDirectory().getElement("STOCK");
-
 
121
 
117
        for (SQLRow rowMvtStock : rowsMvt) {
122
        for (SQLRow rowMvtStock : rowsMvt) {
118
 
123
 
119
            boolean retour = rowMvtStock.getString("SOURCE") == null || rowMvtStock.getString("SOURCE").startsWith("AVOIR_CLIENT");
124
            boolean retour = rowMvtStock.getString("SOURCE") == null || rowMvtStock.getString("SOURCE").startsWith("AVOIR_CLIENT");
120
            // Mise à jour des stocks
125
            // Mise à jour des stocks
121
            SQLTable sqlTableArticle = ((ComptaPropsConfiguration) Configuration.getInstance()).getRootSociete().getTable("ARTICLE");
-
 
122
            SQLElement eltArticle = Configuration.getInstance().getDirectory().getElement(sqlTableArticle);
-
 
123
            SQLElement eltStock = Configuration.getInstance().getDirectory().getElement("STOCK");
-
 
-
 
126
 
124
            final SQLRow rowArticle = rowMvtStock.getForeignRow("ID_ARTICLE");
127
            final SQLRow rowArticle = rowMvtStock.getForeignRow("ID_ARTICLE");
125
 
128
 
126
            SQLRow rowStock = rowArticle.getForeignRow(("ID_STOCK"));
129
            SQLRow rowStock = rowMvtStock.getForeignRow(("ID_STOCK"));
-
 
130
            if (rowStock == null || rowStock.isUndefined()) {
-
 
131
                rowStock = rowArticle.getForeign("ID_STOCK");
-
 
132
            }
-
 
133
 
127
            if (rowMvtStock.getBoolean("REEL")) {
134
            if (rowMvtStock.getBoolean("REEL")) {
128
                float qte = rowStock.getFloat("QTE_REEL");
135
                float qte = rowStock.getFloat("QTE_REEL");
129
                float qteMvt = rowMvtStock.getFloat("QTE");
136
                float qteMvt = rowMvtStock.getFloat("QTE");
130
 
137
 
131
                SQLRowValues rowVals = new SQLRowValues(eltStock.getTable());
138
                SQLRowValues rowVals = new SQLRowValues(elementStock.getTable());
132
 
139
 
133
                float qteNvlle;
140
                float qteNvlle;
134
                float qteNvlleEnAttenteRecept = rowStock.getFloat("QTE_RECEPT_ATTENTE");
141
                float qteNvlleEnAttenteRecept = rowStock.getFloat("QTE_RECEPT_ATTENTE");
135
                float qteNvlleEnAttenteExp = rowStock.getFloat("QTE_LIV_ATTENTE");
142
                float qteNvlleEnAttenteExp = rowStock.getFloat("QTE_LIV_ATTENTE");
136
                if (archive) {
143
                if (archive) {
Line 159... Line 166...
159
                rowVals.put("QTE_REEL", qteNvlle);
166
                rowVals.put("QTE_REEL", qteNvlle);
160
                rowVals.put("QTE_RECEPT_ATTENTE", qteNvlleEnAttenteRecept);
167
                rowVals.put("QTE_RECEPT_ATTENTE", qteNvlleEnAttenteRecept);
161
                rowVals.put("QTE_LIV_ATTENTE", qteNvlleEnAttenteExp);
168
                rowVals.put("QTE_LIV_ATTENTE", qteNvlleEnAttenteExp);
162
 
169
 
163
                try {
170
                try {
164
                    if (rowStock.getID() <= 1) {
-
 
165
                        SQLRow row = rowVals.insert();
-
 
166
                        SQLRowValues rowValsArt = new SQLRowValues(eltArticle.getTable());
-
 
167
                        rowValsArt.put("ID_STOCK", row.getID());
-
 
168
 
-
 
169
                        final int idArticle = rowArticle.getID();
-
 
170
                        if (idArticle > 1) {
-
 
171
                            rowValsArt.update(idArticle);
-
 
172
                        }
-
 
173
                    } else {
-
 
174
                        rowVals.update(rowStock.getID());
171
                    rowVals.update(rowStock.getID());
175
                    }
-
 
176
                } catch (SQLException e) {
-
 
177
 
-
 
178
                    ExceptionHandler.handle("Erreur lors de la mise à jour du stock pour l'article " + rowArticle.getString("CODE"));
-
 
179
                }
-
 
180
 
172
 
181
                SQLPreferences prefs = new SQLPreferences(getTable().getDBRoot());
173
                    SQLPreferences prefs = new SQLPreferences(getTable().getDBRoot());
182
                boolean gestionStockMin = prefs.getBoolean(GestionArticleGlobalPreferencePanel.WARNING_STOCK_MIN, true);
174
                    boolean gestionStockMin = prefs.getBoolean(GestionArticleGlobalPreferencePanel.WARNING_STOCK_MIN, true);
183
 
175
 
184
                if (!archive && rowArticle.getTable().getFieldsName().contains("QTE_MIN") && gestionStockMin && rowArticle.getObject("QTE_MIN") != null && qteNvlle < rowArticle.getInt("QTE_MIN")) {
176
                    if (!archive && gestionStockMin && rowStock.getObject("QTE_MIN") != null && qteNvlle < rowStock.getFloat("QTE_MIN")) {
185
                    // final float qteShow = qteNvlle;
177
                        // final float qteShow = qteNvlle;
186
                    SQLInjector inj = SQLInjector.getInjector(rowArticle.getTable(), tableCmdElt);
178
                        SQLInjector inj = SQLInjector.getInjector(rowArticle.getTable(), tableCommandeElement);
187
                    SQLRowValues rowValsElt = new SQLRowValues(inj.createRowValuesFrom(rowArticle));
179
                        SQLRowValues rowValsElt = new SQLRowValues(inj.createRowValuesFrom(rowArticle));
188
                    rowValsElt.put("ID_STYLE", 2);
180
                        rowValsElt.put("ID_STYLE", 2);
189
                    final SQLRow unite = rowArticle.getForeign("ID_UNITE_VENTE");
181
                        final SQLRow unite = rowArticle.getForeign("ID_UNITE_VENTE");
190
                    final float qteElt = rowArticle.getInt("QTE_MIN") - qteNvlle;
182
                        final float qteElt = rowStock.getFloat("QTE_MIN") - qteNvlle;
191
                    if (unite.isUndefined() || unite.getBoolean("A_LA_PIECE")) {
183
                        if (unite.isUndefined() || unite.getBoolean("A_LA_PIECE")) {
192
                        rowValsElt.put("QTE", Math.round(qteElt));
184
                            rowValsElt.put("QTE", Math.round(qteElt));
193
                        rowValsElt.put("QTE_UNITAIRE", BigDecimal.ONE);
185
                            rowValsElt.put("QTE_UNITAIRE", BigDecimal.ONE);
194
                    } else {
186
                        } else {
195
                        rowValsElt.put("QTE", 1);
187
                            rowValsElt.put("QTE", 1);
Line 197... Line 189...
197
                    }
189
                        }
198
                    rowValsElt.put("ID_TAXE", rowValsElt.getObject("ID_TAXE"));
190
                        rowValsElt.put("ID_TAXE", rowValsElt.getObject("ID_TAXE"));
199
                    rowValsElt.put("T_POIDS", rowValsElt.getLong("POIDS") * qteElt);
191
                        rowValsElt.put("T_POIDS", rowValsElt.getLong("POIDS") * qteElt);
200
                    rowValsElt.put("T_PA_HT", rowValsElt.getLong("PA_HT") * qteElt);
192
                        rowValsElt.put("T_PA_HT", rowValsElt.getLong("PA_HT") * qteElt);
201
                    rowValsElt.put("T_PA_TTC", rowValsElt.getLong("T_PA_HT") * (rowValsElt.getForeign("ID_TAXE").getFloat("TAUX") / 100.0 + 1.0));
193
                        rowValsElt.put("T_PA_TTC", rowValsElt.getLong("T_PA_HT") * (rowValsElt.getForeign("ID_TAXE").getFloat("TAUX") / 100.0 + 1.0));
202
 
-
 
203
                    map.add(rowArticle.getForeignRow("ID_FOURNISSEUR"), rowValsElt);
194
                        map.add(rowArticle.getForeignRow("ID_FOURNISSEUR"), rowValsElt);
204
 
-
 
-
 
195
                    }
-
 
196
                } catch (SQLException e) {
-
 
197
                    throw new SQLException("Erreur lors de la mise à jour du stock pour l'article " + rowArticle.getString("CODE"), e);
205
                }
198
                }
206
            } else {
199
            } else {
207
                float qte = rowStock.getFloat("QTE_TH");
200
                float qte = rowStock.getFloat("QTE_TH");
208
                float qteMvt = rowMvtStock.getFloat("QTE");
201
                float qteMvt = rowMvtStock.getFloat("QTE");
209
 
202
 
210
                SQLRowValues rowVals = new SQLRowValues(eltStock.getTable());
203
                SQLRowValues rowVals = new SQLRowValues(elementStock.getTable());
211
 
204
 
212
                float qteNvlle;
205
                float qteNvlle;
213
                float qteNvlleEnAttenteRecept = rowStock.getFloat("QTE_RECEPT_ATTENTE");
206
                float qteNvlleEnAttenteRecept = rowStock.getFloat("QTE_RECEPT_ATTENTE");
214
                float qteNvlleEnAttenteExp = rowStock.getFloat("QTE_LIV_ATTENTE");
207
                float qteNvlleEnAttenteExp = rowStock.getFloat("QTE_LIV_ATTENTE");
215
 
208
 
Line 239... Line 232...
239
                    }
232
                    }
240
                }
233
                }
241
                rowVals.put("QTE_TH", qteNvlle);
234
                rowVals.put("QTE_TH", qteNvlle);
242
                rowVals.put("QTE_RECEPT_ATTENTE", qteNvlleEnAttenteRecept);
235
                rowVals.put("QTE_RECEPT_ATTENTE", qteNvlleEnAttenteRecept);
243
                rowVals.put("QTE_LIV_ATTENTE", qteNvlleEnAttenteExp);
236
                rowVals.put("QTE_LIV_ATTENTE", qteNvlleEnAttenteExp);
244
 
-
 
245
                try {
237
                try {
246
                    if (rowStock.getID() <= 1) {
-
 
247
                        SQLRow row = rowVals.insert();
-
 
248
                        SQLRowValues rowValsArt = new SQLRowValues(eltArticle.getTable());
-
 
249
                        rowValsArt.put("ID_STOCK", row.getID());
-
 
250
 
-
 
251
                        final int idArticle = rowArticle.getID();
-
 
252
                        if (idArticle > 1) {
-
 
253
                            rowValsArt.update(idArticle);
-
 
254
                        }
-
 
255
                    } else {
-
 
256
                        rowVals.update(rowStock.getID());
238
                    rowVals.update(rowStock.getID());
257
                    }
-
 
258
                } catch (SQLException e) {
239
                } catch (SQLException e) {
259
 
-
 
260
                    ExceptionHandler.handle("Erreur lors de la mise à jour du stock pour l'article " + rowArticle.getString("CODE"));
240
                    throw new SQLException("Erreur lors de la mise à jour du stock pour l'article " + rowArticle.getString("CODE"), e);
261
                }
241
                }
262
            }
242
            }
263
 
243
 
264
        }
244
        }
265
        return map;
245
        return map;
Line 326... Line 306...
326
                            rowVals.put("NOM", ref);
306
                            rowVals.put("NOM", ref);
327
                            cmp.select(rowVals);
307
                            cmp.select(rowVals);
328
                            cmp.getRowValuesTable().getRowValuesTableModel().clearRows();
308
                            cmp.getRowValuesTable().getRowValuesTableModel().clearRows();
329
                        }
309
                        }
330
 
310
 
-
 
311
                        CommandeItemTable itemTable = cmp.getRowValuesTablePanel();
-
 
312
 
331
                        final RowValuesTableModel model = cmp.getRowValuesTable().getRowValuesTableModel();
313
                        final RowValuesTableModel model = cmp.getRowValuesTable().getRowValuesTableModel();
332
                        for (SQLRowValues rowValsElt : e.getValue()) {
314
                        for (SQLRowValues rowValsElt : e.getValue()) {
333
                            SQLRowValues rowValsMatch = null;
315
                            SQLRowValues rowValsMatch = null;
334
                            int index = 0;
316
                            int index = 0;
335
 
317
 
Line 344... Line 326...
344
                            if (rowValsMatch != null) {
326
                            if (rowValsMatch != null) {
345
                                final int qte = rowValsMatch.getInt("QTE");
327
                                final int qte = rowValsMatch.getInt("QTE");
346
                                model.putValue(qte + rowValsElt.getInt("QTE"), index, "QTE");
328
                                model.putValue(qte + rowValsElt.getInt("QTE"), index, "QTE");
347
                            } else {
329
                            } else {
348
                                model.addRow(rowValsElt);
330
                                model.addRow(rowValsElt);
-
 
331
                                if (rowValsElt.getObject("ID_ARTICLE") != null && !rowValsElt.isForeignEmpty("ID_ARTICLE")) {
-
 
332
                                    Object o = itemTable.tarifCompletion(rowValsElt.getForeign("ID_ARTICLE").asRow(), "PRIX_METRIQUE_HA_1");
-
 
333
                                    if (o != null) {
-
 
334
                                        model.putValue(o, model.getRowCount() - 1, "PRIX_METRIQUE_HA_1");
-
 
335
                                    }
-
 
336
                                }
349
                            }
337
                            }
350
                        }
338
                        }
351
 
339
 
352
                        frame.pack();
340
                        frame.pack();
353
                        FrameUtil.show(frame);
341
                        FrameUtil.show(frame);
Line 398... Line 386...
398
        }
386
        }
399
    }
387
    }
400
 
388
 
401
    @Override
389
    @Override
402
    protected String createCode() {
390
    protected String createCode() {
403
        return createCodeFromPackage() + ".transaction";
391
        return createCodeOfPackage() + ".transaction";
404
    }
392
    }
405
}
393
}