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;
|
|
|
18 |
import org.openconcerto.erp.model.PrixHT;
|
|
|
19 |
import org.openconcerto.erp.model.PrixTTC;
|
|
|
20 |
import org.openconcerto.sql.model.SQLRow;
|
|
|
21 |
import org.openconcerto.sql.model.SQLRowValues;
|
|
|
22 |
import org.openconcerto.sql.model.SQLTable;
|
|
|
23 |
|
|
|
24 |
import java.util.Date;
|
|
|
25 |
|
|
|
26 |
public class GenerationMvtAvoirFournisseur extends GenerationEcritures {
|
|
|
27 |
|
|
|
28 |
private static final String source = "AVOIR_FOURNISSEUR";
|
|
|
29 |
// TODO dans quel journal les ecritures des avoirs? OD?
|
|
|
30 |
private static final Integer journal = Integer.valueOf(JournalSQLElement.ACHATS);
|
|
|
31 |
private int idAvoirFourn;
|
|
|
32 |
private static final SQLTable tablePrefCompte = base.getTable("PREFS_COMPTE");
|
|
|
33 |
private static final SQLRow rowPrefsCompte = tablePrefCompte.getRow(2);
|
|
|
34 |
|
93 |
ilm |
35 |
public GenerationMvtAvoirFournisseur(SQLRow row) {
|
|
|
36 |
this(row, 1);
|
18 |
ilm |
37 |
}
|
|
|
38 |
|
93 |
ilm |
39 |
public GenerationMvtAvoirFournisseur(SQLRow row, int idMvt) {
|
18 |
ilm |
40 |
this.idMvt = idMvt;
|
93 |
ilm |
41 |
this.idAvoirFourn = row.getID();
|
|
|
42 |
setRowAnalytiqueSource(row);
|
18 |
ilm |
43 |
}
|
|
|
44 |
|
73 |
ilm |
45 |
public int genereMouvement() throws Exception {
|
18 |
ilm |
46 |
|
|
|
47 |
SQLTable avoirFournTable = base.getTable("AVOIR_FOURNISSEUR");
|
|
|
48 |
SQLTable fournTable = base.getTable("FOURNISSEUR");
|
|
|
49 |
|
|
|
50 |
SQLRow avoirRow = avoirFournTable.getRow(this.idAvoirFourn);
|
|
|
51 |
SQLRow rowFourn = fournTable.getRow(avoirRow.getInt("ID_FOURNISSEUR"));
|
|
|
52 |
|
|
|
53 |
// Calcul des montants
|
|
|
54 |
PrixTTC prixTTC = new PrixTTC(((Long) avoirRow.getObject("MONTANT_TTC")).longValue());
|
|
|
55 |
PrixHT prixHT = new PrixHT(((Long) avoirRow.getObject("MONTANT_HT")).longValue());
|
|
|
56 |
PrixHT prixTVA = new PrixHT(((Long) avoirRow.getObject("MONTANT_TVA")).longValue());
|
|
|
57 |
|
|
|
58 |
// iniatilisation des valeurs de la map
|
|
|
59 |
this.date = (Date) avoirRow.getObject("DATE");
|
|
|
60 |
this.nom = avoirRow.getObject("NOM").toString();
|
149 |
ilm |
61 |
this.putValue("DATE", new java.sql.Date(this.date.getTime()));
|
|
|
62 |
this.putValue("NOM", "Avoir fournisseur : " + avoirRow.getString("NUMERO") + " " + rowFourn.getString("NOM"));
|
|
|
63 |
this.putValue("ID_JOURNAL", GenerationMvtAvoirFournisseur.journal);
|
|
|
64 |
this.putValue("ID_MOUVEMENT", Integer.valueOf(1));
|
18 |
ilm |
65 |
|
|
|
66 |
// on cree un nouveau mouvement
|
|
|
67 |
if (this.idMvt == 1) {
|
|
|
68 |
getNewMouvement(GenerationMvtAvoirFournisseur.source, this.idAvoirFourn, 1, "Avoir Fournisseur : " + avoirRow.getString("NUMERO"));
|
|
|
69 |
} else {
|
149 |
ilm |
70 |
this.putValue("ID_MOUVEMENT", Integer.valueOf(this.idMvt));
|
18 |
ilm |
71 |
}
|
|
|
72 |
|
|
|
73 |
// generation des ecritures + maj des totaux du compte associe
|
|
|
74 |
|
|
|
75 |
// compte Achat
|
|
|
76 |
int idCompteAchat = avoirRow.getInt("ID_COMPTE_PCE");
|
|
|
77 |
|
|
|
78 |
if (idCompteAchat <= 1) {
|
|
|
79 |
idCompteAchat = rowPrefsCompte.getInt("ID_COMPTE_PCE_ACHAT");
|
|
|
80 |
if (idCompteAchat <= 1) {
|
|
|
81 |
try {
|
|
|
82 |
idCompteAchat = ComptePCESQLElement.getIdComptePceDefault("Achats");
|
|
|
83 |
} catch (Exception e) {
|
|
|
84 |
e.printStackTrace();
|
|
|
85 |
}
|
|
|
86 |
}
|
|
|
87 |
}
|
149 |
ilm |
88 |
this.putValue("ID_COMPTE_PCE", Integer.valueOf(idCompteAchat));
|
|
|
89 |
this.putValue("DEBIT", Long.valueOf(0));
|
|
|
90 |
this.putValue("CREDIT", Long.valueOf(prixHT.getLongValue()));
|
93 |
ilm |
91 |
SQLRow rowEcr = ajoutEcriture();
|
|
|
92 |
// addAssocAnalytiqueFromProvider(rowEcr, avoirRow);
|
18 |
ilm |
93 |
|
73 |
ilm |
94 |
if (prixTVA.getLongValue() > 0) {
|
|
|
95 |
// compte TVA
|
|
|
96 |
int idCompteTVA = rowPrefsCompte.getInt("ID_COMPTE_PCE_TVA_ACHAT");
|
|
|
97 |
if (avoirRow.getBoolean("IMMO")) {
|
|
|
98 |
idCompteTVA = rowPrefsCompte.getInt("ID_COMPTE_PCE_TVA_IMMO");
|
|
|
99 |
if (idCompteTVA <= 1) {
|
|
|
100 |
idCompteTVA = ComptePCESQLElement.getIdComptePceDefault("TVAImmo");
|
18 |
ilm |
101 |
}
|
73 |
ilm |
102 |
} else {
|
|
|
103 |
idCompteTVA = rowPrefsCompte.getInt("ID_COMPTE_PCE_TVA_ACHAT");
|
|
|
104 |
if (idCompteTVA <= 1) {
|
|
|
105 |
idCompteTVA = ComptePCESQLElement.getIdComptePceDefault("TVADeductible");
|
|
|
106 |
}
|
|
|
107 |
}
|
18 |
ilm |
108 |
|
149 |
ilm |
109 |
this.putValue("ID_COMPTE_PCE", Integer.valueOf(idCompteTVA));
|
|
|
110 |
this.putValue("DEBIT", Long.valueOf(0));
|
|
|
111 |
this.putValue("CREDIT", Long.valueOf(prixTVA.getLongValue()));
|
73 |
ilm |
112 |
ajoutEcriture();
|
18 |
ilm |
113 |
|
73 |
ilm |
114 |
if (rowFourn.getBoolean("UE")) {
|
|
|
115 |
int idCompteTVAIntra = rowPrefsCompte.getInt("ID_COMPTE_PCE_TVA_INTRA");
|
|
|
116 |
if (idCompteTVAIntra <= 1) {
|
|
|
117 |
idCompteTVAIntra = ComptePCESQLElement.getIdComptePceDefault("TVAIntraComm");
|
18 |
ilm |
118 |
}
|
149 |
ilm |
119 |
this.putValue("ID_COMPTE_PCE", Integer.valueOf(idCompteTVAIntra));
|
|
|
120 |
this.putValue("DEBIT", Long.valueOf(prixTVA.getLongValue()));
|
|
|
121 |
this.putValue("CREDIT", Long.valueOf(0));
|
73 |
ilm |
122 |
ajoutEcriture();
|
18 |
ilm |
123 |
}
|
73 |
ilm |
124 |
}
|
|
|
125 |
// compte Fournisseur
|
|
|
126 |
int idCompteFourn = rowFourn.getInt("ID_COMPTE_PCE");
|
|
|
127 |
if (idCompteFourn <= 1) {
|
|
|
128 |
idCompteFourn = rowPrefsCompte.getInt("ID_COMPTE_PCE_FOURNISSEUR");
|
18 |
ilm |
129 |
if (idCompteFourn <= 1) {
|
73 |
ilm |
130 |
idCompteFourn = ComptePCESQLElement.getIdComptePceDefault("Fournisseurs");
|
18 |
ilm |
131 |
}
|
73 |
ilm |
132 |
}
|
149 |
ilm |
133 |
this.putValue("ID_COMPTE_PCE", Integer.valueOf(idCompteFourn));
|
|
|
134 |
this.putValue("DEBIT", Long.valueOf(prixTTC.getLongValue()));
|
|
|
135 |
this.putValue("CREDIT", Long.valueOf(0));
|
73 |
ilm |
136 |
ajoutEcriture();
|
18 |
ilm |
137 |
|
73 |
ilm |
138 |
// Mise à jour de mouvement associé à la facture d'avoir
|
|
|
139 |
SQLRowValues valAvoir = new SQLRowValues(avoirFournTable);
|
|
|
140 |
valAvoir.put("ID_MOUVEMENT", Integer.valueOf(this.idMvt));
|
18 |
ilm |
141 |
|
73 |
ilm |
142 |
if (valAvoir.getInvalid() == null) {
|
18 |
ilm |
143 |
|
73 |
ilm |
144 |
valAvoir.update(this.idAvoirFourn);
|
80 |
ilm |
145 |
displayMvtNumber();
|
73 |
ilm |
146 |
}
|
18 |
ilm |
147 |
|
73 |
ilm |
148 |
// if (avoirRow.getInt("ID_MODE_REGLEMENT") > 1) {
|
|
|
149 |
// new GenerationMvtReglementAvoir(this.idAvoirFourn, this.idMvt);
|
|
|
150 |
// } else {
|
|
|
151 |
// valAvoir.put("SOLDE", Boolean.FALSE);
|
|
|
152 |
// try {
|
|
|
153 |
// valAvoir.update(this.idAvoirClient);
|
|
|
154 |
// } catch (SQLException e) {
|
|
|
155 |
// e.printStackTrace();
|
|
|
156 |
// }
|
|
|
157 |
// }
|
18 |
ilm |
158 |
|
|
|
159 |
return this.idMvt;
|
|
|
160 |
}
|
|
|
161 |
}
|