OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 142 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 142 Rev 156
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.tax.element;
14
 package org.openconcerto.erp.core.finance.tax.element;
15
 
15
 
16
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
16
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
17
import org.openconcerto.erp.model.ISQLCompteSelector;
17
import org.openconcerto.erp.model.ISQLCompteSelector;
18
import org.openconcerto.sql.element.BaseSQLComponent;
18
import org.openconcerto.sql.element.BaseSQLComponent;
19
import org.openconcerto.sql.element.SQLComponent;
19
import org.openconcerto.sql.element.SQLComponent;
20
import org.openconcerto.sql.model.SQLDataSource;
20
import org.openconcerto.sql.model.SQLDataSource;
21
import org.openconcerto.sql.model.SQLRowAccessor;
21
import org.openconcerto.sql.model.SQLRowAccessor;
22
import org.openconcerto.sql.model.Where;
22
import org.openconcerto.sql.model.Where;
23
import org.openconcerto.sql.request.UpdateBuilder;
23
import org.openconcerto.sql.request.UpdateBuilder;
24
import org.openconcerto.sql.utils.SQLUtils;
24
import org.openconcerto.sql.utils.SQLUtils;
25
import org.openconcerto.sql.view.list.IListe;
25
import org.openconcerto.sql.view.list.IListe;
26
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
26
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
27
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
27
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
28
import org.openconcerto.ui.DefaultGridBagConstraints;
28
import org.openconcerto.ui.DefaultGridBagConstraints;
29
import org.openconcerto.utils.ProductInfo;
29
import org.openconcerto.utils.ProductInfo;
30
 
30
 
31
import java.awt.GridBagConstraints;
31
import java.awt.GridBagConstraints;
32
import java.awt.GridBagLayout;
32
import java.awt.GridBagLayout;
33
import java.awt.event.ActionEvent;
33
import java.awt.event.ActionEvent;
34
import java.sql.SQLException;
34
import java.sql.SQLException;
35
import java.util.ArrayList;
35
import java.util.ArrayList;
36
import java.util.List;
36
import java.util.List;
37
 
37
 
38
import javax.swing.AbstractAction;
38
import javax.swing.AbstractAction;
39
import javax.swing.JLabel;
39
import javax.swing.JLabel;
40
import javax.swing.JOptionPane;
40
import javax.swing.JOptionPane;
41
import javax.swing.JPanel;
41
import javax.swing.JPanel;
42
import javax.swing.JTextField;
42
import javax.swing.JTextField;
43
import javax.swing.SwingConstants;
43
import javax.swing.SwingConstants;
44
 
44
 
