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