OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 144 | Go to most recent revision | 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");
130
        //
131
        // c.gridx++;
132
        // c.weightx = 0;
133
        // this.add(new JLabel(getLabelFor("DATE_DISPOSITION"), SwingConstants.RIGHT), c);
134
        // c.gridx++;
135
        // c.weightx = 1;
136
        // final JDate dateDisposition = new JDate();
137
        // this.add(dateDisposition, c);
138
        // this.addView(dateDisposition, "DATE_DISPOSITION", REQ);
139
 
140
        // c.gridx = 0;
141
        // c.gridy++;
142
        // c.weightx = 0;
143
        // this.add(new JLabel(getLabelFor("ID_CONTACT_FOURNISSEUR"), SwingConstants.RIGHT), c);
144
        // c.gridx++;
145
        // c.weightx = 1;
146
        // final ElementComboBox boxContactFournisseur = new ElementComboBox();
147
        // this.add(boxContactFournisseur, c);
148
        // final SQLElement contactElement =
149
        // Configuration.getInstance().getDirectory().getElement("CONTACT_FOURNISSEUR");
150
        // boxContactFournisseur.init(contactElement, contactElement.getComboRequest(true));
151
        // this.addView(boxContactFournisseur, "ID_CONTACT_FOURNISSEUR", REQ);
152
        //
153
        // boxFournisseur.addModelListener("wantedID", new PropertyChangeListener() {
154
        //
155
        // @Override
156
        // public void propertyChange(PropertyChangeEvent arg0) {
157
        //
158
        // SQLRow selectedRow =
159
        // boxFournisseur.getRequest().getPrimaryTable().getRow(boxFournisseur.getWantedID());
160
        // if (selectedRow != null) {
161
        // boxContactFournisseur.getRequest().setWhere(new
162
        // Where(contactElement.getTable().getField("ID_FOURNISSEUR"), "=", selectedRow.getID()));
163
        // } else {
164
        // boxContactFournisseur.getRequest().setWhere(null);
165
        // }
166
        // }
167
        // });
168
 
169
        // this.addView("ID_ADRESSE");
170
        // Etat devis
171
        // c.gridx = 0;
172
        // c.gridy++;
173
        //
174
        // this.add(new JLabel(getLabelFor("ID_COMMERCIAL")), c);
175
        // c.gridx++;
176
        // ElementComboBox boxComm = new ElementComboBox();
177
        // this.add(boxComm, c);
178
        // this.addView(boxComm, "ID_COMMERCIAL");
179
 
180
        // SQLRequestComboBox boxEtat = new SQLRequestComboBox();
181
        // c.weightx = 0;
182
        // this.add(new JLabel(getLabelFor("ID_ETAT_DEMANDE_PRIX")), c);
183
        // c.gridx++;
184
        // c.weightx = 1;
185
        // this.add(boxEtat, c);
186
        // this.addView(boxEtat, "ID_ETAT_DEMANDE_PRIX");
187
 
182 ilm 188
        c.gridx = 0;
189
        c.gridy++;
144 ilm 190
        c.weightx = 0;
182 ilm 191
        this.add(new JLabel(getLabelFor("ID_COMMERCIAL"), SwingConstants.RIGHT), c);
192
        c.gridx++;
193
        c.weightx = 1;
194
        final ElementComboBox boxCom = new ElementComboBox();
195
        this.add(boxCom, c);
196
        this.addView(boxCom, "ID_COMMERCIAL", REQ);
197
 
198
        c.weightx = 0;
144 ilm 199
        c.gridheight = 1;
200
        c.gridx = 0;
201
        c.gridy++;
202
        c.anchor = GridBagConstraints.WEST;
203
        c.weightx = 0;
204
        JLabel labelObjet = new JLabel(getLabelFor("OBJET"), SwingConstants.RIGHT);
205
        this.add(labelObjet, c);
206
        c.gridx++;
207
        ITextArea area = new ITextArea();
208
        c.weightx = 1;
209
        this.add(area, c);
210
        this.addView(area, "OBJET");
211
 
212
        RadioButtons radioEtat = new RadioButtons("NOM");
213
        radioEtat.setLayout(new VFlowLayout());
