OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 181 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
75 ilm 1
package org.openconcerto.modules.project;
2
 
3
import java.awt.Color;
152 ilm 4
import java.awt.GridBagConstraints;
5
import java.awt.GridBagLayout;
75 ilm 6
import java.awt.event.ActionEvent;
152 ilm 7
import java.awt.event.ActionListener;
8
import java.beans.PropertyChangeEvent;
9
import java.beans.PropertyChangeListener;
75 ilm 10
import java.io.IOException;
152 ilm 11
import java.math.BigDecimal;
12
import java.math.RoundingMode;
75 ilm 13
import java.sql.SQLException;
97 ilm 14
import java.util.ArrayList;
75 ilm 15
import java.util.Arrays;
16
import java.util.Collection;
17
import java.util.Date;
18
import java.util.List;
19
import java.util.Map;
20
import java.util.Set;
21
 
22
import javax.swing.AbstractAction;
152 ilm 23
import javax.swing.JButton;
75 ilm 24
import javax.swing.JComponent;
25
import javax.swing.JFrame;
152 ilm 26
import javax.swing.JLabel;
97 ilm 27
import javax.swing.JOptionPane;
152 ilm 28
import javax.swing.JPanel;
75 ilm 29
import javax.swing.JScrollPane;
97 ilm 30
import javax.swing.SwingUtilities;
75 ilm 31
 
32
import org.openconcerto.erp.action.CreateFrameAbstractAction;
97 ilm 33
import org.openconcerto.erp.config.ComptaPropsConfiguration;
75 ilm 34
import org.openconcerto.erp.config.MainFrame;
35
import org.openconcerto.erp.core.common.element.NumerotationAutoSQLElement;
36
import org.openconcerto.erp.core.sales.invoice.ui.SaisieVenteFactureItemTable;
37
import org.openconcerto.erp.core.sales.order.ui.CommandeClientItemTable;
38
import org.openconcerto.erp.core.sales.quote.component.DevisSQLComponent;
39
import org.openconcerto.erp.core.sales.quote.element.DevisSQLElement;
40
import org.openconcerto.erp.core.sales.quote.element.EtatDevisSQLElement;
41
import org.openconcerto.erp.core.sales.quote.report.DevisXmlSheet;
42
import org.openconcerto.erp.generationEcritures.GenerationMvtSaisieVenteFacture;
43
import org.openconcerto.erp.generationEcritures.provider.AccountingRecordsProvider;
44
import org.openconcerto.erp.generationEcritures.provider.AccountingRecordsProviderManager;
45
import org.openconcerto.erp.model.MouseSheetXmlListeListener;
46
import org.openconcerto.erp.modules.AbstractModule;
47
import org.openconcerto.erp.modules.AlterTableRestricted;
48
import org.openconcerto.erp.modules.ComponentsContext;
49
import org.openconcerto.erp.modules.DBContext;
50
import org.openconcerto.erp.modules.MenuContext;
51
import org.openconcerto.erp.modules.ModuleFactory;
52
import org.openconcerto.modules.project.element.ProjectSQLElement;
53
import org.openconcerto.modules.project.element.ProjectStateSQLElement;
54
import org.openconcerto.modules.project.element.ProjectTypeSQLElement;
55
import org.openconcerto.sql.Configuration;
56
import org.openconcerto.sql.element.SQLComponent;
57
import org.openconcerto.sql.element.SQLElement;
58
import org.openconcerto.sql.element.SQLElementDirectory;
59
import org.openconcerto.sql.model.DBRoot;
60
import org.openconcerto.sql.model.FieldPath;
61
import org.openconcerto.sql.model.SQLRow;
62
import org.openconcerto.sql.model.SQLRowAccessor;
63
import org.openconcerto.sql.model.SQLRowValues;
152 ilm 64
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
75 ilm 65
import org.openconcerto.sql.model.SQLSelect;
152 ilm 66
import org.openconcerto.sql.model.SQLSelectJoin;
75 ilm 67
import org.openconcerto.sql.model.SQLTable;
97 ilm 68
import org.openconcerto.sql.model.SQLTableEvent;
69
import org.openconcerto.sql.model.SQLTableEvent.Mode;
70
import org.openconcerto.sql.model.SQLTableModifiedListener;
75 ilm 71
import org.openconcerto.sql.model.Where;
128 ilm 72
import org.openconcerto.sql.model.graph.Link.Direction;
75 ilm 73
import org.openconcerto.sql.model.graph.Path;
152 ilm 74
import org.openconcerto.sql.request.ComboSQLRequest;
75
import org.openconcerto.sql.sqlobject.SQLRequestComboBox;
146 ilm 76
import org.openconcerto.sql.utils.AlterTable;
75 ilm 77
import org.openconcerto.sql.utils.SQLCreateTable;
78
import org.openconcerto.sql.view.EditFrame;
152 ilm 79
import org.openconcerto.sql.view.EditPanel.EditMode;
75 ilm 80
import org.openconcerto.sql.view.IListFrame;
81
import org.openconcerto.sql.view.ListeAddPanel;
82
import org.openconcerto.sql.view.column.ColumnFooterRenderer;
83
import org.openconcerto.sql.view.column.ColumnPanel;
84
import org.openconcerto.sql.view.column.ColumnPanelFetcher;
85
import org.openconcerto.sql.view.column.ColumnRowRenderer;
86
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn;
87
import org.openconcerto.sql.view.list.IListe;
88
import org.openconcerto.sql.view.list.RowAction;
183 ilm 89
import org.openconcerto.sql.view.list.action.ListEvent;
152 ilm 90
import org.openconcerto.ui.DefaultGridBagConstraints;
91
import org.openconcerto.ui.FrameUtil;
92
import org.openconcerto.ui.PanelFrame;
75 ilm 93
import org.openconcerto.utils.CollectionUtils;
97 ilm 94
import org.openconcerto.utils.ExceptionHandler;
75 ilm 95
import org.openconcerto.utils.Tuple2;
152 ilm 96
import org.openconcerto.utils.cc.IExnClosure;
75 ilm 97
import org.openconcerto.utils.cc.ITransformer;
98
 
