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
180 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.
180 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.sales.invoice.report;
15
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
17
import org.openconcerto.sql.Configuration;
18
import org.openconcerto.sql.element.SQLElement;
19
import org.openconcerto.sql.model.SQLRow;
20
import org.openconcerto.sql.request.ComboSQLRequest;
21
import org.openconcerto.sql.sqlobject.ElementComboBox;
22
import org.openconcerto.ui.DefaultGridBagConstraints;
23
import org.openconcerto.ui.EmailComposer;
24
import org.openconcerto.ui.JLabelBold;
25
import org.openconcerto.utils.ExceptionHandler;
26
import org.openconcerto.utils.FileUtils;
27
 
28
import java.awt.GridBagConstraints;
29
import java.awt.GridBagLayout;
30
import java.awt.event.ActionEvent;
31
import java.beans.PropertyChangeEvent;
32
import java.beans.PropertyChangeListener;
33
import java.io.File;
34
 
35
import javax.swing.AbstractAction;
36
import javax.swing.JButton;
37
import javax.swing.JCheckBox;
38
import javax.swing.JPanel;
39
 
40
public class SituationCompteClientPanel extends JPanel {
41
 
42
    public SituationCompteClientPanel(ComptaPropsConfiguration conf) {
43
        super(new GridBagLayout());
44
 
45
        JLabelBold title = new JLabelBold("Génération d'une situation de compte d'un client");
46
 
47
        final ElementComboBox box = new ElementComboBox(true);
48
        SQLElement element = Configuration.getInstance().getDirectory().getElement("CLIENT");
49
        ComboSQLRequest comboRequest = element.getComboRequest(true);
50
        // comboRequest.setUndefLabel("Tous");
51
        box.init(element, comboRequest);
52
 
53
        GridBagConstraints c = new DefaultGridBagConstraints();
54
        c.gridwidth = 1;
55
        c.weightx = 0;
56
        this.add(title, c);
57
        c.gridx++;
58
        c.gridwidth = 1;
59
        c.weightx = 1;
60
        this.add(box, c);
61
 
62
        final JCheckBox boxMail = new JCheckBox("Envoie par mail");
63
        c.gridx++;
64
        c.weightx = 0;
65
        this.add(boxMail, c);
66
 
67
        final JButton buttonValid = new JButton(new AbstractAction("Valider") {
68
 
69
            @Override
70
            public void actionPerformed(ActionEvent e) {
71
 
72
                final SQLRow selectedClient = box.getSelectedRow();
73
                new Thread() {
74
                    public void run() {
75
 
76
                        try {
77
                            SituationCompteXmlSheet sheet = new SituationCompteXmlSheet(conf, selectedClient);
78
                            File pdf = sheet.getOrCreatePDFDocumentFile(true);
79
                            if (boxMail.isSelected()) {
80
                                sheet.createDocument();
81
                                // sheet.showPrintAndExport(false, false, false);
82
 
83
                                String mail = selectedClient.getString("MAIL");
84
 
85
                                try {
86
                                    EmailComposer.getInstance().compose(mail, "", "", pdf);
87
                                } catch (Exception exn) {
88
                                    ExceptionHandler.handle(null, "Impossible de créer le courriel", exn);
89
                                }
90
                            } else {
91
                                FileUtils.openFile(pdf);
92
                            }
93
                        } catch (Exception e) {
94
                            ExceptionHandler.handle("Une erreur est survenue lors de la création du document", e);
95
                        }
96
                    };
97
                }.start();
98
 
99
            }
100
        });
101
 
102
        c.gridy++;
103
        c.fill = GridBagConstraints.NONE;
104
        c.anchor = GridBagConstraints.EAST;
105
        c.weightx = 0;
106
        this.add(buttonValid, c);
107
 
108
        // Listener enabled/disabled button
109
        buttonValid.setEnabled(false);
110
        box.addModelListener("wantedID", new PropertyChangeListener() {
111
 
112
            @Override
113
            public void propertyChange(PropertyChangeEvent arg0) {
114
                buttonValid.setEnabled(box.getWantedID() != SQLRow.NONEXISTANT_ID && box.getWantedID() != box.getRequest().getPrimaryTable().getUndefinedID());
115
            }
116
        });
117
    }
118
}