OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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