Line 11... |
Line 11... |
11 |
* When distributing the software, include this License Header Notice in each file.
|
11 |
* When distributing the software, include this License Header Notice in each file.
|
12 |
*/
|
12 |
*/
|
13 |
|
13 |
|
14 |
package org.openconcerto.erp.core.supplychain.stock.element;
|
14 |
package org.openconcerto.erp.core.supplychain.stock.element;
|
15 |
|
15 |
|
- |
|
16 |
import org.openconcerto.erp.config.ComptaPropsConfiguration;
|
16 |
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
|
17 |
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
|
17 |
import org.openconcerto.erp.core.common.ui.ListeViewPanel;
|
18 |
import org.openconcerto.erp.core.common.ui.ListeViewPanel;
|
18 |
import org.openconcerto.erp.core.sales.invoice.report.EtatStockInventaireXmlSheet;
|
19 |
import org.openconcerto.erp.core.sales.invoice.report.EtatStockInventaireXmlSheet;
|
- |
|
20 |
import org.openconcerto.erp.core.supplychain.stock.report.StockReportPDF;
|
- |
|
21 |
import org.openconcerto.erp.preferences.GestionArticleGlobalPreferencePanel;
|
19 |
import org.openconcerto.sql.element.GroupSQLComponent;
|
22 |
import org.openconcerto.sql.element.GroupSQLComponent;
|
20 |
import org.openconcerto.sql.element.SQLComponent;
|
23 |
import org.openconcerto.sql.element.SQLComponent;
|
21 |
import org.openconcerto.sql.element.SQLElement;
|
24 |
import org.openconcerto.sql.element.SQLElement;
|
- |
|
25 |
import org.openconcerto.sql.model.ConnectionHandlerNoSetup;
|
- |
|
26 |
import org.openconcerto.sql.model.SQLDataSource;
|
- |
|
27 |
import org.openconcerto.sql.model.SQLRow;
|
22 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
28 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
- |
|
29 |
import org.openconcerto.sql.model.SQLRowListRSH;
|
- |
|
30 |
import org.openconcerto.sql.model.SQLSelect;
|
23 |
import org.openconcerto.sql.model.Where;
|
31 |
import org.openconcerto.sql.model.Where;
|
- |
|
32 |
import org.openconcerto.sql.preferences.SQLPreferences;
|
- |
|
33 |
import org.openconcerto.sql.utils.SQLUtils;
|
24 |
import org.openconcerto.sql.view.IListFrame;
|
34 |
import org.openconcerto.sql.view.IListFrame;
|
25 |
import org.openconcerto.sql.view.list.IListe;
|
35 |
import org.openconcerto.sql.view.list.IListe;
|
26 |
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
|
36 |
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
|
27 |
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
|
37 |
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
|
28 |
import org.openconcerto.sql.view.list.SQLTableModelSource;
|
38 |
import org.openconcerto.sql.view.list.SQLTableModelSource;
|
29 |
import org.openconcerto.ui.FrameUtil;
|
39 |
import org.openconcerto.ui.FrameUtil;
|
30 |
import org.openconcerto.ui.PanelFrame;
|
40 |
import org.openconcerto.ui.PanelFrame;
|
- |
|
41 |
import org.openconcerto.ui.SwingThreadUtils;
|
31 |
import org.openconcerto.utils.ExceptionHandler;
|
42 |
import org.openconcerto.utils.ExceptionHandler;
|
- |
|
43 |
import org.openconcerto.utils.FileUtils;
|
32 |
|
44 |
|
- |
|
45 |
import java.awt.Component;
|
- |
|
46 |
import java.awt.FileDialog;
|
- |
|
47 |
import java.awt.Frame;
|
33 |
import java.awt.event.ActionEvent;
|
48 |
import java.awt.event.ActionEvent;
|
- |
|
49 |
import java.io.File;
|
- |
|
50 |
import java.io.IOException;
|
- |
|
51 |
import java.sql.SQLException;
|
- |
|
52 |
import java.text.SimpleDateFormat;
|
34 |
import java.util.ArrayList;
|
53 |
import java.util.ArrayList;
|
- |
|
54 |
import java.util.Calendar;
|
35 |
import java.util.Collections;
|
55 |
import java.util.Collections;
|
36 |
import java.util.Date;
|
56 |
import java.util.Date;
|
- |
|
57 |
import java.util.HashSet;
|
37 |
import java.util.List;
|
58 |
import java.util.List;
|
- |
|
59 |
import java.util.Set;
|
38 |
|
60 |
|
39 |
import javax.swing.AbstractAction;
|
61 |
import javax.swing.AbstractAction;
|
40 |
import javax.swing.JComponent;
|
62 |
import javax.swing.JComponent;
|
- |
|
63 |
import javax.swing.JOptionPane;
|
41 |
import javax.swing.JTextField;
|
64 |
import javax.swing.JTextField;
|
42 |
|
65 |
|
43 |
public class EtatStockSQLElement extends ComptaSQLConfElement {
|
66 |
public class EtatStockSQLElement extends ComptaSQLConfElement {
|
44 |
|
67 |
|
45 |
public EtatStockSQLElement() {
|
68 |
public EtatStockSQLElement() {
|
Line 56... |
Line 79... |
56 |
}, true);
|
79 |
}, true);
|
57 |
action.setPredicate(IListeEvent.createSelectionCountPredicate(0, Integer.MAX_VALUE));
|
80 |
action.setPredicate(IListeEvent.createSelectionCountPredicate(0, Integer.MAX_VALUE));
|
58 |
getRowActions().add(action);
|
81 |
getRowActions().add(action);
|
59 |
}
|
82 |
}
|
60 |
{
|
83 |
{
|
61 |
PredicateRowAction action = new PredicateRowAction(new AbstractAction("Voir les articles") {
|
84 |
PredicateRowAction action = new PredicateRowAction(new AbstractAction("Import Inventaire") {
|
62 |
|
- |
|
63 |
@Override
|
85 |
@Override
|
64 |
public void actionPerformed(ActionEvent e) {
|
86 |
public void actionPerformed(ActionEvent e) {
|
- |
|
87 |
// PanelFrame frame = new PanelFrame(new
|
65 |
final SQLElement element = getDirectory().getElement("ETAT_STOCK_ELEMENT");
|
88 |
// ImportInventairePanel(getDirectory().getElement(DepotStockSQLElement.class)),
|
- |
|
89 |
// "Import inventaire");
|
- |
|
90 |
// FrameUtil.showPacked(frame);
|
- |
|
91 |
|
66 |
SQLTableModelSource source = element.createTableSource(new Where(element.getTable().getField("ID_ETAT_STOCK"), "=", IListe.get(e).getSelectedId()));
|
92 |
final Frame frame = SwingThreadUtils.getAncestorOrSelf(Frame.class, (Component) e.getSource());
|
67 |
final ListeViewPanel panel = new ListeViewPanel(element, new IListe(source));
|
93 |
final FileDialog fd = new FileDialog(frame, "Import Inventaire", FileDialog.LOAD);
|
- |
|
94 |
fd.setVisible(true);
|
- |
|
95 |
if (fd.getFile() != null) {
|
- |
|
96 |
final File f = new File(fd.getDirectory(), fd.getFile());
|
- |
|
97 |
if (!f.exists()) {
|
- |
|
98 |
JOptionPane.showMessageDialog(null, "Le ficher selectionné n'existe pas", "Erreur", JOptionPane.ERROR_MESSAGE);
|
- |
|
99 |
} else if (f.isDirectory()) {
|
- |
|
100 |
JOptionPane.showMessageDialog(null, "Le fichier selectionné n'est pas valide", "Erreur", JOptionPane.ERROR_MESSAGE);
|
- |
|
101 |
} else {
|
- |
|
102 |
new Thread(new Runnable() {
|
- |
|
103 |
|
- |
|
104 |
@Override
|
- |
|
105 |
public void run() {
|
- |
|
106 |
final InventaireFromEtatStockImporter impoter = new InventaireFromEtatStockImporter(getDirectory().getElement("ARTICLE"));
|
- |
|
107 |
try {
|
- |
|
108 |
SQLUtils.executeAtomic(getTable().getDBSystemRoot().getDataSource(), new ConnectionHandlerNoSetup<Object, IOException>() {
|
- |
|
109 |
@Override
|
- |
|
110 |
public Object handle(final SQLDataSource ds) throws SQLException, IOException {
|
- |
|
111 |
|
- |
|
112 |
impoter.importArticles(f, getTable().getDBRoot());
|
68 |
IListFrame frame = new IListFrame(panel);
|
113 |
return null;
|
- |
|
114 |
}
|
- |
|
115 |
});
|
- |
|
116 |
} catch (Exception e1) {
|
- |
|
117 |
ExceptionHandler.handle("Erreur lors de l'importation", e1);
|
- |
|
118 |
}
|
- |
|
119 |
|
- |
|
120 |
}
|
69 |
FrameUtil.show(frame);
|
121 |
}).start();
|
- |
|
122 |
}
|
- |
|
123 |
}
|
- |
|
124 |
|
70 |
}
|
125 |
}
|
71 |
}, true);
|
126 |
}, true);
|
72 |
action.setPredicate(IListeEvent.getSingleSelectionPredicate());
|
127 |
action.setPredicate(IListeEvent.createSelectionCountPredicate(0, Integer.MAX_VALUE));
|
73 |
getRowActions().add(action);
|
128 |
getRowActions().add(action);
|
74 |
}
|
129 |
}
|
75 |
|
130 |
|
76 |
{
|
131 |
{
|
77 |
PredicateRowAction action = new PredicateRowAction(new AbstractAction("Export pour inventaire") {
|
132 |
PredicateRowAction action = new PredicateRowAction(new AbstractAction("Export d'état pour inventaire") {
|
78 |
@Override
|
133 |
@Override
|
79 |
public void actionPerformed(ActionEvent e) {
|
134 |
public void actionPerformed(ActionEvent e) {
|
- |
|
135 |
|
80 |
EtatStockInventaireXmlSheet sheet = new EtatStockInventaireXmlSheet(IListe.get(e).getSelectedRow().asRow());
|
136 |
EtatStockInventaireXmlSheet sheet = new EtatStockInventaireXmlSheet(getDirectory(), SQLRow.getIDs(IListe.get(e).getSelectedRowAccessors()));
|
- |
|
137 |
|
81 |
try {
|
138 |
try {
|
82 |
sheet.createDocument();
|
139 |
sheet.createDocument();
|
83 |
sheet.showPrintAndExport(true, false, false, false, false, Collections.emptyList());
|
140 |
sheet.showPrintAndExport(true, false, false, false, false, Collections.emptyList());
|
84 |
} catch (Exception e1) {
|
141 |
} catch (Exception e1) {
|
85 |
ExceptionHandler.handle("Erreur lors de la création de l'inventaire", e1);
|
142 |
ExceptionHandler.handle("Erreur lors de la création de l'inventaire", e1);
|
86 |
}
|
143 |
}
|
87 |
}
|
144 |
}
|
88 |
}, true);
|
145 |
}, true);
|
89 |
action.setPredicate(IListeEvent.getSingleSelectionPredicate());
|
146 |
action.setPredicate(IListeEvent.getNonEmptySelectionPredicate());
|
90 |
getRowActions().add(action);
|
147 |
getRowActions().add(action);
|
91 |
}
|
148 |
}
|
92 |
|
149 |
|
93 |
{
|
150 |
{
|
94 |
PredicateRowAction action = new PredicateRowAction(new AbstractAction("Import Inventaire") {
|
151 |
PredicateRowAction action = new PredicateRowAction(new AbstractAction("Générer tous les états de stock") {
|
- |
|
152 |
|
95 |
@Override
|
153 |
@Override
|
96 |
public void actionPerformed(ActionEvent e) {
|
154 |
public void actionPerformed(ActionEvent e) {
|
- |
|
155 |
SQLSelect sel = new SQLSelect();
|
- |
|
156 |
|
- |
|
157 |
sel.addSelectStar(getTable().getForeignTable("ID_DEPOT_STOCK"));
|
- |
|
158 |
final List<SQLRow> rowsDepot = SQLRowListRSH.execute(sel);
|
- |
|
159 |
|
- |
|
160 |
Set<Number> idsEtat = new HashSet<>();
|
- |
|
161 |
for (SQLRow rowDepot : rowsDepot) {
|
- |
|
162 |
Date d = new Date();
|
97 |
PanelFrame frame = new PanelFrame(new ImportInventairePanel(getDirectory().getElement(DepotStockSQLElement.class)), "Import inventaire");
|
163 |
EtatStockSnapshotCreator creator = new EtatStockSnapshotCreator(rowDepot, d, getTable().getDBRoot(), false);
|
- |
|
164 |
|
- |
|
165 |
final int etat = creator.create();
|
- |
|
166 |
if (etat != SQLRow.NONEXISTANT_ID) {
|
98 |
FrameUtil.showPacked(frame);
|
167 |
idsEtat.add(etat);
|
- |
|
168 |
}
|
- |
|
169 |
}
|
- |
|
170 |
|
- |
|
171 |
if (!idsEtat.isEmpty()) {
|
- |
|
172 |
|
- |
|
173 |
EtatStockInventaireXmlSheet sheet = new EtatStockInventaireXmlSheet(getDirectory(), idsEtat);
|
- |
|
174 |
try {
|
- |
|
175 |
sheet.createDocument();
|
- |
|
176 |
sheet.showPrintAndExport(true, false, false, false, false, Collections.emptyList());
|
- |
|
177 |
} catch (Exception e1) {
|
- |
|
178 |
ExceptionHandler.handle("Erreur lors de la création de l'inventaire", e1);
|
- |
|
179 |
}
|
- |
|
180 |
}
|
- |
|
181 |
|
99 |
}
|
182 |
}
|
100 |
}, true);
|
183 |
}, true);
|
101 |
action.setPredicate(IListeEvent.createSelectionCountPredicate(0, Integer.MAX_VALUE));
|
184 |
action.setPredicate(IListeEvent.createSelectionCountPredicate(0, Integer.MAX_VALUE));
|
102 |
getRowActions().add(action);
|
185 |
getRowActions().add(action);
|
103 |
}
|
186 |
}
|
- |
|
187 |
|
- |
|
188 |
{
|
- |
|
189 |
PredicateRowAction action = new PredicateRowAction(new AbstractAction("Voir les articles") {
|
- |
|
190 |
|
- |
|
191 |
@Override
|
- |
|
192 |
public void actionPerformed(ActionEvent e) {
|
- |
|
193 |
final SQLElement element = getDirectory().getElement("ETAT_STOCK_ELEMENT");
|
- |
|
194 |
SQLTableModelSource source = element.createTableSource(new Where(element.getTable().getField("ID_ETAT_STOCK"), "=", IListe.get(e).getSelectedId()));
|
- |
|
195 |
final ListeViewPanel panel = new ListeViewPanel(element, new IListe(source));
|
- |
|
196 |
IListFrame frame = new IListFrame(panel);
|
- |
|
197 |
FrameUtil.show(frame);
|
- |
|
198 |
}
|
- |
|
199 |
}, true);
|
- |
|
200 |
action.setPredicate(IListeEvent.getSingleSelectionPredicate());
|
- |
|
201 |
getRowActions().add(action);
|
- |
|
202 |
}
|
- |
|
203 |
{
|
- |
|
204 |
PredicateRowAction action = new PredicateRowAction(new AbstractAction("Inventaire chiffré") {
|
- |
|
205 |
|
- |
|
206 |
@Override
|
- |
|
207 |
public void actionPerformed(ActionEvent e) {
|
- |
|
208 |
SQLRow r = IListe.get(e).getSelectedRow().fetchNewRow();
|
- |
|
209 |
try {
|
- |
|
210 |
String companyName = ComptaPropsConfiguration.getInstanceCompta().getRowSociete().getString("NOM");
|
- |
|
211 |
final Calendar date = r.getDate("DATE");
|
- |
|
212 |
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
|
- |
|
213 |
StockReportPDF pdf = new StockReportPDF(companyName, df.format(date.getTime()));
|
- |
|
214 |
pdf.addStockDepot(r);
|
- |
|
215 |
final File f = new File("out.pdf");
|
- |
|
216 |
pdf.savePDF(f);
|
- |
|
217 |
FileUtils.openFile(f);
|
- |
|
218 |
} catch (Exception ex) {
|
- |
|
219 |
ExceptionHandler.handle("Erreur", ex);
|
- |
|
220 |
}
|
- |
|
221 |
}
|
- |
|
222 |
}, true);
|
- |
|
223 |
action.setPredicate(IListeEvent.getSingleSelectionPredicate());
|
- |
|
224 |
getRowActions().add(action);
|
- |
|
225 |
}
|
104 |
}
|
226 |
}
|
105 |
|
227 |
|
106 |
@Override
|
228 |
@Override
|
107 |
protected List<String> getListFields() {
|
229 |
protected List<String> getListFields() {
|
108 |
final List<String> l = new ArrayList<>(3);
|
230 |
final List<String> l = new ArrayList<>(3);
|
109 |
l.add("DATE");
|
231 |
l.add("DATE");
|
- |
|
232 |
final SQLPreferences prefs = SQLPreferences.getMemCached(getTable().getDBRoot());
|
- |
|
233 |
final boolean hasDeclinaison = prefs.getBoolean(GestionArticleGlobalPreferencePanel.ACTIVER_DECLINAISON, false);
|
- |
|
234 |
if (hasDeclinaison) {
|
- |
|
235 |
l.add("ID_DEPOT_STOCK");
|
- |
|
236 |
}
|
- |
|
237 |
|
110 |
l.add("MONTANT_HA");
|
238 |
l.add("MONTANT_HA");
|
111 |
l.add("INVENTAIRE");
|
239 |
l.add("INVENTAIRE");
|
112 |
return l;
|
240 |
return l;
|
113 |
}
|
241 |
}
|
114 |
|
242 |
|