OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 182 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
182 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.math.BigDecimal;
21
 
22
public class QteLineDocProvider extends UserInitialsValueProvider {
23
 
24
    protected enum TypePoidsDocProvider {
25
        POIDS_NET, POIDS_BRUT
26
    };
27
 
28
    protected final TypePoidsDocProvider type;
29
 
30
    public QteLineDocProvider(TypePoidsDocProvider t) {
31
        this.type = t;
32
    }
33
 
34
    @Override
35
    public Object getValue(SpreadSheetCellValueContext context) {
36
        SQLRowAccessor sqlRowAccessor = context.getRow();
37
        return getPoidsFromRow(sqlRowAccessor);
38
 
39
    }
40
 
41
    protected BigDecimal getPoidsFromRow(SQLRowAccessor sqlRowAccessor) {
42
        final BigDecimal nbColis;
43
        if (sqlRowAccessor.getObject("NB_COLIS") != null) {
44
            nbColis = new BigDecimal(sqlRowAccessor.getInt("NB_COLIS"));
45
        } else {
46
            nbColis = BigDecimal.ZERO;
47
        }
48
 
49
        final BigDecimal qteUV = sqlRowAccessor.getBigDecimal("QTE_UNITAIRE");
185 ilm 50
        final BigDecimal qte = sqlRowAccessor.getTable().getName().equalsIgnoreCase("BON_DE_LIVRAISON_ELEMENT") ? new BigDecimal(sqlRowAccessor.getInt("QTE_LIVREE"))
51
                : new BigDecimal(sqlRowAccessor.getInt("QTE"));
182 ilm 52
 
53
        final BigDecimal tare;
54
        if (sqlRowAccessor.getObject("TARE") != null) {
185 ilm 55
            tare = sqlRowAccessor.getBigDecimal("TARE");
182 ilm 56
        } else {
57
            tare = BigDecimal.ZERO;
58
        }
59
 
185 ilm 60
        BigDecimal pdsNet = new BigDecimal(sqlRowAccessor.getFloat("POIDS")).multiply(qte).multiply(qteUV);
182 ilm 61
        if (this.type == TypePoidsDocProvider.POIDS_NET) {
62
            return pdsNet;
63
        } else {
64
            return pdsNet.add(tare.multiply(nbColis));
65
        }
66
    }
67
 
68
    public static void register() {
69
        SpreadSheetCellValueProviderManager.put("sales.poids.net.line", new QteLineDocProvider(TypePoidsDocProvider.POIDS_NET));
70
        SpreadSheetCellValueProviderManager.put("sales.poids.brut.line", new QteLineDocProvider(TypePoidsDocProvider.POIDS_BRUT));
71
    }
72
}