OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 156 Rev 174
Line 23... Line 23...
23
import org.openconcerto.sql.model.SQLRowAccessor;
23
import org.openconcerto.sql.model.SQLRowAccessor;
24
import org.openconcerto.sql.model.SQLRowValues;
24
import org.openconcerto.sql.model.SQLRowValues;
25
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
25
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
26
import org.openconcerto.sql.model.SQLSelect;
26
import org.openconcerto.sql.model.SQLSelect;
27
import org.openconcerto.sql.model.SQLTable;
27
import org.openconcerto.sql.model.SQLTable;
-
 
28
import org.openconcerto.sql.model.SQLTableEvent;
-
 
29
import org.openconcerto.sql.model.SQLTableEvent.Mode;
28
import org.openconcerto.sql.model.Where;
30
import org.openconcerto.sql.model.Where;
29
import org.openconcerto.sql.utils.SQLUtils;
31
import org.openconcerto.sql.utils.SQLUtils;
30
import org.openconcerto.utils.DecimalUtils;
32
import org.openconcerto.utils.DecimalUtils;
31
import org.openconcerto.utils.ExceptionHandler;
33
import org.openconcerto.utils.ExceptionHandler;
32
import org.openconcerto.utils.ListMap;
34
import org.openconcerto.utils.ListMap;
Line 152... Line 154...
152
 
154
 
153
        final List<? extends ResultSetHandler> handlers = new ArrayList<ResultSetHandler>(requests.size());
155
        final List<? extends ResultSetHandler> handlers = new ArrayList<ResultSetHandler>(requests.size());
154
        for (String s : requests) {
156
        for (String s : requests) {
155
            handlers.add(null);
157
            handlers.add(null);
156
        }
158
        }
157
        // FIXME FIRE TABLE CHANGED TO UPDATE ILISTE ??
-
 
158
        try {
159
        try {
159
            SQLUtils.executeAtomic(stockTable.getDBSystemRoot().getDataSource(), new ConnectionHandlerNoSetup<Object, IOException>() {
160
            SQLUtils.executeAtomic(stockTable.getDBSystemRoot().getDataSource(), new ConnectionHandlerNoSetup<Object, IOException>() {
160
                @Override
161
                @Override
161
                public Object handle(SQLDataSource ds) throws SQLException, IOException {
162
                public Object handle(SQLDataSource ds) throws SQLException, IOException {
162
                    SQLUtils.executeMultiple(stockTable.getDBSystemRoot(), requests, handlers);
163
                    SQLUtils.executeMultiple(stockTable.getDBSystemRoot(), requests, handlers);
-
 
164
                    // FIXME FIRE ONLY CHANGED ROWS
-
 
165
                    stockTable.fire(new SQLTableEvent(stockTable, SQLRow.NONEXISTANT_ID, Mode.ROW_UPDATED));
163
                    return null;
166
                    return null;
164
                }
167
                }
165
            });
168
            });
166
        } catch (IOException e) {
169
        } catch (IOException e) {
167
            ExceptionHandler.handle("Erreur de la mise à jour des stocks!", e);
170
            ExceptionHandler.handle("Erreur de la mise à jour des stocks!", e);
Line 262... Line 265...
262
            handlers.add(null);
265
            handlers.add(null);
263
        }
266
        }
264
        SQLUtils.executeMultiple(table.getDBSystemRoot(), multipleRequests, handlers);
267
        SQLUtils.executeMultiple(table.getDBSystemRoot(), multipleRequests, handlers);
265
    }
268
    }
266
 
269
 
