OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 73 | Rev 90 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 73 Rev 83
Line 21... Line 21...
21
import org.openconcerto.erp.core.common.ui.DeviseField;
21
import org.openconcerto.erp.core.common.ui.DeviseField;
22
import org.openconcerto.erp.core.common.ui.TotalPanel;
22
import org.openconcerto.erp.core.common.ui.TotalPanel;
23
import org.openconcerto.erp.core.sales.order.element.CommandeClientSQLElement;
23
import org.openconcerto.erp.core.sales.order.element.CommandeClientSQLElement;
24
import org.openconcerto.erp.core.sales.order.report.CommandeClientXmlSheet;
24
import org.openconcerto.erp.core.sales.order.report.CommandeClientXmlSheet;
25
import org.openconcerto.erp.core.sales.order.ui.CommandeClientItemTable;
25
import org.openconcerto.erp.core.sales.order.ui.CommandeClientItemTable;
-
 
26
import org.openconcerto.erp.core.supplychain.stock.element.MouvementStockSQLElement;
-
 
27
import org.openconcerto.erp.core.supplychain.stock.element.StockItemsUpdater;
-
 
28
import org.openconcerto.erp.core.supplychain.stock.element.StockItemsUpdater.Type;
-
 
29
import org.openconcerto.erp.core.supplychain.stock.element.StockLabel;
26
import org.openconcerto.erp.panel.PanelOOSQLComponent;
30
import org.openconcerto.erp.panel.PanelOOSQLComponent;
27
import org.openconcerto.erp.preferences.DefaultNXProps;
31
import org.openconcerto.erp.preferences.DefaultNXProps;
28
import org.openconcerto.sql.Configuration;
32
import org.openconcerto.sql.Configuration;
29
import org.openconcerto.sql.element.SQLElement;
33
import org.openconcerto.sql.element.SQLElement;
30
import org.openconcerto.sql.model.SQLBackgroundTableCache;
34
import org.openconcerto.sql.model.SQLBackgroundTableCache;
31
import org.openconcerto.sql.model.SQLInjector;
35
import org.openconcerto.sql.model.SQLInjector;
32
import org.openconcerto.sql.model.SQLRow;
36
import org.openconcerto.sql.model.SQLRow;
33
import org.openconcerto.sql.model.SQLRowAccessor;
37
import org.openconcerto.sql.model.SQLRowAccessor;
34
import org.openconcerto.sql.model.SQLRowValues;
38
import org.openconcerto.sql.model.SQLRowValues;
-
 
39
import org.openconcerto.sql.model.SQLSelect;
35
import org.openconcerto.sql.model.SQLTable;
40
import org.openconcerto.sql.model.SQLTable;
-
 
41
import org.openconcerto.sql.model.Where;
36
import org.openconcerto.sql.sqlobject.ElementComboBox;
42
import org.openconcerto.sql.sqlobject.ElementComboBox;
37
import org.openconcerto.sql.sqlobject.JUniqueTextField;
43
import org.openconcerto.sql.sqlobject.JUniqueTextField;
38
import org.openconcerto.sql.sqlobject.SQLTextCombo;
44
import org.openconcerto.sql.sqlobject.SQLTextCombo;
39
import org.openconcerto.sql.users.UserManager;
45
import org.openconcerto.sql.users.UserManager;
40
import org.openconcerto.sql.view.EditFrame;
46
import org.openconcerto.sql.view.EditFrame;
Line 52... Line 58...
52
import java.awt.GridBagLayout;
58
import java.awt.GridBagLayout;
53
import java.beans.PropertyChangeEvent;
59
import java.beans.PropertyChangeEvent;
54
import java.beans.PropertyChangeListener;
60
import java.beans.PropertyChangeListener;
55
import java.sql.SQLException;
61
import java.sql.SQLException;
56
import java.util.Date;
62
import java.util.Date;
-
 
63
import java.util.List;
57
 
64
 
58
import javax.swing.JLabel;
65
import javax.swing.JLabel;
59
import javax.swing.JOptionPane;
66
import javax.swing.JOptionPane;
60
import javax.swing.JPanel;
67
import javax.swing.JPanel;
61
import javax.swing.JScrollPane;
68
import javax.swing.JScrollPane;
Line 65... Line 72...
65
import javax.swing.event.DocumentEvent;
72
import javax.swing.event.DocumentEvent;
66
import javax.swing.event.DocumentListener;
73
import javax.swing.event.DocumentListener;
67
import javax.swing.event.TableModelEvent;
74
import javax.swing.event.TableModelEvent;
68
import javax.swing.event.TableModelListener;
75
import javax.swing.event.TableModelListener;
69
 
76
 
-
 
77
import org.apache.commons.dbutils.handlers.ArrayListHandler;
-
 
78
 
