OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 93 Rev 156
Line 11... Line 11...
11
 * When distributing the software, include this License Header Notice in each file.
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.erp.core.customerrelationship.customer.element;
14
 package org.openconcerto.erp.core.customerrelationship.customer.element;
15
 
15
 
16
import java.awt.Component;
-
 
17
import java.awt.Dimension;
-
 
18
import java.awt.FlowLayout;
-
 
19
import java.awt.GridBagConstraints;
-
 
20
import java.awt.GridBagLayout;
-
 
21
import java.awt.Insets;
-
 
22
import java.awt.event.ActionEvent;
-
 
23
import java.awt.event.ActionListener;
-
 
24
import java.beans.PropertyChangeEvent;
-
 
25
import java.beans.PropertyChangeListener;
-
 
26
import java.sql.SQLException;
-
 
27
import java.text.DecimalFormat;
-
 
28
import java.util.ArrayList;
-
 
29
import java.util.Collections;
-
 
30
import java.util.Comparator;
-
 
31
import java.util.Date;
-
 
32
import java.util.HashMap;
-
 
33
import java.util.List;
-
 
34
import java.util.Map;
-
 
35
import java.util.Set;
-
 
36
 
-
 
37
import javax.swing.ButtonGroup;
-
 
38
import javax.swing.Icon;
-
 
39
import javax.swing.JCheckBox;
-
 
40
import javax.swing.JComponent;
-
 
41
import javax.swing.JLabel;
-
 
42
import javax.swing.JOptionPane;
-
 
43
import javax.swing.JPanel;
-
 
44
import javax.swing.JTabbedPane;
-
 
45
import javax.swing.JTextField;
-
 
46
import javax.swing.SwingConstants;
-
 
47
import javax.swing.event.DocumentEvent;
-
 
48
import javax.swing.event.DocumentListener;
-
 
49
 
-
 
50
import org.openconcerto.erp.config.ComptaPropsConfiguration;
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
-
 
17
import org.openconcerto.erp.core.common.component.AdresseSQLComponent;
51
import org.openconcerto.erp.core.common.element.BanqueSQLElement;
18
import org.openconcerto.erp.core.common.element.BanqueSQLElement;
52
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
19
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
53
import org.openconcerto.erp.core.common.element.NumerotationAutoSQLElement;
20
import org.openconcerto.erp.core.common.element.NumerotationAutoSQLElement;
54
import org.openconcerto.erp.core.common.ui.DeviseField;
21
import org.openconcerto.erp.core.common.ui.DeviseField;
55
import org.openconcerto.erp.core.customerrelationship.customer.ui.AdresseClientItemTable;
22
import org.openconcerto.erp.core.customerrelationship.customer.ui.AdresseClientItemTable;
Line 84... Line 51...
84
import org.openconcerto.ui.TitledSeparator;
51
import org.openconcerto.ui.TitledSeparator;
85
import org.openconcerto.ui.component.ComboLockedMode;
52
import org.openconcerto.ui.component.ComboLockedMode;
86
import org.openconcerto.ui.component.ITextArea;
53
import org.openconcerto.ui.component.ITextArea;
87
import org.openconcerto.ui.component.InteractionMode;
54
import org.openconcerto.ui.component.InteractionMode;
88
 
55
 
-
 
56
import java.awt.Component;
-
 
57
import java.awt.Dimension;
-
 
58
import java.awt.FlowLayout;
-
 
59
import java.awt.GridBagConstraints;
-
 
60
import java.awt.GridBagLayout;
-
 
61
import java.awt.Insets;
-
 
62
import java.awt.event.ActionEvent;
-
 
63
import java.awt.event.ActionListener;
-
 
64
import java.beans.PropertyChangeEvent;
-
 
65
import java.beans.PropertyChangeListener;
-
 
66
import java.sql.SQLException;
-
 
67
import java.text.DecimalFormat;
-
 
