OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 83 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 83 Rev 156
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
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
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
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.
9
 * language governing permissions and limitations under the License.
10
 * 
10
 * 
11
 * When distributing the software, include this License Header Notice in each file.
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.erp.core.sales.quote.action;
14
 package org.openconcerto.erp.core.sales.quote.action;
15
 
15
 
16
import org.openconcerto.erp.action.CreateListFrameAbstractAction;
16
import org.openconcerto.erp.action.CreateListFrameAbstractAction;
17
import org.openconcerto.erp.config.ComptaPropsConfiguration;
17
import org.openconcerto.erp.config.ComptaPropsConfiguration;
18
import org.openconcerto.erp.core.common.ui.IListFilterDatePanel;
-
 
19
import org.openconcerto.erp.core.common.ui.IListTotalPanel;
-
 
20
import org.openconcerto.erp.core.common.ui.PanelFrame;
18
import org.openconcerto.erp.core.common.ui.PanelFrame;
21
import org.openconcerto.erp.core.sales.invoice.ui.ListeFactureRenderer;
-
 
22
import org.openconcerto.erp.core.sales.quote.element.DevisSQLElement;
19
import org.openconcerto.erp.core.sales.quote.element.DevisSQLElement;
23
import org.openconcerto.erp.core.sales.quote.element.EtatDevisSQLElement;
-
 
24
import org.openconcerto.erp.core.sales.quote.report.DevisTextSheet;
-
 
25
import org.openconcerto.erp.core.sales.quote.ui.ListeDesDevisPanel;
20
import org.openconcerto.erp.core.sales.quote.ui.ListeDesDevisPanel;
26
import org.openconcerto.erp.generationDoc.DocumentLocalStorageManager;
-
 
27
import org.openconcerto.erp.generationDoc.SheetUtils;
-
 
28
import org.jopendocument.link.OOConnexion;
-
 
29
import org.openconcerto.sql.Configuration;
-
 
30
import org.openconcerto.sql.model.SQLField;
-
 
31
import org.openconcerto.sql.model.SQLRow;
-
 
32
import org.openconcerto.sql.model.SQLRowValues;
-
 
33
import org.openconcerto.sql.view.IListFrame;
-
 
34
import org.openconcerto.sql.view.ListeAddPanel;
-
 
35
import org.openconcerto.sql.view.list.IListe;
-
 
36
import org.openconcerto.sql.view.list.SQLTableModelColumn;
-
 
37
import org.openconcerto.sql.view.list.SQLTableModelColumnPath;
-
 
38
import org.openconcerto.sql.view.list.SQLTableModelSource;
-
 
39
import org.openconcerto.ui.DefaultGridBagConstraints;
-
 
40
import org.openconcerto.ui.table.TableCellRendererUtils;
-
 
41
import org.openconcerto.utils.ExceptionHandler;
-
 
42
 
21
 
43
import java.awt.Component;
-
 
44
import java.awt.Font;
-
 
45
import java.awt.GridBagConstraints;
-
 
46
import java.awt.event.ActionEvent;
-
 
