OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 160 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 160 Rev 181
Line 2... Line 2...
2
 
2
 
3
import java.awt.event.ActionEvent;
3
import java.awt.event.ActionEvent;
4
import java.sql.SQLException;
4
import java.sql.SQLException;
5
import java.util.ArrayList;
5
import java.util.ArrayList;
6
import java.util.Calendar;
6
import java.util.Calendar;
-
 
7
import java.util.Collection;
7
import java.util.Date;
8
import java.util.Date;
8
import java.util.List;
9
import java.util.List;
9
import java.util.Set;
10
import java.util.Set;
10
 
11
 
11
import javax.swing.AbstractAction;
12
import javax.swing.AbstractAction;
Line 52... Line 53...
52
 
53
 
53
    public LeadSQLElement(final AbstractModule module) {
54
    public LeadSQLElement(final AbstractModule module) {
54
        super(module, Module.TABLE_LEAD);
55
        super(module, Module.TABLE_LEAD);
55
 
56
 
56
        // Call
57
        // Call
-
 
58
        final RowAction.PredicateRowAction addDuplicateAction = new RowAction.PredicateRowAction(new AbstractAction("Créer à partir de") {
-
 
59
 
-
 
60
            @Override
-
 
61
            public void actionPerformed(ActionEvent e) {
-
 
62
                SQLRow sRow = IListe.get(e).getSelectedRow().asRow();
-
 
63
                final SQLTable table = LeadSQLElement.this.getTable().getTable(Module.TABLE_LEAD);
-
 
64
                final SQLElement leadElt = LeadSQLElement.this.getDirectory().getElement(table);
-
 
65
                EditFrame editFrame = new EditFrame(leadElt);
-
 
66
                final SQLRowValues sqlRowValues = new SQLRowValues(table);
-
 
67
                sqlRowValues.put("COMPANY", sRow.getObject("COMPANY"));
-
 
68
                sqlRowValues.put("PHONE", sRow.getObject("PHONE"));
-
 
69
                sqlRowValues.put("FAX", sRow.getObject("FAX"));
-
 
70
                sqlRowValues.put("WEBSITE", sRow.getObject("WEBSITE"));
-
 
71
                sqlRowValues.put("DATE", new Date());
-
 
72
                SQLRowValues adr = new SQLRowValues(sRow.getForeign("ID_ADRESSE").asRowValues());
-
 
73
                sqlRowValues.put("ID_ADRESSE", adr);
-
 
74
                sqlRowValues.put("INDUSTRY", sRow.getObject("INDUSTRY"));
-
 
75
                sqlRowValues.put("REVENUE", sRow.getObject("REVENUE"));
-
 
76
                sqlRowValues.put("EMPLOYEES", sRow.getObject("EMPLOYEES"));
-
 
77
                sqlRowValues.put("LOCALISATION", sRow.getObject("LOCALISATION"));
-
 
78
                sqlRowValues.put("SIRET", sRow.getObject("SIRET"));
-
 
79
                sqlRowValues.put("APE", sRow.getObject("APE"));
-
 
80
 
-
 
81
                editFrame.getSQLComponent().select(sqlRowValues);
-
 
82
                FrameUtil.show(editFrame);
-
 
83
            }
-
 
84
        }, true) {
-
 
85
        };
-
 
86
        addDuplicateAction.setPredicate(IListeEvent.getSingleSelectionPredicate());
-
 
87
        getRowActions().add(addDuplicateAction);
-
 
88
 
-
 
89
        // Call
57
        final RowAction.PredicateRowAction addCallAction = new RowAction.PredicateRowAction(new AbstractAction("Appeler") {
90
        final RowAction.PredicateRowAction addCallAction = new RowAction.PredicateRowAction(new AbstractAction("Appeler") {
58
 
91
 
59
            @Override
92
            @Override
60
            public void actionPerformed(ActionEvent e) {
93
            public void actionPerformed(ActionEvent e) {
61
                SQLRow sRow = IListe.get(e).getSelectedRow().asRow();
94
                SQLRow sRow = IListe.get(e).getSelectedRow().asRow();
Line 119... Line 152...
119
                    }
152
                    }
120
                });
153
                });
121
            }
154
            }
122
        }
155
        }
123
 
156
 
-
 
157
        if (getTable().contains("MODIFICATION_DATE")) {
-
 
158
            BaseSQLTableModelColumn dateM = new BaseSQLTableModelColumn("Date de modification", Date.class) {
-
 
159
 
-
 
160
                @Override
-
 
161
                protected Object show_(SQLRowAccessor r) {
-
 
162
                    return r.getObject("MODIFICATION_DATE");
-
 
163
                }
-
 
164
 
-
 
165
                @Override
-
 
166
                public Set<FieldPath> getPaths() {
-
 
167
                    Path p = new Path(getTable());
-
 
168
                    return CollectionUtils.createSet(new FieldPath(p, "MODIFICATION_DATE"));
-
 
169
                }
-
 
170
            };
-
 
171
            source.getColumns().add(1, dateM);
-
 
172
        }
-
 
173
 
-
 
