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.generationEcritures;
|
14 |
package org.openconcerto.erp.generationEcritures;
|
15 |
|
15 |
|
16 |
import org.openconcerto.erp.core.finance.accounting.element.ComptePCESQLElement;
|
16 |
import org.openconcerto.erp.core.finance.accounting.element.ComptePCESQLElement;
|
- |
|
17 |
import org.openconcerto.erp.generationEcritures.provider.AccountingRecordsProvider;
|
- |
|
18 |
import org.openconcerto.erp.generationEcritures.provider.AccountingRecordsProviderManager;
|
17 |
import org.openconcerto.sql.Configuration;
|
19 |
import org.openconcerto.sql.Configuration;
|
18 |
import org.openconcerto.sql.model.SQLRow;
|
20 |
import org.openconcerto.sql.model.SQLRow;
|
19 |
import org.openconcerto.sql.model.SQLRowValues;
|
21 |
import org.openconcerto.sql.model.SQLRowValues;
|
20 |
import org.openconcerto.sql.model.SQLTable;
|
22 |
import org.openconcerto.sql.model.SQLTable;
|
21 |
|
23 |
|
22 |
import java.sql.SQLException;
|
24 |
import java.sql.SQLException;
|
23 |
import java.util.Date;
|
25 |
import java.util.Date;
|
24 |
import java.util.List;
|
26 |
import java.util.List;
|
25 |
|
27 |
|
26 |
public class GenerationMvtSaisieKm extends GenerationEcritures {
|
28 |
public class GenerationMvtSaisieKm extends GenerationEcritures {
|
27 |
|
29 |
|
28 |
private int idSaisieKm;
|
30 |
private int idSaisieKm;
|
29 |
private static final String source = "SAISIE_KM";
|
31 |
private static final String source = "SAISIE_KM";
|
30 |
|
32 |
|
- |
|
33 |
public static final String ID = "accounting.records.km";
|
- |
|
34 |
|
31 |
public GenerationMvtSaisieKm(int idSaisieKm) {
|
35 |
public GenerationMvtSaisieKm(int idSaisieKm) {
|
32 |
this.idSaisieKm = idSaisieKm;
|
36 |
this.idSaisieKm = idSaisieKm;
|
33 |
}
|
37 |
}
|
34 |
|
38 |
|
35 |
public int genereMouvement() throws SQLException {
|
39 |
public int genereMouvement() throws SQLException {
|
36 |
|
40 |
|
37 |
final SQLTable table = base.getTable("SAISIE_KM");
|
41 |
final SQLTable table = base.getTable("SAISIE_KM");
|
38 |
SQLRow saisieRow = table.getRow(this.idSaisieKm);
|
42 |
SQLRow saisieRow = table.getRow(this.idSaisieKm);
|
39 |
|
43 |
|
40 |
// iniatilisation des valeurs de la map
|
44 |
// iniatilisation des valeurs de la map
|
41 |
this.date = (Date) saisieRow.getObject("DATE");
|
45 |
this.date = (Date) saisieRow.getObject("DATE");
|
42 |
final String labelSaisie = saisieRow.getObject("NOM").toString();
|
46 |
final String labelSaisie = saisieRow.getObject("NOM").toString();
|
43 |
this.nom = labelSaisie;
|
47 |
this.nom = labelSaisie;
|
44 |
this.putValue("DATE", this.date);
|
48 |
this.putValue("DATE", this.date);
|
45 |
this.putValue("NOM", this.nom);
|
49 |
this.putValue("NOM", this.nom);
|
46 |
this.putValue("ID_JOURNAL", saisieRow.getObject("ID_JOURNAL"));
|
50 |
this.putValue("ID_JOURNAL", saisieRow.getObject("ID_JOURNAL"));
|
47 |
this.putValue("ID_MOUVEMENT", new Integer(1));
|
51 |
this.putValue("ID_MOUVEMENT", new Integer(1));
|
48 |
|
52 |
|
49 |
// on calcule le nouveau numero de mouvement
|
53 |
// on calcule le nouveau numero de mouvement
|
- |
|
54 |
AccountingRecordsProvider provider = AccountingRecordsProviderManager.get(ID);
|
- |
|
55 |
SQLRowValues rowValsPiece = new SQLRowValues(pieceTable);
|
- |
|
56 |
rowValsPiece.put("NOM", (labelSaisie.length() == 0 ? "Saisie au km " : labelSaisie));
|
- |
|
57 |
if (provider != null) {
|
- |
|
58 |
provider.putPieceLabel(saisieRow, rowValsPiece);
|
- |
|
59 |
}
|
- |
|
60 |
|
50 |
getNewMouvement(GenerationMvtSaisieKm.source, this.idSaisieKm, 1, (labelSaisie.length() == 0 ? "Saisie au km " : labelSaisie));
|
61 |
getNewMouvement(GenerationMvtSaisieKm.source, this.idSaisieKm, 1, rowValsPiece);
|
51 |
|
62 |
|
52 |
// gnération des ecritures
|
63 |
// gnération des ecritures
|
53 |
SQLTable tableElt = Configuration.getInstance().getRoot().findTable("SAISIE_KM_ELEMENT");
|
64 |
SQLTable tableElt = Configuration.getInstance().getRoot().findTable("SAISIE_KM_ELEMENT");
|
54 |
List<SQLRow> set = saisieRow.getReferentRows(tableElt);
|
65 |
List<SQLRow> set = saisieRow.getReferentRows(tableElt);
|
55 |
|
66 |
|
56 |
SQLTable tableAssoc = Configuration.getInstance().getRoot().findTable("ASSOCIATION_ANALYTIQUE");
|
67 |
SQLTable tableAssoc = Configuration.getInstance().getRoot().findTable("ASSOCIATION_ANALYTIQUE");
|
57 |
|
68 |
|
58 |
for (SQLRow rowElement : set) {
|
69 |
for (SQLRow rowElement : set) {
|
59 |
|
70 |
|
60 |
int idCpt = ComptePCESQLElement.getId(rowElement.getString("NUMERO"), rowElement.getString("NOM"));
|
71 |
int idCpt = ComptePCESQLElement.getId(rowElement.getString("NUMERO"), rowElement.getString("NOM"));
|
61 |
|
72 |
|
62 |
// Ajout de l'écriture
|
73 |
// Ajout de l'écriture
|
63 |
this.putValue("ID_COMPTE_PCE", new Integer(idCpt));
|
74 |
this.putValue("ID_COMPTE_PCE", new Integer(idCpt));
|
64 |
this.putValue("NOM", rowElement.getString("NOM_ECRITURE"));
|
75 |
this.putValue("NOM", rowElement.getString("NOM_ECRITURE"));
|
65 |
this.putValue("DEBIT", rowElement.getObject("DEBIT"));
|
76 |
this.putValue("DEBIT", rowElement.getObject("DEBIT"));
|
66 |
this.putValue("CREDIT", rowElement.getObject("CREDIT"));
|
77 |
this.putValue("CREDIT", rowElement.getObject("CREDIT"));
|
67 |
if (tableElt.contains("NOM_PIECE")) {
|
78 |
if (tableElt.contains("NOM_PIECE")) {
|
68 |
this.putValue("NOM_PIECE", rowElement.getObject("NOM_PIECE"));
|
79 |
this.putValue("NOM_PIECE", rowElement.getObject("NOM_PIECE"));
|
69 |
}
|
80 |
}
|
70 |
SQLRow rowEcr = ajoutEcriture();
|
81 |
SQLRow rowEcr = ajoutEcriture();
|
71 |
|
82 |
|
72 |
// List<SQLRow> assocs = rowElement.getReferentRows(tableAssoc);
|
83 |
// List<SQLRow> assocs = rowElement.getReferentRows(tableAssoc);
|
73 |
// for (SQLRow sqlRow : assocs) {
|
84 |
// for (SQLRow sqlRow : assocs) {
|
74 |
// if (!sqlRow.isUndefined()) {
|
85 |
// if (!sqlRow.isUndefined()) {
|
75 |
// addAssocAnalytique(rowEcr, sqlRow.getInt("ID_POSTE_ANALYTIQUE"));
|
86 |
// addAssocAnalytique(rowEcr, sqlRow.getInt("ID_POSTE_ANALYTIQUE"));
|
76 |
// }
|
87 |
// }
|
77 |
// }
|
88 |
// }
|
78 |
|
89 |
|
79 |
// Mise à jour de la clef étrangère écriture de l'élément saisie au km
|
90 |
// Mise à jour de la clef étrangère écriture de l'élément saisie au km
|
80 |
if (rowEcr != null && !rowEcr.isUndefined()) {
|
91 |
if (rowEcr != null && !rowEcr.isUndefined()) {
|
81 |
SQLRowValues vals = rowElement.createEmptyUpdateRow();
|
92 |
SQLRowValues vals = rowElement.createEmptyUpdateRow();
|
82 |
vals.put("ID_ECRITURE", rowEcr.getID());
|
93 |
vals.put("ID_ECRITURE", rowEcr.getID());
|
83 |
vals.update();
|
94 |
vals.update();
|
84 |
}
|
95 |
}
|
85 |
}
|
96 |
}
|
86 |
|
97 |
|
87 |
return this.idMvt;
|
98 |
return this.idMvt;
|
88 |
}
|
99 |
}
|
89 |
}
|
100 |
}
|