OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 151 | Rev 174 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 151 Rev 156
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
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
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
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.
9
 * language governing permissions and limitations under the License.
10
 * 
10
 * 
11
 * When distributing the software, include this License Header Notice in each file.
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.erp.core.sales.invoice.element;
14
 package org.openconcerto.erp.core.sales.invoice.element;
15
 
15
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
17
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
17
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
18
import org.openconcerto.erp.core.common.element.NumerotationAutoSQLElement;
18
import org.openconcerto.erp.core.common.element.NumerotationAutoSQLElement;
19
import org.openconcerto.erp.core.common.ui.DeviseField;
19
import org.openconcerto.erp.core.common.ui.DeviseField;
20
import org.openconcerto.erp.core.customerrelationship.customer.element.RelanceSQLElement;
20
import org.openconcerto.erp.core.customerrelationship.customer.element.RelanceSQLElement;
21
import org.openconcerto.erp.core.finance.accounting.element.MouvementSQLElement;
21
import org.openconcerto.erp.core.finance.accounting.element.MouvementSQLElement;
22
import org.openconcerto.erp.core.sales.invoice.report.MailRelanceCreator;
22
import org.openconcerto.erp.core.sales.invoice.report.MailRelanceCreator;
23
import org.openconcerto.erp.core.sales.invoice.report.VenteFactureXmlSheet;
23
import org.openconcerto.erp.core.sales.invoice.report.VenteFactureXmlSheet;
24
import org.openconcerto.erp.rights.ComptaUserRight;
24
import org.openconcerto.erp.rights.ComptaUserRight;
25
import org.openconcerto.sql.Configuration;
25
import org.openconcerto.sql.Configuration;
26
import org.openconcerto.sql.element.BaseSQLComponent;
26
import org.openconcerto.sql.element.BaseSQLComponent;
27
import org.openconcerto.sql.element.SQLComponent;
27
import org.openconcerto.sql.element.SQLComponent;
28
import org.openconcerto.sql.element.SQLElement;
28
import org.openconcerto.sql.element.SQLElement;
29
import org.openconcerto.sql.model.FieldPath;
29
import org.openconcerto.sql.model.FieldPath;
30
import org.openconcerto.sql.model.SQLBase;
30
import org.openconcerto.sql.model.SQLBase;
31
import org.openconcerto.sql.model.SQLField;
31
import org.openconcerto.sql.model.SQLField;
32
import org.openconcerto.sql.model.SQLRow;
32
import org.openconcerto.sql.model.SQLRow;
33
import org.openconcerto.sql.model.SQLRowAccessor;
33
import org.openconcerto.sql.model.SQLRowAccessor;
34
import org.openconcerto.sql.model.SQLRowValues;
34
import org.openconcerto.sql.model.SQLRowValues;
35
import org.openconcerto.sql.model.SQLTable;
35
import org.openconcerto.sql.model.SQLTable;
36
import org.openconcerto.sql.model.graph.Path;
36
import org.openconcerto.sql.model.graph.Path;
37
import org.openconcerto.sql.model.graph.PathBuilder;
37
import org.openconcerto.sql.model.graph.PathBuilder;
38
import org.openconcerto.sql.request.ListSQLRequest;
38
import org.openconcerto.sql.request.ListSQLRequest;
39
import org.openconcerto.sql.sqlobject.ElementComboBox;
39
import org.openconcerto.sql.sqlobject.ElementComboBox;
40
import org.openconcerto.sql.users.rights.UserRightsManager;
40
import org.openconcerto.sql.users.rights.UserRightsManager;
41
import org.openconcerto.sql.view.EditFrame;
41
import org.openconcerto.sql.view.EditFrame;
42
import org.openconcerto.sql.view.EditPanel.EditMode;
42
import org.openconcerto.sql.view.EditPanel.EditMode;
43
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn;
43
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn;
44
import org.openconcerto.sql.view.list.IListe;
44
import org.openconcerto.sql.view.list.IListe;
45
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
45
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
46
import org.openconcerto.sql.view.list.RowAction;
46
import org.openconcerto.sql.view.list.RowAction;
47
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
47
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
48
import org.openconcerto.sql.view.list.SQLTableModelSource;
48
import org.openconcerto.sql.view.list.SQLTableModelSource;
49
import org.openconcerto.ui.DefaultGridBagConstraints;
49
import org.openconcerto.ui.DefaultGridBagConstraints;
50
import org.openconcerto.ui.EmailComposer;
50
import org.openconcerto.ui.EmailComposer;
51
import org.openconcerto.ui.JDate;
51
import org.openconcerto.ui.JDate;
52
import org.openconcerto.utils.CollectionUtils;
52
import org.openconcerto.utils.CollectionUtils;
53
import org.openconcerto.utils.ExceptionHandler;
53
import org.openconcerto.utils.ExceptionHandler;
54
import org.openconcerto.utils.GestionDevise;
54
import org.openconcerto.utils.GestionDevise;
55
import org.openconcerto.utils.ListMap;
55
import org.openconcerto.utils.ListMap;
56
 
