OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 94 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.ui;
14
 package org.openconcerto.erp.core.finance.accounting.ui;
15
 
15
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
17
import org.openconcerto.erp.core.finance.accounting.element.EcritureSQLElement;
17
import org.openconcerto.erp.core.finance.accounting.element.EcritureSQLElement;
18
import org.openconcerto.sql.Configuration;
18
import org.openconcerto.sql.Configuration;
19
import org.openconcerto.sql.model.SQLBase;
19
import org.openconcerto.sql.model.SQLBase;
20
import org.openconcerto.sql.model.SQLRow;
20
import org.openconcerto.sql.model.SQLRow;
21
import org.openconcerto.sql.model.SQLSelect;
21
import org.openconcerto.sql.model.SQLSelect;
22
import org.openconcerto.sql.model.SQLTable;
22
import org.openconcerto.sql.model.SQLTable;
23
import org.openconcerto.ui.DefaultGridBagConstraints;
23
import org.openconcerto.ui.DefaultGridBagConstraints;
24
import org.openconcerto.ui.warning.JLabelWarning;
24
import org.openconcerto.ui.warning.JLabelWarning;
25
import org.openconcerto.utils.ExceptionHandler;
-
 
26
 
25
 
27
import java.awt.GridBagConstraints;
26
import java.awt.GridBagConstraints;
28
import java.awt.GridBagLayout;
27
import java.awt.GridBagLayout;
29
import java.awt.event.ActionEvent;
28
import java.awt.event.ActionEvent;
30
import java.awt.event.ActionListener;
29
import java.awt.event.ActionListener;
31
import java.util.List;
30
import java.util.List;
32
 
31
 
33
import javax.swing.JButton;
32
import javax.swing.JButton;
34
import javax.swing.JFrame;
33
import javax.swing.JFrame;
35
import javax.swing.JLabel;
34
import javax.swing.JLabel;
36
import javax.swing.JOptionPane;
35
import javax.swing.JOptionPane;
37
import javax.swing.JPanel;
36
import javax.swing.JPanel;
38
import javax.swing.SwingUtilities;
37
import javax.swing.SwingUtilities;
39
 
38
 
40
import org.apache.commons.dbutils.handlers.ArrayListHandler;
39
import org.apache.commons.dbutils.handlers.ArrayListHandler;
41
 
40
 