214
        radioEtat.setBorder(BorderFactory.createTitledBorder(getLabelFor("ID_ETAT_DEMANDE_PRIX")));
215
        c.gridx = 3;
216
        c.gridheight = 5;
217
        c.anchor = GridBagConstraints.NORTHWEST;
218
        this.add(radioEtat, c);
219
        this.addView(radioEtat, "ID_ETAT_DEMANDE_PRIX", REQ);
220
 
221
        // c.gridx = 0;
222
        // c.gridy++;
223
        // c.gridwidth = 2;
224
        // c.weightx = 1;
225
        // this.add(new TitledSeparator("Adresse de destination"), c);
226
        // c.gridy++;
227
        // c.weightx = 0;
228
        // final JCheckBox boxLivr = new JCheckBox("Livré par le fournisseur");
229
        // this.add(boxLivr, c);
230
        // this.addView(boxLivr, "LIVRAISON_F");
231
        // c.gridy++;
232
        // final ElementComboBox boxAdr = new ElementComboBox();
233
        // final SQLElement adrElement = getElement().getForeignElement("ID_ADRESSE");
234
        // boxAdr.init(adrElement);
235
        // c.gridwidth = 1;
236
        // final JLabel labelAdrLiv = new JLabel("Adresse de livraison existante");
237
        // this.add(labelAdrLiv, c);
238
        // c.gridx++;
239
        // c.gridwidth = 2;
240
        // this.add(boxAdr, c);
241
        // c.gridy++;
242
        // c.gridx = 0;
243
        // this.addView("ID_ADRESSE");
244
        // final DefaultElementSQLObject comp = (DefaultElementSQLObject)
245
        // this.getView("ID_ADRESSE").getComp();
246
        // componentPrincipaleAdr = (ElementSQLObject) this.getView("ID_ADRESSE");
247
        // this.add(comp, c);
248
        // boxLivr.addActionListener(new ActionListener() {
249
        //
250
        // @Override
251
        // public void actionPerformed(ActionEvent e) {
252
        // if (boxLivr.isSelected() && !comp.isCreated()) {
253
        // comp.setCreated(true);
254
        // componentPrincipaleAdr.setEditable(InteractionMode.READ_WRITE);
255
        // final SQLRow selectedRow2 = boxAffaire.getSelectedRow();
256
        // if (selectedRow2 != null) {
257
        // SQLRowValues rowVals = getLivraisonAdr(selectedRow2.asRow());
258
        // rowVals.put("RUE", "");
259
        // comp.setValue(rowVals);
260
        // }
261
        // } else {
262
        // if (!boxLivr.isSelected()) {
263
        // comp.setCreated(false);
264
        // componentPrincipaleAdr.setEditable(InteractionMode.DISABLED);
265
        // }
266
        // }
267
        //
268
        // }
269
        // });
270
        // comp.addValueListener(new PropertyChangeListener() {
271
        //
272
        // @Override
273
        // public void propertyChange(PropertyChangeEvent evt) {
274
        // boxAdr.setVisible(comp.isCreated());
275
        // labelAdrLiv.setVisible(comp.isCreated());
276
        // }
277
        // });
278
 
279
        // boxAffaire.addModelListener("wantedID", new PropertyChangeListener() {
280
        // SQLTable tableAdr = getTable().getTable("ADRESSE");
281
        //
282
        // @Override
283
        // public void propertyChange(PropertyChangeEvent evt) {
284
        //
285
        // SQLRow selectedRow =
286
        // boxAffaire.getRequest().getPrimaryTable().getRow(boxAffaire.getWantedID());
287
        // boxCmd.getRequest().setWhere(Where.FALSE);
288
        // if (selectedRow != null && !selectedRow.isUndefined()) {
289
        //
290
        // SQLRow client = selectedRow.getForeign("ID_CLIENT");
291
        //
292
        // boxAdr.getRequest().setWhere(((AffaireSQLElement)
293
        // boxAffaire.getElement()).getWhereAdrL(client));
294
        // boxCmd.getRequest().setWhere(new
295
        // Where(getTable().getForeignTable("ID_COMMANDE_PREV").getField("ID_AFFAIRE"), "=",
296
        // selectedRow.getID()));
