OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 156 | 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
 *
182 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.supplychain.order.element;
15
 
16
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
17
import org.openconcerto.erp.core.common.ui.DeviseField;
182 ilm 18
import org.openconcerto.erp.preferences.GestionArticleGlobalPreferencePanel;
18 ilm 19
import org.openconcerto.sql.element.SQLComponent;
20
import org.openconcerto.sql.element.UISQLComponent;
156 ilm 21
import org.openconcerto.sql.model.SQLRowValues;
22
import org.openconcerto.sql.model.Where;
182 ilm 23
import org.openconcerto.sql.preferences.SQLPreferences;
156 ilm 24
import org.openconcerto.sql.request.UpdateBuilder;
18 ilm 25
import org.openconcerto.sql.sqlobject.ElementComboBox;
156 ilm 26
import org.openconcerto.sql.users.UserManager;
27
import org.openconcerto.sql.view.EditFrame;
28
import org.openconcerto.sql.view.EditPanel.EditMode;
29
import org.openconcerto.sql.view.list.IListe;
30
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
31
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
32
import org.openconcerto.ui.FrameUtil;
18 ilm 33
 
156 ilm 34
import java.awt.event.ActionEvent;
18 ilm 35
import java.util.ArrayList;
156 ilm 36
import java.util.HashSet;
18 ilm 37
import java.util.List;
156 ilm 38
import java.util.Set;
18 ilm 39
 
156 ilm 40
import javax.swing.AbstractAction;
19 ilm 41
import javax.swing.JTextField;
18 ilm 42
 
43
public class CommandeElementSQLElement extends ComptaSQLConfElement {
44
 
45
    public CommandeElementSQLElement() {
46
        super("COMMANDE_ELEMENT", "un element de commande", "éléments de commande");
156 ilm 47
 
48
        PredicateRowAction rowActionCmd = new PredicateRowAction(new AbstractAction("Modifier la commande associée") {
49
 
50
            @Override
51
            public void actionPerformed(ActionEvent e) {
52
                SQLRowValues selectedRow = IListe.get(e).getSelectedRow();
53
                EditFrame f = new EditFrame(getForeignElement("ID_COMMANDE"), EditMode.MODIFICATION);
54
                f.getSQLComponent().select(selectedRow.getForeignID("ID_COMMANDE"));
55
                FrameUtil.showPacked(f);
56
            }
57
 
58
        }, true);
59
        rowActionCmd.setPredicate(IListeEvent.getSingleSelectionPredicate());
60
        getRowActions().add(rowActionCmd);
61
 
62
        if (getTable().getForeignTable("ID_USER_COMMON_CREATE").getRow(UserManager.getUserID()).getBoolean("ADMIN")) {
63
            PredicateRowAction rowActionA = new PredicateRowAction(new AbstractAction("Forcer la réception") {
64
 
65
                @Override
66
                public void actionPerformed(ActionEvent e) {
67
                    updateForceLivrer(e, Boolean.TRUE);
68
                }
69
 
70
            }, true);
71
            rowActionA.setPredicate(IListeEvent.getNonEmptySelectionPredicate());
72
            getRowActions().add(rowActionA);
73
            PredicateRowAction rowActionC = new PredicateRowAction(new AbstractAction("Annuler forcer la réception") {
74
 
75
                @Override
76
                public void actionPerformed(ActionEvent e) {
77
                    updateForceLivrer(e, Boolean.FALSE);
78
                }
79
 
80
            }, true);
81
            rowActionC.setPredicate(IListeEvent.getNonEmptySelectionPredicate());
82
            getRowActions().add(rowActionC);
83
        }
18 ilm 84
    }
85
 
156 ilm 86
    private void updateForceLivrer(ActionEvent e, Boolean state) {
87
        final List<SQLRowValues> selectedRows = IListe.get(e).getSelectedRows();
88
        final Set<Integer> ids = new HashSet<Integer>();
89
        for (SQLRowValues sqlRowValues : selectedRows) {
90
            ids.add(sqlRowValues.getID());
91
        }
92
        UpdateBuilder build = new UpdateBuilder(getTable());
93
        build.setObject("RECU_FORCED", state);
94
        build.setWhere(new Where(getTable().getKey(), ids));
95
        getTable().getDBSystemRoot().getDataSource().execute(build.asString());
96
        IListe.get(e).getModel().updateAll();
97
    }
98
 
132 ilm 99
    @Override
100
    protected String getParentFFName() {
101
        return "ID_COMMANDE";
102
    }
103
 
18 ilm 104
    protected List<String> getListFields() {
105
        final List<String> l = new ArrayList<String>();
106
        l.add("ID_STYLE");
107
        l.add("CODE");
108
        l.add("NOM");
182 ilm 109
        SQLPreferences prefs = new SQLPreferences(getTable().getDBRoot());
110
        if (prefs.getBoolean(GestionArticleGlobalPreferencePanel.ACTIVER_DECLINAISON, false)) {
111
 
112
            for (String fieldName : getTable().getFieldsName()) {
113
                if (fieldName.startsWith("ID_ARTICLE_DECLINAISON_")) {
114
                    l.add(fieldName);
115
                }
116
            }
117
        }
142 ilm 118
        l.add("ID_COMMANDE");
119
        l.add("ID_ARTICLE");
18 ilm 120
        l.add("PA_HT");
121
        l.add("PV_HT");
156 ilm 122
        l.add("T_PA_HT");
123
        l.add("T_PV_HT");
18 ilm 124
        l.add("ID_TAXE");
142 ilm 125
        l.add("QTE");
126
        l.add("QTE_UNITAIRE");
127
        l.add("QTE_RECUE");
18 ilm 128
        l.add("POIDS");
156 ilm 129
        l.add("RECU_FORCED");
130
        l.add("RECU");
18 ilm 131
        return l;
132
    }
133
 
134
    protected List<String> getComboFields() {
135
        final List<String> l = new ArrayList<String>();
136
        l.add("CODE");
137
        l.add("NOM");
138
        l.add("PA_HT");
139
        l.add("PV_HT");
140
        return l;
141
    }
142
 
143
    /*
144
     * (non-Javadoc)
145
     *
146
     * @see org.openconcerto.devis.SQLElement#getComponent()
147
     */
148
    public SQLComponent createComponent() {
149
        return new UISQLComponent(this) {
150
            public void addViews() {
151
                this.addRequiredSQLObject(new JTextField(), "NOM", "left");
152
                this.addRequiredSQLObject(new JTextField(), "CODE", "right");
153
 
154
                this.addSQLObject(new ElementComboBox(), "ID_STYLE", "left");
155
 
156
                this.addRequiredSQLObject(new DeviseField(), "PA_HT", "left");
157
                this.addSQLObject(new DeviseField(), "PV_HT", "right");
158
 
159
                this.addSQLObject(new JTextField(), "POIDS", "left");
160
                this.addSQLObject(new ElementComboBox(), "ID_TAXE", "right");
161
            }
162
        };
163
    }
57 ilm 164
 
165
    @Override
166
    protected String createCode() {
156 ilm 167
        return createCodeOfPackage() + ".item";
57 ilm 168
    }
18 ilm 169
}