OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 80 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 80 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.accounting.element;
14
 package org.openconcerto.erp.core.finance.accounting.element;
15
 
15
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
17
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
17
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
18
import org.openconcerto.sql.Configuration;
18
import org.openconcerto.sql.Configuration;
19
import org.openconcerto.sql.element.BaseSQLComponent;
19
import org.openconcerto.sql.element.BaseSQLComponent;
20
import org.openconcerto.sql.element.SQLComponent;
20
import org.openconcerto.sql.element.SQLComponent;
21
import org.openconcerto.sql.model.SQLBase;
21
import org.openconcerto.sql.model.SQLBase;
22
import org.openconcerto.sql.model.SQLRowValues;
22
import org.openconcerto.sql.model.SQLRowValues;
23
import org.openconcerto.sql.model.SQLSelect;
23
import org.openconcerto.sql.model.SQLSelect;
24
import org.openconcerto.sql.model.SQLTable;
24
import org.openconcerto.sql.model.SQLTable;
25
import org.openconcerto.sql.model.Where;
25
import org.openconcerto.sql.model.Where;
26
import org.openconcerto.ui.DefaultGridBagConstraints;
26
import org.openconcerto.ui.DefaultGridBagConstraints;
27
 
27
 
28
import java.awt.GridBagConstraints;
28
import java.awt.GridBagConstraints;
29
import java.awt.GridBagLayout;
29
import java.awt.GridBagLayout;
30
import java.util.ArrayList;
30
import java.util.ArrayList;
31
import java.util.List;
31
import java.util.List;
32
 
32
 
33
import javax.swing.JCheckBox;
33
import javax.swing.JCheckBox;
34
import javax.swing.JLabel;
34
import javax.swing.JLabel;
35
import javax.swing.JTextField;
35
import javax.swing.JTextField;
36
import javax.swing.SwingConstants;
36
import javax.swing.SwingConstants;
37
 
37
 
38
import org.apache.commons.dbutils.handlers.ArrayListHandler;
38
import org.apache.commons.dbutils.handlers.ArrayListHandler;
39
 
39
 
