156 |
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.payment.component;
|
|
|
15 |
|
|
|
16 |
import org.openconcerto.erp.core.common.element.BanqueSQLElement;
|
|
|
17 |
import org.openconcerto.erp.core.common.ui.DeviseField;
|
|
|
18 |
import org.openconcerto.erp.core.finance.accounting.element.EcritureSQLElement;
|
|
|
19 |
import org.openconcerto.erp.core.finance.payment.ui.DepotChequeTable;
|
|
|
20 |
import org.openconcerto.erp.generationEcritures.GenerationMvtDepotChequeClient;
|
|
|
21 |
import org.openconcerto.sql.Configuration;
|
|
|
22 |
import org.openconcerto.sql.element.BaseSQLComponent;
|
|
|
23 |
import org.openconcerto.sql.element.SQLElement;
|
|
|
24 |
import org.openconcerto.sql.model.SQLRow;
|
|
|
25 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
|
|
26 |
import org.openconcerto.sql.model.SQLRowValues;
|
|
|
27 |
import org.openconcerto.sql.sqlobject.ElementComboBox;
|
|
|
28 |
import org.openconcerto.sql.view.list.RowValuesTableModel;
|
|
|
29 |
import org.openconcerto.ui.DefaultGridBagConstraints;
|
|
|
30 |
import org.openconcerto.ui.JDate;
|
|
|
31 |
import org.openconcerto.ui.JLabelBold;
|
|
|
32 |
import org.openconcerto.utils.ExceptionHandler;
|
|
|
33 |
import org.openconcerto.utils.GestionDevise;
|
|
|
34 |
|
|
|
35 |
import java.awt.GridBagConstraints;
|
|
|
36 |
import java.awt.GridBagLayout;
|
|
|
37 |
|
|
|
38 |
import javax.swing.JLabel;
|
|
|
39 |
import javax.swing.JTextField;
|
|
|
40 |
import javax.swing.SwingConstants;
|
|
|
41 |
import javax.swing.event.TableModelEvent;
|
|
|
42 |
import javax.swing.event.TableModelListener;
|
|
|
43 |
|
|
|
44 |
public class DepotChequeSQLComponent extends BaseSQLComponent {
|
|
|
45 |
|
|
|
46 |
private DepotChequeTable table = new DepotChequeTable();
|
|
|
47 |
|
|
|
48 |
private JTextField nom = new JTextField();
|
|
|
49 |
private DeviseField montant = new DeviseField(10);
|
|
|
50 |
private JDate date;
|
|
|
51 |
private ElementComboBox boxBanque = new ElementComboBox(true);
|
|
|
52 |
|
|
|
53 |
public DepotChequeSQLComponent(SQLElement elt) {
|
|
|
54 |
super(elt);
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
@Override
|
|
|
58 |
public void addViews() {
|
|
|
59 |
this.setLayout(new GridBagLayout());
|
|
|
60 |
|
|
|
61 |
final GridBagConstraints c = new DefaultGridBagConstraints();
|
|
|
62 |
|
|
|
63 |
c.gridwidth = GridBagConstraints.REMAINDER;
|
|
|
64 |
c.weightx = 1;
|
|
|
65 |
this.add(new JLabelBold("Chèques"), c);
|
|
|
66 |
c.gridy++;
|
|
|
67 |
c.weighty = 1;
|
|
|
68 |
c.fill = GridBagConstraints.BOTH;
|
|
|
69 |
this.add(this.table, c);
|
|
|
70 |
this.table.getRowValuesTable().setEnabled(false);
|
|
|
71 |
c.fill = GridBagConstraints.HORIZONTAL;
|
|
|
72 |
c.gridwidth = 1;
|
|
|
73 |
c.gridy++;
|
|
|
74 |
c.weighty = 0;
|
|
|
75 |
|
|
|
76 |
// Client
|
|
|
77 |
c.gridx = 0;
|
|
|
78 |
c.gridy++;
|
|
|
79 |
c.weightx = 0;
|
|
|
80 |
final String itemName = "ID_" + getDirectory().getElement(BanqueSQLElement.class).getTable().getName();
|
|
|
81 |
this.add(new JLabel(getLabelFor(itemName), SwingConstants.RIGHT), c);
|
|
|
82 |
|
|
|
83 |
c.gridx++;
|
|
|
84 |
c.weightx = 1;
|
|
|
85 |
c.gridwidth = 1;
|
|
|
86 |
this.add(this.boxBanque, c);
|
|
|
87 |
c.gridwidth = 1;
|
|
|
88 |
|
|
|
89 |
// Date
|
|
|
90 |
this.date = new JDate(true);
|
|
|
91 |
c.gridx = GridBagConstraints.RELATIVE;
|
|
|
92 |
c.weightx = 0;
|
|
|
93 |
c.gridwidth = 1;
|
|
|
94 |
this.add(new JLabel("Date"), c);
|
|
|
95 |
// c.gridx++;
|
|
|
96 |
c.weightx = 0;
|
|
|
97 |
this.add(this.date, c);
|
|
|
98 |
|
|
|
99 |
this.addSQLObject(this.boxBanque, itemName);
|
|
|
100 |
|
|
|
101 |
// Nom
|
|
|
102 |
c.gridy++;
|
|
|
103 |
c.gridx = 0;
|
|
|
104 |
final JLabel label = new JLabel(getLabelFor("NOM"), SwingConstants.RIGHT);
|
|
|
105 |
c.weightx = 0;
|
|
|
106 |
this.add(label, c);
|
|
|
107 |
c.gridx++;
|
|
|
108 |
c.weightx = 1;
|
|
|
109 |
c.gridwidth = 2;
|
|
|
110 |
this.add(this.nom, c);
|
|
|
111 |
|
|
|
112 |
// Montant
|
|
|
113 |
c.gridwidth = 1;
|
|
|
114 |
c.gridy++;
|
|
|
115 |
c.gridx = 0;
|
|
|
116 |
c.weightx = 0;
|
|
|
117 |
this.add(new JLabel("Montant encaissé", SwingConstants.RIGHT), c);
|
|
|
118 |
|
|
|
119 |
c.gridx++;
|
|
|
120 |
c.gridwidth = 3;
|
|
|
121 |
c.fill = GridBagConstraints.NONE;
|
|
|
122 |
this.add(this.montant, c);
|
|
|
123 |
|
|
|
124 |
this.addRequiredSQLObject(this.date, "DATE");
|
|
|
125 |
this.addRequiredSQLObject(this.montant, "MONTANT");
|
|
|
126 |
|
|
|
127 |
this.addSQLObject(this.nom, "NOM");
|
|
|
128 |
DefaultGridBagConstraints.lockMinimumSize(this.montant);
|
|
|
129 |
|
|
|
130 |
final TableModelListener tableListener = new TableModelListener() {
|
|
|
131 |
|
|
|
132 |
@Override
|
|
|
133 |
public void tableChanged(TableModelEvent e) {
|
|
|
134 |
final RowValuesTableModel model = table.getRowValuesTable().getRowValuesTableModel();
|
|
|
135 |
if (e.getColumn() == TableModelEvent.ALL_COLUMNS || e.getColumn() == model.getColumnIndexForElement(table.getMontantElement())) {
|
|
|
136 |
|
|
|
137 |
final int rowCount = model.getRowCount();
|
|
|
138 |
long total = 0;
|
|
|
139 |
for (int i = 0; i < rowCount; i++) {
|
|
|
140 |
Number nHT = (Number) model.getValueAt(i, model.getColumnIndexForElement(table.getMontantElement()));
|
|
|
141 |
if (nHT != null) {
|
|
|
142 |
total += nHT.longValue();
|
|
|
143 |
}
|
|
|
144 |
}
|
|
|
145 |
|
|
|
146 |
montant.setText(GestionDevise.currencyToString(total));
|
|
|
147 |
|
|
|
148 |
}
|
|
|
149 |
}
|
|
|
150 |
};
|
|
|
151 |
|
|
|
152 |
this.table.getRowValuesTable().getRowValuesTableModel().addTableModelListener(tableListener);
|
|
|
153 |
|
|
|
154 |
}
|
|
|
155 |
|
|
|
156 |
@Override
|
|
|
157 |
public void select(SQLRowAccessor r) {
|
|
|
158 |
super.select(r);
|
|
|
159 |
if (r != null && r.getID() > 1) {
|
|
|
160 |
this.table.insertFrom("ID_DEPOT_CHEQUE", r.getID());
|
|
|
161 |
} else if (r != null && r instanceof SQLRowValues) {
|
|
|
162 |
this.table.insertFrom((SQLRowValues) r);
|
|
|
163 |
|
|
|
164 |
}
|
|
|
165 |
}
|
|
|
166 |
|
|
|
167 |
@Override
|
|
|
168 |
public int insert(SQLRow order) {
|
|
|
169 |
|
|
|
170 |
int id = super.insert(order);
|
|
|
171 |
try {
|
|
|
172 |
this.table.updateField("ID_DEPOT_CHEQUE", id);
|
|
|
173 |
|
|
|
174 |
System.err.println("Génération des ecritures du reglement");
|
|
|
175 |
GenerationMvtDepotChequeClient depotGen = new GenerationMvtDepotChequeClient(getTable().getRow(id));
|
|
|
176 |
depotGen.genere();
|
|
|
177 |
|
|
|
178 |
} catch (Exception e) {
|
|
|
179 |
ExceptionHandler.handle("Erreur lors de la génération des ecritures du reglement", e);
|
|
|
180 |
}
|
|
|
181 |
return id;
|
|
|
182 |
}
|
|
|
183 |
|
|
|
184 |
@Override
|
|
|
185 |
public void update() {
|
|
|
186 |
final int id = this.getSelectedID();
|
|
|
187 |
super.update();
|
|
|
188 |
this.table.updateField("ID_DEPOT_CHEQUE", id);
|
|
|
189 |
SQLRow row = getTable().getRow(id);
|
|
|
190 |
int idMvt = row.getInt("ID_MOUVEMENT");
|
|
|
191 |
|
|
|
192 |
// on supprime tout ce qui est lié à la facture
|
|
|
193 |
try {
|
|
|
194 |
EcritureSQLElement eltEcr = (EcritureSQLElement) Configuration.getInstance().getDirectory().getElement("ECRITURE");
|
|
|
195 |
eltEcr.archiveMouvementProfondeur(idMvt, false);
|
|
|
196 |
|
|
|
197 |
GenerationMvtDepotChequeClient depotGen = new GenerationMvtDepotChequeClient(row);
|
|
|
198 |
depotGen.genere();
|
|
|
199 |
} catch (Exception e) {
|
|
|
200 |
e.printStackTrace();
|
|
|
201 |
}
|
|
|
202 |
}
|
|
|
203 |
|
|
|
204 |
@Override
|
|
|
205 |
protected SQLRowValues createDefaults() {
|
|
|
206 |
this.table.getModel().clearRows();
|
|
|
207 |
|
|
|
208 |
return new SQLRowValues(getTable());
|
|
|
209 |
}
|
|
|
210 |
|
|
|
211 |
}
|