OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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