OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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