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.common.element.StyleSQLElement;
|
|
|
18 |
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
|
18 |
ilm |
19 |
import org.openconcerto.erp.core.sales.product.element.ReferenceArticleSQLElement;
|
61 |
ilm |
20 |
import org.openconcerto.erp.preferences.DefaultNXProps;
|
|
|
21 |
import org.openconcerto.erp.preferences.GestionArticleGlobalPreferencePanel;
|
93 |
ilm |
22 |
import org.openconcerto.erp.utils.TM;
|
18 |
ilm |
23 |
import org.openconcerto.sql.Configuration;
|
|
|
24 |
import org.openconcerto.sql.element.SQLElement;
|
|
|
25 |
import org.openconcerto.sql.model.SQLField;
|
|
|
26 |
import org.openconcerto.sql.model.SQLRow;
|
19 |
ilm |
27 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
18 |
ilm |
28 |
import org.openconcerto.sql.model.SQLRowValues;
|
156 |
ilm |
29 |
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
|
18 |
ilm |
30 |
import org.openconcerto.sql.model.SQLTable;
|
156 |
ilm |
31 |
import org.openconcerto.sql.model.Where;
|
61 |
ilm |
32 |
import org.openconcerto.sql.preferences.SQLPreferences;
|
93 |
ilm |
33 |
import org.openconcerto.sql.view.list.AutoCompletionManager;
|
18 |
ilm |
34 |
import org.openconcerto.sql.view.list.RowValuesTable;
|
|
|
35 |
import org.openconcerto.sql.view.list.RowValuesTableControlPanel;
|
|
|
36 |
import org.openconcerto.sql.view.list.RowValuesTableModel;
|
|
|
37 |
import org.openconcerto.sql.view.list.RowValuesTableRenderer;
|
|
|
38 |
import org.openconcerto.sql.view.list.SQLTableElement;
|
|
|
39 |
import org.openconcerto.ui.DefaultGridBagConstraints;
|
28 |
ilm |
40 |
import org.openconcerto.ui.table.XTableColumnModel;
|
93 |
ilm |
41 |
import org.openconcerto.utils.DecimalUtils;
|
83 |
ilm |
42 |
import org.openconcerto.utils.ExceptionHandler;
|
18 |
ilm |
43 |
|
|
|
44 |
import java.awt.GridBagConstraints;
|
|
|
45 |
import java.awt.GridBagLayout;
|
|
|
46 |
import java.io.File;
|
83 |
ilm |
47 |
import java.math.BigDecimal;
|
|
|
48 |
import java.sql.SQLException;
|
|
|
49 |
import java.util.ArrayList;
|
93 |
ilm |
50 |
import java.util.Collection;
|
142 |
ilm |
51 |
import java.util.Collections;
|
18 |
ilm |
52 |
import java.util.Date;
|
|
|
53 |
import java.util.List;
|
93 |
ilm |
54 |
import java.util.Map;
|
18 |
ilm |
55 |
import java.util.Set;
|
|
|
56 |
|
142 |
ilm |
57 |
import javax.swing.AbstractAction;
|
18 |
ilm |
58 |
import javax.swing.JButton;
|
93 |
ilm |
59 |
import javax.swing.JOptionPane;
|
18 |
ilm |
60 |
import javax.swing.JPanel;
|
|
|
61 |
import javax.swing.JScrollPane;
|
65 |
ilm |
62 |
import javax.swing.ScrollPaneConstants;
|
18 |
ilm |
63 |
|
|
|
64 |
public abstract class AbstractArticleItemTable extends JPanel {
|
|
|
65 |
protected RowValuesTable table;
|
67 |
ilm |
66 |
protected SQLTableElement totalHT, totalHA;
|
61 |
ilm |
67 |
protected SQLTableElement tableElementTVA;
|
18 |
ilm |
68 |
protected SQLTableElement tableElementTotalTTC;
|
19 |
ilm |
69 |
protected SQLTableElement tableElementTotalDevise;
|
18 |
ilm |
70 |
protected SQLTableElement service, qte, ha;
|
|
|
71 |
protected SQLTableElement tableElementPoidsTotal;
|
142 |
ilm |
72 |
protected SQLTableElement tableElementEcoID, tableElementEco, tableElementEcoTotal;
|
61 |
ilm |
73 |
protected SQLTableElement prebilan;
|
156 |
ilm |
74 |
protected SQLRowAccessor rowCatComptable;
|
93 |
ilm |
75 |
private RowValuesTableModel model;
|
18 |
ilm |
76 |
protected SQLRowValues defaultRowVals;
|
174 |
ilm |
77 |
protected List<JButton> buttons = null;
|
18 |
ilm |
78 |
protected RowValuesTableControlPanel control = null;
|
19 |
ilm |
79 |
private SQLRowAccessor tarif = null;
|
18 |
ilm |
80 |
|
142 |
ilm |
81 |
public static String SHOW_TOTAL_ECO_CONTRIBUTION = "SHOW_TOTAL_ECO_CONTRIBUTION";
|
|
|
82 |
public static String SHOW_ECO_CONTRIBUTION_COLUMNS = "SHOW_ECO_CONTRIBUTION_COLUMNS";
|
|
|
83 |
|
93 |
ilm |
84 |
private Date dateDevise = new Date();
|
|
|
85 |
private boolean usedBiasedDevise = true;
|
|
|
86 |
|
18 |
ilm |
87 |
public AbstractArticleItemTable() {
|
93 |
ilm |
88 |
this(null);
|
18 |
ilm |
89 |
}
|
|
|
90 |
|
|
|
91 |
public AbstractArticleItemTable(List<JButton> buttons) {
|
|
|
92 |
this.buttons = buttons;
|
|
|
93 |
init();
|
|
|
94 |
uiInit();
|
|
|
95 |
}
|
|
|
96 |
|
156 |
ilm |
97 |
public void setRowCatComptable(SQLRowAccessor rowCatComptable) {
|
|
|
98 |
this.rowCatComptable = rowCatComptable;
|
|
|
99 |
}
|
|
|
100 |
|
18 |
ilm |
101 |
/**
|
|
|
102 |
*
|
|
|
103 |
*/
|
|
|
104 |
abstract protected void init();
|
|
|
105 |
|
93 |
ilm |
106 |
protected void setModel(RowValuesTableModel model) {
|
|
|
107 |
this.model = model;
|
|
|
108 |
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
public boolean isUsedBiasedDevise() {
|
|
|
112 |
return usedBiasedDevise;
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
public void setUsedBiasedDevise(boolean usedBiasedDevise) {
|
|
|
116 |
this.usedBiasedDevise = usedBiasedDevise;
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
public void setDateDevise(Date dateDevise) {
|
|
|
120 |
if (dateDevise != null) {
|
|
|
121 |
this.dateDevise = dateDevise;
|
|
|
122 |
refreshDeviseAmount();
|
|
|
123 |
}
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
public Date getDateDevise() {
|
|
|
127 |
return dateDevise;
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
protected abstract void refreshDeviseAmount();
|
|
|
131 |
|
18 |
ilm |
132 |
protected File getConfigurationFile() {
|
|
|
133 |
return new File(Configuration.getInstance().getConfDir(), "Table/" + getConfigurationFileName());
|
|
|
134 |
}
|
|
|
135 |
|
|
|
136 |
/**
|
|
|
137 |
*
|
|
|
138 |
*/
|
|
|
139 |
protected void uiInit() {
|
|
|
140 |
// Ui init
|
|
|
141 |
setLayout(new GridBagLayout());
|
61 |
ilm |
142 |
this.setOpaque(false);
|
18 |
ilm |
143 |
final GridBagConstraints c = new DefaultGridBagConstraints();
|
|
|
144 |
|
|
|
145 |
c.weightx = 1;
|
|
|
146 |
|
|
|
147 |
control = new RowValuesTableControlPanel(this.table, this.buttons);
|
61 |
ilm |
148 |
control.setOpaque(false);
|
18 |
ilm |
149 |
this.add(control, c);
|
|
|
150 |
|
|
|
151 |
c.gridy++;
|
|
|
152 |
c.fill = GridBagConstraints.BOTH;
|
|
|
153 |
c.weightx = 1;
|
|
|
154 |
c.weighty = 1;
|
|
|
155 |
final JScrollPane comp = new JScrollPane(this.table);
|
65 |
ilm |
156 |
comp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
|
18 |
ilm |
157 |
this.add(comp, c);
|
|
|
158 |
this.table.setDefaultRenderer(Long.class, new RowValuesTableRenderer());
|
|
|
159 |
}
|
|
|
160 |
|
|
|
161 |
/**
|
|
|
162 |
* @return the coniguration file to store pref
|
|
|
163 |
*/
|
|
|
164 |
protected abstract String getConfigurationFileName();
|
|
|
165 |
|
|
|
166 |
public abstract SQLElement getSQLElement();
|
|
|
167 |
|
|
|
168 |
public void updateField(final String field, final int id) {
|
|
|
169 |
this.table.updateField(field, id);
|
|
|
170 |
}
|
|
|
171 |
|
|
|
172 |
public RowValuesTable getRowValuesTable() {
|
|
|
173 |
return this.table;
|
|
|
174 |
}
|
|
|
175 |
|
|
|
176 |
public void insertFrom(final String field, final int id) {
|
|
|
177 |
this.table.insertFrom(field, id);
|
|
|
178 |
|
|
|
179 |
}
|
|
|
180 |
|
|
|
181 |
public RowValuesTableModel getModel() {
|
|
|
182 |
return this.table.getRowValuesTableModel();
|
|
|
183 |
}
|
|
|
184 |
|
61 |
ilm |
185 |
public SQLTableElement getPrebilanElement() {
|
|
|
186 |
return this.prebilan;
|
|
|
187 |
}
|
|
|
188 |
|
18 |
ilm |
189 |
public SQLTableElement getPrixTotalHTElement() {
|
|
|
190 |
return this.totalHT;
|
|
|
191 |
}
|
|
|
192 |
|
|
|
193 |
public SQLTableElement getPoidsTotalElement() {
|
|
|
194 |
return this.tableElementPoidsTotal;
|
|
|
195 |
}
|
|
|
196 |
|
|
|
197 |
public SQLTableElement getPrixTotalTTCElement() {
|
|
|
198 |
return this.tableElementTotalTTC;
|
|
|
199 |
}
|
|
|
200 |
|
|
|
201 |
public SQLTableElement getPrixServiceElement() {
|
|
|
202 |
return this.service;
|
|
|
203 |
}
|
|
|
204 |
|
|
|
205 |
public SQLTableElement getQteElement() {
|
|
|
206 |
return this.qte;
|
|
|
207 |
}
|
|
|
208 |
|
|
|
209 |
public SQLTableElement getHaElement() {
|
|
|
210 |
return this.ha;
|
|
|
211 |
}
|
|
|
212 |
|
67 |
ilm |
213 |
public SQLTableElement getTotalHaElement() {
|
|
|
214 |
return this.totalHA;
|
|
|
215 |
}
|
|
|
216 |
|
61 |
ilm |
217 |
public SQLTableElement getTVAElement() {
|
|
|
218 |
return this.tableElementTVA;
|
|
|
219 |
}
|
|
|
220 |
|
19 |
ilm |
221 |
public SQLTableElement getTableElementTotalDevise() {
|
|
|
222 |
return this.tableElementTotalDevise;
|
|
|
223 |
}
|
|
|
224 |
|
142 |
ilm |
225 |
public SQLTableElement getTableElementTotalEco() {
|
|
|
226 |
return this.tableElementEcoTotal;
|
|
|
227 |
}
|
|
|
228 |
|
18 |
ilm |
229 |
public void deplacerDe(final int inc) {
|
|
|
230 |
final int rowIndex = this.table.getSelectedRow();
|
|
|
231 |
|
|
|
232 |
final int dest = this.model.moveBy(rowIndex, inc);
|
|
|
233 |
this.table.getSelectionModel().setSelectionInterval(dest, dest);
|
|
|
234 |
}
|
|
|
235 |
|
|
|
236 |
/**
|
83 |
ilm |
237 |
* @return le poids total de tous les éléments (niveau 1) du tableau
|
18 |
ilm |
238 |
*/
|
|
|
239 |
public float getPoidsTotal() {
|
|
|
240 |
|
|
|
241 |
float poids = 0.0F;
|
|
|
242 |
final int poidsTColIndex = this.model.getColumnIndexForElement(this.tableElementPoidsTotal);
|
|
|
243 |
if (poidsTColIndex >= 0) {
|
|
|
244 |
for (int i = 0; i < this.table.getRowCount(); i++) {
|
|
|
245 |
final Number tmp = (Number) this.model.getValueAt(i, poidsTColIndex);
|
90 |
ilm |
246 |
int level = 1;
|
|
|
247 |
if (this.model.getRowValuesAt(i).getObject("NIVEAU") != null) {
|
|
|
248 |
level = this.model.getRowValuesAt(i).getInt("NIVEAU");
|
|
|
249 |
}
|
|
|
250 |
if (tmp != null && level == 1) {
|
18 |
ilm |
251 |
poids += tmp.floatValue();
|
|
|
252 |
}
|
|
|
253 |
}
|
|
|
254 |
}
|
|
|
255 |
return poids;
|
|
|
256 |
}
|
|
|
257 |
|
|
|
258 |
public void refreshTable() {
|
|
|
259 |
this.table.repaint();
|
|
|
260 |
}
|
|
|
261 |
|
|
|
262 |
public void createArticle(final int id, final SQLElement eltSource) {
|
|
|
263 |
|
|
|
264 |
final SQLElement eltArticleTable = getSQLElement();
|
|
|
265 |
|
|
|
266 |
final SQLTable tableArticle = ((ComptaPropsConfiguration) Configuration.getInstance()).getRootSociete().getTable("ARTICLE");
|
|
|
267 |
|
61 |
ilm |
268 |
final boolean modeAvance = DefaultNXProps.getInstance().getBooleanValue("ArticleModeVenteAvance", false);
|
67 |
ilm |
269 |
SQLPreferences prefs = SQLPreferences.getMemCached(tableArticle.getDBRoot());
|
61 |
ilm |
270 |
final boolean createArticle = prefs.getBoolean(GestionArticleGlobalPreferencePanel.CREATE_ARTICLE_AUTO, true);
|
|
|
271 |
|
156 |
ilm |
272 |
if (createArticle) {
|
18 |
ilm |
273 |
|
156 |
ilm |
274 |
SQLRowValues rowValsToFetch = new SQLRowValues(eltArticleTable.getTable());
|
|
|
275 |
rowValsToFetch.putNulls(eltArticleTable.getTable().getFieldsName());
|
|
|
276 |
SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(rowValsToFetch);
|
|
|
277 |
Where w = new Where(eltArticleTable.getTable().getField("CODE"), "!=", "");
|
|
|
278 |
w = w.and(new Where(eltArticleTable.getTable().getField("NOM"), "!=", ""));
|
|
|
279 |
Where w2 = new Where(eltArticleTable.getTable().getField("ID_ARTICLE"), "!=", tableArticle.getUndefinedID());
|
|
|
280 |
w2 = w2.or(new Where(eltArticleTable.getTable().getField("ID_ARTICLE"), "!=", (Object) null));
|
|
|
281 |
final List<SQLRowValues> resultNonAssigned = fetcher.fetch(w.and(w2).and(new Where(eltArticleTable.getTable().getForeignKeys(eltSource.getTable()).iterator().next(), "=", id)));
|
18 |
ilm |
282 |
|
156 |
ilm |
283 |
// On récupére les articles qui composent la table
|
|
|
284 |
// final List<SQLRow> listElts =
|
|
|
285 |
// eltSource.getTable().getRow(id).getReferentRows(eltArticleTable.getTable());
|
|
|
286 |
final SQLRowValues rowArticle = new SQLRowValues(tableArticle);
|
|
|
287 |
final Set<SQLField> fields = tableArticle.getFields();
|
18 |
ilm |
288 |
|
156 |
ilm |
289 |
for (final SQLRowAccessor rowElt : resultNonAssigned) {
|
|
|
290 |
// final SQLRow foreignRow = rowElt.getForeignRow("ID_ARTICLE");
|
|
|
291 |
// if (foreignRow == null || foreignRow.isUndefined()) {
|
|
|
292 |
final Set<String> fieldsName = rowElt.getTable().getFieldsName();
|
|
|
293 |
// on récupére l'article qui lui correspond
|
|
|
294 |
|
|
|
295 |
for (final SQLField field : fields) {
|
|
|
296 |
|
|
|
297 |
final String name = field.getName();
|
|
|
298 |
if (fieldsName.contains(name) && !field.isPrimaryKey()) {
|
|
|
299 |
rowArticle.put(name, rowElt.getObject(name));
|
|
|
300 |
}
|
18 |
ilm |
301 |
}
|
156 |
ilm |
302 |
// crée les articles si il n'existe pas
|
61 |
ilm |
303 |
|
156 |
ilm |
304 |
int idArt = -1;
|
|
|
305 |
if (modeAvance)
|
|
|
306 |
idArt = ReferenceArticleSQLElement.getIdForCNM(rowArticle, createArticle);
|
|
|
307 |
else {
|
|
|
308 |
idArt = ReferenceArticleSQLElement.getIdForCN(rowArticle, createArticle);
|
83 |
ilm |
309 |
}
|
156 |
ilm |
310 |
if (createArticle && idArt > 1 && rowElt.isForeignEmpty("ID_ARTICLE")) {
|
|
|
311 |
try {
|
|
|
312 |
rowElt.createEmptyUpdateRow().put("ID_ARTICLE", idArt).update();
|
|
|
313 |
} catch (SQLException e) {
|
|
|
314 |
ExceptionHandler.handle("Erreur lors de l'affectation de l'article crée!", e);
|
|
|
315 |
}
|
|
|
316 |
}
|
|
|
317 |
// ReferenceArticleSQLElement.getIdForCNM(rowArticle, true);
|
83 |
ilm |
318 |
}
|
18 |
ilm |
319 |
}
|
28 |
ilm |
320 |
// }
|
18 |
ilm |
321 |
}
|
|
|
322 |
|
|
|
323 |
|
|
|
324 |
public SQLRowValues getDefaultRowValues() {
|
|
|
325 |
return this.defaultRowVals;
|
|
|
326 |
}
|
19 |
ilm |
327 |
|
|
|
328 |
public SQLRowAccessor getTarif() {
|
|
|
329 |
return tarif;
|
|
|
330 |
}
|
|
|
331 |
|
|
|
332 |
public void setTarif(SQLRowAccessor idTarif, boolean ask) {
|
|
|
333 |
this.tarif = idTarif;
|
132 |
ilm |
334 |
// Test si ID_DEVISE est dans la table pour KD
|
|
|
335 |
if (this.tarif != null && this.tarif.getTable().contains("ID_DEVISE") && !this.tarif.isForeignEmpty("ID_DEVISE") && this.defaultRowVals != null) {
|
94 |
ilm |
336 |
this.defaultRowVals.put("ID_DEVISE", this.tarif.getForeignID("ID_DEVISE"));
|
|
|
337 |
}
|
19 |
ilm |
338 |
}
|
28 |
ilm |
339 |
|
|
|
340 |
protected void setColumnVisible(int col, boolean visible) {
|
|
|
341 |
if (col >= 0) {
|
|
|
342 |
XTableColumnModel columnModel = this.table.getColumnModel();
|
|
|
343 |
columnModel.setColumnVisible(columnModel.getColumnByModelIndex(col), visible);
|
|
|
344 |
}
|
|
|
345 |
}
|
83 |
ilm |
346 |
|
174 |
ilm |
347 |
private SQLRowAccessor rowClient = null;
|
|
|
348 |
|
|
|
349 |
public SQLRowAccessor getRowClient() {
|
|
|
350 |
return rowClient;
|
|
|
351 |
}
|
|
|
352 |
|
|
|
353 |
public void setClient(SQLRowAccessor rowClient, boolean ask) {
|
|
|
354 |
this.rowClient = rowClient;
|
|
|
355 |
}
|
|
|
356 |
|
93 |
ilm |
357 |
protected void calculTarifNomenclature() {
|
83 |
ilm |
358 |
|
93 |
ilm |
359 |
if (this.model.getRowCount() == 0) {
|
|
|
360 |
return;
|
90 |
ilm |
361 |
}
|
93 |
ilm |
362 |
final int columnForField = this.model.getColumnForField("NIVEAU");
|
|
|
363 |
if (columnForField >= 0) {
|
|
|
364 |
checkNiveau();
|
|
|
365 |
|
|
|
366 |
int rowCount = this.model.getRowCount();
|
|
|
367 |
|
|
|
368 |
for (int niveau = 4; niveau > 1; niveau--) {
|
|
|
369 |
int index = rowCount - 1;
|
|
|
370 |
|
|
|
371 |
while (index > 0) {
|
|
|
372 |
|
|
|
373 |
BigDecimal prixUnitHT = BigDecimal.ZERO;
|
|
|
374 |
BigDecimal prixUnitHA = BigDecimal.ZERO;
|
|
|
375 |
|
|
|
376 |
boolean update = false;
|
|
|
377 |
int indexToUpdate = index;
|
|
|
378 |
// Calcul du sous total
|
|
|
379 |
for (int i = index; i >= 0; i--) {
|
|
|
380 |
indexToUpdate = i;
|
|
|
381 |
SQLRowValues rowVals = this.getRowValuesTable().getRowValuesTableModel().getRowValuesAt(i);
|
|
|
382 |
int niveauCourant = niveau;
|
|
|
383 |
if (rowVals.getObject("NIVEAU") != null) {
|
|
|
384 |
niveauCourant = rowVals.getInt("NIVEAU");
|
|
|
385 |
}
|
132 |
ilm |
386 |
if (niveauCourant > 0) {
|
|
|
387 |
if (niveauCourant < niveau || niveauCourant == 1) {
|
|
|
388 |
break;
|
|
|
389 |
} else if (niveauCourant == niveau) {
|
|
|
390 |
update = true;
|
|
|
391 |
// Cumul des valeurs
|
|
|
392 |
prixUnitHT = prixUnitHT.add(rowVals.getBigDecimal("PV_HT").multiply(new BigDecimal(rowVals.getInt("QTE"))).multiply(rowVals.getBigDecimal("QTE_UNITAIRE")));
|
|
|
393 |
prixUnitHA = prixUnitHA.add(rowVals.getBigDecimal("PA_HT").multiply(new BigDecimal(rowVals.getInt("QTE"))).multiply(rowVals.getBigDecimal("QTE_UNITAIRE")));
|
|
|
394 |
}
|
93 |
ilm |
395 |
}
|
|
|
396 |
}
|
|
|
397 |
if (update) {
|
|
|
398 |
final int columnForFieldHA = this.model.getColumnForField("PRIX_METRIQUE_HA_1");
|
|
|
399 |
if (columnForFieldHA >= 0) {
|
|
|
400 |
this.model.setValueAt(prixUnitHA, indexToUpdate, columnForFieldHA);
|
|
|
401 |
}
|
94 |
ilm |
402 |
|
|
|
403 |
final int columnForFieldPVht1 = this.model.getColumnForField("PRIX_METRIQUE_VT_1");
|
|
|
404 |
if (columnForFieldPVht1 >= 0) {
|
|
|
405 |
this.model.setValueAt(prixUnitHT, indexToUpdate, columnForFieldPVht1);
|
93 |
ilm |
406 |
}
|
|
|
407 |
}
|
|
|
408 |
index = indexToUpdate - 1;
|
83 |
ilm |
409 |
}
|
|
|
410 |
}
|
93 |
ilm |
411 |
}
|
|
|
412 |
}
|
83 |
ilm |
413 |
|
93 |
ilm |
414 |
private void checkNiveau() {
|
83 |
ilm |
415 |
|
93 |
ilm |
416 |
int n = this.model.getRowCount();
|
|
|
417 |
final int columnForField = this.model.getColumnForField("NIVEAU");
|
|
|
418 |
if (n > 0 && columnForField >= 0) {
|
94 |
ilm |
419 |
int start = 0;
|
|
|
420 |
for (int i = 0; i < n; i++) {
|
|
|
421 |
start = i;
|
|
|
422 |
SQLRowValues rowVals = this.model.getRowValuesAt(i);
|
|
|
423 |
if (rowVals.getObject("NIVEAU") == null || rowVals.getInt("NIVEAU") >= 1) {
|
|
|
424 |
this.model.setValueAt(1, i, columnForField);
|
|
|
425 |
break;
|
|
|
426 |
}
|
93 |
ilm |
427 |
}
|
90 |
ilm |
428 |
|
93 |
ilm |
429 |
// Dernier niveau correct autre que -1
|
94 |
ilm |
430 |
int lastGoodPrevious = this.model.getRowValuesAt(start).getInt("NIVEAU");
|
|
|
431 |
for (int i = start + 1; i < n; i++) {
|
93 |
ilm |
432 |
// SQLRowValues rowValsPrev = this.model.getRowValuesAt(i - 1);
|
|
|
433 |
SQLRowValues rowVals = this.model.getRowValuesAt(i);
|
|
|
434 |
if (rowVals.getObject("NIVEAU") == null) {
|
|
|
435 |
this.model.setValueAt(1, i, columnForField);
|
|
|
436 |
}
|
|
|
437 |
// int niveauPrev = rowValsPrev.getInt("NIVEAU");
|
|
|
438 |
int niveau = rowVals.getInt("NIVEAU");
|
|
|
439 |
if (niveau != -1) {
|
90 |
ilm |
440 |
|
93 |
ilm |
441 |
if (niveau - lastGoodPrevious > 1) {
|
|
|
442 |
this.model.setValueAt(lastGoodPrevious, i, columnForField);
|
90 |
ilm |
443 |
}
|
93 |
ilm |
444 |
lastGoodPrevious = niveau;
|
83 |
ilm |
445 |
}
|
|
|
446 |
}
|
|
|
447 |
}
|
|
|
448 |
}
|
|
|
449 |
|
|
|
450 |
public List<SQLRowValues> getRowValuesAtLevel(int level) {
|
|
|
451 |
final int rowCount = this.model.getRowCount();
|
|
|
452 |
final List<SQLRowValues> result = new ArrayList<SQLRowValues>(rowCount);
|
|
|
453 |
for (int i = 0; i < rowCount; i++) {
|
|
|
454 |
final SQLRowValues row = this.model.getRowValuesAt(i);
|
|
|
455 |
if (row.getObject("NIVEAU") == null || row.getInt("NIVEAU") == level) {
|
|
|
456 |
result.add(row);
|
|
|
457 |
}
|
|
|
458 |
}
|
|
|
459 |
return result;
|
|
|
460 |
}
|
93 |
ilm |
461 |
|
94 |
ilm |
462 |
public static enum EXPAND_TYPE {
|
|
|
463 |
VIEW_ONLY, EXPAND, FLAT
|
|
|
464 |
};
|
|
|
465 |
|
|
|
466 |
public void expandNomenclature(int index, AutoCompletionManager m, final EXPAND_TYPE type) {
|
93 |
ilm |
467 |
SQLRowValues rowValsLineFather = this.model.getRowValuesAt(index);
|
|
|
468 |
if (!rowValsLineFather.isForeignEmpty("ID_ARTICLE")) {
|
|
|
469 |
|
94 |
ilm |
470 |
if (type == EXPAND_TYPE.EXPAND) {
|
93 |
ilm |
471 |
int a1 = JOptionPane.showConfirmDialog(this.table, TM.tr("product.bom.expand.warning"), "Warning", JOptionPane.OK_CANCEL_OPTION);
|
|
|
472 |
if (a1 != JOptionPane.YES_OPTION) {
|
|
|
473 |
return;
|
|
|
474 |
}
|
94 |
ilm |
475 |
} else if (type == EXPAND_TYPE.FLAT) {
|
|
|
476 |
int a1 = JOptionPane.showConfirmDialog(this.table, TM.tr("product.bom.flatexpand.warning"), "Warning", JOptionPane.OK_CANCEL_OPTION);
|
|
|
477 |
if (a1 != JOptionPane.YES_OPTION) {
|
|
|
478 |
return;
|
|
|
479 |
}
|
93 |
ilm |
480 |
}
|
94 |
ilm |
481 |
|
93 |
ilm |
482 |
final int fatherLevel = rowValsLineFather.getInt("NIVEAU");
|
|
|
483 |
// Test si il existe déjà des éléments d'un niveau inférieur dans le tableau
|
|
|
484 |
if (index < table.getRowCount() - 1) {
|
|
|
485 |
SQLRowValues rowValsLineNext = this.model.getRowValuesAt(index + 1);
|
|
|
486 |
if (fatherLevel < rowValsLineNext.getInt("NIVEAU")) {
|
94 |
ilm |
487 |
int a = JOptionPane.showConfirmDialog(this.table, "Cette ligne contient déjà des éléments d'un niveau inférieur. Êtes vous sûr de vouloir éclater la nomenclature?", "Nomenclature",
|
|
|
488 |
JOptionPane.YES_NO_OPTION);
|
93 |
ilm |
489 |
if (a == JOptionPane.NO_OPTION) {
|
|
|
490 |
return;
|
|
|
491 |
}
|
|
|
492 |
}
|
|
|
493 |
}
|
|
|
494 |
|
|
|
495 |
SQLRowAccessor rowValsArticleFather = rowValsLineFather.getForeign("ID_ARTICLE");
|
|
|
496 |
// Elements composant la nomenclature
|
|
|
497 |
Collection<? extends SQLRowAccessor> elts = rowValsArticleFather.getReferentRows(rowValsArticleFather.getTable().getTable("ARTICLE_ELEMENT").getField("ID_ARTICLE_PARENT"));
|
|
|
498 |
|
|
|
499 |
if (elts.size() == 0) {
|
|
|
500 |
JOptionPane.showMessageDialog(this.table, "Cet article ne contient aucun élément.");
|
|
|
501 |
}
|
|
|
502 |
|
|
|
503 |
List<? extends SQLRowAccessor> eltsList = new ArrayList<SQLRowAccessor>(elts);
|
94 |
ilm |
504 |
if (type == EXPAND_TYPE.FLAT) {
|
|
|
505 |
this.model.putValue(-1, index, "NIVEAU");
|
|
|
506 |
// this.model.putValue(allStyleByName.get("Composant"), index, "ID_STYLE");
|
|
|
507 |
}
|
142 |
ilm |
508 |
Set<String> fieldsFrom = m.getFieldsFrom();
|
|
|
509 |
fieldsFrom.remove("POURCENT_REMISE");
|
93 |
ilm |
510 |
for (int i = eltsList.size() - 1; i >= 0; i--) {
|
|
|
511 |
SQLRowAccessor sqlRowArticleChildElement = eltsList.get(i);
|
|
|
512 |
final SQLRowAccessor foreignArticleChild = sqlRowArticleChildElement.getForeign("ID_ARTICLE");
|
156 |
ilm |
513 |
if (foreignArticleChild != null && !foreignArticleChild.isUndefined()) {
|
|
|
514 |
final SQLRowValues row2Insert = new SQLRowValues(this.model.getDefaultRowValues());
|
93 |
ilm |
515 |
|
156 |
ilm |
516 |
m.fillRowValues(foreignArticleChild, fieldsFrom, row2Insert);
|
93 |
ilm |
517 |
|
156 |
ilm |
518 |
// Fill prix total
|
|
|
519 |
row2Insert.put("ID_ARTICLE", foreignArticleChild.getID());
|
93 |
ilm |
520 |
|
156 |
ilm |
521 |
row2Insert.put("CODE", foreignArticleChild.getObject("CODE"));
|
|
|
522 |
row2Insert.put("NOM", foreignArticleChild.getObject("NOM"));
|
93 |
ilm |
523 |
|
156 |
ilm |
524 |
if (type == EXPAND_TYPE.FLAT) {
|
|
|
525 |
row2Insert.put("QTE", sqlRowArticleChildElement.getInt("QTE") * rowValsLineFather.getInt("QTE"));
|
|
|
526 |
} else {
|
|
|
527 |
row2Insert.put("QTE", sqlRowArticleChildElement.getInt("QTE"));
|
|
|
528 |
}
|
|
|
529 |
if (row2Insert.getTable().contains("POURCENT_REMISE")) {
|
|
|
530 |
row2Insert.put("POURCENT_REMISE", BigDecimal.ZERO);
|
|
|
531 |
row2Insert.put("MONTANT_REMISE", BigDecimal.ZERO);
|
|
|
532 |
}
|
94 |
ilm |
533 |
|
156 |
ilm |
534 |
if (type == EXPAND_TYPE.EXPAND) {
|
|
|
535 |
row2Insert.put("NIVEAU", fatherLevel + 1);
|
|
|
536 |
} else if (type == EXPAND_TYPE.VIEW_ONLY) {
|
|
|
537 |
row2Insert.put("NIVEAU", -1);
|
|
|
538 |
} else if (type == EXPAND_TYPE.FLAT) {
|
|
|
539 |
row2Insert.put("NIVEAU", 1);
|
|
|
540 |
}
|
93 |
ilm |
541 |
|
156 |
ilm |
542 |
if (type != EXPAND_TYPE.VIEW_ONLY) {
|
93 |
ilm |
543 |
|
156 |
ilm |
544 |
if (row2Insert.getTable().contains("T_PA_TTC")) {
|
|
|
545 |
row2Insert.put("PA_HT", row2Insert.getObject("PRIX_METRIQUE_HA_1"));
|
93 |
ilm |
546 |
|
156 |
ilm |
547 |
final BigDecimal resultTotalHT = row2Insert.getBigDecimal("PA_HT").multiply(new BigDecimal(row2Insert.getInt("QTE")));
|
|
|
548 |
row2Insert.put("T_PA_HT", resultTotalHT);
|
93 |
ilm |
549 |
|
156 |
ilm |
550 |
Float resultTaux = TaxeCache.getCache().getTauxFromId(row2Insert.getForeignID("ID_TAXE"));
|
93 |
ilm |
551 |
|
156 |
ilm |
552 |
if (resultTaux == null) {
|
|
|
553 |
SQLRow rowTax = TaxeCache.getCache().getFirstTaxe();
|
|
|
554 |
resultTaux = rowTax.getFloat("TAUX");
|
|
|
555 |
}
|
93 |
ilm |
556 |
|
156 |
ilm |
557 |
float taux = (resultTaux == null) ? 0.0F : resultTaux.floatValue();
|
93 |
ilm |
558 |
|
156 |
ilm |
559 |
BigDecimal r = resultTotalHT.multiply(BigDecimal.valueOf(taux).movePointLeft(2).add(BigDecimal.ONE), DecimalUtils.HIGH_PRECISION);
|
94 |
ilm |
560 |
|
156 |
ilm |
561 |
row2Insert.put("T_PA_TTC", r);
|
|
|
562 |
} else {
|
|
|
563 |
row2Insert.put("PV_HT", row2Insert.getObject("PRIX_METRIQUE_VT_1"));
|
94 |
ilm |
564 |
|
156 |
ilm |
565 |
final BigDecimal resultTotalHT = row2Insert.getBigDecimal("PV_HT").multiply(new BigDecimal(row2Insert.getInt("QTE")));
|
|
|
566 |
row2Insert.put("T_PV_HT", resultTotalHT);
|
94 |
ilm |
567 |
|
156 |
ilm |
568 |
Float resultTaux = TaxeCache.getCache().getTauxFromId(row2Insert.getForeignID("ID_TAXE"));
|
94 |
ilm |
569 |
|
156 |
ilm |
570 |
if (resultTaux == null) {
|
|
|
571 |
SQLRow rowTax = TaxeCache.getCache().getFirstTaxe();
|
|
|
572 |
resultTaux = rowTax.getFloat("TAUX");
|
|
|
573 |
}
|
94 |
ilm |
574 |
|
156 |
ilm |
575 |
float taux = (resultTaux == null) ? 0.0F : resultTaux.floatValue();
|
94 |
ilm |
576 |
|
156 |
ilm |
577 |
BigDecimal r = resultTotalHT.multiply(BigDecimal.valueOf(taux).movePointLeft(2).add(BigDecimal.ONE), DecimalUtils.HIGH_PRECISION);
|
94 |
ilm |
578 |
|
156 |
ilm |
579 |
row2Insert.put("T_PV_TTC", r);
|
94 |
ilm |
580 |
|
156 |
ilm |
581 |
}
|
94 |
ilm |
582 |
}
|
156 |
ilm |
583 |
Map<String, Integer> allStyleByName = getSQLElement().getDirectory().getElement(StyleSQLElement.class).getAllStyleByName();
|
|
|
584 |
row2Insert.put("ID_STYLE", allStyleByName.get("Composant"));
|
|
|
585 |
this.model.addRowAt(index + 1, row2Insert);
|
93 |
ilm |
586 |
}
|
|
|
587 |
}
|
|
|
588 |
}
|
|
|
589 |
}
|
142 |
ilm |
590 |
|
|
|
591 |
protected List<AbstractAction> getAdditionnalMouseAction(final int rowIndex) {
|
|
|
592 |
return Collections.emptyList();
|
|
|
593 |
}
|
|
|
594 |
|
|
|
595 |
public void insertFromReliquat(List<SQLRowValues> reliquats) {
|
|
|
596 |
|
|
|
597 |
for (SQLRowValues reliquat : reliquats) {
|
|
|
598 |
|
|
|
599 |
final SQLRowValues row2Insert = new SQLRowValues(getRowValuesTable().getRowValuesTableModel().getDefaultRowValues());
|
|
|
600 |
|
|
|
601 |
// Completion depuis l'article trouvé
|
|
|
602 |
final SQLRowAccessor article = reliquat.getForeign("ID_ARTICLE").asRow();
|
|
|
603 |
|
|
|
604 |
row2Insert.put("ID_ARTICLE", article.getID());
|
|
|
605 |
row2Insert.put("CODE", article.getObject("CODE"));
|
|
|
606 |
row2Insert.put("NOM", article.getObject("NOM"));
|
|
|
607 |
|
|
|
608 |
row2Insert.put("QTE", reliquat.getObject("QTE"));
|
|
|
609 |
row2Insert.put("QTE_UNITAIRE", reliquat.getObject("QTE_UNITAIRE"));
|
|
|
610 |
row2Insert.put("ID_UNITE_VENTE", reliquat.getForeignID("ID_UNITE_VENTE"));
|
|
|
611 |
getRowValuesTable().getRowValuesTableModel().addRowAt(0, row2Insert);
|
|
|
612 |
|
|
|
613 |
}
|
|
|
614 |
}
|
18 |
ilm |
615 |
}
|