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;
|
|
|
25 |
import org.openconcerto.ui.DefaultGridBagConstraints;
|
|
|
26 |
import org.openconcerto.ui.preferences.DefaultPreferencePanel;
|
|
|
27 |
|
|
|
28 |
import java.awt.GridBagConstraints;
|
|
|
29 |
import java.awt.GridBagLayout;
|
|
|
30 |
import java.sql.SQLException;
|
|
|
31 |
|
|
|
32 |
import javax.swing.JLabel;
|
|
|
33 |
import javax.swing.JPanel;
|
|
|
34 |
|
|
|
35 |
public class CompteCloturePreferencePanel extends DefaultPreferencePanel {
|
|
|
36 |
private ISQLCompteSelector selCompteOuverture, selCompteFermeture, selCompteResultat, selCompteResultatPerte;
|
|
|
37 |
private final static SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
|
|
|
38 |
private static final SQLTable tablePrefCompte = base.getTable("PREFS_COMPTE");
|
|
|
39 |
private SQLRowValues rowPrefCompteVals = new SQLRowValues(tablePrefCompte);
|
|
|
40 |
|
|
|
41 |
public CompteCloturePreferencePanel() {
|
|
|
42 |
|
|
|
43 |
final SQLRow rowPrefCompte = tablePrefCompte.getRow(2);
|
|
|
44 |
this.rowPrefCompteVals.loadAbsolutelyAll(rowPrefCompte);
|
|
|
45 |
|
|
|
46 |
this.setLayout(new GridBagLayout());
|
|
|
47 |
final GridBagConstraints c = new DefaultGridBagConstraints();
|
|
|
48 |
|
|
|
49 |
// Compte ouverture
|
|
|
50 |
this.add(new JLabel("Compte bilan d'ouverture"), c);
|
|
|
51 |
c.weightx = 1;
|
|
|
52 |
c.gridx++;
|
|
|
53 |
this.selCompteOuverture = new ISQLCompteSelector();
|
|
|
54 |
this.selCompteOuverture.init();
|
|
|
55 |
this.add(this.selCompteOuverture, c);
|
|
|
56 |
|
|
|
57 |
// Compte fermeture
|
|
|
58 |
c.gridy++;
|
|
|
59 |
c.weightx = 0;
|
|
|
60 |
c.gridx = 0;
|
|
|
61 |
this.add(new JLabel("Compte bilan de clôture"), c);
|
|
|
62 |
c.weightx = 1;
|
|
|
63 |
c.gridx++;
|
|
|
64 |
this.selCompteFermeture = new ISQLCompteSelector();
|
|
|
65 |
this.selCompteFermeture.init();
|
|
|
66 |
this.add(this.selCompteFermeture, c);
|
|
|
67 |
|
|
|
68 |
// Compte résultat
|
|
|
69 |
c.gridy++;
|
|
|
70 |
c.gridx = 0;
|
|
|
71 |
c.weightx = 0;
|
|
|
72 |
|
|
|
73 |
this.add(new JLabel("Compte de résultat (bénéfice)"), c);
|
|
|
74 |
c.weightx = 1;
|
|
|
75 |
c.gridx++;
|
|
|
76 |
this.selCompteResultat = new ISQLCompteSelector();
|
|
|
77 |
this.selCompteResultat.init();
|
|
|
78 |
this.add(this.selCompteResultat, c);
|
|
|
79 |
|
|
|
80 |
// Compte résultat
|
|
|
81 |
c.gridy++;
|
|
|
82 |
c.gridx = 0;
|
|
|
83 |
c.weightx = 0;
|
|
|
84 |
this.add(new JLabel("Compte de résultat (perte)"), c);
|
|
|
85 |
c.weightx = 1;
|
|
|
86 |
c.gridx++;
|
|
|
87 |
this.selCompteResultatPerte = new ISQLCompteSelector();
|
|
|
88 |
this.selCompteResultatPerte.init();
|
|
|
89 |
this.add(this.selCompteResultatPerte, c);
|
|
|
90 |
|
|
|
91 |
// Spacer
|
|
|
92 |
|
|
|
93 |
JPanel p = new JPanel();
|
|
|
94 |
p.setOpaque(false);
|
|
|
95 |
c.gridy++;
|
|
|
96 |
c.weighty = 1;
|
|
|
97 |
this.add(p, c);
|
|
|
98 |
setValues();
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
public void storeValues() {
|
|
|
102 |
|
|
|
103 |
this.rowPrefCompteVals.put("ID_COMPTE_PCE_BILAN_O", this.selCompteOuverture.getValue());
|
|
|
104 |
this.rowPrefCompteVals.put("ID_COMPTE_PCE_BILAN_F", this.selCompteFermeture.getValue());
|
|
|
105 |
this.rowPrefCompteVals.put("ID_COMPTE_PCE_RESULTAT", this.selCompteResultat.getValue());
|
|
|
106 |
this.rowPrefCompteVals.put("ID_COMPTE_PCE_RESULTAT_PERTE", this.selCompteResultat.getValue());
|
|
|
107 |
|
|
|
108 |
try {
|
|
|
109 |
this.rowPrefCompteVals.update();
|
|
|
110 |
} catch (SQLException e) {
|
|
|
111 |
e.printStackTrace();
|
|
|
112 |
}
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
public void restoreToDefaults() {
|
|
|
116 |
|
|
|
117 |
try {
|
|
|
118 |
// Ouverture
|
|
|
119 |
String compte;
|
|
|
120 |
compte = ComptePCESQLElement.getComptePceDefault("BilanOuverture");
|
|
|
121 |
|
|
|
122 |
int value = ComptePCESQLElement.getId(compte);
|
|
|
123 |
this.selCompteOuverture.setValue(value);
|
|
|
124 |
|
|
|
125 |
// Fermeture
|
|
|
126 |
compte = ComptePCESQLElement.getComptePceDefault("BilanFermeture");
|
|
|
127 |
value = ComptePCESQLElement.getId(compte);
|
|
|
128 |
this.selCompteFermeture.setValue(value);
|
|
|
129 |
|
|
|
130 |
// Resultat
|
|
|
131 |
compte = ComptePCESQLElement.getComptePceDefault("Resultat");
|
|
|
132 |
value = ComptePCESQLElement.getId(compte);
|
|
|
133 |
this.selCompteResultat.setValue(value);
|
|
|
134 |
|
|
|
135 |
// Resultat
|
|
|
136 |
compte = ComptePCESQLElement.getComptePceDefault("ResultatPerte");
|
|
|
137 |
value = ComptePCESQLElement.getId(compte);
|
|
|
138 |
this.selCompteResultatPerte.setValue(value);
|
|
|
139 |
|
|
|
140 |
} catch (Exception e) {
|
|
|
141 |
e.printStackTrace();
|
|
|
142 |
}
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
public String getTitleName() {
|
|
|
146 |
return "Clôture";
|
|
|
147 |
}
|
|
|
148 |
|
|
|
149 |
private void setValues() {
|
|
|
150 |
|
|
|
151 |
try {
|
|
|
152 |
// Ouverture
|
73 |
ilm |
153 |
SQLRowAccessor rowBilanO = this.rowPrefCompteVals.getForeign("ID_COMPTE_PCE_BILAN_O");
|
|
|
154 |
int value = 1;
|
|
|
155 |
if (rowBilanO == null || rowBilanO.isUndefined()) {
|
18 |
ilm |
156 |
String compte = ComptePCESQLElement.getComptePceDefault("BilanOuverture");
|
|
|
157 |
value = ComptePCESQLElement.getId(compte);
|
73 |
ilm |
158 |
} else {
|
|
|
159 |
value = rowBilanO.getID();
|
18 |
ilm |
160 |
}
|
|
|
161 |
this.selCompteOuverture.setValue(value);
|
|
|
162 |
|
|
|
163 |
// Fermeture
|
73 |
ilm |
164 |
SQLRowAccessor rowBilanF = this.rowPrefCompteVals.getForeign("ID_COMPTE_PCE_BILAN_F");
|
|
|
165 |
if (rowBilanF == null || rowBilanF.isUndefined()) {
|
18 |
ilm |
166 |
String compte = ComptePCESQLElement.getComptePceDefault("BilanFermeture");
|
|
|
167 |
value = ComptePCESQLElement.getId(compte);
|
73 |
ilm |
168 |
} else {
|
|
|
169 |
value = rowBilanF.getID();
|
18 |
ilm |
170 |
}
|
|
|
171 |
this.selCompteFermeture.setValue(value);
|
|
|
172 |
|
|
|
173 |
// Resultat
|
73 |
ilm |
174 |
SQLRowAccessor rowResultat = this.rowPrefCompteVals.getForeign("ID_COMPTE_PCE_RESULTAT");
|
|
|
175 |
if (rowResultat == null || rowResultat.isUndefined()) {
|
18 |
ilm |
176 |
String compte = ComptePCESQLElement.getComptePceDefault("Resultat");
|
|
|
177 |
value = ComptePCESQLElement.getId(compte);
|
73 |
ilm |
178 |
} else {
|
|
|
179 |
value = rowResultat.getID();
|
18 |
ilm |
180 |
}
|
|
|
181 |
this.selCompteResultat.setValue(value);
|
|
|
182 |
|
|
|
183 |
// Resultat Perte
|
73 |
ilm |
184 |
SQLRowAccessor rowResultatP = this.rowPrefCompteVals.getForeign("ID_COMPTE_PCE_RESULTAT_PERTE");
|
|
|
185 |
if (rowResultatP == null || rowResultatP.isUndefined()) {
|
18 |
ilm |
186 |
String compte = ComptePCESQLElement.getComptePceDefault("ResultatPerte");
|
|
|
187 |
value = ComptePCESQLElement.getId(compte);
|
73 |
ilm |
188 |
} else {
|
|
|
189 |
value = rowResultatP.getID();
|
18 |
ilm |
190 |
}
|
|
|
191 |
this.selCompteResultatPerte.setValue(value);
|
|
|
192 |
|
|
|
193 |
} catch (Exception e) {
|
|
|
194 |
e.printStackTrace();
|
|
|
195 |
}
|
|
|
196 |
}
|
|
|
197 |
}
|