OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 93 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 93 Rev 156
Line 12... Line 12...
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.erp.core.common.ui;
14
 package org.openconcerto.erp.core.common.ui;
15
 
15
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
-
 
17
import org.openconcerto.erp.utils.TM;
17
import org.openconcerto.sql.Configuration;
18
import org.openconcerto.sql.Configuration;
18
import org.openconcerto.sql.model.SQLField;
19
import org.openconcerto.sql.model.SQLField;
19
import org.openconcerto.sql.model.SQLRow;
20
import org.openconcerto.sql.model.SQLRow;
20
import org.openconcerto.sql.model.SQLSelect;
21
import org.openconcerto.sql.model.SQLSelect;
21
import org.openconcerto.sql.model.Where;
22
import org.openconcerto.sql.model.Where;
Line 46... Line 47...
46
import javax.swing.event.EventListenerList;
47
import javax.swing.event.EventListenerList;
47
 
48
 
48
public class IListFilterDatePanel extends JPanel {
49
public class IListFilterDatePanel extends JPanel {
49
 
50
 
50
    private JDate dateDu, dateAu;
51
    private JDate dateDu, dateAu;
51
    private static final String CUSTOM_COMBO_ITEM = "Personnalisée";
52
    private static final String CUSTOM_COMBO_ITEM = TM.tr("dateFilter.custom");
52
    private Map<IListe, SQLField> mapList;
53
    private Map<IListe, SQLField> mapList;
53
    // Cache des transformers initiaux
54
    // Cache des transformers initiaux
54
    private Map<IListe, ITransformer<SQLSelect, SQLSelect>> mapListTransformer;
55
    private Map<IListe, ITransformer<SQLSelect, SQLSelect>> mapListTransformer;
55
    // Liste des filtres
56
    // Liste des filtres
56
    private Map<String, Tuple2<Date, Date>> map;
57
    private Map<String, Tuple2<Date, Date>> map;
Line 91... Line 92...
91
    private static void initDefaultMap() {
92
    private static void initDefaultMap() {
92
        mapDefault = new LinkedHashMap<String, Tuple2<Date, Date>>();
93
        mapDefault = new LinkedHashMap<String, Tuple2<Date, Date>>();
93
 
94
 
94
        // ALL
95
        // ALL
95
        Date emptyDate = null;
96
        Date emptyDate = null;
96
        mapDefault.put("Sans filtrage", Tuple2.create(emptyDate, emptyDate));
97
        mapDefault.put(TM.tr("dateFilter.none"), Tuple2.create(emptyDate, emptyDate));
97
 
98
 
98
        Calendar c = Calendar.getInstance();
99
        Calendar c = Calendar.getInstance();
99
        // Année courante
100
        // Année courante
100
        clearTimeSchedule(c);
101
        clearTimeSchedule(c);
101
        c.set(Calendar.DATE, 1);
102
        c.set(Calendar.DATE, 1);
Line 103... Line 104...
103
        Date d1 = c.getTime();
104
        Date d1 = c.getTime();
104
        setEndTimeSchedule(c);
105
        setEndTimeSchedule(c);
105
        c.set(Calendar.DATE, 31);
106
        c.set(Calendar.DATE, 31);
106
        c.set(Calendar.MONTH, 11);
107
        c.set(Calendar.MONTH, 11);
107
        Date d2 = c.getTime();
108
        Date d2 = c.getTime();
108
        mapDefault.put("Année courante", Tuple2.create(d1, d2));
109
        mapDefault.put(TM.tr("dateFilter.currentYear"), Tuple2.create(d1, d2));
109
 
110
 
110
        // Année précedente
111
        // Année précedente
111
        clearTimeSchedule(c);
112
        clearTimeSchedule(c);
112
        c.set(Calendar.DATE, 1);
113
        c.set(Calendar.DATE, 1);
113
        c.set(Calendar.MONTH, 0);
114
        c.set(Calendar.MONTH, 0);
Line 116... Line 117...
116
 
117
 
117
        setEndTimeSchedule(c);
118
        setEndTimeSchedule(c);
118
        c.set(Calendar.DATE, 31);
119
        c.set(Calendar.DATE, 31);
119
        c.set(Calendar.MONTH, 11);
120
        c.set(Calendar.MONTH, 11);
120
        Date d4 = c.getTime();
121
        Date d4 = c.getTime();
121
        mapDefault.put("Année précédente", Tuple2.create(d3, d4));
122
        mapDefault.put(TM.tr("dateFilter.previousYear"), Tuple2.create(d3, d4));
122
 
123
 
123
        // Mois courant
124
        // Mois courant
124
        c = Calendar.getInstance();
125
        c = Calendar.getInstance();
125
        clearTimeSchedule(c);
126
        clearTimeSchedule(c);
126
        c.set(Calendar.DATE, 1);
127
        c.set(Calendar.DATE, 1);
127
        Date d5 = c.getTime();
128
        Date d5 = c.getTime();
128
        c.set(Calendar.DATE, c.getActualMaximum(Calendar.DATE));
129
        c.set(Calendar.DATE, c.getActualMaximum(Calendar.DATE));
129
        setEndTimeSchedule(c);
130
        setEndTimeSchedule(c);
130
        Date d6 = c.getTime();
131
        Date d6 = c.getTime();
131
        mapDefault.put("Mois courant", Tuple2.create(d5, d6));
132
        mapDefault.put(TM.tr("dateFilter.currentMonth"), Tuple2.create(d5, d6));
132
 
133
 
133
        // Mois précédent
134
        // Mois précédent
134
        c = Calendar.getInstance();
135
        c = Calendar.getInstance();
135
        clearTimeSchedule(c);
136
        clearTimeSchedule(c);
136
        c.set(Calendar.DATE, 1);
137
        c.set(Calendar.DATE, 1);
137
        c.add(Calendar.MONTH, -1);
138
        c.add(Calendar.MONTH, -1);
138
        Date d7 = c.getTime();
139
        Date d7 = c.getTime();
139
        c.set(Calendar.DATE, c.getActualMaximum(Calendar.DATE));
140
        c.set(Calendar.DATE, c.getActualMaximum(Calendar.DATE));
140
        setEndTimeSchedule(c);
141
        setEndTimeSchedule(c);
141
        Date d8 = c.getTime();
142
        Date d8 = c.getTime();
142
        mapDefault.put("Mois précédent", Tuple2.create(d7, d8));
143
        mapDefault.put(TM.tr("dateFilter.previousMonth"), Tuple2.create(d7, d8));
143
 
144
 
144
        // semaine courante
145
        // semaine courante
145
        c = Calendar.getInstance();
146
        c = Calendar.getInstance();
146
        clearTimeSchedule(c);
147
        clearTimeSchedule(c);
147
        c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
148
        c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
148
        Date d9 = c.getTime();
149
        Date d9 = c.getTime();
149
        c.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
150
        c.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
150
        setEndTimeSchedule(c);
151
        setEndTimeSchedule(c);
151
        Date d10 = c.getTime();
152
        Date d10 = c.getTime();
152
        mapDefault.put("Semaine courante", Tuple2.create(d9, d10));
153
        mapDefault.put(TM.tr("dateFilter.currentWeek"), Tuple2.create(d9, d10));
153
 
154
 
154
        // semaine précédente
155
        // semaine précédente
155
        c = Calendar.getInstance();
156
        c = Calendar.getInstance();
156
        clearTimeSchedule(c);
157
        clearTimeSchedule(c);
157
        c.add(Calendar.DATE, -7);
158
        c.add(Calendar.DATE, -7);
158
        c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
159
        c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
159
        Date d11 = c.getTime();
160
        Date d11 = c.getTime();
160
        c.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
161
        c.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
161
        setEndTimeSchedule(c);
162
        setEndTimeSchedule(c);
162
        Date d12 = c.getTime();
163
        Date d12 = c.getTime();
163
        mapDefault.put("Semaine précédente", Tuple2.create(d11, d12));
164
        mapDefault.put(TM.tr("dateFilter.previousWeek"), Tuple2.create(d11, d12));
164
 
165
 
165
        // Exercice courant
166
        // Exercice courant
166
        SQLRow rowEx = ComptaPropsConfiguration.getInstanceCompta().getRowSociete().getForeignRow("ID_EXERCICE_COMMON");
167
        SQLRow rowEx = ComptaPropsConfiguration.getInstanceCompta().getRowSociete().getForeignRow("ID_EXERCICE_COMMON");
167
        Calendar c1 = rowEx.getDate("DATE_DEB");
168
        Calendar c1 = rowEx.getDate("DATE_DEB");
168
        clearTimeSchedule(c1);
169
        clearTimeSchedule(c1);
169
        Calendar c2 = rowEx.getDate("DATE_FIN");
170
        Calendar c2 = rowEx.getDate("DATE_FIN");
170
        setEndTimeSchedule(c2);
171
        setEndTimeSchedule(c2);
171
 
172
 
172
        final Tuple2<Date, Date> exerciceTuple = Tuple2.create(c1.getTime(), c2.getTime());
173
        final Tuple2<Date, Date> exerciceTuple = Tuple2.create(c1.getTime(), c2.getTime());
173
        if (findItem(exerciceTuple, mapDefault).equals(CUSTOM_COMBO_ITEM)) {
174
        if (findItem(exerciceTuple, mapDefault).equals(CUSTOM_COMBO_ITEM)) {
174
            mapDefault.put("Exercice courant", exerciceTuple);
175
            mapDefault.put(TM.tr("dateFilter.currentFiscalYear"), exerciceTuple);
175
        }
176
        }
176
 
177
 
177
        // Custom
178
        // Custom
178
        mapDefault.put(CUSTOM_COMBO_ITEM, null);
179
        mapDefault.put(CUSTOM_COMBO_ITEM, null);
179
    }
180
    }
Line 200... Line 201...
200
 
201
 
201
    }
202
    }
