OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 156 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 156 Rev 182
Line 1... Line 1...
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-2019 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.
Line 12... Line 12...
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.core.sales.product.element.TaxeCatComptableSQLElement;
-
 
18
import org.openconcerto.erp.core.sales.product.ui.TaxeCategorieComptableTable;
17
import org.openconcerto.erp.model.ISQLCompteSelector;
19
import org.openconcerto.erp.model.ISQLCompteSelector;
-
 
20
import org.openconcerto.sql.Configuration;
18
import org.openconcerto.sql.element.BaseSQLComponent;
21
import org.openconcerto.sql.element.BaseSQLComponent;
19
import org.openconcerto.sql.element.SQLComponent;
22
import org.openconcerto.sql.element.SQLComponent;
20
import org.openconcerto.sql.model.SQLDataSource;
23
import org.openconcerto.sql.model.SQLDataSource;
-
 
24
import org.openconcerto.sql.model.SQLRow;
21
import org.openconcerto.sql.model.SQLRowAccessor;
25
import org.openconcerto.sql.model.SQLRowAccessor;
-
 
26
import org.openconcerto.sql.model.SQLRowValues;
22
import org.openconcerto.sql.model.Where;
27
import org.openconcerto.sql.model.Where;
23
import org.openconcerto.sql.request.UpdateBuilder;
28
import org.openconcerto.sql.request.UpdateBuilder;
-
 
29
import org.openconcerto.sql.sqlobject.ElementComboBox;
24
import org.openconcerto.sql.utils.SQLUtils;
30
import org.openconcerto.sql.utils.SQLUtils;
25
import org.openconcerto.sql.view.list.IListe;
31
import org.openconcerto.sql.view.list.IListe;
26
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
32
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
27
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
33
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
28
import org.openconcerto.ui.DefaultGridBagConstraints;
34
import org.openconcerto.ui.DefaultGridBagConstraints;
29
import org.openconcerto.utils.ProductInfo;
35
import org.openconcerto.utils.ProductInfo;
30
 
36
 
31
import java.awt.GridBagConstraints;
37
import java.awt.GridBagConstraints;
32
import java.awt.GridBagLayout;
38
import java.awt.GridBagLayout;
33
import java.awt.event.ActionEvent;
39
import java.awt.event.ActionEvent;
-
 
40
import java.awt.event.ActionListener;
34
import java.sql.SQLException;
41
import java.sql.SQLException;
35
import java.util.ArrayList;
42
import java.util.ArrayList;
36
import java.util.List;
43
import java.util.List;
37
 
44
 
38
import javax.swing.AbstractAction;
45
import javax.swing.AbstractAction;
-
 
46
import javax.swing.JButton;
39
import javax.swing.JLabel;
47
import javax.swing.JLabel;
40
import javax.swing.JOptionPane;
48
import javax.swing.JOptionPane;
41
import javax.swing.JPanel;
49
import javax.swing.JPanel;
42
import javax.swing.JTextField;
50
import javax.swing.JTextField;
43
import javax.swing.SwingConstants;
51
import javax.swing.SwingConstants;
Line 103... Line 111...
103
    }
111
    }
104
 
112
 
