OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 180 | 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
 *
182 ilm 4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
80 ilm 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 {
182 ilm 30
        NORMAL, SHIPMENT, REMAIND
83 ilm 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");
182 ilm 49
        if (!this.alwaysShowOnZeroQty && pv != null && pv.compareTo(BigDecimal.ZERO) == 0) {
80 ilm 50
            return null;
51
        }
52
 
182 ilm 53
        final String field;
54
        if (this.type == Type.NORMAL) {
55
            field = "QTE";
56
        } else if (row.getTable().contains("QTE_LIVREE")) {
57
            field = "QTE_LIVREE";
58
        } else if (row.getTable().contains("QTE_ORIGINE")) {
59
            field = "QTE_ORIGINE";
60
        } else {
61
            return null;
62
        }
93 ilm 63
        if (row.getObject(field) == null) {
64
            return null;
65
        }
80 ilm 66
 
182 ilm 67
        int qte = row.getInt(field);
68
        if (this.type == Type.REMAIND) {
69
            if (row.getObject("QTE") != null) {
70
                if (field.equalsIgnoreCase("QTE_ORIGINE")) {
71
                    qte = qte - row.getInt("QTE");
72
                } else {
73
                    qte = row.getInt("QTE") - qte;
74
                }
75
            }
76
        }
93 ilm 77
 
132 ilm 78
        if (!this.pieceName && row.getInt("ID_UNITE_VENTE") == UniteVenteArticleSQLElement.A_LA_PIECE) {
80 ilm 79
            return String.valueOf(qte);
80
        }
81
        String result = "";
180 ilm 82
        if (this.alwaysShowOnZeroQty || qte != 0) {
83
            result += qte + " x ";
83 ilm 84
            final BigDecimal qteUV = row.getBigDecimal("QTE_UNITAIRE");
85
 
86
            result += NumericFormat.getQtyDecimalFormat().format(qteUV);
87
            final SQLRowAccessor rMode = row.getForeign("ID_UNITE_VENTE");
88
            result += " " + ((this.shortName) ? rMode.getString("CODE") : rMode.getString("NOM"));
89
            // 3 x 5.5 meters
90
            // 1 x 6.3 meters -> 6.3 meters
80 ilm 91
        }
92
        return result;
93
    }
94
 
95
    public static void register() {
132 ilm 96
        SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.short.with.quantity", new FormatedGlobalQtyTotalProvider(Type.NORMAL, true, true, false));
83 ilm 97
        SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.short", new FormatedGlobalQtyTotalProvider(Type.NORMAL, true));
98
        SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit", new FormatedGlobalQtyTotalProvider(Type.NORMAL, false));
99
        SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.deliver.short", new FormatedGlobalQtyTotalProvider(Type.SHIPMENT, true));
100
        SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.deliver", new FormatedGlobalQtyTotalProvider(Type.SHIPMENT, false));
180 ilm 101
        SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.deliver.short.with.quantity", new FormatedGlobalQtyTotalProvider(Type.SHIPMENT, true, true, true));
182 ilm 102
        SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.remainder.short", new FormatedGlobalQtyTotalProvider(Type.REMAIND, true));
103
        SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.remainder", new FormatedGlobalQtyTotalProvider(Type.REMAIND, false));
104
        SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.remainder.short.with.quantity", new FormatedGlobalQtyTotalProvider(Type.REMAIND, true, true, true));
132 ilm 105
        SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.alwaysnamed.short.with.quantity", new FormatedGlobalQtyTotalProvider(Type.NORMAL, true, true, true));
106
        SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.alwaysnamed.short", new FormatedGlobalQtyTotalProvider(Type.NORMAL, true, false, true));
107
        SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.alwaysnamed", new FormatedGlobalQtyTotalProvider(Type.NORMAL, false, false, true));
108
        SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.alwaysnamed.deliver.short", new FormatedGlobalQtyTotalProvider(Type.SHIPMENT, true, false, true));
109
        SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.alwaysnamed.deliver", new FormatedGlobalQtyTotalProvider(Type.SHIPMENT, false, false, true));
182 ilm 110
        SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.alwaysnamed.remainder.short", new FormatedGlobalQtyTotalProvider(Type.REMAIND, true, false, true));
111
        SpreadSheetCellValueProviderManager.put("supplychain.element.qtyunit.alwaysnamed.remainder", new FormatedGlobalQtyTotalProvider(Type.REMAIND, false, false, true));
80 ilm 112
    }
113
}