OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 87 | Rev 154 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 87 Rev 140
Line 1... Line 1...
1
package org.openconcerto.modules.customerrelationship.lead;
1
package org.openconcerto.modules.customerrelationship.lead;
2
 
2
 
-
 
3
import java.awt.Component;
-
 
4
import java.awt.FileDialog;
-
 
5
import java.awt.Frame;
-
 
6
import java.awt.event.ActionEvent;
3
import java.io.File;
7
import java.io.File;
-
 
8
import java.io.FilenameFilter;
4
import java.io.IOException;
9
import java.io.IOException;
-
 
10
import java.sql.SQLException;
5
 
11
 
-
 
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;
6
import org.openconcerto.erp.config.Gestion;
17
import org.openconcerto.erp.config.Gestion;
7
import org.openconcerto.erp.config.MainFrame;
18
import org.openconcerto.erp.config.MainFrame;
8
import org.openconcerto.erp.modules.AbstractModule;
19
import org.openconcerto.erp.modules.AbstractModule;
9
import org.openconcerto.erp.modules.ComponentsContext;
20
import org.openconcerto.erp.modules.ComponentsContext;
10
import org.openconcerto.erp.modules.DBContext;
21
import org.openconcerto.erp.modules.DBContext;
11
import org.openconcerto.erp.modules.MenuContext;
22
import org.openconcerto.erp.modules.MenuContext;
12
import org.openconcerto.erp.modules.ModuleFactory;
23
import org.openconcerto.erp.modules.ModuleFactory;
13
import org.openconcerto.erp.modules.ModuleManager;
24
import org.openconcerto.erp.modules.ModuleManager;
14
import org.openconcerto.erp.modules.ModulePackager;
25
import org.openconcerto.erp.modules.ModulePackager;
15
import org.openconcerto.erp.modules.RuntimeModuleFactory;
26
import org.openconcerto.erp.modules.RuntimeModuleFactory;
-
 
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;
16
import org.openconcerto.sql.element.GlobalMapper;
37
import org.openconcerto.sql.element.GlobalMapper;
-
 
38
import org.openconcerto.sql.element.SQLElement;
17
import org.openconcerto.sql.element.SQLElementDirectory;
39
import org.openconcerto.sql.element.SQLElementDirectory;
-
 
40
import org.openconcerto.sql.model.ConnectionHandlerNoSetup;
-
 
41
import org.openconcerto.sql.model.DBRoot;
-
 
42
import org.openconcerto.sql.model.SQLDataSource;
18
import org.openconcerto.sql.model.SQLRequestLog;
43
import org.openconcerto.sql.model.SQLRequestLog;
-
 
44
import org.openconcerto.sql.model.SQLRow;
-
 
45
import org.openconcerto.sql.model.SQLRowValues;
-
 
46
import org.openconcerto.sql.model.SQLTable;
19
import org.openconcerto.sql.ui.ConnexionPanel;
47
import org.openconcerto.sql.ui.ConnexionPanel;
20
import org.openconcerto.sql.utils.SQLCreateTable;
48
import org.openconcerto.sql.utils.SQLCreateTable;
-
 
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;
21
 
58
 
22
public final class Module extends AbstractModule {
59
public final class Module extends AbstractModule {
23
 
60
 
24
    public static final String TABLE_LEAD = "LEAD";
61
    public static final String TABLE_LEAD = "LEAD";
-
 
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";
25
 
72
 
26
    public Module(ModuleFactory f) throws IOException {
73
    public Module(ModuleFactory f) throws IOException {
27
        super(f);
74
        super(f);
28
    }
75
    }
29
 
76
 
Line 58... Line 105...
58
            createTable.addVarCharColumn("RATING", 200);
105
            createTable.addVarCharColumn("RATING", 200);
59
 
106
 
60
            createTable.addIntegerColumn("REVENUE", 0);
107
            createTable.addIntegerColumn("REVENUE", 0);
61
            createTable.addIntegerColumn("EMPLOYEES", 0);
108
            createTable.addIntegerColumn("EMPLOYEES", 0);
62
 
109
 
-
 
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
            }
63
        }
179
        }
64
    }
180
    }
65
 
181
 
66
    @Override
182
    @Override
67
    protected void setupElements(SQLElementDirectory dir) {
183
    protected void setupElements(final SQLElementDirectory dir) {
68
        super.setupElements(dir);
184
        super.setupElements(dir);
-
 
185
 
69
        final LeadSQLElement element = new LeadSQLElement(this);
186
        final LeadSQLElement element = new LeadSQLElement(this);
70
        GlobalMapper.getInstance().map(element.getCode() + ".default", new LeadGroup());
187
        GlobalMapper.getInstance().map(element.getCode() + ".default", new LeadGroup());
71
        dir.addSQLElement(element);
188
        dir.addSQLElement(element);
-
 
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
 
72
    }
238
    }
73
 
239
 
74
    @Override
240
    @Override
75
    protected void setupComponents(ComponentsContext ctxt) {
241
    protected void setupComponents(ComponentsContext ctxt) {
76
 
242
 
77
    }
243
    }
78
 
244
 
79
    @Override
245
    @Override
80
    protected void setupMenu(MenuContext ctxt) {
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);
81
        ctxt.addMenuItem(ctxt.createListAction(TABLE_LEAD), 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);
82
    }
302
    }
83
 
303
 
84
    @Override
304
    @Override
85
    protected void start() {
305
    protected void start() {
-
 
306
        new LeadCustomerSQLInjector();
-
 
307
        new LeadContactSQLInjector();
86
    }
308
    }
87
 
309
 
88
    @Override
310
    @Override
89
    protected void stop() {
311
    protected void stop() {
90
    }
312
    }