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 OpenConcerto, by ILM Informatique. All rights reserved.
|
5 |
*
|
5 |
*
|
6 |
* The contents of this file are subject to the terms of the GNU General Public License Version 3
|
6 |
* The contents of this file are subject to the terms of the GNU General Public License Version 3
|
7 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
|
7 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
|
8 |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
|
8 |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
|
9 |
* language governing permissions and limitations under the License.
|
9 |
* language governing permissions and limitations under the License.
|
10 |
*
|
10 |
*
|
11 |
* When distributing the software, include this License Header Notice in each file.
|
11 |
* When distributing the software, include this License Header Notice in each file.
|
12 |
*/
|
12 |
*/
|
13 |
|
13 |
|
14 |
package org.openconcerto.erp.core.supplychain.stock.element;
|
14 |
package org.openconcerto.erp.core.supplychain.stock.element;
|
15 |
|
15 |
|
16 |
import org.openconcerto.erp.config.ComptaPropsConfiguration;
|
16 |
import org.openconcerto.erp.config.ComptaPropsConfiguration;
|
17 |
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
|
17 |
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
|
18 |
import org.openconcerto.erp.core.sales.product.element.ReferenceArticleSQLElement;
|
18 |
import org.openconcerto.erp.core.sales.product.element.ReferenceArticleSQLElement;
|
- |
|
19 |
import org.openconcerto.erp.core.sales.product.element.UniteVenteArticleSQLElement;
|
19 |
import org.openconcerto.erp.core.supplychain.order.component.CommandeSQLComponent;
|
20 |
import org.openconcerto.erp.core.supplychain.order.component.CommandeSQLComponent;
|
20 |
import org.openconcerto.erp.core.supplychain.order.ui.CommandeItemTable;
|
21 |
import org.openconcerto.erp.core.supplychain.order.ui.CommandeItemTable;
|
21 |
import org.openconcerto.erp.core.supplychain.supplier.component.MouvementStockSQLComponent;
|
22 |
import org.openconcerto.erp.core.supplychain.supplier.component.MouvementStockSQLComponent;
|
22 |
import org.openconcerto.erp.preferences.GestionArticleGlobalPreferencePanel;
|
23 |
import org.openconcerto.erp.preferences.GestionArticleGlobalPreferencePanel;
|
- |
|
24 |
import org.openconcerto.erp.preferences.GestionCommercialeGlobalPreferencePanel;
|
23 |
import org.openconcerto.sql.Configuration;
|
25 |
import org.openconcerto.sql.Configuration;
|
24 |
import org.openconcerto.sql.element.SQLComponent;
|
26 |
import org.openconcerto.sql.element.SQLComponent;
|
25 |
import org.openconcerto.sql.element.SQLElement;
|
27 |
import org.openconcerto.sql.element.SQLElement;
|
26 |
import org.openconcerto.sql.element.TreesOfSQLRows;
|
28 |
import org.openconcerto.sql.element.TreesOfSQLRows;
|
27 |
import org.openconcerto.sql.model.SQLBackgroundTableCache;
|
29 |
import org.openconcerto.sql.model.SQLBackgroundTableCache;
|
28 |
import org.openconcerto.sql.model.SQLBase;
|
30 |
import org.openconcerto.sql.model.SQLBase;
|
29 |
import org.openconcerto.sql.model.SQLInjector;
|
31 |
import org.openconcerto.sql.model.SQLInjector;
|
30 |
import org.openconcerto.sql.model.SQLRow;
|
32 |
import org.openconcerto.sql.model.SQLRow;
|
31 |
import org.openconcerto.sql.model.SQLRowListRSH;
|
33 |
import org.openconcerto.sql.model.SQLRowListRSH;
|
32 |
import org.openconcerto.sql.model.SQLRowValues;
|
34 |
import org.openconcerto.sql.model.SQLRowValues;
|
33 |
import org.openconcerto.sql.model.SQLSelect;
|
35 |
import org.openconcerto.sql.model.SQLSelect;
|
34 |
import org.openconcerto.sql.model.SQLTable;
|
36 |
import org.openconcerto.sql.model.SQLTable;
|
35 |
import org.openconcerto.sql.model.Where;
|
37 |
import org.openconcerto.sql.model.Where;
|
36 |
import org.openconcerto.sql.preferences.SQLPreferences;
|
38 |
import org.openconcerto.sql.preferences.SQLPreferences;
|
37 |
import org.openconcerto.sql.request.ListSQLRequest;
|
39 |
import org.openconcerto.sql.request.ListSQLRequest;
|
38 |
import org.openconcerto.sql.users.UserManager;
|
40 |
import org.openconcerto.sql.users.UserManager;
|
39 |
import org.openconcerto.sql.view.EditFrame;
|
41 |
import org.openconcerto.sql.view.EditFrame;
|
40 |
import org.openconcerto.sql.view.EditPanel;
|
42 |
import org.openconcerto.sql.view.EditPanel;
|
41 |
import org.openconcerto.sql.view.EditPanel.EditMode;
|
43 |
import org.openconcerto.sql.view.EditPanel.EditMode;
|
42 |
import org.openconcerto.sql.view.list.RowValuesTableModel;
|
44 |
import org.openconcerto.sql.view.list.RowValuesTableModel;
|
43 |
import org.openconcerto.ui.FrameUtil;
|
45 |
import org.openconcerto.ui.FrameUtil;
|
44 |
import org.openconcerto.utils.ListMap;
|
46 |
import org.openconcerto.utils.ListMap;
|
45 |
|
47 |
|
46 |
import java.math.BigDecimal;
|
48 |
import java.math.BigDecimal;
|
47 |
import java.sql.SQLException;
|
49 |
import java.sql.SQLException;
|
48 |
import java.util.ArrayList;
|
50 |
import java.util.ArrayList;
|
49 |
import java.util.Collection;
|
51 |
import java.util.Collection;
|
50 |
import java.util.List;
|
52 |
import java.util.List;
|
51 |
import java.util.Map.Entry;
|
53 |
import java.util.Map.Entry;
|
52 |
|
54 |
|
- |
|
55 |
import javax.swing.JOptionPane;
|
53 |
import javax.swing.SwingUtilities;
|
56 |
import javax.swing.SwingUtilities;
|
54 |
|
57 |
|
55 |
public class MouvementStockSQLElement extends ComptaSQLConfElement {
|
58 |
public class MouvementStockSQLElement extends ComptaSQLConfElement {
|
56 |
|
59 |
|
57 |
public MouvementStockSQLElement() {
|
60 |
public MouvementStockSQLElement() {
|
58 |
super("MOUVEMENT_STOCK", "un mouvement de stock", "mouvements de stock");
|
61 |
super("MOUVEMENT_STOCK", "un mouvement de stock", "mouvements de stock");
|
59 |
}
|
62 |
}
|
60 |
|
63 |
|
61 |
@Override
|
64 |
@Override
|
62 |
public ListMap<String, String> getShowAs() {
|
65 |
public ListMap<String, String> getShowAs() {
|
63 |
ListMap<String, String> map = new ListMap<String, String>();
|
66 |
ListMap<String, String> map = new ListMap<String, String>();
|
64 |
map.putCollection("ID_STOCK", "ID_DEPOT_STOCK");
|
67 |
map.putCollection("ID_STOCK", "ID_DEPOT_STOCK");
|
65 |
return map;
|
68 |
return map;
|
66 |
}
|
69 |
}
|
67 |
|
70 |
|
68 |
protected List<String> getListFields() {
|
71 |
protected List<String> getListFields() {
|
69 |
final List<String> l = new ArrayList<String>();
|
72 |
final List<String> l = new ArrayList<String>();
|
70 |
l.add("ID_STOCK");
|
73 |
l.add("ID_STOCK");
|
71 |
l.add("DATE");
|
74 |
l.add("DATE");
|
72 |
l.add("NOM");
|
75 |
l.add("NOM");
|
73 |
l.add("ID_ARTICLE");
|
76 |
l.add("ID_ARTICLE");
|
74 |
l.add("QTE");
|
77 |
l.add("QTE");
|
75 |
l.add("REEL");
|
78 |
l.add("REEL");
|
76 |
return l;
|
79 |
return l;
|
77 |
}
|
80 |
}
|
78 |
|
81 |
|
79 |
protected List<String> getComboFields() {
|
82 |
protected List<String> getComboFields() {
|
80 |
final List<String> l = new ArrayList<String>();
|
83 |
final List<String> l = new ArrayList<String>();
|
81 |
l.add("NOM");
|
84 |
l.add("NOM");
|
82 |
l.add("QTE");
|
85 |
l.add("QTE");
|
83 |
return l;
|
86 |
return l;
|
84 |
}
|
87 |
}
|
85 |
|
88 |
|
86 |
/*
|
89 |
/*
|
87 |
* (non-Javadoc)
|
90 |
* (non-Javadoc)
|
88 |
*
|
91 |
*
|
89 |
* @see org.openconcerto.devis.SQLElement#getComponent()
|
92 |
* @see org.openconcerto.devis.SQLElement#getComponent()
|
90 |
*/
|
93 |
*/
|
91 |
public SQLComponent createComponent() {
|
94 |
public SQLComponent createComponent() {
|
92 |
return new MouvementStockSQLComponent(this);
|
95 |
return new MouvementStockSQLComponent(this);
|
93 |
}
|
96 |
}
|
94 |
|
97 |
|
95 |
@Override
|
98 |
@Override
|
96 |
protected void archive(TreesOfSQLRows trees, boolean cutLinks) throws SQLException {
|
99 |
protected void archive(TreesOfSQLRows trees, boolean cutLinks) throws SQLException {
|
97 |
super.archive(trees, cutLinks);
|
100 |
super.archive(trees, cutLinks);
|
98 |
updateStock(trees.getRows(), true);
|
101 |
updateStock(trees.getRows(), true);
|
99 |
|
102 |
|
100 |
}
|
103 |
}
|
101 |
|
104 |
|
102 |
/**
|
105 |
/**
|
103 |
* Mise à jour des stocks ajoute la quantité si archive est à false
|
106 |
* Mise à jour des stocks ajoute la quantité si archive est à false
|
104 |
*
|
107 |
*
|
105 |
* @param id mouvement stock
|
108 |
* @param id mouvement stock
|
106 |
* @param archive
|
109 |
* @param archive
|
107 |
* @throws SQLException
|
110 |
* @throws SQLException
|
108 |
*/
|
111 |
*/
|
109 |
public ListMap<SQLRow, SQLRowValues> updateStock(Collection<SQLRow> rowsMvt, boolean archive) throws SQLException {
|
112 |
public ListMap<SQLRow, SQLRowValues> updateStock(Collection<SQLRow> rowsMvt, boolean archive) throws SQLException {
|
110 |
// FIXME: if (SwingUtilities.isEventDispatchThread()) {
|
113 |
// FIXME: if (SwingUtilities.isEventDispatchThread()) {
|
111 |
// throw new IllegalStateException("This method must be called outside of EDT");
|
114 |
// throw new IllegalStateException("This method must be called outside of EDT");
|
112 |
// }
|
115 |
// }
|
113 |
// Stock Reel : inc/dec QTE_REEL, inc/dec QTE_LIV_ATTENTE/inc/dec
|
116 |
// Stock Reel : inc/dec QTE_REEL, inc/dec QTE_LIV_ATTENTE/inc/dec
|
114 |
// QTE_RECEPT_ATTENTE
|
117 |
// QTE_RECEPT_ATTENTE
|
115 |
// Stock Th : inc/dec QTE_TH, inc/dec QTE_LIV_ATTENTE/inc/dec
|
118 |
// Stock Th : inc/dec QTE_TH, inc/dec QTE_LIV_ATTENTE/inc/dec
|
116 |
// QTE_RECEPT_ATTENTE
|
119 |
// QTE_RECEPT_ATTENTE
|
117 |
|
120 |
|
118 |
final ListMap<SQLRow, SQLRowValues> map = new ListMap<>();
|
121 |
final ListMap<SQLRow, SQLRowValues> map = new ListMap<>();
|
119 |
final SQLTable tableCommandeElement = Configuration.getInstance().getBase().getTable("COMMANDE_ELEMENT");
|
122 |
final SQLTable tableCommandeElement = Configuration.getInstance().getBase().getTable("COMMANDE_ELEMENT");
|
120 |
final SQLElement elementStock = Configuration.getInstance().getDirectory().getElement("STOCK");
|
123 |
final SQLElement elementStock = Configuration.getInstance().getDirectory().getElement("STOCK");
|
121 |
|
124 |
|
122 |
for (SQLRow rowMvtStock : rowsMvt) {
|
125 |
for (SQLRow rowMvtStock : rowsMvt) {
|
123 |
|
126 |
|
124 |
boolean retour = rowMvtStock.getString("SOURCE") == null || rowMvtStock.getString("SOURCE").startsWith("AVOIR_CLIENT");
|
127 |
boolean retour = rowMvtStock.getString("SOURCE") == null || rowMvtStock.getString("SOURCE").startsWith("AVOIR_CLIENT");
|
125 |
// Mise à jour des stocks
|
128 |
// Mise à jour des stocks
|
126 |
|
129 |
|
127 |
final SQLRow rowArticle = rowMvtStock.getForeignRow("ID_ARTICLE");
|
130 |
final SQLRow rowArticle = rowMvtStock.getForeignRow("ID_ARTICLE");
|
128 |
|
131 |
|
129 |
SQLRow rowStock = rowMvtStock.getForeignRow(("ID_STOCK"));
|
132 |
SQLRow rowStock = rowMvtStock.getForeignRow(("ID_STOCK"));
|
130 |
if (rowStock == null || rowStock.isUndefined()) {
|
133 |
if (rowStock == null || rowStock.isUndefined()) {
|
131 |
rowStock = rowArticle.getForeign("ID_STOCK");
|
134 |
rowStock = rowArticle.getForeign("ID_STOCK");
|
132 |
}
|
135 |
}
|
133 |
|
136 |
|
134 |
if (rowMvtStock.getBoolean("REEL")) {
|
137 |
if (rowMvtStock.getBoolean("REEL")) {
|
135 |
float qte = rowStock.getFloat("QTE_REEL");
|
138 |
float qte = rowStock.getFloat("QTE_REEL");
|
136 |
float qteMvt = rowMvtStock.getFloat("QTE");
|
139 |
float qteMvt = rowMvtStock.getFloat("QTE");
|
137 |
|
140 |
|
138 |
SQLRowValues rowVals = new SQLRowValues(elementStock.getTable());
|
141 |
SQLRowValues rowVals = new SQLRowValues(elementStock.getTable());
|
139 |
|
142 |
|
140 |
float qteNvlle;
|
143 |
float qteNvlle;
|
141 |
float qteNvlleEnAttenteRecept = rowStock.getFloat("QTE_RECEPT_ATTENTE");
|
144 |
float qteNvlleEnAttenteRecept = rowStock.getFloat("QTE_RECEPT_ATTENTE");
|
142 |
float qteNvlleEnAttenteExp = rowStock.getFloat("QTE_LIV_ATTENTE");
|
145 |
float qteNvlleEnAttenteExp = rowStock.getFloat("QTE_LIV_ATTENTE");
|
143 |
if (archive) {
|
146 |
if (archive) {
|
144 |
qteNvlle = qte - qteMvt;
|
147 |
qteNvlle = qte - qteMvt;
|
145 |
if (!retour) {
|
148 |
if (!retour) {
|
146 |
// Réception
|
149 |
// Réception
|
147 |
if (qteMvt > 0) {
|
150 |
if (qteMvt > 0) {
|
148 |
qteNvlleEnAttenteRecept += qteMvt;
|
151 |
qteNvlleEnAttenteRecept += qteMvt;
|
149 |
} else {
|
152 |
} else {
|
150 |
// Livraison
|
153 |
// Livraison
|
151 |
qteNvlleEnAttenteExp -= qteMvt;
|
154 |
qteNvlleEnAttenteExp -= qteMvt;
|
152 |
}
|
155 |
}
|
153 |
}
|
156 |
}
|
154 |
} else {
|
157 |
} else {
|
155 |
qteNvlle = qte + qteMvt;
|
158 |
qteNvlle = qte + qteMvt;
|
156 |
if (!retour) {
|
159 |
if (!retour) {
|
157 |
// Réception
|
160 |
// Réception
|
158 |
if (qteMvt > 0) {
|
161 |
if (qteMvt > 0) {
|
159 |
qteNvlleEnAttenteRecept -= qteMvt;
|
162 |
qteNvlleEnAttenteRecept -= qteMvt;
|
160 |
} else {
|
163 |
} else {
|
161 |
// Livraison
|
164 |
// Livraison
|
162 |
qteNvlleEnAttenteExp += qteMvt;
|
165 |
qteNvlleEnAttenteExp += qteMvt;
|
163 |
}
|
166 |
}
|
164 |
}
|
167 |
}
|
165 |
}
|
168 |
}
|
166 |
rowVals.put("QTE_REEL", qteNvlle);
|
169 |
rowVals.put("QTE_REEL", qteNvlle);
|
167 |
rowVals.put("QTE_RECEPT_ATTENTE", qteNvlleEnAttenteRecept);
|
170 |
rowVals.put("QTE_RECEPT_ATTENTE", qteNvlleEnAttenteRecept);
|
168 |
rowVals.put("QTE_LIV_ATTENTE", qteNvlleEnAttenteExp);
|
171 |
rowVals.put("QTE_LIV_ATTENTE", qteNvlleEnAttenteExp);
|
169 |
|
172 |
|
170 |
try {
|
173 |
try {
|
171 |
rowVals.update(rowStock.getID());
|
174 |
rowVals.update(rowStock.getID());
|
172 |
|
175 |
|
173 |
SQLPreferences prefs = new SQLPreferences(getTable().getDBRoot());
|
176 |
SQLPreferences prefs = new SQLPreferences(getTable().getDBRoot());
|
174 |
boolean gestionStockMin = prefs.getBoolean(GestionArticleGlobalPreferencePanel.WARNING_STOCK_MIN, true);
|
177 |
boolean gestionStockMin = prefs.getBoolean(GestionArticleGlobalPreferencePanel.WARNING_STOCK_MIN, true);
|
175 |
|
178 |
|
176 |
if (!archive && gestionStockMin && rowStock.getObject("QTE_MIN") != null && qteNvlle < rowStock.getFloat("QTE_MIN")) {
|
179 |
if (!archive && gestionStockMin && rowStock.getObject("QTE_MIN") != null && qteNvlle < rowStock.getFloat("QTE_MIN")) {
|
177 |
// final float qteShow = qteNvlle;
|
180 |
// final float qteShow = qteNvlle;
|
178 |
SQLInjector inj = SQLInjector.getInjector(rowArticle.getTable(), tableCommandeElement);
|
181 |
SQLInjector inj = SQLInjector.getInjector(rowArticle.getTable(), tableCommandeElement);
|
179 |
SQLRowValues rowValsElt = new SQLRowValues(inj.createRowValuesFrom(rowArticle));
|
182 |
SQLRowValues rowValsElt = new SQLRowValues(inj.createRowValuesFrom(rowArticle));
|
180 |
rowValsElt.put("ID_STYLE", 2);
|
183 |
rowValsElt.put("ID_STYLE", 2);
|
181 |
final SQLRow unite = rowArticle.getForeign("ID_UNITE_VENTE");
|
184 |
final SQLRow unite = rowArticle.getForeign("ID_UNITE_VENTE");
|
182 |
final float qteElt = rowStock.getFloat("QTE_MIN") - qteNvlle;
|
185 |
final float qteElt = rowStock.getFloat("QTE_MIN") - qteNvlle;
|
183 |
if (unite.isUndefined() || unite.getBoolean("A_LA_PIECE")) {
|
186 |
if (unite.isUndefined() || unite.getBoolean("A_LA_PIECE")) {
|
184 |
rowValsElt.put("QTE", Math.round(qteElt));
|
187 |
rowValsElt.put("QTE", Math.round(qteElt));
|
185 |
rowValsElt.put("QTE_UNITAIRE", BigDecimal.ONE);
|
188 |
rowValsElt.put("QTE_UNITAIRE", BigDecimal.ONE);
|
186 |
} else {
|
189 |
} else {
|
187 |
rowValsElt.put("QTE", 1);
|
190 |
rowValsElt.put("QTE", 1);
|
188 |
rowValsElt.put("QTE_UNITAIRE", new BigDecimal(qteElt));
|
191 |
rowValsElt.put("QTE_UNITAIRE", new BigDecimal(qteElt));
|
189 |
}
|
192 |
}
|
190 |
rowValsElt.put("ID_TAXE", rowValsElt.getObject("ID_TAXE"));
|
193 |
rowValsElt.put("ID_TAXE", rowValsElt.getObject("ID_TAXE"));
|
191 |
rowValsElt.put("T_POIDS", rowValsElt.getLong("POIDS") * qteElt);
|
194 |
rowValsElt.put("T_POIDS", rowValsElt.getLong("POIDS") * qteElt);
|
192 |
rowValsElt.put("T_PA_HT", rowValsElt.getLong("PA_HT") * qteElt);
|
195 |
rowValsElt.put("T_PA_HT", rowValsElt.getLong("PA_HT") * qteElt);
|
193 |
rowValsElt.put("T_PA_TTC", rowValsElt.getLong("T_PA_HT") * (rowValsElt.getForeign("ID_TAXE").getFloat("TAUX") / 100.0 + 1.0));
|
196 |
rowValsElt.put("T_PA_TTC", rowValsElt.getLong("T_PA_HT") * (rowValsElt.getForeign("ID_TAXE").getFloat("TAUX") / 100.0 + 1.0));
|
194 |
map.add(rowArticle.getForeignRow("ID_FOURNISSEUR"), rowValsElt);
|
197 |
map.add(rowArticle.getForeignRow("ID_FOURNISSEUR"), rowValsElt);
|
195 |
}
|
198 |
}
|
196 |
} catch (SQLException e) {
|
199 |
} catch (SQLException e) {
|
197 |
throw new SQLException("Erreur lors de la mise à jour du stock pour l'article " + rowArticle.getString("CODE"), e);
|
200 |
throw new SQLException("Erreur lors de la mise à jour du stock pour l'article " + rowArticle.getString("CODE"), e);
|
198 |
}
|
201 |
}
|
199 |
} else {
|
202 |
} else {
|
200 |
float qte = rowStock.getFloat("QTE_TH");
|
203 |
float qte = rowStock.getFloat("QTE_TH");
|
201 |
float qteMvt = rowMvtStock.getFloat("QTE");
|
204 |
float qteMvt = rowMvtStock.getFloat("QTE");
|
202 |
|
205 |
|
203 |
SQLRowValues rowVals = new SQLRowValues(elementStock.getTable());
|
206 |
SQLRowValues rowVals = new SQLRowValues(elementStock.getTable());
|
204 |
|
207 |
|
205 |
float qteNvlle;
|
208 |
float qteNvlle;
|
206 |
float qteNvlleEnAttenteRecept = rowStock.getFloat("QTE_RECEPT_ATTENTE");
|
209 |
float qteNvlleEnAttenteRecept = rowStock.getFloat("QTE_RECEPT_ATTENTE");
|
207 |
float qteNvlleEnAttenteExp = rowStock.getFloat("QTE_LIV_ATTENTE");
|
210 |
float qteNvlleEnAttenteExp = rowStock.getFloat("QTE_LIV_ATTENTE");
|
208 |
|
211 |
|
209 |
if (archive) {
|
212 |
if (archive) {
|
210 |
qteNvlle = qte - qteMvt;
|
213 |
qteNvlle = qte - qteMvt;
|
211 |
if (!retour) {
|
214 |
if (!retour) {
|
212 |
|
215 |
|
213 |
// CommandeF
|
216 |
// CommandeF
|
214 |
if (qteMvt > 0) {
|
217 |
if (qteMvt > 0) {
|
215 |
qteNvlleEnAttenteRecept -= qteMvt;
|
218 |
qteNvlleEnAttenteRecept -= qteMvt;
|
216 |
} else {
|
219 |
} else {
|
217 |
// CommanceC
|
220 |
// CommanceC
|
218 |
qteNvlleEnAttenteExp += qteMvt;
|
221 |
qteNvlleEnAttenteExp += qteMvt;
|
219 |
}
|
222 |
}
|
220 |
}
|
223 |
}
|
221 |
} else {
|
224 |
} else {
|
222 |
qteNvlle = qte + qteMvt;
|
225 |
qteNvlle = qte + qteMvt;
|
223 |
if (!retour) {
|
226 |
if (!retour) {
|
224 |
|
227 |
|
225 |
// CommandeF
|
228 |
// CommandeF
|
226 |
if (qteMvt > 0) {
|
229 |
if (qteMvt > 0) {
|
227 |
qteNvlleEnAttenteRecept += qteMvt;
|
230 |
qteNvlleEnAttenteRecept += qteMvt;
|
228 |
} else {
|
231 |
} else {
|
229 |
// CommanceC
|
232 |
// CommanceC
|
230 |
qteNvlleEnAttenteExp -= qteMvt;
|
233 |
qteNvlleEnAttenteExp -= qteMvt;
|
231 |
}
|
234 |
}
|
232 |
}
|
235 |
}
|
233 |
}
|
236 |
}
|
234 |
rowVals.put("QTE_TH", qteNvlle);
|
237 |
rowVals.put("QTE_TH", qteNvlle);
|
235 |
rowVals.put("QTE_RECEPT_ATTENTE", qteNvlleEnAttenteRecept);
|
238 |
rowVals.put("QTE_RECEPT_ATTENTE", qteNvlleEnAttenteRecept);
|
236 |
rowVals.put("QTE_LIV_ATTENTE", qteNvlleEnAttenteExp);
|
239 |
rowVals.put("QTE_LIV_ATTENTE", qteNvlleEnAttenteExp);
|
237 |
try {
|
240 |
try {
|
238 |
rowVals.update(rowStock.getID());
|
241 |
rowVals.update(rowStock.getID());
|
239 |
} catch (SQLException e) {
|
242 |
} catch (SQLException e) {
|
240 |
throw new SQLException("Erreur lors de la mise à jour du stock pour l'article " + rowArticle.getString("CODE"), e);
|
243 |
throw new SQLException("Erreur lors de la mise à jour du stock pour l'article " + rowArticle.getString("CODE"), e);
|
241 |
}
|
244 |
}
|
242 |
}
|
245 |
}
|
243 |
|
246 |
|
244 |
}
|
247 |
}
|
245 |
return map;
|
248 |
return map;
|
246 |
}
|
249 |
}
|
247 |
|
250 |
|
248 |
public static void createCommandeF(final ListMap<SQLRow, SQLRowValues> col, final SQLRow rowDevise) {
|
251 |
public static void createCommandeF(final ListMap<SQLRow, SQLRowValues> col, final SQLRow rowDevise) {
|
249 |
createCommandeF(col, rowDevise, "", true);
|
252 |
createCommandeF(col, rowDevise, "");
|
250 |
}
|
253 |
}
|
251 |
|
254 |
|
252 |
public static void createCommandeF(final ListMap<SQLRow, SQLRowValues> col, final SQLRow rowDevise, final String ref, final boolean useCommandeEnCours) {
|
255 |
public static void createCommandeF(final ListMap<SQLRow, SQLRowValues> col, final SQLRow rowDevise, final String ref) {
|
253 |
if (SwingUtilities.isEventDispatchThread()) {
|
256 |
if (SwingUtilities.isEventDispatchThread()) {
|
254 |
throw new IllegalStateException("This method must be called outside of EDT");
|
257 |
throw new IllegalStateException("This method must be called outside of EDT");
|
255 |
}
|
258 |
}
|
256 |
if (col.size() > 0) {
|
259 |
if (col.size() > 0) {
|
257 |
|
260 |
|
258 |
final SQLElement commande = Configuration.getInstance().getDirectory().getElement("COMMANDE");
|
261 |
final SQLElement commande = Configuration.getInstance().getDirectory().getElement("COMMANDE");
|
- |
|
262 |
Boolean useCommandeEnCours = SQLPreferences.getMemCached(commande.getTable().getDBRoot()).getBoolean(GestionCommercialeGlobalPreferencePanel.COMMANDE_FOURNISSEUR_EN_COURS, false);
|
259 |
for (final Entry<SQLRow, List<SQLRowValues>> e : col.entrySet()) {
|
263 |
for (final Entry<SQLRow, List<SQLRowValues>> e : col.entrySet()) {
|
260 |
final SQLRow fournisseur = e.getKey();
|
264 |
final SQLRow fournisseur = e.getKey();
|
261 |
// On regarde si il existe une commande en cours existante
|
265 |
// On regarde si il existe une commande en cours existante
|
262 |
final SQLSelect sel = new SQLSelect();
|
266 |
final SQLSelect sel = new SQLSelect();
|
263 |
sel.addSelectStar(commande.getTable());
|
267 |
sel.addSelectStar(commande.getTable());
|
264 |
Where w = new Where(commande.getTable().getField("EN_COURS"), "=", Boolean.TRUE);
|
268 |
Where w = new Where(commande.getTable().getField("EN_COURS"), "=", Boolean.TRUE);
|
265 |
w = w.and(new Where(commande.getTable().getField("ID_FOURNISSEUR"), "=", fournisseur.getID()));
|
269 |
w = w.and(new Where(commande.getTable().getField("ID_FOURNISSEUR"), "=", fournisseur.getID()));
|
266 |
sel.setWhere(w);
|
270 |
sel.setWhere(w);
|
267 |
|
271 |
|
268 |
final List<SQLRow> rowsCmd = !useCommandeEnCours ? null
|
272 |
final List<SQLRow> rowsCmd = !useCommandeEnCours ? null
|
269 |
: (List<SQLRow>) Configuration.getInstance().getBase().getDataSource().execute(sel.asString(), SQLRowListRSH.createFromSelect(sel));
|
273 |
: (List<SQLRow>) Configuration.getInstance().getBase().getDataSource().execute(sel.asString(), SQLRowListRSH.createFromSelect(sel));
|
270 |
|
274 |
|
271 |
SwingUtilities.invokeLater(new Runnable() {
|
275 |
SwingUtilities.invokeLater(new Runnable() {
|
272 |
|
276 |
|
273 |
@Override
|
277 |
@Override
|
274 |
public void run() {
|
278 |
public void run() {
|
275 |
SQLRow commandeExistante = null;
|
279 |
SQLRow commandeExistante = null;
|
276 |
if (rowsCmd != null && rowsCmd.size() > 0) {
|
280 |
if (rowsCmd != null && rowsCmd.size() > 0) {
|
277 |
commandeExistante = rowsCmd.get(0);
|
281 |
commandeExistante = rowsCmd.get(0);
|
278 |
}
|
282 |
}
|
279 |
EditFrame frame;
|
283 |
EditFrame frame;
|
280 |
CommandeSQLComponent cmp;
|
284 |
CommandeSQLComponent cmp;
|
281 |
|
285 |
|
282 |
if (commandeExistante != null) {
|
286 |
if (commandeExistante != null) {
|
283 |
frame = new EditFrame(commande, EditMode.MODIFICATION);
|
287 |
frame = new EditFrame(commande, EditMode.MODIFICATION);
|
284 |
cmp = (CommandeSQLComponent) frame.getSQLComponent();
|
288 |
cmp = (CommandeSQLComponent) frame.getSQLComponent();
|
285 |
cmp.select(commandeExistante);
|
289 |
cmp.select(commandeExistante);
|
286 |
} else {
|
290 |
} else {
|
287 |
frame = new EditFrame(commande);
|
291 |
frame = new EditFrame(commande);
|
288 |
cmp = (CommandeSQLComponent) frame.getSQLComponent();
|
292 |
cmp = (CommandeSQLComponent) frame.getSQLComponent();
|
289 |
final SQLRowValues rowVals = new SQLRowValues(commande.getTable());
|
293 |
final SQLRowValues rowVals = new SQLRowValues(commande.getTable());
|
290 |
final SQLElement eltComm = Configuration.getInstance().getDirectory().getElement("COMMERCIAL");
|
294 |
final SQLElement eltComm = Configuration.getInstance().getDirectory().getElement("COMMERCIAL");
|
291 |
int idUser = UserManager.getInstance().getCurrentUser().getId();
|
295 |
int idUser = UserManager.getInstance().getCurrentUser().getId();
|
292 |
SQLRow rowsComm = SQLBackgroundTableCache.getInstance().getCacheForTable(eltComm.getTable()).getFirstRowContains(idUser, eltComm.getTable().getField("ID_USER_COMMON"));
|
296 |
SQLRow rowsComm = SQLBackgroundTableCache.getInstance().getCacheForTable(eltComm.getTable()).getFirstRowContains(idUser, eltComm.getTable().getField("ID_USER_COMMON"));
|
293 |
|
297 |
|
294 |
if (rowsComm != null) {
|
298 |
if (rowsComm != null) {
|
295 |
rowVals.put("ID_COMMERCIAL", rowsComm.getID());
|
299 |
rowVals.put("ID_COMMERCIAL", rowsComm.getID());
|
296 |
}
|
300 |
}
|
297 |
if (fournisseur != null && !fournisseur.isUndefined()) {
|
301 |
if (fournisseur != null && !fournisseur.isUndefined()) {
|
298 |
rowVals.put("ID_FOURNISSEUR", fournisseur.getID());
|
302 |
rowVals.put("ID_FOURNISSEUR", fournisseur.getID());
|
299 |
}
|
303 |
}
|
300 |
if (rowDevise != null) {
|
304 |
if (rowDevise != null) {
|
301 |
rowVals.put("ID_DEVISE", rowDevise.getID());
|
305 |
rowVals.put("ID_DEVISE", rowDevise.getID());
|
302 |
}
|
306 |
}
|
303 |
if (commande.getTable().contains("ID_ADRESSE")) {
|
307 |
if (commande.getTable().contains("ID_ADRESSE")) {
|
304 |
rowVals.put("ID_ADRESSE", null);
|
308 |
rowVals.put("ID_ADRESSE", null);
|
305 |
}
|
309 |
}
|
306 |
rowVals.put("NOM", ref);
|
310 |
rowVals.put("NOM", ref);
|
307 |
cmp.select(rowVals);
|
311 |
cmp.select(rowVals);
|
308 |
cmp.getRowValuesTable().getRowValuesTableModel().clearRows();
|
312 |
cmp.getRowValuesTable().getRowValuesTableModel().clearRows();
|
309 |
}
|
313 |
}
|
310 |
|
314 |
|
311 |
CommandeItemTable itemTable = cmp.getRowValuesTablePanel();
|
315 |
CommandeItemTable itemTable = cmp.getRowValuesTablePanel();
|
312 |
|
316 |
|
313 |
final RowValuesTableModel model = cmp.getRowValuesTable().getRowValuesTableModel();
|
317 |
final RowValuesTableModel model = cmp.getRowValuesTable().getRowValuesTableModel();
|
314 |
for (SQLRowValues rowValsElt : e.getValue()) {
|
318 |
for (SQLRowValues rowValsElt : e.getValue()) {
|
315 |
SQLRowValues rowValsMatch = null;
|
319 |
SQLRowValues rowValsMatch = null;
|
316 |
int index = 0;
|
320 |
int index = 0;
|
317 |
|
321 |
|
318 |
for (int i = 0; i < model.getRowCount(); i++) {
|
322 |
for (int i = 0; i < model.getRowCount(); i++) {
|
319 |
final SQLRowValues rowValsCmdElt = model.getRowValuesAt(i);
|
323 |
final SQLRowValues rowValsCmdElt = model.getRowValuesAt(i);
|
320 |
if (ReferenceArticleSQLElement.isReferenceEquals(rowValsCmdElt, rowValsElt)) {
|
324 |
if (ReferenceArticleSQLElement.isReferenceEquals(rowValsCmdElt, rowValsElt)) {
|
321 |
rowValsMatch = rowValsCmdElt;
|
325 |
rowValsMatch = rowValsCmdElt;
|
322 |
index = i;
|
326 |
index = i;
|
323 |
break;
|
327 |
break;
|
324 |
}
|
328 |
}
|
325 |
}
|
329 |
}
|
326 |
if (rowValsMatch != null) {
|
330 |
if (rowValsMatch != null) {
|
- |
|
331 |
|
327 |
final int qte = rowValsMatch.getInt("QTE");
|
332 |
int qte = rowValsMatch.getInt("QTE");
|
- |
|
333 |
BigDecimal qteUV = rowValsMatch.getBigDecimal("QTE_UNITAIRE");
|
- |
|
334 |
|
- |
|
335 |
if (rowValsMatch.getObject("ID_UNITE_VENTE") != null && rowValsMatch.getForeignID("ID_UNITE_VENTE") != UniteVenteArticleSQLElement.A_LA_PIECE) {
|
- |
|
336 |
qteUV = qteUV.multiply(new BigDecimal(qte));
|
- |
|
337 |
int qteElt = rowValsElt.getInt("QTE");
|
- |
|
338 |
BigDecimal qteUVElt = rowValsElt.getBigDecimal("QTE_UNITAIRE");
|
- |
|
339 |
qteUV = qteUV.add(qteUVElt.multiply(new BigDecimal(qteElt)));
|
- |
|
340 |
qte = 1;
|
- |
|
341 |
} else {
|
- |
|
342 |
qte += rowValsElt.getInt("QTE");
|
- |
|
343 |
}
|
- |
|
344 |
|
328 |
model.putValue(qte + rowValsElt.getInt("QTE"), index, "QTE");
|
345 |
model.putValue(qte, index, "QTE");
|
- |
|
346 |
model.putValue(qteUV, index, "QTE_UNITAIRE");
|
329 |
} else {
|
347 |
} else {
|
330 |
model.addRow(rowValsElt);
|
348 |
model.addRow(rowValsElt);
|
331 |
if (rowValsElt.getObject("ID_ARTICLE") != null && !rowValsElt.isForeignEmpty("ID_ARTICLE")) {
|
349 |
if (rowValsElt.getObject("ID_ARTICLE") != null && !rowValsElt.isForeignEmpty("ID_ARTICLE")) {
|
332 |
Object o = itemTable.tarifCompletion(rowValsElt.getForeign("ID_ARTICLE").asRow(), "PRIX_METRIQUE_HA_1");
|
350 |
Object o = itemTable.tarifCompletion(rowValsElt.getForeign("ID_ARTICLE").asRow(), "PRIX_METRIQUE_HA_1");
|
333 |
if (o != null) {
|
351 |
if (o != null) {
|
334 |
model.putValue(o, model.getRowCount() - 1, "PRIX_METRIQUE_HA_1");
|
352 |
model.putValue(o, model.getRowCount() - 1, "PRIX_METRIQUE_HA_1");
|
335 |
}
|
353 |
}
|
336 |
}
|
354 |
}
|
337 |
}
|
355 |
}
|
338 |
}
|
356 |
}
|
339 |
|
357 |
|
340 |
frame.pack();
|
358 |
frame.pack();
|
341 |
FrameUtil.show(frame);
|
359 |
FrameUtil.show(frame);
|
342 |
|
360 |
|
343 |
}
|
361 |
}
|
344 |
});
|
362 |
});
|
- |
|
363 |
}
|
- |
|
364 |
} else {
|
- |
|
365 |
SwingUtilities.invokeLater(new Runnable() {
|
345 |
|
366 |
|
- |
|
367 |
@Override
|
- |
|
368 |
public void run() {
|
- |
|
369 |
JOptionPane.showMessageDialog(null, "Aucune commande à passer", "Commande fournisseur", JOptionPane.INFORMATION_MESSAGE);
|
346 |
}
|
370 |
}
|
347 |
|
371 |
|
- |
|
372 |
});
|
348 |
}
|
373 |
}
|
349 |
|
374 |
|
350 |
}
|
375 |
}
|
351 |
|
376 |
|
352 |
@Override
|
377 |
@Override
|
353 |
protected void _initListRequest(ListSQLRequest req) {
|
378 |
protected void _initListRequest(ListSQLRequest req) {
|
354 |
super._initListRequest(req);
|
379 |
super._initListRequest(req);
|
355 |
req.addToGraphToFetch("SOURCE", "IDSOURCE");
|
380 |
req.addToGraphToFetch("SOURCE", "IDSOURCE");
|
356 |
}
|
381 |
}
|
357 |
|
382 |
|
358 |
public static final void showSource(final int id) {
|
383 |
public static final void showSource(final int id) {
|
359 |
if (!SwingUtilities.isEventDispatchThread()) {
|
384 |
if (!SwingUtilities.isEventDispatchThread()) {
|
360 |
throw new IllegalStateException("This method must be called from EDT");
|
385 |
throw new IllegalStateException("This method must be called from EDT");
|
361 |
}
|
386 |
}
|
362 |
if (id != 1) {
|
387 |
if (id != 1) {
|
363 |
final SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
|
388 |
final SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
|
364 |
final SQLTable tableMvt = base.getTable("MOUVEMENT_STOCK");
|
389 |
final SQLTable tableMvt = base.getTable("MOUVEMENT_STOCK");
|
365 |
final String stringTableSource = tableMvt.getRow(id).getString("SOURCE");
|
390 |
final String stringTableSource = tableMvt.getRow(id).getString("SOURCE");
|
366 |
SwingUtilities.invokeLater(new Runnable() {
|
391 |
SwingUtilities.invokeLater(new Runnable() {
|
367 |
public void run() {
|
392 |
public void run() {
|
368 |
|
393 |
|
369 |
final EditFrame f;
|
394 |
final EditFrame f;
|
370 |
// Si une source est associée on l'affiche en readonly
|
395 |
// Si une source est associée on l'affiche en readonly
|
371 |
if (stringTableSource.trim().length() != 0 && tableMvt.getRow(id).getInt("IDSOURCE") != 1) {
|
396 |
if (stringTableSource.trim().length() != 0 && tableMvt.getRow(id).getInt("IDSOURCE") != 1) {
|
372 |
f = new EditFrame(Configuration.getInstance().getDirectory().getElement(stringTableSource), EditPanel.READONLY);
|
397 |
f = new EditFrame(Configuration.getInstance().getDirectory().getElement(stringTableSource), EditPanel.READONLY);
|
373 |
f.selectionId(tableMvt.getRow(id).getInt("IDSOURCE"));
|
398 |
f.selectionId(tableMvt.getRow(id).getInt("IDSOURCE"));
|
374 |
} else {
|
399 |
} else {
|
375 |
// Sinon on affiche le mouvement de stock
|
400 |
// Sinon on affiche le mouvement de stock
|
376 |
f = new EditFrame(Configuration.getInstance().getDirectory().getElement(tableMvt), EditPanel.READONLY);
|
401 |
f = new EditFrame(Configuration.getInstance().getDirectory().getElement(tableMvt), EditPanel.READONLY);
|
377 |
f.selectionId(id);
|
402 |
f.selectionId(id);
|
378 |
}
|
403 |
}
|
379 |
f.pack();
|
404 |
f.pack();
|
380 |
FrameUtil.show(f);
|
405 |
FrameUtil.show(f);
|
381 |
|
406 |
|
382 |
}
|
407 |
}
|
383 |
});
|
408 |
});
|
384 |
} else {
|
409 |
} else {
|
385 |
System.err.println("Aucun mouvement associé, impossible de modifier ou d'accéder à la source de cette ecriture!");
|
410 |
System.err.println("Aucun mouvement associé, impossible de modifier ou d'accéder à la source de cette ecriture!");
|
386 |
}
|
411 |
}
|
387 |
}
|
412 |
}
|
388 |
|
413 |
|
389 |
@Override
|
414 |
@Override
|
390 |
protected String createCode() {
|
415 |
protected String createCode() {
|
391 |
return createCodeOfPackage() + ".transaction";
|
416 |
return createCodeOfPackage() + ".transaction";
|
392 |
}
|
417 |
}
|
393 |
}
|
418 |
}
|