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
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
 
20
import java.math.BigDecimal;
21
import java.util.ArrayList;
22
import java.util.List;
23
 
24
public class Mouvement {
25
    private String numero;
26
    private List<Ecriture> ecritures = new ArrayList<>();
27
    private Number id;
28
    private BigDecimal debit = BigDecimal.ZERO;
29
    private BigDecimal credit = BigDecimal.ZERO;
30
    private Piece piece;
31
    // Source
32
    private Number idSource;
33
    private String source;
34
    private Mouvement pere;
35
    private MouvementPostInsertionAction postInsertionAction;
36
 
37
    public Mouvement() {
38
    }
39
 
40
    public void setSource(Number idSource, String source) {
41
        this.idSource = idSource;
42
        this.source = source;
43
    }
44
 
45
    public void add(Ecriture e) {
46
        this.ecritures.add(e);
47
        this.debit = this.debit.add(e.getDebit());
48
        this.credit = this.credit.add(e.getCredit());
49
        e.setMouvement(this);
50
    }
51
 
52
    List<Ecriture> getEcritures() {
53
        return this.ecritures;
54
    }
55
 
56
    void setId(Number id) {
57
        this.id = id;
58
    }
59
 
60
    public Number getId() {
61
        return this.id;
62
    }
63
 
64
    SQLInsert createInsert(DBRoot root) {
65
        final SQLInsert insert = new SQLInsert();
66
        final SQLTable table = root.getTable("MOUVEMENT");
67
        // FIXME le numero doit être généré en auto
68
        // Thread.dumpStack();
69
        // NUMERO = SELECT (MAX) ?
70
        // insert.add(table.getField("NUMERO"), this.numero);
71
        // select for update max(numero)
72
        if (this.idSource != null) {
73
            insert.add(table.getField("IDSOURCE"), this.idSource);
74
            insert.add(table.getField("SOURCE"), this.source);
75
        }
76
        insert.add(table.getField("ID_PIECE"), this.piece.getId().intValue());
77
        if (this.pere != null) {
78
            insert.add(table.getField("ID_MOUVEMENT_PERE"), this.pere.getId().intValue());
79
        }
80
        // TODO CREATION_DATE MODIFICATION_DATE
81
        return insert;
82
    }
83
 
84
    public boolean isBalanced() {
85
        BigDecimal d = BigDecimal.ZERO;
86
        BigDecimal c = BigDecimal.ZERO;
87
        for (Ecriture e : this.ecritures) {
88
            d = d.add(e.getDebit());
89
            c = c.add(e.getCredit());
90
        }
91
        return d.compareTo(c) == 0;
92
    }
93
 
94
    public Piece getPiece() {
95
        return this.piece;
96
    }
97
 
98
    public void setPiece(Piece piece) {
99
        this.piece = piece;
100
 
101
    }
102
 
103
    public boolean isEmpty() {
104
        return this.ecritures.isEmpty();
105
    }
106
 
107
    public MouvementPostInsertionAction getPostInsertionAction() {
108
        return this.postInsertionAction;
109
    }
110
 
111
    public void setAfterInsert(MouvementPostInsertionAction insertionAction) {
112
        this.postInsertionAction = insertionAction;
113
    }
114
}