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 14... |
Line 14... |
14 |
package org.openconcerto.erp.core.sales.product.element;
|
14 |
package org.openconcerto.erp.core.sales.product.element;
|
15 |
|
15 |
|
16 |
import org.openconcerto.erp.config.ComptaPropsConfiguration;
|
16 |
import org.openconcerto.erp.config.ComptaPropsConfiguration;
|
17 |
import org.openconcerto.erp.config.update.Updater_1_5;
|
17 |
import org.openconcerto.erp.config.update.Updater_1_5;
|
18 |
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
|
18 |
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
|
- |
|
19 |
import org.openconcerto.erp.core.common.element.NumerotationAutoSQLElement;
|
- |
|
20 |
import org.openconcerto.erp.core.common.ui.NumberCellRenderer;
|
19 |
import org.openconcerto.erp.core.edm.AttachmentAction;
|
21 |
import org.openconcerto.erp.core.edm.AttachmentAction;
|
20 |
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
|
22 |
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
|
21 |
import org.openconcerto.erp.core.reports.history.ui.HistoriqueArticleFrame;
|
23 |
import org.openconcerto.erp.core.reports.history.ui.HistoriqueArticleFrame;
|
- |
|
24 |
import org.openconcerto.erp.core.sales.product.action.InitializeStockPanel;
|
22 |
import org.openconcerto.erp.core.sales.product.action.InventairePanel;
|
25 |
import org.openconcerto.erp.core.sales.product.action.InventairePanel;
|
23 |
import org.openconcerto.erp.core.sales.product.component.ReferenceArticleSQLComponent;
|
26 |
import org.openconcerto.erp.core.sales.product.component.ReferenceArticleSQLComponent;
|
- |
|
27 |
import org.openconcerto.erp.core.sales.product.model.ProductComponent;
|
- |
|
28 |
import org.openconcerto.erp.core.supplychain.stock.action.ListeDesMouvementsStockAction;
|
- |
|
29 |
import org.openconcerto.erp.core.supplychain.stock.element.ComposedItemStockUpdater;
|
24 |
import org.openconcerto.erp.core.supplychain.stock.element.DepotStockSQLElement;
|
30 |
import org.openconcerto.erp.core.supplychain.stock.element.DepotStockSQLElement;
|
- |
|
31 |
import org.openconcerto.erp.core.supplychain.stock.element.StockItem;
|
- |
|
32 |
import org.openconcerto.erp.core.supplychain.stock.element.StockItem.TypeStockMouvement;
|
25 |
import org.openconcerto.erp.generationDoc.gestcomm.FicheArticleXmlSheet;
|
33 |
import org.openconcerto.erp.generationDoc.gestcomm.FicheArticleXmlSheet;
|
26 |
import org.openconcerto.erp.model.MouseSheetXmlListeListener;
|
34 |
import org.openconcerto.erp.model.MouseSheetXmlListeListener;
|
27 |
import org.openconcerto.erp.preferences.DefaultNXProps;
|
35 |
import org.openconcerto.erp.preferences.DefaultNXProps;
|
28 |
import org.openconcerto.erp.preferences.GestionArticleGlobalPreferencePanel;
|
36 |
import org.openconcerto.erp.preferences.GestionArticleGlobalPreferencePanel;
|
29 |
import org.openconcerto.sql.Configuration;
|
37 |
import org.openconcerto.sql.Configuration;
|
30 |
import org.openconcerto.sql.element.SQLComponent;
|
38 |
import org.openconcerto.sql.element.SQLComponent;
|
31 |
import org.openconcerto.sql.element.SQLElement;
|
39 |
import org.openconcerto.sql.element.SQLElement;
|
- |
|
40 |
import org.openconcerto.sql.model.ConnectionHandlerNoSetup;
|
- |
|
41 |
import org.openconcerto.sql.model.DBRoot;
|
- |
|
42 |
import org.openconcerto.sql.model.DBSystemRoot;
|
32 |
import org.openconcerto.sql.model.FieldPath;
|
43 |
import org.openconcerto.sql.model.FieldPath;
|
- |
|
44 |
import org.openconcerto.sql.model.SQLDataSource;
|
33 |
import org.openconcerto.sql.model.SQLRow;
|
45 |
import org.openconcerto.sql.model.SQLRow;
|
34 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
46 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
35 |
import org.openconcerto.sql.model.SQLRowListRSH;
|
47 |
import org.openconcerto.sql.model.SQLRowListRSH;
|
36 |
import org.openconcerto.sql.model.SQLRowValues;
|
48 |
import org.openconcerto.sql.model.SQLRowValues;
|
37 |
import org.openconcerto.sql.model.SQLSelect;
|
49 |
import org.openconcerto.sql.model.SQLSelect;
|
38 |
import org.openconcerto.sql.model.SQLTable;
|
50 |
import org.openconcerto.sql.model.SQLTable;
|
39 |
import org.openconcerto.sql.model.Where;
|
51 |
import org.openconcerto.sql.model.Where;
|
40 |
import org.openconcerto.sql.model.graph.Path;
|
52 |
import org.openconcerto.sql.model.graph.Path;
|
41 |
import org.openconcerto.sql.preferences.SQLPreferences;
|
53 |
import org.openconcerto.sql.preferences.SQLPreferences;
|
42 |
import org.openconcerto.sql.request.ComboSQLRequest;
|
54 |
import org.openconcerto.sql.request.ComboSQLRequest;
|
- |
|
55 |
import org.openconcerto.sql.request.ComboSQLRequest.KeepMode;
|
- |
|
56 |
import org.openconcerto.sql.request.ListSQLRequest;
|
- |
|
57 |
import org.openconcerto.sql.users.rights.UserRightsManager;
|
- |
|
58 |
import org.openconcerto.sql.utils.SQLUtils;
|
43 |
import org.openconcerto.sql.view.EditFrame;
|
59 |
import org.openconcerto.sql.view.EditFrame;
|
44 |
import org.openconcerto.sql.view.EditPanel.EditMode;
|
60 |
import org.openconcerto.sql.view.EditPanel.EditMode;
|
- |
|
61 |
import org.openconcerto.sql.view.ListeAddPanel;
|
45 |
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn;
|
62 |
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn;
|
46 |
import org.openconcerto.sql.view.list.IListe;
|
63 |
import org.openconcerto.sql.view.list.IListe;
|
47 |
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
|
64 |
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
|
- |
|
65 |
import org.openconcerto.sql.view.list.RowAction;
|
48 |
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
|
66 |
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
|
49 |
import org.openconcerto.sql.view.list.SQLTableModelColumn;
|
67 |
import org.openconcerto.sql.view.list.SQLTableModelColumn;
|
50 |
import org.openconcerto.sql.view.list.SQLTableModelSource;
|
68 |
import org.openconcerto.sql.view.list.SQLTableModelSource;
|
- |
|
69 |
import org.openconcerto.sql.view.list.SQLTableModelSourceOnline;
|
- |
|
70 |
import org.openconcerto.sql.view.list.action.ListEvent;
|
- |
|
71 |
import org.openconcerto.ui.DefaultGridBagConstraints;
|
51 |
import org.openconcerto.ui.FrameUtil;
|
72 |
import org.openconcerto.ui.FrameUtil;
|
52 |
import org.openconcerto.ui.PanelFrame;
|
73 |
import org.openconcerto.ui.PanelFrame;
|
53 |
import org.openconcerto.utils.CollectionUtils;
|
74 |
import org.openconcerto.utils.CollectionUtils;
|
54 |
import org.openconcerto.utils.DecimalUtils;
|
75 |
import org.openconcerto.utils.DecimalUtils;
|
- |
|
76 |
import org.openconcerto.utils.ExceptionHandler;
|
55 |
import org.openconcerto.utils.ListMap;
|
77 |
import org.openconcerto.utils.ListMap;
|
- |
|
78 |
import org.openconcerto.utils.Tuple2;
|
56 |
|
79 |
|
- |
|
80 |
import java.awt.GridBagConstraints;
|
- |
|
81 |
import java.awt.GridBagLayout;
|
57 |
import java.awt.event.ActionEvent;
|
82 |
import java.awt.event.ActionEvent;
|
58 |
import java.math.BigDecimal;
|
83 |
import java.math.BigDecimal;
|
- |
|
84 |
import java.math.RoundingMode;
|
59 |
import java.sql.SQLException;
|
85 |
import java.sql.SQLException;
|
- |
|
86 |
import java.text.SimpleDateFormat;
|
60 |
import java.util.ArrayList;
|
87 |
import java.util.ArrayList;
|
61 |
import java.util.Collection;
|
88 |
import java.util.Collection;
|
- |
|
89 |
import java.util.Date;
|
- |
|
90 |
import java.util.HashSet;
|
62 |
import java.util.List;
|
91 |
import java.util.List;
|
63 |
import java.util.Set;
|
92 |
import java.util.Set;
|
64 |
|
93 |
|
65 |
import javax.swing.AbstractAction;
|
94 |
import javax.swing.AbstractAction;
|
- |
|
95 |
import javax.swing.JFrame;
|
- |
|
96 |
import javax.swing.JOptionPane;
|
- |
|
97 |
import javax.swing.JPanel;
|
- |
|
98 |
import javax.swing.JTabbedPane;
|
66 |
|
99 |
|
- |
|
100 |
import org.apache.commons.dbutils.ResultSetHandler;
|
67 |
import org.apache.commons.dbutils.handlers.ArrayListHandler;
|
101 |
import org.apache.commons.dbutils.handlers.ArrayListHandler;
|
68 |
|
102 |
|
69 |
public class ReferenceArticleSQLElement extends ComptaSQLConfElement {
|
103 |
public class ReferenceArticleSQLElement extends ComptaSQLConfElement {
|
70 |
public static final int AU_METRE_LONGUEUR = 2;
|
104 |
public static final int AU_METRE_LONGUEUR = 2;
|
71 |
public static final int AU_METRE_CARRE = 3;
|
105 |
public static final int AU_METRE_CARRE = 3;
|
Line 78... |
Line 112... |
78 |
|
112 |
|
79 |
public static final String[] CONDITIONS = new String[] { "CFR", "CIF", "CPT", "DAT", "DDP", "DDU", "EXW", "FCA", "FOB" };
|
113 |
public static final String[] CONDITIONS = new String[] { "CFR", "CIF", "CPT", "DAT", "DDP", "DDU", "EXW", "FCA", "FOB" };
|
80 |
|
114 |
|
81 |
public ReferenceArticleSQLElement() {
|
115 |
public ReferenceArticleSQLElement() {
|
82 |
super("ARTICLE", "un article", "articles");
|
116 |
super("ARTICLE", "un article", "articles");
|
- |
|
117 |
NumerotationAutoSQLElement.addClass(this.getClass(), "ARTICLE");
|
83 |
|
118 |
|
84 |
getRowActions().addAll(new MouseSheetXmlListeListener(FicheArticleXmlSheet.class).getRowActions());
|
119 |
getRowActions().addAll(new MouseSheetXmlListeListener(this, FicheArticleXmlSheet.class).getRowActions());
|
85 |
this.stock = new PredicateRowAction(new AbstractAction("Mettre à jour les stocks") {
|
120 |
this.stock = new PredicateRowAction(new AbstractAction("Mettre à jour les stocks") {
|
86 |
|
121 |
|
87 |
@Override
|
122 |
@Override
|
88 |
public void actionPerformed(ActionEvent e) {
|
123 |
public void actionPerformed(ActionEvent e) {
|
- |
|
124 |
if (UserRightsManager.getCurrentUserRights().canAdd(getTable().getDBRoot().getTable("STOCK"))) {
|
89 |
|
125 |
|
- |
|
126 |
try {
|
90 |
final List<SQLRowValues> selectedRows = IListe.get(e).getSelectedRows();
|
127 |
final List<SQLRowAccessor> selectedRows = IListe.get(e).getSelectedRowAccessors();
|
91 |
List<SQLRowAccessor> l = new ArrayList<SQLRowAccessor>();
|
128 |
List<SQLRowAccessor> l = new ArrayList<SQLRowAccessor>();
|
92 |
for (SQLRowValues sqlRowValues : selectedRows) {
|
129 |
for (SQLRowAccessor sqlRowValues : selectedRows) {
|
- |
|
130 |
|
- |
|
131 |
final SQLRowAccessor stock = sqlRowValues.asRow().getNonEmptyForeign("ID_STOCK");
|
- |
|
132 |
if (stock != null) {
|
- |
|
133 |
l.add(stock);
|
- |
|
134 |
} else {
|
- |
|
135 |
SQLRowValues rowValsArt = sqlRowValues.createEmptyUpdateRow();
|
- |
|
136 |
SQLRowValues insert = rowValsArt.putRowValues("ID_STOCK");
|
- |
|
137 |
insert.put("ID_ARTICLE", sqlRowValues.getID());
|
- |
|
138 |
insert.put("ID_DEPOT_STOCK", DepotStockSQLElement.DEFAULT_ID);
|
- |
|
139 |
|
93 |
l.add(sqlRowValues.asRow().getForeign("ID_STOCK"));
|
140 |
l.add(rowValsArt.commit().getForeign("ID_STOCK"));
|
- |
|
141 |
}
|
94 |
}
|
142 |
}
|
95 |
|
143 |
|
96 |
PanelFrame p = new PanelFrame(new InventairePanel(IListe.get(e), l), "Mise à jour des stocks");
|
144 |
PanelFrame p = new PanelFrame(new InventairePanel(IListe.get(e), l), "Mise à jour des stocks");
|
97 |
FrameUtil.show(p);
|
145 |
FrameUtil.show(p);
|
- |
|
146 |
} catch (SQLException e1) {
|
- |
|
147 |
ExceptionHandler.handle("Erreur lors de la mise à jour du stock", e1);
|
- |
|
148 |
}
|
- |
|
149 |
} else {
|
- |
|
150 |
JOptionPane.showMessageDialog(null, "Vous n'avez les droits suffisants pour modifier manuellement les stocks!");
|
- |
|
151 |
}
|
98 |
|
152 |
|
99 |
}
|
153 |
}
|
100 |
}, true, false);
|
154 |
}, true, false);
|
101 |
stock.setPredicate(IListeEvent.getNonEmptySelectionPredicate());
|
155 |
stock.setPredicate(IListeEvent.getNonEmptySelectionPredicate());
|
102 |
getRowActions().add(stock);
|
156 |
getRowActions().add(stock);
|
103 |
|
157 |
|
- |
|
158 |
final SQLPreferences prefs = SQLPreferences.getMemCached(getTable().getDBRoot());
|
- |
|
159 |
if (prefs.getBoolean(GestionArticleGlobalPreferencePanel.STOCK_MULTI_DEPOT, false) && UserRightsManager.getCurrentUserRights().canAdd(getTable().getDBRoot().getTable("STOCK"))) {
|
- |
|
160 |
|
- |
|
161 |
RowAction actionConvVirtuel = new PredicateRowAction(new AbstractAction("Initialiser les stocks") {
|
- |
|
162 |
|
- |
|
163 |
@Override
|
- |
|
164 |
public void actionPerformed(ActionEvent e) {
|
- |
|
165 |
|
- |
|
166 |
PanelFrame frame = new PanelFrame(new InitializeStockPanel(ReferenceArticleSQLElement.this, IListe.get(e).getSelectedRowAccessors()), "Initialisation du stock");
|
- |
|
167 |
FrameUtil.showPacked(frame);
|
- |
|
168 |
|
- |
|
169 |
}
|
- |
|
170 |
}, true, false).setPredicate(ListEvent.getNonEmptySelectionPredicate());
|
- |
|
171 |
getRowActions().add(actionConvVirtuel);
|
- |
|
172 |
}
|
- |
|
173 |
if (prefs.getBoolean(GestionArticleGlobalPreferencePanel.ACTIVER_DECLINAISON, false)) {
|
- |
|
174 |
|
- |
|
175 |
RowAction actionConvVirtuel = new RowAction(new AbstractAction("Convertir en article virtuel") {
|
- |
|
176 |
|
- |
|
177 |
@Override
|
- |
|
178 |
public void actionPerformed(ActionEvent e) {
|
- |
|
179 |
|
- |
|
180 |
final SQLRowAccessor selectedRow = IListe.get(e).getSelectedRowAccessor();
|
- |
|
181 |
try {
|
- |
|
182 |
selectedRow.createEmptyUpdateRow().put("VIRTUEL", Boolean.TRUE).commit();
|
- |
|
183 |
} catch (SQLException e1) {
|
- |
|
184 |
ExceptionHandler.handle("Erreur lors de la conversion de l'article en virtuel", e1);
|
- |
|
185 |
}
|
- |
|
186 |
|
- |
|
187 |
}
|
- |
|
188 |
}, true, false) {
|
- |
|
189 |
@Override
|
- |
|
190 |
public boolean enabledFor(ListEvent evt) {
|
- |
|
191 |
final List<? extends SQLRowAccessor> selection = evt.getSelectedRowAccessors();
|
- |
|
192 |
if (selection.size() == 1) {
|
- |
|
193 |
return !selection.get(0).getBoolean("VIRTUEL") && selection.get(0).isForeignEmpty("ID_ARTICLE_VIRTUEL_PERE");
|
- |
|
194 |
}
|
- |
|
195 |
return false;
|
- |
|
196 |
}
|
- |
|
197 |
};
|
- |
|
198 |
getRowActions().add(actionConvVirtuel);
|
- |
|
199 |
|
- |
|
200 |
RowAction actionCreateDecl = new RowAction(new AbstractAction("Créer une déclinaison") {
|
- |
|
201 |
|
- |
|
202 |
@Override
|
- |
|
203 |
public void actionPerformed(ActionEvent e) {
|
- |
|
204 |
SQLRowValues rowVals = ReferenceArticleSQLElement.this.createCopy(IListe.get(e).getSelectedId());
|
- |
|
205 |
ListMap<SQLTable, SQLRow> children = ReferenceArticleSQLElement.this.getChildrenRows(IListe.get(e).getSelectedRowAccessor().asRow());
|
- |
|
206 |
for (SQLRow child : children.allValues()) {
|
- |
|
207 |
if (!child.getTable().getName().equals("STOCK")) {
|
- |
|
208 |
Configuration.getInstance().getDirectory().getElement(child.getTable()).createCopy(child, false, rowVals);
|
- |
|
209 |
}
|
- |
|
210 |
}
|
- |
|
211 |
rowVals.put("ID_ARTICLE_VIRTUEL_PERE", IListe.get(e).getSelectedId());
|
- |
|
212 |
rowVals.put("VIRTUEL", Boolean.FALSE);
|
- |
|
213 |
rowVals.putEmptyLink("ID_STOCK");
|
- |
|
214 |
|
- |
|
215 |
EditFrame f = new EditFrame(createComponent(), EditMode.CREATION);
|
- |
|
216 |
f.getSQLComponent().select(rowVals);
|
- |
|
217 |
FrameUtil.show(f);
|
- |
|
218 |
|
- |
|
219 |
}
|
- |
|
220 |
}, true, false) {
|
- |
|
221 |
@Override
|
- |
|
222 |
public boolean enabledFor(ListEvent evt) {
|
- |
|
223 |
final List<? extends SQLRowAccessor> selection = evt.getSelectedRowAccessors();
|
- |
|
224 |
if (selection.size() == 1) {
|
- |
|
225 |
return selection.get(0).getBoolean("VIRTUEL");
|
- |
|
226 |
}
|
- |
|
227 |
return false;
|
- |
|
228 |
}
|
- |
|
229 |
};
|
- |
|
230 |
getRowActions().add(actionCreateDecl);
|
- |
|
231 |
|
- |
|
232 |
RowAction actionCreateDecls = new RowAction(new AbstractAction("Créer des déclinaisons") {
|
- |
|
233 |
|
- |
|
234 |
@Override
|
- |
|
235 |
public void actionPerformed(ActionEvent e) {
|
- |
|
236 |
SQLRowValues rowVals = ReferenceArticleSQLElement.this.createCopy(IListe.get(e).getSelectedId());
|
- |
|
237 |
final SQLRow selectedRow = IListe.get(e).getSelectedRowAccessor().asRow();
|
- |
|
238 |
ListMap<SQLTable, SQLRow> children = ReferenceArticleSQLElement.this.getChildrenRows(selectedRow);
|
- |
|
239 |
for (SQLRow child : children.allValues()) {
|
- |
|
240 |
if (!child.getTable().getName().equals("STOCK")) {
|
- |
|
241 |
Configuration.getInstance().getDirectory().getElement(child.getTable()).createCopy(child, false, rowVals);
|
- |
|
242 |
}
|
- |
|
243 |
}
|
- |
|
244 |
rowVals.put("ID_ARTICLE_VIRTUEL_PERE", IListe.get(e).getSelectedId());
|
- |
|
245 |
rowVals.put("VIRTUEL", Boolean.FALSE);
|
- |
|
246 |
rowVals.putEmptyLink("ID_STOCK");
|
- |
|
247 |
|
- |
|
248 |
NouvellesDeclinaisonsFrame f = new NouvellesDeclinaisonsFrame(ReferenceArticleSQLElement.this, selectedRow);
|
- |
|
249 |
f.pack();
|
- |
|
250 |
f.setLocationRelativeTo(null);
|
- |
|
251 |
FrameUtil.show(f);
|
- |
|
252 |
|
- |
|
253 |
}
|
- |
|
254 |
}, false, true) {
|
- |
|
255 |
@Override
|
- |
|
256 |
public boolean enabledFor(ListEvent evt) {
|
- |
|
257 |
final List<? extends SQLRowAccessor> selection = evt.getSelectedRowAccessors();
|
- |
|
258 |
if (selection.size() == 1) {
|
- |
|
259 |
return selection.get(0).getBoolean("VIRTUEL");
|
- |
|
260 |
}
|
- |
|
261 |
return false;
|
- |
|
262 |
}
|
- |
|
263 |
};
|
- |
|
264 |
getRowActions().add(actionCreateDecls);
|
- |
|
265 |
|
- |
|
266 |
}
|
104 |
PredicateRowAction history = new PredicateRowAction(new AbstractAction("Historique") {
|
267 |
PredicateRowAction history = new PredicateRowAction(new AbstractAction("Historique") {
|
105 |
|
268 |
|
106 |
@Override
|
269 |
@Override
|
107 |
public void actionPerformed(ActionEvent e) {
|
270 |
public void actionPerformed(ActionEvent e) {
|
108 |
HistoriqueArticleFrame frame = new HistoriqueArticleFrame(ReferenceArticleSQLElement.this);
|
271 |
HistoriqueArticleFrame frame = new HistoriqueArticleFrame(ReferenceArticleSQLElement.this);
|
Line 111... |
Line 274... |
111 |
}
|
274 |
}
|
112 |
}, false, true);
|
275 |
}, false, true);
|
113 |
history.setPredicate(IListeEvent.getSingleSelectionPredicate());
|
276 |
history.setPredicate(IListeEvent.getSingleSelectionPredicate());
|
114 |
getRowActions().add(history);
|
277 |
getRowActions().add(history);
|
115 |
|
278 |
|
- |
|
279 |
PredicateRowAction mvtStock = new PredicateRowAction(new AbstractAction("Consulter les mouvements de stocks") {
|
- |
|
280 |
|
- |
|
281 |
@Override
|
- |
|
282 |
public void actionPerformed(ActionEvent e) {
|
- |
|
283 |
JFrame frame = new ListeDesMouvementsStockAction(ComptaPropsConfiguration.getInstanceCompta(), IListe.get(e).getSelectedRowAccessor()).getFrame();
|
- |
|
284 |
frame.setVisible(true);
|
- |
|
285 |
}
|
- |
|
286 |
}, false, true);
|
- |
|
287 |
mvtStock.setPredicate(IListeEvent.getSingleSelectionPredicate());
|
- |
|
288 |
getRowActions().add(mvtStock);
|
- |
|
289 |
|
- |
|
290 |
if (ComptaPropsConfiguration.getInstanceCompta().isExperimental()) {
|
- |
|
291 |
PredicateRowAction batches = new PredicateRowAction(new AbstractAction("Lots et numéros de série") {
|
- |
|
292 |
@Override
|
- |
|
293 |
public void actionPerformed(ActionEvent e) {
|
- |
|
294 |
ListeDesLotsAction action = new ListeDesLotsAction(ReferenceArticleSQLElement.this.getDirectory(), IListe.get(e).getSelectedRowAccessor());
|
- |
|
295 |
action.actionPerformed(e);
|
- |
|
296 |
}
|
- |
|
297 |
}, false, true);
|
- |
|
298 |
batches.setPredicate(IListeEvent.getSingleSelectionPredicate());
|
- |
|
299 |
getRowActions().add(batches);
|
- |
|
300 |
}
|
116 |
PredicateRowAction clone = new PredicateRowAction(new AbstractAction("Dupliquer") {
|
301 |
PredicateRowAction clone = new PredicateRowAction(new AbstractAction("Dupliquer") {
|
117 |
|
302 |
|
118 |
@Override
|
303 |
@Override
|
119 |
public void actionPerformed(ActionEvent e) {
|
304 |
public void actionPerformed(ActionEvent e) {
|
120 |
|
305 |
|
121 |
SQLRowValues rowVals = ReferenceArticleSQLElement.this.createCopy(IListe.get(e).getSelectedId());
|
306 |
SQLRowValues rowVals = ReferenceArticleSQLElement.this.createCopy(IListe.get(e).getSelectedId());
|
122 |
ListMap<SQLTable, SQLRow> children = ReferenceArticleSQLElement.this.getChildrenRows(IListe.get(e).getSelectedRow().asRow());
|
307 |
ListMap<SQLTable, SQLRow> children = ReferenceArticleSQLElement.this.getChildrenRows(IListe.get(e).getSelectedRowAccessor().asRow());
|
123 |
for (SQLRow child : children.allValues()) {
|
308 |
for (SQLRow child : children.allValues()) {
|
124 |
Configuration.getInstance().getDirectory().getElement(child.getTable()).createCopy(child, false, rowVals);
|
309 |
Configuration.getInstance().getDirectory().getElement(child.getTable()).createCopy(child, false, rowVals);
|
125 |
}
|
310 |
}
|
126 |
EditFrame f = new EditFrame(createComponent(), EditMode.CREATION);
|
311 |
EditFrame f = new EditFrame(createComponent(), EditMode.CREATION);
|
127 |
f.getSQLComponent().select(rowVals);
|
312 |
f.getSQLComponent().select(rowVals);
|
Line 134... |
Line 319... |
134 |
|
319 |
|
135 |
PredicateRowAction actionAttachment = new PredicateRowAction(new AttachmentAction().getAction(), true);
|
320 |
PredicateRowAction actionAttachment = new PredicateRowAction(new AttachmentAction().getAction(), true);
|
136 |
actionAttachment.setPredicate(IListeEvent.getSingleSelectionPredicate());
|
321 |
actionAttachment.setPredicate(IListeEvent.getSingleSelectionPredicate());
|
137 |
|
322 |
|
138 |
getRowActions().add(actionAttachment);
|
323 |
getRowActions().add(actionAttachment);
|
- |
|
324 |
|
- |
|
325 |
if (prefs.getBoolean(GestionArticleGlobalPreferencePanel.ACTIVER_DECLINAISON, false)) {
|
- |
|
326 |
|
- |
|
327 |
PredicateRowAction actionADeclinaison = new PredicateRowAction(new AbstractAction("Gérer les déclinaisons") {
|
- |
|
328 |
|
- |
|
329 |
@Override
|
- |
|
330 |
public void actionPerformed(ActionEvent e) {
|
- |
|
331 |
List<SQLElement> declElts = new ArrayList<>();
|
- |
|
332 |
for (SQLTable table : getTable().getDBRoot().getTables()) {
|
- |
|
333 |
if (table.getName().startsWith("ARTICLE_DECLINAISON_")) {
|
- |
|
334 |
declElts.add(getDirectory().getElement(table));
|
- |
|
335 |
}
|
- |
|
336 |
}
|
- |
|
337 |
|
- |
|
338 |
JTabbedPane tabs = new JTabbedPane();
|
- |
|
339 |
for (SQLElement elt : declElts) {
|
- |
|
340 |
final IListe liste = new IListe(elt.createTableSource());
|
- |
|
341 |
ListeAddPanel panel = new ListeAddPanel(elt, liste);
|
- |
|
342 |
tabs.add(elt.getPluralName(), panel);
|
- |
|
343 |
}
|
- |
|
344 |
|
- |
|
345 |
JPanel panel = new JPanel(new GridBagLayout());
|
- |
|
346 |
GridBagConstraints c = new DefaultGridBagConstraints();
|
- |
|
347 |
c.fill = GridBagConstraints.BOTH;
|
- |
|
348 |
c.weightx = 1;
|
- |
|
349 |
c.weighty = 1;
|
- |
|
350 |
panel.add(tabs, c);
|
- |
|
351 |
PanelFrame frame = new PanelFrame(panel, "Liste des déclinaisons");
|
- |
|
352 |
FrameUtil.showPacked(frame);
|
- |
|
353 |
}
|
- |
|
354 |
}, true);
|
- |
|
355 |
actionADeclinaison.setPredicate(IListeEvent.createTotalRowCountPredicate(0, Integer.MAX_VALUE));
|
- |
|
356 |
getRowActions().add(actionADeclinaison);
|
- |
|
357 |
}
|
- |
|
358 |
}
|
- |
|
359 |
|
- |
|
360 |
@Override
|
- |
|
361 |
protected SQLTableModelSourceOnline instantiateTableSourceOnline(ListSQLRequest req) {
|
- |
|
362 |
return new SQLTableModelSourceOnline(req, this, KeepMode.ROW);
|
139 |
}
|
363 |
}
|
140 |
|
364 |
|
141 |
@Override
|
365 |
@Override
|
142 |
protected synchronized void _initTableSource(final SQLTableModelSource source) {
|
366 |
protected synchronized void _initTableSource(final SQLTableModelSource source) {
|
143 |
super._initTableSource(source);
|
367 |
super._initTableSource(source);
|
- |
|
368 |
source.getReq().addToGraphToFetch("ID_ARTICLE_VIRTUEL_PERE", "VIRTUEL", "ID_DEPOT_STOCK");
|
144 |
source.init();
|
369 |
source.init();
|
145 |
final SQLTableModelColumn pvHA1Col = source.getColumn(getTable().getField("PRIX_METRIQUE_HA_1"));
|
370 |
final SQLTableModelColumn pvHA1Col = source.getColumn(getTable().getField("PRIX_METRIQUE_HA_1"));
|
146 |
if (pvHA1Col != null) {
|
371 |
if (pvHA1Col != null) {
|
147 |
pvHA1Col.setRenderer(CURRENCY_RENDERER);
|
372 |
pvHA1Col.setRenderer(CURRENCY_RENDERER);
|
148 |
}
|
373 |
}
|
Line 163... |
Line 388... |
163 |
final SQLTableModelColumn paHTCol = source.getColumn(getTable().getField("PA_HT"));
|
388 |
final SQLTableModelColumn paHTCol = source.getColumn(getTable().getField("PA_HT"));
|
164 |
if (paHTCol != null) {
|
389 |
if (paHTCol != null) {
|
165 |
paHTCol.setRenderer(CURRENCY_RENDERER);
|
390 |
paHTCol.setRenderer(CURRENCY_RENDERER);
|
166 |
}
|
391 |
}
|
167 |
|
392 |
|
- |
|
393 |
final SQLPreferences prefs = SQLPreferences.getMemCached(getTable().getDBRoot());
|
- |
|
394 |
|
- |
|
395 |
if (prefs.getBoolean(GestionArticleGlobalPreferencePanel.STOCK_MULTI_DEPOT, false)) {
|
- |
|
396 |
final BaseSQLTableModelColumn colStockGlobal = new BaseSQLTableModelColumn("Stock Global", BigDecimal.class) {
|
- |
|
397 |
|
- |
|
398 |
@Override
|
- |
|
399 |
protected Object show_(SQLRowAccessor r) {
|
- |
|
400 |
|
- |
|
401 |
BigDecimal totalQte = BigDecimal.ZERO;
|
- |
|
402 |
|
- |
|
403 |
Collection<? extends SQLRowAccessor> stockElt = r.getReferentRows(getTable().getTable("STOCK").getField("ID_ARTICLE"));
|
- |
|
404 |
for (SQLRowAccessor rowElt : stockElt) {
|
- |
|
405 |
BigDecimal qteCmd = new BigDecimal(rowElt.getFloat("QTE_REEL"));
|
- |
|
406 |
totalQte = totalQte.add(qteCmd);
|
- |
|
407 |
}
|
- |
|
408 |
return totalQte;
|
- |
|
409 |
}
|
- |
|
410 |
|
- |
|
411 |
@Override
|
- |
|
412 |
public Set<FieldPath> getPaths() {
|
- |
|
413 |
Path p2 = new Path(getTable()).add(getTable().getTable("STOCK").getField("ID_ARTICLE"));
|
- |
|
414 |
|
- |
|
415 |
return CollectionUtils.createSet(new FieldPath(p2, "QTE_REEL"));
|
- |
|
416 |
}
|
- |
|
417 |
};
|
- |
|
418 |
colStockGlobal.setRenderer(new NumberCellRenderer());
|
- |
|
419 |
source.getColumns().add(colStockGlobal);
|
- |
|
420 |
}
|
- |
|
421 |
|
168 |
if (getTable().getDBRoot().contains("ARTICLE_ELEMENT") && !getTable().getDBRoot().contains("TARIF_AGENCE")) {
|
422 |
if (getTable().getDBRoot().contains("ARTICLE_ELEMENT") && !getTable().getDBRoot().contains("TARIF_AGENCE")) {
|
169 |
source.getColumns().add(new BaseSQLTableModelColumn("Type", String.class) {
|
423 |
source.getColumns().add(new BaseSQLTableModelColumn("Type", String.class) {
|
170 |
|
424 |
|
171 |
@Override
|
425 |
@Override
|
172 |
protected Object show_(SQLRowAccessor r) {
|
426 |
protected Object show_(SQLRowAccessor r) {
|
Line 189... |
Line 443... |
189 |
}
|
443 |
}
|
190 |
});
|
444 |
});
|
191 |
}
|
445 |
}
|
192 |
}
|
446 |
}
|
193 |
|
447 |
|
- |
|
448 |
@Override
|
- |
|
449 |
public Set<String> getReadOnlyFields() {
|
- |
|
450 |
Set<String> s = new HashSet<>();
|
- |
|
451 |
s.add("ID_ARTICLE_VIRTUEL_PERE");
|
- |
|
452 |
return s;
|
- |
|
453 |
}
|
- |
|
454 |
|
194 |
protected List<String> getListFields() {
|
455 |
protected List<String> getListFields() {
|
195 |
final List<String> l = new ArrayList<String>();
|
456 |
final List<String> l = new ArrayList<String>();
|
196 |
|
457 |
|
197 |
l.add("CODE");
|
458 |
l.add("CODE");
|
198 |
SQLPreferences prefs = new SQLPreferences(getTable().getDBRoot());
|
459 |
SQLPreferences prefs = new SQLPreferences(getTable().getDBRoot());
|
Line 208... |
Line 469... |
208 |
l.add("PRIX_METRIQUE_HA_1");
|
469 |
l.add("PRIX_METRIQUE_HA_1");
|
209 |
l.add("PRIX_METRIQUE_VT_1");
|
470 |
l.add("PRIX_METRIQUE_VT_1");
|
210 |
}
|
471 |
}
|
211 |
l.add("PA_HT");
|
472 |
l.add("PA_HT");
|
212 |
l.add("PV_HT");
|
473 |
l.add("PV_HT");
|
- |
|
474 |
if (prefs.getBoolean(GestionArticleGlobalPreferencePanel.SHOW_LIST_TAXE, false)) {
|
213 |
l.add("ID_TAXE");
|
475 |
l.add("ID_TAXE");
|
- |
|
476 |
}
|
214 |
l.add("PV_TTC");
|
477 |
l.add("PV_TTC");
|
- |
|
478 |
if (prefs.getBoolean(GestionArticleGlobalPreferencePanel.SHOW_LIST_COMPTE, false)) {
|
215 |
l.add("ID_COMPTE_PCE");
|
479 |
l.add("ID_COMPTE_PCE");
|
216 |
l.add("ID_COMPTE_PCE_ACHAT");
|
480 |
l.add("ID_COMPTE_PCE_ACHAT");
|
- |
|
481 |
}
|
- |
|
482 |
if (prefs.getBoolean(GestionArticleGlobalPreferencePanel.SHOW_LIST_FAMILLE, false)) {
|
217 |
l.add("ID_FAMILLE_ARTICLE");
|
483 |
l.add("ID_FAMILLE_ARTICLE");
|
- |
|
484 |
}
|
- |
|
485 |
if (prefs.getBoolean(GestionArticleGlobalPreferencePanel.SHOW_LIST_FOURNISSEUR, false)) {
|
218 |
l.add("ID_FOURNISSEUR");
|
486 |
l.add("ID_FOURNISSEUR");
|
- |
|
487 |
}
|
219 |
l.add("POIDS");
|
488 |
l.add("POIDS");
|
220 |
l.add("SKU");
|
489 |
l.add("SKU");
|
221 |
|
490 |
|
222 |
// if (!prefs.getBoolean(GestionArticleGlobalPreferencePanel.STOCK_MULTI_DEPOT, false)) {
|
491 |
// if (!prefs.getBoolean(GestionArticleGlobalPreferencePanel.STOCK_MULTI_DEPOT, false)) {
|
223 |
l.add("GESTION_STOCK");
|
492 |
l.add("GESTION_STOCK");
|
Line 237... |
Line 506... |
237 |
final ListMap<String, String> res = new ListMap<String, String>();
|
506 |
final ListMap<String, String> res = new ListMap<String, String>();
|
238 |
SQLPreferences prefs = new SQLPreferences(getTable().getDBRoot());
|
507 |
SQLPreferences prefs = new SQLPreferences(getTable().getDBRoot());
|
239 |
if (prefs.getBoolean(GestionArticleGlobalPreferencePanel.SHOW_PRODUCT_BAR_CODE, false)) {
|
508 |
if (prefs.getBoolean(GestionArticleGlobalPreferencePanel.SHOW_PRODUCT_BAR_CODE, false)) {
|
240 |
res.add(null, "CODE_BARRE");
|
509 |
res.add(null, "CODE_BARRE");
|
241 |
}
|
510 |
}
|
- |
|
511 |
List<String> fieldDecl = new ArrayList<>();
|
- |
|
512 |
|
- |
|
513 |
if (prefs.getBoolean(GestionArticleGlobalPreferencePanel.ACTIVER_DECLINAISON, false)) {
|
- |
|
514 |
|
- |
|
515 |
for (String fieldName : getTable().getFieldsName()) {
|
- |
|
516 |
if (fieldName.startsWith("ID_ARTICLE_DECLINAISON_")) {
|
- |
|
517 |
fieldDecl.add(fieldName);
|
- |
|
518 |
}
|
- |
|
519 |
}
|
- |
|
520 |
}
|
242 |
res.addAll(null, "CODE", "NOM", "ID_FAMILLE_ARTICLE");
|
521 |
res.addAll(null, "CODE", "NOM", "ID_FAMILLE_ARTICLE", "ID_FOURNISSEUR");
|
- |
|
522 |
res.addAll(null, fieldDecl);
|
243 |
return res;
|
523 |
return res;
|
244 |
}
|
524 |
}
|
245 |
|
525 |
|
246 |
protected List<String> getComboFields() {
|
526 |
protected List<String> getComboFields() {
|
247 |
final List<String> l = new ArrayList<String>();
|
527 |
final List<String> l = new ArrayList<String>();
|
Line 250... |
Line 530... |
250 |
if (prefs.getBoolean(GestionArticleGlobalPreferencePanel.SHOW_PRODUCT_BAR_CODE, false)) {
|
530 |
if (prefs.getBoolean(GestionArticleGlobalPreferencePanel.SHOW_PRODUCT_BAR_CODE, false)) {
|
251 |
l.add("CODE_BARRE");
|
531 |
l.add("CODE_BARRE");
|
252 |
}
|
532 |
}
|
253 |
|
533 |
|
254 |
l.add("NOM");
|
534 |
l.add("NOM");
|
- |
|
535 |
List<String> fieldDecl = new ArrayList<>();
|
- |
|
536 |
for (String fieldName : getTable().getFieldsName()) {
|
- |
|
537 |
if (fieldName.startsWith("ID_ARTICLE_DECLINAISON_")) {
|
- |
|
538 |
fieldDecl.add(fieldName);
|
- |
|
539 |
}
|
- |
|
540 |
}
|
- |
|
541 |
l.addAll(fieldDecl);
|
255 |
l.add("PA_HT");
|
542 |
l.add("PA_HT");
|
256 |
l.add("PV_HT");
|
543 |
l.add("PV_HT");
|
257 |
l.add("DERNIER_DATE_ACHAT");
|
544 |
l.add("DERNIER_DATE_ACHAT");
|
258 |
return l;
|
545 |
return l;
|
259 |
}
|
546 |
}
|
Line 451... |
Line 738... |
451 |
selMatchingCodeArticle.setWhere(wMatchingCode);
|
738 |
selMatchingCodeArticle.setWhere(wMatchingCode);
|
452 |
List<SQLRow> matchingArticles = SQLRowListRSH.execute(selMatchingCodeArticle, false, false);
|
739 |
List<SQLRow> matchingArticles = SQLRowListRSH.execute(selMatchingCodeArticle, false, false);
|
453 |
if (matchingArticles.size() > 0) {
|
740 |
if (matchingArticles.size() > 0) {
|
454 |
idArticle = matchingArticles.get(0).getID();
|
741 |
idArticle = matchingArticles.get(0).getID();
|
455 |
} else {
|
742 |
} else {
|
- |
|
743 |
Collection<SQLRowValues> refTarif = row.getReferentRows(row.getTable().getTable("ARTICLE_TARIF_FOURNISSEUR"));
|
- |
|
744 |
if (!refTarif.isEmpty()) {
|
- |
|
745 |
for (SQLRowValues sqlRowValues : refTarif) {
|
- |
|
746 |
SQLRowValues rowValsTarif = new SQLRowValues(sqlRowValues);
|
- |
|
747 |
rowValsTarif.put("ID_ARTICLE", vals);
|
- |
|
748 |
}
|
- |
|
749 |
}
|
- |
|
750 |
|
456 |
SQLRow rowNew = vals.insert();
|
751 |
SQLRow rowNew = vals.insert();
|
457 |
idArticle = rowNew.getID();
|
752 |
idArticle = rowNew.getID();
|
458 |
}
|
753 |
}
|
459 |
}
|
754 |
}
|
460 |
return idArticle;
|
755 |
return idArticle;
|
Line 541... |
Line 836... |
541 |
|
836 |
|
542 |
@Override
|
837 |
@Override
|
543 |
protected void _initComboRequest(ComboSQLRequest req) {
|
838 |
protected void _initComboRequest(ComboSQLRequest req) {
|
544 |
super._initComboRequest(req);
|
839 |
super._initComboRequest(req);
|
545 |
req.addToGraphToFetch("ID_DEPOT_STOCK");
|
840 |
req.addToGraphToFetch("ID_DEPOT_STOCK");
|
546 |
// req.addForeignToGraphToFetch("ID_DEPOT_STOCK", Arrays.asList("ID"));
|
841 |
req.setWhere(new Where(getTable().getField("VIRTUEL"), "=", Boolean.FALSE));
|
- |
|
842 |
|
547 |
}
|
843 |
}
|
548 |
|
844 |
|
549 |
static public void updateDateAchat(final SQLTable tableArticle, final SQLRow article) {
|
845 |
static public void updateDateAchat(final SQLTable tableArticle, final SQLRow article) {
|
550 |
|
846 |
|
551 |
assert article == null || article.getTable() == tableArticle;
|
847 |
assert article == null || article.getTable() == tableArticle;
|
Line 560... |
Line 856... |
560 |
}
|
856 |
}
|
561 |
|
857 |
|
562 |
tableArticle.getDBSystemRoot().getDataSource().execute(up);
|
858 |
tableArticle.getDBSystemRoot().getDataSource().execute(up);
|
563 |
}
|
859 |
}
|
564 |
|
860 |
|
- |
|
861 |
/**
|
- |
|
862 |
* Création des déclinaisons tailles/couleurs à partir de l'article virtuel passé en parametre
|
- |
|
863 |
*
|
- |
|
864 |
* @param idArticlePere
|
- |
|
865 |
* @param tupleTailleCouleur
|
- |
|
866 |
* @throws SQLException
|
- |
|
867 |
*/
|
- |
|
868 |
public void createDeclinaison(int idArticlePere, List<Tuple2<SQLRow, SQLRow>> tupleTailleCouleur) throws SQLException {
|
- |
|
869 |
|
- |
|
870 |
final SQLRow row = getTable().getRow(idArticlePere);
|
- |
|
871 |
if (!row.getBoolean("VIRTUEL")) {
|
- |
|
872 |
throw new IllegalArgumentException("L'article n'est pas un article virtuel");
|
- |
|
873 |
}
|
- |
|
874 |
ListMap<SQLTable, SQLRow> children = ReferenceArticleSQLElement.this.getChildrenRows(row);
|
- |
|
875 |
for (Tuple2<SQLRow, SQLRow> t : tupleTailleCouleur) {
|
- |
|
876 |
|
- |
|
877 |
SQLRowValues rowVals = ReferenceArticleSQLElement.this.createCopy(idArticlePere);
|
- |
|
878 |
for (SQLRow child : children.allValues()) {
|
- |
|
879 |
Configuration.getInstance().getDirectory().getElement(child.getTable()).createCopy(child, false, rowVals);
|
- |
|
880 |
}
|
- |
|
881 |
rowVals.put("ID_ARTICLE_VIRTUEL_PERE", idArticlePere);
|
- |
|
882 |
rowVals.put("VIRTUEL", Boolean.FALSE);
|
- |
|
883 |
rowVals.put("ID_ARTICLE_DECLINAISON_TAILLE", t.get0().getID());
|
- |
|
884 |
rowVals.put("ID_ARTICLE_DECLINAISON_COULEUR", t.get1().getID());
|
- |
|
885 |
|
- |
|
886 |
rowVals.commit();
|
- |
|
887 |
|
- |
|
888 |
}
|
- |
|
889 |
|
- |
|
890 |
}
|
- |
|
891 |
|
- |
|
892 |
public void transfert(final List<Tuple2<SQLRow, BigDecimal>> articles, final SQLRowAccessor selectedRowDepotDepart, final SQLRowAccessor selectedRowDepotArrivee, final String label,
|
- |
|
893 |
final Date dateValue) {
|
- |
|
894 |
|
- |
|
895 |
final SQLTable mvtStockTable = getTable().getDBRoot().findTable("MOUVEMENT_STOCK");
|
- |
|
896 |
|
- |
|
897 |
List<String> multipleRequestsHundred = new ArrayList<String>(100);
|
- |
|
898 |
boolean usePrice = mvtStockTable.contains("PRICE");
|
- |
|
899 |
List<StockItem> stockItems = new ArrayList<StockItem>();
|
- |
|
900 |
|
- |
|
901 |
try {
|
- |
|
902 |
final DBSystemRoot dbSystemRoot = selectedRowDepotDepart.getTable().getDBSystemRoot();
|
- |
|
903 |
SQLUtils.executeAtomic(dbSystemRoot.getDataSource(), new ConnectionHandlerNoSetup<Object, SQLException>() {
|
- |
|
904 |
@Override
|
- |
|
905 |
public Object handle(SQLDataSource ds) throws SQLException {
|
- |
|
906 |
|
- |
|
907 |
for (Tuple2<SQLRow, BigDecimal> t : articles) {
|
- |
|
908 |
|
- |
|
909 |
SQLRow selectedRowArticle = t.get0();
|
- |
|
910 |
BigDecimal qteReel = t.get1();
|
- |
|
911 |
{
|
- |
|
912 |
// DEPART
|
- |
|
913 |
final SQLRowAccessor rowStockDepart = ProductComponent.findOrCreateStock(selectedRowArticle, selectedRowDepotDepart);
|
- |
|
914 |
StockItem item = new StockItem(selectedRowArticle, rowStockDepart);
|
- |
|
915 |
if (!item.isStockInit()) {
|
- |
|
916 |
SQLRowValues rowVals = new SQLRowValues(mvtStockTable.getTable("STOCK"));
|
- |
|
917 |
rowVals.put("ID_ARTICLE", selectedRowArticle.getID());
|
- |
|
918 |
rowVals.put("ID_DEPOT_STOCK", selectedRowDepotDepart.getID());
|
- |
|
919 |
rowVals.commit();
|
- |
|
920 |
selectedRowArticle.fetchValues();
|
- |
|
921 |
item = new StockItem(selectedRowArticle, rowStockDepart);
|
- |
|
922 |
}
|
- |
|
923 |
stockItems.add(item);
|
- |
|
924 |
double diff = -qteReel.doubleValue();
|
- |
|
925 |
item.updateQty(diff, TypeStockMouvement.REEL);
|
- |
|
926 |
multipleRequestsHundred.add(getMvtRequest(dateValue, BigDecimal.ZERO, diff, item, getLabel(label, selectedRowDepotDepart, selectedRowDepotArrivee), true, usePrice));
|
- |
|
927 |
item.updateQty(diff, TypeStockMouvement.THEORIQUE);
|
- |
|
928 |
multipleRequestsHundred.add(getMvtRequest(dateValue, BigDecimal.ZERO, diff, item, getLabel(label, selectedRowDepotDepart, selectedRowDepotArrivee), false, usePrice));
|
- |
|
929 |
multipleRequestsHundred.add(item.getUpdateRequest());
|
- |
|
930 |
}
|
- |
|
931 |
// ARRIVEE
|
- |
|
932 |
{
|
- |
|
933 |
final SQLRowAccessor rowStockArrivee = ProductComponent.findOrCreateStock(selectedRowArticle, selectedRowDepotArrivee);
|
- |
|
934 |
StockItem item = new StockItem(selectedRowArticle, rowStockArrivee);
|
- |
|
935 |
if (!item.isStockInit()) {
|
- |
|
936 |
SQLRowValues rowVals = new SQLRowValues(mvtStockTable.getTable("STOCK"));
|
- |
|
937 |
rowVals.put("ID_ARTICLE", selectedRowArticle.getID());
|
- |
|
938 |
rowVals.put("ID_DEPOT_STOCK", selectedRowDepotArrivee.getID());
|
- |
|
939 |
rowVals.commit();
|
- |
|
940 |
selectedRowArticle.fetchValues();
|
- |
|
941 |
item = new StockItem(selectedRowArticle, rowStockArrivee);
|
- |
|
942 |
}
|
- |
|
943 |
stockItems.add(item);
|
- |
|
944 |
double diff = qteReel.doubleValue();
|
- |
|
945 |
item.updateQty(diff, TypeStockMouvement.REEL);
|
- |
|
946 |
multipleRequestsHundred.add(getMvtRequest(dateValue, BigDecimal.ZERO, diff, item, getLabel(label, selectedRowDepotDepart, selectedRowDepotArrivee), true, usePrice));
|
- |
|
947 |
item.updateQty(diff, TypeStockMouvement.THEORIQUE);
|
- |
|
948 |
multipleRequestsHundred.add(getMvtRequest(dateValue, BigDecimal.ZERO, diff, item, getLabel(label, selectedRowDepotDepart, selectedRowDepotArrivee), false, usePrice));
|
- |
|
949 |
multipleRequestsHundred.add(item.getUpdateRequest());
|
- |
|
950 |
}
|
- |
|
951 |
|
- |
|
952 |
final int size = multipleRequestsHundred.size();
|
- |
|
953 |
List<? extends ResultSetHandler> handlers = new ArrayList<ResultSetHandler>(size);
|
- |
|
954 |
for (int i = 0; i < size; i++) {
|
- |
|
955 |
handlers.add(null);
|
- |
|
956 |
}
|
- |
|
957 |
SQLUtils.executeMultiple(dbSystemRoot, multipleRequestsHundred, handlers);
|
- |
|
958 |
|
- |
|
959 |
final DBRoot root = mvtStockTable.getDBRoot();
|
- |
|
960 |
if (root.contains("ARTICLE_ELEMENT")) {
|
- |
|
961 |
// Mise à jour des stocks des nomenclatures
|
- |
|
962 |
ComposedItemStockUpdater comp = new ComposedItemStockUpdater(root, stockItems);
|
- |
|
963 |
comp.update();
|
- |
|
964 |
}
|
- |
|
965 |
}
|
- |
|
966 |
return null;
|
- |
|
967 |
}
|
- |
|
968 |
});
|
- |
|
969 |
} catch (SQLException e1) {
|
- |
|
970 |
ExceptionHandler.handle("Stock update error", e1);
|
- |
|
971 |
}
|
- |
|
972 |
}
|
- |
|
973 |
|
- |
|
974 |
private String getLabel(String label, SQLRowAccessor fromDepot, SQLRowAccessor toDepot) {
|
- |
|
975 |
return label + " de " + fromDepot.getString("NOM") + " vers " + toDepot.getString("NOM");
|
- |
|
976 |
}
|
- |
|
977 |
|
- |
|
978 |
private String getMvtRequest(Date time, BigDecimal prc, double qteFinal, StockItem item, String label, boolean reel, boolean usePrice) {
|
- |
|
979 |
final SQLTable mvtStockTable = getTable().getDBRoot().findTable("MOUVEMENT_STOCK");
|
- |
|
980 |
final String mvtStockTableQuoted = mvtStockTable.getSQLName().quote();
|
- |
|
981 |
|
- |
|
982 |
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
- |
|
983 |
String mvtStockQuery = "INSERT INTO " + mvtStockTableQuoted + " (\"QTE\",\"DATE\",\"ID_ARTICLE\",\"ID_STOCK\",\"NOM\",\"REEL\",\"ORDRE\"";
|
- |
|
984 |
|
- |
|
985 |
if (usePrice && prc != null) {
|
- |
|
986 |
mvtStockQuery += ",\"PRICE\"";
|
- |
|
987 |
}
|
- |
|
988 |
|
- |
|
989 |
mvtStockQuery += ") VALUES(" + qteFinal + ",'" + dateFormat.format(time) + "'," + item.getArticle().getID() + "," + item.stock.getID() + ",'" + label + "'," + reel
|
- |
|
990 |
+ ", (SELECT (MAX(\"ORDRE\")+1) FROM " + mvtStockTableQuoted + ")";
|
- |
|
991 |
if (usePrice && prc != null) {
|
- |
|
992 |
mvtStockQuery += "," + prc.setScale(6, RoundingMode.HALF_UP).toString();
|
- |
|
993 |
}
|
- |
|
994 |
mvtStockQuery += ")";
|
- |
|
995 |
return mvtStockQuery;
|
- |
|
996 |
}
|
- |
|
997 |
|
565 |
}
|
998 |
}
|