OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 19 | Rev 67 | 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.finance.payment.action;
15
 
16
import org.openconcerto.erp.action.CreateFrameAbstractAction;
17
import org.openconcerto.erp.core.sales.invoice.report.VenteFactureXmlSheet;
18
import org.openconcerto.erp.generationDoc.gestcomm.FicheRelanceSheet;
19
import org.openconcerto.erp.generationDoc.gestcomm.RelanceSheet;
20
import org.openconcerto.erp.preferences.PrinterNXProps;
21
import org.openconcerto.sql.Configuration;
22
import org.openconcerto.sql.element.SQLElement;
23
import org.openconcerto.sql.model.SQLRow;
24
import org.openconcerto.sql.view.IListFrame;
25
import org.openconcerto.sql.view.ListeAddPanel;
26
import org.openconcerto.sql.view.list.SQLTableModelColumn;
27
import org.openconcerto.sql.view.list.SQLTableModelColumnPath;
28
import org.openconcerto.sql.view.list.SQLTableModelSourceOnline;
25 ilm 29
import org.openconcerto.utils.ExceptionHandler;
18 ilm 30
 
31
import java.awt.event.ActionEvent;
32
import java.awt.event.MouseEvent;
33
import java.awt.event.MouseListener;
34
 
35
import javax.swing.AbstractAction;
36
import javax.swing.Action;
37
import javax.swing.JFrame;
38
import javax.swing.JPopupMenu;
39
 
40
public class ListeDesRelancesAction extends CreateFrameAbstractAction implements MouseListener {
41
 
42
    private IListFrame frame;
43
 
44
    public ListeDesRelancesAction() {
45
        super();
46
        this.putValue(Action.NAME, "Liste des relances");
47
    }
48
 
49
    public JFrame createFrame() {
50
        final SQLElement elt = Configuration.getInstance().getDirectory().getElement("RELANCE");
51
        this.frame = new IListFrame(new ListeAddPanel(elt));
52
 
53
        final SQLTableModelSourceOnline src = (SQLTableModelSourceOnline) this.frame.getPanel().getListe().getModel().getReq();
54
 
55
        this.frame.getPanel().getListe().setSQLEditable(true);
56
 
57
        for (SQLTableModelColumn column : src.getColumns()) {
58
            if (column.getClass().isAssignableFrom(SQLTableModelColumnPath.class)) {
59
                ((SQLTableModelColumnPath) column).setEditable(false);
60
            }
61
        }
62
 
63
        ((SQLTableModelColumnPath) src.getColumns(elt.getTable().getField("INFOS")).iterator().next()).setEditable(true);
64
 
65
        this.frame.getPanel().getListe().getJTable().addMouseListener(this);
66
        this.frame.getPanel().setAddVisible(false);
67
        return this.frame;
68
    }
69
 
70
    public void mouseClicked(MouseEvent e) {
71
    }
72
 
73
    public void mousePressed(MouseEvent e) {
74
 
75
        int selectedId = this.frame.getPanel().getListe().getSelectedId();
76
        if (selectedId > 1 && e.getButton() == MouseEvent.BUTTON3) {
77
 
78
            // String locationRelance =
79
            // TemplateNXProps.getInstance().getStringProperty("LocationRelanceOO");
80
            final SQLRow rowRelance = this.frame.getPanel().getListe().getSelectedRow();
81
            // final String fileName = "Relance_" + rowRelance.getString("NUMERO");
82
            // final File fileOutOO = new File(locationRelance, fileName + ".odt");
83
            JPopupMenu menu = new JPopupMenu();
84
            final RelanceSheet s = new RelanceSheet(rowRelance);
85
 
86
            // Voir le document
87
            AbstractAction actionOpen = new AbstractAction("Voir le document") {
88
                public void actionPerformed(ActionEvent e) {
89
                    s.generate(false, false, "");
90
                    s.showDocument();
91
                }
92
            };
93
            // actionOpen.setEnabled(s.exists());
94
            menu.add(actionOpen);
95
 
96
            // Impression
97
            AbstractAction actionPrint = new AbstractAction("Imprimer") {
98
                public void actionPerformed(ActionEvent e) {
99
                    s.fastPrintDocument();
100
                }
101
            };
102
            menu.add(actionPrint);
103
 
104
            // Impression
105
            AbstractAction actionPrintFact = new AbstractAction("Imprimer la facture") {
106
                public void actionPerformed(ActionEvent e) {
25 ilm 107
                    final Thread t = new Thread(new Runnable() {
18 ilm 108
 
25 ilm 109
                        @Override
110
                        public void run() {
111
                            try {
112
                                printInvoice(rowRelance);
113
                            } catch (Exception e) {
114
                                ExceptionHandler.handle("Impression impossible", e);
115
                            }
116
                        }
117
                    });
118
                    t.start();
119
 
18 ilm 120
                }
121
            };
122
            menu.add(actionPrintFact);
123
 
124
            // Impression
125
 
126
            AbstractAction actionPrintBoth = new AbstractAction("Imprimer la facture et la relance") {
127
                public void actionPerformed(ActionEvent e) {
25 ilm 128
                    final Thread t = new Thread(new Runnable() {
129
                        @Override
130
                        public void run() {
131
                            try {
132
                                s.fastPrintDocument();
133
                                printInvoice(rowRelance);
134
                            } catch (Exception e) {
135
                                ExceptionHandler.handle("Impression impossible", e);
136
                            }
137
                        }
138
                    });
139
                    t.start();
18 ilm 140
                }
141
            };
142
            menu.add(actionPrintBoth);
143
 
144
            // Générer
145
            menu.add(new AbstractAction("Générer") {
146
                public void actionPerformed(ActionEvent e) {
147
 
148
                    String printer = PrinterNXProps.getInstance().getStringProperty("RelancePrinter");
149
                    s.generate(false, true, printer, true);
150
                }
151
            });
152
 
25 ilm 153
            // Créer la fiche de relance
18 ilm 154
            menu.add(new AbstractAction("Créer la fiche de relance") {
155
                public void actionPerformed(ActionEvent e) {
25 ilm 156
                    try {
157
                        FicheRelanceSheet sheet = new FicheRelanceSheet(rowRelance);
158
                        sheet.createDocumentAsynchronous();
159
                        sheet.showPrintAndExportAsynchronous(true, false, true);
160
                    } catch (Exception ex) {
161
                        ExceptionHandler.handle("Impression impossible", ex);
162
                    }
18 ilm 163
                }
164
            });
165
 
166
            menu.show(e.getComponent(), e.getPoint().x, e.getPoint().y);
167
        }
168
    }
169
 
170
    public void mouseReleased(MouseEvent e) {
171
    }
172
 
173
    public void mouseEntered(MouseEvent e) {
174
    }
175
 
176
    public void mouseExited(MouseEvent e) {
177
    }
25 ilm 178
 
179
    private void printInvoice(final SQLRow rowRelance) throws Exception {
180
        final VenteFactureXmlSheet sheet = new VenteFactureXmlSheet(rowRelance.getForeignRow("ID_SAISIE_VENTE_FACTURE"));
181
        sheet.getOrCreateDocumentFile();
182
        sheet.fastPrintDocument();
183
        sheet.showPrintAndExport(false, false, true);
184
    }
18 ilm 185
}