OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 90 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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