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.SpreadSheetCellValueProvider;
18
import org.openconcerto.erp.generationDoc.SpreadSheetCellValueProviderManager;
19
import org.openconcerto.utils.DecimalUtils;
20
 
21
import java.math.BigDecimal;
22
import java.math.RoundingMode;
23
 
24
public class RGProvider implements SpreadSheetCellValueProvider {
25
 
26
    private enum TypeRGProvider {
27
        HT_RESTANT(true, true), TTC_RESTANT(false, true), HT_RG(true, false), TTC_RG(false, false);
28
 
29
        private final boolean restant, ht;
30
 
31
        TypeRGProvider(boolean ht, boolean restant) {
32
            this.restant = restant;
33
            this.ht = ht;
34
        }
35
 
36
        public boolean isHt() {
37
            return this.ht;
38
        }
39
 
40
        public boolean isRestant() {
41
            return this.restant;
42
        }
43
    };
44
 
45
    private final TypeRGProvider type;
46
 
47
    public RGProvider(TypeRGProvider t) {
48
        this.type = t;
49
    }
50
 
51
    public Object getValue(SpreadSheetCellValueContext context) {
52
        final BigDecimal total;
53
        if (this.type.isHt()) {
54
            total = new BigDecimal(context.getRow().getLong("T_HT")).movePointLeft(2);
55
        } else {
56
            total = new BigDecimal(context.getRow().getLong("T_TTC")).movePointLeft(2);
57
        }
58
 
59
        final BigDecimal pourcentRG = context.getRow().getBigDecimal("POURCENT_RG");
60
        final BigDecimal totalRG = total.multiply(pourcentRG.movePointLeft(2), DecimalUtils.HIGH_PRECISION).setScale(2, RoundingMode.HALF_UP);
61
        if (this.type.isRestant()) {
62
            return total.subtract(totalRG);
63
        } else {
64
            return totalRG;
65
        }
66
    }
67
 
68
    public static void register() {
69
        SpreadSheetCellValueProviderManager.put("sales.rg.due", new RGProvider(TypeRGProvider.TTC_RG));
70
        SpreadSheetCellValueProviderManager.put("sales.total.sub.rg", new RGProvider(TypeRGProvider.TTC_RESTANT));
71
 
72
        SpreadSheetCellValueProviderManager.put("sales.rg.due.ht", new RGProvider(TypeRGProvider.HT_RG));
73
        SpreadSheetCellValueProviderManager.put("sales.total.sub.rg.ht", new RGProvider(TypeRGProvider.HT_RESTANT));
74
    }
75
 
76
}