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