OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 177 | Rev 182 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 177 Rev 180
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
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
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
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.
9
 * language governing permissions and limitations under the License.
10
 * 
10
 * 
11
 * When distributing the software, include this License Header Notice in each file.
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.erp.generationDoc;
14
 package org.openconcerto.erp.generationDoc;
15
 
15
 
16
import org.openconcerto.erp.core.finance.payment.element.ModeDeReglementSQLElement;
16
import org.openconcerto.erp.core.finance.payment.element.ModeDeReglementSQLElement;
17
import org.openconcerto.sql.Configuration;
17
import org.openconcerto.sql.Configuration;
18
import org.openconcerto.sql.element.SQLElement;
18
import org.openconcerto.sql.element.SQLElement;
19
import org.openconcerto.sql.model.SQLField;
19
import org.openconcerto.sql.model.SQLField;
20
import org.openconcerto.sql.model.SQLRow;
20
import org.openconcerto.sql.model.SQLRow;
21
import org.openconcerto.sql.model.SQLRowAccessor;
21
import org.openconcerto.sql.model.SQLRowAccessor;
22
import org.openconcerto.sql.model.SQLSelect;
22
import org.openconcerto.sql.model.SQLSelect;
23
import org.openconcerto.sql.model.SQLTable;
23
import org.openconcerto.sql.model.SQLTable;
24
import org.openconcerto.sql.model.Where;
24
import org.openconcerto.sql.model.Where;
25
import org.openconcerto.utils.GestionDevise;
25
import org.openconcerto.utils.GestionDevise;
26
 
26
 
27
import java.text.DateFormat;
27
import java.text.DateFormat;
28
import java.text.SimpleDateFormat;
28
import java.text.SimpleDateFormat;
29
import java.util.ArrayList;
29
import java.util.ArrayList;
30
import java.util.Collection;
30
import java.util.Collection;
31
import java.util.Date;
31
import java.util.Date;
32
import java.util.List;
32
import java.util.List;
33
 
33
 
34
import org.jdom2.Attribute;
34
import org.jdom2.Attribute;
35
import org.jdom2.Element;
35
import org.jdom2.Element;
36
 
36
 
