OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 90 | Rev 177 | 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.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);
96
        if (!showRegCompta) {
97
            wNotRegle = wNotRegle.and(new Where(elementEchT.getField("REG_COMPTA"), "=", Boolean.FALSE));
98
        }
99
        if (onlyOld) {
100
            Calendar c = Calendar.getInstance();
101
            c.add(Calendar.DAY_OF_MONTH, -7);
102
            Date date = c.getTime();
103
            wNotRegle = wNotRegle.and(new Where(elementEchT.getField("DATE"), "<", date));
104
        }
105
        getListe().getRequest().setWhere(wNotRegle);
18 ilm 106
 
90 ilm 107
        final ListEcheanceClientRenderer rend = new ListEcheanceClientRenderer(false);
108
        final ListEcheanceClientRenderer rendDate = new ListEcheanceClientRenderer(true);
109
        //
110
        SQLTableModelColumn colDate = ListPanelEcheancesClients.this.getListe().getSource().getColumn(elementEchT.getField("DATE"));
111
        int indexColDate = ListPanelEcheancesClients.this.getListe().getSource().getColumns().indexOf(colDate);
112
        for (int i = 0; i < ListPanelEcheancesClients.this.getListe().getJTable().getColumnCount(); i++) {
113
            if (ListPanelEcheancesClients.this.getListe().getJTable().getColumnClass(i) != Boolean.class) {
18 ilm 114
 
90 ilm 115
                TableColumn col = ListPanelEcheancesClients.this.getListe().getJTable().getColumnModel().getColumn(i);
116
                if (col.getModelIndex() == indexColDate) {
117
                    col.setCellRenderer(rendDate);
118
                } else {
119
                    col.setCellRenderer(rend);
120
                }
121
            }
122
        }
123
 
124
        getListe().getSource().getColumn(elementEchT.getField("DATE")).setRenderer(rendDate);
73 ilm 125
        ListPanelEcheancesClients.this.buttonAjouter.setVisible(false);
126
        ListPanelEcheancesClients.this.buttonEffacer.setVisible(false);
127
        ListPanelEcheancesClients.this.buttonModifier.setVisible(false);
18 ilm 128
 
73 ilm 129
        final SQLTableModelSource src = ListPanelEcheancesClients.this.getListe().getSource();
18 ilm 130
 
151 ilm 131
        ListPanelEcheancesClients.this.getListe().setModificationAllowed(true);
18 ilm 132
 
90 ilm 133
        SQLField fieldDateEch = elementEchT.getField("DATE");
73 ilm 134
        for (SQLTableModelColumn column : src.getColumns()) {
135
            if (column.getClass().isAssignableFrom(SQLTableModelColumnPath.class)) {
136
                ((SQLTableModelColumnPath) column).setEditable(false);
137
            }
90 ilm 138
            if (column.getFields().contains(fieldDateEch)) {
139
                column.setRenderer(rendDate);
140
            } else {
141
                column.setRenderer(rend);
142
            }
73 ilm 143
        }
18 ilm 144
 
73 ilm 145
        ((SQLTableModelColumnPath) src.getColumns(getElement().getTable().getField("INFOS")).iterator().next()).setEditable(true);
18 ilm 146
 
147
    }
148
 
149
    @Override
150
    public SQLComponent getModifComp() {
151
        return null;
152
    }
153
}