OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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