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