297
        //
298
        // }
299
        // }
300
        // });
301
        // boxAdr.addValueListener(new PropertyChangeListener() {
302
        //
303
        // @Override
304
        // public void propertyChange(PropertyChangeEvent evt) {
305
        // final SQLRow selectedRow = boxAdr.getSelectedRow().asRow();
306
        // if (selectedRow != null && !selectedRow.isUndefined()) {
307
        // SQLRowValues rowVals = selectedRow.asRowValues();
308
        // rowVals.clearPrimaryKeys();
309
        // rowVals.put("RUE", "");
310
        // comp.setValue(rowVals);
311
        // }
312
        // }
313
        // });
314
        // boxAdr.setVisible(false);
315
        // labelAdrLiv.setVisible(false);
316
        c.gridwidth = GridBagConstraints.REMAINDER;
317
        c.gridheight = 1;
318
        c.gridy += 6;
319
        c.gridx = 0;
320
        c.weightx = 1;
321
        c.weighty = 1;
322
        c.fill = GridBagConstraints.BOTH;
323
        this.add(this.table, c);
324
 
325
        // boxFournisseur.addValueListener(new PropertyChangeListener() {
326
        //
327
        // @Override
328
        // public void propertyChange(PropertyChangeEvent evt) {
329
        // // TODO Raccord de méthode auto-généré
330
        // table.setFournisseurFilterOnCompletion(boxFournisseur.getSelectedRow().asRow());
331
        // if (boxFournisseur.getSelectedRow().asRow() != null &&
332
        // !boxFournisseur.getSelectedRow().asRow().isUndefined()) {
333
        // SQLRow rowFam =
334
        // boxFournisseur.getSelectedRow().asRow().getForeignRow("ID_FAMILLE_ARTICLE");
335
        // if (rowFam != null && !rowFam.isUndefined()) {
336
        // table.getRowValuesTable().getRowValuesTableModel().getDefaultRowValues().put("ID_FAMILLE_ARTICLE",
337
        // rowFam.getID());
338
        // } else {
339
        // table.getRowValuesTable().getRowValuesTableModel().getDefaultRowValues().putEmptyLink("ID_FAMILLE_ARTICLE");
340
        // }
341
        // } else {
342
        // table.getRowValuesTable().getRowValuesTableModel().getDefaultRowValues().putEmptyLink("ID_FAMILLE_ARTICLE");
343
        // }
344
        // }
345
        // });
346
 
347
        // INfos
348
        c.gridx = 0;
349
        c.gridy++;
350
        c.gridheight = 1;
351
        c.weighty = 0;
352
        c.weightx = 1;
353
        c.anchor = GridBagConstraints.WEST;
354
        c.gridwidth = 3;
355
        c.fill = GridBagConstraints.HORIZONTAL;
356
        this.add(new TitledSeparator(getLabelFor("INFOS")), c);
357
 
358
        c.gridy++;
359
        c.weightx = 1;
360
        c.weighty = 1;
361
        c.fill = GridBagConstraints.BOTH;
362
        JTextArea infos = new ITextArea();
363
        final JScrollPane scrollPane = new JScrollPane(infos);
364
        scrollPane.setBorder(null);
365
        this.add(scrollPane, c);
366
 
367
        // Total
368
        // DeviseField fieldHT = new DeviseField();
369
        // DeviseField fieldTVA = new DeviseField();
370
        // DeviseField fieldTTC = new DeviseField();
371
        // fieldHT.setOpaque(false);
372
        // fieldTVA.setOpaque(false);
373
        // fieldTTC.setOpaque(false);
374
        //
375
        // addRequiredSQLObject(fieldHT, "T_HT");
376
        // addRequiredSQLObject(fieldTVA, "T_TVA");
377
        // addRequiredSQLObject(fieldTTC, "T_TTC");
378
        // JTextField poids = new JTextField();
379
        // // addSQLObject(poids, "T_POIDS");
380
        // final TotalPanel totalTTC = new TotalPanel(this.table.getRowValuesTable(),
381
        // this.table.getPrixTotalHTElement(), this.table.getPrixTotalTTCElement(),
382
        // this.table.getHaElement(),
