OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 132 | 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.supplier.element;
15
 
16
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
17
import org.openconcerto.erp.core.common.ui.DeviseField;
80 ilm 18
import org.openconcerto.erp.core.finance.accounting.element.MouvementSQLElement;
19
import org.openconcerto.erp.rights.ComptaUserRight;
18 ilm 20
import org.openconcerto.sql.element.BaseSQLComponent;
21
import org.openconcerto.sql.element.SQLComponent;
80 ilm 22
import org.openconcerto.sql.model.SQLRow;
23
import org.openconcerto.sql.model.SQLRowAccessor;
24
import org.openconcerto.sql.model.SQLRowValues;
25
import org.openconcerto.sql.request.ListSQLRequest;
18 ilm 26
import org.openconcerto.sql.sqlobject.ElementComboBox;
80 ilm 27
import org.openconcerto.sql.users.rights.UserRightsManager;
28
import org.openconcerto.sql.view.list.IListe;
29
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
30
import org.openconcerto.sql.view.list.RowAction;
31
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
18 ilm 32
import org.openconcerto.ui.DefaultGridBagConstraints;
33
import org.openconcerto.ui.JDate;
80 ilm 34
import org.openconcerto.utils.ExceptionHandler;
35
import org.openconcerto.utils.GestionDevise;
18 ilm 36
 
37
import java.awt.GridBagConstraints;
38
import java.awt.GridBagLayout;
80 ilm 39
import java.awt.event.ActionEvent;
40
import java.sql.SQLException;
18 ilm 41
import java.util.ArrayList;
42
import java.util.List;
43
 
80 ilm 44
import javax.swing.AbstractAction;
18 ilm 45
import javax.swing.JLabel;
80 ilm 46
import javax.swing.JOptionPane;
18 ilm 47
import javax.swing.JTextField;
48
 