68
import java.util.ArrayList;
-
 
69
import java.util.Collections;
-
 
70
import java.util.Comparator;
-
 
71
import java.util.Date;
-
 
72
import java.util.HashMap;
-
 
73
import java.util.List;
-
 
74
import java.util.Map;
-
 
75
import java.util.Set;
-
 
76
 
-
 
77
import javax.swing.ButtonGroup;
-
 
78
import javax.swing.Icon;
-
 
79
import javax.swing.JCheckBox;
-
 
80
import javax.swing.JComponent;
-
 
81
import javax.swing.JLabel;
-
 
82
import javax.swing.JOptionPane;
-
 
83
import javax.swing.JPanel;
-
 
84
import javax.swing.JTabbedPane;
-
 
85
import javax.swing.JTextField;
-
 
86
import javax.swing.SwingConstants;
-
 
87
import javax.swing.event.DocumentEvent;
-
 
88
import javax.swing.event.DocumentListener;
-
 
89
 
89
// Client without CTech link (i.e. there's one and only table in the DB)
90
// Client without CTech link (i.e. there's one and only table in the DB)
90
public class ClientNormalSQLComponent extends BaseSQLComponent {
91
public class ClientNormalSQLComponent extends BaseSQLComponent {
91
 
92
 
92
    private int idDefaultCompteClient = 1;
93
    private int idDefaultCompteClient = 1;
93
    private JCheckBox checkAdrLivraison, checkAdrFacturation;
94
    private JCheckBox checkAdrFacturation;
-
 
95
 
94
    private final SQLTable tableNum = getTable().getBase().getTable("NUMEROTATION_AUTO");
96
    private final SQLTable tableNum = getTable().getBase().getTable("NUMEROTATION_AUTO");
95
    private ElementComboBox boxPays = null;
97
    private ElementComboBox boxPays = null;
96
    private final ElementComboBox boxTarif = new ElementComboBox();
98
    private final ElementComboBox boxTarif = new ElementComboBox();
97
 
99
 
98
    protected boolean showMdr = true;
100
    protected boolean showMdr = true;
99
 
101
 
100
    private ElementSQLObject componentPrincipale, componentLivraison, componentFacturation;
102
    private ElementSQLObject componentPrincipale, componentFacturation;
101
    private AdresseClientItemTable adresseTable = new AdresseClientItemTable();
103
    private AdresseClientItemTable adresseTable = new AdresseClientItemTable();
102
    private JCheckBox boxGestionAutoCompte;
104
    private JCheckBox boxGestionAutoCompte;
103
    private Map<SQLField, JCheckBox> mapCheckLivraison = new HashMap<SQLField, JCheckBox>();
105
    private Map<SQLField, JCheckBox> mapCheckLivraison = new HashMap<SQLField, JCheckBox>();
104
 
106
 
105
    private JCheckBox boxAffacturage, boxComptant;
107
    private JCheckBox boxAffacturage, boxComptant;
Line 139... Line 141...
139
        this.add(textType, c);
141
        this.add(textType, c);
140
 
142
 
141
        // Code
143
        // Code
142
        JLabel labelCode = new JLabel(getLabelFor("CODE"));
144
        JLabel labelCode = new JLabel(getLabelFor("CODE"));
143
        labelCode.setHorizontalAlignment(SwingConstants.RIGHT);
145
        labelCode.setHorizontalAlignment(SwingConstants.RIGHT);
144
        this.textCode = new JUniqueTextField();
146
        this.textCode = new JUniqueTextField() {
-
 
147
            @Override
-
 
148
            public String getAutoRefreshNumber() {
-
 
149
                if (getMode() == Mode.INSERTION) {
-
 
150
                    return NumerotationAutoSQLElement.getNextNumero(getElement().getClass());
-
 
151
                } else {
-
 
152
                    return null;
-
 
153
                }
-
 
154
            }
-
 
155
        };
145
        c.gridx++;
156
        c.gridx++;
146
        c.weightx = 0;
157
        c.weightx = 0;
147
        c.weighty = 0;
158
        c.weighty = 0;
148
        c.gridwidth = 1;
159
        c.gridwidth = 1;
149
        c.fill = GridBagConstraints.HORIZONTAL;
160
        c.fill = GridBagConstraints.HORIZONTAL;
Line 446... Line 457...
446
        c.gridy++;
457
        c.gridy++;
447
        c.weighty = 0.3;
458
        c.weighty = 0.3;
448
        c.fill = GridBagConstraints.BOTH;
459
        c.fill = GridBagConstraints.BOTH;
449
        this.add(textInfos, c);
460
        this.add(textInfos, c);
450
 
461
 
451
        this.checkAdrLivraison.addActionListener(new ActionListener() {
-
 
452
 
-
 
453
            public void actionPerformed(java.awt.event.ActionEvent e) {
-
 
454
                boolean b = checkAdrLivraison.isSelected();
-
 
455
                componentLivraison.setEditable((!b) ? InteractionMode.READ_WRITE : InteractionMode.DISABLED);
-
 
456
                componentLivraison.setCreated(!b);
-
 
457
            };
-
 
458
        });
-
 
459
 
-
 
460
        this.checkAdrFacturation.addActionListener(new ActionListener() {
462
        this.checkAdrFacturation.addActionListener(new ActionListener() {
461
            public void actionPerformed(ActionEvent e) {
463
            public void actionPerformed(ActionEvent e) {
462
                boolean b = checkAdrFacturation.isSelected();
464
                boolean b = checkAdrFacturation.isSelected();
463
                componentFacturation.setEditable((!b) ? InteractionMode.READ_WRITE : InteractionMode.DISABLED);
465
                componentFacturation.setEditable((!b) ? InteractionMode.READ_WRITE : InteractionMode.DISABLED);
464
                componentFacturation.setCreated(!b);
466
                componentFacturation.setCreated(!b);
Line 477... Line 479...
477
        this.addSQLObject(textNumIntracomm, "NUMERO_TVA");
479
        this.addSQLObject(textNumIntracomm, "NUMERO_TVA");
478
        this.addSQLObject(textResp, "RESPONSABLE");
480
        this.addSQLObject(textResp, "RESPONSABLE");
479
        this.addSQLObject(textInfos, "INFOS");
481
        this.addSQLObject(textInfos, "INFOS");
480
        this.addSQLObject(this.compteSel, "ID_COMPTE_PCE");
482
        this.addSQLObject(this.compteSel, "ID_COMPTE_PCE");
481
 
483
 
482
        this.checkAdrFacturation.setSelected(true);
-
 
483
        this.checkAdrLivraison.setSelected(true);
-
 
484
 
-
 
485
    }
484
    }
486
 
485
 
487
    private Component createAdressesComponent() {
486
    private Component createAdressesComponent() {
488
        final JTabbedPane tabbedAdresse = new JTabbedPane() {
487
        final JTabbedPane tabbedAdresse = new JTabbedPane() {
489
            public void insertTab(String title, Icon icon, Component component, String tip, int index) {
488
            public void insertTab(String title, Icon icon, Component component, String tip, int index) {
Line 499... Line 498...
499
        this.addView("ID_ADRESSE", REQ + ";" + DEC + ";" + SEP);
498
        this.addView("ID_ADRESSE", REQ + ";" + DEC + ";" + SEP);
500
        this.componentPrincipale = (ElementSQLObject) this.getView("ID_ADRESSE");
499
        this.componentPrincipale = (ElementSQLObject) this.getView("ID_ADRESSE");
501
        this.componentPrincipale.setOpaque(false);
500
        this.componentPrincipale.setOpaque(false);
502
        tabbedAdresse.add(getLabelFor("ID_ADRESSE"), this.componentPrincipale);
501
        tabbedAdresse.add(getLabelFor("ID_ADRESSE"), this.componentPrincipale);
503
        tabbedAdresse.setOpaque(false);
502
        tabbedAdresse.setOpaque(false);
-
 
503
 
504
        // Adr facturation
504
        // Adr facturation
505
        JPanel panelFacturation = new JPanel(new GridBagLayout());
505
        JPanel panelFacturation = new JPanel(new GridBagLayout());
506
        panelFacturation.setOpaque(false);
506
        panelFacturation.setOpaque(false);
507
        GridBagConstraints cPanelF = new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(2, 1, 2, 1), 0, 0);
507
        GridBagConstraints cPanelF = new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(2, 1, 2, 1), 0, 0);
508
 
508
 
509
        this.addView("ID_ADRESSE_F", DEC + ";" + SEP);
509
        this.addView("ID_ADRESSE_F", DEC + ";" + SEP);
-
 
510
 
510
        this.componentFacturation = (ElementSQLObject) this.getView("ID_ADRESSE_F");
511
        this.componentFacturation = (ElementSQLObject) this.getView("ID_ADRESSE_F");
511
        this.componentFacturation.setOpaque(false);
512
        this.componentFacturation.setOpaque(false);
512
        this.componentFacturation.setCreatedUIVisible(false);
513
        ((AdresseSQLComponent) componentFacturation.getSQLChild()).setDestinataireVisible(true);
-
 
514
 
513
        panelFacturation.add(this.componentFacturation, cPanelF);
515
        panelFacturation.add(this.componentFacturation, cPanelF);
-
 
516
 
514
        this.checkAdrFacturation = new JCheckBox("Adresse de facturation identique à la principale");
517
        this.checkAdrFacturation = new JCheckBox("Adresse de facturation identique à la principale");
515
        this.checkAdrFacturation.setOpaque(false);
518
        this.checkAdrFacturation.setOpaque(false);
516
        cPanelF.gridy++;
519
        cPanelF.gridy++;
517
        panelFacturation.add(this.checkAdrFacturation, cPanelF);
520
        panelFacturation.add(this.checkAdrFacturation, cPanelF);
518
            tabbedAdresse.add(getLabelFor("ID_ADRESSE_F"), panelFacturation);
521
        tabbedAdresse.add(getLabelFor("ID_ADRESSE_F"), panelFacturation);
-
 
522
 
-
 
523
        this.checkAdrFacturation.addActionListener(new ActionListener() {
-
 
524
 
-
 
525
            public void actionPerformed(java.awt.event.ActionEvent e) {
-
 
526
                boolean b = checkAdrFacturation.isSelected();
-
 
527
 
-
 
528
                componentFacturation.setEditable(!b ? InteractionMode.READ_WRITE : InteractionMode.DISABLED);
-
 
529
                componentFacturation.setCreated(!b);
-
 
530
            }
-
 
531
        });
-
 
532
        checkAdrFacturation.setSelected(true);
-
 
533
 
519
            Set<SQLField> fieldsAdr = getTable().getForeignKeys("ADRESSE");
534
            Set<SQLField> fieldsAdr = getTable().getForeignKeys("ADRESSE");
520
            List<SQLField> fieldsAdrOrder = new ArrayList<SQLField>(fieldsAdr);
535
            List<SQLField> fieldsAdrOrder = new ArrayList<SQLField>(fieldsAdr);
521
            Collections.sort(fieldsAdrOrder, new Comparator<SQLField>() {
536
            Collections.sort(fieldsAdrOrder, new Comparator<SQLField>() {
522
                @Override
537
                @Override
523
                public int compare(SQLField o1, SQLField o2) {
538
                public int compare(SQLField o1, SQLField o2) {
Line 534... Line 549...
534
                    JPanel panelLivraison = new JPanel(new GridBagLayout());
549
                    JPanel panelLivraison = new JPanel(new GridBagLayout());
535
                    panelLivraison.setOpaque(false);
550
                    panelLivraison.setOpaque(false);
536
                    GridBagConstraints cPanelL = new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(2, 1, 2, 1), 0, 0);
551
                    GridBagConstraints cPanelL = new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(2, 1, 2, 1), 0, 0);
537
 
552
 
538
                    this.addView(fieldName, DEC + ";" + SEP);
553
                    this.addView(fieldName, DEC + ";" + SEP);
539
                    this.componentLivraison = (ElementSQLObject) this.getView(fieldName);
-
 
540
                    this.componentLivraison.setOpaque(false);
-
 
541
                    this.componentLivraison.setCreatedUIVisible(false);
-
 
542
 
554
 
-
 
555
                    final ElementSQLObject componentLivraison = (ElementSQLObject) this.getView(fieldName);
-
 
556
                    componentLivraison.setOpaque(false);
-
 
557
                    ((AdresseSQLComponent) componentLivraison.getSQLChild()).setDestinataireVisible(true);
543
                    panelLivraison.add(this.componentLivraison, cPanelL);
558
                    panelLivraison.add(componentLivraison, cPanelL);
544
 
559
 
545
                    checkAdrLivraison = new JCheckBox("Adresse de livraison identique à l'adresse principale");
560
                    final JCheckBox checkAdrLivraison = new JCheckBox("Adresse de livraison identique à l'adresse principale");
546
                    checkAdrLivraison.setOpaque(false);
561
                    checkAdrLivraison.setOpaque(false);
547
                    cPanelL.gridy++;
562
                    cPanelL.gridy++;
548
                    panelLivraison.add(checkAdrLivraison, cPanelL);
563
                    panelLivraison.add(checkAdrLivraison, cPanelL);
549
                    tabbedAdresse.add(getLabelFor(fieldName) + (val == 1 ? "" : " " + val), panelLivraison);
564
                    tabbedAdresse.add(getLabelFor(fieldName) + (val == 1 ? "" : " " + val), panelLivraison);
550
                    val++;
565
                    val++;
551
 
566
 
552
                    checkAdrLivraison.addActionListener(new ActionListener() {
567
                    checkAdrLivraison.addActionListener(new ActionListener() {
553
 
568
 
554
                        public void actionPerformed(java.awt.event.ActionEvent e) {
569
                        public void actionPerformed(java.awt.event.ActionEvent e) {
555
                            boolean b = checkAdrLivraison.isSelected();
570
                            boolean b = checkAdrLivraison.isSelected();
-
 
571
 
556
                            componentLivraison.setEditable((!b) ? InteractionMode.READ_WRITE : InteractionMode.DISABLED);
572
                            componentLivraison.setEditable((!b) ? InteractionMode.READ_WRITE : InteractionMode.DISABLED);
557
                            componentLivraison.setCreated(!b);
573
                            componentLivraison.setCreated(!b);
558
                        }
574
                        }
559
                    });
575
                    });
560
                    checkAdrLivraison.setSelected(true);
576
                    checkAdrLivraison.setSelected(true);
Line 645... Line 661...
645
                public void actionPerformed(ActionEvent e) {
661
                public void actionPerformed(ActionEvent e) {
646
 
662
 
647
                    setCompteVisible(!(boxGestionAutoCompte.isSelected() && getSelectedID() <= 1));
663
                    setCompteVisible(!(boxGestionAutoCompte.isSelected() && getSelectedID() <= 1));
648
                }
664
                }
649
            });
665
            });
-
 
666
 
-
 
667
            c.gridwidth = 1;
-
 
668
            c.gridy++;
-
 
669
            c.gridx = 0;
-
 
670
            c.weightx = 0;
-
 
671
            p.add(new JLabel(getLabelFor("ID_COMPTE_PCE_SERVICE")), c);
-
 
672
 
-
 
673
            c.gridwidth = GridBagConstraints.REMAINDER;
-
 
674
            c.gridx++;
-
 
675
            c.weightx = 1;
-
 
676
            ISQLCompteSelector compteSelService = new ISQLCompteSelector();
-
 
677
            p.add(compteSelService, c);
-
 
678
            this.addView(compteSelService, "ID_COMPTE_PCE_SERVICE");
650
        }
679
        }
-
 
680
 
651
        return p;
681
        return p;
652
    }
682
    }
653
 
683
 
654
    private void setCompteVisible(boolean b) {
684
    private void setCompteVisible(boolean b) {
655
 
685
 
Line 747... Line 777...
747
 
777
 
748
    @Override
778
    @Override
749
    public int insert(SQLRow order) {
779
    public int insert(SQLRow order) {
750
 
780
 
751
        // incrémentation du numéro auto
781
        // incrémentation du numéro auto
752
        if (NumerotationAutoSQLElement.getNextNumero(ClientNormalSQLElement.class, new Date()).equalsIgnoreCase(this.textCode.getText().trim())) {
782
        if (NumerotationAutoSQLElement.getNextNumero(getElement().getClass(), new Date()).equalsIgnoreCase(this.textCode.getText().trim())) {
753
            SQLRowValues rowVals = new SQLRowValues(this.tableNum);
783
            SQLRowValues rowVals = new SQLRowValues(this.tableNum);
-
 
784
 
-
 
785
            final SQLRow rowNumAuto = this.tableNum.getRow(2);
-
 
786
            if (rowNumAuto.getObject("CLIENT_START") != null) {
754
            int val = this.tableNum.getRow(2).getInt("CLIENT_START");
787
                int val = rowNumAuto.getInt("CLIENT_START");
755
            val++;
788
                val++;
756
            rowVals.put("CLIENT_START", new Integer(val));
789
                rowVals.put("CLIENT_START", new Integer(val));
757
 
790
 
758
            try {
791
                try {
759
                rowVals.update(2);
792
                    rowVals.update(2);
760
            } catch (SQLException e) {
793
                } catch (SQLException e) {
761
                e.printStackTrace();
794
                    e.printStackTrace();
762
            }
795
                }
763
        }
796
            }
-
 
797
        }
764
 
798
 
765
        int id = super.insert(order);
799
        int id = super.insert(order);
766
 
800
 
767
        this.table.updateField("ID_CLIENT", id);
801
        this.table.updateField("ID_CLIENT", id);
768
        this.adresseTable.updateField("ID_CLIENT", id);
802
        this.adresseTable.updateField("ID_CLIENT", id);
Line 776... Line 810...
776
    protected SQLRowValues createDefaults() {
810
    protected SQLRowValues createDefaults() {
777
        SQLRowValues vals = new SQLRowValues(this.getTable());
811
        SQLRowValues vals = new SQLRowValues(this.getTable());
778
        SQLRow r;
812
        SQLRow r;
779
 
813
 
780
        vals.put("MARCHE_PUBLIC", Boolean.TRUE);
814
        vals.put("MARCHE_PUBLIC", Boolean.TRUE);
781
        vals.put("CODE", NumerotationAutoSQLElement.getNextNumero(ClientNormalSQLElement.class, new Date()));
815
        vals.put("CODE", NumerotationAutoSQLElement.getNextNumero(getElement().getClass(), new Date()));
782
 
816
 
783
        // Mode de règlement par defaut
817
        // Mode de règlement par defaut
784
        try {
818
        try {
785
            r = ModeReglementDefautPrefPanel.getDefaultRow(true);
819
            r = ModeReglementDefautPrefPanel.getDefaultRow(true);
786
            SQLElement eltModeReglement = Configuration.getInstance().getDirectory().getElement("MODE_REGLEMENT");
820
            SQLElement eltModeReglement = Configuration.getInstance().getDirectory().getElement("MODE_REGLEMENT");