99
public final class Module extends AbstractModule {
100
 
101
    public static final String PROJECT_TABLENAME = "AFFAIRE";
152 ilm 102
    private List<String> listTableAffaire = Arrays.asList("DEMANDE_PRIX", "BON_RECEPTION", "DEMANDE_ACHAT_ELEMENT", "SAISIE_VENTE_FACTURE", "AVOIR_CLIENT", "BON_DE_LIVRAISON", "COMMANDE_CLIENT",
103
            "DEVIS", "COMMANDE", "SAISIE_ACHAT", "AVOIR_FOURNISSEUR");
75 ilm 104
 
105
    public Module(ModuleFactory f) throws IOException {
106
        super(f);
107
 
108
    }
109
 
110
    @Override
152 ilm 111
    protected void install(DBContext ctxt) throws SQLException, IOException {
75 ilm 112
        super.install(ctxt);
113
 
114
        if (ctxt.getLastInstalledVersion() == null) {
115
 
116
            if (ctxt.getRoot().getTable(PROJECT_TABLENAME) == null) {
117
                final SQLCreateTable createTableEtatAff = ctxt.getCreateTable("ETAT_AFFAIRE");
118
                createTableEtatAff.addVarCharColumn("NOM", 128);
119
 
120
                final SQLCreateTable createTableType = ctxt.getCreateTable("TYPE_AFFAIRE");
121
                createTableType.addVarCharColumn("NOM", 256);
122
 
123
                // AFFAIRE
124
                final SQLCreateTable createTable = ctxt.getCreateTable(PROJECT_TABLENAME);
125
                createTable.addVarCharColumn("NUMERO", 256);
126
                createTable.addVarCharColumn("NOM", 1024);
127
                createTable.addVarCharColumn("INFOS", 1024);
128
                createTable.addForeignColumn("ID_CLIENT", ctxt.getRoot().getTable("CLIENT"));
129
                createTable.addForeignColumn("ID_DEVIS", ctxt.getRoot().getTable("DEVIS"));
130
                createTable.addColumn("DATE", "date");
131
                createTable.addForeignColumn("ID_COMMERCIAL", ctxt.getRoot().getTable("COMMERCIAL"));
132
                createTable.addForeignColumn("ID_ETAT_AFFAIRE", createTableEtatAff);
133
                createTable.addForeignColumn("ID_TYPE_AFFAIRE", createTableType);
134
 
135
                for (String table : this.listTableAffaire) {
136
                    SQLTable tableDevis = ctxt.getRoot().getTable(table);
137
                    if (!tableDevis.getFieldsName().contains("ID_AFFAIRE")) {
138
                        AlterTableRestricted alter = ctxt.getAlterTable(table);
139
                        alter.addForeignColumn("ID_AFFAIRE", createTable);
140
                    }
141
                }
152 ilm 142
 
143
                ctxt.manipulateData(new IExnClosure<DBRoot, SQLException>() {
144
 
75 ilm 145
                    @Override
152 ilm 146
                    public void executeChecked(DBRoot input) throws SQLException {
75 ilm 147
                        // Undefined Affaire
148
                        SQLTable tableAff = input.getTable(PROJECT_TABLENAME);
149
                        SQLRowValues rowVals = new SQLRowValues(tableAff);
152 ilm 150
                        rowVals.insert();
75 ilm 151
 
152
                        // Etat Affaire
153
                        SQLTable tableTypeAffaire = input.getTable("TYPE_AFFAIRE");
154
                        rowVals = new SQLRowValues(tableTypeAffaire);
152 ilm 155
                        rowVals.put("NOM", "Indéfini");
156
                        rowVals.insert();
75 ilm 157
 
158
                        // Etat Affaire
159
                        SQLTable tableEtatAffaire = input.getTable("ETAT_AFFAIRE");
160
                        rowVals = new SQLRowValues(tableEtatAffaire);
152 ilm 161
                        rowVals.put("NOM", "Indéfini");
162
                        rowVals.insert();
75 ilm 163
 
152 ilm 164
                        rowVals.clear();
165
                        rowVals.put("NOM", "A traiter");
166
                        rowVals.insert();
75 ilm 167
 
152 ilm 168
                        rowVals.clear();
169
                        rowVals.put("NOM", "En cours");
170
                        rowVals.insert();
75 ilm 171
 
152 ilm 172
                        rowVals.clear();
173
                        rowVals.put("NOM", "Traitement terminé");
174
                        rowVals.insert();
75 ilm 175
 
152 ilm 176
                        rowVals.clear();
177
                        rowVals.put("NOM", "A facturer");
178
                        rowVals.insert();
75 ilm 179
 
152 ilm 180
                        rowVals.clear();
181
                        rowVals.put("NOM", "Dossier clos");
182
                        rowVals.insert();
75 ilm 183
                    }
184
                });
152 ilm 185
 
75 ilm 186
            }
187
        }
188
 
189
    }
190
 
191
    @Override
192
    protected void setupElements(final SQLElementDirectory dir) {
193
        super.setupElements(dir);
194
        dir.addSQLElement(ProjectSQLElement.class);
195
        dir.addSQLElement(ProjectStateSQLElement.class);
196
        dir.addSQLElement(ProjectTypeSQLElement.class);
197
 
198
        final SQLElement element = dir.getElement("DEVIS");
199
        DevisSQLElement eltDevis = dir.getElement(DevisSQLElement.class);
200
        eltDevis.getRowActions().clear();
201
 
202
        eltDevis.addListColumn(new BaseSQLTableModelColumn("Temps Total", Double.class) {
203
 
204
            SQLTable tableDevisElt = Configuration.getInstance().getDirectory().getElement("DEVIS_ELEMENT").getTable();
205
 
206
            @Override
207
            protected Object show_(SQLRowAccessor r) {
208
 
209
                Collection<? extends SQLRowAccessor> rows = r.getReferentRows(tableDevisElt);
210
                double time = 0;
211
                for (SQLRowAccessor sqlRowAccessor : rows) {
212
                    time += OrderColumnRowRenderer.getHours(sqlRowAccessor);
213
                }
214
                return time;
215
            }
216
 
217
            @Override
218
            public Set<FieldPath> getPaths() {
219
                SQLTable table = Configuration.getInstance().getDirectory().getElement("DEVIS").getTable();
88 ilm 220
                Path p = new Path(table).add(tableDevisElt.getField("ID_DEVIS"));
75 ilm 221
 
88 ilm 222
                Path p2 = new Path(table).add(tableDevisElt.getField("ID_DEVIS")).addForeignField("ID_UNITE_VENTE");
75 ilm 223
                return CollectionUtils.createSet(new FieldPath(p, "QTE"), new FieldPath(p, "QTE_UNITAIRE"), new FieldPath(p2, "CODE"));
224
            }
225
        });
226
 
227
        // Transfert vers facture
228
        RowAction factureAction = eltDevis.getDevis2FactureAction();
229
        eltDevis.getRowActions().add(factureAction);
230
 
231
        // Transfert vers commande
232
        RowAction commandeAction = eltDevis.getDevis2CmdCliAction();
233
        eltDevis.getRowActions().add(commandeAction);
234
 
235
        // Marqué accepté
236
        RowAction accepteAction = getAcceptAction();
237
        eltDevis.getRowActions().add(accepteAction);
238
 
239
        // Marqué accepté
240
        RowAction refuseAction = eltDevis.getRefuseAction();
241
        eltDevis.getRowActions().add(refuseAction);
242
 
243
        // // Dupliquer
244
        RowAction cloneAction = eltDevis.getCloneAction();
245
        eltDevis.getRowActions().add(cloneAction);
246
 
183 ilm 247
        MouseSheetXmlListeListener mouseSheetXmlListeListener = new MouseSheetXmlListeListener(eltDevis, DevisXmlSheet.class);
75 ilm 248
        mouseSheetXmlListeListener.setGenerateHeader(true);
249
        mouseSheetXmlListeListener.setShowHeader(true);
250
        eltDevis.getRowActions().addAll(mouseSheetXmlListeListener.getRowActions());
251
 
252
        element.addComponentFactory(SQLElement.DEFAULT_COMP_ID, new ITransformer<Tuple2<SQLElement, String>, SQLComponent>() {
253
 
254
            @Override
255
            public SQLComponent transformChecked(Tuple2<SQLElement, String> input) {
256
                return new DevisSQLComponent(element) {
257
 
258
                    public int insert(SQLRow order) {
259
                        int id = super.insert(order);
260
                        checkAffaire(id);
261
                        return id;
262
                    }
263
 
264
                    public void update() {
265
                        super.update();
266
                        checkAffaire(getSelectedID());
267
                    }
268
 
269
                };
270
            }
271
        });
272
 
273
        final SQLElement elementCmd = dir.getElement("COMMANDE_CLIENT");
274
        elementCmd.addListColumn(new BaseSQLTableModelColumn("Temps Total", Double.class) {
275
 
276
            SQLTable tableCmdElt = dir.getElement("COMMANDE_CLIENT_ELEMENT").getTable();
277
 
278
            @Override
279
            protected Object show_(SQLRowAccessor r) {
280
 
281
                Collection<? extends SQLRowAccessor> rows = r.getReferentRows(tableCmdElt);
282
                double time = 0;
283
                for (SQLRowAccessor sqlRowAccessor : rows) {
284
                    time += OrderColumnRowRenderer.getHours(sqlRowAccessor);
285
                }
286
                return time;
287
            }
288
 
289
            @Override
290
            public Set<FieldPath> getPaths() {
291
                final SQLTable table = elementCmd.getTable();
88 ilm 292
                final Path p = new Path(table).add(tableCmdElt.getField("ID_COMMANDE_CLIENT"));
293
                final Path p2 = new Path(table).add(tableCmdElt.getField("ID_COMMANDE_CLIENT")).addForeignField("ID_UNITE_VENTE");
75 ilm 294
                return CollectionUtils.createSet(new FieldPath(p, "QTE"), new FieldPath(p, "QTE_UNITAIRE"), new FieldPath(p2, "CODE"));
295
            }
296
        });
297
 
298
        NumerotationAutoSQLElement.addClass(ProjectSQLElement.class, PROJECT_TABLENAME);
299
 
128 ilm 300
        for (String tableName : this.listTableAffaire) {
301
            if (!tableName.equalsIgnoreCase("DEVIS")) {
302
                final SQLElement elt = dir.getElement(tableName);
146 ilm 303
                if (elt == null) {
304
                    JOptionPane.showMessageDialog(null, "Table " + tableName + " manquante");
305
                    continue;
306
                }
128 ilm 307
                RowAction action = new RowAction(new AbstractAction("Historique affaire") {
308
                    @Override
309
                    public void actionPerformed(ActionEvent e) {
310
                        ProjectHistory histo = new ProjectHistory();
311
                        histo.getHistoriquePanel().selectIDinJList(IListe.get(e).getSelectedRow().getForeignID("ID_AFFAIRE"));
312
                        histo.getFrame().setVisible(true);
313
                    }
314
                }, false) {
152 ilm 315
 
128 ilm 316
                    @Override
183 ilm 317
                    public boolean enabledFor(List<SQLRowValues> evt) {
318
                        if (evt.size() == 1) {
319
                            SQLRowAccessor r = evt.get(0);
128 ilm 320
                            return !r.isForeignEmpty("ID_AFFAIRE");
321
                        }
322
                        return false;
323
                    }
324
                };
325
 
326
                elt.getRowActions().add(action);
327
                elt.addListColumn(new BaseSQLTableModelColumn("Affaire", String.class) {
328
 
329
                    @Override
330
                    protected Object show_(SQLRowAccessor r) {
331
                        if (!r.isForeignEmpty("ID_AFFAIRE") && r.getForeign("ID_AFFAIRE") != null) {
332
                            return r.getForeign("ID_AFFAIRE").getString("NUMERO");
333
                        } else {
334
                            return "";
335
                        }
336
                    }
337
 
338
                    @Override
339
                    public Set<FieldPath> getPaths() {
340
                        SQLTable table = elt.getTable();
341
                        Path p = new Path(table).add(table.getField("ID_AFFAIRE"));
342
                        return CollectionUtils.createSet(new FieldPath(p, "NUMERO"));
343
                    }
344
                });
345
            }
346
        }
347
 
348
        final SQLElement elt = dir.getElement("DEVIS");
349
        RowAction action = new RowAction(new AbstractAction("Historique affaire") {
350
            @Override
351
            public void actionPerformed(ActionEvent e) {
352
                ProjectHistory histo = new ProjectHistory();
353
                SQLRowAccessor selectedRow = IListe.get(e).getSelectedRow();
354
                Collection<? extends SQLRowAccessor> l = selectedRow.getReferentRows(selectedRow.getTable().getTable("AFFAIRE"));
355
                histo.getHistoriquePanel().selectIDinJList(l.iterator().next().getID());
356
                histo.getFrame().setVisible(true);
357
            }
358
        }, false) {
152 ilm 359
 
128 ilm 360
            @Override
183 ilm 361
            public boolean enabledFor(List<SQLRowValues> evt) {
362
                if (evt.size() == 1) {
363
                    SQLRowAccessor r = evt.get(0);
128 ilm 364
                    Collection<? extends SQLRowAccessor> l = r.getReferentRows(r.getTable().getTable("AFFAIRE"));
365
                    return l.size() > 0;
366
                }
367
                return false;
368
            }
369
        };
370
 
371
        elt.getRowActions().add(action);
372
 
373
        elt.addListColumn(new BaseSQLTableModelColumn("Affaire", String.class) {
374
 
375
            @Override
376
            protected Object show_(SQLRowAccessor r) {
170 ilm 377
                final SQLRowAccessor foreignAff = r.getForeign("ID_AFFAIRE");
378
                if (foreignAff != null && !foreignAff.isUndefined()) {
379
                    return foreignAff.getString("NUMERO");
128 ilm 380
                } else {
170 ilm 381
                    Collection<? extends SQLRowAccessor> rows = r.getReferentRows(elt.getTable().getTable("AFFAIRE"));
382
                    if (rows.size() == 1) {
383
                        return rows.iterator().next().getString("NUMERO");
384
                    } else {
385
                        return "";
386
                    }
128 ilm 387
                }
388
            }
389
 
390
            @Override
391
            public Set<FieldPath> getPaths() {
392
                SQLTable table = elt.getTable();
170 ilm 393
                Path pDev = new Path(table).add(table.getField("ID_AFFAIRE"));
394
                Path pAff = new Path(table).add(table.getTable("AFFAIRE"), Direction.REFERENT);
395
                return CollectionUtils.createSet(new FieldPath(pDev, "NUMERO"), new FieldPath(pAff, "NUMERO"));
128 ilm 396
            }
397
        });
152 ilm 398
        new CmdToBrSQLInjector();
75 ilm 399
        new QuoteToOrderSQLInjector();
400
        new QuoteToInvoiceSQLInjector();
401
        new OrderToInvoiceSQLInjector();
402
    }
403
 
152 ilm 404
    public static JFrame checkAffaire(int id) {
405
        return checkAffaire(id, true);
406
    }
407
 
408
    public static JFrame checkAffaire(int id, final boolean createCommandeClient) {
75 ilm 409
        final SQLTable tableDevis = Configuration.getInstance().getRoot().findTable("DEVIS");
410
        final SQLTable tableNum = Configuration.getInstance().getRoot().findTable("NUMEROTATION_AUTO");
411
        final SQLRow row = tableDevis.getRow(id);
412
        final SQLRow rowAffaire = row.getForeign("ID_AFFAIRE");
413
        if (rowAffaire == null || rowAffaire.isUndefined()) {
414
            if (row.getInt("ID_ETAT_DEVIS") == EtatDevisSQLElement.ACCEPTE) {
415
                // FIXME Vérifier si le devis n'est pas déjà rattaché à une affaire
416
 
152 ilm 417
                JPanel p = new JPanel(new GridBagLayout());
418
                GridBagConstraints c = new DefaultGridBagConstraints();
419
                c.gridwidth = GridBagConstraints.REMAINDER;
420
                p.add(new JLabel("Voulez vous intégrer ce devis sur une affaire existante?"), c);
421
                c.gridy++;
422
                c.gridwidth = 1;
423
                p.add(new JLabel("Rattacher à l'affaire : "), c);
424
                c.gridx++;
425
                final SQLRequestComboBox box = new SQLRequestComboBox();
426
                final ComboSQLRequest comboRequest = Configuration.getInstance().getDirectory().getElement("AFFAIRE").getComboRequest(true);
427
                Where w = new Where(comboRequest.getPrimaryTable().getField("ID_CLIENT"), "=", row.getForeignID("ID_CLIENT"));
428
                comboRequest.setWhere(w);
429
                box.uiInit(comboRequest);
430
                p.add(box, c);
431
                c.gridy++;
432
                c.gridx = 0;
433
                final JButton buttonApply = new JButton("Appliquer");
434
                JButton buttonAnnuler = new JButton("Nouvelle affaire");
435
                p.add(buttonApply, c);
436
                buttonApply.setEnabled(false);
437
                box.addValueListener(new PropertyChangeListener() {
75 ilm 438
 
152 ilm 439
                    @Override
440
                    public void propertyChange(PropertyChangeEvent evt) {
441
                        buttonApply.setEnabled(box.getSelectedRow() != null);
75 ilm 442
 
152 ilm 443
                    }
444
                });
445
                c.gridx++;
446
                p.add(buttonAnnuler, c);
447
                final PanelFrame f = new PanelFrame(p, "Affection d'un devis à une affaire");
75 ilm 448
 
152 ilm 449
                buttonAnnuler.addActionListener(new ActionListener() {
75 ilm 450
 
152 ilm 451
                    @Override
452
                    public void actionPerformed(ActionEvent ae) {
453
                        f.dispose();
454
                        final SQLTable table = tableDevis.getTable(PROJECT_TABLENAME);
455
                        final SQLRowValues rowVals = new SQLRowValues(table);
456
 
457
                        final String nextNumero = NumerotationAutoSQLElement.getNextNumero(ProjectSQLElement.class);
458
                        rowVals.put("NUMERO", nextNumero);
459
 
460
                        // incrémentation du numéro auto
461
                        final SQLRowValues rowValsNum = new SQLRowValues(tableNum);
462
                        int val = tableNum.getRow(2).getInt(NumerotationAutoSQLElement.getLabelNumberFor(ProjectSQLElement.class));
463
                        val++;
464
                        rowValsNum.put(NumerotationAutoSQLElement.getLabelNumberFor(ProjectSQLElement.class), new Integer(val));
465
                        try {
466
                            rowValsNum.update(2);
467
                        } catch (final SQLException e) {
468
                            e.printStackTrace();
469
                        }
470
 
471
                        rowVals.put("ID_DEVIS", row.getID());
472
                        rowVals.put("ID_CLIENT", row.getObject("ID_CLIENT"));
473
                        rowVals.put("ID_COMMERCIAL", row.getObject("ID_COMMERCIAL"));
474
                        rowVals.put("DATE", new Date());
475
                        rowVals.put("ID_ETAT_AFFAIRE", ProjectStateSQLElement.EN_COURS);
476
 
477
                        SQLRowValues rowValsDevis = row.asRowValues();
478
                        rowValsDevis.put("ID_AFFAIRE", rowVals);
479
 
480
                        try {
481
                            int id = rowVals.commit().getID();
482
                            row.fetchValues();
483
                            if (createCommandeClient) {
484
                                Configuration.getInstance().getDirectory().getElement(DevisSQLElement.class).transfertCommandeClient(Arrays.asList(row.asRowValues()));
485
                                EditFrame frame = new EditFrame(Configuration.getInstance().getDirectory().getElement("AFFAIRE"), EditMode.MODIFICATION);
486
                                frame.selectionId(id);
487
                                FrameUtil.showPacked(frame);
488
                            }
489
                        } catch (SQLException exn) {
490
                            // TODO Bloc catch auto-généré
491
                            exn.printStackTrace();
492
                        }
493
                    }
494
                });
495
 
496
                buttonApply.addActionListener(new ActionListener() {
497
 
498
                    @Override
499
                    public void actionPerformed(ActionEvent e) {
500
                        f.dispose();
501
 
502
                        SQLRowValues rowValsDevis = row.asRowValues();
503
                        rowValsDevis.put("ID_AFFAIRE", box.getSelectedId());
504
 
505
                        try {
506
                            rowValsDevis.commit();
170 ilm 507
                            row.fetchValues();
508
                            if (createCommandeClient) {
509
                                Configuration.getInstance().getDirectory().getElement(DevisSQLElement.class).transfertCommandeClient(Arrays.asList(row.asRowValues()));
510
                            }
152 ilm 511
                        } catch (SQLException exn) {
170 ilm 512
                            ExceptionHandler.handle("Erreur lors de la création de la commande client!", exn);
152 ilm 513
                        }
514
                    }
515
                });
516
                FrameUtil.show(f);
517
                return f;
75 ilm 518
            }
146 ilm 519
 
520
        } else if (row.getInt("ID_ETAT_DEVIS") != EtatDevisSQLElement.ACCEPTE) {
75 ilm 521
            SQLRowValues rowVals = rowAffaire.asRowValues();
522
            rowVals.putEmptyLink("ID_DEVIS");
523
            try {
524
                rowVals.update();
525
            } catch (SQLException exn) {
526
                exn.printStackTrace();
527
            }
528
        }
152 ilm 529
        return null;
75 ilm 530
    }
531
 
97 ilm 532
    List<Integer> idsAsked = new ArrayList<Integer>();
533
 
534
    public void checkProjectState(final SQLRowAccessor rowFact) {
535
        if (!rowFact.isForeignEmpty("ID_AFFAIRE")) {
536
            final SQLRowAccessor rowAff = rowFact.getForeign("ID_AFFAIRE");
537
 
538
            if (rowAff.getInt("ID_ETAT_AFFAIRE") < ProjectStateSQLElement.DOSSIER_CLOS) {
539
 
540
                SQLSelect sel = new SQLSelect();
541
                final SQLTable tableVF = rowFact.getTable();
542
                sel.addSelect(tableVF.getField("T_TTC"), "SUM");
543
                Where w = new Where(tableVF.getField("ID_AFFAIRE"), "=", rowAff.getID());
544
                sel.setWhere(w);
545
 
546
                Number total = (Number) tableVF.getDBSystemRoot().getDataSource().executeScalar(sel.asString());
547
 
548
                long devis = rowAff.getForeign("ID_DEVIS").getLong("T_TTC");
549
                if (devis == total.longValue()) {
550
                    if (!idsAsked.contains(rowFact.getID())) {
551
                        idsAsked.add(rowFact.getID());
552
                        SwingUtilities.invokeLater(new Runnable() {
553
 
554
                            @Override
555
                            public void run() {
556
                                int a = JOptionPane.showConfirmDialog(null, "Voulez vous passer l'affaire " + rowAff.getString("NUMERO") + " dans l'état \"Dossier Clos\"?", "Affaire 100% facturée",
557
                                        JOptionPane.YES_NO_OPTION);
558
                                if (a == JOptionPane.YES_OPTION) {
559
                                    SQLRowValues rowVals = rowAff.createEmptyUpdateRow();
560
                                    rowVals.put("ID_ETAT_AFFAIRE", ProjectStateSQLElement.DOSSIER_CLOS);
561
                                    try {
562
                                        rowVals.commit();
563
                                    } catch (SQLException e) {
564
                                        ExceptionHandler.handle("Erreur lors de la mise à jour de l'état de l'affaire", e);
565
                                    }
566
                                }
567
                                idsAsked.remove(Integer.valueOf(rowFact.getID()));
568
                            }
569
                        });
570
                    }
571
                }
572
 
573
            }
574
        }
575
    }
576
 
75 ilm 577
    public RowAction getAcceptAction() {
578
        return new RowAction(new AbstractAction() {
579
            public void actionPerformed(ActionEvent e) {
88 ilm 580
                SQLRow selectedRow = IListe.get(e).getSelectedRow().asRow();
75 ilm 581
                SQLRowValues rowVals = selectedRow.createEmptyUpdateRow();
582
                rowVals.put("ID_ETAT_DEVIS", EtatDevisSQLElement.ACCEPTE);
583
                try {
584
                    rowVals.update();
585
                } catch (SQLException e1) {
586
                    e1.printStackTrace();
587
                }
588
                selectedRow.getTable().fireTableModified(selectedRow.getID());
589
                checkAffaire(selectedRow.getID());
590
            }
591
        }, false, "project.accept") {
152 ilm 592
 
97 ilm 593
            public boolean enabledFor(List<SQLRowValues> selection) {
75 ilm 594
                if (selection != null && selection.size() == 1) {
595
                    if (selection.get(0).getInt("ID_ETAT_DEVIS") == EtatDevisSQLElement.EN_ATTENTE) {
596
                        return true;
597
                    }
598
                }
599
                return false;
600
            };
152 ilm 601
 
75 ilm 602
        };
603
    }
604
 
605
    @Override
606
    protected void setupComponents(final ComponentsContext ctxt) {
152 ilm 607
 
146 ilm 608
        DBRoot root = ComptaPropsConfiguration.getInstanceCompta().getRootSociete();
181 ilm 609
        List<String> table2check = Arrays.asList("BON_RECEPTION", "DEMANDE_PRIX", "DEMANDE_ACHAT_ELEMENT", "FACTURE_FOURNISSEUR");
146 ilm 610
        for (String table : table2check) {
611
            if (root.contains(table)) {
612
                SQLTable tableCR = root.getTable(table);
613
                if (!tableCR.contains("ID_AFFAIRE")) {
614
                    try {
615
                        AlterTable alt = new AlterTable(tableCR);
616
                        alt.addForeignColumn("ID_AFFAIRE", root.getTable("AFFAIRE"));
617
                        root.getDBSystemRoot().getDataSource().execute(alt.asString());
618
                        String s = "INSERT INTO " + root.getTable("FWK_MODULE_METADATA").getSQLName().quote()
619
                                + "(\"MODULE_NAME\",\"TABLE\",\"FIELD\",\"KEY\",\"MODULE_VERSION\") VALUES('org.openconcerto.modules.project','" + table + "','ID_AFFAIRE',true,10000)";
620
                        root.getDBSystemRoot().getDataSource().execute(s);
621
                        root.getSchema().updateVersion();
622
                        root.refetchTable(tableCR.getName());
623
                    } catch (SQLException e) {
624
                        e.printStackTrace();
625
                    }
626
                }
627
            }
628
        }
152 ilm 629
 
75 ilm 630
        for (String table : this.listTableAffaire) {
631
            if (!table.equalsIgnoreCase("DEVIS"))
632
                ctxt.putAdditionalField(table, "ID_AFFAIRE");
633
        }
146 ilm 634
 
75 ilm 635
    }
636
 
637
    @Override
638
    protected void setupMenu(final MenuContext ctxt) {
639
        ctxt.addMenuItem(new CreateFrameAbstractAction("Liste des affaires") {
640
            @Override
641
            public JFrame createFrame() {
642
                IListFrame frame = new IListFrame(new ListeAddPanel(ctxt.getElement(PROJECT_TABLENAME)));
643
                return frame;
644
            }
645
        }, MainFrame.LIST_MENU);
646
        ctxt.addMenuItem(new CreateFrameAbstractAction("Historique des affaires") {
647
            @Override
648
            public JFrame createFrame() {
649
                ProjectHistory histo = new ProjectHistory();
650
 
651
                return histo.getFrame();
652
            }
653
        }, MainFrame.LIST_MENU);
654
 
655
        ctxt.addMenuItem(new CreateFrameAbstractAction("Saisie affaire") {
656
            @Override
657
            public JFrame createFrame() {
658
                return new EditFrame(ctxt.getElement(PROJECT_TABLENAME));
659
            }
660
        }, MainFrame.CREATE_MENU);
661
 
152 ilm 662
        addMenuImportExport(ctxt);
146 ilm 663
 
75 ilm 664
    }
665
 
152 ilm 666
    private void addMenuImportExport(final MenuContext ctxt) {
667
        ////
668
 
669
        ctxt.addMenuItem(new AbstractAction("Export Affaire") {
670
            @Override
671
            public void actionPerformed(ActionEvent e) {
672
                ProjectImportExport importExport = new ProjectImportExport(ctxt.getElement("AFFAIRE").getTable().getDBRoot());
673
                importExport.export();
674
            }
675
        }, MainFrame.HELP_MENU);
676
 
677
        ctxt.addMenuItem(new AbstractAction("Import Affaire") {
678
            @Override
679
            public void actionPerformed(ActionEvent e) {
680
                ProjectImportExport importExport = new ProjectImportExport(ctxt.getElement("AFFAIRE").getTable().getDBRoot());
681
                importExport.importProjects();
682
            }
683
        }, MainFrame.HELP_MENU);
170 ilm 684
        if (false) {
685
            ctxt.addMenuItem(new AbstractAction("Fix ID_AFFAIRE") {
686
                @Override
687
                public void actionPerformed(ActionEvent e) {
688
                    {
689
                        SQLTable tableCmd = ctxt.getElement("COMMANDE_CLIENT").getTable();
690
                        SQLSelect selBadCmd = new SQLSelect();
691
                        selBadCmd.addSelect(tableCmd.getKey());
692
                        selBadCmd.addSelect(tableCmd.getField("ID_AFFAIRE"));
693
                        SQLSelectJoin joinTR = selBadCmd.addBackwardJoin("RIGHT", "tr", tableCmd.getTable().getTable("TR_DEVIS").getField("ID_COMMANDE_CLIENT"), null);
694
                        SQLSelectJoin joinDevis = selBadCmd.addJoin("LEFT", joinTR.getJoinedTable().getField("ID_DEVIS"));
695
                        SQLSelectJoin joinAff = selBadCmd.addBackwardJoin("LEFT", "aff", tableCmd.getTable().getTable("AFFAIRE").getField("ID_DEVIS"), null);
696
                        selBadCmd.addSelect(joinAff.getJoinedTable().getKey());
152 ilm 697
 
170 ilm 698
                        selBadCmd.setWhere(Where.isNull(tableCmd.getField("ID_AFFAIRE")));
699
                        System.err.println(selBadCmd.asString());
152 ilm 700
 
170 ilm 701
                        List<Object[]> result = (List<Object[]>) tableCmd.getDBSystemRoot().getDataSource().executeA(selBadCmd.asString());
702
                        try {
703
                            for (Object[] objects : result) {
704
                                if (objects[2] != null && objects[2].toString().trim().length() > 0)
705
                                    tableCmd.getRow(((Number) objects[0]).intValue()).createEmptyUpdateRow().put("ID_AFFAIRE", ((Number) objects[2]).intValue()).commit();
706
                            }
707
                        } catch (SQLException e1) {
708
                            // TODO Auto-generated catch block
709
                            e1.printStackTrace();
710
                        }
152 ilm 711
 
170 ilm 712
                        // List<SQLRow> list = SQLRowListRSH.execute(selBadVF);
152 ilm 713
                    }
170 ilm 714
                    {
715
                        SQLTable tableVF = ctxt.getElement("SAISIE_VENTE_FACTURE").getTable();
716
                        SQLSelect selBadVF = new SQLSelect();
717
                        selBadVF.addSelect(tableVF.getKey());
718
                        selBadVF.addSelect(tableVF.getField("ID_AFFAIRE"));
719
                        SQLSelectJoin joinTR = selBadVF.addBackwardJoin("RIGHT", "tr", tableVF.getTable().getTable("TR_COMMANDE_CLIENT").getField("ID_SAISIE_VENTE_FACTURE"), null);
720
                        SQLSelectJoin joinCmd = selBadVF.addJoin("LEFT", joinTR.getJoinedTable().getField("ID_COMMANDE_CLIENT"));
721
                        selBadVF.addSelect(joinCmd.getJoinedTable().getField("ID_AFFAIRE"));
152 ilm 722
 
170 ilm 723
                        selBadVF.setWhere(Where.isNull(tableVF.getField("ID_AFFAIRE")));
724
                        System.err.println(selBadVF.asString());
725
                        List<Object[]> result = (List<Object[]>) tableVF.getDBSystemRoot().getDataSource().executeA(selBadVF.asString());
726
                        try {
727
                            for (Object[] objects : result) {
728
                                if (objects[2] != null && objects[2].toString().trim().length() > 0)
729
                                    tableVF.getRow(((Number) objects[0]).intValue()).createEmptyUpdateRow().put("ID_AFFAIRE", ((Number) objects[2]).intValue()).commit();
730
                            }
731
                        } catch (SQLException e1) {
732
                            // TODO Auto-generated catch block
733
                            e1.printStackTrace();
152 ilm 734
                        }
735
                    }
736
                }
170 ilm 737
            }, MainFrame.CREATE_MENU);
738
        }
152 ilm 739
        ctxt.addMenuItem(new AbstractAction("Recalcul Total achat facture prorata") {
740
            @Override
741
            public void actionPerformed(ActionEvent e) {
742
 
743
                {
744
                    final SQLTable table = ctxt.getElement("SAISIE_VENTE_FACTURE").getTable();
745
                    SQLRowValues rowValsFact = new SQLRowValues(table);
746
                    rowValsFact.putNulls("SOLDE", "PARTIAL", "T_HA", "T_HT");
747
 
748
                    final SQLTable tableCmd = ctxt.getElement("COMMANDE_CLIENT").getTable();
749
                    SQLRowValues rowValsCmd = new SQLRowValues(tableCmd);
750
                    rowValsCmd.putNulls("T_HT");
751
 
752
                    final SQLTable tableCmdElt = ctxt.getElement("COMMANDE_CLIENT_ELEMENT").getTable();
753
                    SQLRowValues rowValsCmdElt = new SQLRowValues(tableCmdElt);
754
                    rowValsCmdElt.put("ID_COMMANDE_CLIENT", rowValsCmd);
755
                    rowValsCmdElt.putNulls("T_PA_HT", "NIVEAU");
756
 
757
                    final SQLTable tableTR = table.getTable("TR_COMMANDE_CLIENT");
758
                    SQLRowValues rowValsTR = new SQLRowValues(tableTR);
759
                    rowValsTR.put("ID_SAISIE_VENTE_FACTURE", rowValsFact);
760
                    rowValsTR.put("ID_COMMANDE_CLIENT", rowValsCmd);
761
 
762
                    SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(rowValsFact);
763
                    fetcher.appendSelTransf(new ITransformer<SQLSelect, SQLSelect>() {
764
                        @Override
765
                        public SQLSelect transformChecked(SQLSelect input) {
766
                            Where w = new Where(table.getField("SOLDE"), "=", Boolean.TRUE);
767
                            w = w.or(new Where(table.getField("PARTIAL"), "=", Boolean.TRUE));
768
                            input.setWhere(w);
769
                            return input;
770
                        }
771
                    });
772
 
773
                    List<SQLRowValues> rowVals = fetcher.fetch();
774
 
775
                    for (SQLRowValues sqlRowValues : rowVals) {
776
                        // Recuperation de la commande
777
                        final Collection<SQLRowValues> referentRows = sqlRowValues.getReferentRows(tableTR);
778
                        if (!referentRows.isEmpty()) {
779
                            SQLRowAccessor rowTR = referentRows.iterator().next();
780
                            SQLRowAccessor rowCmd = rowTR.getForeign("ID_COMMANDE_CLIENT");
781
                            final long htCmd = rowCmd.getLong("T_HT");
782
                            if (htCmd != 0) {
783
 
784
                                BigDecimal totalHA = BigDecimal.ZERO;
785
                                Collection<? extends SQLRowAccessor> elt = rowCmd.getReferentRows(tableCmdElt);
786
                                for (SQLRowAccessor sqlRowAccessor : elt) {
787
                                    if (sqlRowAccessor.getInt("NIVEAU") == 1) {
788
                                        totalHA = totalHA.add(sqlRowAccessor.getBigDecimal("T_PA_HT"));
789
                                    }
790
                                }
791
                                BigDecimal prorata = new BigDecimal((double) sqlRowValues.getLong("T_HT") / (double) htCmd);
792
                                try {
793
                                    sqlRowValues.createEmptyUpdateRow().put("T_HA", totalHA.multiply(prorata).movePointRight(2).setScale(0, RoundingMode.HALF_UP).longValue()).update();
794
                                } catch (SQLException e1) {
795
                                    e1.printStackTrace();
796
                                }
797
                            }
798
                        }
799
                    }
800
                }
801
            }
802
        }, MainFrame.CREATE_MENU);
803
    }
804
 
75 ilm 805
    @Override
806
    protected void start() {
146 ilm 807
 
75 ilm 808
        final JComponent quoteComponent = createQuotePanel();
809
        final JComponent orderComponent = createOrderPanel();
810
        MainFrame.getInstance().getTabbedPane().addTab("Commandes en cours", orderComponent);
811
        MainFrame.getInstance().getTabbedPane().addTab("Devis en attente", quoteComponent);
812
        MainFrame.getInstance().getTabbedPane().addTab("Affaires", new ListeAddPanel(Configuration.getInstance().getDirectory().getElement(PROJECT_TABLENAME)));
813
        // Fix for classic XP Theme
814
        quoteComponent.setOpaque(true);
815
        quoteComponent.setBackground(Color.WHITE);
816
        orderComponent.setOpaque(true);
817
        orderComponent.setBackground(Color.WHITE);
818
        // Select first tab
819
        MainFrame.getInstance().getTabbedPane().setSelectedIndex(1);
820
 
821
        CommandeClientItemTable.getVisibilityMap().put("POURCENT_ACOMPTE", Boolean.TRUE);
822
        SaisieVenteFactureItemTable.getVisibilityMap().put("POURCENT_ACOMPTE", Boolean.TRUE);
823
        AccountingRecordsProvider p = new AccountingRecordsProvider() {
824
 
825
            @Override
826
            public void putLabel(SQLRowAccessor rowSource, Map<String, Object> values) {
827
                values.put("NOM", "Fact. vente " + rowSource.getString("NUMERO"));
828
            }
829
 
830
            @Override
831
            public void putPieceLabel(SQLRowAccessor rowSource, SQLRowValues rowValsPiece) {
832
                rowValsPiece.put("NOM", rowSource.getString("NUMERO"));
833
            }
834
        };
835
        AccountingRecordsProviderManager.put(GenerationMvtSaisieVenteFacture.ID, p);
97 ilm 836
 
837
        final SQLTable tableFact = ComptaPropsConfiguration.getInstanceCompta().getRootSociete().getTable("SAISIE_VENTE_FACTURE");
838
 
839
        tableFact.addTableModifiedListener(new SQLTableModifiedListener() {
840
 
841
            @Override
842
            public void tableModified(SQLTableEvent evt) {
843
                if (evt.getMode() == Mode.ROW_ADDED || evt.getMode() == Mode.ROW_UPDATED) {
844
                    checkProjectState(evt.getRow());
845
                }
846
            }
847
        });
75 ilm 848
    }
849
 
850
    private JComponent createQuotePanel() {
851
        ColumnRowRenderer cRenderer = new QuoteColumnRowRenderer();
852
        ColumnFooterRenderer fRenderer = new QuoteColumnFooterRenderer();
853
        final ColumnPanel columnPanel = new ColumnPanel(220, cRenderer, fRenderer);
854
        columnPanel.setOpaque(false);
855
        final SQLElement element = Configuration.getInstance().getDirectory().getElement("DEVIS_ELEMENT");
88 ilm 856
        Path p = Path.get(element.getTable()).addForeignField("ID_ARTICLE").addForeignField("ID_FAMILLE_ARTICLE");
75 ilm 857
 
858
        SQLRowValues values = new SQLRowValues(element.getTable());
859
        values.put("NOM", null);
860
        values.put("T_PV_HT", null);
861
        SQLRowValues rowValsClient = new SQLRowValues(element.getTable().getTable("CLIENT"));
862
        rowValsClient.put("NOM", null);
863
        final SQLTable tableDevis = element.getTable().getTable("DEVIS");
864
        SQLRowValues rowValsDevis = new SQLRowValues(tableDevis);
865
        rowValsDevis.put("NUMERO", null);
866
        rowValsDevis.put("DATE", null);
867
        rowValsDevis.put("T_HT", null);
868
 
869
        rowValsDevis.put("ID_CLIENT", rowValsClient);
870
        values.put("ID_DEVIS", rowValsDevis);
871
        SQLRowValues rowValsUnite = new SQLRowValues(element.getTable().getTable("UNITE_VENTE"));
872
        rowValsUnite.put("CODE", null);
873
        values.put("ID_UNITE_VENTE", rowValsUnite);
874
        values.put("QTE", null);
875
        values.put("QTE_UNITAIRE", null);
876
 
877
        ITransformer<SQLSelect, SQLSelect> t = new ITransformer<SQLSelect, SQLSelect>() {
878
            @Override
879
            public SQLSelect transformChecked(SQLSelect input) {
880
                input.andWhere(new Where(input.getAlias(tableDevis.getField("ID_ETAT_DEVIS")), "=", EtatDevisSQLElement.EN_ATTENTE));
881
                return input;
882
            }
883
        };
884
        final ColumnPanelFetcher projectFetcher = new ColumnPanelFetcher(values, new FieldPath(p, "NOM"), t);
885
        columnPanel.setHeaderRenderer(new TotalHeaderRenderer());
886
        columnPanel.setFetch(projectFetcher);
887
 
888
        final JScrollPane comp = new JScrollPane(columnPanel);
889
        comp.setBorder(null);
890
        comp.getViewport().setOpaque(false);
891
        return comp;
892
    }
893
 
894
    private JComponent createOrderPanel() {
895
        ColumnRowRenderer cRenderer = new OrderColumnRowRenderer();
896
        ColumnFooterRenderer fRenderer = new OrderColumnFooterRenderer();
897
        final ColumnPanel columnPanel = new ColumnPanel(220, cRenderer, fRenderer);
898
        columnPanel.setOpaque(false);
899
        final SQLElement element = Configuration.getInstance().getDirectory().getElement("COMMANDE_CLIENT_ELEMENT");
900
        final SQLTable tableOrder = element.getTable();
88 ilm 901
        Path p = Path.get(tableOrder).addForeignField("ID_ARTICLE").addForeignField("ID_FAMILLE_ARTICLE");
75 ilm 902
 
903
        SQLRowValues values = new SQLRowValues(tableOrder);
904
        values.put("NOM", null);
905
        values.put("T_PV_HT", null);
906
        SQLRowValues rowValsClient = new SQLRowValues(tableOrder.getTable("CLIENT"));
907
        rowValsClient.put("NOM", null);
908
        SQLRowValues rowValsCmd = new SQLRowValues(tableOrder.getTable("COMMANDE_CLIENT"));
909
        rowValsCmd.put("NUMERO", null);
910
        rowValsCmd.put("DATE", null);
911
        rowValsCmd.put("T_HT", null);
912
 
913
        rowValsCmd.put("ID_CLIENT", rowValsClient);
914
        values.put("ID_COMMANDE_CLIENT", rowValsCmd);
915
        SQLRowValues rowValsUnite = new SQLRowValues(tableOrder.getTable("UNITE_VENTE"));
916
        rowValsUnite.put("CODE", null);
917
        values.put("ID_UNITE_VENTE", rowValsUnite);
918
        values.put("QTE", null);
919
        values.put("QTE_UNITAIRE", null);
920
 
921
        final SQLTable tableAffaire = tableOrder.getTable(PROJECT_TABLENAME);
922
        SQLRowValues rowValsAffaire = new SQLRowValues(tableAffaire);
923
        rowValsAffaire.put("NUMERO", null);
924
        rowValsAffaire.put("DATE", null);
925
        rowValsCmd.put("ID_AFFAIRE", rowValsAffaire);
926
 
927
        if (tableOrder.getDBRoot().contains("AFFAIRE_TEMPS")) {
928
            final SQLTable tableAffaireTemps = tableOrder.getTable("AFFAIRE_TEMPS");
929
            SQLRowValues rowValsAffaireTemps = new SQLRowValues(tableAffaireTemps);
930
            rowValsAffaireTemps.put("TEMPS", null);
931
            rowValsAffaireTemps.put("ID_COMMANDE_CLIENT_ELEMENT", values);
932
        }
933
        ITransformer<SQLSelect, SQLSelect> t = new ITransformer<SQLSelect, SQLSelect>() {
934
            @Override
935
            public SQLSelect transformChecked(SQLSelect input) {
936
                input.andWhere(new Where(input.getAlias(tableAffaire.getField("ID_ETAT_AFFAIRE")), "=", ProjectStateSQLElement.EN_COURS));
937
                return input;
938
            }
939
        };
940
        final ColumnPanelFetcher projectFetcher = new ColumnPanelFetcher(values, new FieldPath(p, "NOM"), t);
941
        columnPanel.setHeaderRenderer(new TotalHeaderRenderer());
942
        columnPanel.setFetch(projectFetcher);
943
        final JScrollPane comp = new JScrollPane(columnPanel);
944
        comp.setBorder(null);
945
        comp.getViewport().setOpaque(false);
946
        return comp;
947
    }
948
 
949
    @Override
950
    protected void stop() {
951
    }
952
}