OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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