174
        BaseSQLTableModelColumn dateV = new BaseSQLTableModelColumn("Visite", Date.class) {
-
 
175
 
-
 
176
            @Override
-
 
177
            protected Object show_(SQLRowAccessor r) {
-
 
178
                Date d = null;
-
 
179
                Collection<? extends SQLRowAccessor> l = r.getReferentRows(r.getTable().getTable("LEAD_VISIT"));
-
 
180
                for (SQLRowAccessor sqlRowAccessor : l) {
-
 
181
                    if (d != null && sqlRowAccessor.getObject("DATE") != null && d.before(sqlRowAccessor.getDate("DATE").getTime())) {
-
 
182
                        d = sqlRowAccessor.getDate("DATE").getTime();
-
 
183
                    } else {
-
 
184
                        if (d == null && sqlRowAccessor.getObject("DATE") != null) {
-
 
185
                            d = sqlRowAccessor.getDate("DATE").getTime();
-
 
186
                        }
-
 
187
                    }
-
 
188
 
-
 
189
                }
-
 
190
                return d;
-
 
191
            }
-
 
192
 
-
 
193
            @Override
-
 
194
            public Set<FieldPath> getPaths() {
-
 
195
                Path p = new Path(getTable());
-
 
196
                p = p.add(p.getLast().getTable("LEAD_VISIT"));
-
 
197
                return CollectionUtils.createSet(new FieldPath(p, "DATE"));
-
 
198
            }
-
 
199
        };
-
 
200
        source.getColumns().add(1, dateV);
-
 
201
 
-
 
202
        BaseSQLTableModelColumn dateA = new BaseSQLTableModelColumn("Appel", Date.class) {
-
 
203
 
-
 
204
            @Override
-
 
205
            protected Object show_(SQLRowAccessor r) {
-
 
206
                Date d = null;
-
 
207
                Collection<? extends SQLRowAccessor> l = r.getReferentRows(r.getTable().getTable("LEAD_CALL"));
-
 
208
                for (SQLRowAccessor sqlRowAccessor : l) {
-
 
209
                    if (d != null && sqlRowAccessor.getObject("DATE") != null && d.before(sqlRowAccessor.getDate("DATE").getTime())) {
-
 
210
                        d = sqlRowAccessor.getDate("DATE").getTime();
-
 
211
                    } else {
-
 
212
                        if (d == null && sqlRowAccessor.getObject("DATE") != null) {
-
 
213
                            d = sqlRowAccessor.getDate("DATE").getTime();
-
 
214
                        }
-
 
215
                    }
-
 
216
 
-
 
217
                }
-
 
218
                return d;
-
 
219
            }
-
 
220
 
-
 
221
            @Override
-
 
222
            public Set<FieldPath> getPaths() {
-
 
223
                Path p = new Path(getTable());
-
 
224
                p = p.add(p.getLast().getTable("LEAD_CALL"));
-
 
225
                return CollectionUtils.createSet(new FieldPath(p, "DATE"));
-
 
226
            }
-
 
227
        };
-
 
228
        source.getColumns().add(1, dateA);
-
 
229
 
124
        BaseSQLTableModelColumn adresse = new BaseSQLTableModelColumn("Adresse", String.class) {
230
        BaseSQLTableModelColumn adresse = new BaseSQLTableModelColumn("Adresse", String.class) {
125
 
231
 
126
            @Override
232
            @Override
127
            protected Object show_(SQLRowAccessor r) {
233
            protected Object show_(SQLRowAccessor r) {
128
                final SQLRowAccessor rAdr = r.getForeign("ID_ADRESSE");
234
                final SQLRowAccessor rAdr = r.getForeign("ID_ADRESSE");
Line 187... Line 293...
187
                return CollectionUtils.createSet(new FieldPath(p, "VILLE"));
293
                return CollectionUtils.createSet(new FieldPath(p, "VILLE"));
188
            }
294
            }
189
        };
295
        };
190
        source.getColumns().add(ville);
296
        source.getColumns().add(ville);
191
 
297
 
-
 
298
        BaseSQLTableModelColumn dpt = new BaseSQLTableModelColumn("Département", String.class) {
-
 
299
 
-
 
300
            @Override
-
 
301
            protected Object show_(SQLRowAccessor r) {
-
 
302
 
-
 
303
                String s = r.getForeign("ID_ADRESSE").getString("CODE_POSTAL");
-
 
304
                if (s != null && s.length() >= 2) {
-
 
305
                    return s.substring(0, 2);
-
 
306
                } else {
-
 
307
                    return s;
-
 
308
                }
-
 
309
 
-
 
310
            }
-
 
311
 
-
 
312
            @Override
-
 
313
            public Set<FieldPath> getPaths() {
-
 
314
                Path p = new Path(getTable());
-
 
315
                final SQLTable clientT = getTable().getForeignTable("ID_CLIENT");
-
 
316
                p = p.add(clientT);
-
 
317
                p = p.add(clientT.getField("ID_ADRESSE"));
-
 
318
                return CollectionUtils.createSet(new FieldPath(p, "VILLE"), new FieldPath(p, "CODE_POSTAL"));
-
 
319
            }
-
 
320
        };
-
 
321
 
-
 
322
        source.getColumns().add(dpt);
-
 
323
 
192
        if (getTable().contains("REMIND_DATE")) {
324
        if (getTable().contains("REMIND_DATE")) {
193
            BaseSQLTableModelColumn dateRemind = new BaseSQLTableModelColumn("Date de rappel", Date.class) {
325
            BaseSQLTableModelColumn dateRemind = new BaseSQLTableModelColumn("Date de rappel", Date.class) {
194
 
326
 
195
                @Override
327
                @Override
196
                protected Object show_(SQLRowAccessor r) {
328
                protected Object show_(SQLRowAccessor r) {