OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 67 | Rev 142 | 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.accounting.ui;
15
 
16
import org.openconcerto.erp.core.common.ui.PanelFrame;
17
import org.openconcerto.erp.core.finance.accounting.element.MouvementSQLElement;
18
import org.openconcerto.sql.element.SQLElement;
19
import org.openconcerto.sql.model.SQLRow;
80 ilm 20
import org.openconcerto.sql.model.SQLRowAccessor;
18 ilm 21
import org.openconcerto.sql.model.Where;
22
import org.openconcerto.sql.view.EditFrame;
23
import org.openconcerto.sql.view.EditPanel;
24
import org.openconcerto.sql.view.ListeAddPanel;
25
import org.openconcerto.sql.view.list.IListe;
80 ilm 26
import org.openconcerto.utils.cc.ITransformer;
18 ilm 27
 
28
import java.awt.event.ActionEvent;
80 ilm 29
import java.util.Collection;
18 ilm 30
 
31
import javax.swing.JButton;
32
 
33
public class ListeGestCommEltPanel extends ListeAddPanel {
34
 
35
    private EditFrame editModifyFrame, editReadOnlyFrame;
36
 
41 ilm 37
    private ListeGestCommEltPanel(SQLElement elem, boolean showAdd, Where w, String variant) {
18 ilm 38
        // TODO verifier que l'element contient la clef etrangere ID_MOUVEMENT
19 ilm 39
        this(elem, new IListe(elem.createTableSource(w)), showAdd);
18 ilm 40
    }
41
 
42
    public ListeGestCommEltPanel(SQLElement elem, IListe l) {
43
        this(elem, l, false);
44
    }
19 ilm 45
 
18 ilm 46
    public ListeGestCommEltPanel(SQLElement elem, IListe l, boolean showAdd) {
47
        super(elem, l);
48
        this.setAddVisible(showAdd);
49
        this.setOpaque(false);
80 ilm 50
        if (elem.getTable().getName().equals("SAISIE_VENTE_FACTURE")) {
51
            this.btnMngr.setAdditional(this.buttonEffacer, new ITransformer<JButton, String>() {
52
 
53
                @Override
54
                public String transformChecked(JButton input) {
55
 
56
                    SQLRowAccessor row = getListe().fetchSelectedRow();
57
 
58
                    if (row.getBoolean("PARTIAL") && !isLastPartialInvoice(row)) {
59
                        return "Vous ne pouvez pas supprimer cette facture intermédiaire.\n Des factures antérieures ont été établies !";
60
                    }
61
                    return null;
62
                }
63
            });
64
            this.btnMngr.setAdditional(this.buttonModifier, new ITransformer<JButton, String>() {
65
 
66
                @Override
67
                public String transformChecked(JButton input) {
68
 
69
                    SQLRowAccessor row = getListe().fetchSelectedRow();
70
 
71
                    if (row.getBoolean("PARTIAL") || row.getBoolean("SOLDE")) {
72
                        return "Vous ne pouvez pas modifier une facture intermédiaire.";
73
                    }
74
                    return null;
75
                }
76
            });
77
        }
18 ilm 78
    }
79
 
80 ilm 80
    public boolean isLastPartialInvoice(SQLRowAccessor sqlRowAccessor) {
81
        Collection<? extends SQLRowAccessor> rows = sqlRowAccessor.getReferentRows(sqlRowAccessor.getTable().getTable("TR_COMMANDE_CLIENT"));
82
        for (SQLRowAccessor sqlRowAccessor2 : rows) {
83
            SQLRowAccessor rowCmd = sqlRowAccessor2.getForeign("ID_COMMANDE_CLIENT");
84
            if (rowCmd != null && !rowCmd.isUndefined()) {
85
                Collection<? extends SQLRowAccessor> rowSFacts = rowCmd.getReferentRows(sqlRowAccessor.getTable().getTable("TR_COMMANDE_CLIENT"));
86
                for (SQLRowAccessor sqlRowAccessor3 : rowSFacts) {
87
                    if (!sqlRowAccessor3.isForeignEmpty("ID_SAISIE_VENTE_FACTURE")) {
88
                        SQLRowAccessor rowFact = sqlRowAccessor3.getForeign("ID_SAISIE_VENTE_FACTURE");
89
                        if (rowFact.getDate("DATE").after(sqlRowAccessor.getDate("DATE"))) {
90
                            return false;
91
                        }
92
                    }
93
                }
94
            }
95
        }
96
        return true;
97
    }
98
 
67 ilm 99
    public ListeGestCommEltPanel(SQLElement elem, IListe l, String variant) {
100
        // TODO verifier que l'element contient la clef etrangere ID_MOUVEMENT
101
        super(elem, l, variant);
102
        this.setAddVisible(false);
103
        this.setOpaque(false);
104
    }
105
 
18 ilm 106
    public ListeGestCommEltPanel(SQLElement elem, boolean showAdd) {
41 ilm 107
        this(elem, showAdd, null, null);
18 ilm 108
    }
109
 
110
    public ListeGestCommEltPanel(SQLElement elem) {
111
        this(elem, false);
112
    }
113
 
41 ilm 114
    public ListeGestCommEltPanel(SQLElement elem, Where w, String variant) {
115
        this(elem, false, w, variant);
116
    }
117
 
18 ilm 118
    public ListeGestCommEltPanel(SQLElement elem, Where w) {
41 ilm 119
        this(elem, false, w, null);
18 ilm 120
    }
121
 
122
    protected void handleAction(JButton source, ActionEvent evt) {
123
 
124
        SQLRow row = this.getElement().getTable().getRow(this.getListe().getSelectedId());
125
 
126
        if (row != null && row.getID() > 1) {
80 ilm 127
            final SQLRowAccessor mvt = row.getForeign("ID_MOUVEMENT");
18 ilm 128
            if (source == this.buttonEffacer) {
129
 
80 ilm 130
                if (mvt != null && !mvt.isUndefined()) {
131
                    PanelFrame frame = new PanelFrame(new SuppressionEcrituresPanel(mvt.getID()), "Suppression");
18 ilm 132
                    frame.pack();
133
                    frame.setLocationRelativeTo(null);
134
                    frame.setResizable(false);
135
                    frame.setVisible(true);
136
                } else {
137
                    super.handleAction(source, evt);
138
                }
139
            } else {
140
                if (source == this.buttonModifier) {
141
 
80 ilm 142
                    if (mvt == null || mvt.isUndefined() | MouvementSQLElement.isEditable(mvt.getID())) {
18 ilm 143
                        if (this.editModifyFrame == null) {
144
                            this.editModifyFrame = new EditFrame(this.element, EditPanel.MODIFICATION);
145
                        }
146
                        this.editModifyFrame.selectionId(this.getListe().getSelectedId());
147
                        this.editModifyFrame.setVisible(true);
148
                    } else {
149
                        if (this.editReadOnlyFrame == null) {
150
                            this.editReadOnlyFrame = new EditFrame(this.element, EditPanel.READONLY);
151
                        }
152
                        this.editReadOnlyFrame.selectionId(this.getListe().getSelectedId());
153
                        this.editReadOnlyFrame.setVisible(true);
154
                    }
155
                } else {
156
                    super.handleAction(source, evt);
157
                }
158
            }
159
        } else {
160
            super.handleAction(source, evt);
161
        }
162
    }
163
}