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.sales.invoice.ui;
|
|
|
15 |
|
|
|
16 |
import org.openconcerto.erp.config.ComptaPropsConfiguration;
|
|
|
17 |
import org.openconcerto.erp.config.Gestion;
|
73 |
ilm |
18 |
import org.openconcerto.erp.core.common.ui.IListFilterDatePanel;
|
19 |
ilm |
19 |
import org.openconcerto.erp.core.common.ui.IListTotalPanel;
|
18 |
ilm |
20 |
import org.openconcerto.erp.core.finance.accounting.element.MouvementSQLElement;
|
|
|
21 |
import org.openconcerto.erp.core.finance.payment.component.EncaisserMontantSQLComponent;
|
177 |
ilm |
22 |
import org.openconcerto.erp.core.sales.invoice.element.EcheanceClientSQLElement;
|
18 |
ilm |
23 |
import org.openconcerto.erp.rights.ComptaUserRight;
|
|
|
24 |
import org.openconcerto.erp.rights.NXRights;
|
|
|
25 |
import org.openconcerto.sql.Configuration;
|
|
|
26 |
import org.openconcerto.sql.element.SQLElement;
|
|
|
27 |
import org.openconcerto.sql.model.SQLBase;
|
|
|
28 |
import org.openconcerto.sql.model.SQLRow;
|
|
|
29 |
import org.openconcerto.sql.model.SQLRowValues;
|
|
|
30 |
import org.openconcerto.sql.model.SQLTable;
|
|
|
31 |
import org.openconcerto.sql.users.rights.UserRightsManager;
|
|
|
32 |
import org.openconcerto.sql.view.EditFrame;
|
|
|
33 |
import org.openconcerto.sql.view.IListPanel;
|
|
|
34 |
import org.openconcerto.sql.view.IListener;
|
73 |
ilm |
35 |
import org.openconcerto.sql.view.list.IListe;
|
18 |
ilm |
36 |
import org.openconcerto.ui.DefaultGridBagConstraints;
|
|
|
37 |
|
|
|
38 |
import java.awt.GridBagConstraints;
|
|
|
39 |
import java.awt.GridBagLayout;
|
|
|
40 |
import java.awt.event.ActionEvent;
|
|
|
41 |
import java.awt.event.ActionListener;
|
|
|
42 |
import java.awt.event.MouseAdapter;
|
|
|
43 |
import java.awt.event.MouseEvent;
|
|
|
44 |
import java.util.ArrayList;
|
19 |
ilm |
45 |
import java.util.Arrays;
|
18 |
ilm |
46 |
import java.util.List;
|
|
|
47 |
|
|
|
48 |
import javax.swing.JButton;
|
|
|
49 |
import javax.swing.JCheckBox;
|
|
|
50 |
import javax.swing.JOptionPane;
|
|
|
51 |
import javax.swing.JPanel;
|
|
|
52 |
import javax.swing.SwingConstants;
|
|
|
53 |
|
|
|
54 |
public class ListeDesEcheancesClientsPanel extends JPanel {
|
|
|
55 |
|
|
|
56 |
private ListPanelEcheancesClients panelEcheances;
|
|
|
57 |
private EditFrame editRelance = null;
|
156 |
ilm |
58 |
private JButton relancer;
|
|
|
59 |
private JButton encaisser;
|
18 |
ilm |
60 |
|
73 |
ilm |
61 |
public ListeDesEcheancesClientsPanel() {
|
|
|
62 |
this(false);
|
|
|
63 |
}
|
|
|
64 |
|
18 |
ilm |
65 |
// TODO GEstion Relance (??? loi NRE pour le calcul des penalites)
|
73 |
ilm |
66 |
public ListeDesEcheancesClientsPanel(boolean onlyOld) {
|
18 |
ilm |
67 |
this.setLayout(new GridBagLayout());
|
|
|
68 |
final GridBagConstraints c = new DefaultGridBagConstraints();
|
|
|
69 |
|
73 |
ilm |
70 |
this.panelEcheances = new ListPanelEcheancesClients(onlyOld);
|
18 |
ilm |
71 |
|
|
|
72 |
// PANEL AVEC LA LISTE DES ECHEANCES
|
|
|
73 |
c.weightx = 1;
|
|
|
74 |
c.weighty = 1;
|
|
|
75 |
c.gridwidth = GridBagConstraints.REMAINDER;
|
|
|
76 |
c.fill = GridBagConstraints.BOTH;
|
|
|
77 |
this.add(this.panelEcheances, c);
|
|
|
78 |
|
73 |
ilm |
79 |
final IListe liste = this.panelEcheances.getListe();
|
|
|
80 |
IListFilterDatePanel datePanel = new IListFilterDatePanel(liste, liste.getRequest().getPrimaryTable().getField("DATE"), IListFilterDatePanel.getDefaultMap());
|
19 |
ilm |
81 |
|
|
|
82 |
c.weighty = 0;
|
|
|
83 |
c.gridy++;
|
73 |
ilm |
84 |
c.weightx = 1;
|
|
|
85 |
this.add(datePanel, c);
|
|
|
86 |
|
|
|
87 |
IListTotalPanel totalPanel = new IListTotalPanel(liste, Arrays.asList(this.panelEcheances.getElement().getTable().getField("MONTANT")));
|
|
|
88 |
|
|
|
89 |
c.weighty = 0;
|
|
|
90 |
c.gridy++;
|
19 |
ilm |
91 |
c.anchor = GridBagConstraints.EAST;
|
|
|
92 |
c.weightx = 0;
|
|
|
93 |
c.fill = GridBagConstraints.NONE;
|
|
|
94 |
this.add(totalPanel, c);
|
|
|
95 |
|
|
|
96 |
c.anchor = GridBagConstraints.WEST;
|
18 |
ilm |
97 |
c.gridx = 0;
|
|
|
98 |
c.gridy++;
|
|
|
99 |
c.gridwidth = 1;
|
|
|
100 |
|
|
|
101 |
c.weighty = 0;
|
|
|
102 |
c.fill = GridBagConstraints.NONE;
|
|
|
103 |
c.weightx = 0;
|
|
|
104 |
final JCheckBox checkRegCompta = new JCheckBox("Voir les régularisations de comptabilité");
|
|
|
105 |
if (UserRightsManager.getCurrentUserRights().haveRight(ComptaUserRight.MENU)) {
|
|
|
106 |
this.add(checkRegCompta, c);
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
checkRegCompta.addActionListener(new ActionListener() {
|
|
|
110 |
@Override
|
|
|
111 |
public void actionPerformed(ActionEvent e) {
|
|
|
112 |
panelEcheances.setShowRegCompta(checkRegCompta.isSelected());
|
|
|
113 |
|
|
|
114 |
}
|
|
|
115 |
});
|
|
|
116 |
|
|
|
117 |
c.weightx = 1;
|
|
|
118 |
c.anchor = GridBagConstraints.EAST;
|
|
|
119 |
// Bouton Relancer
|
|
|
120 |
this.relancer = new JButton("Relancer");
|
|
|
121 |
this.relancer.setHorizontalAlignment(SwingConstants.RIGHT);
|
142 |
ilm |
122 |
if (UserRightsManager.getCurrentUserRights().haveRight(NXRights.GESTION_ENCAISSEMENT.getCode())) {
|
18 |
ilm |
123 |
c.gridx++;
|
|
|
124 |
this.add(this.relancer, c);
|
|
|
125 |
this.relancer.addActionListener(new ActionListener() {
|
|
|
126 |
public void actionPerformed(ActionEvent e) {
|
177 |
ilm |
127 |
((EcheanceClientSQLElement) panelEcheances.getElement()).relanceClient(getListPanelEcheancesClients().getListe().getSelectedRow().asRow());
|
18 |
ilm |
128 |
}
|
|
|
129 |
});
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
// Bouton Encaisser
|
|
|
133 |
this.encaisser = new JButton("Encaisser");
|
|
|
134 |
this.encaisser.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
135 |
c.gridx++;
|
|
|
136 |
c.weightx = 0;
|
142 |
ilm |
137 |
if (UserRightsManager.getCurrentUserRights().haveRight(NXRights.GESTION_ENCAISSEMENT.getCode())) {
|
18 |
ilm |
138 |
|
|
|
139 |
this.add(this.encaisser, c);
|
|
|
140 |
}
|
|
|
141 |
this.encaisser.addActionListener(new ActionListener() {
|
|
|
142 |
|
|
|
143 |
public void actionPerformed(ActionEvent e) {
|
|
|
144 |
|
|
|
145 |
List<Integer> selectedIds = ListeDesEcheancesClientsPanel.this.panelEcheances.getListe().getSelection().getSelectedIDs();
|
156 |
ilm |
146 |
List<SQLRow> selectedRows = new ArrayList<>(selectedIds.size());
|
18 |
ilm |
147 |
int idCpt = -1;
|
|
|
148 |
int idClient = -1;
|
156 |
ilm |
149 |
int idCptTiers = -1;
|
|
|
150 |
String tiers = "";
|
18 |
ilm |
151 |
boolean showMessage = false;
|
|
|
152 |
|
156 |
ilm |
153 |
StringBuilder numerosFacturesBuilders = new StringBuilder();
|
18 |
ilm |
154 |
for (Integer integer : selectedIds) {
|
|
|
155 |
final SQLRow row = ListeDesEcheancesClientsPanel.this.panelEcheances.getListe().getSource().getPrimaryTable().getRow(integer);
|
156 |
ilm |
156 |
|
18 |
ilm |
157 |
selectedRows.add(row);
|
156 |
ilm |
158 |
tiers = row.getString("TIERS");
|
18 |
ilm |
159 |
String nom = row.getForeignRow("ID_MOUVEMENT").getForeignRow("ID_PIECE").getString("NOM");
|
|
|
160 |
|
156 |
ilm |
161 |
numerosFacturesBuilders.append(nom);
|
|
|
162 |
numerosFacturesBuilders.append(' ');
|
|
|
163 |
|
18 |
ilm |
164 |
SQLRow rowClient = row.getForeignRow("ID_CLIENT");
|
156 |
ilm |
165 |
if (rowClient != null && !rowClient.isUndefined()) {
|
|
|
166 |
int idTmp = rowClient.getInt("ID_COMPTE_PCE");
|
|
|
167 |
int idCliTmp = rowClient.getID();
|
|
|
168 |
if (idCpt > -1 && idCpt != idTmp) {
|
|
|
169 |
JOptionPane.showMessageDialog(null, "Impossible d'effectuer un encaissement sur plusieurs factures ayant des clients avec des comptes différents.");
|
|
|
170 |
return;
|
|
|
171 |
} else {
|
|
|
172 |
idCpt = idTmp;
|
|
|
173 |
}
|
18 |
ilm |
174 |
|
156 |
ilm |
175 |
if (idClient > -1 && idClient != idCliTmp) {
|
|
|
176 |
showMessage = true;
|
|
|
177 |
} else {
|
|
|
178 |
idClient = idCliTmp;
|
|
|
179 |
}
|
18 |
ilm |
180 |
}
|
156 |
ilm |
181 |
SQLRow rowCptTiers = row.getForeignRow("ID_COMPTE_PCE_TIERS");
|
|
|
182 |
if (rowCptTiers != null && !rowCptTiers.isUndefined()) {
|
|
|
183 |
idCptTiers = rowCptTiers.getID();
|
|
|
184 |
}
|
18 |
ilm |
185 |
}
|
|
|
186 |
if (showMessage) {
|
|
|
187 |
int answer = JOptionPane.showConfirmDialog(null, "Attention vous avez sélectionné des factures ayant des clients différents. Voulez vous continuer?");
|
|
|
188 |
if (answer != JOptionPane.YES_OPTION) {
|
|
|
189 |
return;
|
|
|
190 |
}
|
|
|
191 |
|
|
|
192 |
}
|
|
|
193 |
SQLElement encaisseElt = Configuration.getInstance().getDirectory().getElement("ENCAISSER_MONTANT");
|
180 |
ilm |
194 |
EditFrame editEncaisse = new EditFrame(encaisseElt);
|
18 |
ilm |
195 |
|
|
|
196 |
SQLRowValues rowVals = new SQLRowValues(encaisseElt.getTable());
|
156 |
ilm |
197 |
if (idClient > -1) {
|
|
|
198 |
rowVals.put("ID_CLIENT", idClient);
|
|
|
199 |
}
|
|
|
200 |
rowVals.put("NOM", numerosFacturesBuilders.toString().trim());
|
|
|
201 |
rowVals.put("TIERS", tiers);
|
|
|
202 |
if (idCptTiers > -1) {
|
|
|
203 |
rowVals.put("ID_COMPTE_PCE_TIERS", idCptTiers);
|
|
|
204 |
}
|
18 |
ilm |
205 |
|
180 |
ilm |
206 |
final EncaisserMontantSQLComponent sqlComponent = (EncaisserMontantSQLComponent) editEncaisse.getSQLComponent();
|
18 |
ilm |
207 |
|
|
|
208 |
sqlComponent.resetValue();
|
|
|
209 |
sqlComponent.select(rowVals);
|
|
|
210 |
sqlComponent.loadEcheancesFromRows(selectedRows);
|
180 |
ilm |
211 |
editEncaisse.setTitle("Encaissement de factures clients");
|
|
|
212 |
editEncaisse.pack();
|
|
|
213 |
editEncaisse.setVisible(true);
|
18 |
ilm |
214 |
}
|
|
|
215 |
});
|
|
|
216 |
|
73 |
ilm |
217 |
liste.addIListener(new IListener() {
|
18 |
ilm |
218 |
public void selectionId(int id, int field) {
|
|
|
219 |
|
180 |
ilm |
220 |
ListeDesEcheancesClientsPanel.this.relancer.setEnabled(id > 1);
|
|
|
221 |
ListeDesEcheancesClientsPanel.this.encaisser.setEnabled(id > 1);
|
18 |
ilm |
222 |
}
|
|
|
223 |
});
|
|
|
224 |
this.relancer.setEnabled(false);
|
|
|
225 |
this.encaisser.setEnabled(false);
|
|
|
226 |
|
|
|
227 |
}
|
|
|
228 |
|
|
|
229 |
public IListPanel getListPanelEcheancesClients() {
|
|
|
230 |
return this.panelEcheances;
|
|
|
231 |
}
|
|
|
232 |
}
|