202
 
203
 
203
    public void init(Map<IListe, SQLField> mapList, Map<String, Tuple2<Date, Date>> m) {
204
    public void init(Map<IListe, SQLField> mapList, Map<String, Tuple2<Date, Date>> m) {
204
 
205
 
205
        this.setBorder(BorderFactory.createTitledBorder("Période"));
206
        this.setBorder(BorderFactory.createTitledBorder(TM.tr("dateFilter.range")));
206
        this.mapList = mapList;
207
        this.mapList = mapList;
207
 
208
 
208
        this.mapListTransformer = new HashMap<IListe, ITransformer<SQLSelect, SQLSelect>>();
209
        this.mapListTransformer = new HashMap<IListe, ITransformer<SQLSelect, SQLSelect>>();
209
        for (IListe l : mapList.keySet()) {
210
        for (IListe l : mapList.keySet()) {
210
 
211
 
Line 240... Line 241...
240
                    setPeriode(map.get(s));
241
                    setPeriode(map.get(s));
241
                }
242
                }
242
            });
243
            });
243
        }
244
        }
244
        // Filtre
245
        // Filtre
245
        this.add(new JLabel("Du"), c);
246
        this.add(new JLabel(TM.tr("dateFilter.from")), c);
246
        this.add(this.dateDu, c);
247
        this.add(this.dateDu, c);
247
        this.add(new JLabel("Au"), c);
248
        this.add(new JLabel(TM.tr("dateFilter.to")), c);
248
        this.add(this.dateAu, c);
249
        this.add(this.dateAu, c);
249
        this.dateAu.addValueListener(this.listener);
250
        this.dateAu.addValueListener(this.listener);
250
        this.dateDu.addValueListener(this.listener);
251
        this.dateDu.addValueListener(this.listener);
251
 
252
 
252
        IListFilterDateStateManager stateManager = new IListFilterDateStateManager(this, getConfigFile(mapList), true);
253
        IListFilterDateStateManager stateManager = new IListFilterDateStateManager(this, getConfigFile(mapList), true);