OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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