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