OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 150 Rev 153
Line 7... Line 7...
7
import java.awt.GridBagLayout;
7
import java.awt.GridBagLayout;
8
import java.awt.event.ActionEvent;
8
import java.awt.event.ActionEvent;
9
import java.awt.event.ActionListener;
9
import java.awt.event.ActionListener;
10
import java.io.File;
10
import java.io.File;
11
import java.io.InputStream;
11
import java.io.InputStream;
-
 
12
import java.math.BigDecimal;
12
import java.text.DateFormat;
13
import java.text.DateFormat;
13
import java.text.SimpleDateFormat;
14
import java.text.SimpleDateFormat;
14
import java.util.ArrayList;
15
import java.util.ArrayList;
15
import java.util.Calendar;
16
import java.util.Calendar;
16
import java.util.Collections;
17
import java.util.Collections;
Line 32... Line 33...
32
import javax.swing.JRadioButton;
33
import javax.swing.JRadioButton;
33
import javax.swing.SwingConstants;
34
import javax.swing.SwingConstants;
34
import javax.swing.SwingUtilities;
35
import javax.swing.SwingUtilities;
35
import javax.swing.table.AbstractTableModel;
36
import javax.swing.table.AbstractTableModel;
36
import javax.swing.table.TableModel;
37
import javax.swing.table.TableModel;
-
 
38
import javax.xml.datatype.DatatypeConfigurationException;
-
 
39
import javax.xml.datatype.DatatypeFactory;
37
 
40
 
38
import org.jdom2.Document;
41
import org.jdom2.Document;
-
 
42
import org.jdom2.Element;
39
import org.jopencalendar.model.JCalendarItem;
43
import org.jopencalendar.model.JCalendarItem;
40
import org.openconcerto.erp.config.ComptaPropsConfiguration;
44
import org.openconcerto.erp.config.ComptaPropsConfiguration;
41
import org.openconcerto.erp.generationDoc.TemplateManager;
45
import org.openconcerto.erp.generationDoc.TemplateManager;
42
import org.openconcerto.openoffice.OOUtils;
46
import org.openconcerto.openoffice.OOUtils;
43
import org.openconcerto.openoffice.spreadsheet.Sheet;
47
import org.openconcerto.openoffice.spreadsheet.Sheet;
44
import org.openconcerto.openoffice.spreadsheet.SpreadSheet;
48
import org.openconcerto.openoffice.spreadsheet.SpreadSheet;
45
import org.openconcerto.sql.PropsConfiguration;
49
import org.openconcerto.sql.PropsConfiguration;
46
import org.openconcerto.sql.model.DBRoot;
50
import org.openconcerto.sql.model.DBRoot;
47
import org.openconcerto.sql.model.FieldMapper;
51
import org.openconcerto.sql.model.FieldMapper;
-
 
52
import org.openconcerto.sql.model.SQLRowAccessor;
48
import org.openconcerto.sql.model.SQLRowValues;
53
import org.openconcerto.sql.model.SQLRowValues;
49
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
54
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
50
import org.openconcerto.sql.model.SQLTable;
55
import org.openconcerto.sql.model.SQLTable;
51
import org.openconcerto.sql.model.Where;
56
import org.openconcerto.sql.model.Where;
52
import org.openconcerto.sql.sqlobject.SQLTextCombo;
57
import org.openconcerto.sql.sqlobject.SQLTextCombo;
Line 54... Line 59...
54
import org.openconcerto.ui.DefaultGridBagConstraints;
59
import org.openconcerto.ui.DefaultGridBagConstraints;
55
import org.openconcerto.ui.JDate;
60
import org.openconcerto.ui.JDate;
56
import org.openconcerto.ui.date.DateRangePlannerPanel;
61
import org.openconcerto.ui.date.DateRangePlannerPanel;
57
import org.openconcerto.utils.CollectionMap2.Mode;
62
import org.openconcerto.utils.CollectionMap2.Mode;
58
import org.openconcerto.utils.CompareUtils;
63
import org.openconcerto.utils.CompareUtils;
-
 
