OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 18 | Rev 41 | 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
 
18 ilm 37
    public ContactSQLElement() {
21 ilm 38
        this("CONTACT", "un contact", "contacts");
18 ilm 39
    }
40
 
21 ilm 41
    protected ContactSQLElement(String tableName, String singular, String plural) {
42
        super(tableName, singular, plural);
43
    }
44
 
18 ilm 45
    protected List<String> getListFields() {
46
        final List<String> l = new ArrayList<String>();
47
        l.add("NOM");
48
        l.add("PRENOM");
49
        l.add("FONCTION");
50
        if (getTable().contains("ID_CLIENT")) {
51
            l.add("ID_CLIENT");
52
        }
21 ilm 53
 
54
        if (getTable().contains("ID_FOURNISSEUR")) {
55
            l.add("ID_FOURNISSEUR");
56
        }
18 ilm 57
        l.add("TEL_STANDARD");
58
        l.add("TEL_DIRECT");
59
        return l;
60
    }
61
 
62
    protected List<String> getComboFields() {
63
        final List<String> l = new ArrayList<String>();
64
        l.add("NOM");
65
        l.add("PRENOM");
66
        l.add("FONCTION");
67
        if (getTable().contains("ID_SITE"))
68
            l.add("ID_SITE");
69
        if (getTable().contains("ID_CLIENT"))
70
            l.add("ID_CLIENT");
21 ilm 71
        if (getTable().contains("ID_FOURNISSEUR")) {
72
            l.add("ID_FOURNISSEUR");
73
        }
18 ilm 74
        return l;
75
    }
76
 
77
    @Override
78
    public CollectionMap<String, String> getShowAs() {
79
        return CollectionMap.singleton(null, "NOM", "TEL_STANDARD");
80
    }
81
 
82
    /*
83
     * (non-Javadoc)
84
     *
85
     * @see org.openconcerto.devis.SQLElement#getComponent()
86
     */
87
    public SQLComponent createComponent() {
88
        return new ContactSQLComponent(this);
89
    }
90
 
91
    public static class ContactSQLComponent extends UISQLComponent {
92
 
93
        public ContactSQLComponent(SQLElement elt) {
94
            super(elt);
95
        }
96
 
97
        @Override
98
        protected Set<String> createRequiredNames() {
99
            final Set<String> s = new HashSet<String>();
100
            s.add("NOM");
101
            return s;
102
        }
103
 
104
        public void addViews() {
105
            if (getTable().contains("ID_CLIENT")) {
106
                this.addView("ID_CLIENT");
107
            }
21 ilm 108
            if (getTable().contains("ID_FOURNISSEUR")) {
109
                this.addView("ID_FOURNISSEUR");
110
            }
18 ilm 111
            if (getTable().contains("ID_TITRE_PERSONNEL")) {
112
                this.addView("ID_TITRE_PERSONNEL", "1");
113
                this.addView("NOM", "1");
114
                this.addView("PRENOM", "1");
115
            } else {
116
                this.addView("NOM", "left");
117
                this.addView("PRENOM", "right");
118
            }
119
 
120
            this.addView("FONCTION", "1");
121
 
122
            if (getTable().contains("ID_SITE"))
123
                this.addView("ID_SITE");
124
 
125
            if (getTable().contains("ACTIF"))
126
                this.addView("ACTIF");
127
 
128
            if (getTable().contains("SUFFIXE"))
129
                this.addView("SUFFIXE");
130
 
131
            this.addView("TEL_STANDARD", "left");
132
            this.addView("TEL_DIRECT", "right");
133
 
134
            this.addView("TEL_MOBILE", "left");
135
            this.addView("TEL_PERSONEL", "right");
136
 
137
            this.addView("FAX", "left");
138
            this.addView("EMAIL", "right");
139
 
140
            if (getTable().contains("SERVICE"))
141
                this.addView("SERVICE");
142
 
143
            if (getTable().contains("NOM_ASSISTANTE"))
144
                this.addView("NOM_ASSISTANTE");
145
 
146
            if (getTable().contains("EMAIL_ASSISTANTE"))
147
                this.addView("EMAIL_ASSISTANTE");
148
 
149
            if (getTable().contains("TEL_ASSISTANTE"))
150
                this.addView("TEL_ASSISTANTE");
151
 
152
            if (getTable().contains("NOM_RESPONSABLE"))
153
                this.addView("NOM_RESPONSABLE");
154
 
155
        }
156
 
157
        public void setIdClient(int idClient) {
158
            if (idClient != SQLRow.NONEXISTANT_ID) {
159
                this.setDefaults(Collections.singletonMap("ID_CLIENT", idClient));
160
            } else {
161
                this.clearDefaults();
162
            }
163
        }
164
    }
165
 
166
}