OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 128 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
75 ilm 1
/*
2
 * Créé le 3 juin 2012
3
 */
4
package org.openconcerto.modules.project;
5
 
146 ilm 6
import java.awt.Component;
7
import java.awt.FileDialog;
8
import java.awt.Frame;
75 ilm 9
import java.awt.GridBagConstraints;
146 ilm 10
import java.awt.event.ActionEvent;
75 ilm 11
import java.awt.event.WindowAdapter;
12
import java.awt.event.WindowEvent;
13
import java.io.File;
146 ilm 14
import java.io.FilenameFilter;
15
import java.io.IOException;
16
import java.sql.SQLException;
75 ilm 17
import java.util.Arrays;
128 ilm 18
import java.util.HashMap;
75 ilm 19
import java.util.LinkedHashMap;
20
import java.util.List;
21
import java.util.Map;
22
 
146 ilm 23
import javax.swing.AbstractAction;
75 ilm 24
import javax.swing.JFrame;
146 ilm 25
import javax.swing.JOptionPane;
75 ilm 26
import javax.swing.event.TableModelEvent;
27
import javax.swing.event.TableModelListener;
28
 
29
import org.openconcerto.erp.config.ComptaPropsConfiguration;
30
import org.openconcerto.erp.config.Gestion;
31
import org.openconcerto.erp.core.reports.history.ui.ListeHistoriquePanel;
146 ilm 32
import org.openconcerto.erp.core.supplychain.order.action.ImportProductsToOrder;
75 ilm 33
import org.openconcerto.sql.Configuration;
34
import org.openconcerto.sql.model.SQLBase;
35
import org.openconcerto.sql.request.ComboSQLRequest;
36
import org.openconcerto.sql.view.IListPanel;
146 ilm 37
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
38
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
75 ilm 39
import org.openconcerto.ui.DefaultGridBagConstraints;
40
import org.openconcerto.ui.PanelFrame;
146 ilm 41
import org.openconcerto.ui.SwingThreadUtils;
75 ilm 42
import org.openconcerto.ui.state.WindowStateManager;
43
 
