OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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