OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
185 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
5
 *
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
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.
10
 *
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
13
 
14
 package org.openconcerto.erp.generationDoc.provider;
15
 
16
import org.openconcerto.erp.generationDoc.SpreadSheetCellValueContext;
17
import org.openconcerto.erp.generationDoc.SpreadSheetCellValueProviderManager;
18
import org.openconcerto.sql.model.SQLRowAccessor;
19
 
20
import java.text.DateFormat;
21
import java.text.SimpleDateFormat;
22
import java.util.Calendar;
23
import java.util.Collection;
24
 
25
public class BatchListProvider extends UserInitialsValueProvider {
26
 
27
    private final String refTable;
28
 
29
    public BatchListProvider(String refTable) {
30
        this.refTable = refTable;
31
    }
32
 
33
    @Override
34
    public Object getValue(SpreadSheetCellValueContext context) {
35
        final DateFormat format = new SimpleDateFormat("dd/MM/yyyy");
36
        final SQLRowAccessor row = context.getRow();
37
 
38
        final Collection<? extends SQLRowAccessor> cols = row.asRow().getReferentRows(row.getTable().getTable(this.refTable));
39
        final StringBuilder res = new StringBuilder();
40
        for (SQLRowAccessor sqlRowAccessor : cols) {
41
            final Calendar dluo = sqlRowAccessor.getDate("DLUO");
42
            final Calendar dlc = sqlRowAccessor.getDate("DLC");
43
            final String lot = sqlRowAccessor.getString("NUMERO_LOT");
44
            final String serie = sqlRowAccessor.getString("NUMERO_SERIE");
45
            if (res.length() > 0) {
46
                res.append("\n");
47
            }
48
            if (serie != null && serie.trim().length() > 0) {
49
                res.append("N° Série : " + serie);
50
            }
51
            if (lot != null && lot.trim().length() > 0) {
52
                if (res.length() > 0) {
53
                    res.append(", ");
54
                }
55
                res.append("N° Lot : " + lot);
56
            }
57
            if (dlc != null) {
58
                if (res.length() > 0) {
59
                    res.append(", ");
60
                }
61
                res.append("DLC : " + format.format(dlc.getTime()));
62
            }
63
            if (dluo != null) {
64
                if (res.length() > 0) {
65
                    res.append(", ");
66
                }
67
                res.append("DLUO : " + format.format(dluo.getTime()));
68
            }
69
 
70
        }
71
 
72
        return res.toString();
73
    }
74
 
75
    public static void register() {
76
        SpreadSheetCellValueProviderManager.put("sales.batch.list", new BatchListProvider("LOT_LIVRAISON"));
77
        SpreadSheetCellValueProviderManager.put("purchase.batch.list", new BatchListProvider("LOT_RECEPTION"));
78
 
79
    }
80
}