OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 180 | 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
 *
182 ilm 4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
93 ilm 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
 
182 ilm 16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
142 ilm 17
import org.openconcerto.erp.core.edm.AttachmentAction;
156 ilm 18
import org.openconcerto.erp.core.reports.history.ui.HistoriqueClientFrame;
182 ilm 19
import org.openconcerto.erp.core.sales.product.element.ListeTarifClient;
180 ilm 20
import org.openconcerto.erp.preferences.GestionCommercialeGlobalPreferencePanel;
182 ilm 21
import org.openconcerto.sql.Configuration;
94 ilm 22
import org.openconcerto.sql.element.GlobalMapper;
93 ilm 23
import org.openconcerto.sql.element.GroupSQLComponent;
24
import org.openconcerto.sql.element.SQLComponent;
144 ilm 25
import org.openconcerto.sql.model.SQLRowAccessor;
182 ilm 26
import org.openconcerto.sql.model.SQLRowValues;
180 ilm 27
import org.openconcerto.sql.preferences.SQLPreferences;
182 ilm 28
import org.openconcerto.sql.request.ListSQLRequest;
144 ilm 29
import org.openconcerto.sql.request.SQLFieldTranslator;
156 ilm 30
import org.openconcerto.sql.view.list.IListe;
142 ilm 31
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
182 ilm 32
import org.openconcerto.sql.view.list.RowAction;
142 ilm 33
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
144 ilm 34
import org.openconcerto.ui.light.LightUIElement;
35
import org.openconcerto.ui.light.LightUILine;
36
import org.openconcerto.ui.light.LightUIPanel;
37
import org.openconcerto.ui.light.SimpleTextLine;
93 ilm 38
 
156 ilm 39
import java.awt.event.ActionEvent;
182 ilm 40
import java.util.HashSet;
132 ilm 41
import java.util.List;
182 ilm 42
import java.util.Set;
132 ilm 43
 
156 ilm 44
import javax.swing.AbstractAction;
45
 
93 ilm 46
public class CustomerSQLElement extends ClientNormalSQLElement {
47
 
48
    public CustomerSQLElement() {
49
        super();
94 ilm 50
        final CustomerGroup group = new CustomerGroup();
51
        GlobalMapper.getInstance().map(CustomerGroup.ID, group);
52
        setDefaultGroup(group);
144 ilm 53
 
142 ilm 54
        PredicateRowAction actionAttachment = new PredicateRowAction(new AttachmentAction().getAction(), true);
55
        actionAttachment.setPredicate(IListeEvent.getSingleSelectionPredicate());
56
        getRowActions().add(actionAttachment);
57
 
156 ilm 58
        PredicateRowAction actionHistory = new PredicateRowAction(new AbstractAction("Historique client") {
59
 
60
            @Override
61
            public void actionPerformed(ActionEvent e) {
62
                HistoriqueClientFrame histoFrame = new HistoriqueClientFrame();
63
                int idClient = IListe.get(e).getSelectedId();
64
                histoFrame.selectId(idClient);
65
                histoFrame.setVisible(true);
66
            }
67
        }, true);
68
        actionHistory.setPredicate(IListeEvent.getSingleSelectionPredicate());
69
        getRowActions().add(actionHistory);
70
 
182 ilm 71
        RowAction actionTarif = new RowAction(new AbstractAction("Tarifs associés") {
72
 
73
            @Override
74
            public void actionPerformed(ActionEvent e) {
75
                final ListeTarifClient listeHistoCodeClient = new ListeTarifClient(((ComptaPropsConfiguration) Configuration.getInstance()).getRootSociete());
76
                int idClient = IListe.get(e).getSelectedRowAccessor().getForeignID("ID_TARIF");
77
                listeHistoCodeClient.getHistoriquePanel().selectIDinJList(idClient);
78
                listeHistoCodeClient.getFrame().setVisible(true);
79
            }
80
 
81
        }, true) {
82
            @Override
83
            public boolean enabledFor(List<SQLRowValues> selection) {
84
                if (selection != null && selection.size() == 1) {
85
                    return !selection.get(0).isForeignEmpty("ID_TARIF");
86
                } else {
87
                    return false;
88
                }
89
            }
90
        };
91
        getRowActions().add(actionTarif);
92
 
93 ilm 93
    }
94
 
182 ilm 95
    protected void _initListRequest(final ListSQLRequest req) {
96
        super._initListRequest(req);
97
        req.addToGraphToFetch("ID_TARIF");
98
    }
99
 
93 ilm 100
    @Override
101
    public SQLComponent createComponent() {
102
        final GroupSQLComponent c = new CustomerSQLComponent(this);
103
        c.startTabGroupAfter("customerrelationship.customer.identifier");
104
        return c;
105
    }
132 ilm 106
 
107
    @Override
182 ilm 108
    public Set<String> getReadOnlyFields() {
109
        Set<String> s = new HashSet<>();
110
        return s;
111
    }
112
 
113
    @Override
132 ilm 114
    protected List<String> getListFields() {
115
        final List<String> fields = super.getListFields();
182 ilm 116
 
142 ilm 117
        if (getTable().contains("GROUPE")) {
118
            fields.add("GROUPE");
119
        }
182 ilm 120
        fields.add("ENCOURS_MAX");
180 ilm 121
        SQLPreferences prefs = new SQLPreferences(getTable().getDBRoot());
122
 
123
        if (prefs.getBoolean(GestionCommercialeGlobalPreferencePanel.CATEGORIE_COMPTABLE_SPEC, false)) {
124
            fields.add("ID_CATEGORIE_COMPTABLE");
125
        }
142 ilm 126
        fields.add("SOLDE_COMPTE");
127
        fields.add("REMIND_DATE");
132 ilm 128
        fields.add("OBSOLETE");
129
        return fields;
130
    }
144 ilm 131
 
132
    @Override
133
    protected void fillDataPanel(final String sessionToken, final List<SQLRowAccessor> selection, final LightUIPanel dataPanel) {
134
        final SQLFieldTranslator translator = this.getDirectory().getTranslator();
135
        final SQLRowAccessor sqlRow = selection.get(0);
136
 
137
        final int rowId = sqlRow.getID();
138
        final LightUILine mainLine = new LightUILine();
139
        final LightUIPanel mainLinePanel = new LightUIPanel(dataPanel.getId() + ".main.line." + rowId);
140
        mainLinePanel.setWeightX(1);
141
 
142
        final SimpleTextLine spacer = new SimpleTextLine("", true, LightUIElement.HALIGN_LEFT, 2);
143
        spacer.setMarginBottom(4);
144
 
145
        String name = sqlRow.getString("NOM");
146
 
147
        mainLinePanel.addChild(new SimpleTextLine(name, true, LightUIElement.HALIGN_LEFT));
148
 
149
        final SimpleTextLine titleSituationContact = new SimpleTextLine("Coordonnées du client", true, LightUIElement.HALIGN_LEFT, 2);
150
        titleSituationContact.setMarginTop(10);
151
        mainLinePanel.addChild(titleSituationContact);
152
 
153
        addFieldToPanel("TEL", mainLinePanel, sqlRow, translator, true, "non renseigné");
154
        addFieldToPanel("MAIL", mainLinePanel, sqlRow, translator, true, "non renseigné");
155
 
156
        mainLine.addChild(mainLinePanel);
157
        dataPanel.addChild(mainLine);
158
    }
159
 
93 ilm 160
}