OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 132 | Rev 182 | 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
 
132 ilm 27
    private final boolean shortName, alwaysShowOnZeroQty, pieceName;
80 ilm 28
 
180 ilm 29
    public static enum Type {
83 ilm 30
        NORMAL, SHIPMENT
31
    }
32
 
180 ilm 33
    public final Type type;
83 ilm 34
 
35
    private FormatedGlobalQtyTotalProvider(Type t, boolean shortName) {
132 ilm 36
        this(t, shortName, false, false);
93 ilm 37
    }
38
 
132 ilm 39
    private FormatedGlobalQtyTotalProvider(Type t, boolean shortName, boolean alwaysShowOnZeroQty, boolean withPieceName) {
80 ilm 40
        this.shortName = shortName;
83 ilm 41
        this.type = t;
93 ilm 42
        this.alwaysShowOnZeroQty = alwaysShowOnZeroQty;
132 ilm 43
        this.pieceName = withPieceName;
80 ilm 44
    }
45
 
46
    public Object getValue(SpreadSheetCellValueContext context) {
47
        final SQLRowAccessor row = context.getRow();
48
        final BigDecimal pv = row.getBigDecimal("PV_HT");
180 ilm 49
        if (!this.alwaysShowOnZeroQty && pv.compareTo(BigDecimal.ZERO) == 0) {
80 ilm 50
            return null;
51
        }
52
 
93 ilm 53
        final String field = this.type == Type.NORMAL ? "QTE" : "QTE_LIVREE";
54
        if (row.getObject(field) == null) {
55
            return null;
56
        }
80 ilm 57
 
93 ilm 58
        final int qte = row.getInt(field);
59
 
132 ilm 60
        if (!this.pieceName && row.getInt("ID_UNITE_VENTE") == UniteVenteArticleSQLElement.A_LA_PIECE) {
80 ilm 61
            return String.valueOf(qte);
62
        }
63
        String result = "";
180 ilm 64
        if (this.alwaysShowOnZeroQty || qte != 0) {
65
            result += qte + " x ";
83 ilm 66
            final BigDecimal qteUV = row.getBigDecimal("QTE_UNITAIRE");
67
 
68
            result += NumericFormat.getQtyDecimalFormat().format(qteUV);
69
            final SQLRowAccessor rMode = row.getForeign("ID_UNITE_VENTE");
70
            result += " " + ((this.shortName) ? rMode.getString("CODE") : rMode.getString("NOM"));
71
            // 3 x 5.5 meters
72
            // 1 x 6.3 meters -> 6.3 meters
80 ilm 73
        }
74
        return result;
75
    }
76
 
77
    public static void register() {
132 ilm 78
        SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.short.with.quantity", new FormatedGlobalQtyTotalProvider(Type.NORMAL, true, true, false));
83 ilm 79
        SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.short", new FormatedGlobalQtyTotalProvider(Type.NORMAL, true));
80
        SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit", new FormatedGlobalQtyTotalProvider(Type.NORMAL, false));
81
        SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.deliver.short", new FormatedGlobalQtyTotalProvider(Type.SHIPMENT, true));
82
        SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.deliver", new FormatedGlobalQtyTotalProvider(Type.SHIPMENT, false));
180 ilm 83
        SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.deliver.short.with.quantity", new FormatedGlobalQtyTotalProvider(Type.SHIPMENT, true, true, true));
132 ilm 84
        SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.alwaysnamed.short.with.quantity", new FormatedGlobalQtyTotalProvider(Type.NORMAL, true, true, true));
85
        SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.alwaysnamed.short", new FormatedGlobalQtyTotalProvider(Type.NORMAL, true, false, true));
86
        SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.alwaysnamed", new FormatedGlobalQtyTotalProvider(Type.NORMAL, false, false, true));
87
        SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.alwaysnamed.deliver.short", new FormatedGlobalQtyTotalProvider(Type.SHIPMENT, true, false, true));
88
        SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.alwaysnamed.deliver", new FormatedGlobalQtyTotalProvider(Type.SHIPMENT, false, false, true));
80 ilm 89
    }
90
}