OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 156 | 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.finance.accounting.element;
15
 
16
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
17
import org.openconcerto.sql.element.BaseSQLComponent;
18
import org.openconcerto.sql.element.SQLComponent;
174 ilm 19
import org.openconcerto.sql.element.SQLElementLink.LinkType;
20
import org.openconcerto.sql.element.SQLElementLinksSetup;
83 ilm 21
import org.openconcerto.sql.model.FieldPath;
22
import org.openconcerto.sql.model.SQLRowAccessor;
23
import org.openconcerto.sql.model.graph.Path;
24
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn;
142 ilm 25
import org.openconcerto.sql.view.list.SQLTableModelSource;
83 ilm 26
import org.openconcerto.utils.CollectionUtils;
18 ilm 27
 
83 ilm 28
import java.math.BigDecimal;
18 ilm 29
import java.util.ArrayList;
30
import java.util.List;
83 ilm 31
import java.util.Set;
18 ilm 32
 
33
import javax.swing.JTextField;
34
 
35
public class AssociationAnalytiqueSQLElement extends ComptaSQLConfElement {
36
 
37
    public AssociationAnalytiqueSQLElement() {
38
        super("ASSOCIATION_ANALYTIQUE", "une association analytique", "associations analytiques");
73 ilm 39
 
40
    }
41
 
42
    @Override
43
    protected void ffInited() {
44
        super.ffInited();
18 ilm 45
        this.setAction("ID_ECRITURE", ReferenceAction.CASCADE);
46
        this.setAction("ID_SAISIE_KM_ELEMENT", ReferenceAction.CASCADE);
47
    }
48
 
174 ilm 49
    @Override
50
    protected void setupLinks(SQLElementLinksSetup links) {
51
        super.setupLinks(links);
52
        if (getTable().contains("ID_ECRITURE")) {
53
            links.get("ID_ECRITURE").setType(LinkType.ASSOCIATION);
54
        }
55
    }
56
 
18 ilm 57
    protected List<String> getListFields() {
58
        final List<String> list = new ArrayList<String>(2);
59
        list.add("ID_ECRITURE");
60
        list.add("ID_POSTE_ANALYTIQUE");
83 ilm 61
        // list.add("MONTANT");
18 ilm 62
        return list;
63
    }
64
 
65
    protected List<String> getComboFields() {
66
        final List<String> list = new ArrayList<String>(2);
67
        list.add("ID_ECRITURE");
68
        list.add("ID_POSTE_ANALYTIQUE");
69
        return list;
70
    }
71
 
72
    public SQLComponent createComponent() {
73
        return new BaseSQLComponent(this) {
74
            public void addViews() {
75
                this.addRequiredSQLObject(new JTextField(), "ID_ECRITURE");
76
                this.addRequiredSQLObject(new JTextField(), "ID_POSTE_ANALYTIQUE");
77
            }
78
        };
79
    }
57 ilm 80
 
81
    @Override
82
    protected String createCode() {
156 ilm 83
        return createCodeOfPackage() + ".analytic.relation";
57 ilm 84
    }
83 ilm 85
 
86
    @Override
142 ilm 87
    protected synchronized void _initTableSource(final SQLTableModelSource table) {
88
        super._initTableSource(table);
83 ilm 89
        BaseSQLTableModelColumn debit = new BaseSQLTableModelColumn("Débit", BigDecimal.class) {
90
 
91
            @Override
92
            protected Object show_(SQLRowAccessor r) {
93
 
94
                long montant = r.getLong("MONTANT");
95
                if (montant > 0) {
96
                    return new BigDecimal(montant).movePointLeft(2);
97
                } else {
98
                    return BigDecimal.ZERO;
99
                }
100
            }
101
 
102
            @Override
103
            public Set<FieldPath> getPaths() {
104
                Path p = new Path(getTable());
105
                return CollectionUtils.createSet(new FieldPath(p, "MONTANT"));
106
            }
107
        };
108
 
109
        table.getColumns().add(debit);
110
 
111
        BaseSQLTableModelColumn credit = new BaseSQLTableModelColumn("Crédit", BigDecimal.class) {
112
 
113
            @Override
114
            protected Object show_(SQLRowAccessor r) {
115
 
116
                long montant = r.getLong("MONTANT");
117
                if (montant < 0) {
118
                    return new BigDecimal(-montant).movePointLeft(2);
119
                } else {
120
                    return BigDecimal.ZERO;
121
                }
122
            }
123
 
124
            @Override
125
            public Set<FieldPath> getPaths() {
126
                Path p = new Path(getTable());
127
                return CollectionUtils.createSet(new FieldPath(p, "MONTANT"));
128
            }
129
        };
130
 
131
        table.getColumns().add(credit);
132
    }
18 ilm 133
}