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.config.ComptaPropsConfiguration;
|
|
|
17 |
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
|
|
|
18 |
import org.openconcerto.sql.Configuration;
|
|
|
19 |
import org.openconcerto.sql.element.BaseSQLComponent;
|
|
|
20 |
import org.openconcerto.sql.element.SQLComponent;
|
|
|
21 |
import org.openconcerto.sql.model.SQLBase;
|
|
|
22 |
import org.openconcerto.sql.model.SQLRowValues;
|
|
|
23 |
import org.openconcerto.sql.model.SQLSelect;
|
|
|
24 |
import org.openconcerto.sql.model.SQLTable;
|
|
|
25 |
import org.openconcerto.sql.model.Where;
|
80 |
ilm |
26 |
import org.openconcerto.ui.DefaultGridBagConstraints;
|
18 |
ilm |
27 |
|
80 |
ilm |
28 |
import java.awt.GridBagConstraints;
|
|
|
29 |
import java.awt.GridBagLayout;
|
18 |
ilm |
30 |
import java.util.ArrayList;
|
|
|
31 |
import java.util.List;
|
|
|
32 |
|
|
|
33 |
import javax.swing.JCheckBox;
|
|
|
34 |
import javax.swing.JLabel;
|
|
|
35 |
import javax.swing.JTextField;
|
80 |
ilm |
36 |
import javax.swing.SwingConstants;
|
18 |
ilm |
37 |
|
|
|
38 |
import org.apache.commons.dbutils.handlers.ArrayListHandler;
|
|
|
39 |
|
|
|
40 |
public class JournalSQLElement extends ComptaSQLConfElement {
|
|
|
41 |
|
|
|
42 |
public static final int ACHATS = 2;
|
|
|
43 |
public static final int VENTES = 3;
|
|
|
44 |
public static final int OD = 6;
|
|
|
45 |
public static final int BANQUES = 4;
|
|
|
46 |
public static final int CAISSES = 5;
|
|
|
47 |
|
|
|
48 |
public JournalSQLElement() {
|
|
|
49 |
super("JOURNAL", "un journal", "journaux");
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
protected List<String> getListFields() {
|
|
|
53 |
final List<String> list = new ArrayList<String>();
|
|
|
54 |
list.add("NOM");
|
|
|
55 |
list.add("CODE");
|
|
|
56 |
return list;
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
protected List<String> getComboFields() {
|
|
|
60 |
final List<String> list = new ArrayList<String>();
|
|
|
61 |
list.add("NOM");
|
|
|
62 |
list.add("CODE");
|
|
|
63 |
return list;
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
public SQLComponent createComponent() {
|
|
|
67 |
return new BaseSQLComponent(this) {
|
|
|
68 |
public void addViews() {
|
80 |
ilm |
69 |
this.setLayout(new GridBagLayout());
|
|
|
70 |
final GridBagConstraints c = new DefaultGridBagConstraints();
|
|
|
71 |
this.add(new JLabel(getLabelFor("CODE"), SwingConstants.RIGHT), c);
|
|
|
72 |
c.gridx++;
|
|
|
73 |
c.weightx = 1;
|
|
|
74 |
c.fill = GridBagConstraints.NONE;
|
18 |
ilm |
75 |
final JTextField code = new JTextField(6);
|
80 |
ilm |
76 |
this.add(code, c);
|
18 |
ilm |
77 |
|
80 |
ilm |
78 |
c.gridx = 0;
|
|
|
79 |
c.gridy++;
|
|
|
80 |
c.fill = GridBagConstraints.HORIZONTAL;
|
|
|
81 |
c.weightx = 0;
|
|
|
82 |
this.add(new JLabel(getLabelFor("NOM"), SwingConstants.RIGHT), c);
|
|
|
83 |
c.gridx++;
|
|
|
84 |
c.weightx = 1;
|
18 |
ilm |
85 |
final JTextField nom = new JTextField(25);
|
80 |
ilm |
86 |
this.add(nom, c);
|
|
|
87 |
c.gridy++;
|
|
|
88 |
c.anchor = GridBagConstraints.NORTHWEST;
|
|
|
89 |
c.weighty = 1;
|
18 |
ilm |
90 |
final JCheckBox checkBox = new JCheckBox(getLabelFor("TYPE_BANQUE"));
|
80 |
ilm |
91 |
this.add(checkBox, c);
|
18 |
ilm |
92 |
|
|
|
93 |
this.addView(nom, "NOM", REQ);
|
|
|
94 |
this.addView(code, "CODE", REQ);
|
|
|
95 |
this.addView(checkBox, "TYPE_BANQUE");
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
@Override
|
|
|
99 |
protected SQLRowValues createDefaults() {
|
|
|
100 |
final SQLRowValues rowVals = new SQLRowValues(getTable());
|
|
|
101 |
rowVals.put("TYPE_BANQUE", Boolean.TRUE);
|
|
|
102 |
return rowVals;
|
|
|
103 |
}
|
|
|
104 |
};
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
public static int getIdJournal(final String nom) {
|
|
|
108 |
final SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
|
|
|
109 |
final SQLTable journalTable = base.getTable("JOURNAL");
|
80 |
ilm |
110 |
final SQLSelect selJrnl = new SQLSelect();
|
18 |
ilm |
111 |
selJrnl.addSelect(journalTable.getField("ID"));
|
|
|
112 |
selJrnl.setWhere(new Where(journalTable.getField("NOM"), "=", nom.trim()));
|
|
|
113 |
|
80 |
ilm |
114 |
@SuppressWarnings("unchecked")
|
18 |
ilm |
115 |
final List<Object[]> myListJrnl = (List<Object[]>) base.getDataSource().execute(selJrnl.asString(), new ArrayListHandler());
|
|
|
116 |
|
|
|
117 |
if (myListJrnl.size() != 0) {
|
|
|
118 |
return Integer.parseInt(myListJrnl.get(0)[0].toString());
|
|
|
119 |
} else {
|
|
|
120 |
return -1;
|
|
|
121 |
}
|
|
|
122 |
}
|
57 |
ilm |
123 |
|
|
|
124 |
@Override
|
|
|
125 |
protected String createCode() {
|
|
|
126 |
return createCodeFromPackage() + ".book";
|
|
|
127 |
}
|
18 |
ilm |
128 |
}
|