OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 144 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 144 Rev 180
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.supplychain.order.table;
14
 package org.openconcerto.erp.core.supplychain.order.table;
15
 
15
 
16
import org.openconcerto.erp.core.sales.order.ui.TypeFactureCommandeCellRenderer;
16
import org.openconcerto.erp.core.sales.order.ui.TypeFactureCommandeCellRenderer;
17
import org.openconcerto.erp.core.sales.order.ui.TypeFactureCommandeTableCellEditor;
17
import org.openconcerto.erp.core.sales.order.ui.TypeFactureCommandeTableCellEditor;
18
import org.openconcerto.sql.Configuration;
18
import org.openconcerto.sql.Configuration;
19
import org.openconcerto.sql.element.SQLComponent;
19
import org.openconcerto.sql.element.SQLComponent;
20
import org.openconcerto.sql.element.SQLElement;
20
import org.openconcerto.sql.element.SQLElement;
21
import org.openconcerto.sql.model.SQLRow;
21
import org.openconcerto.sql.model.SQLRow;
22
import org.openconcerto.sql.model.SQLRowValues;
22
import org.openconcerto.sql.model.SQLRowValues;
-
 
23
import org.openconcerto.sql.model.SQLTable;
23
import org.openconcerto.sql.model.UndefinedRowValuesCache;
24
import org.openconcerto.sql.model.UndefinedRowValuesCache;
24
import org.openconcerto.sql.model.Where;
25
import org.openconcerto.sql.model.Where;
25
import org.openconcerto.sql.request.ComboSQLRequest;
26
import org.openconcerto.sql.request.ComboSQLRequest;
26
import org.openconcerto.sql.sqlobject.ElementComboBox;
27
import org.openconcerto.sql.sqlobject.ElementComboBox;
27
import org.openconcerto.sql.view.list.RowValuesTable;
28
import org.openconcerto.sql.view.list.RowValuesTable;
28
import org.openconcerto.sql.view.list.RowValuesTableControlPanel;
29
import org.openconcerto.sql.view.list.RowValuesTableControlPanel;
29
import org.openconcerto.sql.view.list.RowValuesTableModel;
30
import org.openconcerto.sql.view.list.RowValuesTableModel;
30
import org.openconcerto.sql.view.list.RowValuesTableRenderer;
31
import org.openconcerto.sql.view.list.RowValuesTableRenderer;
31
import org.openconcerto.sql.view.list.SQLTableElement;
32
import org.openconcerto.sql.view.list.SQLTableElement;
32
import org.openconcerto.ui.DefaultGridBagConstraints;
33
import org.openconcerto.ui.DefaultGridBagConstraints;
33
import org.openconcerto.ui.table.PercentTableCellRenderer;
34
import org.openconcerto.ui.table.PercentTableCellRenderer;
34
import org.openconcerto.ui.table.TimestampTableCellEditor;
35
import org.openconcerto.ui.table.TimestampTableCellEditor;
-
 
36
import org.openconcerto.ui.table.XTableColumnModel;
35
 
37
 
36
import java.awt.GridBagConstraints;
38
import java.awt.GridBagConstraints;
37
import java.awt.GridBagLayout;
39
import java.awt.GridBagLayout;
38
import java.awt.event.ActionEvent;
40
import java.awt.event.ActionEvent;
39
import java.awt.event.ActionListener;
41
import java.awt.event.ActionListener;
40
import java.math.BigDecimal;
42
import java.math.BigDecimal;
41
import java.sql.Date;
43
import java.sql.Date;
42
import java.sql.Timestamp;
44
import java.sql.Timestamp;
-
 
45
import java.util.HashMap;
43
import java.util.List;
46
import java.util.List;
-
 
47
import java.util.Map;
44
import java.util.Vector;
48
import java.util.Vector;
45
 
49
 
46
import javax.swing.JButton;
50
import javax.swing.JButton;
47
import javax.swing.JLabel;
51
import javax.swing.JLabel;
48
import javax.swing.JPanel;
52
import javax.swing.JPanel;
49
import javax.swing.JScrollPane;
53
import javax.swing.JScrollPane;
50
import javax.swing.ScrollPaneConstants;
54
import javax.swing.ScrollPaneConstants;
51
import javax.swing.ToolTipManager;
55
import javax.swing.ToolTipManager;
52
 
