OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 140 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
30 ilm 1
package org.openconcerto.modules.customerrelationship.lead;
2
 
3
import java.util.HashSet;
4
import java.util.Set;
5
 
6
import javax.swing.JComponent;
7
import javax.swing.JLabel;
181 ilm 8
import javax.swing.JTextField;
30 ilm 9
 
181 ilm 10
import org.openconcerto.modules.customerrelationship.lead.visit.LeadActionItemTable;
30 ilm 11
import org.openconcerto.sql.element.GroupSQLComponent;
12
import org.openconcerto.sql.element.SQLElement;
140 ilm 13
import org.openconcerto.sql.model.SQLBackgroundTableCache;
14
import org.openconcerto.sql.model.SQLRow;
181 ilm 15
import org.openconcerto.sql.model.SQLRowAccessor;
140 ilm 16
import org.openconcerto.sql.model.SQLRowValues;
17
import org.openconcerto.sql.model.SQLTable;
181 ilm 18
import org.openconcerto.sql.sqlobject.ElementComboBox;
30 ilm 19
import org.openconcerto.sql.sqlobject.SQLSearchableTextCombo;
140 ilm 20
import org.openconcerto.sql.users.UserManager;
30 ilm 21
import org.openconcerto.ui.JDate;
140 ilm 22
import org.openconcerto.ui.JLabelBold;
30 ilm 23
import org.openconcerto.ui.component.ComboLockedMode;
140 ilm 24
import org.openconcerto.ui.component.ITextArea;
30 ilm 25
import org.openconcerto.ui.group.Group;
26
 
27
public class LeadSQLComponent extends GroupSQLComponent {
181 ilm 28
 
29
    private LeadActionItemTable tableCall, tableVisit;
30
 
30 ilm 31
    public LeadSQLComponent(SQLElement element, Group group) {
32
        super(element, group);
181 ilm 33
        startTabGroupAfter("customerrelationship.lead.state");
30 ilm 34
    }
35
 
36
    @Override
37
    protected Set<String> createRequiredNames() {
38
        final Set<String> s = new HashSet<String>(1);
39
        s.add("ID_ADRESSE");
140 ilm 40
        s.add("NOM");
30 ilm 41
        return s;
42
    }
43
 
44
    @Override
140 ilm 45
    public JComponent getLabel(String id) {
46
        if (id.equals("customerrelationship.lead.person")) {
47
            return new JLabelBold("Contact");
181 ilm 48
        }
49
        if (id.equals("customerrelationship.lead.items.visit.tab")) {
50
            return new JLabelBold("Visites");
51
        }
52
        if (id.equals("customerrelationship.lead.items.visit")) {
53
            return new JLabelBold("");
54
        }
55
        if (id.equals("customerrelationship.lead.items.call.tab")) {
56
            return new JLabelBold("Appels");
57
        }
58
        if (id.equals("customerrelationship.lead.items.call")) {
59
            return new JLabelBold("");
140 ilm 60
        } else if (id.equals("customerrelationship.lead.contact")) {
61
            return new JLabel();
62
        } else if (id.equals("customerrelationship.lead.address")) {
63
            return new JLabelBold("Adresse");
181 ilm 64
        } else if (id.equals("customerrelationship.lead.info")) {
65
            return new JLabelBold("Infos");
66
        } else if (id.equals("customerrelationship.lead.state")) {
67
            return new JLabelBold("Statut");
140 ilm 68
        } else {
69
            return super.getLabel(id);
70
        }
71
    }
72
 
73
    @Override
87 ilm 74
    public JComponent createEditor(String id) {
140 ilm 75
        if (id.equals("INFORMATION") || id.equals("INFOS")) {
181 ilm 76
            final ITextArea jTextArea = new ITextArea(3,3);
30 ilm 77
            jTextArea.setFont(new JLabel().getFont());
140 ilm 78
            return jTextArea;
181 ilm 79
        } else if (id.equals("ID_COMMERCIAL") || id.equals("ID_TITRE_PERSONNEL")) {
80
            ElementComboBox comp = new ElementComboBox(false, 1);
81
            ((ElementComboBox) comp).init(getElement().getForeignElement(id));
82
            return comp;
83
        } else if (id.equals("customerrelationship.lead.items.call")) {
84
            tableCall = new LeadActionItemTable(getElement().getDirectory().getElement(Module.TABLE_LEAD_CALL));
85
            return tableCall;
86
        } else if (id.equals("customerrelationship.lead.items.visit")) {
87
            tableVisit = new LeadActionItemTable(getElement().getDirectory().getElement(Module.TABLE_LEAD_VISIT));
88
            return tableVisit;
140 ilm 89
        } else if (id.equals("INDUSTRY") || id.equals("STATUS") || id.equals("RATING") || id.equals("SOURCE") || id.equals("DISPO")) {
181 ilm 90
            return new SQLSearchableTextCombo(ComboLockedMode.UNLOCKED, 1, 1, false);
30 ilm 91
        } else if (id.equals("DATE")) {
92
            return new JDate(true);
93
        }
181 ilm 94
 
95
        JComponent comp = super.createEditor(id);
96
 
97
        if(comp.getClass() == JTextField.class) {
98
        	JTextField jtxt = new JTextField(10);
99
        	comp = jtxt;
100
        }
101
 
102
        return comp;
30 ilm 103
    }
140 ilm 104
 
105
    @Override
181 ilm 106
    public int insert(SQLRow order) {
107
        int id = super.insert(order);
108
        this.tableCall.updateField("ID_LEAD", id);
109
        this.tableVisit.updateField("ID_LEAD", id);
110
        return id;
111
    }
112
 
113
    @Override
114
    public void select(SQLRowAccessor r) {
115
        super.select(r);
116
        if (r != null) {
117
            this.tableCall.insertFrom("ID_LEAD", r.getID());
118
            this.tableVisit.insertFrom("ID_LEAD", r.getID());
119
        }
120
    }
121
 
122
    @Override
123
    public void update() {
124
        super.update();
125
        this.tableCall.updateField("ID_LEAD", getSelectedID());
126
        this.tableVisit.updateField("ID_LEAD", getSelectedID());
127
    }
128
 
129
    @Override
140 ilm 130
    protected SQLRowValues createDefaults() {
131
        SQLRowValues rowVals = new SQLRowValues(getTable());
132
        rowVals.put("STATUS", "Nouveau");
133
 
134
        final int idUser = UserManager.getInstance().getCurrentUser().getId();
135
        final SQLTable foreignTableComm = getTable().getForeignTable("ID_COMMERCIAL");
136
        SQLRow rowsComm = SQLBackgroundTableCache.getInstance().getCacheForTable(foreignTableComm).getFirstRowContains(idUser, foreignTableComm.getField("ID_USER_COMMON"));
137
 
138
        if (rowsComm != null) {
139
            rowVals.put("ID_COMMERCIAL", rowsComm.getID());
140
        }
141
        return rowVals;
142
    }
30 ilm 143
}