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.core.finance.accounting.element.MouvementSQLElement;
|
|
|
19 |
import org.openconcerto.sql.Configuration;
|
|
|
20 |
import org.openconcerto.sql.element.SQLElement;
|
|
|
21 |
import org.openconcerto.sql.model.SQLRow;
|
|
|
22 |
import org.openconcerto.sql.model.SQLRowValues;
|
|
|
23 |
import org.openconcerto.sql.model.SQLTable;
|
|
|
24 |
|
|
|
25 |
import java.sql.SQLException;
|
|
|
26 |
import java.sql.Timestamp;
|
|
|
27 |
import java.util.Date;
|
|
|
28 |
|
|
|
29 |
public class GenerationMvtReglementChequeClient extends GenerationEcritures {
|
|
|
30 |
|
|
|
31 |
private long montant;
|
|
|
32 |
|
|
|
33 |
private static final SQLTable tablePrefCompte = base.getTable("PREFS_COMPTE");
|
|
|
34 |
private static final SQLRow rowPrefsCompte = tablePrefCompte.getRow(2);
|
|
|
35 |
private int idCheque;
|
|
|
36 |
|
73 |
ilm |
37 |
public GenerationMvtReglementChequeClient(int idMvt, long montant, Date d, int idCheque, String s) {
|
|
|
38 |
this.montant = montant;
|
|
|
39 |
this.date = d;
|
|
|
40 |
this.idMvt = idMvt;
|
|
|
41 |
this.idCheque = idCheque;
|
80 |
ilm |
42 |
SQLRow chequeRow = base.getTable("CHEQUE_A_ENCAISSER").getRow(this.idCheque);
|
|
|
43 |
String num = "";
|
|
|
44 |
if (chequeRow != null && !chequeRow.isUndefined() && chequeRow.getString("NUMERO").trim().length() > 0) {
|
|
|
45 |
num = " N° " + chequeRow.getString("NUMERO");
|
|
|
46 |
}
|
|
|
47 |
|
73 |
ilm |
48 |
if (s != null && s.trim().length() > 0) {
|
80 |
ilm |
49 |
this.nom = s + (num.trim().length() > 0 ? " - Cheque" + num : "");
|
73 |
ilm |
50 |
} else {
|
80 |
ilm |
51 |
this.nom = "Reglement cheque client" + num;
|
73 |
ilm |
52 |
}
|
|
|
53 |
}
|
18 |
ilm |
54 |
|
73 |
ilm |
55 |
public void genere() throws Exception {
|
18 |
ilm |
56 |
System.err.println("génération des ecritures de règlement d'un cheque client du mouvement " + this.idMvt);
|
|
|
57 |
SQLRow chequeRow = base.getTable("CHEQUE_A_ENCAISSER").getRow(this.idCheque);
|
|
|
58 |
SQLRow clientRow = base.getTable("CLIENT").getRow(chequeRow.getInt("ID_CLIENT"));
|
|
|
59 |
|
73 |
ilm |
60 |
// initialisation des valeurs de la map
|
18 |
ilm |
61 |
this.mEcritures.put("DATE", new java.sql.Date(this.date.getTime()));
|
|
|
62 |
this.mEcritures.put("NOM", this.nom);
|
|
|
63 |
this.mEcritures.put("ID_MOUVEMENT", new Integer(this.idMvt));
|
|
|
64 |
|
83 |
ilm |
65 |
fillJournalBanqueFromRow(chequeRow);
|
|
|
66 |
|
18 |
ilm |
67 |
setDateReglement(this.idCheque, this.date);
|
|
|
68 |
|
|
|
69 |
// compte Clients
|
|
|
70 |
int idCompteClient = -1;
|
|
|
71 |
if (clientRow != null) {
|
|
|
72 |
idCompteClient = clientRow.getInt("ID_COMPTE_PCE");
|
|
|
73 |
}
|
|
|
74 |
if (idCompteClient <= 1) {
|
|
|
75 |
idCompteClient = rowPrefsCompte.getInt("ID_COMPTE_PCE_CLIENT");
|
|
|
76 |
if (idCompteClient <= 1) {
|
73 |
ilm |
77 |
idCompteClient = ComptePCESQLElement.getIdComptePceDefault("Clients");
|
18 |
ilm |
78 |
}
|
|
|
79 |
}
|
|
|
80 |
|
73 |
ilm |
81 |
this.mEcritures.put("ID_COMPTE_PCE", new Integer(idCompteClient));
|
|
|
82 |
this.mEcritures.put("DEBIT", new Long(0));
|
|
|
83 |
this.mEcritures.put("CREDIT", new Long(this.montant));
|
|
|
84 |
ajoutEcriture();
|
|
|
85 |
System.err.println("First ECriture for mvt " + this.idMvt);
|
|
|
86 |
|
|
|
87 |
// compte de reglement cheque, ...
|
83 |
ilm |
88 |
fillCompteBanqueFromRow(chequeRow, "VenteCheque", false);
|
73 |
ilm |
89 |
this.mEcritures.put("DEBIT", new Long(this.montant));
|
|
|
90 |
this.mEcritures.put("CREDIT", new Long(0));
|
|
|
91 |
ajoutEcriture();
|
|
|
92 |
System.err.println("Ecritures générées pour le mouvement " + this.idMvt);
|
|
|
93 |
|
18 |
ilm |
94 |
}
|
|
|
95 |
|
73 |
ilm |
96 |
private void setDateReglement(int idCheque, Date d) throws SQLException {
|
18 |
ilm |
97 |
if (idCheque > 1) {
|
|
|
98 |
SQLRow chequeRow = Configuration.getInstance().getBase().getTable("CHEQUE_A_ENCAISSER").getRow(idCheque);
|
|
|
99 |
final int sourceId = MouvementSQLElement.getSourceId(chequeRow.getInt("ID_MOUVEMENT"));
|
|
|
100 |
SQLRow rowMvt = Configuration.getInstance().getBase().getTable("MOUVEMENT").getRow(sourceId);
|
|
|
101 |
|
|
|
102 |
if (rowMvt.getString("SOURCE").equalsIgnoreCase("SAISIE_VENTE_FACTURE")) {
|
|
|
103 |
SQLElement eltFacture = Configuration.getInstance().getDirectory().getElement("SAISIE_VENTE_FACTURE");
|
|
|
104 |
SQLRow saisieRow = eltFacture.getTable().getRow(rowMvt.getInt("IDSOURCE"));
|
|
|
105 |
// On fixe la date du paiement
|
|
|
106 |
SQLRowValues rowValsUpdateVF = saisieRow.createEmptyUpdateRow();
|
|
|
107 |
rowValsUpdateVF.put("DATE_REGLEMENT", new Timestamp(d.getTime()));
|
73 |
ilm |
108 |
rowValsUpdateVF.update();
|
18 |
ilm |
109 |
}
|
|
|
110 |
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
}
|