OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 28 | Rev 65 | 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.common.ui;
15
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
17
import org.openconcerto.erp.core.sales.product.element.ReferenceArticleSQLElement;
61 ilm 18
import org.openconcerto.erp.preferences.DefaultNXProps;
19
import org.openconcerto.erp.preferences.GestionArticleGlobalPreferencePanel;
18 ilm 20
import org.openconcerto.sql.Configuration;
21
import org.openconcerto.sql.element.SQLElement;
22
import org.openconcerto.sql.model.SQLField;
23
import org.openconcerto.sql.model.SQLRow;
19 ilm 24
import org.openconcerto.sql.model.SQLRowAccessor;
18 ilm 25
import org.openconcerto.sql.model.SQLRowValues;
26
import org.openconcerto.sql.model.SQLTable;
61 ilm 27
import org.openconcerto.sql.preferences.SQLPreferences;
18 ilm 28
import org.openconcerto.sql.view.list.RowValuesTable;
29
import org.openconcerto.sql.view.list.RowValuesTableControlPanel;
30
import org.openconcerto.sql.view.list.RowValuesTableModel;
31
import org.openconcerto.sql.view.list.RowValuesTableRenderer;
32
import org.openconcerto.sql.view.list.SQLTableElement;
33
import org.openconcerto.ui.DefaultGridBagConstraints;
28 ilm 34
import org.openconcerto.ui.table.XTableColumnModel;
18 ilm 35
 
36
import java.awt.GridBagConstraints;
37
import java.awt.GridBagLayout;
38
import java.io.File;
39
import java.util.Date;
40
import java.util.List;
41
import java.util.Set;
42
 
43
import javax.swing.JButton;
44
import javax.swing.JPanel;
45
import javax.swing.JScrollPane;
46
 
