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 56... Line 56...
56
    private final StockLabel label;
56
    private final StockLabel label;
57
    private final List<? extends SQLRowAccessor> items;
57
    private final List<? extends SQLRowAccessor> items;
58
    private final TypeStockUpdate type;
58
    private final TypeStockUpdate type;
59
    private final boolean createMouvementStock;
59
    private final boolean createMouvementStock;
60
    private final SQLRowAccessor rowSource;
60
    private final SQLRowAccessor rowSource;
-
 
61
    private boolean resetStockTH = false;
61
 
62
 
62
    private boolean headless = false;
63
    private boolean headless = false;
63
 
64
 
64
    public static enum TypeStockUpdate {
65
    public static enum TypeStockUpdate {
65
 
66
 
Line 133... Line 134...
133
                SQLRowValues rowVals = new SQLRowValues(stockTable);
134
                SQLRowValues rowVals = new SQLRowValues(stockTable);
134
                rowVals.put("QTE_REEL", stockItem.getRealQty());
135
                rowVals.put("QTE_REEL", stockItem.getRealQty());
135
                rowVals.put("QTE_TH", stockItem.getVirtualQty());
136
                rowVals.put("QTE_TH", stockItem.getVirtualQty());
136
                rowVals.put("QTE_LIV_ATTENTE", stockItem.getDeliverQty());
137
                rowVals.put("QTE_LIV_ATTENTE", stockItem.getDeliverQty());
137
                rowVals.put("QTE_RECEPT_ATTENTE", stockItem.getReceiptQty());
138
                rowVals.put("QTE_RECEPT_ATTENTE", stockItem.getReceiptQty());
-
 
139
                rowVals.put("ID_ARTICLE", stockItem.getArticle().getID());
-
 
140
                rowVals.put("ID_DEPOT_STOCK", stockItem.stock.getForeignID("ID_DEPOT_STOCK"));
-
 
141
                rowVals.commit();
-
 
142
                if (stockItem.getArticle().getForeignID("ID_DEPOT_STOCK") == stockItem.stock.getForeignID("ID_DEPOT_STOCK")) {
138
                SQLRowValues rowValsArt = stockItem.getArticle().createEmptyUpdateRow();
143
                    SQLRowValues rowValsArt = stockItem.getArticle().createEmptyUpdateRow();
139
                rowValsArt.put("ID_STOCK", rowVals);
144
                    rowValsArt.put("ID_STOCK", rowVals);
140
                rowValsArt.commit();
145
                    rowValsArt.commit();
141
            }
146
                }
-
 
147
            }
142
            if (!this.type.isEntry()) {
148
            if (!this.type.isEntry()) {
143
                stockItem.fillCommandeFournisseur(cmd);
149
                stockItem.fillCommandeFournisseur(cmd);
144
            }
150
            }
145
        }
151
        }
146
 
152
 
Line 208... Line 214...
208
        rowValsStock.put("QTE_REEL", null);
214
        rowValsStock.put("QTE_REEL", null);
209
        rowValsStock.put("QTE_TH", null);
215
        rowValsStock.put("QTE_TH", null);
210
        rowValsStock.put("QTE_RECEPT_ATTENTE", null);
216
        rowValsStock.put("QTE_RECEPT_ATTENTE", null);
211
        rowValsStock.put("QTE_LIV_ATTENTE", null);
217
        rowValsStock.put("QTE_LIV_ATTENTE", null);
212
 
218
 
213
        rowValsArt.put("ID_STOCK", rowValsStock);
219
        rowVals.put("ID_STOCK", rowValsStock);
214
        rowVals.put("ID_ARTICLE", rowValsArt);
220
        rowVals.put("ID_ARTICLE", rowValsArt);
215
 
221
 
216
        SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(rowVals);
222
        SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(rowVals);
