185 |
ilm |
1 |
/*
|
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
|
|
3 |
*
|
|
|
4 |
* Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
|
|
|
5 |
*
|
|
|
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
|
|
|
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.
|
|
|
10 |
*
|
|
|
11 |
* When distributing the software, include this License Header Notice in each file.
|
|
|
12 |
*/
|
|
|
13 |
|
|
|
14 |
package org.openconcerto.erp.core.supplychain.stock.element;
|
|
|
15 |
|
|
|
16 |
import org.openconcerto.erp.core.sales.product.element.LotSQLElement;
|
|
|
17 |
import org.openconcerto.sql.element.SQLElement;
|
|
|
18 |
import org.openconcerto.sql.model.FieldPath;
|
|
|
19 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
|
|
20 |
import org.openconcerto.sql.model.SQLRowValues;
|
|
|
21 |
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
|
|
|
22 |
import org.openconcerto.sql.model.SQLTable;
|
|
|
23 |
import org.openconcerto.sql.model.Where;
|
|
|
24 |
import org.openconcerto.sql.model.graph.Path;
|
|
|
25 |
|
|
|
26 |
import java.util.ArrayList;
|
|
|
27 |
import java.util.HashMap;
|
|
|
28 |
import java.util.List;
|
|
|
29 |
import java.util.Map;
|
|
|
30 |
|
|
|
31 |
public class StockRootNode {
|
|
|
32 |
private final List<StockNode> children = new ArrayList<>();
|
|
|
33 |
private final List<SQLRowValues> listRowValsStock = new ArrayList<>();
|
|
|
34 |
private final List<FieldPath> cols = new ArrayList<>();
|
|
|
35 |
private final SQLElement eltStock;
|
|
|
36 |
private boolean hasBatch = false;
|
|
|
37 |
|
|
|
38 |
public StockRootNode(SQLElement e) {
|
|
|
39 |
this.eltStock = e;
|
|
|
40 |
final SQLTable tableStock = this.eltStock.getTable();
|
|
|
41 |
final Path pStock = new Path(tableStock);
|
|
|
42 |
final Path pDepotStock = pStock.add(tableStock.getField("ID_DEPOT_STOCK"));
|
|
|
43 |
this.cols.add(new FieldPath(pDepotStock, "NOM"));
|
|
|
44 |
this.cols.add(new FieldPath(pStock, "QTE_TH"));
|
|
|
45 |
this.cols.add(new FieldPath(pStock, "QTE_RECEPT_ATTENTE"));
|
|
|
46 |
this.cols.add(new FieldPath(pStock, "QTE_LIV_ATTENTE"));
|
|
|
47 |
this.cols.add(new FieldPath(pStock, "QTE_REEL"));
|
|
|
48 |
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
public void load(SQLRowAccessor article) {
|
|
|
52 |
|
|
|
53 |
this.children.clear();
|
|
|
54 |
final SQLTable tableStock = this.eltStock.getTable();
|
|
|
55 |
final SQLRowValues rowValsStock = new SQLRowValues(tableStock);
|
|
|
56 |
rowValsStock.putNulls("QTE_TH", "QTE_RECEPT_ATTENTE", "QTE_LIV_ATTENTE", "QTE_REEL");
|
|
|
57 |
rowValsStock.putRowValues("ID_DEPOT_STOCK").putNulls("NOM");
|
|
|
58 |
|
|
|
59 |
final SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(rowValsStock);
|
|
|
60 |
final List<SQLRowValues> fetch = fetcher.fetch(
|
|
|
61 |
new Where(tableStock.getField("ID_ARTICLE"), "=", article.getID()).and(new Where(tableStock.getField("QTE_REEL"), "!=", 0).or(new Where(tableStock.getField("QTE_TH"), "!=", 0))));
|
|
|
62 |
this.listRowValsStock.clear();
|
|
|
63 |
this.listRowValsStock.addAll(fetch);
|
|
|
64 |
final List<Integer> idsStock = new ArrayList<>();
|
|
|
65 |
for (SQLRowValues r : this.listRowValsStock) {
|
|
|
66 |
idsStock.add(r.getID());
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
final SQLTable tableLot = this.eltStock.getDirectory().getElement(LotSQLElement.class).getTable();
|
|
|
70 |
SQLRowValues rLot = new SQLRowValues(tableLot);
|
|
|
71 |
rLot.putNulls("ID_STOCK", "QUANTITE", "NUMERO_LOT", "NUMERO_SERIE", "DLC", "DLUO");
|
|
|
72 |
final List<SQLRowValues> fetchLots = SQLRowValuesListFetcher.create(rLot).fetch(Where.inValues(tableLot.getField("ID_STOCK"), idsStock));
|
|
|
73 |
this.hasBatch = !fetchLots.isEmpty();
|
|
|
74 |
|
|
|
75 |
final Map<Integer, List<BatchNode>> stockLots = new HashMap<>();
|
|
|
76 |
for (SQLRowValues lot : fetchLots) {
|
|
|
77 |
int idStock = lot.getInt("ID_STOCK");
|
|
|
78 |
List<BatchNode> lots = stockLots.get(idStock);
|
|
|
79 |
if (lots == null) {
|
|
|
80 |
lots = new ArrayList<>();
|
|
|
81 |
stockLots.put(idStock, lots);
|
|
|
82 |
}
|
|
|
83 |
lots.add(new BatchNode(lot));
|
|
|
84 |
}
|
|
|
85 |
for (SQLRowValues r : this.listRowValsStock) {
|
|
|
86 |
this.children.add(new StockNode(r, stockLots.get(r.getID())));
|
|
|
87 |
}
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
public boolean hasBatch() {
|
|
|
91 |
return this.hasBatch;
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
public StockNode getChild(int i) {
|
|
|
95 |
return this.children.get(i);
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
public int getSize() {
|
|
|
99 |
return this.children.size();
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
public String getLabelFor(int column) {
|
|
|
103 |
return this.eltStock.getDirectory().getTranslator().getLabelFor(this.cols.get(column).getField()).replace("Quantité", "Quantité\n");
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
public FieldPath getFieldPath(int columnIndex) {
|
|
|
107 |
final FieldPath fieldPath = this.cols.get(columnIndex);
|
|
|
108 |
return fieldPath;
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
}
|