OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 174 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 42... Line 42...
42
 
42
 
43
public class ExportFEC extends AbstractExport {
43
public class ExportFEC extends AbstractExport {
44
 
44
 
45
    public static final char ZONE_SEPARATOR = '\t';
45
    public static final char ZONE_SEPARATOR = '\t';
46
    public static final char RECORD_SEPARATOR = '\n';
46
    public static final char RECORD_SEPARATOR = '\n';
47
    private static final char REPLACEMENT = ' ';
-
 
-
 
47
    
48
    public static final List<String> COLS = Arrays.asList("JournalCode", "JournalLib", "EcritureNum", "EcritureDate", "CompteNum", "CompteLib", "CompAuxNum", "CompAuxLib", "PieceRef", "PieceDate",
48
    public static final List<String> COLS = Arrays.asList("JournalCode", "JournalLib", "EcritureNum", "EcritureDate", "CompteNum", "CompteLib", "CompAuxNum", "CompAuxLib", "PieceRef", "PieceDate",
49
            "EcritureLib", "Debit", "Credit", "EcritureLet", "DateLet", "ValidDate", "Montantdevise", "Idevise");
49
            "EcritureLib", "Debit", "Credit", "EcritureLet", "DateLet", "ValidDate", "Montantdevise", "Idevise");
50
 
50
 
51
    private final DecimalFormat format = new DecimalFormat("##0.00", DecimalFormatSymbols.getInstance(Locale.FRANCE));
51
    private final DecimalFormat format = new DecimalFormat("##0.00", DecimalFormatSymbols.getInstance(Locale.FRANCE));
52
    private List<Object[]> data;
52
    private List<Object[]> data;
Line 97... Line 97...
97
    private final void addEmptyField(final List<String> line) {
97
    private final void addEmptyField(final List<String> line) {
98
        line.add(null);
98
        line.add(null);
99
    }
99
    }
100
 
100
 
101
    private final void addAmountField(final List<String> line, final Number cents) {
101
    private final void addAmountField(final List<String> line, final Number cents) {
102
        final String formattedAmount = format.format(BigDecimal.valueOf(cents.longValue()).movePointLeft(2));
102
        final String formattedAmount = this.format.format(BigDecimal.valueOf(cents.longValue()).movePointLeft(2));
103
        line.add(formattedAmount);
103
        line.add(formattedAmount);
104
    }
104
    }
105
 
105
 
106
    private final void addField(final List<String> line, final String s) {
106
    private final void addField(final List<String> line, final String s) {
107
        if (s == null) {
107
        if (s == null) {
108
            throw new NullPointerException("Valeur manquante pour remplir la ligne : " + line);
108
            throw new NullPointerException("Valeur manquante pour remplir la ligne : " + line);
109
        }
109
        }
110
        final String escapedString = StringUtils.toAsciiString(s).trim();
110
        final String escapedString = strongEscape(s).trim();
-
 
111
        line.add(escapedString);
-
 
112
    }
-
 
113
 
-
 
114
    private final String strongEscape(String str) {
-
 
115
        if (str == null) {
-
 
116
            return "";
-
 
117
        }
-
 
118
        final int length = str.length();
111
        line.add(escapedString.replace(ZONE_SEPARATOR, REPLACEMENT).replace(RECORD_SEPARATOR, REPLACEMENT));
119
        final StringBuilder b = new StringBuilder(length);
-
 
120
        for (int i = 0; i < length; i++) {
-
 
121
            final char c = str.charAt(i);
-
 
122
            final char newChar;
-
 
123
            if (c > 31 && c < 126 && c != ';') {
-
 
124
                // ';' is escaped to avoid issue with Excel
-
 
125
                newChar = c;
-
 
126
            } else if (c == 'é' || c == 'è' || c == 'ê') {
-
 
127
                newChar = 'e';
-
 
128
            } else if (c == 'â' || c == 'à') {
-
 
129
                newChar = 'a';
-
 
130
            } else if (c == 'î') {
-
 
131
                newChar = 'i';
-
 
132
            } else if (c == 'ù' || c == 'û') {
-
 
133
                newChar = 'u';
-
 
134
            } else if (c == 'ô') {
-
 
135
                newChar = 'o';
-
 
136
            } else if (c == 'ç') {
-
 
137
                newChar = 'c';
-
 
138
            } else {
-
 
139
                newChar = ' ';
-
 
140
            }
-
 
141
            b.append(newChar);
-
 
142
        }
-
 
143
        return b.toString();
112
    }
144
    }
113
 
145
 
114
    @Override
146
    @Override
115
    protected void export(OutputStream out) throws IOException {
147
    protected void export(OutputStream out) throws IOException {
116
        final Writer bufOut = new OutputStreamWriter(out, StringUtils.ISO8859_15);
148
        final Writer bufOut = new OutputStreamWriter(out, StringUtils.ISO8859_15);
Line 184... Line 216...
184
            if (array[12] != null) {
216
            if (array[12] != null) {
185
                final String ecritureDateValid = dateFormat.format(array[12]);
217
                final String ecritureDateValid = dateFormat.format(array[12]);
186
                line.add(ecritureDateValid);
218
                line.add(ecritureDateValid);
187
            } else {
219
            } else {
188
                line.add("");
220
                line.add("");
189
                if (cloture) {
221
                if (this.cloture) {
190
                    bufOut.close();
222
                    bufOut.close();
191
                    JOptionPane.showMessageDialog(new JFrame(), "Une écriture n'est pas validée (pas de date):\n" + line, "Erreur FEC", JOptionPane.ERROR_MESSAGE);
223
                    JOptionPane.showMessageDialog(new JFrame(), "Une écriture n'est pas validée (pas de date):\n" + line, "Erreur FEC", JOptionPane.ERROR_MESSAGE);
192
                    return;
224
                    return;
193
                }
225
                }
194
            }
226
            }