OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 96 Rev 169
1
/*
1
/*
2
 * Créé le 1 juin 2012
2
 * Créé le 1 juin 2012
3
 */
3
 */
4
package org.openconcerto.modules.subscription.element;
4
package org.openconcerto.modules.subscription.element;
5
 
5
 
6
import java.awt.Component;
6
import java.awt.Component;
7
import java.awt.GridBagConstraints;
7
import java.awt.GridBagConstraints;
8
import java.awt.GridBagLayout;
8
import java.awt.GridBagLayout;
9
import java.awt.event.ActionEvent;
9
import java.awt.event.ActionEvent;
10
import java.awt.event.ActionListener;
10
import java.awt.event.ActionListener;
11
import java.sql.SQLException;
11
import java.sql.SQLException;
12
import java.util.Date;
12
import java.util.Date;
13
 
13
 
14
import javax.swing.JCheckBox;
14
import javax.swing.JCheckBox;
15
import javax.swing.JComponent;
15
import javax.swing.JComponent;
16
import javax.swing.JLabel;
16
import javax.swing.JLabel;
17
import javax.swing.JPanel;
17
import javax.swing.JPanel;
18
import javax.swing.JTabbedPane;
18
import javax.swing.JTabbedPane;
19
import javax.swing.JTextField;
19
import javax.swing.JTextField;
20
import javax.swing.SwingConstants;
20
import javax.swing.SwingConstants;
21
 
21
 
22
import org.openconcerto.erp.core.common.element.NumerotationAutoSQLElement;
22
import org.openconcerto.erp.core.common.element.NumerotationAutoSQLElement;
23
import org.openconcerto.erp.core.sales.quote.element.DevisSQLElement;
-
 
24
import org.openconcerto.sql.element.BaseSQLComponent;
23
import org.openconcerto.sql.element.BaseSQLComponent;
25
import org.openconcerto.sql.element.SQLElement;
24
import org.openconcerto.sql.element.SQLElement;
26
import org.openconcerto.sql.model.SQLRow;
25
import org.openconcerto.sql.model.SQLRow;
27
import org.openconcerto.sql.model.SQLRowAccessor;
26
import org.openconcerto.sql.model.SQLRowAccessor;
28
import org.openconcerto.sql.model.SQLRowValues;
27
import org.openconcerto.sql.model.SQLRowValues;
29
import org.openconcerto.sql.model.SQLTable;
28
import org.openconcerto.sql.model.SQLTable;
30
import org.openconcerto.sql.sqlobject.ElementComboBox;
29
import org.openconcerto.sql.sqlobject.ElementComboBox;
31
import org.openconcerto.sql.sqlobject.JUniqueTextField;
30
import org.openconcerto.sql.sqlobject.JUniqueTextField;
32
import org.openconcerto.ui.DefaultGridBagConstraints;
31
import org.openconcerto.ui.DefaultGridBagConstraints;
33
import org.openconcerto.ui.JDate;
32
import org.openconcerto.ui.JDate;
34
import org.openconcerto.ui.component.ITextArea;
33
import org.openconcerto.ui.component.ITextArea;
35
 
34
 
