OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev Author Line No. Line
18 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
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
 package org.openconcerto.erp.core.finance.accounting.ui;
15
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
17
import org.openconcerto.erp.core.finance.accounting.element.ComptePCESQLElement;
18
import org.openconcerto.erp.core.finance.accounting.model.PlanComptableEModel;
19
import org.openconcerto.erp.element.objet.Compte;
20
import org.openconcerto.sql.Configuration;
21
import org.openconcerto.sql.element.SQLElement;
22
import org.openconcerto.sql.model.SQLRow;
23
import org.openconcerto.sql.model.SQLTable;
80 ilm 24
import org.openconcerto.sql.model.SQLTableEvent;
18 ilm 25
import org.openconcerto.sql.model.SQLTableListener;
80 ilm 26
import org.openconcerto.sql.model.SQLTableModifiedListener;
18 ilm 27
import org.openconcerto.sql.view.EditFrame;
28
import org.openconcerto.ui.DefaultGridBagConstraints;
29
import org.openconcerto.utils.ExceptionHandler;
30
 
31
import java.awt.Container;
32
import java.awt.GridBagConstraints;
33
import java.awt.GridBagLayout;
34
import java.awt.event.ActionEvent;
35
import java.awt.event.ActionListener;
36
import java.sql.SQLException;
37
import java.util.Vector;
38
 
39
import javax.swing.AbstractAction;
40
import javax.swing.JButton;
41
import javax.swing.JFrame;
42
import javax.swing.JTable;
43
 
44
public class GestionPlanComptableEFrame extends JFrame {
45
 
80 ilm 46
    private JButton boutonAjout = new JButton("Créer un nouveau compte");
18 ilm 47
    private JButton boutonSuppr = new JButton("Supprimer");
80 ilm 48
    private JButton boutonAjoutPCG = new JButton("Ajouter un compte depuis le PCG");
18 ilm 49
    private EditFrame edit = null;
50
    private AjouterComptePCGtoPCEFrame ajoutCptFrame = null;
51
 
52
    private SQLTable compteTable = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete().getTable("COMPTE_PCE");
53
    private PlanComptableEPanel panelPCE;
54
 
55
    public GestionPlanComptableEFrame() {
56
        super("Gérer le plan comptable entreprise");
57
        Container container = this.getContentPane();
58
 
59
        // instanciation du panel et du menu click droit associé
60
        Vector<AbstractAction> actionClickDroitTable = new Vector<AbstractAction>();
61
 
62
        actionClickDroitTable.add(new AbstractAction("Ajouter un compte") {
63
 
64
            public void actionPerformed(ActionEvent e) {
65
                if (GestionPlanComptableEFrame.this.edit == null) {
73 ilm 66
                    GestionPlanComptableEFrame.this.edit = new EditFrame(Configuration.getInstance().getDirectory().getElement("COMPTE_PCE"));
18 ilm 67
                    GestionPlanComptableEFrame.this.edit.pack();
68
                }
69
                GestionPlanComptableEFrame.this.edit.setVisible(true);
70
            }
71
        });
72
 
73
        this.panelPCE = new PlanComptableEPanel(actionClickDroitTable);
74
 
75
        container.setLayout(new GridBagLayout());
76
        final GridBagConstraints c = new DefaultGridBagConstraints();
80 ilm 77
        c.fill = GridBagConstraints.NONE;
18 ilm 78
        container.add(this.boutonAjout, c);
79
 
80
        this.boutonAjout.addActionListener(new ActionListener() {
81
 
82
            public void actionPerformed(ActionEvent e) {
83
                if (GestionPlanComptableEFrame.this.edit == null) {
73 ilm 84
                    GestionPlanComptableEFrame.this.edit = new EditFrame(Configuration.getInstance().getDirectory().getElement("COMPTE_PCE"));
18 ilm 85
                    GestionPlanComptableEFrame.this.edit.pack();
86
                }
87
                GestionPlanComptableEFrame.this.edit.setVisible(true);
88
            }
89
        });
90
 
91
        c.gridx++;
92
        container.add(this.boutonSuppr, c);
93
        this.boutonSuppr.addActionListener(new ActionListener() {
94
            public void actionPerformed(ActionEvent e) {
95
                supprimerCompte();
96
            }
97
        });
98
 
99
        c.gridx++;
80 ilm 100
        container.add(this.boutonAjoutPCG, c);
18 ilm 101
        this.boutonAjoutPCG.addActionListener(new ActionListener() {
102
 
103
            public void actionPerformed(ActionEvent e) {
104
                if (GestionPlanComptableEFrame.this.ajoutCptFrame == null) {
105
                    GestionPlanComptableEFrame.this.ajoutCptFrame = new AjouterComptePCGtoPCEFrame();
106
                    GestionPlanComptableEFrame.this.ajoutCptFrame.pack();
107
                }
108
                GestionPlanComptableEFrame.this.ajoutCptFrame.setVisible(true);
109
            }
110
        });
111
 
112
        c.gridy++;
113
        c.gridx = 0;
114
        c.gridwidth = GridBagConstraints.REMAINDER;
115
        c.fill = GridBagConstraints.BOTH;
116
        c.weightx = 1;
117
        c.weighty = 1;
118
 
119
        container.add(this.panelPCE, c);
120
 
80 ilm 121
        this.compteTable.addTableModifiedListener(new SQLTableModifiedListener() {
18 ilm 122
 
80 ilm 123
            @Override
124
            public void tableModified(SQLTableEvent evt) {
125
                final SQLRow row = evt.getRow();
126
                GestionPlanComptableEFrame.this.panelPCE.fireModificationCompte(new Compte(evt.getId(), row.getString("NUMERO"), row.getString("NOM")));
18 ilm 127
            }
128
        });
129
    }
130
 
131
    private void supprimerCompte() {
132
 
133
        JTable tableTmp = (JTable) (this.panelPCE.getTables().get(this.panelPCE.getSelectedIndex()));
134
 
135
        PlanComptableEModel model = (PlanComptableEModel) tableTmp.getModel();
136
 
137
        int[] selectedRows = tableTmp.getSelectedRows();
138
 
139
        if (selectedRows.length == 0) {
140
            return;
141
        }
142
 
143
        SQLElement eltComptePCE = Configuration.getInstance().getDirectory().getElement("COMPTE_PCE");
144
 
145
        for (int i = 0; i < selectedRows.length; i++) {
146
 
147
            // Numéro du compte à supprimer
148
            // String numero = tableTmp.getValueAt(selectedRows[i], 0).toString();
149
            // int id = ComptePCESQLElement.getId(numero);
150
            int id = model.getId(selectedRows[i]);
151
            try {
152
                eltComptePCE.archive(id);
153
            } catch (SQLException e) {
154
                e.printStackTrace();
156 ilm 155
                ExceptionHandler.handle("Erreur lors de la suppression du compte.", e);
18 ilm 156
            }
157
            System.out.println("Compte Supprimé");
158
        }
159
    }
160
 
161
    public PlanComptableEPanel getPanelPCE() {
162
        return this.panelPCE;
163
    }
164
}