49
public class EcheanceFournisseurSQLElement extends ComptaSQLConfElement {
50
 
51
    public EcheanceFournisseurSQLElement() {
52
        super("ECHEANCE_FOURNISSEUR", "une échéance fournisseur", "échéances fournisseurs");
80 ilm 53
 
54
        PredicateRowAction actionShowSource = new PredicateRowAction(new AbstractAction("Voir la source") {
55
 
56
            public void actionPerformed(ActionEvent e) {
57
                SQLRow row = IListe.get(e).fetchSelectedRow();
58
                MouvementSQLElement.showSource(row.getInt("ID_MOUVEMENT"));
59
            }
60
        }, false);
61
        actionShowSource.setPredicate(IListeEvent.getNonEmptySelectionPredicate());
62
        getRowActions().add(actionShowSource);
63
        if (UserRightsManager.getCurrentUserRights().haveRight(ComptaUserRight.MENU)) {
64
 
65
            RowAction actionCancel = new RowAction(new AbstractAction("Annuler la régularisation en comptabilité") {
66
 
67
                public void actionPerformed(ActionEvent e) {
68
 
69
                    int answer = JOptionPane.showConfirmDialog(null, "Etes vous sûr de vouloir annuler la régularisation ?");
70
                    if (answer == JOptionPane.YES_OPTION) {
71
                        SQLRow row = IListe.get(e).getSelectedRow().asRow();
72
                        SQLRowValues rowVals = row.createEmptyUpdateRow();
73
                        rowVals.put("REG_COMPTA", Boolean.FALSE);
74
                        try {
75
                            rowVals.commit();
76
                        } catch (SQLException e1) {
77
                            ExceptionHandler.handle("Une erreur est survenue lors de l'annulation de la régularisation.", e1);
78
                        }
79
                    }
80
                }
81
            }, false) {
82
                @Override
93 ilm 83
                public boolean enabledFor(List<SQLRowValues> selection) {
80 ilm 84
                    if (selection != null && selection.size() == 1) {
85
                        SQLRowAccessor row = selection.get(0);
86
                        return row.getBoolean("REG_COMPTA");
87
                    } else {
88
                        return true;
89
                    }
90
                }
91
            };
92
            getRowActions().add(actionCancel);
93
 
94
            RowAction actionRegul = new RowAction(new AbstractAction("Régularisation en comptabilité") {
95
 
96
                public void actionPerformed(ActionEvent e) {
97
 
98
                    SQLRow row = IListe.get(e).fetchSelectedRow();
99
                    String price = GestionDevise.currencyToString(row.getLong("MONTANT"));
100
                    SQLRow rowFournisseur = row.getForeignRow("ID_FOURNISSEUR");
101
 
102
                    String nomFour = rowFournisseur.getString("NOM");
103
                    String piece = "";
104
                    SQLRow rowMvt = row.getForeignRow("ID_MOUVEMENT");
105
                    if (rowMvt != null) {
106
                        SQLRow rowPiece = rowMvt.getForeignRow("ID_PIECE");
107
                        piece = rowPiece.getString("NOM");
108
                    }
109
                    int answer = JOptionPane.showConfirmDialog(null, "Etes vous sûr de vouloir régulariser l'échéance de " + nomFour + " d'un montant de " + price
110
                            + "€ avec une saisie au kilometre?\nNom de la piéce : " + piece + ".");
111
                    if (answer == JOptionPane.YES_OPTION) {
112
 
113
                        SQLRowValues rowVals = row.createEmptyUpdateRow();
114
                        rowVals.put("REG_COMPTA", Boolean.TRUE);
115
                        try {
116
                            rowVals.commit();
117
                        } catch (SQLException e1) {
118
                            ExceptionHandler.handle("Une erreur est survenue lors de la régularisation.", e1);
119
                        }
120
                    }
121
                }
122
            }, false) {
123
                @Override
93 ilm 124
                public boolean enabledFor(List<SQLRowValues> selection) {
80 ilm 125
                    if (selection != null && selection.size() == 1) {
126
                        SQLRowAccessor row = selection.get(0);
127
                        return !row.getBoolean("REG_COMPTA");
128
                    } else {
129
                        return true;
130
                    }
131
                }
132
            };
133
            getRowActions().add(actionRegul);
134
 
135
        }
18 ilm 136
    }
137
 
80 ilm 138
    @Override
132 ilm 139
    protected void _initListRequest(ListSQLRequest req) {
140
        super._initListRequest(req);
141
        req.addToGraphToFetch("REG_COMPTA", "REGLE");
80 ilm 142
    }
143
 
18 ilm 144
    protected List<String> getListFields() {
145
        final List<String> l = new ArrayList<String>();
146
 
147
        l.add("MONTANT");
148
        l.add("DATE");
149
        l.add("ID_MOUVEMENT");
150
        l.add("ID_FOURNISSEUR");
151
        return l;
152
    }
153
 
154
    protected List<String> getComboFields() {
155
        final List<String> l = new ArrayList<String>();
156
        l.add("DATE");
157
        l.add("ID_FOURNISSEUR");
158
        l.add("MONTANT");
159
        return l;
160
    }
161
 
162
    /*
163
     * (non-Javadoc)
164
     *
165
     * @see org.openconcerto.devis.SQLElement#getComponent()
166
     */
167
    public SQLComponent createComponent() {
168
        return new BaseSQLComponent(this) {
169
 
170
            private DeviseField montant;
171
            private JDate date;
172
            private JTextField idMouvement;
173
 
174
            public void addViews() {
175
                this.setLayout(new GridBagLayout());
176
                final GridBagConstraints c = new DefaultGridBagConstraints();
177
 
178
                this.montant = new DeviseField();
179
                this.date = new JDate();
180
                this.idMouvement = new JTextField();
181
                final ElementComboBox fournisseur = new ElementComboBox();
182
 
183
                // Mouvement
184
                JLabel labelMouvement = new JLabel("Mouvement");
185
                this.add(labelMouvement, c);
186
 
187
                c.weightx = 1;
188
                c.gridx++;
189
                this.add(this.idMouvement, c);
190
 
191
                // Date
192
                JLabel labelDate = new JLabel("Date");
193
                c.gridx++;
194
                this.add(labelDate, c);
195
 
196
                c.gridx++;
197
                c.weightx = 1;
198
                this.add(this.date, c);
199
 
200
                // Fournisseur
201
                JLabel labelFournisseur = new JLabel("Fournisseur");
202
                c.gridy++;
203
                c.gridx = 0;
204
 
205
                this.add(labelFournisseur, c);
206
 
207
                c.gridx++;
208
                c.weightx = 1;
209
                c.gridwidth = GridBagConstraints.REMAINDER;
210
                this.add(fournisseur, c);
211
 
212
                // montant
213
                c.gridwidth = 1;
214
                JLabel labelMontant = new JLabel("Montant");
215
                c.gridy++;
216
                c.gridx = 0;
217
                this.add(labelMontant, c);
218
 
219
                c.gridx++;
220
                c.weightx = 1;
221
                this.add(this.montant, c);
222
 
223
                this.addSQLObject(this.montant, "MONTANT");
224
                this.addSQLObject(this.date, "DATE");
225
                this.addRequiredSQLObject(fournisseur, "ID_FOURNISSEUR");
226
                this.addSQLObject(this.idMouvement, "ID_MOUVEMENT");
227
            }
228
        };
229
    }
230
 
57 ilm 231
    @Override
232
    protected String createCode() {
156 ilm 233
        return createCodeOfPackage() + ".commitment";
57 ilm 234
    }
18 ilm 235
}