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 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 132 Rev 180
Line 14... Line 14...
14
 package org.openconcerto.erp.core.finance.payment.action;
14
 package org.openconcerto.erp.core.finance.payment.action;
15
 
15
 
16
import org.openconcerto.erp.action.CreateFrameAbstractAction;
16
import org.openconcerto.erp.action.CreateFrameAbstractAction;
17
import org.openconcerto.erp.core.common.ui.IListFilterDatePanel;
17
import org.openconcerto.erp.core.common.ui.IListFilterDatePanel;
18
import org.openconcerto.erp.core.common.ui.IListTotalPanel;
18
import org.openconcerto.erp.core.common.ui.IListTotalPanel;
19
import org.openconcerto.erp.core.common.ui.ListeViewPanel;
-
 
20
import org.openconcerto.sql.Configuration;
19
import org.openconcerto.sql.Configuration;
21
import org.openconcerto.sql.element.SQLElement;
20
import org.openconcerto.sql.element.SQLElement;
22
import org.openconcerto.sql.model.SQLField;
21
import org.openconcerto.sql.model.SQLField;
-
 
22
import org.openconcerto.sql.model.SQLRow;
-
 
23
import org.openconcerto.sql.model.SQLRowAccessor;
-
 
24
import org.openconcerto.sql.model.SQLRowValues;
23
import org.openconcerto.sql.view.IListFrame;
25
import org.openconcerto.sql.view.IListFrame;
24
import org.openconcerto.sql.view.ListeAddPanel;
26
import org.openconcerto.sql.view.ListeAddPanel;
25
import org.openconcerto.sql.view.list.IListe;
27
import org.openconcerto.sql.view.list.IListe;
26
import org.openconcerto.ui.DefaultGridBagConstraints;
28
import org.openconcerto.ui.DefaultGridBagConstraints;
27
 
29
 
28
import java.awt.GridBagConstraints;
30
import java.awt.GridBagConstraints;
-
 
31
import java.awt.event.ActionEvent;
29
import java.util.ArrayList;
32
import java.util.ArrayList;
-
 
33
import java.util.Collection;
30
import java.util.List;
34
import java.util.List;
31
 
35
 
32
import javax.swing.Action;
36
import javax.swing.Action;
-
 
37
import javax.swing.JButton;
33
import javax.swing.JFrame;
38
import javax.swing.JFrame;
-
 
39
import javax.swing.JOptionPane;
34
 
40
 
35
public class ListeDesEncaissementsAction extends CreateFrameAbstractAction {
41
public class ListeDesEncaissementsAction extends CreateFrameAbstractAction {
36
 
42
 
37
    public ListeDesEncaissementsAction() {
43
    public ListeDesEncaissementsAction() {
38
        super();
44
        super();
Line 41... Line 47...
41
 
47
 
42
    public JFrame createFrame() {
48
    public JFrame createFrame() {
43
 
49
 
44
        final SQLElement elementEchClient = Configuration.getInstance().getDirectory().getElement("ENCAISSER_MONTANT");
50
        final SQLElement elementEchClient = Configuration.getInstance().getDirectory().getElement("ENCAISSER_MONTANT");
45
 
51
 
-
 
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();
-
 
58
 
-
 
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
 
46
        // FIXME Cacher les encaissements de reports (créer à partir d'une échéance pour la reporter
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;
47
        // ????)
95
            }
-
 
96
        };
48
 
97
 
49
        ListeViewPanel panel = new ListeViewPanel(elementEchClient, new IListe(elementEchClient.getTableSource(true)));
-
 
50
        panel.setAddVisible(false);
98
        panel.setAddVisible(false);
-
 
99
 
51
        panel.setDeleteVisible(false);
100
        // panel.setDeleteVisible(false);
52
        IListFrame frame = new IListFrame(panel);
101
        IListFrame frame = new IListFrame(panel);
53
 
102
 
54
        List<SQLField> fields = new ArrayList<SQLField>(2);
103
        List<SQLField> fields = new ArrayList<SQLField>(2);
55
        fields.add(elementEchClient.getTable().getField("MONTANT"));
104
        fields.add(elementEchClient.getTable().getField("MONTANT"));
56
 
105