64
import org.openconcerto.utils.DecimalUtils;
59
import org.openconcerto.utils.ExceptionHandler;
65
import org.openconcerto.utils.ExceptionHandler;
60
import org.openconcerto.utils.ListMap;
66
import org.openconcerto.utils.ListMap;
61
import org.openconcerto.utils.StreamUtils;
67
import org.openconcerto.utils.StreamUtils;
62
import org.openconcerto.utils.StringUtils;
68
import org.openconcerto.utils.StringUtils;
63
import org.openconcerto.utils.TimeUtils;
69
import org.openconcerto.utils.TimeUtils;
Line 211... Line 217...
211
            }
217
            }
212
        });
218
        });
213
    }
219
    }
214
 
220
 
215
    static private final class Planner implements Comparable<Planner> {
221
    static private final class Planner implements Comparable<Planner> {
-
 
222
 
-
 
223
        static private final BigDecimal MS_PER_HOUR = BigDecimal.valueOf(1000 * 3600);
-
 
224
 
216
        private final String uid;
225
        private final String uid;
217
        private final String xml;
226
        private final String xml;
218
        private Date rangeStart;
227
        private Date rangeStart;
-
 
228
        private Date startTime;
-
 
229
        private BigDecimal hours;
219
 
230
 
220
        protected Planner(String uid, String xml) {
231
        protected Planner(String uid, String xml) {
221
            super();
232
            super();
222
            this.uid = uid;
233
            this.uid = uid;
223
            this.xml = xml;
234
            this.xml = xml;
Line 226... Line 237...
226
        public final String getUID() {
237
        public final String getUID() {
227
            return this.uid;
238
            return this.uid;
228
        }
239
        }
229
 
240
 
230
        public final String getDescription() {
241
        public final String getDescription() {
231
            return DateRangePlannerPanel.getDescriptionFromXML(this.xml);
242
            return DateRangePlannerPanel.getDescriptionFromXML(this.xml, false);
232
        }
243
        }
233
 
244
 
234
        public final Date getRangeStart() {
245
        public final Date getRangeStart() {
235
            if (this.rangeStart == null) {
246
            if (this.rangeStart == null) {
-
 
247
                parse();
-
 
248
            }
-
 
249
            return this.rangeStart;
-
 
250
        }
-
 
251
 
-
 
252
        protected void parse() {
236
                try {
253
            try {
237
                    final Document doc = JDOM2Utils.parseStringDocument(this.xml);
254
                final Document doc = JDOM2Utils.parseStringDocument(this.xml);
238
                    this.rangeStart = new Date(Long.valueOf(doc.getRootElement().getChild("range").getAttributeValue("start")));
255
                this.rangeStart = new Date(Long.valueOf(doc.getRootElement().getChild("range").getAttributeValue("start")));
-
 
256
 
-
 
257
                final Element scheduleElem = doc.getRootElement().getChild("schedule");
-
 
258
                this.startTime = new Date(Long.valueOf(scheduleElem.getAttributeValue("start")));
-
 
259
                final long endTime = Long.valueOf(scheduleElem.getAttributeValue("end"));
-
 
260
                this.hours = DecimalUtils.round(BigDecimal.valueOf(endTime - this.startTime.getTime()).divide(MS_PER_HOUR, DecimalUtils.HIGH_PRECISION), 5);
239
                } catch (Exception e) {
261
            } catch (Exception e) {
240
                    throw new IllegalStateException("couldn't get start for " + this.xml, e);
262
                throw new IllegalStateException("couldn't get start for " + this.xml, e);
241
                }
263
            }
242
            }
264
        }
-
 
265
 
-
 
266
        public final Date getStartTime() {
-
 
267
            if (this.startTime == null) {
-
 
268
                parse();
-
 
269
            }
-
 
270
            return this.startTime;
-
 
271
        }
-
 
272
 
-
 
273
        public final BigDecimal getHours() {
-
 
274
            if (this.hours == null) {
-
 
275
                parse();
-
 
276
            }
243
            return this.rangeStart;
277
            return this.hours;
244
        }
278
        }
245
 
279
 
246
        @Override
280
        @Override
247
        public int hashCode() {
281
        public int hashCode() {
248
            final int prime = 31;
282
            final int prime = 31;
Line 284... Line 318...
284
        final SQLRowValues valOperation = new SQLRowValues(table);
318
        final SQLRowValues valOperation = new SQLRowValues(table);
285
 
319
 
286
        final SQLRowValues valSite = new SQLRowValues(root.getTable(ModuleOperation.TABLE_SITE));
320
        final SQLRowValues valSite = new SQLRowValues(root.getTable(ModuleOperation.TABLE_SITE));
287
        valSite.putNulls("NAME", "COMMENT");
321
        valSite.putNulls("NAME", "COMMENT");
288
 
322
 
289
        final SQLRowValues userVals = valOperation.putRowValues("ID_USER_COMMON").putNulls("NOM");
323
        valOperation.putRowValues("ID_USER_COMMON").putNulls("NOM", "PRENOM");
290
 
-
 
291
        // valOperation.put("ID_CALENDAR_ITEM_GROUP", valsCalendarItemsGroup);
324
        // valOperation.put("ID_CALENDAR_ITEM_GROUP", valsCalendarItemsGroup);
292
        valOperation.put("ID_USER_COMMON", userVals);
-
 
293
        valOperation.put("ID_SITE", valSite);
325
        valOperation.put("ID_SITE", valSite);
294
        valOperation.putNulls("STATUS", "DESCRIPTION", "TYPE", "PLANNER_XML", "PLANNER_UID");
326
        valOperation.putNulls("STATUS", "DESCRIPTION", "TYPE", "PLANNER_XML", "PLANNER_UID");
295
 
327
 
296
        final SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(valOperation);
328
        final SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(valOperation);
297
        fetcher.setFullOnly(true);
329
        fetcher.setFullOnly(true);
Line 300... Line 332...
300
        final ListMap<Planner, SQLRowValues> operationsByPlanner = new ListMap<>(new TreeMap<Planner, List<SQLRowValues>>(), Mode.NULL_FORBIDDEN);
332
        final ListMap<Planner, SQLRowValues> operationsByPlanner = new ListMap<>(new TreeMap<Planner, List<SQLRowValues>>(), Mode.NULL_FORBIDDEN);
301
        for (SQLRowValues d : itemsFetched) {
333
        for (SQLRowValues d : itemsFetched) {
302
            operationsByPlanner.add(new Planner(d.getString("PLANNER_UID"), d.getString("PLANNER_XML")), d);
334
            operationsByPlanner.add(new Planner(d.getString("PLANNER_UID"), d.getString("PLANNER_XML")), d);
303
        }
335
        }
304
        final List<Entry<Planner, List<SQLRowValues>>> items = new ArrayList<>(operationsByPlanner.entrySet());
336
        final List<Entry<Planner, List<SQLRowValues>>> items = new ArrayList<>(operationsByPlanner.entrySet());
-
 
337
        final DatatypeFactory dataTypeFactory;
-
 
338
        try {
-
 
339
            dataTypeFactory = DatatypeFactory.newInstance();
-
 
340
        } catch (DatatypeConfigurationException e) {
-
 
341
            throw new IllegalStateException(e);
-
 
342
        }
305
 
343
 
306
        TableModel model = new AbstractTableModel() {
344
        TableModel model = new AbstractTableModel() {
307
 
345
 
308
            @Override
346
            @Override
309
            public int getRowCount() {
347
            public int getRowCount() {
310
                return items.size();
348
                return items.size();
311
            }
349
            }
312
 
350
 
313
            @Override
351
            @Override
314
            public int getColumnCount() {
352
            public int getColumnCount() {
315
                return 5;
353
                return 7;
316
            }
354
            }
317
 
355
 
318
            @Override
356
            @Override
319
            public Object getValueAt(int rowIndex, int columnIndex) {
357
            public Object getValueAt(int rowIndex, int columnIndex) {
320
                final Entry<Planner, List<SQLRowValues>> rows = items.get(rowIndex);
358
                final Entry<Planner, List<SQLRowValues>> rows = items.get(rowIndex);
Line 322... Line 360...
322
                // for now, only the "Employé" column check all operations for a planner, the other
360
                // for now, only the "Employé" column check all operations for a planner, the other
323
                // columns just take the first one.
361
                // columns just take the first one.
324
                final SQLRowValues i = rows.getValue().get(0);
362
                final SQLRowValues i = rows.getValue().get(0);
325
                switch (columnIndex) {
363
                switch (columnIndex) {
326
                case 0:
364
                case 0:
-
 
365
                    return dataTypeFactory.newDurationDayTime(planner.getStartTime().getTime());
-
 
366
 
-
 
367
                case 1:
-
 
368
                    return planner.getHours();
-
 
369
 
-
 
370
                case 2:
327
                    // Plannif
371
                    // Plannif
328
                    return planner.getDescription();
372
                    return planner.getDescription();
329
 
373
 
330
                case 1:
374
                case 3:
331
                    // Employé
375
                    // Employé
332
                    final ListMap<Integer, SQLRowValues> operationsByUserID = new ListMap<>();
376
                    final ListMap<Integer, SQLRowValues> operationsByUserID = new ListMap<>();
333
                    for (final SQLRowValues r : rows.getValue()) {
377
                    for (final SQLRowValues r : rows.getValue()) {
334
                        operationsByUserID.add(r.getForeignID("ID_USER_COMMON"), r);
378
                        operationsByUserID.add(r.getForeignID("ID_USER_COMMON"), r);
335
                    }
379
                    }
Line 347... Line 391...
347
                    final ListIterator<Entry<Integer, List<SQLRowValues>>> listIter = entries.listIterator();
391
                    final ListIterator<Entry<Integer, List<SQLRowValues>>> listIter = entries.listIterator();
348
                    final StringBuilder sb = new StringBuilder(128);
392
                    final StringBuilder sb = new StringBuilder(128);
349
                    while (listIter.hasNext()) {
393
                    while (listIter.hasNext()) {
350
                        final Entry<Integer, List<SQLRowValues>> element = listIter.next();
394
                        final Entry<Integer, List<SQLRowValues>> element = listIter.next();
351
                        final SQLRowValues operationR = element.getValue().get(0);
395
                        final SQLRowValues operationR = element.getValue().get(0);
-
 
396
                        final SQLRowAccessor userR = operationR.getForeign("ID_USER_COMMON");
352
                        sb.append(operationR.getForeign("ID_USER_COMMON").getString("NOM"));
397
                        sb.append(userR.getString("PRENOM") + " " + userR.getString("NOM"));
353
                        if (listIter.previousIndex() > 0) {
398
                        if (listIter.previousIndex() > 0) {
354
                            sb.append(" (");
399
                            sb.append(" (");
355
                            sb.append(element.getValue().size());
400
                            sb.append(element.getValue().size());
356
                            sb.append(")");
401
                            sb.append(")");
357
                        }
402
                        }
358
                        if (listIter.hasNext()) {
403
                        if (listIter.hasNext()) {
359
                            sb.append(", ");
404
                            sb.append(", ");
360
                        }
405
                        }
361
                    }
406
                    }
362
                    return sb.toString();
407
                    return sb.toString();
363
                case 2:
408
                case 4:
364
                    // Nature
409
                    // Nature
365
                    final String type = i.getString("TYPE");
410
                    final String type = i.getString("TYPE");
366
                    return type;
411
                    return type;
367
                case 3:
412
                case 5:
368
                    // Chantier
413
                    // Chantier
369
                    final String siteName = i.getForeign("ID_SITE").getString("NAME");
414
                    final String siteName = i.getForeign("ID_SITE").getString("NAME");
370
                    return siteName;
415
                    return siteName;
371
                case 4:
416
                case 6:
372
                    // Description
417
                    // Description
373
                    final String desc = i.getString("DESCRIPTION");
418
                    final String desc = i.getString("DESCRIPTION");
374
                    return desc;
419
                    return desc;
375
                default:
420
                default:
376
                    break;
421
                    break;