383
        // this.table.getQteElement(), fieldHT, fieldTVA, fieldTTC, new DeviseField(), new
384
        // DeviseField(), new DeviseField(), this.table.getPrixServiceElement(), new DeviseField(),
385
        // this.table.getTableElementTotalDevise(), poids, this.table.getPoidsTotalElement());
386
        //
387
        // c.gridx = GridBagConstraints.RELATIVE;
388
        // c.gridy--;
389
        // c.gridwidth = GridBagConstraints.REMAINDER;
390
        // c.gridheight = 2;
391
        // c.anchor = GridBagConstraints.NORTHEAST;
392
        // c.fill = GridBagConstraints.NONE;
393
        // c.weighty = 0;
394
        //
395
        // this.add(totalTTC, c);
396
 
397
        addSQLObject(infos, "INFOS");
398
 
399
        this.panelOO = new PanelOOSQLComponent(this);
400
        c.gridwidth = 1;
401
        c.fill = GridBagConstraints.HORIZONTAL;
402
        c.anchor = GridBagConstraints.SOUTHEAST;
403
        // c.gridx = 0;
404
        c.gridx += 3;
405
        c.weightx = 0;
406
        c.fill = GridBagConstraints.NONE;
407
        c.gridwidth = GridBagConstraints.REMAINDER;
408
        this.add(this.panelOO, c);
409
        // this.addView("PRIX");
410
 
411
        // boxAffaire.addValueListener(new PropertyChangeListener() {
412
        //
413
        // @Override
414
        // public void propertyChange(PropertyChangeEvent evt) {
415
        // SQLRow selectedRow = boxAffaire.getSelectedRow().asRow();
416
        // if (!isFilling() && selectedRow != null && !selectedRow.isUndefined()) {
417
        // Calendar date = selectedRow.getDate("DATE_LIVRAISON_EFFECTIVE");
418
        // if (date != null) {
419
        //
420
        // dateDisposition.setValue(date.getTime());
421
        // }
422
        // }
423
        // }
424
        // });
425
 
426
    }
427
 
428
    private SQLRowValues getLivraisonAdr(SQLRow rowAffaire) {
429
        if (rowAffaire != null) {
430
            SQLRow rowClient = rowAffaire.getForeignRow("ID_CLIENT");
431
            SQLRow rowAdrL = rowClient.getForeignRow("ID_ADRESSE_L");
432
            if (rowAdrL == null || rowAdrL.isUndefined()) {
433
                rowAdrL = rowClient.getForeignRow("ID_ADRESSE");
434
            }
435
            SQLRowValues rowVals = rowAdrL.asRowValues();
436
            rowVals.clearPrimaryKeys();
437
            return rowVals;
438
        } else {
439
            return new SQLRowValues(getTable().getTable("ADRESSE"));
440
        }
441
    }
442
 
443
    @Override
444
    public void select(SQLRowAccessor r) {
445
        // TODO Raccord de méthode auto-généré
446
        if (getTable().contains("LIVRAISON_F") && componentPrincipaleAdr != null) {
447
            final boolean bLivraison = r != null && r.getFields().contains("ID_ADRESSE") && !r.isForeignEmpty("ID_ADRESSE");
448
            componentPrincipaleAdr.setEditable(bLivraison ? InteractionMode.READ_WRITE : InteractionMode.DISABLED);
449
        }
450
 
451
        if (r != null) {
452
            // final SQLRowValues rVals = r.asRowValues().deepCopy();
453
            // final SQLRowValues vals = new SQLRowValues(r.getTable());
454
            // vals.load(rVals, CollectionUtils.createSet("ID_AFFAIRE"));
455
            // // vals a besoin de l'ID sinon incohérence entre ID_AFFAIRE et ID (eg for
456
            // // reloadTable())
457
            // // ne pas supprimer l'ID de rVals pour qu'on puisse UPDATE
458
            // vals.setID(rVals.getID());
459
            // super.select(vals);
460
            // rVals.remove("ID_AFFAIRE");
461
            // super.select(rVals);
462
            super.select(r);
463
            this.field.setIdSelected(r.getID());
464
            this.table.insertFrom("ID_DEMANDE_PRIX", r.getID());
465
        } else {
466
            super.select(r);
467
        }
468
    }
