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.sales.quote.element;
|
|
|
15 |
|
|
|
16 |
import org.openconcerto.erp.config.ComptaPropsConfiguration;
|
|
|
17 |
import org.openconcerto.erp.config.Gestion;
|
73 |
ilm |
18 |
import org.openconcerto.erp.core.common.component.TransfertBaseSQLComponent;
|
18 |
ilm |
19 |
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
|
94 |
ilm |
20 |
import org.openconcerto.erp.core.common.ui.AbstractVenteArticleItemTable;
|
18 |
ilm |
21 |
import org.openconcerto.erp.core.sales.invoice.component.SaisieVenteFactureSQLComponent;
|
65 |
ilm |
22 |
import org.openconcerto.erp.core.sales.product.element.ReferenceArticleSQLElement;
|
18 |
ilm |
23 |
import org.openconcerto.erp.core.sales.quote.component.DevisSQLComponent;
|
61 |
ilm |
24 |
import org.openconcerto.erp.core.sales.quote.report.DevisXmlSheet;
|
83 |
ilm |
25 |
import org.openconcerto.erp.core.sales.quote.ui.QuoteEditGroup;
|
93 |
ilm |
26 |
import org.openconcerto.erp.core.sales.quote.ui.QuoteSQLComponent;
|
156 |
ilm |
27 |
import org.openconcerto.erp.core.sales.shipment.component.BonDeLivraisonSQLComponent;
|
65 |
ilm |
28 |
import org.openconcerto.erp.core.supplychain.stock.element.MouvementStockSQLElement;
|
61 |
ilm |
29 |
import org.openconcerto.erp.model.MouseSheetXmlListeListener;
|
149 |
ilm |
30 |
import org.openconcerto.erp.preferences.GestionCommercialeGlobalPreferencePanel;
|
18 |
ilm |
31 |
import org.openconcerto.sql.Configuration;
|
93 |
ilm |
32 |
import org.openconcerto.sql.element.GlobalMapper;
|
18 |
ilm |
33 |
import org.openconcerto.sql.element.SQLComponent;
|
|
|
34 |
import org.openconcerto.sql.element.SQLElement;
|
132 |
ilm |
35 |
import org.openconcerto.sql.element.SQLElementLink.LinkType;
|
|
|
36 |
import org.openconcerto.sql.element.SQLElementLinksSetup;
|
90 |
ilm |
37 |
import org.openconcerto.sql.model.FieldPath;
|
65 |
ilm |
38 |
import org.openconcerto.sql.model.SQLField;
|
|
|
39 |
import org.openconcerto.sql.model.SQLInjector;
|
|
|
40 |
import org.openconcerto.sql.model.SQLRow;
|
80 |
ilm |
41 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
18 |
ilm |
42 |
import org.openconcerto.sql.model.SQLRowValues;
|
80 |
ilm |
43 |
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
|
|
|
44 |
import org.openconcerto.sql.model.SQLSelect;
|
156 |
ilm |
45 |
import org.openconcerto.sql.model.SQLSelectJoin;
|
65 |
ilm |
46 |
import org.openconcerto.sql.model.SQLTable;
|
80 |
ilm |
47 |
import org.openconcerto.sql.model.Where;
|
90 |
ilm |
48 |
import org.openconcerto.sql.model.graph.Path;
|
149 |
ilm |
49 |
import org.openconcerto.sql.preferences.SQLPreferences;
|
18 |
ilm |
50 |
import org.openconcerto.sql.request.ListSQLRequest;
|
174 |
ilm |
51 |
import org.openconcerto.sql.ui.light.CustomRowEditor;
|
94 |
ilm |
52 |
import org.openconcerto.sql.users.UserManager;
|
93 |
ilm |
53 |
import org.openconcerto.sql.users.rights.UserRightsManager;
|
18 |
ilm |
54 |
import org.openconcerto.sql.view.EditFrame;
|
65 |
ilm |
55 |
import org.openconcerto.sql.view.EditPanel;
|
90 |
ilm |
56 |
import org.openconcerto.sql.view.EditPanel.EditMode;
|
|
|
57 |
import org.openconcerto.sql.view.EditPanelListener;
|
|
|
58 |
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn;
|
65 |
ilm |
59 |
import org.openconcerto.sql.view.list.IListe;
|
90 |
ilm |
60 |
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
|
65 |
ilm |
61 |
import org.openconcerto.sql.view.list.RowAction;
|
90 |
ilm |
62 |
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
|
142 |
ilm |
63 |
import org.openconcerto.sql.view.list.SQLTableModelSource;
|
83 |
ilm |
64 |
import org.openconcerto.ui.light.ActivationOnSelectionControler;
|
|
|
65 |
import org.openconcerto.ui.light.ColumnSpec;
|
|
|
66 |
import org.openconcerto.ui.light.ColumnsSpec;
|
156 |
ilm |
67 |
import org.openconcerto.ui.light.LightController;
|
149 |
ilm |
68 |
import org.openconcerto.ui.light.LightUIButtonUnmanaged;
|
132 |
ilm |
69 |
import org.openconcerto.ui.light.LightUIComboBox;
|
83 |
ilm |
70 |
import org.openconcerto.ui.light.LightUIElement;
|
|
|
71 |
import org.openconcerto.ui.light.LightUILine;
|
94 |
ilm |
72 |
import org.openconcerto.ui.light.LightUIPanel;
|
|
|
73 |
import org.openconcerto.ui.light.LightUITable;
|
83 |
ilm |
74 |
import org.openconcerto.ui.light.LightUITextField;
|
|
|
75 |
import org.openconcerto.ui.light.Row;
|
94 |
ilm |
76 |
import org.openconcerto.ui.light.RowSelectionSpec;
|
83 |
ilm |
77 |
import org.openconcerto.ui.light.TableContent;
|
|
|
78 |
import org.openconcerto.ui.light.TableSpec;
|
90 |
ilm |
79 |
import org.openconcerto.ui.table.TimestampTableCellRenderer;
|
|
|
80 |
import org.openconcerto.utils.CollectionUtils;
|
|
|
81 |
import org.openconcerto.utils.DecimalUtils;
|
80 |
ilm |
82 |
import org.openconcerto.utils.ExceptionHandler;
|
90 |
ilm |
83 |
import org.openconcerto.utils.FileUtils;
|
83 |
ilm |
84 |
import org.openconcerto.utils.ListMap;
|
80 |
ilm |
85 |
import org.openconcerto.utils.cc.ITransformer;
|
94 |
ilm |
86 |
import org.openconcerto.utils.ui.StringWithId;
|
18 |
ilm |
87 |
|
93 |
ilm |
88 |
import java.awt.Desktop;
|
65 |
ilm |
89 |
import java.awt.event.ActionEvent;
|
90 |
ilm |
90 |
import java.io.File;
|
93 |
ilm |
91 |
import java.io.IOException;
|
67 |
ilm |
92 |
import java.math.BigDecimal;
|
90 |
ilm |
93 |
import java.net.URI;
|
65 |
ilm |
94 |
import java.sql.SQLException;
|
18 |
ilm |
95 |
import java.util.ArrayList;
|
93 |
ilm |
96 |
import java.util.Arrays;
|
90 |
ilm |
97 |
import java.util.Calendar;
|
156 |
ilm |
98 |
import java.util.Collections;
|
90 |
ilm |
99 |
import java.util.Date;
|
18 |
ilm |
100 |
import java.util.HashSet;
|
|
|
101 |
import java.util.List;
|
|
|
102 |
import java.util.Set;
|
|
|
103 |
|
65 |
ilm |
104 |
import javax.swing.AbstractAction;
|
18 |
ilm |
105 |
import javax.swing.ImageIcon;
|
|
|
106 |
import javax.swing.JFrame;
|
80 |
ilm |
107 |
import javax.swing.JOptionPane;
|
|
|
108 |
import javax.swing.SwingWorker;
|
18 |
ilm |
109 |
|
132 |
ilm |
110 |
import org.jdom2.Document;
|
|
|
111 |
import org.jdom2.Element;
|
|
|
112 |
import org.jdom2.input.DOMBuilder;
|
94 |
ilm |
113 |
|
18 |
ilm |
114 |
public class DevisSQLElement extends ComptaSQLConfElement {
|
|
|
115 |
|
25 |
ilm |
116 |
public static final String TABLENAME = "DEVIS";
|
93 |
ilm |
117 |
public static final String FACTURE_TAG_RIGHT = "TAG_FACTURE_DEVIS";
|
25 |
ilm |
118 |
|
90 |
ilm |
119 |
public static enum Month {
|
|
|
120 |
|
132 |
ilm |
121 |
JANVIER("01", "Janvier"), FEVRIER("02", "Février"), MARS("03", "Mars"), AVRIL("04", "Avril"), MAI("05", "Mai"), JUIN("06", "Juin"), JUILLET("07", "Juillet"), AOUT("08",
|
|
|
122 |
"Août"), SEPTEMBRE("09", "Septembre"), OCTOBRE("10", "Octobre"), NOVEMBRE("11", "Novembre"), DECEMBRE("12", "Décembre");
|
90 |
ilm |
123 |
|
|
|
124 |
private String number;
|
|
|
125 |
private String name;
|
|
|
126 |
|
|
|
127 |
Month(String number, String name) {
|
|
|
128 |
this.number = number;
|
|
|
129 |
this.name = name;
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
public String getName() {
|
|
|
133 |
return this.name;
|
|
|
134 |
}
|
|
|
135 |
|
|
|
136 |
public String getNumber() {
|
|
|
137 |
return this.number;
|
|
|
138 |
}
|
|
|
139 |
|
|
|
140 |
public String getPath() {
|
|
|
141 |
return this.getNumber() + "-" + this.getName();
|
|
|
142 |
}
|
156 |
ilm |
143 |
}
|
90 |
ilm |
144 |
|
18 |
ilm |
145 |
public DevisSQLElement() {
|
156 |
ilm |
146 |
super(TABLENAME);
|
61 |
ilm |
147 |
|
65 |
ilm |
148 |
getRowActions().addAll(getDevisRowActions());
|
93 |
ilm |
149 |
final QuoteEditGroup group = new QuoteEditGroup();
|
|
|
150 |
GlobalMapper.getInstance().map(QuoteSQLComponent.ID, group);
|
|
|
151 |
setDefaultGroup(group);
|
|
|
152 |
|
18 |
ilm |
153 |
}
|
|
|
154 |
|
149 |
ilm |
155 |
@Override
|
|
|
156 |
public Set<String> getReadOnlyFields() {
|
156 |
ilm |
157 |
Set<String> s = new HashSet<>();
|
149 |
ilm |
158 |
s.add("T_ACOMPTE");
|
|
|
159 |
return s;
|
|
|
160 |
}
|
90 |
ilm |
161 |
|
65 |
ilm |
162 |
private List<RowAction> getDevisRowActions() {
|
|
|
163 |
|
156 |
ilm |
164 |
List<RowAction> rowsActions = new ArrayList<>();
|
65 |
ilm |
165 |
|
|
|
166 |
// Transfert vers facture
|
|
|
167 |
RowAction factureAction = getDevis2FactureAction();
|
|
|
168 |
|
|
|
169 |
rowsActions.add(factureAction);
|
|
|
170 |
|
149 |
ilm |
171 |
SQLPreferences prefs = new SQLPreferences(getTable().getDBRoot());
|
|
|
172 |
if (prefs.getBoolean(GestionCommercialeGlobalPreferencePanel.ACOMPTE_DEVIS, false)) {
|
|
|
173 |
PredicateRowAction actionClient = new PredicateRowAction(new AbstractAction("Saisir un acompte") {
|
|
|
174 |
EditFrame edit;
|
|
|
175 |
|
|
|
176 |
public void actionPerformed(ActionEvent e) {
|
|
|
177 |
final SQLElement eltEncaisser = Configuration.getInstance().getDirectory()
|
|
|
178 |
.getElement(((ComptaPropsConfiguration) Configuration.getInstance()).getRootSociete().getTable("ENCAISSER_MONTANT"));
|
|
|
179 |
|
|
|
180 |
if (this.edit == null) {
|
|
|
181 |
this.edit = new EditFrame(eltEncaisser, EditMode.CREATION);
|
|
|
182 |
}
|
|
|
183 |
final SQLRowAccessor selRow = IListe.get(e).getSelectedRow();
|
|
|
184 |
SQLRowValues rowVals = new SQLRowValues(eltEncaisser.getTable());
|
|
|
185 |
rowVals.put("ACOMPTE", true);
|
|
|
186 |
rowVals.put("NOM", "Acompte devis " + selRow.getString("NUMERO"));
|
|
|
187 |
rowVals.put("ID_CLIENT", selRow.getForeignID("ID_CLIENT"));
|
|
|
188 |
rowVals.put("ID_DEVIS", selRow.getID());
|
|
|
189 |
SQLRowValues rowValsElt = new SQLRowValues(eltEncaisser.getTable().getTable("ENCAISSER_MONTANT_ELEMENT"));
|
|
|
190 |
rowValsElt.put("MONTANT_A_REGLER", selRow.getLong("T_TTC"));
|
|
|
191 |
rowValsElt.put("DATE", selRow.getObject("DATE"));
|
|
|
192 |
rowValsElt.put("ID_ENCAISSER_MONTANT", rowVals);
|
|
|
193 |
this.edit.getSQLComponent().select(rowVals);
|
|
|
194 |
this.edit.setVisible(true);
|
|
|
195 |
this.edit.addEditPanelListener(new EditPanelListener() {
|
|
|
196 |
|
|
|
197 |
@Override
|
|
|
198 |
public void modified() {
|
|
|
199 |
}
|
|
|
200 |
|
|
|
201 |
@Override
|
|
|
202 |
public void inserted(int id) {
|
|
|
203 |
// Put id devis and refresh devis.t_acompte
|
|
|
204 |
SQLRow rowE = eltEncaisser.getTable().getRow(id);
|
|
|
205 |
String up = "UPDATE " + selRow.getTable().getSQLName().quote() + " set \"T_ACOMPTE\"=(SELECT COALESCE(SUM(\"MONTANT\"),0) from " + rowE.getTable().getSQLName().quote()
|
|
|
206 |
+ " where \"ARCHIVE\"=0 and \"ID_DEVIS\"=" + selRow.getID() + ") where \"ID_DEVIS\"=" + selRow.getID();
|
|
|
207 |
eltEncaisser.getTable().getDBSystemRoot().getDataSource().execute(up);
|
|
|
208 |
}
|
|
|
209 |
|
|
|
210 |
@Override
|
|
|
211 |
public void deleted() {
|
|
|
212 |
}
|
|
|
213 |
|
|
|
214 |
@Override
|
|
|
215 |
public void cancelled() {
|
|
|
216 |
}
|
|
|
217 |
});
|
|
|
218 |
}
|
|
|
219 |
}, false);
|
|
|
220 |
actionClient.setPredicate(IListeEvent.getSingleSelectionPredicate());
|
|
|
221 |
rowsActions.add(actionClient);
|
|
|
222 |
}
|
|
|
223 |
|
90 |
ilm |
224 |
PredicateRowAction actionClient = new PredicateRowAction(new AbstractAction("Détails client") {
|
|
|
225 |
EditFrame edit;
|
|
|
226 |
private SQLElement eltClient = Configuration.getInstance().getDirectory().getElement(((ComptaPropsConfiguration) Configuration.getInstance()).getRootSociete().getTable("CLIENT"));
|
|
|
227 |
|
|
|
228 |
public void actionPerformed(ActionEvent e) {
|
94 |
ilm |
229 |
if (this.edit == null) {
|
|
|
230 |
this.edit = new EditFrame(this.eltClient, EditMode.MODIFICATION);
|
90 |
ilm |
231 |
}
|
94 |
ilm |
232 |
this.edit.selectionId(IListe.get(e).getSelectedRow().getForeignID("ID_CLIENT"));
|
|
|
233 |
this.edit.setVisible(true);
|
90 |
ilm |
234 |
}
|
|
|
235 |
}, false);
|
|
|
236 |
actionClient.setPredicate(IListeEvent.getSingleSelectionPredicate());
|
|
|
237 |
rowsActions.add(actionClient);
|
|
|
238 |
|
|
|
239 |
|
65 |
ilm |
240 |
// Voir le document
|
|
|
241 |
RowAction actionTransfertCmd = getDevis2CmdFournAction();
|
|
|
242 |
rowsActions.add(actionTransfertCmd);
|
|
|
243 |
|
|
|
244 |
// Transfert vers commande
|
|
|
245 |
RowAction commandeAction = getDevis2CmdCliAction();
|
|
|
246 |
rowsActions.add(commandeAction);
|
|
|
247 |
|
156 |
ilm |
248 |
RowAction blAction = getDevis2BlAction();
|
|
|
249 |
rowsActions.add(blAction);
|
|
|
250 |
|
65 |
ilm |
251 |
RowAction accepteEtCmdAction = getAcceptAndCmdClientAction();
|
|
|
252 |
rowsActions.add(accepteEtCmdAction);
|
|
|
253 |
|
|
|
254 |
// Marqué accepté
|
|
|
255 |
RowAction accepteAction = getAcceptAction();
|
|
|
256 |
|
|
|
257 |
rowsActions.add(accepteAction);
|
|
|
258 |
|
|
|
259 |
// Marqué accepté
|
|
|
260 |
RowAction refuseAction = getRefuseAction();
|
|
|
261 |
|
|
|
262 |
rowsActions.add(refuseAction);
|
|
|
263 |
|
|
|
264 |
// // Dupliquer
|
|
|
265 |
RowAction cloneAction = getCloneAction();
|
|
|
266 |
|
|
|
267 |
rowsActions.add(cloneAction);
|
|
|
268 |
|
|
|
269 |
MouseSheetXmlListeListener mouseSheetXmlListeListener = new MouseSheetXmlListeListener(DevisXmlSheet.class);
|
|
|
270 |
mouseSheetXmlListeListener.setGenerateHeader(true);
|
|
|
271 |
mouseSheetXmlListeListener.setShowHeader(true);
|
|
|
272 |
|
|
|
273 |
rowsActions.addAll(mouseSheetXmlListeListener.getRowActions());
|
|
|
274 |
|
|
|
275 |
return rowsActions;
|
|
|
276 |
}
|
|
|
277 |
|
156 |
ilm |
278 |
public RowAction getDevis2BlAction() {
|
|
|
279 |
return new RowAction(new AbstractAction() {
|
|
|
280 |
public void actionPerformed(ActionEvent e) {
|
|
|
281 |
|
|
|
282 |
final List<SQLRowValues> copySelectedRows = IListe.get(e).getSelectedRows();
|
|
|
283 |
transfertDevis(copySelectedRows, "BON_DE_LIVRAISON");
|
|
|
284 |
}
|
|
|
285 |
|
|
|
286 |
}, true, "sales.quote.create.customer.delivery") {
|
|
|
287 |
@Override
|
|
|
288 |
public boolean enabledFor(java.util.List<org.openconcerto.sql.model.SQLRowValues> selection) {
|
|
|
289 |
if (selection != null && selection.size() == 1) {
|
|
|
290 |
if (selection.get(0).getForeignID("ID_ETAT_DEVIS") == EtatDevisSQLElement.ACCEPTE) {
|
|
|
291 |
return true;
|
|
|
292 |
}
|
|
|
293 |
}
|
|
|
294 |
return false;
|
|
|
295 |
}
|
|
|
296 |
};
|
|
|
297 |
}
|
|
|
298 |
|
93 |
ilm |
299 |
public static void davBrowse(String s) throws Exception {
|
|
|
300 |
final boolean windows = System.getProperty("os.name").startsWith("Windows");
|
|
|
301 |
if (windows) {
|
|
|
302 |
Desktop.getDesktop().browse(new URI(s));
|
|
|
303 |
} else {
|
|
|
304 |
String[] cmdarray = new String[] { "xdg-open", s };
|
|
|
305 |
final int res = Runtime.getRuntime().exec(cmdarray).waitFor();
|
|
|
306 |
if (res != 0)
|
|
|
307 |
throw new IOException("error (" + res + ") executing " + Arrays.asList(cmdarray));
|
|
|
308 |
}
|
|
|
309 |
}
|
|
|
310 |
|
65 |
ilm |
311 |
public RowAction getCloneAction() {
|
67 |
ilm |
312 |
return new RowAction(new AbstractAction() {
|
65 |
ilm |
313 |
|
|
|
314 |
public void actionPerformed(ActionEvent e) {
|
80 |
ilm |
315 |
SQLRowAccessor selectedRow = IListe.get(e).getSelectedRow();
|
65 |
ilm |
316 |
|
93 |
ilm |
317 |
SQLElement eltFact = Configuration.getInstance().getDirectory().getElement("DEVIS");
|
|
|
318 |
EditFrame editFrame = new EditFrame(eltFact, EditPanel.CREATION);
|
65 |
ilm |
319 |
|
93 |
ilm |
320 |
((DevisSQLComponent) editFrame.getSQLComponent()).loadDevisExistant(selectedRow.getID());
|
|
|
321 |
editFrame.setVisible(true);
|
65 |
ilm |
322 |
}
|
67 |
ilm |
323 |
}, true, "sales.quote.clone") {
|
156 |
ilm |
324 |
@Override
|
93 |
ilm |
325 |
public boolean enabledFor(java.util.List<org.openconcerto.sql.model.SQLRowValues> selection) {
|
65 |
ilm |
326 |
return (selection != null && selection.size() == 1);
|
156 |
ilm |
327 |
}
|
65 |
ilm |
328 |
};
|
|
|
329 |
}
|
|
|
330 |
|
|
|
331 |
public RowAction getRefuseAction() {
|
67 |
ilm |
332 |
return new RowAction(new AbstractAction() {
|
65 |
ilm |
333 |
public void actionPerformed(ActionEvent e) {
|
80 |
ilm |
334 |
SQLRowValues rowVals = IListe.get(e).getSelectedRow().asRow().createEmptyUpdateRow();
|
65 |
ilm |
335 |
rowVals.put("ID_ETAT_DEVIS", EtatDevisSQLElement.REFUSE);
|
|
|
336 |
try {
|
|
|
337 |
rowVals.update();
|
|
|
338 |
} catch (SQLException e1) {
|
|
|
339 |
// TODO Auto-generated catch block
|
|
|
340 |
e1.printStackTrace();
|
|
|
341 |
}
|
|
|
342 |
}
|
67 |
ilm |
343 |
}, false, "sales.quote.refuse") {
|
156 |
ilm |
344 |
@Override
|
93 |
ilm |
345 |
public boolean enabledFor(java.util.List<org.openconcerto.sql.model.SQLRowValues> selection) {
|
65 |
ilm |
346 |
if (selection != null && selection.size() == 1) {
|
93 |
ilm |
347 |
if (selection.get(0).getForeignID("ID_ETAT_DEVIS") == EtatDevisSQLElement.EN_ATTENTE) {
|
65 |
ilm |
348 |
return true;
|
|
|
349 |
}
|
|
|
350 |
}
|
|
|
351 |
return false;
|
156 |
ilm |
352 |
}
|
65 |
ilm |
353 |
};
|
|
|
354 |
}
|
|
|
355 |
|
|
|
356 |
public RowAction getAcceptAction() {
|
67 |
ilm |
357 |
return new RowAction(new AbstractAction() {
|
65 |
ilm |
358 |
public void actionPerformed(ActionEvent e) {
|
80 |
ilm |
359 |
SQLRow selectedRow = IListe.get(e).getSelectedRow().asRow();
|
65 |
ilm |
360 |
SQLRowValues rowVals = selectedRow.createEmptyUpdateRow();
|
|
|
361 |
rowVals.put("ID_ETAT_DEVIS", EtatDevisSQLElement.ACCEPTE);
|
|
|
362 |
try {
|
|
|
363 |
rowVals.update();
|
|
|
364 |
} catch (SQLException e1) {
|
|
|
365 |
// TODO Auto-generated catch block
|
|
|
366 |
e1.printStackTrace();
|
|
|
367 |
}
|
|
|
368 |
}
|
67 |
ilm |
369 |
}, false, "sales.quote.accept") {
|
156 |
ilm |
370 |
@Override
|
93 |
ilm |
371 |
public boolean enabledFor(java.util.List<org.openconcerto.sql.model.SQLRowValues> selection) {
|
65 |
ilm |
372 |
if (selection != null && selection.size() == 1) {
|
93 |
ilm |
373 |
final int int1 = selection.get(0).getForeignID("ID_ETAT_DEVIS");
|
90 |
ilm |
374 |
if (int1 != EtatDevisSQLElement.REFUSE && int1 != EtatDevisSQLElement.ACCEPTE) {
|
65 |
ilm |
375 |
return true;
|
|
|
376 |
}
|
|
|
377 |
}
|
|
|
378 |
return false;
|
156 |
ilm |
379 |
}
|
65 |
ilm |
380 |
};
|
|
|
381 |
}
|
|
|
382 |
|
|
|
383 |
public RowAction getDevis2FactureAction() {
|
67 |
ilm |
384 |
return new RowAction(new AbstractAction() {
|
65 |
ilm |
385 |
public void actionPerformed(ActionEvent e) {
|
93 |
ilm |
386 |
TransfertBaseSQLComponent.openTransfertFrame(IListe.get(e).getSelectedRows(), "SAISIE_VENTE_FACTURE");
|
90 |
ilm |
387 |
|
65 |
ilm |
388 |
}
|
67 |
ilm |
389 |
}, true, "sales.quote.create.invoice") {
|
156 |
ilm |
390 |
@Override
|
93 |
ilm |
391 |
public boolean enabledFor(java.util.List<org.openconcerto.sql.model.SQLRowValues> selection) {
|
90 |
ilm |
392 |
boolean b = selection.size() > 0;
|
|
|
393 |
for (SQLRowAccessor sqlRowAccessor : selection) {
|
93 |
ilm |
394 |
b &= sqlRowAccessor.getForeignID("ID_ETAT_DEVIS") == EtatDevisSQLElement.ACCEPTE;
|
65 |
ilm |
395 |
}
|
90 |
ilm |
396 |
|
|
|
397 |
return b;
|
156 |
ilm |
398 |
}
|
65 |
ilm |
399 |
};
|
|
|
400 |
}
|
|
|
401 |
|
|
|
402 |
public RowAction getDevis2CmdFournAction() {
|
67 |
ilm |
403 |
return new RowAction(new AbstractAction() {
|
65 |
ilm |
404 |
public void actionPerformed(ActionEvent e) {
|
80 |
ilm |
405 |
final SQLRow selectedRow = IListe.get(e).fetchSelectedRow();
|
73 |
ilm |
406 |
ComptaPropsConfiguration.getInstanceCompta().getNonInteractiveSQLExecutor().execute(new Runnable() {
|
|
|
407 |
|
|
|
408 |
@Override
|
|
|
409 |
public void run() {
|
|
|
410 |
transfertCommande(selectedRow);
|
|
|
411 |
|
|
|
412 |
}
|
|
|
413 |
});
|
|
|
414 |
|
65 |
ilm |
415 |
}
|
67 |
ilm |
416 |
}, false, "sales.quote.create.supplier.order") {
|
156 |
ilm |
417 |
@Override
|
93 |
ilm |
418 |
public boolean enabledFor(java.util.List<org.openconcerto.sql.model.SQLRowValues> selection) {
|
65 |
ilm |
419 |
if (selection != null && selection.size() == 1) {
|
93 |
ilm |
420 |
if (selection.get(0).getForeignID("ID_ETAT_DEVIS") == EtatDevisSQLElement.ACCEPTE) {
|
65 |
ilm |
421 |
return true;
|
|
|
422 |
}
|
|
|
423 |
}
|
|
|
424 |
return false;
|
156 |
ilm |
425 |
}
|
65 |
ilm |
426 |
};
|
|
|
427 |
}
|
|
|
428 |
|
|
|
429 |
public RowAction getDevis2CmdCliAction() {
|
67 |
ilm |
430 |
return new RowAction(new AbstractAction() {
|
65 |
ilm |
431 |
public void actionPerformed(ActionEvent e) {
|
80 |
ilm |
432 |
|
93 |
ilm |
433 |
final List<SQLRowValues> copySelectedRows = IListe.get(e).getSelectedRows();
|
80 |
ilm |
434 |
transfertCommandeClient(copySelectedRows);
|
65 |
ilm |
435 |
}
|
80 |
ilm |
436 |
|
67 |
ilm |
437 |
}, true, "sales.quote.create.customer.order") {
|
156 |
ilm |
438 |
@Override
|
93 |
ilm |
439 |
public boolean enabledFor(java.util.List<org.openconcerto.sql.model.SQLRowValues> selection) {
|
65 |
ilm |
440 |
if (selection != null && selection.size() == 1) {
|
93 |
ilm |
441 |
if (selection.get(0).getForeignID("ID_ETAT_DEVIS") == EtatDevisSQLElement.ACCEPTE) {
|
65 |
ilm |
442 |
return true;
|
|
|
443 |
}
|
|
|
444 |
}
|
|
|
445 |
return false;
|
156 |
ilm |
446 |
}
|
65 |
ilm |
447 |
};
|
|
|
448 |
}
|
|
|
449 |
|
|
|
450 |
public RowAction getAcceptAndCmdClientAction() {
|
67 |
ilm |
451 |
return new RowAction(new AbstractAction() {
|
65 |
ilm |
452 |
public void actionPerformed(ActionEvent e) {
|
80 |
ilm |
453 |
SQLRow selectedRow = IListe.get(e).fetchSelectedRow();
|
65 |
ilm |
454 |
SQLRowValues rowVals = selectedRow.createEmptyUpdateRow();
|
|
|
455 |
rowVals.put("ID_ETAT_DEVIS", EtatDevisSQLElement.ACCEPTE);
|
|
|
456 |
try {
|
|
|
457 |
rowVals.update();
|
|
|
458 |
} catch (SQLException e1) {
|
80 |
ilm |
459 |
ExceptionHandler.handle("Erreur la de la mise à jour de l'état du devis!", e1);
|
|
|
460 |
|
65 |
ilm |
461 |
}
|
93 |
ilm |
462 |
transfertCommandeClient(IListe.get(e).getSelectedRows());
|
65 |
ilm |
463 |
}
|
67 |
ilm |
464 |
}, false, "sales.quote.accept.create.customer.order") {
|
156 |
ilm |
465 |
@Override
|
93 |
ilm |
466 |
public boolean enabledFor(java.util.List<org.openconcerto.sql.model.SQLRowValues> selection) {
|
65 |
ilm |
467 |
if (selection != null && selection.size() == 1) {
|
93 |
ilm |
468 |
if (selection.get(0).getForeignID("ID_ETAT_DEVIS") == EtatDevisSQLElement.EN_ATTENTE) {
|
65 |
ilm |
469 |
return true;
|
|
|
470 |
}
|
|
|
471 |
}
|
|
|
472 |
return false;
|
156 |
ilm |
473 |
}
|
65 |
ilm |
474 |
};
|
|
|
475 |
}
|
|
|
476 |
|
156 |
ilm |
477 |
public void transfertDevis(final List<SQLRowValues> copySelectedRows, final String destTable) {
|
80 |
ilm |
478 |
SwingWorker<Boolean, Object> worker = new SwingWorker<Boolean, Object>() {
|
|
|
479 |
@Override
|
|
|
480 |
protected Boolean doInBackground() throws Exception {
|
|
|
481 |
|
|
|
482 |
final SQLTable tableTransfert = getTable().getTable("TR_DEVIS");
|
|
|
483 |
SQLRowValues rowVals = new SQLRowValues(tableTransfert);
|
|
|
484 |
rowVals.put("ID_DEVIS", new SQLRowValues(getTable()).put("NUMERO", null));
|
156 |
ilm |
485 |
rowVals.put("ID_" + destTable, null);
|
80 |
ilm |
486 |
rowVals.put("ID", null);
|
|
|
487 |
|
156 |
ilm |
488 |
final List<Number> lID = new ArrayList<>();
|
80 |
ilm |
489 |
for (SQLRowValues sqlRowValues : copySelectedRows) {
|
|
|
490 |
lID.add(sqlRowValues.getID());
|
|
|
491 |
}
|
|
|
492 |
|
|
|
493 |
SQLRowValuesListFetcher fetch = SQLRowValuesListFetcher.create(rowVals);
|
|
|
494 |
fetch.setSelTransf(new ITransformer<SQLSelect, SQLSelect>() {
|
|
|
495 |
|
|
|
496 |
@Override
|
|
|
497 |
public SQLSelect transformChecked(SQLSelect input) {
|
|
|
498 |
Where w = new Where(tableTransfert.getField("ID_DEVIS"), lID);
|
156 |
ilm |
499 |
w = w.and(new Where(tableTransfert.getField("ID_" + destTable), "IS NOT", (Object) null));
|
80 |
ilm |
500 |
input.setWhere(w);
|
|
|
501 |
return input;
|
|
|
502 |
}
|
|
|
503 |
});
|
|
|
504 |
|
|
|
505 |
List<SQLRowValues> rows = fetch.fetch();
|
|
|
506 |
if (rows != null && rows.size() > 0) {
|
|
|
507 |
String numero = "";
|
|
|
508 |
|
|
|
509 |
for (SQLRowValues sqlRow : rows) {
|
|
|
510 |
numero += sqlRow.getForeign("ID_DEVIS").getString("NUMERO") + " ,";
|
|
|
511 |
}
|
|
|
512 |
|
|
|
513 |
numero = numero.substring(0, numero.length() - 2);
|
|
|
514 |
String label = "Attention ";
|
|
|
515 |
if (rows.size() > 1) {
|
156 |
ilm |
516 |
label += " les devis " + numero + " ont déjà été transféré!";
|
80 |
ilm |
517 |
} else {
|
156 |
ilm |
518 |
label += " le devis " + numero + " a déjà été transféré!";
|
80 |
ilm |
519 |
}
|
|
|
520 |
label += "\n Voulez vous continuer?";
|
|
|
521 |
|
156 |
ilm |
522 |
int ans = JOptionPane.showConfirmDialog(null, label, "Transfert devis", JOptionPane.YES_NO_OPTION);
|
80 |
ilm |
523 |
if (ans == JOptionPane.NO_OPTION) {
|
|
|
524 |
return Boolean.FALSE;
|
|
|
525 |
}
|
|
|
526 |
|
|
|
527 |
}
|
|
|
528 |
return Boolean.TRUE;
|
|
|
529 |
|
|
|
530 |
}
|
|
|
531 |
|
|
|
532 |
@Override
|
|
|
533 |
protected void done() {
|
|
|
534 |
|
|
|
535 |
try {
|
|
|
536 |
Boolean b = get();
|
|
|
537 |
if (b != null && b) {
|
156 |
ilm |
538 |
EditFrame frame = TransfertBaseSQLComponent.openTransfertFrame(copySelectedRows, destTable);
|
|
|
539 |
if (destTable.equalsIgnoreCase("BON_DE_LIVRAISON")) {
|
|
|
540 |
BonDeLivraisonSQLComponent comp = (BonDeLivraisonSQLComponent) frame.getSQLComponent();
|
|
|
541 |
final SQLTable tableElt = comp.getElement().getTable().getTable("BON_DE_LIVRAISON_ELEMENT");
|
|
|
542 |
SQLRowValues rowVals = new SQLRowValues(tableElt);
|
|
|
543 |
rowVals.put("QTE_UNITAIRE", null);
|
|
|
544 |
rowVals.put("QTE", null);
|
|
|
545 |
rowVals.put("QTE_LIVREE", null);
|
|
|
546 |
rowVals.put("ID_ARTICLE", null);
|
|
|
547 |
rowVals.put("PV_HT", null);
|
|
|
548 |
rowVals.put("ID_DEVIS_ELEMENT", null);
|
|
|
549 |
|
|
|
550 |
SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(rowVals);
|
|
|
551 |
fetcher.setSelTransf(new ITransformer<SQLSelect, SQLSelect>() {
|
|
|
552 |
|
|
|
553 |
@Override
|
|
|
554 |
public SQLSelect transformChecked(SQLSelect input) {
|
|
|
555 |
List<Integer> ids = new ArrayList<>(copySelectedRows.size());
|
|
|
556 |
for (SQLRowValues sqlRowValues : copySelectedRows) {
|
|
|
557 |
ids.add(sqlRowValues.getID());
|
|
|
558 |
}
|
|
|
559 |
SQLSelectJoin joinBR = input.addJoin("RIGHT", tableElt.getTable("BON_DE_LIVRAISON_ELEMENT").getField("ID_BON_DE_LIVRAISON"));
|
|
|
560 |
SQLSelectJoin joinTR = input.addBackwardJoin("RIGHT", tableElt.getTable("TR_DEVIS").getField("ID_BON_DE_LIVRAISON"), joinBR.getJoinedTable().getAlias());
|
|
|
561 |
joinTR.setWhere(new Where(joinTR.getJoinedTable().getField("ID_DEVIS"), ids));
|
|
|
562 |
System.err.println(input.asString());
|
|
|
563 |
return input;
|
|
|
564 |
}
|
|
|
565 |
});
|
|
|
566 |
comp.loadQuantity(fetcher.fetch(), "DEVIS_ELEMENT");
|
|
|
567 |
}
|
80 |
ilm |
568 |
}
|
|
|
569 |
} catch (Exception e) {
|
156 |
ilm |
570 |
ExceptionHandler.handle("Erreur lors du transfert des devis!", e);
|
80 |
ilm |
571 |
}
|
|
|
572 |
super.done();
|
|
|
573 |
}
|
|
|
574 |
};
|
|
|
575 |
worker.execute();
|
|
|
576 |
}
|
|
|
577 |
|
156 |
ilm |
578 |
public void transfertCommandeClient(final List<SQLRowValues> copySelectedRows) {
|
|
|
579 |
transfertDevis(copySelectedRows, "COMMANDE_CLIENT");
|
|
|
580 |
}
|
|
|
581 |
|
|
|
582 |
@Override
|
18 |
ilm |
583 |
protected List<String> getComboFields() {
|
156 |
ilm |
584 |
List<String> l = new ArrayList<>(1);
|
18 |
ilm |
585 |
l.add("NUMERO");
|
|
|
586 |
return l;
|
|
|
587 |
}
|
|
|
588 |
|
83 |
ilm |
589 |
private void transfertCommande(final SQLRow row) {
|
|
|
590 |
ComptaPropsConfiguration.getInstanceCompta().getNonInteractiveSQLExecutor().execute(new Runnable() {
|
|
|
591 |
|
|
|
592 |
@Override
|
|
|
593 |
public void run() {
|
|
|
594 |
DevisItemSQLElement elt = (DevisItemSQLElement) Configuration.getInstance().getDirectory().getElement("DEVIS_ELEMENT");
|
|
|
595 |
SQLTable tableCmdElt = Configuration.getInstance().getDirectory().getElement("COMMANDE_ELEMENT").getTable();
|
|
|
596 |
SQLElement eltArticle = Configuration.getInstance().getDirectory().getElement("ARTICLE");
|
|
|
597 |
List<SQLRow> rows = row.getReferentRows(elt.getTable());
|
156 |
ilm |
598 |
final ListMap<SQLRow, SQLRowValues> map = new ListMap<>();
|
83 |
ilm |
599 |
SQLRow rowDeviseF = null;
|
|
|
600 |
for (SQLRow sqlRow : rows) {
|
|
|
601 |
// on récupére l'article qui lui correspond
|
|
|
602 |
SQLRowValues rowArticle = new SQLRowValues(eltArticle.getTable());
|
|
|
603 |
for (SQLField field : eltArticle.getTable().getFields()) {
|
|
|
604 |
if (sqlRow.getTable().getFieldsName().contains(field.getName())) {
|
|
|
605 |
rowArticle.put(field.getName(), sqlRow.getObject(field.getName()));
|
|
|
606 |
}
|
|
|
607 |
}
|
|
|
608 |
|
|
|
609 |
// rowArticle.loadAllSafe(rowEltFact);
|
|
|
610 |
int idArticle = ReferenceArticleSQLElement.getIdForCNM(rowArticle, true);
|
|
|
611 |
SQLRow rowArticleFind = eltArticle.getTable().getRow(idArticle);
|
132 |
ilm |
612 |
if (rowArticleFind != null) {
|
|
|
613 |
SQLInjector inj = SQLInjector.getInjector(rowArticle.getTable(), tableCmdElt);
|
|
|
614 |
SQLRowValues rowValsElt = new SQLRowValues(inj.createRowValuesFrom(rowArticleFind));
|
|
|
615 |
rowValsElt.put("ID_STYLE", sqlRow.getObject("ID_STYLE"));
|
|
|
616 |
rowValsElt.put("QTE", sqlRow.getObject("QTE"));
|
|
|
617 |
rowValsElt.put("T_POIDS", rowValsElt.getLong("POIDS") * rowValsElt.getInt("QTE"));
|
|
|
618 |
rowValsElt.put("T_PA_HT", ((BigDecimal) rowValsElt.getObject("PA_HT")).multiply(new BigDecimal(rowValsElt.getInt("QTE"), DecimalUtils.HIGH_PRECISION)));
|
156 |
ilm |
619 |
rowValsElt.put("T_PA_TTC", ((BigDecimal) rowValsElt.getObject("T_PA_HT")).multiply(BigDecimal.valueOf(rowValsElt.getForeign("ID_TAXE").getFloat("TAUX") / 100.0 + 1.0),
|
|
|
620 |
DecimalUtils.HIGH_PRECISION));
|
83 |
ilm |
621 |
|
132 |
ilm |
622 |
// gestion de la devise
|
|
|
623 |
rowDeviseF = sqlRow.getForeignRow("ID_DEVISE");
|
|
|
624 |
SQLRow rowDeviseHA = rowArticleFind.getForeignRow("ID_DEVISE_HA");
|
|
|
625 |
BigDecimal qte = new BigDecimal(rowValsElt.getInt("QTE"));
|
|
|
626 |
if (rowDeviseF != null && !rowDeviseF.isUndefined()) {
|
|
|
627 |
if (rowDeviseF.getID() == rowDeviseHA.getID()) {
|
|
|
628 |
rowValsElt.put("PA_DEVISE", rowArticleFind.getObject("PA_DEVISE"));
|
|
|
629 |
rowValsElt.put("PA_DEVISE_T", ((BigDecimal) rowArticleFind.getObject("PA_DEVISE")).multiply(qte, DecimalUtils.HIGH_PRECISION));
|
|
|
630 |
rowValsElt.put("ID_DEVISE", rowDeviseF.getID());
|
|
|
631 |
} else {
|
|
|
632 |
BigDecimal taux = (BigDecimal) rowDeviseF.getObject("TAUX");
|
|
|
633 |
rowValsElt.put("PA_DEVISE", taux.multiply((BigDecimal) rowValsElt.getObject("PA_HT")));
|
|
|
634 |
rowValsElt.put("PA_DEVISE_T", ((BigDecimal) rowValsElt.getObject("PA_DEVISE")).multiply(qte, DecimalUtils.HIGH_PRECISION));
|
|
|
635 |
rowValsElt.put("ID_DEVISE", rowDeviseF.getID());
|
|
|
636 |
}
|
|
|
637 |
}
|
83 |
ilm |
638 |
|
132 |
ilm |
639 |
map.add(rowArticleFind.getForeignRow("ID_FOURNISSEUR"), rowValsElt);
|
83 |
ilm |
640 |
}
|
65 |
ilm |
641 |
}
|
83 |
ilm |
642 |
MouvementStockSQLElement.createCommandeF(map, rowDeviseF);
|
65 |
ilm |
643 |
}
|
83 |
ilm |
644 |
});
|
65 |
ilm |
645 |
|
|
|
646 |
}
|
|
|
647 |
|
18 |
ilm |
648 |
protected List<String> getListFields() {
|
156 |
ilm |
649 |
List<String> l = new ArrayList<>();
|
18 |
ilm |
650 |
l.add("NUMERO");
|
|
|
651 |
l.add("DATE");
|
|
|
652 |
l.add("ID_CLIENT");
|
|
|
653 |
l.add("OBJET");
|
41 |
ilm |
654 |
l.add("ID_COMMERCIAL");
|
94 |
ilm |
655 |
if (UserRightsManager.getCurrentUserRights().haveRight(AbstractVenteArticleItemTable.SHOW_PRIX_ACHAT_CODE)) {
|
|
|
656 |
l.add("T_HA");
|
|
|
657 |
}
|
18 |
ilm |
658 |
l.add("T_HT");
|
|
|
659 |
l.add("T_TTC");
|
149 |
ilm |
660 |
SQLPreferences prefs = SQLPreferences.getMemCached(getTable().getDBRoot());
|
|
|
661 |
if (prefs.getBoolean(GestionCommercialeGlobalPreferencePanel.ACOMPTE_DEVIS, false)) {
|
|
|
662 |
l.add("T_ACOMPTE");
|
|
|
663 |
}
|
18 |
ilm |
664 |
l.add("INFOS");
|
93 |
ilm |
665 |
if (getTable().contains("DUNNING_DATE")) {
|
|
|
666 |
l.add("DUNNING_DATE");
|
|
|
667 |
}
|
18 |
ilm |
668 |
return l;
|
|
|
669 |
}
|
|
|
670 |
|
94 |
ilm |
671 |
@Override
|
142 |
ilm |
672 |
protected synchronized void _initTableSource(final SQLTableModelSource table) {
|
|
|
673 |
super._initTableSource(table);
|
94 |
ilm |
674 |
|
151 |
ilm |
675 |
final BaseSQLTableModelColumn colAdrLiv = new BaseSQLTableModelColumn("Adresse de livraison", String.class) {
|
94 |
ilm |
676 |
|
151 |
ilm |
677 |
@Override
|
|
|
678 |
protected Object show_(SQLRowAccessor r) {
|
94 |
ilm |
679 |
|
151 |
ilm |
680 |
SQLRowAccessor rowAd;
|
|
|
681 |
if (!r.isForeignEmpty("ID_ADRESSE_LIVRAISON")) {
|
|
|
682 |
rowAd = r.getForeign("ID_ADRESSE_LIVRAISON");
|
|
|
683 |
} else if (r.getForeign("ID_CLIENT").getObject("ID_ADRESSE_L") != null && !r.getForeign("ID_CLIENT").isForeignEmpty("ID_ADRESSE_L")) {
|
|
|
684 |
rowAd = r.getForeign("ID_CLIENT").getForeign("ID_ADRESSE_L");
|
|
|
685 |
} else {
|
|
|
686 |
rowAd = r.getForeign("ID_CLIENT").getForeign("ID_ADRESSE");
|
|
|
687 |
}
|
94 |
ilm |
688 |
|
151 |
ilm |
689 |
String lib = rowAd.getString("LIBELLE") + " " + rowAd.getString("VILLE");
|
94 |
ilm |
690 |
|
151 |
ilm |
691 |
return lib;
|
|
|
692 |
}
|
94 |
ilm |
693 |
|
151 |
ilm |
694 |
@Override
|
|
|
695 |
public Set<FieldPath> getPaths() {
|
|
|
696 |
SQLTable devisTable = getTable();
|
|
|
697 |
Path p = new Path(devisTable);
|
|
|
698 |
p = p.add(devisTable.getField("ID_CLIENT"));
|
|
|
699 |
p = p.add(p.getLast().getField("ID_ADRESSE_L"));
|
94 |
ilm |
700 |
|
151 |
ilm |
701 |
Path p2 = new Path(devisTable);
|
|
|
702 |
p2 = p2.add(devisTable.getField("ID_CLIENT"));
|
|
|
703 |
p2 = p2.add(p2.getLast().getField("ID_ADRESSE"));
|
94 |
ilm |
704 |
|
151 |
ilm |
705 |
Path p3 = new Path(devisTable);
|
|
|
706 |
p3 = p3.add(devisTable.getField("ID_ADRESSE_LIVRAISON"));
|
94 |
ilm |
707 |
|
151 |
ilm |
708 |
return CollectionUtils.createSet(new FieldPath(p, "LIBELLE"), new FieldPath(p, "VILLE"), new FieldPath(p2, "LIBELLE"), new FieldPath(p2, "VILLE"), new FieldPath(p3, "LIBELLE"),
|
|
|
709 |
new FieldPath(p3, "VILLE"));
|
|
|
710 |
}
|
|
|
711 |
};
|
|
|
712 |
table.getColumns().add(3, colAdrLiv);
|
94 |
ilm |
713 |
}
|
|
|
714 |
|
18 |
ilm |
715 |
@Override
|
132 |
ilm |
716 |
public ListMap<String, String> getShowAs() {
|
|
|
717 |
return ListMap.singleton(null, "NUMERO");
|
28 |
ilm |
718 |
}
|
|
|
719 |
|
|
|
720 |
@Override
|
132 |
ilm |
721 |
protected void _initListRequest(ListSQLRequest req) {
|
|
|
722 |
super._initListRequest(req);
|
|
|
723 |
req.addToGraphToFetch("ID_ETAT_DEVIS");
|
18 |
ilm |
724 |
}
|
|
|
725 |
|
|
|
726 |
@Override
|
132 |
ilm |
727 |
protected void setupLinks(SQLElementLinksSetup links) {
|
|
|
728 |
super.setupLinks(links);
|
|
|
729 |
if (getTable().contains("ID_ADRESSE")) {
|
|
|
730 |
links.get("ID_ADRESSE").setType(LinkType.ASSOCIATION);
|
|
|
731 |
}
|
|
|
732 |
if (getTable().contains("ID_ADRESSE_LIVRAISON")) {
|
|
|
733 |
links.get("ID_ADRESSE_LIVRAISON").setType(LinkType.ASSOCIATION);
|
|
|
734 |
}
|
18 |
ilm |
735 |
}
|
|
|
736 |
|
|
|
737 |
/*
|
|
|
738 |
* (non-Javadoc)
|
|
|
739 |
*
|
|
|
740 |
* @see org.openconcerto.devis.SQLElement#getComponent()
|
|
|
741 |
*/
|
|
|
742 |
public SQLComponent createComponent() {
|
93 |
ilm |
743 |
return new DevisSQLComponent(this);
|
18 |
ilm |
744 |
}
|
|
|
745 |
|
|
|
746 |
/**
|
|
|
747 |
* Transfert d'un devis en facture
|
|
|
748 |
*
|
|
|
749 |
* @param devisID
|
|
|
750 |
*/
|
90 |
ilm |
751 |
public void transfertFacture(final int devisID) {
|
18 |
ilm |
752 |
|
|
|
753 |
SQLElement elt = Configuration.getInstance().getDirectory().getElement("SAISIE_VENTE_FACTURE");
|
|
|
754 |
EditFrame editFactureFrame = new EditFrame(elt);
|
|
|
755 |
editFactureFrame.setIconImage(new ImageIcon(Gestion.class.getResource("frameicon.png")).getImage());
|
|
|
756 |
|
|
|
757 |
SaisieVenteFactureSQLComponent comp = (SaisieVenteFactureSQLComponent) editFactureFrame.getSQLComponent();
|
|
|
758 |
|
|
|
759 |
comp.setDefaults();
|
|
|
760 |
comp.loadDevis(devisID);
|
|
|
761 |
|
90 |
ilm |
762 |
|
18 |
ilm |
763 |
editFactureFrame.pack();
|
|
|
764 |
editFactureFrame.setState(JFrame.NORMAL);
|
|
|
765 |
editFactureFrame.setVisible(true);
|
|
|
766 |
}
|
|
|
767 |
|
83 |
ilm |
768 |
@Override
|
174 |
ilm |
769 |
public List<CustomRowEditor> getCustomRowEditors(Configuration configuration, String sessionToken) {
|
|
|
770 |
List<CustomRowEditor> map = super.getCustomRowEditors(configuration, sessionToken);
|
|
|
771 |
map.add(new CustomRowEditor("sales.quote.items.list") {
|
83 |
ilm |
772 |
|
|
|
773 |
@Override
|
174 |
ilm |
774 |
public LightUIElement createUIElement() {
|
132 |
ilm |
775 |
final ColumnSpec c1 = new ColumnSpec("sales.quote.item.style", StringWithId.class, "Style", new StringWithId(2, "Normal"), true, new LightUIComboBox("sales.quote.item.style"));
|
94 |
ilm |
776 |
final ColumnSpec c2 = new ColumnSpec("sales.quote.item.code", String.class, "Code", "", true, new LightUITextField("sales.quote.item.code"));
|
|
|
777 |
final ColumnSpec c3 = new ColumnSpec("sales.quote.item.label", String.class, "Nom", "", true, new LightUITextField("sales.quote.item.name"));
|
|
|
778 |
final ColumnSpec c4 = new ColumnSpec("sales.quote.item.description", String.class, "Descriptif", "", true, new LightUITextField("sales.quote.item.description"));
|
132 |
ilm |
779 |
final ColumnSpec c5 = new ColumnSpec("sales.quote.item.purchase.unit.price", BigDecimal.class, "P.U. Achat HT", new BigDecimal(0), true,
|
|
|
780 |
new LightUITextField("sales.quote.item.purchase.unit.price"));
|
|
|
781 |
final ColumnSpec c6 = new ColumnSpec("sales.quote.item.sales.unit.price", BigDecimal.class, "P.U. Vente HT", new BigDecimal(0), true,
|
|
|
782 |
new LightUITextField("sales.quote.item.sales.unit.price"));
|
94 |
ilm |
783 |
final ColumnSpec c7 = new ColumnSpec("sales.quote.item.quantity", Integer.class, "Quantité", new BigDecimal(1), true, new LightUITextField("sales.quote.item.quantity"));
|
83 |
ilm |
784 |
|
156 |
ilm |
785 |
final List<ColumnSpec> columnsSpec = new ArrayList<>(7);
|
94 |
ilm |
786 |
columnsSpec.add(c1);
|
|
|
787 |
columnsSpec.add(c2);
|
|
|
788 |
columnsSpec.add(c3);
|
|
|
789 |
columnsSpec.add(c4);
|
|
|
790 |
columnsSpec.add(c5);
|
|
|
791 |
columnsSpec.add(c6);
|
|
|
792 |
columnsSpec.add(c7);
|
156 |
ilm |
793 |
final List<String> possibleColumnIds = new ArrayList<>(columnsSpec.size());
|
94 |
ilm |
794 |
for (ColumnSpec c : columnsSpec) {
|
|
|
795 |
possibleColumnIds.add(c.getId());
|
83 |
ilm |
796 |
}
|
|
|
797 |
|
94 |
ilm |
798 |
final String lId = "sales.quote.items";
|
|
|
799 |
final long userId = UserManager.getUserID();
|
|
|
800 |
Document columnsPrefs = null;
|
|
|
801 |
try {
|
|
|
802 |
final DOMBuilder in = new DOMBuilder();
|
|
|
803 |
final org.w3c.dom.Document w3cDoc = Configuration.getInstance().getXMLConf(userId, lId);
|
|
|
804 |
if (w3cDoc != null) {
|
|
|
805 |
columnsPrefs = in.build(w3cDoc);
|
|
|
806 |
}
|
142 |
ilm |
807 |
if (columnsPrefs == null) {
|
|
|
808 |
throw new IllegalStateException("Columns Prefs is null");
|
|
|
809 |
}
|
94 |
ilm |
810 |
} catch (Exception ex) {
|
132 |
ilm |
811 |
throw new IllegalArgumentException(
|
|
|
812 |
"DevisSQLElement getItemsCustomEditorProvider - Failed to get ColumnPrefs for descriptor " + lId + " and for user " + userId + "\n" + ex.getMessage());
|
94 |
ilm |
813 |
}
|
83 |
ilm |
814 |
|
94 |
ilm |
815 |
final Element rootElement = columnsPrefs.getRootElement();
|
|
|
816 |
if (!rootElement.getName().equals("list")) {
|
|
|
817 |
throw new IllegalArgumentException("invalid xml, roots node list expected but " + rootElement.getName() + " found");
|
|
|
818 |
}
|
|
|
819 |
final List<Element> xmlColumns = rootElement.getChildren();
|
|
|
820 |
final int columnsCount = columnsSpec.size();
|
|
|
821 |
if (xmlColumns.size() != columnsCount) {
|
|
|
822 |
throw new IllegalArgumentException("incorrect columns count in xml");
|
|
|
823 |
}
|
|
|
824 |
|
|
|
825 |
for (int i = 0; i < columnsCount; i++) {
|
|
|
826 |
final ColumnSpec columnSpec = columnsSpec.get(i);
|
|
|
827 |
final String columnId = columnSpec.getId();
|
|
|
828 |
boolean find = false;
|
|
|
829 |
|
|
|
830 |
for (int j = 0; j < columnsCount; j++) {
|
|
|
831 |
final Element xmlColumn = xmlColumns.get(j);
|
|
|
832 |
final String xmlColumnId = xmlColumn.getAttribute("id").getValue();
|
|
|
833 |
|
|
|
834 |
if (xmlColumnId.equals(columnId)) {
|
|
|
835 |
|
|
|
836 |
if (!xmlColumn.getName().equals("column")) {
|
|
|
837 |
throw new IllegalArgumentException("ColumnSpec setPrefs - Invalid xml, element node column expected but " + xmlColumn.getName() + " found");
|
|
|
838 |
}
|
|
|
839 |
if (xmlColumn.getAttribute("width") == null || xmlColumn.getAttribute("min-width") == null || xmlColumn.getAttribute("max-width") == null) {
|
|
|
840 |
throw new IllegalArgumentException("ColumnSpec setPrefs - Invalid column node for " + columnId + ", it must have attribute width, min-width, max-width");
|
|
|
841 |
}
|
|
|
842 |
|
|
|
843 |
final int width = Integer.parseInt(xmlColumn.getAttribute("width").getValue());
|
|
|
844 |
final int maxWidth = Integer.parseInt(xmlColumn.getAttribute("max-width").getValue());
|
|
|
845 |
final int minWidth = Integer.parseInt(xmlColumn.getAttribute("min-width").getValue());
|
|
|
846 |
|
|
|
847 |
columnSpec.setPrefs(width, maxWidth, minWidth);
|
|
|
848 |
if (i != j) {
|
|
|
849 |
final ColumnSpec swap = columnsSpec.get(i);
|
|
|
850 |
columnsSpec.set(i, columnsSpec.get(j));
|
|
|
851 |
columnsSpec.set(j, swap);
|
|
|
852 |
}
|
|
|
853 |
find = true;
|
|
|
854 |
break;
|
|
|
855 |
}
|
|
|
856 |
}
|
|
|
857 |
if (!find) {
|
|
|
858 |
throw new IllegalArgumentException("xml contain unknow column: " + columnId);
|
|
|
859 |
}
|
|
|
860 |
}
|
|
|
861 |
final ColumnsSpec cSpec = new ColumnsSpec(lId, columnsSpec, possibleColumnIds, null);
|
|
|
862 |
cSpec.setAllowMove(true);
|
|
|
863 |
cSpec.setAllowResize(true);
|
174 |
ilm |
864 |
final RowSelectionSpec selectionSpec = new RowSelectionSpec(getItemId());
|
|
|
865 |
final TableSpec tSpec = new TableSpec(getItemId(), selectionSpec, cSpec);
|
94 |
ilm |
866 |
tSpec.setColumns(cSpec);
|
|
|
867 |
|
174 |
ilm |
868 |
String id = getItemId();
|
94 |
ilm |
869 |
final LightUITable eList = new LightUITable(id);
|
|
|
870 |
eList.setTableSpec(tSpec);
|
83 |
ilm |
871 |
|
132 |
ilm |
872 |
LightUIPanel panel = new LightUIPanel("sales.quote.items.list");
|
|
|
873 |
panel.setGridWidth(1);
|
|
|
874 |
panel.setFillWidth(true);
|
83 |
ilm |
875 |
|
|
|
876 |
LightUILine toolbarLine = new LightUILine();
|
|
|
877 |
|
149 |
ilm |
878 |
LightUIButtonUnmanaged b1 = new LightUIButtonUnmanaged("up");
|
83 |
ilm |
879 |
b1.setIcon("up.png");
|
132 |
ilm |
880 |
panel.addControler(new ActivationOnSelectionControler(id, b1.getId()));
|
156 |
ilm |
881 |
panel.addControler(new LightController(LightController.TYPE_UP, id, b1.getId()));
|
132 |
ilm |
882 |
toolbarLine.addChild(b1);
|
83 |
ilm |
883 |
|
149 |
ilm |
884 |
final LightUIButtonUnmanaged b2 = new LightUIButtonUnmanaged("down");
|
83 |
ilm |
885 |
b2.setIcon("down.png");
|
132 |
ilm |
886 |
panel.addControler(new ActivationOnSelectionControler(id, b2.getId()));
|
156 |
ilm |
887 |
panel.addControler(new LightController(LightController.TYPE_DOWN, id, b2.getId()));
|
132 |
ilm |
888 |
toolbarLine.addChild(b2);
|
83 |
ilm |
889 |
// Add
|
149 |
ilm |
890 |
LightUIElement addButton = new LightUIButtonUnmanaged("add", "Ajouter une ligne");
|
156 |
ilm |
891 |
panel.addControler(new LightController(LightController.TYPE_ADD_DEFAULT, id, addButton.getId()));
|
132 |
ilm |
892 |
toolbarLine.addChild(addButton);
|
83 |
ilm |
893 |
// Insert
|
149 |
ilm |
894 |
LightUIElement insertButton = new LightUIButtonUnmanaged("insert", "Insérer une ligne");
|
156 |
ilm |
895 |
panel.addControler(new LightController(LightController.TYPE_INSERT_DEFAULT, id, insertButton.getId()));
|
132 |
ilm |
896 |
toolbarLine.addChild(insertButton);
|
83 |
ilm |
897 |
|
|
|
898 |
// Copy
|
149 |
ilm |
899 |
LightUIElement copyButton = new LightUIButtonUnmanaged("copy", "Dupliquer");
|
132 |
ilm |
900 |
panel.addControler(new ActivationOnSelectionControler(id, copyButton.getId()));
|
156 |
ilm |
901 |
panel.addControler(new LightController(LightController.TYPE_COPY, id, copyButton.getId()));
|
132 |
ilm |
902 |
toolbarLine.addChild(copyButton);
|
83 |
ilm |
903 |
|
|
|
904 |
// Remove
|
149 |
ilm |
905 |
LightUIElement removeButton = new LightUIButtonUnmanaged("remove", "Supprimer");
|
132 |
ilm |
906 |
panel.addControler(new ActivationOnSelectionControler(id, removeButton.getId()));
|
156 |
ilm |
907 |
panel.addControler(new LightController(LightController.TYPE_REMOVE, id, removeButton.getId()));
|
132 |
ilm |
908 |
toolbarLine.addChild(removeButton);
|
83 |
ilm |
909 |
|
132 |
ilm |
910 |
panel.addChild(toolbarLine);
|
83 |
ilm |
911 |
final LightUILine listLine = new LightUILine();
|
|
|
912 |
listLine.setWeightY(1);
|
|
|
913 |
listLine.setFillHeight(true);
|
132 |
ilm |
914 |
listLine.addChild(eList);
|
83 |
ilm |
915 |
|
|
|
916 |
//
|
132 |
ilm |
917 |
panel.addChild(listLine);
|
83 |
ilm |
918 |
|
132 |
ilm |
919 |
return panel;
|
174 |
ilm |
920 |
|
83 |
ilm |
921 |
}
|
|
|
922 |
|
174 |
ilm |
923 |
@Override
|
|
|
924 |
public void fillFrom(LightUIElement uiElement, SQLRowAccessor sqlRow) {
|
|
|
925 |
LightUIPanel p = (LightUIPanel) uiElement;
|
|
|
926 |
LightUITable ltable = p.getFirstChild(LightUITable.class);
|
|
|
927 |
TableSpec tSpec = ltable.getTableSpec();
|
|
|
928 |
ColumnsSpec columnsSpec = tSpec.getColumns();
|
|
|
929 |
// send: id,value
|
|
|
930 |
final SQLElement elem = configuration.getDirectory().getElement("DEVIS_ELEMENT");
|
|
|
931 |
final SQLTable table = elem.getTable();
|
|
|
932 |
final List<String> fieldsToFetch = new ArrayList<>();
|
|
|
933 |
for (ColumnSpec cs : columnsSpec.getColumns()) {
|
|
|
934 |
String colId = cs.getId();
|
|
|
935 |
SQLField f = configuration.getFieldMapper().getSQLFieldForItem(colId);
|
|
|
936 |
if (f != null) {
|
|
|
937 |
fieldsToFetch.add(f.getName());
|
|
|
938 |
} else {
|
|
|
939 |
throw new IllegalStateException("No field in " + table + " for column id " + colId);
|
|
|
940 |
}
|
|
|
941 |
}
|
|
|
942 |
|
|
|
943 |
final Where where = new Where(table.getField("ID_DEVIS"), "=", sqlRow.getID());
|
|
|
944 |
final ListSQLRequest req = elem.createListRequest(fieldsToFetch, where, configuration.getShowAs());
|
|
|
945 |
List<SQLRowValues> fetchedRows = req.getValues();
|
|
|
946 |
|
|
|
947 |
List<Row> rows = new ArrayList<>();
|
|
|
948 |
for (final SQLRowValues vals : fetchedRows) {
|
|
|
949 |
Row r = new Row(vals.getID(), columnsSpec.getColumns().size());
|
|
|
950 |
List<Object> values = new ArrayList<>();
|
|
|
951 |
for (ColumnSpec cs : columnsSpec.getColumns()) {
|
|
|
952 |
String colId = cs.getId();
|
|
|
953 |
SQLField f = configuration.getFieldMapper().getSQLFieldForItem(colId);
|
|
|
954 |
if (f != null) {
|
|
|
955 |
Object object = vals.getObject(f.getName());
|
|
|
956 |
if (object instanceof SQLRowValues) {
|
|
|
957 |
SQLRowValues sqlRowValues = (SQLRowValues) object;
|
|
|
958 |
long rowId = sqlRowValues.getIDNumber().longValue();
|
|
|
959 |
List<SQLField> fieldsToExpand = configuration.getShowAs().getFieldExpand(sqlRowValues.getTable());
|
|
|
960 |
final StringBuilder b = new StringBuilder();
|
|
|
961 |
for (SQLField sqlField : fieldsToExpand) {
|
|
|
962 |
b.append(sqlRowValues.getObject(sqlField.getName()).toString());
|
|
|
963 |
b.append(' ');
|
|
|
964 |
}
|
|
|
965 |
object = new StringWithId(rowId, b.toString().trim());
|
|
|
966 |
}
|
|
|
967 |
values.add(object);
|
|
|
968 |
} else {
|
|
|
969 |
throw new IllegalStateException("No field in " + table + " for column id " + colId);
|
|
|
970 |
}
|
|
|
971 |
}
|
|
|
972 |
r.setValues(values);
|
|
|
973 |
rows.add(r);
|
|
|
974 |
}
|
|
|
975 |
|
|
|
976 |
TableContent tableContent = new TableContent();
|
|
|
977 |
tableContent.setRows(rows);
|
|
|
978 |
tSpec.setContent(tableContent);
|
|
|
979 |
|
|
|
980 |
}
|
|
|
981 |
|
|
|
982 |
@Override
|
|
|
983 |
public void store(LightUIElement uiElement, SQLRowValues row) {
|
|
|
984 |
// TODO Auto-generated method stub
|
|
|
985 |
|
|
|
986 |
}
|
|
|
987 |
|
132 |
ilm |
988 |
});
|
|
|
989 |
return map;
|
83 |
ilm |
990 |
}
|
156 |
ilm |
991 |
|
|
|
992 |
@Override
|
|
|
993 |
protected String createCode() {
|
|
|
994 |
return "sales.quote";
|
|
|
995 |
}
|
18 |
ilm |
996 |
}
|