OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev Author Line No. Line
174 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.generationEcritures;
15
 
16
import org.openconcerto.sql.model.DBRoot;
17
import org.openconcerto.sql.model.SQLInsert;
18
import org.openconcerto.sql.model.SQLTable;
19
import org.openconcerto.sql.users.User;
20
 
21
import java.math.BigDecimal;
22
import java.util.ArrayList;
23
import java.util.Date;
24
import java.util.HashMap;
25
import java.util.List;
26
import java.util.Map;
27
 
28
public class Ecriture {
29
    private Date date;
30
    private BigDecimal debit;
31
    private BigDecimal credit;
32
    private Mouvement mouvement;
33
    private String nom;
34
    private String compteNumero;
35
    private String compteNom;
36
    private Number compteID;
37
    private String journalNom;
38
    private String journalCode;
39
    private Number journalID;
40
    private List<AssociationAnalytique> associations;
41
    private Number id;
42
    private Map<String, Object> cookies;
43
    private boolean cloture;
44
    private boolean aNouveau;
45
    private Date dateValidation;
46
    private Date dateLettrage;
47
    private String lettrage;
48
 
49
    public Ecriture(Date date, BigDecimal debit, BigDecimal credit) {
50
        this.date = date;
51
        this.debit = debit;
52
        this.credit = credit;
53
    }
54
 
55
    public SQLInsert createInsert(DBRoot root, User user) {
56
        final SQLInsert insert = new SQLInsert();
57
        final SQLTable table = root.getTable("ECRITURE");
58
        insert.add(table.getField("DATE"), this.date);
59
        insert.add(table.getField("ID_MOUVEMENT"), this.mouvement.getId().intValue());
60
        insert.add(table.getField("DEBIT"), this.debit.multiply(new BigDecimal(100)).longValue());
61
        insert.add(table.getField("CREDIT"), this.credit.multiply(new BigDecimal(100)).longValue());
62
        insert.add(table.getField("NOM"), this.nom);
63
 
64
        if (this.compteNom == null) {
65
            throw new IllegalStateException("nom du compte manquant");
66
        }
67
        if (this.compteNumero == null || this.compteNumero.isEmpty()) {
68
            throw new IllegalStateException("numéro du compte manquant");
69
        }
70
        insert.add(table.getField("ID_COMPTE_PCE"), this.compteID);
71
        insert.add(table.getField("COMPTE_NUMERO"), this.compteNumero);
72
        insert.add(table.getField("COMPTE_NOM"), this.compteNom);
73
        if (this.journalNom == null) {
74
            throw new IllegalStateException("nom du journal manquant");
75
        }
76
        if (this.journalCode == null || this.journalCode.isEmpty()) {
77
            throw new IllegalStateException("code du journal manquant");
78
        }
79
        insert.add(table.getField("ID_JOURNAL"), this.journalID);
80
        insert.add(table.getField("JOURNAL_NOM"), this.journalNom);
81
        insert.add(table.getField("JOURNAL_CODE"), this.journalCode);
82
        insert.add(table.getField("NOM_PIECE"), this.mouvement.getPiece().getNom());
83
        insert.add(table.getField("ID_USER_COMMON_CREATE"), user.getId());
84
        insert.add(table.getField("ID_USER_COMMON_MODIFY"), user.getId());
85
        insert.add(table.getField("CLOTURE"), this.cloture);
86
        insert.add(table.getField("RAN"), this.aNouveau);
87
        if (this.dateValidation != null) {
88
            insert.add(table.getField("DATE_VALIDE"), this.dateValidation);
89
            insert.add(table.getField("VALIDE"), Boolean.TRUE);
90
        } else {
91
            insert.add(table.getField("DATE_VALIDE"), null);
92
            insert.add(table.getField("VALIDE"), Boolean.FALSE);
93
        }
94
        insert.add(table.getField("DATE_LETTRAGE"), this.dateLettrage);
177 ilm 95
        insert.add(table.getField("LETTRAGE"), this.lettrage == null || this.lettrage.isEmpty() ? "" : this.lettrage);
174 ilm 96
        return insert;
97
    }
98
 
99
    public void setDateValidation(Date dateValidation) {
100
        this.dateValidation = dateValidation;
101
    }
102
 
103
    public void setDateLettrage(Date dateLettrage) {
104
        this.dateLettrage = dateLettrage;
105
    }
106
 
107
    public void setLettrage(String lettrage) {
108
        this.lettrage = lettrage;
109
    }
110
 
111
    public void setCloture(boolean cloture) {
112
        this.cloture = cloture;
113
    }
114
 
115
    public void setaNouveau(boolean aNouveau) {
116
        this.aNouveau = aNouveau;
117
    }
118
 
119
    public String getNom() {
120
        return this.nom;
121
    }
122
 
123
    public void setNom(String nom) {
124
        this.nom = nom;
125
    }
126
 
127
    void setId(Number id) {
128
        this.id = id;
129
    }
130
 
131
    public Number getId() {
132
        return this.id;
133
    }
134
 
135
    public Number getCompteID() {
136
        return this.compteID;
137
    }
138
 
139
    public void setCompteID(Number compteID) {
140
        this.compteID = compteID;
141
    }
142
 
143
    public void setCompte(String numero, String nom) {
144
        this.compteNumero = numero;
145
        this.compteNom = nom;
146
    }
147
 
148
    public String getCompteNumero() {
149
        return this.compteNumero;
150
    }
151
 
152
    public String getCompteNom() {
153
        return this.compteNom;
154
    }
155
 
156
    public Number getJournalID() {
157
        return this.journalID;
158
    }
159
 
160
    public void setJournalID(Number journalID) {
161
        this.journalID = journalID;
162
    }
163
 
164
    public void setJournal(String code, String nom) {
165
        this.journalCode = code;
166
        this.journalNom = nom;
167
    }
168
 
169
    public String getJournalCode() {
170
        return this.journalCode;
171
    }
172
 
173
    public String getJournalNom() {
174
        return this.journalNom;
175
    }
176
 
177
    public BigDecimal getDebit() {
178
        return this.debit;
179
    }
180
 
181
    public BigDecimal getCredit() {
182
        return this.credit;
183
    }
184
 
185
    public Date getDate() {
186
        return this.date;
187
    }
188
 
189
    public void setMouvement(Mouvement mouvement) {
190
        this.mouvement = mouvement;
191
    }
192
 
193
    public List<AssociationAnalytique> getAssociationsAnalytiques() {
194
        return this.associations;
195
    }
196
 
197
    public void addAssociationAnalytique(AssociationAnalytique a) {
198
        if (this.associations == null) {
199
            this.associations = new ArrayList<>();
200
        }
201
        a.setEcriture(this);
202
        this.associations.add(a);
203
    }
204
 
205
    public void removeAssociationAnalytique(AssociationAnalytique a) {
206
        if (this.associations == null) {
207
            a.setEcriture(null);
208
            return;
209
        }
210
        this.associations.remove(a);
211
        a.setEcriture(null);
212
        if (this.associations.isEmpty()) {
213
            this.associations = null;
214
        }
215
    }
216
 
217
    public boolean hasAnalytique() {
218
        return this.associations != null;
219
    }
220
 
221
    public void putCookie(String key, Object value) {
222
        if (this.cookies == null) {
223
            this.cookies = new HashMap<>();
224
        }
225
        this.cookies.put(key, value);
226
    }
227
 
228
    public Object getCookie(String key) {
229
        return this.cookies.get(key);
230
    }
231
 
232
    @Override
233
    public String toString() {
234
        return "Ecriture : " + this.nom + ", Compte (id:" + this.compteID + ") " + this.compteNumero + " " + this.compteNom + ", Débit : " + this.debit + ", Crédit:" + this.credit;
235
    }
236
 
237
}