OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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