OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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