OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 21 | Rev 73 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
18 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
10
 *
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
13
 
14
 package org.openconcerto.erp.core.customerrelationship.customer.element;
15
 
16
import org.openconcerto.sql.element.ConfSQLElement;
17
import org.openconcerto.sql.element.SQLComponent;
18
import org.openconcerto.sql.element.SQLElement;
19
import org.openconcerto.sql.element.UISQLComponent;
20
import org.openconcerto.sql.model.SQLRow;
21
import org.openconcerto.utils.CollectionMap;
22
 
23
import java.util.ArrayList;
24
import java.util.Collections;
25
import java.util.HashSet;
26
import java.util.List;
27
import java.util.Set;
28
 
29
public class ContactSQLElement extends ConfSQLElement {
30
 
21 ilm 31
    static public class ContactFournisseurSQLElement extends ContactSQLElement {
32
        public ContactFournisseurSQLElement() {
33
            super("CONTACT_FOURNISSEUR", "un contact fournisseur", "contacts fournisseurs");
34
        }
35
    }
36
 
41 ilm 37
    static public class ContactAdministratifSQLElement extends ContactSQLElement {
38
        public ContactAdministratifSQLElement() {
39
            super("CONTACT_ADMINISTRATIF", "un contact administratif", "contacts administratif");
40
        }
41
    }
42
 
18 ilm 43
    public ContactSQLElement() {
21 ilm 44
        this("CONTACT", "un contact", "contacts");
18 ilm 45
    }
46
 
21 ilm 47
    protected ContactSQLElement(String tableName, String singular, String plural) {
48
        super(tableName, singular, plural);
49
    }
50
 
18 ilm 51
    protected List<String> getListFields() {
52
        final List<String> l = new ArrayList<String>();
53
        l.add("NOM");
54
        l.add("PRENOM");
55
        l.add("FONCTION");
56
        if (getTable().contains("ID_CLIENT")) {
57
            l.add("ID_CLIENT");
58
        }
21 ilm 59
 
60
        if (getTable().contains("ID_FOURNISSEUR")) {
61
            l.add("ID_FOURNISSEUR");
62
        }
18 ilm 63
        l.add("TEL_STANDARD");
64
        l.add("TEL_DIRECT");
41 ilm 65
        l.add("EMAIL");
66
        l.add("TEL_MOBILE");
67
        if (getTable().contains("ORIGINE")) {
68
            l.add("ORIGINE");
69
        }
70
        if (getTable().contains("TYPE_DEMANDE")) {
71
            l.add("TYPE_DEMANDE");
72
        }
73
        if (getTable().contains("N4DS")) {
74
            l.add("N4DS");
75
        }
18 ilm 76
        return l;
77
    }
78
 
79
    protected List<String> getComboFields() {
80
        final List<String> l = new ArrayList<String>();
81
        l.add("NOM");
82
        l.add("PRENOM");
83
        l.add("FONCTION");
84
        if (getTable().contains("ID_SITE"))
85
            l.add("ID_SITE");
86
        if (getTable().contains("ID_CLIENT"))
87
            l.add("ID_CLIENT");
21 ilm 88
        if (getTable().contains("ID_FOURNISSEUR")) {
89
            l.add("ID_FOURNISSEUR");
90
        }
18 ilm 91
        return l;
92
    }
93
 
94
    @Override
95
    public CollectionMap<String, String> getShowAs() {
96
        return CollectionMap.singleton(null, "NOM", "TEL_STANDARD");
97
    }
98
 
99
    /*
100
     * (non-Javadoc)
101
     *
102
     * @see org.openconcerto.devis.SQLElement#getComponent()
103
     */
104
    public SQLComponent createComponent() {
105
        return new ContactSQLComponent(this);
106
    }
107
 
108
    public static class ContactSQLComponent extends UISQLComponent {
109
 
110
        public ContactSQLComponent(SQLElement elt) {
111
            super(elt);
112
        }
113
 
114
        @Override
115
        protected Set<String> createRequiredNames() {
116
            final Set<String> s = new HashSet<String>();
117
            s.add("NOM");
118
            return s;
119
        }
120
 
121
        public void addViews() {
122
            if (getTable().contains("ID_CLIENT")) {
123
                this.addView("ID_CLIENT");
124
            }
21 ilm 125
            if (getTable().contains("ID_FOURNISSEUR")) {
126
                this.addView("ID_FOURNISSEUR");
127
            }
18 ilm 128
            if (getTable().contains("ID_TITRE_PERSONNEL")) {
129
                this.addView("ID_TITRE_PERSONNEL", "1");
130
                this.addView("NOM", "1");
131
                this.addView("PRENOM", "1");
132
            } else {
133
                this.addView("NOM", "left");
134
                this.addView("PRENOM", "right");
135
            }
136
 
137
            this.addView("FONCTION", "1");
138
 
139
            if (getTable().contains("ID_SITE"))
140
                this.addView("ID_SITE");
141
 
142
            if (getTable().contains("ACTIF"))
143
                this.addView("ACTIF");
144
 
145
            if (getTable().contains("SUFFIXE"))
146
                this.addView("SUFFIXE");
147
 
148
            this.addView("TEL_STANDARD", "left");
149
            this.addView("TEL_DIRECT", "right");
150
 
151
            this.addView("TEL_MOBILE", "left");
152
            this.addView("TEL_PERSONEL", "right");
153
 
154
            this.addView("FAX", "left");
155
            this.addView("EMAIL", "right");
156
 
157
            if (getTable().contains("SERVICE"))
158
                this.addView("SERVICE");
159
 
160
            if (getTable().contains("NOM_ASSISTANTE"))
161
                this.addView("NOM_ASSISTANTE");
162
 
163
            if (getTable().contains("EMAIL_ASSISTANTE"))
164
                this.addView("EMAIL_ASSISTANTE");
165
 
166
            if (getTable().contains("TEL_ASSISTANTE"))
167
                this.addView("TEL_ASSISTANTE");
168
 
169
            if (getTable().contains("NOM_RESPONSABLE"))
170
                this.addView("NOM_RESPONSABLE");
171
 
41 ilm 172
            if (getTable().contains("N4DS")) {
173
                addView("N4DS");
174
            }
18 ilm 175
        }
176
 
177
        public void setIdClient(int idClient) {
178
            if (idClient != SQLRow.NONEXISTANT_ID) {
179
                this.setDefaults(Collections.singletonMap("ID_CLIENT", idClient));
180
            } else {
181
                this.clearDefaults();
182
            }
183
        }
184
    }
185
 
186
}