469
 
470
    @Override
471
    public int insert(SQLRow order) {
472
 
473
        int idCommande = getSelectedID();
474
 
475
        // on verifie qu'un devis du meme numero n'a pas été inséré entre temps
476
        if (this.field.checkValidation()) {
477
 
478
            idCommande = super.insert(order);
479
            // this.table.updateField("ID_COMMANDE_CLIENT", idCommande);
480
            this.table.updateField("ID_DEMANDE_PRIX", idCommande);
481
            // Création des articles
482
            // this.table.createArticle(idCommande, this.getElement());
483
 
484
            // generation du document
182 ilm 485
            final SQLRow row = getTable().getRow(idCommande);
486
            DemandePrixSheetXML sheet = new DemandePrixSheetXML(row);
144 ilm 487
            sheet.createDocumentAsynchronous();
182 ilm 488
            sheet.showPrintAndExportAsynchronous(true, false, true, getElement(), row);
144 ilm 489
 
490
            // incrémentation du numéro auto
491
            if (NumerotationAutoSQLElement.getNextNumero(DemandePrixSQLElement.class).equalsIgnoreCase(this.field.getText().trim())) {
492
                SQLTable tableNum = Configuration.getInstance().getRoot().findTable("NUMEROTATION_AUTO");
493
                SQLRowValues rowVals = new SQLRowValues(tableNum);
494
                int val = tableNum.getRow(2).getInt("DMD_PRIX_START");
495
                val++;
496
                rowVals.put("DMD_PRIX_START", new Integer(val));
497
 
498
                try {
499
                    rowVals.update(2);
500
                } catch (SQLException e) {
501
                    e.printStackTrace();
502
                }
503
            }
504
 
505
            DemandeAchatItemSQLElement elt = getElement().getDirectory().getElement(DemandeAchatItemSQLElement.class);
506
            elt.updateStatus(getTable(), getTable().getTable("DEMANDE_PRIX_ELEMENT"), idCommande);
507
        } else {
508
            ExceptionHandler.handle("Impossible d'ajouter, numéro de demande existant.");
509
            Object root = SwingUtilities.getRoot(this);
510
            if (root instanceof EditFrame) {
511
                EditFrame frame = (EditFrame) root;
512
                frame.getPanel().setAlwaysVisible(true);
513
            }
514
        }
515
 
516
        return idCommande;
517
    }
518
 
519
    @Override
520
    public void update() {
521
 
522
        if (!this.field.checkValidation()) {
523
            ExceptionHandler.handle("Impossible d'ajouter, numéro de demande existant.");
524
            Object root = SwingUtilities.getRoot(this);
525
            if (root instanceof EditFrame) {
526
                EditFrame frame = (EditFrame) root;
527
                frame.getPanel().setAlwaysVisible(true);
528
            }
529
            return;
530
        }
531
        super.update();
532
        // this.table.updateField("ID_COMMANDE_CLIENT", getSelectedID());
533
        // this.table.createArticle(getSelectedID(), this.getElement());
534
        this.table.updateField("ID_DEMANDE_PRIX", getSelectedID());
535
        DemandeAchatItemSQLElement elt = getElement().getDirectory().getElement(DemandeAchatItemSQLElement.class);
536
        elt.updateStatus(getTable(), getTable().getTable("DEMANDE_PRIX_ELEMENT"), getSelectedID());
537
 
182 ilm 538
        final SQLRow row = getTable().getRow(getSelectedID());
539
        DemandePrixSheetXML sheet = new DemandePrixSheetXML(row);
144 ilm 540
        sheet.createDocumentAsynchronous();
182 ilm 541
        sheet.showPrintAndExportAsynchronous(true, false, true, getElement(), row);
144 ilm 542
 
543
    }
544
 
545
    @Override
