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
156 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.stock.element;
15
 
16
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
17
import org.openconcerto.erp.core.common.ui.ListeViewPanel;
18
import org.openconcerto.erp.core.sales.invoice.report.EtatStockInventaireXmlSheet;
19
import org.openconcerto.sql.element.GroupSQLComponent;
20
import org.openconcerto.sql.element.SQLComponent;
21
import org.openconcerto.sql.element.SQLElement;
22
import org.openconcerto.sql.model.SQLRowAccessor;
23
import org.openconcerto.sql.model.Where;
24
import org.openconcerto.sql.view.IListFrame;
25
import org.openconcerto.sql.view.list.IListe;
26
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
27
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
28
import org.openconcerto.sql.view.list.SQLTableModelSource;
29
import org.openconcerto.ui.FrameUtil;
177 ilm 30
import org.openconcerto.ui.PanelFrame;
156 ilm 31
import org.openconcerto.utils.ExceptionHandler;
32
 
33
import java.awt.event.ActionEvent;
34
import java.util.ArrayList;
35
import java.util.Date;
36
import java.util.List;
37
 
38
import javax.swing.AbstractAction;
39
import javax.swing.JComponent;
40
import javax.swing.JTextField;
41
 
42
public class EtatStockSQLElement extends ComptaSQLConfElement {
43
 
44
    public EtatStockSQLElement() {
45
        super("ETAT_STOCK");
46
        setDefaultGroup(new EtatStockGroup());
47
        {
48
            PredicateRowAction action = new PredicateRowAction(new AbstractAction("Créer un état de stock") {
49
 
50
                @Override
51
                public void actionPerformed(ActionEvent e) {
177 ilm 52
                    EtatStockSnapshotCreator creator = new EtatStockSnapshotCreator(getTable().getTable("DEPOT_STOCK").getRow(DepotStockSQLElement.DEFAULT_ID), new Date(), getTable().getDBRoot());
156 ilm 53
                    creator.create();
54
                }
55
            }, true);
56
            action.setPredicate(IListeEvent.createSelectionCountPredicate(0, Integer.MAX_VALUE));
57
            getRowActions().add(action);
58
        }
59
        {
60
            PredicateRowAction action = new PredicateRowAction(new AbstractAction("Voir les articles") {
61
 
62
                @Override
63
                public void actionPerformed(ActionEvent e) {
64
                    final SQLElement element = getDirectory().getElement("ETAT_STOCK_ELEMENT");
65
                    SQLTableModelSource source = element.createTableSource(new Where(element.getTable().getField("ID_ETAT_STOCK"), "=", IListe.get(e).getSelectedId()));
66
                    final ListeViewPanel panel = new ListeViewPanel(element, new IListe(source));
67
                    IListFrame frame = new IListFrame(panel);
68
                    FrameUtil.show(frame);
69
                }
70
            }, true);
71
            action.setPredicate(IListeEvent.getSingleSelectionPredicate());
72
            getRowActions().add(action);
73
        }
74
 
75
        {
76
            PredicateRowAction action = new PredicateRowAction(new AbstractAction("Export pour inventaire") {
77
                @Override
78
                public void actionPerformed(ActionEvent e) {
79
                    EtatStockInventaireXmlSheet sheet = new EtatStockInventaireXmlSheet(IListe.get(e).getSelectedRow().asRow());
80
                    try {
81
                        sheet.createDocument();
82
                        sheet.showPrintAndExport(true, false, false, false, false);
83
                    } catch (Exception e1) {
84
                        ExceptionHandler.handle("Erreur lors de la création de l'inventaire", e1);
85
                    }
86
                }
87
            }, true);
88
            action.setPredicate(IListeEvent.getSingleSelectionPredicate());
89
            getRowActions().add(action);
90
        }
91
 
92
        {
93
            PredicateRowAction action = new PredicateRowAction(new AbstractAction("Import Inventaire") {
94
                @Override
95
                public void actionPerformed(ActionEvent e) {
177 ilm 96
                    PanelFrame frame = new PanelFrame(new ImportInventairePanel(getDirectory().getElement(DepotStockSQLElement.class)), "Import inventaire");
97
                    FrameUtil.showPacked(frame);
156 ilm 98
                }
99
            }, true);
100
            action.setPredicate(IListeEvent.getSingleSelectionPredicate());
101
            getRowActions().add(action);
102
        }
103
    }
104
 
105
    @Override
106
    protected List<String> getListFields() {
107
        final List<String> l = new ArrayList<>(3);
108
        l.add("DATE");
109
        l.add("MONTANT_HA");
110
        l.add("INVENTAIRE");
111
        return l;
112
    }
113
 
114
    @Override
115
    protected List<String> getComboFields() {
116
        final List<String> l = new ArrayList<>(2);
117
        l.add("DATE");
118
        l.add("MONTANT_HA");
119
        return l;
120
    }
121
 
122
    /*
123
     * (non-Javadoc)
124
     *
125
     * @see org.openconcerto.devis.SQLElement#getComponent()
126
     */
127
    public SQLComponent createComponent() {
128
        return new GroupSQLComponent(this) {
129
 
130
            @Override
131
            public JComponent createEditor(String id) {
132
                if (id.equals("supplychain.stock.state.items")) {
133
                    return new EtatStockTable((JTextField) getEditor("MONTANT_HA"));
134
                } else {
135
                    return super.createEditor(id);
136
                }
137
            }
138
 
139
            @Override
140
            public void select(SQLRowAccessor r) {
141
                super.select(r);
142
                EtatStockTable table = (EtatStockTable) getEditor("supplychain.stock.state.items");
143
                if (r != null) {
144
                    table.insertFrom("ID_ETAT_STOCK", r.getID());
145
                }
146
            }
147
 
148
            @Override
149
            public void update() {
150
                super.update();
151
                EtatStockTable table = (EtatStockTable) getEditor("supplychain.stock.state.items");
152
                table.updateField("ID_ETAT_STOCK", getSelectedID());
153
            }
154
        };
155
    }
156
 
157
    @Override
158
    protected String createCode() {
159
        return createCodeOfPackage() + ".state";
160
    }
161
 
162
}