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.
|
10 |
*
|
10 |
*
|
11 |
* When distributing the software, include this License Header Notice in each file.
|
11 |
* When distributing the software, include this License Header Notice in each file.
|
12 |
*/
|
12 |
*/
|
13 |
|
13 |
|
14 |
package org.openconcerto.erp.core.supplychain.stock.element;
|
14 |
package org.openconcerto.erp.core.supplychain.stock.element;
|
15 |
|
15 |
|
16 |
import org.openconcerto.erp.core.sales.product.model.PriceByQty;
|
16 |
import org.openconcerto.erp.core.sales.product.model.PriceByQty;
|
17 |
import org.openconcerto.erp.importer.ArrayTableModel;
|
17 |
import org.openconcerto.erp.importer.ArrayTableModel;
|
18 |
import org.openconcerto.erp.importer.DataImporter;
|
18 |
import org.openconcerto.erp.importer.DataImporter;
|
- |
|
19 |
import org.openconcerto.erp.preferences.GestionArticleGlobalPreferencePanel;
|
19 |
import org.openconcerto.sql.Configuration;
|
20 |
import org.openconcerto.sql.Configuration;
|
- |
|
21 |
import org.openconcerto.sql.element.SQLElement;
|
- |
|
22 |
import org.openconcerto.sql.model.DBRoot;
|
20 |
import org.openconcerto.sql.model.SQLRow;
|
23 |
import org.openconcerto.sql.model.SQLRow;
|
- |
|
24 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
- |
|
25 |
import org.openconcerto.sql.model.SQLRowListRSH;
|
21 |
import org.openconcerto.sql.model.SQLRowValues;
|
26 |
import org.openconcerto.sql.model.SQLRowValues;
|
22 |
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
|
27 |
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
|
- |
|
28 |
import org.openconcerto.sql.model.SQLSelect;
|
23 |
import org.openconcerto.sql.model.SQLTable;
|
29 |
import org.openconcerto.sql.model.SQLTable;
|
- |
|
30 |
import org.openconcerto.sql.preferences.SQLPreferences;
|
- |
|
31 |
import org.openconcerto.utils.Tuple3;
|
24 |
|
32 |
|
25 |
import java.io.File;
|
33 |
import java.io.File;
|
26 |
import java.io.IOException;
|
34 |
import java.io.IOException;
|
27 |
import java.math.BigDecimal;
|
35 |
import java.math.BigDecimal;
|
28 |
import java.sql.SQLException;
|
36 |
import java.sql.SQLException;
|
29 |
import java.util.ArrayList;
|
37 |
import java.util.ArrayList;
|
- |
|
38 |
import java.util.Arrays;
|
30 |
import java.util.Calendar;
|
39 |
import java.util.Calendar;
|
31 |
import java.util.Collection;
|
40 |
import java.util.Collection;
|
32 |
import java.util.Date;
|
41 |
import java.util.Date;
|
33 |
import java.util.HashMap;
|
42 |
import java.util.HashMap;
|
34 |
import java.util.List;
|
43 |
import java.util.List;
|
35 |
import java.util.Map;
|
44 |
import java.util.Map;
|
- |
|
45 |
import java.util.Map.Entry;
|
36 |
import java.util.Set;
|
46 |
import java.util.Set;
|
37 |
|
47 |
|
- |
|
48 |
import javax.swing.JOptionPane;
|
- |
|
49 |
|
38 |
public class EtatStockFromInventoryFileCreator {
|
50 |
public class EtatStockFromInventoryFileCreator {
|
39 |
|
51 |
|
40 |
// Map<String, SQLRowValues> kits = new HashMap<String, SQLRowValues>();
|
52 |
// Map<String, SQLRowValues> kits = new HashMap<String, SQLRowValues>();
|
41 |
// List<String> codeKits = new ArrayList<String>();
|
53 |
// List<String> codeKits = new ArrayList<String>();
|
42 |
// List<SQLRowValues> rowValsArtNonSync = new ArrayList<SQLRowValues>();
|
54 |
// List<SQLRowValues> rowValsArtNonSync = new ArrayList<SQLRowValues>();
|
43 |
|
55 |
|
- |
|
56 |
private static String FAMILLE = "Famille";
|
- |
|
57 |
private static String CODE = "Code";
|
- |
|
58 |
private static String NOM = "Nom";
|
- |
|
59 |
private static String TAILLE = "Taille";
|
- |
|
60 |
private static String COULEUR = "Couleur";
|
- |
|
61 |
private static String QTE = "Qté réelle relevée";
|
- |
|
62 |
private final Map<String, Integer> mapCouleur = new HashMap<String, Integer>();
|
- |
|
63 |
private final Map<String, Integer> mapTaille = new HashMap<String, Integer>();
|
- |
|
64 |
private final DBRoot root;
|
- |
|
65 |
private final SQLElement artElt;
|
- |
|
66 |
|
- |
|
67 |
public EtatStockFromInventoryFileCreator(SQLElement artElt) {
|
- |
|
68 |
this.artElt = artElt;
|
- |
|
69 |
this.root = artElt.getTable().getDBRoot();
|
- |
|
70 |
}
|
- |
|
71 |
|
44 |
public void importArticles(File file, Date d) throws IOException, SQLException {
|
72 |
public void importArticles(File file, Date d) throws IOException, SQLException {
|
45 |
|
73 |
|
46 |
final SQLTable table = Configuration.getInstance().getRoot().findTable("ARTICLE");
|
74 |
final SQLTable table = this.root.findTable("ARTICLE");
|
- |
|
75 |
|
- |
|
76 |
{
|
- |
|
77 |
SQLSelect sel = new SQLSelect();
|
- |
|
78 |
sel.addSelect(table.getDBRoot().getTable("ARTICLE_DECLINAISON_COULEUR").getKey());
|
- |
|
79 |
sel.addSelect(table.getDBRoot().getTable("ARTICLE_DECLINAISON_COULEUR").getField("NOM"));
|
- |
|
80 |
|
- |
|
81 |
List<SQLRow> l = SQLRowListRSH.execute(sel);
|
- |
|
82 |
|
- |
|
83 |
for (SQLRow sqlRow : l) {
|
- |
|
84 |
mapCouleur.put(sqlRow.getString("NOM").trim(), sqlRow.getID());
|
- |
|
85 |
}
|
- |
|
86 |
}
|
- |
|
87 |
|
- |
|
88 |
{
|
- |
|
89 |
SQLSelect sel = new SQLSelect();
|
- |
|
90 |
sel.addSelect(table.getDBRoot().getTable("ARTICLE_DECLINAISON_TAILLE").getKey());
|
- |
|
91 |
sel.addSelect(table.getDBRoot().getTable("ARTICLE_DECLINAISON_TAILLE").getField("NOM"));
|
- |
|
92 |
|
- |
|
93 |
List<SQLRow> l = SQLRowListRSH.execute(sel);
|
- |
|
94 |
|
- |
|
95 |
for (SQLRow sqlRow : l) {
|
- |
|
96 |
mapTaille.put(sqlRow.getString("NOM").trim(), sqlRow.getID());
|
- |
|
97 |
}
|
- |
|
98 |
}
|
- |
|
99 |
|
- |
|
100 |
fillArticles();
|
- |
|
101 |
|
47 |
Map<String, SQLRowValues> articles = getArticles();
|
102 |
Map<String, Integer> columnMapping = new HashMap<String, Integer>();
|
- |
|
103 |
columnMapping.put(CODE, null);
|
- |
|
104 |
columnMapping.put(NOM, null);
|
- |
|
105 |
columnMapping.put(TAILLE, null);
|
- |
|
106 |
columnMapping.put(FAMILLE, null);
|
- |
|
107 |
columnMapping.put(COULEUR, null);
|
- |
|
108 |
columnMapping.put(QTE, null);
|
- |
|
109 |
{
|
- |
|
110 |
// Searching column index from column Header
|
- |
|
111 |
final DataImporter importer = new DataImporter(table);
|
- |
|
112 |
importer.setSkipFirstLine(false);
|
- |
|
113 |
ArrayTableModel m = importer.createModelFrom(file);
|
- |
|
114 |
List<Object> line = m.getLineValuesAt(0);
|
- |
|
115 |
for (int i = 0; i < line.size(); i++) {
|
- |
|
116 |
Object object = line.get(i);
|
- |
|
117 |
if (object != null) {
|
- |
|
118 |
for (String key : columnMapping.keySet()) {
|
- |
|
119 |
if (object.toString().equalsIgnoreCase(key)) {
|
- |
|
120 |
columnMapping.put(key, i);
|
- |
|
121 |
}
|
- |
|
122 |
}
|
- |
|
123 |
}
|
- |
|
124 |
}
|
- |
|
125 |
}
|
- |
|
126 |
|
- |
|
127 |
String msg = "Colonnes importées : \n";
|
- |
|
128 |
final SQLPreferences prefs = SQLPreferences.getMemCached(table.getDBRoot());
|
- |
|
129 |
final boolean hasDeclinaison = prefs.getBoolean(GestionArticleGlobalPreferencePanel.ACTIVER_DECLINAISON, false);
|
- |
|
130 |
List<String> required;
|
- |
|
131 |
if (hasDeclinaison) {
|
- |
|
132 |
required = Arrays.asList(CODE, QTE, TAILLE, COULEUR);
|
- |
|
133 |
} else {
|
- |
|
134 |
required = Arrays.asList(CODE, QTE);
|
- |
|
135 |
}
|
- |
|
136 |
|
- |
|
137 |
for (Entry<String, Integer> e : columnMapping.entrySet()) {
|
- |
|
138 |
if (e.getValue() != null) {
|
- |
|
139 |
msg += e.getKey() + " : " + getColumnName(e.getValue()) + "\n";
|
- |
|
140 |
} else {
|
- |
|
141 |
if (required.contains(e.getKey())) {
|
- |
|
142 |
JOptionPane.showMessageDialog(null, "Aucune colonne " + e.getKey() + " trouvée, import annulé!\nCette colonne est obligatoire.");
|
- |
|
143 |
return;
|
- |
|
144 |
}
|
- |
|
145 |
msg += e.getKey() + " : non importée\n";
|
- |
|
146 |
}
|
- |
|
147 |
}
|
- |
|
148 |
msg += "\nVoulez vous continuer ?";
|
- |
|
149 |
int a = JOptionPane.showConfirmDialog(null, msg);
|
- |
|
150 |
if (a == JOptionPane.YES_OPTION) {
|
48 |
|
151 |
|
49 |
final DataImporter importer = new DataImporter(table) {
|
152 |
final DataImporter importer = new DataImporter(table) {
|
50 |
@Override
|
153 |
@Override
|
51 |
protected void customizeRowValuesToFetch(SQLRowValues vals) {
|
154 |
protected void customizeRowValuesToFetch(SQLRowValues vals) {
|
52 |
|
155 |
|
53 |
vals.putRowValues("ID_STOCK").putNulls("ID", "QTE_REEL", "QTE_TH");
|
156 |
vals.putRowValues("ID_STOCK").putNulls("ID", "QTE_REEL", "QTE_TH");
|
54 |
}
|
157 |
}
|
55 |
};
|
158 |
};
|
56 |
importer.setSkipFirstLine(true);
|
159 |
importer.setSkipFirstLine(true);
|
57 |
|
160 |
|
58 |
ArrayTableModel m = importer.createModelFrom(file);
|
161 |
ArrayTableModel m = importer.createModelFrom(file);
|
59 |
|
162 |
|
60 |
SQLRowValues rowValsEtatStock = new SQLRowValues(table.getTable("ETAT_STOCK"));
|
163 |
SQLRowValues rowValsEtatStock = new SQLRowValues(table.getTable("ETAT_STOCK"));
|
61 |
rowValsEtatStock.put("DATE", d);
|
164 |
rowValsEtatStock.put("DATE", d);
|
62 |
SQLRow etatStock = rowValsEtatStock.commit();
|
165 |
SQLRow etatStock = rowValsEtatStock.commit();
|
63 |
BigDecimal total = BigDecimal.ZERO;
|
166 |
BigDecimal total = BigDecimal.ZERO;
|
64 |
for (int i = 0; i < m.getRowCount(); i++) {
|
167 |
for (int i = 0; i < m.getRowCount(); i++) {
|
65 |
List<Object> o = m.getLineValuesAt(i);
|
168 |
List<Object> o = m.getLineValuesAt(i);
|
66 |
String code = o.get(0).toString();
|
169 |
String code = o.get(columnMapping.get(CODE)).toString();
|
67 |
if (code.trim().length() == 0) {
|
170 |
if (code.trim().length() == 0) {
|
68 |
break;
|
171 |
break;
|
69 |
}
|
172 |
}
|
- |
|
173 |
|
70 |
final String stringQty = o.get(3).toString();
|
174 |
final String stringQty = o.get(columnMapping.get(QTE)).toString();
|
71 |
Integer qty = stringQty.trim().length() == 0 ? 0 : Integer.valueOf(stringQty);
|
175 |
Integer qty = stringQty.trim().length() == 0 ? 0 : Integer.valueOf(stringQty);
|
72 |
|
176 |
|
- |
|
177 |
String couleur = "";
|
- |
|
178 |
if (columnMapping.get(COULEUR) != null) {
|
- |
|
179 |
couleur = o.get(columnMapping.get(COULEUR)).toString();
|
- |
|
180 |
}
|
- |
|
181 |
|
- |
|
182 |
String taille = "";
|
- |
|
183 |
if (columnMapping.get(TAILLE) != null) {
|
- |
|
184 |
taille = o.get(columnMapping.get(TAILLE)).toString();
|
- |
|
185 |
}
|
- |
|
186 |
|
73 |
SQLRowValues match = articles.get(code);
|
187 |
SQLRowAccessor match = findArticle(code, couleur, taille);
|
74 |
if (match != null) {
|
188 |
if (match != null) {
|
75 |
|
189 |
|
76 |
SQLRowValues stockValues = new SQLRowValues(table.getTable("ETAT_STOCK_ELEMENT"));
|
190 |
SQLRowValues stockValues = new SQLRowValues(table.getTable("ETAT_STOCK_ELEMENT"));
|
77 |
|
191 |
|
78 |
final BigDecimal qtyB = new BigDecimal(qty);
|
192 |
final BigDecimal qtyB = new BigDecimal(qty);
|
79 |
stockValues.put("QTE", qtyB);
|
193 |
stockValues.put("QTE", qtyB);
|
80 |
stockValues.put("NOM", match.getString("NOM"));
|
194 |
stockValues.put("NOM", match.getString("NOM"));
|
81 |
stockValues.put("CODE", match.getString("CODE"));
|
195 |
stockValues.put("CODE", match.getString("CODE"));
|
82 |
stockValues.put("ID_ARTICLE", match.getID());
|
196 |
stockValues.put("ID_ARTICLE", match.getID());
|
83 |
final BigDecimal prc = getPRC(match, qty, d);
|
197 |
final BigDecimal prc = getPRC(match, qty, d);
|
84 |
stockValues.put("PA", prc);
|
198 |
stockValues.put("PA", prc);
|
85 |
final BigDecimal totalElt = prc.multiply(qtyB);
|
199 |
final BigDecimal totalElt = prc.multiply(qtyB);
|
86 |
stockValues.put("T_PA", totalElt);
|
200 |
stockValues.put("T_PA", totalElt);
|
87 |
stockValues.put("ID_ETAT_STOCK", etatStock.getID());
|
201 |
stockValues.put("ID_ETAT_STOCK", etatStock.getID());
|
88 |
stockValues.commit();
|
202 |
stockValues.commit();
|
89 |
|
203 |
|
90 |
total = total.add(totalElt);
|
204 |
total = total.add(totalElt);
|
91 |
|
205 |
|
92 |
} else {
|
206 |
} else {
|
93 |
System.err.println("Aucun article correspondant au code " + code);
|
207 |
System.err.println("Aucun article correspondant au code " + code);
|
94 |
}
|
208 |
}
|
95 |
}
|
209 |
}
|
96 |
etatStock.createEmptyUpdateRow().put("MONTANT_HA", total).commit();
|
210 |
etatStock.createEmptyUpdateRow().put("MONTANT_HA", total).commit();
|
97 |
}
|
211 |
}
|
- |
|
212 |
}
|
98 |
|
213 |
|
99 |
public BigDecimal getPRC(SQLRowValues rowVals, int qty, Date d) {
|
214 |
public BigDecimal getPRC(SQLRowAccessor rowVals, int qty, Date d) {
|
100 |
if (rowVals.getTable().getDBRoot().contains("ARTICLE_PRIX_REVIENT")) {
|
215 |
if (rowVals.getTable().getDBRoot().contains("ARTICLE_PRIX_REVIENT")) {
|
101 |
SQLTable table = rowVals.getTable().getDBRoot().getTable("ARTICLE_PRIX_REVIENT");
|
216 |
SQLTable table = rowVals.getTable().getDBRoot().getTable("ARTICLE_PRIX_REVIENT");
|
102 |
Collection<SQLRow> prcs = rowVals.asRow().getReferentRows(table);
|
217 |
Collection<SQLRow> prcs = rowVals.asRow().getReferentRows(table);
|
103 |
|
218 |
|
104 |
BigDecimal result = null;
|
219 |
BigDecimal result = null;
|
105 |
final List<PriceByQty> prices = new ArrayList<PriceByQty>();
|
220 |
final List<PriceByQty> prices = new ArrayList<PriceByQty>();
|
106 |
|
221 |
|
107 |
for (SQLRow row : prcs) {
|
222 |
for (SQLRow row : prcs) {
|
108 |
Calendar date = Calendar.getInstance();
|
223 |
Calendar date = Calendar.getInstance();
|
109 |
date.set(Calendar.DAY_OF_MONTH, 1);
|
224 |
date.set(Calendar.DAY_OF_MONTH, 1);
|
110 |
date.set(Calendar.MONTH, 1);
|
225 |
date.set(Calendar.MONTH, 1);
|
111 |
date.set(Calendar.YEAR, 2001);
|
226 |
date.set(Calendar.YEAR, 2001);
|
112 |
if (row.getObject("DATE") != null) {
|
227 |
if (row.getObject("DATE") != null) {
|
113 |
date = row.getDate("DATE");
|
228 |
date = row.getDate("DATE");
|
114 |
}
|
229 |
}
|
115 |
prices.add(new PriceByQty(row.getLong("QTE"), row.getBigDecimal("PRIX"), date.getTime()));
|
230 |
prices.add(new PriceByQty(row.getLong("QTE"), row.getBigDecimal("PRIX"), date.getTime()));
|
116 |
}
|
231 |
}
|
117 |
|
232 |
|
118 |
result = PriceByQty.getPriceForQty(qty, prices, d);
|
233 |
result = PriceByQty.getPriceForQty(qty, prices, d);
|
119 |
if (result == null) {
|
234 |
if (result == null) {
|
120 |
// Can occur during editing
|
235 |
// Can occur during editing
|
121 |
result = BigDecimal.ZERO;
|
236 |
result = BigDecimal.ZERO;
|
122 |
}
|
237 |
}
|
123 |
return result;
|
238 |
return result;
|
124 |
} else {
|
239 |
} else {
|
125 |
return rowVals.getBigDecimal("PA_HT");
|
240 |
return rowVals.getBigDecimal("PA_HT");
|
126 |
}
|
241 |
}
|
127 |
}
|
242 |
}
|
128 |
|
243 |
|
- |
|
244 |
private final Map<String, SQLRowAccessor> mapArticle = new HashMap<String, SQLRowAccessor>();
|
- |
|
245 |
private final Map<Tuple3<String, String, String>, SQLRowAccessor> mapDeclArticle = new HashMap<Tuple3<String, String, String>, SQLRowAccessor>();
|
- |
|
246 |
|
129 |
private Map<String, SQLRowValues> getArticles() throws SQLException {
|
247 |
private void fillArticles() throws SQLException {
|
130 |
final SQLTable table = Configuration.getInstance().getRoot().findTable("ARTICLE");
|
248 |
final SQLTable table = Configuration.getInstance().getRoot().findTable("ARTICLE");
|
131 |
SQLRowValues graph = new SQLRowValues(table);
|
249 |
SQLRowValues graph = new SQLRowValues(table);
|
132 |
graph.put("ID", null);
|
250 |
graph.put("ID", null);
|
133 |
graph.put("CODE", null);
|
251 |
graph.put("CODE", null);
|
134 |
graph.put("SYNC_ID", null);
|
252 |
graph.put("SYNC_ID", null);
|
135 |
graph.put("NOM", null);
|
253 |
graph.put("NOM", null);
|
136 |
graph.put("PA_HT", null);
|
254 |
graph.put("PA_HT", null);
|
137 |
graph.putRowValues("ID_STOCK").putNulls("ID", "QTE_REEL", "QTE_TH", "QTE_LIV_ATTENTE", "QTE_RECEPT_ATTENTE");
|
255 |
graph.putRowValues("ID_STOCK").putNulls("ID", "QTE_REEL", "QTE_TH", "QTE_LIV_ATTENTE", "QTE_RECEPT_ATTENTE");
|
- |
|
256 |
graph.putRowValues("ID_ARTICLE_DECLINAISON_COULEUR").putNulls("ID", "NOM");
|
- |
|
257 |
graph.putRowValues("ID_ARTICLE_DECLINAISON_TAILLE").putNulls("ID", "NOM");
|
138 |
|
258 |
|
139 |
final SQLTable tableArtElt = table.getTable("ARTICLE_ELEMENT");
|
259 |
final SQLTable tableArtElt = table.getTable("ARTICLE_ELEMENT");
|
140 |
SQLRowValues artElt = new SQLRowValues(tableArtElt);
|
260 |
SQLRowValues artElt = new SQLRowValues(tableArtElt);
|
141 |
artElt.put("ID", null);
|
261 |
artElt.put("ID", null);
|
142 |
artElt.put("QTE", null);
|
262 |
artElt.put("QTE", null);
|
143 |
artElt.put("QTE_UNITAIRE", null);
|
263 |
artElt.put("QTE_UNITAIRE", null);
|
144 |
artElt.put("ID_ARTICLE_PARENT", graph);
|
264 |
artElt.put("ID_ARTICLE_PARENT", graph);
|
- |
|
265 |
final SQLRowValues putRowValues = artElt.putRowValues("ID_ARTICLE");
|
145 |
artElt.putRowValues("ID_ARTICLE").putNulls("ID", "CODE", "NOM").putRowValues("ID_STOCK").putNulls("QTE_TH", "QTE_REEL", "QTE_LIV_ATTENTE", "QTE_RECEPT_ATTENTE");
|
266 |
putRowValues.putNulls("ID", "CODE", "NOM").putRowValues("ID_STOCK").putNulls("QTE_TH", "QTE_REEL", "QTE_LIV_ATTENTE", "QTE_RECEPT_ATTENTE");
|
- |
|
267 |
putRowValues.putRowValues("ID_ARTICLE_DECLINAISON_TAILLE").putNulls("ID", "NOM");
|
- |
|
268 |
putRowValues.putRowValues("ID_ARTICLE_DECLINAISON_COULEUR").putNulls("ID", "NOM");
|
146 |
|
269 |
|
147 |
SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(graph);
|
270 |
SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(graph);
|
148 |
List<SQLRowValues> results = fetcher.fetch();
|
271 |
List<SQLRowValues> results = fetcher.fetch();
|
149 |
|
- |
|
150 |
Map<String, SQLRowValues> vals = new HashMap<String, SQLRowValues>();
|
- |
|
151 |
for (SQLRowValues sqlRowValues : results) {
|
272 |
for (SQLRowValues sqlRowValues : results) {
|
152 |
|
273 |
|
153 |
final Set<SQLRowValues> referentRows = sqlRowValues.getReferentRows(tableArtElt.getField("ID_ARTICLE_PARENT"));
|
274 |
final Set<SQLRowValues> referentRows = sqlRowValues.getReferentRows(tableArtElt.getField("ID_ARTICLE_PARENT"));
|
154 |
// On ne prend que les articles simples
|
275 |
// On ne prend que les articles simples
|
155 |
if (referentRows.size() == 0) {
|
276 |
if (referentRows.size() == 0) {
|
- |
|
277 |
final SQLRowAccessor couleur = sqlRowValues.getObject("ID_ARTICLE_DECLINAISON_COULEUR") == null ? null : sqlRowValues.getNonEmptyForeign("ID_ARTICLE_DECLINAISON_COULEUR");
|
- |
|
278 |
final SQLRowAccessor taille = sqlRowValues.getObject("ID_ARTICLE_DECLINAISON_TAILLE") == null ? null : sqlRowValues.getNonEmptyForeign("ID_ARTICLE_DECLINAISON_TAILLE");
|
- |
|
279 |
if (couleur == null && taille == null) {
|
156 |
final String code = sqlRowValues.getString("CODE");
|
280 |
mapArticle.put(sqlRowValues.getString("CODE"), sqlRowValues);
|
157 |
vals.put(code, sqlRowValues);
|
281 |
} else if (couleur == null) {
|
- |
|
282 |
mapDeclArticle.put(Tuple3.create(sqlRowValues.getString("CODE"), null, taille.getString("NOM")), sqlRowValues);
|
- |
|
283 |
} else if (taille == null) {
|
- |
|
284 |
mapDeclArticle.put(Tuple3.create(sqlRowValues.getString("CODE"), couleur.getString("NOM"), null), sqlRowValues);
|
- |
|
285 |
} else {
|
- |
|
286 |
mapDeclArticle.put(Tuple3.create(sqlRowValues.getString("CODE"), couleur.getString("NOM"), taille.getString("NOM")), sqlRowValues);
|
- |
|
287 |
}
|
158 |
|
288 |
|
159 |
} else {
|
289 |
} else {
|
160 |
|
290 |
|
161 |
}
|
291 |
}
|
162 |
}
|
292 |
}
|
- |
|
293 |
|
- |
|
294 |
}
|
- |
|
295 |
|
- |
|
296 |
private SQLRowAccessor findArticle(String code, String couleur, String taille) throws SQLException {
|
- |
|
297 |
if (!mapCouleur.containsKey(couleur)) {
|
- |
|
298 |
SQLRowValues rowVals = new SQLRowValues(root.getTable("ARTICLE_DECLINAISON_COULEUR"));
|
- |
|
299 |
rowVals.put("NOM", couleur);
|
- |
|
300 |
mapCouleur.put(couleur, rowVals.commit().getID());
|
- |
|
301 |
}
|
- |
|
302 |
if (!mapTaille.containsKey(taille)) {
|
- |
|
303 |
SQLRowValues rowVals = new SQLRowValues(root.getTable("ARTICLE_DECLINAISON_TAILLE"));
|
- |
|
304 |
rowVals.put("NOM", taille);
|
- |
|
305 |
mapTaille.put(taille, rowVals.commit().getID());
|
- |
|
306 |
}
|
- |
|
307 |
|
- |
|
308 |
SQLRowAccessor sqlRowAccessor;
|
- |
|
309 |
if ((couleur == null || couleur.trim().length() == 0) && (taille == null || taille.trim().length() == 0)) {
|
- |
|
310 |
|
- |
|
311 |
sqlRowAccessor = mapArticle.get(code);
|
- |
|
312 |
|
- |
|
313 |
} else if (couleur == null || couleur.trim().length() == 0) {
|
- |
|
314 |
sqlRowAccessor = mapDeclArticle.get(Tuple3.create(code, null, taille.trim()));
|
- |
|
315 |
if (sqlRowAccessor == null) {
|
- |
|
316 |
sqlRowAccessor = cloneFromArticle(mapArticle.get(code), null, mapTaille.get(taille.trim()));
|
- |
|
317 |
mapDeclArticle.put(Tuple3.create(code, null, taille.trim()), sqlRowAccessor);
|
- |
|
318 |
}
|
- |
|
319 |
} else if (taille == null || taille.trim().length() == 0) {
|
- |
|
320 |
sqlRowAccessor = mapDeclArticle.get(Tuple3.create(code, couleur.trim(), null));
|
- |
|
321 |
if (sqlRowAccessor == null) {
|
- |
|
322 |
sqlRowAccessor = cloneFromArticle(mapArticle.get(code), mapCouleur.get(couleur.trim()), null);
|
- |
|
323 |
mapDeclArticle.put(Tuple3.create(code, couleur.trim(), null), sqlRowAccessor);
|
- |
|
324 |
}
|
- |
|
325 |
} else {
|
- |
|
326 |
sqlRowAccessor = mapDeclArticle.get(Tuple3.create(code, couleur.trim(), taille.trim()));
|
- |
|
327 |
if (sqlRowAccessor == null) {
|
- |
|
328 |
if (mapArticle.get(code) != null) {
|
- |
|
329 |
sqlRowAccessor = cloneFromArticle(mapArticle.get(code),
|
- |
|
330 |
|
- |
|
331 |
mapCouleur.get(couleur.trim()), mapTaille.get(taille.trim()));
|
- |
|
332 |
mapDeclArticle.put(Tuple3.create(code, couleur.trim(), taille.trim()), sqlRowAccessor);
|
- |
|
333 |
}
|
- |
|
334 |
}
|
- |
|
335 |
}
|
- |
|
336 |
return sqlRowAccessor;
|
- |
|
337 |
}
|
- |
|
338 |
|
- |
|
339 |
public SQLRow cloneFromArticle(SQLRowAccessor rArt, Integer idCouleur, Integer idTaille) throws SQLException {
|
- |
|
340 |
if (rArt == null) {
|
163 |
return vals;
|
341 |
return null;
|
- |
|
342 |
}
|
- |
|
343 |
SQLRowValues copy = artElt.createCopy(rArt.getID());
|
- |
|
344 |
if (idCouleur != null) {
|
- |
|
345 |
copy.put("ID_ARTICLE_DECLINAISON_COULEUR", idCouleur);
|
- |
|
346 |
}
|
- |
|
347 |
if (idTaille != null) {
|
- |
|
348 |
copy.put("ID_ARTICLE_DECLINAISON_TAILLE", idTaille);
|
- |
|
349 |
}
|
- |
|
350 |
return copy.commit();
|
- |
|
351 |
}
|
- |
|
352 |
|
- |
|
353 |
private String getColumnName(int columnNumber) {
|
- |
|
354 |
int dividend = columnNumber;
|
- |
|
355 |
String columnName = "";
|
- |
|
356 |
int modulo;
|
- |
|
357 |
|
- |
|
358 |
while (dividend >= 0) {
|
- |
|
359 |
modulo = dividend % 26;
|
- |
|
360 |
columnName = String.valueOf((char) (65 + modulo)) + columnName;
|
- |
|
361 |
dividend = (int) ((dividend - modulo) / 26);
|
- |
|
362 |
if (dividend <= 0) {
|
- |
|
363 |
break;
|
- |
|
364 |
} else {
|
- |
|
365 |
dividend--;
|
- |
|
366 |
}
|
- |
|
367 |
}
|
- |
|
368 |
|
- |
|
369 |
return columnName;
|
164 |
}
|
370 |
}
|
165 |
}
|
371 |
}
|