30 |
ilm |
1 |
package org.openconcerto.modules.customerrelationship.lead;
|
|
|
2 |
|
140 |
ilm |
3 |
import java.awt.Component;
|
|
|
4 |
import java.awt.FileDialog;
|
|
|
5 |
import java.awt.Frame;
|
|
|
6 |
import java.awt.event.ActionEvent;
|
30 |
ilm |
7 |
import java.io.File;
|
140 |
ilm |
8 |
import java.io.FilenameFilter;
|
30 |
ilm |
9 |
import java.io.IOException;
|
140 |
ilm |
10 |
import java.sql.SQLException;
|
30 |
ilm |
11 |
|
140 |
ilm |
12 |
import javax.swing.AbstractAction;
|
|
|
13 |
import javax.swing.JFrame;
|
|
|
14 |
|
|
|
15 |
import org.openconcerto.erp.action.CreateFrameAbstractAction;
|
|
|
16 |
import org.openconcerto.erp.config.ComptaPropsConfiguration;
|
30 |
ilm |
17 |
import org.openconcerto.erp.config.Gestion;
|
|
|
18 |
import org.openconcerto.erp.config.MainFrame;
|
|
|
19 |
import org.openconcerto.erp.modules.AbstractModule;
|
|
|
20 |
import org.openconcerto.erp.modules.ComponentsContext;
|
|
|
21 |
import org.openconcerto.erp.modules.DBContext;
|
77 |
ilm |
22 |
import org.openconcerto.erp.modules.MenuContext;
|
30 |
ilm |
23 |
import org.openconcerto.erp.modules.ModuleFactory;
|
|
|
24 |
import org.openconcerto.erp.modules.ModuleManager;
|
|
|
25 |
import org.openconcerto.erp.modules.ModulePackager;
|
|
|
26 |
import org.openconcerto.erp.modules.RuntimeModuleFactory;
|
140 |
ilm |
27 |
import org.openconcerto.modules.customerrelationship.lead.call.CustomerCallSQLElement;
|
|
|
28 |
import org.openconcerto.modules.customerrelationship.lead.call.CustomerCallServiceSQLElement;
|
|
|
29 |
import org.openconcerto.modules.customerrelationship.lead.call.LeadCallSQLElement;
|
|
|
30 |
import org.openconcerto.modules.customerrelationship.lead.call.LeadCallServiceSQLElement;
|
|
|
31 |
import org.openconcerto.modules.customerrelationship.lead.importer.LeadImporter;
|
|
|
32 |
import org.openconcerto.modules.customerrelationship.lead.visit.CustomerVisitSQLElement;
|
|
|
33 |
import org.openconcerto.modules.customerrelationship.lead.visit.CustomerVisitServiceSQLElement;
|
|
|
34 |
import org.openconcerto.modules.customerrelationship.lead.visit.LeadVisitSQLElement;
|
|
|
35 |
import org.openconcerto.modules.customerrelationship.lead.visit.LeadVisitServiceSQLElement;
|
|
|
36 |
import org.openconcerto.openoffice.ContentTypeVersioned;
|
30 |
ilm |
37 |
import org.openconcerto.sql.element.GlobalMapper;
|
140 |
ilm |
38 |
import org.openconcerto.sql.element.SQLElement;
|
30 |
ilm |
39 |
import org.openconcerto.sql.element.SQLElementDirectory;
|
140 |
ilm |
40 |
import org.openconcerto.sql.model.ConnectionHandlerNoSetup;
|
|
|
41 |
import org.openconcerto.sql.model.DBRoot;
|
|
|
42 |
import org.openconcerto.sql.model.SQLDataSource;
|
30 |
ilm |
43 |
import org.openconcerto.sql.model.SQLRequestLog;
|
140 |
ilm |
44 |
import org.openconcerto.sql.model.SQLRow;
|
|
|
45 |
import org.openconcerto.sql.model.SQLRowValues;
|
|
|
46 |
import org.openconcerto.sql.model.SQLTable;
|
30 |
ilm |
47 |
import org.openconcerto.sql.ui.ConnexionPanel;
|
|
|
48 |
import org.openconcerto.sql.utils.SQLCreateTable;
|
140 |
ilm |
49 |
import org.openconcerto.sql.utils.SQLUtils;
|
|
|
50 |
import org.openconcerto.sql.view.EditFrame;
|
|
|
51 |
import org.openconcerto.sql.view.ListeAddPanel;
|
|
|
52 |
import org.openconcerto.sql.view.list.IListe;
|
|
|
53 |
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
|
|
|
54 |
import org.openconcerto.sql.view.list.RowAction;
|
|
|
55 |
import org.openconcerto.ui.FrameUtil;
|
|
|
56 |
import org.openconcerto.ui.SwingThreadUtils;
|
|
|
57 |
import org.openconcerto.utils.ExceptionHandler;
|
30 |
ilm |
58 |
|
|
|
59 |
public final class Module extends AbstractModule {
|
|
|
60 |
|
|
|
61 |
public static final String TABLE_LEAD = "LEAD";
|
140 |
ilm |
62 |
public static final String TABLE_LEAD_CALL = "LEAD_CALL";
|
|
|
63 |
public static final String TABLE_CUSTOMER_CALL = "CUSTOMER_CALL";
|
|
|
64 |
public static final String TABLE_LEAD_VISIT = "LEAD_VISIT";
|
|
|
65 |
public static final String TABLE_CUSTOMER_VISIT = "CUSTOMER_VISIT";
|
|
|
66 |
public static final String TABLE_SERVICE = "SERVICE";
|
|
|
67 |
//
|
|
|
68 |
public static final String TABLE_LEAD_CALL_SERVICE = "LEAD_CALL_SERVICE";
|
|
|
69 |
public static final String TABLE_CUSTOMER_CALL_SERVICE = "CUSTOMER_CALL_SERVICE";
|
|
|
70 |
public static final String TABLE_LEAD_VISIT_SERVICE = "LEAD_VISIT_SERVICE";
|
|
|
71 |
public static final String TABLE_CUSTOMER_VISIT_SERVICE = "CUSTOMER_VISIT_SERVICE";
|
30 |
ilm |
72 |
|
|
|
73 |
public Module(ModuleFactory f) throws IOException {
|
|
|
74 |
super(f);
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
@Override
|
154 |
ilm |
78 |
protected void install(DBContext ctxt) throws SQLException, IOException {
|
30 |
ilm |
79 |
super.install(ctxt);
|
|
|
80 |
// TODO use version to upgrade
|
77 |
ilm |
81 |
if (ctxt.getRoot().getTable(TABLE_LEAD) == null) {
|
30 |
ilm |
82 |
final SQLCreateTable createTable = ctxt.getCreateTable(TABLE_LEAD);
|
|
|
83 |
|
|
|
84 |
createTable.addVarCharColumn("NUMBER", 20);
|
|
|
85 |
createTable.addDateAndTimeColumn("DATE");
|
|
|
86 |
createTable.addVarCharColumn("FIRSTNAME", 64);
|
|
|
87 |
createTable.addVarCharColumn("NAME", 64);
|
|
|
88 |
createTable.addVarCharColumn("COMPANY", 64);
|
|
|
89 |
//
|
|
|
90 |
createTable.addVarCharColumn("PHONE", 16);
|
|
|
91 |
createTable.addVarCharColumn("MOBILE", 16);
|
|
|
92 |
createTable.addVarCharColumn("FAX", 16);
|
|
|
93 |
createTable.addVarCharColumn("EMAIL", 32);
|
|
|
94 |
createTable.addVarCharColumn("WEBSITE", 64);
|
|
|
95 |
//
|
|
|
96 |
createTable.addVarCharColumn("SOURCE", 200);
|
|
|
97 |
createTable.addVarCharColumn("STATUS", 50);
|
|
|
98 |
//
|
|
|
99 |
createTable.addForeignColumn("ADRESSE");
|
|
|
100 |
createTable.addForeignColumn("COMMERCIAL");
|
|
|
101 |
//
|
|
|
102 |
createTable.addVarCharColumn("INFORMATION", 512);
|
|
|
103 |
//
|
|
|
104 |
createTable.addVarCharColumn("INDUSTRY", 200);
|
|
|
105 |
createTable.addVarCharColumn("RATING", 200);
|
|
|
106 |
|
|
|
107 |
createTable.addIntegerColumn("REVENUE", 0);
|
|
|
108 |
createTable.addIntegerColumn("EMPLOYEES", 0);
|
|
|
109 |
|
140 |
ilm |
110 |
createTable.addVarCharColumn("ROLE", 128);
|
|
|
111 |
createTable.addForeignColumn("CLIENT");
|
|
|
112 |
createTable.addVarCharColumn("LOCALISATION", 256);
|
|
|
113 |
createTable.addVarCharColumn("INFOS", 128);
|
|
|
114 |
createTable.addForeignColumn("TITRE_PERSONNEL");
|
|
|
115 |
createTable.addDateAndTimeColumn("REMIND_DATE");
|
|
|
116 |
createTable.addVarCharColumn("APE", 128);
|
|
|
117 |
createTable.addVarCharColumn("SIRET", 256);
|
|
|
118 |
createTable.addVarCharColumn("DISPO", 256);
|
|
|
119 |
createTable.addBooleanColumn("MAILING", Boolean.FALSE, false);
|
|
|
120 |
|
|
|
121 |
// V2
|
|
|
122 |
|
|
|
123 |
// Appel à un prospect
|
|
|
124 |
final SQLCreateTable createLCall = ctxt.getCreateTable(TABLE_LEAD_CALL);
|
|
|
125 |
createLCall.addDateAndTimeColumn("DATE");
|
|
|
126 |
createLCall.addForeignColumn(createTable);
|
|
|
127 |
createLCall.addVarCharColumn("INFORMATION", 10240);
|
|
|
128 |
createLCall.addDateAndTimeColumn("NEXTCONTACT_DATE");
|
|
|
129 |
createLCall.addVarCharColumn("NEXTCONTACT_INFO", 1024);
|
|
|
130 |
|
|
|
131 |
// Appel à un client
|
|
|
132 |
final SQLCreateTable createCCall = ctxt.getCreateTable(TABLE_CUSTOMER_CALL);
|
|
|
133 |
createCCall.addDateAndTimeColumn("DATE");
|
|
|
134 |
createCCall.addForeignColumn("CLIENT");
|
|
|
135 |
createCCall.addVarCharColumn("INFORMATION", 10240);
|
|
|
136 |
createCCall.addDateAndTimeColumn("NEXTCONTACT_DATE");
|
|
|
137 |
createCCall.addVarCharColumn("NEXTCONTACT_INFO", 1024);
|
|
|
138 |
|
|
|
139 |
// Visites chez un prospect
|
|
|
140 |
final SQLCreateTable createLV = ctxt.getCreateTable(TABLE_LEAD_VISIT);
|
|
|
141 |
createLV.addDateAndTimeColumn("DATE");
|
|
|
142 |
createLV.addForeignColumn(createTable);
|
|
|
143 |
createLV.addVarCharColumn("INFORMATION", 10240);
|
|
|
144 |
createLV.addDateAndTimeColumn("NEXTCONTACT_DATE");
|
|
|
145 |
createLV.addVarCharColumn("NEXTCONTACT_INFO", 1024);
|
|
|
146 |
// Visites chez un client
|
|
|
147 |
final SQLCreateTable createCV = ctxt.getCreateTable(TABLE_CUSTOMER_VISIT);
|
|
|
148 |
createCV.addDateAndTimeColumn("DATE");
|
|
|
149 |
createCV.addForeignColumn("CLIENT");
|
|
|
150 |
createCV.addVarCharColumn("INFORMATION", 10240);
|
|
|
151 |
createCV.addDateAndTimeColumn("NEXTCONTACT_DATE");
|
|
|
152 |
createCV.addVarCharColumn("NEXTCONTACT_INFO", 1024);
|
|
|
153 |
|
|
|
154 |
// Services
|
|
|
155 |
final SQLCreateTable createService = ctxt.getCreateTable(TABLE_SERVICE);
|
|
|
156 |
createService.addVarCharColumn("NAME", 256);
|
|
|
157 |
|
|
|
158 |
//
|
|
|
159 |
if (ctxt.getRoot().getTable(TABLE_LEAD_CALL_SERVICE) == null) {
|
|
|
160 |
final SQLCreateTable createTable1 = ctxt.getCreateTable(TABLE_LEAD_CALL_SERVICE);
|
|
|
161 |
createTable1.addForeignColumn(createLCall);
|
|
|
162 |
createTable1.addForeignColumn(createService);
|
|
|
163 |
}
|
|
|
164 |
if (ctxt.getRoot().getTable(TABLE_CUSTOMER_CALL_SERVICE) == null) {
|
|
|
165 |
final SQLCreateTable createTable1 = ctxt.getCreateTable(TABLE_CUSTOMER_CALL_SERVICE);
|
|
|
166 |
createTable1.addForeignColumn(createCCall);
|
|
|
167 |
createTable1.addForeignColumn(createService);
|
|
|
168 |
}
|
|
|
169 |
if (ctxt.getRoot().getTable(TABLE_LEAD_VISIT_SERVICE) == null) {
|
|
|
170 |
final SQLCreateTable createTable1 = ctxt.getCreateTable(TABLE_LEAD_VISIT_SERVICE);
|
|
|
171 |
createTable1.addForeignColumn(createLV);
|
|
|
172 |
createTable1.addForeignColumn(createService);
|
|
|
173 |
}
|
|
|
174 |
if (ctxt.getRoot().getTable(TABLE_CUSTOMER_VISIT_SERVICE) == null) {
|
|
|
175 |
final SQLCreateTable createTable1 = ctxt.getCreateTable(TABLE_CUSTOMER_VISIT_SERVICE);
|
|
|
176 |
createTable1.addForeignColumn(createCV);
|
|
|
177 |
createTable1.addForeignColumn(createService);
|
|
|
178 |
}
|
30 |
ilm |
179 |
}
|
|
|
180 |
}
|
|
|
181 |
|
|
|
182 |
@Override
|
140 |
ilm |
183 |
protected void setupElements(final SQLElementDirectory dir) {
|
30 |
ilm |
184 |
super.setupElements(dir);
|
140 |
ilm |
185 |
|
87 |
ilm |
186 |
final LeadSQLElement element = new LeadSQLElement(this);
|
|
|
187 |
GlobalMapper.getInstance().map(element.getCode() + ".default", new LeadGroup());
|
30 |
ilm |
188 |
dir.addSQLElement(element);
|
140 |
ilm |
189 |
|
|
|
190 |
dir.addSQLElement(new LeadCallSQLElement(this));
|
|
|
191 |
dir.addSQLElement(new CustomerCallSQLElement(this));
|
|
|
192 |
dir.addSQLElement(new LeadVisitSQLElement(this));
|
|
|
193 |
dir.addSQLElement(new CustomerVisitSQLElement(this));
|
|
|
194 |
dir.addSQLElement(new ServiceSQLElement(this));
|
|
|
195 |
// Services
|
|
|
196 |
dir.addSQLElement(new LeadCallServiceSQLElement(this));
|
|
|
197 |
dir.addSQLElement(new CustomerCallServiceSQLElement(this));
|
|
|
198 |
dir.addSQLElement(new LeadVisitServiceSQLElement(this));
|
|
|
199 |
dir.addSQLElement(new CustomerVisitServiceSQLElement(this));
|
|
|
200 |
|
|
|
201 |
// Call
|
|
|
202 |
final RowAction.PredicateRowAction addCallAction = new RowAction.PredicateRowAction(new AbstractAction("Appeler") {
|
|
|
203 |
|
|
|
204 |
@Override
|
|
|
205 |
public void actionPerformed(ActionEvent e) {
|
|
|
206 |
SQLRow sRow = IListe.get(e).getSelectedRow().asRow();
|
|
|
207 |
final SQLElement eCall = dir.getElement(Module.TABLE_CUSTOMER_CALL);
|
|
|
208 |
final SQLTable table = eCall.getTable();
|
|
|
209 |
EditFrame editFrame = new EditFrame(eCall);
|
|
|
210 |
final SQLRowValues sqlRowValues = new SQLRowValues(table);
|
|
|
211 |
sqlRowValues.put("ID_CLIENT", sRow.getIDNumber());
|
|
|
212 |
editFrame.getSQLComponent().select(sqlRowValues);
|
|
|
213 |
FrameUtil.show(editFrame);
|
|
|
214 |
}
|
|
|
215 |
}, true) {
|
|
|
216 |
};
|
|
|
217 |
addCallAction.setPredicate(IListeEvent.getSingleSelectionPredicate());
|
|
|
218 |
dir.getElement("CLIENT").getRowActions().add(addCallAction);
|
|
|
219 |
// Visit
|
|
|
220 |
final RowAction.PredicateRowAction addVisitAction = new RowAction.PredicateRowAction(new AbstractAction("Enregister une visite") {
|
|
|
221 |
|
|
|
222 |
@Override
|
|
|
223 |
public void actionPerformed(ActionEvent e) {
|
|
|
224 |
SQLRow sRow = IListe.get(e).getSelectedRow().asRow();
|
|
|
225 |
final SQLElement eCall = dir.getElement(Module.TABLE_CUSTOMER_VISIT);
|
|
|
226 |
final SQLTable table = eCall.getTable();
|
|
|
227 |
EditFrame editFrame = new EditFrame(eCall);
|
|
|
228 |
final SQLRowValues sqlRowValues = new SQLRowValues(table);
|
|
|
229 |
sqlRowValues.put("ID_CLIENT", sRow.getIDNumber());
|
|
|
230 |
editFrame.getSQLComponent().select(sqlRowValues);
|
|
|
231 |
FrameUtil.show(editFrame);
|
|
|
232 |
}
|
|
|
233 |
}, true) {
|
|
|
234 |
};
|
|
|
235 |
addVisitAction.setPredicate(IListeEvent.getSingleSelectionPredicate());
|
|
|
236 |
dir.getElement("CLIENT").getRowActions().add(addVisitAction);
|
|
|
237 |
|
30 |
ilm |
238 |
}
|
|
|
239 |
|
|
|
240 |
@Override
|
|
|
241 |
protected void setupComponents(ComponentsContext ctxt) {
|
77 |
ilm |
242 |
|
|
|
243 |
}
|
|
|
244 |
|
|
|
245 |
@Override
|
140 |
ilm |
246 |
protected void setupMenu(final MenuContext ctxt) {
|
|
|
247 |
ctxt.addMenuItem(new LeadListAction(), MainFrame.LIST_MENU);
|
|
|
248 |
|
|
|
249 |
ctxt.addMenuItem(new CreateFrameAbstractAction("Liste des services") {
|
|
|
250 |
@Override
|
|
|
251 |
public JFrame createFrame() {
|
|
|
252 |
final JFrame frame = new JFrame("Services proposés");
|
|
|
253 |
frame.setContentPane(new ListeAddPanel(ctxt.getElement(TABLE_SERVICE)));
|
|
|
254 |
return frame;
|
|
|
255 |
}
|
|
|
256 |
}, MainFrame.STRUCTURE_MENU);
|
|
|
257 |
ctxt.addMenuItem(new SuiviClientProspectListAction(), MainFrame.LIST_MENU);
|
|
|
258 |
// ctxt.addMenuItem(ctxt.createListAction(TABLE_CUSTOMER_CALL), MainFrame.LIST_MENU);
|
|
|
259 |
// ctxt.addMenuItem(ctxt.createListAction(TABLE_CUSTOMER_VISIT), MainFrame.LIST_MENU);
|
|
|
260 |
// ctxt.addMenuItem(ctxt.createListAction(TABLE_LEAD_CALL), MainFrame.LIST_MENU);
|
|
|
261 |
// ctxt.addMenuItem(ctxt.createListAction(TABLE_LEAD_VISIT), MainFrame.LIST_MENU);
|
|
|
262 |
|
|
|
263 |
ctxt.addMenuItem(new AbstractAction("Import de prospects") {
|
|
|
264 |
@Override
|
|
|
265 |
public void actionPerformed(ActionEvent e) {
|
|
|
266 |
final Frame frame = SwingThreadUtils.getAncestorOrSelf(Frame.class, (Component) e.getSource());
|
|
|
267 |
final FileDialog fd = new FileDialog(frame, "Import de prospects", FileDialog.LOAD);
|
|
|
268 |
fd.setFilenameFilter(new FilenameFilter() {
|
|
|
269 |
@Override
|
|
|
270 |
public boolean accept(File dir, String name) {
|
|
|
271 |
return name.endsWith("." + ContentTypeVersioned.SPREADSHEET.getExtension());
|
|
|
272 |
}
|
|
|
273 |
});
|
|
|
274 |
fd.setVisible(true);
|
|
|
275 |
if (fd.getFile() != null) {
|
|
|
276 |
final DBRoot rootSociete = ((ComptaPropsConfiguration) ComptaPropsConfiguration.getInstance()).getRootSociete();
|
|
|
277 |
try {
|
|
|
278 |
SQLUtils.executeAtomic(rootSociete.getDBSystemRoot().getDataSource(), new ConnectionHandlerNoSetup<Object, IOException>() {
|
|
|
279 |
@Override
|
|
|
280 |
public Object handle(final SQLDataSource ds) throws SQLException, IOException {
|
|
|
281 |
File f = new File(fd.getDirectory());
|
|
|
282 |
|
|
|
283 |
LeadImporter imp = new LeadImporter();
|
|
|
284 |
try {
|
|
|
285 |
imp.exportLead(rootSociete, f, new File(fd.getDirectory(), fd.getFile()));
|
|
|
286 |
imp.importFromFile(f, rootSociete);
|
|
|
287 |
} catch (Exception exn) {
|
|
|
288 |
// TODO Bloc catch auto-généré
|
|
|
289 |
exn.printStackTrace();
|
|
|
290 |
}
|
|
|
291 |
return null;
|
|
|
292 |
}
|
|
|
293 |
});
|
|
|
294 |
} catch (IOException exn) {
|
|
|
295 |
ExceptionHandler.handle(frame, "Erreur lors de la lecture du fichier", exn);
|
|
|
296 |
} catch (SQLException exn) {
|
|
|
297 |
ExceptionHandler.handle(frame, "Erreur lors de l'insertion dans la base", exn);
|
|
|
298 |
}
|
|
|
299 |
}
|
|
|
300 |
}
|
|
|
301 |
}, MainFrame.FILE_MENU);
|
30 |
ilm |
302 |
}
|
|
|
303 |
|
|
|
304 |
@Override
|
|
|
305 |
protected void start() {
|
140 |
ilm |
306 |
new LeadCustomerSQLInjector();
|
|
|
307 |
new LeadContactSQLInjector();
|
30 |
ilm |
308 |
}
|
|
|
309 |
|
|
|
310 |
@Override
|
|
|
311 |
protected void stop() {
|
|
|
312 |
}
|
|
|
313 |
|
|
|
314 |
public static void main(String[] args) throws IOException {
|
|
|
315 |
System.setProperty(ConnexionPanel.QUICK_LOGIN, "true");
|
|
|
316 |
final File propsFile = new File("module.properties");
|
|
|
317 |
System.out.println(propsFile.getAbsolutePath());
|
|
|
318 |
final ModuleFactory factory = new RuntimeModuleFactory(propsFile);
|
|
|
319 |
SQLRequestLog.setEnabled(true);
|
|
|
320 |
SQLRequestLog.showFrame();
|
|
|
321 |
// uncomment to create and use the jar
|
|
|
322 |
final ModulePackager modulePackager = new ModulePackager(propsFile, new File("bin/"));
|
|
|
323 |
modulePackager.writeToDir(new File("../OpenConcerto/Modules"));
|
|
|
324 |
// final ModuleFactory factory = new JarModuleFactory(jar);
|
|
|
325 |
ModuleManager.getInstance().addFactories(new File("../OpenConcerto/Modules"));
|
|
|
326 |
ModuleManager.getInstance().addFactoryAndStart(factory, false);
|
|
|
327 |
Gestion.main(args);
|
|
|
328 |
}
|
|
|
329 |
|
|
|
330 |
}
|