Line 1... |
Line 1... |
1 |
/*
|
1 |
/*
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
3 |
*
|
3 |
*
|
4 |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
|
4 |
* Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
|
5 |
*
|
5 |
*
|
6 |
* The contents of this file are subject to the terms of the GNU General Public License Version 3
|
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
|
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
|
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.
|
9 |
* language governing permissions and limitations under the License.
|
Line 16... |
Line 16... |
16 |
import org.openconcerto.erp.core.sales.product.model.ProductComponent;
|
16 |
import org.openconcerto.erp.core.sales.product.model.ProductComponent;
|
17 |
import org.openconcerto.erp.core.sales.product.model.ProductHelper;
|
17 |
import org.openconcerto.erp.core.sales.product.model.ProductHelper;
|
18 |
import org.openconcerto.erp.core.sales.product.model.ProductHelper.SupplierPriceField;
|
18 |
import org.openconcerto.erp.core.sales.product.model.ProductHelper.SupplierPriceField;
|
19 |
import org.openconcerto.erp.importer.ArrayTableModel;
|
19 |
import org.openconcerto.erp.importer.ArrayTableModel;
|
20 |
import org.openconcerto.erp.importer.DataImporter;
|
20 |
import org.openconcerto.erp.importer.DataImporter;
|
- |
|
21 |
import org.openconcerto.erp.preferences.GestionArticleGlobalPreferencePanel;
|
21 |
import org.openconcerto.sql.Configuration;
|
22 |
import org.openconcerto.sql.Configuration;
|
- |
|
23 |
import org.openconcerto.sql.element.SQLElement;
|
22 |
import org.openconcerto.sql.model.DBRoot;
|
24 |
import org.openconcerto.sql.model.DBRoot;
|
23 |
import org.openconcerto.sql.model.SQLRow;
|
25 |
import org.openconcerto.sql.model.SQLRow;
|
24 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
26 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
- |
|
27 |
import org.openconcerto.sql.model.SQLRowListRSH;
|
25 |
import org.openconcerto.sql.model.SQLRowValues;
|
28 |
import org.openconcerto.sql.model.SQLRowValues;
|
26 |
import org.openconcerto.sql.model.SQLRowValuesCluster.StoreMode;
|
29 |
import org.openconcerto.sql.model.SQLRowValuesCluster.StoreMode;
|
27 |
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
|
30 |
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
|
- |
|
31 |
import org.openconcerto.sql.model.SQLSelect;
|
28 |
import org.openconcerto.sql.model.SQLTable;
|
32 |
import org.openconcerto.sql.model.SQLTable;
|
- |
|
33 |
import org.openconcerto.sql.preferences.SQLPreferences;
|
29 |
import org.openconcerto.sql.utils.SQLUtils;
|
34 |
import org.openconcerto.sql.utils.SQLUtils;
|
30 |
import org.openconcerto.utils.Tuple2;
|
35 |
import org.openconcerto.utils.Tuple2;
|
- |
|
36 |
import org.openconcerto.utils.Tuple3;
|
31 |
|
37 |
|
32 |
import java.io.File;
|
38 |
import java.io.File;
|
33 |
import java.io.IOException;
|
39 |
import java.io.IOException;
|
34 |
import java.math.BigDecimal;
|
40 |
import java.math.BigDecimal;
|
35 |
import java.sql.SQLException;
|
41 |
import java.sql.SQLException;
|
36 |
import java.util.ArrayList;
|
42 |
import java.util.ArrayList;
|
- |
|
43 |
import java.util.Arrays;
|
37 |
import java.util.Calendar;
|
44 |
import java.util.Calendar;
|
38 |
import java.util.Collection;
|
45 |
import java.util.Collection;
|
39 |
import java.util.Date;
|
46 |
import java.util.Date;
|
40 |
import java.util.HashMap;
|
47 |
import java.util.HashMap;
|
41 |
import java.util.List;
|
48 |
import java.util.List;
|
42 |
import java.util.Map;
|
49 |
import java.util.Map;
|
- |
|
50 |
import java.util.Map.Entry;
|
43 |
import java.util.Set;
|
51 |
import java.util.Set;
|
44 |
|
52 |
|
- |
|
53 |
import javax.swing.JOptionPane;
|
- |
|
54 |
|
45 |
import org.apache.commons.dbutils.ResultSetHandler;
|
55 |
import org.apache.commons.dbutils.ResultSetHandler;
|
46 |
|
56 |
|
47 |
public class InventaireFromEtatStockImporter {
|
57 |
public class InventaireFromEtatStockImporter {
|
48 |
|
58 |
|
49 |
private Map<String, SQLRowValues> kits = new HashMap<String, SQLRowValues>();
|
59 |
private Map<String, SQLRowValues> kits = new HashMap<String, SQLRowValues>();
|
50 |
private List<String> codeKits = new ArrayList<String>();
|
60 |
private List<String> codeKits = new ArrayList<String>();
|
51 |
private SQLRowAccessor depot;
|
61 |
private SQLRowAccessor depot;
|
- |
|
62 |
private static String FAMILLE = "Famille";
|
- |
|
63 |
private static String CODE = "Code";
|
- |
|
64 |
private static String NOM = "Nom";
|
- |
|
65 |
private static String TAILLE = "Taille";
|
- |
|
66 |
private static String COULEUR = "Couleur";
|
- |
|
67 |
private static String QTE = "Qté réelle relevée";
|
- |
|
68 |
private static String QTE_OPENCONCERTO = "QTE OpenConcerto";
|
- |
|
69 |
private final Map<String, Integer> mapCouleur = new HashMap<String, Integer>();
|
- |
|
70 |
private final Map<String, Integer> mapTaille = new HashMap<String, Integer>();
|
- |
|
71 |
private final DBRoot root;
|
- |
|
72 |
private final SQLElement artElt;
|
52 |
|
73 |
|
53 |
public InventaireFromEtatStockImporter(SQLRowAccessor depot) {
|
74 |
public InventaireFromEtatStockImporter(SQLElement articleElt, SQLRowAccessor depot) {
|
54 |
this.depot = depot;
|
75 |
this.depot = depot;
|
- |
|
76 |
this.root = articleElt.getTable().getDBRoot();
|
- |
|
77 |
this.artElt = articleElt;
|
- |
|
78 |
{
|
- |
|
79 |
SQLSelect sel = new SQLSelect();
|
- |
|
80 |
sel.addSelect(articleElt.getTable().getTable("ARTICLE_DECLINAISON_COULEUR").getKey());
|
- |
|
81 |
sel.addSelect(articleElt.getTable().getTable("ARTICLE_DECLINAISON_COULEUR").getField("NOM"));
|
- |
|
82 |
|
- |
|
83 |
List<SQLRow> l = SQLRowListRSH.execute(sel);
|
- |
|
84 |
|
- |
|
85 |
for (SQLRow sqlRow : l) {
|
- |
|
86 |
mapCouleur.put(sqlRow.getString("NOM").trim(), sqlRow.getID());
|
- |
|
87 |
}
|
- |
|
88 |
}
|
- |
|
89 |
|
- |
|
90 |
{
|
- |
|
91 |
SQLSelect sel = new SQLSelect();
|
- |
|
92 |
sel.addSelect(articleElt.getTable().getTable("ARTICLE_DECLINAISON_TAILLE").getKey());
|
- |
|
93 |
sel.addSelect(articleElt.getTable().getTable("ARTICLE_DECLINAISON_TAILLE").getField("NOM"));
|
- |
|
94 |
|
- |
|
95 |
List<SQLRow> l = SQLRowListRSH.execute(sel);
|
- |
|
96 |
|
- |
|
97 |
for (SQLRow sqlRow : l) {
|
- |
|
98 |
mapTaille.put(sqlRow.getString("NOM").trim(), sqlRow.getID());
|
- |
|
99 |
}
|
- |
|
100 |
}
|
55 |
}
|
101 |
}
|
56 |
|
102 |
|
57 |
public void importArticles(File file, DBRoot root) throws IOException, SQLException {
|
103 |
public void importArticles(File file, DBRoot root) throws IOException, SQLException {
|
58 |
|
104 |
|
59 |
final SQLTable table = root.findTable("ARTICLE");
|
105 |
final SQLTable table = root.findTable("ARTICLE");
|
60 |
final SQLTable tableArtElt = root.findTable("ARTICLE_ELEMENT");
|
106 |
final SQLTable tableArtElt = root.findTable("ARTICLE_ELEMENT");
|
61 |
|
107 |
|
- |
|
108 |
// Récupération des couples articles/stocks existant
|
- |
|
109 |
fillArticles();
|
- |
|
110 |
|
- |
|
111 |
// Matching des colonnes
|
62 |
Map<String, Tuple2<SQLRowValues, SQLRowValues>> articles = getArticles();
|
112 |
Map<String, Integer> columnMapping = new HashMap<String, Integer>();
|
- |
|
113 |
columnMapping.put(CODE, null);
|
- |
|
114 |
columnMapping.put(NOM, null);
|
- |
|
115 |
columnMapping.put(TAILLE, null);
|
- |
|
116 |
columnMapping.put(FAMILLE, null);
|
- |
|
117 |
columnMapping.put(COULEUR, null);
|
- |
|
118 |
columnMapping.put(QTE, null);
|
- |
|
119 |
columnMapping.put(QTE_OPENCONCERTO, null);
|
- |
|
120 |
{
|
- |
|
121 |
// Searching column index from column Header
|
- |
|
122 |
final DataImporter importer = new DataImporter(table);
|
- |
|
123 |
importer.setSkipFirstLine(false);
|
- |
|
124 |
ArrayTableModel m = importer.createModelFrom(file);
|
- |
|
125 |
List<Object> line = m.getLineValuesAt(0);
|
- |
|
126 |
for (int i = 0; i < line.size(); i++) {
|
- |
|
127 |
Object object = line.get(i);
|
- |
|
128 |
if (object != null) {
|
- |
|
129 |
for (String key : columnMapping.keySet()) {
|
- |
|
130 |
if (object.toString().equalsIgnoreCase(key)) {
|
- |
|
131 |
columnMapping.put(key, i);
|
- |
|
132 |
}
|
- |
|
133 |
}
|
- |
|
134 |
}
|
- |
|
135 |
}
|
- |
|
136 |
}
|
- |
|
137 |
|
- |
|
138 |
String msg = "Colonnes importées : \n";
|
- |
|
139 |
final SQLPreferences prefs = SQLPreferences.getMemCached(table.getDBRoot());
|
- |
|
140 |
final boolean hasDeclinaison = prefs.getBoolean(GestionArticleGlobalPreferencePanel.ACTIVER_DECLINAISON, false);
|
- |
|
141 |
List<String> required;
|
- |
|
142 |
if (hasDeclinaison) {
|
- |
|
143 |
required = Arrays.asList(CODE, QTE, QTE_OPENCONCERTO, TAILLE, COULEUR);
|
- |
|
144 |
} else {
|
- |
|
145 |
required = Arrays.asList(CODE, QTE, QTE_OPENCONCERTO);
|
- |
|
146 |
}
|
- |
|
147 |
|
- |
|
148 |
for (Entry<String, Integer> e : columnMapping.entrySet()) {
|
- |
|
149 |
if (e.getValue() != null) {
|
- |
|
150 |
msg += e.getKey() + " : " + getColumnName(e.getValue()) + "\n";
|
- |
|
151 |
} else {
|
- |
|
152 |
if (required.contains(e.getKey())) {
|
- |
|
153 |
JOptionPane.showMessageDialog(null, "Aucune colonne " + e.getKey() + " trouvée, import annulé!\nCette colonne est obligatoire.");
|
- |
|
154 |
return;
|
- |
|
155 |
}
|
- |
|
156 |
msg += e.getKey() + " : non importée\n";
|
- |
|
157 |
}
|
- |
|
158 |
}
|
- |
|
159 |
msg += "\nVoulez vous continuer ?";
|
- |
|
160 |
int a = JOptionPane.showConfirmDialog(null, msg);
|
- |
|
161 |
if (a == JOptionPane.YES_OPTION) {
|
63 |
|
162 |
|
64 |
final DataImporter importer = new DataImporter(table) {
|
163 |
final DataImporter importer = new DataImporter(table) {
|
65 |
@Override
|
164 |
@Override
|
66 |
protected void customizeRowValuesToFetch(SQLRowValues vals) {
|
165 |
protected void customizeRowValuesToFetch(SQLRowValues vals) {
|
67 |
|
166 |
|
Line 88... |
Line 187... |
88 |
|
187 |
|
89 |
for (int i = 1; i < m.getRowCount(); i++) {
|
188 |
for (int i = 1; i < m.getRowCount(); i++) {
|
90 |
List<Object> o = m.getLineValuesAt(i);
|
189 |
List<Object> o = m.getLineValuesAt(i);
|
91 |
if (o.size() >= 5) {
|
190 |
if (o.size() >= 5) {
|
92 |
System.err.println(o);
|
191 |
System.err.println(o);
|
93 |
String code = o.get(1).toString();
|
192 |
String code = o.get(columnMapping.get(CODE)).toString();
|
94 |
if (code.trim().length() > 0) {
|
193 |
if (code.trim().length() > 0) {
|
95 |
|
194 |
|
96 |
final String stringQty = o.get(4).toString();
|
195 |
final String stringQty = o.get(columnMapping.get(QTE)).toString();
|
97 |
Double qty = stringQty.trim().length() == 0 ? 0 : Double.valueOf(stringQty);
|
196 |
Double qty = stringQty.trim().length() == 0 ? 0 : Double.valueOf(stringQty);
|
98 |
final String stringQtyOld = o.get(3).toString();
|
197 |
final String stringQtyOld = o.get(columnMapping.get(QTE_OPENCONCERTO)).toString();
|
99 |
float qtyOld = stringQtyOld.trim().length() == 0 ? 0 : Float.valueOf(stringQtyOld);
|
198 |
float qtyOld = stringQtyOld.trim().length() == 0 ? 0 : Float.valueOf(stringQtyOld);
|
100 |
|
199 |
|
- |
|
200 |
String couleur = "";
|
- |
|
201 |
if (columnMapping.get(COULEUR) != null) {
|
- |
|
202 |
couleur = o.get(columnMapping.get(COULEUR)).toString();
|
- |
|
203 |
}
|
- |
|
204 |
|
- |
|
205 |
String taille = "";
|
- |
|
206 |
if (columnMapping.get(TAILLE) != null) {
|
- |
|
207 |
taille = o.get(columnMapping.get(TAILLE)).toString();
|
- |
|
208 |
}
|
- |
|
209 |
|
- |
|
210 |
// SQLRowAccessor match = findArticle(code, couleur, taille);
|
- |
|
211 |
|
101 |
Tuple2<SQLRowValues, SQLRowValues> match = articles.get(code);
|
212 |
Tuple2<SQLRowValues, SQLRowValues> match = findArticle(code, couleur, taille);
|
102 |
if (match != null) {
|
213 |
if (match != null) {
|
103 |
|
214 |
|
104 |
SQLRowAccessor stockValues = match.get1();
|
215 |
SQLRowAccessor stockValues = match.get1();
|
105 |
|
216 |
|
106 |
final SQLTable tableMvt = table.getTable("MOUVEMENT_STOCK");
|
217 |
final SQLTable tableMvt = table.getTable("MOUVEMENT_STOCK");
|
Line 172... |
Line 283... |
172 |
|
283 |
|
173 |
List<String> reqs = new ArrayList<String>();
|
284 |
List<String> reqs = new ArrayList<String>();
|
174 |
for (String code : codeKits) {
|
285 |
for (String code : codeKits) {
|
175 |
System.err.println(code);
|
286 |
System.err.println(code);
|
176 |
SQLRowValues rowValsKit = kits.get(code);
|
287 |
SQLRowValues rowValsKit = kits.get(code);
|
177 |
StockItem item = new StockItem(rowValsKit, rowValsKit.getForeign("ID_STOCK"));
|
288 |
StockItem item = new StockItem(rowValsKit, ProductComponent.findOrCreateStock(rowValsKit, depot));
|
178 |
Collection<SQLRowValues> elts = rowValsKit.getReferentRows(tableArtElt.getField("ID_ARTICLE_PARENT"));
|
289 |
Collection<SQLRowValues> elts = rowValsKit.getReferentRows(tableArtElt.getField("ID_ARTICLE_PARENT"));
|
179 |
for (SQLRowValues sqlRowValues : elts) {
|
290 |
for (SQLRowValues sqlRowValues : elts) {
|
180 |
if (sqlRowValues.getForeign("ID_ARTICLE") != null) {
|
291 |
if (sqlRowValues.getForeign("ID_ARTICLE") != null) {
|
- |
|
292 |
item.addItemComponent(
|
181 |
item.addItemComponent(new StockItemComponent(new StockItem(sqlRowValues.getForeign("ID_ARTICLE"), sqlRowValues.getForeign("ID_ARTICLE").getForeign("ID_STOCK")),
|
293 |
new StockItemComponent(new StockItem(sqlRowValues.getForeign("ID_ARTICLE"), ProductComponent.findOrCreateStock(sqlRowValues.getForeign("ID_ARTICLE"), depot)),
|
182 |
sqlRowValues.getBigDecimal("QTE_UNITAIRE"), sqlRowValues.getInt("QTE")));
|
294 |
sqlRowValues.getBigDecimal("QTE_UNITAIRE"), sqlRowValues.getInt("QTE")));
|
183 |
}
|
295 |
}
|
184 |
}
|
296 |
}
|
185 |
item.updateQtyFromChildren();
|
297 |
item.updateQtyFromChildren();
|
186 |
reqs.add(item.getUpdateRequest());
|
298 |
reqs.add(item.getUpdateRequest());
|
Line 229... |
Line 341... |
229 |
// for (Integer qte : mapLastValidAchatRows.keySet()) {
|
341 |
// for (Integer qte : mapLastValidAchatRows.keySet()) {
|
230 |
// SQLRow rowVals = mapLastValidAchatRows.get(qte);
|
342 |
// SQLRow rowVals = mapLastValidAchatRows.get(qte);
|
231 |
// checkMinPrice(rowVals, mapLastValidRows.get(qte));
|
343 |
// checkMinPrice(rowVals, mapLastValidRows.get(qte));
|
232 |
// }
|
344 |
// }
|
233 |
// }
|
345 |
// }
|
234 |
|
346 |
}
|
235 |
}
|
347 |
}
|
236 |
|
348 |
|
237 |
private void checkMinPrice(SQLRow rowValsSuplierLastValid, SQLRow lastValidRow) {
|
349 |
private void checkMinPrice(SQLRow rowValsSuplierLastValid, SQLRow lastValidRow) {
|
238 |
boolean update = false;
|
350 |
boolean update = false;
|
239 |
final ProductHelper helper = new ProductHelper(rowValsSuplierLastValid.getTable().getDBRoot());
|
351 |
final ProductHelper helper = new ProductHelper(rowValsSuplierLastValid.getTable().getDBRoot());
|
Line 307... |
Line 419... |
307 |
ProductComponent comp = new ProductComponent(rowVals, new BigDecimal(qty), null, null);
|
419 |
ProductComponent comp = new ProductComponent(rowVals, new BigDecimal(qty), null, null);
|
308 |
return comp.getPRC(d);
|
420 |
return comp.getPRC(d);
|
309 |
// return result;
|
421 |
// return result;
|
310 |
}
|
422 |
}
|
311 |
|
423 |
|
312 |
private Map<String, Tuple2<SQLRowValues, SQLRowValues>> getArticles() throws SQLException {
|
424 |
private final Map<String, Tuple2<SQLRowValues, SQLRowValues>> mapArticle = new HashMap<String, Tuple2<SQLRowValues, SQLRowValues>>();
|
- |
|
425 |
private final Map<String, Tuple2<SQLRowValues, SQLRowValues>> mapArticleVirtuel = new HashMap<String, Tuple2<SQLRowValues, SQLRowValues>>();
|
- |
|
426 |
private final Map<Tuple3<String, String, String>, Tuple2<SQLRowValues, SQLRowValues>> mapDeclArticle = new HashMap<Tuple3<String, String, String>, Tuple2<SQLRowValues, SQLRowValues>>();
|
- |
|
427 |
|
- |
|
428 |
private void fillArticles() throws SQLException {
|
313 |
final SQLTable table = Configuration.getInstance().getRoot().findTable("ARTICLE");
|
429 |
final SQLTable table = Configuration.getInstance().getRoot().findTable("ARTICLE");
|
314 |
SQLRowValues graph = new SQLRowValues(table);
|
430 |
SQLRowValues graph = new SQLRowValues(table);
|
315 |
graph.put("ID", null);
|
431 |
graph.put("ID", null);
|
316 |
graph.put("CODE", null);
|
432 |
graph.put("CODE", null);
|
317 |
graph.put("NOM", null);
|
433 |
graph.put("NOM", null);
|
318 |
graph.put("NOM", null);
|
434 |
graph.put("VIRTUEL", null);
|
- |
|
435 |
graph.putRowValues("ID_ARTICLE_DECLINAISON_COULEUR").putNulls("ID", "NOM");
|
- |
|
436 |
graph.putRowValues("ID_ARTICLE_DECLINAISON_TAILLE").putNulls("ID", "NOM");
|
- |
|
437 |
|
319 |
final SQLTable foreignTableStock = table.getForeignTable("ID_STOCK");
|
438 |
final SQLTable foreignTableStock = table.getForeignTable("ID_STOCK");
|
320 |
SQLRowValues graphStock = new SQLRowValues(foreignTableStock);
|
439 |
SQLRowValues graphStock = new SQLRowValues(foreignTableStock);
|
321 |
graphStock.putNulls("ID_DEPOT_STOCK", "ID", "QTE_REEL", "QTE_TH", "QTE_LIV_ATTENTE", "QTE_RECEPT_ATTENTE");
|
440 |
graphStock.putNulls("ID_DEPOT_STOCK", "ID", "QTE_REEL", "QTE_TH", "QTE_LIV_ATTENTE", "QTE_RECEPT_ATTENTE");
|
322 |
graphStock.put("ID_ARTICLE", graph);
|
441 |
graphStock.put("ID_ARTICLE", graph);
|
323 |
|
442 |
|
- |
|
443 |
SQLRowValues graphStockArt = new SQLRowValues(foreignTableStock);
|
- |
|
444 |
graphStockArt.putNulls("ID_DEPOT_STOCK", "ID", "QTE_REEL", "QTE_TH", "QTE_LIV_ATTENTE", "QTE_RECEPT_ATTENTE");
|
- |
|
445 |
graph.put("ID_STOCK", graphStockArt);
|
- |
|
446 |
|
324 |
final SQLTable tableArtElt = table.getTable("ARTICLE_ELEMENT");
|
447 |
final SQLTable tableArtElt = table.getTable("ARTICLE_ELEMENT");
|
325 |
SQLRowValues artElt = new SQLRowValues(tableArtElt);
|
448 |
SQLRowValues artElt = new SQLRowValues(tableArtElt);
|
326 |
artElt.put("ID", null);
|
449 |
artElt.put("ID", null);
|
327 |
artElt.put("QTE", null);
|
450 |
artElt.put("QTE", null);
|
328 |
artElt.put("QTE_UNITAIRE", null);
|
451 |
artElt.put("QTE_UNITAIRE", null);
|
329 |
artElt.put("ID_ARTICLE_PARENT", graph);
|
452 |
artElt.put("ID_ARTICLE_PARENT", graph);
|
330 |
final SQLRowValues articleParent = artElt.putRowValues("ID_ARTICLE");
|
453 |
final SQLRowValues articleParent = artElt.putRowValues("ID_ARTICLE");
|
331 |
articleParent.putNulls("ID", "CODE", "NOM");
|
454 |
articleParent.putNulls("ID", "CODE", "NOM", "VIRTUEL");
|
- |
|
455 |
articleParent.putRowValues("ID_ARTICLE_DECLINAISON_COULEUR").putNulls("ID", "NOM");
|
- |
|
456 |
articleParent.putRowValues("ID_ARTICLE_DECLINAISON_TAILLE").putNulls("ID", "NOM");
|
- |
|
457 |
|
332 |
SQLRowValues graphStockItem = new SQLRowValues(foreignTableStock);
|
458 |
SQLRowValues graphStockItem = new SQLRowValues(foreignTableStock);
|
333 |
graphStockItem.putNulls("ID_DEPOT_STOCK", "ID", "QTE_REEL", "QTE_TH", "QTE_LIV_ATTENTE", "QTE_RECEPT_ATTENTE");
|
- |
|
334 |
graphStockItem.put("ID_ARTICLE", articleParent);
|
459 |
graphStockItem.put("ID_ARTICLE", articleParent);
|
335 |
|
460 |
|
- |
|
461 |
SQLRowValues graphStockArtItem = new SQLRowValues(foreignTableStock);
|
- |
|
462 |
graphStockArtItem.putNulls("ID_DEPOT_STOCK", "ID", "QTE_REEL", "QTE_TH", "QTE_LIV_ATTENTE", "QTE_RECEPT_ATTENTE");
|
- |
|
463 |
articleParent.put("ID_STOCK", graphStockArtItem);
|
- |
|
464 |
|
336 |
SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(graph);
|
465 |
SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(graph);
|
337 |
List<SQLRowValues> results = fetcher.fetch();
|
466 |
List<SQLRowValues> results = fetcher.fetch();
|
338 |
|
467 |
|
339 |
Calendar c = Calendar.getInstance();
|
468 |
Calendar c = Calendar.getInstance();
|
340 |
// c.set(Calendar.DAY_OF_MONTH, 1);
|
469 |
// c.set(Calendar.DAY_OF_MONTH, 1);
|
341 |
c.add(Calendar.MONTH, -2);
|
470 |
c.add(Calendar.MONTH, -2);
|
342 |
c.set(Calendar.DAY_OF_MONTH, 31);
|
471 |
c.set(Calendar.DAY_OF_MONTH, 31);
|
343 |
Date dEndYear = c.getTime();
|
472 |
Date dEndYear = c.getTime();
|
344 |
|
473 |
|
345 |
Map<String, Tuple2<SQLRowValues, SQLRowValues>> vals = new HashMap<String, Tuple2<SQLRowValues, SQLRowValues>>();
|
- |
|
346 |
for (SQLRowValues sqlRowValues : results) {
|
474 |
for (SQLRowValues sqlRowValues : results) {
|
347 |
final String code = sqlRowValues.getString("CODE");
|
475 |
final String code = sqlRowValues.getString("CODE");
|
348 |
|
476 |
|
349 |
Collection<SQLRowValues> stocks = sqlRowValues.getReferentRows(foreignTableStock);
|
477 |
Collection<SQLRowValues> stocks = sqlRowValues.getReferentRows(foreignTableStock);
|
350 |
|
478 |
|
Line 352... |
Line 480... |
352 |
for (SQLRowValues sqlRowValues2 : stocks) {
|
480 |
for (SQLRowValues sqlRowValues2 : stocks) {
|
353 |
if (sqlRowValues2.getForeignID("ID_DEPOT_STOCK") == depot.getID()) {
|
481 |
if (sqlRowValues2.getForeignID("ID_DEPOT_STOCK") == depot.getID()) {
|
354 |
rowValsStock = sqlRowValues2;
|
482 |
rowValsStock = sqlRowValues2;
|
355 |
}
|
483 |
}
|
356 |
}
|
484 |
}
|
357 |
if (rowValsStock == null) {
|
485 |
// if (rowValsStock == null) {
|
358 |
rowValsStock = ProductComponent.findOrCreateStock(sqlRowValues, depot).asRowValues();
|
486 |
// rowValsStock = ProductComponent.findOrCreateStock(sqlRowValues, depot).asRowValues();
|
- |
|
487 |
// }
|
- |
|
488 |
|
- |
|
489 |
if (sqlRowValues.getBoolean("VIRTUEL")) {
|
- |
|
490 |
mapArticleVirtuel.put(sqlRowValues.getString("CODE"), Tuple2.create(sqlRowValues, rowValsStock));
|
359 |
}
|
491 |
}
|
360 |
|
492 |
|
- |
|
493 |
final SQLRowAccessor couleur = sqlRowValues.getObject("ID_ARTICLE_DECLINAISON_COULEUR") == null ? null : sqlRowValues.getNonEmptyForeign("ID_ARTICLE_DECLINAISON_COULEUR");
|
- |
|
494 |
final SQLRowAccessor taille = sqlRowValues.getObject("ID_ARTICLE_DECLINAISON_TAILLE") == null ? null : sqlRowValues.getNonEmptyForeign("ID_ARTICLE_DECLINAISON_TAILLE");
|
- |
|
495 |
if (couleur == null && taille == null) {
|
361 |
vals.put(code, Tuple2.create(sqlRowValues, rowValsStock));
|
496 |
mapArticle.put(sqlRowValues.getString("CODE"), Tuple2.create(sqlRowValues, rowValsStock));
|
- |
|
497 |
} else if (couleur == null) {
|
- |
|
498 |
mapDeclArticle.put(Tuple3.create(sqlRowValues.getString("CODE"), null, taille.getString("NOM")), Tuple2.create(sqlRowValues, rowValsStock));
|
- |
|
499 |
} else if (taille == null) {
|
- |
|
500 |
mapDeclArticle.put(Tuple3.create(sqlRowValues.getString("CODE"), couleur.getString("NOM"), null), Tuple2.create(sqlRowValues, rowValsStock));
|
- |
|
501 |
} else {
|
- |
|
502 |
mapDeclArticle.put(Tuple3.create(sqlRowValues.getString("CODE"), couleur.getString("NOM"), taille.getString("NOM")), Tuple2.create(sqlRowValues, rowValsStock));
|
- |
|
503 |
}
|
362 |
|
504 |
|
363 |
final Set<SQLRowValues> referentRows = sqlRowValues.getReferentRows(tableArtElt.getField("ID_ARTICLE_PARENT"));
|
505 |
final Set<SQLRowValues> referentRows = sqlRowValues.getReferentRows(tableArtElt.getField("ID_ARTICLE_PARENT"));
|
364 |
if (referentRows.size() == 0) {
|
506 |
if (referentRows.size() == 0) {
|
365 |
// if (!sqlRowValues.isForeignEmpty("ID_STOCK")) {
|
507 |
// if (!sqlRowValues.isForeignEmpty("ID_STOCK")) {
|
366 |
// SQLRowAccessor rowValsStock = sqlRowValues.getForeign("ID_STOCK");
|
508 |
// SQLRowAccessor rowValsStock = sqlRowValues.getForeign("ID_STOCK");
|
Line 401... |
Line 543... |
401 |
// if (sqlRowValues.isForeignEmpty("ID_STOCK")) {
|
543 |
// if (sqlRowValues.isForeignEmpty("ID_STOCK")) {
|
402 |
// sqlRowValues.putRowValues("ID_STOCK").commit();
|
544 |
// sqlRowValues.putRowValues("ID_STOCK").commit();
|
403 |
// }
|
545 |
// }
|
404 |
}
|
546 |
}
|
405 |
}
|
547 |
}
|
- |
|
548 |
}
|
- |
|
549 |
|
- |
|
550 |
private Tuple2<SQLRowValues, SQLRowValues> findArticle(String code, String couleur, String taille) throws SQLException {
|
- |
|
551 |
if (!mapCouleur.containsKey(couleur)) {
|
- |
|
552 |
SQLRowValues rowVals = new SQLRowValues(root.getTable("ARTICLE_DECLINAISON_COULEUR"));
|
- |
|
553 |
rowVals.put("NOM", couleur);
|
- |
|
554 |
mapCouleur.put(couleur, rowVals.commit().getID());
|
- |
|
555 |
}
|
- |
|
556 |
if (!mapTaille.containsKey(taille)) {
|
- |
|
557 |
SQLRowValues rowVals = new SQLRowValues(root.getTable("ARTICLE_DECLINAISON_TAILLE"));
|
- |
|
558 |
rowVals.put("NOM", taille);
|
- |
|
559 |
mapTaille.put(taille, rowVals.commit().getID());
|
- |
|
560 |
}
|
- |
|
561 |
|
- |
|
562 |
Tuple2<SQLRowValues, SQLRowValues> t;
|
- |
|
563 |
if ((couleur == null || couleur.trim().length() == 0) && (taille == null || taille.trim().length() == 0)) {
|
- |
|
564 |
|
- |
|
565 |
t = mapArticle.get(code);
|
- |
|
566 |
if (t.get1() == null) {
|
- |
|
567 |
t = Tuple2.create(t.get0(), ProductComponent.findOrCreateStock(t.get0(), depot).asRowValues());
|
- |
|
568 |
mapArticle.put(code, t);
|
- |
|
569 |
}
|
- |
|
570 |
} else if (couleur == null || couleur.trim().length() == 0) {
|
- |
|
571 |
t = mapDeclArticle.get(Tuple3.create(code, null, taille.trim()));
|
- |
|
572 |
if (t == null) {
|
- |
|
573 |
SQLRowValues artRow = cloneFromArticle(mapArticleVirtuel.get(code).get0(), null, mapTaille.get(taille.trim())).asRowValues();
|
- |
|
574 |
final SQLRowValues stockRow = ProductComponent.findOrCreateStock(artRow, depot).asRowValues();
|
- |
|
575 |
t = Tuple2.create(artRow, stockRow);
|
- |
|
576 |
mapDeclArticle.put(Tuple3.create(code, null, taille.trim()), t);
|
- |
|
577 |
} else if (t.get1() == null) {
|
- |
|
578 |
t = Tuple2.create(t.get0(), ProductComponent.findOrCreateStock(t.get0(), depot).asRowValues());
|
- |
|
579 |
mapDeclArticle.put(Tuple3.create(code, null, taille.trim()), t);
|
- |
|
580 |
}
|
- |
|
581 |
} else if (taille == null || taille.trim().length() == 0) {
|
- |
|
582 |
t = mapDeclArticle.get(Tuple3.create(code, couleur.trim(), null));
|
- |
|
583 |
if (t == null) {
|
- |
|
584 |
SQLRowValues artRow = cloneFromArticle(mapArticleVirtuel.get(code).get0(), mapCouleur.get(couleur.trim()), null).asRowValues();
|
- |
|
585 |
final SQLRowValues stockRow = ProductComponent.findOrCreateStock(artRow, depot).asRowValues();
|
- |
|
586 |
t = Tuple2.create(artRow, stockRow);
|
- |
|
587 |
mapDeclArticle.put(Tuple3.create(code, couleur.trim(), null), t);
|
- |
|
588 |
} else if (t.get1() == null) {
|
- |
|
589 |
t = Tuple2.create(t.get0(), ProductComponent.findOrCreateStock(t.get0(), depot).asRowValues());
|
- |
|
590 |
mapDeclArticle.put(Tuple3.create(code, couleur.trim(), null), t);
|
- |
|
591 |
}
|
- |
|
592 |
} else {
|
- |
|
593 |
t = mapDeclArticle.get(Tuple3.create(code, couleur.trim(), taille.trim()));
|
- |
|
594 |
if (t == null) {
|
- |
|
595 |
if (mapArticle.get(code) != null) {
|
- |
|
596 |
SQLRowValues artRow = cloneFromArticle(mapArticleVirtuel.get(code).get0(), mapCouleur.get(couleur.trim()), mapTaille.get(taille.trim())).asRowValues();
|
- |
|
597 |
final SQLRowValues stockRow = ProductComponent.findOrCreateStock(artRow, depot).asRowValues();
|
- |
|
598 |
t = Tuple2.create(artRow, stockRow);
|
- |
|
599 |
mapDeclArticle.put(Tuple3.create(code, couleur.trim(), taille.trim()), t);
|
- |
|
600 |
}
|
- |
|
601 |
} else if (t.get1() == null) {
|
- |
|
602 |
t = Tuple2.create(t.get0(), ProductComponent.findOrCreateStock(t.get0(), depot).asRowValues());
|
- |
|
603 |
mapDeclArticle.put(Tuple3.create(code, couleur.trim(), taille.trim()), t);
|
- |
|
604 |
}
|
- |
|
605 |
}
|
406 |
return vals;
|
606 |
return t;
|
- |
|
607 |
}
|
- |
|
608 |
|
- |
|
609 |
public SQLRow cloneFromArticle(SQLRowAccessor rArt, Integer idCouleur, Integer idTaille) throws SQLException {
|
- |
|
610 |
if (rArt == null) {
|
- |
|
611 |
return null;
|
- |
|
612 |
}
|
- |
|
613 |
SQLRowValues copy = artElt.createCopy(rArt.getID());
|
- |
|
614 |
copy.put("VIRTUEL", Boolean.FALSE);
|
- |
|
615 |
copy.put("ID_ARTICLE_VIRTUEL_PERE", rArt.getID());
|
- |
|
616 |
if (idCouleur != null) {
|
- |
|
617 |
copy.put("ID_ARTICLE_DECLINAISON_COULEUR", idCouleur);
|
- |
|
618 |
}
|
- |
|
619 |
if (idTaille != null) {
|
- |
|
620 |
copy.put("ID_ARTICLE_DECLINAISON_TAILLE", idTaille);
|
- |
|
621 |
}
|
- |
|
622 |
return copy.commit();
|
- |
|
623 |
}
|
- |
|
624 |
|
- |
|
625 |
private String getColumnName(int columnNumber) {
|
- |
|
626 |
int dividend = columnNumber;
|
- |
|
627 |
String columnName = "";
|
- |
|
628 |
int modulo;
|
- |
|
629 |
|
- |
|
630 |
while (dividend >= 0) {
|
- |
|
631 |
modulo = dividend % 26;
|
- |
|
632 |
columnName = String.valueOf((char) (65 + modulo)) + columnName;
|
- |
|
633 |
dividend = (int) ((dividend - modulo) / 26);
|
- |
|
634 |
if (dividend <= 0) {
|
- |
|
635 |
break;
|
- |
|
636 |
} else {
|
- |
|
637 |
dividend--;
|
- |
|
638 |
}
|
- |
|
639 |
}
|
- |
|
640 |
|
- |
|
641 |
return columnName;
|
407 |
}
|
642 |
}
|
408 |
}
|
643 |
}
|