Line 1... |
Line 1... |
1 |
/*
|
1 |
/*
|
2 |
* Créé le 3 juin 2012
|
2 |
* Créé le 3 juin 2012
|
3 |
*/
|
3 |
*/
|
4 |
package org.openconcerto.modules.project;
|
4 |
package org.openconcerto.modules.project;
|
5 |
|
5 |
|
6 |
import java.awt.Component;
|
- |
|
7 |
import java.awt.FileDialog;
|
- |
|
8 |
import java.awt.Frame;
|
- |
|
9 |
import java.awt.GridBagConstraints;
|
6 |
import java.awt.GridBagConstraints;
|
10 |
import java.awt.event.ActionEvent;
|
- |
|
11 |
import java.awt.event.WindowAdapter;
|
7 |
import java.awt.event.WindowAdapter;
|
12 |
import java.awt.event.WindowEvent;
|
8 |
import java.awt.event.WindowEvent;
|
13 |
import java.io.File;
|
9 |
import java.io.File;
|
14 |
import java.io.FilenameFilter;
|
- |
|
15 |
import java.io.IOException;
|
- |
|
16 |
import java.sql.SQLException;
|
- |
|
17 |
import java.util.Arrays;
|
10 |
import java.util.Arrays;
|
18 |
import java.util.HashMap;
|
11 |
import java.util.HashMap;
|
19 |
import java.util.LinkedHashMap;
|
12 |
import java.util.LinkedHashMap;
|
20 |
import java.util.List;
|
13 |
import java.util.List;
|
21 |
import java.util.Map;
|
14 |
import java.util.Map;
|
22 |
|
15 |
|
23 |
import javax.swing.AbstractAction;
|
- |
|
24 |
import javax.swing.JFrame;
|
16 |
import javax.swing.JFrame;
|
25 |
import javax.swing.JOptionPane;
|
17 |
import javax.swing.event.ListSelectionEvent;
|
- |
|
18 |
import javax.swing.event.ListSelectionListener;
|
26 |
import javax.swing.event.TableModelEvent;
|
19 |
import javax.swing.event.TableModelEvent;
|
27 |
import javax.swing.event.TableModelListener;
|
20 |
import javax.swing.event.TableModelListener;
|
28 |
|
21 |
|
29 |
import org.openconcerto.erp.config.ComptaPropsConfiguration;
|
22 |
import org.openconcerto.erp.config.ComptaPropsConfiguration;
|
30 |
import org.openconcerto.erp.config.Gestion;
|
23 |
import org.openconcerto.erp.config.Gestion;
|
31 |
import org.openconcerto.erp.core.reports.history.ui.ListeHistoriquePanel;
|
24 |
import org.openconcerto.erp.core.reports.history.ui.ListeHistoriquePanel;
|
32 |
import org.openconcerto.erp.core.supplychain.order.action.ImportProductsToOrder;
|
25 |
import org.openconcerto.modules.project.panel.HistoriqueAffaireBilanPanel;
|
33 |
import org.openconcerto.sql.Configuration;
|
26 |
import org.openconcerto.sql.Configuration;
|
34 |
import org.openconcerto.sql.model.SQLBase;
|
27 |
import org.openconcerto.sql.model.SQLBase;
|
- |
|
28 |
import org.openconcerto.sql.model.SQLField;
|
- |
|
29 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
- |
|
30 |
import org.openconcerto.sql.model.SQLSelect;
|
- |
|
31 |
import org.openconcerto.sql.model.SQLTable;
|
- |
|
32 |
import org.openconcerto.sql.model.SQLTableEvent;
|
- |
|
33 |
import org.openconcerto.sql.model.SQLTableModifiedListener;
|
- |
|
34 |
import org.openconcerto.sql.model.Where;
|
35 |
import org.openconcerto.sql.request.ComboSQLRequest;
|
35 |
import org.openconcerto.sql.request.ComboSQLRequest;
|
36 |
import org.openconcerto.sql.view.IListPanel;
|
36 |
import org.openconcerto.sql.view.IListPanel;
|
37 |
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
|
- |
|
38 |
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
|
- |
|
39 |
import org.openconcerto.ui.DefaultGridBagConstraints;
|
37 |
import org.openconcerto.ui.DefaultGridBagConstraints;
|
40 |
import org.openconcerto.ui.PanelFrame;
|
38 |
import org.openconcerto.ui.PanelFrame;
|
41 |
import org.openconcerto.ui.SwingThreadUtils;
|
- |
|
42 |
import org.openconcerto.ui.state.WindowStateManager;
|
39 |
import org.openconcerto.ui.state.WindowStateManager;
|
- |
|
40 |
import org.openconcerto.utils.cc.ITransformer;
|
43 |
|
41 |
|
44 |
public class ProjectHistory {
|
42 |
public class ProjectHistory {
|
45 |
private PanelFrame panelFrame;
|
43 |
private PanelFrame panelFrame;
|
46 |
private ListeHistoriquePanel listPanel;
|
44 |
private ListeHistoriquePanel listPanel;
|
47 |
|
45 |
|
Line 61... |
Line 59... |
61 |
final SQLBase b = comptaPropsConfiguration.getSQLBaseSociete();
|
59 |
final SQLBase b = comptaPropsConfiguration.getSQLBaseSociete();
|
62 |
|
60 |
|
63 |
final Map<String, List<String>> mapList = new LinkedHashMap<String, List<String>>();
|
61 |
final Map<String, List<String>> mapList = new LinkedHashMap<String, List<String>>();
|
64 |
mapList.put("Devis", Arrays.asList("DEVIS"));
|
62 |
mapList.put("Devis", Arrays.asList("DEVIS"));
|
65 |
mapList.put("Bons de commande", Arrays.asList("COMMANDE_CLIENT"));
|
63 |
mapList.put("Bons de commande", Arrays.asList("COMMANDE_CLIENT"));
|
- |
|
64 |
mapList.put("Chiffrage", Arrays.asList("CHIFFRAGE_COMMANDE_CLIENT"));
|
66 |
mapList.put("Factures", Arrays.asList("SAISIE_VENTE_FACTURE"));
|
65 |
mapList.put("Factures", Arrays.asList("SAISIE_VENTE_FACTURE"));
|
67 |
mapList.put("Avoirs", Arrays.asList("AVOIR_CLIENT"));
|
66 |
mapList.put("Avoirs", Arrays.asList("AVOIR_CLIENT"));
|
68 |
mapList.put("Demandes d'achat", Arrays.asList("DEMANDE_ACHAT_ELEMENT"));
|
67 |
mapList.put("Demandes d'achat", Arrays.asList("DEMANDE_ACHAT_ELEMENT"));
|
69 |
mapList.put("Demandes de prix", Arrays.asList("DEMANDE_PRIX"));
|
68 |
mapList.put("Demandes de prix", Arrays.asList("DEMANDE_PRIX"));
|
70 |
mapList.put("Commandes", Arrays.asList("COMMANDE"));
|
69 |
mapList.put("Commandes", Arrays.asList("COMMANDE"));
|
- |
|
70 |
mapList.put("Bons de réception", Arrays.asList("BON_RECEPTION"));
|
71 |
mapList.put("Achats", Arrays.asList("SAISIE_ACHAT"));
|
71 |
mapList.put("Achats", Arrays.asList("SAISIE_ACHAT"));
|
- |
|
72 |
// mapList.put("Factures fournisseurs", Arrays.asList("FACTURE_FOURNISSEUR"));
|
- |
|
73 |
mapList.put("Avoirs fournisseurs", Arrays.asList("AVOIR_FOURNISSEUR"));
|
72 |
|
74 |
|
73 |
if (Configuration.getInstance().getRoot().findTable("AFFAIRE_TEMPS") != null) {
|
75 |
if (Configuration.getInstance().getRoot().findTable("AFFAIRE_TEMPS") != null) {
|
74 |
mapList.put("Temps", Arrays.asList("AFFAIRE_TEMPS"));
|
76 |
mapList.put("Temps", Arrays.asList("AFFAIRE_TEMPS"));
|
75 |
}
|
77 |
}
|
76 |
|
78 |
|
77 |
mapList.putAll(moduleTab);
|
79 |
mapList.putAll(moduleTab);
|
78 |
|
80 |
|
- |
|
81 |
final HistoriqueAffaireBilanPanel bilanPanel = new HistoriqueAffaireBilanPanel();
|
- |
|
82 |
|
79 |
final ComboSQLRequest request = new org.openconcerto.sql.request.ComboSQLRequest(b.getTable("AFFAIRE"), Arrays.asList("NUMERO", "ID_CLIENT"));
|
83 |
final ComboSQLRequest request = new org.openconcerto.sql.request.ComboSQLRequest(b.getTable("AFFAIRE"), Arrays.asList("NUMERO", "ID_CLIENT"));
|
- |
|
84 |
if (b.getTable("AFFAIRE").contains("ID_SOCIETE_COMMON")) {
|
- |
|
85 |
|
- |
|
86 |
final int socID = comptaPropsConfiguration.getSocieteID();
|
- |
|
87 |
request.setSelectTransf(new ITransformer<SQLSelect, SQLSelect>() {
|
- |
|
88 |
@Override
|
- |
|
89 |
public SQLSelect transformChecked(SQLSelect input) {
|
- |
|
90 |
Where w = new Where(b.getTable("AFFAIRE").getField("ID_SOCIETE_COMMON"), "=", (Object) null).or(new Where(b.getTable("AFFAIRE").getField("ID_SOCIETE_COMMON"), "=", 1))
|
- |
|
91 |
.or(new Where(b.getTable("AFFAIRE").getField("ID_SOCIETE_COMMON"), "=", socID));
|
- |
|
92 |
|
- |
|
93 |
input.andWhere(w);
|
- |
|
94 |
return input;
|
- |
|
95 |
}
|
- |
|
96 |
});
|
- |
|
97 |
}
|
80 |
request.setUndefLabel("Toutes les affaires");
|
98 |
request.setUndefLabel("Toutes les affaires");
|
81 |
request.setFieldSeparator(" ");
|
99 |
request.setFieldSeparator(" ");
|
82 |
|
- |
|
- |
|
100 |
Map<String, String> splitter = new HashMap<String, String>();
|
- |
|
101 |
splitter.put("DEMANDE_ACHAT_ELEMENT", "ID_FAMILLE_ARTICLE");
|
- |
|
102 |
Map<SQLTable, SQLField> fieldLink = new HashMap<SQLTable, SQLField>();
|
- |
|
103 |
fieldLink.put(b.getTable("CHIFFRAGE_COMMANDE_CLIENT"), b.getTable("CHIFFRAGE_COMMANDE_CLIENT").getField("ID_COMMANDE_CLIENT"));
|
83 |
this.listPanel = new ListeHistoriquePanel("Affaires", request, mapList, null, null, "Toutes les affaires", true, null, null);
|
104 |
this.listPanel = new ListeHistoriquePanel("Affaires", request, mapList, bilanPanel, fieldLink, "Toutes les affaires", true, null, null, splitter);
|
84 |
|
105 |
|
85 |
final IListPanel listeDevis = listPanel.getIListePanelFromTableName("DEVIS");
|
106 |
final IListPanel listeDevis = listPanel.getIListePanelFromTableName("DEVIS");
|
86 |
GridBagConstraints c = new DefaultGridBagConstraints();
|
107 |
GridBagConstraints c = new DefaultGridBagConstraints();
|
87 |
c.gridy = 4;
|
108 |
c.gridy = 4;
|
88 |
c.fill = GridBagConstraints.BOTH;
|
109 |
c.fill = GridBagConstraints.BOTH;
|
Line 95... |
Line 116... |
95 |
devisPanel.updateDevis(listeDevis.getListe());
|
116 |
devisPanel.updateDevis(listeDevis.getListe());
|
96 |
devisPanel.updateTimeDevis(listeDevis.getListe());
|
117 |
devisPanel.updateTimeDevis(listeDevis.getListe());
|
97 |
}
|
118 |
}
|
98 |
});
|
119 |
});
|
99 |
|
120 |
|
100 |
final IListPanel listeDmdAchat = listPanel.getIListePanelFromTableName("DEMANDE_ACHAT_ELEMENT");
|
- |
|
101 |
PredicateRowAction actionDrop = new PredicateRowAction(new AbstractAction("Importer depuis Fichier Inventor") {
|
- |
|
102 |
|
- |
|
103 |
@Override
|
- |
|
104 |
public void actionPerformed(ActionEvent e) {
|
- |
|
105 |
final Frame frame = SwingThreadUtils.getAncestorOrSelf(Frame.class, (Component) e.getSource());
|
- |
|
106 |
final FileDialog fd = new FileDialog(frame, "Import fichier inventor", FileDialog.LOAD);
|
- |
|
107 |
fd.setFilenameFilter(new FilenameFilter() {
|
- |
|
108 |
@Override
|
- |
|
109 |
public boolean accept(File dir, String name) {
|
- |
|
110 |
return name.endsWith(".xls");
|
- |
|
111 |
}
|
- |
|
112 |
});
|
- |
|
113 |
fd.setVisible(true);
|
- |
|
114 |
if (fd.getFile() != null) {
|
- |
|
115 |
|
- |
|
116 |
ImportProductsToOrder importer = new ImportProductsToOrder();
|
- |
|
117 |
|
- |
|
118 |
int a = JOptionPane.showConfirmDialog(frame, "Etes vous sûr de vouloir importer ces éléments dans l'affaire N°" + listPanel.getSelectedRow().getString("NUMERO") + "?",
|
- |
|
119 |
"Import invertor", JOptionPane.YES_NO_OPTION);
|
- |
|
120 |
if (a == JOptionPane.YES_OPTION) {
|
- |
|
121 |
importer.setRowAffaire(listPanel.getSelectedRow());
|
- |
|
122 |
try {
|
- |
|
123 |
importer.importFile(new File(fd.getDirectory(), fd.getFile()), b.getTable("DEMANDE_ACHAT_ELEMENT").getDBRoot());
|
- |
|
124 |
listeDmdAchat.getListe().getModel().updateAll();
|
- |
|
125 |
} catch (IOException e1) {
|
- |
|
126 |
org.openconcerto.utils.ExceptionHandler.handle("Erreur lors de l'import du fichier!", e1);
|
- |
|
127 |
} catch (SQLException e1) {
|
- |
|
128 |
org.openconcerto.utils.ExceptionHandler.handle("Erreur lors de l'import du fichier!", e1);
|
- |
|
129 |
}
|
- |
|
130 |
}
|
- |
|
131 |
}
|
- |
|
132 |
}
|
- |
|
133 |
}, true);
|
- |
|
134 |
actionDrop.setPredicate(IListeEvent.createSelectionCountPredicate(0, Integer.MAX_VALUE));
|
- |
|
135 |
listeDmdAchat.getListe().addIListeAction(actionDrop);
|
- |
|
136 |
|
- |
|
137 |
final IListPanel listeCmd = listPanel.getIListePanelFromTableName("COMMANDE_CLIENT");
|
121 |
final IListPanel listeCmd = listPanel.getIListePanelFromTableName("COMMANDE_CLIENT");
|
138 |
final ProjectHistoryCmdBottomPanel cmdPanel = new ProjectHistoryCmdBottomPanel();
|
122 |
final ProjectHistoryCmdBottomPanel cmdPanel = new ProjectHistoryCmdBottomPanel();
|
139 |
|
123 |
|
140 |
listeCmd.add(cmdPanel, c);
|
124 |
listeCmd.add(cmdPanel, c);
|
141 |
listeCmd.getListe().getTableModel().addTableModelListener(new TableModelListener() {
|
125 |
listeCmd.getListe().getTableModel().addTableModelListener(new TableModelListener() {
|
Line 161... |
Line 145... |
161 |
});
|
145 |
});
|
162 |
}
|
146 |
}
|
163 |
// History
|
147 |
// History
|
164 |
this.panelFrame = new PanelFrame(this.listPanel, "Historique affaires");
|
148 |
this.panelFrame = new PanelFrame(this.listPanel, "Historique affaires");
|
165 |
this.panelFrame.addWindowListener(new WindowAdapter() {
|
149 |
this.panelFrame.addWindowListener(new WindowAdapter() {
|
- |
|
150 |
|
166 |
public void windowClosing(WindowEvent e) {
|
151 |
public void windowClosing(WindowEvent e) {
|
167 |
listPanel.removeAllTableListener();
|
152 |
listPanel.removeAllTableListener();
|
168 |
};
|
153 |
};
|
- |
|
154 |
|
169 |
});
|
155 |
});
|
170 |
|
156 |
|
171 |
this.panelFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
157 |
this.panelFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
172 |
|
158 |
|
- |
|
159 |
final SQLTableModifiedListener cmdClientListener = new SQLTableModifiedListener() {
|
- |
|
160 |
|
- |
|
161 |
@Override
|
- |
|
162 |
public void tableModified(SQLTableEvent evt) {
|
- |
|
163 |
if (bilanPanel != null) {
|
- |
|
164 |
final SQLRowAccessor selectedRow = ProjectHistory.this.listPanel.getSelectedRow();
|
- |
|
165 |
if (selectedRow != null) {
|
- |
|
166 |
bilanPanel.updateCommandeClient(selectedRow.asRow());
|
- |
|
167 |
}
|
- |
|
168 |
}
|
- |
|
169 |
}
|
- |
|
170 |
};
|
- |
|
171 |
final SQLTableModifiedListener devisListener = new SQLTableModifiedListener() {
|
- |
|
172 |
|
- |
|
173 |
@Override
|
- |
|
174 |
public void tableModified(SQLTableEvent evt) {
|
- |
|
175 |
if (bilanPanel != null) {
|
- |
|
176 |
final SQLRowAccessor selectedRow = ProjectHistory.this.listPanel.getSelectedRow();
|
- |
|
177 |
if (selectedRow != null) {
|
- |
|
178 |
bilanPanel.updateDevis(selectedRow.asRow());
|
- |
|
179 |
}
|
- |
|
180 |
}
|
- |
|
181 |
}
|
- |
|
182 |
};
|
- |
|
183 |
this.panelFrame.addWindowListener(new WindowAdapter() {
|
- |
|
184 |
public void windowClosing(WindowEvent e) {
|
- |
|
185 |
listPanel.removeAllTableListener();
|
- |
|
186 |
b.getTable("COMMANDE_CLIENT").removeTableModifiedListener(cmdClientListener);
|
- |
|
187 |
b.getTable("DEVIS").removeTableModifiedListener(devisListener);
|
- |
|
188 |
};
|
- |
|
189 |
});
|
- |
|
190 |
|
- |
|
191 |
b.getTable("COMMANDE_CLIENT").addTableModifiedListener(cmdClientListener);
|
- |
|
192 |
b.getTable("DEVIS").addTableModifiedListener(devisListener);
|
- |
|
193 |
|
- |
|
194 |
this.listPanel.addListSelectionListener(new ListSelectionListener() {
|
- |
|
195 |
|
- |
|
196 |
@Override
|
- |
|
197 |
public void valueChanged(ListSelectionEvent arg0) {
|
- |
|
198 |
|
- |
|
199 |
final SQLRowAccessor selectedRow = ProjectHistory.this.listPanel.getSelectedRow();
|
- |
|
200 |
if (selectedRow != null) {
|
- |
|
201 |
bilanPanel.updateCommandeClient(selectedRow.asRow());
|
- |
|
202 |
bilanPanel.updateDevis(selectedRow.asRow());
|
- |
|
203 |
bilanPanel.updateBilanPreBilan(ProjectHistory.this.listPanel.getIListeFromTableName("COMMANDE"));
|
- |
|
204 |
}
|
- |
|
205 |
}
|
- |
|
206 |
});
|
- |
|
207 |
|
- |
|
208 |
this.listPanel.addListenerTable(new TableModelListener() {
|
- |
|
209 |
public void tableChanged(TableModelEvent arg0) {
|
- |
|
210 |
final SQLRowAccessor selectedRow = ProjectHistory.this.listPanel.getSelectedRow();
|
- |
|
211 |
if (selectedRow != null) {
|
- |
|
212 |
bilanPanel.updateBilanPreBilan(ProjectHistory.this.listPanel.getIListeFromTableName("COMMANDE"));
|
- |
|
213 |
}
|
- |
|
214 |
}
|
- |
|
215 |
}, "COMMANDE");
|
- |
|
216 |
|
- |
|
217 |
this.listPanel.addListenerTable(new TableModelListener() {
|
- |
|
218 |
public void tableChanged(TableModelEvent arg0) {
|
- |
|
219 |
bilanPanel.updateAchat(ProjectHistory.this.listPanel.getIListeFromTableName("SAISIE_ACHAT"), ProjectHistory.this.listPanel.getIListeFromTableName("AVOIR_FOURNISSEUR"));
|
- |
|
220 |
}
|
- |
|
221 |
}, "SAISIE_ACHAT");
|
- |
|
222 |
this.listPanel.addListenerTable(new TableModelListener() {
|
- |
|
223 |
public void tableChanged(TableModelEvent arg0) {
|
- |
|
224 |
bilanPanel.updateAchat(ProjectHistory.this.listPanel.getIListeFromTableName("SAISIE_ACHAT"), ProjectHistory.this.listPanel.getIListeFromTableName("AVOIR_FOURNISSEUR"));
|
- |
|
225 |
}
|
- |
|
226 |
}, "AVOIR_FOURNISSEUR");
|
- |
|
227 |
|
- |
|
228 |
this.listPanel.addListenerTable(new TableModelListener() {
|
- |
|
229 |
public void tableChanged(TableModelEvent arg0) {
|
- |
|
230 |
bilanPanel.updateFacturer(ProjectHistory.this.listPanel.getIListeFromTableName("SAISIE_VENTE_FACTURE"), ProjectHistory.this.listPanel.getIListeFromTableName("AVOIR_CLIENT"));
|
- |
|
231 |
}
|
- |
|
232 |
}, "SAISIE_VENTE_FACTURE");
|
- |
|
233 |
|
- |
|
234 |
this.listPanel.addListenerTable(new TableModelListener() {
|
- |
|
235 |
public void tableChanged(TableModelEvent arg0) {
|
- |
|
236 |
bilanPanel.updateFacturer(ProjectHistory.this.listPanel.getIListeFromTableName("SAISIE_VENTE_FACTURE"), ProjectHistory.this.listPanel.getIListeFromTableName("AVOIR_CLIENT"));
|
- |
|
237 |
}
|
- |
|
238 |
}, "AVOIR_CLIENT");
|
173 |
}
|
239 |
}
|
174 |
|
240 |
|
175 |
public PanelFrame getFrame() {
|
241 |
public PanelFrame getFrame() {
|
176 |
this.panelFrame.setIconImages(Gestion.getFrameIcon());
|
242 |
this.panelFrame.setIconImages(Gestion.getFrameIcon());
|
177 |
final WindowStateManager stateManager = new WindowStateManager(this.panelFrame,
|
243 |
final WindowStateManager stateManager = new WindowStateManager(this.panelFrame,
|