OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 151 | 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.sales.invoice.ui;
15
 
16
import org.openconcerto.erp.core.finance.accounting.element.EcritureSQLElement;
17
import org.openconcerto.erp.core.finance.accounting.element.MouvementSQLElement;
18
import org.openconcerto.sql.Configuration;
19
import org.openconcerto.sql.element.SQLComponent;
20
import org.openconcerto.sql.element.SQLElement;
90 ilm 21
import org.openconcerto.sql.model.SQLField;
18 ilm 22
import org.openconcerto.sql.model.SQLRow;
23
import org.openconcerto.sql.model.SQLTable;
24
import org.openconcerto.sql.model.Where;
25
import org.openconcerto.sql.view.EditFrame;
26
import org.openconcerto.sql.view.ListeAddPanel;
19 ilm 27
import org.openconcerto.sql.view.list.IListe;
18 ilm 28
import org.openconcerto.sql.view.list.SQLTableModelColumn;
29
import org.openconcerto.sql.view.list.SQLTableModelColumnPath;
19 ilm 30
import org.openconcerto.sql.view.list.SQLTableModelSource;
18 ilm 31
 
32
import java.awt.event.ActionEvent;
73 ilm 33
import java.util.Calendar;
34
import java.util.Date;
18 ilm 35
 
36
import javax.swing.JButton;
37
import javax.swing.JTable;
90 ilm 38
import javax.swing.table.TableColumn;
18 ilm 39
 
19 ilm 40
public class ListPanelEcheancesClients extends ListeAddPanel {
18 ilm 41
 
42
    // TODO Ajouter une légende dans liste echeance panel pour les couleurs du renderer
43
 
44
    private EditFrame editFrame;
45
    private boolean showRegCompta = false;
73 ilm 46
    private boolean onlyOld = false;
18 ilm 47
 
48
    public ListPanelEcheancesClients() {
73 ilm 49
        this(false);
19 ilm 50
    }
18 ilm 51
 
73 ilm 52
    public ListPanelEcheancesClients(boolean onlyOld) {
53
        this(Configuration.getInstance().getDirectory().getElement("ECHEANCE_CLIENT"), onlyOld);
54
    }
55
 
56
    private ListPanelEcheancesClients(final SQLElement elem, boolean onlyOld) {
19 ilm 57
        super(elem, new IListe(elem.getTableSource(true)));
73 ilm 58
        this.onlyOld = onlyOld;
18 ilm 59
        setListe();
60
    }
61
 
62
    public JTable getJTable() {
63
 
64
        return this.getListe().getJTable();
65
    }
66
 
67
    public void setShowRegCompta(boolean b) {
68
        this.showRegCompta = b;
69
        setListe();
70
    }
71
 
72
    protected void handleAction(JButton source, ActionEvent e) {
73
        if (source == this.buttonModifier) {
74
 
75
            if (this.editFrame == null) {
76
                this.editFrame = new EditFrame(this.element, EditFrame.MODIFICATION);
77
            }
19 ilm 78
            this.editFrame.selectionId(this.getListe().getSelectedId());
18 ilm 79
            this.editFrame.pack();
80
            this.editFrame.setVisible(true);
81
 
80 ilm 82
            SQLRow ecritureRow = Configuration.getInstance().getDirectory().getElement(EcritureSQLElement.class).getTable().getRow(this.getListe().getSelectedId());
18 ilm 83
 
84
            MouvementSQLElement.showSource(ecritureRow.getInt("ID_MOUVEMENT"));
85
 
86
        } else {
87
 
88
            super.handleAction(source, e);
89
        }
90
    }
91
 
92
    private void setListe() {
73 ilm 93
        // FIXME : remove queries from AWT
94
        final SQLTable elementEchT = getListe().getSource().getPrimaryTable();
95
        Where wNotRegle = new Where(elementEchT.getField("REGLE"), "=", Boolean.FALSE);
177 ilm 96
        wNotRegle = wNotRegle.and(new Where(elementEchT.getTable().getField("ID_SEPA_MANDATE"), "=", (Object) null));
97
 
73 ilm 98
        if (!showRegCompta) {
99
            wNotRegle = wNotRegle.and(new Where(elementEchT.getField("REG_COMPTA"), "=", Boolean.FALSE));
100
        }
101
        if (onlyOld) {
102
            Calendar c = Calendar.getInstance();
103
            c.add(Calendar.DAY_OF_MONTH, -7);
104
            Date date = c.getTime();
105
            wNotRegle = wNotRegle.and(new Where(elementEchT.getField("DATE"), "<", date));
106
        }
107
        getListe().getRequest().setWhere(wNotRegle);
18 ilm 108
 
90 ilm 109
        final ListEcheanceClientRenderer rend = new ListEcheanceClientRenderer(false);
110
        final ListEcheanceClientRenderer rendDate = new ListEcheanceClientRenderer(true);
111
        //
112
        SQLTableModelColumn colDate = ListPanelEcheancesClients.this.getListe().getSource().getColumn(elementEchT.getField("DATE"));
113
        int indexColDate = ListPanelEcheancesClients.this.getListe().getSource().getColumns().indexOf(colDate);
114
        for (int i = 0; i < ListPanelEcheancesClients.this.getListe().getJTable().getColumnCount(); i++) {
115
            if (ListPanelEcheancesClients.this.getListe().getJTable().getColumnClass(i) != Boolean.class) {
18 ilm 116
 
90 ilm 117
                TableColumn col = ListPanelEcheancesClients.this.getListe().getJTable().getColumnModel().getColumn(i);
118
                if (col.getModelIndex() == indexColDate) {
119
                    col.setCellRenderer(rendDate);
120
                } else {
121
                    col.setCellRenderer(rend);
122
                }
123
            }
124
        }
125
 
126
        getListe().getSource().getColumn(elementEchT.getField("DATE")).setRenderer(rendDate);
73 ilm 127
        ListPanelEcheancesClients.this.buttonAjouter.setVisible(false);
128
        ListPanelEcheancesClients.this.buttonEffacer.setVisible(false);
129
        ListPanelEcheancesClients.this.buttonModifier.setVisible(false);
18 ilm 130
 
73 ilm 131
        final SQLTableModelSource src = ListPanelEcheancesClients.this.getListe().getSource();
18 ilm 132
 
151 ilm 133
        ListPanelEcheancesClients.this.getListe().setModificationAllowed(true);
18 ilm 134
 
90 ilm 135
        SQLField fieldDateEch = elementEchT.getField("DATE");
73 ilm 136
        for (SQLTableModelColumn column : src.getColumns()) {
137
            if (column.getClass().isAssignableFrom(SQLTableModelColumnPath.class)) {
138
                ((SQLTableModelColumnPath) column).setEditable(false);
139
            }
90 ilm 140
            if (column.getFields().contains(fieldDateEch)) {
141
                column.setRenderer(rendDate);
142
            } else {
143
                column.setRenderer(rend);
144
            }
73 ilm 145
        }
18 ilm 146
 
73 ilm 147
        ((SQLTableModelColumnPath) src.getColumns(getElement().getTable().getField("INFOS")).iterator().next()).setEditable(true);
18 ilm 148
 
149
    }
150
 
151
    @Override
152
    public SQLComponent getModifComp() {
153
        return null;
154
    }
155
}