18 |
ilm |
1 |
/*
|
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
|
|
3 |
*
|
182 |
ilm |
4 |
* Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
|
18 |
ilm |
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.element;
|
|
|
15 |
|
|
|
16 |
import org.openconcerto.erp.config.ComptaPropsConfiguration;
|
|
|
17 |
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
|
177 |
ilm |
18 |
import org.openconcerto.erp.core.finance.accounting.ui.AnalytiqueItemTable;
|
180 |
ilm |
19 |
import org.openconcerto.erp.core.finance.accounting.ui.ComptabiliteWorkflowPreferencePanel;
|
|
|
20 |
import org.openconcerto.erp.core.finance.accounting.ui.PropoLettrage;
|
18 |
ilm |
21 |
import org.openconcerto.erp.core.finance.accounting.ui.SaisieKmItemTable;
|
|
|
22 |
import org.openconcerto.erp.generationEcritures.GenerationMvtSaisieKm;
|
180 |
ilm |
23 |
import org.openconcerto.erp.generationEcritures.provider.AccountingRecordsProvider;
|
|
|
24 |
import org.openconcerto.erp.generationEcritures.provider.AccountingRecordsProviderManager;
|
|
|
25 |
import org.openconcerto.erp.preferences.DefaultNXProps;
|
18 |
ilm |
26 |
import org.openconcerto.sql.Configuration;
|
|
|
27 |
import org.openconcerto.sql.element.BaseSQLComponent;
|
|
|
28 |
import org.openconcerto.sql.element.SQLComponent;
|
|
|
29 |
import org.openconcerto.sql.element.SQLElement;
|
|
|
30 |
import org.openconcerto.sql.model.SQLBase;
|
180 |
ilm |
31 |
import org.openconcerto.sql.model.SQLName;
|
18 |
ilm |
32 |
import org.openconcerto.sql.model.SQLRow;
|
|
|
33 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
|
|
34 |
import org.openconcerto.sql.model.SQLRowValues;
|
|
|
35 |
import org.openconcerto.sql.model.SQLSelect;
|
|
|
36 |
import org.openconcerto.sql.model.SQLTable;
|
180 |
ilm |
37 |
import org.openconcerto.sql.model.TableRef;
|
18 |
ilm |
38 |
import org.openconcerto.sql.model.UndefinedRowValuesCache;
|
|
|
39 |
import org.openconcerto.sql.model.Where;
|
180 |
ilm |
40 |
import org.openconcerto.sql.request.UpdateBuilder;
|
18 |
ilm |
41 |
import org.openconcerto.sql.sqlobject.ElementComboBox;
|
21 |
ilm |
42 |
import org.openconcerto.sql.utils.SQLUtils;
|
18 |
ilm |
43 |
import org.openconcerto.sql.view.list.RowValuesTableModel;
|
|
|
44 |
import org.openconcerto.ui.DefaultGridBagConstraints;
|
|
|
45 |
import org.openconcerto.ui.JDate;
|
|
|
46 |
import org.openconcerto.ui.warning.JLabelWarning;
|
21 |
ilm |
47 |
import org.openconcerto.utils.ExceptionHandler;
|
18 |
ilm |
48 |
import org.openconcerto.utils.GestionDevise;
|
21 |
ilm |
49 |
import org.openconcerto.utils.checks.ValidState;
|
18 |
ilm |
50 |
import org.openconcerto.utils.text.SimpleDocumentListener;
|
|
|
51 |
|
|
|
52 |
import java.awt.Dimension;
|
|
|
53 |
import java.awt.GridBagConstraints;
|
|
|
54 |
import java.awt.GridBagLayout;
|
|
|
55 |
import java.awt.event.ActionEvent;
|
|
|
56 |
import java.awt.event.ActionListener;
|
83 |
ilm |
57 |
import java.beans.PropertyChangeEvent;
|
|
|
58 |
import java.beans.PropertyChangeListener;
|
18 |
ilm |
59 |
import java.sql.SQLException;
|
|
|
60 |
import java.util.ArrayList;
|
83 |
ilm |
61 |
import java.util.Calendar;
|
18 |
ilm |
62 |
import java.util.Date;
|
|
|
63 |
import java.util.List;
|
|
|
64 |
import java.util.Set;
|
|
|
65 |
|
|
|
66 |
import javax.swing.BorderFactory;
|
|
|
67 |
import javax.swing.JCheckBox;
|
|
|
68 |
import javax.swing.JLabel;
|
|
|
69 |
import javax.swing.JOptionPane;
|
|
|
70 |
import javax.swing.JPanel;
|
|
|
71 |
import javax.swing.JTextField;
|
|
|
72 |
import javax.swing.SwingConstants;
|
|
|
73 |
import javax.swing.SwingUtilities;
|
|
|
74 |
import javax.swing.event.DocumentEvent;
|
|
|
75 |
import javax.swing.event.TableModelEvent;
|
|
|
76 |
import javax.swing.event.TableModelListener;
|
|
|
77 |
|
|
|
78 |
import org.apache.commons.dbutils.handlers.ArrayListHandler;
|
|
|
79 |
|
|
|
80 |
public class SaisieKmSQLElement extends ComptaSQLConfElement {
|
|
|
81 |
|
|
|
82 |
public SaisieKmSQLElement() {
|
|
|
83 |
super("SAISIE_KM", "une saisie au kilomètre", "saisies au kilomètre");
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
protected List<String> getListFields() {
|
|
|
87 |
final List<String> l = new ArrayList<String>();
|
|
|
88 |
l.add("DATE");
|
|
|
89 |
l.add("NOM");
|
|
|
90 |
l.add("ID_JOURNAL");
|
|
|
91 |
return l;
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
protected List<String> getComboFields() {
|
|
|
95 |
final List<String> l = new ArrayList<String>();
|
|
|
96 |
l.add("DATE");
|
|
|
97 |
l.add("NOM");
|
|
|
98 |
|
|
|
99 |
return l;
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
/*
|
|
|
103 |
* (non-Javadoc)
|
|
|
104 |
*
|
|
|
105 |
* @see org.openconcerto.devis.SQLElement#getComponent()
|
|
|
106 |
*/
|
|
|
107 |
public SQLComponent createComponent() {
|
|
|
108 |
|
|
|
109 |
return new SaisieKmComponent();
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
/**
|
|
|
113 |
* Genere une saisie au kilometre à partir d'un mouvement
|
|
|
114 |
*
|
|
|
115 |
* @param idMvt
|
|
|
116 |
*
|
|
|
117 |
* @return l'id de la saisie au kilometre créé
|
73 |
ilm |
118 |
* @throws SQLException
|
18 |
ilm |
119 |
*/
|
73 |
ilm |
120 |
public static int createSaisie(int idMvt) throws SQLException {
|
18 |
ilm |
121 |
int idSaisie = 1;
|
|
|
122 |
SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
|
|
|
123 |
SQLTable ecrTable = base.getTable("ECRITURE");
|
|
|
124 |
SQLTable compteTable = base.getTable("COMPTE_PCE");
|
|
|
125 |
SQLTable saisieKmTable = base.getTable("SAISIE_KM_ELEMENT");
|
177 |
ilm |
126 |
SQLTable assocTable = base.getTable("ASSOCIATION_ANALYTIQUE");
|
18 |
ilm |
127 |
|
|
|
128 |
SQLRowValues vals = new SQLRowValues(base.getTable("SAISIE_KM"));
|
|
|
129 |
vals.put("ID_MOUVEMENT", new Integer(idMvt));
|
|
|
130 |
|
73 |
ilm |
131 |
SQLRow rowSaisieKm = vals.insert();
|
|
|
132 |
idSaisie = rowSaisieKm.getID();
|
18 |
ilm |
133 |
|
73 |
ilm |
134 |
SQLSelect selEcriture = new SQLSelect();
|
|
|
135 |
selEcriture.addSelect(ecrTable.getField("ID"));
|
18 |
ilm |
136 |
|
73 |
ilm |
137 |
Where w = new Where(ecrTable.getField("ID_MOUVEMENT"), "=", idMvt);
|
|
|
138 |
selEcriture.setWhere(w);
|
18 |
ilm |
139 |
|
73 |
ilm |
140 |
String reqEcriture = selEcriture.asString();
|
18 |
ilm |
141 |
|
73 |
ilm |
142 |
Object obEcriture = base.getDataSource().execute(reqEcriture, new ArrayListHandler());
|
18 |
ilm |
143 |
|
73 |
ilm |
144 |
List myListEcriture = (List) obEcriture;
|
18 |
ilm |
145 |
|
73 |
ilm |
146 |
if (myListEcriture.size() != 0) {
|
18 |
ilm |
147 |
|
73 |
ilm |
148 |
for (int i = 0; i < myListEcriture.size(); i++) {
|
|
|
149 |
Object[] objTmp = (Object[]) myListEcriture.get(i);
|
18 |
ilm |
150 |
|
|
|
151 |
SQLRow rowEcrTmp = ecrTable.getRow(Integer.parseInt(objTmp[0].toString()));
|
73 |
ilm |
152 |
SQLRow rowCompteTmp = compteTable.getRow(rowEcrTmp.getInt("ID_COMPTE_PCE"));
|
18 |
ilm |
153 |
|
73 |
ilm |
154 |
SQLRowValues valsTmp = new SQLRowValues(saisieKmTable);
|
|
|
155 |
valsTmp.put("ID_SAISIE_KM", new Integer(rowSaisieKm.getID()));
|
|
|
156 |
valsTmp.put("NUMERO", rowCompteTmp.getString("NUMERO"));
|
|
|
157 |
valsTmp.put("NOM", rowCompteTmp.getString("NOM"));
|
|
|
158 |
valsTmp.put("NOM_ECRITURE", rowEcrTmp.getString("NOM"));
|
93 |
ilm |
159 |
if (ecrTable.contains("NOM_PIECE")) {
|
|
|
160 |
valsTmp.put("NOM_PIECE", rowEcrTmp.getString("NOM_PIECE"));
|
|
|
161 |
}
|
73 |
ilm |
162 |
valsTmp.put("DEBIT", rowEcrTmp.getObject("DEBIT"));
|
|
|
163 |
valsTmp.put("CREDIT", rowEcrTmp.getObject("CREDIT"));
|
|
|
164 |
valsTmp.put("ID_ECRITURE", new Integer(rowEcrTmp.getID()));
|
177 |
ilm |
165 |
|
|
|
166 |
List<SQLRow> assocRows = rowEcrTmp.getReferentRows(assocTable);
|
|
|
167 |
if (assocRows.size() > 0) {
|
|
|
168 |
for (int a = 0; a < assocRows.size(); a++) {
|
|
|
169 |
assocRows.get(a).createUpdateRow().put("ID_SAISIE_KM_ELEMENT", valsTmp);
|
|
|
170 |
}
|
|
|
171 |
valsTmp.put("ANALYTIQUE", AnalytiqueItemTable.getStringAssocs(valsTmp));
|
|
|
172 |
}
|
|
|
173 |
|
|
|
174 |
valsTmp.commit();
|
18 |
ilm |
175 |
}
|
|
|
176 |
|
73 |
ilm |
177 |
Object[] objTmp = (Object[]) myListEcriture.get(0);
|
|
|
178 |
SQLRow rowEcrTmp = ecrTable.getRow(Integer.parseInt(objTmp[0].toString()));
|
|
|
179 |
vals.put("NOM", rowEcrTmp.getString("NOM"));
|
|
|
180 |
vals.put("DATE", rowEcrTmp.getObject("DATE"));
|
|
|
181 |
vals.put("ID_JOURNAL", rowEcrTmp.getObject("ID_JOURNAL"));
|
18 |
ilm |
182 |
|
73 |
ilm |
183 |
vals.update(idSaisie);
|
|
|
184 |
}
|
18 |
ilm |
185 |
|
73 |
ilm |
186 |
SQLTable mouvementTable = base.getTable("MOUVEMENT");
|
|
|
187 |
SQLRow rowMvt = mouvementTable.getRow(idMvt);
|
18 |
ilm |
188 |
|
73 |
ilm |
189 |
if ((rowMvt.getString("SOURCE").trim().length() == 0) || (rowMvt.getInt("IDSOURCE") == 1)) {
|
|
|
190 |
SQLRowValues valsMouvement = new SQLRowValues(mouvementTable);
|
|
|
191 |
valsMouvement.put("SOURCE", "SAISIE_KM");
|
|
|
192 |
valsMouvement.put("IDSOURCE", new Integer(rowSaisieKm.getID()));
|
|
|
193 |
valsMouvement.update(idMvt);
|
18 |
ilm |
194 |
}
|
73 |
ilm |
195 |
|
18 |
ilm |
196 |
return idSaisie;
|
|
|
197 |
}
|
|
|
198 |
|
|
|
199 |
public static void loadContrePassation(SQLComponent comp, int idMvt) {
|
|
|
200 |
SaisieKmComponent compKm = (SaisieKmComponent) comp;
|
|
|
201 |
compKm.loadContrepassation(idMvt);
|
|
|
202 |
}
|
|
|
203 |
|
|
|
204 |
class SaisieKmComponent extends BaseSQLComponent {
|
|
|
205 |
|
|
|
206 |
private JTextField textNom;
|
|
|
207 |
private JDate date;
|
|
|
208 |
private RowValuesTableModel model;
|
|
|
209 |
private ElementComboBox comboJrnl;
|
|
|
210 |
private JLabel labelTotalDebit;
|
|
|
211 |
private JLabel labelTotalCredit;
|
|
|
212 |
private long totalCred;
|
|
|
213 |
private long totalDeb;
|
|
|
214 |
private int debitIndex, creditIndex;
|
|
|
215 |
private JCheckBox checkCreateCompte;
|
73 |
ilm |
216 |
private JCheckBox checkCreateLineAuto;
|
18 |
ilm |
217 |
private boolean isCompteExist = false;
|
|
|
218 |
private boolean allLineValid = true;
|
|
|
219 |
private SaisieKmItemTable tableKm;
|
21 |
ilm |
220 |
private final JLabel labelMotifWarning = new JLabelWarning();
|
18 |
ilm |
221 |
private SQLElement eltKmItem = Configuration.getInstance().getDirectory().getElement("SAISIE_KM_ELEMENT");
|
|
|
222 |
private SQLRowValues defaultEcritureRowVals = new SQLRowValues(UndefinedRowValuesCache.getInstance().getDefaultRowValues(this.eltKmItem.getTable()));
|
|
|
223 |
|
21 |
ilm |
224 |
// depends on inner table, at creation it's empty and thus valid
|
|
|
225 |
private ValidState validState = ValidState.getTrueInstance();
|
|
|
226 |
|
83 |
ilm |
227 |
private ValidState validStateCloture = ValidState.getTrueInstance();
|
|
|
228 |
private final SQLRow rowExercice = ComptaPropsConfiguration.getInstanceCompta().getRowSociete().getForeign("ID_EXERCICE_COMMON");
|
|
|
229 |
|
18 |
ilm |
230 |
private TableModelListener tableListener = new TableModelListener() {
|
|
|
231 |
public void tableChanged(TableModelEvent e) {
|
21 |
ilm |
232 |
SaisieKmComponent.this.tableChanged(e);
|
18 |
ilm |
233 |
}
|
|
|
234 |
};
|
|
|
235 |
|
|
|
236 |
public SaisieKmComponent() {
|
|
|
237 |
super(SaisieKmSQLElement.this);
|
|
|
238 |
}
|
|
|
239 |
|
|
|
240 |
public void addViews() {
|
|
|
241 |
|
|
|
242 |
this.setLayout(new GridBagLayout());
|
|
|
243 |
|
|
|
244 |
GridBagConstraints c = new DefaultGridBagConstraints();
|
|
|
245 |
|
|
|
246 |
this.textNom = new JTextField();
|
|
|
247 |
this.labelTotalCredit = new JLabel("0.00", SwingConstants.RIGHT);
|
|
|
248 |
this.labelTotalDebit = new JLabel("0.00", SwingConstants.RIGHT);
|
80 |
ilm |
249 |
this.date = new JDate();
|
83 |
ilm |
250 |
this.date.addValueListener(new PropertyChangeListener() {
|
18 |
ilm |
251 |
|
83 |
ilm |
252 |
@Override
|
|
|
253 |
public void propertyChange(PropertyChangeEvent evt) {
|
|
|
254 |
Calendar cDeb = rowExercice.getDate("DATE_DEB");
|
|
|
255 |
Calendar cClo = rowExercice.getDate("DATE_CLOTURE");
|
|
|
256 |
if (date.getValue() != null && cDeb.getTime().after(date.getValue())) {
|
|
|
257 |
validStateCloture = new ValidState(false, "La date de saisie doit être supérieure à celle du début de l'exercice!");
|
|
|
258 |
} else if (date.getValue() != null && cClo != null && cClo.getTime().after(date.getValue())) {
|
|
|
259 |
validStateCloture = new ValidState(false, "La date de saisie doit être supérieure à celle de la période de clôture définie dans l'exercice courant!");
|
|
|
260 |
} else {
|
|
|
261 |
validStateCloture = ValidState.getTrueInstance();
|
|
|
262 |
}
|
|
|
263 |
fireValidChange();
|
|
|
264 |
}
|
|
|
265 |
});
|
18 |
ilm |
266 |
this.comboJrnl = new ElementComboBox(false, 20);
|
|
|
267 |
|
|
|
268 |
// Libellé
|
|
|
269 |
this.add(new JLabel("Libellé", SwingConstants.RIGHT), c);
|
|
|
270 |
|
|
|
271 |
c.gridx++;
|
|
|
272 |
c.weightx = 1;
|
|
|
273 |
c.gridwidth = 1;
|
|
|
274 |
this.add(this.textNom, c);
|
|
|
275 |
|
|
|
276 |
// Date
|
|
|
277 |
JLabel labelDate = new JLabel("Date");
|
|
|
278 |
c.gridx++;
|
|
|
279 |
c.weightx = 0;
|
|
|
280 |
c.gridwidth = 1;
|
|
|
281 |
this.add(labelDate, c);
|
|
|
282 |
c.gridx++;
|
|
|
283 |
c.gridwidth = 1;
|
|
|
284 |
this.add(this.date, c);
|
|
|
285 |
|
|
|
286 |
// Journal
|
|
|
287 |
c.gridy++;
|
|
|
288 |
c.gridx = 0;
|
|
|
289 |
c.gridwidth = 1;
|
|
|
290 |
c.weightx = 0;
|
|
|
291 |
this.add(new JLabel("Journal", SwingConstants.RIGHT), c);
|
|
|
292 |
|
|
|
293 |
c.gridx++;
|
|
|
294 |
c.gridwidth = 3;
|
|
|
295 |
c.fill = GridBagConstraints.NONE;
|
|
|
296 |
c.weightx = 1;
|
|
|
297 |
this.add(this.comboJrnl, c);
|
|
|
298 |
|
|
|
299 |
// Km ItemTable
|
|
|
300 |
this.tableKm = new SaisieKmItemTable(this.defaultEcritureRowVals);
|
|
|
301 |
c.gridx = 0;
|
|
|
302 |
c.gridy++;
|
|
|
303 |
c.weightx = 1;
|
|
|
304 |
c.weighty = 1;
|
|
|
305 |
c.gridwidth = GridBagConstraints.REMAINDER;
|
|
|
306 |
c.fill = GridBagConstraints.BOTH;
|
|
|
307 |
this.add(this.tableKm, c);
|
|
|
308 |
|
|
|
309 |
// Initialisation du panel des Totaux
|
|
|
310 |
JPanel panelTotal = new JPanel();
|
|
|
311 |
panelTotal.setLayout(new GridBagLayout());
|
|
|
312 |
panelTotal.setBorder(BorderFactory.createTitledBorder("Totaux"));
|
|
|
313 |
final GridBagConstraints cc = new DefaultGridBagConstraints();
|
|
|
314 |
cc.anchor = GridBagConstraints.EAST;
|
|
|
315 |
|
|
|
316 |
// Total Debit
|
|
|
317 |
cc.fill = GridBagConstraints.NONE;
|
|
|
318 |
panelTotal.add(new JLabel("Débit"), cc);
|
|
|
319 |
cc.fill = GridBagConstraints.HORIZONTAL;
|
|
|
320 |
cc.gridx++;
|
|
|
321 |
cc.weightx = 1;
|
|
|
322 |
panelTotal.add(this.labelTotalDebit, cc);
|
|
|
323 |
|
|
|
324 |
// Total Credit
|
|
|
325 |
cc.gridy++;
|
|
|
326 |
cc.gridx = 0;
|
|
|
327 |
cc.weightx = 0;
|
|
|
328 |
cc.fill = GridBagConstraints.NONE;
|
|
|
329 |
panelTotal.add(new JLabel("Crédit"), cc);
|
|
|
330 |
cc.weightx = 1;
|
|
|
331 |
cc.gridx++;
|
|
|
332 |
cc.fill = GridBagConstraints.HORIZONTAL;
|
|
|
333 |
panelTotal.add(this.labelTotalCredit, cc);
|
|
|
334 |
|
|
|
335 |
// Création auto des comptes
|
|
|
336 |
this.checkCreateCompte = new JCheckBox("Création automatique des comptes");
|
|
|
337 |
|
|
|
338 |
c.gridy++;
|
|
|
339 |
c.gridx = 0;
|
|
|
340 |
c.gridwidth = 2;
|
|
|
341 |
c.weightx = 0;
|
|
|
342 |
c.weighty = 0;
|
|
|
343 |
this.add(this.checkCreateCompte, c);
|
|
|
344 |
|
73 |
ilm |
345 |
// Création de ligne auto
|
|
|
346 |
this.checkCreateLineAuto = new JCheckBox("Ligne de contrepartie automatique");
|
|
|
347 |
c.gridy++;
|
|
|
348 |
this.checkCreateLineAuto.setSelected(true);
|
|
|
349 |
this.add(this.checkCreateLineAuto, c);
|
|
|
350 |
|
18 |
ilm |
351 |
// Ligne : Warning
|
|
|
352 |
|
|
|
353 |
c.gridy++;
|
|
|
354 |
c.weightx = 0;
|
21 |
ilm |
355 |
c.gridwidth = 2;
|
|
|
356 |
this.labelMotifWarning.setText("Le solde des écritures n'est pas nul!");
|
18 |
ilm |
357 |
DefaultGridBagConstraints.lockMinimumSize(this.labelMotifWarning);
|
|
|
358 |
this.add(this.labelMotifWarning, c);
|
|
|
359 |
this.labelMotifWarning.setVisible(false);
|
21 |
ilm |
360 |
c.gridwidth = 1;
|
18 |
ilm |
361 |
|
|
|
362 |
c.gridy--;
|
|
|
363 |
c.gridx = 2;
|
|
|
364 |
|
|
|
365 |
c.anchor = GridBagConstraints.EAST;
|
|
|
366 |
c.weightx = 0;
|
|
|
367 |
c.weighty = 0;
|
|
|
368 |
c.fill = GridBagConstraints.NONE;
|
|
|
369 |
c.gridwidth = 2;
|
|
|
370 |
c.gridheight = 2;
|
|
|
371 |
panelTotal.setPreferredSize(new Dimension(250, panelTotal.getPreferredSize().height));
|
|
|
372 |
DefaultGridBagConstraints.lockMinimumSize(panelTotal);
|
|
|
373 |
this.add(panelTotal, c);
|
|
|
374 |
|
|
|
375 |
this.model = this.tableKm.getModel();
|
|
|
376 |
this.creditIndex = this.model.getColumnIndexForElement(this.tableKm.getCreditElement());
|
|
|
377 |
this.debitIndex = this.model.getColumnIndexForElement(this.tableKm.getDebitElement());
|
|
|
378 |
|
|
|
379 |
// Listeners
|
|
|
380 |
|
|
|
381 |
this.tableKm.getModel().addTableModelListener(this.tableListener);
|
|
|
382 |
|
|
|
383 |
this.addSQLObject(this.textNom, "NOM");
|
|
|
384 |
this.addRequiredSQLObject(this.date, "DATE");
|
|
|
385 |
this.addRequiredSQLObject(this.comboJrnl, "ID_JOURNAL");
|
|
|
386 |
this.comboJrnl.setButtonsVisible(false);
|
|
|
387 |
this.textNom.getDocument().addDocumentListener(new SimpleDocumentListener() {
|
73 |
ilm |
388 |
String previousName = "";
|
18 |
ilm |
389 |
|
|
|
390 |
@Override
|
|
|
391 |
public void update(DocumentEvent e) {
|
|
|
392 |
SaisieKmComponent.this.defaultEcritureRowVals.put("NOM_ECRITURE", SaisieKmComponent.this.textNom.getText());
|
73 |
ilm |
393 |
tableKm.fillEmptyEntryLabel(previousName, textNom.getText());
|
|
|
394 |
previousName = textNom.getText();
|
18 |
ilm |
395 |
}
|
|
|
396 |
});
|
|
|
397 |
|
|
|
398 |
this.checkCreateCompte.addActionListener(new ActionListener() {
|
|
|
399 |
public void actionPerformed(ActionEvent e) {
|
|
|
400 |
SaisieKmComponent.this.tableKm.setCreateAutoActive(SaisieKmComponent.this.checkCreateCompte.isSelected());
|
21 |
ilm |
401 |
updateValidState();
|
18 |
ilm |
402 |
}
|
|
|
403 |
});
|
|
|
404 |
|
|
|
405 |
// Lock (after adding to this *and* after adding to the request since some items
|
|
|
406 |
// initialize themselves when added)
|
|
|
407 |
DefaultGridBagConstraints.lockMinimumSize(this.comboJrnl);
|
|
|
408 |
}
|
|
|
409 |
|
|
|
410 |
public int insert(SQLRow order) {
|
21 |
ilm |
411 |
final int id = super.insert(order);
|
18 |
ilm |
412 |
|
|
|
413 |
this.tableKm.updateField("ID_SAISIE_KM", id);
|
|
|
414 |
|
|
|
415 |
try {
|
21 |
ilm |
416 |
SQLUtils.executeAtomic(Configuration.getInstance().getSystemRoot().getDataSource(), new SQLUtils.SQLFactory<Object>() {
|
|
|
417 |
@Override
|
|
|
418 |
public Object create() throws SQLException {
|
18 |
ilm |
419 |
|
21 |
ilm |
420 |
GenerationMvtSaisieKm gen = new GenerationMvtSaisieKm(id);
|
|
|
421 |
int idMvt = gen.genereMouvement();
|
|
|
422 |
|
|
|
423 |
// maj de l'id du mouvement correspondant
|
|
|
424 |
SQLRowValues valEcriture = new SQLRowValues(SaisieKmSQLElement.this.getTable());
|
|
|
425 |
valEcriture.put("ID_MOUVEMENT", new Integer(idMvt));
|
|
|
426 |
if (valEcriture.getInvalid() == null) {
|
|
|
427 |
|
|
|
428 |
valEcriture.update(id);
|
|
|
429 |
}
|
|
|
430 |
|
|
|
431 |
SQLElement eltMvt = Configuration.getInstance().getDirectory().getElement("MOUVEMENT");
|
|
|
432 |
final SQLRow rowMvt = eltMvt.getTable().getRow(idMvt);
|
|
|
433 |
SwingUtilities.invokeLater(new Runnable() {
|
|
|
434 |
@Override
|
|
|
435 |
public void run() {
|
|
|
436 |
JOptionPane.showMessageDialog(SaisieKmComponent.this, "Numéro de mouvement associé : " + rowMvt.getObject("NUMERO"));
|
|
|
437 |
}
|
|
|
438 |
});
|
|
|
439 |
return null;
|
|
|
440 |
}
|
|
|
441 |
});
|
93 |
ilm |
442 |
this.updateEcriture(getTable().getRow(id));
|
180 |
ilm |
443 |
|
21 |
ilm |
444 |
} catch (SQLException exn) {
|
|
|
445 |
ExceptionHandler.handle("Erreur lors de la création des écritures associées à la saisie au kilometre.", exn);
|
18 |
ilm |
446 |
}
|
180 |
ilm |
447 |
boolean showPropoLettrage = Boolean.valueOf(DefaultNXProps.getInstance().getProperty(ComptabiliteWorkflowPreferencePanel.LETTRAGE_PROPO_KM));
|
|
|
448 |
if (showPropoLettrage) {
|
|
|
449 |
if (id > SQLRow.NONEXISTANT_ID) {
|
|
|
450 |
final SQLRow rowKM = getTable().getRow(id);
|
|
|
451 |
SwingUtilities.invokeLater(new Runnable() {
|
|
|
452 |
|
|
|
453 |
@Override
|
|
|
454 |
public void run() {
|
|
|
455 |
PropoLettrage lettragePropo = new PropoLettrage(getElement().getDirectory().getElement(EcritureSQLElement.class));
|
|
|
456 |
lettragePropo.transfert(rowKM);
|
|
|
457 |
}
|
|
|
458 |
});
|
|
|
459 |
|
|
|
460 |
}
|
|
|
461 |
}
|
18 |
ilm |
462 |
return id;
|
|
|
463 |
}
|
|
|
464 |
|
156 |
ilm |
465 |
@Override
|
|
|
466 |
public Set<String> getPartialResetNames() {
|
|
|
467 |
return null;
|
|
|
468 |
}
|
|
|
469 |
|
18 |
ilm |
470 |
public void loadMouvement(int idMvt) {
|
|
|
471 |
this.tableKm.loadMouvement(idMvt, false);
|
|
|
472 |
}
|
|
|
473 |
|
|
|
474 |
public void loadContrepassation(int idMvt) {
|
|
|
475 |
this.tableKm.loadMouvement(idMvt, true);
|
|
|
476 |
}
|
|
|
477 |
|
|
|
478 |
public void select(SQLRowAccessor r) {
|
|
|
479 |
if (r == null) {
|
|
|
480 |
this.dTemp = this.date.getDate();
|
|
|
481 |
}
|
|
|
482 |
super.select(r);
|
|
|
483 |
if (r != null) {
|
80 |
ilm |
484 |
this.tableKm.insertFrom(r);
|
18 |
ilm |
485 |
}
|
|
|
486 |
}
|
|
|
487 |
|
|
|
488 |
public void update() {
|
|
|
489 |
super.update();
|
|
|
490 |
this.tableKm.updateField("ID_SAISIE_KM", getSelectedID());
|
|
|
491 |
System.err.println("UPDATE ECRITURE");
|
93 |
ilm |
492 |
this.updateEcriture(getElement().getTable().getRow(getSelectedID()));
|
180 |
ilm |
493 |
boolean showPropoLettrage = Boolean.valueOf(DefaultNXProps.getInstance().getProperty(ComptabiliteWorkflowPreferencePanel.LETTRAGE_PROPO_KM));
|
|
|
494 |
if (showPropoLettrage) {
|
|
|
495 |
SQLRow rowKM = getTable().getRow(getSelectedID());
|
|
|
496 |
SwingUtilities.invokeLater(new Runnable() {
|
|
|
497 |
|
|
|
498 |
@Override
|
|
|
499 |
public void run() {
|
|
|
500 |
PropoLettrage lettragePropo = new PropoLettrage(getElement().getDirectory().getElement(EcritureSQLElement.class));
|
|
|
501 |
lettragePropo.transfert(rowKM);
|
|
|
502 |
}
|
|
|
503 |
});
|
|
|
504 |
}
|
18 |
ilm |
505 |
}
|
|
|
506 |
|
|
|
507 |
private Date dTemp = null;
|
|
|
508 |
|
|
|
509 |
@Override
|
|
|
510 |
protected SQLRowValues createDefaults() {
|
80 |
ilm |
511 |
assert SwingUtilities.isEventDispatchThread();
|
18 |
ilm |
512 |
SQLRowValues rowVals = new SQLRowValues(this.getTable());
|
|
|
513 |
|
80 |
ilm |
514 |
if (this.dTemp != null) {
|
|
|
515 |
rowVals.put("DATE", this.dTemp);
|
18 |
ilm |
516 |
}
|
|
|
517 |
this.tableKm.getModel().clearRows();
|
|
|
518 |
this.tableKm.revalidate();
|
|
|
519 |
this.tableKm.repaint();
|
|
|
520 |
|
|
|
521 |
return rowVals;
|
|
|
522 |
}
|
|
|
523 |
|
93 |
ilm |
524 |
public void updateEcriture(final SQLRow rowSaisieKm) {
|
21 |
ilm |
525 |
try {
|
|
|
526 |
SQLUtils.executeAtomic(Configuration.getInstance().getSystemRoot().getDataSource(), new SQLUtils.SQLFactory<Object>() {
|
|
|
527 |
@Override
|
|
|
528 |
public Object create() throws SQLException {
|
18 |
ilm |
529 |
|
21 |
ilm |
530 |
SQLTable ecritureTable = getTable().getBase().getTable("ECRITURE");
|
93 |
ilm |
531 |
SQLElement assocElt = Configuration.getInstance().getDirectory().getElement("ASSOCIATION_ANALYTIQUE");
|
|
|
532 |
final SQLTable tableElt = getTable().getBase().getTable("SAISIE_KM_ELEMENT");
|
|
|
533 |
List<SQLRow> myListKmItem = rowSaisieKm.getReferentRows(tableElt);
|
18 |
ilm |
534 |
|
21 |
ilm |
535 |
List<SQLRow> listEcr = rowSaisieKm.getForeignRow("ID_MOUVEMENT").getReferentRows(ecritureTable);
|
18 |
ilm |
536 |
|
156 |
ilm |
537 |
// Fix bug sur saisie journal qui ne mettait pas l'id mouvement sur la
|
|
|
538 |
// saisie
|
|
|
539 |
boolean fixMvt = false;
|
|
|
540 |
if (myListKmItem != null && rowSaisieKm.isForeignEmpty("ID_MOUVEMENT")) {
|
|
|
541 |
for (SQLRow rowKmElement : myListKmItem) {
|
|
|
542 |
if (!rowKmElement.isForeignEmpty("ID_ECRITURE")) {
|
|
|
543 |
SQLRow rowEcr = rowKmElement.getForeign("ID_ECRITURE");
|
|
|
544 |
if (!rowEcr.isForeignEmpty("ID_MOUVEMENT")) {
|
|
|
545 |
rowSaisieKm.createEmptyUpdateRow().put("ID_MOUVEMENT", rowEcr.getForeignID("ID_MOUVEMENT")).commit();
|
|
|
546 |
rowSaisieKm.fetchValues();
|
|
|
547 |
listEcr = rowSaisieKm.getForeignRow("ID_MOUVEMENT").getReferentRows(ecritureTable);
|
|
|
548 |
fixMvt = true;
|
|
|
549 |
break;
|
|
|
550 |
}
|
|
|
551 |
}
|
|
|
552 |
}
|
|
|
553 |
}
|
93 |
ilm |
554 |
if (myListKmItem != null) {
|
18 |
ilm |
555 |
|
156 |
ilm |
556 |
// Mise à jour du nom de la pièce
|
|
|
557 |
final SQLRow mvt = rowSaisieKm.getForeign("ID_MOUVEMENT");
|
|
|
558 |
final SQLRow piece = mvt.getForeign("ID_PIECE");
|
|
|
559 |
String labelSaisie = rowSaisieKm.getString("NOM");
|
180 |
ilm |
560 |
AccountingRecordsProvider provider = AccountingRecordsProviderManager.get(GenerationMvtSaisieKm.ID);
|
156 |
ilm |
561 |
|
180 |
ilm |
562 |
SQLRowValues rowValsPiece = piece.asRowValues();
|
|
|
563 |
rowValsPiece.put("NOM", (labelSaisie.length() == 0 ? "Saisie au km " : labelSaisie));
|
|
|
564 |
if (provider != null) {
|
|
|
565 |
provider.putPieceLabel(rowSaisieKm, rowValsPiece);
|
|
|
566 |
}
|
|
|
567 |
|
|
|
568 |
rowValsPiece.commit();
|
156 |
ilm |
569 |
// Mise à jour des écritures
|
93 |
ilm |
570 |
for (SQLRow rowKmElement : myListKmItem) {
|
18 |
ilm |
571 |
|
93 |
ilm |
572 |
int idCpt = ComptePCESQLElement.getId(rowKmElement.getString("NUMERO"), rowKmElement.getString("NOM"));
|
18 |
ilm |
573 |
|
93 |
ilm |
574 |
if (rowKmElement.getID() > 1) {
|
21 |
ilm |
575 |
SQLRowValues vals = new SQLRowValues(ecritureTable);
|
|
|
576 |
vals.put("ID_COMPTE_PCE", idCpt);
|
93 |
ilm |
577 |
vals.put("COMPTE_NUMERO", rowKmElement.getString("NUMERO"));
|
|
|
578 |
vals.put("COMPTE_NOM", rowKmElement.getString("NOM"));
|
|
|
579 |
vals.put("DEBIT", rowKmElement.getObject("DEBIT"));
|
|
|
580 |
vals.put("CREDIT", rowKmElement.getObject("CREDIT"));
|
21 |
ilm |
581 |
vals.put("DATE", rowSaisieKm.getObject("DATE"));
|
|
|
582 |
SQLRow rowJournal = rowSaisieKm.getForeignRow("ID_JOURNAL");
|
|
|
583 |
vals.put("ID_JOURNAL", rowJournal.getID());
|
|
|
584 |
vals.put("JOURNAL_NOM", rowJournal.getString("NOM"));
|
|
|
585 |
vals.put("JOURNAL_CODE", rowJournal.getString("CODE"));
|
93 |
ilm |
586 |
vals.put("NOM", rowKmElement.getObject("NOM_ECRITURE"));
|
|
|
587 |
if (tableElt.contains("NOM_PIECE")) {
|
|
|
588 |
vals.put("NOM_PIECE", rowKmElement.getObject("NOM_PIECE"));
|
|
|
589 |
}
|
156 |
ilm |
590 |
|
93 |
ilm |
591 |
if (rowKmElement.getInt("ID_ECRITURE") > 1) {
|
156 |
ilm |
592 |
|
93 |
ilm |
593 |
SQLRow rowTmp = ecritureTable.getRow(rowKmElement.getInt("ID_ECRITURE"));
|
156 |
ilm |
594 |
if (fixMvt) {
|
|
|
595 |
vals.put("ID_MOUVEMENT", rowSaisieKm.getObject("ID_MOUVEMENT"));
|
|
|
596 |
}
|
73 |
ilm |
597 |
if (!rowTmp.getBoolean("VALIDE")) {
|
93 |
ilm |
598 |
vals.update(rowKmElement.getInt("ID_ECRITURE"));
|
73 |
ilm |
599 |
} else {
|
|
|
600 |
System.err.println("Impossible de modifier une ecriture valide");
|
|
|
601 |
}
|
18 |
ilm |
602 |
|
21 |
ilm |
603 |
} else {
|
18 |
ilm |
604 |
|
21 |
ilm |
605 |
vals.put("ID_MOUVEMENT", rowSaisieKm.getObject("ID_MOUVEMENT"));
|
18 |
ilm |
606 |
|
73 |
ilm |
607 |
if (MouvementSQLElement.isEditable(rowSaisieKm.getInt("ID_MOUVEMENT"))) {
|
|
|
608 |
SQLRow rowEcr = vals.insert();
|
93 |
ilm |
609 |
SQLRowValues rowElementVals = rowKmElement.createEmptyUpdateRow();
|
73 |
ilm |
610 |
rowElementVals.put("ID_ECRITURE", rowEcr.getID());
|
93 |
ilm |
611 |
rowKmElement = rowElementVals.update();
|
73 |
ilm |
612 |
}
|
18 |
ilm |
613 |
|
21 |
ilm |
614 |
}
|
18 |
ilm |
615 |
|
93 |
ilm |
616 |
for (SQLRow sqlRow : rowKmElement.getReferentRows(assocElt.getTable())) {
|
|
|
617 |
SQLRowValues rowVals = sqlRow.asRowValues();
|
|
|
618 |
rowVals.put("ID_ECRITURE", rowKmElement.getInt("ID_ECRITURE"));
|
|
|
619 |
rowVals.commit();
|
|
|
620 |
}
|
21 |
ilm |
621 |
List<SQLRow> l = new ArrayList<SQLRow>(listEcr);
|
|
|
622 |
for (SQLRow sqlRow : l) {
|
93 |
ilm |
623 |
if (sqlRow.getID() == rowKmElement.getInt("ID_ECRITURE")) {
|
21 |
ilm |
624 |
listEcr.remove(sqlRow);
|
|
|
625 |
}
|
|
|
626 |
}
|
180 |
ilm |
627 |
|
21 |
ilm |
628 |
}
|
18 |
ilm |
629 |
|
|
|
630 |
}
|
180 |
ilm |
631 |
// Suppression des lettrages déséquilibré (ex : si on modifie un
|
|
|
632 |
// montant d'une écriture lettrée)
|
|
|
633 |
SQLSelect sel = new SQLSelect();
|
|
|
634 |
sel.addSelect(ecritureTable.getField("LETTRAGE"));
|
|
|
635 |
sel.addGroupBy(ecritureTable.getField("LETTRAGE"));
|
|
|
636 |
final TableRef aliasEcrTable = sel.getAlias(ecritureTable);
|
|
|
637 |
final String quoteDebit = new SQLName(aliasEcrTable.getAlias(), "DEBIT").quote();
|
|
|
638 |
final String quoteCredit = new SQLName(aliasEcrTable.getAlias(), "CREDIT").quote();
|
182 |
ilm |
639 |
sel.setWhere(Where.isNotNull(ecritureTable.getField("LETTRAGE")).and(new Where(ecritureTable.getField("LETTRAGE"), "!=", "")));
|
180 |
ilm |
640 |
sel.setHaving(Where.createRaw("SUM (" + quoteCredit + ") != SUM(" + quoteDebit + ")", aliasEcrTable.getField("DEBIT")));
|
|
|
641 |
|
|
|
642 |
List<String> resultBadLettrage = getElement().getTable().getDBSystemRoot().getDataSource().executeCol(sel.asString());
|
|
|
643 |
if (resultBadLettrage != null && !resultBadLettrage.isEmpty()) {
|
182 |
ilm |
644 |
|
180 |
ilm |
645 |
UpdateBuilder update = new UpdateBuilder(ecritureTable);
|
|
|
646 |
update.setObject(ecritureTable.getField("LETTRAGE"), "");
|
|
|
647 |
update.setObject(ecritureTable.getField("DATE_LETTRAGE"), null);
|
|
|
648 |
Where w = new Where(ecritureTable.getField("LETTRAGE"), resultBadLettrage);
|
|
|
649 |
update.setWhere(w);
|
|
|
650 |
getElement().getTable().getDBSystemRoot().getDataSource().execute(update.asString());
|
182 |
ilm |
651 |
|
180 |
ilm |
652 |
}
|
|
|
653 |
|
18 |
ilm |
654 |
}
|
|
|
655 |
|
21 |
ilm |
656 |
if (!listEcr.isEmpty()) {
|
73 |
ilm |
657 |
final EcritureSQLElement e = (EcritureSQLElement) Configuration.getInstance().getDirectory().getElement(ecritureTable);
|
21 |
ilm |
658 |
for (SQLRow sqlRow : listEcr) {
|
73 |
ilm |
659 |
e.archiveEcriture(sqlRow);
|
18 |
ilm |
660 |
}
|
|
|
661 |
}
|
21 |
ilm |
662 |
return null;
|
|
|
663 |
}
|
|
|
664 |
});
|
|
|
665 |
} catch (SQLException exn) {
|
|
|
666 |
ExceptionHandler.handle("Erreur lors de la mise à jour des écritures associées à la saisie au kilometre.", exn);
|
|
|
667 |
}
|
|
|
668 |
}
|
18 |
ilm |
669 |
|
21 |
ilm |
670 |
@Override
|
|
|
671 |
public synchronized ValidState getValidState() {
|
80 |
ilm |
672 |
assert SwingUtilities.isEventDispatchThread();
|
83 |
ilm |
673 |
return super.getValidState().and(this.validState).and(this.validStateCloture);
|
21 |
ilm |
674 |
}
|
|
|
675 |
|
|
|
676 |
private void updateValidState() {
|
80 |
ilm |
677 |
assert SwingUtilities.isEventDispatchThread();
|
21 |
ilm |
678 |
ValidState state = ValidState.create(!this.labelMotifWarning.isVisible(), this.labelMotifWarning.getText());
|
|
|
679 |
if (!this.isCompteExist && !this.checkCreateCompte.isSelected())
|
|
|
680 |
state = state.and(ValidState.createCached(false, "Certains comptes n'existent pas"));
|
|
|
681 |
if (!this.allLineValid)
|
|
|
682 |
state = state.and(ValidState.createCached(false, "Certaines lignes n'ont pas de crédit ni de débit"));
|
|
|
683 |
this.setValidState(state);
|
|
|
684 |
}
|
|
|
685 |
|
|
|
686 |
private void setValidState(final ValidState state) {
|
80 |
ilm |
687 |
assert SwingUtilities.isEventDispatchThread();
|
21 |
ilm |
688 |
if (!state.equals(this.validState)) {
|
|
|
689 |
this.validState = state;
|
|
|
690 |
fireValidChange();
|
|
|
691 |
}
|
|
|
692 |
}
|
|
|
693 |
|
|
|
694 |
private void setTotals(final long totalCred, final long totalDeb) {
|
80 |
ilm |
695 |
assert SwingUtilities.isEventDispatchThread();
|
21 |
ilm |
696 |
this.totalCred = totalCred;
|
|
|
697 |
this.totalDeb = totalDeb;
|
|
|
698 |
this.labelTotalCredit.setText(GestionDevise.currencyToString(this.totalCred));
|
|
|
699 |
this.labelTotalDebit.setText(GestionDevise.currencyToString(this.totalDeb));
|
|
|
700 |
|
|
|
701 |
final long diff = this.totalDeb - this.totalCred;
|
|
|
702 |
final String reason;
|
|
|
703 |
if (diff == 0) {
|
|
|
704 |
reason = null;
|
|
|
705 |
} else if (diff > 0) {
|
|
|
706 |
reason = "Le solde des écritures n'est pas nul! Il manque " + GestionDevise.currencyToString(diff) + " en crédit.";
|
|
|
707 |
} else {
|
|
|
708 |
reason = "Le solde des écritures n'est pas nul! Il manque " + GestionDevise.currencyToString(diff) + " en débit.";
|
|
|
709 |
}
|
|
|
710 |
this.labelMotifWarning.setVisible(reason != null);
|
|
|
711 |
if (reason != null)
|
|
|
712 |
this.labelMotifWarning.setText(reason);
|
|
|
713 |
}
|
|
|
714 |
|
|
|
715 |
private void tableChanged(TableModelEvent e) {
|
80 |
ilm |
716 |
assert SwingUtilities.isEventDispatchThread();
|
132 |
ilm |
717 |
int col = e.getColumn();
|
|
|
718 |
if (e.getType() == TableModelEvent.UPDATE && (col == this.model.getColumnCount() - 1 || col == this.model.getColumnCount() - 2) && e.getFirstRow() >= 0
|
|
|
719 |
&& e.getFirstRow() < this.model.getRowCount()) {
|
|
|
720 |
SQLRowValues rowVals = this.model.getRowValuesAt(e.getFirstRow());
|
|
|
721 |
Long longValue = (Long) this.model.getValueAt(e.getFirstRow(), col);
|
|
|
722 |
if (rowVals.getReferentRows(getTable().getTable("ASSOCIATION_ANALYTIQUE")).size() > 0 && longValue != null && longValue != 0) {
|
|
|
723 |
JOptionPane.showMessageDialog(SwingUtilities.getRootPane(this.labelTotalCredit), "Pensez à mettre à jour la répartition analytique!");
|
|
|
724 |
}
|
|
|
725 |
}
|
|
|
726 |
|
21 |
ilm |
727 |
long totalCred = 0;
|
|
|
728 |
long totalDeb = 0;
|
|
|
729 |
long totalCredWithNoValid = 0;
|
|
|
730 |
long totalDebWithNoValid = 0;
|
|
|
731 |
boolean isCompteExist = true;
|
|
|
732 |
boolean allLineValid = true;
|
|
|
733 |
for (int i = 0; i < this.model.getRowCount(); i++) {
|
|
|
734 |
final boolean rowValid = this.model.isRowValid(i);
|
|
|
735 |
final long fTc = ((Number) this.model.getValueAt(i, this.creditIndex)).longValue();
|
|
|
736 |
final long fTd = ((Number) this.model.getValueAt(i, this.debitIndex)).longValue();
|
|
|
737 |
String numCpt = this.model.getValueAt(i, this.model.getColumnIndexForElement(this.tableKm.getNumeroCompteElement())).toString();
|
|
|
738 |
isCompteExist &= ComptePCESQLElement.isExist(numCpt);
|
|
|
739 |
// see SaisieKmItemTable RowValuesTableModel, one of the values will be zeroed
|
|
|
740 |
if (fTc != 0 && fTd != 0)
|
|
|
741 |
return;
|
|
|
742 |
|
73 |
ilm |
743 |
if (rowValid) {
|
21 |
ilm |
744 |
totalCred += fTc;
|
73 |
ilm |
745 |
totalDeb += fTd;
|
|
|
746 |
}
|
21 |
ilm |
747 |
totalCredWithNoValid += fTc;
|
|
|
748 |
|
|
|
749 |
totalDebWithNoValid += fTd;
|
132 |
ilm |
750 |
|
|
|
751 |
// Les lignes à 0 sont permises
|
21 |
ilm |
752 |
}
|
|
|
753 |
this.tableKm.revalidate();
|
|
|
754 |
this.tableKm.repaint();
|
|
|
755 |
this.isCompteExist = isCompteExist;
|
|
|
756 |
this.allLineValid = allLineValid;
|
|
|
757 |
this.setTotals(totalCred, totalDeb);
|
|
|
758 |
updateValidState();
|
|
|
759 |
|
|
|
760 |
// add a row to balance totals
|
|
|
761 |
final long diffWithNoValid = totalDebWithNoValid - totalCredWithNoValid;
|
|
|
762 |
if (diffWithNoValid != 0) {
|
|
|
763 |
if (diffWithNoValid > 0) {
|
|
|
764 |
this.defaultEcritureRowVals.put("DEBIT", Long.valueOf(0));
|
|
|
765 |
this.defaultEcritureRowVals.put("CREDIT", Long.valueOf(diffWithNoValid));
|
67 |
ilm |
766 |
|
21 |
ilm |
767 |
} else {
|
|
|
768 |
this.defaultEcritureRowVals.put("DEBIT", Long.valueOf(-diffWithNoValid));
|
|
|
769 |
this.defaultEcritureRowVals.put("CREDIT", Long.valueOf(0));
|
73 |
ilm |
770 |
|
18 |
ilm |
771 |
}
|
73 |
ilm |
772 |
if (this.model.isLastRowValid() && checkCreateLineAuto.isSelected()) {
|
|
|
773 |
this.tableKm.getModel().addRow(new SQLRowValues(this.defaultEcritureRowVals));
|
|
|
774 |
}
|
21 |
ilm |
775 |
} else {
|
|
|
776 |
this.defaultEcritureRowVals.put("DEBIT", Long.valueOf(0));
|
|
|
777 |
this.defaultEcritureRowVals.put("CREDIT", Long.valueOf(0));
|
18 |
ilm |
778 |
}
|
|
|
779 |
}
|
21 |
ilm |
780 |
|
18 |
ilm |
781 |
}
|
57 |
ilm |
782 |
|
|
|
783 |
@Override
|
|
|
784 |
protected String createCode() {
|
156 |
ilm |
785 |
return createCodeOfPackage() + ".userentry";
|
57 |
ilm |
786 |
}
|
18 |
ilm |
787 |
}
|