OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 156 Rev 174
Line 14... Line 14...
14
 package org.openconcerto.erp.core.sales.order.element;
14
 package org.openconcerto.erp.core.sales.order.element;
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.sales.product.element.UniteVenteArticleSQLElement;
19
import org.openconcerto.erp.core.supplychain.stock.element.MouvementStockSQLElement;
20
import org.openconcerto.erp.core.supplychain.stock.element.MouvementStockSQLElement;
20
import org.openconcerto.erp.core.supplychain.stock.element.StockItemsUpdater;
21
import org.openconcerto.erp.core.supplychain.stock.element.StockItemsUpdater;
21
import org.openconcerto.erp.core.supplychain.stock.element.StockItemsUpdater.TypeStockUpdate;
22
import org.openconcerto.erp.core.supplychain.stock.element.StockItemsUpdater.TypeStockUpdate;
22
import org.openconcerto.erp.core.supplychain.stock.element.StockLabel;
23
import org.openconcerto.erp.core.supplychain.stock.element.StockLabel;
23
import org.openconcerto.erp.core.supplychain.stock.element.StockSQLElement;
-
 
24
import org.openconcerto.sql.element.SQLComponent;
24
import org.openconcerto.sql.element.SQLComponent;
25
import org.openconcerto.sql.element.SQLElement;
25
import org.openconcerto.sql.element.SQLElement;
26
import org.openconcerto.sql.element.UISQLComponent;
26
import org.openconcerto.sql.element.UISQLComponent;
27
import org.openconcerto.sql.model.SQLInjector;
27
import org.openconcerto.sql.model.SQLInjector;
28
import org.openconcerto.sql.model.SQLRow;
28
import org.openconcerto.sql.model.SQLRow;
Line 64... Line 64...
64
 
64
 
65
        PredicateRowAction rowAction = new PredicateRowAction(new AbstractAction("Transfert vers commande fournisseur") {
65
        PredicateRowAction rowAction = new PredicateRowAction(new AbstractAction("Transfert vers commande fournisseur") {
66
 
66
 
67
            @Override
67
            @Override
68
            public void actionPerformed(ActionEvent e) {
68
            public void actionPerformed(ActionEvent e) {
69
                final List<SQLRowValues> selectedRows = IListe.get(e).getSelectedRows();
69
                final List<SQLRow> rows = SQLRowListRSH.fetch(IListe.get(e).getRequest().getPrimaryTable(), IListe.get(e).getSelection().getSelectedIDs());
70
                ComptaPropsConfiguration.getInstanceCompta().getNonInteractiveSQLExecutor().execute(new Runnable() {
70
                ((CommandeClientSQLElement) getForeignElement("ID_COMMANDE_CLIENT")).transfertEltToCommandeF(rows);
71
 
-
 
72
                    @Override
-
 
73
                    public void run() {
-
 
74
 
-
 
75
                        createCommandeF(selectedRows);
-
 
76
                    }
-
 
77
                });
-
 
78
            }
71
            }
79
 
72
 
80
        }, true);
73
        }, true);
81
        rowAction.setPredicate(IListeEvent.getNonEmptySelectionPredicate());
74
        rowAction.setPredicate(IListeEvent.getNonEmptySelectionPredicate());
82
        getRowActions().add(rowAction);
75
        getRowActions().add(rowAction);
Line 212... Line 205...
212
        final List<String> l = new ArrayList<String>();
205
        final List<String> l = new ArrayList<String>();
213
        l.add("CODE");
206
        l.add("CODE");
214
        l.add("NOM");
207
        l.add("NOM");
215
        l.add("ID_COMMANDE_CLIENT");
208
        l.add("ID_COMMANDE_CLIENT");
216
        l.add("ID_ARTICLE");
209
        l.add("ID_ARTICLE");
-
 
210
        l.add("ID_DEPOT_STOCK");
217
        l.add("PA_HT");
211
        l.add("PA_HT");
218
        l.add("PV_HT");
212
        l.add("PV_HT");
219
        l.add("T_PA_HT");
213
        l.add("T_PA_HT");
220
        l.add("T_PV_HT");
214
        l.add("T_PV_HT");
221
        l.add("T_PV_TTC");
215
        l.add("T_PV_TTC");
Line 232... Line 226...
232
     * 
226
     * 
233
     * @param commandeID
227
     * @param commandeID
234
     */
228
     */
