OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 57 | Rev 93 | 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.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
83
                public boolean enabledFor(List<SQLRowAccessor> selection) {
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
124
                public boolean enabledFor(List<SQLRowAccessor> selection) {
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
139
    public synchronized ListSQLRequest createListRequest() {
140
        return new ListSQLRequest(this.getTable(), this.getListFields()) {
141
            @Override
142
            protected void customizeToFetch(SQLRowValues graphToFetch) {
143
                super.customizeToFetch(graphToFetch);
144
                graphToFetch.put("REG_COMPTA", null);
145
                graphToFetch.put("REGLE", null);
146
            }
147
        };
148
    }
149
 
18 ilm 150
    protected List<String> getListFields() {
151
        final List<String> l = new ArrayList<String>();
152
 
153
        l.add("MONTANT");
154
        l.add("DATE");
155
        l.add("ID_MOUVEMENT");
156
        l.add("ID_FOURNISSEUR");
157
        return l;
158
    }
159
 
160
    protected List<String> getComboFields() {
161
        final List<String> l = new ArrayList<String>();
162
        l.add("DATE");
163
        l.add("ID_FOURNISSEUR");
164
        l.add("MONTANT");
165
        return l;
166
    }
167
 
168
    /*
169
     * (non-Javadoc)
170
     *
171
     * @see org.openconcerto.devis.SQLElement#getComponent()
172
     */
173
    public SQLComponent createComponent() {
174
        return new BaseSQLComponent(this) {
175
 
176
            private DeviseField montant;
177
            private JDate date;
178
            private JTextField idMouvement;
179
 
180
            public void addViews() {
181
                this.setLayout(new GridBagLayout());
182
                final GridBagConstraints c = new DefaultGridBagConstraints();
183
 
184
                this.montant = new DeviseField();
185
                this.date = new JDate();
186
                this.idMouvement = new JTextField();
187
                final ElementComboBox fournisseur = new ElementComboBox();
188
 
189
                // Mouvement
190
                JLabel labelMouvement = new JLabel("Mouvement");
191
                this.add(labelMouvement, c);
192
 
193
                c.weightx = 1;
194
                c.gridx++;
195
                this.add(this.idMouvement, c);
196
 
197
                // Date
198
                JLabel labelDate = new JLabel("Date");
199
                c.gridx++;
200
                this.add(labelDate, c);
201
 
202
                c.gridx++;
203
                c.weightx = 1;
204
                this.add(this.date, c);
205
 
206
                // Fournisseur
207
                JLabel labelFournisseur = new JLabel("Fournisseur");
208
                c.gridy++;
209
                c.gridx = 0;
210
 
211
                this.add(labelFournisseur, c);
212
 
213
                c.gridx++;
214
                c.weightx = 1;
215
                c.gridwidth = GridBagConstraints.REMAINDER;
216
                this.add(fournisseur, c);
217
 
218
                // montant
219
                c.gridwidth = 1;
220
                JLabel labelMontant = new JLabel("Montant");
221
                c.gridy++;
222
                c.gridx = 0;
223
                this.add(labelMontant, c);
224
 
225
                c.gridx++;
226
                c.weightx = 1;
227
                this.add(this.montant, c);
228
 
229
                this.addSQLObject(this.montant, "MONTANT");
230
                this.addSQLObject(this.date, "DATE");
231
                this.addRequiredSQLObject(fournisseur, "ID_FOURNISSEUR");
232
                this.addSQLObject(this.idMouvement, "ID_MOUVEMENT");
233
            }
234
        };
235
    }
236
 
57 ilm 237
    @Override
238
    protected String createCode() {
239
        return createCodeFromPackage() + ".commitment";
240
    }
18 ilm 241
}