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.supplychain.stock.action;
|
14 |
package org.openconcerto.erp.core.supplychain.stock.action;
|
15 |
|
15 |
|
16 |
import org.openconcerto.erp.action.CreateFrameAbstractAction;
|
16 |
import org.openconcerto.erp.action.CreateFrameAbstractAction;
|
17 |
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
|
17 |
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
|
18 |
import org.openconcerto.erp.core.common.ui.IListTotalPanel;
|
18 |
import org.openconcerto.erp.core.common.ui.IListTotalPanel;
|
19 |
import org.openconcerto.erp.core.common.ui.ListeViewPanel;
|
- |
|
20 |
import org.openconcerto.erp.core.common.ui.PanelFrame;
|
19 |
import org.openconcerto.erp.rights.DepotStockViewRightEditor;
|
21 |
import org.openconcerto.sql.Configuration;
|
20 |
import org.openconcerto.sql.Configuration;
|
22 |
import org.openconcerto.sql.element.SQLElement;
|
21 |
import org.openconcerto.sql.element.SQLElement;
|
23 |
import org.openconcerto.sql.model.FieldPath;
|
22 |
import org.openconcerto.sql.model.FieldPath;
|
24 |
import org.openconcerto.sql.model.SQLBackgroundTableCache;
|
23 |
import org.openconcerto.sql.model.SQLBackgroundTableCache;
|
25 |
import org.openconcerto.sql.model.SQLRow;
|
24 |
import org.openconcerto.sql.model.SQLRow;
|
26 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
25 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
27 |
import org.openconcerto.sql.model.SQLSelect;
|
26 |
import org.openconcerto.sql.model.SQLSelect;
|
28 |
import org.openconcerto.sql.model.SQLTable;
|
27 |
import org.openconcerto.sql.model.SQLTable;
|
29 |
import org.openconcerto.sql.model.Where;
|
28 |
import org.openconcerto.sql.model.Where;
|
30 |
import org.openconcerto.sql.model.graph.Path;
|
29 |
import org.openconcerto.sql.model.graph.Path;
|
- |
|
30 |
import org.openconcerto.sql.users.rights.UserRightsManager;
|
31 |
import org.openconcerto.sql.view.ListeAddPanel;
|
31 |
import org.openconcerto.sql.view.ListeAddPanel;
|
32 |
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn;
|
32 |
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn;
|
33 |
import org.openconcerto.sql.view.list.IListe;
|
33 |
import org.openconcerto.sql.view.list.IListe;
|
34 |
import org.openconcerto.sql.view.list.SQLTableModelColumn;
|
34 |
import org.openconcerto.sql.view.list.SQLTableModelColumn;
|
35 |
import org.openconcerto.sql.view.list.SQLTableModelSourceOnline;
|
35 |
import org.openconcerto.sql.view.list.SQLTableModelSourceOnline;
|
36 |
import org.openconcerto.ui.DefaultGridBagConstraints;
|
36 |
import org.openconcerto.ui.DefaultGridBagConstraints;
|
- |
|
37 |
import org.openconcerto.ui.PanelFrame;
|
37 |
import org.openconcerto.utils.CollectionUtils;
|
38 |
import org.openconcerto.utils.CollectionUtils;
|
38 |
import org.openconcerto.utils.DecimalUtils;
|
39 |
import org.openconcerto.utils.DecimalUtils;
|
39 |
import org.openconcerto.utils.Tuple2;
|
40 |
import org.openconcerto.utils.Tuple2;
|
40 |
import org.openconcerto.utils.cc.ITransformer;
|
41 |
import org.openconcerto.utils.cc.ITransformer;
|
41 |
|
42 |
|
Line 51... |
Line 52... |
51 |
import javax.swing.JPanel;
|
52 |
import javax.swing.JPanel;
|
52 |
import javax.swing.JTabbedPane;
|
53 |
import javax.swing.JTabbedPane;
|
53 |
|
54 |
|
54 |
public class ListeDesStocksAction extends CreateFrameAbstractAction {
|
55 |
public class ListeDesStocksAction extends CreateFrameAbstractAction {
|
55 |
|
56 |
|
- |
|
57 |
private final boolean besoin;
|
- |
|
58 |
|
56 |
public ListeDesStocksAction() {
|
59 |
public ListeDesStocksAction() {
|
- |
|
60 |
this(false);
|
- |
|
61 |
}
|
- |
|
62 |
|
- |
|
63 |
public ListeDesStocksAction(boolean b) {
|
57 |
super();
|
64 |
super();
|
- |
|
65 |
this.besoin = b;
|
58 |
this.putValue(Action.NAME, "Liste des stocks");
|
66 |
this.putValue(Action.NAME, "Liste des stocks");
|
59 |
|
67 |
|
60 |
}
|
68 |
}
|
61 |
|
69 |
|
62 |
public JFrame createFrame() {
|
70 |
public JFrame createFrame() {
|
Line 65... |
Line 73... |
65 |
final SQLTable depotTable = stockTable.getForeignTable("ID_DEPOT_STOCK");
|
73 |
final SQLTable depotTable = stockTable.getForeignTable("ID_DEPOT_STOCK");
|
66 |
|
74 |
|
67 |
List<SQLRow> rowsEtat = SQLBackgroundTableCache.getInstance().getCacheForTable(depotTable).getRows();
|
75 |
List<SQLRow> rowsEtat = SQLBackgroundTableCache.getInstance().getCacheForTable(depotTable).getRows();
|
68 |
|
76 |
|
69 |
JTabbedPane tabs = new JTabbedPane();
|
77 |
JTabbedPane tabs = new JTabbedPane();
|
70 |
|
- |
|
- |
|
78 |
boolean canViewAll = true;
|
71 |
for (final SQLRow sqlRow : rowsEtat) {
|
79 |
for (final SQLRow sqlRow : rowsEtat) {
|
- |
|
80 |
boolean canView = UserRightsManager.getCurrentUserRights().haveRight(DepotStockViewRightEditor.ID_RIGHT, String.valueOf(sqlRow.getID()));
|
- |
|
81 |
canViewAll &= canView;
|
- |
|
82 |
if (canView) {
|
- |
|
83 |
|
- |
|
84 |
ListeAddPanel panel = createPanel(eltStock, stockTable, sqlRow);
|
- |
|
85 |
tabs.add(sqlRow.getString("NOM"), panel);
|
- |
|
86 |
}
|
- |
|
87 |
|
- |
|
88 |
}
|
- |
|
89 |
|
- |
|
90 |
if (canViewAll && this.besoin) {
|
- |
|
91 |
tabs.insertTab("Global", null, createPanel(eltStock, stockTable, null), null, 0);
|
- |
|
92 |
}
|
- |
|
93 |
|
- |
|
94 |
JPanel panel = new JPanel(new GridBagLayout());
|
- |
|
95 |
GridBagConstraints c = new DefaultGridBagConstraints();
|
- |
|
96 |
c.fill = GridBagConstraints.BOTH;
|
- |
|
97 |
c.weightx = 1;
|
- |
|
98 |
c.weighty = 1;
|
- |
|
99 |
panel.add(tabs, c);
|
- |
|
100 |
return new PanelFrame(panel, "Liste des stocks");
|
- |
|
101 |
}
|
72 |
|
102 |
|
- |
|
103 |
private ListeAddPanel createPanel(SQLElement eltStock, final SQLTable stockTable, final SQLRow sqlRow) {
|
73 |
final SQLTableModelSourceOnline tableSource = eltStock.getTableSource(true);
|
104 |
final SQLTableModelSourceOnline tableSource = eltStock.getTableSource(true);
|
74 |
|
105 |
|
75 |
SQLTableModelColumn colStock;
|
106 |
SQLTableModelColumn colStock;
|
76 |
if (stockTable.getDBRoot().contains("ARTICLE_PRIX_REVIENT")) {
|
107 |
if (stockTable.getDBRoot().contains("ARTICLE_PRIX_REVIENT")) {
|
77 |
colStock = tableSource.getColumn(tableSource.getColumns().size() - 2);
|
108 |
colStock = tableSource.getColumn(tableSource.getColumns().size() - 2);
|
Line 98... |
Line 129... |
98 |
}
|
129 |
}
|
99 |
|
130 |
|
100 |
@Override
|
131 |
@Override
|
101 |
public Set<FieldPath> getPaths() {
|
132 |
public Set<FieldPath> getPaths() {
|
102 |
final SQLTable table = stockTable;
|
133 |
final SQLTable table = stockTable;
|
103 |
Path p = new Path(table);
|
- |
|
104 |
Path p2 = new Path(table).addForeignField("ID_ARTICLE");
|
134 |
Path p2 = new Path(table).addForeignField("ID_ARTICLE");
|
105 |
return CollectionUtils.createSet(new FieldPath(p2, "PA_HT"));
|
135 |
return CollectionUtils.createSet(new FieldPath(p2, "PA_HT"));
|
106 |
}
|
136 |
}
|
107 |
};
|
137 |
};
|
108 |
colStock.setRenderer(ComptaSQLConfElement.CURRENCY_RENDERER);
|
138 |
colStock.setRenderer(ComptaSQLConfElement.CURRENCY_RENDERER);
|
Line 111... |
Line 141... |
111 |
|
141 |
|
112 |
tableSource.getReq().setSelectTransf(new ITransformer<SQLSelect, SQLSelect>() {
|
142 |
tableSource.getReq().setSelectTransf(new ITransformer<SQLSelect, SQLSelect>() {
|
113 |
|
143 |
|
114 |
@Override
|
144 |
@Override
|
115 |
public SQLSelect transformChecked(SQLSelect input) {
|
145 |
public SQLSelect transformChecked(SQLSelect input) {
|
116 |
input.setWhere(new Where(input.getTable("STOCK").getField("ID_DEPOT_STOCK"), "=", sqlRow.getID()));
|
146 |
Where w = sqlRow == null ? null : new Where(input.getTable("STOCK").getField("ID_DEPOT_STOCK"), "=", sqlRow.getID());
|
- |
|
147 |
if (besoin) {
|
- |
|
148 |
w = Where.and(w, new Where(input.getTable("STOCK").getField("QTE_TH"), "<", input.getTable("STOCK").getField("QTE_MIN")));
|
- |
|
149 |
}
|
- |
|
150 |
input.setWhere(w);
|
117 |
return input;
|
151 |
return input;
|
118 |
}
|
152 |
}
|
119 |
});
|
153 |
});
|
120 |
|
154 |
|
121 |
final IListe liste = new IListe(tableSource);
|
155 |
final IListe liste = new IListe(tableSource);
|
Line 130... |
Line 164... |
130 |
c2.gridy = 4;
|
164 |
c2.gridy = 4;
|
131 |
c2.anchor = GridBagConstraints.EAST;
|
165 |
c2.anchor = GridBagConstraints.EAST;
|
132 |
c2.weightx = 0;
|
166 |
c2.weightx = 0;
|
133 |
c2.fill = GridBagConstraints.NONE;
|
167 |
c2.fill = GridBagConstraints.NONE;
|
134 |
panel.add(total, c2);
|
168 |
panel.add(total, c2);
|
135 |
tabs.add(sqlRow.getString("NOM"), panel);
|
- |
|
136 |
}
|
- |
|
137 |
JPanel panel = new JPanel(new GridBagLayout());
|
- |
|
138 |
GridBagConstraints c = new DefaultGridBagConstraints();
|
- |
|
139 |
c.fill = GridBagConstraints.BOTH;
|
- |
|
140 |
c.weightx = 1;
|
- |
|
141 |
c.weighty = 1;
|
169 |
return panel;
|
142 |
panel.add(tabs, c);
|
- |
|
143 |
return new PanelFrame(panel, "Liste des stocks");
|
- |
|
144 |
}
|
170 |
}
|
145 |
}
|
171 |
}
|