546
    protected SQLRowValues createDefaults() {
547
        SQLRowValues rowVals = new SQLRowValues(getTable());
548
        rowVals.put("NUMERO", NumerotationAutoSQLElement.getNextNumero(DemandePrixSQLElement.class));
182 ilm 549
        SQLElement eltComm = getElement().getForeignElement("ID_COMMERCIAL");
550
        int idUser = UserManager.getInstance().getCurrentUserID();
551
 
552
        SQLRow rowsComm = SQLBackgroundTableCache.getInstance().getCacheForTable(eltComm.getTable()).getFirstRowContains(idUser, eltComm.getTable().getField("ID_USER_COMMON"));
553
 
554
        if (rowsComm != null) {
555
            rowVals.put("ID_COMMERCIAL", rowsComm.getID());
556
        }
557
 
144 ilm 558
        if (getTable().getUndefinedID() == SQLRow.NONEXISTANT_ID) {
559
            rowVals.put("ID_ETAT_DEMANDE_PRIX", EtatDemandePrixSQLElement.EN_ATTENTE);
560
        } else {
561
            SQLRow rowUndef = getTable().getRow(getTable().getUndefinedID());
562
            SQLRow foreign = rowUndef.getForeign("ID_ETAT_DEMANDE_PRIX");
563
            if (foreign != null && !foreign.isUndefined()) {
564
                rowVals.put("ID_ETAT_DEMANDE_PRIX", foreign.getID());
565
            } else {
566
                rowVals.put("ID_ETAT_DEMANDE_PRIX", EtatDemandePrixSQLElement.EN_ATTENTE);
567
            }
568
        }
569
        if (getTable().contains("LIVRAISON_F") && componentPrincipaleAdr != null) {
570
            componentPrincipaleAdr.setEditable(InteractionMode.DISABLED);
571
        }
572
        return rowVals;
573
    }
574
 
575
    /**
576
     * Création d'une demande à partir d'une demande existante
577
     *
578
     * @param idDemande
579
     *
580
     */
581
    public void loadDemandeExistant(final int idDemande) {
582
 
583
        final SQLElement demande = Configuration.getInstance().getDirectory().getElement("DEMANDE_PRIX");
584
        final SQLElement demandeElt = Configuration.getInstance().getDirectory().getElement("DEMANDE_PRIX_ELEMENT");
585
 
586
        // On duplique la demande
587
        if (idDemande > 1) {
588
            final SQLRow row = demande.getTable().getRow(idDemande);
589
            final SQLRowValues rowVals = new SQLRowValues(demande.getTable());
590
            rowVals.put("ID_AFFAIRE", row.getInt("ID_AFFAIRE"));
591
            // rowVals.put("DATE_BUTOIRE", row.getObject("DATE_BUTOIRE"));
592
            // rowVals.put("DATE_DISPOSITION", row.getObject("DATE_DISPOSITION"));
593
            rowVals.put("NUMERO", NumerotationAutoSQLElement.getNextNumero(DemandePrixSQLElement.class));
594
            rowVals.put("ID_ETAT_DEMANDE_PRIX", EtatDemandePrixSQLElement.EN_ATTENTE);
595
            rowVals.put("OBJET", row.getObject("OBJET"));
596
            rowVals.put("ID_COMMERCIAL", row.getObject("ID_COMMERCIAL"));
597
            this.select(rowVals);
598
        }
599
 
600
        // On duplique les elements de devis
601
        final List<SQLRow> myListItem = demande.getTable().getRow(idDemande).getReferentRows(demandeElt.getTable());
602
 
603
        if (myListItem.size() != 0) {
604
            this.table.getModel().clearRows();
605
 
606
            for (final SQLRow rowElt : myListItem) {
607
 
608
                final SQLRowValues rowVals = rowElt.createUpdateRow();
609
                rowVals.clearPrimaryKeys();
610
                this.table.getModel().addRow(rowVals);
611
                final int rowIndex = this.table.getModel().getRowCount() - 1;
612
                this.table.getModel().fireTableModelModified(rowIndex);
613
            }
614
        } else {
615
            this.table.getModel().clearRows();
616
        }
617
        this.table.getModel().fireTableDataChanged();
618
        this.table.repaint();
619
    }
620
 
621
    @Override
622
    protected RowValuesTable getRowValuesTable() {
623
        return this.table.getRowValuesTable();
624
    }
625
 
626
    @Override
627
    protected void refreshAfterSelect(SQLRowAccessor rSource) {
628
        // TODO Auto-generated method stub
629
 
630
    }
631
}