OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 132 | 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;
19 ilm 17
import org.openconcerto.erp.core.common.ui.IListFilterDatePanel;
18
import org.openconcerto.erp.core.common.ui.IListTotalPanel;
18 ilm 19
import org.openconcerto.sql.Configuration;
20
import org.openconcerto.sql.element.SQLElement;
19 ilm 21
import org.openconcerto.sql.model.SQLField;
180 ilm 22
import org.openconcerto.sql.model.SQLRow;
23
import org.openconcerto.sql.model.SQLRowAccessor;
24
import org.openconcerto.sql.model.SQLRowValues;
18 ilm 25
import org.openconcerto.sql.view.IListFrame;
132 ilm 26
import org.openconcerto.sql.view.ListeAddPanel;
73 ilm 27
import org.openconcerto.sql.view.list.IListe;
19 ilm 28
import org.openconcerto.ui.DefaultGridBagConstraints;
18 ilm 29
 
73 ilm 30
import java.awt.GridBagConstraints;
180 ilm 31
import java.awt.event.ActionEvent;
73 ilm 32
import java.util.ArrayList;
180 ilm 33
import java.util.Collection;
73 ilm 34
import java.util.List;
35
 
18 ilm 36
import javax.swing.Action;
180 ilm 37
import javax.swing.JButton;
18 ilm 38
import javax.swing.JFrame;
180 ilm 39
import javax.swing.JOptionPane;
18 ilm 40
 
41
public class ListeDesEncaissementsAction extends CreateFrameAbstractAction {
42
 
43
    public ListeDesEncaissementsAction() {
44
        super();
45
        this.putValue(Action.NAME, "Liste des encaissements");
46
    }
47
 
48
    public JFrame createFrame() {
49
 
50
        final SQLElement elementEchClient = Configuration.getInstance().getDirectory().getElement("ENCAISSER_MONTANT");
51
 
180 ilm 52
        ListeAddPanel panel = new ListeAddPanel(elementEchClient, new IListe(elementEchClient.getTableSource(true))) {
53
            // FIXME faire les checks en plus dans l'element
54
            @Override
55
            protected void handleAction(JButton source, ActionEvent evt) {
56
                if (source == this.buttonEffacer) {
57
                    List<SQLRowValues> rowValsSel = this.getListe().getSelectedRows();
73 ilm 58
 
180 ilm 59
                    if (isEncaissementEditable(rowValsSel, "effacer")) {
60
                        super.handleAction(source, evt);
61
                    }
62
                } else if (source == this.buttonModifier) {
63
                    List<SQLRowValues> rowValsSel = this.getListe().getSelectedRows();
64
 
65
                    if (isEncaissementEditable(rowValsSel, "supprimer")) {
66
                        super.handleAction(source, evt);
67
                    }
68
                } else {
69
                    super.handleAction(source, evt);
70
                }
71
            }
72
 
73
            private boolean isEncaissementEditable(List<SQLRowValues> rowValsSel, String action) {
74
                for (SQLRowValues sqlRowValues : rowValsSel) {
75
                    final SQLRow asRow = sqlRowValues.asRow();
76
                    Collection<? extends SQLRowAccessor> rowItems = asRow.getReferentRows(sqlRowValues.getTable().getTable("ENCAISSER_MONTANT_ELEMENT"));
77
                    for (SQLRowAccessor sqlRowValues2 : rowItems) {
78
                        if (sqlRowValues2.isForeignEmpty("ID_ECHEANCE_CLIENT")) {
79
                            JOptionPane.showMessageDialog(null, "Impossible de " + action + " un encaissement qui ne vient pas d'une échéance");
80
                            return false;
81
                        }
82
                    }
83
                    SQLRowAccessor rowAcMvt = asRow.getNonEmptyForeign("ID_MOUVEMENT");
84
                    if (rowAcMvt != null) {
85
                        Collection<? extends SQLRowAccessor> rowItemsEcr = rowAcMvt.getReferentRows(rowAcMvt.getTable().getTable("ECRITURE").getField("ID_MOUVEMENT"));
86
                        for (SQLRowAccessor sqlRowValues2 : rowItemsEcr) {
87
                            if (sqlRowValues2.getBoolean("VALIDE")) {
88
                                JOptionPane.showMessageDialog(null, "Impossible de " + action + " un encaissement dont les écritures sont validées.");
89
                                return false;
90
                            }
91
                        }
92
                    }
93
                }
94
                return true;
95
            }
96
        };
97
 
132 ilm 98
        panel.setAddVisible(false);
180 ilm 99
 
100
        // panel.setDeleteVisible(false);
132 ilm 101
        IListFrame frame = new IListFrame(panel);
73 ilm 102
 
19 ilm 103
        List<SQLField> fields = new ArrayList<SQLField>(2);
104
        fields.add(elementEchClient.getTable().getField("MONTANT"));
105
 
61 ilm 106
        IListTotalPanel totalPanel = new IListTotalPanel(frame.getPanel().getListe(), fields, "Total Global");
19 ilm 107
 
108
        GridBagConstraints c = new DefaultGridBagConstraints();
109
        c.gridwidth = GridBagConstraints.REMAINDER;
110
        c.fill = GridBagConstraints.NONE;
111
        c.weightx = 0;
112
 
113
        // Total panel
114
        c.gridwidth = GridBagConstraints.REMAINDER;
115
        c.fill = GridBagConstraints.NONE;
116
        c.anchor = GridBagConstraints.EAST;
117
        c.weightx = 1;
118
        c.gridy = 4;
119
 
120
        frame.getPanel().add(totalPanel, c);
121
 
122
        // Date panel
123
        IListFilterDatePanel datePanel = new IListFilterDatePanel(frame.getPanel().getListe(), elementEchClient.getTable().getField("DATE"), IListFilterDatePanel.getDefaultMap());
124
        c.gridy++;
125
        c.anchor = GridBagConstraints.CENTER;
126
        frame.getPanel().add(datePanel, c);
127
 
18 ilm 128
        return frame;
129
    }
130
}