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 | Last modification | View Log | RSS feed

Rev Author Line No. Line
94 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.product.element;
15
 
16
import java.awt.GridBagConstraints;
17
import java.awt.GridBagLayout;
18
import java.awt.event.ActionEvent;
19
import java.sql.SQLException;
20
import java.util.ArrayList;
21
import java.util.List;
22
 
23
import javax.swing.AbstractAction;
24
import javax.swing.JLabel;
25
 
26
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
27
import org.openconcerto.erp.core.sales.invoice.ui.FactureAffacturerTable;
28
import org.openconcerto.erp.core.supplychain.receipt.component.BonReceptionSQLComponent;
29
import org.openconcerto.sql.element.BaseSQLComponent;
30
import org.openconcerto.sql.element.SQLComponent;
31
import org.openconcerto.sql.model.SQLRowValues;
32
import org.openconcerto.sql.view.EditFrame;
33
import org.openconcerto.sql.view.EditPanel.EditMode;
34
import org.openconcerto.sql.view.EditPanelListener;
35
import org.openconcerto.sql.view.list.IListe;
36
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
37
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
38
import org.openconcerto.ui.DefaultGridBagConstraints;
39
 
40
public class ReliquatSQLElement extends ComptaSQLConfElement {
41
 
42
    private final String tableBonName;
43
 
44
    static public class ReliquatBRSQLElement extends ReliquatSQLElement {
45
        public ReliquatBRSQLElement() {
46
            super("RELIQUAT_BR", "un reliquat de BR", "reliquats de BR", "BON_RECEPTION");
47
        }
48
 
49
        @Override
50
        protected String createCode() {
51
            return createCodeFromPackage() + ".reliquatbr";
52
        }
53
    }
54
 
55
    public ReliquatSQLElement(final String tableName, final String singularName, final String pluralName, final String tableBonName) {
56
        super(tableName, singularName, pluralName);
57
        this.tableBonName = tableBonName;
58
 
59
        PredicateRowAction actionTR = new PredicateRowAction(new AbstractAction("Transfert vers Bon") {
60
 
61
            @Override
62
            public void actionPerformed(ActionEvent e) {
63
                final List<SQLRowValues> rows = IListe.get(e).getSelectedRows();
64
                EditFrame frame = new EditFrame(getForeignElement("ID_" + tableBonName), EditMode.CREATION);
65
                frame.addEditPanelListener(new EditPanelListener() {
66
 
67
                    @Override
68
                    public void modified() {
69
                    }
70
 
71
                    @Override
72
                    public void inserted(int id) {
73
                        for (SQLRowValues rowVals : rows) {
74
                            try {
75
                                SQLRowValues upRowVals = rowVals.createEmptyUpdateRow();
76
                                upRowVals.put("ID_BON_RECEPTION", id);
77
                                upRowVals.update();
78
                            } catch (SQLException exn) {
79
                                exn.printStackTrace();
80
                            }
81
                        }
82
 
83
                    }
84
 
85
                    @Override
86
                    public void deleted() {
87
                    }
88
 
89
                    @Override
90
                    public void cancelled() {
91
                    }
92
                });
93
 
94
                BonReceptionSQLComponent comp = (BonReceptionSQLComponent) frame.getSQLComponent();
95
                comp.loadFromReliquat(rows);
96
                frame.setVisible(true);
97
 
98
            }
99
        }, true);
100
        actionTR.setPredicate(IListeEvent.getNonEmptySelectionPredicate());
101
        getRowActions().add(actionTR);
102
    }
103
 
104
    public ReliquatSQLElement() {
105
        this("RELIQUAT_BL", "un reliquat de BL", "reliquats de BL", "BON_DE_LIVRAISON");
106
    }
107
 
108
    @Override
109
    protected String getParentFFName() {
110
 
111
        return "ID_" + this.tableBonName;
112
    }
113
 
114
    protected List<String> getListFields() {
115
        final List<String> l = new ArrayList<String>();
116
        // l.add("DATE");
117
        l.add("ID_" + this.tableBonName + "_ORIGINE");
118
        l.add("ID_ARTICLE");
119
        l.add("QTE_UNITAIRE");
120
        l.add("ID_UNITE_VENTE");
121
        l.add("QTE");
122
        l.add("ID_" + this.tableBonName);
123
        return l;
124
    }
125
 
126
    protected List<String> getComboFields() {
127
        final List<String> l = new ArrayList<String>();
128
        l.add("DATE");
129
        l.add("QTE");
130
        return l;
131
    }
132
 
133
    /*
134
     * (non-Javadoc)
135
     *
136
     * @see org.openconcerto.devis.SQLElement#getComponent()
137
     */
138
    public SQLComponent createComponent() {
139
        return new BaseSQLComponent(this) {
140
            FactureAffacturerTable table = new FactureAffacturerTable(null);
141
 
142
            public void addViews() {
143
 
144
                // FIXME CREATION DE L'UI
145
                this.setLayout(new GridBagLayout());
146
 
147
                GridBagConstraints c = new DefaultGridBagConstraints();
148
 
149
                this.add(new JLabel(getLabelFor("NB_FACT")), c);
150
                // c.gridx++;
151
                // c.weightx = 1;
152
                // JTextField fieldNbFact = new JTextField();
153
                // this.add(fieldNbFact, c);
154
                //
155
                // c.gridx++;
156
                // c.weightx = 0;
157
                // this.add(new JLabel(getLabelFor("MONTANT_FACT")), c);
158
                // c.gridx++;
159
                // c.weightx = 1;
160
                // DeviseField fieldMontantFact = new DeviseField();
161
                // this.add(fieldMontantFact, c);
162
                //
163
                // c.gridx++;
164
                // c.weightx = 0;
165
                // this.add(new JLabel(getLabelFor("DATE")), c);
166
                // c.gridx++;
167
                //
168
                // JDate date = new JDate();
169
                // this.add(date, c);
170
                //
171
                // c.gridwidth = GridBagConstraints.REMAINDER;
172
                // c.gridx = 0;
173
                // c.gridy++;
174
                // this.add(this.table, c);
175
                //
176
                // this.addView(fieldNbFact, "NB_FACT");
177
                // this.addSQLObject(fieldMontantFact, "MONTANT_FACT");
178
                // this.addView(date, "DATE");
179
            }
180
 
181
        };
182
    }
183
 
184
    @Override
185
    protected String createCode() {
186
        return createCodeFromPackage() + ".reliquatbl";
187
    }
188
}