OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev Author Line No. Line
144 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
182 ilm 4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
144 ilm 5
 *
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
10
 *
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
13
 
14
 /*
15
 * Créé le 19 oct. 2011
16
 */
17
package org.openconcerto.erp.core.supplychain.order.element;
18
 
19
import org.openconcerto.erp.core.common.component.TransfertBaseSQLComponent;
20
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
21
import org.openconcerto.erp.core.common.element.NumerotationAutoSQLElement;
22
import org.openconcerto.erp.panel.PanelOOSQLComponent;
23
import org.openconcerto.sql.Configuration;
24
import org.openconcerto.sql.element.ElementSQLObject;
25
import org.openconcerto.sql.element.SQLElement;
182 ilm 26
import org.openconcerto.sql.model.SQLBackgroundTableCache;
144 ilm 27
import org.openconcerto.sql.model.SQLRow;
28
import org.openconcerto.sql.model.SQLRowAccessor;
29
import org.openconcerto.sql.model.SQLRowValues;
30
import org.openconcerto.sql.model.SQLTable;
31
import org.openconcerto.sql.sqlobject.ElementComboBox;
32
import org.openconcerto.sql.sqlobject.JUniqueTextField;
33
import org.openconcerto.sql.ui.RadioButtons;
182 ilm 34
import org.openconcerto.sql.users.UserManager;
144 ilm 35
import org.openconcerto.sql.view.EditFrame;
36
import org.openconcerto.sql.view.list.RowValuesTable;
37
import org.openconcerto.ui.DefaultGridBagConstraints;
38
import org.openconcerto.ui.FormLayouter;
39
import org.openconcerto.ui.JDate;
40
import org.openconcerto.ui.TitledSeparator;
41
import org.openconcerto.ui.VFlowLayout;
42
import org.openconcerto.ui.component.ITextArea;
43
import org.openconcerto.ui.component.InteractionMode;
44
import org.openconcerto.utils.ExceptionHandler;
45
 
46
import java.awt.GridBagConstraints;
47
import java.awt.GridBagLayout;
48
import java.sql.SQLException;
49
import java.util.List;
50
 
51
import javax.swing.BorderFactory;
52
import javax.swing.JLabel;
53
import javax.swing.JPanel;
54
import javax.swing.JScrollPane;
55
import javax.swing.JTextArea;
56
import javax.swing.SwingConstants;
57
import javax.swing.SwingUtilities;
58
 