44
public class ProjectHistory {
45
    private PanelFrame panelFrame;
46
    private ListeHistoriquePanel listPanel;
47
 
48
    public ListeHistoriquePanel getHistoriquePanel() {
49
        return this.listPanel;
50
    }
51
 
128 ilm 52
    private static Map<String, List<String>> moduleTab = new HashMap<String, List<String>>();
53
 
54
    public static void addTab(String tabName, List<String> table) {
55
        moduleTab.put(tabName, table);
56
    }
57
 
75 ilm 58
    public ProjectHistory() {
59
 
60
        final ComptaPropsConfiguration comptaPropsConfiguration = ((ComptaPropsConfiguration) Configuration.getInstance());
61
        final SQLBase b = comptaPropsConfiguration.getSQLBaseSociete();
62
 
63
        final Map<String, List<String>> mapList = new LinkedHashMap<String, List<String>>();
64
        mapList.put("Devis", Arrays.asList("DEVIS"));
65
        mapList.put("Bons de commande", Arrays.asList("COMMANDE_CLIENT"));
66
        mapList.put("Factures", Arrays.asList("SAISIE_VENTE_FACTURE"));
67
        mapList.put("Avoirs", Arrays.asList("AVOIR_CLIENT"));
146 ilm 68
        mapList.put("Demandes d'achat", Arrays.asList("DEMANDE_ACHAT_ELEMENT"));
69
        mapList.put("Demandes de prix", Arrays.asList("DEMANDE_PRIX"));
70
        mapList.put("Commandes", Arrays.asList("COMMANDE"));
128 ilm 71
        mapList.put("Achats", Arrays.asList("SAISIE_ACHAT"));
75 ilm 72
 
73
        if (Configuration.getInstance().getRoot().findTable("AFFAIRE_TEMPS") != null) {
74
            mapList.put("Temps", Arrays.asList("AFFAIRE_TEMPS"));
75
        }
76
 
128 ilm 77
        mapList.putAll(moduleTab);
78
 
75 ilm 79
        final ComboSQLRequest request = new org.openconcerto.sql.request.ComboSQLRequest(b.getTable("AFFAIRE"), Arrays.asList("NUMERO", "ID_CLIENT"));
80
        request.setUndefLabel("Toutes les affaires");
81
        request.setFieldSeparator(" ");
82
 
88 ilm 83
        this.listPanel = new ListeHistoriquePanel("Affaires", request, mapList, null, null, "Toutes les affaires", true, null, null);
75 ilm 84
 
85
        final IListPanel listeDevis = listPanel.getIListePanelFromTableName("DEVIS");
86
        GridBagConstraints c = new DefaultGridBagConstraints();
87
        c.gridy = 4;
88
        c.fill = GridBagConstraints.BOTH;
89
        final ProjectHistoryDevisBottomPanel devisPanel = new ProjectHistoryDevisBottomPanel();
90
        listeDevis.add(devisPanel, c);
91
        listeDevis.getListe().getTableModel().addTableModelListener(new TableModelListener() {
92
 
93
            @Override
94
            public void tableChanged(TableModelEvent e) {
95
                devisPanel.updateDevis(listeDevis.getListe());
96
                devisPanel.updateTimeDevis(listeDevis.getListe());
97
            }
98
        });
99
 
146 ilm 100
        final IListPanel listeDmdAchat = listPanel.getIListePanelFromTableName("DEMANDE_ACHAT_ELEMENT");
101
        PredicateRowAction actionDrop = new PredicateRowAction(new AbstractAction("Importer depuis Fichier Inventor") {
102
 
103
            @Override
104
            public void actionPerformed(ActionEvent e) {
105
                final Frame frame = SwingThreadUtils.getAncestorOrSelf(Frame.class, (Component) e.getSource());
106
                final FileDialog fd = new FileDialog(frame, "Import fichier inventor", FileDialog.LOAD);
107
                fd.setFilenameFilter(new FilenameFilter() {
108
                    @Override
109
                    public boolean accept(File dir, String name) {
110
                        return name.endsWith(".xls");
111
                    }
112
                });
113
                fd.setVisible(true);
114
                if (fd.getFile() != null) {
115
 
116
                    ImportProductsToOrder importer = new ImportProductsToOrder();
117
 
118
                    int a = JOptionPane.showConfirmDialog(frame, "Etes vous sûr de vouloir importer ces éléments dans l'affaire N°" + listPanel.getSelectedRow().getString("NUMERO") + "?",
119
                            "Import invertor", JOptionPane.YES_NO_OPTION);
120
                    if (a == JOptionPane.YES_OPTION) {
121
                        importer.setRowAffaire(listPanel.getSelectedRow());
122
                        try {
123
                            importer.importFile(new File(fd.getDirectory(), fd.getFile()), b.getTable("DEMANDE_ACHAT_ELEMENT").getDBRoot());
124
                            listeDmdAchat.getListe().getModel().updateAll();
125
                        } catch (IOException e1) {
126
                            org.openconcerto.utils.ExceptionHandler.handle("Erreur lors de l'import du fichier!", e1);
127
                        } catch (SQLException e1) {
128
                            org.openconcerto.utils.ExceptionHandler.handle("Erreur lors de l'import du fichier!", e1);
129
                        }
130
                    }
131
                }
132
            }
133
        }, true);
134
        actionDrop.setPredicate(IListeEvent.createSelectionCountPredicate(0, Integer.MAX_VALUE));
135
        listeDmdAchat.getListe().addIListeAction(actionDrop);
136
 
75 ilm 137
        final IListPanel listeCmd = listPanel.getIListePanelFromTableName("COMMANDE_CLIENT");
138
        final ProjectHistoryCmdBottomPanel cmdPanel = new ProjectHistoryCmdBottomPanel();
139
 
140
        listeCmd.add(cmdPanel, c);
141
        listeCmd.getListe().getTableModel().addTableModelListener(new TableModelListener() {
142
 
143
            @Override
144
            public void tableChanged(TableModelEvent e) {
145
                cmdPanel.updateCmd(listeCmd.getListe());
146
                cmdPanel.updateTimeCmd(listeCmd.getListe());
147
            }
148
        });
149
 
88 ilm 150
        // If time tracking is installed
75 ilm 151
        final IListPanel listeTemps = listPanel.getIListePanelFromTableName("AFFAIRE_TEMPS");
88 ilm 152
        if (listeTemps != null) {
153
            final ProjectHistoryTimeBottomPanel timePanel = new ProjectHistoryTimeBottomPanel();
154
            listeTemps.add(timePanel, c);
155
            listeTemps.getListe().getTableModel().addTableModelListener(new TableModelListener() {
75 ilm 156
 
88 ilm 157
                @Override
158
                public void tableChanged(TableModelEvent e) {
159
                    timePanel.updateTime(listeTemps.getListe());
160
                }
161
            });
162
        }
163
        // History
75 ilm 164
        this.panelFrame = new PanelFrame(this.listPanel, "Historique affaires");
165
        this.panelFrame.addWindowListener(new WindowAdapter() {
166
            public void windowClosing(WindowEvent e) {
167
                listPanel.removeAllTableListener();
168
            };
169
        });
170
 
171
        this.panelFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
172
 
173
    }
174
 
175
    public PanelFrame getFrame() {
176
        this.panelFrame.setIconImages(Gestion.getFrameIcon());
146 ilm 177
        final WindowStateManager stateManager = new WindowStateManager(this.panelFrame,
178
                new File(Configuration.getInstance().getConfDir(), "Configuration" + File.separator + "Frame" + File.separator + "HistoAffaires.xml"), true);
75 ilm 179
        this.panelFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
180
        this.panelFrame.pack();
181
        this.panelFrame.setLocationRelativeTo(null);
182
        stateManager.loadState();
183
        return this.panelFrame;
184
    }
185
}