37
public class OOXMLElement {
37
public class OOXMLElement {
38
    protected Element elt;
38
    protected Element elt;
39
    protected SQLElement sqlElt;
39
    protected SQLElement sqlElt;
40
    protected int id;
40
    protected int id;
41
    protected SQLRowAccessor row;
41
    protected SQLRowAccessor row;
42
    protected SQLRow rowLanguage;
42
    protected SQLRow rowLanguage;
43
    protected OOXMLCache cache;
43
    protected OOXMLCache cache;
44
 
44
 
45
    public OOXMLElement(Element elt, SQLElement sqlElt, int id, SQLRow rowLanguage, OOXMLCache cache) {
45
    public OOXMLElement(Element elt, SQLElement sqlElt, int id, SQLRow rowLanguage, OOXMLCache cache) {
46
        this(elt, sqlElt, id, null, rowLanguage, cache);
46
        this(elt, sqlElt, id, null, rowLanguage, cache);
47
 
47
 
48
    }
48
    }
49
 
49
 
50
    public OOXMLElement(Element elt, SQLElement sqlElt, int id, SQLRowAccessor row, SQLRow rowLanguage, OOXMLCache cache) {
50
    public OOXMLElement(Element elt, SQLElement sqlElt, int id, SQLRowAccessor row, SQLRow rowLanguage, OOXMLCache cache) {
51
        this.elt = elt;
51
        this.elt = elt;
52
        this.sqlElt = sqlElt;
52
        this.sqlElt = sqlElt;
53
        this.id = id;
53
        this.id = id;
54
        this.row = row;
54
        this.row = row;
55
        this.rowLanguage = rowLanguage;
55
        this.rowLanguage = rowLanguage;
56
        this.cache = cache;
56
        this.cache = cache;
57
    }
57
    }
58
 
58
 
59
    public Object getValue() {
59
    public Object getValue() {
60
        Object res = "";
60
        Object res = "";
61
 
61
 
62
        final String type = this.elt.getAttributeValue("type");
62
        final String type = this.elt.getAttributeValue("type");
63
        SpreadSheetCellValueProvider provider = SpreadSheetCellValueProviderManager.get(type);
63
        SpreadSheetCellValueProvider provider = SpreadSheetCellValueProviderManager.get(type);
64
        if (provider != null) {
64
        if (provider != null) {
65
            final SpreadSheetCellValueContext context = new SpreadSheetCellValueContext(this.row);
65
            final SpreadSheetCellValueContext context = new SpreadSheetCellValueContext(this.row);
66
            List<Attribute> attrs = this.elt.getAttributes();
66
            List<Attribute> attrs = this.elt.getAttributes();
67
            for (Attribute attr : attrs) {
67
            for (Attribute attr : attrs) {
68
                context.put(attr.getName(), attr.getValue());
68
                context.put(attr.getName(), attr.getValue());
69
            }
69
            }
70
            res = provider.getValue(context);
70
            res = provider.getValue(context);
71
        } else
71
        } else
72
 
72
 
73
        if (type.equalsIgnoreCase("TotalHTTable")) {
73
        if (type.equalsIgnoreCase("TotalHTTable")) {
74
            res = getTotalHTTable(row);
74
            res = getTotalHTTable(row);
75
        } else if (type.equalsIgnoreCase("sql.function")) {
75
        } else if (type.equalsIgnoreCase("sql.function")) {
76
            String field = this.elt.getAttributeValue("field");
76
            String field = this.elt.getAttributeValue("field");
77
            String table = this.elt.getAttributeValue("table");
77
            String table = this.elt.getAttributeValue("table");
78
            String function = this.elt.getAttributeValue("function");
78
            String function = this.elt.getAttributeValue("function");
79
            SQLTable referentTable = this.row.getTable().getTable(table);
79
            SQLTable referentTable = this.row.getTable().getTable(table);
80
            return getFromSQLFunction(referentTable.getField(field), function);
80
            return getFromSQLFunction(referentTable.getField(field), function);
81
        } else if (type.equalsIgnoreCase("DateEcheance")) {
81
        } else if (type.equalsIgnoreCase("DateEcheance")) {
82
            int idModeReglement = row.getInt("ID_MODE_REGLEMENT");
82
            int idModeReglement = row.getInt("ID_MODE_REGLEMENT");
83
            Date d = (Date) row.getObject("DATE");
83
            Date d = (Date) row.getObject("DATE");
84
            res = getDateEcheance(idModeReglement, d, this.elt.getAttributeValue("datePattern"));
84
            res = getDateEcheance(idModeReglement, d, this.elt.getAttributeValue("datePattern"));
85
        } else {
85
        } else {
86
 
86
 
87
            final List<Element> eltFields = this.elt.getChildren("field");
87
            final List<Element> eltFields = this.elt.getChildren("field");
88
 
88
 
89
            if (eltFields != null && !eltFields.isEmpty()) {
89
            if (eltFields != null && !eltFields.isEmpty()) {
90
                if (eltFields.size() > 1) {
90
                if (eltFields.size() > 1) {
91
                    String result = "";
91
                    String result = "";
92
                    for (Element eltField : eltFields) {
92
                    for (Element eltField : eltFields) {
93
 
93
 
94
                        OOXMLField field = new OOXMLField(eltField, this.row, this.sqlElt, this.id, this.rowLanguage, cache);
94
                        OOXMLField field = new OOXMLField(eltField, this.row, this.sqlElt, this.id, this.rowLanguage, cache);
95
 
95
 
96
                        Object value = field.getValue();
96
                        Object value = field.getValue();
97
                        if (value != null) {
97
                        if (value != null) {
98
                            result += value.toString() + " ";
98
                            result += value.toString() + " ";
99
                        }
99
                        }
100
                    }
100
                    }
101
                    res = result;
101
                    res = result;
102
                } else {
102
                } else {
103
                    OOXMLField field = new OOXMLField(eltFields.get(0), this.row, this.sqlElt, this.id, this.rowLanguage, cache);
103
                    OOXMLField field = new OOXMLField(eltFields.get(0), this.row, this.sqlElt, this.id, this.rowLanguage, cache);
104
                    res = field.getValue();
104
                    res = field.getValue();
105
                }
105
                }
106
            }
106
            }
107
        }
107
        }
108
 
108
 
109
        // Liste des valeurs à ne pas afficher
109
        // Liste des valeurs à ne pas afficher
110
        List<String> listOfExcludedValues = null;
110
        List<String> listOfExcludedValues = null;
111
 
111
 
112
        List<Element> excludeValue = this.elt.getChildren("exclude");
112
        List<Element> excludeValue = this.elt.getChildren("exclude");
113
        if (excludeValue != null && excludeValue.size() > 0) {
113
        if (excludeValue != null && excludeValue.size() > 0) {
114
 
114
 
115
            listOfExcludedValues = new ArrayList<String>();
115
            listOfExcludedValues = new ArrayList<String>();
116
 
116
 
117
            for (Element element : excludeValue) {
117
            for (Element element : excludeValue) {
118
                String attributeValue = element.getAttributeValue("value");
118
                String attributeValue = element.getAttributeValue("value");
119
                listOfExcludedValues.add(attributeValue);
119
                listOfExcludedValues.add(attributeValue);
120
            }
120
            }
121
        }
121
        }
122
 
122
 
123
        if (res != null && listOfExcludedValues != null && listOfExcludedValues.contains(res.toString())) {
123
        if (res != null && listOfExcludedValues != null && listOfExcludedValues.contains(res.toString())) {
124
            res = null;
124
            res = null;
125
        }
125
        }
126
 
126
 
127
        final String k = this.elt.getAttributeValue("removeBreakLine");
127
        final String k = this.elt.getAttributeValue("removeBreakLine");
128
        boolean rmBreakLines = (k == null) ? false : k.equalsIgnoreCase("true");
128
        boolean rmBreakLines = (k == null) ? false : k.equalsIgnoreCase("true");
129
        if (rmBreakLines) {
129
        if (rmBreakLines) {
130
            res = (res == null ? res : res.toString().replaceAll("\n", ","));
130
            res = (res == null ? res : res.toString().replaceAll("\n", ","));
131
        }
131
        }
132
        return res;
132
        return res;
133
    }
133
    }
134
 
134
 
135
    private Object getFromSQLFunction(SQLField field, String function) {
135
    private Object getFromSQLFunction(SQLField field, String function) {
136
        SQLSelect sel = new SQLSelect();
136
        SQLSelect sel = new SQLSelect();
137
        sel.addSelect(field, function);
137
        sel.addSelect(field, function);
138
        Where w = new Where(field.getTable().getField("ID_" + this.row.getTable().getName()), "=", this.row.getID());
138
        Where w = new Where(field.getTable().getField("ID_" + this.row.getTable().getName()), "=", this.row.getID());
139
        sel.setWhere(w);
139
        sel.setWhere(w);
140
        return Configuration.getInstance().getBase().getDataSource().executeScalar(sel.asString());
140
        return Configuration.getInstance().getBase().getDataSource().executeScalar(sel.asString());
141
    }
141
    }
142
 
142
 
143
 
143
 
144
    public DateFormat format = new SimpleDateFormat("dd/MM/yyyy");
144
    public DateFormat format = new SimpleDateFormat("dd/MM/yyyy");
145
 
145
 
146
    protected String getStringProposition(SQLRowAccessor rowProp) {
146
    protected String getStringProposition(SQLRowAccessor rowProp) {
147
 
147
 
148
        return "Notre proposition " + rowProp.getString("NUMERO") + " du " + format.format(rowProp.getObject("DATE"));
148
        return "Notre proposition " + rowProp.getString("NUMERO") + " du " + format.format(rowProp.getObject("DATE"));
149
    }
149
    }
150
 
150
 
151
 
151
 
152
    public Double getTotalHTTable(SQLRowAccessor rowFact) {
152
    public Double getTotalHTTable(SQLRowAccessor rowFact) {
153
 
153
 
154
        SQLTable tableElt = Configuration.getInstance().getRoot().findTable("SAISIE_VENTE_FACTURE_ELEMENT");
154
        SQLTable tableElt = Configuration.getInstance().getRoot().findTable("SAISIE_VENTE_FACTURE_ELEMENT");
155
        Collection<? extends SQLRowAccessor> set = rowFact.getReferentRows(tableElt);
155
        Collection<? extends SQLRowAccessor> set = rowFact.getReferentRows(tableElt);
156
        long total = 0;
156
        long total = 0;
157
        for (SQLRowAccessor row : set) {
157
        for (SQLRowAccessor row : set) {
158
            total += row.getLong("T_PV_HT");
158
            total += row.getLong("T_PV_HT");
159
        }
159
        }
160
 
160
 
161
        return new Double(GestionDevise.currencyToString(total, false));
161
        return new Double(GestionDevise.currencyToString(total, false));
162
    }
162
    }
163
 
163
 
164
 
164
 
165
    /**
165
    /**
166
     * Calcul la date d'échéance d'un élément par rapport au mode de reglement et à la date
166
     * Calcul la date d'échéance d'un élément par rapport au mode de reglement et à la date
167
     * d'émission
167
     * d'émission
168
     * 
168
     * 
169
     * @param idModeRegl
169
     * @param idModeRegl
170
     * @param currentDate
170
     * @param currentDate
171
     * @return la date d'échéance au format dd/MM/yy si datePattern !=null sinon une Date
171
     * @return la date d'échéance au format dd/MM/yy si datePattern !=null sinon une Date
172
     */
172
     */
173
    protected Object getDateEcheance(int idModeRegl, Date currentDate, String datePattern) {
173
    protected Object getDateEcheance(int idModeRegl, Date currentDate, String datePattern) {
174
        SQLElement eltModeRegl = Configuration.getInstance().getDirectory().getElement("MODE_REGLEMENT");
174
        SQLElement eltModeRegl = Configuration.getInstance().getDirectory().getElement("MODE_REGLEMENT");
175
        SQLRow row = eltModeRegl.getTable().getRow(idModeRegl);
175
        SQLRow row = eltModeRegl.getTable().getRow(idModeRegl);
176
        int aJ = row.getInt("AJOURS");
176
        int aJ = row.getInt("AJOURS");
177
        int nJ = row.getInt("LENJOUR");
177
        int nJ = row.getInt("LENJOUR");
178
        if (aJ + nJ == 0) {
178
        if (aJ + nJ == 0) {
179
            if (!row.getBoolean("COMPTANT") && row.getBoolean("DATE_FACTURE")) {
179
            if (!row.getBoolean("COMPTANT") && row.getBoolean("DATE_FACTURE")) {
180
                return Configuration.getInstance().getTranslator().getLabelFor(row.getTable().getField("DATE_FACTURE"));
180
                return Configuration.getInstance().getTranslator().getLabelFor(row.getTable().getField("DATE_FACTURE"));
181
            } else {
181
            } else {
182
                return " ";
182
                return " ";
183
            }
183
            }
184
        }
184
        }
185
        Date calculDate = ModeDeReglementSQLElement.calculDate(aJ, nJ, currentDate);
185
        Date calculDate = ModeDeReglementSQLElement.calculDate(aJ, nJ, currentDate);
186
        if (datePattern != null && datePattern.trim().length() > 0) {
186
        if (datePattern != null && datePattern.trim().length() > 0) {
187
            final DateFormat format2 = new SimpleDateFormat(datePattern);
187
            final DateFormat format2 = new SimpleDateFormat(datePattern);
188
            return format2.format(calculDate);
188
            return format2.format(calculDate);
189
        } else {
189
        } else {
190
            return calculDate;
190
            return calculDate;
191
        }
191
        }
192
    }
192
    }
193
 
193
 
194
    public boolean isTypeReplace() {
194
    public boolean isTypeReplace() {
195
        // remplacement d'un pattern contenu dans la cellule
195
        // remplacement d'un pattern contenu dans la cellule
196
        return this.elt.getAttributeValue("type").equalsIgnoreCase("Replace");
196
        return this.elt.getAttributeValue("type").equalsIgnoreCase("Replace");
197
    }
197
    }
198
 
198
 
199
    public String getReplacePattern() {
199
    public String getReplacePattern() {
200
        return this.elt.getAttributeValue("replacePattern");
200
        return this.elt.getAttributeValue("replacePattern");
201
    }
201
    }
202
 
202
 
203
    public boolean isMultilineAuto() {
203
    public boolean isMultilineAuto() {
204
        // gestion manuel du multiligne
204
        // gestion manuel du multiligne
205
        final String multiLineValue = this.elt.getAttributeValue("controleMultiline");
205
        final String multiLineValue = this.elt.getAttributeValue("controleMultiline");
206
        return (multiLineValue == null) ? true : !multiLineValue.equalsIgnoreCase("false");
206
        return (multiLineValue == null) ? true : !multiLineValue.equalsIgnoreCase("false");
207
    }
207
    }
208
 
208
 
209
    public boolean isKeepingEmptyLines() {
209
    public boolean isKeepingEmptyLines() {
210
        // gestion manuel du multiligne
210
        // gestion manuel du multiligne
211
        final String k = this.elt.getAttributeValue("keepEmptyLines");
211
        final String k = this.elt.getAttributeValue("keepEmptyLines");
212
        return (k == null) ? false : k.equalsIgnoreCase("true");
212
        return (k == null) ? false : k.equalsIgnoreCase("true");
213
    }
213
    }
214
 
214
 
-
 
215
    public boolean isImage() {
-
 
216
        return this.elt.getAttributeValue("type").equalsIgnoreCase("image");
-
 
217
    }
215
}
218
}