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