45
public class TaxeSQLElement extends ComptaSQLConfElement {
45
public class TaxeSQLElement extends ComptaSQLConfElement {
46
 
46
 
47
    public TaxeSQLElement() {
47
    public TaxeSQLElement() {
48
        super("TAXE", "une taxe", "taxes");
48
        super("TAXE", "une taxe", "taxes");
49
 
49
 
50
        PredicateRowAction action = new PredicateRowAction(new AbstractAction("Définir par défaut") {
50
        PredicateRowAction action = new PredicateRowAction(new AbstractAction("Définir par défaut") {
51
 
51
 
52
            @Override
52
            @Override
53
            public void actionPerformed(ActionEvent e) {
53
            public void actionPerformed(ActionEvent e) {
54
 
54
 
55
                final SQLRowAccessor row = IListe.get(e).getSelectedRow();
55
                final SQLRowAccessor row = IListe.get(e).getSelectedRow();
56
                final SQLDataSource ds = row.getTable().getDBSystemRoot().getDataSource();
56
                final SQLDataSource ds = row.getTable().getDBSystemRoot().getDataSource();
57
 
57
 
58
                try {
58
                try {
59
                    SQLUtils.executeAtomic(ds, new SQLUtils.SQLFactory<Object>() {
59
                    SQLUtils.executeAtomic(ds, new SQLUtils.SQLFactory<Object>() {
60
                        @Override
60
                        @Override
61
                        public Object create() throws SQLException {
61
                        public Object create() throws SQLException {
62
                            // Transaction
62
                            // Transaction
63
                            UpdateBuilder upRemoveDefault = new UpdateBuilder(row.getTable());
63
                            UpdateBuilder upRemoveDefault = new UpdateBuilder(row.getTable());
64
                            upRemoveDefault.set("DEFAULT", "FALSE");
64
                            upRemoveDefault.set("DEFAULT", "FALSE");
65
 
65
 
66
                            ds.execute(upRemoveDefault.asString());
66
                            ds.execute(upRemoveDefault.asString());
67
 
67
 
68
                            UpdateBuilder upSetDefault = new UpdateBuilder(row.getTable());
68
                            UpdateBuilder upSetDefault = new UpdateBuilder(row.getTable());
69
                            upSetDefault.set("DEFAULT", "TRUE");
69
                            upSetDefault.set("DEFAULT", "TRUE");
70
                            upSetDefault.setWhere(new Where(row.getTable().getKey(), "=", row.getID()));
70
                            upSetDefault.setWhere(new Where(row.getTable().getKey(), "=", row.getID()));
71
 
71
 
72
                            ds.execute(upSetDefault.asString());
72
                            ds.execute(upSetDefault.asString());
73
 
73
 
74
                            JOptionPane.showMessageDialog(null, "Rédémarrez " + ProductInfo.getInstance().getName() + " pour valider le changement de TVA par défaut.");
74
                            JOptionPane.showMessageDialog(null, "Rédémarrez " + ProductInfo.getInstance().getName() + " pour valider le changement de TVA par défaut.");
75
 
75
 
76
                            return null;
76
                            return null;
77
                        }
77
                        }
78
                    });
78
                    });
79
                } catch (Exception ex) {
79
                } catch (Exception ex) {
80
                    throw new IllegalStateException("Erreur lors d'affectation de la nouvelle TVA par défaut", ex);
80
                    throw new IllegalStateException("Erreur lors d'affectation de la nouvelle TVA par défaut", ex);
81
                }
81
                }
82
 
82
 
83
            }
83
            }
84
        }, true);
84
        }, true);
85
        action.setPredicate(IListeEvent.getSingleSelectionPredicate());
85
        action.setPredicate(IListeEvent.getSingleSelectionPredicate());
86
 
86
 
87
        this.getRowActions().add(action);
87
        this.getRowActions().add(action);
88
 
88
 
89
    }
89
    }
90
 
90
 
91
    protected List<String> getListFields() {
91
    protected List<String> getListFields() {
92
        final List<String> l = new ArrayList<String>();
92
        final List<String> l = new ArrayList<String>();
93
        l.add("NOM");
93
        l.add("NOM");
94
        l.add("TAUX");
94
        l.add("TAUX");
95
        l.add("DEFAULT");
95
        l.add("DEFAULT");
96
        return l;
96
        return l;
97
    }
97
    }
98
 
98
 
99
    protected List<String> getComboFields() {
99
    protected List<String> getComboFields() {
100
        final List<String> l = new ArrayList<String>();
100
        final List<String> l = new ArrayList<String>();
101
        l.add("NOM");
101
        l.add("NOM");
102
        return l;
102
        return l;
103
    }
103
    }
104
 
104
 
105
    public SQLComponent createComponent() {
105
    public SQLComponent createComponent() {
106
        return new BaseSQLComponent(this) {
106
        return new BaseSQLComponent(this) {
107
 
107
 
108
            @Override
108
            @Override
109
            protected void addViews() {
109
            protected void addViews() {
110
 
110
 
111
                this.setLayout(new GridBagLayout());
111
                this.setLayout(new GridBagLayout());
112
                GridBagConstraints c = new DefaultGridBagConstraints();
112
                GridBagConstraints c = new DefaultGridBagConstraints();
113
                JLabel labelNom = new JLabel(getLabelFor("NOM"), SwingConstants.RIGHT);
113
                JLabel labelNom = new JLabel(getLabelFor("NOM"), SwingConstants.RIGHT);
114
 
114
 
115
                this.add(labelNom, c);
115
                this.add(labelNom, c);
116
                c.gridx++;
116
                c.gridx++;
117
                c.weightx = 1;
117
                c.weightx = 1;
118
                c.fill = GridBagConstraints.NONE;
118
                c.fill = GridBagConstraints.NONE;
119
                JTextField fieldNom = new JTextField(40);
119
                JTextField fieldNom = new JTextField(40);
120
                DefaultGridBagConstraints.lockMinimumSize(fieldNom);
120
                DefaultGridBagConstraints.lockMinimumSize(fieldNom);
121
                this.add(fieldNom, c);
121
                this.add(fieldNom, c);
122
                c.gridx = 0;
122
                c.gridx = 0;
123
                c.gridy++;
123
                c.gridy++;
124
                c.weightx = 0;
124
                c.weightx = 0;
125
                c.fill = GridBagConstraints.HORIZONTAL;
125
                c.fill = GridBagConstraints.HORIZONTAL;
126
                JLabel labelTaux = new JLabel(getLabelFor("TAUX"), SwingConstants.RIGHT);
126
                JLabel labelTaux = new JLabel(getLabelFor("TAUX"), SwingConstants.RIGHT);
127
                this.add(labelTaux, c);
127
                this.add(labelTaux, c);
128
                c.gridx++;
128
                c.gridx++;
129
                c.fill = GridBagConstraints.NONE;
129
                c.fill = GridBagConstraints.NONE;
130
                JTextField fieldTaux = new JTextField(6);
130
                JTextField fieldTaux = new JTextField(6);
131
                DefaultGridBagConstraints.lockMinimumSize(fieldTaux);
131
                DefaultGridBagConstraints.lockMinimumSize(fieldTaux);
132
                this.add(fieldTaux, c);
132
                this.add(fieldTaux, c);
133
 
133
 
134
                JLabel labelCompteCol = new JLabel(getLabelFor("ID_COMPTE_PCE_COLLECTE"), SwingConstants.RIGHT);
134
                JLabel labelCompteCol = new JLabel(getLabelFor("ID_COMPTE_PCE_COLLECTE"), SwingConstants.RIGHT);
135
                c.fill = GridBagConstraints.HORIZONTAL;
135
                c.fill = GridBagConstraints.HORIZONTAL;
136
                c.gridx = 0;
136
                c.gridx = 0;
137
                c.gridy++;
137
                c.gridy++;
138
                this.add(labelCompteCol, c);
138
                this.add(labelCompteCol, c);
139
                c.gridx++;
139
                c.gridx++;
140
                c.weightx = 1;
140
                c.weightx = 1;
141
                c.gridwidth = GridBagConstraints.REMAINDER;
141
                c.gridwidth = GridBagConstraints.REMAINDER;
142
                ISQLCompteSelector compteCol = new ISQLCompteSelector();
142
                ISQLCompteSelector compteCol = new ISQLCompteSelector();
143
                this.add(compteCol, c);
143
                this.add(compteCol, c);
144
 
144
 
145
                JLabel labelCompteDed = new JLabel(getLabelFor("ID_COMPTE_PCE_DED"), SwingConstants.RIGHT);
145
                JLabel labelCompteDed = new JLabel(getLabelFor("ID_COMPTE_PCE_DED"), SwingConstants.RIGHT);
146
                c.gridx = 0;
146
                c.gridx = 0;
147
                c.gridy++;
147
                c.gridy++;
148
                c.weightx = 0;
148
                c.weightx = 0;
149
                c.gridwidth = 1;
149
                c.gridwidth = 1;
150
                c.fill = GridBagConstraints.HORIZONTAL;
150
                c.fill = GridBagConstraints.HORIZONTAL;
151
                this.add(labelCompteDed, c);
151
                this.add(labelCompteDed, c);
152
                c.gridx++;
152
                c.gridx++;
153
                c.weightx = 1;
153
                c.weightx = 1;
154
 
154
 
155
                c.gridwidth = GridBagConstraints.REMAINDER;
155
                c.gridwidth = GridBagConstraints.REMAINDER;
156
                ISQLCompteSelector compteDed = new ISQLCompteSelector();
156
                ISQLCompteSelector compteDed = new ISQLCompteSelector();
157
                this.add(compteDed, c);
157
                this.add(compteDed, c);
158
 
158
 
159
                JLabel labelCompteVente = new JLabel(getLabelFor("ID_COMPTE_PCE_VENTE"), SwingConstants.RIGHT);
159
                JLabel labelCompteVente = new JLabel(getLabelFor("ID_COMPTE_PCE_VENTE"), SwingConstants.RIGHT);
160
                c.fill = GridBagConstraints.HORIZONTAL;
160
                c.fill = GridBagConstraints.HORIZONTAL;
161
                c.gridwidth = 1;
161
                c.gridwidth = 1;
162
                c.gridx = 0;
162
                c.gridx = 0;
163
                c.gridy++;
163
                c.gridy++;
164
                this.add(labelCompteVente, c);
164
                this.add(labelCompteVente, c);
165
                c.gridx++;
165
                c.gridx++;
166
                c.weightx = 1;
166
                c.weightx = 1;
167
                c.gridwidth = GridBagConstraints.REMAINDER;
167
                c.gridwidth = GridBagConstraints.REMAINDER;
168
                ISQLCompteSelector compteVente = new ISQLCompteSelector();
168
                ISQLCompteSelector compteVente = new ISQLCompteSelector();
169
                this.add(compteVente, c);
169
                this.add(compteVente, c);
170
 
170
 
171
                JLabel labelCompteVenteS = new JLabel(getLabelFor("ID_COMPTE_PCE_VENTE_SERVICE"), SwingConstants.RIGHT);
171
                JLabel labelCompteVenteS = new JLabel(getLabelFor("ID_COMPTE_PCE_VENTE_SERVICE"), SwingConstants.RIGHT);
172
                c.gridx = 0;
172
                c.gridx = 0;
173
                c.gridy++;
173
                c.gridy++;
174
                c.weightx = 0;
174
                c.weightx = 0;
175
                c.gridwidth = 1;
175
                c.gridwidth = 1;
176
                c.fill = GridBagConstraints.HORIZONTAL;
176
                c.fill = GridBagConstraints.HORIZONTAL;
177
                this.add(labelCompteVenteS, c);
177
                this.add(labelCompteVenteS, c);
178
                c.gridx++;
178
                c.gridx++;
179
                c.weightx = 1;
179
                c.weightx = 1;
180
 
180
 
181
                c.gridwidth = GridBagConstraints.REMAINDER;
181
                c.gridwidth = GridBagConstraints.REMAINDER;
182
                ISQLCompteSelector compteVenteS = new ISQLCompteSelector();
182
                ISQLCompteSelector compteVenteS = new ISQLCompteSelector();
183
                this.add(compteVenteS, c);
183
                this.add(compteVenteS, c);
184
 
184
 
185
                JLabel labelCompteColIntra = new JLabel(getLabelFor("ID_COMPTE_PCE_COLLECTE_INTRA"), SwingConstants.RIGHT);
185
                JLabel labelCompteColIntra = new JLabel(getLabelFor("ID_COMPTE_PCE_COLLECTE_INTRA"), SwingConstants.RIGHT);
186
                c.fill = GridBagConstraints.HORIZONTAL;
186
                c.fill = GridBagConstraints.HORIZONTAL;
187
                c.gridx = 0;
187
                c.gridx = 0;
188
                c.gridy++;
188
                c.gridy++;
-
 
189
                c.gridwidth = 1;
-
 
190
                c.weightx = 0;
189
                this.add(labelCompteColIntra, c);
191
                this.add(labelCompteColIntra, c);
190
                c.gridx++;
192
                c.gridx++;
191
                c.weightx = 1;
193
                c.weightx = 1;
192
                c.gridwidth = GridBagConstraints.REMAINDER;
194
                c.gridwidth = GridBagConstraints.REMAINDER;
193
                ISQLCompteSelector compteColIntra = new ISQLCompteSelector();
195
                ISQLCompteSelector compteColIntra = new ISQLCompteSelector();
194
                this.add(compteColIntra, c);
196
                this.add(compteColIntra, c);
195
 
197
 
196
                JLabel labelCompteDedIntra = new JLabel(getLabelFor("ID_COMPTE_PCE_DED_INTRA"), SwingConstants.RIGHT);
198
                JLabel labelCompteDedIntra = new JLabel(getLabelFor("ID_COMPTE_PCE_DED_INTRA"), SwingConstants.RIGHT);
197
                c.gridx = 0;
199
                c.gridx = 0;
198
                c.gridy++;
200
                c.gridy++;
199
                c.weightx = 0;
201
                c.weightx = 0;
200
                c.gridwidth = 1;
202
                c.gridwidth = 1;
201
                c.fill = GridBagConstraints.HORIZONTAL;
203
                c.fill = GridBagConstraints.HORIZONTAL;
202
                this.add(labelCompteDedIntra, c);
204
                this.add(labelCompteDedIntra, c);
203
                c.gridx++;
205
                c.gridx++;
204
                c.weightx = 1;
206
                c.weightx = 1;
205
 
207
 
206
                c.gridwidth = GridBagConstraints.REMAINDER;
208
                c.gridwidth = GridBagConstraints.REMAINDER;
207
                ISQLCompteSelector compteDedIntra = new ISQLCompteSelector();
209
                ISQLCompteSelector compteDedIntra = new ISQLCompteSelector();
208
                this.add(compteDedIntra, c);
210
                this.add(compteDedIntra, c);
209
 
211
 
210
                // Spacer
212
                // Spacer
211
                c.gridy++;
213
                c.gridy++;
212
                c.weighty = 1;
214
                c.weighty = 1;
213
                c.anchor = GridBagConstraints.NORTHWEST;
215
                c.anchor = GridBagConstraints.NORTHWEST;
214
                this.add(new JPanel(), c);
216
                this.add(new JPanel(), c);
215
 
217
 
216
                this.addSQLObject(compteCol, "ID_COMPTE_PCE_COLLECTE");
218
                this.addSQLObject(compteCol, "ID_COMPTE_PCE_COLLECTE");
217
                this.addSQLObject(compteDed, "ID_COMPTE_PCE_DED");
219
                this.addSQLObject(compteDed, "ID_COMPTE_PCE_DED");
218
                this.addSQLObject(compteVente, "ID_COMPTE_PCE_VENTE");
220
                this.addSQLObject(compteVente, "ID_COMPTE_PCE_VENTE");
219
                this.addSQLObject(compteVenteS, "ID_COMPTE_PCE_VENTE_SERVICE");
221
                this.addSQLObject(compteVenteS, "ID_COMPTE_PCE_VENTE_SERVICE");
220
                this.addSQLObject(compteColIntra, "ID_COMPTE_PCE_COLLECTE_INTRA");
222
                this.addSQLObject(compteColIntra, "ID_COMPTE_PCE_COLLECTE_INTRA");
221
                this.addSQLObject(compteDedIntra, "ID_COMPTE_PCE_DED_INTRA");
223
                this.addSQLObject(compteDedIntra, "ID_COMPTE_PCE_DED_INTRA");
222
 
224
 
223
                this.addRequiredSQLObject(fieldNom, "NOM");
225
                this.addRequiredSQLObject(fieldNom, "NOM");
224
                this.addRequiredSQLObject(fieldTaux, "TAUX");
226
                this.addRequiredSQLObject(fieldTaux, "TAUX");
225
            }
227
            }
226
        };
228
        };
227
    }
229
    }
228
 
230
 
-
 
231
    @Override
-
 
232
    protected String createCode() {
-
 
233
        return "finance.tax";
-
 
234
    }
229
}
235
}