OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 174 | 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
 *
182 ilm 4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
18 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
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
17
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
67 ilm 18
import org.openconcerto.erp.core.customerrelationship.customer.report.FicheClientXmlSheet;
142 ilm 19
import org.openconcerto.erp.preferences.GestionClientPreferencePanel;
67 ilm 20
import org.openconcerto.erp.preferences.PrinterNXProps;
21
import org.openconcerto.ql.LabelCreator;
22
import org.openconcerto.ql.QLPrinter;
18 ilm 23
import org.openconcerto.sql.Configuration;
24
import org.openconcerto.sql.element.SQLComponent;
174 ilm 25
import org.openconcerto.sql.model.FieldPath;
67 ilm 26
import org.openconcerto.sql.model.SQLRowAccessor;
18 ilm 27
import org.openconcerto.sql.model.SQLRowValues;
182 ilm 28
import org.openconcerto.sql.model.Where;
174 ilm 29
import org.openconcerto.sql.model.graph.Path;
142 ilm 30
import org.openconcerto.sql.preferences.SQLPreferences;
182 ilm 31
import org.openconcerto.sql.request.ComboSQLRequest;
18 ilm 32
import org.openconcerto.sql.request.ListSQLRequest;
174 ilm 33
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn;
67 ilm 34
import org.openconcerto.sql.view.list.IListe;
35
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
36
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
174 ilm 37
import org.openconcerto.sql.view.list.SQLTableModelSource;
67 ilm 38
import org.openconcerto.ui.EmailComposer;
174 ilm 39
import org.openconcerto.utils.CollectionUtils;
67 ilm 40
import org.openconcerto.utils.ExceptionHandler;
18 ilm 41
 
67 ilm 42
import java.awt.Font;
43
import java.awt.event.ActionEvent;
18 ilm 44
import java.util.ArrayList;
132 ilm 45
import java.util.Arrays;
182 ilm 46
import java.util.Collections;
18 ilm 47
import java.util.List;
174 ilm 48
import java.util.Set;
18 ilm 49
 
67 ilm 50
import javax.swing.AbstractAction;
51
 
