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.generationDoc.gestcomm;
|
|
|
15 |
|
|
|
16 |
import org.openconcerto.erp.config.ComptaPropsConfiguration;
|
|
|
17 |
import org.openconcerto.erp.core.finance.payment.element.ModeDeReglementSQLElement;
|
|
|
18 |
import org.openconcerto.erp.generationDoc.AbstractJOOReportsSheet;
|
|
|
19 |
import org.openconcerto.sql.Configuration;
|
|
|
20 |
import org.openconcerto.sql.model.SQLRow;
|
|
|
21 |
import org.openconcerto.sql.model.SQLSelect;
|
|
|
22 |
import org.openconcerto.sql.model.Where;
|
|
|
23 |
import org.openconcerto.utils.GestionDevise;
|
|
|
24 |
|
|
|
25 |
import java.util.Date;
|
|
|
26 |
import java.util.HashMap;
|
|
|
27 |
import java.util.List;
|
|
|
28 |
import java.util.Map;
|
|
|
29 |
|
|
|
30 |
public class RelanceSheet extends AbstractJOOReportsSheet {
|
|
|
31 |
|
|
|
32 |
private SQLRow rowRelance;
|
|
|
33 |
|
25 |
ilm |
34 |
public static final String TEMPLATE_ID = "Relance";
|
18 |
ilm |
35 |
|
25 |
ilm |
36 |
public static final String TEMPLATE_PROPERTY_NAME = "LocationRelance";
|
18 |
ilm |
37 |
|
|
|
38 |
/**
|
|
|
39 |
* @return une Map contenant les valeurs à remplacer dans la template
|
|
|
40 |
*/
|
19 |
ilm |
41 |
protected Map<String, Object> createMap() {
|
18 |
ilm |
42 |
|
19 |
ilm |
43 |
final SQLRow rowSoc = ((ComptaPropsConfiguration) Configuration.getInstance()).getRowSociete();
|
|
|
44 |
final SQLRow rowSocAdresse = rowSoc.getForeignRow("ID_ADRESSE_COMMON");
|
18 |
ilm |
45 |
|
19 |
ilm |
46 |
final Map<String, Object> map = new HashMap<String, Object>();
|
18 |
ilm |
47 |
|
|
|
48 |
// Infos societe
|
19 |
ilm |
49 |
map.put("SocieteType", rowSoc.getString("TYPE"));
|
|
|
50 |
map.put("SocieteNom", rowSoc.getString("NOM"));
|
|
|
51 |
map.put("SocieteAdresse", rowSocAdresse.getString("RUE"));
|
|
|
52 |
map.put("SocieteCodePostal", getVilleCP(rowSocAdresse.getString("VILLE")));
|
18 |
ilm |
53 |
|
|
|
54 |
String ville = getVille(rowSocAdresse.getString("VILLE"));
|
|
|
55 |
final Object cedex = rowSocAdresse.getObject("CEDEX");
|
|
|
56 |
final boolean hasCedex = rowSocAdresse.getBoolean("HAS_CEDEX");
|
|
|
57 |
|
|
|
58 |
if (hasCedex) {
|
|
|
59 |
ville += " CEDEX";
|
|
|
60 |
if (cedex != null && cedex.toString().trim().length() > 0) {
|
|
|
61 |
ville += " " + cedex.toString().trim();
|
|
|
62 |
}
|
|
|
63 |
}
|
|
|
64 |
|
19 |
ilm |
65 |
map.put("SocieteVille", ville);
|
18 |
ilm |
66 |
|
|
|
67 |
SQLRow rowClient;
|
|
|
68 |
final SQLRow clientRowNX = this.rowRelance.getForeignRow("ID_CLIENT");
|
|
|
69 |
rowClient = clientRowNX;
|
|
|
70 |
SQLRow rowAdresse = rowClient.getForeignRow("ID_ADRESSE");
|
|
|
71 |
|
|
|
72 |
// Client compte
|
|
|
73 |
SQLRow rowCompteClient = clientRowNX.getForeignRow("ID_COMPTE_PCE");
|
|
|
74 |
String numero = rowCompteClient.getString("NUMERO");
|
19 |
ilm |
75 |
map.put("ClientNumeroCompte", numero);
|
18 |
ilm |
76 |
|
|
|
77 |
// Infos Client
|
19 |
ilm |
78 |
map.put("ClientType", rowClient.getString("FORME_JURIDIQUE"));
|
|
|
79 |
map.put("ClientNom", rowClient.getString("NOM"));
|
|
|
80 |
map.put("ClientAdresse", rowAdresse.getString("RUE"));
|
|
|
81 |
map.put("ClientCodePostal", getVilleCP(rowAdresse.getString("VILLE")));
|
18 |
ilm |
82 |
String villeCli = getVille(rowAdresse.getString("VILLE"));
|
|
|
83 |
final Object cedexCli = rowAdresse.getObject("CEDEX");
|
|
|
84 |
final boolean hasCedexCli = rowAdresse.getBoolean("HAS_CEDEX");
|
|
|
85 |
|
|
|
86 |
if (hasCedexCli) {
|
|
|
87 |
villeCli += " CEDEX";
|
|
|
88 |
if (cedexCli != null && cedexCli.toString().trim().length() > 0) {
|
|
|
89 |
villeCli += " " + cedexCli.toString().trim();
|
|
|
90 |
}
|
|
|
91 |
}
|
|
|
92 |
|
19 |
ilm |
93 |
map.put("ClientVille", villeCli);
|
18 |
ilm |
94 |
|
|
|
95 |
// Date relance
|
|
|
96 |
Date d = (Date) this.rowRelance.getObject("DATE");
|
19 |
ilm |
97 |
map.put("RelanceDate", dateFormat.format(d));
|
21 |
ilm |
98 |
map.put("RelanceNumero", this.rowRelance.getString("NUMERO"));
|
18 |
ilm |
99 |
|
|
|
100 |
SQLRow rowFacture = this.rowRelance.getForeignRow("ID_SAISIE_VENTE_FACTURE");
|
|
|
101 |
|
|
|
102 |
// Infos facture
|
|
|
103 |
Long lTotal = (Long) rowFacture.getObject("T_TTC");
|
|
|
104 |
Long lRestant = (Long) this.rowRelance.getObject("MONTANT");
|
|
|
105 |
Long lVerse = new Long(lTotal.longValue() - lRestant.longValue());
|
19 |
ilm |
106 |
map.put("FactureNumero", rowFacture.getString("NUMERO"));
|
|
|
107 |
map.put("FactureTotal", GestionDevise.currencyToString(lTotal.longValue(), true));
|
|
|
108 |
map.put("FactureRestant", GestionDevise.currencyToString(lRestant.longValue(), true));
|
|
|
109 |
map.put("FactureVerse", GestionDevise.currencyToString(lVerse.longValue(), true));
|
|
|
110 |
map.put("FactureDate", dateFormat2.format((Date) rowFacture.getObject("DATE")));
|
18 |
ilm |
111 |
|
|
|
112 |
Date dFacture = (Date) rowFacture.getObject("DATE");
|
|
|
113 |
SQLRow modeRegRow = rowFacture.getForeignRow("ID_MODE_REGLEMENT");
|
|
|
114 |
Date dateEch = ModeDeReglementSQLElement.calculDate(modeRegRow.getInt("AJOURS"), modeRegRow.getInt("LENJOUR"), dFacture);
|
19 |
ilm |
115 |
map.put("FactureDateEcheance", dateFormat2.format(dateEch));
|
18 |
ilm |
116 |
|
|
|
117 |
SQLSelect sel = new SQLSelect(Configuration.getInstance().getBase());
|
|
|
118 |
sel.addSelect(this.rowRelance.getTable().getKey());
|
|
|
119 |
sel.setWhere(new Where(this.rowRelance.getTable().getField("ID_SAISIE_VENTE_FACTURE"), "=", this.rowRelance.getInt("ID_SAISIE_VENTE_FACTURE")));
|
65 |
ilm |
120 |
sel.addFieldOrder(this.rowRelance.getTable().getField("DATE"));
|
25 |
ilm |
121 |
@SuppressWarnings("unchecked")
|
|
|
122 |
List<Map<String, Number>> listResult = Configuration.getInstance().getBase().getDataSource().execute(sel.asString());
|
18 |
ilm |
123 |
if (listResult != null && listResult.size() > 0) {
|
25 |
ilm |
124 |
Map<String, Number> o = listResult.get(0);
|
|
|
125 |
Number n = o.get(this.rowRelance.getTable().getKey().getName());
|
18 |
ilm |
126 |
SQLRow rowOldRelance = this.rowRelance.getTable().getRow(n.intValue());
|
|
|
127 |
Date dOldRelance = (Date) rowOldRelance.getObject("DATE");
|
19 |
ilm |
128 |
map.put("DatePremiereRelance", dateFormat2.format(dOldRelance));
|
18 |
ilm |
129 |
} else {
|
19 |
ilm |
130 |
map.put("DatePremiereRelance", "");
|
18 |
ilm |
131 |
}
|
|
|
132 |
|
19 |
ilm |
133 |
return map;
|
18 |
ilm |
134 |
}
|
|
|
135 |
|
|
|
136 |
public RelanceSheet(SQLRow row) {
|
|
|
137 |
this.rowRelance = row;
|
|
|
138 |
Date d = (Date) this.rowRelance.getObject("DATE");
|
|
|
139 |
String year = yearFormat.format(d);
|
|
|
140 |
SQLRow rowLettre = this.rowRelance.getForeignRow("ID_TYPE_LETTRE_RELANCE");
|
|
|
141 |
|
|
|
142 |
final String string = rowLettre.getString("MODELE");
|
|
|
143 |
System.err.println(this.locationTemplate + "/" + string);
|
25 |
ilm |
144 |
init(year, string, "RelancePrinter");
|
18 |
ilm |
145 |
}
|
|
|
146 |
|
|
|
147 |
protected boolean savePDF() {
|
|
|
148 |
return true;
|
|
|
149 |
}
|
|
|
150 |
|
65 |
ilm |
151 |
protected String getName() {
|
25 |
ilm |
152 |
return "Relance_" + this.rowRelance.getString("NUMERO");
|
18 |
ilm |
153 |
}
|
|
|
154 |
}
|