75 |
ilm |
1 |
/*
|
|
|
2 |
* Créé le 3 juin 2012
|
|
|
3 |
*/
|
|
|
4 |
package org.openconcerto.modules.project;
|
|
|
5 |
|
|
|
6 |
import java.awt.GridBagConstraints;
|
|
|
7 |
import java.awt.event.WindowAdapter;
|
|
|
8 |
import java.awt.event.WindowEvent;
|
|
|
9 |
import java.io.File;
|
|
|
10 |
import java.util.Arrays;
|
128 |
ilm |
11 |
import java.util.HashMap;
|
75 |
ilm |
12 |
import java.util.LinkedHashMap;
|
|
|
13 |
import java.util.List;
|
|
|
14 |
import java.util.Map;
|
|
|
15 |
|
|
|
16 |
import javax.swing.JFrame;
|
170 |
ilm |
17 |
import javax.swing.event.ListSelectionEvent;
|
|
|
18 |
import javax.swing.event.ListSelectionListener;
|
75 |
ilm |
19 |
import javax.swing.event.TableModelEvent;
|
|
|
20 |
import javax.swing.event.TableModelListener;
|
|
|
21 |
|
|
|
22 |
import org.openconcerto.erp.config.ComptaPropsConfiguration;
|
|
|
23 |
import org.openconcerto.erp.config.Gestion;
|
|
|
24 |
import org.openconcerto.erp.core.reports.history.ui.ListeHistoriquePanel;
|
170 |
ilm |
25 |
import org.openconcerto.modules.project.panel.HistoriqueAffaireBilanPanel;
|
75 |
ilm |
26 |
import org.openconcerto.sql.Configuration;
|
|
|
27 |
import org.openconcerto.sql.model.SQLBase;
|
170 |
ilm |
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;
|
75 |
ilm |
35 |
import org.openconcerto.sql.request.ComboSQLRequest;
|
|
|
36 |
import org.openconcerto.sql.view.IListPanel;
|
|
|
37 |
import org.openconcerto.ui.DefaultGridBagConstraints;
|
|
|
38 |
import org.openconcerto.ui.PanelFrame;
|
|
|
39 |
import org.openconcerto.ui.state.WindowStateManager;
|
170 |
ilm |
40 |
import org.openconcerto.utils.cc.ITransformer;
|
75 |
ilm |
41 |
|
|
|
42 |
public class ProjectHistory {
|
|
|
43 |
private PanelFrame panelFrame;
|
|
|
44 |
private ListeHistoriquePanel listPanel;
|
|
|
45 |
|
|
|
46 |
public ListeHistoriquePanel getHistoriquePanel() {
|
|
|
47 |
return this.listPanel;
|
|
|
48 |
}
|
|
|
49 |
|
128 |
ilm |
50 |
private static Map<String, List<String>> moduleTab = new HashMap<String, List<String>>();
|
|
|
51 |
|
|
|
52 |
public static void addTab(String tabName, List<String> table) {
|
|
|
53 |
moduleTab.put(tabName, table);
|
|
|
54 |
}
|
|
|
55 |
|
75 |
ilm |
56 |
public ProjectHistory() {
|
|
|
57 |
|
|
|
58 |
final ComptaPropsConfiguration comptaPropsConfiguration = ((ComptaPropsConfiguration) Configuration.getInstance());
|
|
|
59 |
final SQLBase b = comptaPropsConfiguration.getSQLBaseSociete();
|
|
|
60 |
|
|
|
61 |
final Map<String, List<String>> mapList = new LinkedHashMap<String, List<String>>();
|
|
|
62 |
mapList.put("Devis", Arrays.asList("DEVIS"));
|
|
|
63 |
mapList.put("Bons de commande", Arrays.asList("COMMANDE_CLIENT"));
|
170 |
ilm |
64 |
mapList.put("Chiffrage", Arrays.asList("CHIFFRAGE_COMMANDE_CLIENT"));
|
75 |
ilm |
65 |
mapList.put("Factures", Arrays.asList("SAISIE_VENTE_FACTURE"));
|
|
|
66 |
mapList.put("Avoirs", Arrays.asList("AVOIR_CLIENT"));
|
146 |
ilm |
67 |
mapList.put("Demandes d'achat", Arrays.asList("DEMANDE_ACHAT_ELEMENT"));
|
|
|
68 |
mapList.put("Demandes de prix", Arrays.asList("DEMANDE_PRIX"));
|
|
|
69 |
mapList.put("Commandes", Arrays.asList("COMMANDE"));
|
170 |
ilm |
70 |
mapList.put("Bons de réception", Arrays.asList("BON_RECEPTION"));
|
128 |
ilm |
71 |
mapList.put("Achats", Arrays.asList("SAISIE_ACHAT"));
|
170 |
ilm |
72 |
// mapList.put("Factures fournisseurs", Arrays.asList("FACTURE_FOURNISSEUR"));
|
|
|
73 |
mapList.put("Avoirs fournisseurs", Arrays.asList("AVOIR_FOURNISSEUR"));
|
75 |
ilm |
74 |
|
|
|
75 |
if (Configuration.getInstance().getRoot().findTable("AFFAIRE_TEMPS") != null) {
|
|
|
76 |
mapList.put("Temps", Arrays.asList("AFFAIRE_TEMPS"));
|
|
|
77 |
}
|
|
|
78 |
|
128 |
ilm |
79 |
mapList.putAll(moduleTab);
|
|
|
80 |
|
170 |
ilm |
81 |
final HistoriqueAffaireBilanPanel bilanPanel = new HistoriqueAffaireBilanPanel();
|
|
|
82 |
|
75 |
ilm |
83 |
final ComboSQLRequest request = new org.openconcerto.sql.request.ComboSQLRequest(b.getTable("AFFAIRE"), Arrays.asList("NUMERO", "ID_CLIENT"));
|
170 |
ilm |
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 |
}
|
75 |
ilm |
98 |
request.setUndefLabel("Toutes les affaires");
|
|
|
99 |
request.setFieldSeparator(" ");
|
170 |
ilm |
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"));
|
|
|
104 |
this.listPanel = new ListeHistoriquePanel("Affaires", request, mapList, bilanPanel, fieldLink, "Toutes les affaires", true, null, null, splitter);
|
75 |
ilm |
105 |
|
|
|
106 |
final IListPanel listeDevis = listPanel.getIListePanelFromTableName("DEVIS");
|
|
|
107 |
GridBagConstraints c = new DefaultGridBagConstraints();
|
|
|
108 |
c.gridy = 4;
|
|
|
109 |
c.fill = GridBagConstraints.BOTH;
|
|
|
110 |
final ProjectHistoryDevisBottomPanel devisPanel = new ProjectHistoryDevisBottomPanel();
|
|
|
111 |
listeDevis.add(devisPanel, c);
|
|
|
112 |
listeDevis.getListe().getTableModel().addTableModelListener(new TableModelListener() {
|
|
|
113 |
|
|
|
114 |
@Override
|
|
|
115 |
public void tableChanged(TableModelEvent e) {
|
|
|
116 |
devisPanel.updateDevis(listeDevis.getListe());
|
|
|
117 |
devisPanel.updateTimeDevis(listeDevis.getListe());
|
|
|
118 |
}
|
|
|
119 |
});
|
|
|
120 |
|
|
|
121 |
final IListPanel listeCmd = listPanel.getIListePanelFromTableName("COMMANDE_CLIENT");
|
|
|
122 |
final ProjectHistoryCmdBottomPanel cmdPanel = new ProjectHistoryCmdBottomPanel();
|
|
|
123 |
|
|
|
124 |
listeCmd.add(cmdPanel, c);
|
|
|
125 |
listeCmd.getListe().getTableModel().addTableModelListener(new TableModelListener() {
|
|
|
126 |
|
|
|
127 |
@Override
|
|
|
128 |
public void tableChanged(TableModelEvent e) {
|
|
|
129 |
cmdPanel.updateCmd(listeCmd.getListe());
|
|
|
130 |
cmdPanel.updateTimeCmd(listeCmd.getListe());
|
|
|
131 |
}
|
|
|
132 |
});
|
|
|
133 |
|
88 |
ilm |
134 |
// If time tracking is installed
|
75 |
ilm |
135 |
final IListPanel listeTemps = listPanel.getIListePanelFromTableName("AFFAIRE_TEMPS");
|
88 |
ilm |
136 |
if (listeTemps != null) {
|
|
|
137 |
final ProjectHistoryTimeBottomPanel timePanel = new ProjectHistoryTimeBottomPanel();
|
|
|
138 |
listeTemps.add(timePanel, c);
|
|
|
139 |
listeTemps.getListe().getTableModel().addTableModelListener(new TableModelListener() {
|
75 |
ilm |
140 |
|
88 |
ilm |
141 |
@Override
|
|
|
142 |
public void tableChanged(TableModelEvent e) {
|
|
|
143 |
timePanel.updateTime(listeTemps.getListe());
|
|
|
144 |
}
|
|
|
145 |
});
|
|
|
146 |
}
|
|
|
147 |
// History
|
75 |
ilm |
148 |
this.panelFrame = new PanelFrame(this.listPanel, "Historique affaires");
|
|
|
149 |
this.panelFrame.addWindowListener(new WindowAdapter() {
|
170 |
ilm |
150 |
|
75 |
ilm |
151 |
public void windowClosing(WindowEvent e) {
|
|
|
152 |
listPanel.removeAllTableListener();
|
|
|
153 |
};
|
170 |
ilm |
154 |
|
75 |
ilm |
155 |
});
|
|
|
156 |
|
|
|
157 |
this.panelFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
|
|
158 |
|
170 |
ilm |
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");
|
75 |
ilm |
239 |
}
|
|
|
240 |
|
|
|
241 |
public PanelFrame getFrame() {
|
|
|
242 |
this.panelFrame.setIconImages(Gestion.getFrameIcon());
|
146 |
ilm |
243 |
final WindowStateManager stateManager = new WindowStateManager(this.panelFrame,
|
|
|
244 |
new File(Configuration.getInstance().getConfDir(), "Configuration" + File.separator + "Frame" + File.separator + "HistoAffaires.xml"), true);
|
75 |
ilm |
245 |
this.panelFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
|
|
246 |
this.panelFrame.pack();
|
|
|
247 |
this.panelFrame.setLocationRelativeTo(null);
|
|
|
248 |
stateManager.loadState();
|
|
|
249 |
return this.panelFrame;
|
|
|
250 |
}
|
|
|
251 |
}
|