OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 73 | Go to most recent revision | Details | 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.accounting.ui;
15
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
17
import org.openconcerto.erp.core.finance.accounting.element.ComptePCESQLElement;
18
import org.openconcerto.erp.model.ISQLCompteSelector;
19
import org.openconcerto.sql.Configuration;
20
import org.openconcerto.sql.model.SQLBase;
21
import org.openconcerto.sql.model.SQLRow;
22
import org.openconcerto.sql.model.SQLRowValues;
23
import org.openconcerto.sql.model.SQLTable;
24
import org.openconcerto.ui.DefaultGridBagConstraints;
25
import org.openconcerto.ui.TitledSeparator;
26
import org.openconcerto.ui.preferences.DefaultPreferencePanel;
27
 
28
import java.awt.GridBagConstraints;
29
import java.awt.GridBagLayout;
30
import java.awt.Insets;
31
import java.sql.SQLException;
32
 
33
import javax.swing.JLabel;
34
import javax.swing.JPanel;
35
 
36
public class ComptePayePreferencePanel extends DefaultPreferencePanel {
37
    private ISQLCompteSelector selCompteAcompte, selCompteAcompteReglement, selCompteRemunPers;
38
    private final static SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
39
    private static final SQLTable tablePrefCompte = base.getTable("PREFS_COMPTE");
40
    private SQLRowValues rowPrefCompteVals = new SQLRowValues(tablePrefCompte);
41
 
42
    public ComptePayePreferencePanel() {
43
        super();
44
 
45
        final SQLRow rowPrefCompte = tablePrefCompte.getRow(2);
46
        this.rowPrefCompteVals.loadAbsolutelyAll(rowPrefCompte);
47
 
48
        final Insets separatorInsets = new Insets(10, 2, 1, 2);
49
 
50
        this.setLayout(new GridBagLayout());
51
 
52
        final GridBagConstraints c = new DefaultGridBagConstraints();
53
        final Insets normalInsets = c.insets;
54
        c.gridwidth = 1;
55
        c.gridheight = 1;
56
        c.weightx = 1;
57
        c.weighty = 0;
58
 
59
        /*******************************************************************************************
60
         * ACOMPTE
61
         ******************************************************************************************/
62
        TitledSeparator sep = new TitledSeparator("Acompte");
63
        c.gridwidth = GridBagConstraints.REMAINDER;
64
        this.add(sep, c);
65
        c.gridwidth = 1;
66
 
67
        // Compte acompte
68
        c.gridy++;
69
        c.weightx = 0;
70
        this.add(new JLabel("Compte Acomptes"), c);
71
        c.weightx = 1;
72
 
73
        c.gridx++;
74
        this.selCompteAcompte = new ISQLCompteSelector();
75
        this.selCompteAcompte.init();
76
        this.add(this.selCompteAcompte, c);
77
 
78
        // Compte acompte reglement
79
        c.gridy++;
80
        c.weightx = 0;
81
        c.gridx = 0;
82
        this.add(new JLabel("Compte règlement acompte"), c);
83
        c.weightx = 1;
84
        c.gridx++;
85
        this.selCompteAcompteReglement = new ISQLCompteSelector();
86
        this.selCompteAcompteReglement.init();
87
        this.add(this.selCompteAcompteReglement, c);
88
 
89
        /*******************************************************************************************
90
         * PAYE
91
         ******************************************************************************************/
92
        c.gridy++;
93
        c.gridx = 0;
94
        TitledSeparator sepVenteC = new TitledSeparator("Paye");
95
        c.gridwidth = GridBagConstraints.REMAINDER;
96
        c.insets = separatorInsets;
97
        this.add(sepVenteC, c);
98
        c.insets = normalInsets;
99
        c.gridwidth = 1;
100
 
101
        // Compte client
102
        c.gridy++;
103
        c.weightx = 0;
104
 
105
        this.add(new JLabel("Compte rémunérations du personnel"), c);
106
        c.weightx = 1;
107
        c.gridx++;
108
 
109
        this.selCompteRemunPers = new ISQLCompteSelector();
110
        this.selCompteRemunPers.init();
111
        this.add(this.selCompteRemunPers, c);
112
        // Spacer
113
        c.weighty = 1;
114
        c.gridy++;
115
        this.add(new JPanel(), c);
116
        setValues();
117
    }
118
 
119
    public void storeValues() {
120
 
121
        this.rowPrefCompteVals.put("ID_COMPTE_PCE_ACOMPTE", this.selCompteAcompte.getValue());
122
        this.rowPrefCompteVals.put("ID_COMPTE_PCE_ACOMPTE_REGL", this.selCompteAcompteReglement.getValue());
123
        this.rowPrefCompteVals.put("ID_COMPTE_PCE_PAYE", this.selCompteRemunPers.getValue());
124
 
125
        try {
126
            this.rowPrefCompteVals.update();
127
        } catch (SQLException e) {
128
            e.printStackTrace();
129
        }
130
    }
131
 
132
    public void restoreToDefaults() {
133
 
134
        try {
135
            // Acompte
136
            String compte;
137
            compte = ComptePCESQLElement.getComptePceDefault("PayeAcompte");
138
 
139
            int value = ComptePCESQLElement.getId(compte);
140
            this.selCompteAcompte.setValue(value);
141
 
142
            // Reglement acompte
143
            compte = ComptePCESQLElement.getComptePceDefault("PayeReglementAcompte");
144
            value = ComptePCESQLElement.getId(compte);
145
            this.selCompteAcompteReglement.setValue(value);
146
 
147
            // Remuneration du personel
148
            compte = ComptePCESQLElement.getComptePceDefault("PayeRemunerationPersonnel");
149
            value = ComptePCESQLElement.getId(compte);
150
            this.selCompteRemunPers.setValue(value);
151
 
152
        } catch (Exception e) {
153
            // TODO Auto-generated catch block
154
            e.printStackTrace();
155
        }
156
    }
157
 
158
    public String getTitleName() {
159
        return "Paye";
160
    }
161
 
162
    private void setValues() {
163
 
164
        try {
165
            // Acompte
166
            int value = this.rowPrefCompteVals.getInt("ID_COMPTE_PCE_ACOMPTE");
167
            if (value <= 1) {
168
                String compte = ComptePCESQLElement.getComptePceDefault("PayeAcompte");
169
                value = ComptePCESQLElement.getId(compte);
170
            }
171
            this.selCompteAcompte.setValue(value);
172
 
173
            // Reglement acompte
174
            value = this.rowPrefCompteVals.getInt("ID_COMPTE_PCE_ACOMPTE_REGL");
175
            if (value <= 1) {
176
                String compte = ComptePCESQLElement.getComptePceDefault("PayeReglementAcompte");
177
                value = ComptePCESQLElement.getId(compte);
178
            }
179
            this.selCompteAcompteReglement.setValue(value);
180
 
181
            // Remuneration du personel
182
            value = this.rowPrefCompteVals.getInt("ID_COMPTE_PCE_PAYE");
183
            if (value <= 1) {
184
                String compte = ComptePCESQLElement.getComptePceDefault("PayeRemunerationPersonnel");
185
                value = ComptePCESQLElement.getId(compte);
186
            }
187
            this.selCompteRemunPers.setValue(value);
188
        } catch (Exception e) {
189
            // TODO Auto-generated catch block
190
            e.printStackTrace();
191
        }
192
    }
193
}