18 ilm 52
public class ClientNormalSQLElement extends ComptaSQLConfElement {
53
 
54
    public ClientNormalSQLElement() {
55
        super("CLIENT", "un client", "clients");
144 ilm 56
        try {
57
            final String property = PrinterNXProps.getInstance().getProperty("QLPrinter");
58
                if (property != null && property.trim().length() > 0) {
59
                    PredicateRowAction actionPrintLabel = new PredicateRowAction(new AbstractAction() {
67 ilm 60
 
144 ilm 61
                        @Override
62
                        public void actionPerformed(ActionEvent e) {
63
                            final SQLRowAccessor row = IListe.get(e).fetchSelectedRow();
64
                            printLabel(row, property);
65
                        }
66
                    }, false, "customerrelationship.customer.label.print");
67
                    actionPrintLabel.setPredicate(IListeEvent.getSingleSelectionPredicate());
68
                    getRowActions().add(actionPrintLabel);
69
                }
70
 
71
                PredicateRowAction actionFicheClient = new PredicateRowAction(new AbstractAction() {
67 ilm 72
                    @Override
73
                    public void actionPerformed(ActionEvent e) {
80 ilm 74
                        final SQLRowAccessor row = IListe.get(e).fetchSelectedRow();
144 ilm 75
                        FicheClientXmlSheet sheet = new FicheClientXmlSheet(row.asRow());
76
                        sheet.createDocumentAsynchronous();
182 ilm 77
                        sheet.showPrintAndExportAsynchronous(true, false, true, Collections.emptyList());
67 ilm 78
                    }
144 ilm 79
                }, false, "customerrelationship.customer.info.create");
80
                actionFicheClient.setPredicate(IListeEvent.getSingleSelectionPredicate());
81
                getRowActions().add(actionFicheClient);
67 ilm 82
 
144 ilm 83
 
84
            PredicateRowAction action = new PredicateRowAction(new AbstractAction() {
85
 
132 ilm 86
                @Override
87
                public void actionPerformed(ActionEvent e) {
144 ilm 88
                    sendMail(IListe.get(e).getSelectedRows());
89
 
132 ilm 90
                }
144 ilm 91
            }, true, "customerrelationship.customer.email.send");
92
            action.setPredicate(IListeEvent.getNonEmptySelectionPredicate());
93
            getRowActions().add(action);
67 ilm 94
 
144 ilm 95
        } catch (Exception e) {
96
            e.printStackTrace();
97
        }
18 ilm 98
    }
99
 
142 ilm 100
    public void printLabel(SQLRowAccessor row, String qlPrinterProperty) {
101
        final LabelCreator c = new LabelCreator(720);
102
        c.setLeftMargin(10);
103
        c.setTopMargin(10);
104
        c.setDefaultFont(new Font("Verdana", Font.PLAIN, 50));
105
        c.addLineBold(row.getString("NOM"));
106
        final SQLRowAccessor foreignRow = row.asRow().getForeign("ID_ADRESSE");
107
        final String string = foreignRow.getString("RUE");
108
        String[] s = string.split("\n");
109
        for (String string2 : s) {
110
            c.addLineNormal(string2);
111
        }
112
        c.addLineNormal(foreignRow.getString("CODE_POSTAL") + " " + foreignRow.getString("VILLE"));
113
 
114
        final String pays = foreignRow.getString("PAYS");
115
        if (pays != null && pays.trim().length() > 0 && !pays.equalsIgnoreCase(ComptaPropsConfiguration.getInstanceCompta().getRowSociete().getForeignRow("ID_ADRESSE_COMMON").getString("PAYS"))) {
116
            c.addLineNormal(pays);
117
        }
118
 
119
        final QLPrinter prt = new QLPrinter(qlPrinterProperty);
120
        try {
121
            prt.print(c.getImage());
122
        } catch (Exception ex) {
123
            ex.printStackTrace();
124
        }
125
    }
126
 
93 ilm 127
    protected void sendMail(List<SQLRowValues> l) {
67 ilm 128
 
129
        String mail = "";
130
            for (SQLRowAccessor rowCli : l) {
131
                String string = rowCli.getString("MAIL");
93 ilm 132
 
133
                if (string == null) {
134
                    // Refetch au cas où la colonne n'est pas présente dans la liste
135
                    string = rowCli.asRow().getString("MAIL");
136
                }
67 ilm 137
                if (string != null && string.trim().length() > 0) {
138
                    mail += string + ";";
139
                }
140
            }
141
        try {
142
            EmailComposer.getInstance().compose(mail, "", "");
143
        } catch (Exception exn) {
144
            ExceptionHandler.handle(null, "Impossible de créer le courriel", exn);
145
        }
146
 
147
    }
148
 
18 ilm 149
    protected boolean showMdr = true;
150
 
151
    protected List<String> getListFields() {
152
        final List<String> l = new ArrayList<String>();
153
            l.add("CODE");
154
        l.add("NOM");
41 ilm 155
        l.add("RESPONSABLE");
18 ilm 156
        l.add("ID_ADRESSE");
157
        l.add("TEL");
80 ilm 158
        l.add("TEL_P");
18 ilm 159
        l.add("FAX");
160
        l.add("MAIL");
161
            l.add("NUMERO_TVA");
162
            l.add("SIRET");
163
            l.add("ID_COMPTE_PCE");
164
            l.add("ID_MODE_REGLEMENT");
165
        l.add("INFOS");
149 ilm 166
        l.add("ID_COMMERCIAL");
18 ilm 167
        return l;
168
    }
169
 
170
    @Override
132 ilm 171
    protected void _initListRequest(ListSQLRequest req) {
172
        super._initListRequest(req);
173
        req.addForeignToGraphToFetch("ID_MODE_REGLEMENT", Arrays.asList("AJOURS", "LENJOUR"));
18 ilm 174
    }
175
 
176
    protected List<String> getComboFields() {
177
        final List<String> l = new ArrayList<String>();
93 ilm 178
        l.add("GROUPE");
18 ilm 179
        l.add("NOM");
25 ilm 180
        if (getTable().getFieldsName().contains("LOCALISATION")) {
181
            l.add("LOCALISATION");
182
        } else {
183
            l.add("CODE");
184
        }
142 ilm 185
        SQLPreferences prefs = SQLPreferences.getMemCached(getTable().getDBRoot());
186
        if (prefs.getBoolean(GestionClientPreferencePanel.DISPLAY_CLIENT_PCE, false)) {
187
            l.add("ID_COMPTE_PCE");
188
        }
18 ilm 189
        return l;
190
    }
191
 
174 ilm 192
    @Override
193
    protected void _initTableSource(SQLTableModelSource res) {
194
        super._initTableSource(res);
195
 
196
        res.getColumns().add(new BaseSQLTableModelColumn(getDirectory().getTranslator().getLabelFor(getTable().getField("CATEGORIES")), String.class) {
197
 
198
            @Override
199
            protected Object show_(SQLRowAccessor r) {
200
 
201
                return r.getString("CATEGORIES");
202
            }
203
 
204
            @Override
205
            public Set<FieldPath> getPaths() {
206
                Path p = new Path(getTable());
207
                return CollectionUtils.createSet(new FieldPath(p, "CATEGORIES"));
208
 
209
            }
210
        });
211
 
212
    }
213
 
182 ilm 214
    @Override
215
    protected void _initComboRequest(ComboSQLRequest req) {
216
        super._initComboRequest(req);
217
        req.setWhere(new Where(getTable().getField("OBSOLETE"), "=", Boolean.FALSE));
218
    }
219
 
18 ilm 220
    /*
221
     * (non-Javadoc)
222
     *
223
     * @see org.openconcerto.devis.SQLElement#getComponent()
224
     */
225
    public SQLComponent createComponent() {
28 ilm 226
        return new ClientNormalSQLComponent(this);
18 ilm 227
    }
228
 
156 ilm 229
    @Override
230
    protected String createCode() {
231
        return "customerrelationship.customer";
232
    }
18 ilm 233
}