Line 1... |
Line 1... |
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-2019 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.
|
Line 14... |
Line 14... |
14 |
package org.openconcerto.erp.core.sales.shipment.element;
|
14 |
package org.openconcerto.erp.core.sales.shipment.element;
|
15 |
|
15 |
|
16 |
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
|
16 |
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
|
17 |
import org.openconcerto.erp.core.sales.shipment.component.BonDeLivraisonSQLComponent;
|
17 |
import org.openconcerto.erp.core.sales.shipment.component.BonDeLivraisonSQLComponent;
|
18 |
import org.openconcerto.erp.preferences.DefaultNXProps;
|
18 |
import org.openconcerto.erp.preferences.DefaultNXProps;
|
19 |
import org.openconcerto.erp.preferences.GestionArticleGlobalPreferencePanel;
|
- |
|
20 |
import org.openconcerto.sql.Configuration;
|
19 |
import org.openconcerto.sql.Configuration;
|
21 |
import org.openconcerto.sql.element.SQLComponent;
|
20 |
import org.openconcerto.sql.element.SQLComponent;
|
22 |
import org.openconcerto.sql.element.SQLElement;
|
21 |
import org.openconcerto.sql.element.SQLElement;
|
23 |
import org.openconcerto.sql.element.SQLElementLink.LinkType;
|
22 |
import org.openconcerto.sql.element.SQLElementLink.LinkType;
|
24 |
import org.openconcerto.sql.element.SQLElementLinksSetup;
|
23 |
import org.openconcerto.sql.element.SQLElementLinksSetup;
|
Line 27... |
Line 26... |
27 |
import org.openconcerto.sql.model.SQLName;
|
26 |
import org.openconcerto.sql.model.SQLName;
|
28 |
import org.openconcerto.sql.model.SQLRow;
|
27 |
import org.openconcerto.sql.model.SQLRow;
|
29 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
28 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
30 |
import org.openconcerto.sql.model.SQLSelect;
|
29 |
import org.openconcerto.sql.model.SQLSelect;
|
31 |
import org.openconcerto.sql.model.SQLTable;
|
30 |
import org.openconcerto.sql.model.SQLTable;
|
- |
|
31 |
import org.openconcerto.sql.model.SQLTableEvent;
|
- |
|
32 |
import org.openconcerto.sql.model.SQLTableEvent.Mode;
|
- |
|
33 |
import org.openconcerto.sql.model.SQLTableModifiedListener;
|
32 |
import org.openconcerto.sql.model.Where;
|
34 |
import org.openconcerto.sql.model.Where;
|
33 |
import org.openconcerto.sql.preferences.SQLPreferences;
|
35 |
import org.openconcerto.sql.request.ListSQLRequest;
|
34 |
import org.openconcerto.sql.request.UpdateBuilder;
|
36 |
import org.openconcerto.sql.request.UpdateBuilder;
|
35 |
import org.openconcerto.sql.view.EditFrame;
|
37 |
import org.openconcerto.sql.view.EditFrame;
|
36 |
import org.openconcerto.sql.view.EditPanel;
|
38 |
import org.openconcerto.sql.view.EditPanel;
|
37 |
import org.openconcerto.sql.view.list.IListe;
|
39 |
import org.openconcerto.sql.view.list.IListe;
|
38 |
import org.openconcerto.sql.view.list.RowAction;
|
40 |
import org.openconcerto.sql.view.list.RowAction;
|
- |
|
41 |
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
|
- |
|
42 |
import org.openconcerto.sql.view.list.action.ListEvent;
|
39 |
import org.openconcerto.ui.preferences.DefaultProps;
|
43 |
import org.openconcerto.ui.preferences.DefaultProps;
|
40 |
import org.openconcerto.utils.ListMap;
|
44 |
import org.openconcerto.utils.ListMap;
|
41 |
|
45 |
|
42 |
import java.awt.event.ActionEvent;
|
46 |
import java.awt.event.ActionEvent;
|
43 |
import java.sql.SQLException;
|
47 |
import java.sql.SQLException;
|
44 |
import java.util.ArrayList;
|
48 |
import java.util.ArrayList;
|
- |
|
49 |
import java.util.Arrays;
|
45 |
import java.util.List;
|
50 |
import java.util.List;
|
46 |
|
51 |
|
47 |
import javax.swing.AbstractAction;
|
52 |
import javax.swing.AbstractAction;
|
48 |
|
53 |
|
49 |
import org.apache.commons.dbutils.handlers.ArrayListHandler;
|
54 |
import org.apache.commons.dbutils.handlers.ArrayListHandler;
|
Line 53... |
Line 58... |
53 |
// TODO afficher uniquement les factures non livrees dans la combo
|
58 |
// TODO afficher uniquement les factures non livrees dans la combo
|
54 |
// MAYBE mettre un niceCellRenderer dans les rowValuesTable
|
59 |
// MAYBE mettre un niceCellRenderer dans les rowValuesTable
|
55 |
|
60 |
|
56 |
public BonDeLivraisonSQLElement(String single, String plural) {
|
61 |
public BonDeLivraisonSQLElement(String single, String plural) {
|
57 |
super("BON_DE_LIVRAISON", single, plural);
|
62 |
super("BON_DE_LIVRAISON", single, plural);
|
- |
|
63 |
// Verrou facture
|
- |
|
64 |
if (getTable().contains("VERROU_FACTURATION")) {
|
- |
|
65 |
PredicateRowAction lock = new PredicateRowAction(new AbstractAction("Verrouiller") {
|
- |
|
66 |
@Override
|
- |
|
67 |
public void actionPerformed(ActionEvent e) {
|
- |
|
68 |
updateVerrouFacture(IListe.get(e).getSelectedRowAccessors(), true);
|
- |
|
69 |
}
|
- |
|
70 |
}, false);
|
- |
|
71 |
lock.setPredicate(ListEvent.getNonEmptySelectionPredicate());
|
- |
|
72 |
lock.setPath(Arrays.asList("Verrou facturaction", "Verrou facturaction", "Verrou facturaction"));
|
- |
|
73 |
PredicateRowAction unlock = new PredicateRowAction(new AbstractAction("Déverrouiller") {
|
- |
|
74 |
@Override
|
- |
|
75 |
public void actionPerformed(ActionEvent e) {
|
- |
|
76 |
updateVerrouFacture(IListe.get(e).getSelectedRowAccessors(), false);
|
- |
|
77 |
}
|
- |
|
78 |
}, false);
|
- |
|
79 |
unlock.setPath(Arrays.asList("Verrou facturaction", "Verrou facturaction", "Verrou facturaction"));
|
- |
|
80 |
unlock.setPredicate(ListEvent.getNonEmptySelectionPredicate());
|
- |
|
81 |
getRowActions().add(lock);
|
- |
|
82 |
getRowActions().add(unlock);
|
- |
|
83 |
}
|
- |
|
84 |
|
- |
|
85 |
}
|
- |
|
86 |
|
- |
|
87 |
@Override
|
- |
|
88 |
protected void _initListRequest(ListSQLRequest req) {
|
- |
|
89 |
super._initListRequest(req);
|
- |
|
90 |
req.addToGraphToFetch("VERROU_FACTURATION");
|
- |
|
91 |
}
|
- |
|
92 |
|
- |
|
93 |
private void updateVerrouFacture(List<SQLRowAccessor> rows, boolean state) {
|
- |
|
94 |
UpdateBuilder builder = new UpdateBuilder(getTable());
|
- |
|
95 |
builder.setObject("VERROU_FACTURATION", state);
|
- |
|
96 |
builder.setWhere(Where.inValues(getTable().getKey(), SQLRow.getIDs(rows)));
|
- |
|
97 |
getTable().getDBSystemRoot().getDataSource().execute(builder.asString());
|
- |
|
98 |
getTable().fireTableModified();
|
58 |
}
|
99 |
}
|
59 |
|
100 |
|
60 |
public BonDeLivraisonSQLElement() {
|
101 |
public BonDeLivraisonSQLElement() {
|
61 |
this("un bon de livraison", "bons de livraison");
|
102 |
this("un bon de livraison", "bons de livraison");
|
62 |
}
|
103 |
}
|
Line 146... |
Line 187... |
146 |
List<Object> cmds = new ArrayList<>();
|
187 |
List<Object> cmds = new ArrayList<>();
|
147 |
List<Object> devis = new ArrayList<>();
|
188 |
List<Object> devis = new ArrayList<>();
|
148 |
List<Integer> ids = new ArrayList<>();
|
189 |
List<Integer> ids = new ArrayList<>();
|
149 |
for (SQLRow row : trees.getRows()) {
|
190 |
for (SQLRow row : trees.getRows()) {
|
150 |
|
191 |
|
151 |
SQLPreferences prefs = new SQLPreferences(getTable().getDBRoot());
|
- |
|
152 |
|
- |
|
153 |
cmds.addAll(getSourceTrRowsFrom(row.getID(), "COMMANDE_CLIENT_ELEMENT", "COMMANDE_CLIENT"));
|
192 |
cmds.addAll(getSourceTrRowsFrom(row.getID(), "COMMANDE_CLIENT_ELEMENT", "COMMANDE_CLIENT"));
|
154 |
devis.addAll(getSourceTrRowsFrom(row.getID(), "DEVIS_ELEMENT", "DEVIS"));
|
193 |
devis.addAll(getSourceTrRowsFrom(row.getID(), "DEVIS_ELEMENT", "DEVIS"));
|
155 |
ids.add(row.getID());
|
194 |
ids.add(row.getID());
|
156 |
if (!prefs.getBoolean(GestionArticleGlobalPreferencePanel.STOCK_FACT, true)) {
|
- |
|
157 |
|
195 |
|
158 |
// Mise à jour des stocks
|
196 |
// Mise à jour des stocks
|
159 |
SQLElement eltMvtStock = Configuration.getInstance().getDirectory().getElement("MOUVEMENT_STOCK");
|
197 |
SQLElement eltMvtStock = Configuration.getInstance().getDirectory().getElement("MOUVEMENT_STOCK");
|
160 |
SQLSelect sel = new SQLSelect();
|
198 |
SQLSelect sel = new SQLSelect();
|
161 |
sel.addSelect(eltMvtStock.getTable().getField("ID"));
|
199 |
sel.addSelect(eltMvtStock.getTable().getField("ID"));
|
Line 169... |
Line 207... |
169 |
for (int i = 0; i < l.size(); i++) {
|
207 |
for (int i = 0; i < l.size(); i++) {
|
170 |
Object[] tmp = (Object[]) l.get(i);
|
208 |
Object[] tmp = (Object[]) l.get(i);
|
171 |
eltMvtStock.archive(((Number) tmp[0]).intValue());
|
209 |
eltMvtStock.archive(((Number) tmp[0]).intValue());
|
172 |
}
|
210 |
}
|
173 |
}
|
211 |
}
|
174 |
}
|
212 |
|
175 |
}
|
213 |
}
|
176 |
super.archive(trees, cutLinks);
|
214 |
super.archive(trees, cutLinks);
|
177 |
|
215 |
|
178 |
updateQteLivree(devis, "DEVIS_ELEMENT", "DEVIS");
|
216 |
updateQteLivree(devis, "DEVIS_ELEMENT", "DEVIS");
|
179 |
updateQteLivree(cmds, "COMMANDE_CLIENT_ELEMENT", "COMMANDE_CLIENT");
|
217 |
updateQteLivree(cmds, "COMMANDE_CLIENT_ELEMENT", "COMMANDE_CLIENT");
|
Line 197... |
Line 235... |
197 |
return (selection != null && selection.size() == 1);
|
235 |
return (selection != null && selection.size() == 1);
|
198 |
}
|
236 |
}
|
199 |
};
|
237 |
};
|
200 |
}
|
238 |
}
|
201 |
|
239 |
|
- |
|
240 |
private final List<SQLTableModifiedListener> listenerCmdInserted = new ArrayList<>();
|
- |
|
241 |
|
- |
|
242 |
public void addInsertedCmdListener(SQLTableModifiedListener l) {
|
- |
|
243 |
this.listenerCmdInserted.add(l);
|
- |
|
244 |
}
|
- |
|
245 |
|
- |
|
246 |
public void removeInsertedCmdListener(SQLTableModifiedListener l) {
|
- |
|
247 |
this.listenerCmdInserted.remove(l);
|
- |
|
248 |
}
|
- |
|
249 |
|
- |
|
250 |
public void fireInsertedCmdListener(SQLRow row) {
|
- |
|
251 |
for (SQLTableModifiedListener sqlTableModifiedListener : this.listenerCmdInserted) {
|
- |
|
252 |
sqlTableModifiedListener.tableModified(new SQLTableEvent(row, Mode.ROW_ADDED, null));
|
- |
|
253 |
}
|
- |
|
254 |
}
|
- |
|
255 |
|
202 |
@Override
|
256 |
@Override
|
203 |
protected String createCodeSuffix() {
|
257 |
protected String createCodeSuffix() {
|
204 |
return ".delivery.note";
|
258 |
return ".delivery.note";
|
205 |
}
|
259 |
}
|
206 |
|
260 |
|