18 |
ilm |
1 |
/*
|
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
|
|
3 |
*
|
|
|
4 |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
|
|
|
5 |
*
|
|
|
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
|
|
|
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.
|
|
|
10 |
*
|
|
|
11 |
* When distributing the software, include this License Header Notice in each file.
|
|
|
12 |
*/
|
|
|
13 |
|
|
|
14 |
package org.openconcerto.erp.core.common.ui;
|
|
|
15 |
|
|
|
16 |
import org.openconcerto.erp.config.ComptaPropsConfiguration;
|
93 |
ilm |
17 |
import org.openconcerto.erp.core.finance.accounting.model.CurrencyConverter;
|
18 |
ilm |
18 |
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
|
142 |
ilm |
19 |
import org.openconcerto.erp.core.sales.pos.io.BarcodeReader;
|
|
|
20 |
import org.openconcerto.erp.core.sales.pos.ui.BarcodeListener;
|
18 |
ilm |
21 |
import org.openconcerto.erp.core.sales.product.element.ReferenceArticleSQLElement;
|
94 |
ilm |
22 |
import org.openconcerto.erp.core.sales.product.element.UniteVenteArticleSQLElement;
|
|
|
23 |
import org.openconcerto.erp.core.sales.product.ui.CurrencyWithSymbolRenderer;
|
174 |
ilm |
24 |
import org.openconcerto.erp.core.sales.product.ui.DeliveredQtyRowValuesRenderer;
|
61 |
ilm |
25 |
import org.openconcerto.erp.core.sales.product.ui.QteUnitRowValuesRenderer;
|
177 |
ilm |
26 |
import org.openconcerto.erp.core.supplychain.stock.element.DepotStockSQLElement;
|
|
|
27 |
import org.openconcerto.erp.core.supplychain.stock.element.StockSQLElement;
|
18 |
ilm |
28 |
import org.openconcerto.erp.preferences.DefaultNXProps;
|
61 |
ilm |
29 |
import org.openconcerto.erp.preferences.GestionArticleGlobalPreferencePanel;
|
18 |
ilm |
30 |
import org.openconcerto.sql.Configuration;
|
|
|
31 |
import org.openconcerto.sql.element.SQLElement;
|
94 |
ilm |
32 |
import org.openconcerto.sql.model.FieldPath;
|
19 |
ilm |
33 |
import org.openconcerto.sql.model.SQLRow;
|
|
|
34 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
142 |
ilm |
35 |
import org.openconcerto.sql.model.SQLRowListRSH;
|
18 |
ilm |
36 |
import org.openconcerto.sql.model.SQLRowValues;
|
142 |
ilm |
37 |
import org.openconcerto.sql.model.SQLSelect;
|
41 |
ilm |
38 |
import org.openconcerto.sql.model.SQLTable;
|
80 |
ilm |
39 |
import org.openconcerto.sql.model.UndefinedRowValuesCache;
|
41 |
ilm |
40 |
import org.openconcerto.sql.model.Where;
|
94 |
ilm |
41 |
import org.openconcerto.sql.model.graph.Path;
|
61 |
ilm |
42 |
import org.openconcerto.sql.preferences.SQLPreferences;
|
83 |
ilm |
43 |
import org.openconcerto.sql.sqlobject.ITextArticleWithCompletionCellEditor;
|
61 |
ilm |
44 |
import org.openconcerto.sql.sqlobject.ITextWithCompletion;
|
177 |
ilm |
45 |
import org.openconcerto.sql.view.EditFrame;
|
|
|
46 |
import org.openconcerto.sql.view.EditPanel.EditMode;
|
18 |
ilm |
47 |
import org.openconcerto.sql.view.list.AutoCompletionManager;
|
|
|
48 |
import org.openconcerto.sql.view.list.CellDynamicModifier;
|
|
|
49 |
import org.openconcerto.sql.view.list.RowValuesTable;
|
|
|
50 |
import org.openconcerto.sql.view.list.RowValuesTableModel;
|
|
|
51 |
import org.openconcerto.sql.view.list.SQLTableElement;
|
65 |
ilm |
52 |
import org.openconcerto.sql.view.list.ValidStateChecker;
|
177 |
ilm |
53 |
import org.openconcerto.ui.preferences.DefaultProps;
|
90 |
ilm |
54 |
import org.openconcerto.utils.DecimalUtils;
|
142 |
ilm |
55 |
import org.openconcerto.utils.Tuple3;
|
94 |
ilm |
56 |
import org.openconcerto.utils.i18n.TranslationManager;
|
18 |
ilm |
57 |
|
174 |
ilm |
58 |
import java.awt.Component;
|
132 |
ilm |
59 |
import java.awt.event.ActionEvent;
|
177 |
ilm |
60 |
import java.awt.event.ActionListener;
|
142 |
ilm |
61 |
import java.awt.event.HierarchyEvent;
|
|
|
62 |
import java.awt.event.HierarchyListener;
|
|
|
63 |
import java.awt.event.KeyEvent;
|
132 |
ilm |
64 |
import java.awt.event.MouseAdapter;
|
|
|
65 |
import java.awt.event.MouseEvent;
|
|
|
66 |
import java.math.BigDecimal;
|
|
|
67 |
import java.math.RoundingMode;
|
|
|
68 |
import java.util.ArrayList;
|
|
|
69 |
import java.util.Arrays;
|
|
|
70 |
import java.util.Calendar;
|
|
|
71 |
import java.util.HashMap;
|
|
|
72 |
import java.util.HashSet;
|
|
|
73 |
import java.util.List;
|
|
|
74 |
import java.util.Map;
|
|
|
75 |
import java.util.Set;
|
|
|
76 |
import java.util.Vector;
|
|
|
77 |
|
|
|
78 |
import javax.swing.AbstractAction;
|
177 |
ilm |
79 |
import javax.swing.JButton;
|
142 |
ilm |
80 |
import javax.swing.JFrame;
|
174 |
ilm |
81 |
import javax.swing.JLabel;
|
132 |
ilm |
82 |
import javax.swing.JOptionPane;
|
|
|
83 |
import javax.swing.JPopupMenu;
|
|
|
84 |
import javax.swing.JTable;
|
|
|
85 |
import javax.swing.SwingUtilities;
|
|
|
86 |
import javax.swing.ToolTipManager;
|
|
|
87 |
import javax.swing.event.TableModelEvent;
|
|
|
88 |
import javax.swing.event.TableModelListener;
|
174 |
ilm |
89 |
import javax.swing.table.DefaultTableCellRenderer;
|
132 |
ilm |
90 |
import javax.swing.table.TableCellRenderer;
|
|
|
91 |
|
18 |
ilm |
92 |
public abstract class AbstractAchatArticleItemTable extends AbstractArticleItemTable {
|
|
|
93 |
|
73 |
ilm |
94 |
private AutoCompletionManager m;
|
|
|
95 |
private AutoCompletionManager m2, m3;
|
|
|
96 |
private AutoCompletionManager m4;
|
|
|
97 |
private final SQLTable tableArticle = getSQLElement().getTable().getTable("ARTICLE");
|
|
|
98 |
private SQLRowAccessor rowDevise;
|
|
|
99 |
private boolean supplierCode;
|
|
|
100 |
|
18 |
ilm |
101 |
public AbstractAchatArticleItemTable() {
|
|
|
102 |
super();
|
|
|
103 |
}
|
|
|
104 |
|
94 |
ilm |
105 |
@Override
|
|
|
106 |
protected void setModel(RowValuesTableModel model) {
|
|
|
107 |
super.setModel(model);
|
|
|
108 |
model.addTableModelListener(new TableModelListener() {
|
|
|
109 |
|
|
|
110 |
@Override
|
|
|
111 |
public void tableChanged(TableModelEvent e) {
|
|
|
112 |
|
|
|
113 |
calculTarifNomenclature();
|
|
|
114 |
|
|
|
115 |
}
|
|
|
116 |
});
|
|
|
117 |
}
|
|
|
118 |
|
18 |
ilm |
119 |
protected void init() {
|
|
|
120 |
|
|
|
121 |
final SQLElement e = getSQLElement();
|
132 |
ilm |
122 |
final SQLPreferences prefs = SQLPreferences.getMemCached(getSQLElement().getTable().getDBRoot());
|
61 |
ilm |
123 |
final boolean selectArticle = prefs.getBoolean(GestionArticleGlobalPreferencePanel.USE_CREATED_ARTICLE, false);
|
|
|
124 |
final boolean createAuto = prefs.getBoolean(GestionArticleGlobalPreferencePanel.CREATE_ARTICLE_AUTO, true);
|
142 |
ilm |
125 |
final boolean showEco = prefs.getBoolean(AbstractVenteArticleItemTable.SHOW_ECO_CONTRIBUTION_COLUMNS, false);
|
149 |
ilm |
126 |
final boolean showDmdAchat = prefs.getBoolean(GestionArticleGlobalPreferencePanel.ACTIVE_DEMANDE_ACHAT, false);
|
156 |
ilm |
127 |
final boolean showDevise = prefs.getBoolean(AbstractVenteArticleItemTable.ARTICLE_SHOW_DEVISE, false);
|
67 |
ilm |
128 |
this.supplierCode = prefs.getBoolean(GestionArticleGlobalPreferencePanel.SUPPLIER_PRODUCT_CODE, false);
|
61 |
ilm |
129 |
|
18 |
ilm |
130 |
final List<SQLTableElement> list = new Vector<SQLTableElement>();
|
94 |
ilm |
131 |
final SQLTableElement eNiveau = new SQLTableElement(e.getTable().getField("NIVEAU")) {
|
|
|
132 |
@Override
|
|
|
133 |
public void setValueFrom(SQLRowValues row, Object value) {
|
|
|
134 |
super.setValueFrom(row, value);
|
|
|
135 |
}
|
|
|
136 |
};
|
|
|
137 |
eNiveau.setRenderer(new NiveauTableCellRender());
|
|
|
138 |
eNiveau.setEditor(new NiveauTableCellEditor());
|
|
|
139 |
list.add(eNiveau);
|
18 |
ilm |
140 |
list.add(new SQLTableElement(e.getTable().getField("ID_STYLE")));
|
28 |
ilm |
141 |
|
149 |
ilm |
142 |
SQLTableElement dmdElt = null;
|
|
|
143 |
if (showDmdAchat && e.getTable().contains("ID_DEMANDE_ACHAT_ELEMENT")) {
|
|
|
144 |
dmdElt = new SQLTableElement(e.getTable().getField("ID_DEMANDE_ACHAT_ELEMENT"));
|
|
|
145 |
list.add(dmdElt);
|
|
|
146 |
}
|
|
|
147 |
|
174 |
ilm |
148 |
if (e.getTable().contains("ID_AFFAIRE")) {
|
|
|
149 |
list.add(new SQLTableElement(e.getTable().getField("ID_AFFAIRE")));
|
|
|
150 |
}
|
|
|
151 |
|
67 |
ilm |
152 |
SQLTableElement tableElementCodeFournisseur = null;
|
|
|
153 |
|
|
|
154 |
if (e.getTable().contains("ID_CODE_FOURNISSEUR") && supplierCode) {
|
|
|
155 |
tableElementCodeFournisseur = new SQLTableElement(e.getTable().getField("ID_CODE_FOURNISSEUR"), true, true, true);
|
|
|
156 |
list.add(tableElementCodeFournisseur);
|
|
|
157 |
}
|
|
|
158 |
|
174 |
ilm |
159 |
if (e.getTable().contains("ID_COMPTE_PCE")) {
|
|
|
160 |
list.add(new SQLTableElement(e.getTable().getField("ID_COMPTE_PCE")));
|
|
|
161 |
}
|
|
|
162 |
|
142 |
ilm |
163 |
SQLTableElement tableElementArticle = new SQLTableElement(e.getTable().getField("ID_ARTICLE"), true, true, true) {
|
180 |
ilm |
164 |
|
142 |
ilm |
165 |
@Override
|
|
|
166 |
public boolean isCellEditable(SQLRowValues vals, int rowIndex, int columnIndex) {
|
|
|
167 |
boolean b = super.isCellEditable(vals, rowIndex, columnIndex);
|
|
|
168 |
|
180 |
ilm |
169 |
return b && !isFromTranferred(vals);
|
|
|
170 |
|
142 |
ilm |
171 |
}
|
180 |
ilm |
172 |
|
142 |
ilm |
173 |
};
|
61 |
ilm |
174 |
list.add(tableElementArticle);
|
28 |
ilm |
175 |
|
156 |
ilm |
176 |
// Article
|
|
|
177 |
SQLTableElement tableElementDepot = new SQLTableElement(e.getTable().getField("ID_DEPOT_STOCK"), true, true, true);
|
|
|
178 |
list.add(tableElementDepot);
|
|
|
179 |
|
28 |
ilm |
180 |
if (e.getTable().getFieldsName().contains("ID_FAMILLE_ARTICLE")) {
|
|
|
181 |
final SQLTableElement tableFamille = new SQLTableElement(e.getTable().getField("ID_FAMILLE_ARTICLE"));
|
|
|
182 |
list.add(tableFamille);
|
|
|
183 |
}
|
|
|
184 |
|
142 |
ilm |
185 |
if (e.getTable().getFieldsName().contains("ID_ECO_CONTRIBUTION")) {
|
|
|
186 |
this.tableElementEcoID = new SQLTableElement(e.getTable().getField("ID_ECO_CONTRIBUTION"));
|
|
|
187 |
list.add(this.tableElementEcoID);
|
|
|
188 |
}
|
|
|
189 |
|
94 |
ilm |
190 |
if (e.getTable().getFieldsName().contains("INCOTERM")) {
|
|
|
191 |
final SQLTableElement tableElementInco = new SQLTableElement(e.getTable().getField("INCOTERM"));
|
|
|
192 |
tableElementInco.setEditable(false);
|
|
|
193 |
list.add(tableElementInco);
|
|
|
194 |
}
|
|
|
195 |
|
28 |
ilm |
196 |
if (e.getTable().getFieldsName().contains("PREBILAN")) {
|
93 |
ilm |
197 |
final SQLTableElement tableElementPre = new SQLTableElement(e.getTable().getField("PREBILAN"), BigDecimal.class);
|
|
|
198 |
tableElementPre.setRenderer(new DeviseTableCellRenderer());
|
28 |
ilm |
199 |
list.add(tableElementPre);
|
|
|
200 |
}
|
|
|
201 |
|
18 |
ilm |
202 |
// Code article
|
94 |
ilm |
203 |
final SQLTableElement tableElementCode = new SQLTableElement(e.getTable().getField("CODE"), String.class,
|
142 |
ilm |
204 |
new ITextArticleWithCompletionCellEditor(e.getTable().getTable("ARTICLE"), e.getTable().getTable("ARTICLE_FOURNISSEUR"))) {
|
|
|
205 |
@Override
|
|
|
206 |
public boolean isCellEditable(SQLRowValues vals, int rowIndex, int columnIndex) {
|
|
|
207 |
boolean b = super.isCellEditable(vals, rowIndex, columnIndex);
|
180 |
ilm |
208 |
return b && !isFromTranferred(vals);
|
142 |
ilm |
209 |
|
|
|
210 |
}
|
|
|
211 |
};
|
18 |
ilm |
212 |
list.add(tableElementCode);
|
|
|
213 |
// Désignation de l'article
|
142 |
ilm |
214 |
final SQLTableElement tableElementNom = new SQLTableElement(e.getTable().getField("NOM")) {
|
|
|
215 |
@Override
|
|
|
216 |
public boolean isCellEditable(SQLRowValues vals, int rowIndex, int columnIndex) {
|
|
|
217 |
boolean b = super.isCellEditable(vals, rowIndex, columnIndex);
|
180 |
ilm |
218 |
return b && !isFromTranferred(vals);
|
142 |
ilm |
219 |
|
|
|
220 |
}
|
|
|
221 |
};
|
18 |
ilm |
222 |
list.add(tableElementNom);
|
142 |
ilm |
223 |
|
73 |
ilm |
224 |
if (e.getTable().getFieldsName().contains("DESCRIPTIF")) {
|
|
|
225 |
final SQLTableElement tableElementDesc = new SQLTableElement(e.getTable().getField("DESCRIPTIF"));
|
|
|
226 |
list.add(tableElementDesc);
|
|
|
227 |
}
|
41 |
ilm |
228 |
if (e.getTable().getFieldsName().contains("COLORIS")) {
|
|
|
229 |
final SQLTableElement tableElementColoris = new SQLTableElement(e.getTable().getField("COLORIS"));
|
|
|
230 |
list.add(tableElementColoris);
|
|
|
231 |
}
|
18 |
ilm |
232 |
// Valeur des métriques
|
|
|
233 |
final SQLTableElement tableElement_ValeurMetrique2 = new SQLTableElement(e.getTable().getField("VALEUR_METRIQUE_2"), Float.class);
|
|
|
234 |
list.add(tableElement_ValeurMetrique2);
|
|
|
235 |
final SQLTableElement tableElement_ValeurMetrique3 = new SQLTableElement(e.getTable().getField("VALEUR_METRIQUE_3"), Float.class);
|
|
|
236 |
list.add(tableElement_ValeurMetrique3);
|
|
|
237 |
final SQLTableElement tableElement_ValeurMetrique1 = new SQLTableElement(e.getTable().getField("VALEUR_METRIQUE_1"), Float.class);
|
|
|
238 |
list.add(tableElement_ValeurMetrique1);
|
|
|
239 |
// Prix d'achat HT de la métrique 1
|
156 |
ilm |
240 |
final DeviseNumericHTConvertorCellEditor editorPAHT = new DeviseNumericHTConvertorCellEditor(e.getTable().getField("PRIX_METRIQUE_HA_1"));
|
|
|
241 |
final SQLTableElement tableElement_PrixMetrique1_AchatHT = new SQLTableElement(e.getTable().getField("PRIX_METRIQUE_HA_1"), BigDecimal.class, editorPAHT);
|
94 |
ilm |
242 |
tableElement_PrixMetrique1_AchatHT.setRenderer(new CurrencyWithSymbolRenderer());
|
18 |
ilm |
243 |
list.add(tableElement_PrixMetrique1_AchatHT);
|
19 |
ilm |
244 |
|
142 |
ilm |
245 |
if (e.getTable().getFieldsName().contains("ECO_CONTRIBUTION")) {
|
|
|
246 |
this.tableElementEco = new SQLTableElement(e.getTable().getField("ECO_CONTRIBUTION"));
|
|
|
247 |
list.add(this.tableElementEco);
|
|
|
248 |
}
|
|
|
249 |
|
19 |
ilm |
250 |
final SQLTableElement tableElement_Devise = new SQLTableElement(e.getTable().getField("ID_DEVISE"));
|
94 |
ilm |
251 |
tableElement_Devise.setEditable(false);
|
67 |
ilm |
252 |
final SQLTableElement tableElement_PA_Devise = new SQLTableElement(e.getTable().getField("PA_DEVISE"), BigDecimal.class);
|
94 |
ilm |
253 |
Path p = new Path(getSQLElement().getTable()).addForeignField("ID_DEVISE");
|
|
|
254 |
tableElement_PA_Devise.setRenderer(new CurrencyWithSymbolRenderer(new FieldPath(p, "CODE")));
|
156 |
ilm |
255 |
if (showDevise) {
|
28 |
ilm |
256 |
// Devise
|
|
|
257 |
list.add(tableElement_Devise);
|
19 |
ilm |
258 |
|
28 |
ilm |
259 |
// Prix d'achat HT devise
|
|
|
260 |
list.add(tableElement_PA_Devise);
|
|
|
261 |
}
|
18 |
ilm |
262 |
// Mode de vente
|
|
|
263 |
final SQLTableElement tableElement_ModeVente = new SQLTableElement(e.getTable().getField("ID_MODE_VENTE_ARTICLE"));
|
|
|
264 |
list.add(tableElement_ModeVente);
|
19 |
ilm |
265 |
|
18 |
ilm |
266 |
// Prix d'achat unitaire HT
|
67 |
ilm |
267 |
this.ha = new SQLTableElement(e.getTable().getField("PA_HT"), BigDecimal.class);
|
94 |
ilm |
268 |
this.ha.setRenderer(new CurrencyWithSymbolRenderer());
|
18 |
ilm |
269 |
list.add(this.ha);
|
19 |
ilm |
270 |
|
61 |
ilm |
271 |
SQLTableElement qteU = new SQLTableElement(e.getTable().getField("QTE_UNITAIRE"), BigDecimal.class) {
|
|
|
272 |
@Override
|
132 |
ilm |
273 |
public boolean isCellEditable(SQLRowValues vals, int rowIndex, int columnIndex) {
|
61 |
ilm |
274 |
|
|
|
275 |
SQLRowAccessor row = vals.getForeign("ID_UNITE_VENTE");
|
|
|
276 |
if (row != null && !row.isUndefined() && row.getBoolean("A_LA_PIECE")) {
|
|
|
277 |
return false;
|
|
|
278 |
} else {
|
132 |
ilm |
279 |
return super.isCellEditable(vals, rowIndex, columnIndex);
|
61 |
ilm |
280 |
}
|
|
|
281 |
}
|
|
|
282 |
|
|
|
283 |
@Override
|
|
|
284 |
public TableCellRenderer getTableCellRenderer() {
|
|
|
285 |
return new QteUnitRowValuesRenderer();
|
|
|
286 |
}
|
67 |
ilm |
287 |
|
|
|
288 |
protected Object getDefaultNullValue() {
|
|
|
289 |
return BigDecimal.ZERO;
|
|
|
290 |
}
|
61 |
ilm |
291 |
};
|
|
|
292 |
list.add(qteU);
|
|
|
293 |
|
|
|
294 |
SQLTableElement uniteVente = new SQLTableElement(e.getTable().getField("ID_UNITE_VENTE"));
|
|
|
295 |
list.add(uniteVente);
|
|
|
296 |
|
174 |
ilm |
297 |
SQLTableElement tableCmdElt = null;
|
|
|
298 |
if (e.getTable().contains("ID_COMMANDE_ELEMENT")) {
|
|
|
299 |
tableCmdElt = new SQLTableElement(e.getTable().getField("ID_COMMANDE_ELEMENT"));
|
|
|
300 |
tableCmdElt.setRenderer(new DefaultTableCellRenderer() {
|
|
|
301 |
@Override
|
|
|
302 |
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
|
|
|
303 |
SQLRowValues rowVals = getRowValuesTable().getRowValuesTableModel().getRowValuesAt(row);
|
|
|
304 |
|
|
|
305 |
JLabel tableCellRendererComponent = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
|
|
|
306 |
tableCellRendererComponent.setText("");
|
|
|
307 |
if (rowVals.getObject("ID_COMMANDE_ELEMENT") != null && !rowVals.isForeignEmpty("ID_COMMANDE_ELEMENT")) {
|
|
|
308 |
SQLRowAccessor rowCmdItem = rowVals.getForeign("ID_COMMANDE_ELEMENT");
|
|
|
309 |
int qte = rowCmdItem.getInt("QTE");
|
|
|
310 |
BigDecimal qteU = rowCmdItem.getBigDecimal("QTE_UNITAIRE");
|
|
|
311 |
BigDecimal qteR = rowCmdItem.getBigDecimal("QTE_RECUE");
|
|
|
312 |
qteU = qteU.multiply(new BigDecimal(qte));
|
|
|
313 |
if (qteR != null) {
|
|
|
314 |
tableCellRendererComponent.setText(qteU.subtract(qteR).setScale(2, RoundingMode.HALF_UP).toString());
|
|
|
315 |
} else {
|
|
|
316 |
tableCellRendererComponent.setText(qteU.setScale(2, RoundingMode.HALF_UP).toString());
|
|
|
317 |
}
|
|
|
318 |
}
|
|
|
319 |
|
|
|
320 |
return tableCellRendererComponent;
|
|
|
321 |
}
|
|
|
322 |
});
|
|
|
323 |
tableCmdElt.setEditable(false);
|
|
|
324 |
list.add(tableCmdElt);
|
|
|
325 |
}
|
|
|
326 |
|
180 |
ilm |
327 |
if (e.getTable().contains("ID_BON_RECEPTION_ELEMENT")) {
|
|
|
328 |
SQLTableElement tableBrElt = null;
|
|
|
329 |
tableBrElt = new SQLTableElement(e.getTable().getField("ID_BON_RECEPTION_ELEMENT"));
|
|
|
330 |
tableBrElt.setEditable(false);
|
|
|
331 |
list.add(tableBrElt);
|
|
|
332 |
}
|
|
|
333 |
|
149 |
ilm |
334 |
if (e.getTable().getFieldsName().contains("QTE_ORIGINE")) {
|
|
|
335 |
final SQLTableElement tableQteO = new SQLTableElement(e.getTable().getField("QTE_ORIGINE"));
|
|
|
336 |
tableQteO.setEditable(false);
|
|
|
337 |
list.add(tableQteO);
|
|
|
338 |
}
|
|
|
339 |
|
19 |
ilm |
340 |
// Quantité
|
|
|
341 |
final SQLTableElement qteElement = new SQLTableElement(e.getTable().getField("QTE"), Integer.class) {
|
|
|
342 |
protected Object getDefaultNullValue() {
|
|
|
343 |
return Integer.valueOf(0);
|
|
|
344 |
}
|
|
|
345 |
};
|
174 |
ilm |
346 |
if (e.getTable().getFieldsName().contains("QTE_ORIGINE")) {
|
|
|
347 |
qteElement.setRenderer(new DeliveredQtyRowValuesRenderer(false));
|
|
|
348 |
}
|
19 |
ilm |
349 |
list.add(qteElement);
|
18 |
ilm |
350 |
// TVA
|
61 |
ilm |
351 |
this.tableElementTVA = new SQLTableElement(e.getTable().getField("ID_TAXE"));
|
|
|
352 |
list.add(this.tableElementTVA);
|
18 |
ilm |
353 |
// Poids piece
|
|
|
354 |
SQLTableElement tableElementPoids = new SQLTableElement(e.getTable().getField("POIDS"), Float.class);
|
|
|
355 |
list.add(tableElementPoids);
|
|
|
356 |
|
|
|
357 |
// Poids total
|
|
|
358 |
this.tableElementPoidsTotal = new SQLTableElement(e.getTable().getField("T_POIDS"), Float.class);
|
|
|
359 |
list.add(this.tableElementPoidsTotal);
|
177 |
ilm |
360 |
// Packaging
|
|
|
361 |
if (e.getTable().contains("POIDS_COLIS_NET") && prefs.getBoolean(GestionArticleGlobalPreferencePanel.ITEM_PACKAGING, false)) {
|
18 |
ilm |
362 |
|
177 |
ilm |
363 |
SQLTableElement tareColis = new SQLTableElement(e.getTable().getField("TARE"), BigDecimal.class) {
|
|
|
364 |
@Override
|
|
|
365 |
public TableCellRenderer getTableCellRenderer() {
|
|
|
366 |
return new QteUnitRowValuesRenderer();
|
|
|
367 |
}
|
|
|
368 |
|
|
|
369 |
};
|
|
|
370 |
list.add(tareColis);
|
|
|
371 |
|
|
|
372 |
SQLTableElement poidsColis = new SQLTableElement(e.getTable().getField("POIDS_COLIS_NET"), BigDecimal.class) {
|
|
|
373 |
@Override
|
|
|
374 |
public TableCellRenderer getTableCellRenderer() {
|
|
|
375 |
return new QteUnitRowValuesRenderer();
|
|
|
376 |
}
|
|
|
377 |
|
|
|
378 |
};
|
|
|
379 |
list.add(poidsColis);
|
|
|
380 |
|
|
|
381 |
SQLTableElement nbColis = new SQLTableElement(e.getTable().getField("NB_COLIS"), Integer.class);
|
|
|
382 |
list.add(nbColis);
|
|
|
383 |
|
|
|
384 |
final SQLTableElement totalPoidsColis = new SQLTableElement(e.getTable().getField("T_POIDS_COLIS_NET"), BigDecimal.class) {
|
|
|
385 |
@Override
|
|
|
386 |
public TableCellRenderer getTableCellRenderer() {
|
|
|
387 |
return new QteUnitRowValuesRenderer();
|
|
|
388 |
}
|
|
|
389 |
|
|
|
390 |
};
|
|
|
391 |
list.add(totalPoidsColis);
|
|
|
392 |
|
|
|
393 |
poidsColis.addModificationListener(totalPoidsColis);
|
|
|
394 |
nbColis.addModificationListener(totalPoidsColis);
|
|
|
395 |
totalPoidsColis.setModifier(new CellDynamicModifier() {
|
|
|
396 |
public Object computeValueFrom(final SQLRowValues row, SQLTableElement source) {
|
|
|
397 |
final BigDecimal pdsColis = row.getBigDecimal("POIDS_COLIS_NET");
|
|
|
398 |
final Object o3 = row.getObject("NB_COLIS");
|
|
|
399 |
|
|
|
400 |
BigDecimal pdsColisTotal = BigDecimal.ZERO;
|
|
|
401 |
|
|
|
402 |
if (pdsColis != null && o3 != null) {
|
|
|
403 |
int nb = (Integer) o3;
|
|
|
404 |
pdsColisTotal = pdsColis.multiply(new BigDecimal(nb), DecimalUtils.HIGH_PRECISION);
|
|
|
405 |
}
|
|
|
406 |
return pdsColisTotal.setScale(totalPoidsColis.getDecimalDigits(), RoundingMode.HALF_UP);
|
|
|
407 |
}
|
|
|
408 |
});
|
|
|
409 |
|
|
|
410 |
final SQLTableElement totalPoidsBrut = new SQLTableElement(e.getTable().getField("T_POIDS_BRUT"), BigDecimal.class) {
|
|
|
411 |
@Override
|
|
|
412 |
public TableCellRenderer getTableCellRenderer() {
|
|
|
413 |
return new QteUnitRowValuesRenderer();
|
|
|
414 |
}
|
|
|
415 |
|
|
|
416 |
};
|
|
|
417 |
list.add(totalPoidsBrut);
|
|
|
418 |
|
|
|
419 |
tareColis.addModificationListener(totalPoidsBrut);
|
|
|
420 |
poidsColis.addModificationListener(totalPoidsBrut);
|
|
|
421 |
nbColis.addModificationListener(totalPoidsBrut);
|
|
|
422 |
this.tableElementPoidsTotal.addModificationListener(totalPoidsBrut);
|
|
|
423 |
totalPoidsBrut.setModifier(new CellDynamicModifier() {
|
|
|
424 |
public Object computeValueFrom(final SQLRowValues row, SQLTableElement source) {
|
|
|
425 |
final BigDecimal tare = row.getBigDecimal("TARE");
|
|
|
426 |
final int qte = row.getInt("QTE");
|
|
|
427 |
final BigDecimal pdsColis = row.getBigDecimal("POIDS_COLIS_NET");
|
|
|
428 |
final Object o3 = row.getObject("NB_COLIS");
|
|
|
429 |
|
|
|
430 |
BigDecimal pdsBrutTotal = BigDecimal.ZERO;
|
|
|
431 |
|
|
|
432 |
if (row.getObject("T_POIDS") != null) {
|
|
|
433 |
pdsBrutTotal = new BigDecimal(row.getFloat("T_POIDS"));
|
|
|
434 |
}
|
|
|
435 |
|
|
|
436 |
if (tare != null) {
|
|
|
437 |
pdsBrutTotal = pdsBrutTotal.add(tare.multiply(new BigDecimal(qte)));
|
|
|
438 |
}
|
|
|
439 |
|
|
|
440 |
if (pdsColis != null && o3 != null) {
|
|
|
441 |
int nb = (Integer) o3;
|
|
|
442 |
pdsBrutTotal = pdsBrutTotal.add(pdsColis.multiply(new BigDecimal(nb), DecimalUtils.HIGH_PRECISION));
|
|
|
443 |
}
|
|
|
444 |
// return row.getObject("T_POIDS_COLIS_NET");
|
|
|
445 |
return pdsBrutTotal.setScale(totalPoidsBrut.getDecimalDigits(), RoundingMode.HALF_UP);
|
|
|
446 |
}
|
|
|
447 |
});
|
|
|
448 |
|
|
|
449 |
}
|
18 |
ilm |
450 |
// Service
|
|
|
451 |
String val = DefaultNXProps.getInstance().getStringProperty("ArticleService");
|
|
|
452 |
Boolean b = Boolean.valueOf(val);
|
|
|
453 |
if (b != null && b.booleanValue()) {
|
|
|
454 |
this.service = new SQLTableElement(e.getTable().getField("SERVICE"), Boolean.class);
|
|
|
455 |
list.add(this.service);
|
|
|
456 |
}
|
|
|
457 |
|
156 |
ilm |
458 |
if (showDevise) {
|
28 |
ilm |
459 |
// Prix d'achat HT devise
|
67 |
ilm |
460 |
this.tableElementTotalDevise = new SQLTableElement(e.getTable().getField("PA_DEVISE_T"), BigDecimal.class);
|
174 |
ilm |
461 |
CurrencyWithSymbolRenderer deviseTotalRenderer = new CurrencyWithSymbolRenderer(new FieldPath(p, "CODE"));
|
|
|
462 |
deviseTotalRenderer.setHideZeroValue(true);
|
|
|
463 |
this.tableElementTotalDevise.setRenderer(deviseTotalRenderer);
|
28 |
ilm |
464 |
list.add(tableElementTotalDevise);
|
|
|
465 |
}
|
67 |
ilm |
466 |
|
|
|
467 |
SQLTableElement tableElementRemise = null;
|
|
|
468 |
if (e.getTable().contains("POURCENT_REMISE")) {
|
|
|
469 |
tableElementRemise = new SQLTableElement(e.getTable().getField("POURCENT_REMISE"));
|
|
|
470 |
list.add(tableElementRemise);
|
|
|
471 |
}
|
|
|
472 |
|
142 |
ilm |
473 |
if (e.getTable().getFieldsName().contains("T_ECO_CONTRIBUTION")) {
|
|
|
474 |
this.tableElementEcoTotal = new SQLTableElement(e.getTable().getField("T_ECO_CONTRIBUTION"));
|
|
|
475 |
list.add(this.tableElementEcoTotal);
|
|
|
476 |
}
|
|
|
477 |
|
18 |
ilm |
478 |
// Total HT
|
67 |
ilm |
479 |
this.totalHT = new SQLTableElement(e.getTable().getField("T_PA_HT"), BigDecimal.class);
|
174 |
ilm |
480 |
DeviseTableCellRenderer totalRenderer = new DeviseTableCellRenderer();
|
|
|
481 |
totalRenderer.setHideZeroValue(true);
|
|
|
482 |
this.totalHT.setRenderer(totalRenderer);
|
65 |
ilm |
483 |
this.totalHT.setEditable(false);
|
73 |
ilm |
484 |
if (e.getTable().contains("POURCENT_REMISE") && tableElementRemise != null) {
|
67 |
ilm |
485 |
tableElementRemise.addModificationListener(this.totalHT);
|
|
|
486 |
}
|
18 |
ilm |
487 |
list.add(this.totalHT);
|
67 |
ilm |
488 |
this.totalHA = this.totalHT;
|
18 |
ilm |
489 |
// Total TTC
|
67 |
ilm |
490 |
this.tableElementTotalTTC = new SQLTableElement(e.getTable().getField("T_PA_TTC"), BigDecimal.class);
|
174 |
ilm |
491 |
this.tableElementTotalTTC.setRenderer(totalRenderer);
|
18 |
ilm |
492 |
list.add(this.tableElementTotalTTC);
|
|
|
493 |
|
94 |
ilm |
494 |
this.defaultRowVals = new SQLRowValues(UndefinedRowValuesCache.getInstance().getDefaultRowValues(e.getTable()));
|
177 |
ilm |
495 |
this.defaultRowVals.put("ID_TAXE", TaxeCache.getCache().getFirstTaxeAchat().getID());
|
94 |
ilm |
496 |
this.defaultRowVals.put("CODE", "");
|
|
|
497 |
this.defaultRowVals.put("NOM", "");
|
|
|
498 |
this.defaultRowVals.put("QTE", 1);
|
|
|
499 |
this.defaultRowVals.put("QTE_UNITAIRE", BigDecimal.ONE);
|
|
|
500 |
this.defaultRowVals.put("ID_UNITE_VENTE", UniteVenteArticleSQLElement.A_LA_PIECE);
|
|
|
501 |
this.defaultRowVals.put("ID_MODE_VENTE_ARTICLE", ReferenceArticleSQLElement.A_LA_PIECE);
|
177 |
ilm |
502 |
|
|
|
503 |
if (e.getTable().contains("ID_DEPOT_STOCK")) {
|
|
|
504 |
DefaultProps props = DefaultNXProps.getInstance();
|
|
|
505 |
Integer depotDefault = props.getIntProperty("DepotStockDefault", DepotStockSQLElement.DEFAULT_ID);
|
|
|
506 |
this.defaultRowVals.put("ID_DEPOT_STOCK", depotDefault);
|
|
|
507 |
}
|
|
|
508 |
|
180 |
ilm |
509 |
final RowValuesTableModel model = new RowValuesTableModel(e, list, e.getTable().getField("QTE"), false, this.defaultRowVals) {
|
177 |
ilm |
510 |
@Override
|
|
|
511 |
public void commitData() {
|
|
|
512 |
super.commitData(true);
|
|
|
513 |
}
|
|
|
514 |
};
|
|
|
515 |
|
93 |
ilm |
516 |
setModel(model);
|
80 |
ilm |
517 |
|
93 |
ilm |
518 |
this.table = new RowValuesTable(model, getConfigurationFile());
|
18 |
ilm |
519 |
ToolTipManager.sharedInstance().unregisterComponent(this.table);
|
|
|
520 |
ToolTipManager.sharedInstance().unregisterComponent(this.table.getTableHeader());
|
177 |
ilm |
521 |
if (getSQLElement().getTable().getName().equals("COMMANDE_ELEMENT")) {
|
|
|
522 |
this.table.getClearCloneTableElement().add("QTE_RECUE");
|
|
|
523 |
this.table.getClearCloneTableElement().add("RECU");
|
|
|
524 |
this.table.getClearCloneTableElement().add("RECU_FORCED");
|
|
|
525 |
} else if (getSQLElement().getTable().getName().equals("BON_RECEPTION_ELEMENT")) {
|
|
|
526 |
this.table.getClearCloneTableElement().add("ID_COMMANDE_ELEMENT");
|
180 |
ilm |
527 |
} else if (getSQLElement().getTable().getName().equals("FACTURE_FOURNISSEUR_ELEMENT")) {
|
|
|
528 |
if (getSQLElement().getTable().contains("ID_COMMANDE_ELEMENT")) {
|
|
|
529 |
this.table.getClearCloneTableElement().add("ID_COMMANDE_ELEMENT");
|
|
|
530 |
}
|
|
|
531 |
if (getSQLElement().getTable().contains("ID_BON_RECEPTION_ELEMENT")) {
|
|
|
532 |
this.table.getClearCloneTableElement().add("ID_BON_RECEPTION_ELEMENT");
|
|
|
533 |
}
|
177 |
ilm |
534 |
}
|
18 |
ilm |
535 |
|
94 |
ilm |
536 |
table.addMouseListener(new MouseAdapter() {
|
|
|
537 |
@Override
|
|
|
538 |
public void mouseReleased(MouseEvent e) {
|
132 |
ilm |
539 |
handlePopup(e);
|
|
|
540 |
}
|
|
|
541 |
|
|
|
542 |
@Override
|
|
|
543 |
public void mousePressed(MouseEvent e) {
|
|
|
544 |
handlePopup(e);
|
|
|
545 |
}
|
|
|
546 |
|
|
|
547 |
public void handlePopup(MouseEvent e) {
|
94 |
ilm |
548 |
final int rowindex = table.getSelectedRow();
|
|
|
549 |
if (rowindex < 0)
|
|
|
550 |
return;
|
|
|
551 |
if (e.isPopupTrigger() && e.getComponent() instanceof JTable) {
|
|
|
552 |
JPopupMenu popup = new JPopupMenu();
|
132 |
ilm |
553 |
if (prefs.getBoolean(GestionArticleGlobalPreferencePanel.CAN_EXPAND_NOMENCLATURE_HA, true)) {
|
|
|
554 |
popup.add(new AbstractAction(TranslationManager.getInstance().getTranslationForItem("product.bom.expand")) {
|
94 |
ilm |
555 |
|
132 |
ilm |
556 |
@Override
|
|
|
557 |
public void actionPerformed(ActionEvent arg0) {
|
|
|
558 |
expandNomenclature(rowindex, m, EXPAND_TYPE.EXPAND);
|
|
|
559 |
}
|
|
|
560 |
});
|
|
|
561 |
popup.add(new AbstractAction(TranslationManager.getInstance().getTranslationForItem("product.bom.expose")) {
|
94 |
ilm |
562 |
|
132 |
ilm |
563 |
@Override
|
|
|
564 |
public void actionPerformed(ActionEvent arg0) {
|
|
|
565 |
expandNomenclature(rowindex, m, EXPAND_TYPE.VIEW_ONLY);
|
|
|
566 |
}
|
|
|
567 |
});
|
|
|
568 |
popup.add(new AbstractAction(TranslationManager.getInstance().getTranslationForItem("product.bom.flat")) {
|
94 |
ilm |
569 |
|
132 |
ilm |
570 |
@Override
|
|
|
571 |
public void actionPerformed(ActionEvent arg0) {
|
|
|
572 |
expandNomenclature(rowindex, m, EXPAND_TYPE.FLAT);
|
|
|
573 |
}
|
|
|
574 |
});
|
|
|
575 |
}
|
94 |
ilm |
576 |
for (AbstractAction action : getAdditionnalMouseAction(rowindex)) {
|
|
|
577 |
popup.add(action);
|
|
|
578 |
}
|
|
|
579 |
|
|
|
580 |
popup.show(e.getComponent(), e.getX(), e.getY());
|
|
|
581 |
}
|
|
|
582 |
}
|
|
|
583 |
});
|
|
|
584 |
|
18 |
ilm |
585 |
// Autocompletion
|
149 |
ilm |
586 |
if (dmdElt != null) {
|
|
|
587 |
AutoCompletionManager dmd = new AutoCompletionManager(dmdElt, ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete().getField("DEMANDE_ACHAT_ELEMENT.ID"), this.table,
|
|
|
588 |
this.table.getRowValuesTableModel(), ITextWithCompletion.MODE_CONTAINS, true, true, new ValidStateChecker());
|
|
|
589 |
dmd.fill("ID_FAMILLE_ARTICLE", "ID_FAMILLE_ARTICLE");
|
|
|
590 |
}
|
28 |
ilm |
591 |
List<String> completionFields = new ArrayList<String>();
|
132 |
ilm |
592 |
if (e.getTable().getFieldsName().contains("INCOTERM")) {
|
|
|
593 |
completionFields.add("INCOTERM");
|
|
|
594 |
}
|
142 |
ilm |
595 |
if (e.getTable().getFieldsName().contains("ID_ECO_CONTRIBUTION")) {
|
|
|
596 |
completionFields.add("ID_ECO_CONTRIBUTION");
|
|
|
597 |
}
|
61 |
ilm |
598 |
completionFields.add("ID_UNITE_VENTE");
|
156 |
ilm |
599 |
completionFields.add("QTE_UNITAIRE");
|
28 |
ilm |
600 |
completionFields.add("PA_HT");
|
|
|
601 |
completionFields.add("PV_HT");
|
|
|
602 |
completionFields.add("POIDS");
|
|
|
603 |
completionFields.add("ID_TAXE");
|
|
|
604 |
completionFields.add("PRIX_METRIQUE_HA_1");
|
|
|
605 |
completionFields.add("PRIX_METRIQUE_HA_2");
|
|
|
606 |
completionFields.add("PRIX_METRIQUE_HA_3");
|
|
|
607 |
completionFields.add("VALEUR_METRIQUE_1");
|
|
|
608 |
completionFields.add("VALEUR_METRIQUE_2");
|
|
|
609 |
completionFields.add("VALEUR_METRIQUE_3");
|
|
|
610 |
completionFields.add("ID_MODE_VENTE_ARTICLE");
|
|
|
611 |
completionFields.add("PRIX_METRIQUE_VT_1");
|
|
|
612 |
completionFields.add("PRIX_METRIQUE_VT_2");
|
|
|
613 |
completionFields.add("PRIX_METRIQUE_VT_3");
|
|
|
614 |
completionFields.add("SERVICE");
|
|
|
615 |
completionFields.add("ID_DEVISE");
|
|
|
616 |
completionFields.add("PA_DEVISE");
|
41 |
ilm |
617 |
if (e.getTable().getFieldsName().contains("COLORIS")) {
|
|
|
618 |
completionFields.add("COLORIS");
|
|
|
619 |
}
|
132 |
ilm |
620 |
|
73 |
ilm |
621 |
if (e.getTable().getFieldsName().contains("DESCRIPTIF")) {
|
|
|
622 |
completionFields.add("DESCRIPTIF");
|
|
|
623 |
}
|
28 |
ilm |
624 |
if (e.getTable().getFieldsName().contains("ID_FAMILLE_ARTICLE")) {
|
|
|
625 |
completionFields.add("ID_FAMILLE_ARTICLE");
|
|
|
626 |
}
|
177 |
ilm |
627 |
final SQLTable sqlTableArticle = e.getTable().getTable("ARTICLE");
|
|
|
628 |
if (getSQLElement().getTable().getFieldsName().contains("POIDS_COLIS_NET") && sqlTableArticle.getTable().getFieldsName().contains("POIDS_COLIS_NET")) {
|
|
|
629 |
completionFields.add("POIDS_COLIS_NET");
|
|
|
630 |
}
|
|
|
631 |
if (getSQLElement().getTable().getFieldsName().contains("TARE") && sqlTableArticle.getTable().getFieldsName().contains("TARE")) {
|
|
|
632 |
completionFields.add("TARE");
|
|
|
633 |
}
|
|
|
634 |
this.m = new AutoCompletionManager(tableElementCode, sqlTableArticle.getField("CODE"), this.table, this.table.getRowValuesTableModel()) {
|
19 |
ilm |
635 |
@Override
|
93 |
ilm |
636 |
protected Object getValueFrom(SQLRow row, String field, SQLRowAccessor rowDest) {
|
19 |
ilm |
637 |
Object res = tarifCompletion(row, field);
|
|
|
638 |
if (res == null) {
|
93 |
ilm |
639 |
return super.getValueFrom(row, field, rowDest);
|
19 |
ilm |
640 |
} else {
|
|
|
641 |
return res;
|
|
|
642 |
}
|
|
|
643 |
}
|
|
|
644 |
};
|
18 |
ilm |
645 |
m.fill("NOM", "NOM");
|
61 |
ilm |
646 |
m.fill("ID", "ID_ARTICLE");
|
177 |
ilm |
647 |
if (e.getTable().contains("ID_CODE_FOURNISSEUR") && supplierCode) {
|
|
|
648 |
m.fill("ID_CODE_FOURNISSEUR", "ID_CODE_FOURNISSEUR");
|
|
|
649 |
}
|
28 |
ilm |
650 |
for (String string : completionFields) {
|
|
|
651 |
m.fill(string, string);
|
|
|
652 |
}
|
93 |
ilm |
653 |
final Where w = new Where(sqlTableArticle.getField("OBSOLETE"), "=", Boolean.FALSE);
|
|
|
654 |
m.setWhere(w);
|
|
|
655 |
|
41 |
ilm |
656 |
this.m2 = new AutoCompletionManager(tableElementNom, ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete().getField("ARTICLE.NOM"), this.table,
|
19 |
ilm |
657 |
this.table.getRowValuesTableModel()) {
|
|
|
658 |
@Override
|
93 |
ilm |
659 |
protected Object getValueFrom(SQLRow row, String field, SQLRowAccessor rowDest) {
|
19 |
ilm |
660 |
Object res = tarifCompletion(row, field);
|
|
|
661 |
if (res == null) {
|
93 |
ilm |
662 |
return super.getValueFrom(row, field, rowDest);
|
19 |
ilm |
663 |
} else {
|
|
|
664 |
return res;
|
|
|
665 |
}
|
|
|
666 |
}
|
|
|
667 |
};
|
18 |
ilm |
668 |
m2.fill("CODE", "CODE");
|
61 |
ilm |
669 |
m2.fill("ID", "ID_ARTICLE");
|
28 |
ilm |
670 |
for (String string : completionFields) {
|
|
|
671 |
m2.fill(string, string);
|
|
|
672 |
}
|
93 |
ilm |
673 |
m2.setWhere(w);
|
28 |
ilm |
674 |
|
61 |
ilm |
675 |
this.m3 = new AutoCompletionManager(tableElementArticle, ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete().getField("ARTICLE.NOM"), this.table,
|
65 |
ilm |
676 |
this.table.getRowValuesTableModel(), ITextWithCompletion.MODE_CONTAINS, true, true, new ValidStateChecker()) {
|
61 |
ilm |
677 |
@Override
|
93 |
ilm |
678 |
protected Object getValueFrom(SQLRow row, String field, SQLRowAccessor rowDest) {
|
61 |
ilm |
679 |
Object res = tarifCompletion(row, field);
|
|
|
680 |
if (res == null) {
|
93 |
ilm |
681 |
return super.getValueFrom(row, field, rowDest);
|
61 |
ilm |
682 |
} else {
|
|
|
683 |
return res;
|
|
|
684 |
}
|
|
|
685 |
}
|
|
|
686 |
};
|
|
|
687 |
m3.fill("CODE", "CODE");
|
|
|
688 |
m3.fill("NOM", "NOM");
|
|
|
689 |
for (String string : completionFields) {
|
|
|
690 |
m3.fill(string, string);
|
|
|
691 |
}
|
93 |
ilm |
692 |
m3.setWhere(w);
|
28 |
ilm |
693 |
|
67 |
ilm |
694 |
if (e.getTable().contains("ID_CODE_FOURNISSEUR") && supplierCode) {
|
|
|
695 |
this.m4 = new AutoCompletionManager(tableElementCodeFournisseur, ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete().getField("ARTICLE.NOM"), this.table,
|
|
|
696 |
this.table.getRowValuesTableModel(), ITextWithCompletion.MODE_CONTAINS, true, true, new ValidStateChecker()) {
|
|
|
697 |
@Override
|
93 |
ilm |
698 |
protected Object getValueFrom(SQLRow row, String field, SQLRowAccessor rowDest) {
|
67 |
ilm |
699 |
Object res = tarifCompletion(row, field);
|
|
|
700 |
if (res == null) {
|
93 |
ilm |
701 |
return super.getValueFrom(row, field, rowDest);
|
67 |
ilm |
702 |
} else {
|
|
|
703 |
return res;
|
|
|
704 |
}
|
|
|
705 |
}
|
|
|
706 |
};
|
177 |
ilm |
707 |
m4.fill("ID", "ID_ARTICLE");
|
67 |
ilm |
708 |
m4.fill("CODE", "CODE");
|
|
|
709 |
m4.fill("NOM", "NOM");
|
|
|
710 |
for (String string : completionFields) {
|
|
|
711 |
m4.fill(string, string);
|
|
|
712 |
}
|
|
|
713 |
}
|
|
|
714 |
|
|
|
715 |
tableElementCode.addModificationListener(tableElementArticle);
|
|
|
716 |
tableElementArticle.setModifier(new CellDynamicModifier() {
|
|
|
717 |
@Override
|
93 |
ilm |
718 |
public Object computeValueFrom(SQLRowValues row, SQLTableElement source) {
|
83 |
ilm |
719 |
try {
|
|
|
720 |
SQLRowAccessor foreign = row.getForeign("ID_ARTICLE");
|
|
|
721 |
if (foreign != null && !foreign.isUndefined() && foreign.getObject("CODE") != null && foreign.getString("CODE").equals(row.getString("CODE"))) {
|
|
|
722 |
return foreign.getID();
|
|
|
723 |
} else {
|
|
|
724 |
return tableArticle.getUndefinedID();
|
|
|
725 |
}
|
|
|
726 |
} catch (Exception e) {
|
67 |
ilm |
727 |
return tableArticle.getUndefinedID();
|
|
|
728 |
}
|
|
|
729 |
}
|
|
|
730 |
});
|
|
|
731 |
|
142 |
ilm |
732 |
// ECO Contribution
|
|
|
733 |
if (this.tableElementEco != null && this.tableElementEcoTotal != null && this.tableElementEcoID != null) {
|
|
|
734 |
qteElement.addModificationListener(this.tableElementEcoTotal);
|
|
|
735 |
this.tableElementEco.addModificationListener(this.tableElementEcoTotal);
|
|
|
736 |
this.tableElementEcoTotal.setModifier(new CellDynamicModifier() {
|
|
|
737 |
public Object computeValueFrom(final SQLRowValues row, SQLTableElement source) {
|
|
|
738 |
|
|
|
739 |
int qte = Integer.parseInt(row.getObject("QTE").toString());
|
|
|
740 |
BigDecimal f = (row.getObject("ECO_CONTRIBUTION") == null) ? BigDecimal.ZERO : (BigDecimal) row.getObject("ECO_CONTRIBUTION");
|
|
|
741 |
return f.multiply(new BigDecimal(qte));
|
|
|
742 |
}
|
|
|
743 |
|
|
|
744 |
});
|
|
|
745 |
this.tableElementEcoID.addModificationListener(this.tableElementEco);
|
|
|
746 |
this.tableElementEco.setModifier(new CellDynamicModifier() {
|
|
|
747 |
public Object computeValueFrom(final SQLRowValues row, SQLTableElement source) {
|
|
|
748 |
|
|
|
749 |
if (source.equals(tableElementEcoID)) {
|
|
|
750 |
return row.getForeign("ID_ECO_CONTRIBUTION").getBigDecimal("TAUX");
|
|
|
751 |
} else {
|
|
|
752 |
return row.getObject("ECO_CONTRIBUTION");
|
|
|
753 |
}
|
|
|
754 |
}
|
|
|
755 |
});
|
|
|
756 |
}
|
|
|
757 |
|
18 |
ilm |
758 |
// Calcul automatique du total HT
|
|
|
759 |
qteElement.addModificationListener(this.totalHT);
|
61 |
ilm |
760 |
qteU.addModificationListener(this.totalHT);
|
18 |
ilm |
761 |
this.ha.addModificationListener(this.totalHT);
|
|
|
762 |
this.totalHT.setModifier(new CellDynamicModifier() {
|
93 |
ilm |
763 |
public Object computeValueFrom(final SQLRowValues row, SQLTableElement source) {
|
18 |
ilm |
764 |
|
|
|
765 |
int qte = Integer.parseInt(row.getObject("QTE").toString());
|
83 |
ilm |
766 |
BigDecimal f = (row.getObject("PA_HT") == null) ? BigDecimal.ZERO : (BigDecimal) row.getObject("PA_HT");
|
61 |
ilm |
767 |
BigDecimal b = (row.getObject("QTE_UNITAIRE") == null) ? BigDecimal.ONE : (BigDecimal) row.getObject("QTE_UNITAIRE");
|
90 |
ilm |
768 |
BigDecimal r = b.multiply(f.multiply(BigDecimal.valueOf(qte)), DecimalUtils.HIGH_PRECISION).setScale(totalHT.getDecimalDigits(), BigDecimal.ROUND_HALF_UP);
|
67 |
ilm |
769 |
|
|
|
770 |
if (row.getTable().contains("POURCENT_REMISE")) {
|
|
|
771 |
final Object o2 = row.getObject("POURCENT_REMISE");
|
|
|
772 |
|
|
|
773 |
BigDecimal lremise = (o2 == null) ? BigDecimal.ZERO : ((BigDecimal) o2);
|
|
|
774 |
if (lremise.compareTo(BigDecimal.ZERO) >= 0 && lremise.compareTo(BigDecimal.valueOf(100)) < 0) {
|
|
|
775 |
|
|
|
776 |
r = r.multiply(new BigDecimal(100).subtract(lremise).movePointLeft(2)).setScale(totalHT.getDecimalDigits(), BigDecimal.ROUND_HALF_UP);
|
|
|
777 |
}
|
|
|
778 |
}
|
|
|
779 |
|
|
|
780 |
return r;
|
18 |
ilm |
781 |
}
|
|
|
782 |
|
|
|
783 |
});
|
156 |
ilm |
784 |
if (showDevise) {
|
93 |
ilm |
785 |
|
|
|
786 |
if (tableElement_PA_Devise != null) {
|
|
|
787 |
tableElement_PA_Devise.addModificationListener(tableElement_PrixMetrique1_AchatHT);
|
|
|
788 |
}
|
|
|
789 |
|
|
|
790 |
if (tableElement_PA_Devise != null) {
|
|
|
791 |
tableElement_PrixMetrique1_AchatHT.addModificationListener(tableElement_PA_Devise);
|
|
|
792 |
|
|
|
793 |
tableElement_PA_Devise.setModifier(new CellDynamicModifier() {
|
|
|
794 |
public Object computeValueFrom(SQLRowValues row, SQLTableElement source) {
|
|
|
795 |
if (source != null && source.getField().getName().equals("PA_DEVISE")) {
|
|
|
796 |
return row.getObject("PA_DEVISE");
|
|
|
797 |
} else {
|
142 |
ilm |
798 |
if (!row.isForeignEmpty("ID_DEVISE") && row.getForeign("ID_DEVISE") != null) {
|
93 |
ilm |
799 |
String devCode = row.getForeign("ID_DEVISE").getString("CODE");
|
|
|
800 |
BigDecimal bigDecimal = (BigDecimal) row.getObject("PRIX_METRIQUE_HA_1");
|
|
|
801 |
|
|
|
802 |
CurrencyConverter c = new CurrencyConverter();
|
94 |
ilm |
803 |
BigDecimal result = convert(bigDecimal, devCode, true);
|
93 |
ilm |
804 |
if (result == null) {
|
|
|
805 |
JOptionPane.showMessageDialog(AbstractAchatArticleItemTable.this, "Unable to convert " + bigDecimal + " from " + c.getCompanyCurrencyCode() + " to " + devCode);
|
|
|
806 |
return BigDecimal.ZERO;
|
|
|
807 |
}
|
|
|
808 |
return result;
|
|
|
809 |
} else if (source != null && source.getField().getName().equalsIgnoreCase("PRIX_METRIQUE_HA_1")) {
|
|
|
810 |
return row.getObject("PRIX_METRIQUE_HA_1");
|
|
|
811 |
}
|
|
|
812 |
return row.getObject("PA_DEVISE");
|
|
|
813 |
}
|
|
|
814 |
}
|
|
|
815 |
|
|
|
816 |
});
|
|
|
817 |
}
|
|
|
818 |
|
28 |
ilm |
819 |
qteElement.addModificationListener(this.tableElementTotalDevise);
|
61 |
ilm |
820 |
qteU.addModificationListener(this.tableElementTotalDevise);
|
28 |
ilm |
821 |
tableElement_PA_Devise.addModificationListener(this.tableElementTotalDevise);
|
73 |
ilm |
822 |
if (e.getTable().contains("POURCENT_REMISE") && tableElementRemise != null) {
|
67 |
ilm |
823 |
tableElementRemise.addModificationListener(this.tableElementTotalDevise);
|
|
|
824 |
}
|
28 |
ilm |
825 |
this.tableElementTotalDevise.setModifier(new CellDynamicModifier() {
|
93 |
ilm |
826 |
public Object computeValueFrom(final SQLRowValues row, SQLTableElement source) {
|
28 |
ilm |
827 |
int qte = Integer.parseInt(row.getObject("QTE").toString());
|
67 |
ilm |
828 |
BigDecimal f = (BigDecimal) row.getObject("PA_DEVISE");
|
61 |
ilm |
829 |
BigDecimal b = (row.getObject("QTE_UNITAIRE") == null) ? BigDecimal.ONE : (BigDecimal) row.getObject("QTE_UNITAIRE");
|
90 |
ilm |
830 |
BigDecimal r = b.multiply(f.multiply(BigDecimal.valueOf(qte)), DecimalUtils.HIGH_PRECISION).setScale(tableElementTotalDevise.getDecimalDigits(), BigDecimal.ROUND_HALF_UP);
|
67 |
ilm |
831 |
|
|
|
832 |
if (row.getTable().contains("POURCENT_REMISE")) {
|
|
|
833 |
final Object o2 = row.getObject("POURCENT_REMISE");
|
|
|
834 |
BigDecimal lremise = (o2 == null) ? BigDecimal.ZERO : ((BigDecimal) o2);
|
|
|
835 |
if (lremise.compareTo(BigDecimal.ZERO) >= 0 && lremise.compareTo(BigDecimal.valueOf(100)) < 0) {
|
|
|
836 |
|
|
|
837 |
r = r.multiply(new BigDecimal(100).subtract(lremise).movePointLeft(2)).setScale(tableElementTotalDevise.getDecimalDigits(), BigDecimal.ROUND_HALF_UP);
|
|
|
838 |
}
|
|
|
839 |
}
|
61 |
ilm |
840 |
return r;
|
28 |
ilm |
841 |
}
|
19 |
ilm |
842 |
|
28 |
ilm |
843 |
});
|
|
|
844 |
}
|
18 |
ilm |
845 |
// Calcul automatique du total TTC
|
|
|
846 |
qteElement.addModificationListener(this.tableElementTotalTTC);
|
61 |
ilm |
847 |
qteU.addModificationListener(this.tableElementTotalTTC);
|
18 |
ilm |
848 |
this.ha.addModificationListener(this.tableElementTotalTTC);
|
61 |
ilm |
849 |
this.tableElementTVA.addModificationListener(this.tableElementTotalTTC);
|
18 |
ilm |
850 |
this.tableElementTotalTTC.setModifier(new CellDynamicModifier() {
|
|
|
851 |
@Override
|
93 |
ilm |
852 |
public Object computeValueFrom(SQLRowValues row, SQLTableElement source) {
|
18 |
ilm |
853 |
int qte = Integer.parseInt(row.getObject("QTE").toString());
|
67 |
ilm |
854 |
BigDecimal f = (BigDecimal) row.getObject("PA_HT");
|
18 |
ilm |
855 |
int idTaux = Integer.parseInt(row.getObject("ID_TAXE").toString());
|
177 |
ilm |
856 |
Float resultTaux = TaxeCache.getCache().getTauxFromId(idTaux);
|
|
|
857 |
if (resultTaux == null) {
|
|
|
858 |
SQLRow rowTax = TaxeCache.getCache().getFirstTaxe();
|
|
|
859 |
row.put("ID_TAXE", rowTax.getID());
|
|
|
860 |
resultTaux = rowTax.getFloat("TAUX");
|
18 |
ilm |
861 |
}
|
156 |
ilm |
862 |
editorPAHT.setTaxe(resultTaux);
|
61 |
ilm |
863 |
BigDecimal b = (row.getObject("QTE_UNITAIRE") == null) ? BigDecimal.ONE : (BigDecimal) row.getObject("QTE_UNITAIRE");
|
90 |
ilm |
864 |
BigDecimal r = b.multiply(f.multiply(BigDecimal.valueOf(qte), DecimalUtils.HIGH_PRECISION), DecimalUtils.HIGH_PRECISION).setScale(tableElementTotalTTC.getDecimalDigits(),
|
67 |
ilm |
865 |
BigDecimal.ROUND_HALF_UP);
|
73 |
ilm |
866 |
float taux = (resultTaux == null) ? 0.0F : resultTaux.floatValue();
|
67 |
ilm |
867 |
|
|
|
868 |
BigDecimal total = r.multiply(BigDecimal.ONE.add(new BigDecimal(taux / 100f))).setScale(tableElementTotalTTC.getDecimalDigits(), RoundingMode.HALF_UP);
|
61 |
ilm |
869 |
return total;
|
18 |
ilm |
870 |
}
|
|
|
871 |
|
|
|
872 |
});
|
|
|
873 |
|
|
|
874 |
this.table.readState();
|
|
|
875 |
|
|
|
876 |
// Mode Gestion article avancé
|
|
|
877 |
String valModeAvanceVt = DefaultNXProps.getInstance().getStringProperty("ArticleModeVenteAvance");
|
|
|
878 |
Boolean bModeAvance = Boolean.valueOf(valModeAvanceVt);
|
28 |
ilm |
879 |
boolean view = !(bModeAvance != null && !bModeAvance.booleanValue());
|
93 |
ilm |
880 |
setColumnVisible(model.getColumnForField("VALEUR_METRIQUE_1"), view);
|
|
|
881 |
setColumnVisible(model.getColumnForField("VALEUR_METRIQUE_2"), view);
|
|
|
882 |
setColumnVisible(model.getColumnForField("VALEUR_METRIQUE_3"), view);
|
|
|
883 |
setColumnVisible(model.getColumnForField("PRIX_METRIQUE_VT_1"), view);
|
|
|
884 |
setColumnVisible(model.getColumnForField("ID_MODE_VENTE_ARTICLE"), view);
|
|
|
885 |
setColumnVisible(model.getColumnForField("PA_HT"), view);
|
18 |
ilm |
886 |
|
142 |
ilm |
887 |
if (e.getTable().contains("ID_COMMANDE_ELEMENT")) {
|
|
|
888 |
setColumnVisible(model.getColumnForField("ID_COMMANDE_ELEMENT"), false);
|
|
|
889 |
}
|
|
|
890 |
|
180 |
ilm |
891 |
if (e.getTable().contains("ID_BON_RECEPTION_ELEMENT")) {
|
|
|
892 |
setColumnVisible(model.getColumnForField("ID_BON_RECEPTION_ELEMENT"), false);
|
|
|
893 |
}
|
|
|
894 |
|
61 |
ilm |
895 |
// Gestion des unités de vente
|
|
|
896 |
final boolean gestionUV = prefs.getBoolean(GestionArticleGlobalPreferencePanel.UNITE_VENTE, true);
|
93 |
ilm |
897 |
setColumnVisible(model.getColumnForField("QTE_UNITAIRE"), gestionUV);
|
|
|
898 |
setColumnVisible(model.getColumnForField("ID_UNITE_VENTE"), gestionUV);
|
61 |
ilm |
899 |
|
93 |
ilm |
900 |
setColumnVisible(model.getColumnForField("ID_STYLE"), DefaultNXProps.getInstance().getBooleanValue("ArticleShowStyle", true));
|
61 |
ilm |
901 |
|
142 |
ilm |
902 |
if (this.tableElementEco != null && this.tableElementEcoTotal != null && this.tableElementEcoID != null) {
|
|
|
903 |
setColumnVisible(model.getColumnForField("ID_ECO_CONTRIBUTION"), showEco);
|
|
|
904 |
setColumnVisible(model.getColumnForField("ECO_CONTRIBUTION"), showEco);
|
|
|
905 |
setColumnVisible(model.getColumnForField("T_ECO_CONTRIBUTION"), showEco);
|
|
|
906 |
}
|
|
|
907 |
|
93 |
ilm |
908 |
setColumnVisible(model.getColumnForField("ID_ARTICLE"), selectArticle);
|
|
|
909 |
setColumnVisible(model.getColumnForField("CODE"), !selectArticle || (selectArticle && createAuto));
|
|
|
910 |
setColumnVisible(model.getColumnForField("NOM"), !selectArticle || (selectArticle && createAuto));
|
61 |
ilm |
911 |
|
156 |
ilm |
912 |
setColumnVisible(model.getColumnForField("ID_DEPOT_STOCK"), prefs.getBoolean(GestionArticleGlobalPreferencePanel.STOCK_MULTI_DEPOT, false));
|
|
|
913 |
|
177 |
ilm |
914 |
setColumnVisible(model.getColumnForField("T_POIDS_COLIS_NET"), false);
|
|
|
915 |
setColumnVisible(model.getColumnForField("T_POIDS_BRUT"), false);
|
|
|
916 |
|
18 |
ilm |
917 |
// Calcul automatique du poids unitaire
|
|
|
918 |
tableElement_ValeurMetrique1.addModificationListener(tableElementPoids);
|
|
|
919 |
tableElement_ValeurMetrique2.addModificationListener(tableElementPoids);
|
|
|
920 |
tableElement_ValeurMetrique3.addModificationListener(tableElementPoids);
|
|
|
921 |
tableElementPoids.setModifier(new CellDynamicModifier() {
|
93 |
ilm |
922 |
public Object computeValueFrom(SQLRowValues row, SQLTableElement source) {
|
18 |
ilm |
923 |
return new Float(ReferenceArticleSQLElement.getPoidsFromDetails(row));
|
|
|
924 |
}
|
|
|
925 |
|
|
|
926 |
});
|
|
|
927 |
// Calcul automatique du poids total
|
|
|
928 |
tableElementPoids.addModificationListener(this.tableElementPoidsTotal);
|
|
|
929 |
qteElement.addModificationListener(this.tableElementPoidsTotal);
|
61 |
ilm |
930 |
qteU.addModificationListener(this.tableElementPoidsTotal);
|
18 |
ilm |
931 |
this.tableElementPoidsTotal.setModifier(new CellDynamicModifier() {
|
93 |
ilm |
932 |
public Object computeValueFrom(SQLRowValues row, SQLTableElement source) {
|
73 |
ilm |
933 |
|
65 |
ilm |
934 |
Number f = (row.getObject("POIDS") == null) ? 0 : (Number) row.getObject("POIDS");
|
18 |
ilm |
935 |
int qte = Integer.parseInt(row.getObject("QTE").toString());
|
61 |
ilm |
936 |
|
|
|
937 |
BigDecimal b = (row.getObject("QTE_UNITAIRE") == null) ? BigDecimal.ONE : (BigDecimal) row.getObject("QTE_UNITAIRE");
|
|
|
938 |
// FIXME convertir en float autrement pour éviter une valeur non transposable
|
|
|
939 |
// avec floatValue ou passer POIDS en bigDecimal
|
|
|
940 |
return b.multiply(new BigDecimal(f.floatValue() * qte)).floatValue();
|
18 |
ilm |
941 |
}
|
|
|
942 |
|
|
|
943 |
});
|
|
|
944 |
|
93 |
ilm |
945 |
tableElement_PrixMetrique1_AchatHT.setModifier(new CellDynamicModifier() {
|
|
|
946 |
public Object computeValueFrom(SQLRowValues row, SQLTableElement source) {
|
|
|
947 |
if (source != null && source.getField().getName().equals("PRIX_METRIQUE_HA_1")) {
|
|
|
948 |
return row.getObject("PRIX_METRIQUE_HA_1");
|
|
|
949 |
} else {
|
|
|
950 |
if (source != null && source.getField().getName().equals("PA_DEVISE")) {
|
142 |
ilm |
951 |
if (!row.isForeignEmpty("ID_DEVISE") && row.getForeign("ID_DEVISE") != null) {
|
93 |
ilm |
952 |
String devCode = row.getForeign("ID_DEVISE").getString("CODE");
|
|
|
953 |
BigDecimal bigDecimal = (BigDecimal) row.getObject("PA_DEVISE");
|
|
|
954 |
|
94 |
ilm |
955 |
return convert(bigDecimal, devCode, false);
|
93 |
ilm |
956 |
} else {
|
|
|
957 |
return row.getObject("PRIX_METRIQUE_HA_1");
|
|
|
958 |
}
|
|
|
959 |
}
|
|
|
960 |
return row.getObject("PRIX_METRIQUE_HA_1");
|
|
|
961 |
}
|
|
|
962 |
}
|
|
|
963 |
|
|
|
964 |
});
|
|
|
965 |
|
18 |
ilm |
966 |
// Calcul automatique du prix d'achat unitaire HT
|
|
|
967 |
tableElement_ValeurMetrique1.addModificationListener(this.ha);
|
|
|
968 |
tableElement_ValeurMetrique2.addModificationListener(this.ha);
|
|
|
969 |
tableElement_ValeurMetrique3.addModificationListener(this.ha);
|
|
|
970 |
tableElement_PrixMetrique1_AchatHT.addModificationListener(this.ha);
|
|
|
971 |
this.ha.setModifier(new CellDynamicModifier() {
|
93 |
ilm |
972 |
public Object computeValueFrom(SQLRowValues row, SQLTableElement source) {
|
18 |
ilm |
973 |
|
93 |
ilm |
974 |
if (row.isForeignEmpty("ID_MODE_VENTE_ARTICLE") || row.getInt("ID_MODE_VENTE_ARTICLE") == ReferenceArticleSQLElement.A_LA_PIECE) {
|
67 |
ilm |
975 |
return row.getObject("PRIX_METRIQUE_HA_1");
|
18 |
ilm |
976 |
} else {
|
|
|
977 |
|
67 |
ilm |
978 |
final BigDecimal prixHAFromDetails = ReferenceArticleSQLElement.getPrixHAFromDetails(row);
|
|
|
979 |
return prixHAFromDetails.setScale(ha.getDecimalDigits(), RoundingMode.HALF_UP);
|
18 |
ilm |
980 |
}
|
|
|
981 |
|
|
|
982 |
}
|
|
|
983 |
|
|
|
984 |
});
|
|
|
985 |
|
61 |
ilm |
986 |
uniteVente.addModificationListener(qteU);
|
|
|
987 |
qteU.setModifier(new CellDynamicModifier() {
|
93 |
ilm |
988 |
public Object computeValueFrom(SQLRowValues row, SQLTableElement source) {
|
61 |
ilm |
989 |
SQLRowAccessor rowUnite = row.getForeign("ID_UNITE_VENTE");
|
|
|
990 |
if (rowUnite != null && !rowUnite.isUndefined() && rowUnite.getBoolean("A_LA_PIECE")) {
|
|
|
991 |
return BigDecimal.ONE;
|
|
|
992 |
} else {
|
|
|
993 |
return row.getObject("QTE_UNITAIRE");
|
|
|
994 |
}
|
|
|
995 |
}
|
|
|
996 |
|
|
|
997 |
});
|
132 |
ilm |
998 |
// La devise est renseignée globalement dans la commande et est reportée automatiquement sur
|
|
|
999 |
// les lignes
|
|
|
1000 |
setColumnVisible(model.getColumnIndexForElement(tableElement_Devise), false);
|
28 |
ilm |
1001 |
for (String string : visibilityMap.keySet()) {
|
93 |
ilm |
1002 |
setColumnVisible(model.getColumnForField(string), visibilityMap.get(string));
|
28 |
ilm |
1003 |
}
|
|
|
1004 |
|
142 |
ilm |
1005 |
// Barcode reader
|
|
|
1006 |
final BarcodeReader barcodeReader = ComptaPropsConfiguration.getInstanceCompta().getBarcodeReader();
|
|
|
1007 |
if (barcodeReader != null) {
|
|
|
1008 |
|
|
|
1009 |
final BarcodeListener l = new BarcodeListener() {
|
|
|
1010 |
|
|
|
1011 |
@Override
|
|
|
1012 |
public void keyReceived(KeyEvent ee) {
|
|
|
1013 |
// TODO Auto-generated method stub
|
|
|
1014 |
}
|
|
|
1015 |
|
|
|
1016 |
@Override
|
|
|
1017 |
public void barcodeRead(String code) {
|
|
|
1018 |
if (((JFrame) SwingUtilities.getRoot(getRowValuesTable())).isActive()) {
|
|
|
1019 |
final SQLSelect selArticle = new SQLSelect();
|
|
|
1020 |
final SQLTable tableArticle = getSQLElement().getForeignElement("ID_ARTICLE").getTable();
|
|
|
1021 |
selArticle.addSelectStar(tableArticle);
|
|
|
1022 |
Where w = new Where(tableArticle.getField("OBSOLETE"), "=", Boolean.FALSE);
|
|
|
1023 |
w = w.and(new Where(tableArticle.getField("CODE_BARRE"), "=", code));
|
|
|
1024 |
selArticle.setWhere(w);
|
|
|
1025 |
List<SQLRow> l2 = SQLRowListRSH.execute(selArticle);
|
|
|
1026 |
if (l2.size() > 0) {
|
|
|
1027 |
System.err.println("ARTICLE " + l2.get(0).getString("NOM"));
|
|
|
1028 |
Tuple3<Double, String, String> art = Tuple3.create(1.0D, l2.get(0).getString("CODE"), l2.get(0).getString("NOM"));
|
|
|
1029 |
List<Tuple3<Double, String, String>> l = new ArrayList<Tuple3<Double, String, String>>();
|
|
|
1030 |
l.add(art);
|
|
|
1031 |
insertFromDrop(l, m);
|
|
|
1032 |
} else {
|
|
|
1033 |
System.err.println("ARTICLE NOT FOUND !");
|
|
|
1034 |
}
|
|
|
1035 |
}
|
|
|
1036 |
|
|
|
1037 |
}
|
|
|
1038 |
};
|
|
|
1039 |
getRowValuesTable().addHierarchyListener(new HierarchyListener() {
|
|
|
1040 |
public void hierarchyChanged(HierarchyEvent e) {
|
|
|
1041 |
if ((e.getChangeFlags() & HierarchyEvent.DISPLAYABILITY_CHANGED) != 0)
|
|
|
1042 |
if (getRowValuesTable().isDisplayable()) {
|
|
|
1043 |
barcodeReader.addBarcodeListener(l);
|
|
|
1044 |
} else {
|
|
|
1045 |
barcodeReader.removeBarcodeListener(l);
|
|
|
1046 |
}
|
|
|
1047 |
}
|
|
|
1048 |
});
|
|
|
1049 |
|
|
|
1050 |
}
|
|
|
1051 |
|
19 |
ilm |
1052 |
// On réécrit la configuration au cas ou les preferences aurait changé
|
18 |
ilm |
1053 |
this.table.writeState();
|
177 |
ilm |
1054 |
|
|
|
1055 |
if (this.table.getRowValuesTableModel().getColumnForField("ID_DEPOT_STOCK") >= 0 && this.table.getRowValuesTableModel().getColumnForField("ID_ARTICLE") >= 0) {
|
|
|
1056 |
if (this.buttons == null) {
|
|
|
1057 |
this.buttons = new ArrayList<>();
|
|
|
1058 |
}
|
|
|
1059 |
|
|
|
1060 |
JButton buttonStock = new JButton("Consulter le stock");
|
|
|
1061 |
buttonStock.addActionListener(new ActionListener() {
|
|
|
1062 |
public void actionPerformed(ActionEvent event) {
|
|
|
1063 |
SQLRowValues rowValsSel = table.getSelectedRowValues();
|
|
|
1064 |
if (rowValsSel != null) {
|
|
|
1065 |
SQLRowAccessor foreignArt = rowValsSel.getForeign("ID_ARTICLE");
|
|
|
1066 |
if (foreignArt != null && !foreignArt.isUndefined()) {
|
|
|
1067 |
SQLRowAccessor rowValsStock = StockSQLElement.getStock(rowValsSel);
|
|
|
1068 |
if (rowValsStock != null && !rowValsStock.isUndefined()) {
|
|
|
1069 |
EditFrame frame = new EditFrame(table.getRowValuesTableModel().getSQLElement().getDirectory().getElement("STOCK"), EditMode.READONLY);
|
|
|
1070 |
frame.selectionId(rowValsStock.getID());
|
|
|
1071 |
frame.setVisible(true);
|
|
|
1072 |
}
|
|
|
1073 |
}
|
|
|
1074 |
}
|
|
|
1075 |
|
|
|
1076 |
}
|
|
|
1077 |
});
|
|
|
1078 |
|
|
|
1079 |
this.buttons.add(buttonStock);
|
|
|
1080 |
|
|
|
1081 |
}
|
18 |
ilm |
1082 |
}
|
|
|
1083 |
|
28 |
ilm |
1084 |
private static Map<String, Boolean> visibilityMap = new HashMap<String, Boolean>();
|
|
|
1085 |
|
|
|
1086 |
public static Map<String, Boolean> getVisibilityMap() {
|
|
|
1087 |
return visibilityMap;
|
|
|
1088 |
}
|
|
|
1089 |
|
132 |
ilm |
1090 |
private String incoterm = "";
|
|
|
1091 |
|
|
|
1092 |
public void setIncoterms(String incoterm) {
|
|
|
1093 |
if (incoterm == null) {
|
|
|
1094 |
incoterm = "";
|
|
|
1095 |
}
|
|
|
1096 |
this.incoterm = incoterm;
|
|
|
1097 |
}
|
|
|
1098 |
|
|
|
1099 |
private SQLRow rowFournisseur = null;
|
|
|
1100 |
|
67 |
ilm |
1101 |
public void setFournisseur(SQLRow rowFournisseur) {
|
132 |
ilm |
1102 |
this.rowFournisseur = rowFournisseur;
|
67 |
ilm |
1103 |
if (getSQLElement().getTable().contains("ID_CODE_FOURNISSEUR") && this.supplierCode) {
|
|
|
1104 |
|
|
|
1105 |
if (rowFournisseur != null && !rowFournisseur.isUndefined()) {
|
|
|
1106 |
Where w = new Where(getSQLElement().getTable().getTable("CODE_FOURNISSEUR").getField("ID_FOURNISSEUR"), "=", rowFournisseur.getID());
|
|
|
1107 |
this.m4.setWhere(w);
|
|
|
1108 |
} else {
|
|
|
1109 |
this.m4.setWhere(null);
|
|
|
1110 |
}
|
|
|
1111 |
}
|
|
|
1112 |
}
|
|
|
1113 |
|
93 |
ilm |
1114 |
private BigDecimal getPrice(final SQLRowAccessor r, List<String> list) {
|
|
|
1115 |
BigDecimal result = r.getBigDecimal(list.get(0));
|
|
|
1116 |
|
|
|
1117 |
for (int i = 1; i < list.size(); i++) {
|
|
|
1118 |
BigDecimal m0 = r.getBigDecimal(list.get(i));
|
|
|
1119 |
if (m0 != null && m0.floatValue() > 0) {
|
|
|
1120 |
result = result.divide(m0, 2, RoundingMode.HALF_UP);
|
|
|
1121 |
}
|
|
|
1122 |
}
|
|
|
1123 |
return result;
|
|
|
1124 |
}
|
|
|
1125 |
|
149 |
ilm |
1126 |
public Object tarifCompletion(SQLRow row, String field) {
|
132 |
ilm |
1127 |
final SQLTable tTarifFournisseur = this.getSQLElement().getTable().getDBRoot().getTable("ARTICLE_TARIF_FOURNISSEUR");
|
94 |
ilm |
1128 |
|
177 |
ilm |
1129 |
if (row != null && !row.isUndefined() && (field.equalsIgnoreCase("ID_CODE_FOURNISSEUR")) && this.rowFournisseur != null && !this.rowFournisseur.isUndefined()) {
|
|
|
1130 |
final SQLTable foreignTableCodeF = getSQLElement().getTable().getForeignTable("ID_CODE_FOURNISSEUR");
|
|
|
1131 |
List<SQLRow> resultCode = row.getReferentRows(foreignTableCodeF);
|
|
|
1132 |
int idCode = foreignTableCodeF.getUndefinedID();
|
|
|
1133 |
for (SQLRow sqlRow : resultCode) {
|
|
|
1134 |
if (sqlRow.getForeignID("ID_FOURNISSEUR") == this.rowFournisseur.getID()) {
|
|
|
1135 |
return sqlRow.getID();
|
|
|
1136 |
}
|
|
|
1137 |
|
|
|
1138 |
}
|
|
|
1139 |
return idCode;
|
|
|
1140 |
}
|
|
|
1141 |
if (field.equalsIgnoreCase("ID_CODE_FOURNISSEUR")) {
|
|
|
1142 |
final SQLTable foreignTableCodeF = getSQLElement().getTable().getForeignTable("ID_CODE_FOURNISSEUR");
|
|
|
1143 |
return foreignTableCodeF.getUndefinedID();
|
|
|
1144 |
}
|
|
|
1145 |
|
174 |
ilm |
1146 |
if (row != null && !row.isUndefined() && (field.equalsIgnoreCase("PRIX_METRIQUE_HA_1") || field.equalsIgnoreCase("PA_HT")) && tTarifFournisseur != null) {
|
132 |
ilm |
1147 |
List<String> incoTerms;
|
|
|
1148 |
|
|
|
1149 |
if (this.incoterm != null && this.incoterm.equalsIgnoreCase("CPT")) {
|
|
|
1150 |
incoTerms = Arrays.asList("PRIX_ACHAT", "COEF_TRANSPORT_PORT");
|
|
|
1151 |
} else if (this.incoterm != null && this.incoterm.equalsIgnoreCase("DDP")) {
|
|
|
1152 |
incoTerms = Arrays.asList("PRIX_ACHAT", "COEF_TRANSPORT_PORT", "COEF_TAXE_D");
|
|
|
1153 |
} else {
|
|
|
1154 |
incoTerms = Arrays.asList("PRIX_ACHAT");
|
|
|
1155 |
}
|
93 |
ilm |
1156 |
List<SQLRow> rows = row.getReferentRows(tTarifFournisseur);
|
177 |
ilm |
1157 |
if (row.getBoolean("AUTO_PRIX_ACHAT_NOMENCLATURE") && row.getTable().getDBRoot().contains("ARTICLE_PRIX_REVIENT")) {
|
19 |
ilm |
1158 |
|
132 |
ilm |
1159 |
List<SQLRow> rowsElt = row.getReferentRows(row.getTable().getTable("ARTICLE_ELEMENT").getField("ID_ARTICLE_PARENT"));
|
|
|
1160 |
BigDecimal price = BigDecimal.ZERO;
|
|
|
1161 |
final Set<String> tarifNotFound = new HashSet<String>();
|
|
|
1162 |
for (SQLRow sqlRow : rowsElt) {
|
|
|
1163 |
List<SQLRow> rowsT = sqlRow.getForeign("ID_ARTICLE").getReferentRows(tTarifFournisseur);
|
94 |
ilm |
1164 |
|
132 |
ilm |
1165 |
boolean priceFound = false;
|
|
|
1166 |
boolean tarifFound = false;
|
|
|
1167 |
if (rowsT.size() > 0) {
|
|
|
1168 |
BigDecimal min = BigDecimal.ZERO;
|
|
|
1169 |
|
174 |
ilm |
1170 |
BigDecimal defaultPrice = sqlRow.getForeign("ID_ARTICLE").getBigDecimal("PRIX_METRIQUE_HA_1");
|
132 |
ilm |
1171 |
Calendar c = null;
|
|
|
1172 |
for (SQLRow sqlRowT : rowsT) {
|
|
|
1173 |
if (this.rowFournisseur != null && this.rowFournisseur.getID() == sqlRowT.getForeignID("ID_FOURNISSEUR")) {
|
|
|
1174 |
BigDecimal priceT = getPrice(sqlRowT, incoTerms);
|
|
|
1175 |
defaultPrice = priceT;
|
|
|
1176 |
final Calendar datePrice = sqlRowT.getDate("DATE_PRIX");
|
142 |
ilm |
1177 |
datePrice.set(Calendar.HOUR, 0);
|
|
|
1178 |
datePrice.set(Calendar.MINUTE, 0);
|
|
|
1179 |
datePrice.set(Calendar.SECOND, 0);
|
|
|
1180 |
datePrice.set(Calendar.MILLISECOND, 0);
|
132 |
ilm |
1181 |
if (datePrice == null || (this.getDateDevise() != null && !this.getDateDevise().before(datePrice.getTime()))) {
|
|
|
1182 |
if (c == null || c.before(datePrice)) {
|
|
|
1183 |
|
|
|
1184 |
min = priceT;
|
|
|
1185 |
c = datePrice;
|
|
|
1186 |
priceFound = true;
|
|
|
1187 |
} else if (c != null) {
|
|
|
1188 |
defaultPrice = priceT;
|
|
|
1189 |
}
|
|
|
1190 |
}
|
|
|
1191 |
tarifFound = true;
|
|
|
1192 |
}
|
|
|
1193 |
}
|
|
|
1194 |
|
|
|
1195 |
if (priceFound) {
|
|
|
1196 |
price = price.add(min.multiply(sqlRow.getBigDecimal("QTE_UNITAIRE").multiply(new BigDecimal(sqlRow.getInt("QTE"), DecimalUtils.HIGH_PRECISION))));
|
|
|
1197 |
} else {
|
|
|
1198 |
price = price.add(defaultPrice.multiply(sqlRow.getBigDecimal("QTE_UNITAIRE").multiply(new BigDecimal(sqlRow.getInt("QTE"), DecimalUtils.HIGH_PRECISION))));
|
|
|
1199 |
}
|
|
|
1200 |
}
|
|
|
1201 |
if (!tarifFound) {
|
|
|
1202 |
tarifNotFound.add(sqlRow.getForeign("ID_ARTICLE").getString("CODE"));
|
|
|
1203 |
}
|
93 |
ilm |
1204 |
}
|
132 |
ilm |
1205 |
if (!tarifNotFound.isEmpty()) {
|
|
|
1206 |
SwingUtilities.invokeLater(new Runnable() {
|
93 |
ilm |
1207 |
|
132 |
ilm |
1208 |
@Override
|
|
|
1209 |
public void run() {
|
|
|
1210 |
JOptionPane.showMessageDialog(AbstractAchatArticleItemTable.this.table,
|
|
|
1211 |
"Attention, impossible de calculer le tarif.\nLes articles suivants n'ont pas de tarif associé :\n" + tarifNotFound);
|
|
|
1212 |
}
|
|
|
1213 |
});
|
|
|
1214 |
}
|
|
|
1215 |
return price;
|
|
|
1216 |
} else if (!rows.isEmpty()) {
|
174 |
ilm |
1217 |
|
|
|
1218 |
BigDecimal min = row.getBigDecimal("PRIX_METRIQUE_HA_1");
|
|
|
1219 |
|
132 |
ilm |
1220 |
Calendar c = null;
|
93 |
ilm |
1221 |
for (SQLRow sqlRow : rows) {
|
132 |
ilm |
1222 |
if (this.rowFournisseur != null && this.rowFournisseur.getID() == sqlRow.getForeignID("ID_FOURNISSEUR")) {
|
|
|
1223 |
BigDecimal price = getPrice(sqlRow, incoTerms);
|
|
|
1224 |
final Calendar datePrice = sqlRow.getDate("DATE_PRIX");
|
|
|
1225 |
if (datePrice == null || (this.getDateDevise() != null && !this.getDateDevise().before(datePrice.getTime()))) {
|
|
|
1226 |
if (c == null || c.before(datePrice)) {
|
|
|
1227 |
min = price;
|
|
|
1228 |
c = datePrice;
|
|
|
1229 |
}
|
|
|
1230 |
}
|
93 |
ilm |
1231 |
}
|
|
|
1232 |
}
|
94 |
ilm |
1233 |
return min.setScale(2, RoundingMode.HALF_UP);
|
93 |
ilm |
1234 |
}
|
|
|
1235 |
}
|
94 |
ilm |
1236 |
if (field.equalsIgnoreCase("INCOTERM")) {
|
132 |
ilm |
1237 |
// if (tTarifFournisseur != null) {
|
|
|
1238 |
// List<SQLRow> rows = row.getReferentRows(tTarifFournisseur);
|
|
|
1239 |
// if (!rows.isEmpty()) {
|
|
|
1240 |
// final SQLRow sqlRow0 = rows.get(0);
|
|
|
1241 |
// return sqlRow0.getString("CONDITIONS");
|
|
|
1242 |
// }
|
|
|
1243 |
// }
|
|
|
1244 |
return this.incoterm;
|
94 |
ilm |
1245 |
}
|
93 |
ilm |
1246 |
|
19 |
ilm |
1247 |
if (getDevise() != null && !getDevise().isUndefined()) {
|
|
|
1248 |
if ((field.equalsIgnoreCase("ID_DEVISE") || field.equalsIgnoreCase("ID_DEVISE_HA"))) {
|
|
|
1249 |
return getDevise().getID();
|
|
|
1250 |
} else if ((field.equalsIgnoreCase("PA_DEVISE"))) {
|
132 |
ilm |
1251 |
if (row.getBigDecimal("PA_DEVISE") != null && row.getBigDecimal("PA_DEVISE").signum() != 0 && this.incoterm.length() == 0) {
|
93 |
ilm |
1252 |
return row.getBigDecimal("PA_DEVISE");
|
|
|
1253 |
} else {
|
132 |
ilm |
1254 |
String devCode = getDevise().getString("CODE");
|
93 |
ilm |
1255 |
|
132 |
ilm |
1256 |
BigDecimal tarifCompletion = (BigDecimal) tarifCompletion(row, "PRIX_METRIQUE_HA_1");
|
|
|
1257 |
if (tarifCompletion == null) {
|
|
|
1258 |
tarifCompletion = row.getBigDecimal("PRIX_METRIQUE_HA_1");
|
93 |
ilm |
1259 |
}
|
132 |
ilm |
1260 |
if (tarifCompletion == null) {
|
|
|
1261 |
return null;
|
|
|
1262 |
} else {
|
|
|
1263 |
// Remove set scale 2 --> if scale ex : PA = 95.74MAD --> 0.76592€
|
|
|
1264 |
// with Scale 0.77€ so put 96.25MAD in PA
|
|
|
1265 |
return convert(tarifCompletion, devCode, true);
|
|
|
1266 |
}
|
93 |
ilm |
1267 |
}
|
132 |
ilm |
1268 |
|
19 |
ilm |
1269 |
}
|
|
|
1270 |
} else {
|
|
|
1271 |
if ((field.equalsIgnoreCase("ID_DEVISE") || field.equalsIgnoreCase("ID_DEVISE_HA"))) {
|
|
|
1272 |
return Configuration.getInstance().getDirectory().getElement("DEVISE").getTable().getUndefinedID();
|
|
|
1273 |
} else if ((field.equalsIgnoreCase("PA_DEVISE"))) {
|
|
|
1274 |
|
67 |
ilm |
1275 |
return BigDecimal.ZERO;
|
19 |
ilm |
1276 |
}
|
156 |
ilm |
1277 |
|
19 |
ilm |
1278 |
}
|
156 |
ilm |
1279 |
if (field.equalsIgnoreCase("ID_TAXE") && this.rowCatComptable != null) {
|
|
|
1280 |
return this.rowCatComptable.getForeignID("ID_TAXE_VENTE");
|
|
|
1281 |
}
|
19 |
ilm |
1282 |
return null;
|
132 |
ilm |
1283 |
|
19 |
ilm |
1284 |
}
|
|
|
1285 |
|
93 |
ilm |
1286 |
@Override
|
|
|
1287 |
protected void refreshDeviseAmount() {
|
|
|
1288 |
int count = getRowValuesTable().getRowCount();
|
|
|
1289 |
final int columnForField = getRowValuesTable().getRowValuesTableModel().getColumnForField("PA_DEVISE");
|
|
|
1290 |
if (columnForField >= 0) {
|
|
|
1291 |
SQLTableElement eltDevise = getRowValuesTable().getRowValuesTableModel().getSQLTableElementAt(columnForField);
|
|
|
1292 |
for (int i = 0; i < count; i++) {
|
|
|
1293 |
SQLRowValues rowVals = getRowValuesTable().getRowValuesTableModel().getRowValuesAt(i);
|
|
|
1294 |
// getRowValuesTable().getRowValuesTableModel().putValue(rowVals.getObject("PV_U_DEVISE"),
|
|
|
1295 |
// i, "PV_U_DEVISE", true);
|
|
|
1296 |
eltDevise.setValueFrom(rowVals, rowVals.getObject("PA_DEVISE"));
|
|
|
1297 |
getRowValuesTable().getRowValuesTableModel().fireTableChanged(new TableModelEvent(getRowValuesTable().getRowValuesTableModel(), i, i, columnForField));
|
|
|
1298 |
}
|
|
|
1299 |
}
|
|
|
1300 |
}
|
|
|
1301 |
|
19 |
ilm |
1302 |
public SQLRowAccessor getDevise() {
|
|
|
1303 |
return this.rowDevise;
|
|
|
1304 |
}
|
|
|
1305 |
|
|
|
1306 |
public void setDevise(SQLRowAccessor deviseRow) {
|
|
|
1307 |
this.rowDevise = deviseRow;
|
94 |
ilm |
1308 |
if (deviseRow == null) {
|
|
|
1309 |
getDefaultRowValues().put("ID_DEVISE", null);
|
|
|
1310 |
} else {
|
|
|
1311 |
getDefaultRowValues().put("ID_DEVISE", this.rowDevise.getID());
|
|
|
1312 |
}
|
19 |
ilm |
1313 |
}
|
41 |
ilm |
1314 |
|
94 |
ilm |
1315 |
private BigDecimal tauxConversion = null;
|
|
|
1316 |
|
|
|
1317 |
public void setTauxConversion(BigDecimal tauxConversion) {
|
|
|
1318 |
if (tauxConversion != null && tauxConversion.signum() == 0) {
|
|
|
1319 |
tauxConversion = null;
|
|
|
1320 |
}
|
|
|
1321 |
this.tauxConversion = tauxConversion;
|
|
|
1322 |
refreshDeviseAmount();
|
|
|
1323 |
}
|
|
|
1324 |
|
|
|
1325 |
public BigDecimal convert(BigDecimal val, String devCode, boolean fromCompanyCurrency) {
|
|
|
1326 |
if (val == null) {
|
|
|
1327 |
return val;
|
|
|
1328 |
}
|
|
|
1329 |
if (this.tauxConversion == null) {
|
|
|
1330 |
CurrencyConverter c = new CurrencyConverter();
|
|
|
1331 |
if (fromCompanyCurrency) {
|
|
|
1332 |
return c.convert(val, c.getCompanyCurrencyCode(), devCode, getDateDevise(), isUsedBiasedDevise());
|
|
|
1333 |
} else {
|
|
|
1334 |
return c.convert(val, devCode, c.getCompanyCurrencyCode(), getDateDevise(), isUsedBiasedDevise());
|
|
|
1335 |
}
|
|
|
1336 |
} else {
|
|
|
1337 |
if (fromCompanyCurrency) {
|
|
|
1338 |
return val.divide(this.tauxConversion, DecimalUtils.HIGH_PRECISION).setScale(val.scale(), RoundingMode.HALF_UP);
|
|
|
1339 |
} else {
|
|
|
1340 |
return val.multiply(this.tauxConversion, DecimalUtils.HIGH_PRECISION).setScale(val.scale(), RoundingMode.HALF_UP);
|
|
|
1341 |
}
|
|
|
1342 |
}
|
|
|
1343 |
}
|
|
|
1344 |
|
41 |
ilm |
1345 |
public void setFournisseurFilterOnCompletion(SQLRow row) {
|
93 |
ilm |
1346 |
final SQLTable sqlTableArticle = ((ComptaPropsConfiguration) Configuration.getInstance()).getRootSociete().getTable("ARTICLE");
|
|
|
1347 |
Where w = new Where(sqlTableArticle.getField("OBSOLETE"), "=", Boolean.FALSE);
|
41 |
ilm |
1348 |
if (row != null && !row.isUndefined()) {
|
93 |
ilm |
1349 |
w = w.and(new Where(this.tableArticle.getField("ID_FOURNISSEUR"), "=", row.getID()));
|
41 |
ilm |
1350 |
}
|
93 |
ilm |
1351 |
this.m.setWhere(w);
|
|
|
1352 |
this.m2.setWhere(w);
|
|
|
1353 |
this.m3.setWhere(w);
|
41 |
ilm |
1354 |
}
|
|
|
1355 |
|
142 |
ilm |
1356 |
private void insertFromDrop(List<Tuple3<Double, String, String>> articles, AutoCompletionManager m) {
|
94 |
ilm |
1357 |
|
142 |
ilm |
1358 |
List<String> code = new ArrayList<String>(articles.size());
|
|
|
1359 |
for (int i = articles.size() - 1; i >= 0; i--) {
|
94 |
ilm |
1360 |
|
142 |
ilm |
1361 |
Tuple3<Double, String, String> tuple = articles.get(i);
|
|
|
1362 |
code.add(tuple.get1());
|
|
|
1363 |
}
|
94 |
ilm |
1364 |
|
142 |
ilm |
1365 |
int rowCount = getRowValuesTable().getRowValuesTableModel().getRowCount();
|
|
|
1366 |
Map<Integer, Integer> mapRows = new HashMap<Integer, Integer>();
|
|
|
1367 |
for (int i = 0; i < rowCount; i++) {
|
|
|
1368 |
SQLRowValues rowVals = getRowValuesTable().getRowValuesTableModel().getRowValuesAt(i);
|
|
|
1369 |
if (rowVals.getObject("ID_ARTICLE") != null && !rowVals.isForeignEmpty("ID_ARTICLE")) {
|
|
|
1370 |
mapRows.put(rowVals.getForeignID("ID_ARTICLE"), i);
|
|
|
1371 |
}
|
|
|
1372 |
}
|
94 |
ilm |
1373 |
|
142 |
ilm |
1374 |
SQLSelect sel = new SQLSelect();
|
|
|
1375 |
final SQLTable articleTable = getSQLElement().getTable().getForeignTable("ID_ARTICLE");
|
|
|
1376 |
sel.addSelectStar(articleTable);
|
|
|
1377 |
sel.setWhere(new Where(articleTable.getField("CODE"), code));
|
|
|
1378 |
List<SQLRow> matchCode = SQLRowListRSH.execute(sel);
|
|
|
1379 |
Map<String, SQLRow> mapCode = new HashMap<String, SQLRow>();
|
|
|
1380 |
for (SQLRow sqlRow : matchCode) {
|
|
|
1381 |
mapCode.put(sqlRow.getString("CODE"), sqlRow);
|
|
|
1382 |
}
|
|
|
1383 |
Set<String> fieldsFrom = m.getFieldsFrom();
|
|
|
1384 |
fieldsFrom.remove("POURCENT_REMISE");
|
|
|
1385 |
for (int i = articles.size() - 1; i >= 0; i--) {
|
94 |
ilm |
1386 |
|
142 |
ilm |
1387 |
Tuple3<Double, String, String> tuple = articles.get(i);
|
94 |
ilm |
1388 |
|
142 |
ilm |
1389 |
SQLRow article = mapCode.get(tuple.get1());
|
|
|
1390 |
if (article != null && mapRows.containsKey(article.getID())) {
|
|
|
1391 |
Integer index = mapRows.get(article.getID());
|
|
|
1392 |
SQLRowValues rowVals = getRowValuesTable().getRowValuesTableModel().getRowValuesAt(index);
|
|
|
1393 |
getRowValuesTable().getRowValuesTableModel().putValue(rowVals.getInt("QTE") + 1, index, "QTE");
|
|
|
1394 |
} else {
|
|
|
1395 |
final SQLRowValues row2Insert = new SQLRowValues(getRowValuesTable().getRowValuesTableModel().getDefaultRowValues());
|
|
|
1396 |
|
|
|
1397 |
// Completion depuis l'article trouvé
|
|
|
1398 |
if (article != null) {
|
|
|
1399 |
m.fillRowValues(article, fieldsFrom, row2Insert);
|
|
|
1400 |
// Fill prix total
|
|
|
1401 |
row2Insert.put("ID_ARTICLE", article.getID());
|
|
|
1402 |
row2Insert.put("CODE", article.getObject("CODE"));
|
|
|
1403 |
row2Insert.put("NOM", article.getObject("NOM"));
|
|
|
1404 |
} else {
|
|
|
1405 |
row2Insert.put("CODE", tuple.get1());
|
|
|
1406 |
row2Insert.put("NOM", tuple.get2());
|
|
|
1407 |
}
|
|
|
1408 |
|
|
|
1409 |
row2Insert.put("QTE", Math.round(tuple.get0().floatValue()));
|
|
|
1410 |
|
|
|
1411 |
row2Insert.put("PA_HT", row2Insert.getObject("PRIX_METRIQUE_HA_1"));
|
|
|
1412 |
//
|
|
|
1413 |
final BigDecimal resultTotalHT = row2Insert.getBigDecimal("PA_HT").multiply(new BigDecimal(row2Insert.getInt("QTE")));
|
|
|
1414 |
row2Insert.put("T_PA_HT", resultTotalHT);
|
|
|
1415 |
|
|
|
1416 |
Float resultTaux = TaxeCache.getCache().getTauxFromId(row2Insert.getForeignID("ID_TAXE"));
|
|
|
1417 |
|
|
|
1418 |
if (resultTaux == null) {
|
177 |
ilm |
1419 |
SQLRow rowTax = TaxeCache.getCache().getFirstTaxeAchat();
|
142 |
ilm |
1420 |
resultTaux = rowTax.getFloat("TAUX");
|
|
|
1421 |
}
|
|
|
1422 |
|
|
|
1423 |
float taux = (resultTaux == null) ? 0.0F : resultTaux.floatValue();
|
|
|
1424 |
|
|
|
1425 |
BigDecimal r = resultTotalHT.multiply(BigDecimal.valueOf(taux).movePointLeft(2).add(BigDecimal.ONE), DecimalUtils.HIGH_PRECISION);
|
|
|
1426 |
|
|
|
1427 |
row2Insert.put("T_PA_TTC", r);
|
|
|
1428 |
// row2Insert.put("ID_STYLE", allStyleByName.get("Composant"));
|
|
|
1429 |
getRowValuesTable().getRowValuesTableModel().addRowAt(0, row2Insert);
|
|
|
1430 |
}
|
94 |
ilm |
1431 |
}
|
|
|
1432 |
}
|
|
|
1433 |
|
180 |
ilm |
1434 |
private final List<String> trFields = Arrays.asList("ID_COMMANDE_ELEMENT", "ID_BON_RECEPTION_ELEMENT");
|
|
|
1435 |
|
|
|
1436 |
private boolean isFromTranferred(SQLRowValues vals) {
|
|
|
1437 |
|
|
|
1438 |
for (String trField : this.trFields) {
|
|
|
1439 |
if (vals.getTable().contains(trField)) {
|
|
|
1440 |
boolean noCmdElt = vals.getObject(trField) == null || vals.isForeignEmpty(trField);
|
|
|
1441 |
if (!noCmdElt) {
|
|
|
1442 |
return true;
|
|
|
1443 |
}
|
|
|
1444 |
}
|
|
|
1445 |
}
|
|
|
1446 |
return false;
|
|
|
1447 |
}
|
|
|
1448 |
|
18 |
ilm |
1449 |
}
|