36
public class SubscriptionSQLComponent extends BaseSQLComponent {
35
public class SubscriptionSQLComponent extends BaseSQLComponent {
37
 
36
 
38
    private static final long serialVersionUID = 4274010869219769289L;
37
    private static final long serialVersionUID = 4274010869219769289L;
39
    private final SQLTable tableNum = getTable().getBase().getTable("NUMEROTATION_AUTO");
38
    private final SQLTable tableNum = getTable().getBase().getTable("NUMEROTATION_AUTO");
40
 
39
 
41
    final JLabel labelNumero = new JLabel(getLabelFor("NUMERO"), SwingConstants.RIGHT);
40
    final JLabel labelNumero = new JLabel(getLabelFor("NUMERO"), SwingConstants.RIGHT);
42
    final JLabel labelDate = new JLabel(getLabelFor("DATE"), SwingConstants.RIGHT);
41
    final JLabel labelDate = new JLabel(getLabelFor("DATE"), SwingConstants.RIGHT);
43
    final JDate date = new JDate(true);
42
    final JDate date = new JDate(true);
44
    final JLabel labelClient = new JLabel(getLabelFor("ID_CLIENT"), SwingConstants.RIGHT);
43
    final JLabel labelClient = new JLabel(getLabelFor("ID_CLIENT"), SwingConstants.RIGHT);
45
    final ElementComboBox client = new ElementComboBox();
44
    final ElementComboBox client = new ElementComboBox();
46
 
45
 
47
    public SubscriptionSQLComponent(SQLElement element) {
46
    public SubscriptionSQLComponent(SQLElement element) {
48
        super(element);
47
        super(element);
49
    }
48
    }
50
 
49
 
51
    public void setLightUI(boolean b) {
50
    public void setLightUI(boolean b) {
52
        labelClient.setVisible(b);
51
        labelClient.setVisible(b);
53
        labelNumero.setVisible(b);
52
        labelNumero.setVisible(b);
54
        labelDate.setVisible(b);
53
        labelDate.setVisible(b);
55
        textNumero.setVisible(b);
54
        textNumero.setVisible(b);
56
 
-
 
57
        date.setVisible(b);
55
        date.setVisible(b);
58
        client.setVisible(b);
56
        client.setVisible(b);
59
    }
57
    }
60
 
58
 
61
    final JUniqueTextField textNumero = new JUniqueTextField(8);
59
    final JUniqueTextField textNumero = new JUniqueTextField(8);
62
 
60
 
63
    @Override
61
    @Override
64
    public void addViews() {
62
    public void addViews() {
65
 
63
 
66
        this.setLayout(new GridBagLayout());
64
        this.setLayout(new GridBagLayout());
67
        final GridBagConstraints c = new DefaultGridBagConstraints();
65
        final GridBagConstraints c = new DefaultGridBagConstraints();
68
        // Numéro
66
        // Numéro
69
        c.weightx = 0;
67
        c.weightx = 0;
70
 
68
 
71
        this.add(labelNumero, c);
69
        this.add(labelNumero, c);
72
        c.gridx++;
70
        c.gridx++;
73
        c.weightx = 1;
71
        c.weightx = 1;
74
        this.add(textNumero, c);
72
        this.add(textNumero, c);
75
 
73
 
76
        // Date
74
        // Date
77
        c.gridx++;
75
        c.gridx++;
78
        c.weightx = 0;
76
        c.weightx = 0;
79
        this.add(labelDate, c);
77
        this.add(labelDate, c);
80
        c.gridx++;
78
        c.gridx++;
81
        c.weightx = 1;
79
        c.weightx = 1;
82
 
80
 
83
        this.add(date, c);
81
        this.add(date, c);
84
        // Libellé
82
        // Libellé
85
        c.gridy++;
83
        c.gridy++;
86
        c.gridx = 0;
84
        c.gridx = 0;
87
        c.weightx = 0;
85
        c.weightx = 0;
88
        this.add(new JLabel(getLabelFor("NOM"), SwingConstants.RIGHT), c);
86
        this.add(new JLabel(getLabelFor("NOM"), SwingConstants.RIGHT), c);
89
        c.gridx++;
87
        c.gridx++;
90
        c.weightx = 1;
88
        c.weightx = 1;
91
        c.gridwidth = 3;
89
        c.gridwidth = 3;
92
        final JTextField textNom = new JTextField();
90
        final JTextField textNom = new JTextField();
93
        this.add(textNom, c);
91
        this.add(textNom, c);
94
 
92
 
95
        // Libellé
93
        // Libellé
96
        c.gridy++;
94
        c.gridy++;
97
        c.gridx = 0;
95
        c.gridx = 0;
98
        c.weightx = 0;
96
        c.weightx = 0;
99
        c.gridwidth = 1;
97
        c.gridwidth = 1;
100
        this.add(new JLabel(getLabelFor("INTITULE_FACTURE"), SwingConstants.RIGHT), c);
98
        this.add(new JLabel(getLabelFor("INTITULE_FACTURE"), SwingConstants.RIGHT), c);
101
        c.gridx++;
99
        c.gridx++;
102
        c.weightx = 1;
100
        c.weightx = 1;
103
        c.gridwidth = 3;
101
        c.gridwidth = 3;
104
        final JTextField intitule = new JTextField();
102
        final JTextField intitule = new JTextField();
105
        this.add(intitule, c);
103
        this.add(intitule, c);
106
        this.addView(intitule, "INTITULE_FACTURE");
104
        this.addView(intitule, "INTITULE_FACTURE");
107
 
105
 
108
        // Description
106
        // Description
109
        c.gridwidth = 1;
107
        c.gridwidth = 1;
110
        c.gridy++;
108
        c.gridy++;
111
        c.gridx = 0;
109
        c.gridx = 0;
112
        c.weightx = 0;
110
        c.weightx = 0;
113
        this.add(new JLabel(getLabelFor("DESCRIPTION"), SwingConstants.RIGHT), c);
111
        this.add(new JLabel(getLabelFor("DESCRIPTION"), SwingConstants.RIGHT), c);
114
        c.gridx++;
112
        c.gridx++;
115
        c.weightx = 1;
113
        c.weightx = 1;
116
        c.gridwidth = 3;
114
        c.gridwidth = 3;
117
        final ITextArea textDescription = new ITextArea();
115
        final ITextArea textDescription = new ITextArea();
118
        this.add(textDescription, c);
116
        this.add(textDescription, c);
119
 
117
 
120
        // Client
118
        // Client
121
        c.gridwidth = 1;
119
        c.gridwidth = 1;
122
        c.gridy++;
120
        c.gridy++;
123
        c.gridx = 0;
121
        c.gridx = 0;
124
        c.weightx = 0;
122
        c.weightx = 0;
125
        this.add(labelClient, c);
123
        this.add(labelClient, c);
126
        c.gridx++;
124
        c.gridx++;
127
        c.weightx = 1;
125
        c.weightx = 1;
128
        c.gridwidth = 3;
126
        c.gridwidth = 3;
129
 
127
 
130
        this.add(client, c);
128
        this.add(client, c);
131
 
129
 
132
        //
130
        //
133
        c.gridwidth = 4;
131
        c.gridwidth = 4;
134
        c.gridx = 0;
132
        c.gridx = 0;
135
        c.gridy++;
133
        c.gridy++;
136
 
134
 
137
        c.weightx = 1;
135
        c.weightx = 1;
138
        c.weighty = 1;
136
        c.weighty = 1;
139
 
137
 
140
        final JTabbedPane tabbedPane = new JTabbedPane();
138
        final JTabbedPane tabbedPane = new JTabbedPane();
141
        tabbedPane.add("Facture", createTypeAboComponent("FACTURE", "ID_SAISIE_VENTE_FACTURE"));
139
        tabbedPane.add("Facture", createTypeAboComponent("FACTURE", "ID_SAISIE_VENTE_FACTURE"));
142
        tabbedPane.add("Devis", createTypeAboComponent("DEVIS", "ID_DEVIS"));
140
        tabbedPane.add("Devis", createTypeAboComponent("DEVIS", "ID_DEVIS"));
143
        tabbedPane.add("Bon de commande", createTypeAboComponent("COMMANDE", "ID_COMMANDE_CLIENT"));
141
        tabbedPane.add("Bon de commande", createTypeAboComponent("COMMANDE", "ID_COMMANDE_CLIENT"));
144
 
142
 
145
        this.add(tabbedPane, c);
143
        this.add(tabbedPane, c);
146
 
144
 
147
        this.addView(textNumero, "NUMERO", REQ);
145
        this.addView(textNumero, "NUMERO", REQ);
148
        this.addView(date, "DATE");
146
        this.addView(date, "DATE");
149
        this.addView(textNom, "NOM");
147
        this.addView(textNom, "NOM");
150
        this.addView(textDescription, "DESCRIPTION");
148
        this.addView(textDescription, "DESCRIPTION");
151
        this.addView(client, "ID_CLIENT");
149
        this.addView(client, "ID_CLIENT");
152
 
150
 
153
        // Codé mais jamais lancé.. a verifier: nom des champs
-
 
154
    }
151
    }
155
 
152
 
156
    private Component createTypeAboComponent(String type, String idName) {
153
    private Component createTypeAboComponent(String type, String idName) {
157
        final String fieldCreate = "CREATE_" + type;
154
        final String fieldCreate = "CREATE_" + type;
158
        final String fieldStart = "DATE_DEBUT_" + type;
155
        final String fieldStart = "DATE_DEBUT_" + type;
159
        final String fieldStop = "DATE_FIN_" + type;
156
        final String fieldStop = "DATE_FIN_" + type;
160
        final String fieldPeriodicity = "NB_MOIS_" + type;
157
        final String fieldPeriodicity = "NB_MOIS_" + type;
161
 
158
 
162
        final JPanel panel = new JPanel();
159
        final JPanel panel = new JPanel();
163
        panel.setOpaque(false);
160
        panel.setOpaque(false);
164
 
161
 
165
        panel.setLayout(new GridBagLayout());
162
        panel.setLayout(new GridBagLayout());
166
        final GridBagConstraints c = new DefaultGridBagConstraints();
163
        final GridBagConstraints c = new DefaultGridBagConstraints();
167
 
164
 
168
        // Checkbox
165
        // Checkbox
169
        c.gridx = 1;
166
        c.gridx = 1;
170
        c.weightx = 1;
167
        c.weightx = 1;
171
        final JCheckBox check = new JCheckBox(getLabelFor(fieldCreate));
168
        final JCheckBox check = new JCheckBox(getLabelFor(fieldCreate));
172
        check.setOpaque(false);
169
        check.setOpaque(false);
173
        panel.add(check, c);
170
        panel.add(check, c);
174
 
171
 
175
        // Item
172
        // Item
176
        c.gridx = 0;
173
        c.gridx = 0;
177
        c.gridy++;
174
        c.gridy++;
178
        c.weightx = 0;
175
        c.weightx = 0;
179
        panel.add(new JLabel(getLabelFor(idName), SwingConstants.RIGHT), c);
176
        panel.add(new JLabel(getLabelFor(idName), SwingConstants.RIGHT), c);
180
        c.gridx++;
177
        c.gridx++;
181
        c.weightx = 1;
178
        c.weightx = 1;
182
        final ElementComboBox item = new ElementComboBox();
179
        final ElementComboBox item = new ElementComboBox();
183
        // SQLElement elt =
-
 
184
        // Configuration.getInstance().getDirectory().getElement(getTable().getForeignTable(idName));
-
 
185
        // ComboSQLRequest req = new ComboSQLRequest(elt.getComboRequest(true),
-
 
186
        // Arrays.asList(elt.getTable().getField("NUMERO"), elt.getTable().getField("ID_CLIENT")));
-
 
187
        // item.init(elt, req);
-
 
188
        panel.add(item, c);
180
        panel.add(item, c);
189
 
181
 
190
        // Start
182
        // Start
191
        c.gridx = 0;
183
        c.gridx = 0;
192
        c.gridy++;
184
        c.gridy++;
193
        c.weightx = 0;
185
        c.weightx = 0;
194
        c.fill = GridBagConstraints.HORIZONTAL;
186
        c.fill = GridBagConstraints.HORIZONTAL;
195
        panel.add(new JLabel(getLabelFor(fieldStart), SwingConstants.RIGHT), c);
187
        panel.add(new JLabel(getLabelFor(fieldStart), SwingConstants.RIGHT), c);
196
        c.gridx++;
188
        c.gridx++;
197
        c.weightx = 1;
189
        c.weightx = 1;
198
        c.fill = GridBagConstraints.NONE;
190
        c.fill = GridBagConstraints.NONE;
199
        final JDate startDate = new JDate(true);
191
        final JDate startDate = new JDate(true);
200
        panel.add(startDate, c);
192
        panel.add(startDate, c);
201
 
193
 
202
        // Stop
194
        // Stop
203
        c.gridx = 0;
195
        c.gridx = 0;
204
        c.gridy++;
196
        c.gridy++;
205
        c.weightx = 0;
197
        c.weightx = 0;
206
        c.fill = GridBagConstraints.HORIZONTAL;
198
        c.fill = GridBagConstraints.HORIZONTAL;
207
        panel.add(new JLabel(getLabelFor(fieldStop), SwingConstants.RIGHT), c);
199
        panel.add(new JLabel(getLabelFor(fieldStop), SwingConstants.RIGHT), c);
208
        c.gridx++;
200
        c.gridx++;
209
        c.weightx = 1;
201
        c.weightx = 1;
210
        final JDate stopDate = new JDate();
202
        final JDate stopDate = new JDate();
211
        c.fill = GridBagConstraints.NONE;
203
        c.fill = GridBagConstraints.NONE;
212
        panel.add(stopDate, c);
204
        panel.add(stopDate, c);
213
 
205
 
214
        // Periodicity
206
        // Periodicity
215
        c.gridx = 0;
207
        c.gridx = 0;
216
        c.gridy++;
208
        c.gridy++;
217
        c.weightx = 0;
209
        c.weightx = 0;
218
        c.fill = GridBagConstraints.HORIZONTAL;
210
        c.fill = GridBagConstraints.HORIZONTAL;
219
        panel.add(new JLabel(getLabelFor(fieldPeriodicity), SwingConstants.RIGHT), c);
211
        panel.add(new JLabel(getLabelFor(fieldPeriodicity), SwingConstants.RIGHT), c);
220
        c.gridx++;
212
        c.gridx++;
221
        c.weightx = 1;
213
        c.weightx = 1;
222
        c.fill = GridBagConstraints.NONE;
214
        c.fill = GridBagConstraints.NONE;
223
        final JTextField textPeriod = new JTextField(5);
215
        final JTextField textPeriod = new JTextField(5);
224
        panel.add(textPeriod, c);
216
        panel.add(textPeriod, c);
225
 
217
 
226
        check.addActionListener(new ActionListener() {
218
        check.addActionListener(new ActionListener() {
227
 
219
 
228
            @Override
220
            @Override
229
            public void actionPerformed(ActionEvent e) {
221
            public void actionPerformed(ActionEvent e) {
230
                setFieldEnabled(item, startDate, stopDate, textPeriod, check.isSelected());
222
                setFieldEnabled(item, startDate, stopDate, textPeriod, check.isSelected());
231
            }
223
            }
232
        });
224
        });
233
 
225
 
234
        this.addView(check, fieldCreate);
226
        this.addView(check, fieldCreate);
235
        this.addView(item, idName);
227
        this.addView(item, idName);
236
        this.addView(startDate, fieldStart);
228
        this.addView(startDate, fieldStart);
237
        this.addView(stopDate, fieldStop);
229
        this.addView(stopDate, fieldStop);
238
        this.addView(textPeriod, fieldPeriodicity);
230
        this.addView(textPeriod, fieldPeriodicity);
239
 
231
 
240
        setFieldEnabled(item, startDate, stopDate, textPeriod, false);
232
        setFieldEnabled(item, startDate, stopDate, textPeriod, false);
241
        return panel;
233
        return panel;
242
    }
234
    }
243
 
235
 
244
    // @Override
-
 
245
    // protected SQLRowValues createDefaults() {
-
 
246
    // SQLRowValues rowVals = new SQLRowValues(getTable());
-
 
247
    // return super.createDefaults();
-
 
248
    // }
-
 
249
 
-
 
250
    public void setFieldEnabled(JComponent item, JComponent startDate, JComponent stopDate, JComponent textPeriod, boolean b) {
236
    public void setFieldEnabled(JComponent item, JComponent startDate, JComponent stopDate, JComponent textPeriod, boolean b) {
251
        System.err.println(b);
-
 
252
        // Thread.dumpStack();
-
 
253
        item.setEnabled(b);
237
        item.setEnabled(b);
254
        startDate.setEnabled(b);
238
        startDate.setEnabled(b);
255
        stopDate.setEnabled(b);
239
        stopDate.setEnabled(b);
256
        textPeriod.setEnabled(b);
240
        textPeriod.setEnabled(b);
257
    }
241
    }
258
 
242
 
259
    @Override
243
    @Override
260
    protected SQLRowValues createDefaults() {
244
    protected SQLRowValues createDefaults() {
261
        SQLRowValues vals = new SQLRowValues(getTable());
245
        SQLRowValues vals = new SQLRowValues(getTable());
262
        vals.put("NUMERO", NumerotationAutoSQLElement.getNextNumero(this.getElement().getClass(), new Date()));
246
        vals.put("NUMERO", NumerotationAutoSQLElement.getNextNumero(this.getElement().getClass(), new Date()));
263
        return vals;
247
        return vals;
264
    }
248
    }
265
 
249
 
266
    @Override
250
    @Override
267
    public void select(SQLRowAccessor r) {
251
    public void select(SQLRowAccessor r) {
268
        // TODO Auto-generated method stub
-
 
269
        super.select(r);
252
        super.select(r);
270
        if (r != null) {
253
        if (r != null) {
271
            this.textNumero.setIdSelected(r.getID());
254
            this.textNumero.setIdSelected(r.getID());
272
        }
255
        }
273
    }
256
    }
274
 
257
 
275
    @Override
258
    @Override
276
    public int insert(SQLRow order) {
259
    public int insert(SQLRow order) {
277
        // TODO Auto-generated method stub
-
 
278
        int id = super.insert(order);
260
        int id = super.insert(order);
279
        // incrémentation du numéro auto
261
        // incrémentation du numéro auto
280
        if (NumerotationAutoSQLElement.getNextNumero(DevisSQLElement.class).equalsIgnoreCase(this.textNumero.getText().trim())) {
262
        if (NumerotationAutoSQLElement.getNextNumero(SubscriptionSQLElement.class).equalsIgnoreCase(this.textNumero.getText().trim())) {
281
            final SQLRowValues rowVals = new SQLRowValues(this.tableNum);
263
            final SQLRowValues rowVals = new SQLRowValues(this.tableNum);
282
            int val = this.tableNum.getRow(2).getInt(NumerotationAutoSQLElement.getLabelNumberFor(DevisSQLElement.class));
264
            int val = this.tableNum.getRow(2).getInt(NumerotationAutoSQLElement.getLabelNumberFor(SubscriptionSQLElement.class));
283
            val++;
265
            val++;
284
            rowVals.put(NumerotationAutoSQLElement.getLabelNumberFor(DevisSQLElement.class), new Integer(val));
266
            rowVals.put(NumerotationAutoSQLElement.getLabelNumberFor(SubscriptionSQLElement.class), val);
285
            try {
267
            try {
286
                rowVals.update(2);
268
                rowVals.update(2);
287
            } catch (final SQLException e) {
269
            } catch (final SQLException e) {
288
                e.printStackTrace();
270
                e.printStackTrace();
289
            }
271
            }
290
        }
272
        }
291
        return id;
273
        return id;
292
    }
274
    }
293
 
275
 
294
    @Override
-
 
295
    public void update() {
-
 
296
        // TODO Auto-generated method stub
-
 
297
        super.update();
-
 
298
    }
-
 
299
}
276
}