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.generationEcritures;
|
|
|
15 |
|
67 |
ilm |
16 |
import org.openconcerto.erp.core.common.ui.TotalCalculator;
|
18 |
ilm |
17 |
import org.openconcerto.erp.core.finance.accounting.element.ComptePCESQLElement;
|
|
|
18 |
import org.openconcerto.erp.core.finance.accounting.element.JournalSQLElement;
|
185 |
ilm |
19 |
import org.openconcerto.erp.core.finance.payment.element.TypeReglementSQLElement;
|
|
|
20 |
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
|
94 |
ilm |
21 |
import org.openconcerto.erp.generationDoc.SheetXml;
|
67 |
ilm |
22 |
import org.openconcerto.erp.generationEcritures.provider.AccountingRecordsProvider;
|
|
|
23 |
import org.openconcerto.erp.generationEcritures.provider.AccountingRecordsProviderManager;
|
18 |
ilm |
24 |
import org.openconcerto.erp.model.PrixTTC;
|
185 |
ilm |
25 |
import org.openconcerto.erp.preferences.DefaultNXProps;
|
|
|
26 |
import org.openconcerto.erp.preferences.GestionCommercialeGlobalPreferencePanel;
|
18 |
ilm |
27 |
import org.openconcerto.sql.model.SQLRow;
|
67 |
ilm |
28 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
18 |
ilm |
29 |
import org.openconcerto.sql.model.SQLRowValues;
|
|
|
30 |
import org.openconcerto.sql.model.SQLTable;
|
185 |
ilm |
31 |
import org.openconcerto.sql.preferences.SQLPreferences;
|
|
|
32 |
import org.openconcerto.utils.DecimalUtils;
|
18 |
ilm |
33 |
import org.openconcerto.utils.ExceptionHandler;
|
149 |
ilm |
34 |
import org.openconcerto.utils.StringUtils;
|
18 |
ilm |
35 |
|
67 |
ilm |
36 |
import java.math.BigDecimal;
|
|
|
37 |
import java.math.RoundingMode;
|
18 |
ilm |
38 |
import java.util.Date;
|
|
|
39 |
import java.util.Map;
|
|
|
40 |
|
|
|
41 |
// FIXME probleme lors de certaines generation tout reste figer
|
|
|
42 |
|
|
|
43 |
/**
|
|
|
44 |
* Génération des ecritures associées à une saisie de vente avec facture. Entaine la génération du
|
|
|
45 |
* reglement de la vente
|
|
|
46 |
*/
|
|
|
47 |
public class GenerationMvtSaisieVenteFacture extends GenerationEcritures implements Runnable {
|
|
|
48 |
|
67 |
ilm |
49 |
public static final String ID = "accounting.records.invoice.sales";
|
185 |
ilm |
50 |
public static final String NOT_GEN_ECRITURE = "accounting.invoice.generation.disable";
|
18 |
ilm |
51 |
private static final String source = "SAISIE_VENTE_FACTURE";
|
|
|
52 |
public static final Integer journal = Integer.valueOf(JournalSQLElement.VENTES);
|
|
|
53 |
private int idSaisieVenteFacture;
|
83 |
ilm |
54 |
private boolean useComptePCEVente;
|
18 |
ilm |
55 |
private static final SQLTable saisieVFTable = base.getTable("SAISIE_VENTE_FACTURE");
|
|
|
56 |
private static final SQLTable mvtTable = base.getTable("MOUVEMENT");
|
67 |
ilm |
57 |
private static final SQLTable ecrTable = base.getTable("ECRITURE");
|
18 |
ilm |
58 |
private static final SQLTable tablePrefCompte = base.getTable("PREFS_COMPTE");
|
|
|
59 |
private static final SQLRow rowPrefsCompte = tablePrefCompte.getRow(2);
|
93 |
ilm |
60 |
private final boolean genereReglement;
|
18 |
ilm |
61 |
|
|
|
62 |
/**
|
|
|
63 |
* Generation de la comptabilité associée à la modification d'une saisie de vente facture
|
|
|
64 |
*
|
|
|
65 |
* @param idSaisieVenteFacture
|
|
|
66 |
* @param idMvt id du mouvement qui est dejà associé à la facture
|
|
|
67 |
*/
|
93 |
ilm |
68 |
public GenerationMvtSaisieVenteFacture(int idSaisieVenteFacture, int idMvt, boolean useComptePCEVente, boolean genereReglement) {
|
151 |
ilm |
69 |
this(idSaisieVenteFacture, idMvt, useComptePCEVente, genereReglement, false);
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
public GenerationMvtSaisieVenteFacture(int idSaisieVenteFacture, int idMvt, boolean useComptePCEVente, boolean genereReglement, boolean threadSafe) {
|
18 |
ilm |
73 |
System.err.println("********* init GeneRation");
|
|
|
74 |
this.idMvt = idMvt;
|
|
|
75 |
this.idSaisieVenteFacture = idSaisieVenteFacture;
|
83 |
ilm |
76 |
this.useComptePCEVente = useComptePCEVente;
|
93 |
ilm |
77 |
this.genereReglement = genereReglement;
|
94 |
ilm |
78 |
// Submit in sheetxml queue in order to get the good paiement in document
|
151 |
ilm |
79 |
if (!threadSafe)
|
|
|
80 |
SheetXml.submitInQueue(GenerationMvtSaisieVenteFacture.this);
|
18 |
ilm |
81 |
}
|
|
|
82 |
|
93 |
ilm |
83 |
public GenerationMvtSaisieVenteFacture(int idSaisieVenteFacture, int idMvt, boolean useComptePCEVente) {
|
|
|
84 |
this(idSaisieVenteFacture, idMvt, useComptePCEVente, true);
|
|
|
85 |
}
|
|
|
86 |
|
83 |
ilm |
87 |
public GenerationMvtSaisieVenteFacture(int idSaisieVenteFacture, int idMvt) {
|
93 |
ilm |
88 |
this(idSaisieVenteFacture, idMvt, false, true);
|
83 |
ilm |
89 |
}
|
|
|
90 |
|
18 |
ilm |
91 |
/**
|
|
|
92 |
* Generation de la comptabilité associée à la création d'une saisie de vente facture
|
|
|
93 |
*
|
|
|
94 |
* @param idSaisieVenteFacture
|
|
|
95 |
*/
|
|
|
96 |
public GenerationMvtSaisieVenteFacture(int idSaisieVenteFacture) {
|
151 |
ilm |
97 |
this(idSaisieVenteFacture, false);
|
18 |
ilm |
98 |
}
|
|
|
99 |
|
151 |
ilm |
100 |
public GenerationMvtSaisieVenteFacture(int idSaisieVenteFacture, final boolean threadSafe) {
|
|
|
101 |
this(idSaisieVenteFacture, 1, false, true, threadSafe);
|
|
|
102 |
}
|
18 |
ilm |
103 |
|
151 |
ilm |
104 |
public final void genereMouvement() throws Exception {
|
|
|
105 |
|
18 |
ilm |
106 |
SQLRow saisieRow = GenerationMvtSaisieVenteFacture.saisieVFTable.getRow(this.idSaisieVenteFacture);
|
93 |
ilm |
107 |
setRowAnalytiqueSource(saisieRow);
|
185 |
ilm |
108 |
boolean genEcrDisabled = DefaultNXProps.getInstance().getBooleanValue(GenerationMvtSaisieVenteFacture.NOT_GEN_ECRITURE, false);
|
|
|
109 |
|
|
|
110 |
this.putValue("ID_JOURNAL", GenerationMvtSaisieVenteFacture.journal);
|
18 |
ilm |
111 |
SQLRow clientRow = saisieRow.getForeignRow("ID_CLIENT");
|
65 |
ilm |
112 |
int idCompteClient = clientRow.getInt("ID_COMPTE_PCE");
|
|
|
113 |
|
|
|
114 |
Boolean acompte = saisieRow.getBoolean("ACOMPTE");
|
|
|
115 |
if (acompte != null && acompte) {
|
|
|
116 |
this.nom = "Fact. acompte client" + saisieRow.getObject("NUMERO").toString();
|
|
|
117 |
} else {
|
|
|
118 |
this.nom = "Fact. vente " + saisieRow.getObject("NUMERO").toString();
|
|
|
119 |
}
|
185 |
ilm |
120 |
|
|
|
121 |
boolean typeCaisse = false;
|
|
|
122 |
SQLRow modeRegl = saisieRow.getForeignRow("ID_MODE_REGLEMENT");
|
|
|
123 |
final SQLRow typeRegRow = modeRegl.getForeignRow("ID_TYPE_REGLEMENT");
|
|
|
124 |
final SQLRowAccessor nonEmptyForeign = modeRegl.getNonEmptyForeign("ID_BANQUE");
|
|
|
125 |
if (nonEmptyForeign != null && nonEmptyForeign.getTable().contains("TYPE_CAISSE") && nonEmptyForeign.getBoolean("TYPE_CAISSE")) {
|
|
|
126 |
typeCaisse = true;
|
|
|
127 |
idCompteClient = nonEmptyForeign.getForeignID("ID_COMPTE_PCE");
|
|
|
128 |
Number idJournal = nonEmptyForeign.getNonEmptyForeignIDNumber("ID_JOURNAL");
|
|
|
129 |
if (idJournal != null) {
|
|
|
130 |
this.putValue("ID_JOURNAL", idJournal);
|
|
|
131 |
} else {
|
|
|
132 |
this.putValue("ID_JOURNAL", JournalSQLElement.CAISSES);
|
|
|
133 |
}
|
|
|
134 |
this.nom += " (" + typeRegRow.getString("NOM") + ") " + StringUtils.limitLength(clientRow.getString("NOM"), 20);
|
|
|
135 |
} else {
|
|
|
136 |
this.nom += " " + StringUtils.limitLength(clientRow.getString("NOM"), 20);
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
if (SQLPreferences.getMemCached(saisieRow.getTable().getDBRoot()).getBoolean(GestionCommercialeGlobalPreferencePanel.ECRITURE_FACTURE_REF_LIBELLE, false)) {
|
|
|
140 |
if (saisieRow.getString("NOM") != null && saisieRow.getString("NOM").trim().length() > 0)
|
|
|
141 |
this.nom += " " + StringUtils.limitLength(saisieRow.getString("NOM"), 30);
|
|
|
142 |
}
|
|
|
143 |
|
|
|
144 |
|
|
|
145 |
// Calcul des montants
|
|
|
146 |
PrixTTC prixTTC = new PrixTTC(((Long) saisieRow.getObject("T_TTC")).longValue());
|
|
|
147 |
// Total des acomptes déjà versés sur la facture
|
|
|
148 |
long montantAcompteTTC = 0;
|
|
|
149 |
|
149 |
ilm |
150 |
this.putValue("NOM", this.nom);
|
67 |
ilm |
151 |
|
|
|
152 |
// iniatilisation des valeurs de la map
|
|
|
153 |
this.date = (Date) saisieRow.getObject("DATE");
|
|
|
154 |
AccountingRecordsProvider provider = AccountingRecordsProviderManager.get(ID);
|
|
|
155 |
provider.putLabel(saisieRow, this.mEcritures);
|
|
|
156 |
|
149 |
ilm |
157 |
this.putValue("DATE", this.date);
|
185 |
ilm |
158 |
|
149 |
ilm |
159 |
this.putValue("ID_MOUVEMENT", Integer.valueOf(1));
|
18 |
ilm |
160 |
|
|
|
161 |
// on calcule le nouveau numero de mouvement
|
|
|
162 |
if (this.idMvt == 1) {
|
67 |
ilm |
163 |
SQLRowValues rowValsPiece = new SQLRowValues(pieceTable);
|
|
|
164 |
provider.putPieceLabel(saisieRow, rowValsPiece);
|
|
|
165 |
getNewMouvement(GenerationMvtSaisieVenteFacture.source, this.idSaisieVenteFacture, 1, rowValsPiece);
|
18 |
ilm |
166 |
} else {
|
149 |
ilm |
167 |
this.putValue("ID_MOUVEMENT", Integer.valueOf(this.idMvt));
|
65 |
ilm |
168 |
SQLRowValues rowValsPiece = mvtTable.getRow(idMvt).getForeign("ID_PIECE").asRowValues();
|
67 |
ilm |
169 |
provider.putPieceLabel(saisieRow, rowValsPiece);
|
73 |
ilm |
170 |
rowValsPiece.update();
|
18 |
ilm |
171 |
}
|
|
|
172 |
|
67 |
ilm |
173 |
SQLTable tableEchantillon = null;
|
|
|
174 |
BigDecimal portHT = BigDecimal.valueOf(saisieRow.getLong("PORT_HT")).movePointLeft(2);
|
156 |
ilm |
175 |
BigDecimal fraisDocHT = BigDecimal.valueOf(saisieRow.getLong("FRAIS_DOCUMENT_HT")).movePointLeft(2);
|
182 |
ilm |
176 |
SQLRow taxeDoc = saisieRow.getNonEmptyForeign("ID_TAXE_FRAIS_DOCUMENT") == null ? TaxeCache.getCache().getFirstTaxe()
|
|
|
177 |
: TaxeCache.getCache().getRowFromId(saisieRow.getForeignID("ID_TAXE_FRAIS_DOCUMENT")).asRow();
|
|
|
178 |
|
93 |
ilm |
179 |
TotalCalculator calc;
|
182 |
ilm |
180 |
SQLRow taxePort = saisieRow.getNonEmptyForeign("ID_TAXE_PORT") == null ? TaxeCache.getCache().getFirstTaxe()
|
|
|
181 |
: TaxeCache.getCache().getRowFromId(saisieRow.getForeignID("ID_TAXE_PORT")).asRow();
|
|
|
182 |
|
93 |
ilm |
183 |
if (clientRow.getTable().contains("ID_COMPTE_PCE_PRODUIT") && !clientRow.isForeignEmpty("ID_COMPTE_PCE_PRODUIT")) {
|
182 |
ilm |
184 |
|
|
|
185 |
calc = getValuesFromElement(false, false, "T_PV_HT", saisieRow, saisieVFTable.getTable("SAISIE_VENTE_FACTURE_ELEMENT"), portHT, taxePort, fraisDocHT, taxeDoc, tableEchantillon,
|
|
|
186 |
clientRow.getForeign("ID_COMPTE_PCE_PRODUIT"));
|
93 |
ilm |
187 |
} else {
|
182 |
ilm |
188 |
|
|
|
189 |
calc = getValuesFromElement(saisieRow, saisieVFTable.getTable("SAISIE_VENTE_FACTURE_ELEMENT"), portHT, taxePort, fraisDocHT, taxeDoc, tableEchantillon);
|
93 |
ilm |
190 |
}
|
67 |
ilm |
191 |
|
65 |
ilm |
192 |
// On génére les ecritures si la facture n'est pas un acompte
|
67 |
ilm |
193 |
long ttcLongValue = calc.getTotalTTC().movePointRight(2).longValue();
|
65 |
ilm |
194 |
if (acompte == null || !acompte) {
|
18 |
ilm |
195 |
|
144 |
ilm |
196 |
Map<SQLRowAccessor, Map<SQLRowAccessor, BigDecimal>> taxeCompl = calc.getMapHtTaxeCompl();
|
67 |
ilm |
197 |
for (SQLRowAccessor row : calc.getMapHt().keySet()) {
|
|
|
198 |
long b = calc.getMapHt().get(row).setScale(2, RoundingMode.HALF_UP).movePointRight(2).longValue();
|
|
|
199 |
if (b != 0) {
|
83 |
ilm |
200 |
final Integer idComptePCE;
|
144 |
ilm |
201 |
long taxe = 0;
|
|
|
202 |
|
|
|
203 |
if (taxeCompl.containsKey(row)) {
|
|
|
204 |
Map<SQLRowAccessor, BigDecimal> compl = taxeCompl.get(row);
|
|
|
205 |
for (SQLRowAccessor rowCompl : compl.keySet()) {
|
|
|
206 |
if (compl.get(rowCompl) != null) {
|
|
|
207 |
long taxeC = compl.get(rowCompl).multiply(rowCompl.getBigDecimal("POURCENT").movePointLeft(2)).setScale(2, RoundingMode.HALF_UP).movePointRight(2).longValue();
|
149 |
ilm |
208 |
this.putValue("ID_COMPTE_PCE", rowCompl.getForeignID("ID_COMPTE_PCE"));
|
|
|
209 |
this.putValue("DEBIT", Long.valueOf(0));
|
|
|
210 |
this.putValue("CREDIT", Long.valueOf(taxeC));
|
185 |
ilm |
211 |
if (!genEcrDisabled) {
|
|
|
212 |
ajoutEcriture();
|
|
|
213 |
}
|
144 |
ilm |
214 |
taxe += taxeC;
|
149 |
ilm |
215 |
// this.putValue("ID_COMPTE_PCE",
|
144 |
ilm |
216 |
// rowCompl.getForeignID("ID_COMPTE_PCE_PRODUITS"));
|
149 |
ilm |
217 |
// this.putValue("DEBIT", Long.valueOf(taxeC));
|
|
|
218 |
// this.putValue("CREDIT", Long.valueOf(0));
|
144 |
ilm |
219 |
// ajoutEcriture();
|
|
|
220 |
}
|
|
|
221 |
}
|
|
|
222 |
}
|
|
|
223 |
// TODO check if taxe compl > b
|
83 |
ilm |
224 |
if (this.useComptePCEVente) {
|
|
|
225 |
// Utilise le compte de la facture
|
|
|
226 |
idComptePCE = saisieRow.getInt("ID_COMPTE_PCE_VENTE");
|
|
|
227 |
} else {
|
|
|
228 |
idComptePCE = Integer.valueOf(row.getID());
|
|
|
229 |
}
|
144 |
ilm |
230 |
|
149 |
ilm |
231 |
this.putValue("ID_COMPTE_PCE", idComptePCE);
|
|
|
232 |
this.putValue("DEBIT", Long.valueOf(0));
|
|
|
233 |
this.putValue("CREDIT", Long.valueOf(b - taxe));
|
185 |
ilm |
234 |
if (!genEcrDisabled) {
|
|
|
235 |
ajoutEcriture();
|
|
|
236 |
}
|
18 |
ilm |
237 |
}
|
|
|
238 |
}
|
|
|
239 |
|
67 |
ilm |
240 |
Map<SQLRowAccessor, BigDecimal> tvaMap = calc.getMapHtTVA();
|
|
|
241 |
for (SQLRowAccessor rowAc : tvaMap.keySet()) {
|
|
|
242 |
long longValue = tvaMap.get(rowAc).setScale(2, RoundingMode.HALF_UP).movePointRight(2).longValue();
|
|
|
243 |
if (longValue != 0) {
|
149 |
ilm |
244 |
this.putValue("ID_COMPTE_PCE", rowAc.getID());
|
|
|
245 |
this.putValue("DEBIT", Long.valueOf(0));
|
|
|
246 |
this.putValue("CREDIT", longValue);
|
185 |
ilm |
247 |
if (!genEcrDisabled) {
|
|
|
248 |
ajoutEcriture();
|
|
|
249 |
}
|
18 |
ilm |
250 |
}
|
67 |
ilm |
251 |
}
|
65 |
ilm |
252 |
|
|
|
253 |
// compte Clients
|
18 |
ilm |
254 |
|
|
|
255 |
if (idCompteClient <= 1) {
|
65 |
ilm |
256 |
idCompteClient = rowPrefsCompte.getInt("ID_COMPTE_PCE_CLIENT");
|
|
|
257 |
if (idCompteClient <= 1) {
|
73 |
ilm |
258 |
idCompteClient = ComptePCESQLElement.getIdComptePceDefault("Clients");
|
18 |
ilm |
259 |
}
|
|
|
260 |
}
|
149 |
ilm |
261 |
this.putValue("ID_COMPTE_PCE", Integer.valueOf(idCompteClient));
|
67 |
ilm |
262 |
if (ecrTable.contains("CODE_CLIENT")) {
|
149 |
ilm |
263 |
this.putValue("CODE_CLIENT", clientRow.getString("CODE"));
|
67 |
ilm |
264 |
}
|
149 |
ilm |
265 |
this.putValue("DEBIT", ttcLongValue);
|
|
|
266 |
this.putValue("CREDIT", Long.valueOf(0));
|
185 |
ilm |
267 |
if (!genEcrDisabled) {
|
|
|
268 |
ajoutEcriture();
|
|
|
269 |
}
|
65 |
ilm |
270 |
|
|
|
271 |
// TODO Gestion des factures d'acomptes
|
|
|
272 |
// Solde des acomptes
|
|
|
273 |
// List<SQLRow> rowsAcompte =
|
|
|
274 |
// saisieRow.getReferentRows(saisieVFTable.getField("ID_SAISIE_VENTE_FACTURE_ACOMPTE"));
|
|
|
275 |
// if (rowsAcompte != null && rowsAcompte.size() > 0) {
|
|
|
276 |
// // Compte acompte
|
|
|
277 |
// int idCompteAcompteClient = ComptePCESQLElement.getId("4191",
|
|
|
278 |
// "Clients - Avances et acomptes reçus sur commandes");
|
|
|
279 |
// int idTVAAcompte = ComptePCESQLElement.getId("44587",
|
|
|
280 |
// "Taxes sur le chiffre d'affaire à régulariser ou en attente");
|
|
|
281 |
// for (SQLRow sqlRow : rowsAcompte) {
|
|
|
282 |
// long acompteTTC = sqlRow.getLong("T_TTC");
|
|
|
283 |
// long acompteHT = sqlRow.getLong("T_HT");
|
149 |
ilm |
284 |
// this.putValue("ID_COMPTE_PCE", Integer.valueOf(idCompteAcompteClient));
|
|
|
285 |
// this.putValue("DEBIT", acompteTTC);
|
|
|
286 |
// this.putValue("CREDIT", Long.valueOf(0));
|
65 |
ilm |
287 |
// ajoutEcriture();
|
149 |
ilm |
288 |
// this.putValue("ID_COMPTE_PCE", Integer.valueOf(idCompteClient));
|
|
|
289 |
// this.putValue("DEBIT", Long.valueOf(0));
|
|
|
290 |
// this.putValue("CREDIT", acompteTTC);
|
65 |
ilm |
291 |
// ajoutEcriture();
|
|
|
292 |
//
|
|
|
293 |
// montantAcompteTTC += acompteTTC;
|
|
|
294 |
//
|
|
|
295 |
// long tva = acompteTTC - acompteHT;
|
|
|
296 |
// if (tva > 0) {
|
|
|
297 |
//
|
|
|
298 |
//
|
149 |
ilm |
299 |
// this.putValue("ID_COMPTE_PCE", Integer.valueOf(idTVAAcompte));
|
|
|
300 |
// this.putValue("DEBIT", Long.valueOf(0));
|
|
|
301 |
// this.putValue("CREDIT", Long.valueOf(tva));
|
65 |
ilm |
302 |
// ajoutEcriture();
|
|
|
303 |
//
|
|
|
304 |
// Map<Integer, Long> m = getMultiTVAFromRow(saisieRow,
|
|
|
305 |
// saisieVFTable.getTable("SAISIE_VENTE_FACTURE_ELEMENT"), true);
|
|
|
306 |
// long allTaxe = 0;
|
|
|
307 |
// for (Integer i : m.keySet()) {
|
|
|
308 |
// Long l = m.get(i);
|
|
|
309 |
// if (l != null && l > 0) {
|
|
|
310 |
// // FIXME
|
|
|
311 |
// int idCpt = i;
|
|
|
312 |
// if (idCpt <= 1) {
|
|
|
313 |
// idCpt = idCompteTVA;
|
|
|
314 |
// }
|
149 |
ilm |
315 |
// this.putValue("ID_COMPTE_PCE", Integer.valueOf(idCpt));
|
|
|
316 |
// this.putValue("DEBIT", Long.valueOf(0));
|
|
|
317 |
// this.putValue("CREDIT", Long.valueOf(l));
|
65 |
ilm |
318 |
// ajoutEcriture();
|
|
|
319 |
// allTaxe += l;
|
|
|
320 |
// }
|
|
|
321 |
// }
|
|
|
322 |
// if (allTaxe < prixTVA.getLongValue()) {
|
149 |
ilm |
323 |
// this.putValue("ID_COMPTE_PCE", Integer.valueOf(idCompteTVA));
|
|
|
324 |
// this.putValue("DEBIT", Long.valueOf(0));
|
|
|
325 |
// this.putValue("CREDIT", Long.valueOf(prixTVA.getLongValue() - allTaxe));
|
65 |
ilm |
326 |
// ajoutEcriture();
|
|
|
327 |
// }
|
|
|
328 |
//
|
149 |
ilm |
329 |
// this.putValue("ID_COMPTE_PCE", Integer.valueOf(compteDebitTvaAcompte));
|
|
|
330 |
// this.putValue("DEBIT", Long.valueOf(tva));
|
|
|
331 |
// this.putValue("CREDIT", Long.valueOf(0));
|
65 |
ilm |
332 |
// ajoutEcriture();
|
|
|
333 |
// }
|
|
|
334 |
// }
|
|
|
335 |
// }
|
18 |
ilm |
336 |
}
|
73 |
ilm |
337 |
|
|
|
338 |
{
|
|
|
339 |
SQLRowValues valSasieVF = new SQLRowValues(GenerationMvtSaisieVenteFacture.saisieVFTable);
|
|
|
340 |
valSasieVF.put("DATE_REGLEMENT", null);
|
|
|
341 |
valSasieVF.update(this.idSaisieVenteFacture);
|
|
|
342 |
}
|
|
|
343 |
|
93 |
ilm |
344 |
if (genereReglement) {
|
|
|
345 |
// Génération du reglement
|
185 |
ilm |
346 |
|
|
|
347 |
String label = this.nom + " (" + typeRegRow.getString("NOM") + ") ";
|
93 |
ilm |
348 |
int idAvoir = saisieRow.getInt("ID_AVOIR_CLIENT");
|
|
|
349 |
if (idAvoir > 1) {
|
|
|
350 |
// SQLRow avoirRow = base.getTable("AVOIR_CLIENT").getRow(idAvoir);
|
|
|
351 |
long l = ((Number) saisieRow.getObject("T_AVOIR_TTC")).longValue();
|
|
|
352 |
prixTTC = new PrixTTC(((Long) saisieRow.getObject("T_TTC")).longValue() - l);
|
|
|
353 |
}
|
185 |
ilm |
354 |
final long totalNet = saisieRow.getLong("NET_A_PAYER");
|
|
|
355 |
final SQLRow rowClient;
|
|
|
356 |
final SQLRow rowCptTiers;
|
|
|
357 |
if (typeCaisse) {
|
|
|
358 |
rowClient = null;
|
|
|
359 |
rowCptTiers = modeRegl.getForeign("ID_BANQUE").getForeign("ID_COMPTE_PCE");
|
|
|
360 |
} else {
|
|
|
361 |
rowClient = clientRow;
|
|
|
362 |
rowCptTiers = null;
|
93 |
ilm |
363 |
}
|
185 |
ilm |
364 |
final String tiers = clientRow.getString("NOM");
|
|
|
365 |
|
|
|
366 |
if (saisieRow.contains("POURCENT_RG") && saisieRow.getBigDecimal("POURCENT_RG") != null && saisieRow.getBigDecimal("POURCENT_RG").signum() != 0) {
|
|
|
367 |
long totalRG = new BigDecimal(totalNet).multiply(saisieRow.getBigDecimal("POURCENT_RG"), DecimalUtils.HIGH_PRECISION).movePointLeft(2).setScale(0, RoundingMode.HALF_UP)
|
|
|
368 |
.longValue();
|
|
|
369 |
PrixTTC prixRG = new PrixTTC(totalRG);
|
|
|
370 |
prixTTC = new PrixTTC(totalNet - totalRG);
|
|
|
371 |
if (prixTTC.getLongValue() > 0) {
|
|
|
372 |
new GenerationReglementVenteNG(label.trim(), rowClient, prixTTC, this.date, modeRegl, saisieRow, mvtTable.getRow(idMvt), true, false, tiers, rowCptTiers);
|
|
|
373 |
}
|
|
|
374 |
if (prixRG.getLongValue() > 0) {
|
|
|
375 |
SQLRowValues rowValsMdrRg = new SQLRowValues(modeRegl.getTable());
|
|
|
376 |
rowValsMdrRg.put("AJOURS", 365);
|
|
|
377 |
rowValsMdrRg.put("LENJOUR", 0);
|
|
|
378 |
rowValsMdrRg.put("COMPTANT", Boolean.FALSE);
|
|
|
379 |
rowValsMdrRg.put("FIN_MOIS", Boolean.FALSE);
|
|
|
380 |
rowValsMdrRg.put("DATE_FACTURE", Boolean.TRUE);
|
|
|
381 |
rowValsMdrRg.put("RG", Boolean.TRUE);
|
|
|
382 |
rowValsMdrRg.put("ID_TYPE_REGLEMENT", TypeReglementSQLElement.INDEFINI);
|
|
|
383 |
final SQLRow rowMdrRG = rowValsMdrRg.commit();
|
|
|
384 |
new GenerationReglementVenteNG(label.trim(), rowClient, prixRG, this.date, rowMdrRG, saisieRow, mvtTable.getRow(idMvt), true, false, tiers, rowCptTiers);
|
|
|
385 |
}
|
|
|
386 |
} else {
|
|
|
387 |
prixTTC = new PrixTTC(totalNet);
|
|
|
388 |
if (prixTTC.getLongValue() > 0) {
|
|
|
389 |
new GenerationReglementVenteNG(label.trim(), rowClient, prixTTC, this.date, modeRegl, saisieRow, mvtTable.getRow(idMvt), true, false, tiers, rowCptTiers);
|
|
|
390 |
}
|
|
|
391 |
}
|
|
|
392 |
|
18 |
ilm |
393 |
}
|
|
|
394 |
// Mise à jour de mouvement associé à la facture
|
|
|
395 |
|
|
|
396 |
SQLRowValues valSasieVF = new SQLRowValues(GenerationMvtSaisieVenteFacture.saisieVFTable);
|
|
|
397 |
valSasieVF.put("ID_MOUVEMENT", Integer.valueOf(this.idMvt));
|
|
|
398 |
|
73 |
ilm |
399 |
if (valSasieVF.getInvalid() == null) {
|
|
|
400 |
valSasieVF.update(this.idSaisieVenteFacture);
|
80 |
ilm |
401 |
displayMvtNumber();
|
73 |
ilm |
402 |
}
|
18 |
ilm |
403 |
|
|
|
404 |
}
|
|
|
405 |
|
|
|
406 |
public void run() {
|
|
|
407 |
try {
|
|
|
408 |
genereMouvement();
|
73 |
ilm |
409 |
} catch (Exception e) {
|
18 |
ilm |
410 |
ExceptionHandler.handle("Erreur pendant la générations des écritures comptables", e);
|
73 |
ilm |
411 |
|
18 |
ilm |
412 |
}
|
|
|
413 |
}
|
|
|
414 |
}
|