OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 61 | Rev 65 | 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;
15
 
16
import org.openconcerto.erp.core.finance.payment.element.ModeDeReglementSQLElement;
17
import org.openconcerto.sql.Configuration;
18
import org.openconcerto.sql.element.SQLElement;
19
import org.openconcerto.sql.model.SQLRow;
20
import org.openconcerto.sql.model.SQLRowAccessor;
21
import org.openconcerto.sql.model.SQLTable;
22
import org.openconcerto.utils.GestionDevise;
23
 
24
import java.text.DateFormat;
25
import java.text.SimpleDateFormat;
26
import java.util.ArrayList;
27
import java.util.Collection;
28
import java.util.Date;
29
import java.util.List;
30
 
63 ilm 31
import org.jdom.Attribute;
18 ilm 32
import org.jdom.Element;
33
 
34
public class OOXMLElement {
35
    protected Element elt;
36
    protected SQLElement sqlElt;
37
    protected int id;
63 ilm 38
    protected SQLRowAccessor row;
19 ilm 39
    protected SQLRow rowLanguage;
63 ilm 40
    protected OOXMLCache cache;
18 ilm 41
 
63 ilm 42
    public OOXMLElement(Element elt, SQLElement sqlElt, int id, SQLRow rowLanguage, OOXMLCache cache) {
43
        this(elt, sqlElt, id, null, rowLanguage, cache);
44
 
18 ilm 45
    }
46
 
63 ilm 47
    public OOXMLElement(Element elt, SQLElement sqlElt, int id, SQLRowAccessor row, SQLRow rowLanguage, OOXMLCache cache) {
18 ilm 48
        this.elt = elt;
49
        this.sqlElt = sqlElt;
50
        this.id = id;
51
        this.row = row;
19 ilm 52
        this.rowLanguage = rowLanguage;
63 ilm 53
        this.cache = cache;
18 ilm 54
    }
55
 
56
    public Object getValue() {
57
        Object res = "";
58
 
63 ilm 59
        final String type = this.elt.getAttributeValue("type");
60
        SpreadSheetCellValueProvider provider = SpreadSheetCellValueProviderManager.get(type);
61
        if (provider != null) {
62
            final SpreadSheetCellValueContext context = new SpreadSheetCellValueContext(this.row);
63
            List<Attribute> attrs = this.elt.getAttributes();
64
            for (Attribute attr : attrs) {
65
                context.put(attr.getName(), attr.getValue());
66
            }
67
            return provider.getValue(context);
18 ilm 68
        }
69
 
63 ilm 70
        if (type.equalsIgnoreCase("TotalHTTable")) {
18 ilm 71
            return getTotalHTTable(row);
72
        }
73
 
63 ilm 74
        if (type.equalsIgnoreCase("DateEcheance")) {
18 ilm 75
            int idModeReglement = row.getInt("ID_MODE_REGLEMENT");
76
            Date d = (Date) row.getObject("DATE");
61 ilm 77
            return getDateEcheance(idModeReglement, d, this.elt.getAttributeValue("DatePattern"));
18 ilm 78
        }
79
 
80
        final List<Element> eltFields = this.elt.getChildren("field");
81
 
82
        if (eltFields != null) {
83
            if (eltFields.size() > 1) {
84
                String result = "";
85
                for (Element eltField : eltFields) {
86
 
63 ilm 87
                    OOXMLField field = new OOXMLField(eltField, this.row, this.sqlElt, this.id, this.rowLanguage, cache);
18 ilm 88
 
89
                    Object value = field.getValue();
90
                    if (value != null) {
91
                        result += value.toString() + " ";
92
                    }
93
                }
94
                res = result;
95
            } else {
63 ilm 96
                OOXMLField field = new OOXMLField(eltFields.get(0), this.row, this.sqlElt, this.id, this.rowLanguage, cache);
18 ilm 97
                res = field.getValue();
98
            }
99
        }
100
        return res;
101
    }
102
 
103
 
104
    public static DateFormat format = new SimpleDateFormat("dd/MM/yyyy");
105
 
106
    protected String getStringProposition(SQLRowAccessor rowProp) {
107
 
108
        return "Notre proposition " + rowProp.getString("NUMERO") + " du " + format.format(rowProp.getObject("DATE"));
109
    }
110
 
111
 
112
    public Double getTotalHTTable(SQLRowAccessor rowFact) {
113
 
114
        SQLTable tableElt = Configuration.getInstance().getRoot().findTable("SAISIE_VENTE_FACTURE_ELEMENT");
115
        Collection<? extends SQLRowAccessor> set = rowFact.getReferentRows(tableElt);
116
        long total = 0;
117
        for (SQLRowAccessor row : set) {
118
            total += row.getLong("T_PV_HT");
119
        }
120
 
121
        return new Double(GestionDevise.currencyToString(total, false));
122
    }
123
 
124
 
125
    /**
126
     * Calcul la date d'échéance d'un élément par rapport au mode de reglement et à la date
127
     * d'émission
128
     *
129
     * @param idModeRegl
130
     * @param currentDate
61 ilm 131
     * @return la date d'échéance au format dd/MM/yy si datePattern !=null sinon une Date
18 ilm 132
     */
61 ilm 133
    protected Object getDateEcheance(int idModeRegl, Date currentDate, String datePattern) {
18 ilm 134
        SQLElement eltModeRegl = Configuration.getInstance().getDirectory().getElement("MODE_REGLEMENT");
135
        SQLRow row = eltModeRegl.getTable().getRow(idModeRegl);
136
        int aJ = row.getInt("AJOURS");
137
        int nJ = row.getInt("LENJOUR");
138
        if (aJ + nJ == 0) {
139
            if (row.getBoolean("DATE_FACTURE")) {
140
                return Configuration.getInstance().getTranslator().getLabelFor(row.getTable().getField("DATE_FACTURE"));
141
            } else {
142
                return " ";
143
            }
144
        }
61 ilm 145
        Date calculDate = ModeDeReglementSQLElement.calculDate(aJ, nJ, currentDate);
146
        if (datePattern != null && datePattern.trim().length() > 0) {
147
            final DateFormat format2 = new SimpleDateFormat(datePattern);
148
            return format2.format(calculDate);
149
        } else {
150
            return calculDate;
151
        }
18 ilm 152
    }
153
 
154
    public boolean isTypeReplace() {
155
        // remplacement d'un pattern contenu dans la cellule
156
        return this.elt.getAttributeValue("type").equalsIgnoreCase("Replace");
157
    }
158
 
159
    public String getReplacePattern() {
160
        return this.elt.getAttributeValue("replacePattern");
161
    }
162
 
163
    public boolean isMultilineAuto() {
164
        // gestion manuel du multiligne
165
        final String multiLineValue = this.elt.getAttributeValue("controleMultiline");
166
        return (multiLineValue == null) ? true : !multiLineValue.equalsIgnoreCase("false");
167
    }
168
 
169
}