OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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