OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev Author Line No. Line
93 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
 
142 ilm 16
import org.openconcerto.erp.core.edm.AttachmentAction;
156 ilm 17
import org.openconcerto.erp.core.reports.history.ui.HistoriqueClientFrame;
180 ilm 18
import org.openconcerto.erp.preferences.GestionCommercialeGlobalPreferencePanel;
94 ilm 19
import org.openconcerto.sql.element.GlobalMapper;
93 ilm 20
import org.openconcerto.sql.element.GroupSQLComponent;
21
import org.openconcerto.sql.element.SQLComponent;
144 ilm 22
import org.openconcerto.sql.model.SQLRowAccessor;
180 ilm 23
import org.openconcerto.sql.preferences.SQLPreferences;
144 ilm 24
import org.openconcerto.sql.request.SQLFieldTranslator;
156 ilm 25
import org.openconcerto.sql.view.list.IListe;
142 ilm 26
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
27
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
144 ilm 28
import org.openconcerto.ui.light.LightUIElement;
29
import org.openconcerto.ui.light.LightUILine;
30
import org.openconcerto.ui.light.LightUIPanel;
31
import org.openconcerto.ui.light.SimpleTextLine;
93 ilm 32
 
156 ilm 33
import java.awt.event.ActionEvent;
132 ilm 34
import java.util.List;
35
 
156 ilm 36
import javax.swing.AbstractAction;
37
 
93 ilm 38
public class CustomerSQLElement extends ClientNormalSQLElement {
39
 
40
    public CustomerSQLElement() {
41
        super();
94 ilm 42
        final CustomerGroup group = new CustomerGroup();
43
        GlobalMapper.getInstance().map(CustomerGroup.ID, group);
44
        setDefaultGroup(group);
144 ilm 45
 
142 ilm 46
        PredicateRowAction actionAttachment = new PredicateRowAction(new AttachmentAction().getAction(), true);
47
        actionAttachment.setPredicate(IListeEvent.getSingleSelectionPredicate());
48
        getRowActions().add(actionAttachment);
49
 
156 ilm 50
        PredicateRowAction actionHistory = new PredicateRowAction(new AbstractAction("Historique client") {
51
 
52
            @Override
53
            public void actionPerformed(ActionEvent e) {
54
                HistoriqueClientFrame histoFrame = new HistoriqueClientFrame();
55
                int idClient = IListe.get(e).getSelectedId();
56
                histoFrame.selectId(idClient);
57
                histoFrame.setVisible(true);
58
            }
59
        }, true);
60
        actionHistory.setPredicate(IListeEvent.getSingleSelectionPredicate());
61
        getRowActions().add(actionHistory);
62
 
93 ilm 63
    }
64
 
65
    @Override
66
    public SQLComponent createComponent() {
67
        final GroupSQLComponent c = new CustomerSQLComponent(this);
68
        c.startTabGroupAfter("customerrelationship.customer.identifier");
69
        return c;
70
    }
132 ilm 71
 
72
    @Override
73
    protected List<String> getListFields() {
74
        final List<String> fields = super.getListFields();
142 ilm 75
        if (getTable().contains("GROUPE")) {
76
            fields.add("GROUPE");
77
        }
180 ilm 78
        SQLPreferences prefs = new SQLPreferences(getTable().getDBRoot());
79
 
80
        if (prefs.getBoolean(GestionCommercialeGlobalPreferencePanel.CATEGORIE_COMPTABLE_SPEC, false)) {
81
            fields.add("ID_CATEGORIE_COMPTABLE");
82
        }
142 ilm 83
        fields.add("SOLDE_COMPTE");
84
        fields.add("REMIND_DATE");
132 ilm 85
        fields.add("OBSOLETE");
86
        return fields;
87
    }
144 ilm 88
 
89
    @Override
90
    protected void fillDataPanel(final String sessionToken, final List<SQLRowAccessor> selection, final LightUIPanel dataPanel) {
91
        final SQLFieldTranslator translator = this.getDirectory().getTranslator();
92
        final SQLRowAccessor sqlRow = selection.get(0);
93
 
94
        final int rowId = sqlRow.getID();
95
        final LightUILine mainLine = new LightUILine();
96
        final LightUIPanel mainLinePanel = new LightUIPanel(dataPanel.getId() + ".main.line." + rowId);
97
        mainLinePanel.setWeightX(1);
98
 
99
        final SimpleTextLine spacer = new SimpleTextLine("", true, LightUIElement.HALIGN_LEFT, 2);
100
        spacer.setMarginBottom(4);
101
 
102
        String name = sqlRow.getString("NOM");
103
 
104
        mainLinePanel.addChild(new SimpleTextLine(name, true, LightUIElement.HALIGN_LEFT));
105
 
106
        final SimpleTextLine titleSituationContact = new SimpleTextLine("Coordonnées du client", true, LightUIElement.HALIGN_LEFT, 2);
107
        titleSituationContact.setMarginTop(10);
108
        mainLinePanel.addChild(titleSituationContact);
109
 
110
        addFieldToPanel("TEL", mainLinePanel, sqlRow, translator, true, "non renseigné");
111
        addFieldToPanel("MAIL", mainLinePanel, sqlRow, translator, true, "non renseigné");
112
 
113
        mainLine.addChild(mainLinePanel);
114
        dataPanel.addChild(mainLine);
115
    }
116
 
93 ilm 117
}