1 |
/*
|
1 |
/*
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
3 |
*
|
3 |
*
|
4 |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
|
4 |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
|
5 |
*
|
5 |
*
|
6 |
* The contents of this file are subject to the terms of the GNU General Public License Version 3
|
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
|
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
|
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.
|
9 |
* language governing permissions and limitations under the License.
|
10 |
*
|
10 |
*
|
11 |
* When distributing the software, include this License Header Notice in each file.
|
11 |
* When distributing the software, include this License Header Notice in each file.
|
12 |
*/
|
12 |
*/
|
13 |
|
13 |
|
14 |
package org.openconcerto.erp.generationDoc.gestcomm;
|
14 |
package org.openconcerto.erp.generationDoc.gestcomm;
|
15 |
|
15 |
|
16 |
import org.openconcerto.erp.config.ComptaPropsConfiguration;
|
16 |
import org.openconcerto.erp.config.ComptaPropsConfiguration;
|
17 |
import org.openconcerto.erp.core.finance.payment.element.ModeDeReglementSQLElement;
|
17 |
import org.openconcerto.erp.core.finance.payment.element.ModeDeReglementSQLElement;
|
18 |
import org.openconcerto.erp.generationDoc.AbstractJOOReportsSheet;
|
18 |
import org.openconcerto.erp.generationDoc.AbstractJOOReportsSheet;
|
19 |
import org.openconcerto.sql.Configuration;
|
19 |
import org.openconcerto.sql.Configuration;
|
20 |
import org.openconcerto.sql.model.SQLRow;
|
20 |
import org.openconcerto.sql.model.SQLRow;
|
- |
|
21 |
import org.openconcerto.sql.model.SQLRowListRSH;
|
21 |
import org.openconcerto.sql.model.SQLSelect;
|
22 |
import org.openconcerto.sql.model.SQLSelect;
|
22 |
import org.openconcerto.sql.model.Where;
|
23 |
import org.openconcerto.sql.model.Where;
|
23 |
import org.openconcerto.sql.users.UserManager;
|
24 |
import org.openconcerto.sql.users.UserManager;
|
24 |
import org.openconcerto.utils.GestionDevise;
|
25 |
import org.openconcerto.utils.GestionDevise;
|
25 |
|
26 |
|
26 |
import java.util.Date;
|
27 |
import java.util.Date;
|
27 |
import java.util.HashMap;
|
28 |
import java.util.HashMap;
|
28 |
import java.util.List;
|
29 |
import java.util.List;
|
29 |
import java.util.Map;
|
30 |
import java.util.Map;
|
30 |
|
31 |
|
31 |
public class RelanceSheet extends AbstractJOOReportsSheet {
|
32 |
public class RelanceSheet extends AbstractJOOReportsSheet {
|
32 |
|
33 |
|
33 |
private SQLRow rowRelance;
|
34 |
private SQLRow rowRelance;
|
34 |
|
35 |
|
35 |
public static final String TEMPLATE_ID = "Relance";
|
36 |
public static final String TEMPLATE_ID = "Relance";
|
36 |
|
37 |
|
37 |
public static final String TEMPLATE_PROPERTY_NAME = "LocationRelance";
|
38 |
public static final String TEMPLATE_PROPERTY_NAME = "LocationRelance";
|
38 |
|
39 |
|
39 |
@Override
|
40 |
@Override
|
40 |
public String getDefaultTemplateID() {
|
41 |
public String getDefaultTemplateID() {
|
41 |
return TEMPLATE_ID;
|
42 |
return TEMPLATE_ID;
|
42 |
}
|
43 |
}
|
43 |
|
44 |
|
44 |
@Override
|
45 |
@Override
|
45 |
public String getDefaultLocationProperty() {
|
46 |
public String getDefaultLocationProperty() {
|
46 |
return TEMPLATE_PROPERTY_NAME;
|
47 |
return TEMPLATE_PROPERTY_NAME;
|
47 |
}
|
48 |
}
|
48 |
|
49 |
|
49 |
/**
|
50 |
/**
|
50 |
* @return une Map contenant les valeurs à remplacer dans la template
|
51 |
* @return une Map contenant les valeurs à remplacer dans la template
|
51 |
*/
|
52 |
*/
|
52 |
protected Map<String, Object> createMap() {
|
53 |
protected Map<String, Object> createMap() {
|
53 |
final Map<String, Object> map = new HashMap<String, Object>();
|
54 |
final Map<String, Object> map = new HashMap<String, Object>();
|
54 |
|
55 |
|
55 |
final SQLRow rowSoc = ((ComptaPropsConfiguration) Configuration.getInstance()).getRowSociete();
|
56 |
final SQLRow rowSoc = ((ComptaPropsConfiguration) Configuration.getInstance()).getRowSociete();
|
56 |
final SQLRow rowSocAdresse = rowSoc.getForeignRow("ID_ADRESSE_COMMON");
|
57 |
final SQLRow rowSocAdresse = rowSoc.getForeignRow("ID_ADRESSE_COMMON");
|
57 |
SQLRow rowUser = rowSoc.getTable().getDBRoot().findTable("USER_COMMON").getRow(UserManager.getUser().getId());
|
58 |
SQLRow rowUser = rowSoc.getTable().getDBRoot().findTable("USER_COMMON").getRow(UserManager.getUser().getId());
|
58 |
map.put("UserName", rowUser.getString("NOM"));
|
59 |
map.put("UserName", rowUser.getString("NOM"));
|
59 |
map.put("UserFirstName", rowUser.getString("PRENOM"));
|
60 |
map.put("UserFirstName", rowUser.getString("PRENOM"));
|
60 |
if (rowUser.getTable().contains("MAIL")) {
|
61 |
if (rowUser.getTable().contains("MAIL")) {
|
61 |
map.put("UserMail", rowUser.getString("MAIL"));
|
62 |
map.put("UserMail", rowUser.getString("MAIL"));
|
62 |
}
|
63 |
}
|
63 |
if (rowUser.getTable().contains("TEL")) {
|
64 |
if (rowUser.getTable().contains("TEL")) {
|
64 |
map.put("UserTel", rowUser.getString("TEL"));
|
65 |
map.put("UserTel", rowUser.getString("TEL"));
|
65 |
}
|
66 |
}
|
66 |
// Infos societe
|
67 |
// Infos societe
|
67 |
map.put("SocieteType", rowSoc.getString("TYPE"));
|
68 |
map.put("SocieteType", rowSoc.getString("TYPE"));
|
- |
|
69 |
map.put("SocieteTel", rowSoc.getString("NUM_TEL"));
|
- |
|
70 |
map.put("SocieteFax", rowSoc.getString("NUM_FAX"));
|
- |
|
71 |
map.put("SocieteRCS", rowSoc.getString("RCS"));
|
- |
|
72 |
map.put("SocieteSiret", rowSoc.getString("NUM_SIRET"));
|
- |
|
73 |
map.put("SocieteAPE", rowSoc.getString("NUM_APE"));
|
- |
|
74 |
map.put("SocieteCapital", GestionDevise.currencyToString(rowSoc.getBigDecimal("CAPITAL")));
|
68 |
map.put("SocieteNom", rowSoc.getString("NOM"));
|
75 |
map.put("SocieteNom", rowSoc.getString("NOM"));
|
69 |
map.put("SocieteAdresse", rowSocAdresse.getString("RUE"));
|
76 |
map.put("SocieteAdresse", rowSocAdresse.getString("RUE"));
|
70 |
map.put("SocieteCodePostal", rowSocAdresse.getString("CODE_POSTAL"));
|
77 |
map.put("SocieteCodePostal", rowSocAdresse.getString("CODE_POSTAL"));
|
71 |
|
78 |
|
72 |
String ville = rowSocAdresse.getString("VILLE");
|
79 |
String ville = rowSocAdresse.getString("VILLE");
|
73 |
final Object cedex = rowSocAdresse.getObject("CEDEX");
|
80 |
final Object cedex = rowSocAdresse.getObject("CEDEX");
|
74 |
final boolean hasCedex = rowSocAdresse.getBoolean("HAS_CEDEX");
|
81 |
final boolean hasCedex = rowSocAdresse.getBoolean("HAS_CEDEX");
|
75 |
|
82 |
|
76 |
if (hasCedex) {
|
83 |
if (hasCedex) {
|
77 |
ville += " CEDEX";
|
84 |
ville += " CEDEX";
|
78 |
if (cedex != null && cedex.toString().trim().length() > 0) {
|
85 |
if (cedex != null && cedex.toString().trim().length() > 0) {
|
79 |
ville += " " + cedex.toString().trim();
|
86 |
ville += " " + cedex.toString().trim();
|
80 |
}
|
87 |
}
|
81 |
}
|
88 |
}
|
82 |
|
89 |
|
83 |
map.put("SocieteVille", ville);
|
90 |
map.put("SocieteVille", ville);
|
84 |
|
91 |
|
85 |
SQLRow rowClient;
|
92 |
SQLRow rowClient;
|
86 |
final SQLRow clientRowNX = this.rowRelance.getForeignRow("ID_CLIENT");
|
93 |
final SQLRow clientRowNX = this.rowRelance.getForeignRow("ID_CLIENT");
|
87 |
rowClient = clientRowNX;
|
94 |
rowClient = clientRowNX;
|
88 |
SQLRow rowAdresse = rowClient.getForeignRow("ID_ADRESSE");
|
95 |
SQLRow rowAdresse = rowClient.getForeignRow("ID_ADRESSE");
|
89 |
if (!clientRowNX.isForeignEmpty("ID_ADRESSE_F")) {
|
96 |
if (!clientRowNX.isForeignEmpty("ID_ADRESSE_F")) {
|
90 |
rowAdresse = clientRowNX.getForeign("ID_ADRESSE_F");
|
97 |
rowAdresse = clientRowNX.getForeign("ID_ADRESSE_F");
|
91 |
}
|
98 |
}
|
92 |
// Client compte
|
99 |
// Client compte
|
93 |
SQLRow rowCompteClient = clientRowNX.getForeignRow("ID_COMPTE_PCE");
|
100 |
SQLRow rowCompteClient = clientRowNX.getForeignRow("ID_COMPTE_PCE");
|
94 |
String numero = rowCompteClient.getString("NUMERO");
|
101 |
String numero = rowCompteClient.getString("NUMERO");
|
95 |
map.put("ClientNumeroCompte", numero);
|
102 |
map.put("ClientNumeroCompte", numero);
|
96 |
|
103 |
|
97 |
// Infos Client
|
104 |
// Infos Client
|
98 |
map.put("ClientType", rowClient.getString("FORME_JURIDIQUE"));
|
105 |
map.put("ClientType", rowClient.getString("FORME_JURIDIQUE"));
|
99 |
map.put("ClientNom", rowClient.getString("NOM"));
|
106 |
map.put("ClientNom", rowClient.getString("NOM"));
|
100 |
map.put("ClientAdresse", rowAdresse.getString("RUE"));
|
107 |
map.put("ClientAdresse", rowAdresse.getString("RUE"));
|
101 |
map.put("ClientCodePostal", rowAdresse.getString("CODE_POSTAL"));
|
108 |
map.put("ClientCodePostal", rowAdresse.getString("CODE_POSTAL"));
|
102 |
String villeCli = rowAdresse.getString("VILLE");
|
109 |
String villeCli = rowAdresse.getString("VILLE");
|
103 |
final Object cedexCli = rowAdresse.getObject("CEDEX");
|
110 |
final Object cedexCli = rowAdresse.getObject("CEDEX");
|
104 |
final boolean hasCedexCli = rowAdresse.getBoolean("HAS_CEDEX");
|
111 |
final boolean hasCedexCli = rowAdresse.getBoolean("HAS_CEDEX");
|
105 |
|
112 |
|
106 |
if (hasCedexCli) {
|
113 |
if (hasCedexCli) {
|
107 |
villeCli += " CEDEX";
|
114 |
villeCli += " CEDEX";
|
108 |
if (cedexCli != null && cedexCli.toString().trim().length() > 0) {
|
115 |
if (cedexCli != null && cedexCli.toString().trim().length() > 0) {
|
109 |
villeCli += " " + cedexCli.toString().trim();
|
116 |
villeCli += " " + cedexCli.toString().trim();
|
110 |
}
|
117 |
}
|
111 |
}
|
118 |
}
|
112 |
|
119 |
|
113 |
map.put("ClientVille", villeCli);
|
120 |
map.put("ClientVille", villeCli);
|
114 |
|
121 |
|
115 |
// Date relance
|
122 |
// Date relance
|
116 |
Date d = (Date) this.rowRelance.getObject("DATE");
|
123 |
Date d = (Date) this.rowRelance.getObject("DATE");
|
117 |
map.put("RelanceDate", dateFormat.format(d));
|
124 |
map.put("RelanceDate", dateFormat.format(d));
|
118 |
map.put("RelanceNumero", this.rowRelance.getString("NUMERO"));
|
125 |
map.put("RelanceNumero", this.rowRelance.getString("NUMERO"));
|
119 |
|
126 |
|
120 |
SQLRow rowFacture = this.rowRelance.getForeignRow("ID_SAISIE_VENTE_FACTURE");
|
127 |
SQLRow rowFacture = this.rowRelance.getForeignRow("ID_SAISIE_VENTE_FACTURE");
|
121 |
|
128 |
|
122 |
|
129 |
|
123 |
// Infos facture
|
130 |
// Infos facture
|
124 |
Long lTotal = (Long) rowFacture.getObject("T_TTC");
|
131 |
Long lTotal = (Long) rowFacture.getObject("T_TTC");
|
125 |
Long lRestant = (Long) this.rowRelance.getObject("MONTANT");
|
132 |
Long lRestant = (Long) this.rowRelance.getObject("MONTANT");
|
126 |
Long lVerse = new Long(lTotal.longValue() - lRestant.longValue());
|
133 |
Long lVerse = new Long(lTotal.longValue() - lRestant.longValue());
|
127 |
map.put("FactureNumero", rowFacture.getString("NUMERO"));
|
134 |
map.put("FactureNumero", rowFacture.getString("NUMERO"));
|
128 |
map.put("FactureTotal", GestionDevise.currencyToString(lTotal.longValue(), true));
|
135 |
map.put("FactureTotal", GestionDevise.currencyToString(lTotal.longValue(), true));
|
129 |
map.put("FactureRestant", GestionDevise.currencyToString(lRestant.longValue(), true));
|
136 |
map.put("FactureRestant", GestionDevise.currencyToString(lRestant.longValue(), true));
|
130 |
map.put("FactureVerse", GestionDevise.currencyToString(lVerse.longValue(), true));
|
137 |
map.put("FactureVerse", GestionDevise.currencyToString(lVerse.longValue(), true));
|
131 |
map.put("FactureDate", dateFormat2.format((Date) rowFacture.getObject("DATE")));
|
138 |
map.put("FactureDate", dateFormat2.format((Date) rowFacture.getObject("DATE")));
|
132 |
|
139 |
|
133 |
Date dFacture = (Date) rowFacture.getObject("DATE");
|
140 |
Date dFacture = (Date) rowFacture.getObject("DATE");
|
134 |
SQLRow modeRegRow = rowFacture.getForeignRow("ID_MODE_REGLEMENT");
|
141 |
SQLRow modeRegRow = rowFacture.getForeignRow("ID_MODE_REGLEMENT");
|
135 |
Date dateEch = ModeDeReglementSQLElement.calculDate(modeRegRow.getInt("AJOURS"), modeRegRow.getInt("LENJOUR"), dFacture);
|
142 |
Date dateEch = ModeDeReglementSQLElement.calculDate(modeRegRow.getInt("AJOURS"), modeRegRow.getInt("LENJOUR"), dFacture);
|
136 |
map.put("FactureDateEcheance", dateFormat2.format(dateEch));
|
143 |
map.put("FactureDateEcheance", dateFormat2.format(dateEch));
|
137 |
|
144 |
|
138 |
SQLSelect sel = new SQLSelect();
|
145 |
SQLSelect sel = new SQLSelect();
|
139 |
sel.addSelect(this.rowRelance.getTable().getKey());
|
146 |
sel.addSelect(this.rowRelance.getTable().getKey());
|
- |
|
147 |
sel.addSelect(this.rowRelance.getTable().getField("DATE"));
|
140 |
sel.setWhere(new Where(this.rowRelance.getTable().getField("ID_SAISIE_VENTE_FACTURE"), "=", this.rowRelance.getInt("ID_SAISIE_VENTE_FACTURE")));
|
148 |
sel.setWhere(new Where(this.rowRelance.getTable().getField("ID_SAISIE_VENTE_FACTURE"), "=", this.rowRelance.getInt("ID_SAISIE_VENTE_FACTURE")));
|
141 |
sel.addFieldOrder(this.rowRelance.getTable().getField("DATE"));
|
149 |
sel.addFieldOrder(this.rowRelance.getTable().getField("DATE"));
|
142 |
@SuppressWarnings("unchecked")
|
150 |
@SuppressWarnings("unchecked")
|
143 |
List<Map<String, Number>> listResult = Configuration.getInstance().getBase().getDataSource().execute(sel.asString());
|
151 |
List<SQLRow> listResult = SQLRowListRSH.execute(sel);
|
- |
|
152 |
|
- |
|
153 |
String oldDateRelance = "";
|
- |
|
154 |
|
144 |
if (listResult != null && listResult.size() > 0) {
|
155 |
if (listResult != null && listResult.size() > 0) {
|
145 |
Map<String, Number> o = listResult.get(0);
|
156 |
SQLRow rowOldRelance = listResult.get(0);
|
146 |
Number n = o.get(this.rowRelance.getTable().getKey().getName());
|
- |
|
147 |
SQLRow rowOldRelance = this.rowRelance.getTable().getRow(n.intValue());
|
- |
|
148 |
Date dOldRelance = (Date) rowOldRelance.getObject("DATE");
|
157 |
Date dOldRelance = (Date) rowOldRelance.getObject("DATE");
|
149 |
map.put("DatePremiereRelance", dateFormat2.format(dOldRelance));
|
158 |
map.put("DatePremiereRelance", dateFormat2.format(dOldRelance));
|
- |
|
159 |
|
- |
|
160 |
for (SQLRow rowOldR : listResult) {
|
- |
|
161 |
oldDateRelance += dateFormat2.format((Date) rowOldR.getObject("DATE")) + ", ";
|
- |
|
162 |
}
|
- |
|
163 |
|
150 |
} else {
|
164 |
} else {
|
151 |
map.put("DatePremiereRelance", "");
|
165 |
map.put("DatePremiereRelance", "");
|
152 |
}
|
166 |
}
|
- |
|
167 |
map.put("DateAncienneRelance", oldDateRelance);
|
153 |
|
168 |
|
154 |
return map;
|
169 |
return map;
|
155 |
}
|
170 |
}
|
156 |
|
171 |
|
157 |
public RelanceSheet(SQLRow row) {
|
172 |
public RelanceSheet(SQLRow row) {
|
158 |
this.rowRelance = row;
|
173 |
this.rowRelance = row;
|
159 |
Date d = (Date) this.rowRelance.getObject("DATE");
|
174 |
Date d = (Date) this.rowRelance.getObject("DATE");
|
160 |
String year = yearFormat.format(d);
|
175 |
String year = yearFormat.format(d);
|
161 |
SQLRow rowLettre = this.rowRelance.getForeignRow("ID_TYPE_LETTRE_RELANCE");
|
176 |
SQLRow rowLettre = this.rowRelance.getForeignRow("ID_TYPE_LETTRE_RELANCE");
|
162 |
|
177 |
|
163 |
final String string = rowLettre.getString("MODELE");
|
178 |
final String string = rowLettre.getString("MODELE");
|
164 |
System.err.println(this.locationTemplate + "/" + string);
|
179 |
System.err.println(this.locationTemplate + "/" + string);
|
165 |
init(year, string, "RelancePrinter");
|
180 |
init(year, string, "RelancePrinter");
|
166 |
}
|
181 |
}
|
167 |
|
182 |
|
168 |
protected boolean savePDF() {
|
183 |
protected boolean savePDF() {
|
169 |
return true;
|
184 |
return true;
|
170 |
}
|
185 |
}
|
171 |
|
186 |
|
172 |
protected String getName() {
|
187 |
protected String getName() {
|
173 |
return "Relance_" + this.rowRelance.getString("NUMERO");
|
188 |
return "Relance_" + this.rowRelance.getString("NUMERO");
|
174 |
}
|
189 |
}
|
175 |
}
|
190 |
}
|