OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 73 | Rev 132 | 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"));
73 ilm 62
        map.put("SocieteCodePostal", rowSocAdresse.getString("CODE_POSTAL"));
18 ilm 63
 
73 ilm 64
        String ville = rowSocAdresse.getString("VILLE");
18 ilm 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");
90 ilm 81
        if (!clientRowNX.isForeignEmpty("ID_ADRESSE_F")) {
82
            rowAdresse = clientRowNX.getForeign("ID_ADRESSE_F");
83
        }
18 ilm 84
        // Client compte
85
        SQLRow rowCompteClient = clientRowNX.getForeignRow("ID_COMPTE_PCE");
86
        String numero = rowCompteClient.getString("NUMERO");
19 ilm 87
        map.put("ClientNumeroCompte", numero);
18 ilm 88
 
89
        // Infos Client
19 ilm 90
        map.put("ClientType", rowClient.getString("FORME_JURIDIQUE"));
91
        map.put("ClientNom", rowClient.getString("NOM"));
92
        map.put("ClientAdresse", rowAdresse.getString("RUE"));
73 ilm 93
        map.put("ClientCodePostal", rowAdresse.getString("CODE_POSTAL"));
94
        String villeCli = rowAdresse.getString("VILLE");
18 ilm 95
        final Object cedexCli = rowAdresse.getObject("CEDEX");
96
        final boolean hasCedexCli = rowAdresse.getBoolean("HAS_CEDEX");
97
 
98
        if (hasCedexCli) {
99
            villeCli += " CEDEX";
100
            if (cedexCli != null && cedexCli.toString().trim().length() > 0) {
101
                villeCli += " " + cedexCli.toString().trim();
102
            }
103
        }
104
 
19 ilm 105
        map.put("ClientVille", villeCli);
18 ilm 106
 
107
        // Date relance
108
        Date d = (Date) this.rowRelance.getObject("DATE");
19 ilm 109
        map.put("RelanceDate", dateFormat.format(d));
21 ilm 110
        map.put("RelanceNumero", this.rowRelance.getString("NUMERO"));
18 ilm 111
 
112
        SQLRow rowFacture = this.rowRelance.getForeignRow("ID_SAISIE_VENTE_FACTURE");
113
 
73 ilm 114
 
18 ilm 115
        // Infos facture
116
        Long lTotal = (Long) rowFacture.getObject("T_TTC");
117
        Long lRestant = (Long) this.rowRelance.getObject("MONTANT");
118
        Long lVerse = new Long(lTotal.longValue() - lRestant.longValue());
19 ilm 119
        map.put("FactureNumero", rowFacture.getString("NUMERO"));
120
        map.put("FactureTotal", GestionDevise.currencyToString(lTotal.longValue(), true));
121
        map.put("FactureRestant", GestionDevise.currencyToString(lRestant.longValue(), true));
122
        map.put("FactureVerse", GestionDevise.currencyToString(lVerse.longValue(), true));
123
        map.put("FactureDate", dateFormat2.format((Date) rowFacture.getObject("DATE")));
18 ilm 124
 
125
        Date dFacture = (Date) rowFacture.getObject("DATE");
126
        SQLRow modeRegRow = rowFacture.getForeignRow("ID_MODE_REGLEMENT");
127
        Date dateEch = ModeDeReglementSQLElement.calculDate(modeRegRow.getInt("AJOURS"), modeRegRow.getInt("LENJOUR"), dFacture);
19 ilm 128
        map.put("FactureDateEcheance", dateFormat2.format(dateEch));
18 ilm 129
 
130
        SQLSelect sel = new SQLSelect(Configuration.getInstance().getBase());
131
        sel.addSelect(this.rowRelance.getTable().getKey());
132
        sel.setWhere(new Where(this.rowRelance.getTable().getField("ID_SAISIE_VENTE_FACTURE"), "=", this.rowRelance.getInt("ID_SAISIE_VENTE_FACTURE")));
65 ilm 133
        sel.addFieldOrder(this.rowRelance.getTable().getField("DATE"));
25 ilm 134
        @SuppressWarnings("unchecked")
135
        List<Map<String, Number>> listResult = Configuration.getInstance().getBase().getDataSource().execute(sel.asString());
18 ilm 136
        if (listResult != null && listResult.size() > 0) {
25 ilm 137
            Map<String, Number> o = listResult.get(0);
138
            Number n = o.get(this.rowRelance.getTable().getKey().getName());
18 ilm 139
            SQLRow rowOldRelance = this.rowRelance.getTable().getRow(n.intValue());
140
            Date dOldRelance = (Date) rowOldRelance.getObject("DATE");
19 ilm 141
            map.put("DatePremiereRelance", dateFormat2.format(dOldRelance));
18 ilm 142
        } else {
19 ilm 143
            map.put("DatePremiereRelance", "");
18 ilm 144
        }
145
 
19 ilm 146
        return map;
18 ilm 147
    }
148
 
149
    public RelanceSheet(SQLRow row) {
150
        this.rowRelance = row;
151
        Date d = (Date) this.rowRelance.getObject("DATE");
152
        String year = yearFormat.format(d);
153
        SQLRow rowLettre = this.rowRelance.getForeignRow("ID_TYPE_LETTRE_RELANCE");
154
 
155
        final String string = rowLettre.getString("MODELE");
156
        System.err.println(this.locationTemplate + "/" + string);
25 ilm 157
        init(year, string, "RelancePrinter");
18 ilm 158
    }
159
 
160
    protected boolean savePDF() {
161
        return true;
162
    }
163
 
65 ilm 164
    protected String getName() {
25 ilm 165
        return "Relance_" + this.rowRelance.getString("NUMERO");
18 ilm 166
    }
167
}