235
    public void transfertCommande(List<SQLRowValues> commandeClientEltsRows) {
229
    public void transfertCommande(List<SQLRowValues> commandeClientEltsRows) {
236
 
230
 
-
 
231
        ComptaPropsConfiguration.getInstanceCompta().getNonInteractiveSQLExecutor().execute(new Runnable() {
-
 
232
 
-
 
233
            @Override
-
 
234
            public void run() {
-
 
235
 
237
        SQLTable tableCmdElt = getDirectory().getElement("COMMANDE_ELEMENT").getTable();
236
                SQLTable tableCmdElt = getDirectory().getElement("COMMANDE_ELEMENT").getTable();
238
        SQLElement eltArticle = getDirectory().getElement("ARTICLE");
237
                SQLElement eltArticle = getDirectory().getElement("ARTICLE");
239
 
238
 
240
        final ListMap<SQLRow, SQLRowValues> map = new ListMap<SQLRow, SQLRowValues>();
239
                final ListMap<SQLRow, SQLRowValues> map = new ListMap<SQLRow, SQLRowValues>();
241
        List<String> fields2copy = Arrays.asList("CODE", "NOM", "VALEUR_METRIQUE_1", "VALEUR_METRIQUE_2", "VALEUR_METRIQUE_3");
240
                List<String> fields2copy = Arrays.asList("CODE", "NOM", "VALEUR_METRIQUE_1", "VALEUR_METRIQUE_2", "VALEUR_METRIQUE_3");
242
 
241
 
243
        // Set<Integer> art = new HashSet<Integer>();
242
                Set<Integer> artAdded = new HashSet<Integer>();
244
        for (SQLRowValues sqlRow : commandeClientEltsRows) {
243
                for (SQLRowValues sqlRow : commandeClientEltsRows) {
-
 
244
                    boolean article = false;
-
 
245
                    if (sqlRow.getTable().getName().equalsIgnoreCase("ARTICLE")) {
-
 
246
                        article = true;
-
 
247
                    }
-
 
248
 
-
 
249
                    // renderer sur liste des ar
-
 
250
 
-
 
251
                    // if()
-
 
252
 
-
 
253
                    /// rowValsElt.put("QTE", sqlRow.getObject("QTE"));
-
 
254
                    SQLRowAccessor rowArticleFind;
-
 
255
                    SQLRowValues rowArticle;
-
 
256
                    int qte = 1;
-
 
257
                    BigDecimal qteUV = BigDecimal.ONE;
-
 
258
                    boolean gestionStock = true;
-
 
259
                    if (!article) {
245
            // on récupére l'article qui lui correspond
260
                        // on récupére l'article qui lui correspond
246
            SQLRowValues rowArticle = new SQLRowValues(eltArticle.getTable());
261
                        rowArticle = new SQLRowValues(eltArticle.getTable());
247
            for (String field : fields2copy) {
262
                        for (String field : fields2copy) {
248
                // if (sqlRow.getTable().getFieldsName().contains(field.getName())) {
263
                            // if (sqlRow.getTable().getFieldsName().contains(field.getName())) {
249
                rowArticle.put(field, sqlRow.asRow().getObject(field));
264
                            rowArticle.put(field, sqlRow.asRow().getObject(field));
250
                // }
265
                            // }
251
            }
266
                        }
252
 
267
 
253
            int idArticle = ReferenceArticleSQLElement.getIdForCNM(rowArticle, true);
268
                        int idArticle = ReferenceArticleSQLElement.getIdForCNM(rowArticle, true);
254
            SQLRow rowArticleFind = eltArticle.getTable().getRow(idArticle);
269
                        rowArticleFind = eltArticle.getTable().getRow(idArticle);
255
            if (rowArticleFind != null && !rowArticleFind.isUndefined()) {
-
 
256
                SQLInjector inj = SQLInjector.getInjector(rowArticle.getTable(), tableCmdElt);
-
 
257
                SQLRowValues rowValsElt = new SQLRowValues(inj.createRowValuesFrom(rowArticleFind));
-
 
258
                rowValsElt.put("ID_STYLE", sqlRow.getObject("ID_STYLE"));
-
 
259
 
270
 
-
 
271
                        gestionStock = rowArticleFind.getBoolean("GESTION_STOCK");
260
                // if()
272
                        if (!gestionStock) {
-
 
273
                            qte = sqlRow.getInt("QTE");
-
 
274
                            qteUV = sqlRow.getBigDecimal("QTE_UNITAIRE");
261
 
275
 
262
                rowValsElt.put("QTE", sqlRow.getObject("QTE"));
-
 
263
                rowValsElt.put("T_POIDS", rowValsElt.getLong("POIDS") * rowValsElt.getInt("QTE"));
-
 
264
                rowValsElt.put("T_PA_HT", ((BigDecimal) rowValsElt.getObject("PA_HT")).multiply(new BigDecimal(rowValsElt.getInt("QTE")), DecimalUtils.HIGH_PRECISION));
276
                            if (sqlRow.getObject("ID_UNITE_VENTE") != null && sqlRow.getForeignID("ID_UNITE_VENTE") != UniteVenteArticleSQLElement.A_LA_PIECE) {
265
                rowValsElt.put("T_PA_TTC",
277
                                qteUV = qteUV.multiply(new BigDecimal(qte));
266
                        ((BigDecimal) rowValsElt.getObject("T_PA_HT")).multiply(new BigDecimal((rowValsElt.getForeign("ID_TAXE").getFloat("TAUX") / 100.0 + 1.0)), DecimalUtils.HIGH_PRECISION));
-
 
267
                // rowValsElt.put("ID_DEVISE",
278
                                qte = 1;
268
                // rowCmd.getForeignRow("ID_TARIF").getForeignID("ID_DEVISE"));
-
 
269
                map.add(rowArticleFind.getForeignRow("ID_FOURNISSEUR"), rowValsElt);
-
 
270
            }
279
                            }
271
 
-
 
-
 
280
                        } else {
-
 
281
                            if (rowArticle.getForeign("ID_STOCK") != null && !rowArticle.isForeignEmpty("ID_STOCK")) {
-
 
282
                                SQLRowAccessor rowStock = rowArticle.getForeign("ID_STOCK");
-
 
283
                                qte = -Math.round(rowStock.getFloat("QTE_TH") - rowStock.getFloat("QTE_MIN"));
272
        }
284
                            }
273
        // TODO
-
 
274
        MouvementStockSQLElement.createCommandeF(map, null, "", false);
-
 
275
    }
285
                        }
-
 
286
                    } else {
-
 
287
                        rowArticleFind = sqlRow;
-
 
288
                        rowArticle = sqlRow;
-
 
289
                        if (rowArticle.getForeign("ID_STOCK") != null && !rowArticle.isForeignEmpty("ID_STOCK")) {
-
 
290
                            SQLRowAccessor rowStock = rowArticle.getForeign("ID_STOCK");
-
 
291
                            qte = -Math.round(rowStock.getFloat("QTE_TH") - rowStock.getFloat("QTE_MIN"));
-
 
292
                        }
-
 
293
                    }
-
 
294
                    if (rowArticleFind != null && !rowArticleFind.isUndefined() && (!gestionStock || !artAdded.contains(rowArticleFind.getID()))) {
276
 
295
 
277
    public void createCommandeF(final List<? extends SQLRowAccessor> rowsItems) {
-
 
278
 
-
 
279
        ComptaPropsConfiguration.getInstanceCompta().getNonInteractiveSQLExecutor().execute(new Runnable() {
-
 
280
 
-
 
281
            @Override
-
 
282
            public void run() {
-
 
283
                final ListMap<SQLRow, SQLRowValues> map = new ListMap<SQLRow, SQLRowValues>();
-
 
284
                final Set<Integer> stockChecked = new HashSet<Integer>();
-
 
285
                for (SQLRowAccessor rowItem : rowsItems) {
-
 
286
                    if (rowItem.getObject("ID_ARTICLE") != null && !rowItem.isForeignEmpty("ID_ARTICLE")) {
-
 
287
                        SQLRowAccessor rowArticleFind = rowItem.getForeign("ID_ARTICLE");
-
 
288
 
-
 
289
                        SQLRow row = rowArticleFind.asRow();
296
                        artAdded.add(rowArticleFind.getID());
290
                        SQLRowAccessor rowStock = StockSQLElement.getStock(rowItem);
-
 
291
                        if (!stockChecked.contains(rowStock.getID())) {
-
 
292
                            stockChecked.add(rowStock.getID());
-
 
293
 
297
 
294
                            int value = -Math.round(rowStock.getFloat("QTE_TH") - rowStock.getFloat("QTE_MIN"));
298
                        SQLInjector inj = SQLInjector.getInjector(rowArticle.getTable(), tableCmdElt);
-
 
299
                        SQLRowValues rowValsElt = new SQLRowValues(inj.createRowValuesFrom(rowArticleFind.asRow()));
295
 
300
 
296
                            if (value > 0) {
301
                        rowValsElt.put("ID_STYLE", sqlRow.getObject("ID_STYLE"));
297
 
302
 
298
                                SQLInjector inj = SQLInjector.getInjector(row.getTable(), row.getTable().getTable("COMMANDE_ELEMENT"));
303
                        rowValsElt.put("QTE", qte);
299
                                SQLRowValues rowValsElt = new SQLRowValues(inj.createRowValuesFrom(row));
304
                        rowValsElt.put("QTE_UNITAIRE", qteUV);
300
 
305
 
301
                                rowValsElt.put("QTE", value);
-
 
302
                                rowValsElt.put("T_POIDS", rowValsElt.getLong("POIDS") * rowValsElt.getInt("QTE"));
306
                        rowValsElt.put("T_POIDS", rowValsElt.getLong("POIDS") * rowValsElt.getInt("QTE"));
303
                                rowValsElt.put("T_PA_HT", ((BigDecimal) rowValsElt.getObject("PA_HT")).multiply(new BigDecimal(rowValsElt.getInt("QTE")), DecimalUtils.HIGH_PRECISION));
307
                        rowValsElt.put("T_PA_HT", ((BigDecimal) rowValsElt.getObject("PA_HT")).multiply(new BigDecimal(rowValsElt.getInt("QTE")), DecimalUtils.HIGH_PRECISION));
304
                                rowValsElt.put("T_PA_TTC", ((BigDecimal) rowValsElt.getObject("T_PA_HT")).multiply(new BigDecimal((rowValsElt.getForeign("ID_TAXE").getFloat("TAUX") / 100.0 + 1.0)),
308
                        rowValsElt.put("T_PA_TTC", ((BigDecimal) rowValsElt.getObject("T_PA_HT")).multiply(new BigDecimal((rowValsElt.getForeign("ID_TAXE").getFloat("TAUX") / 100.0 + 1.0)),
305
                                        DecimalUtils.HIGH_PRECISION));
309
                                DecimalUtils.HIGH_PRECISION));
306
                                // rowValsElt.put("ID_DEVISE",
310
                        // rowValsElt.put("ID_DEVISE",
307
                                // rowCmd.getForeignRow("ID_TARIF").getForeignID("ID_DEVISE"));
311
                        // rowCmd.getForeignRow("ID_TARIF").getForeignID("ID_DEVISE"));
308
                                map.add(rowArticleFind.getForeign("ID_FOURNISSEUR").asRow(), rowValsElt);
312
                        map.add(rowArticleFind.asRow().getForeignRow("ID_FOURNISSEUR"), rowValsElt);
309
                            }
-
 
310
                        }
-
 
311
                    }
313
                    }
312
                }
314
                }
-
 
315
 
313
                MouvementStockSQLElement.createCommandeF(map, null, "", false);
316
                MouvementStockSQLElement.createCommandeF(map, null, "");
314
            }
317
            }
315
        });
318
        });
316
 
-
 
317
    }
319
    }