267
    private void fillProductComponent(List<ProductComponent> productComponents, int qte, int index, int level) {
-
 
268
        if (level > 0) {
-
 
269
            for (int i = index; i < items.size(); i++) {
-
 
270
                SQLRowAccessor r = items.get(i);
-
 
271
 
-
 
272
                if (!r.getTable().contains("NIVEAU") || r.getInt("NIVEAU") >= level) {
-
 
273
                    // On ne calcul pas les stocks pour les éléments ayant des fils (le mouvement de
-
 
274
                    // stock
-
 
275
                    // des fils impactera les stocks automatiquement)
-
 
276
                    if (r.getTable().contains("NIVEAU")) {
-
 
277
                        if (i + 1 < items.size()) {
-
 
278
                            SQLRowAccessor rNext = items.get(i + 1);
-
 
279
                            if (rNext.getInt("NIVEAU") > r.getInt("NIVEAU")) {
-
 
280
                                fillProductComponent(productComponents, qte * r.getInt("QTE"), i + 1, rNext.getInt("NIVEAU"));
-
 
281
                                continue;
-
 
282
                            }
-
 
283
                        }
-
 
284
                    }
-
 
285
                    if ((!r.getTable().contains("NIVEAU") || r.getInt("NIVEAU") == level) && !r.isForeignEmpty("ID_ARTICLE") && r.getForeign("ID_ARTICLE") != null) {
-
 
286
                        productComponents.add(ProductComponent.createFrom(r, qte, r));
-
 
287
                    }
-
 
288
                } else if (r.getInt("NIVEAU") < level) {
-
 
289
                    // BREAK si on sort de l'article composé
-
 
290
                    break;
-
 
291
                }
-
 
292
            }
-
 
293
        }
-
 
294
    }
-
 
295
 
-
 
296
    /**
270
    /**
297
     * Récupére les stocks associés aux articles non composés (inclus les fils des nomenclatures) et
271
     * Récupére les stocks associés aux articles non composés (inclus les fils des nomenclatures) et
298
     * les met à jour
272
     * les met à jour
299
     * 
273
     * 
300
     * @return la liste des stocks à jour
274
     * @return la liste des stocks à jour
Line 303... Line 277...
303
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
277
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
304
        Map<Number, StockItem> stockItems = new HashMap<Number, StockItem>();
278
        Map<Number, StockItem> stockItems = new HashMap<Number, StockItem>();
305
 
279
 
306
        String mvtStockTableQuoted = rowSource.getTable().getTable("MOUVEMENT_STOCK").getSQLName().quote();
280
        String mvtStockTableQuoted = rowSource.getTable().getTable("MOUVEMENT_STOCK").getSQLName().quote();
307
 
281
 
-
 
282
        ProductHelper helper = new ProductHelper(rowSource.getTable().getDBRoot());
308
        // Liste des éléments à mettre à jour
283
        // Liste des éléments à mettre à jour
309
        List<ProductComponent> productComponents = new ArrayList<ProductComponent>();
284
        List<ProductComponent> productComponents = new ArrayList<ProductComponent>();
310
        fillProductComponent(productComponents, 1, 0, 1);
285
        helper.fillProductComponent(this.items, productComponents, 1, 0, 1);
311
        // for (int i = 0; i < items.size(); i++) {
286
        // for (int i = 0; i < items.size(); i++) {
312
        // SQLRowAccessor r = items.get(i);
287
        // SQLRowAccessor r = items.get(i);
313
        //
288
        //
314
        // // On ne calcul pas les stocks pour les éléments ayant des fils (le mouvement de stock
289
        // // On ne calcul pas les stocks pour les éléments ayant des fils (le mouvement de stock
315
        // // des fils impactera les stocks automatiquement)
290
        // // des fils impactera les stocks automatiquement)
Line 325... Line 300...
325
        // productComponents.add(ProductComponent.createFrom(r));
300
        // productComponents.add(ProductComponent.createFrom(r));
326
        // }
301
        // }
327
        // }
302
        // }
328
 
303
 
329
        // Liste des articles non composés à mettre à jour (avec les fils des nomenclatures)
304
        // Liste des articles non composés à mettre à jour (avec les fils des nomenclatures)
330
        ProductHelper helper = new ProductHelper(rowSource.getTable().getDBRoot());
-
 
331
        List<ProductComponent> boms = helper.getChildWithQtyFrom(productComponents);
305
        List<ProductComponent> boms = helper.getChildWithQtyFrom(productComponents);
332
 
306
 
333
        for (ProductComponent productComp : boms) {
307
        for (ProductComponent productComp : boms) {
334
 
308
 
335
            if (productComp.getProduct().getBoolean("GESTION_STOCK") && productComp.getQty().signum() != 0) {
309
            if (productComp.getProduct().getBoolean("GESTION_STOCK") && productComp.getQty().signum() != 0) {