47
public abstract class AbstractArticleItemTable extends JPanel {
48
    protected RowValuesTable table;
49
    protected SQLTableElement totalHT;
61 ilm 50
    protected SQLTableElement tableElementTVA;
18 ilm 51
    protected SQLTableElement tableElementTotalTTC;
19 ilm 52
    protected SQLTableElement tableElementTotalDevise;
18 ilm 53
    protected SQLTableElement service, qte, ha;
54
    protected SQLTableElement tableElementPoidsTotal;
61 ilm 55
    protected SQLTableElement prebilan;
18 ilm 56
    protected RowValuesTableModel model;
57
    protected SQLRowValues defaultRowVals;
58
    private List<JButton> buttons = null;
59
    protected RowValuesTableControlPanel control = null;
19 ilm 60
    private SQLRowAccessor tarif = null;
18 ilm 61
 
62
    public AbstractArticleItemTable() {
63
        init();
64
        uiInit();
65
    }
66
 
67
    public AbstractArticleItemTable(List<JButton> buttons) {
68
        this.buttons = buttons;
69
        init();
70
        uiInit();
71
    }
72
 
73
    /**
74
     *
75
     */
76
    abstract protected void init();
77
 
78
    protected File getConfigurationFile() {
79
        return new File(Configuration.getInstance().getConfDir(), "Table/" + getConfigurationFileName());
80
    }
81
 
82
    /**
83
     *
84
     */
85
    protected void uiInit() {
86
        // Ui init
87
        setLayout(new GridBagLayout());
61 ilm 88
        this.setOpaque(false);
18 ilm 89
        final GridBagConstraints c = new DefaultGridBagConstraints();
90
 
91
        c.weightx = 1;
92
 
93
        control = new RowValuesTableControlPanel(this.table, this.buttons);
61 ilm 94
        control.setOpaque(false);
18 ilm 95
        this.add(control, c);
96
 
97
        c.gridy++;
98
        c.fill = GridBagConstraints.BOTH;
99
        c.weightx = 1;
100
        c.weighty = 1;
101
        final JScrollPane comp = new JScrollPane(this.table);
102
        this.add(comp, c);
103
        this.table.setDefaultRenderer(Long.class, new RowValuesTableRenderer());
104
    }
105
 
106
    /**
107
     * @return the coniguration file to store pref
108
     */
109
    protected abstract String getConfigurationFileName();
110
 
111
    public abstract SQLElement getSQLElement();
112
 
113
    public void updateField(final String field, final int id) {
114
        this.table.updateField(field, id);
115
    }
116
 
117
    public RowValuesTable getRowValuesTable() {
118
        return this.table;
119
    }
120
 
121
    public void insertFrom(final String field, final int id) {
122
        this.table.insertFrom(field, id);
123
 
124
    }
125
 
126
    public RowValuesTableModel getModel() {
127
        return this.table.getRowValuesTableModel();
128
    }
129
 
61 ilm 130
    public SQLTableElement getPrebilanElement() {
131
        return this.prebilan;
132
    }
133
 
18 ilm 134
    public SQLTableElement getPrixTotalHTElement() {
135
        return this.totalHT;
136
    }
137
 
138
    public SQLTableElement getPoidsTotalElement() {
139
        return this.tableElementPoidsTotal;
140
    }
141
 
142
    public SQLTableElement getPrixTotalTTCElement() {
143
        return this.tableElementTotalTTC;
144
    }
145
 
146
    public SQLTableElement getPrixServiceElement() {
147
        return this.service;
148
    }
149
 
150
    public SQLTableElement getQteElement() {
151
        return this.qte;
152
    }
153
 
154
    public SQLTableElement getHaElement() {
155
        return this.ha;
156
    }
157
 
61 ilm 158
    public SQLTableElement getTVAElement() {
159
        return this.tableElementTVA;
160
    }
161
 
19 ilm 162
    public SQLTableElement getTableElementTotalDevise() {
163
        return this.tableElementTotalDevise;
164
    }
165
 
18 ilm 166
    public void deplacerDe(final int inc) {
167
        final int rowIndex = this.table.getSelectedRow();
168
 
169
        final int dest = this.model.moveBy(rowIndex, inc);
170
        this.table.getSelectionModel().setSelectionInterval(dest, dest);
171
    }
172
 
173
    /**
174
     * @return le poids total de tous les éléments du tableau
175
     */
176
    public float getPoidsTotal() {
177
 
178
        float poids = 0.0F;
179
        final int poidsTColIndex = this.model.getColumnIndexForElement(this.tableElementPoidsTotal);
180
        if (poidsTColIndex >= 0) {
181
            for (int i = 0; i < this.table.getRowCount(); i++) {
182
                final Number tmp = (Number) this.model.getValueAt(i, poidsTColIndex);
183
                if (tmp != null) {
184
                    poids += tmp.floatValue();
185
                }
186
            }
187
        }
188
        return poids;
189
    }
190
 
191
    public void refreshTable() {
192
        this.table.repaint();
193
    }
194
 
195
    public void createArticle(final int id, final SQLElement eltSource) {
196
 
197
        final SQLElement eltArticleTable = getSQLElement();
198
 
199
        final SQLTable tableArticle = ((ComptaPropsConfiguration) Configuration.getInstance()).getRootSociete().getTable("ARTICLE");
200
 
61 ilm 201
        final boolean modeAvance = DefaultNXProps.getInstance().getBooleanValue("ArticleModeVenteAvance", false);
202
        SQLPreferences prefs = new SQLPreferences(tableArticle.getDBRoot());
203
        final boolean createArticle = prefs.getBoolean(GestionArticleGlobalPreferencePanel.CREATE_ARTICLE_AUTO, true);
204
 
18 ilm 205
        // On récupére les articles qui composent la table
206
        final List<SQLRow> listElts = eltSource.getTable().getRow(id).getReferentRows(eltArticleTable.getTable());
207
        final SQLRowValues rowArticle = new SQLRowValues(tableArticle);
208
        final Set<SQLField> fields = tableArticle.getFields();
209
 
210
        for (final SQLRow rowElt : listElts) {
28 ilm 211
            // final SQLRow foreignRow = rowElt.getForeignRow("ID_ARTICLE");
212
            // if (foreignRow == null || foreignRow.isUndefined()) {
18 ilm 213
            final Set<String> fieldsName = rowElt.getTable().getFieldsName();
214
            // on récupére l'article qui lui correspond
215
 
216
            for (final SQLField field : fields) {
217
 
218
                final String name = field.getName();
219
                if (fieldsName.contains(name) && !field.isPrimaryKey()) {
220
                    rowArticle.put(name, rowElt.getObject(name));
221
                }
222
            }
223
            // crée les articles si il n'existe pas
61 ilm 224
 
225
            if (modeAvance)
226
                ReferenceArticleSQLElement.getIdForCNM(rowArticle, createArticle);
227
            else {
228
                ReferenceArticleSQLElement.getIdForCN(rowArticle, createArticle);
229
            }
230
            // ReferenceArticleSQLElement.getIdForCNM(rowArticle, true);
18 ilm 231
        }
28 ilm 232
        // }
18 ilm 233
    }
234
 
235
 
236
    public SQLRowValues getDefaultRowValues() {
237
        return this.defaultRowVals;
238
    }
19 ilm 239
 
240
    public SQLRowAccessor getTarif() {
241
        return tarif;
242
    }
243
 
244
    public void setTarif(SQLRowAccessor idTarif, boolean ask) {
245
        this.tarif = idTarif;
246
    }
28 ilm 247
 
248
    protected void setColumnVisible(int col, boolean visible) {
249
        if (col >= 0) {
250
            XTableColumnModel columnModel = this.table.getColumnModel();
251
            columnModel.setColumnVisible(columnModel.getColumnByModelIndex(col), visible);
252
        }
253
    }
18 ilm 254
}