OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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