42
public class SuppressionEcrituresPanel extends JPanel {
41
public class SuppressionEcrituresPanel extends JPanel {
43
 
42
 
44
    public SuppressionEcrituresPanel(final int idMvt) {
43
    public SuppressionEcrituresPanel(final int idMvt) {
45
        this.setLayout(new GridBagLayout());
44
        this.setLayout(new GridBagLayout());
46
        final GridBagConstraints c = new DefaultGridBagConstraints();
45
        final GridBagConstraints c = new DefaultGridBagConstraints();
47
        c.weightx = 1;
46
        c.weightx = 1;
48
        SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
47
        SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
49
        SQLTable tableMouvement = base.getTable("MOUVEMENT");
48
        SQLTable tableMouvement = base.getTable("MOUVEMENT");
50
        SQLRow rowMvt = tableMouvement.getRow(idMvt);
49
        SQLRow rowMvt = tableMouvement.getRow(idMvt);
51
        JLabel label = new JLabel("Vous allez supprimer la piéce n°" + rowMvt.getInt("ID_PIECE"));
50
        JLabel label = new JLabel("Vous allez supprimer la piéce n°" + rowMvt.getInt("ID_PIECE"));
52
        JLabelWarning warning = new JLabelWarning();
51
        JLabelWarning warning = new JLabelWarning();
53
        JPanel panelLabel = new JPanel();
52
        JPanel panelLabel = new JPanel();
54
        panelLabel.add(warning);
53
        panelLabel.add(warning);
55
        panelLabel.add(label);
54
        panelLabel.add(label);
56
 
55
 
57
        c.gridwidth = GridBagConstraints.REMAINDER;
56
        c.gridwidth = GridBagConstraints.REMAINDER;
58
        this.add(panelLabel, c);
57
        this.add(panelLabel, c);
59
 
58
 
60
        // TODO afficher les numeros de mouvement implique
59
        // TODO afficher les numeros de mouvement implique
61
        int[] idS = getMouvement(rowMvt.getInt("ID_PIECE"));
60
        int[] idS = getMouvement(rowMvt.getInt("ID_PIECE"));
62
        if (idS == null) {
61
        if (idS == null) {
63
            ExceptionHandler.handle("Aucun mouvement associé à la piéce n°" + ((rowMvt != null) ? rowMvt.getInt("ID_PIECE") : "mouvement nul"));
62
            JOptionPane.showMessageDialog(null, "Aucun mouvement associé à la piéce n°" + ((rowMvt != null) ? rowMvt.getInt("ID_PIECE") : "mouvement nul"));
64
        } else {
63
        } else {
65
            StringBuffer s = new StringBuffer();
64
            StringBuffer s = new StringBuffer();
66
            s.append("Elle est composée par les mouvements : (");
65
            s.append("Elle est composée par les mouvements : (");
67
            JLabel labelMouv = new JLabel();
66
            JLabel labelMouv = new JLabel();
68
            // c.gridwidth = 1;
67
            // c.gridwidth = 1;
69
            c.gridy++;
68
            c.gridy++;
70
            c.gridx = 0;
69
            c.gridx = 0;
71
            this.add(labelMouv, c);
70
            this.add(labelMouv, c);
72
            s.append(idS[0]);
71
            s.append(idS[0]);
73
            for (int i = 1; i < idS.length; i++) {
72
            for (int i = 1; i < idS.length; i++) {
74
 
73
 
75
                s.append(", ");
74
                s.append(", ");
76
                s.append(idS[i]);
75
                s.append(idS[i]);
77
            }
76
            }
78
            s.append(')');
77
            s.append(')');
79
            labelMouv.setText(s.toString());
78
            labelMouv.setText(s.toString());
80
        }
79
        }
81
 
80
 
82
        JButton buttonOK = new JButton("OK");
81
        JButton buttonOK = new JButton("OK");
83
        JButton buttonCancel = new JButton("Annuler");
82
        JButton buttonCancel = new JButton("Annuler");
84
 
83
 
85
        c.gridwidth = 1;
84
        c.gridwidth = 1;
86
        c.gridy++;
85
        c.gridy++;
87
        c.gridx = 0;
86
        c.gridx = 0;
88
        this.add(buttonOK, c);
87
        this.add(buttonOK, c);
89
        c.gridx++;
88
        c.gridx++;
90
        this.add(buttonCancel, c);
89
        this.add(buttonCancel, c);
91
 
90
 
92
        buttonOK.addActionListener(new ActionListener() {
91
        buttonOK.addActionListener(new ActionListener() {
93
            public void actionPerformed(ActionEvent e) {
92
            public void actionPerformed(ActionEvent e) {
94
                ((JFrame) SwingUtilities.getRoot(SuppressionEcrituresPanel.this)).dispose();
93
                ((JFrame) SwingUtilities.getRoot(SuppressionEcrituresPanel.this)).dispose();
95
                try {
94
                try {
96
                    EcritureSQLElement elt = (EcritureSQLElement) Configuration.getInstance().getDirectory().getElement("ECRITURE");
95
                    EcritureSQLElement elt = (EcritureSQLElement) Configuration.getInstance().getDirectory().getElement("ECRITURE");
97
                    elt.archiveMouvement(idMvt);
96
                    elt.archiveMouvement(idMvt);
98
                } catch (Exception ex) {
97
                } catch (Exception ex) {
99
                    JOptionPane.showMessageDialog(null, "Impossible de supprimer le mouvement associé.\n" + ex.getMessage());
98
                    JOptionPane.showMessageDialog(null, "Impossible de supprimer le mouvement associé.\n" + ex.getMessage());
100
                }
99
                }
101
 
100
 
102
            }
101
            }
103
        });
102
        });
104
        buttonCancel.addActionListener(new ActionListener() {
103
        buttonCancel.addActionListener(new ActionListener() {
105
            public void actionPerformed(ActionEvent e) {
104
            public void actionPerformed(ActionEvent e) {
106
                ((JFrame) SwingUtilities.getRoot(SuppressionEcrituresPanel.this)).dispose();
105
                ((JFrame) SwingUtilities.getRoot(SuppressionEcrituresPanel.this)).dispose();
107
            }
106
            }
108
        });
107
        });
109
    }
108
    }
110
 
109
 
111
    private int[] getMouvement(int idPiece) {
110
    private int[] getMouvement(int idPiece) {
112
 
111
 
113
        int[] idS = null;
112
        int[] idS = null;
114
 
113
 
115
        SQLBase b = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
114
        SQLBase b = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
116
        SQLTable tableMvt = b.getTable("MOUVEMENT");
115
        SQLTable tableMvt = b.getTable("MOUVEMENT");
117
 
116
 
118
        SQLSelect sel = new SQLSelect(b);
117
        SQLSelect sel = new SQLSelect();
119
        sel.addSelect(tableMvt.getField("NUMERO"));
118
        sel.addSelect(tableMvt.getField("NUMERO"));
120
        sel.setWhere(tableMvt.getField("ID_PIECE"), "=", idPiece);
119
        sel.setWhere(tableMvt.getField("ID_PIECE"), "=", idPiece);
121
 
120
 
122
        List l = (List) b.getDataSource().execute(sel.asString(), new ArrayListHandler());
121
        List l = (List) b.getDataSource().execute(sel.asString(), new ArrayListHandler());
123
 
122
 
124
        if (l.size() > 0) {
123
        if (!l.isEmpty()) {
125
            idS = new int[l.size()];
124
            idS = new int[l.size()];
126
        }
125
        }
127
 
126
 
128
        for (int i = 0; i < l.size(); i++) {
127
        for (int i = 0; i < l.size(); i++) {
129
            Object[] tmp = (Object[]) l.get(i);
128
            Object[] tmp = (Object[]) l.get(i);
130
            idS[i] = Integer.parseInt(tmp[0].toString());
129
            idS[i] = ((Number) tmp[0]).intValue();
131
        }
130
        }
132
 
131
 
133
        return idS;
132
        return idS;
134
    }
133
    }
135
 
134
 
136
}
135
}