OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 80 | 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.accounting.ui;
15
 
16
import org.openconcerto.erp.core.finance.accounting.element.EcritureSQLElement;
17
import org.openconcerto.erp.core.finance.accounting.element.MouvementSQLElement;
18
import org.openconcerto.erp.element.objet.ClasseCompte;
19
import org.openconcerto.erp.rights.ComptaUserRight;
20
import org.openconcerto.sql.Configuration;
21
import org.openconcerto.sql.element.SQLElement;
22
import org.openconcerto.sql.model.SQLRow;
23
import org.openconcerto.sql.model.SQLSelect;
19 ilm 24
import org.openconcerto.sql.model.SQLSystem;
18 ilm 25
import org.openconcerto.sql.model.Where;
144 ilm 26
import org.openconcerto.sql.users.rights.UserRightsManager;
18 ilm 27
import org.openconcerto.sql.view.ListeAddPanel;
19 ilm 28
import org.openconcerto.sql.view.list.IListe;
29
import org.openconcerto.sql.view.list.SQLTableModelSourceOnline;
18 ilm 30
import org.openconcerto.ui.DefaultGridBagConstraints;
31
import org.openconcerto.utils.cc.ITransformer;
32
 
33
import java.awt.GridBagConstraints;
34
import java.awt.GridBagLayout;
35
import java.awt.event.ActionEvent;
36
import java.awt.event.MouseAdapter;
37
import java.awt.event.MouseEvent;
38
 
39
import javax.swing.AbstractAction;
40
import javax.swing.JPanel;
41
import javax.swing.JPopupMenu;
42
import javax.swing.JScrollPane;
43
import javax.swing.JTabbedPane;
44
import javax.swing.JTable;
45
 