105
    public SQLComponent createComponent() {
113
    public SQLComponent createComponent() {
106
        return new BaseSQLComponent(this) {
114
        return new BaseSQLComponent(this) {
107
 
115
 
-
 
116
            TaxeCategorieComptableTable tableCatComptable = new TaxeCategorieComptableTable(getElement().getDirectory().getElement(TaxeCatComptableSQLElement.class));
-
 
117
 
108
            @Override
118
            @Override
109
            protected void addViews() {
119
            protected void addViews() {
110
 
120
 
111
                this.setLayout(new GridBagLayout());
121
                this.setLayout(new GridBagLayout());
112
                GridBagConstraints c = new DefaultGridBagConstraints();
122
                GridBagConstraints c = new DefaultGridBagConstraints();
Line 207... Line 217...
207
 
217
 
208
                c.gridwidth = GridBagConstraints.REMAINDER;
218
                c.gridwidth = GridBagConstraints.REMAINDER;
209
                ISQLCompteSelector compteDedIntra = new ISQLCompteSelector();
219
                ISQLCompteSelector compteDedIntra = new ISQLCompteSelector();
210
                this.add(compteDedIntra, c);
220
                this.add(compteDedIntra, c);
211
 
221
 
212
                // Spacer
-
 
213
                c.gridy++;
222
                c.gridy++;
-
 
223
                c.gridx = 0;
214
                c.weighty = 1;
224
                c.weighty = 1;
-
 
225
                c.weightx = 1;
215
                c.anchor = GridBagConstraints.NORTHWEST;
226
                c.fill = GridBagConstraints.BOTH;
-
 
227
                c.gridwidth = GridBagConstraints.REMAINDER;
-
 
228
 
216
                this.add(new JPanel(), c);
229
                this.add(createCategorieComptablePanel(), c);
217
 
230
 
218
                this.addSQLObject(compteCol, "ID_COMPTE_PCE_COLLECTE");
231
                this.addSQLObject(compteCol, "ID_COMPTE_PCE_COLLECTE");
219
                this.addSQLObject(compteDed, "ID_COMPTE_PCE_DED");
232
                this.addSQLObject(compteDed, "ID_COMPTE_PCE_DED");
220
                this.addSQLObject(compteVente, "ID_COMPTE_PCE_VENTE");
233
                this.addSQLObject(compteVente, "ID_COMPTE_PCE_VENTE");
221
                this.addSQLObject(compteVenteS, "ID_COMPTE_PCE_VENTE_SERVICE");
234
                this.addSQLObject(compteVenteS, "ID_COMPTE_PCE_VENTE_SERVICE");
Line 223... Line 236...
223
                this.addSQLObject(compteDedIntra, "ID_COMPTE_PCE_DED_INTRA");
236
                this.addSQLObject(compteDedIntra, "ID_COMPTE_PCE_DED_INTRA");
224
 
237
 
225
                this.addRequiredSQLObject(fieldNom, "NOM");
238
                this.addRequiredSQLObject(fieldNom, "NOM");
226
                this.addRequiredSQLObject(fieldTaux, "TAUX");
239
                this.addRequiredSQLObject(fieldTaux, "TAUX");
227
            }
240
            }
-
 
241
 
-
 
242
            @Override
-
 
243
            public void select(SQLRowAccessor r) {
-
 
244
                super.select(r);
-
 
245
                if (r != null) {
-
 
246
                    this.tableCatComptable.getRowValuesTable().insertFrom(r);
-
 
247
                }
-
 
248
            }
-
 
249
 
-
 
250
            @Override
-
 
251
            public int insert(SQLRow order) {
-
 
252
                int id = super.insert(order);
-
 
253
                this.tableCatComptable.updateField("ID_TAXE", id);
-
 
254
                return id;
-
 
255
            }
-
 
256
 
-
 
257
            @Override
-
 
258
            public void update() {
-
 
259
                super.update();
-
 
260
                this.tableCatComptable.updateField("ID_TAXE", getSelectedID());
-
 
261
            }
-
 
262
 
-
 
263
            protected JPanel createCategorieComptablePanel() {
-
 
264
                JPanel panel = new JPanel(new GridBagLayout());
-
 
265
                panel.setOpaque(false);
-
 
266
                GridBagConstraints c = new DefaultGridBagConstraints();
-
 
267
 
-
 
268
                // Ajout catégorie
-
 
269
                c.gridwidth = 1;
-
 
270
                c.weightx = 0;
-
 
271
                c.gridy++;
-
 
272
                c.gridx = 0;
-
 
273
                panel.add(new JLabel("Ajouter la catégorie "), c);
-
 
274
 
-
 
275
                final ElementComboBox boxCat = new ElementComboBox();
-
 
276
                boxCat.init(getDirectory().getElement("CATEGORIE_COMPTABLE"));
-
 
277
 
-
 
278
                c.gridx++;
-
 
279
                panel.add(boxCat, c);
-
 
280
 
-
 
281
                c.fill = GridBagConstraints.NONE;
-
 
282
                c.gridx++;
-
 
283
                JButton buttonAjouter = new JButton("Ajouter");
-
 
284
                buttonAjouter.setOpaque(false);
-
 
285
                panel.add(buttonAjouter, c);
-
 
286
                c.gridx++;
-
 
287
                JButton buttonSupprimer = new JButton("Supprimer");
-
 
288
                buttonSupprimer.setOpaque(false);
-
 
289
                panel.add(buttonSupprimer, c);
-
 
290
 
-
 
291
                c.gridwidth = GridBagConstraints.REMAINDER;
-
 
292
                c.fill = GridBagConstraints.BOTH;
-
 
293
                c.weightx = 1;
-
 
294
                c.weighty = 1;
-
 
295
                c.gridy++;
-
 
296
                c.gridx = 0;
-
 
297
                c.fill = GridBagConstraints.BOTH;
-
 
298
                this.tableCatComptable.setOpaque(false);
-
 
299
                panel.add(this.tableCatComptable, c);
-
 
300
 
-
 
301
                // Listeners
-
 
302
                buttonAjouter.addActionListener(new ActionListener() {
-
 
303
 
-
 
304
                    @Override
-
 
305
                    public void actionPerformed(ActionEvent e) {
-
 
306
 
-
 
307
                        SQLRow rowCat = boxCat.getSelectedRow();
-
 
308
                        if (rowCat == null || rowCat.isUndefined()) {
-
 
309
                            return;
-
 
310
                        }
-
 
311
                        int nbRows = tableCatComptable.getModel().getRowCount();
-
 
312
 
-
 
313
                        for (int i = 0; i < nbRows; i++) {
-
 
314
                            SQLRowValues rowVals = tableCatComptable.getModel().getRowValuesAt(i);
-
 
315
                            int idTarif = Integer.parseInt(rowVals.getObject("ID_CATEGORIE_COMPTABLE").toString());
-
 
316
                            if (idTarif == rowCat.getID()) {
-
 
317
                                JOptionPane.showMessageDialog(null, "Impossible d'ajouter.\nLa catégorie est déjà présente dans la liste!");
-
 
318
                                return;
-
 
319
                            }
-
 
320
                        }
-
 
321
 
-
 
322
                        SQLRowValues rowVals = new SQLRowValues(Configuration.getInstance().getBase().getTable("TAXE_CATEGORIE_COMPTABLE"));
-
 
323
                        if (getSelectedID() > 1) {
-
 
324
                            rowVals.put("ID_TAXE", getSelectedID());
-
 
325
                        }
-
 
326
                        rowVals.put("ID_CATEGORIE_COMPTABLE", rowCat.getID());
-
 
327
                        tableCatComptable.getModel().addRow(rowVals);
-
 
328
                    }
-
 
329
                });
-
 
330
                buttonSupprimer.addActionListener(new ActionListener() {
-
 
331
 
-
 
332
                    @Override
-
 
333
                    public void actionPerformed(ActionEvent e) {
-
 
334
                        tableCatComptable.removeSelectedRow();
-
 
335
                    }
-
 
336
                });
-
 
337
                return panel;
-
 
338
            }
228
        };
339
        };
229
    }
340
    }
230
 
341
 
231
    @Override
342
    @Override
232
    protected String createCode() {
343
    protected String createCode() {