59
public class DemandePrixSQLComponent extends TransfertBaseSQLComponent {
60
    JUniqueTextField field = new JUniqueTextField();
61
    DemandePrixItemTable table = new DemandePrixItemTable();
62
    PanelOOSQLComponent panelOO;
63
    private ElementSQLObject componentPrincipaleAdr;
64
 
65
    public DemandePrixSQLComponent(SQLElement elt) {
66
        super(elt);
67
    }
68
 
69
    @Override
70
    protected void addViews() {
71
 
72
        GridBagConstraints c = new DefaultGridBagConstraints();
73
        setLayout(new GridBagLayout());
74
        // Champ Module
75
        c.gridx = 0;
76
        c.gridy++;
77
        c.gridwidth = GridBagConstraints.REMAINDER;
78
        final JPanel addP = ComptaSQLConfElement.createAdditionalPanel();
79
        this.setAdditionalFieldsPanel(new FormLayouter(addP, 2));
80
        this.add(addP, c);
81
 
82
        // c.gridy++;
83
        // c.gridx = 0;
84
        // c.weightx = 0;
85
        // this.add(new JLabel(getLabelFor("ID_COMMANDE_PREV"), SwingConstants.RIGHT), c);
86
        // c.gridx++;
87
        // c.weightx = 1;
88
        // final ElementComboBox boxCmd = new ElementComboBox();
89
        // this.add(boxCmd, c);
90
        // this.addView(boxCmd, "ID_COMMANDE_PREV");
91
 
92
        c.gridy++;
93
        c.gridwidth = 1;
94
        c.gridx = 0;
95
        c.weightx = 0;
96
        this.add(new JLabel(getLabelFor("NUMERO"), SwingConstants.RIGHT), c);
97
        c.gridx++;
98
        c.weightx = 1;
99
        this.add(field, c);
100
        this.addView(field, "NUMERO", REQ);
101
 
102
        c.gridx++;
103
        c.weightx = 0;
104
        this.add(new JLabel(getLabelFor("DATE"), SwingConstants.RIGHT), c);
105
        c.gridx++;
106
        c.weightx = 1;
107
        JDate date = new JDate(true);
108
        this.add(date, c);
109
        this.addView(date, "DATE", REQ);
110
 
111
        c.gridx = 0;
112
        c.gridy++;
113
        c.weightx = 0;
114
        this.add(new JLabel(getLabelFor("ID_FOURNISSEUR"), SwingConstants.RIGHT), c);
115
        c.gridx++;
116
        c.weightx = 1;
117
        final ElementComboBox boxFournisseur = new ElementComboBox();
118
        this.add(boxFournisseur, c);
119
        this.addView(boxFournisseur, "ID_FOURNISSEUR", REQ);
120
 
121
        c.gridx++;
122
        c.weightx = 0;
123
        this.add(new JLabel(getLabelFor("DATE_BUTOIRE"), SwingConstants.RIGHT), c);
124
        c.gridx++;
125
        c.weightx = 1;
126
        JDate dateButoire = new JDate(false);
127
        this.add(dateButoire, c);
128
 
129
        this.addView(dateButoire, "DATE_BUTOIRE");
185 ilm 130
 
144 ilm 131
        //
132
        // c.gridx++;
133
        // c.weightx = 0;
134
        // this.add(new JLabel(getLabelFor("DATE_DISPOSITION"), SwingConstants.RIGHT), c);
135
        // c.gridx++;
136
        // c.weightx = 1;
137
        // final JDate dateDisposition = new JDate();
138
        // this.add(dateDisposition, c);
139
        // this.addView(dateDisposition, "DATE_DISPOSITION", REQ);
140
 
141
        // c.gridx = 0;
142
        // c.gridy++;
143
        // c.weightx = 0;
144
        // this.add(new JLabel(getLabelFor("ID_CONTACT_FOURNISSEUR"), SwingConstants.RIGHT), c);
145
        // c.gridx++;
146
        // c.weightx = 1;
147
        // final ElementComboBox boxContactFournisseur = new ElementComboBox();
148
        // this.add(boxContactFournisseur, c);
149
        // final SQLElement contactElement =
150
        // Configuration.getInstance().getDirectory().getElement("CONTACT_FOURNISSEUR");
151
        // boxContactFournisseur.init(contactElement, contactElement.getComboRequest(true));
152
        // this.addView(boxContactFournisseur, "ID_CONTACT_FOURNISSEUR", REQ);
153
        //
154
        // boxFournisseur.addModelListener("wantedID", new PropertyChangeListener() {
155
        //
156
        // @Override
157
        // public void propertyChange(PropertyChangeEvent arg0) {
158
        //
159
        // SQLRow selectedRow =
160
        // boxFournisseur.getRequest().getPrimaryTable().getRow(boxFournisseur.getWantedID());
161
        // if (selectedRow != null) {
162
        // boxContactFournisseur.getRequest().setWhere(new
163
        // Where(contactElement.getTable().getField("ID_FOURNISSEUR"), "=", selectedRow.getID()));
164
        // } else {
165
        // boxContactFournisseur.getRequest().setWhere(null);
166
        // }
167
        // }
168
        // });
169
 
170
        // this.addView("ID_ADRESSE");
171
        // Etat devis
172
        // c.gridx = 0;
173
        // c.gridy++;
174
        //
175
        // this.add(new JLabel(getLabelFor("ID_COMMERCIAL")), c);
176
        // c.gridx++;
177
        // ElementComboBox boxComm = new ElementComboBox();
178
        // this.add(boxComm, c);
179
        // this.addView(boxComm, "ID_COMMERCIAL");
180
 
181
        // SQLRequestComboBox boxEtat = new SQLRequestComboBox();
182
        // c.weightx = 0;
183
        // this.add(new JLabel(getLabelFor("ID_ETAT_DEMANDE_PRIX")), c);
184
        // c.gridx++;
185
        // c.weightx = 1;
186
        // this.add(boxEtat, c);
187
        // this.addView(boxEtat, "ID_ETAT_DEMANDE_PRIX");
188
 
182 ilm 189
        c.gridx = 0;
190
        c.gridy++;
144 ilm 191
        c.weightx = 0;
182 ilm 192
        this.add(new JLabel(getLabelFor("ID_COMMERCIAL"), SwingConstants.RIGHT), c);
193
        c.gridx++;
194
        c.weightx = 1;
195
        final ElementComboBox boxCom = new ElementComboBox();
196
        this.add(boxCom, c);
197
        this.addView(boxCom, "ID_COMMERCIAL", REQ);
198
 
199
        c.weightx = 0;
144 ilm 200
        c.gridheight = 1;
201
        c.gridx = 0;
202
        c.gridy++;
203
        c.anchor = GridBagConstraints.WEST;
204
        c.weightx = 0;
205
        JLabel labelObjet = new JLabel(getLabelFor("OBJET"), SwingConstants.RIGHT);
206
        this.add(labelObjet, c);
207
        c.gridx++;
208
        ITextArea area = new ITextArea();
209
        c.weightx = 1;
210
        this.add(area, c);
211
        this.addView(area, "OBJET");
212
 
213
        RadioButtons radioEtat = new RadioButtons("NOM");
214
        radioEtat.setLayout(new VFlowLayout());
215
        radioEtat.setBorder(BorderFactory.createTitledBorder(getLabelFor("ID_ETAT_DEMANDE_PRIX")));
216
        c.gridx = 3;
217
        c.gridheight = 5;
218
        c.anchor = GridBagConstraints.NORTHWEST;
219
        this.add(radioEtat, c);
220
        this.addView(radioEtat, "ID_ETAT_DEMANDE_PRIX", REQ);
221
 
222
        // c.gridx = 0;
223
        // c.gridy++;
224
        // c.gridwidth = 2;
225
        // c.weightx = 1;
226
        // this.add(new TitledSeparator("Adresse de destination"), c);
227
        // c.gridy++;
228
        // c.weightx = 0;
229
        // final JCheckBox boxLivr = new JCheckBox("Livré par le fournisseur");
230
        // this.add(boxLivr, c);
231
        // this.addView(boxLivr, "LIVRAISON_F");
232
        // c.gridy++;
233
        // final ElementComboBox boxAdr = new ElementComboBox();
234
        // final SQLElement adrElement = getElement().getForeignElement("ID_ADRESSE");
235
        // boxAdr.init(adrElement);
236
        // c.gridwidth = 1;
237
        // final JLabel labelAdrLiv = new JLabel("Adresse de livraison existante");
238
        // this.add(labelAdrLiv, c);
239
        // c.gridx++;
240
        // c.gridwidth = 2;
241
        // this.add(boxAdr, c);
242
        // c.gridy++;
243
        // c.gridx = 0;
244
        // this.addView("ID_ADRESSE");
245
        // final DefaultElementSQLObject comp = (DefaultElementSQLObject)
246
        // this.getView("ID_ADRESSE").getComp();
247
        // componentPrincipaleAdr = (ElementSQLObject) this.getView("ID_ADRESSE");
248
        // this.add(comp, c);
249
        // boxLivr.addActionListener(new ActionListener() {
250
        //
251
        // @Override
252
        // public void actionPerformed(ActionEvent e) {
253
        // if (boxLivr.isSelected() && !comp.isCreated()) {
254
        // comp.setCreated(true);
255
        // componentPrincipaleAdr.setEditable(InteractionMode.READ_WRITE);
256
        // final SQLRow selectedRow2 = boxAffaire.getSelectedRow();
257
        // if (selectedRow2 != null) {
258
        // SQLRowValues rowVals = getLivraisonAdr(selectedRow2.asRow());
259
        // rowVals.put("RUE", "");
260
        // comp.setValue(rowVals);
261
        // }
262
        // } else {
263
        // if (!boxLivr.isSelected()) {
264
        // comp.setCreated(false);
265
        // componentPrincipaleAdr.setEditable(InteractionMode.DISABLED);
266
        // }
267
        // }
268
        //
269
        // }
270
        // });
271
        // comp.addValueListener(new PropertyChangeListener() {
272
        //
273
        // @Override
274
        // public void propertyChange(PropertyChangeEvent evt) {
275
        // boxAdr.setVisible(comp.isCreated());
276
        // labelAdrLiv.setVisible(comp.isCreated());
277
        // }
278
        // });
279
 
280
        // boxAffaire.addModelListener("wantedID", new PropertyChangeListener() {
281
        // SQLTable tableAdr = getTable().getTable("ADRESSE");
282
        //
283
        // @Override
284
        // public void propertyChange(PropertyChangeEvent evt) {
285
        //
286
        // SQLRow selectedRow =
287
        // boxAffaire.getRequest().getPrimaryTable().getRow(boxAffaire.getWantedID());
288
        // boxCmd.getRequest().setWhere(Where.FALSE);
289
        // if (selectedRow != null && !selectedRow.isUndefined()) {
290
        //
291
        // SQLRow client = selectedRow.getForeign("ID_CLIENT");
292
        //
293
        // boxAdr.getRequest().setWhere(((AffaireSQLElement)
294
        // boxAffaire.getElement()).getWhereAdrL(client));
295
        // boxCmd.getRequest().setWhere(new
296
        // Where(getTable().getForeignTable("ID_COMMANDE_PREV").getField("ID_AFFAIRE"), "=",
297
        // selectedRow.getID()));
298
        //
299
        // }
300
        // }
301
        // });
302
        // boxAdr.addValueListener(new PropertyChangeListener() {
303
        //
304
        // @Override
305
        // public void propertyChange(PropertyChangeEvent evt) {
306
        // final SQLRow selectedRow = boxAdr.getSelectedRow().asRow();
307
        // if (selectedRow != null && !selectedRow.isUndefined()) {
308
        // SQLRowValues rowVals = selectedRow.asRowValues();
309
        // rowVals.clearPrimaryKeys();
310
        // rowVals.put("RUE", "");
311
        // comp.setValue(rowVals);
312
        // }
313
        // }
314
        // });
315
        // boxAdr.setVisible(false);
316
        // labelAdrLiv.setVisible(false);
317
        c.gridwidth = GridBagConstraints.REMAINDER;
318
        c.gridheight = 1;
319
        c.gridy += 6;
320
        c.gridx = 0;
321
        c.weightx = 1;
322
        c.weighty = 1;
323
        c.fill = GridBagConstraints.BOTH;
324
        this.add(this.table, c);
325
 
326
        // boxFournisseur.addValueListener(new PropertyChangeListener() {
327
        //
328
        // @Override
329
        // public void propertyChange(PropertyChangeEvent evt) {
330
        // // TODO Raccord de méthode auto-généré
331
        // table.setFournisseurFilterOnCompletion(boxFournisseur.getSelectedRow().asRow());
332
        // if (boxFournisseur.getSelectedRow().asRow() != null &&
333
        // !boxFournisseur.getSelectedRow().asRow().isUndefined()) {
334
        // SQLRow rowFam =
335
        // boxFournisseur.getSelectedRow().asRow().getForeignRow("ID_FAMILLE_ARTICLE");
336
        // if (rowFam != null && !rowFam.isUndefined()) {
337
        // table.getRowValuesTable().getRowValuesTableModel().getDefaultRowValues().put("ID_FAMILLE_ARTICLE",
338
        // rowFam.getID());
339
        // } else {
340
        // table.getRowValuesTable().getRowValuesTableModel().getDefaultRowValues().putEmptyLink("ID_FAMILLE_ARTICLE");
341
        // }
342
        // } else {
343
        // table.getRowValuesTable().getRowValuesTableModel().getDefaultRowValues().putEmptyLink("ID_FAMILLE_ARTICLE");
344
        // }
345
        // }
346
        // });
347
 
348
        // INfos
349
        c.gridx = 0;
350
        c.gridy++;
351
        c.gridheight = 1;
352
        c.weighty = 0;
353
        c.weightx = 1;
354
        c.anchor = GridBagConstraints.WEST;
355
        c.gridwidth = 3;
356
        c.fill = GridBagConstraints.HORIZONTAL;
357
        this.add(new TitledSeparator(getLabelFor("INFOS")), c);
358
 
359
        c.gridy++;
360
        c.weightx = 1;
361
        c.weighty = 1;
362
        c.fill = GridBagConstraints.BOTH;
363
        JTextArea infos = new ITextArea();
364
        final JScrollPane scrollPane = new JScrollPane(infos);
365
        scrollPane.setBorder(null);
366
        this.add(scrollPane, c);
367
 
368
        // Total
369
        // DeviseField fieldHT = new DeviseField();
370
        // DeviseField fieldTVA = new DeviseField();
371
        // DeviseField fieldTTC = new DeviseField();
372
        // fieldHT.setOpaque(false);
373
        // fieldTVA.setOpaque(false);
374
        // fieldTTC.setOpaque(false);
375
        //
376
        // addRequiredSQLObject(fieldHT, "T_HT");
377
        // addRequiredSQLObject(fieldTVA, "T_TVA");
378
        // addRequiredSQLObject(fieldTTC, "T_TTC");
379
        // JTextField poids = new JTextField();
380
        // // addSQLObject(poids, "T_POIDS");
381
        // final TotalPanel totalTTC = new TotalPanel(this.table.getRowValuesTable(),
382
        // this.table.getPrixTotalHTElement(), this.table.getPrixTotalTTCElement(),
383
        // this.table.getHaElement(),
384
        // this.table.getQteElement(), fieldHT, fieldTVA, fieldTTC, new DeviseField(), new
385
        // DeviseField(), new DeviseField(), this.table.getPrixServiceElement(), new DeviseField(),
386
        // this.table.getTableElementTotalDevise(), poids, this.table.getPoidsTotalElement());
387
        //
388
        // c.gridx = GridBagConstraints.RELATIVE;
389
        // c.gridy--;
390
        // c.gridwidth = GridBagConstraints.REMAINDER;
391
        // c.gridheight = 2;
392
        // c.anchor = GridBagConstraints.NORTHEAST;
393
        // c.fill = GridBagConstraints.NONE;
394
        // c.weighty = 0;
395
        //
396
        // this.add(totalTTC, c);
397
 
398
        addSQLObject(infos, "INFOS");
399
 
400
        this.panelOO = new PanelOOSQLComponent(this);
401
        c.gridwidth = 1;
402
        c.fill = GridBagConstraints.HORIZONTAL;
403
        c.anchor = GridBagConstraints.SOUTHEAST;
404
        // c.gridx = 0;
405
        c.gridx += 3;
406
        c.weightx = 0;
407
        c.fill = GridBagConstraints.NONE;
408
        c.gridwidth = GridBagConstraints.REMAINDER;
409
        this.add(this.panelOO, c);
410
        // this.addView("PRIX");
411
 
412
        // boxAffaire.addValueListener(new PropertyChangeListener() {
413
        //
414
        // @Override
415
        // public void propertyChange(PropertyChangeEvent evt) {
416
        // SQLRow selectedRow = boxAffaire.getSelectedRow().asRow();
417
        // if (!isFilling() && selectedRow != null && !selectedRow.isUndefined()) {
418
        // Calendar date = selectedRow.getDate("DATE_LIVRAISON_EFFECTIVE");
419
        // if (date != null) {
420
        //
421
        // dateDisposition.setValue(date.getTime());
422
        // }
423
        // }
424
        // }
425
        // });
426
 
427
    }
428
 
429
    private SQLRowValues getLivraisonAdr(SQLRow rowAffaire) {
430
        if (rowAffaire != null) {
431
            SQLRow rowClient = rowAffaire.getForeignRow("ID_CLIENT");
432
            SQLRow rowAdrL = rowClient.getForeignRow("ID_ADRESSE_L");
433
            if (rowAdrL == null || rowAdrL.isUndefined()) {
434
                rowAdrL = rowClient.getForeignRow("ID_ADRESSE");
435
            }
436
            SQLRowValues rowVals = rowAdrL.asRowValues();
437
            rowVals.clearPrimaryKeys();
438
            return rowVals;
439
        } else {
440
            return new SQLRowValues(getTable().getTable("ADRESSE"));
441
        }
442
    }
443
 
444
    @Override
445
    public void select(SQLRowAccessor r) {
446
        // TODO Raccord de méthode auto-généré
447
        if (getTable().contains("LIVRAISON_F") && componentPrincipaleAdr != null) {
448
            final boolean bLivraison = r != null && r.getFields().contains("ID_ADRESSE") && !r.isForeignEmpty("ID_ADRESSE");
449
            componentPrincipaleAdr.setEditable(bLivraison ? InteractionMode.READ_WRITE : InteractionMode.DISABLED);
450
        }
451
 
452
        if (r != null) {
453
            // final SQLRowValues rVals = r.asRowValues().deepCopy();
454
            // final SQLRowValues vals = new SQLRowValues(r.getTable());
455
            // vals.load(rVals, CollectionUtils.createSet("ID_AFFAIRE"));
456
            // // vals a besoin de l'ID sinon incohérence entre ID_AFFAIRE et ID (eg for
457
            // // reloadTable())
458
            // // ne pas supprimer l'ID de rVals pour qu'on puisse UPDATE
459
            // vals.setID(rVals.getID());
460
            // super.select(vals);
461
            // rVals.remove("ID_AFFAIRE");
462
            // super.select(rVals);
463
            super.select(r);
464
            this.field.setIdSelected(r.getID());
465
            this.table.insertFrom("ID_DEMANDE_PRIX", r.getID());
466
        } else {
467
            super.select(r);
468
        }
469
    }
470
 
471
    @Override
472
    public int insert(SQLRow order) {
473
 
474
        int idCommande = getSelectedID();
475
 
476
        // on verifie qu'un devis du meme numero n'a pas été inséré entre temps
477
        if (this.field.checkValidation()) {
478
 
479
            idCommande = super.insert(order);
480
            // this.table.updateField("ID_COMMANDE_CLIENT", idCommande);
481
            this.table.updateField("ID_DEMANDE_PRIX", idCommande);
482
            // Création des articles
483
            // this.table.createArticle(idCommande, this.getElement());
484
 
485
            // generation du document
182 ilm 486
            final SQLRow row = getTable().getRow(idCommande);
487
            DemandePrixSheetXML sheet = new DemandePrixSheetXML(row);
144 ilm 488
            sheet.createDocumentAsynchronous();
182 ilm 489
            sheet.showPrintAndExportAsynchronous(true, false, true, getElement(), row);
144 ilm 490
 
491
            // incrémentation du numéro auto
492
            if (NumerotationAutoSQLElement.getNextNumero(DemandePrixSQLElement.class).equalsIgnoreCase(this.field.getText().trim())) {
493
                SQLTable tableNum = Configuration.getInstance().getRoot().findTable("NUMEROTATION_AUTO");
494
                SQLRowValues rowVals = new SQLRowValues(tableNum);
495
                int val = tableNum.getRow(2).getInt("DMD_PRIX_START");
496
                val++;
497
                rowVals.put("DMD_PRIX_START", new Integer(val));
498
 
499
                try {
500
                    rowVals.update(2);
501
                } catch (SQLException e) {
502
                    e.printStackTrace();
503
                }
504
            }
505
 
506
            DemandeAchatItemSQLElement elt = getElement().getDirectory().getElement(DemandeAchatItemSQLElement.class);
507
            elt.updateStatus(getTable(), getTable().getTable("DEMANDE_PRIX_ELEMENT"), idCommande);
508
        } else {
509
            ExceptionHandler.handle("Impossible d'ajouter, numéro de demande existant.");
510
            Object root = SwingUtilities.getRoot(this);
511
            if (root instanceof EditFrame) {
512
                EditFrame frame = (EditFrame) root;
513
                frame.getPanel().setAlwaysVisible(true);
514
            }
515
        }
516
 
517
        return idCommande;
518
    }
519
 
520
    @Override
521
    public void update() {
522
 
523
        if (!this.field.checkValidation()) {
524
            ExceptionHandler.handle("Impossible d'ajouter, numéro de demande existant.");
525
            Object root = SwingUtilities.getRoot(this);
526
            if (root instanceof EditFrame) {
527
                EditFrame frame = (EditFrame) root;
528
                frame.getPanel().setAlwaysVisible(true);
529
            }
530
            return;
531
        }
532
        super.update();
533
        // this.table.updateField("ID_COMMANDE_CLIENT", getSelectedID());
534
        // this.table.createArticle(getSelectedID(), this.getElement());
535
        this.table.updateField("ID_DEMANDE_PRIX", getSelectedID());
536
        DemandeAchatItemSQLElement elt = getElement().getDirectory().getElement(DemandeAchatItemSQLElement.class);
537
        elt.updateStatus(getTable(), getTable().getTable("DEMANDE_PRIX_ELEMENT"), getSelectedID());
538
 
182 ilm 539
        final SQLRow row = getTable().getRow(getSelectedID());
540
        DemandePrixSheetXML sheet = new DemandePrixSheetXML(row);
144 ilm 541
        sheet.createDocumentAsynchronous();
182 ilm 542
        sheet.showPrintAndExportAsynchronous(true, false, true, getElement(), row);
144 ilm 543
 
544
    }
545
 
546
    @Override
547
    protected SQLRowValues createDefaults() {
548
        SQLRowValues rowVals = new SQLRowValues(getTable());
549
        rowVals.put("NUMERO", NumerotationAutoSQLElement.getNextNumero(DemandePrixSQLElement.class));
182 ilm 550
        SQLElement eltComm = getElement().getForeignElement("ID_COMMERCIAL");
185 ilm 551
        int idUser = UserManager.getInstance().getCurrentUser().getId();
182 ilm 552
 
553
        SQLRow rowsComm = SQLBackgroundTableCache.getInstance().getCacheForTable(eltComm.getTable()).getFirstRowContains(idUser, eltComm.getTable().getField("ID_USER_COMMON"));
554
 
555
        if (rowsComm != null) {
556
            rowVals.put("ID_COMMERCIAL", rowsComm.getID());
557
        }
558
 
144 ilm 559
        if (getTable().getUndefinedID() == SQLRow.NONEXISTANT_ID) {
560
            rowVals.put("ID_ETAT_DEMANDE_PRIX", EtatDemandePrixSQLElement.EN_ATTENTE);
561
        } else {
562
            SQLRow rowUndef = getTable().getRow(getTable().getUndefinedID());
563
            SQLRow foreign = rowUndef.getForeign("ID_ETAT_DEMANDE_PRIX");
564
            if (foreign != null && !foreign.isUndefined()) {
565
                rowVals.put("ID_ETAT_DEMANDE_PRIX", foreign.getID());
566
            } else {
567
                rowVals.put("ID_ETAT_DEMANDE_PRIX", EtatDemandePrixSQLElement.EN_ATTENTE);
568
            }
569
        }
570
        if (getTable().contains("LIVRAISON_F") && componentPrincipaleAdr != null) {
571
            componentPrincipaleAdr.setEditable(InteractionMode.DISABLED);
572
        }
573
        return rowVals;
574
    }
575
 
576
    /**
577
     * Création d'une demande à partir d'une demande existante
578
     *
579
     * @param idDemande
580
     *
581
     */
582
    public void loadDemandeExistant(final int idDemande) {
583
 
185 ilm 584
        final SQLElement demande = getElement();
585
        final SQLElement demandeElt = getElement().getDirectory().getElement("DEMANDE_PRIX_ELEMENT");
144 ilm 586
 
587
        // On duplique la demande
588
        if (idDemande > 1) {
589
            final SQLRow row = demande.getTable().getRow(idDemande);
590
            final SQLRowValues rowVals = new SQLRowValues(demande.getTable());
185 ilm 591
            if (demande.getTable().contains("ID_AFFAIRE")) {
592
                rowVals.put("ID_AFFAIRE", row.getForeignIDNumber("ID_AFFAIRE"));
593
            }
144 ilm 594
            // rowVals.put("DATE_BUTOIRE", row.getObject("DATE_BUTOIRE"));
595
            // rowVals.put("DATE_DISPOSITION", row.getObject("DATE_DISPOSITION"));
596
            rowVals.put("NUMERO", NumerotationAutoSQLElement.getNextNumero(DemandePrixSQLElement.class));
597
            rowVals.put("ID_ETAT_DEMANDE_PRIX", EtatDemandePrixSQLElement.EN_ATTENTE);
598
            rowVals.put("OBJET", row.getObject("OBJET"));
599
            rowVals.put("ID_COMMERCIAL", row.getObject("ID_COMMERCIAL"));
600
            this.select(rowVals);
601
        }
602
 
603
        // On duplique les elements de devis
604
        final List<SQLRow> myListItem = demande.getTable().getRow(idDemande).getReferentRows(demandeElt.getTable());
605
 
606
        if (myListItem.size() != 0) {
607
            this.table.getModel().clearRows();
608
 
609
            for (final SQLRow rowElt : myListItem) {
610
 
611
                final SQLRowValues rowVals = rowElt.createUpdateRow();
612
                rowVals.clearPrimaryKeys();
613
                this.table.getModel().addRow(rowVals);
614
                final int rowIndex = this.table.getModel().getRowCount() - 1;
615
                this.table.getModel().fireTableModelModified(rowIndex);
616
            }
617
        } else {
618
            this.table.getModel().clearRows();
619
        }
620
        this.table.getModel().fireTableDataChanged();
621
        this.table.repaint();
622
    }
623
 
624
    @Override
625
    protected RowValuesTable getRowValuesTable() {
626
        return this.table.getRowValuesTable();
627
    }
628
 
629
    @Override
630
    protected void refreshAfterSelect(SQLRowAccessor rSource) {
631
        // TODO Auto-generated method stub
632
 
633
    }
634
}