OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 149 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.ui;
14
 package org.openconcerto.erp.core.finance.accounting.ui;
15
 
15
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
17
import org.openconcerto.erp.core.finance.accounting.element.ComptePCESQLElement;
17
import org.openconcerto.erp.core.finance.accounting.element.ComptePCESQLElement;
18
import org.openconcerto.erp.core.finance.accounting.element.JournalSQLElement;
18
import org.openconcerto.erp.core.finance.accounting.element.JournalSQLElement;
19
import org.openconcerto.erp.model.ISQLCompteSelector;
19
import org.openconcerto.erp.model.ISQLCompteSelector;
20
import org.openconcerto.sql.Configuration;
20
import org.openconcerto.sql.Configuration;
21
import org.openconcerto.sql.model.SQLBase;
21
import org.openconcerto.sql.model.SQLBase;
22
import org.openconcerto.sql.model.SQLRow;
22
import org.openconcerto.sql.model.SQLRow;
23
import org.openconcerto.sql.model.SQLRowAccessor;
23
import org.openconcerto.sql.model.SQLRowAccessor;
24
import org.openconcerto.sql.model.SQLRowValues;
24
import org.openconcerto.sql.model.SQLRowValues;
25
import org.openconcerto.sql.model.SQLTable;
25
import org.openconcerto.sql.model.SQLTable;
26
import org.openconcerto.sql.sqlobject.ElementComboBox;
26
import org.openconcerto.sql.request.SQLFieldTranslator;
27
import org.openconcerto.sql.sqlobject.SQLRequestComboBox;
27
import org.openconcerto.sql.sqlobject.SQLRequestComboBox;
28
import org.openconcerto.ui.DefaultGridBagConstraints;
28
import org.openconcerto.ui.DefaultGridBagConstraints;
29
import org.openconcerto.ui.preferences.DefaultPreferencePanel;
29
import org.openconcerto.ui.preferences.DefaultPreferencePanel;
30
 
30
 
31
import java.awt.GridBagConstraints;
31
import java.awt.GridBagConstraints;
32
import java.awt.GridBagLayout;
32
import java.awt.GridBagLayout;
33
import java.sql.SQLException;
33
import java.sql.SQLException;
34
 
34
 
35
import javax.swing.JCheckBox;
35
import javax.swing.JCheckBox;
36
import javax.swing.JLabel;
36
import javax.swing.JLabel;
-
 
37
import javax.swing.JOptionPane;
37
import javax.swing.JPanel;
38
import javax.swing.JPanel;
-
 
39
import javax.swing.SwingUtilities;
38
 
40
 