217
        fetcher.setSelTransf(new ITransformer<SQLSelect, SQLSelect>() {
223
        fetcher.setSelTransf(new ITransformer<SQLSelect, SQLSelect>() {
218
 
224
 
Line 231... Line 237...
231
        // on archive un mvt reel et theorique)
237
        // on archive un mvt reel et theorique)
232
        Map<Number, StockItem> items = new HashMap<Number, StockItem>();
238
        Map<Number, StockItem> items = new HashMap<Number, StockItem>();
233
        List<SQLRowValues> result = fetcher.fetch();
239
        List<SQLRowValues> result = fetcher.fetch();
234
        for (SQLRowValues sqlRowValues : result) {
240
        for (SQLRowValues sqlRowValues : result) {
235
            final StockItem item;
241
            final StockItem item;
236
            if (!items.containsKey(sqlRowValues.getForeignIDNumber("ID_ARTICLE"))) {
242
            if (!items.containsKey(sqlRowValues.getForeignIDNumber("ID_STOCK"))) {
237
                item = new StockItem(sqlRowValues.getForeign("ID_ARTICLE"));
243
                item = new StockItem(sqlRowValues.getForeign("ID_ARTICLE"), sqlRowValues.getForeign("ID_STOCK"));
238
                items.put(sqlRowValues.getForeignIDNumber("ID_ARTICLE"), item);
244
                items.put(sqlRowValues.getForeignIDNumber("ID_STOCK"), item);
239
            } else {
245
            } else {
240
                item = items.get(sqlRowValues.getForeignIDNumber("ID_ARTICLE"));
246
                item = items.get(sqlRowValues.getForeignIDNumber("ID_STOCK"));
241
            }
247
            }
242
            final TypeStockMouvement t;
248
            final TypeStockMouvement t;
243
            if (sqlRowValues.getBoolean("REEL")) {
249
            if (sqlRowValues.getBoolean("REEL")) {
244
                t = TypeStockMouvement.REEL;
250
                t = TypeStockMouvement.REEL;
245
            } else {
251
            } else {
Line 275... Line 281...
275
                                continue;
281
                                continue;
276
                            }
282
                            }
277
                        }
283
                        }
278
                    }
284
                    }
279
                    if ((!r.getTable().contains("NIVEAU") || r.getInt("NIVEAU") == level) && !r.isForeignEmpty("ID_ARTICLE") && r.getForeign("ID_ARTICLE") != null) {
285
                    if ((!r.getTable().contains("NIVEAU") || r.getInt("NIVEAU") == level) && !r.isForeignEmpty("ID_ARTICLE") && r.getForeign("ID_ARTICLE") != null) {
280
                        productComponents.add(ProductComponent.createFrom(r, qte));
286
                        productComponents.add(ProductComponent.createFrom(r, qte, r));
281
                    }
287
                    }
282
                } else if (r.getInt("NIVEAU") < level) {
288
                } else if (r.getInt("NIVEAU") < level) {
283
                    // BREAK si on sort de l'article composé
289
                    // BREAK si on sort de l'article composé
284
                    break;
290
                    break;
285
                }
291
                }
Line 293... Line 299...
293
     * 
299
     * 
294
     * @return la liste des stocks à jour
300
     * @return la liste des stocks à jour
295
     */
301
     */