56
 
57
import java.awt.GridBagConstraints;
57
import java.awt.GridBagConstraints;
58
import java.awt.GridBagLayout;
58
import java.awt.GridBagLayout;
59
import java.awt.event.ActionEvent;
59
import java.awt.event.ActionEvent;
60
import java.io.File;
60
import java.io.File;
61
import java.io.IOException;
61
import java.io.IOException;
62
import java.sql.SQLException;
62
import java.sql.SQLException;
63
import java.text.SimpleDateFormat;
63
import java.text.SimpleDateFormat;
64
import java.util.ArrayList;
64
import java.util.ArrayList;
65
import java.util.Date;
65
import java.util.Date;
66
import java.util.List;
66
import java.util.List;
67
import java.util.Locale;
67
import java.util.Locale;
68
import java.util.Set;
68
import java.util.Set;
69
 
69
 
70
import javax.swing.AbstractAction;
70
import javax.swing.AbstractAction;
71
import javax.swing.JLabel;
71
import javax.swing.JLabel;
72
import javax.swing.JOptionPane;
72
import javax.swing.JOptionPane;
73
import javax.swing.JTextField;
73
import javax.swing.JTextField;
74
import javax.swing.SwingUtilities;
74
import javax.swing.SwingUtilities;
75
 
75
 
