Line 20... |
Line 20... |
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.erp.preferences.GestionArticleGlobalPreferencePanel;
|
22 |
import org.openconcerto.sql.Configuration;
|
22 |
import org.openconcerto.sql.Configuration;
|
23 |
import org.openconcerto.sql.element.SQLElement;
|
23 |
import org.openconcerto.sql.element.SQLElement;
|
24 |
import org.openconcerto.sql.model.DBRoot;
|
24 |
import org.openconcerto.sql.model.DBRoot;
|
- |
|
25 |
import org.openconcerto.sql.model.SQLBase;
|
- |
|
26 |
import org.openconcerto.sql.model.SQLInsert;
|
25 |
import org.openconcerto.sql.model.SQLRow;
|
27 |
import org.openconcerto.sql.model.SQLRow;
|
26 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
28 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
27 |
import org.openconcerto.sql.model.SQLRowListRSH;
|
29 |
import org.openconcerto.sql.model.SQLRowListRSH;
|
28 |
import org.openconcerto.sql.model.SQLRowValues;
|
30 |
import org.openconcerto.sql.model.SQLRowValues;
|
29 |
import org.openconcerto.sql.model.SQLRowValuesCluster.StoreMode;
|
- |
|
30 |
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
|
31 |
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
|
31 |
import org.openconcerto.sql.model.SQLSelect;
|
32 |
import org.openconcerto.sql.model.SQLSelect;
|
32 |
import org.openconcerto.sql.model.SQLTable;
|
33 |
import org.openconcerto.sql.model.SQLTable;
|
- |
|
34 |
import org.openconcerto.sql.model.SQLUpdate;
|
- |
|
35 |
import org.openconcerto.sql.model.Where;
|
33 |
import org.openconcerto.sql.preferences.SQLPreferences;
|
36 |
import org.openconcerto.sql.preferences.SQLPreferences;
|
- |
|
37 |
import org.openconcerto.sql.request.UpdateBuilder;
|
34 |
import org.openconcerto.sql.utils.SQLUtils;
|
38 |
import org.openconcerto.sql.utils.SQLUtils;
|
35 |
import org.openconcerto.utils.Tuple2;
|
39 |
import org.openconcerto.utils.CollectionUtils;
|
36 |
import org.openconcerto.utils.Tuple3;
|
40 |
import org.openconcerto.utils.Tuple3;
|
- |
|
41 |
import org.openconcerto.utils.cc.ITransformer;
|
37 |
|
42 |
|
38 |
import java.io.File;
|
43 |
import java.io.File;
|
39 |
import java.io.IOException;
|
44 |
import java.io.IOException;
|
40 |
import java.math.BigDecimal;
|
45 |
import java.math.BigDecimal;
|
41 |
import java.sql.SQLException;
|
46 |
import java.sql.SQLException;
|
Line 43... |
Line 48... |
43 |
import java.util.Arrays;
|
48 |
import java.util.Arrays;
|
44 |
import java.util.Calendar;
|
49 |
import java.util.Calendar;
|
45 |
import java.util.Collection;
|
50 |
import java.util.Collection;
|
46 |
import java.util.Date;
|
51 |
import java.util.Date;
|
47 |
import java.util.HashMap;
|
52 |
import java.util.HashMap;
|
- |
|
53 |
import java.util.HashSet;
|
48 |
import java.util.List;
|
54 |
import java.util.List;
|
49 |
import java.util.Map;
|
55 |
import java.util.Map;
|
50 |
import java.util.Map.Entry;
|
56 |
import java.util.Map.Entry;
|
51 |
import java.util.Set;
|
57 |
import java.util.Set;
|
52 |
|
58 |
|
Line 55... |
Line 61... |
55 |
import org.apache.commons.dbutils.ResultSetHandler;
|
61 |
import org.apache.commons.dbutils.ResultSetHandler;
|
56 |
|
62 |
|
57 |
public class InventaireFromEtatStockImporter {
|
63 |
public class InventaireFromEtatStockImporter {
|
58 |
|
64 |
|
59 |
private Map<String, SQLRowValues> kits = new HashMap<String, SQLRowValues>();
|
65 |
private Map<String, SQLRowValues> kits = new HashMap<String, SQLRowValues>();
|
- |
|
66 |
private Map<Integer, InventaireProductLine> kitsChildren = new HashMap<Integer, InventaireProductLine>();
|
60 |
private List<String> codeKits = new ArrayList<String>();
|
67 |
private List<String> codeKits = new ArrayList<String>();
|
61 |
private SQLRowAccessor depot;
|
- |
|
62 |
private static String FAMILLE = "Famille";
|
68 |
private static String FAMILLE = "Famille";
|
63 |
private static String CODE = "Code";
|
69 |
private static String CODE = "Code";
|
64 |
private static String NOM = "Nom";
|
70 |
private static String NOM = "Nom";
|
65 |
private static String TAILLE = "Taille";
|
71 |
private static String TAILLE = "Taille";
|
- |
|
72 |
private static String DEPOT = "Dépôt";
|
66 |
private static String COULEUR = "Couleur";
|
73 |
private static String COULEUR = "Couleur";
|
67 |
private static String QTE = "Qté réelle relevée";
|
74 |
private static String QTE = "Qté réelle relevée";
|
68 |
private static String QTE_OPENCONCERTO = "QTE OpenConcerto";
|
75 |
private static String QTE_OPENCONCERTO = "QTE OpenConcerto";
|
69 |
private final Map<String, Integer> mapCouleur = new HashMap<String, Integer>();
|
76 |
private final Map<String, Integer> mapCouleur = new HashMap<String, Integer>();
|
70 |
private final Map<String, Integer> mapTaille = new HashMap<String, Integer>();
|
77 |
private final Map<String, Integer> mapTaille = new HashMap<String, Integer>();
|
71 |
private final DBRoot root;
|
78 |
private final DBRoot root;
|
72 |
private final SQLElement artElt;
|
79 |
private final SQLElement artElt;
|
73 |
|
80 |
|
74 |
public InventaireFromEtatStockImporter(SQLElement articleElt, SQLRowAccessor depot) {
|
81 |
public InventaireFromEtatStockImporter(SQLElement articleElt) {
|
75 |
this.depot = depot;
|
- |
|
76 |
this.root = articleElt.getTable().getDBRoot();
|
82 |
this.root = articleElt.getTable().getDBRoot();
|
77 |
this.artElt = articleElt;
|
83 |
this.artElt = articleElt;
|
78 |
{
|
84 |
{
|
79 |
SQLSelect sel = new SQLSelect();
|
85 |
SQLSelect sel = new SQLSelect();
|
80 |
sel.addSelect(articleElt.getTable().getTable("ARTICLE_DECLINAISON_COULEUR").getKey());
|
86 |
sel.addSelect(articleElt.getTable().getTable("ARTICLE_DECLINAISON_COULEUR").getKey());
|
81 |
sel.addSelect(articleElt.getTable().getTable("ARTICLE_DECLINAISON_COULEUR").getField("NOM"));
|
87 |
sel.addSelect(articleElt.getTable().getTable("ARTICLE_DECLINAISON_COULEUR").getField("NOM"));
|
82 |
|
88 |
|
83 |
List<SQLRow> l = SQLRowListRSH.execute(sel);
|
89 |
List<SQLRow> l = SQLRowListRSH.execute(sel);
|
84 |
|
90 |
|
85 |
for (SQLRow sqlRow : l) {
|
91 |
for (SQLRow sqlRow : l) {
|
86 |
mapCouleur.put(sqlRow.getString("NOM").trim(), sqlRow.getID());
|
92 |
this.mapCouleur.put(sqlRow.getString("NOM").trim(), sqlRow.getID());
|
87 |
}
|
93 |
}
|
88 |
}
|
94 |
}
|
89 |
|
95 |
|
90 |
{
|
96 |
{
|
91 |
SQLSelect sel = new SQLSelect();
|
97 |
SQLSelect sel = new SQLSelect();
|
Line 93... |
Line 99... |
93 |
sel.addSelect(articleElt.getTable().getTable("ARTICLE_DECLINAISON_TAILLE").getField("NOM"));
|
99 |
sel.addSelect(articleElt.getTable().getTable("ARTICLE_DECLINAISON_TAILLE").getField("NOM"));
|
94 |
|
100 |
|
95 |
List<SQLRow> l = SQLRowListRSH.execute(sel);
|
101 |
List<SQLRow> l = SQLRowListRSH.execute(sel);
|
96 |
|
102 |
|
97 |
for (SQLRow sqlRow : l) {
|
103 |
for (SQLRow sqlRow : l) {
|
98 |
mapTaille.put(sqlRow.getString("NOM").trim(), sqlRow.getID());
|
104 |
this.mapTaille.put(sqlRow.getString("NOM").trim(), sqlRow.getID());
|
99 |
}
|
105 |
}
|
100 |
}
|
106 |
}
|
101 |
}
|
107 |
}
|
102 |
|
108 |
|
103 |
public void importArticles(File file, DBRoot root) throws IOException, SQLException {
|
109 |
public void importArticles(File file, DBRoot root) throws IOException, SQLException {
|
Line 115... |
Line 121... |
115 |
columnMapping.put(TAILLE, null);
|
121 |
columnMapping.put(TAILLE, null);
|
116 |
columnMapping.put(FAMILLE, null);
|
122 |
columnMapping.put(FAMILLE, null);
|
117 |
columnMapping.put(COULEUR, null);
|
123 |
columnMapping.put(COULEUR, null);
|
118 |
columnMapping.put(QTE, null);
|
124 |
columnMapping.put(QTE, null);
|
119 |
columnMapping.put(QTE_OPENCONCERTO, null);
|
125 |
columnMapping.put(QTE_OPENCONCERTO, null);
|
- |
|
126 |
columnMapping.put(DEPOT, null);
|
120 |
{
|
127 |
{
|
121 |
// Searching column index from column Header
|
128 |
// Searching column index from column Header
|
122 |
final DataImporter importer = new DataImporter(table);
|
129 |
final DataImporter importer = new DataImporter(table);
|
123 |
importer.setSkipFirstLine(false);
|
130 |
importer.setSkipFirstLine(false);
|
124 |
ArrayTableModel m = importer.createModelFrom(file);
|
131 |
ArrayTableModel m = importer.createModelFrom(file);
|
Line 138... |
Line 145... |
138 |
String msg = "Colonnes importées : \n";
|
145 |
String msg = "Colonnes importées : \n";
|
139 |
final SQLPreferences prefs = SQLPreferences.getMemCached(table.getDBRoot());
|
146 |
final SQLPreferences prefs = SQLPreferences.getMemCached(table.getDBRoot());
|
140 |
final boolean hasDeclinaison = prefs.getBoolean(GestionArticleGlobalPreferencePanel.ACTIVER_DECLINAISON, false);
|
147 |
final boolean hasDeclinaison = prefs.getBoolean(GestionArticleGlobalPreferencePanel.ACTIVER_DECLINAISON, false);
|
141 |
List<String> required;
|
148 |
List<String> required;
|
142 |
if (hasDeclinaison) {
|
149 |
if (hasDeclinaison) {
|
- |
|
150 |
|
143 |
required = Arrays.asList(CODE, QTE, QTE_OPENCONCERTO, TAILLE, COULEUR);
|
151 |
required = Arrays.asList(CODE, QTE, QTE_OPENCONCERTO, TAILLE, COULEUR);
|
144 |
} else {
|
152 |
} else {
|
145 |
required = Arrays.asList(CODE, QTE, QTE_OPENCONCERTO);
|
153 |
required = Arrays.asList(CODE, QTE, QTE_OPENCONCERTO);
|
146 |
}
|
154 |
}
|
147 |
|
155 |
|
- |
|
156 |
SQLSelect selDepot = new SQLSelect();
|
- |
|
157 |
selDepot.addSelectStar(tableArtElt.getTable("DEPOT_STOCK"));
|
- |
|
158 |
final List<SQLRow> listDepot = SQLRowListRSH.execute(selDepot);
|
- |
|
159 |
final Map<String, SQLRow> mapDepot = new HashMap<>();
|
- |
|
160 |
for (SQLRow sqlRow : listDepot) {
|
- |
|
161 |
mapDepot.put(sqlRow.getString("NOM"), sqlRow);
|
- |
|
162 |
}
|
- |
|
163 |
|
148 |
for (Entry<String, Integer> e : columnMapping.entrySet()) {
|
164 |
for (Entry<String, Integer> e : columnMapping.entrySet()) {
|
149 |
if (e.getValue() != null) {
|
165 |
if (e.getValue() != null) {
|
150 |
msg += e.getKey() + " : " + getColumnName(e.getValue()) + "\n";
|
166 |
msg += e.getKey() + " : " + getColumnName(e.getValue()) + "\n";
|
151 |
} else {
|
167 |
} else {
|
152 |
if (required.contains(e.getKey())) {
|
168 |
if (required.contains(e.getKey())) {
|
Line 169... |
Line 185... |
169 |
};
|
185 |
};
|
170 |
importer.setSkipFirstLine(true);
|
186 |
importer.setSkipFirstLine(true);
|
171 |
|
187 |
|
172 |
ArrayTableModel m = importer.createModelFrom(file);
|
188 |
ArrayTableModel m = importer.createModelFrom(file);
|
173 |
|
189 |
|
- |
|
190 |
// Check depot
|
- |
|
191 |
boolean multiDepotPrefs = prefs.getBoolean(GestionArticleGlobalPreferencePanel.STOCK_MULTI_DEPOT, false);
|
- |
|
192 |
SQLRowAccessor defaultDepotRow = null;
|
- |
|
193 |
boolean multiDepotFile = columnMapping.containsKey(DEPOT);
|
- |
|
194 |
if (!multiDepotFile) {
|
- |
|
195 |
if (multiDepotPrefs) {
|
- |
|
196 |
// TODO popup choix depot
|
- |
|
197 |
} else {
|
- |
|
198 |
defaultDepotRow = table.getTable("DEPOT_STOCK").getRow(DepotStockSQLElement.DEFAULT_ID);
|
- |
|
199 |
}
|
- |
|
200 |
} else {
|
- |
|
201 |
Set<String> errors = new HashSet<>();
|
- |
|
202 |
for (int i = 1; i < m.getRowCount(); i++) {
|
- |
|
203 |
List<Object> o = m.getLineValuesAt(i);
|
- |
|
204 |
if (o.size() >= 5) {
|
- |
|
205 |
System.err.println(o);
|
- |
|
206 |
String code = o.get(columnMapping.get(CODE)).toString();
|
- |
|
207 |
if (code.trim().length() > 0) {
|
- |
|
208 |
|
- |
|
209 |
final String depotName = o.get(columnMapping.get(DEPOT)).toString().trim();
|
- |
|
210 |
if (depotName.length() == 0) {
|
- |
|
211 |
errors.add("Le Depôt n'est pas renseigné, ligne " + i + ". Import annulé!");
|
- |
|
212 |
|
- |
|
213 |
} else if (mapDepot.get(depotName) == null) {
|
- |
|
214 |
errors.add("Impossible de trouver le dépôt " + depotName + ", ligne " + i + ". Import annulé!");
|
- |
|
215 |
}
|
- |
|
216 |
|
- |
|
217 |
}
|
- |
|
218 |
}
|
- |
|
219 |
}
|
- |
|
220 |
if (!errors.isEmpty()) {
|
- |
|
221 |
JOptionPane.showMessageDialog(null, errors);
|
- |
|
222 |
return;
|
- |
|
223 |
}
|
- |
|
224 |
}
|
- |
|
225 |
|
174 |
Calendar c = Calendar.getInstance();
|
226 |
Calendar c = Calendar.getInstance();
|
175 |
// c.set(Calendar.DAY_OF_MONTH, 1);
|
227 |
// c.set(Calendar.DAY_OF_MONTH, 1);
|
176 |
// c.set(Calendar.MONTH, Calendar.JANUARY);
|
228 |
// c.set(Calendar.MONTH, Calendar.JANUARY);
|
177 |
// c.set(Calendar.HOUR_OF_DAY, 0);
|
229 |
// c.set(Calendar.HOUR_OF_DAY, 0);
|
178 |
Date today = c.getTime();
|
230 |
Date today = c.getTime();
|
179 |
|
231 |
|
180 |
// TODO ne pas vider les stocks des kits, recalculer les stocks des kits
|
232 |
// TODO ne pas vider les stocks des kits, recalculer les stocks des kits
|
181 |
|
233 |
|
182 |
SQLRowValues rowVals = new SQLRowValues(table.getTable("ETAT_STOCK"));
|
- |
|
183 |
rowVals.put("DATE", today);
|
- |
|
184 |
rowVals.put("INVENTAIRE", Boolean.TRUE);
|
- |
|
185 |
rowVals.put("ID_DEPOT_STOCK", this.depot.getID());
|
- |
|
186 |
SQLRow rowEtat = rowVals.commit();
|
234 |
Map<Integer, Integer> mapDepotEtat = new HashMap<>();
|
187 |
|
235 |
|
- |
|
236 |
List<SQLInsert> inserts = new ArrayList<>();
|
- |
|
237 |
List<SQLUpdate> updates = new ArrayList<>();
|
188 |
for (int i = 1; i < m.getRowCount(); i++) {
|
238 |
for (int i = 1; i < m.getRowCount(); i++) {
|
189 |
List<Object> o = m.getLineValuesAt(i);
|
239 |
List<Object> o = m.getLineValuesAt(i);
|
190 |
if (o.size() >= 5) {
|
240 |
if (o.size() >= 5) {
|
191 |
System.err.println(o);
|
241 |
System.err.println(o);
|
192 |
String code = o.get(columnMapping.get(CODE)).toString();
|
242 |
String code = o.get(columnMapping.get(CODE)).toString();
|
Line 207... |
Line 257... |
207 |
taille = o.get(columnMapping.get(TAILLE)).toString();
|
257 |
taille = o.get(columnMapping.get(TAILLE)).toString();
|
208 |
}
|
258 |
}
|
209 |
|
259 |
|
210 |
// SQLRowAccessor match = findArticle(code, couleur, taille);
|
260 |
// SQLRowAccessor match = findArticle(code, couleur, taille);
|
211 |
|
261 |
|
212 |
Tuple2<SQLRowValues, SQLRowValues> match = findArticle(code, couleur, taille);
|
262 |
InventaireProductLine match = findArticle(code, couleur, taille);
|
213 |
if (match != null) {
|
263 |
if (match != null) {
|
214 |
|
264 |
|
215 |
SQLRowAccessor stockValues = match.get1();
|
265 |
SQLRowAccessor depotRow = defaultDepotRow;
|
- |
|
266 |
|
- |
|
267 |
if (multiDepotFile) {
|
- |
|
268 |
final String depotName = o.get(columnMapping.get(DEPOT)).toString().trim();
|
- |
|
269 |
depotRow = mapDepot.get(depotName);
|
- |
|
270 |
}
|
- |
|
271 |
|
- |
|
272 |
if (!mapDepotEtat.containsKey(depotRow.getID())) {
|
- |
|
273 |
mapDepotEtat.put(depotRow.getID(), createEtat(table.getTable("ETAT_STOCK"), depotRow.getID()).commit().getID());
|
- |
|
274 |
}
|
- |
|
275 |
|
- |
|
276 |
int etatID = mapDepotEtat.get(depotRow.getID());
|
- |
|
277 |
|
- |
|
278 |
SQLRowAccessor stockValues = match.getOrCreateStockRowValues(depotRow);
|
216 |
|
279 |
|
217 |
final SQLTable tableMvt = table.getTable("MOUVEMENT_STOCK");
|
280 |
final SQLTable tableMvt = table.getTable("MOUVEMENT_STOCK");
|
218 |
SQLRowValues rowValsMvtStockClotureFermeture = new SQLRowValues(tableMvt);
|
281 |
SQLInsert insertMvtStockClotureFermeture = new SQLInsert();
|
219 |
rowValsMvtStockClotureFermeture.put("QTE", -qtyOld);
|
282 |
insertMvtStockClotureFermeture.add(tableMvt.getField("QTE"), -qtyOld);
|
220 |
rowValsMvtStockClotureFermeture.put("NOM", "Clôture stock avant inventaire");
|
283 |
insertMvtStockClotureFermeture.add(tableMvt.getField("NOM"), "Clôture stock avant inventaire");
|
221 |
rowValsMvtStockClotureFermeture.put("ID_ARTICLE", match.get0().getID());
|
284 |
insertMvtStockClotureFermeture.add(tableMvt.getField("ID_ARTICLE"), match.getRowValsArt().getID());
|
222 |
rowValsMvtStockClotureFermeture.put("DATE", today);
|
285 |
insertMvtStockClotureFermeture.add(tableMvt.getField("DATE"), today);
|
223 |
rowValsMvtStockClotureFermeture.put("REEL", Boolean.TRUE);
|
286 |
insertMvtStockClotureFermeture.add(tableMvt.getField("REEL"), Boolean.TRUE);
|
224 |
rowValsMvtStockClotureFermeture.put("ID_STOCK", stockValues.getID());
|
287 |
insertMvtStockClotureFermeture.add(tableMvt.getField("ID_STOCK"), stockValues.getID());
|
225 |
|
288 |
|
226 |
BigDecimal prc = getPRC(match.get0(), Math.round(qtyOld), today);
|
289 |
BigDecimal prc = getPRC(match.getRowValsArt(), Math.round(qtyOld), today);
|
227 |
if (prc == null) {
|
290 |
if (prc == null) {
|
228 |
prc = BigDecimal.ZERO;
|
291 |
prc = BigDecimal.ZERO;
|
229 |
}
|
292 |
}
|
230 |
if (tableMvt.contains("PRICE")) {
|
293 |
if (tableMvt.contains("PRICE")) {
|
231 |
rowValsMvtStockClotureFermeture.put("PRICE", prc);
|
294 |
insertMvtStockClotureFermeture.add(tableMvt.getField("PRICE"), prc);
|
232 |
}
|
295 |
}
|
233 |
rowValsMvtStockClotureFermeture.put("CLOTURE", Boolean.TRUE);
|
296 |
insertMvtStockClotureFermeture.add(tableMvt.getField("CLOTURE"), Boolean.TRUE);
|
234 |
rowValsMvtStockClotureFermeture.put("ID_ETAT_STOCK", rowEtat.getID());
|
297 |
insertMvtStockClotureFermeture.add(tableMvt.getField("ID_ETAT_STOCK"), etatID);
|
235 |
rowValsMvtStockClotureFermeture.getGraph().store(StoreMode.COMMIT, false);
|
298 |
// insertMvtStockClotureFermeture.getGraph().store(StoreMode.COMMIT,
|
- |
|
299 |
// false);
|
- |
|
300 |
|
- |
|
301 |
inserts.add(insertMvtStockClotureFermeture);
|
236 |
|
302 |
|
237 |
SQLRowValues rowValsItem = new SQLRowValues(table.getTable("ETAT_STOCK_ELEMENT"));
|
303 |
final SQLTable tableEtatElt = table.getTable("ETAT_STOCK_ELEMENT");
|
- |
|
304 |
SQLInsert insertItem = new SQLInsert();
|
238 |
rowValsItem.put("ID_ETAT_STOCK", rowEtat.getID());
|
305 |
insertItem.add(tableEtatElt.getField("ID_ETAT_STOCK"), etatID);
|
239 |
rowValsItem.put("PA", prc);
|
306 |
insertItem.add(tableEtatElt.getField("PA"), prc);
|
240 |
rowValsItem.put("PV", BigDecimal.ZERO);
|
307 |
insertItem.add(tableEtatElt.getField("PV"), BigDecimal.ZERO);
|
241 |
rowValsItem.put("QTE", qtyOld);
|
308 |
insertItem.add(tableEtatElt.getField("QTE"), qtyOld);
|
242 |
rowValsItem.put("T_PA", prc.multiply(new BigDecimal(qtyOld)));
|
309 |
insertItem.add(tableEtatElt.getField("T_PA"), prc.multiply(new BigDecimal(qtyOld)));
|
243 |
rowValsItem.put("T_PV", BigDecimal.ZERO);
|
310 |
insertItem.add(tableEtatElt.getField("T_PV"), BigDecimal.ZERO);
|
244 |
rowValsItem.put("CODE", match.get0().getString("CODE"));
|
311 |
insertItem.add(tableEtatElt.getField("CODE"), match.getRowValsArt().getString("CODE"));
|
245 |
rowValsItem.put("NOM", match.get0().getString("NOM"));
|
312 |
insertItem.add(tableEtatElt.getField("NOM"), match.getRowValsArt().getString("NOM"));
|
246 |
rowValsItem.put("ID_ARTICLE", match.get0().getID());
|
313 |
insertItem.add(tableEtatElt.getField("ID_ARTICLE"), match.getRowValsArt().getID());
|
247 |
rowValsItem.getGraph().store(StoreMode.COMMIT, false);
|
314 |
// insertItem.getGraph().store(StoreMode.COMMIT, false);
|
- |
|
315 |
inserts.add(insertItem);
|
248 |
|
316 |
|
249 |
SQLRowValues rowValsMvtStockClotureOuverture = new SQLRowValues(tableMvt);
|
317 |
SQLInsert insertMvtStockClotureOuverture = new SQLInsert();
|
250 |
rowValsMvtStockClotureOuverture.put("QTE", qty);
|
318 |
insertMvtStockClotureOuverture.add(tableMvt.getField("QTE"), qty);
|
251 |
rowValsMvtStockClotureOuverture.put("NOM", "Mise en stock inventaire");
|
319 |
insertMvtStockClotureOuverture.add(tableMvt.getField("NOM"), "Mise en stock inventaire");
|
252 |
rowValsMvtStockClotureOuverture.put("ID_ETAT_STOCK", rowEtat.getID());
|
320 |
insertMvtStockClotureOuverture.add(tableMvt.getField("ID_ETAT_STOCK"), etatID);
|
253 |
rowValsMvtStockClotureOuverture.put("ID_ARTICLE", match.get0().getID());
|
321 |
insertMvtStockClotureOuverture.add(tableMvt.getField("ID_ARTICLE"), match.getRowValsArt().getID());
|
254 |
rowValsMvtStockClotureOuverture.put("DATE", today);
|
322 |
insertMvtStockClotureOuverture.add(tableMvt.getField("DATE"), today);
|
255 |
rowValsMvtStockClotureOuverture.put("REEL", Boolean.TRUE);
|
323 |
insertMvtStockClotureOuverture.add(tableMvt.getField("REEL"), Boolean.TRUE);
|
256 |
rowValsMvtStockClotureOuverture.put("ID_STOCK", stockValues.getID());
|
324 |
insertMvtStockClotureOuverture.add(tableMvt.getField("ID_STOCK"), stockValues.getID());
|
257 |
rowValsMvtStockClotureOuverture.put("OUVERTURE", Boolean.TRUE);
|
325 |
insertMvtStockClotureOuverture.add(tableMvt.getField("OUVERTURE"), Boolean.TRUE);
|
258 |
if (tableMvt.contains("PRICE")) {
|
326 |
if (tableMvt.contains("PRICE")) {
|
259 |
rowValsMvtStockClotureOuverture.put("PRICE", getPRC(match.get0(), qty.intValue(), today));
|
327 |
insertMvtStockClotureOuverture.add(tableMvt.getField("PRICE"), getPRC(match.getRowValsArt(), qty.intValue(), today));
|
260 |
}
|
328 |
}
|
- |
|
329 |
inserts.add(insertMvtStockClotureOuverture);
|
261 |
rowValsMvtStockClotureOuverture.getGraph().store(StoreMode.COMMIT, false);
|
330 |
// insertMvtStockClotureOuverture.getGraph().store(StoreMode.COMMIT,
|
- |
|
331 |
// false);
|
262 |
|
332 |
|
263 |
// if (!match.isForeignEmpty("ID_STOCK")) {
|
333 |
// if (!match.isForeignEmpty("ID_STOCK")) {
|
264 |
// match.getForeign("ID_STOCK").createEmptyUpdateRow().put("QTE_REEL",
|
334 |
// match.getForeign("ID_STOCK").createEmptyUpdateRow().put("QTE_REEL",
|
265 |
// qty).commit();
|
335 |
// qty).commit();
|
266 |
// } else {
|
336 |
// } else {
|
267 |
final SQLRowValues createEmptyUpdateRow = match.get1().createEmptyUpdateRow();
|
337 |
// final SQLRowValues createEmptyUpdateRow =
|
- |
|
338 |
// stockValues.createEmptyUpdateRow();
|
268 |
createEmptyUpdateRow.put("QTE_REEL", qty);
|
339 |
// createEmptyUpdateRow.put("QTE_REEL", qty);
|
269 |
createEmptyUpdateRow.getGraph().store(StoreMode.COMMIT, false);
|
340 |
// createEmptyUpdateRow.getGraph().store(StoreMode.COMMIT, false);
|
270 |
|
- |
|
- |
|
341 |
SQLUpdate up = new SQLUpdate(new Where(stockValues.getTable().getKey(), "=", stockValues.getID()));
|
- |
|
342 |
up.add(stockValues.getTable().getField("QTE_REEL"), qty);
|
- |
|
343 |
updates.add(up);
|
271 |
// }
|
344 |
// }
|
272 |
|
345 |
|
273 |
} else {
|
346 |
} else {
|
274 |
System.err.println("Aucun article correspondant au code " + code);
|
347 |
System.err.println("\t Aucun article correspondant au code " + code);
|
275 |
}
|
348 |
}
|
276 |
}
|
349 |
}
|
277 |
}
|
350 |
}
|
278 |
}
|
351 |
}
|
279 |
|
352 |
|
- |
|
353 |
if (!inserts.isEmpty()) {
|
- |
|
354 |
SQLInsert.executeMultipleWithBatch(table.getDBSystemRoot(), inserts);
|
- |
|
355 |
}
|
- |
|
356 |
if (!updates.isEmpty()) {
|
- |
|
357 |
SQLUpdate.executeMultipleWithBatch(table.getDBSystemRoot(), updates);
|
- |
|
358 |
System.err.println(CollectionUtils.join(updates, ";\n"));
|
- |
|
359 |
}
|
- |
|
360 |
|
280 |
/**
|
361 |
/**
|
281 |
* Mise à jour des kits
|
362 |
* Mise à jour des kits
|
282 |
*/
|
363 |
*/
|
283 |
|
364 |
|
- |
|
365 |
final List<? extends SQLRowAccessor> rowsDepot;
|
- |
|
366 |
if (multiDepotFile) {
|
- |
|
367 |
rowsDepot = listDepot;
|
- |
|
368 |
} else {
|
- |
|
369 |
rowsDepot = Arrays.asList(defaultDepotRow);
|
- |
|
370 |
}
|
- |
|
371 |
|
284 |
List<String> reqs = new ArrayList<String>();
|
372 |
List<String> reqs = new ArrayList<String>();
|
- |
|
373 |
// Recalcul des stocks pour chaque kit impacté
|
285 |
for (String code : codeKits) {
|
374 |
for (String code : this.codeKits) {
|
286 |
System.err.println(code);
|
375 |
System.err.println(code);
|
287 |
SQLRowValues rowValsKit = kits.get(code);
|
376 |
SQLRowValues rowValsKit = this.kits.get(code);
|
- |
|
377 |
|
- |
|
378 |
// récupération des stocks initialisés pour ce kit
|
- |
|
379 |
final Set<SQLRowValues> referentRowsStock = rowValsKit.getReferentRows(table.getTable("STOCK").getField("ID_ARTICLE"));
|
- |
|
380 |
for (SQLRowAccessor d : referentRowsStock) {
|
288 |
StockItem item = new StockItem(rowValsKit, ProductComponent.findOrCreateStock(rowValsKit, depot));
|
381 |
StockItem item = new StockItem(rowValsKit, d);
|
289 |
Collection<SQLRowValues> elts = rowValsKit.getReferentRows(tableArtElt.getField("ID_ARTICLE_PARENT"));
|
382 |
Collection<SQLRowValues> elts = rowValsKit.getReferentRows(tableArtElt.getField("ID_ARTICLE_PARENT"));
|
- |
|
383 |
|
- |
|
384 |
// Recalcul du stock pour le dépot
|
290 |
for (SQLRowValues sqlRowValues : elts) {
|
385 |
for (SQLRowValues sqlRowValues : elts) {
|
- |
|
386 |
final InventaireProductLine inventaireProductLine = this.kitsChildren.get(sqlRowValues.getID());
|
- |
|
387 |
|
291 |
if (sqlRowValues.getForeign("ID_ARTICLE") != null) {
|
388 |
if (inventaireProductLine != null && sqlRowValues.getForeign("ID_ARTICLE") != null) {
|
- |
|
389 |
final SQLRowValues stockArticle = inventaireProductLine.getStockRowValues(d.getForeign("ID_DEPOT_STOCK"));
|
292 |
item.addItemComponent(
|
390 |
if (stockArticle != null)
|
293 |
new StockItemComponent(new StockItem(sqlRowValues.getForeign("ID_ARTICLE"), ProductComponent.findOrCreateStock(sqlRowValues.getForeign("ID_ARTICLE"), depot)),
|
391 |
item.addItemComponent(new StockItemComponent(new StockItem(sqlRowValues.getForeign("ID_ARTICLE"), stockArticle), sqlRowValues.getBigDecimal("QTE_UNITAIRE"),
|
294 |
sqlRowValues.getBigDecimal("QTE_UNITAIRE"), sqlRowValues.getInt("QTE")));
|
392 |
sqlRowValues.getInt("QTE")));
|
295 |
}
|
393 |
}
|
296 |
}
|
394 |
}
|
297 |
item.updateQtyFromChildren();
|
395 |
item.updateQtyFromChildren();
|
298 |
reqs.add(item.getUpdateRequest());
|
396 |
reqs.add(item.getUpdateRequest());
|
299 |
}
|
397 |
}
|
- |
|
398 |
}
|
300 |
|
399 |
|
- |
|
400 |
if (!reqs.isEmpty()) {
|
301 |
List<? extends ResultSetHandler> handlers = new ArrayList<ResultSetHandler>(reqs.size());
|
401 |
List<? extends ResultSetHandler> handlers = new ArrayList<ResultSetHandler>(reqs.size());
|
302 |
for (String s : reqs) {
|
402 |
for (String s : reqs) {
|
303 |
handlers.add(null);
|
403 |
handlers.add(null);
|
304 |
}
|
404 |
}
|
305 |
// FIXME FIRE TABLE CHANGED TO UPDATE ILISTE ??
|
405 |
// FIXME FIRE TABLE CHANGED TO UPDATE ILISTE ??
|
306 |
SQLUtils.executeMultiple(table.getDBSystemRoot(), reqs, handlers);
|
406 |
SQLUtils.executeMultiple(table.getDBSystemRoot(), reqs, handlers);
|
- |
|
407 |
}
|
- |
|
408 |
// Recalcul du stock théorique
|
- |
|
409 |
final SQLTable tableStock = root.getTable("STOCK");
|
- |
|
410 |
org.openconcerto.sql.request.UpdateBuilder req = new UpdateBuilder(tableStock);
|
- |
|
411 |
req.set("QTE_TH", SQLBase.quoteIdentifier("QTE_REEL") + "-" + SQLBase.quoteIdentifier("QTE_LIV_ATTENTE") + "+" + SQLBase.quoteIdentifier("QTE_RECEPT_ATTENTE"));
|
- |
|
412 |
table.getDBSystemRoot().getDataSource().execute(req.asString());
|
307 |
|
413 |
|
308 |
/**
|
414 |
/**
|
309 |
* Mise à jour des prix mini
|
415 |
* Mise à jour des prix mini
|
310 |
*/
|
416 |
*/
|
311 |
// for (SQLRowValues rowValsArt : rowValsArtNonSync) {
|
417 |
// for (SQLRowValues rowValsArt : rowValsArtNonSync) {
|
Line 342... |
Line 448... |
342 |
// SQLRow rowVals = mapLastValidAchatRows.get(qte);
|
448 |
// SQLRow rowVals = mapLastValidAchatRows.get(qte);
|
343 |
// checkMinPrice(rowVals, mapLastValidRows.get(qte));
|
449 |
// checkMinPrice(rowVals, mapLastValidRows.get(qte));
|
344 |
// }
|
450 |
// }
|
345 |
// }
|
451 |
// }
|
346 |
}
|
452 |
}
|
- |
|
453 |
|
- |
|
454 |
}
|
- |
|
455 |
|
- |
|
456 |
public static SQLInsert getCreateStock(SQLRowAccessor article, SQLRowAccessor depot) {
|
- |
|
457 |
|
- |
|
458 |
SQLTable stockTable = article.getTable().getTable("STOCK");
|
- |
|
459 |
SQLRowValues putRowValuesStock = new SQLRowValues(stockTable);
|
- |
|
460 |
putRowValuesStock.putNulls(stockTable.getTable().getFieldsName());
|
- |
|
461 |
|
- |
|
462 |
SQLRowValuesListFetcher fetch = SQLRowValuesListFetcher.create(putRowValuesStock);
|
- |
|
463 |
Where w = new Where(putRowValuesStock.getTable().getField("ID_DEPOT_STOCK"), "=", depot.getID());
|
- |
|
464 |
Where w2 = new Where(putRowValuesStock.getTable().getField("ID_ARTICLE"), "=", article.getID());
|
- |
|
465 |
Collection<SQLRowValues> rowValsResult = fetch.fetch(w.and(w2));
|
- |
|
466 |
if (rowValsResult.size() == 0) {
|
- |
|
467 |
SQLInsert insert = new SQLInsert();
|
- |
|
468 |
insert.add(stockTable.getField("ID_ARTICLE"), article.getID());
|
- |
|
469 |
insert.add(stockTable.getField("ID_DEPOT_STOCK"), depot.getID());
|
- |
|
470 |
insert.add(stockTable.getField("QTE_TH"), 0F);
|
- |
|
471 |
insert.add(stockTable.getField("QTE_REEL"), 0F);
|
- |
|
472 |
insert.add(stockTable.getField("QTE_RECEPT_ATTENTE"), 0F);
|
- |
|
473 |
insert.add(stockTable.getField("QTE_LIV_ATTENTE"), 0F);
|
- |
|
474 |
return insert;
|
- |
|
475 |
}
|
- |
|
476 |
return null;
|
- |
|
477 |
|
- |
|
478 |
}
|
- |
|
479 |
|
- |
|
480 |
private SQLRowValues createEtat(SQLTable tableEtat, int depotID) {
|
- |
|
481 |
SQLRowValues rowVals = new SQLRowValues(tableEtat);
|
- |
|
482 |
rowVals.put("DATE", new Date());
|
- |
|
483 |
rowVals.put("INVENTAIRE", Boolean.TRUE);
|
- |
|
484 |
rowVals.put("ID_DEPOT_STOCK", depotID);
|
- |
|
485 |
return rowVals;
|
347 |
}
|
486 |
}
|
348 |
|
487 |
|
349 |
private void checkMinPrice(SQLRow rowValsSuplierLastValid, SQLRow lastValidRow) {
|
488 |
private void checkMinPrice(SQLRow rowValsSuplierLastValid, SQLRow lastValidRow) {
|
350 |
boolean update = false;
|
489 |
boolean update = false;
|
351 |
final ProductHelper helper = new ProductHelper(rowValsSuplierLastValid.getTable().getDBRoot());
|
490 |
final ProductHelper helper = new ProductHelper(rowValsSuplierLastValid.getTable().getDBRoot());
|
Line 419... |
Line 558... |
419 |
ProductComponent comp = new ProductComponent(rowVals, new BigDecimal(qty), null, null);
|
558 |
ProductComponent comp = new ProductComponent(rowVals, new BigDecimal(qty), null, null);
|
420 |
return comp.getPRC(d);
|
559 |
return comp.getPRC(d);
|
421 |
// return result;
|
560 |
// return result;
|
422 |
}
|
561 |
}
|
423 |
|
562 |
|
424 |
private final Map<String, Tuple2<SQLRowValues, SQLRowValues>> mapArticle = new HashMap<String, Tuple2<SQLRowValues, SQLRowValues>>();
|
563 |
private final Map<String, InventaireProductLine> mapDepotArticle = new HashMap();
|
425 |
private final Map<String, Tuple2<SQLRowValues, SQLRowValues>> mapArticleVirtuel = new HashMap<String, Tuple2<SQLRowValues, SQLRowValues>>();
|
564 |
private final Map<String, InventaireProductLine> mapDepotArticleVirtuel = new HashMap();
|
426 |
private final Map<Tuple3<String, String, String>, Tuple2<SQLRowValues, SQLRowValues>> mapDeclArticle = new HashMap<Tuple3<String, String, String>, Tuple2<SQLRowValues, SQLRowValues>>();
|
565 |
private final Map<Tuple3<String, String, String>, InventaireProductLine> mapDepotDeclArticle = new HashMap();
|
427 |
|
566 |
|
428 |
private void fillArticles() throws SQLException {
|
567 |
private void fillArticles() throws SQLException {
|
429 |
final SQLTable table = Configuration.getInstance().getRoot().findTable("ARTICLE");
|
568 |
final SQLTable table = Configuration.getInstance().getRoot().findTable("ARTICLE");
|
- |
|
569 |
|
430 |
SQLRowValues graph = new SQLRowValues(table);
|
570 |
SQLRowValues graph = new SQLRowValues(table);
|
431 |
graph.put("ID", null);
|
571 |
graph.put("ID", null);
|
432 |
graph.put("CODE", null);
|
572 |
graph.put("CODE", null);
|
433 |
graph.put("NOM", null);
|
573 |
graph.put("NOM", null);
|
434 |
graph.put("VIRTUEL", null);
|
574 |
graph.put("VIRTUEL", null);
|
435 |
graph.putRowValues("ID_ARTICLE_DECLINAISON_COULEUR").putNulls("ID", "NOM");
|
575 |
graph.putRowValues("ID_ARTICLE_DECLINAISON_COULEUR").putNulls("ID", "NOM");
|
436 |
graph.putRowValues("ID_ARTICLE_DECLINAISON_TAILLE").putNulls("ID", "NOM");
|
576 |
graph.putRowValues("ID_ARTICLE_DECLINAISON_TAILLE").putNulls("ID", "NOM");
|
437 |
|
577 |
|
438 |
final SQLTable foreignTableStock = table.getForeignTable("ID_STOCK");
|
578 |
final SQLTable foreignTableStock = table.getForeignTable("ID_STOCK");
|
439 |
SQLRowValues graphStock = new SQLRowValues(foreignTableStock);
|
579 |
SQLRowValues graphStock = new SQLRowValues(foreignTableStock);
|
440 |
graphStock.putNulls("ID_DEPOT_STOCK", "ID", "QTE_REEL", "QTE_TH", "QTE_LIV_ATTENTE", "QTE_RECEPT_ATTENTE");
|
580 |
graphStock.putNulls("ID", "QTE_REEL", "QTE_TH", "QTE_LIV_ATTENTE", "QTE_RECEPT_ATTENTE").putRowValues("ID_DEPOT_STOCK").putNulls("NOM");
|
441 |
graphStock.put("ID_ARTICLE", graph);
|
581 |
graphStock.put("ID_ARTICLE", graph);
|
442 |
|
582 |
|
443 |
SQLRowValues graphStockArt = new SQLRowValues(foreignTableStock);
|
583 |
SQLRowValues graphStockArt = new SQLRowValues(foreignTableStock);
|
444 |
graphStockArt.putNulls("ID_DEPOT_STOCK", "ID", "QTE_REEL", "QTE_TH", "QTE_LIV_ATTENTE", "QTE_RECEPT_ATTENTE");
|
584 |
graphStockArt.putNulls("ID", "QTE_REEL", "QTE_TH", "QTE_LIV_ATTENTE", "QTE_RECEPT_ATTENTE").putRowValues("ID_DEPOT_STOCK").putNulls("NOM");
|
445 |
graph.put("ID_STOCK", graphStockArt);
|
585 |
graph.put("ID_STOCK", graphStockArt);
|
446 |
|
586 |
|
447 |
final SQLTable tableArtElt = table.getTable("ARTICLE_ELEMENT");
|
587 |
final SQLTable tableArtElt = table.getTable("ARTICLE_ELEMENT");
|
448 |
SQLRowValues artElt = new SQLRowValues(tableArtElt);
|
588 |
SQLRowValues artElt = new SQLRowValues(tableArtElt);
|
449 |
artElt.put("ID", null);
|
589 |
artElt.put("ID", null);
|
Line 467... |
Line 607... |
467 |
|
607 |
|
468 |
Calendar c = Calendar.getInstance();
|
608 |
Calendar c = Calendar.getInstance();
|
469 |
// c.set(Calendar.DAY_OF_MONTH, 1);
|
609 |
// c.set(Calendar.DAY_OF_MONTH, 1);
|
470 |
c.add(Calendar.MONTH, -2);
|
610 |
c.add(Calendar.MONTH, -2);
|
471 |
c.set(Calendar.DAY_OF_MONTH, 31);
|
611 |
c.set(Calendar.DAY_OF_MONTH, 31);
|
472 |
Date dEndYear = c.getTime();
|
- |
|
473 |
|
612 |
|
474 |
for (SQLRowValues sqlRowValues : results) {
|
613 |
for (SQLRowValues sqlRowValues : results) {
|
475 |
final String code = sqlRowValues.getString("CODE");
|
614 |
final String code = sqlRowValues.getString("CODE");
|
476 |
|
615 |
|
477 |
Collection<SQLRowValues> stocks = sqlRowValues.getReferentRows(foreignTableStock);
|
- |
|
478 |
|
- |
|
479 |
SQLRowValues rowValsStock = null;
|
- |
|
480 |
for (SQLRowValues sqlRowValues2 : stocks) {
|
- |
|
481 |
if (sqlRowValues2.getForeignID("ID_DEPOT_STOCK") == depot.getID()) {
|
- |
|
482 |
rowValsStock = sqlRowValues2;
|
- |
|
483 |
}
|
- |
|
484 |
}
|
- |
|
485 |
// if (rowValsStock == null) {
|
- |
|
486 |
// rowValsStock = ProductComponent.findOrCreateStock(sqlRowValues, depot).asRowValues();
|
- |
|
487 |
// }
|
- |
|
488 |
|
- |
|
489 |
if (sqlRowValues.getBoolean("VIRTUEL")) {
|
616 |
if (sqlRowValues.getBoolean("VIRTUEL")) {
|
490 |
mapArticleVirtuel.put(sqlRowValues.getString("CODE"), Tuple2.create(sqlRowValues, rowValsStock));
|
617 |
this.mapDepotArticleVirtuel.put(sqlRowValues.getString("CODE"), new InventaireProductLine(sqlRowValues));
|
491 |
}
|
618 |
}
|
492 |
|
619 |
|
493 |
final SQLRowAccessor couleur = sqlRowValues.getObject("ID_ARTICLE_DECLINAISON_COULEUR") == null ? null : sqlRowValues.getNonEmptyForeign("ID_ARTICLE_DECLINAISON_COULEUR");
|
620 |
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");
|
621 |
final SQLRowAccessor taille = sqlRowValues.getObject("ID_ARTICLE_DECLINAISON_TAILLE") == null ? null : sqlRowValues.getNonEmptyForeign("ID_ARTICLE_DECLINAISON_TAILLE");
|
495 |
if (couleur == null && taille == null) {
|
622 |
if (couleur == null && taille == null) {
|
496 |
mapArticle.put(sqlRowValues.getString("CODE"), Tuple2.create(sqlRowValues, rowValsStock));
|
623 |
this.mapDepotArticle.put(sqlRowValues.getString("CODE"), new InventaireProductLine(sqlRowValues));
|
497 |
} else if (couleur == null) {
|
624 |
} else if (couleur == null) {
|
498 |
mapDeclArticle.put(Tuple3.create(sqlRowValues.getString("CODE"), null, taille.getString("NOM")), Tuple2.create(sqlRowValues, rowValsStock));
|
625 |
this.mapDepotDeclArticle.put(Tuple3.create(sqlRowValues.getString("CODE"), null, taille.getString("NOM")), new InventaireProductLine(sqlRowValues));
|
499 |
} else if (taille == null) {
|
626 |
} else if (taille == null) {
|
500 |
mapDeclArticle.put(Tuple3.create(sqlRowValues.getString("CODE"), couleur.getString("NOM"), null), Tuple2.create(sqlRowValues, rowValsStock));
|
627 |
this.mapDepotDeclArticle.put(Tuple3.create(sqlRowValues.getString("CODE"), couleur.getString("NOM"), null), new InventaireProductLine(sqlRowValues));
|
501 |
} else {
|
628 |
} else {
|
502 |
mapDeclArticle.put(Tuple3.create(sqlRowValues.getString("CODE"), couleur.getString("NOM"), taille.getString("NOM")), Tuple2.create(sqlRowValues, rowValsStock));
|
629 |
this.mapDepotDeclArticle.put(Tuple3.create(sqlRowValues.getString("CODE"), couleur.getString("NOM"), taille.getString("NOM")), new InventaireProductLine(sqlRowValues));
|
503 |
}
|
630 |
}
|
504 |
|
631 |
|
505 |
final Set<SQLRowValues> referentRows = sqlRowValues.getReferentRows(tableArtElt.getField("ID_ARTICLE_PARENT"));
|
632 |
final Set<SQLRowValues> referentRows = sqlRowValues.getReferentRows(tableArtElt.getField("ID_ARTICLE_PARENT"));
|
506 |
if (referentRows.size() == 0) {
|
633 |
if (referentRows.size() == 0) {
|
507 |
// if (!sqlRowValues.isForeignEmpty("ID_STOCK")) {
|
634 |
// if (!sqlRowValues.isForeignEmpty("ID_STOCK")) {
|
Line 526... |
Line 653... |
526 |
// }
|
653 |
// }
|
527 |
} else {
|
654 |
} else {
|
528 |
boolean contains = false;
|
655 |
boolean contains = false;
|
529 |
for (SQLRowValues sqlRowValues2 : referentRows) {
|
656 |
for (SQLRowValues sqlRowValues2 : referentRows) {
|
530 |
if (sqlRowValues2.getForeign("ID_ARTICLE") != null && !sqlRowValues2.isForeignEmpty("ID_ARTICLE") && sqlRowValues2.getForeign("ID_ARTICLE").getString("CODE") != null) {
|
657 |
if (sqlRowValues2.getForeign("ID_ARTICLE") != null && !sqlRowValues2.isForeignEmpty("ID_ARTICLE") && sqlRowValues2.getForeign("ID_ARTICLE").getString("CODE") != null) {
|
531 |
if (codeKits.contains(sqlRowValues2.getForeign("ID_ARTICLE").getString("CODE"))) {
|
658 |
if (this.codeKits.contains(sqlRowValues2.getForeign("ID_ARTICLE").getString("CODE"))) {
|
532 |
contains = true;
|
659 |
contains = true;
|
533 |
break;
|
660 |
break;
|
534 |
}
|
661 |
}
|
535 |
}
|
662 |
}
|
536 |
}
|
663 |
}
|
537 |
if (!contains) {
|
664 |
if (!contains) {
|
538 |
codeKits.add(0, code);
|
665 |
this.codeKits.add(0, code);
|
539 |
} else {
|
666 |
} else {
|
540 |
codeKits.add(code);
|
667 |
this.codeKits.add(code);
|
541 |
}
|
668 |
}
|
542 |
kits.put(code, sqlRowValues);
|
669 |
this.kits.put(code, sqlRowValues);
|
543 |
// if (sqlRowValues.isForeignEmpty("ID_STOCK")) {
|
670 |
// if (sqlRowValues.isForeignEmpty("ID_STOCK")) {
|
544 |
// sqlRowValues.putRowValues("ID_STOCK").commit();
|
671 |
// sqlRowValues.putRowValues("ID_STOCK").commit();
|
545 |
// }
|
672 |
// }
|
546 |
}
|
673 |
}
|
- |
|
674 |
|
- |
|
675 |
}
|
- |
|
676 |
fillKitChildren();
|
- |
|
677 |
}
|
- |
|
678 |
|
- |
|
679 |
private void fillKitChildren() {
|
- |
|
680 |
final SQLTable table = Configuration.getInstance().getRoot().findTable("ARTICLE");
|
- |
|
681 |
|
- |
|
682 |
SQLRowValues graph = new SQLRowValues(table);
|
- |
|
683 |
graph.put("ID", null);
|
- |
|
684 |
graph.put("CODE", null);
|
- |
|
685 |
graph.put("NOM", null);
|
- |
|
686 |
graph.put("VIRTUEL", null);
|
- |
|
687 |
graph.putRowValues("ID_ARTICLE_DECLINAISON_COULEUR").putNulls("ID", "NOM");
|
- |
|
688 |
graph.putRowValues("ID_ARTICLE_DECLINAISON_TAILLE").putNulls("ID", "NOM");
|
- |
|
689 |
|
- |
|
690 |
final SQLTable foreignTableStock = table.getForeignTable("ID_STOCK");
|
- |
|
691 |
SQLRowValues graphStock = new SQLRowValues(foreignTableStock);
|
- |
|
692 |
graphStock.putNulls("ID", "QTE_REEL", "QTE_TH", "QTE_LIV_ATTENTE", "QTE_RECEPT_ATTENTE").putRowValues("ID_DEPOT_STOCK").putNulls("NOM");
|
- |
|
693 |
graphStock.put("ID_ARTICLE", graph);
|
- |
|
694 |
|
- |
|
695 |
final SQLTable tableArtElt = table.getTable("ARTICLE_ELEMENT");
|
- |
|
696 |
SQLRowValues artElt = new SQLRowValues(tableArtElt);
|
- |
|
697 |
artElt.put("ID", null);
|
- |
|
698 |
artElt.put("QTE", null);
|
- |
|
699 |
artElt.put("QTE_UNITAIRE", null);
|
- |
|
700 |
artElt.put("ID_ARTICLE", graph);
|
- |
|
701 |
|
- |
|
702 |
SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(artElt);
|
- |
|
703 |
fetcher.appendSelTransf(new ITransformer<SQLSelect, SQLSelect>() {
|
- |
|
704 |
|
- |
|
705 |
@Override
|
- |
|
706 |
public SQLSelect transformChecked(SQLSelect input) {
|
- |
|
707 |
input.setWhere(Where.inValues(tableArtElt.getField("ID_ARTICLE_PARENT"), SQLRow.getIDs(InventaireFromEtatStockImporter.this.kits.values())));
|
- |
|
708 |
return input;
|
- |
|
709 |
}
|
- |
|
710 |
});
|
- |
|
711 |
List<SQLRowValues> results = fetcher.fetch();
|
- |
|
712 |
for (SQLRowValues sqlRowValues : results) {
|
- |
|
713 |
final SQLRowAccessor foreign = sqlRowValues.getNonEmptyForeign("ID_ARTICLE");
|
- |
|
714 |
if (foreign != null) {
|
- |
|
715 |
this.kitsChildren.put(foreign.getID(), new InventaireProductLine(foreign.asRowValues()));
|
- |
|
716 |
}
|
547 |
}
|
717 |
}
|
548 |
}
|
718 |
}
|
549 |
|
719 |
|
550 |
private Tuple2<SQLRowValues, SQLRowValues> findArticle(String code, String couleur, String taille) throws SQLException {
|
720 |
private InventaireProductLine findArticle(String code, String couleur, String taille) throws SQLException {
|
551 |
if (!mapCouleur.containsKey(couleur)) {
|
721 |
if (!this.mapCouleur.containsKey(couleur)) {
|
552 |
SQLRowValues rowVals = new SQLRowValues(root.getTable("ARTICLE_DECLINAISON_COULEUR"));
|
722 |
SQLRowValues rowVals = new SQLRowValues(this.root.getTable("ARTICLE_DECLINAISON_COULEUR"));
|
553 |
rowVals.put("NOM", couleur);
|
723 |
rowVals.put("NOM", couleur);
|
554 |
mapCouleur.put(couleur, rowVals.commit().getID());
|
724 |
this.mapCouleur.put(couleur, rowVals.commit().getID());
|
555 |
}
|
725 |
}
|
556 |
if (!mapTaille.containsKey(taille)) {
|
726 |
if (!this.mapTaille.containsKey(taille)) {
|
557 |
SQLRowValues rowVals = new SQLRowValues(root.getTable("ARTICLE_DECLINAISON_TAILLE"));
|
727 |
SQLRowValues rowVals = new SQLRowValues(this.root.getTable("ARTICLE_DECLINAISON_TAILLE"));
|
558 |
rowVals.put("NOM", taille);
|
728 |
rowVals.put("NOM", taille);
|
559 |
mapTaille.put(taille, rowVals.commit().getID());
|
729 |
this.mapTaille.put(taille, rowVals.commit().getID());
|
560 |
}
|
730 |
}
|
561 |
|
731 |
|
562 |
Tuple2<SQLRowValues, SQLRowValues> t;
|
732 |
InventaireProductLine t;
|
563 |
if ((couleur == null || couleur.trim().length() == 0) && (taille == null || taille.trim().length() == 0)) {
|
733 |
if ((couleur == null || couleur.trim().length() == 0) && (taille == null || taille.trim().length() == 0)) {
|
564 |
|
- |
|
565 |
t = mapArticle.get(code);
|
734 |
t = this.mapDepotArticle.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) {
|
735 |
} else if (couleur == null || couleur.trim().length() == 0) {
|
571 |
t = mapDeclArticle.get(Tuple3.create(code, null, taille.trim()));
|
736 |
t = this.mapDepotDeclArticle.get(Tuple3.create(code, null, taille.trim()));
|
- |
|
737 |
if (t == null) {
|
- |
|
738 |
t = this.mapDepotDeclArticle.get(Tuple3.create(code, "", taille.trim()));
|
- |
|
739 |
}
|
572 |
if (t == null) {
|
740 |
if (t == null) {
|
573 |
SQLRowValues artRow = cloneFromArticle(mapArticleVirtuel.get(code).get0(), null, mapTaille.get(taille.trim())).asRowValues();
|
741 |
System.err.println("\tCREATE ARTICLE " + code + " taille : " + taille);
|
574 |
final SQLRowValues stockRow = ProductComponent.findOrCreateStock(artRow, depot).asRowValues();
|
742 |
SQLRowValues rARtVirt = this.mapDepotArticleVirtuel.get(code).getRowValsArt();
|
575 |
t = Tuple2.create(artRow, stockRow);
|
- |
|
576 |
mapDeclArticle.put(Tuple3.create(code, null, taille.trim()), t);
|
743 |
SQLRowValues artRow = cloneFromArticle(rARtVirt, null, this.mapTaille.get(taille.trim())).asRowValues();
|
577 |
} else if (t.get1() == null) {
|
744 |
t = new InventaireProductLine(artRow);
|
578 |
t = Tuple2.create(t.get0(), ProductComponent.findOrCreateStock(t.get0(), depot).asRowValues());
|
- |
|
579 |
mapDeclArticle.put(Tuple3.create(code, null, taille.trim()), t);
|
745 |
this.mapDepotDeclArticle.put(Tuple3.create(code, null, taille.trim()), t);
|
580 |
}
|
746 |
}
|
581 |
} else if (taille == null || taille.trim().length() == 0) {
|
747 |
} else if (taille == null || taille.trim().length() == 0) {
|
582 |
t = mapDeclArticle.get(Tuple3.create(code, couleur.trim(), null));
|
748 |
t = this.mapDepotDeclArticle.get(Tuple3.create(code, couleur.trim(), null));
|
- |
|
749 |
if (t == null) {
|
- |
|
750 |
t = this.mapDepotDeclArticle.get(Tuple3.create(code, couleur.trim(), ""));
|
- |
|
751 |
}
|
583 |
if (t == null) {
|
752 |
if (t == null) {
|
584 |
SQLRowValues artRow = cloneFromArticle(mapArticleVirtuel.get(code).get0(), mapCouleur.get(couleur.trim()), null).asRowValues();
|
753 |
System.err.println("\tCREATE ARTICLE " + code + " couleur : " + couleur);
|
585 |
final SQLRowValues stockRow = ProductComponent.findOrCreateStock(artRow, depot).asRowValues();
|
754 |
SQLRowValues rARtVirt = this.mapDepotArticleVirtuel.get(code).getRowValsArt();
|
586 |
t = Tuple2.create(artRow, stockRow);
|
- |
|
587 |
mapDeclArticle.put(Tuple3.create(code, couleur.trim(), null), t);
|
755 |
SQLRowValues artRow = cloneFromArticle(rARtVirt, this.mapCouleur.get(couleur.trim()), null).asRowValues();
|
588 |
} else if (t.get1() == null) {
|
756 |
t = new InventaireProductLine(artRow);
|
589 |
t = Tuple2.create(t.get0(), ProductComponent.findOrCreateStock(t.get0(), depot).asRowValues());
|
- |
|
590 |
mapDeclArticle.put(Tuple3.create(code, couleur.trim(), null), t);
|
757 |
this.mapDepotDeclArticle.put(Tuple3.create(code, couleur.trim(), null), t);
|
591 |
}
|
758 |
}
|
592 |
} else {
|
759 |
} else {
|
593 |
t = mapDeclArticle.get(Tuple3.create(code, couleur.trim(), taille.trim()));
|
760 |
t = this.mapDepotDeclArticle.get(Tuple3.create(code, couleur.trim(), taille.trim()));
|
594 |
if (t == null) {
|
761 |
if (t == null) {
|
595 |
if (mapArticle.get(code) != null) {
|
762 |
if (this.mapDepotArticleVirtuel.get(code) != null) {
|
596 |
SQLRowValues artRow = cloneFromArticle(mapArticleVirtuel.get(code).get0(), mapCouleur.get(couleur.trim()), mapTaille.get(taille.trim())).asRowValues();
|
763 |
System.err.println("\tCREATE ARTICLE " + code + " taille : " + taille + " couleur : " + couleur);
|
597 |
final SQLRowValues stockRow = ProductComponent.findOrCreateStock(artRow, depot).asRowValues();
|
764 |
SQLRowValues rARtVirt = this.mapDepotArticleVirtuel.get(code).getRowValsArt();
|
- |
|
765 |
SQLRowValues artRow = cloneFromArticle(rARtVirt, this.mapCouleur.get(couleur.trim()), this.mapTaille.get(taille.trim())).asRowValues();
|
598 |
t = Tuple2.create(artRow, stockRow);
|
766 |
t = new InventaireProductLine(artRow);
|
599 |
mapDeclArticle.put(Tuple3.create(code, couleur.trim(), taille.trim()), t);
|
767 |
this.mapDepotDeclArticle.put(Tuple3.create(code, couleur.trim(), taille.trim()), t);
|
600 |
}
|
768 |
}
|
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 |
}
|
769 |
}
|
605 |
}
|
770 |
}
|
606 |
return t;
|
771 |
return t;
|
607 |
}
|
772 |
}
|
608 |
|
773 |
|
609 |
public SQLRow cloneFromArticle(SQLRowAccessor rArt, Integer idCouleur, Integer idTaille) throws SQLException {
|
774 |
public SQLRow cloneFromArticle(SQLRowAccessor rArt, Integer idCouleur, Integer idTaille) throws SQLException {
|
610 |
if (rArt == null) {
|
775 |
if (rArt == null) {
|
611 |
return null;
|
776 |
return null;
|
612 |
}
|
777 |
}
|
613 |
SQLRowValues copy = artElt.createCopy(rArt.getID());
|
778 |
SQLRowValues copy = this.artElt.createCopy(rArt.getID());
|
614 |
copy.put("VIRTUEL", Boolean.FALSE);
|
779 |
copy.put("VIRTUEL", Boolean.FALSE);
|
615 |
copy.put("ID_ARTICLE_VIRTUEL_PERE", rArt.getID());
|
780 |
copy.put("ID_ARTICLE_VIRTUEL_PERE", rArt.getID());
|
616 |
if (idCouleur != null) {
|
781 |
if (idCouleur != null) {
|
617 |
copy.put("ID_ARTICLE_DECLINAISON_COULEUR", idCouleur);
|
782 |
copy.put("ID_ARTICLE_DECLINAISON_COULEUR", idCouleur);
|
618 |
}
|
783 |
}
|
Line 638... |
Line 803... |
638 |
}
|
803 |
}
|
639 |
}
|
804 |
}
|
640 |
|
805 |
|
641 |
return columnName;
|
806 |
return columnName;
|
642 |
}
|
807 |
}
|
- |
|
808 |
|
- |
|
809 |
class InventaireProductLine {
|
- |
|
810 |
private final SQLRowValues rowValsArt;
|
- |
|
811 |
private final Map<String, SQLRowValues> stockMap = new HashMap<>();
|
- |
|
812 |
|
- |
|
813 |
public InventaireProductLine(SQLRowValues rowValsArt) {
|
- |
|
814 |
this.rowValsArt = rowValsArt;
|
- |
|
815 |
|
- |
|
816 |
Collection<SQLRowValues> stocks = this.rowValsArt.getReferentRows(this.rowValsArt.getTable().getTable("STOCK"));
|
- |
|
817 |
|
- |
|
818 |
for (SQLRowValues rowValsStock : stocks) {
|
- |
|
819 |
this.stockMap.put(rowValsStock.getForeign("ID_DEPOT_STOCK").getString("NOM"), rowValsStock);
|
- |
|
820 |
}
|
- |
|
821 |
}
|
- |
|
822 |
|
- |
|
823 |
public SQLRowValues getOrCreateStockRowValues(SQLRowAccessor depot) {
|
- |
|
824 |
final String depotName = depot.getString("NOM");
|
- |
|
825 |
if (!this.stockMap.containsKey(depotName)) {
|
- |
|
826 |
this.stockMap.put(depotName, ProductComponent.findOrCreateStock(this.rowValsArt, depot).asRowValues());
|
- |
|
827 |
}
|
- |
|
828 |
return this.stockMap.get(depotName);
|
- |
|
829 |
}
|
- |
|
830 |
|
- |
|
831 |
public SQLRowValues getStockRowValues(SQLRowAccessor depot) {
|
- |
|
832 |
final String depotName = depot.getString("NOM");
|
- |
|
833 |
if (!this.stockMap.containsKey(depotName)) {
|
- |
|
834 |
return null;
|
- |
|
835 |
}
|
- |
|
836 |
return this.stockMap.get(depotName);
|
- |
|
837 |
}
|
- |
|
838 |
|
- |
|
839 |
public SQLRowValues getRowValsArt() {
|
- |
|
840 |
return this.rowValsArt;
|
- |
|
841 |
}
|
- |
|
842 |
|
- |
|
843 |
}
|
643 |
}
|
844 |
}
|