OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 83 | Rev 132 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
80 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 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.core.common.ui.NumericFormat;
17
import org.openconcerto.erp.core.sales.product.element.UniteVenteArticleSQLElement;
18
import org.openconcerto.erp.generationDoc.SpreadSheetCellValueContext;
19
import org.openconcerto.erp.generationDoc.SpreadSheetCellValueProvider;
20
import org.openconcerto.erp.generationDoc.SpreadSheetCellValueProviderManager;
21
import org.openconcerto.sql.model.SQLRowAccessor;
22
 
23
import java.math.BigDecimal;
24
 
25
public class FormatedGlobalQtyTotalProvider implements SpreadSheetCellValueProvider {
26
 
93 ilm 27
    private final boolean shortName, alwaysShowOnZeroQty;
80 ilm 28
 
83 ilm 29
    private static enum Type {
30
        NORMAL, SHIPMENT
31
    }
32
 
33
    private final Type type;
34
 
35
    private FormatedGlobalQtyTotalProvider(Type t, boolean shortName) {
93 ilm 36
        this(t, shortName, false);
37
    }
38
 
39
    private FormatedGlobalQtyTotalProvider(Type t, boolean shortName, boolean alwaysShowOnZeroQty) {
80 ilm 40
        this.shortName = shortName;
83 ilm 41
        this.type = t;
93 ilm 42
        this.alwaysShowOnZeroQty = alwaysShowOnZeroQty;
80 ilm 43
    }
44
 
45
    public Object getValue(SpreadSheetCellValueContext context) {
46
        final SQLRowAccessor row = context.getRow();
47
        final BigDecimal pv = row.getBigDecimal("PV_HT");
93 ilm 48
        if (!alwaysShowOnZeroQty && pv.compareTo(BigDecimal.ZERO) == 0) {
80 ilm 49
            return null;
50
        }
51
 
93 ilm 52
        final String field = this.type == Type.NORMAL ? "QTE" : "QTE_LIVREE";
53
        if (row.getObject(field) == null) {
54
            return null;
55
        }
80 ilm 56
 
93 ilm 57
        final int qte = row.getInt(field);
58
 
80 ilm 59
        if (row.getInt("ID_UNITE_VENTE") == UniteVenteArticleSQLElement.A_LA_PIECE) {
60
            return String.valueOf(qte);
61
        }
62
        String result = "";
83 ilm 63
        if (qte > 0) {
64
            if (qte > 1) {
65
                result += qte + " x ";
66
            }
67
            final BigDecimal qteUV = row.getBigDecimal("QTE_UNITAIRE");
68
 
69
            result += NumericFormat.getQtyDecimalFormat().format(qteUV);
70
            final SQLRowAccessor rMode = row.getForeign("ID_UNITE_VENTE");
71
            result += " " + ((this.shortName) ? rMode.getString("CODE") : rMode.getString("NOM"));
72
            // 3 x 5.5 meters
73
            // 1 x 6.3 meters -> 6.3 meters
80 ilm 74
        }
75
        return result;
76
 
77
    }
78
 
79
    public static void register() {
93 ilm 80
        SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.short.with.quantity", new FormatedGlobalQtyTotalProvider(Type.NORMAL, true, true));
83 ilm 81
        SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.short", new FormatedGlobalQtyTotalProvider(Type.NORMAL, true));
82
        SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit", new FormatedGlobalQtyTotalProvider(Type.NORMAL, false));
83
        SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.deliver.short", new FormatedGlobalQtyTotalProvider(Type.SHIPMENT, true));
84
        SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.deliver", new FormatedGlobalQtyTotalProvider(Type.SHIPMENT, false));
80 ilm 85
    }
86
}