OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 142 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 142 Rev 156
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
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
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
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.
9
 * language governing permissions and limitations under the License.
10
 * 
10
 * 
11
 * When distributing the software, include this License Header Notice in each file.
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.erp.core.finance.accounting.element;
14
 package org.openconcerto.erp.core.finance.accounting.element;
15
 
15
 
16
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
16
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
17
import org.openconcerto.sql.element.BaseSQLComponent;
17
import org.openconcerto.sql.element.BaseSQLComponent;
18
import org.openconcerto.sql.element.SQLComponent;
18
import org.openconcerto.sql.element.SQLComponent;
19
import org.openconcerto.sql.model.FieldPath;
19
import org.openconcerto.sql.model.FieldPath;
20
import org.openconcerto.sql.model.SQLRowAccessor;
20
import org.openconcerto.sql.model.SQLRowAccessor;
21
import org.openconcerto.sql.model.graph.Path;
21
import org.openconcerto.sql.model.graph.Path;
22
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn;
22
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn;
23
import org.openconcerto.sql.view.list.SQLTableModelSource;
23
import org.openconcerto.sql.view.list.SQLTableModelSource;
24
import org.openconcerto.utils.CollectionUtils;
24
import org.openconcerto.utils.CollectionUtils;
25
 
25
 
26
import java.math.BigDecimal;
26
import java.math.BigDecimal;
27
import java.util.ArrayList;
27
import java.util.ArrayList;
28
import java.util.List;
28
import java.util.List;
29
import java.util.Set;
29
import java.util.Set;
30
 
30
 
31
import javax.swing.JTextField;
31
import javax.swing.JTextField;
32
 
32
 
