OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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