75 |
ilm |
1 |
package org.openconcerto.modules.project;
|
|
|
2 |
|
|
|
3 |
import java.awt.Color;
|
|
|
4 |
import java.awt.event.ActionEvent;
|
|
|
5 |
import java.io.IOException;
|
|
|
6 |
import java.sql.SQLException;
|
97 |
ilm |
7 |
import java.util.ArrayList;
|
75 |
ilm |
8 |
import java.util.Arrays;
|
|
|
9 |
import java.util.Collection;
|
|
|
10 |
import java.util.Date;
|
|
|
11 |
import java.util.List;
|
|
|
12 |
import java.util.Map;
|
|
|
13 |
import java.util.Set;
|
|
|
14 |
|
|
|
15 |
import javax.swing.AbstractAction;
|
|
|
16 |
import javax.swing.JComponent;
|
|
|
17 |
import javax.swing.JFrame;
|
97 |
ilm |
18 |
import javax.swing.JOptionPane;
|
75 |
ilm |
19 |
import javax.swing.JScrollPane;
|
97 |
ilm |
20 |
import javax.swing.SwingUtilities;
|
75 |
ilm |
21 |
|
|
|
22 |
import org.openconcerto.erp.action.CreateFrameAbstractAction;
|
97 |
ilm |
23 |
import org.openconcerto.erp.config.ComptaPropsConfiguration;
|
75 |
ilm |
24 |
import org.openconcerto.erp.config.MainFrame;
|
|
|
25 |
import org.openconcerto.erp.core.common.element.NumerotationAutoSQLElement;
|
|
|
26 |
import org.openconcerto.erp.core.sales.invoice.ui.SaisieVenteFactureItemTable;
|
|
|
27 |
import org.openconcerto.erp.core.sales.order.ui.CommandeClientItemTable;
|
|
|
28 |
import org.openconcerto.erp.core.sales.quote.component.DevisSQLComponent;
|
|
|
29 |
import org.openconcerto.erp.core.sales.quote.element.DevisSQLElement;
|
|
|
30 |
import org.openconcerto.erp.core.sales.quote.element.EtatDevisSQLElement;
|
|
|
31 |
import org.openconcerto.erp.core.sales.quote.report.DevisXmlSheet;
|
|
|
32 |
import org.openconcerto.erp.generationEcritures.GenerationMvtSaisieVenteFacture;
|
|
|
33 |
import org.openconcerto.erp.generationEcritures.provider.AccountingRecordsProvider;
|
|
|
34 |
import org.openconcerto.erp.generationEcritures.provider.AccountingRecordsProviderManager;
|
|
|
35 |
import org.openconcerto.erp.model.MouseSheetXmlListeListener;
|
|
|
36 |
import org.openconcerto.erp.modules.AbstractModule;
|
|
|
37 |
import org.openconcerto.erp.modules.AlterTableRestricted;
|
|
|
38 |
import org.openconcerto.erp.modules.ComponentsContext;
|
|
|
39 |
import org.openconcerto.erp.modules.DBContext;
|
|
|
40 |
import org.openconcerto.erp.modules.MenuContext;
|
|
|
41 |
import org.openconcerto.erp.modules.ModuleFactory;
|
|
|
42 |
import org.openconcerto.modules.project.element.ProjectSQLElement;
|
|
|
43 |
import org.openconcerto.modules.project.element.ProjectStateSQLElement;
|
|
|
44 |
import org.openconcerto.modules.project.element.ProjectTypeSQLElement;
|
|
|
45 |
import org.openconcerto.sql.Configuration;
|
|
|
46 |
import org.openconcerto.sql.element.SQLComponent;
|
|
|
47 |
import org.openconcerto.sql.element.SQLElement;
|
|
|
48 |
import org.openconcerto.sql.element.SQLElementDirectory;
|
|
|
49 |
import org.openconcerto.sql.model.DBRoot;
|
|
|
50 |
import org.openconcerto.sql.model.FieldPath;
|
|
|
51 |
import org.openconcerto.sql.model.SQLRow;
|
|
|
52 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
|
|
53 |
import org.openconcerto.sql.model.SQLRowValues;
|
|
|
54 |
import org.openconcerto.sql.model.SQLSelect;
|
|
|
55 |
import org.openconcerto.sql.model.SQLTable;
|
97 |
ilm |
56 |
import org.openconcerto.sql.model.SQLTableEvent;
|
|
|
57 |
import org.openconcerto.sql.model.SQLTableEvent.Mode;
|
|
|
58 |
import org.openconcerto.sql.model.SQLTableModifiedListener;
|
75 |
ilm |
59 |
import org.openconcerto.sql.model.Where;
|
128 |
ilm |
60 |
import org.openconcerto.sql.model.graph.Link.Direction;
|
75 |
ilm |
61 |
import org.openconcerto.sql.model.graph.Path;
|
|
|
62 |
import org.openconcerto.sql.utils.SQLCreateTable;
|
|
|
63 |
import org.openconcerto.sql.view.EditFrame;
|
|
|
64 |
import org.openconcerto.sql.view.IListFrame;
|
|
|
65 |
import org.openconcerto.sql.view.ListeAddPanel;
|
|
|
66 |
import org.openconcerto.sql.view.column.ColumnFooterRenderer;
|
|
|
67 |
import org.openconcerto.sql.view.column.ColumnPanel;
|
|
|
68 |
import org.openconcerto.sql.view.column.ColumnPanelFetcher;
|
|
|
69 |
import org.openconcerto.sql.view.column.ColumnRowRenderer;
|
|
|
70 |
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn;
|
|
|
71 |
import org.openconcerto.sql.view.list.IListe;
|
|
|
72 |
import org.openconcerto.sql.view.list.RowAction;
|
|
|
73 |
import org.openconcerto.utils.CollectionUtils;
|
97 |
ilm |
74 |
import org.openconcerto.utils.ExceptionHandler;
|
75 |
ilm |
75 |
import org.openconcerto.utils.Tuple2;
|
|
|
76 |
import org.openconcerto.utils.cc.IClosure;
|
|
|
77 |
import org.openconcerto.utils.cc.ITransformer;
|
|
|
78 |
import org.openconcerto.utils.i18n.TranslationManager;
|
|
|
79 |
|
|
|
80 |
public final class Module extends AbstractModule {
|
|
|
81 |
|
|
|
82 |
public static final String PROJECT_TABLENAME = "AFFAIRE";
|
|
|
83 |
private List<String> listTableAffaire = Arrays.asList("SAISIE_VENTE_FACTURE", "AVOIR_CLIENT", "BON_DE_LIVRAISON", "COMMANDE_CLIENT", "DEVIS", "COMMANDE", "SAISIE_ACHAT", "AVOIR_FOURNISSEUR");
|
|
|
84 |
|
|
|
85 |
public Module(ModuleFactory f) throws IOException {
|
|
|
86 |
super(f);
|
|
|
87 |
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
@Override
|
|
|
91 |
protected void install(DBContext ctxt) {
|
|
|
92 |
super.install(ctxt);
|
|
|
93 |
|
|
|
94 |
if (ctxt.getLastInstalledVersion() == null) {
|
|
|
95 |
|
|
|
96 |
if (ctxt.getRoot().getTable(PROJECT_TABLENAME) == null) {
|
|
|
97 |
final SQLCreateTable createTableEtatAff = ctxt.getCreateTable("ETAT_AFFAIRE");
|
|
|
98 |
createTableEtatAff.addVarCharColumn("NOM", 128);
|
|
|
99 |
|
|
|
100 |
final SQLCreateTable createTableType = ctxt.getCreateTable("TYPE_AFFAIRE");
|
|
|
101 |
createTableType.addVarCharColumn("NOM", 256);
|
|
|
102 |
|
|
|
103 |
// AFFAIRE
|
|
|
104 |
final SQLCreateTable createTable = ctxt.getCreateTable(PROJECT_TABLENAME);
|
|
|
105 |
createTable.addVarCharColumn("NUMERO", 256);
|
|
|
106 |
createTable.addVarCharColumn("NOM", 1024);
|
|
|
107 |
createTable.addVarCharColumn("INFOS", 1024);
|
|
|
108 |
createTable.addForeignColumn("ID_CLIENT", ctxt.getRoot().getTable("CLIENT"));
|
|
|
109 |
createTable.addForeignColumn("ID_DEVIS", ctxt.getRoot().getTable("DEVIS"));
|
|
|
110 |
createTable.addColumn("DATE", "date");
|
|
|
111 |
createTable.addForeignColumn("ID_COMMERCIAL", ctxt.getRoot().getTable("COMMERCIAL"));
|
|
|
112 |
createTable.addForeignColumn("ID_ETAT_AFFAIRE", createTableEtatAff);
|
|
|
113 |
createTable.addForeignColumn("ID_TYPE_AFFAIRE", createTableType);
|
|
|
114 |
|
|
|
115 |
for (String table : this.listTableAffaire) {
|
|
|
116 |
SQLTable tableDevis = ctxt.getRoot().getTable(table);
|
|
|
117 |
if (!tableDevis.getFieldsName().contains("ID_AFFAIRE")) {
|
|
|
118 |
AlterTableRestricted alter = ctxt.getAlterTable(table);
|
|
|
119 |
alter.addForeignColumn("ID_AFFAIRE", createTable);
|
|
|
120 |
}
|
|
|
121 |
}
|
|
|
122 |
ctxt.manipulateData(new IClosure<DBRoot>() {
|
|
|
123 |
@Override
|
|
|
124 |
public void executeChecked(DBRoot input) {
|
|
|
125 |
// Undefined Affaire
|
|
|
126 |
SQLTable tableAff = input.getTable(PROJECT_TABLENAME);
|
|
|
127 |
SQLRowValues rowVals = new SQLRowValues(tableAff);
|
|
|
128 |
try {
|
|
|
129 |
rowVals.insert();
|
|
|
130 |
} catch (SQLException exn) {
|
|
|
131 |
// TODO Bloc catch auto-généré
|
|
|
132 |
exn.printStackTrace();
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
// Etat Affaire
|
|
|
136 |
SQLTable tableTypeAffaire = input.getTable("TYPE_AFFAIRE");
|
|
|
137 |
rowVals = new SQLRowValues(tableTypeAffaire);
|
|
|
138 |
try {
|
|
|
139 |
rowVals.put("NOM", "Indéfini");
|
|
|
140 |
rowVals.insert();
|
|
|
141 |
} catch (SQLException exn) {
|
|
|
142 |
// TODO Bloc catch auto-généré
|
|
|
143 |
exn.printStackTrace();
|
|
|
144 |
}
|
|
|
145 |
|
|
|
146 |
// Etat Affaire
|
|
|
147 |
SQLTable tableEtatAffaire = input.getTable("ETAT_AFFAIRE");
|
|
|
148 |
rowVals = new SQLRowValues(tableEtatAffaire);
|
|
|
149 |
try {
|
|
|
150 |
rowVals.put("NOM", "Indéfini");
|
|
|
151 |
rowVals.insert();
|
|
|
152 |
|
|
|
153 |
rowVals.clear();
|
|
|
154 |
rowVals.put("NOM", "A traiter");
|
|
|
155 |
rowVals.insert();
|
|
|
156 |
|
|
|
157 |
rowVals.clear();
|
|
|
158 |
rowVals.put("NOM", "En cours");
|
|
|
159 |
rowVals.insert();
|
|
|
160 |
|
|
|
161 |
rowVals.clear();
|
|
|
162 |
rowVals.put("NOM", "Traitement terminé");
|
|
|
163 |
rowVals.insert();
|
|
|
164 |
|
|
|
165 |
rowVals.clear();
|
|
|
166 |
rowVals.put("NOM", "A facturer");
|
|
|
167 |
rowVals.insert();
|
|
|
168 |
|
|
|
169 |
rowVals.clear();
|
|
|
170 |
rowVals.put("NOM", "Dossier clos");
|
|
|
171 |
rowVals.insert();
|
|
|
172 |
} catch (SQLException exn) {
|
|
|
173 |
exn.printStackTrace();
|
|
|
174 |
}
|
|
|
175 |
|
|
|
176 |
}
|
|
|
177 |
});
|
|
|
178 |
}
|
|
|
179 |
}
|
|
|
180 |
|
|
|
181 |
}
|
|
|
182 |
|
|
|
183 |
@Override
|
|
|
184 |
protected void setupElements(final SQLElementDirectory dir) {
|
|
|
185 |
super.setupElements(dir);
|
|
|
186 |
TranslationManager.getInstance().addTranslationStreamFromClass(this.getClass());
|
|
|
187 |
dir.addSQLElement(ProjectSQLElement.class);
|
|
|
188 |
dir.addSQLElement(ProjectStateSQLElement.class);
|
|
|
189 |
dir.addSQLElement(ProjectTypeSQLElement.class);
|
|
|
190 |
|
|
|
191 |
final SQLElement element = dir.getElement("DEVIS");
|
|
|
192 |
DevisSQLElement eltDevis = dir.getElement(DevisSQLElement.class);
|
|
|
193 |
eltDevis.getRowActions().clear();
|
|
|
194 |
|
|
|
195 |
eltDevis.addListColumn(new BaseSQLTableModelColumn("Temps Total", Double.class) {
|
|
|
196 |
|
|
|
197 |
SQLTable tableDevisElt = Configuration.getInstance().getDirectory().getElement("DEVIS_ELEMENT").getTable();
|
|
|
198 |
|
|
|
199 |
@Override
|
|
|
200 |
protected Object show_(SQLRowAccessor r) {
|
|
|
201 |
|
|
|
202 |
Collection<? extends SQLRowAccessor> rows = r.getReferentRows(tableDevisElt);
|
|
|
203 |
double time = 0;
|
|
|
204 |
for (SQLRowAccessor sqlRowAccessor : rows) {
|
|
|
205 |
time += OrderColumnRowRenderer.getHours(sqlRowAccessor);
|
|
|
206 |
}
|
|
|
207 |
return time;
|
|
|
208 |
}
|
|
|
209 |
|
|
|
210 |
@Override
|
|
|
211 |
public Set<FieldPath> getPaths() {
|
|
|
212 |
SQLTable table = Configuration.getInstance().getDirectory().getElement("DEVIS").getTable();
|
88 |
ilm |
213 |
Path p = new Path(table).add(tableDevisElt.getField("ID_DEVIS"));
|
75 |
ilm |
214 |
|
88 |
ilm |
215 |
Path p2 = new Path(table).add(tableDevisElt.getField("ID_DEVIS")).addForeignField("ID_UNITE_VENTE");
|
75 |
ilm |
216 |
return CollectionUtils.createSet(new FieldPath(p, "QTE"), new FieldPath(p, "QTE_UNITAIRE"), new FieldPath(p2, "CODE"));
|
|
|
217 |
}
|
|
|
218 |
});
|
|
|
219 |
|
|
|
220 |
// Transfert vers facture
|
|
|
221 |
RowAction factureAction = eltDevis.getDevis2FactureAction();
|
|
|
222 |
eltDevis.getRowActions().add(factureAction);
|
|
|
223 |
|
|
|
224 |
// Transfert vers commande
|
|
|
225 |
RowAction commandeAction = eltDevis.getDevis2CmdCliAction();
|
|
|
226 |
eltDevis.getRowActions().add(commandeAction);
|
|
|
227 |
|
|
|
228 |
// Marqué accepté
|
|
|
229 |
RowAction accepteAction = getAcceptAction();
|
|
|
230 |
eltDevis.getRowActions().add(accepteAction);
|
|
|
231 |
|
|
|
232 |
// Marqué accepté
|
|
|
233 |
RowAction refuseAction = eltDevis.getRefuseAction();
|
|
|
234 |
eltDevis.getRowActions().add(refuseAction);
|
|
|
235 |
|
|
|
236 |
// // Dupliquer
|
|
|
237 |
RowAction cloneAction = eltDevis.getCloneAction();
|
|
|
238 |
eltDevis.getRowActions().add(cloneAction);
|
|
|
239 |
|
|
|
240 |
MouseSheetXmlListeListener mouseSheetXmlListeListener = new MouseSheetXmlListeListener(DevisXmlSheet.class);
|
|
|
241 |
mouseSheetXmlListeListener.setGenerateHeader(true);
|
|
|
242 |
mouseSheetXmlListeListener.setShowHeader(true);
|
|
|
243 |
eltDevis.getRowActions().addAll(mouseSheetXmlListeListener.getRowActions());
|
|
|
244 |
|
|
|
245 |
element.addComponentFactory(SQLElement.DEFAULT_COMP_ID, new ITransformer<Tuple2<SQLElement, String>, SQLComponent>() {
|
|
|
246 |
|
|
|
247 |
@Override
|
|
|
248 |
public SQLComponent transformChecked(Tuple2<SQLElement, String> input) {
|
|
|
249 |
return new DevisSQLComponent(element) {
|
|
|
250 |
|
|
|
251 |
public int insert(SQLRow order) {
|
|
|
252 |
int id = super.insert(order);
|
|
|
253 |
checkAffaire(id);
|
|
|
254 |
return id;
|
|
|
255 |
}
|
|
|
256 |
|
|
|
257 |
public void update() {
|
|
|
258 |
super.update();
|
|
|
259 |
checkAffaire(getSelectedID());
|
|
|
260 |
}
|
|
|
261 |
|
|
|
262 |
};
|
|
|
263 |
}
|
|
|
264 |
});
|
|
|
265 |
|
|
|
266 |
final SQLElement elementCmd = dir.getElement("COMMANDE_CLIENT");
|
|
|
267 |
elementCmd.addListColumn(new BaseSQLTableModelColumn("Temps Total", Double.class) {
|
|
|
268 |
|
|
|
269 |
SQLTable tableCmdElt = dir.getElement("COMMANDE_CLIENT_ELEMENT").getTable();
|
|
|
270 |
|
|
|
271 |
@Override
|
|
|
272 |
protected Object show_(SQLRowAccessor r) {
|
|
|
273 |
|
|
|
274 |
Collection<? extends SQLRowAccessor> rows = r.getReferentRows(tableCmdElt);
|
|
|
275 |
double time = 0;
|
|
|
276 |
for (SQLRowAccessor sqlRowAccessor : rows) {
|
|
|
277 |
time += OrderColumnRowRenderer.getHours(sqlRowAccessor);
|
|
|
278 |
}
|
|
|
279 |
return time;
|
|
|
280 |
}
|
|
|
281 |
|
|
|
282 |
@Override
|
|
|
283 |
public Set<FieldPath> getPaths() {
|
|
|
284 |
final SQLTable table = elementCmd.getTable();
|
88 |
ilm |
285 |
final Path p = new Path(table).add(tableCmdElt.getField("ID_COMMANDE_CLIENT"));
|
|
|
286 |
final Path p2 = new Path(table).add(tableCmdElt.getField("ID_COMMANDE_CLIENT")).addForeignField("ID_UNITE_VENTE");
|
75 |
ilm |
287 |
return CollectionUtils.createSet(new FieldPath(p, "QTE"), new FieldPath(p, "QTE_UNITAIRE"), new FieldPath(p2, "CODE"));
|
|
|
288 |
}
|
|
|
289 |
});
|
|
|
290 |
|
|
|
291 |
NumerotationAutoSQLElement.addClass(ProjectSQLElement.class, PROJECT_TABLENAME);
|
|
|
292 |
|
128 |
ilm |
293 |
for (String tableName : this.listTableAffaire) {
|
|
|
294 |
if (!tableName.equalsIgnoreCase("DEVIS")) {
|
|
|
295 |
final SQLElement elt = dir.getElement(tableName);
|
|
|
296 |
RowAction action = new RowAction(new AbstractAction("Historique affaire") {
|
|
|
297 |
@Override
|
|
|
298 |
public void actionPerformed(ActionEvent e) {
|
|
|
299 |
ProjectHistory histo = new ProjectHistory();
|
|
|
300 |
histo.getHistoriquePanel().selectIDinJList(IListe.get(e).getSelectedRow().getForeignID("ID_AFFAIRE"));
|
|
|
301 |
histo.getFrame().setVisible(true);
|
|
|
302 |
}
|
|
|
303 |
}, false) {
|
|
|
304 |
@Override
|
|
|
305 |
public boolean enabledFor(IListeEvent evt) {
|
|
|
306 |
if (evt.getSelectedRows().size() == 1) {
|
|
|
307 |
SQLRowAccessor r = evt.getSelectedRow();
|
|
|
308 |
return !r.isForeignEmpty("ID_AFFAIRE");
|
|
|
309 |
}
|
|
|
310 |
return false;
|
|
|
311 |
}
|
|
|
312 |
};
|
|
|
313 |
|
|
|
314 |
elt.getRowActions().add(action);
|
|
|
315 |
elt.addListColumn(new BaseSQLTableModelColumn("Affaire", String.class) {
|
|
|
316 |
|
|
|
317 |
@Override
|
|
|
318 |
protected Object show_(SQLRowAccessor r) {
|
|
|
319 |
if (!r.isForeignEmpty("ID_AFFAIRE") && r.getForeign("ID_AFFAIRE") != null) {
|
|
|
320 |
return r.getForeign("ID_AFFAIRE").getString("NUMERO");
|
|
|
321 |
} else {
|
|
|
322 |
return "";
|
|
|
323 |
}
|
|
|
324 |
}
|
|
|
325 |
|
|
|
326 |
@Override
|
|
|
327 |
public Set<FieldPath> getPaths() {
|
|
|
328 |
SQLTable table = elt.getTable();
|
|
|
329 |
Path p = new Path(table).add(table.getField("ID_AFFAIRE"));
|
|
|
330 |
return CollectionUtils.createSet(new FieldPath(p, "NUMERO"));
|
|
|
331 |
}
|
|
|
332 |
});
|
|
|
333 |
}
|
|
|
334 |
}
|
|
|
335 |
|
|
|
336 |
final SQLElement elt = dir.getElement("DEVIS");
|
|
|
337 |
RowAction action = new RowAction(new AbstractAction("Historique affaire") {
|
|
|
338 |
@Override
|
|
|
339 |
public void actionPerformed(ActionEvent e) {
|
|
|
340 |
ProjectHistory histo = new ProjectHistory();
|
|
|
341 |
SQLRowAccessor selectedRow = IListe.get(e).getSelectedRow();
|
|
|
342 |
Collection<? extends SQLRowAccessor> l = selectedRow.getReferentRows(selectedRow.getTable().getTable("AFFAIRE"));
|
|
|
343 |
histo.getHistoriquePanel().selectIDinJList(l.iterator().next().getID());
|
|
|
344 |
histo.getFrame().setVisible(true);
|
|
|
345 |
}
|
|
|
346 |
}, false) {
|
|
|
347 |
@Override
|
|
|
348 |
public boolean enabledFor(IListeEvent evt) {
|
|
|
349 |
if (evt.getSelectedRows().size() == 1) {
|
|
|
350 |
SQLRowAccessor r = evt.getSelectedRow();
|
|
|
351 |
Collection<? extends SQLRowAccessor> l = r.getReferentRows(r.getTable().getTable("AFFAIRE"));
|
|
|
352 |
return l.size() > 0;
|
|
|
353 |
}
|
|
|
354 |
return false;
|
|
|
355 |
}
|
|
|
356 |
};
|
|
|
357 |
|
|
|
358 |
elt.getRowActions().add(action);
|
|
|
359 |
|
|
|
360 |
elt.addListColumn(new BaseSQLTableModelColumn("Affaire", String.class) {
|
|
|
361 |
|
|
|
362 |
@Override
|
|
|
363 |
protected Object show_(SQLRowAccessor r) {
|
|
|
364 |
Collection<? extends SQLRowAccessor> rows = r.getReferentRows(elt.getTable().getTable("AFFAIRE"));
|
|
|
365 |
if (rows.size() == 1) {
|
|
|
366 |
return rows.iterator().next().getString("NUMERO");
|
|
|
367 |
} else {
|
|
|
368 |
return "";
|
|
|
369 |
}
|
|
|
370 |
}
|
|
|
371 |
|
|
|
372 |
@Override
|
|
|
373 |
public Set<FieldPath> getPaths() {
|
|
|
374 |
SQLTable table = elt.getTable();
|
|
|
375 |
Path p = new Path(table).add(table.getTable("AFFAIRE"), Direction.REFERENT);
|
|
|
376 |
return CollectionUtils.createSet(new FieldPath(p, "NUMERO"));
|
|
|
377 |
}
|
|
|
378 |
});
|
|
|
379 |
|
75 |
ilm |
380 |
new QuoteToOrderSQLInjector();
|
|
|
381 |
new QuoteToInvoiceSQLInjector();
|
|
|
382 |
new OrderToInvoiceSQLInjector();
|
|
|
383 |
}
|
|
|
384 |
|
|
|
385 |
public void checkAffaire(int id) {
|
|
|
386 |
final SQLTable tableDevis = Configuration.getInstance().getRoot().findTable("DEVIS");
|
|
|
387 |
final SQLTable tableNum = Configuration.getInstance().getRoot().findTable("NUMEROTATION_AUTO");
|
|
|
388 |
final SQLRow row = tableDevis.getRow(id);
|
|
|
389 |
final SQLRow rowAffaire = row.getForeign("ID_AFFAIRE");
|
|
|
390 |
if (rowAffaire == null || rowAffaire.isUndefined()) {
|
|
|
391 |
if (row.getInt("ID_ETAT_DEVIS") == EtatDevisSQLElement.ACCEPTE) {
|
|
|
392 |
// FIXME Vérifier si le devis n'est pas déjà rattaché à une affaire
|
|
|
393 |
final SQLTable table = tableDevis.getTable(PROJECT_TABLENAME);
|
|
|
394 |
final SQLRowValues rowVals = new SQLRowValues(table);
|
|
|
395 |
|
|
|
396 |
final String nextNumero = NumerotationAutoSQLElement.getNextNumero(ProjectSQLElement.class);
|
|
|
397 |
rowVals.put("NUMERO", nextNumero);
|
|
|
398 |
|
|
|
399 |
// incrémentation du numéro auto
|
|
|
400 |
final SQLRowValues rowValsNum = new SQLRowValues(tableNum);
|
|
|
401 |
int val = tableNum.getRow(2).getInt(NumerotationAutoSQLElement.getLabelNumberFor(ProjectSQLElement.class));
|
|
|
402 |
val++;
|
|
|
403 |
rowValsNum.put(NumerotationAutoSQLElement.getLabelNumberFor(ProjectSQLElement.class), new Integer(val));
|
|
|
404 |
try {
|
|
|
405 |
rowValsNum.update(2);
|
|
|
406 |
} catch (final SQLException e) {
|
|
|
407 |
e.printStackTrace();
|
|
|
408 |
}
|
|
|
409 |
|
|
|
410 |
rowVals.put("ID_DEVIS", row.getID());
|
|
|
411 |
rowVals.put("ID_CLIENT", row.getObject("ID_CLIENT"));
|
|
|
412 |
rowVals.put("ID_COMMERCIAL", row.getObject("ID_COMMERCIAL"));
|
|
|
413 |
rowVals.put("DATE", new Date());
|
|
|
414 |
rowVals.put("ID_ETAT_AFFAIRE", ProjectStateSQLElement.EN_COURS);
|
|
|
415 |
|
|
|
416 |
SQLRowValues rowValsDevis = row.asRowValues();
|
|
|
417 |
rowValsDevis.put("ID_AFFAIRE", rowVals);
|
|
|
418 |
|
|
|
419 |
try {
|
|
|
420 |
rowVals.commit();
|
|
|
421 |
} catch (SQLException exn) {
|
|
|
422 |
// TODO Bloc catch auto-généré
|
|
|
423 |
exn.printStackTrace();
|
|
|
424 |
}
|
|
|
425 |
}
|
|
|
426 |
} else {
|
|
|
427 |
SQLRowValues rowVals = rowAffaire.asRowValues();
|
|
|
428 |
rowVals.putEmptyLink("ID_DEVIS");
|
|
|
429 |
try {
|
|
|
430 |
rowVals.update();
|
|
|
431 |
} catch (SQLException exn) {
|
|
|
432 |
// TODO Bloc catch auto-généré
|
|
|
433 |
exn.printStackTrace();
|
|
|
434 |
}
|
|
|
435 |
}
|
|
|
436 |
}
|
|
|
437 |
|
97 |
ilm |
438 |
List<Integer> idsAsked = new ArrayList<Integer>();
|
|
|
439 |
|
|
|
440 |
public void checkProjectState(final SQLRowAccessor rowFact) {
|
|
|
441 |
if (!rowFact.isForeignEmpty("ID_AFFAIRE")) {
|
|
|
442 |
final SQLRowAccessor rowAff = rowFact.getForeign("ID_AFFAIRE");
|
|
|
443 |
|
|
|
444 |
if (rowAff.getInt("ID_ETAT_AFFAIRE") < ProjectStateSQLElement.DOSSIER_CLOS) {
|
|
|
445 |
|
|
|
446 |
SQLSelect sel = new SQLSelect();
|
|
|
447 |
final SQLTable tableVF = rowFact.getTable();
|
|
|
448 |
sel.addSelect(tableVF.getField("T_TTC"), "SUM");
|
|
|
449 |
Where w = new Where(tableVF.getField("ID_AFFAIRE"), "=", rowAff.getID());
|
|
|
450 |
sel.setWhere(w);
|
|
|
451 |
|
|
|
452 |
Number total = (Number) tableVF.getDBSystemRoot().getDataSource().executeScalar(sel.asString());
|
|
|
453 |
|
|
|
454 |
long devis = rowAff.getForeign("ID_DEVIS").getLong("T_TTC");
|
|
|
455 |
if (devis == total.longValue()) {
|
|
|
456 |
if (!idsAsked.contains(rowFact.getID())) {
|
|
|
457 |
idsAsked.add(rowFact.getID());
|
|
|
458 |
SwingUtilities.invokeLater(new Runnable() {
|
|
|
459 |
|
|
|
460 |
@Override
|
|
|
461 |
public void run() {
|
|
|
462 |
int a = JOptionPane.showConfirmDialog(null, "Voulez vous passer l'affaire " + rowAff.getString("NUMERO") + " dans l'état \"Dossier Clos\"?", "Affaire 100% facturée",
|
|
|
463 |
JOptionPane.YES_NO_OPTION);
|
|
|
464 |
if (a == JOptionPane.YES_OPTION) {
|
|
|
465 |
SQLRowValues rowVals = rowAff.createEmptyUpdateRow();
|
|
|
466 |
rowVals.put("ID_ETAT_AFFAIRE", ProjectStateSQLElement.DOSSIER_CLOS);
|
|
|
467 |
try {
|
|
|
468 |
rowVals.commit();
|
|
|
469 |
} catch (SQLException e) {
|
|
|
470 |
ExceptionHandler.handle("Erreur lors de la mise à jour de l'état de l'affaire", e);
|
|
|
471 |
}
|
|
|
472 |
}
|
|
|
473 |
idsAsked.remove(Integer.valueOf(rowFact.getID()));
|
|
|
474 |
}
|
|
|
475 |
});
|
|
|
476 |
}
|
|
|
477 |
}
|
|
|
478 |
|
|
|
479 |
}
|
|
|
480 |
}
|
|
|
481 |
}
|
|
|
482 |
|
75 |
ilm |
483 |
public RowAction getAcceptAction() {
|
|
|
484 |
return new RowAction(new AbstractAction() {
|
|
|
485 |
public void actionPerformed(ActionEvent e) {
|
88 |
ilm |
486 |
SQLRow selectedRow = IListe.get(e).getSelectedRow().asRow();
|
75 |
ilm |
487 |
SQLRowValues rowVals = selectedRow.createEmptyUpdateRow();
|
|
|
488 |
rowVals.put("ID_ETAT_DEVIS", EtatDevisSQLElement.ACCEPTE);
|
|
|
489 |
try {
|
|
|
490 |
rowVals.update();
|
|
|
491 |
} catch (SQLException e1) {
|
|
|
492 |
e1.printStackTrace();
|
|
|
493 |
}
|
|
|
494 |
selectedRow.getTable().fireTableModified(selectedRow.getID());
|
|
|
495 |
checkAffaire(selectedRow.getID());
|
|
|
496 |
}
|
|
|
497 |
}, false, "project.accept") {
|
97 |
ilm |
498 |
public boolean enabledFor(List<SQLRowValues> selection) {
|
75 |
ilm |
499 |
if (selection != null && selection.size() == 1) {
|
|
|
500 |
if (selection.get(0).getInt("ID_ETAT_DEVIS") == EtatDevisSQLElement.EN_ATTENTE) {
|
|
|
501 |
return true;
|
|
|
502 |
}
|
|
|
503 |
}
|
|
|
504 |
return false;
|
|
|
505 |
};
|
|
|
506 |
};
|
|
|
507 |
}
|
|
|
508 |
|
|
|
509 |
@Override
|
|
|
510 |
protected void setupComponents(final ComponentsContext ctxt) {
|
|
|
511 |
|
|
|
512 |
for (String table : this.listTableAffaire) {
|
|
|
513 |
if (!table.equalsIgnoreCase("DEVIS"))
|
|
|
514 |
ctxt.putAdditionalField(table, "ID_AFFAIRE");
|
|
|
515 |
}
|
|
|
516 |
}
|
|
|
517 |
|
|
|
518 |
@Override
|
|
|
519 |
protected void setupMenu(final MenuContext ctxt) {
|
|
|
520 |
ctxt.addMenuItem(new CreateFrameAbstractAction("Liste des affaires") {
|
|
|
521 |
@Override
|
|
|
522 |
public JFrame createFrame() {
|
|
|
523 |
IListFrame frame = new IListFrame(new ListeAddPanel(ctxt.getElement(PROJECT_TABLENAME)));
|
|
|
524 |
return frame;
|
|
|
525 |
}
|
|
|
526 |
}, MainFrame.LIST_MENU);
|
|
|
527 |
ctxt.addMenuItem(new CreateFrameAbstractAction("Historique des affaires") {
|
|
|
528 |
@Override
|
|
|
529 |
public JFrame createFrame() {
|
|
|
530 |
ProjectHistory histo = new ProjectHistory();
|
|
|
531 |
|
|
|
532 |
return histo.getFrame();
|
|
|
533 |
}
|
|
|
534 |
}, MainFrame.LIST_MENU);
|
|
|
535 |
|
|
|
536 |
ctxt.addMenuItem(new CreateFrameAbstractAction("Saisie affaire") {
|
|
|
537 |
@Override
|
|
|
538 |
public JFrame createFrame() {
|
|
|
539 |
return new EditFrame(ctxt.getElement(PROJECT_TABLENAME));
|
|
|
540 |
}
|
|
|
541 |
}, MainFrame.CREATE_MENU);
|
|
|
542 |
|
|
|
543 |
}
|
|
|
544 |
|
|
|
545 |
@Override
|
|
|
546 |
protected void start() {
|
|
|
547 |
final JComponent quoteComponent = createQuotePanel();
|
|
|
548 |
final JComponent orderComponent = createOrderPanel();
|
|
|
549 |
MainFrame.getInstance().getTabbedPane().addTab("Commandes en cours", orderComponent);
|
|
|
550 |
MainFrame.getInstance().getTabbedPane().addTab("Devis en attente", quoteComponent);
|
|
|
551 |
MainFrame.getInstance().getTabbedPane().addTab("Affaires", new ListeAddPanel(Configuration.getInstance().getDirectory().getElement(PROJECT_TABLENAME)));
|
|
|
552 |
// Fix for classic XP Theme
|
|
|
553 |
quoteComponent.setOpaque(true);
|
|
|
554 |
quoteComponent.setBackground(Color.WHITE);
|
|
|
555 |
orderComponent.setOpaque(true);
|
|
|
556 |
orderComponent.setBackground(Color.WHITE);
|
|
|
557 |
// Select first tab
|
|
|
558 |
MainFrame.getInstance().getTabbedPane().setSelectedIndex(1);
|
|
|
559 |
|
|
|
560 |
CommandeClientItemTable.getVisibilityMap().put("POURCENT_ACOMPTE", Boolean.TRUE);
|
|
|
561 |
SaisieVenteFactureItemTable.getVisibilityMap().put("POURCENT_ACOMPTE", Boolean.TRUE);
|
|
|
562 |
AccountingRecordsProvider p = new AccountingRecordsProvider() {
|
|
|
563 |
|
|
|
564 |
@Override
|
|
|
565 |
public void putLabel(SQLRowAccessor rowSource, Map<String, Object> values) {
|
|
|
566 |
values.put("NOM", "Fact. vente " + rowSource.getString("NUMERO"));
|
|
|
567 |
}
|
|
|
568 |
|
|
|
569 |
@Override
|
|
|
570 |
public void putPieceLabel(SQLRowAccessor rowSource, SQLRowValues rowValsPiece) {
|
|
|
571 |
rowValsPiece.put("NOM", rowSource.getString("NUMERO"));
|
|
|
572 |
}
|
|
|
573 |
};
|
|
|
574 |
AccountingRecordsProviderManager.put(GenerationMvtSaisieVenteFacture.ID, p);
|
97 |
ilm |
575 |
|
|
|
576 |
final SQLTable tableFact = ComptaPropsConfiguration.getInstanceCompta().getRootSociete().getTable("SAISIE_VENTE_FACTURE");
|
|
|
577 |
|
|
|
578 |
tableFact.addTableModifiedListener(new SQLTableModifiedListener() {
|
|
|
579 |
|
|
|
580 |
@Override
|
|
|
581 |
public void tableModified(SQLTableEvent evt) {
|
|
|
582 |
if (evt.getMode() == Mode.ROW_ADDED || evt.getMode() == Mode.ROW_UPDATED) {
|
|
|
583 |
checkProjectState(evt.getRow());
|
|
|
584 |
}
|
|
|
585 |
}
|
|
|
586 |
});
|
75 |
ilm |
587 |
}
|
|
|
588 |
|
|
|
589 |
private JComponent createQuotePanel() {
|
|
|
590 |
ColumnRowRenderer cRenderer = new QuoteColumnRowRenderer();
|
|
|
591 |
ColumnFooterRenderer fRenderer = new QuoteColumnFooterRenderer();
|
|
|
592 |
final ColumnPanel columnPanel = new ColumnPanel(220, cRenderer, fRenderer);
|
|
|
593 |
columnPanel.setOpaque(false);
|
|
|
594 |
final SQLElement element = Configuration.getInstance().getDirectory().getElement("DEVIS_ELEMENT");
|
88 |
ilm |
595 |
Path p = Path.get(element.getTable()).addForeignField("ID_ARTICLE").addForeignField("ID_FAMILLE_ARTICLE");
|
75 |
ilm |
596 |
|
|
|
597 |
SQLRowValues values = new SQLRowValues(element.getTable());
|
|
|
598 |
values.put("NOM", null);
|
|
|
599 |
values.put("T_PV_HT", null);
|
|
|
600 |
SQLRowValues rowValsClient = new SQLRowValues(element.getTable().getTable("CLIENT"));
|
|
|
601 |
rowValsClient.put("NOM", null);
|
|
|
602 |
final SQLTable tableDevis = element.getTable().getTable("DEVIS");
|
|
|
603 |
SQLRowValues rowValsDevis = new SQLRowValues(tableDevis);
|
|
|
604 |
rowValsDevis.put("NUMERO", null);
|
|
|
605 |
rowValsDevis.put("DATE", null);
|
|
|
606 |
rowValsDevis.put("T_HT", null);
|
|
|
607 |
|
|
|
608 |
rowValsDevis.put("ID_CLIENT", rowValsClient);
|
|
|
609 |
values.put("ID_DEVIS", rowValsDevis);
|
|
|
610 |
SQLRowValues rowValsUnite = new SQLRowValues(element.getTable().getTable("UNITE_VENTE"));
|
|
|
611 |
rowValsUnite.put("CODE", null);
|
|
|
612 |
values.put("ID_UNITE_VENTE", rowValsUnite);
|
|
|
613 |
values.put("QTE", null);
|
|
|
614 |
values.put("QTE_UNITAIRE", null);
|
|
|
615 |
|
|
|
616 |
ITransformer<SQLSelect, SQLSelect> t = new ITransformer<SQLSelect, SQLSelect>() {
|
|
|
617 |
@Override
|
|
|
618 |
public SQLSelect transformChecked(SQLSelect input) {
|
|
|
619 |
input.andWhere(new Where(input.getAlias(tableDevis.getField("ID_ETAT_DEVIS")), "=", EtatDevisSQLElement.EN_ATTENTE));
|
|
|
620 |
return input;
|
|
|
621 |
}
|
|
|
622 |
};
|
|
|
623 |
final ColumnPanelFetcher projectFetcher = new ColumnPanelFetcher(values, new FieldPath(p, "NOM"), t);
|
|
|
624 |
columnPanel.setHeaderRenderer(new TotalHeaderRenderer());
|
|
|
625 |
columnPanel.setFetch(projectFetcher);
|
|
|
626 |
|
|
|
627 |
final JScrollPane comp = new JScrollPane(columnPanel);
|
|
|
628 |
comp.setBorder(null);
|
|
|
629 |
comp.getViewport().setOpaque(false);
|
|
|
630 |
return comp;
|
|
|
631 |
}
|
|
|
632 |
|
|
|
633 |
private JComponent createOrderPanel() {
|
|
|
634 |
ColumnRowRenderer cRenderer = new OrderColumnRowRenderer();
|
|
|
635 |
ColumnFooterRenderer fRenderer = new OrderColumnFooterRenderer();
|
|
|
636 |
final ColumnPanel columnPanel = new ColumnPanel(220, cRenderer, fRenderer);
|
|
|
637 |
columnPanel.setOpaque(false);
|
|
|
638 |
final SQLElement element = Configuration.getInstance().getDirectory().getElement("COMMANDE_CLIENT_ELEMENT");
|
|
|
639 |
final SQLTable tableOrder = element.getTable();
|
88 |
ilm |
640 |
Path p = Path.get(tableOrder).addForeignField("ID_ARTICLE").addForeignField("ID_FAMILLE_ARTICLE");
|
75 |
ilm |
641 |
|
|
|
642 |
SQLRowValues values = new SQLRowValues(tableOrder);
|
|
|
643 |
values.put("NOM", null);
|
|
|
644 |
values.put("T_PV_HT", null);
|
|
|
645 |
SQLRowValues rowValsClient = new SQLRowValues(tableOrder.getTable("CLIENT"));
|
|
|
646 |
rowValsClient.put("NOM", null);
|
|
|
647 |
SQLRowValues rowValsCmd = new SQLRowValues(tableOrder.getTable("COMMANDE_CLIENT"));
|
|
|
648 |
rowValsCmd.put("NUMERO", null);
|
|
|
649 |
rowValsCmd.put("DATE", null);
|
|
|
650 |
rowValsCmd.put("T_HT", null);
|
|
|
651 |
|
|
|
652 |
rowValsCmd.put("ID_CLIENT", rowValsClient);
|
|
|
653 |
values.put("ID_COMMANDE_CLIENT", rowValsCmd);
|
|
|
654 |
SQLRowValues rowValsUnite = new SQLRowValues(tableOrder.getTable("UNITE_VENTE"));
|
|
|
655 |
rowValsUnite.put("CODE", null);
|
|
|
656 |
values.put("ID_UNITE_VENTE", rowValsUnite);
|
|
|
657 |
values.put("QTE", null);
|
|
|
658 |
values.put("QTE_UNITAIRE", null);
|
|
|
659 |
|
|
|
660 |
final SQLTable tableAffaire = tableOrder.getTable(PROJECT_TABLENAME);
|
|
|
661 |
SQLRowValues rowValsAffaire = new SQLRowValues(tableAffaire);
|
|
|
662 |
rowValsAffaire.put("NUMERO", null);
|
|
|
663 |
rowValsAffaire.put("DATE", null);
|
|
|
664 |
rowValsCmd.put("ID_AFFAIRE", rowValsAffaire);
|
|
|
665 |
|
|
|
666 |
if (tableOrder.getDBRoot().contains("AFFAIRE_TEMPS")) {
|
|
|
667 |
final SQLTable tableAffaireTemps = tableOrder.getTable("AFFAIRE_TEMPS");
|
|
|
668 |
SQLRowValues rowValsAffaireTemps = new SQLRowValues(tableAffaireTemps);
|
|
|
669 |
rowValsAffaireTemps.put("TEMPS", null);
|
|
|
670 |
rowValsAffaireTemps.put("ID_COMMANDE_CLIENT_ELEMENT", values);
|
|
|
671 |
}
|
|
|
672 |
ITransformer<SQLSelect, SQLSelect> t = new ITransformer<SQLSelect, SQLSelect>() {
|
|
|
673 |
@Override
|
|
|
674 |
public SQLSelect transformChecked(SQLSelect input) {
|
|
|
675 |
input.andWhere(new Where(input.getAlias(tableAffaire.getField("ID_ETAT_AFFAIRE")), "=", ProjectStateSQLElement.EN_COURS));
|
|
|
676 |
return input;
|
|
|
677 |
}
|
|
|
678 |
};
|
|
|
679 |
final ColumnPanelFetcher projectFetcher = new ColumnPanelFetcher(values, new FieldPath(p, "NOM"), t);
|
|
|
680 |
columnPanel.setHeaderRenderer(new TotalHeaderRenderer());
|
|
|
681 |
columnPanel.setFetch(projectFetcher);
|
|
|
682 |
final JScrollPane comp = new JScrollPane(columnPanel);
|
|
|
683 |
comp.setBorder(null);
|
|
|
684 |
comp.getViewport().setOpaque(false);
|
|
|
685 |
return comp;
|
|
|
686 |
}
|
|
|
687 |
|
|
|
688 |
@Override
|
|
|
689 |
protected void stop() {
|
|
|
690 |
}
|
|
|
691 |
}
|