70
public class CommandeClientSQLComponent extends TransfertBaseSQLComponent {
79
public class CommandeClientSQLComponent extends TransfertBaseSQLComponent {
71
 
80
 
72
    private CommandeClientItemTable table;
81
    private CommandeClientItemTable table;
73
    private JUniqueTextField numeroUniqueCommande;
82
    private JUniqueTextField numeroUniqueCommande;
74
    private final SQLTable tableNum = getTable().getBase().getTable("NUMEROTATION_AUTO");
83
    private final SQLTable tableNum = getTable().getBase().getTable("NUMEROTATION_AUTO");
Line 407... Line 416...
407
        // on verifie qu'un devis du meme numero n'a pas été inséré entre temps
416
        // on verifie qu'un devis du meme numero n'a pas été inséré entre temps
408
        if (this.numeroUniqueCommande.checkValidation()) {
417
        if (this.numeroUniqueCommande.checkValidation()) {
409
 
418
 
410
            idCommande = super.insert(order);
419
            idCommande = super.insert(order);
411
            this.table.updateField("ID_COMMANDE_CLIENT", idCommande);
420
            this.table.updateField("ID_COMMANDE_CLIENT", idCommande);
-
 
421
            try {
-
 
422
                updateStock(idCommande);
-
 
423
            } catch (SQLException e1) {
-
 
424
                ExceptionHandler.handle("Erreur lors de la mise à du stock!", e1);
412
 
425
            }
413
            // Création des articles
426
            // Création des articles
414
            this.table.createArticle(idCommande, this.getElement());
427
            this.table.createArticle(idCommande, this.getElement());
415
            // generation du document
428
            // generation du document
416
 
429
 
417
            try {
430
            try {
Line 484... Line 497...
484
                frame.getPanel().setAlwaysVisible(true);
497
                frame.getPanel().setAlwaysVisible(true);
485
            }
498
            }
486
            return;
499
            return;
487
        }
500
        }
488
        super.update();
501
        super.update();
-
 
502
        final int id = getSelectedID();
489
        this.table.updateField("ID_COMMANDE_CLIENT", getSelectedID());
503
        this.table.updateField("ID_COMMANDE_CLIENT", id);
490
        this.table.createArticle(getSelectedID(), this.getElement());
504
        this.table.createArticle(id, this.getElement());
491
 
505
 
-
 
506
        final SQLRow row = getTable().getRow(id);
-
 
507
        try {
492
        // generation du document
508
            updateStock(id);
-
 
509
        } catch (SQLException e1) {
-
 
510
            ExceptionHandler.handle("Erreur lors de la mise à du stock!", e1);
-
 
511
        }
493
 
512
 
-
 
513
        // generation du document
494
        try {
514
        try {
495
            CommandeClientXmlSheet sheet = new CommandeClientXmlSheet(getTable().getRow(getSelectedID()));
515
            CommandeClientXmlSheet sheet = new CommandeClientXmlSheet(row);
496
            sheet.createDocumentAsynchronous();
516
            sheet.createDocumentAsynchronous();
497
            sheet.showPrintAndExportAsynchronous(CommandeClientSQLComponent.this.panelOO.isVisualisationSelected(), CommandeClientSQLComponent.this.panelOO.isImpressionSelected(), true);
517
            sheet.showPrintAndExportAsynchronous(CommandeClientSQLComponent.this.panelOO.isVisualisationSelected(), CommandeClientSQLComponent.this.panelOO.isImpressionSelected(), true);
498
        } catch (Exception e) {
518
        } catch (Exception e) {
499
            ExceptionHandler.handle("Impossible de créer la commande", e);
519
            ExceptionHandler.handle("Impossible de créer la commande", e);
500
        }
520
        }
501
 
521
 
502
    }
522
    }
503
 
523
 
-
 
524
    protected String getLibelleStock(SQLRowAccessor row, SQLRowAccessor rowElt) {
-
 
525
        return "Commande client N°" + row.getString("NUMERO");
-
 
526
    }
-
 
527
 
-
 
528
    /**
-
 
529
     * Mise à jour des stocks pour chaque article composant la facture
-
 
530
     * 
-
 
531
     * @throws SQLException
-
 
532
     */
-
 
533
    private void updateStock(int id) throws SQLException {
-
 
534
 
-
 
535
        SQLRow row = getTable().getRow(id);
-
 
536
        StockItemsUpdater stockUpdater = new StockItemsUpdater(new StockLabel() {
-
 
537
            @Override
-
 
538
            public String getLabel(SQLRowAccessor rowOrigin, SQLRowAccessor rowElt) {
-
 
539
                return getLibelleStock(rowOrigin, rowElt);
-
 
540
            }
-
 
541
        }, row, row.getReferentRows(getTable().getTable("COMMANDE_CLIENT_ELEMENT")), Type.VIRTUAL_DELIVER);
-
 
542
 
-
 
543
        stockUpdater.update();
-
 
544
    }
-
 
545
 
504
    public void setDefaults() {
546
    public void setDefaults() {
505
        this.resetValue();
547
        this.resetValue();
506
        this.numeroUniqueCommande.setText(NumerotationAutoSQLElement.getNextNumero(CommandeClientSQLElement.class, new Date()));
548
        this.numeroUniqueCommande.setText(NumerotationAutoSQLElement.getNextNumero(CommandeClientSQLElement.class, new Date()));
507
        this.table.getModel().clearRows();
549
        this.table.getModel().clearRows();
508
    }
550
    }