318
 
320
 
319
    protected List<String> getComboFields() {
321
    protected List<String> getComboFields() {
320
        final List<String> l = new ArrayList<String>();
322
        final List<String> l = new ArrayList<String>();
321
        if (getTable().contains("ID_ARTICLE")) {
323
        if (getTable().contains("ID_ARTICLE")) {
Line 336... Line 338...
336
    public ListMap<String, String> getShowAs() {
338
    public ListMap<String, String> getShowAs() {
337
        final ListMap<String, String> res = new ListMap<String, String>();
339
        final ListMap<String, String> res = new ListMap<String, String>();
338
        res.putCollection("ID_COMMANDE_CLIENT", "NUMERO", "DATE", "DATE_LIVRAISON_PREV", "ID_CLIENT");
340
        res.putCollection("ID_COMMANDE_CLIENT", "NUMERO", "DATE", "DATE_LIVRAISON_PREV", "ID_CLIENT");
339
 
341
 
340
        if (getTable().contains("ID_ARTICLE")) {
342
        if (getTable().contains("ID_ARTICLE")) {
341
            res.putCollection("ID_ARTICLE", "ID_FAMILLE_ARTICLE", "ID_FOURNISSEUR");
343
            res.putCollection("ID_ARTICLE", "GESTION_STOCK", "ID_FAMILLE_ARTICLE", "ID_FOURNISSEUR");
342
        }
344
        }
343
        res.putCollection(null, "NOM");
345
        res.putCollection(null, "NOM");
344
        return res;
346
        return res;
345
    }
347
    }
346
 
348