OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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