39
public class CompteCloturePreferencePanel extends DefaultPreferencePanel {
41
public class CompteCloturePreferencePanel extends DefaultPreferencePanel {
40
    private ISQLCompteSelector selCompteOuverture, selCompteFermeture, selCompteResultat, selCompteResultatPerte;
42
    private ISQLCompteSelector selCompteOuverture, selCompteFermeture, selCompteResultat, selCompteResultatPerte;
41
    private SQLRequestComboBox selJournal;
43
    private SQLRequestComboBox selJournal;
42
    private JCheckBox boxCompteSolde;
44
    private JCheckBox boxCompteSolde;
43
    private final static SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
45
    private final static SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
44
    private static final SQLTable tablePrefCompte = base.getTable("PREFS_COMPTE");
46
    private static final SQLTable tablePrefCompte = base.getTable("PREFS_COMPTE");
45
    private SQLRowValues rowPrefCompteVals = new SQLRowValues(tablePrefCompte);
47
    private SQLRowValues rowPrefCompteVals = new SQLRowValues(tablePrefCompte);
46
 
48
 
47
    public CompteCloturePreferencePanel() {
49
    public CompteCloturePreferencePanel() {
48
 
50
 
49
        final SQLRow rowPrefCompte = tablePrefCompte.getRow(2);
51
        final SQLRow rowPrefCompte = tablePrefCompte.getRow(2);
50
        this.rowPrefCompteVals.loadAbsolutelyAll(rowPrefCompte);
52
        this.rowPrefCompteVals.loadAbsolutelyAll(rowPrefCompte);
51
 
53
 
52
        this.setLayout(new GridBagLayout());
54
        this.setLayout(new GridBagLayout());
53
        final GridBagConstraints c = new DefaultGridBagConstraints();
55
        final GridBagConstraints c = new DefaultGridBagConstraints();
54
 
56
 
55
        // Compte ouverture
57
        // Compte ouverture
56
        this.add(new JLabel("Compte bilan d'ouverture"), c);
58
        this.add(new JLabel("Compte bilan d'ouverture"), c);
57
        c.weightx = 1;
59
        c.weightx = 1;
58
        c.gridx++;
60
        c.gridx++;
59
        this.selCompteOuverture = new ISQLCompteSelector();
61
        this.selCompteOuverture = new ISQLCompteSelector();
60
        this.selCompteOuverture.init();
62
        this.selCompteOuverture.init();
61
        this.add(this.selCompteOuverture, c);
63
        this.add(this.selCompteOuverture, c);
62
 
64
 
63
        // Compte fermeture
65
        // Compte fermeture
64
        c.gridy++;
66
        c.gridy++;
65
        c.weightx = 0;
67
        c.weightx = 0;
66
        c.gridx = 0;
68
        c.gridx = 0;
67
        this.add(new JLabel("Compte bilan de clôture"), c);
69
        this.add(new JLabel("Compte bilan de clôture"), c);
68
        c.weightx = 1;
70
        c.weightx = 1;
69
        c.gridx++;
71
        c.gridx++;
70
        this.selCompteFermeture = new ISQLCompteSelector();
72
        this.selCompteFermeture = new ISQLCompteSelector();
71
        this.selCompteFermeture.init();
73
        this.selCompteFermeture.init();
72
        this.add(this.selCompteFermeture, c);
74
        this.add(this.selCompteFermeture, c);
73
 
75
 
74
        // Compte résultat
76
        // Compte résultat
75
        c.gridy++;
77
        c.gridy++;
76
        c.gridx = 0;
78
        c.gridx = 0;
77
        c.weightx = 0;
79
        c.weightx = 0;
78
 
80
 
79
        this.add(new JLabel("Compte de résultat (bénéfice)"), c);
81
        this.add(new JLabel("Compte de résultat (bénéfice)"), c);
80
        c.weightx = 1;
82
        c.weightx = 1;
81
        c.gridx++;
83
        c.gridx++;
82
        this.selCompteResultat = new ISQLCompteSelector();
84
        this.selCompteResultat = new ISQLCompteSelector();
83
        this.selCompteResultat.init();
85
        this.selCompteResultat.init();
84
        this.add(this.selCompteResultat, c);
86
        this.add(this.selCompteResultat, c);
85
 
87
 
86
        // Compte résultat
88
        // Compte résultat
87
        c.gridy++;
89
        c.gridy++;
88
        c.gridx = 0;
90
        c.gridx = 0;
89
        c.weightx = 0;
91
        c.weightx = 0;
90
        this.add(new JLabel("Compte de résultat (perte)"), c);
92
        this.add(new JLabel("Compte de résultat (perte)"), c);
91
        c.weightx = 1;
93
        c.weightx = 1;
92
        c.gridx++;
94
        c.gridx++;
93
        this.selCompteResultatPerte = new ISQLCompteSelector();
95
        this.selCompteResultatPerte = new ISQLCompteSelector();
94
        this.selCompteResultatPerte.init();
96
        this.selCompteResultatPerte.init();
95
        this.add(this.selCompteResultatPerte, c);
97
        this.add(this.selCompteResultatPerte, c);
96
 
98
 
97
        // Compte résultat
99
        // Compte résultat
98
        c.gridy++;
100
        c.gridy++;
99
        c.gridx = 0;
101
        c.gridx = 0;
100
        c.weightx = 0;
102
        c.weightx = 0;
101
        this.add(new JLabel("Journal des à nouveaux"), c);
103
        this.add(new JLabel("Journal des à nouveaux"), c);
102
        c.weightx = 1;
104
        c.weightx = 1;
103
        c.gridx++;
105
        c.gridx++;
104
        this.selJournal = new SQLRequestComboBox(false);
106
        this.selJournal = new SQLRequestComboBox(false);
105
        this.selJournal.uiInit(Configuration.getInstance().getDirectory().getElement("JOURNAL").createComboRequest());
107
        this.selJournal.uiInit(Configuration.getInstance().getDirectory().getElement("JOURNAL").createComboRequest());
106
        this.add(this.selJournal, c);
108
        this.add(this.selJournal, c);
107
 
109
 
108
        // Compte résultat
110
        // Compte résultat
109
        c.gridy++;
111
        c.gridy++;
110
        c.gridx = 0;
112
        c.gridx = 0;
111
        c.weightx = 0;
113
        c.weightx = 0;
112
        this.add(new JLabel("Générer des écritures de fermetures et d'à nouveaux pour les comptes soldés"), c);
114
        this.add(new JLabel("Générer des écritures de fermetures et d'à nouveaux pour les comptes soldés"), c);
113
        c.weightx = 1;
115
        c.weightx = 1;
114
        c.gridx++;
116
        c.gridx++;
115
        this.boxCompteSolde = new JCheckBox();
117
        this.boxCompteSolde = new JCheckBox();
116
        this.boxCompteSolde.setSelected(true);
118
        this.boxCompteSolde.setSelected(true);
117
        this.add(this.boxCompteSolde, c);
119
        this.add(this.boxCompteSolde, c);
118
 
120
 
119
        // Spacer
121
        // Spacer
120
 
122
 
121
        JPanel p = new JPanel();
123
        JPanel p = new JPanel();
122
        p.setOpaque(false);
124
        p.setOpaque(false);
123
        c.gridy++;
125
        c.gridy++;
124
        c.weighty = 1;
126
        c.weighty = 1;
125
        this.add(p, c);
127
        this.add(p, c);
126
        setValues();
128
        setValues();
127
    }
129
    }
128
 
130
 
129
    public void storeValues() {
131
    public void storeValues() {
130
 
132
 
131
        this.rowPrefCompteVals.put("ID_COMPTE_PCE_BILAN_O", this.selCompteOuverture.getValue());
133
        this.rowPrefCompteVals.put("ID_COMPTE_PCE_BILAN_O", this.selCompteOuverture.getValue());
132
        this.rowPrefCompteVals.put("ID_COMPTE_PCE_BILAN_F", this.selCompteFermeture.getValue());
134
        this.rowPrefCompteVals.put("ID_COMPTE_PCE_BILAN_F", this.selCompteFermeture.getValue());
133
        this.rowPrefCompteVals.put("ID_COMPTE_PCE_RESULTAT", this.selCompteResultat.getValue());
135
        this.rowPrefCompteVals.put("ID_COMPTE_PCE_RESULTAT", this.selCompteResultat.getValue());
134
        this.rowPrefCompteVals.put("ID_COMPTE_PCE_RESULTAT_PERTE", this.selCompteResultat.getValue());
136
        this.rowPrefCompteVals.put("ID_COMPTE_PCE_RESULTAT_PERTE", this.selCompteResultat.getValue());
135
        this.rowPrefCompteVals.put("ID_JOURNAL_AN", this.selJournal.getValue());
137
        this.rowPrefCompteVals.put("ID_JOURNAL_AN", this.selJournal.getValue());
136
        this.rowPrefCompteVals.put("CREATE_NUL_SOLDE_ECR", this.boxCompteSolde.isSelected());
138
        this.rowPrefCompteVals.put("CREATE_NUL_SOLDE_ECR", this.boxCompteSolde.isSelected());
137
 
139
 
138
        try {
140
        try {
-
 
141
            final Object[] pb = this.rowPrefCompteVals.getInvalid();
-
 
142
            if (pb != null) {
-
 
143
                final SQLFieldTranslator trans = Configuration.getInstance().getTranslator();
-
 
144
                JOptionPane.showMessageDialog(SwingUtilities.getRoot(this), "Impossible de valider les modifications! Le champ <"
-
 
145
                        + trans.getLabelFor(this.rowPrefCompteVals.getTable().getField(pb[0].toString())) + "> pointe sur un compte invalide!(" + pb[1] + ")");
-
 
146
            } else {
139
            this.rowPrefCompteVals.update();
147
                this.rowPrefCompteVals.update();
-
 
148
            }
140
        } catch (SQLException e) {
149
        } catch (SQLException e) {
141
            e.printStackTrace();
150
            e.printStackTrace();
142
        }
151
        }
143
    }
152
    }
144
 
153
 
145
    public void restoreToDefaults() {
154
    public void restoreToDefaults() {
146
 
155
 
147
        try {
156
        try {
148
            // Ouverture
157
            // Ouverture
149
            String compte;
158
            String compte;
150
            compte = ComptePCESQLElement.getComptePceDefault("BilanOuverture");
159
            compte = ComptePCESQLElement.getComptePceDefault("BilanOuverture");
151
 
160
 
152
            int value = ComptePCESQLElement.getId(compte);
161
            int value = ComptePCESQLElement.getId(compte);
153
            this.selCompteOuverture.setValue(value);
162
            this.selCompteOuverture.setValue(value);
154
 
163
 
155
            // Fermeture
164
            // Fermeture
156
            compte = ComptePCESQLElement.getComptePceDefault("BilanFermeture");
165
            compte = ComptePCESQLElement.getComptePceDefault("BilanFermeture");
157
            value = ComptePCESQLElement.getId(compte);
166
            value = ComptePCESQLElement.getId(compte);
158
            this.selCompteFermeture.setValue(value);
167
            this.selCompteFermeture.setValue(value);
159
 
168
 
160
            // Resultat
169
            // Resultat
161
            compte = ComptePCESQLElement.getComptePceDefault("Resultat");
170
            compte = ComptePCESQLElement.getComptePceDefault("Resultat");
162
            value = ComptePCESQLElement.getId(compte);
171
            value = ComptePCESQLElement.getId(compte);
163
            this.selCompteResultat.setValue(value);
172
            this.selCompteResultat.setValue(value);
164
 
173
 
165
            // Resultat
174
            // Resultat
166
            compte = ComptePCESQLElement.getComptePceDefault("ResultatPerte");
175
            compte = ComptePCESQLElement.getComptePceDefault("ResultatPerte");
167
            value = ComptePCESQLElement.getId(compte);
176
            value = ComptePCESQLElement.getId(compte);
168
            this.selCompteResultatPerte.setValue(value);
177
            this.selCompteResultatPerte.setValue(value);
169
 
178
 
170
            // AN
179
            // AN
171
            this.selJournal.setValue(JournalSQLElement.OD);
180
            this.selJournal.setValue(JournalSQLElement.OD);
172
 
181
 
173
            this.boxCompteSolde.setSelected(true);
182
            this.boxCompteSolde.setSelected(true);
174
 
183
 
175
        } catch (Exception e) {
184
        } catch (Exception e) {
176
            e.printStackTrace();
185
            e.printStackTrace();
177
        }
186
        }
178
    }
187
    }
179
 
188
 
180
    public String getTitleName() {
189
    public String getTitleName() {
181
        return "Clôture";
190
        return "Clôture";
182
    }
191
    }
183
 
192
 
184
    private void setValues() {
193
    private void setValues() {
185
 
194
 
186
        try {
195
        try {
187
            // Ouverture
196
            // Ouverture
188
            SQLRowAccessor rowBilanO = this.rowPrefCompteVals.getForeign("ID_COMPTE_PCE_BILAN_O");
197
            SQLRowAccessor rowBilanO = this.rowPrefCompteVals.getForeign("ID_COMPTE_PCE_BILAN_O");
189
            int value = 1;
198
            int value = 1;
190
            if (rowBilanO == null || rowBilanO.isUndefined()) {
199
            if (rowBilanO == null || rowBilanO.isUndefined()) {
191
                String compte = ComptePCESQLElement.getComptePceDefault("BilanOuverture");
200
                String compte = ComptePCESQLElement.getComptePceDefault("BilanOuverture");
192
                value = ComptePCESQLElement.getId(compte);
201
                value = ComptePCESQLElement.getId(compte);
193
            } else {
202
            } else {
194
                value = rowBilanO.getID();
203
                value = rowBilanO.getID();
195
            }
204
            }
196
            this.selCompteOuverture.setValue(value);
205
            this.selCompteOuverture.setValue(value);
197
 
206
 
198
            // Fermeture
207
            // Fermeture
199
            SQLRowAccessor rowBilanF = this.rowPrefCompteVals.getForeign("ID_COMPTE_PCE_BILAN_F");
208
            SQLRowAccessor rowBilanF = this.rowPrefCompteVals.getForeign("ID_COMPTE_PCE_BILAN_F");
200
            if (rowBilanF == null || rowBilanF.isUndefined()) {
209
            if (rowBilanF == null || rowBilanF.isUndefined()) {
201
                String compte = ComptePCESQLElement.getComptePceDefault("BilanFermeture");
210
                String compte = ComptePCESQLElement.getComptePceDefault("BilanFermeture");
202
                value = ComptePCESQLElement.getId(compte);
211
                value = ComptePCESQLElement.getId(compte);
203
            } else {
212
            } else {
204
                value = rowBilanF.getID();
213
                value = rowBilanF.getID();
205
            }
214
            }
206
            this.selCompteFermeture.setValue(value);
215
            this.selCompteFermeture.setValue(value);
207
 
216
 
208
            // Resultat
217
            // Resultat
209
            SQLRowAccessor rowResultat = this.rowPrefCompteVals.getForeign("ID_COMPTE_PCE_RESULTAT");
218
            SQLRowAccessor rowResultat = this.rowPrefCompteVals.getForeign("ID_COMPTE_PCE_RESULTAT");
210
            if (rowResultat == null || rowResultat.isUndefined()) {
219
            if (rowResultat == null || rowResultat.isUndefined()) {
211
                String compte = ComptePCESQLElement.getComptePceDefault("Resultat");
220
                String compte = ComptePCESQLElement.getComptePceDefault("Resultat");
212
                value = ComptePCESQLElement.getId(compte);
221
                value = ComptePCESQLElement.getId(compte);
213
            } else {
222
            } else {
214
                value = rowResultat.getID();
223
                value = rowResultat.getID();
215
            }
224
            }
216
            this.selCompteResultat.setValue(value);
225
            this.selCompteResultat.setValue(value);
217
 
226
 
218
            // Resultat Perte
227
            // Resultat Perte
219
            SQLRowAccessor rowResultatP = this.rowPrefCompteVals.getForeign("ID_COMPTE_PCE_RESULTAT_PERTE");
228
            SQLRowAccessor rowResultatP = this.rowPrefCompteVals.getForeign("ID_COMPTE_PCE_RESULTAT_PERTE");
220
            if (rowResultatP == null || rowResultatP.isUndefined()) {
229
            if (rowResultatP == null || rowResultatP.isUndefined()) {
221
                String compte = ComptePCESQLElement.getComptePceDefault("ResultatPerte");
230
                String compte = ComptePCESQLElement.getComptePceDefault("ResultatPerte");
222
                value = ComptePCESQLElement.getId(compte);
231
                value = ComptePCESQLElement.getId(compte);
223
            } else {
232
            } else {
224
                value = rowResultatP.getID();
233
                value = rowResultatP.getID();
225
            }
234
            }
226
            this.selCompteResultatPerte.setValue(value);
235
            this.selCompteResultatPerte.setValue(value);
227
 
236
 
228
            // Journal
237
            // Journal
229
            SQLRowAccessor rowJ = this.rowPrefCompteVals.getForeign("ID_JOURNAL_AN");
238
            SQLRowAccessor rowJ = this.rowPrefCompteVals.getForeign("ID_JOURNAL_AN");
230
            if (rowJ == null || rowJ.isUndefined()) {
239
            if (rowJ == null || rowJ.isUndefined()) {
231
                value = JournalSQLElement.OD;
240
                value = JournalSQLElement.OD;
232
            } else {
241
            } else {
233
                value = rowJ.getID();
242
                value = rowJ.getID();
234
            }
243
            }
235
            this.selJournal.setValue(value);
244
            this.selJournal.setValue(value);
236
 
245
 
237
            // Journal
246
            // Journal
238
            boolean b = true;
247
            boolean b = true;
239
            if (this.rowPrefCompteVals.getObject("CREATE_NUL_SOLDE_ECR") != null) {
248
            if (this.rowPrefCompteVals.getObject("CREATE_NUL_SOLDE_ECR") != null) {
240
                b = this.rowPrefCompteVals.getBoolean("CREATE_NUL_SOLDE_ECR");
249
                b = this.rowPrefCompteVals.getBoolean("CREATE_NUL_SOLDE_ECR");
241
            }
250
            }
242
            this.boxCompteSolde.setSelected(b);
251
            this.boxCompteSolde.setSelected(b);
243
 
252
 
244
        } catch (Exception e) {
253
        } catch (Exception e) {
245
            e.printStackTrace();
254
            e.printStackTrace();
246
        }
255
        }
247
    }
256
    }
248
}
257
}