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