18 |
ilm |
1 |
/*
|
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
|
|
3 |
*
|
|
|
4 |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
|
|
|
5 |
*
|
|
|
6 |
* The contents of this file are subject to the terms of the GNU General Public License Version 3
|
|
|
7 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
|
|
|
8 |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
|
|
|
9 |
* language governing permissions and limitations under the License.
|
|
|
10 |
*
|
|
|
11 |
* When distributing the software, include this License Header Notice in each file.
|
|
|
12 |
*/
|
|
|
13 |
|
|
|
14 |
package org.openconcerto.erp.generationEcritures;
|
|
|
15 |
|
|
|
16 |
import org.openconcerto.erp.core.finance.accounting.element.ComptePCESQLElement;
|
|
|
17 |
import org.openconcerto.erp.core.finance.accounting.element.JournalSQLElement;
|
156 |
ilm |
18 |
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
|
18 |
ilm |
19 |
import org.openconcerto.erp.model.PrixHT;
|
|
|
20 |
import org.openconcerto.erp.model.PrixTTC;
|
|
|
21 |
import org.openconcerto.sql.model.SQLRow;
|
156 |
ilm |
22 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
18 |
ilm |
23 |
import org.openconcerto.sql.model.SQLRowValues;
|
|
|
24 |
import org.openconcerto.sql.model.SQLTable;
|
|
|
25 |
|
|
|
26 |
import java.util.Date;
|
|
|
27 |
|
|
|
28 |
public class GenerationMvtAvoirFournisseur extends GenerationEcritures {
|
|
|
29 |
|
|
|
30 |
private static final String source = "AVOIR_FOURNISSEUR";
|
|
|
31 |
// TODO dans quel journal les ecritures des avoirs? OD?
|
|
|
32 |
private static final Integer journal = Integer.valueOf(JournalSQLElement.ACHATS);
|
|
|
33 |
private int idAvoirFourn;
|
|
|
34 |
private static final SQLTable tablePrefCompte = base.getTable("PREFS_COMPTE");
|
|
|
35 |
private static final SQLRow rowPrefsCompte = tablePrefCompte.getRow(2);
|
|
|
36 |
|
93 |
ilm |
37 |
public GenerationMvtAvoirFournisseur(SQLRow row) {
|
|
|
38 |
this(row, 1);
|
18 |
ilm |
39 |
}
|
|
|
40 |
|
93 |
ilm |
41 |
public GenerationMvtAvoirFournisseur(SQLRow row, int idMvt) {
|
18 |
ilm |
42 |
this.idMvt = idMvt;
|
93 |
ilm |
43 |
this.idAvoirFourn = row.getID();
|
|
|
44 |
setRowAnalytiqueSource(row);
|
18 |
ilm |
45 |
}
|
|
|
46 |
|
73 |
ilm |
47 |
public int genereMouvement() throws Exception {
|
18 |
ilm |
48 |
|
|
|
49 |
SQLTable avoirFournTable = base.getTable("AVOIR_FOURNISSEUR");
|
|
|
50 |
SQLTable fournTable = base.getTable("FOURNISSEUR");
|
|
|
51 |
|
|
|
52 |
SQLRow avoirRow = avoirFournTable.getRow(this.idAvoirFourn);
|
|
|
53 |
SQLRow rowFourn = fournTable.getRow(avoirRow.getInt("ID_FOURNISSEUR"));
|
|
|
54 |
|
|
|
55 |
// Calcul des montants
|
|
|
56 |
PrixTTC prixTTC = new PrixTTC(((Long) avoirRow.getObject("MONTANT_TTC")).longValue());
|
|
|
57 |
PrixHT prixHT = new PrixHT(((Long) avoirRow.getObject("MONTANT_HT")).longValue());
|
|
|
58 |
PrixHT prixTVA = new PrixHT(((Long) avoirRow.getObject("MONTANT_TVA")).longValue());
|
|
|
59 |
|
|
|
60 |
// iniatilisation des valeurs de la map
|
|
|
61 |
this.date = (Date) avoirRow.getObject("DATE");
|
|
|
62 |
this.nom = avoirRow.getObject("NOM").toString();
|
149 |
ilm |
63 |
this.putValue("DATE", new java.sql.Date(this.date.getTime()));
|
|
|
64 |
this.putValue("NOM", "Avoir fournisseur : " + avoirRow.getString("NUMERO") + " " + rowFourn.getString("NOM"));
|
|
|
65 |
this.putValue("ID_JOURNAL", GenerationMvtAvoirFournisseur.journal);
|
|
|
66 |
this.putValue("ID_MOUVEMENT", Integer.valueOf(1));
|
177 |
ilm |
67 |
if (rowFourn.getTable().getTable("ECRITURE").contains("CODE_CLIENT")) {
|
|
|
68 |
this.putValue("CODE_CLIENT", rowFourn.getString("CODE"));
|
|
|
69 |
}
|
18 |
ilm |
70 |
// on cree un nouveau mouvement
|
|
|
71 |
if (this.idMvt == 1) {
|
|
|
72 |
getNewMouvement(GenerationMvtAvoirFournisseur.source, this.idAvoirFourn, 1, "Avoir Fournisseur : " + avoirRow.getString("NUMERO"));
|
|
|
73 |
} else {
|
149 |
ilm |
74 |
this.putValue("ID_MOUVEMENT", Integer.valueOf(this.idMvt));
|
18 |
ilm |
75 |
}
|
|
|
76 |
|
|
|
77 |
// generation des ecritures + maj des totaux du compte associe
|
|
|
78 |
|
|
|
79 |
// compte Achat
|
|
|
80 |
int idCompteAchat = avoirRow.getInt("ID_COMPTE_PCE");
|
|
|
81 |
|
|
|
82 |
if (idCompteAchat <= 1) {
|
|
|
83 |
idCompteAchat = rowPrefsCompte.getInt("ID_COMPTE_PCE_ACHAT");
|
|
|
84 |
if (idCompteAchat <= 1) {
|
|
|
85 |
try {
|
|
|
86 |
idCompteAchat = ComptePCESQLElement.getIdComptePceDefault("Achats");
|
|
|
87 |
} catch (Exception e) {
|
|
|
88 |
e.printStackTrace();
|
|
|
89 |
}
|
|
|
90 |
}
|
|
|
91 |
}
|
177 |
ilm |
92 |
|
149 |
ilm |
93 |
this.putValue("ID_COMPTE_PCE", Integer.valueOf(idCompteAchat));
|
|
|
94 |
this.putValue("DEBIT", Long.valueOf(0));
|
|
|
95 |
this.putValue("CREDIT", Long.valueOf(prixHT.getLongValue()));
|
93 |
ilm |
96 |
SQLRow rowEcr = ajoutEcriture();
|
|
|
97 |
// addAssocAnalytiqueFromProvider(rowEcr, avoirRow);
|
18 |
ilm |
98 |
|
156 |
ilm |
99 |
SQLRowAccessor taxe = TaxeCache.getCache().getRowFromId(avoirRow.getForeignID("ID_TAXE"));
|
73 |
ilm |
100 |
if (prixTVA.getLongValue() > 0) {
|
|
|
101 |
// compte TVA
|
|
|
102 |
int idCompteTVA = rowPrefsCompte.getInt("ID_COMPTE_PCE_TVA_ACHAT");
|
|
|
103 |
if (avoirRow.getBoolean("IMMO")) {
|
|
|
104 |
idCompteTVA = rowPrefsCompte.getInt("ID_COMPTE_PCE_TVA_IMMO");
|
|
|
105 |
if (idCompteTVA <= 1) {
|
|
|
106 |
idCompteTVA = ComptePCESQLElement.getIdComptePceDefault("TVAImmo");
|
18 |
ilm |
107 |
}
|
73 |
ilm |
108 |
} else {
|
156 |
ilm |
109 |
if (rowFourn.getBoolean("UE")) {
|
|
|
110 |
idCompteTVA = taxe.getForeignID("ID_COMPTE_PCE_DED_INTRA");
|
|
|
111 |
if (idCompteTVA <= 1) {
|
|
|
112 |
idCompteTVA = rowPrefsCompte.getInt("ID_COMPTE_PCE_TVA_INTRA");
|
|
|
113 |
if (idCompteTVA <= 1) {
|
|
|
114 |
idCompteTVA = ComptePCESQLElement.getIdComptePceDefault("TVAIntraComm");
|
|
|
115 |
}
|
|
|
116 |
}
|
|
|
117 |
} else {
|
|
|
118 |
idCompteTVA = rowPrefsCompte.getInt("ID_COMPTE_PCE_TVA_ACHAT");
|
|
|
119 |
if (idCompteTVA <= 1) {
|
|
|
120 |
idCompteTVA = ComptePCESQLElement.getIdComptePceDefault("TVADeductible");
|
|
|
121 |
}
|
73 |
ilm |
122 |
}
|
|
|
123 |
}
|
18 |
ilm |
124 |
|
149 |
ilm |
125 |
this.putValue("ID_COMPTE_PCE", Integer.valueOf(idCompteTVA));
|
|
|
126 |
this.putValue("DEBIT", Long.valueOf(0));
|
|
|
127 |
this.putValue("CREDIT", Long.valueOf(prixTVA.getLongValue()));
|
73 |
ilm |
128 |
ajoutEcriture();
|
18 |
ilm |
129 |
|
73 |
ilm |
130 |
if (rowFourn.getBoolean("UE")) {
|
156 |
ilm |
131 |
int idCompteTVAIntra = taxe.getForeignID("ID_COMPTE_PCE_COLLECTE_INTRA");
|
73 |
ilm |
132 |
if (idCompteTVAIntra <= 1) {
|
156 |
ilm |
133 |
idCompteTVAIntra = rowPrefsCompte.getInt("ID_COMPTE_PCE_TVA_INTRA");
|
|
|
134 |
if (idCompteTVAIntra <= 1) {
|
|
|
135 |
idCompteTVAIntra = ComptePCESQLElement.getIdComptePceDefault("TVAIntraComm");
|
|
|
136 |
}
|
18 |
ilm |
137 |
}
|
149 |
ilm |
138 |
this.putValue("ID_COMPTE_PCE", Integer.valueOf(idCompteTVAIntra));
|
|
|
139 |
this.putValue("DEBIT", Long.valueOf(prixTVA.getLongValue()));
|
|
|
140 |
this.putValue("CREDIT", Long.valueOf(0));
|
73 |
ilm |
141 |
ajoutEcriture();
|
18 |
ilm |
142 |
}
|
73 |
ilm |
143 |
}
|
|
|
144 |
// compte Fournisseur
|
|
|
145 |
int idCompteFourn = rowFourn.getInt("ID_COMPTE_PCE");
|
|
|
146 |
if (idCompteFourn <= 1) {
|
|
|
147 |
idCompteFourn = rowPrefsCompte.getInt("ID_COMPTE_PCE_FOURNISSEUR");
|
18 |
ilm |
148 |
if (idCompteFourn <= 1) {
|
73 |
ilm |
149 |
idCompteFourn = ComptePCESQLElement.getIdComptePceDefault("Fournisseurs");
|
18 |
ilm |
150 |
}
|
73 |
ilm |
151 |
}
|
149 |
ilm |
152 |
this.putValue("ID_COMPTE_PCE", Integer.valueOf(idCompteFourn));
|
|
|
153 |
this.putValue("DEBIT", Long.valueOf(prixTTC.getLongValue()));
|
|
|
154 |
this.putValue("CREDIT", Long.valueOf(0));
|
73 |
ilm |
155 |
ajoutEcriture();
|
18 |
ilm |
156 |
|
73 |
ilm |
157 |
// Mise à jour de mouvement associé à la facture d'avoir
|
|
|
158 |
SQLRowValues valAvoir = new SQLRowValues(avoirFournTable);
|
|
|
159 |
valAvoir.put("ID_MOUVEMENT", Integer.valueOf(this.idMvt));
|
18 |
ilm |
160 |
|
73 |
ilm |
161 |
if (valAvoir.getInvalid() == null) {
|
18 |
ilm |
162 |
|
73 |
ilm |
163 |
valAvoir.update(this.idAvoirFourn);
|
80 |
ilm |
164 |
displayMvtNumber();
|
73 |
ilm |
165 |
}
|
18 |
ilm |
166 |
|
73 |
ilm |
167 |
// if (avoirRow.getInt("ID_MODE_REGLEMENT") > 1) {
|
|
|
168 |
// new GenerationMvtReglementAvoir(this.idAvoirFourn, this.idMvt);
|
|
|
169 |
// } else {
|
|
|
170 |
// valAvoir.put("SOLDE", Boolean.FALSE);
|
|
|
171 |
// try {
|
|
|
172 |
// valAvoir.update(this.idAvoirClient);
|
|
|
173 |
// } catch (SQLException e) {
|
|
|
174 |
// e.printStackTrace();
|
|
|
175 |
// }
|
|
|
176 |
// }
|
18 |
ilm |
177 |
|
|
|
178 |
return this.idMvt;
|
|
|
179 |
}
|
|
|
180 |
}
|