156 |
ilm |
1 |
/*
|
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
|
|
3 |
*
|
182 |
ilm |
4 |
* Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
|
156 |
ilm |
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.supplychain.stock.action;
|
|
|
15 |
|
|
|
16 |
import org.openconcerto.erp.action.CreateFrameAbstractAction;
|
|
|
17 |
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
|
|
|
18 |
import org.openconcerto.erp.core.common.ui.IListTotalPanel;
|
182 |
ilm |
19 |
import org.openconcerto.erp.rights.DepotStockViewRightEditor;
|
156 |
ilm |
20 |
import org.openconcerto.sql.Configuration;
|
|
|
21 |
import org.openconcerto.sql.element.SQLElement;
|
|
|
22 |
import org.openconcerto.sql.model.FieldPath;
|
|
|
23 |
import org.openconcerto.sql.model.SQLBackgroundTableCache;
|
|
|
24 |
import org.openconcerto.sql.model.SQLRow;
|
|
|
25 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
|
|
26 |
import org.openconcerto.sql.model.SQLSelect;
|
|
|
27 |
import org.openconcerto.sql.model.SQLTable;
|
|
|
28 |
import org.openconcerto.sql.model.Where;
|
|
|
29 |
import org.openconcerto.sql.model.graph.Path;
|
182 |
ilm |
30 |
import org.openconcerto.sql.users.rights.UserRightsManager;
|
156 |
ilm |
31 |
import org.openconcerto.sql.view.ListeAddPanel;
|
|
|
32 |
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn;
|
|
|
33 |
import org.openconcerto.sql.view.list.IListe;
|
|
|
34 |
import org.openconcerto.sql.view.list.SQLTableModelColumn;
|
|
|
35 |
import org.openconcerto.sql.view.list.SQLTableModelSourceOnline;
|
|
|
36 |
import org.openconcerto.ui.DefaultGridBagConstraints;
|
182 |
ilm |
37 |
import org.openconcerto.ui.PanelFrame;
|
156 |
ilm |
38 |
import org.openconcerto.utils.CollectionUtils;
|
|
|
39 |
import org.openconcerto.utils.DecimalUtils;
|
|
|
40 |
import org.openconcerto.utils.Tuple2;
|
|
|
41 |
import org.openconcerto.utils.cc.ITransformer;
|
|
|
42 |
|
|
|
43 |
import java.awt.GridBagConstraints;
|
|
|
44 |
import java.awt.GridBagLayout;
|
|
|
45 |
import java.math.BigDecimal;
|
|
|
46 |
import java.util.ArrayList;
|
|
|
47 |
import java.util.List;
|
|
|
48 |
import java.util.Set;
|
|
|
49 |
|
|
|
50 |
import javax.swing.Action;
|
|
|
51 |
import javax.swing.JFrame;
|
|
|
52 |
import javax.swing.JPanel;
|
|
|
53 |
import javax.swing.JTabbedPane;
|
|
|
54 |
|
|
|
55 |
public class ListeDesStocksAction extends CreateFrameAbstractAction {
|
|
|
56 |
|
182 |
ilm |
57 |
private final boolean besoin;
|
|
|
58 |
|
156 |
ilm |
59 |
public ListeDesStocksAction() {
|
182 |
ilm |
60 |
this(false);
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
public ListeDesStocksAction(boolean b) {
|
156 |
ilm |
64 |
super();
|
182 |
ilm |
65 |
this.besoin = b;
|
156 |
ilm |
66 |
this.putValue(Action.NAME, "Liste des stocks");
|
|
|
67 |
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
public JFrame createFrame() {
|
|
|
71 |
SQLElement eltStock = Configuration.getInstance().getDirectory().getElement("STOCK");
|
|
|
72 |
final SQLTable stockTable = eltStock.getTable();
|
|
|
73 |
final SQLTable depotTable = stockTable.getForeignTable("ID_DEPOT_STOCK");
|
|
|
74 |
|
|
|
75 |
List<SQLRow> rowsEtat = SQLBackgroundTableCache.getInstance().getCacheForTable(depotTable).getRows();
|
|
|
76 |
|
|
|
77 |
JTabbedPane tabs = new JTabbedPane();
|
182 |
ilm |
78 |
boolean canViewAll = true;
|
156 |
ilm |
79 |
for (final SQLRow sqlRow : rowsEtat) {
|
182 |
ilm |
80 |
boolean canView = UserRightsManager.getCurrentUserRights().haveRight(DepotStockViewRightEditor.ID_RIGHT, String.valueOf(sqlRow.getID()));
|
|
|
81 |
canViewAll &= canView;
|
|
|
82 |
if (canView) {
|
156 |
ilm |
83 |
|
182 |
ilm |
84 |
ListeAddPanel panel = createPanel(eltStock, stockTable, sqlRow);
|
|
|
85 |
tabs.add(sqlRow.getString("NOM"), panel);
|
|
|
86 |
}
|
156 |
ilm |
87 |
|
182 |
ilm |
88 |
}
|
156 |
ilm |
89 |
|
182 |
ilm |
90 |
if (canViewAll && this.besoin) {
|
|
|
91 |
tabs.insertTab("Global", null, createPanel(eltStock, stockTable, null), null, 0);
|
|
|
92 |
}
|
156 |
ilm |
93 |
|
182 |
ilm |
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 |
}
|
156 |
ilm |
102 |
|
182 |
ilm |
103 |
private ListeAddPanel createPanel(SQLElement eltStock, final SQLTable stockTable, final SQLRow sqlRow) {
|
|
|
104 |
final SQLTableModelSourceOnline tableSource = eltStock.getTableSource(true);
|
|
|
105 |
|
|
|
106 |
SQLTableModelColumn colStock;
|
|
|
107 |
if (stockTable.getDBRoot().contains("ARTICLE_PRIX_REVIENT")) {
|
|
|
108 |
colStock = tableSource.getColumn(tableSource.getColumns().size() - 2);
|
|
|
109 |
} else {
|
|
|
110 |
|
|
|
111 |
colStock = new BaseSQLTableModelColumn("Valeur HT du stock", BigDecimal.class) {
|
|
|
112 |
|
|
|
113 |
@Override
|
|
|
114 |
protected Object show_(SQLRowAccessor stock) {
|
|
|
115 |
|
|
|
116 |
if (stock == null || stock.isUndefined()) {
|
|
|
117 |
return BigDecimal.ZERO;
|
|
|
118 |
} else {
|
|
|
119 |
float qte = stock.getFloat("QTE_REEL");
|
|
|
120 |
BigDecimal ha = stock.getForeign("ID_ARTICLE").getBigDecimal("PA_HT");
|
|
|
121 |
|
|
|
122 |
BigDecimal total = ha.multiply(new BigDecimal(qte), DecimalUtils.HIGH_PRECISION);
|
|
|
123 |
if (total.signum() == 1) {
|
|
|
124 |
return total;
|
|
|
125 |
} else {
|
156 |
ilm |
126 |
return BigDecimal.ZERO;
|
|
|
127 |
}
|
|
|
128 |
}
|
182 |
ilm |
129 |
}
|
156 |
ilm |
130 |
|
182 |
ilm |
131 |
@Override
|
|
|
132 |
public Set<FieldPath> getPaths() {
|
|
|
133 |
final SQLTable table = stockTable;
|
|
|
134 |
Path p2 = new Path(table).addForeignField("ID_ARTICLE");
|
|
|
135 |
return CollectionUtils.createSet(new FieldPath(p2, "PA_HT"));
|
|
|
136 |
}
|
|
|
137 |
};
|
|
|
138 |
colStock.setRenderer(ComptaSQLConfElement.CURRENCY_RENDERER);
|
|
|
139 |
tableSource.getColumns().add(colStock);
|
|
|
140 |
}
|
156 |
ilm |
141 |
|
182 |
ilm |
142 |
tableSource.getReq().setSelectTransf(new ITransformer<SQLSelect, SQLSelect>() {
|
156 |
ilm |
143 |
|
182 |
ilm |
144 |
@Override
|
|
|
145 |
public SQLSelect transformChecked(SQLSelect input) {
|
|
|
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")));
|
156 |
ilm |
149 |
}
|
182 |
ilm |
150 |
input.setWhere(w);
|
|
|
151 |
return input;
|
|
|
152 |
}
|
|
|
153 |
});
|
156 |
ilm |
154 |
|
182 |
ilm |
155 |
final IListe liste = new IListe(tableSource);
|
|
|
156 |
ListeAddPanel panel = new ListeAddPanel(eltStock, liste);
|
|
|
157 |
panel.setAddVisible(false);
|
|
|
158 |
panel.setDeleteVisible(false);
|
|
|
159 |
List<Tuple2<? extends SQLTableModelColumn, IListTotalPanel.Type>> fields = new ArrayList<Tuple2<? extends SQLTableModelColumn, IListTotalPanel.Type>>(1);
|
|
|
160 |
fields.add(Tuple2.create(colStock, IListTotalPanel.Type.SOMME));
|
156 |
ilm |
161 |
|
182 |
ilm |
162 |
IListTotalPanel total = new IListTotalPanel(liste, fields, null, "Total");
|
|
|
163 |
GridBagConstraints c2 = new DefaultGridBagConstraints();
|
|
|
164 |
c2.gridy = 4;
|
|
|
165 |
c2.anchor = GridBagConstraints.EAST;
|
|
|
166 |
c2.weightx = 0;
|
|
|
167 |
c2.fill = GridBagConstraints.NONE;
|
|
|
168 |
panel.add(total, c2);
|
|
|
169 |
return panel;
|
156 |
ilm |
170 |
}
|
|
|
171 |
}
|