56
 
53
public class FacturationCommandeTable extends JPanel {
57
public class FacturationCommandeTable extends JPanel {
54
    private RowValuesTable table;
58
    private RowValuesTable table;
55
    private RowValuesTableModel model;
59
    private RowValuesTableModel model;
56
    private SQLComponent comp;
60
    private SQLComponent comp;
57
 
61
 
-
 
62
    public static Map<String, Boolean> map = new HashMap<String, Boolean>();
-
 
63
 
-
 
64
    protected Map<String, Boolean> getCustomVisibilityMap() {
-
 
65
        return map;
-
 
66
    }
-
 
67
 
58
    public FacturationCommandeTable(SQLComponent comp) {
68
    public FacturationCommandeTable(SQLComponent comp) {
59
        this.comp = comp;
69
        this.comp = comp;
60
        init();
70
        init();
61
        uiInit();
71
        uiInit();
62
    }
72
    }
63
 
73
 
64
    protected void init() {
74
    protected void init() {
65
 
75
 
66
        final SQLElement e = getSQLElement();
76
        final SQLElement e = getSQLElement();
67
 
77
 
68
        final List<SQLTableElement> list = new Vector<SQLTableElement>();
78
        final List<SQLTableElement> list = new Vector<SQLTableElement>();
69
 
79
 
70
        final SQLTableElement tableElementNom = new SQLTableElement(e.getTable().getField("NOM"));
80
        final SQLTableElement tableElementNom = new SQLTableElement(e.getTable().getField("NOM"));
71
        list.add(tableElementNom);
81
        list.add(tableElementNom);
72
 
82
 
73
        final SQLTableElement tableElementTF = new SQLTableElement(e.getTable().getField("TYPE_FACTURE"), Integer.class, new TypeFactureCommandeTableCellEditor());
83
        final SQLTableElement tableElementTF = new SQLTableElement(e.getTable().getField("TYPE_FACTURE"), Integer.class, new TypeFactureCommandeTableCellEditor());
74
        tableElementTF.setRenderer(new TypeFactureCommandeCellRenderer());
84
        tableElementTF.setRenderer(new TypeFactureCommandeCellRenderer());
75
        list.add(tableElementTF);
85
        list.add(tableElementTF);
76
 
86
 
77
        final SQLTableElement pourcent = new SQLTableElement(e.getTable().getField("POURCENT"), BigDecimal.class);
87
        final SQLTableElement pourcent = new SQLTableElement(e.getTable().getField("POURCENT"), BigDecimal.class);
78
        pourcent.setRenderer(new PercentTableCellRenderer());
88
        pourcent.setRenderer(new PercentTableCellRenderer());
79
        list.add(pourcent);
89
        list.add(pourcent);
80
 
90
 
81
        final SQLTableElement type = new SQLTableElement(e.getTable().getField("ID_TYPE_REGLEMENT"));
91
        final SQLTableElement type = new SQLTableElement(e.getTable().getField("ID_TYPE_REGLEMENT"));
82
        list.add(type);
92
        list.add(type);
83
 
93
 
84
        final SQLTableElement ajours = new SQLTableElement(e.getTable().getField("AJOURS"));
94
        final SQLTableElement ajours = new SQLTableElement(e.getTable().getField("AJOURS"));
85
        list.add(ajours);
95
        list.add(ajours);
86
        final SQLTableElement finM = new SQLTableElement(e.getTable().getField("FIN_MOIS"));
96
        final SQLTableElement finM = new SQLTableElement(e.getTable().getField("FIN_MOIS"));
87
        list.add(finM);
97
        list.add(finM);
88
 
98
 
89
        final SQLTableElement comptant = new SQLTableElement(e.getTable().getField("COMPTANT"));
99
        final SQLTableElement comptant = new SQLTableElement(e.getTable().getField("COMPTANT"));
90
        list.add(comptant);
100
        list.add(comptant);
91
 
101
 
-
 
102
        // TODO fix return value of timestamp if not show hour return date object
92
        final SQLTableElement date = new SQLTableElement(e.getTable().getField("DATE_PREVISIONNELLE"), Date.class, new TimestampTableCellEditor(false) {
103
        final SQLTableElement date = new SQLTableElement(e.getTable().getField("DATE_PREVISIONNELLE"), Date.class, new TimestampTableCellEditor(false) {
93
            @Override
104
            @Override
94
            public Object getCellEditorValue() {
105
            public Object getCellEditorValue() {
95
 
106
 
96
                Object o = super.getCellEditorValue();
107
                Object o = super.getCellEditorValue();
97
                Date d = null;
108
                Date d = null;
98
                if (o != null) {
109
                if (o != null) {
99
                    d = new Date(((Timestamp) o).getTime());
110
                    d = new Date(((Timestamp) o).getTime());
100
                }
111
                }
101
                return d;
112
                return d;
102
            }
113
            }
103
        });
114
        });
104
        list.add(date);
115
        list.add(date);
105
 
116
 
106
        SQLRowValues defautRow = new SQLRowValues(UndefinedRowValuesCache.getInstance().getDefaultRowValues(e.getTable()));
117
        SQLRowValues defautRow = new SQLRowValues(UndefinedRowValuesCache.getInstance().getDefaultRowValues(e.getTable()));
107
        this.model = new RowValuesTableModel(e, list, e.getTable().getField("NOM"), false, defautRow);
118
        this.model = new RowValuesTableModel(e, list, e.getTable().getField("NOM"), false, defautRow);
108
 
119
 
109
        this.table = new RowValuesTable(this.model, null, true);
120
        this.table = new RowValuesTable(this.model, null, true);
110
        ToolTipManager.sharedInstance().unregisterComponent(this.table);
121
        ToolTipManager.sharedInstance().unregisterComponent(this.table);
111
        ToolTipManager.sharedInstance().unregisterComponent(this.table.getTableHeader());
122
        ToolTipManager.sharedInstance().unregisterComponent(this.table.getTableHeader());
112
 
123
 
113
        // Autocompletion
-
 
114
        // AutoCompletionManager m = new AutoCompletionManager(tableElementNom,
124
        Map<String, Boolean> mapCustom = getCustomVisibilityMap();
115
        // ((ComptaPropsConfiguration)
125
        if (mapCustom != null) {
116
        // Configuration.getInstance()).getSQLBaseSociete().getField("ECHANTILLON.NOM"), this.table,
-
 
117
        // this.table.getRowValuesTableModel());
126
            for (String string : mapCustom.keySet()) {
118
        // m.fill("NOM", "NOM");
-
 
119
        // m.fill("PV_HT", "PV_HT");
-
 
120
 
-
 
121
        // // Calcul automatique du total HT
-
 
122
        // qteElement.addModificationListener(this.totalHT);
-
 
123
        // this.pvHT.addModificationListener(this.totalHT);
-
 
124
        // this.totalHT.setModifier(new CellDynamicModifier() {
-
 
125
        // public Object computeValueFrom(final SQLRowValues row, SQLTableElement source) {
-
 
126
        // System.out.println("Compute totalHT");
-
 
127
        //
-
 
128
        // int qte = Integer.parseInt(row.getObject("QTE").toString());
127
                setColumnVisible(model.getColumnForField(string), mapCustom.get(string));
129
        // BigDecimal f = row.getBigDecimal("PV_HT");
-
 
130
        // BigDecimal r = f.multiply(new BigDecimal(qte), DecimalUtils.HIGH_PRECISION);
-
 
131
        // return r;
-
 
132
        // }
128
            }
133
        //
129
        }
134
        // });
-
 
135
 
130
 
136
    }
131
    }
137
 
132
 
-
 
133
    protected void setColumnVisible(int col, boolean visible) {
-
 
134
        if (col >= 0) {
-
 
135
            XTableColumnModel columnModel = this.table.getColumnModel();
-
 
136
            columnModel.setColumnVisible(columnModel.getColumnByModelIndex(col), visible);
-
 
137
        }
-
 
138
    }
-
 
139
 
138
    /**
140
    /**
139
     * 
141
     * 
140
     */
142
     */
141
    protected void uiInit() {
143
    protected void uiInit() {
142
        // Ui init
144
        // Ui init
143
        this.setLayout(new GridBagLayout());
145
        this.setLayout(new GridBagLayout());
144
        this.setOpaque(false);
146
        this.setOpaque(false);
145
        final GridBagConstraints c = new DefaultGridBagConstraints();
147
        final GridBagConstraints c = new DefaultGridBagConstraints();
146
        c.weightx = 1;
148
        c.weightx = 1;
147
 
149
 
148
        // Ajout catégorie
150
        // Ajout catégorie
149
        c.gridwidth = 1;
151
        c.gridwidth = 1;
150
        c.weightx = 0;
152
        c.weightx = 0;
151
        c.gridx = 0;
153
        c.gridx = 0;
152
        this.add(new JLabel("Ajouter un terme"), c);
154
        this.add(new JLabel("Ajouter un terme"), c);
153
 
155
 
154
        final ElementComboBox boxCat = new ElementComboBox();
156
        final ElementComboBox boxCat = new ElementComboBox();
155
        final SQLElement element = Configuration.getInstance().getDirectory().getElement("FACTURATION_COMMANDE_CLIENT");
157
        final SQLElement element = getSQLElement();
156
        ComboSQLRequest req = element.getComboRequest(true);
158
        ComboSQLRequest req = element.getComboRequest(true);
157
        req.setWhere(new Where(element.getTable().getField("CHOICE"), "=", Boolean.TRUE));
159
        req.setWhere(new Where(element.getTable().getField("CHOICE"), "=", Boolean.TRUE));
158
        boxCat.init(element, req);
160
        boxCat.init(element, req);
159
 
161
 
160
        c.gridx++;
162
        c.gridx++;
161
        this.add(boxCat, c);
163
        this.add(boxCat, c);
162
 
164
 
163
        c.fill = GridBagConstraints.NONE;
165
        c.fill = GridBagConstraints.NONE;
164
        c.gridx++;
166
        c.gridx++;
165
        JButton buttonAjouter = new JButton("Ajouter");
167
        JButton buttonAjouter = new JButton("Ajouter");
166
        buttonAjouter.setOpaque(false);
168
        buttonAjouter.setOpaque(false);
167
        this.add(buttonAjouter, c);
169
        this.add(buttonAjouter, c);
168
 
170
 
169
        c.gridwidth = GridBagConstraints.REMAINDER;
171
        c.gridwidth = GridBagConstraints.REMAINDER;
170
        // Listeners
172
        // Listeners
171
        buttonAjouter.addActionListener(new ActionListener() {
173
        buttonAjouter.addActionListener(new ActionListener() {
172
 
174
 
173
            @Override
175
            @Override
174
            public void actionPerformed(ActionEvent e) {
176
            public void actionPerformed(ActionEvent e) {
175
 
177
 
176
                SQLRow rowCat = boxCat.getSelectedRow();
178
                SQLRow rowCat = boxCat.getSelectedRow();
177
                if (rowCat == null || rowCat.isUndefined()) {
179
                if (rowCat == null || rowCat.isUndefined()) {
178
                    return;
180
                    return;
179
                }
181
                }
180
 
182
 
-
 
183
                final SQLTable table2 = getSQLElement().getTable();
-
 
184
                SQLRowValues rowVals = new SQLRowValues(table2);
181
                SQLRowValues rowVals = new SQLRowValues(Configuration.getInstance().getBase().getTable("FACTURATION_COMMANDE_CLIENT"));
185
                if (table2.getName().equals("FACTURATION_COMMANDE_CLIENT")) {
182
                if (comp.getSelectedID() > 1) {
186
                    if (comp != null && comp.getSelectedID() > 1) {
183
                    rowVals.put("ID_COMMANDE_CLIENT", comp.getSelectedID());
187
                        rowVals.put("ID_COMMANDE_CLIENT", comp.getSelectedID());
184
                }
188
                    }
-
 
189
                }
185
                rowVals.put("NOM", rowCat.getObject("NOM"));
190
                rowVals.put("NOM", rowCat.getObject("NOM"));
186
                rowVals.put("ID_TYPE_REGLEMENT", rowCat.getObject("ID_TYPE_REGLEMENT"));
191
                rowVals.put("ID_TYPE_REGLEMENT", rowCat.getObject("ID_TYPE_REGLEMENT"));
187
                rowVals.put("AJOURS", rowCat.getObject("AJOURS"));
192
                rowVals.put("AJOURS", rowCat.getObject("AJOURS"));
188
                rowVals.put("COMPTANT", rowCat.getObject("COMPTANT"));
193
                rowVals.put("COMPTANT", rowCat.getObject("COMPTANT"));
189
                rowVals.put("FIN_MOIS", rowCat.getObject("FIN_MOIS"));
194
                rowVals.put("FIN_MOIS", rowCat.getObject("FIN_MOIS"));
190
                rowVals.put("MONTANT", rowCat.getObject("MONTANT"));
195
                rowVals.put("MONTANT", rowCat.getObject("MONTANT"));
191
                rowVals.put("POURCENT", rowCat.getObject("POURCENT"));
196
                rowVals.put("POURCENT", rowCat.getObject("POURCENT"));
192
                rowVals.put("TYPE_FACTURE", rowCat.getObject("TYPE_FACTURE"));
197
                rowVals.put("TYPE_FACTURE", rowCat.getObject("TYPE_FACTURE"));
193
                getModel().addRow(rowVals);
198
                getModel().addRow(rowVals);
194
            }
199
            }
195
        });
200
        });
196
 
201
 
197
        c.gridy++;
202
        c.gridy++;
198
        c.gridx = 0;
203
        c.gridx = 0;
199
        final JPanel control = new RowValuesTableControlPanel(this.table);
204
        final JPanel control = new RowValuesTableControlPanel(this.table);
200
        control.setOpaque(false);
205
        control.setOpaque(false);
201
        this.add(control, c);
206
        this.add(control, c);
202
 
207
 
203
        c.gridy++;
208
        c.gridy++;
204
        c.fill = GridBagConstraints.BOTH;
209
        c.fill = GridBagConstraints.BOTH;
205
        c.weighty = 1;
210
        c.weighty = 1;
206
        c.weightx = 1;
211
        c.weightx = 1;
207
        JScrollPane comp = new JScrollPane(this.table);
212
        JScrollPane comp = new JScrollPane(this.table);
208
        comp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
213
        comp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
209
        this.add(comp, c);
214
        this.add(comp, c);
210
        this.table.setDefaultRenderer(Long.class, new RowValuesTableRenderer());
215
        this.table.setDefaultRenderer(Long.class, new RowValuesTableRenderer());
211
    }
216
    }
212
 
217
 
213
    public SQLElement getSQLElement() {
218
    public SQLElement getSQLElement() {
214
        return Configuration.getInstance().getDirectory().getElement("FACTURATION_COMMANDE_CLIENT");
219
        return Configuration.getInstance().getDirectory().getElement("FACTURATION_COMMANDE_CLIENT");
215
    }
220
    }
216
 
221
 
217
    public void updateField(String field, int id) {
222
    public void updateField(String field, int id) {
218
        this.table.updateField(field, id);
223
        this.table.updateField(field, id);
219
    }
224
    }
220
 
225
 
221
    public RowValuesTable getRowValuesTable() {
226
    public RowValuesTable getRowValuesTable() {
222
        return this.table;
227
        return this.table;
223
    }
228
    }
224
 
229
 
225
    public void insertFrom(String field, int id) {
230
    public void insertFrom(String field, int id) {
226
        this.table.insertFrom(field, id);
231
        this.table.insertFrom(field, id);
227
    }
232
    }
228
 
233
 
229
    public RowValuesTableModel getModel() {
234
    public RowValuesTableModel getModel() {
230
        return this.table.getRowValuesTableModel();
235
        return this.table.getRowValuesTableModel();
231
    }
236
    }
232
 
237
 
233
    public void refreshTable() {
238
    public void refreshTable() {
234
        this.table.repaint();
239
        this.table.repaint();
235
    }
240
    }
236
}
241
}