76
public class EcheanceClientSQLElement extends ComptaSQLConfElement {
76
public class EcheanceClientSQLElement extends ComptaSQLConfElement {
77
 
77
 
78
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy", Locale.ENGLISH);
78
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy", Locale.ENGLISH);
79
 
79
 
80
    public EcheanceClientSQLElement() {
80
    public EcheanceClientSQLElement() {
81
        super("ECHEANCE_CLIENT", "une échéance client", "échéances clients");
81
        super("ECHEANCE_CLIENT", "une échéance client", "échéances clients");
82
        {
82
        {
83
            PredicateRowAction action = new PredicateRowAction(new AbstractAction("Détails client") {
83
            PredicateRowAction action = new PredicateRowAction(new AbstractAction("Détails client") {
84
 
84
 
85
                @Override
85
                @Override
86
                public void actionPerformed(ActionEvent arg0) {
86
                public void actionPerformed(ActionEvent arg0) {
87
 
87
 
88
                    SQLElement eltClient = Configuration.getInstance().getDirectory().getElement(((ComptaPropsConfiguration) Configuration.getInstance()).getRootSociete().getTable("CLIENT"));
88
                    SQLElement eltClient = Configuration.getInstance().getDirectory().getElement(((ComptaPropsConfiguration) Configuration.getInstance()).getRootSociete().getTable("CLIENT"));
89
 
89
 
90
                    EditFrame edit = new EditFrame(eltClient, EditMode.MODIFICATION);
90
                    EditFrame edit = new EditFrame(eltClient, EditMode.MODIFICATION);
91
 
91
 
92
                    edit.selectionId(IListe.get(arg0).getSelectedRow().asRow().getInt("ID_CLIENT"));
92
                    edit.selectionId(IListe.get(arg0).getSelectedRow().asRow().getInt("ID_CLIENT"));
93
                    edit.setVisible(true);
93
                    edit.setVisible(true);
94
                }
94
                }
95
            }, false);
95
            }, false);
96
            action.setPredicate(IListeEvent.getSingleSelectionPredicate());
96
            action.setPredicate(IListeEvent.getSingleSelectionPredicate());
97
            getRowActions().add(action);
97
            getRowActions().add(action);
98
        }
98
        }
99
        {
99
        {
100
            PredicateRowAction action = new PredicateRowAction(new AbstractAction("Voir la source") {
100
            PredicateRowAction action = new PredicateRowAction(new AbstractAction("Voir la source") {
101
 
101
 
102
                @Override
102
                @Override
103
                public void actionPerformed(ActionEvent arg0) {
103
                public void actionPerformed(ActionEvent arg0) {
104
 
104
 
105
                    SQLRow row = IListe.get(arg0).fetchSelectedRow();
105
                    SQLRow row = IListe.get(arg0).fetchSelectedRow();
106
                    MouvementSQLElement.showSource(row.getInt("ID_MOUVEMENT"));
106
                    MouvementSQLElement.showSource(row.getInt("ID_MOUVEMENT"));
107
                }
107
                }
108
            }, false);
108
            }, false);
109
            action.setPredicate(IListeEvent.getSingleSelectionPredicate());
109
            action.setPredicate(IListeEvent.getSingleSelectionPredicate());
110
            getRowActions().add(action);
110
            getRowActions().add(action);
111
        }
111
        }
112
 
112
 
113
        {
113
        {
114
            PredicateRowAction action = new PredicateRowAction(new AbstractAction("Envoyer un mail") {
114
            PredicateRowAction action = new PredicateRowAction(new AbstractAction("Envoyer un mail") {
115
 
115
 
116
                @Override
116
                @Override
117
                public void actionPerformed(ActionEvent arg0) {
117
                public void actionPerformed(ActionEvent arg0) {
118
 
118
 
119
                    SQLRow row = IListe.get(arg0).fetchSelectedRow();
119
                    SQLRow row = IListe.get(arg0).fetchSelectedRow();
120
                    sendMail(row);
120
                    sendMail(row);
121
                }
121
                }
122
            }, false);
122
            }, false);
123
            action.setPredicate(IListeEvent.getSingleSelectionPredicate());
123
            action.setPredicate(IListeEvent.getSingleSelectionPredicate());
124
            getRowActions().add(action);
124
            getRowActions().add(action);
125
        }
125
        }
126
 
126
 
127
        if (UserRightsManager.getCurrentUserRights().haveRight(ComptaUserRight.MENU)) {
127
        if (UserRightsManager.getCurrentUserRights().haveRight(ComptaUserRight.MENU)) {
128
            RowAction actionCancel = new RowAction(new AbstractAction("Annuler la régularisation en comptabilité") {
128
            RowAction actionCancel = new RowAction(new AbstractAction("Annuler la régularisation en comptabilité") {
129
 
129
 
130
                public void actionPerformed(ActionEvent e) {
130
                public void actionPerformed(ActionEvent e) {
131
 
131
 
132
                    int answer = JOptionPane.showConfirmDialog(null, "Etes vous sûr de vouloir annuler la régularisation ?");
132
                    int answer = JOptionPane.showConfirmDialog(null, "Etes vous sûr de vouloir annuler la régularisation ?");
133
                    if (answer == JOptionPane.YES_OPTION) {
133
                    if (answer == JOptionPane.YES_OPTION) {
134
                        SQLRow row = IListe.get(e).getSelectedRow().asRow();
134
                        SQLRow row = IListe.get(e).getSelectedRow().asRow();
135
                        SQLRowValues rowVals = row.createEmptyUpdateRow();
135
                        SQLRowValues rowVals = row.createEmptyUpdateRow();
136
                        rowVals.put("REG_COMPTA", Boolean.FALSE);
136
                        rowVals.put("REG_COMPTA", Boolean.FALSE);
137
                        try {
137
                        try {
138
                            rowVals.commit();
138
                            rowVals.commit();
139
                        } catch (SQLException e1) {
139
                        } catch (SQLException e1) {
140
                            // TODO Auto-generated catch block
140
                            // TODO Auto-generated catch block
141
                            e1.printStackTrace();
141
                            e1.printStackTrace();
142
                        }
142
                        }
143
                    }
143
                    }
144
                }
144
                }
145
            }, false) {
145
            }, false) {
146
                @Override
146
                @Override
147
                public boolean enabledFor(List<SQLRowValues> selection) {
147
                public boolean enabledFor(List<SQLRowValues> selection) {
148
                    if (selection != null && selection.size() == 1) {
148
                    if (selection != null && selection.size() == 1) {
149
                        SQLRowAccessor row = selection.get(0);
149
                        SQLRowAccessor row = selection.get(0);
150
                        return row.getBoolean("REG_COMPTA");
150
                        return row.getBoolean("REG_COMPTA");
151
                    } else {
151
                    } else {
152
                        return true;
152
                        return true;
153
                    }
153
                    }
154
                }
154
                }
155
            };
155
            };
156
            getRowActions().add(actionCancel);
156
            getRowActions().add(actionCancel);
157
 
157
 
158
            RowAction actionRegul = new RowAction(new AbstractAction("Régularisation en comptabilité") {
158
            RowAction actionRegul = new RowAction(new AbstractAction("Régularisation en comptabilité") {
159
 
159
 
160
                public void actionPerformed(ActionEvent e) {
160
                public void actionPerformed(ActionEvent e) {
161
 
161
 
162
                    SQLRow row = IListe.get(e).fetchSelectedRow();
162
                    SQLRow row = IListe.get(e).fetchSelectedRow();
163
                    String price = GestionDevise.currencyToString(row.getLong("MONTANT"));
163
                    String price = GestionDevise.currencyToString(row.getLong("MONTANT"));
164
                    SQLRow rowClient = row.getForeignRow("ID_CLIENT");
164
                    SQLRow rowClient = row.getForeignRow("ID_CLIENT");
165
                    String nomClient = rowClient.getString("NOM");
165
                    String nomClient = rowClient.getString("NOM");
166
                    String piece = "";
166
                    String piece = "";
167
                    SQLRow rowMvt = row.getForeignRow("ID_MOUVEMENT");
167
                    SQLRow rowMvt = row.getForeignRow("ID_MOUVEMENT");
168
                    if (rowMvt != null) {
168
                    if (rowMvt != null) {
169
                        SQLRow rowPiece = rowMvt.getForeignRow("ID_PIECE");
169
                        SQLRow rowPiece = rowMvt.getForeignRow("ID_PIECE");
170
                        piece = rowPiece.getString("NOM");
170
                        piece = rowPiece.getString("NOM");
171
                    }
171
                    }
172
                    int answer = JOptionPane.showConfirmDialog(null,
172
                    int answer = JOptionPane.showConfirmDialog(null,
173
                            "Etes vous sûr de vouloir régulariser l'échéance de " + nomClient + " d'un montant de " + price + "€ avec une saisie au kilometre?\nNom de la piéce : " + piece + ".");
173
                            "Etes vous sûr de vouloir régulariser l'échéance de " + nomClient + " d'un montant de " + price + "€ avec une saisie au kilometre?\nNom de la piéce : " + piece + ".");
174
                    if (answer == JOptionPane.YES_OPTION) {
174
                    if (answer == JOptionPane.YES_OPTION) {
175
 
175
 
176
                        SQLRowValues rowVals = row.createEmptyUpdateRow();
176
                        SQLRowValues rowVals = row.createEmptyUpdateRow();
177
                        rowVals.put("REG_COMPTA", Boolean.TRUE);
177
                        rowVals.put("REG_COMPTA", Boolean.TRUE);
178
                        try {
178
                        try {
179
                            rowVals.commit();
179
                            rowVals.commit();
180
                        } catch (SQLException e1) {
180
                        } catch (SQLException e1) {
181
                            // TODO Auto-generated catch block
181
                            // TODO Auto-generated catch block
182
                            e1.printStackTrace();
182
                            e1.printStackTrace();
183
                        }
183
                        }
184
                    }
184
                    }
185
                }
185
                }
186
            }, false) {
186
            }, false) {
187
                @Override
187
                @Override
188
                public boolean enabledFor(List<SQLRowValues> selection) {
188
                public boolean enabledFor(List<SQLRowValues> selection) {
189
                    if (selection != null && selection.size() == 1) {
189
                    if (selection != null && selection.size() == 1) {
190
                        SQLRowAccessor row = selection.get(0);
190
                        SQLRowAccessor row = selection.get(0);
191
                        return !row.getBoolean("REG_COMPTA");
191
                        return !row.getBoolean("REG_COMPTA");
192
                    } else {
192
                    } else {
193
                        return true;
193
                        return true;
194
                    }
194
                    }
195
                }
195
                }
196
            };
196
            };
197
            getRowActions().add(actionRegul);
197
            getRowActions().add(actionRegul);
198
        }
198
        }
199
 
199
 
200
    }
200
    }
201
 
201
 
202
 
202
 
203
    private void sendMail(final SQLRow row) {
203
    private void sendMail(final SQLRow row) {
204
 
204
 
205
        SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
205
        SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
206
 
206
 
207
        if (row != null) {
207
        if (row != null) {
208
 
208
 
209
            int idMvtSource = MouvementSQLElement.getSourceId(row.getInt("ID_MOUVEMENT"));
209
            int idMvtSource = MouvementSQLElement.getSourceId(row.getInt("ID_MOUVEMENT"));
210
            SQLRow rowMvtSource = base.getTable("MOUVEMENT").getRow(idMvtSource);
210
            SQLRow rowMvtSource = base.getTable("MOUVEMENT").getRow(idMvtSource);
211
 
211
 
212
            if (!rowMvtSource.getString("SOURCE").equalsIgnoreCase("SAISIE_VENTE_FACTURE")) {
212
            if (!rowMvtSource.getString("SOURCE").equalsIgnoreCase("SAISIE_VENTE_FACTURE")) {
213
                // this.relancer.setEnabled(false);
213
                // this.relancer.setEnabled(false);
214
                return;
214
                return;
215
            }
215
            }
216
            int idFact = rowMvtSource.getInt("IDSOURCE");
216
            int idFact = rowMvtSource.getInt("IDSOURCE");
217
            SQLRow rowFacture = base.getTable("SAISIE_VENTE_FACTURE").getRow(idFact);
217
            SQLRow rowFacture = base.getTable("SAISIE_VENTE_FACTURE").getRow(idFact);
218
 
218
 
219
            final VenteFactureXmlSheet sheet = new VenteFactureXmlSheet(rowFacture);
219
            final VenteFactureXmlSheet sheet = new VenteFactureXmlSheet(rowFacture);
220
 
220
 
221
            Set<SQLField> setContact = null;
221
            Set<SQLField> setContact = null;
222
            SQLTable tableContact = Configuration.getInstance().getRoot().findTable("CONTACT");
222
            SQLTable tableContact = Configuration.getInstance().getRoot().findTable("CONTACT");
223
            setContact = row.getTable().getForeignKeys(tableContact);
223
            setContact = row.getTable().getForeignKeys(tableContact);
224
 
224
 
225
            Set<SQLField> setClient = null;
225
            Set<SQLField> setClient = null;
226
            SQLTable tableClient = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete().getTable("CLIENT");
226
            SQLTable tableClient = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete().getTable("CLIENT");
227
            setClient = row.getTable().getForeignKeys(tableClient);
227
            setClient = row.getTable().getForeignKeys(tableClient);
228
 
228
 
229
            // Récupération du mail du client
229
            // Récupération du mail du client
230
            String mail = "";
230
            String mail = "";
231
            for (SQLField field : setContact) {
231
            for (SQLField field : setContact) {
232
                if (mail == null || mail.trim().length() == 0) {
232
                if (mail == null || mail.trim().length() == 0) {
233
                    mail = row.getForeignRow(field.getName()).getString("EMAIL");
233
                    mail = row.getForeignRow(field.getName()).getString("EMAIL");
234
                }
234
                }
235
            }
235
            }
236
 
236
 
237
            for (SQLField field : setClient) {
237
            for (SQLField field : setClient) {
238
                SQLRow rowCli = row.getForeignRow(field.getName());
238
                SQLRow rowCli = row.getForeignRow(field.getName());
239
                if (mail == null || mail.trim().length() == 0) {
239
                if (mail == null || mail.trim().length() == 0) {
240
                    mail = rowCli.getString("MAIL");
240
                    mail = rowCli.getString("MAIL");
241
                }
241
                }
242
            }
242
            }
243
            final String adresseMail = mail;
243
            final String adresseMail = mail;
244
 
244
 
245
            MailRelanceCreator creator = new MailRelanceCreator();
245
            MailRelanceCreator creator = new MailRelanceCreator();
246
            final String references = creator.getObject(row);
246
            final String references = creator.getObject(row);
247
            final String text = creator.getValue(row);
247
            final String text = creator.getValue(row);
248
 
248
 
249
            final Thread t = new Thread() {
249
            final Thread t = new Thread() {
250
                @Override
250
                @Override
251
                public void run() {
251
                public void run() {
252
 
252
 
253
                    final File f;
253
                    final File f;
254
                    try {
254
                    try {
255
                        f = sheet.getOrCreatePDFDocumentFile(true);
255
                        f = sheet.getOrCreatePDFDocumentFile(true);
256
 
256
 
257
                        EmailComposer.getInstance().compose(adresseMail, references, text, f.getAbsoluteFile());
257
                        EmailComposer.getInstance().compose(adresseMail, references, text, f.getAbsoluteFile());
258
 
258
 
259
                        // Création d'une relance
259
                        // Création d'une relance
260
                        String numero = NumerotationAutoSQLElement.getNextNumero(RelanceSQLElement.class);
260
                        String numero = NumerotationAutoSQLElement.getNextNumero(RelanceSQLElement.class);
261
                        SQLRowValues rowValsR = new SQLRowValues(row.getTable().getTable("RELANCE"));
261
                        SQLRowValues rowValsR = new SQLRowValues(row.getTable().getTable("RELANCE"));
262
                        rowValsR.put("DATE", new Date());
262
                        rowValsR.put("DATE", new Date());
263
                        rowValsR.put("NUMERO", numero);
263
                        rowValsR.put("NUMERO", numero);
264
                        rowValsR.put("ID_CLIENT", row.getForeignID("ID_CLIENT"));
264
                        rowValsR.put("ID_CLIENT", row.getForeignID("ID_CLIENT"));
265
                        rowValsR.put("ID_SAISIE_VENTE_FACTURE", row.getForeignID("ID_SAISIE_VENTE_FACTURE"));
265
                        rowValsR.put("ID_SAISIE_VENTE_FACTURE", row.getForeignID("ID_SAISIE_VENTE_FACTURE"));
266
                        rowValsR.put("MONTANT", row.getObject("MONTANT"));
266
                        rowValsR.put("MONTANT", row.getObject("MONTANT"));
267
                        rowValsR.put("INFOS", "Email");
267
                        rowValsR.put("INFOS", "Email");
268
                        rowValsR.put("ID_ECHEANCE_CLIENT", row.getID());
268
                        rowValsR.put("ID_ECHEANCE_CLIENT", row.getID());
269
                        try {
269
                        try {
270
                            rowValsR.insert();
270
                            rowValsR.insert();
271
 
271
 
272
                            SQLTable tableNum = getTable().getBase().getTable("NUMEROTATION_AUTO");
272
                            SQLTable tableNum = getTable().getBase().getTable("NUMEROTATION_AUTO");
273
                            SQLRowValues rowVals = new SQLRowValues(tableNum);
273
                            SQLRowValues rowVals = new SQLRowValues(tableNum);
274
                            int val = tableNum.getRow(2).getInt("RELANCE_START");
274
                            int val = tableNum.getRow(2).getInt("RELANCE_START");
275
                            val++;
275
                            val++;
276
                            rowVals.put("RELANCE_START", Integer.valueOf(val));
276
                            rowVals.put("RELANCE_START", Integer.valueOf(val));
277
 
277
 
278
                            rowVals.update(2);
278
                            rowVals.update(2);
279
 
279
 
280
                            // Incrémentation du nombre de relance
280
                            // Incrémentation du nombre de relance
281
                            int nbRelance = row.getInt("NOMBRE_RELANCE");
281
                            int nbRelance = row.getInt("NOMBRE_RELANCE");
282
                            nbRelance++;
282
                            nbRelance++;
283
 
283
 
284
                            SQLRowValues rowValsEch = new SQLRowValues(row.getTable());
284
                            SQLRowValues rowValsEch = new SQLRowValues(row.getTable());
285
                            rowValsEch.put("NOMBRE_RELANCE", nbRelance);
285
                            rowValsEch.put("NOMBRE_RELANCE", nbRelance);
286
                            rowValsEch.put("DATE_LAST_RELANCE", new Date());
286
                            rowValsEch.put("DATE_LAST_RELANCE", new Date());
287
 
287
 
288
                            rowValsEch.update(row.getID());
288
                            rowValsEch.update(row.getID());
289
 
289
 
290
                        } catch (SQLException e) {
290
                        } catch (SQLException e) {
291
 
291
 
292
                            e.printStackTrace();
292
                            e.printStackTrace();
293
                        }
293
                        }
294
                    } catch (IOException exn) {
294
                    } catch (IOException exn) {
295
                        exn.printStackTrace();
295
                        exn.printStackTrace();
296
                    } catch (InterruptedException exn) {
296
                    } catch (InterruptedException exn) {
297
                        exn.printStackTrace();
297
                        exn.printStackTrace();
298
                    } catch (Exception e1) {
298
                    } catch (Exception e1) {
299
                        // TODO Auto-generated catch block
299
                        // TODO Auto-generated catch block
300
                        e1.printStackTrace();
300
                        e1.printStackTrace();
301
                    }
301
                    }
302
 
302
 
303
                }
303
                }
304
            };
304
            };
305
 
305
 
306
            t.start();
306
            t.start();
307
        }
307
        }
308
    }
308
    }
309
 
309
 
310
    @Override
310
    @Override
311
    public ListMap<String, String> getShowAs() {
311
    public ListMap<String, String> getShowAs() {
312
        ListMap<String, String> map = new ListMap<String, String>();
312
        ListMap<String, String> map = new ListMap<String, String>();
313
        return map;
313
        return map;
314
    }
314
    }
315
 
315
 
316
    protected List<String> getListFields() {
316
    protected List<String> getListFields() {
317
        final List<String> l = new ArrayList<String>();
317
        final List<String> l = new ArrayList<String>();
318
 
318
 
319
 
319
 
320
            l.add("ID_SAISIE_VENTE_FACTURE");
320
            l.add("ID_SAISIE_VENTE_FACTURE");
321
            l.add("DATE");
321
            l.add("DATE");
322
            l.add("ID_CLIENT");
322
            l.add("ID_CLIENT");
323
            l.add("MONTANT");
323
            l.add("MONTANT");
324
            l.add("ID_MOUVEMENT");
324
            l.add("ID_MOUVEMENT");
325
                l.add("NOMBRE_RELANCE");
325
                l.add("NOMBRE_RELANCE");
326
            l.add("INFOS");
326
            l.add("INFOS");
327
            l.add("DATE_LAST_RELANCE");
327
            l.add("DATE_LAST_RELANCE");
328
        return l;
328
        return l;
329
    }
329
    }
330
 
330
 
331
    protected List<String> getComboFields() {
331
    protected List<String> getComboFields() {
332
        final List<String> l = new ArrayList<String>();
332
        final List<String> l = new ArrayList<String>();
333
        l.add("DATE");
333
        l.add("DATE");
334
        l.add("ID_CLIENT");
334
        l.add("ID_CLIENT");
335
        l.add("MONTANT");
335
        l.add("MONTANT");
336
        return l;
336
        return l;
337
    }
337
    }
338
 
338
 
339
    @Override
339
    @Override
340
    protected void _initListRequest(ListSQLRequest req) {
340
    protected void _initListRequest(ListSQLRequest req) {
341
        super._initListRequest(req);
341
        super._initListRequest(req);
342
        req.addToGraphToFetch("REG_COMPTA", "REGLE");
342
        req.addToGraphToFetch("REG_COMPTA", "REGLE");
343
    }
343
    }
344
 
344
 
345
    /*
345
    /*
346
     * (non-Javadoc)
346
     * (non-Javadoc)
347
     * 
347
     * 
348
     * @see org.openconcerto.devis.SQLElement#getComponent()
348
     * @see org.openconcerto.devis.SQLElement#getComponent()
349
     */
349
     */
350
    public SQLComponent createComponent() {
350
    public SQLComponent createComponent() {
351
        return new BaseSQLComponent(this) {
351
        return new BaseSQLComponent(this) {
352
 
352
 
353
            private DeviseField montant;
353
            private DeviseField montant;
354
            private JTextField nbRelance;
354
            private JTextField nbRelance;
355
            private JDate date;
355
            private JDate date;
356
            private JTextField idMouvement;
356
            private JTextField idMouvement;
357
            private ElementComboBox comboClient;
357
            private ElementComboBox comboClient;
358
 
358
 
359
            public void addViews() {
359
            public void addViews() {
360
                this.setLayout(new GridBagLayout());
360
                this.setLayout(new GridBagLayout());
361
                final GridBagConstraints c = new DefaultGridBagConstraints();
361
                final GridBagConstraints c = new DefaultGridBagConstraints();
362
 
362
 
363
                this.montant = new DeviseField();
363
                this.montant = new DeviseField();
364
                this.nbRelance = new JTextField();
364
                this.nbRelance = new JTextField();
365
                this.date = new JDate();
365
                this.date = new JDate();
366
                this.idMouvement = new JTextField();
366
                this.idMouvement = new JTextField();
367
                this.comboClient = new ElementComboBox();
367
                this.comboClient = new ElementComboBox();
368
 
368
 
369
                // Mouvement
369
                // Mouvement
370
                JLabel labelMouvement = new JLabel("Mouvement");
370
                JLabel labelMouvement = new JLabel("Mouvement");
371
                this.add(labelMouvement, c);
371
                this.add(labelMouvement, c);
372
 
372
 
373
                c.weightx = 1;
373
                c.weightx = 1;
374
                c.gridx++;
374
                c.gridx++;
375
                this.add(this.idMouvement, c);
375
                this.add(this.idMouvement, c);
376
 
376
 
377
                // Date
377
                // Date
378
                JLabel labelDate = new JLabel("Date");
378
                JLabel labelDate = new JLabel("Date");
379
                c.gridx++;
379
                c.gridx++;
380
                this.add(labelDate, c);
380
                this.add(labelDate, c);
381
 
381
 
382
                c.gridx++;
382
                c.gridx++;
383
                c.weightx = 1;
383
                c.weightx = 1;
384
                this.add(this.date, c);
384
                this.add(this.date, c);
385
 
385
 
386
                // Client
386
                // Client
387
                JLabel labelClient = new JLabel("Client");
387
                JLabel labelClient = new JLabel("Client");
388
                c.gridy++;
388
                c.gridy++;
389
                c.gridx = 0;
389
                c.gridx = 0;
390
 
390
 
391
                this.add(labelClient, c);
391
                this.add(labelClient, c);
392
 
392
 
393
                c.gridx++;
393
                c.gridx++;
394
                c.weightx = 1;
394
                c.weightx = 1;
395
                c.gridwidth = GridBagConstraints.REMAINDER;
395
                c.gridwidth = GridBagConstraints.REMAINDER;
396
                this.add(this.comboClient, c);
396
                this.add(this.comboClient, c);
397
 
397
 
398
                // libellé
398
                // libellé
399
                JLabel labelRelance = new JLabel("Nombre de relance");
399
                JLabel labelRelance = new JLabel("Nombre de relance");
400
                c.gridy++;
400
                c.gridy++;
401
                c.gridx = 0;
401
                c.gridx = 0;
402
                c.gridwidth = 1;
402
                c.gridwidth = 1;
403
                this.add(labelRelance, c);
403
                this.add(labelRelance, c);
404
 
404
 
405
                c.gridx++;
405
                c.gridx++;
406
                c.weightx = 1;
406
                c.weightx = 1;
407
                this.add(this.nbRelance, c);
407
                this.add(this.nbRelance, c);
408
 
408
 
409
                // montant
409
                // montant
410
                c.gridwidth = 1;
410
                c.gridwidth = 1;
411
                JLabel labelMontant = new JLabel("Montant");
411
                JLabel labelMontant = new JLabel("Montant");
412
                c.gridx++;
412
                c.gridx++;
413
                this.add(labelMontant, c);
413
                this.add(labelMontant, c);
414
 
414
 
415
                c.gridx++;
415
                c.gridx++;
416
                c.weightx = 1;
416
                c.weightx = 1;
417
                this.add(this.montant, c);
417
                this.add(this.montant, c);
418
 
418
 
419
                this.addSQLObject(this.montant, "MONTANT");
419
                this.addSQLObject(this.montant, "MONTANT");
420
                this.addRequiredSQLObject(this.date, "DATE");
420
                this.addRequiredSQLObject(this.date, "DATE");
421
                this.addSQLObject(this.nbRelance, "NOMBRE_RELANCE");
421
                this.addSQLObject(this.nbRelance, "NOMBRE_RELANCE");
422
                this.addRequiredSQLObject(this.comboClient, "ID_CLIENT");
422
                this.addRequiredSQLObject(this.comboClient, "ID_CLIENT");
423
                this.addSQLObject(this.idMouvement, "ID_MOUVEMENT");
423
                this.addSQLObject(this.idMouvement, "ID_MOUVEMENT");
424
            }
424
            }
425
        };
425
        };
426
    }
426
    }
427
 
427
 
428
    @Override
428
    @Override
429
    protected String createCode() {
429
    protected String createCode() {
430
        return createCodeFromPackage() + ".commitment";
430
        return createCodeOfPackage() + ".commitment";
431
    }
431
    }
432
 
432
 
433
}
433
}