OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev Author Line No. Line
18 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.core.sales.pos.model;
15
 
142 ilm 16
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
17
import org.openconcerto.utils.DecimalUtils;
18
 
67 ilm 19
import java.math.BigDecimal;
142 ilm 20
import java.math.RoundingMode;
18 ilm 21
import java.util.HashMap;
22
import java.util.Map;
23
 
24
public class Article {
25
    private Categorie s;
26
    private String name;
151 ilm 27
    private boolean additionalCopyRequested = false;
132 ilm 28
    private BigDecimal priceTTC;
29
    private int idTaxe;
30
    private BigDecimal priceHT;
31
    private String barCode = "empty barcode";
32
    private String code = "";
61 ilm 33
    private final int id;
174 ilm 34
    // unité de vente (null si à la pièce)
35
    private String salesUnit;
18 ilm 36
    private static Map<String, Article> codes = new HashMap<String, Article>();
37
 
61 ilm 38
    public Article(Categorie s1, String string, int id) {
18 ilm 39
        this.s = s1;
61 ilm 40
        this.id = id;
18 ilm 41
        this.name = string;
42
        s1.addArticle(this);
43
    }
44
 
142 ilm 45
    public Article(Article a) {
46
        this.s = a.s;
47
        this.name = a.name;
48
        this.priceTTC = a.priceTTC;
49
        this.idTaxe = a.idTaxe;
50
        this.priceHT = a.priceHT;
51
        this.barCode = a.barCode;
52
        this.id = a.id;
174 ilm 53
        this.salesUnit = a.salesUnit;
142 ilm 54
        this.s.addArticle(this);
55
    }
56
 
151 ilm 57
    public boolean isAdditionalCopyRequested() {
174 ilm 58
        return this.additionalCopyRequested;
151 ilm 59
    }
60
 
61
    public void setAdditionalCopyRequested(boolean additionalCopyRequested) {
62
        this.additionalCopyRequested = additionalCopyRequested;
63
    }
64
 
61 ilm 65
    public int getId() {
66
        return this.id;
67
    }
68
 
132 ilm 69
    public BigDecimal getPriceWithoutTax() {
70
        return this.priceHT;
18 ilm 71
    }
72
 
132 ilm 73
    public void setPriceWithoutTax(BigDecimal priceHTInCents) {
74
        this.priceHT = priceHTInCents;
18 ilm 75
    }
76
 
77
    public int getIdTaxe() {
21 ilm 78
        return this.idTaxe;
18 ilm 79
    }
80
 
81
    public void setIdTaxe(int idTaxe) {
82
        this.idTaxe = idTaxe;
83
    }
84
 
85
    public void setBarCode(String bar) {
25 ilm 86
        this.barCode = bar;
18 ilm 87
        codes.put(bar, this);
88
    }
89
 
132 ilm 90
    public void setPriceWithTax(BigDecimal priceInCents) {
91
        this.priceTTC = priceInCents;
18 ilm 92
    }
93
 
132 ilm 94
    public BigDecimal getPriceWithTax() {
95
        return this.priceTTC;
18 ilm 96
    }
97
 
98
    public String getName() {
21 ilm 99
        return this.name;
18 ilm 100
    }
101
 
25 ilm 102
    public void setCode(String code) {
103
        this.code = code;
104
    }
105
 
18 ilm 106
    public String getCode() {
21 ilm 107
        return this.code;
25 ilm 108
    };
109
 
110
    public String getBarCode() {
111
        return this.barCode;
18 ilm 112
    }
113
 
114
    public Categorie getCategorie() {
21 ilm 115
        return this.s;
18 ilm 116
    }
117
 
118
    @Override
119
    public String toString() {
174 ilm 120
        return "Article:" + this.name + " " + this.priceTTC + " cents" + "(HT:" + this.priceHT + ") " + getSalesUnit();
18 ilm 121
    }
122
 
123
    public static Article getArticleFromBarcode(String code) {
124
        return codes.get(code);
125
    }
142 ilm 126
 
127
    @Override
128
    public boolean equals(Object obj) {
129
        if (obj == null)
130
            return false;
131
        return this.id == ((Article) obj).id;
132
    }
133
 
134
    @Override
135
    public int hashCode() {
136
        return this.id;
137
    }
138
 
139
    public void updatePriceWithoutTax(BigDecimal ht) {
140
        this.priceHT = ht;
141
        this.priceTTC = computePriceWithTax(ht, this.getIdTaxe());
142
    }
143
 
144
    public static BigDecimal computePriceWithTax(BigDecimal ht, int idTaxe) {
174 ilm 145
        final BigDecimal tax = BigDecimal.valueOf(TaxeCache.getCache().getTauxFromId(idTaxe)).movePointLeft(2).add(BigDecimal.ONE);
142 ilm 146
        return ht.multiply(tax).setScale(2, RoundingMode.HALF_UP);
147
    }
148
 
149
    public static BigDecimal computePriceWithoutTax(BigDecimal ttc, int idTaxe) {
174 ilm 150
        final BigDecimal tax = BigDecimal.valueOf(TaxeCache.getCache().getTauxFromId(idTaxe)).movePointLeft(2).add(BigDecimal.ONE);
142 ilm 151
        return ttc.divide(tax, DecimalUtils.HIGH_PRECISION).setScale(6, RoundingMode.HALF_UP);
152
    }
174 ilm 153
 
154
    public void setSalesUnit(String name) {
155
        this.salesUnit = name;
156
    }
157
 
158
    public String getSalesUnit() {
159
        return this.salesUnit;
160
    }
18 ilm 161
}