OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 156 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 156 Rev 182
Line 1... Line 1...
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-2019 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.
Line 120... Line 120...
120
 
120
 
121
        if (r1 == null || r2 == null) {
121
        if (r1 == null || r2 == null) {
122
            // Clean date
122
            // Clean date
123
            final Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
123
            final Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
124
            c.setTimeInMillis(date.getTime());
124
            c.setTimeInMillis(date.getTime());
125
            c.set(Calendar.HOUR_OF_DAY, 0);
125
            c.set(Calendar.HOUR_OF_DAY, 23);
126
            c.set(Calendar.MINUTE, 0);
126
            c.set(Calendar.MINUTE, 59);
127
            c.set(Calendar.SECOND, 0);
127
            c.set(Calendar.SECOND, 59);
128
            c.set(Calendar.MILLISECOND, 0);
128
            c.set(Calendar.MILLISECOND, 59);
-
 
129
 
-
 
130
            // Limit pour récupérer le taux de la veille pour le taux réel
-
 
131
            if (!useBiased) {
-
 
132
                c.add(Calendar.DAY_OF_MONTH, -1);
-
 
133
            }
-
 
134
 
129
            final Date d = c.getTime();
135
            final Date d = c.getTime();
130
 
136
 
131
            // Get conversion info
137
            // Get conversion info
132
            final List<SQLRow> rowsFrom = getRates(from, d);
138
            final List<SQLRow> rowsFrom = getRates(from, d);
133
            final List<SQLRow> rowsTo = getRates(to, d);
139
            final List<SQLRow> rowsTo = getRates(to, d);
Line 201... Line 207...
201
                cacheBiased.put(key, Tuple2.create(r1, r2));
207
                cacheBiased.put(key, Tuple2.create(r1, r2));
202
            } else {
208
            } else {
203
                cacheNotBiased.put(key, Tuple2.create(r1, r2));
209
                cacheNotBiased.put(key, Tuple2.create(r1, r2));
204
            }
210
            }
205
        }
211
        }
-
 
212
        if (r1.equals(BigDecimal.ZERO)) {
-
 
213
            r1 = BigDecimal.ONE;
-
 
214
        }
206
        final BigDecimal result = amount.multiply(r2, DecimalUtils.HIGH_PRECISION).divide(r1, DecimalUtils.HIGH_PRECISION);
215
        final BigDecimal result = amount.multiply(r2, DecimalUtils.HIGH_PRECISION).divide(r1, DecimalUtils.HIGH_PRECISION);
207
        return result;
216
        return result;
208
    }
217
    }
209
 
218
 
210
    public List<SQLRow> getRates(String currencyCode, final Date d) {
219
    public List<SQLRow> getRates(String currencyCode, final Date d) {
Line 214... Line 223...
214
        Where w = new Where(t.getField("SRC"), "=", baseCurrencyCode);
223
        Where w = new Where(t.getField("SRC"), "=", baseCurrencyCode);
215
        w = w.and(new Where(t.getField("DST"), "=", currencyCode));
224
        w = w.and(new Where(t.getField("DST"), "=", currencyCode));
216
        w = w.and(new Where(t.getField("DATE"), "<=", d));
225
        w = w.and(new Where(t.getField("DATE"), "<=", d));
217
        select.setWhere(w);
226
        select.setWhere(w);
218
        select.addFieldOrder(t.getField("DATE"), Order.desc());
227
        select.addFieldOrder(t.getField("DATE"), Order.desc());
219
        // Limit pour récupérer le taux de la veille
228
        // On ne veut que le plus récent
220
        select.setLimit(2);
229
        select.setLimit(1);
221
        final List<SQLRow> rows = SQLRowListRSH.execute(select);
230
        final List<SQLRow> rows = SQLRowListRSH.execute(select);
222
        return rows;
231
        return rows;
223
    }
232
    }
224
}
233
}