33
public class AssociationAnalytiqueSQLElement extends ComptaSQLConfElement {
33
public class AssociationAnalytiqueSQLElement extends ComptaSQLConfElement {
34
 
34
 
35
    public AssociationAnalytiqueSQLElement() {
35
    public AssociationAnalytiqueSQLElement() {
36
        super("ASSOCIATION_ANALYTIQUE", "une association analytique", "associations analytiques");
36
        super("ASSOCIATION_ANALYTIQUE", "une association analytique", "associations analytiques");
37
 
37
 
38
    }
38
    }
39
 
39
 
40
    @Override
40
    @Override
41
    protected void ffInited() {
41
    protected void ffInited() {
42
        super.ffInited();
42
        super.ffInited();
43
        this.setAction("ID_ECRITURE", ReferenceAction.CASCADE);
43
        this.setAction("ID_ECRITURE", ReferenceAction.CASCADE);
44
        this.setAction("ID_SAISIE_KM_ELEMENT", ReferenceAction.CASCADE);
44
        this.setAction("ID_SAISIE_KM_ELEMENT", ReferenceAction.CASCADE);
45
    }
45
    }
46
 
46
 
47
    protected List<String> getListFields() {
47
    protected List<String> getListFields() {
48
        final List<String> list = new ArrayList<String>(2);
48
        final List<String> list = new ArrayList<String>(2);
49
        list.add("ID_ECRITURE");
49
        list.add("ID_ECRITURE");
50
        list.add("ID_POSTE_ANALYTIQUE");
50
        list.add("ID_POSTE_ANALYTIQUE");
51
        // list.add("MONTANT");
51
        // list.add("MONTANT");
52
        return list;
52
        return list;
53
    }
53
    }
54
 
54
 
55
    protected List<String> getComboFields() {
55
    protected List<String> getComboFields() {
56
        final List<String> list = new ArrayList<String>(2);
56
        final List<String> list = new ArrayList<String>(2);
57
        list.add("ID_ECRITURE");
57
        list.add("ID_ECRITURE");
58
        list.add("ID_POSTE_ANALYTIQUE");
58
        list.add("ID_POSTE_ANALYTIQUE");
59
        return list;
59
        return list;
60
    }
60
    }
61
 
61
 
62
    public SQLComponent createComponent() {
62
    public SQLComponent createComponent() {
63
        return new BaseSQLComponent(this) {
63
        return new BaseSQLComponent(this) {
64
            public void addViews() {
64
            public void addViews() {
65
                this.addRequiredSQLObject(new JTextField(), "ID_ECRITURE");
65
                this.addRequiredSQLObject(new JTextField(), "ID_ECRITURE");
66
                this.addRequiredSQLObject(new JTextField(), "ID_POSTE_ANALYTIQUE");
66
                this.addRequiredSQLObject(new JTextField(), "ID_POSTE_ANALYTIQUE");
67
            }
67
            }
68
        };
68
        };
69
    }
69
    }
70
 
70
 
71
    @Override
71
    @Override
72
    protected String createCode() {
72
    protected String createCode() {
73
        return createCodeFromPackage() + ".analytic.relation";
73
        return createCodeOfPackage() + ".analytic.relation";
74
    }
74
    }
75
 
75
 
76
    @Override
76
    @Override
77
    protected synchronized void _initTableSource(final SQLTableModelSource table) {
77
    protected synchronized void _initTableSource(final SQLTableModelSource table) {
78
        super._initTableSource(table);
78
        super._initTableSource(table);
79
        BaseSQLTableModelColumn debit = new BaseSQLTableModelColumn("Débit", BigDecimal.class) {
79
        BaseSQLTableModelColumn debit = new BaseSQLTableModelColumn("Débit", BigDecimal.class) {
80
 
80
 
81
            @Override
81
            @Override
82
            protected Object show_(SQLRowAccessor r) {
82
            protected Object show_(SQLRowAccessor r) {
83
 
83
 
84
                long montant = r.getLong("MONTANT");
84
                long montant = r.getLong("MONTANT");
85
                if (montant > 0) {
85
                if (montant > 0) {
86
                    return new BigDecimal(montant).movePointLeft(2);
86
                    return new BigDecimal(montant).movePointLeft(2);
87
                } else {
87
                } else {
88
                    return BigDecimal.ZERO;
88
                    return BigDecimal.ZERO;
89
                }
89
                }
90
            }
90
            }
91
 
91
 
92
            @Override
92
            @Override
93
            public Set<FieldPath> getPaths() {
93
            public Set<FieldPath> getPaths() {
94
                Path p = new Path(getTable());
94
                Path p = new Path(getTable());
95
                return CollectionUtils.createSet(new FieldPath(p, "MONTANT"));
95
                return CollectionUtils.createSet(new FieldPath(p, "MONTANT"));
96
            }
96
            }
97
        };
97
        };
98
 
98
 
99
        table.getColumns().add(debit);
99
        table.getColumns().add(debit);
100
 
100
 
101
        BaseSQLTableModelColumn credit = new BaseSQLTableModelColumn("Crédit", BigDecimal.class) {
101
        BaseSQLTableModelColumn credit = new BaseSQLTableModelColumn("Crédit", BigDecimal.class) {
102
 
102
 
103
            @Override
103
            @Override
104
            protected Object show_(SQLRowAccessor r) {
104
            protected Object show_(SQLRowAccessor r) {
105
 
105
 
106
                long montant = r.getLong("MONTANT");
106
                long montant = r.getLong("MONTANT");
107
                if (montant < 0) {
107
                if (montant < 0) {
108
                    return new BigDecimal(-montant).movePointLeft(2);
108
                    return new BigDecimal(-montant).movePointLeft(2);
109
                } else {
109
                } else {
110
                    return BigDecimal.ZERO;
110
                    return BigDecimal.ZERO;
111
                }
111
                }
112
            }
112
            }
113
 
113
 
114
            @Override
114
            @Override
115
            public Set<FieldPath> getPaths() {
115
            public Set<FieldPath> getPaths() {
116
                Path p = new Path(getTable());
116
                Path p = new Path(getTable());
117
                return CollectionUtils.createSet(new FieldPath(p, "MONTANT"));
117
                return CollectionUtils.createSet(new FieldPath(p, "MONTANT"));
118
            }
118
            }
119
        };
119
        };
120
 
120
 
121
        table.getColumns().add(credit);
121
        table.getColumns().add(credit);
122
    }
122
    }
123
}
123
}