296
    private List<StockItem> fetch() {
302
    private List<StockItem> fetch() {
297
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
303
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
298
        List<StockItem> stockItems = new ArrayList<StockItem>(items.size());
304
        Map<Number, StockItem> stockItems = new HashMap<Number, StockItem>();
-
 
305
 
299
        String mvtStockTableQuoted = rowSource.getTable().getTable("MOUVEMENT_STOCK").getSQLName().quote();
306
        String mvtStockTableQuoted = rowSource.getTable().getTable("MOUVEMENT_STOCK").getSQLName().quote();
300
 
307
 
301
        // Liste des éléments à mettre à jour
308
        // Liste des éléments à mettre à jour
302
        List<ProductComponent> productComponents = new ArrayList<ProductComponent>();
309
        List<ProductComponent> productComponents = new ArrayList<ProductComponent>();
303
        fillProductComponent(productComponents, 1, 0, 1);
310
        fillProductComponent(productComponents, 1, 0, 1);
Line 324... Line 331...
324
        List<ProductComponent> boms = helper.getChildWithQtyFrom(productComponents);
331
        List<ProductComponent> boms = helper.getChildWithQtyFrom(productComponents);
325
 
332
 
326
        for (ProductComponent productComp : boms) {
333
        for (ProductComponent productComp : boms) {
327
 
334
 
328
            if (productComp.getProduct().getBoolean("GESTION_STOCK") && productComp.getQty().signum() != 0) {
335
            if (productComp.getProduct().getBoolean("GESTION_STOCK") && productComp.getQty().signum() != 0) {
-
 
336
                final StockItem stockItem;
-
 
337
                if (!stockItems.containsKey(productComp.getStock().getID())) {
329
                StockItem stockItem = new StockItem(productComp.getProduct());
338
                    stockItem = new StockItem(productComp.getProduct(), productComp.getStock());
-
 
339
                    stockItems.put(productComp.getStock().getID(), stockItem);
-
 
340
                } else {
-
 
341
                    stockItem = stockItems.get(productComp.getStock().getID());
-
 
342
                }
330
                double qteFinal = productComp.getQty().doubleValue();
343
                double qteFinal = productComp.getQty().doubleValue();
331
 
344
 
332
                // reliquat
345
                // reliquat
333
                for (Tuple3<SQLRowAccessor, Integer, BigDecimal> t : reliquat) {
346
                for (Tuple3<SQLRowAccessor, Integer, BigDecimal> t : reliquat) {
334
                    if (stockItem.getArticle() != null && stockItem.getArticle().equalsAsRow(t.get0())) {
347
                    if (stockItem.getArticle() != null && stockItem.getArticle().equalsAsRow(t.get0())) {
Line 339... Line 352...
339
                if (!this.type.isEntry()) {
352
                if (!this.type.isEntry()) {
340
                    qteFinal = -qteFinal;
353
                    qteFinal = -qteFinal;
341
                }
354
                }
342
 
355
 
343
                stockItem.updateQty(qteFinal, this.type.getType());
356
                stockItem.updateQty(qteFinal, this.type.getType());
344
                stockItems.add(stockItem);
-
 
-
 
357
 
345
                if (this.createMouvementStock) {
358
                if (this.createMouvementStock) {
346
                    final Date time = this.rowSource.getDate("DATE").getTime();
359
                    final Date time = this.rowSource.getDate("DATE").getTime();
347
                    BigDecimal prc = productComp.getPRC(time);
360
                    BigDecimal prc = productComp.getPRC(time);
348
                    if (this.type.getType() == TypeStockMouvement.REEL || this.type.getType() == TypeStockMouvement.REEL_THEORIQUE || this.type.getType() == TypeStockMouvement.RETOUR) {
361
                    if (this.type.getType() == TypeStockMouvement.REEL || this.type.getType() == TypeStockMouvement.REEL_THEORIQUE || this.type.getType() == TypeStockMouvement.RETOUR) {
349
                        String mvtStockQuery = "INSERT INTO " + mvtStockTableQuoted + " (\"QTE\",\"DATE\",\"ID_ARTICLE\",\"SOURCE\",\"IDSOURCE\",\"NOM\",\"REEL\",\"ORDRE\"";
362
                        String mvtStockQuery = "INSERT INTO " + mvtStockTableQuoted + " (\"QTE\",\"DATE\",\"ID_ARTICLE\",\"ID_STOCK\",\"SOURCE\",\"IDSOURCE\",\"NOM\",\"REEL\",\"ORDRE\"";
350
 
363
 
351
                        if (prc != null) {
364
                        if (prc != null) {
352
                            mvtStockQuery += ",\"PRICE\"";
365
                            mvtStockQuery += ",\"PRICE\"";
353
                        }
366
                        }
354
 
367
 
355
                        mvtStockQuery += ") VALUES(" + qteFinal + ",'" + dateFormat.format(time) + "'," + productComp.getProduct().getID() + ",'" + this.rowSource.getTable().getName() + "',"
368
                        mvtStockQuery += ") VALUES(" + qteFinal + ",'" + dateFormat.format(time) + "'," + productComp.getProduct().getID() + "," + productComp.getStock().getID() + ",'"
356
                                + this.rowSource.getID() + ",'" + this.label.getLabel(this.rowSource, productComp.getProduct()) + "',true, (SELECT (MAX(\"ORDRE\")+1) FROM " + mvtStockTableQuoted
369
                                + this.rowSource.getTable().getName() + "'," + this.rowSource.getID() + ",'" + this.label.getLabel(this.rowSource, productComp.getProduct())
357
                                + ")";
370
                                + "',true, (SELECT (MAX(\"ORDRE\")+1) FROM " + mvtStockTableQuoted + ")";
358
                        if (prc != null) {
371
                        if (prc != null) {
359
                            mvtStockQuery += "," + prc.setScale(6, RoundingMode.HALF_UP).toString();
372
                            mvtStockQuery += "," + prc.setScale(6, RoundingMode.HALF_UP).toString();
360
                        }
373
                        }
361
                        mvtStockQuery += ")";
374
                        mvtStockQuery += ")";
362
                        this.requests.add(mvtStockQuery);
375
                        this.requests.add(mvtStockQuery);
363
                    }
376
                    }
364
                    if (this.type.getType() == TypeStockMouvement.THEORIQUE || this.type.getType() == TypeStockMouvement.REEL_THEORIQUE || this.type.getType() == TypeStockMouvement.RETOUR) {
377
                    if (this.type.getType() == TypeStockMouvement.THEORIQUE || this.type.getType() == TypeStockMouvement.REEL_THEORIQUE || this.type.getType() == TypeStockMouvement.RETOUR) {
365
                        String mvtStockQuery = "INSERT INTO " + mvtStockTableQuoted + " (\"QTE\",\"DATE\",\"ID_ARTICLE\",\"SOURCE\",\"IDSOURCE\",\"NOM\",\"REEL\",\"ORDRE\"";
378
                        String mvtStockQuery = "INSERT INTO " + mvtStockTableQuoted + " (\"QTE\",\"DATE\",\"ID_ARTICLE\",\"ID_STOCK\",\"SOURCE\",\"IDSOURCE\",\"NOM\",\"REEL\",\"ORDRE\"";
366
                        if (prc != null) {
379
                        if (prc != null) {
367
                            mvtStockQuery += ",\"PRICE\"";
380
                            mvtStockQuery += ",\"PRICE\"";
368
                        }
381
                        }
369
 
382
 
370
                        mvtStockQuery += ") VALUES(" + qteFinal + ",'" + dateFormat.format(time) + "'," + productComp.getProduct().getID() + ",'" + this.rowSource.getTable().getName() + "',"
383
                        mvtStockQuery += ") VALUES(" + qteFinal + ",'" + dateFormat.format(time) + "'," + productComp.getProduct().getID() + "," + productComp.getStock().getID() + ",'"
371
                                + this.rowSource.getID() + ",'" + this.label.getLabel(this.rowSource, productComp.getProduct()) + "',false, (SELECT (MAX(\"ORDRE\")+1) FROM " + mvtStockTableQuoted
384
                                + this.rowSource.getTable().getName() + "'," + this.rowSource.getID() + ",'" + this.label.getLabel(this.rowSource, productComp.getProduct())
372
                                + ")";
385
                                + "',false, (SELECT (MAX(\"ORDRE\")+1) FROM " + mvtStockTableQuoted + ")";
373
                        if (prc != null) {
386
                        if (prc != null) {
374
                            mvtStockQuery += "," + prc.setScale(6, RoundingMode.HALF_UP).toString();
387
                            mvtStockQuery += "," + prc.setScale(6, RoundingMode.HALF_UP).toString();
375
                        }
388
                        }
376
                        mvtStockQuery += ")";
389
                        mvtStockQuery += ")";
377
                        this.requests.add(mvtStockQuery);
390
                        this.requests.add(mvtStockQuery);
378
                    }
391
                    }
379
                }
392
                }
380
            }
393
            }
381
        }
394
        }
382
 
395
 
-
 
396
        return new ArrayList<StockItem>(stockItems.values());
-
 
397
    }
-
 
398
 
-
 
399
    public void setResetStockTH(boolean resetStockTH) {
383
        return stockItems;
400
        this.resetStockTH = resetStockTH;
384
    }
401
    }
385
}
402
}