40
public class JournalSQLElement extends ComptaSQLConfElement {
40
public class JournalSQLElement extends ComptaSQLConfElement {
41
 
41
 
42
    public static final int ACHATS = 2;
42
    public static final int ACHATS = 2;
43
    public static final int VENTES = 3;
43
    public static final int VENTES = 3;
44
    public static final int OD = 6;
44
    public static final int OD = 6;
45
    public static final int BANQUES = 4;
45
    public static final int BANQUES = 4;
46
    public static final int CAISSES = 5;
46
    public static final int CAISSES = 5;
47
 
47
 
48
    public JournalSQLElement() {
48
    public JournalSQLElement() {
49
        super("JOURNAL", "un journal", "journaux");
49
        super("JOURNAL", "un journal", "journaux");
50
    }
50
    }
51
 
51
 
52
    protected List<String> getListFields() {
52
    protected List<String> getListFields() {
53
        final List<String> list = new ArrayList<String>();
53
        final List<String> list = new ArrayList<String>();
54
        list.add("NOM");
54
        list.add("NOM");
55
        list.add("CODE");
55
        list.add("CODE");
56
        return list;
56
        return list;
57
    }
57
    }
58
 
58
 
59
    protected List<String> getComboFields() {
59
    protected List<String> getComboFields() {
60
        final List<String> list = new ArrayList<String>();
60
        final List<String> list = new ArrayList<String>();
61
        list.add("NOM");
61
        list.add("NOM");
62
        list.add("CODE");
62
        list.add("CODE");
63
        return list;
63
        return list;
64
    }
64
    }
65
 
65
 
66
    public SQLComponent createComponent() {
66
    public SQLComponent createComponent() {
67
        return new BaseSQLComponent(this) {
67
        return new BaseSQLComponent(this) {
68
            public void addViews() {
68
            public void addViews() {
69
                this.setLayout(new GridBagLayout());
69
                this.setLayout(new GridBagLayout());
70
                final GridBagConstraints c = new DefaultGridBagConstraints();
70
                final GridBagConstraints c = new DefaultGridBagConstraints();
71
                this.add(new JLabel(getLabelFor("CODE"), SwingConstants.RIGHT), c);
71
                this.add(new JLabel(getLabelFor("CODE"), SwingConstants.RIGHT), c);
72
                c.gridx++;
72
                c.gridx++;
73
                c.weightx = 1;
73
                c.weightx = 1;
74
                c.fill = GridBagConstraints.NONE;
74
                c.fill = GridBagConstraints.NONE;
75
                final JTextField code = new JTextField(6);
75
                final JTextField code = new JTextField(6);
76
                this.add(code, c);
76
                this.add(code, c);
77
 
77
 
78
                c.gridx = 0;
78
                c.gridx = 0;
79
                c.gridy++;
79
                c.gridy++;
80
                c.fill = GridBagConstraints.HORIZONTAL;
80
                c.fill = GridBagConstraints.HORIZONTAL;
81
                c.weightx = 0;
81
                c.weightx = 0;
82
                this.add(new JLabel(getLabelFor("NOM"), SwingConstants.RIGHT), c);
82
                this.add(new JLabel(getLabelFor("NOM"), SwingConstants.RIGHT), c);
83
                c.gridx++;
83
                c.gridx++;
84
                c.weightx = 1;
84
                c.weightx = 1;
85
                final JTextField nom = new JTextField(25);
85
                final JTextField nom = new JTextField(25);
86
                this.add(nom, c);
86
                this.add(nom, c);
87
                c.gridy++;
87
                c.gridy++;
88
                c.anchor = GridBagConstraints.NORTHWEST;
88
                c.anchor = GridBagConstraints.NORTHWEST;
89
                c.weighty = 1;
89
                c.weighty = 1;
90
                final JCheckBox checkBox = new JCheckBox(getLabelFor("TYPE_BANQUE"));
90
                final JCheckBox checkBox = new JCheckBox(getLabelFor("TYPE_BANQUE"));
91
                this.add(checkBox, c);
91
                this.add(checkBox, c);
92
 
92
 
93
                this.addView(nom, "NOM", REQ);
93
                this.addView(nom, "NOM", REQ);
94
                this.addView(code, "CODE", REQ);
94
                this.addView(code, "CODE", REQ);
95
                this.addView(checkBox, "TYPE_BANQUE");
95
                this.addView(checkBox, "TYPE_BANQUE");
96
            }
96
            }
97
 
97
 
98
            @Override
98
            @Override
99
            protected SQLRowValues createDefaults() {
99
            protected SQLRowValues createDefaults() {
100
                final SQLRowValues rowVals = new SQLRowValues(getTable());
100
                final SQLRowValues rowVals = new SQLRowValues(getTable());
101
                rowVals.put("TYPE_BANQUE", Boolean.TRUE);
101
                rowVals.put("TYPE_BANQUE", Boolean.TRUE);
102
                return rowVals;
102
                return rowVals;
103
            }
103
            }
104
        };
104
        };
105
    }
105
    }
106
 
106
 
107
    public static int getIdJournal(final String nom) {
107
    public static int getIdJournal(final String nom) {
108
        final SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
108
        final SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
109
        final SQLTable journalTable = base.getTable("JOURNAL");
109
        final SQLTable journalTable = base.getTable("JOURNAL");
110
        final SQLSelect selJrnl = new SQLSelect();
110
        final SQLSelect selJrnl = new SQLSelect();
111
        selJrnl.addSelect(journalTable.getField("ID"));
111
        selJrnl.addSelect(journalTable.getField("ID"));
112
        selJrnl.setWhere(new Where(journalTable.getField("NOM"), "=", nom.trim()));
112
        selJrnl.setWhere(new Where(journalTable.getField("NOM"), "=", nom.trim()));
113
 
113
 
114
        @SuppressWarnings("unchecked")
114
        @SuppressWarnings("unchecked")
115
        final List<Object[]> myListJrnl = (List<Object[]>) base.getDataSource().execute(selJrnl.asString(), new ArrayListHandler());
115
        final List<Object[]> myListJrnl = (List<Object[]>) base.getDataSource().execute(selJrnl.asString(), new ArrayListHandler());
116
 
116
 
117
        if (myListJrnl.size() != 0) {
117
        if (myListJrnl.size() != 0) {
118
            return Integer.parseInt(myListJrnl.get(0)[0].toString());
118
            return Integer.parseInt(myListJrnl.get(0)[0].toString());
119
        } else {
119
        } else {
120
            return -1;
120
            return -1;
121
        }
121
        }
122
    }
122
    }
123
 
123
 
124
    @Override
124
    @Override
125
    protected String createCode() {
125
    protected String createCode() {
126
        return createCodeFromPackage() + ".book";
126
        return createCodeOfPackage() + ".book";
127
    }
127
    }
128
}
128
}