47
import java.awt.event.ActionListener;
22
public class ListeDesDevisAction extends CreateListFrameAbstractAction<DevisSQLElement, PanelFrame> {
48
import java.awt.event.MouseEvent;
-
 
49
import java.awt.event.MouseListener;
-
 
50
import java.io.File;
-
 
51
import java.sql.SQLException;
-
 
52
import java.text.DateFormat;
-
 
53
import java.text.DecimalFormat;
-
 
54
import java.text.SimpleDateFormat;
-
 
55
import java.util.ArrayList;
-
 
56
import java.util.Date;
-
 
57
import java.util.List;
-
 
58
 
23
 
59
import javax.swing.AbstractAction;
-
 
60
import javax.swing.Action;
-
 
61
import javax.swing.JFrame;
-
 
62
import javax.swing.JLabel;
-
 
63
import javax.swing.JMenu;
-
 
64
import javax.swing.JMenuItem;
-
 
65
import javax.swing.JOptionPane;
-
 
66
import javax.swing.JPopupMenu;
-
 
67
import javax.swing.JTable;
-
 
68
import javax.swing.SwingConstants;
-
 
69
import javax.swing.table.DefaultTableCellRenderer;
-
 
70
 
-
 
71
public class ListeDesDevisAction extends CreateListFrameAbstractAction implements MouseListener {
-
 
72
 
-
 
73
    DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm");
-
 
74
 
-
 
75
    public ListeDesDevisAction() {
24
    public ListeDesDevisAction(final ComptaPropsConfiguration conf) {
76
        super();
-
 
77
        final String pluralName = this.element.getPluralName();
-
 
78
        this.putValue(Action.NAME, "Liste des " + pluralName);
-
 
79
    }
-
 
80
 
-
 
81
    IListFrame frame = null;
-
 
82
    final DevisSQLElement element = (DevisSQLElement) Configuration.getInstance().getDirectory().getElement("DEVIS");
-
 
83
 
-
 
84
    public String getTableName() {
-
 
85
        return "DEVIS";
-
 
86
    }
-
 
87
 
-
 
88
    public JFrame createFrame() {
-
 
89
            final String pluralName = this.element.getPluralName();
-
 
90
            final PanelFrame frame2 = new PanelFrame(new ListeDesDevisPanel(), "Liste des " + pluralName);
-
 
91
            return frame2;
-
 
92
    }
-
 
93
 
-
 
94
    public void mouseClicked(MouseEvent e) {
-
 
95
    }
-
 
96
 
-
 
97
    public void mousePressed(MouseEvent e) {
-
 
98
 
-
 
99
        int selectedId = this.frame.getPanel().getListe().getSelectedId();
-
 
100
        if (selectedId > 1 && e.getButton() == MouseEvent.BUTTON3) {
-
 
101
 
-
 
102
            final SQLRow row = this.frame.getPanel().getListe().fetchSelectedRow();
-
 
103
            JPopupMenu menu = new JPopupMenu();
-
 
104
            final DevisTextSheet s = new DevisTextSheet(row);
-
 
105
 
-
 
106
            // Voir le document
-
 
107
            AbstractAction actionOpen = new AbstractAction("Voir le document") {
-
 
108
                public void actionPerformed(ActionEvent e) {
-
 
109
                    s.generate(false, false, "");
-
 
110
                    s.showDocument();
25
        super(conf, DevisSQLElement.class);
111
                }
26
    }
112
            };
-
 
113
            JMenuItem openItem = new JMenuItem(actionOpen);
-
 
114
            openItem.setFont(openItem.getFont().deriveFont(Font.BOLD));
-
 
115
            menu.add(openItem);
-
 
116
 
-
 
117
            final File outpuDirectory = DocumentLocalStorageManager.getInstance().getDocumentOutputDirectory(s.getTemplateId());
-
 
118
            List<File> files = SheetUtils.getHistorique(s.getFileName(), outpuDirectory);
-
 
119
            if (files.size() > 0) {
-
 
120
                JMenu item = new JMenu("Historique");
-
 
121
                int i = 0;
-
 
122
                for (final File file : files) {
-
 
123
                    JMenuItem subItem = new JMenuItem("Version " + i + " du " + this.dateFormat.format(new Date(file.lastModified())));
-
 
124
                    subItem.addActionListener(new ActionListener() {
-
 
125
 
27
 
126
                        @Override
28
    @Override
127
                        public void actionPerformed(ActionEvent e) {
-
 
128
                            if (file.exists()) {
-
 
129
                                try {
-
 
130
                                    final OOConnexion ooConnexion = ComptaPropsConfiguration.getOOConnexion();
-
 
131
                                    if (ooConnexion == null) {
-
 
132
                                        return;
-
 
133
                                    }
-
 
134
                                    ooConnexion.loadDocument(file, false);
-
 
135
 
-
 
136
                                } catch (LinkageError ex) {
-
 
137
                                    JOptionPane.showMessageDialog(new JFrame(), "Merci d'installer OpenOffice ou LibreOffice");
-
 
138
                                } catch (Exception ex) {
-
 
139
                                    ex.printStackTrace();
-
 
140
                                    ExceptionHandler.handle("Impossible de charger le document OpenOffice", ex);
-
 
141
                                }
-
 
142
 
-
 
143
                            }
-
 
144
                        }
-
 
145
                    });
-
 
146
                    i++;
-
 
147
                    item.add(subItem);
-
 
148
 
-
 
149
                }
-
 
150
                menu.add(item);
-
 
151
            }
-
 
152
 
-
 
153
            AbstractAction actionAcc = new AbstractAction("Marquer comme accepté") {
-
 
154
                public void actionPerformed(ActionEvent e) {
-
 
155
                    SQLRowValues rowVals = IListe.get(e).fetchSelectedRow().createEmptyUpdateRow();
-
 
156
                    rowVals.put("ID_ETAT_DEVIS", EtatDevisSQLElement.ACCEPTE);
-
 
157
                    try {
-
 
158
                        rowVals.update();
-
 
159
                    } catch (SQLException e1) {
-
 
160
                        // TODO Auto-generated catch block
-
 
161
                        e1.printStackTrace();
-
 
162
                    }
-
 
163
                    IListe.get(e).fetchSelectedRow().getTable().fireTableModified(IListe.get(e).getSelectedId());
-
 
164
                }
-
 
165
            };
-
 
166
            menu.add(actionAcc);
-
 
167
 
-
 
168
            AbstractAction actionRefus = new AbstractAction("Marquer comme refusé") {
-
 
169
                public void actionPerformed(ActionEvent e) {
-
 
170
                    SQLRowValues rowVals = IListe.get(e).fetchSelectedRow().createEmptyUpdateRow();
-
 
171
                    rowVals.put("ID_ETAT_DEVIS", EtatDevisSQLElement.REFUSE);
-
 
172
                    try {
-
 
173
                        rowVals.update();
-
 
174
                    } catch (SQLException e1) {
-
 
175
                        // TODO Auto-generated catch block
-
 
176
                        e1.printStackTrace();
29
    protected PanelFrame instantiateFrame() {
177
                    }
-
 
178
                    IListe.get(e).fetchSelectedRow().getTable().fireTableModified(IListe.get(e).getSelectedId());
-
 
179
                }
-
 
180
            };
-
 
181
            menu.add(actionRefus);
-
 
182
 
-
 
183
            // Voir le document
-
 
184
            AbstractAction actionTransfert = new AbstractAction("Transférer en facture") {
-
 
185
                public void actionPerformed(ActionEvent e) {
-
 
186
 
-
 
187
                    ListeDesDevisAction.this.element.transfertFacture(row.getID());
30
        return new PanelFrame(new ListeDesDevisPanel(), String.valueOf(getValue(NAME)));
188
                }
-
 
189
            };
-
 
190
            menu.add(actionTransfert);
-
 
191
 
-
 
192
            // Impression
-
 
193
            AbstractAction actionPrint = new AbstractAction("Imprimer") {
-
 
194
                public void actionPerformed(ActionEvent e) {
-
 
195
                    s.fastPrintDocument();
-
 
196
                }
-
 
197
            };
-
 
198
            menu.add(actionPrint);
-
 
199
 
-
 
200
            menu.show(e.getComponent(), e.getPoint().x, e.getPoint().y);
-
 
201
        }
-
 
202
    }
-
 
203
 
-
 
204
    public void mouseReleased(MouseEvent e) {
-
 
205
    }
-
 
206
 
-
 
207
    public void mouseEntered(MouseEvent e) {
-
 
208
    }
-
 
209
 
-
 
210
    public void mouseExited(MouseEvent e) {
-
 
211
    }
31
    }
212
 
32
 
213
}
33
}