46
public class ListeEcritureParClassePanel extends JPanel {
47
 
48
    public ListeEcritureParClassePanel() {
49
 
50
        super(new GridBagLayout());
51
        GridBagConstraints c = new DefaultGridBagConstraints();
52
 
53
        JTabbedPane tabbedClasseCpt = new JTabbedPane();
54
 
55
        // On recupere les differentes classes
56
        // SQLBase base = ((ComptaPropsConfiguration)
57
        // Configuration.getInstance()).getSQLBaseSociete();
58
        // SQLTable classeCompteTable = base.getTable("CLASSE_COMPTE");
59
        //
60
        // SQLSelect selClasse = new SQLSelect(base);
61
        //
62
        // selClasse.addSelect(classeCompteTable.getField("ID"));
63
        // selClasse.addSelect(classeCompteTable.getField("NOM"));
64
        // selClasse.addSelect(classeCompteTable.getField("TYPE_NUMERO_COMPTE"));
65
        //
66
        // selClasse.addRawOrder("\"CLASSE_COMPTE\".\"TYPE_NUMERO_COMPTE\"");
67
        //
68
        // String reqClasse = selClasse.asString();
69
        // System.err.println(reqClasse);
70
        // List<Map<String, Object>> obClasse = base.getDataSource().execute(reqClasse);
71
        //
72
        // for (Map<String, Object> map : obClasse) {
73
        //
74
        // ClasseCompte ccTmp = new ClasseCompte(Integer.parseInt(map.get("ID").toString()),
75
        // map.get("NOM").toString(), map.get("TYPE_NUMERO_COMPTE").toString());
76
        //
77
        // final JScrollPane scrollPane = new JScrollPane(createIListe(ccTmp));
78
        // scrollPane.setOpaque(false);
79
        // scrollPane.setBorder(null);
80
        // scrollPane.getViewport().setOpaque(false);
81
        // // On créer les comptes de chaque classe
82
        // tabbedClasseCpt.addTab(ccTmp.getNom(), scrollPane);
83
        //
84
        // }
85
 
86
        for (ClasseCompte cc : ClasseCompte.getClasseCompte()) {
87
 
88
            final JScrollPane scrollPane = new JScrollPane(createIListe(cc));
89
            scrollPane.setOpaque(false);
90
            scrollPane.setBorder(null);
91
            scrollPane.getViewport().setOpaque(false);
92
            // On créer les comptes de chaque classe
93
            tabbedClasseCpt.addTab(cc.getNom(), scrollPane);
94
        }
95
 
96
        c.fill = GridBagConstraints.BOTH;
97
        c.weightx = 1;
98
        c.weighty = 1;
99
        c.gridx = 0;
100
 
101
        c.gridy = 0;
102
        c.gridwidth = 2;
103
        this.add(tabbedClasseCpt, c);
104
 
105
    }
106
 
107
    private ListeAddPanel createIListe(final ClasseCompte ccTmp) {
108
 
109
        final SQLElement elementEcriture = Configuration.getInstance().getDirectory().getElement("ECRITURE");
19 ilm 110
        final SQLTableModelSourceOnline src = elementEcriture.getTableSource(true);
111
        src.getReq().setSelectTransf(new ITransformer<SQLSelect, SQLSelect>() {
18 ilm 112
 
113
            @Override
114
            public SQLSelect transformChecked(SQLSelect sel) {
115
 
116
                // Filtre sur les comptes de la classe
117
                String function = "REGEXP";
118
                String match = ccTmp.getTypeNumeroCompte();
19 ilm 119
                if (elementEcriture.getTable().getServer().getSQLSystem() == SQLSystem.POSTGRESQL) {
144 ilm 120
                    // function = "SIMILAR TO";
28 ilm 121
                    function = "~";
144 ilm 122
                    // match = ccTmp.getTypeNumeroCompte().replace(".*", "%");
18 ilm 123
                }
124
 
125
                Where w = new Where(sel.getAlias(elementEcriture.getTable().getField("COMPTE_NUMERO")), function, match);
144 ilm 126
                if (!UserRightsManager.getCurrentUserRights().haveRight(ComptaUserRight.ACCES_NOT_RESCTRICTED_TO_411)) {
18 ilm 127
                    // TODO Show Restricted acces in UI + Voir avec pour fonction LIKE -->
128
                    // differents par BD??
129
                    w = w.and(new Where(elementEcriture.getTable().getField("COMPTE_NUMERO"), "LIKE", "411%"));
130
                }
131
                return sel.andWhere(w);
132
            }
133
        });
19 ilm 134
        final ListeAddPanel panel = new ListeAddPanel(elementEcriture, new IListe(src));
18 ilm 135
 
136
        panel.setOpaque(false);
137
        panel.setSearchFullMode(true);
138
 
139
        JTable table = panel.getListe().getJTable();
140
 
141
        panel.setCloneVisible(false);
142
        panel.setAddVisible(false);
143
        panel.setModifyVisible(false);
144
        panel.setReloadVisible(true);
145
 
146
        // Gestion du clic droit
147
        table.addMouseListener(new MouseAdapter() {
148
            public void mousePressed(MouseEvent event) {
149
                if (event.getButton() == MouseEvent.BUTTON3) {
150
                    JPopupMenu menuDroit = new JPopupMenu();
151
                    menuDroit.add(new AbstractAction("Contrepassation") {
152
                        public void actionPerformed(ActionEvent e) {
153
                            EcritureSQLElement.contrePassationPiece(panel.getListe().getSelectedId());
154
                        }
155
                    });
156
                    menuDroit.add(new AbstractAction("Voir la source") {
157
                        public void actionPerformed(ActionEvent e) {
158
 
80 ilm 159
                            SQLRow row = panel.getListe().fetchSelectedRow();
18 ilm 160
 
161
                            MouvementSQLElement.showSource(row.getInt("ID_MOUVEMENT"));
162
                        }
163
                    });
164
 
165
                    menuDroit.show(event.getComponent(), event.getPoint().x, event.getPoint().y);
166
                }
167
            }
168
        });
169
 
170
        panel.getListe().getModel().invokeLater(new Runnable() {
171
            public void run() {
172
                int rowCount = panel.getListe().getModel().getRowCount() - 1;
173
                if (rowCount > 0) {
174
                    panel.getListe().getJTable().setRowSelectionInterval(rowCount, rowCount);
175
                }
176
            }
177
        });
178
 
179
        return panel;
180
    }
181
}