OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 177 Rev 182
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-2019 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.quote.element;
14
 package org.openconcerto.erp.core.sales.quote.element;
15
 
15
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
17
import org.openconcerto.erp.config.Gestion;
17
import org.openconcerto.erp.config.Gestion;
18
import org.openconcerto.erp.core.common.component.TransfertBaseSQLComponent;
18
import org.openconcerto.erp.core.common.component.TransfertBaseSQLComponent;
19
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
19
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
20
import org.openconcerto.erp.core.common.ui.AbstractVenteArticleItemTable;
20
import org.openconcerto.erp.core.common.ui.AbstractVenteArticleItemTable;
21
import org.openconcerto.erp.core.sales.invoice.component.SaisieVenteFactureSQLComponent;
21
import org.openconcerto.erp.core.sales.invoice.component.SaisieVenteFactureSQLComponent;
22
import org.openconcerto.erp.core.sales.product.element.ReferenceArticleSQLElement;
22
import org.openconcerto.erp.core.sales.product.element.ReferenceArticleSQLElement;
23
import org.openconcerto.erp.core.sales.quote.component.DevisSQLComponent;
23
import org.openconcerto.erp.core.sales.quote.component.DevisSQLComponent;
24
import org.openconcerto.erp.core.sales.quote.report.DevisXmlSheet;
24
import org.openconcerto.erp.core.sales.quote.report.DevisXmlSheet;
25
import org.openconcerto.erp.core.sales.quote.ui.QuoteEditGroup;
25
import org.openconcerto.erp.core.sales.quote.ui.QuoteEditGroup;
26
import org.openconcerto.erp.core.sales.quote.ui.QuoteSQLComponent;
26
import org.openconcerto.erp.core.sales.quote.ui.QuoteSQLComponent;
27
import org.openconcerto.erp.core.sales.shipment.component.BonDeLivraisonSQLComponent;
27
import org.openconcerto.erp.core.sales.shipment.component.BonDeLivraisonSQLComponent;
28
import org.openconcerto.erp.core.supplychain.stock.element.MouvementStockSQLElement;
28
import org.openconcerto.erp.core.supplychain.stock.element.MouvementStockSQLElement;
29
import org.openconcerto.erp.model.MouseSheetXmlListeListener;
29
import org.openconcerto.erp.model.MouseSheetXmlListeListener;
30
import org.openconcerto.erp.preferences.GestionCommercialeGlobalPreferencePanel;
30
import org.openconcerto.erp.preferences.GestionCommercialeGlobalPreferencePanel;
31
import org.openconcerto.sql.Configuration;
31
import org.openconcerto.sql.Configuration;
32
import org.openconcerto.sql.element.GlobalMapper;
32
import org.openconcerto.sql.element.GlobalMapper;
33
import org.openconcerto.sql.element.SQLComponent;
33
import org.openconcerto.sql.element.SQLComponent;
34
import org.openconcerto.sql.element.SQLElement;
34
import org.openconcerto.sql.element.SQLElement;
35
import org.openconcerto.sql.element.SQLElementLink.LinkType;
35
import org.openconcerto.sql.element.SQLElementLink.LinkType;
36
import org.openconcerto.sql.element.SQLElementLinksSetup;
36
import org.openconcerto.sql.element.SQLElementLinksSetup;
37
import org.openconcerto.sql.model.FieldPath;
37
import org.openconcerto.sql.model.FieldPath;
38
import org.openconcerto.sql.model.SQLField;
38
import org.openconcerto.sql.model.SQLField;
39
import org.openconcerto.sql.model.SQLInjector;
39
import org.openconcerto.sql.model.SQLInjector;
40
import org.openconcerto.sql.model.SQLRow;
40
import org.openconcerto.sql.model.SQLRow;
41
import org.openconcerto.sql.model.SQLRowAccessor;
41
import org.openconcerto.sql.model.SQLRowAccessor;
42
import org.openconcerto.sql.model.SQLRowValues;
42
import org.openconcerto.sql.model.SQLRowValues;
43
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
43
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
44
import org.openconcerto.sql.model.SQLSelect;
44
import org.openconcerto.sql.model.SQLSelect;
45
import org.openconcerto.sql.model.SQLSelectJoin;
45
import org.openconcerto.sql.model.SQLSelectJoin;
46
import org.openconcerto.sql.model.SQLTable;
46
import org.openconcerto.sql.model.SQLTable;
47
import org.openconcerto.sql.model.Where;
47
import org.openconcerto.sql.model.Where;
48
import org.openconcerto.sql.model.graph.Path;
48
import org.openconcerto.sql.model.graph.Path;
49
import org.openconcerto.sql.preferences.SQLPreferences;
49
import org.openconcerto.sql.preferences.SQLPreferences;
50
import org.openconcerto.sql.request.ListSQLRequest;
50
import org.openconcerto.sql.request.ListSQLRequest;
51
import org.openconcerto.sql.ui.light.CustomRowEditor;
51
import org.openconcerto.sql.ui.light.CustomRowEditor;
52
import org.openconcerto.sql.users.UserManager;
52
import org.openconcerto.sql.users.UserManager;
53
import org.openconcerto.sql.users.rights.UserRightsManager;
53
import org.openconcerto.sql.users.rights.UserRightsManager;
54
import org.openconcerto.sql.view.EditFrame;
54
import org.openconcerto.sql.view.EditFrame;
55
import org.openconcerto.sql.view.EditPanel;
55
import org.openconcerto.sql.view.EditPanel;
56
import org.openconcerto.sql.view.EditPanel.EditMode;
56
import org.openconcerto.sql.view.EditPanel.EditMode;
57
import org.openconcerto.sql.view.EditPanelListener;
57
import org.openconcerto.sql.view.EditPanelListener;
58
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn;
58
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn;
59
import org.openconcerto.sql.view.list.IListe;
59
import org.openconcerto.sql.view.list.IListe;
60
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
60
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
61
import org.openconcerto.sql.view.list.RowAction;
61
import org.openconcerto.sql.view.list.RowAction;
62
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
62
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
63
import org.openconcerto.sql.view.list.SQLTableModelSource;
63
import org.openconcerto.sql.view.list.SQLTableModelSource;
64
import org.openconcerto.ui.light.ActivationOnSelectionControler;
64
import org.openconcerto.ui.light.ActivationOnSelectionControler;
65
import org.openconcerto.ui.light.ColumnSpec;
65
import org.openconcerto.ui.light.ColumnSpec;
66
import org.openconcerto.ui.light.ColumnsSpec;
66
import org.openconcerto.ui.light.ColumnsSpec;
67
import org.openconcerto.ui.light.LightController;
67
import org.openconcerto.ui.light.LightController;
68
import org.openconcerto.ui.light.LightUIButtonUnmanaged;
68
import org.openconcerto.ui.light.LightUIButtonUnmanaged;
69
import org.openconcerto.ui.light.LightUIComboBox;
69
import org.openconcerto.ui.light.LightUIComboBox;
70
import org.openconcerto.ui.light.LightUIElement;
70
import org.openconcerto.ui.light.LightUIElement;
71
import org.openconcerto.ui.light.LightUILine;
71
import org.openconcerto.ui.light.LightUILine;
72
import org.openconcerto.ui.light.LightUIPanel;
72
import org.openconcerto.ui.light.LightUIPanel;
73
import org.openconcerto.ui.light.LightUITable;
73
import org.openconcerto.ui.light.LightUITable;
74
import org.openconcerto.ui.light.LightUITextField;
74
import org.openconcerto.ui.light.LightUITextField;
75
import org.openconcerto.ui.light.Row;
75
import org.openconcerto.ui.light.Row;
76
import org.openconcerto.ui.light.RowSelectionSpec;
76
import org.openconcerto.ui.light.RowSelectionSpec;
77
import org.openconcerto.ui.light.TableContent;
77
import org.openconcerto.ui.light.TableContent;
78
import org.openconcerto.ui.light.TableSpec;
78
import org.openconcerto.ui.light.TableSpec;
79
import org.openconcerto.ui.table.TimestampTableCellRenderer;
79
import org.openconcerto.ui.table.TimestampTableCellRenderer;
80
import org.openconcerto.utils.CollectionUtils;
80
import org.openconcerto.utils.CollectionUtils;
81
import org.openconcerto.utils.DecimalUtils;
81
import org.openconcerto.utils.DecimalUtils;
82
import org.openconcerto.utils.ExceptionHandler;
82
import org.openconcerto.utils.ExceptionHandler;
83
import org.openconcerto.utils.FileUtils;
83
import org.openconcerto.utils.FileUtils;
84
import org.openconcerto.utils.ListMap;
84
import org.openconcerto.utils.ListMap;
85
import org.openconcerto.utils.cc.ITransformer;
85
import org.openconcerto.utils.cc.ITransformer;
86
import org.openconcerto.utils.ui.StringWithId;
86
import org.openconcerto.utils.ui.StringWithId;
87
 
87
 
88
import java.awt.Desktop;
88
import java.awt.Desktop;
89
import java.awt.event.ActionEvent;
89
import java.awt.event.ActionEvent;
90
import java.io.File;
90
import java.io.File;
91
import java.io.IOException;
91
import java.io.IOException;
92
import java.math.BigDecimal;
92
import java.math.BigDecimal;
93
import java.net.URI;
93
import java.net.URI;
94
import java.sql.SQLException;
94
import java.sql.SQLException;
95
import java.util.ArrayList;
95
import java.util.ArrayList;
96
import java.util.Arrays;
96
import java.util.Arrays;
97
import java.util.Calendar;
97
import java.util.Calendar;
98
import java.util.Collections;
98
import java.util.Collections;
99
import java.util.Date;
99
import java.util.Date;
100
import java.util.HashSet;
100
import java.util.HashSet;
101
import java.util.List;
101
import java.util.List;
102
import java.util.Set;
102
import java.util.Set;
103
 
103
 
104
import javax.swing.AbstractAction;
104
import javax.swing.AbstractAction;
105
import javax.swing.ImageIcon;
105
import javax.swing.ImageIcon;
106
import javax.swing.JFrame;
106
import javax.swing.JFrame;
107
import javax.swing.JOptionPane;
107
import javax.swing.JOptionPane;
108
import javax.swing.SwingWorker;
108
import javax.swing.SwingWorker;
109
 
109
 
110
import org.jdom2.Document;
110
import org.jdom2.Document;
111
import org.jdom2.Element;
111
import org.jdom2.Element;
112
import org.jdom2.input.DOMBuilder;
112
import org.jdom2.input.DOMBuilder;
113
 
113
 
114
public class DevisSQLElement extends ComptaSQLConfElement {
114
public class DevisSQLElement extends ComptaSQLConfElement {
115
 
115
 
116
    public static final String TABLENAME = "DEVIS";
116
    public static final String TABLENAME = "DEVIS";
117
    public static final String FACTURE_TAG_RIGHT = "TAG_FACTURE_DEVIS";
117
    public static final String FACTURE_TAG_RIGHT = "TAG_FACTURE_DEVIS";
118
 
118
 
119
    public static enum Month {
119
    public static enum Month {
120
 
120
 
121
        JANVIER("01", "Janvier"), FEVRIER("02", "Février"), MARS("03", "Mars"), AVRIL("04", "Avril"), MAI("05", "Mai"), JUIN("06", "Juin"), JUILLET("07", "Juillet"), AOUT("08",
121
        JANVIER("01", "Janvier"), FEVRIER("02", "Février"), MARS("03", "Mars"), AVRIL("04", "Avril"), MAI("05", "Mai"), JUIN("06", "Juin"), JUILLET("07", "Juillet"), AOUT("08",
122
                "Août"), SEPTEMBRE("09", "Septembre"), OCTOBRE("10", "Octobre"), NOVEMBRE("11", "Novembre"), DECEMBRE("12", "Décembre");
122
                "Août"), SEPTEMBRE("09", "Septembre"), OCTOBRE("10", "Octobre"), NOVEMBRE("11", "Novembre"), DECEMBRE("12", "Décembre");
123
 
123
 
124
        private String number;
124
        private String number;
125
        private String name;
125
        private String name;
126
 
126
 
127
        Month(String number, String name) {
127
        Month(String number, String name) {
128
            this.number = number;
128
            this.number = number;
129
            this.name = name;
129
            this.name = name;
130
        }
130
        }
131
 
131
 
132
        public String getName() {
132
        public String getName() {
133
            return this.name;
133
            return this.name;
134
        }
134
        }
135
 
135
 
136
        public String getNumber() {
136
        public String getNumber() {
137
            return this.number;
137
            return this.number;
138
        }
138
        }
139
 
139
 
140
        public String getPath() {
140
        public String getPath() {
141
            return this.getNumber() + "-" + this.getName();
141
            return this.getNumber() + "-" + this.getName();
142
        }
142
        }
143
    }
143
    }
144
 
144
 
145
    public DevisSQLElement() {
145
    public DevisSQLElement() {
146
        super(TABLENAME);
146
        super(TABLENAME);
147
 
147
 
148
        getRowActions().addAll(getDevisRowActions());
148
        getRowActions().addAll(getDevisRowActions());
149
        final QuoteEditGroup group = new QuoteEditGroup();
149
        final QuoteEditGroup group = new QuoteEditGroup();
150
        GlobalMapper.getInstance().map(QuoteSQLComponent.ID, group);
150
        GlobalMapper.getInstance().map(QuoteSQLComponent.ID, group);
151
        setDefaultGroup(group);
151
        setDefaultGroup(group);
152
 
152
 
153
    }
153
    }
154
 
154
 
155
    @Override
155
    @Override
156
    public Set<String> getReadOnlyFields() {
156
    public Set<String> getReadOnlyFields() {
157
        Set<String> s = new HashSet<>();
157
        Set<String> s = new HashSet<>();
158
        s.add("T_ACOMPTE");
158
        s.add("T_ACOMPTE");
159
        return s;
159
        return s;
160
    }
160
    }
161
 
161
 
162
    private List<RowAction> getDevisRowActions() {
162
    private List<RowAction> getDevisRowActions() {
163
 
163
 
164
        List<RowAction> rowsActions = new ArrayList<>();
164
        List<RowAction> rowsActions = new ArrayList<>();
165
 
165
 
166
        // Transfert vers facture
166
        // Transfert vers facture
167
        RowAction factureAction = getDevis2FactureAction();
167
        RowAction factureAction = getDevis2FactureAction();
168
 
168
 
169
        rowsActions.add(factureAction);
169
        rowsActions.add(factureAction);
170
 
170
 
171
        SQLPreferences prefs = new SQLPreferences(getTable().getDBRoot());
171
        SQLPreferences prefs = new SQLPreferences(getTable().getDBRoot());
172
        if (prefs.getBoolean(GestionCommercialeGlobalPreferencePanel.ACOMPTE_DEVIS, false)) {
172
        if (prefs.getBoolean(GestionCommercialeGlobalPreferencePanel.ACOMPTE_DEVIS, false)) {
173
            PredicateRowAction actionClient = new PredicateRowAction(new AbstractAction("Saisir un acompte") {
173
            PredicateRowAction actionClient = new PredicateRowAction(new AbstractAction("Saisir un acompte") {
174
                EditFrame edit;
174
                EditFrame edit;
175
 
175
 
176
                public void actionPerformed(ActionEvent e) {
176
                public void actionPerformed(ActionEvent e) {
177
                    final SQLElement eltEncaisser = Configuration.getInstance().getDirectory()
177
                    final SQLElement eltEncaisser = Configuration.getInstance().getDirectory()
178
                            .getElement(((ComptaPropsConfiguration) Configuration.getInstance()).getRootSociete().getTable("ENCAISSER_MONTANT"));
178
                            .getElement(((ComptaPropsConfiguration) Configuration.getInstance()).getRootSociete().getTable("ENCAISSER_MONTANT"));
179
 
179
 
180
                    if (this.edit == null) {
180
                    if (this.edit == null) {
181
                        this.edit = new EditFrame(eltEncaisser, EditMode.CREATION);
181
                        this.edit = new EditFrame(eltEncaisser, EditMode.CREATION);
182
                    }
182
                    }
183
                    final SQLRowAccessor selRow = IListe.get(e).getSelectedRow();
183
                    final SQLRowAccessor selRow = IListe.get(e).getSelectedRow();
184
                    SQLRowValues rowVals = new SQLRowValues(eltEncaisser.getTable());
184
                    SQLRowValues rowVals = new SQLRowValues(eltEncaisser.getTable());
185
                    rowVals.put("ACOMPTE", true);
185
                    rowVals.put("ACOMPTE", true);
186
                    rowVals.put("NOM", "Acompte devis " + selRow.getString("NUMERO"));
186
                    rowVals.put("NOM", "Acompte devis " + selRow.getString("NUMERO"));
187
                    rowVals.put("ID_CLIENT", selRow.getForeignID("ID_CLIENT"));
187
                    rowVals.put("ID_CLIENT", selRow.getForeignID("ID_CLIENT"));
188
                    rowVals.put("ID_DEVIS", selRow.getID());
188
                    rowVals.put("ID_DEVIS", selRow.getID());
189
                    SQLRowValues rowValsElt = new SQLRowValues(eltEncaisser.getTable().getTable("ENCAISSER_MONTANT_ELEMENT"));
189
                    SQLRowValues rowValsElt = new SQLRowValues(eltEncaisser.getTable().getTable("ENCAISSER_MONTANT_ELEMENT"));
190
                    rowValsElt.put("MONTANT_A_REGLER", selRow.getLong("T_TTC"));
190
                    rowValsElt.put("MONTANT_A_REGLER", selRow.getLong("T_TTC"));
191
                    rowValsElt.put("DATE", selRow.getObject("DATE"));
191
                    rowValsElt.put("DATE", selRow.getObject("DATE"));
192
                    rowValsElt.put("ID_ENCAISSER_MONTANT", rowVals);
192
                    rowValsElt.put("ID_ENCAISSER_MONTANT", rowVals);
193
                    this.edit.getSQLComponent().select(rowVals);
193
                    this.edit.getSQLComponent().select(rowVals);
194
                    this.edit.setVisible(true);
194
                    this.edit.setVisible(true);
195
                    this.edit.addEditPanelListener(new EditPanelListener() {
195
                    this.edit.addEditPanelListener(new EditPanelListener() {
196
 
196
 
197
                        @Override
197
                        @Override
198
                        public void modified() {
198
                        public void modified() {
199
                        }
199
                        }
200
 
200
 
201
                        @Override
201
                        @Override
202
                        public void inserted(int id) {
202
                        public void inserted(int id) {
203
                            // Put id devis and refresh devis.t_acompte
203
                            // Put id devis and refresh devis.t_acompte
204
                            SQLRow rowE = eltEncaisser.getTable().getRow(id);
204
                            SQLRow rowE = eltEncaisser.getTable().getRow(id);
205
                            String up = "UPDATE " + selRow.getTable().getSQLName().quote() + " set \"T_ACOMPTE\"=(SELECT COALESCE(SUM(\"MONTANT\"),0) from " + rowE.getTable().getSQLName().quote()
205
                            String up = "UPDATE " + selRow.getTable().getSQLName().quote() + " set \"T_ACOMPTE\"=(SELECT COALESCE(SUM(\"MONTANT\"),0) from " + rowE.getTable().getSQLName().quote()
206
                                    + " where \"ARCHIVE\"=0 and \"ID_DEVIS\"=" + selRow.getID() + ") where \"ID_DEVIS\"=" + selRow.getID();
206
                                    + " where \"ARCHIVE\"=0 and \"ID_DEVIS\"=" + selRow.getID() + ") where \"ID_DEVIS\"=" + selRow.getID();
207
                            eltEncaisser.getTable().getDBSystemRoot().getDataSource().execute(up);
207
                            eltEncaisser.getTable().getDBSystemRoot().getDataSource().execute(up);
208
                        }
208
                        }
209
 
209
 
210
                        @Override
210
                        @Override
211
                        public void deleted() {
211
                        public void deleted() {
212
                        }
212
                        }
213
 
213
 
214
                        @Override
214
                        @Override
215
                        public void cancelled() {
215
                        public void cancelled() {
216
                        }
216
                        }
217
                    });
217
                    });
218
                }
218
                }
219
            }, false);
219
            }, false);
220
            actionClient.setPredicate(IListeEvent.getSingleSelectionPredicate());
220
            actionClient.setPredicate(IListeEvent.getSingleSelectionPredicate());
221
            rowsActions.add(actionClient);
221
            rowsActions.add(actionClient);
222
        }
222
        }
223
 
223
 
224
        PredicateRowAction actionClient = new PredicateRowAction(new AbstractAction("Détails client") {
224
        PredicateRowAction actionClient = new PredicateRowAction(new AbstractAction("Détails client") {
225
            EditFrame edit;
225
            EditFrame edit;
226
            private SQLElement eltClient = Configuration.getInstance().getDirectory().getElement(((ComptaPropsConfiguration) Configuration.getInstance()).getRootSociete().getTable("CLIENT"));
226
            private SQLElement eltClient = Configuration.getInstance().getDirectory().getElement(((ComptaPropsConfiguration) Configuration.getInstance()).getRootSociete().getTable("CLIENT"));
227
 
227
 
228
            public void actionPerformed(ActionEvent e) {
228
            public void actionPerformed(ActionEvent e) {
229
                if (this.edit == null) {
229
                if (this.edit == null) {
230
                    this.edit = new EditFrame(this.eltClient, EditMode.MODIFICATION);
230
                    this.edit = new EditFrame(this.eltClient, EditMode.MODIFICATION);
231
                }
231
                }
232
                this.edit.selectionId(IListe.get(e).getSelectedRow().getForeignID("ID_CLIENT"));
232
                this.edit.selectionId(IListe.get(e).getSelectedRow().getForeignID("ID_CLIENT"));
233
                this.edit.setVisible(true);
233
                this.edit.setVisible(true);
234
            }
234
            }
235
        }, false);
235
        }, false);
236
        actionClient.setPredicate(IListeEvent.getSingleSelectionPredicate());
236
        actionClient.setPredicate(IListeEvent.getSingleSelectionPredicate());
237
        rowsActions.add(actionClient);
237
        rowsActions.add(actionClient);
238
 
238
 
239
 
239
 
240
        // Voir le document
240
        // Voir le document
241
        RowAction actionTransfertCmd = getDevis2CmdFournAction();
241
        RowAction actionTransfertCmd = getDevis2CmdFournAction();
242
        rowsActions.add(actionTransfertCmd);
242
        rowsActions.add(actionTransfertCmd);
243
 
243
 
244
        // Transfert vers commande
244
        // Transfert vers commande
245
        RowAction commandeAction = getDevis2CmdCliAction();
245
        RowAction commandeAction = getDevis2CmdCliAction();
246
        rowsActions.add(commandeAction);
246
        rowsActions.add(commandeAction);
247
 
247
 
248
        RowAction blAction = getDevis2BlAction();
248
        RowAction blAction = getDevis2BlAction();
249
        rowsActions.add(blAction);
249
        rowsActions.add(blAction);
250
 
250
 
251
        RowAction accepteEtCmdAction = getAcceptAndCmdClientAction();
251
        RowAction accepteEtCmdAction = getAcceptAndCmdClientAction();
252
        rowsActions.add(accepteEtCmdAction);
252
        rowsActions.add(accepteEtCmdAction);
253
 
253
 
254
        // Marqué accepté
254
        // Marqué accepté
255
        RowAction accepteAction = getAcceptAction();
255
        RowAction accepteAction = getAcceptAction();
256
 
256
 
257
        rowsActions.add(accepteAction);
257
        rowsActions.add(accepteAction);
258
 
258
 
259
        // Marqué accepté
259
        // Marqué accepté
260
        RowAction refuseAction = getRefuseAction();
260
        RowAction refuseAction = getRefuseAction();
261
 
261
 
262
        rowsActions.add(refuseAction);
262
        rowsActions.add(refuseAction);
263
 
263
 
264
        // // Dupliquer
264
        // // Dupliquer
265
        RowAction cloneAction = getCloneAction();
265
        RowAction cloneAction = getCloneAction();
266
 
266
 
267
        rowsActions.add(cloneAction);
267
        rowsActions.add(cloneAction);
268
 
268
 
269
        MouseSheetXmlListeListener mouseSheetXmlListeListener = new MouseSheetXmlListeListener(DevisXmlSheet.class);
269
        MouseSheetXmlListeListener mouseSheetXmlListeListener = new MouseSheetXmlListeListener(this, DevisXmlSheet.class);
270
        mouseSheetXmlListeListener.setGenerateHeader(true);
270
        mouseSheetXmlListeListener.setGenerateHeader(true);
271
        mouseSheetXmlListeListener.setShowHeader(true);
271
        mouseSheetXmlListeListener.setShowHeader(true);
272
 
272
 
273
        rowsActions.addAll(mouseSheetXmlListeListener.getRowActions());
273
        rowsActions.addAll(mouseSheetXmlListeListener.getRowActions());
274
 
274
 
275
        return rowsActions;
275
        return rowsActions;
276
    }
276
    }
277
 
277
 
278
    public RowAction getDevis2BlAction() {
278
    public RowAction getDevis2BlAction() {
279
        return new RowAction(new AbstractAction() {
279
        return new RowAction(new AbstractAction() {
280
            public void actionPerformed(ActionEvent e) {
280
            public void actionPerformed(ActionEvent e) {
281
 
281
 
282
                final List<SQLRowValues> copySelectedRows = IListe.get(e).getSelectedRows();
282
                final List<SQLRowValues> copySelectedRows = IListe.get(e).getSelectedRows();
283
                transfertDevis(copySelectedRows, "BON_DE_LIVRAISON");
283
                transfertDevis(copySelectedRows, "BON_DE_LIVRAISON");
284
            }
284
            }
285
 
285
 
286
        }, true, "sales.quote.create.customer.delivery") {
286
        }, true, "sales.quote.create.customer.delivery") {
287
            @Override
287
            @Override
288
            public boolean enabledFor(java.util.List<org.openconcerto.sql.model.SQLRowValues> selection) {
288
            public boolean enabledFor(java.util.List<org.openconcerto.sql.model.SQLRowValues> selection) {
289
                if (selection != null && selection.size() == 1) {
289
                if (selection != null && selection.size() == 1) {
290
                    if (selection.get(0).getForeignID("ID_ETAT_DEVIS") == EtatDevisSQLElement.ACCEPTE) {
290
                    if (selection.get(0).getForeignID("ID_ETAT_DEVIS") == EtatDevisSQLElement.ACCEPTE) {
291
                        return true;
291
                        return true;
292
                    }
292
                    }
293
                }
293
                }
294
                return false;
294
                return false;
295
            }
295
            }
296
        };
296
        };
297
    }
297
    }
298
 
298
 
299
    public static void davBrowse(String s) throws Exception {
299
    public static void davBrowse(String s) throws Exception {
300
        final boolean windows = System.getProperty("os.name").startsWith("Windows");
300
        final boolean windows = System.getProperty("os.name").startsWith("Windows");
301
        if (windows) {
301
        if (windows) {
302
            Desktop.getDesktop().browse(new URI(s));
302
            Desktop.getDesktop().browse(new URI(s));
303
        } else {
303
        } else {
304
            String[] cmdarray = new String[] { "xdg-open", s };
304
            String[] cmdarray = new String[] { "xdg-open", s };
305
            final int res = Runtime.getRuntime().exec(cmdarray).waitFor();
305
            final int res = Runtime.getRuntime().exec(cmdarray).waitFor();
306
            if (res != 0)
306
            if (res != 0)
307
                throw new IOException("error (" + res + ") executing " + Arrays.asList(cmdarray));
307
                throw new IOException("error (" + res + ") executing " + Arrays.asList(cmdarray));
308
        }
308
        }
309
    }
309
    }
310
 
310
 
311
    public RowAction getCloneAction() {
311
    public RowAction getCloneAction() {
312
        return new RowAction(new AbstractAction() {
312
        return new RowAction(new AbstractAction() {
313
 
313
 
314
            public void actionPerformed(ActionEvent e) {
314
            public void actionPerformed(ActionEvent e) {
315
                SQLRowAccessor selectedRow = IListe.get(e).getSelectedRow();
315
                SQLRowAccessor selectedRow = IListe.get(e).getSelectedRow();
316
 
316
 
317
                SQLElement eltFact = Configuration.getInstance().getDirectory().getElement("DEVIS");
317
                SQLElement eltFact = Configuration.getInstance().getDirectory().getElement("DEVIS");
318
                EditFrame editFrame = new EditFrame(eltFact, EditPanel.CREATION);
318
                EditFrame editFrame = new EditFrame(eltFact, EditPanel.CREATION);
319
 
319
 
320
                ((DevisSQLComponent) editFrame.getSQLComponent()).loadDevisExistant(selectedRow.getID());
320
                ((DevisSQLComponent) editFrame.getSQLComponent()).loadDevisExistant(selectedRow.getID());
321
                editFrame.setVisible(true);
321
                editFrame.setVisible(true);
322
            }
322
            }
323
        }, true, "sales.quote.clone") {
323
        }, true, "sales.quote.clone") {
324
            @Override
324
            @Override
325
            public boolean enabledFor(java.util.List<org.openconcerto.sql.model.SQLRowValues> selection) {
325
            public boolean enabledFor(java.util.List<org.openconcerto.sql.model.SQLRowValues> selection) {
326
                return (selection != null && selection.size() == 1);
326
                return (selection != null && selection.size() == 1);
327
            }
327
            }
328
        };
328
        };
329
    }
329
    }
330
 
330
 
331
    public RowAction getRefuseAction() {
331
    public RowAction getRefuseAction() {
332
        return new RowAction(new AbstractAction() {
332
        return new RowAction(new AbstractAction() {
333
            public void actionPerformed(ActionEvent e) {
333
            public void actionPerformed(ActionEvent e) {
334
                SQLRowValues rowVals = IListe.get(e).getSelectedRow().asRow().createEmptyUpdateRow();
334
                SQLRowValues rowVals = IListe.get(e).getSelectedRow().asRow().createEmptyUpdateRow();
335
                rowVals.put("ID_ETAT_DEVIS", EtatDevisSQLElement.REFUSE);
335
                rowVals.put("ID_ETAT_DEVIS", EtatDevisSQLElement.REFUSE);
336
                try {
336
                try {
337
                    rowVals.update();
337
                    rowVals.update();
338
                } catch (SQLException e1) {
338
                } catch (SQLException e1) {
339
                    // TODO Auto-generated catch block
339
                    // TODO Auto-generated catch block
340
                    e1.printStackTrace();
340
                    e1.printStackTrace();
341
                }
341
                }
342
            }
342
            }
343
        }, false, "sales.quote.refuse") {
343
        }, false, "sales.quote.refuse") {
344
            @Override
344
            @Override
345
            public boolean enabledFor(java.util.List<org.openconcerto.sql.model.SQLRowValues> selection) {
345
            public boolean enabledFor(java.util.List<org.openconcerto.sql.model.SQLRowValues> selection) {
346
                if (selection != null && selection.size() == 1) {
346
                if (selection != null && selection.size() == 1) {
347
                    if (selection.get(0).getForeignID("ID_ETAT_DEVIS") == EtatDevisSQLElement.EN_ATTENTE) {
347
                    if (selection.get(0).getForeignID("ID_ETAT_DEVIS") == EtatDevisSQLElement.EN_ATTENTE) {
348
                        return true;
348
                        return true;
349
                    }
349
                    }
350
                }
350
                }
351
                return false;
351
                return false;
352
            }
352
            }
353
        };
353
        };
354
    }
354
    }
355
 
355
 
356
    public RowAction getAcceptAction() {
356
    public RowAction getAcceptAction() {
357
        return new RowAction(new AbstractAction() {
357
        return new RowAction(new AbstractAction() {
358
            public void actionPerformed(ActionEvent e) {
358
            public void actionPerformed(ActionEvent e) {
359
                SQLRow selectedRow = IListe.get(e).getSelectedRow().asRow();
359
                SQLRow selectedRow = IListe.get(e).getSelectedRow().asRow();
360
                SQLRowValues rowVals = selectedRow.createEmptyUpdateRow();
360
                SQLRowValues rowVals = selectedRow.createEmptyUpdateRow();
361
                rowVals.put("ID_ETAT_DEVIS", EtatDevisSQLElement.ACCEPTE);
361
                rowVals.put("ID_ETAT_DEVIS", EtatDevisSQLElement.ACCEPTE);
362
                try {
362
                try {
363
                    rowVals.update();
363
                    rowVals.update();
364
                } catch (SQLException e1) {
364
                } catch (SQLException e1) {
365
                    // TODO Auto-generated catch block
365
                    // TODO Auto-generated catch block
366
                    e1.printStackTrace();
366
                    e1.printStackTrace();
367
                }
367
                }
368
            }
368
            }
369
        }, false, "sales.quote.accept") {
369
        }, false, "sales.quote.accept") {
370
            @Override
370
            @Override
371
            public boolean enabledFor(java.util.List<org.openconcerto.sql.model.SQLRowValues> selection) {
371
            public boolean enabledFor(java.util.List<org.openconcerto.sql.model.SQLRowValues> selection) {
372
                if (selection != null && selection.size() == 1) {
372
                if (selection != null && selection.size() == 1) {
373
                    final int int1 = selection.get(0).getForeignID("ID_ETAT_DEVIS");
373
                    final int int1 = selection.get(0).getForeignID("ID_ETAT_DEVIS");
374
                    if (int1 != EtatDevisSQLElement.REFUSE && int1 != EtatDevisSQLElement.ACCEPTE) {
374
                    if (int1 != EtatDevisSQLElement.REFUSE && int1 != EtatDevisSQLElement.ACCEPTE) {
375
                        return true;
375
                        return true;
376
                    }
376
                    }
377
                }
377
                }
378
                return false;
378
                return false;
379
            }
379
            }
380
        };
380
        };
381
    }
381
    }
382
 
382
 
383
    public RowAction getDevis2FactureAction() {
383
    public RowAction getDevis2FactureAction() {
384
        return new RowAction(new AbstractAction() {
384
        return new RowAction(new AbstractAction() {
385
            public void actionPerformed(ActionEvent e) {
385
            public void actionPerformed(ActionEvent e) {
386
                TransfertBaseSQLComponent.openTransfertFrame(IListe.get(e).getSelectedRows(), "SAISIE_VENTE_FACTURE");
386
                TransfertBaseSQLComponent.openTransfertFrame(IListe.get(e).getSelectedRows(), "SAISIE_VENTE_FACTURE");
387
 
387
 
388
            }
388
            }
389
        }, true, "sales.quote.create.invoice") {
389
        }, true, "sales.quote.create.invoice") {
390
            @Override
390
            @Override
391
            public boolean enabledFor(java.util.List<org.openconcerto.sql.model.SQLRowValues> selection) {
391
            public boolean enabledFor(java.util.List<org.openconcerto.sql.model.SQLRowValues> selection) {
392
                boolean b = selection.size() > 0;
392
                boolean b = selection.size() > 0;
393
                for (SQLRowAccessor sqlRowAccessor : selection) {
393
                for (SQLRowAccessor sqlRowAccessor : selection) {
394
                    b &= sqlRowAccessor.getForeignID("ID_ETAT_DEVIS") == EtatDevisSQLElement.ACCEPTE;
394
                    b &= sqlRowAccessor.getForeignID("ID_ETAT_DEVIS") == EtatDevisSQLElement.ACCEPTE;
395
                }
395
                }
396
 
396
 
397
                return b;
397
                return b;
398
            }
398
            }
399
        };
399
        };
400
    }
400
    }
401
 
401
 
402
    public RowAction getDevis2CmdFournAction() {
402
    public RowAction getDevis2CmdFournAction() {
403
        return new RowAction(new AbstractAction() {
403
        return new RowAction(new AbstractAction() {
404
            public void actionPerformed(ActionEvent e) {
404
            public void actionPerformed(ActionEvent e) {
405
                final SQLRow selectedRow = IListe.get(e).fetchSelectedRow();
405
                final SQLRow selectedRow = IListe.get(e).fetchSelectedRow();
406
                ComptaPropsConfiguration.getInstanceCompta().getNonInteractiveSQLExecutor().execute(new Runnable() {
406
                ComptaPropsConfiguration.getInstanceCompta().getNonInteractiveSQLExecutor().execute(new Runnable() {
407
 
407
 
408
                    @Override
408
                    @Override
409
                    public void run() {
409
                    public void run() {
410
                        transfertCommande(selectedRow);
410
                        transfertCommande(selectedRow);
411
 
411
 
412
                    }
412
                    }
413
                });
413
                });
414
 
414
 
415
            }
415
            }
416
        }, false, "sales.quote.create.supplier.order") {
416
        }, false, "sales.quote.create.supplier.order") {
417
            @Override
417
            @Override
418
            public boolean enabledFor(java.util.List<org.openconcerto.sql.model.SQLRowValues> selection) {
418
            public boolean enabledFor(java.util.List<org.openconcerto.sql.model.SQLRowValues> selection) {
419
                if (selection != null && selection.size() == 1) {
419
                if (selection != null && selection.size() == 1) {
420
                    if (selection.get(0).getForeignID("ID_ETAT_DEVIS") == EtatDevisSQLElement.ACCEPTE) {
420
                    if (selection.get(0).getForeignID("ID_ETAT_DEVIS") == EtatDevisSQLElement.ACCEPTE) {
421
                        return true;
421
                        return true;
422
                    }
422
                    }
423
                }
423
                }
424
                return false;
424
                return false;
425
            }
425
            }
426
        };
426
        };
427
    }
427
    }
428
 
428
 
429
    public RowAction getDevis2CmdCliAction() {
429
    public RowAction getDevis2CmdCliAction() {
430
        return new RowAction(new AbstractAction() {
430
        return new RowAction(new AbstractAction() {
431
            public void actionPerformed(ActionEvent e) {
431
            public void actionPerformed(ActionEvent e) {
432
 
432
 
433
                final List<SQLRowValues> copySelectedRows = IListe.get(e).getSelectedRows();
433
                final List<SQLRowValues> copySelectedRows = IListe.get(e).getSelectedRows();
434
                transfertCommandeClient(copySelectedRows);
434
                transfertCommandeClient(copySelectedRows);
435
            }
435
            }
436
 
436
 
437
        }, true, "sales.quote.create.customer.order") {
437
        }, true, "sales.quote.create.customer.order") {
438
            @Override
438
            @Override
439
            public boolean enabledFor(java.util.List<org.openconcerto.sql.model.SQLRowValues> selection) {
439
            public boolean enabledFor(java.util.List<org.openconcerto.sql.model.SQLRowValues> selection) {
440
                if (selection != null && selection.size() == 1) {
440
                if (selection != null && selection.size() == 1) {
441
                    if (selection.get(0).getForeignID("ID_ETAT_DEVIS") == EtatDevisSQLElement.ACCEPTE) {
441
                    if (selection.get(0).getForeignID("ID_ETAT_DEVIS") == EtatDevisSQLElement.ACCEPTE) {
442
                        return true;
442
                        return true;
443
                    }
443
                    }
444
                }
444
                }
445
                return false;
445
                return false;
446
            }
446
            }
447
        };
447
        };
448
    }
448
    }
449
 
449
 
450
    public RowAction getAcceptAndCmdClientAction() {
450
    public RowAction getAcceptAndCmdClientAction() {
451
        return new RowAction(new AbstractAction() {
451
        return new RowAction(new AbstractAction() {
452
            public void actionPerformed(ActionEvent e) {
452
            public void actionPerformed(ActionEvent e) {
453
                SQLRow selectedRow = IListe.get(e).fetchSelectedRow();
453
                SQLRow selectedRow = IListe.get(e).fetchSelectedRow();
454
                SQLRowValues rowVals = selectedRow.createEmptyUpdateRow();
454
                SQLRowValues rowVals = selectedRow.createEmptyUpdateRow();
455
                rowVals.put("ID_ETAT_DEVIS", EtatDevisSQLElement.ACCEPTE);
455
                rowVals.put("ID_ETAT_DEVIS", EtatDevisSQLElement.ACCEPTE);
456
                try {
456
                try {
457
                    rowVals.update();
457
                    rowVals.update();
458
                } catch (SQLException e1) {
458
                } catch (SQLException e1) {
459
                    ExceptionHandler.handle("Erreur la de la mise à jour de l'état du devis!", e1);
459
                    ExceptionHandler.handle("Erreur la de la mise à jour de l'état du devis!", e1);
460
 
460
 
461
                }
461
                }
462
                transfertCommandeClient(IListe.get(e).getSelectedRows());
462
                transfertCommandeClient(IListe.get(e).getSelectedRows());
463
            }
463
            }
464
        }, false, "sales.quote.accept.create.customer.order") {
464
        }, false, "sales.quote.accept.create.customer.order") {
465
            @Override
465
            @Override
466
            public boolean enabledFor(java.util.List<org.openconcerto.sql.model.SQLRowValues> selection) {
466
            public boolean enabledFor(java.util.List<org.openconcerto.sql.model.SQLRowValues> selection) {
467
                if (selection != null && selection.size() == 1) {
467
                if (selection != null && selection.size() == 1) {
468
                    if (selection.get(0).getForeignID("ID_ETAT_DEVIS") == EtatDevisSQLElement.EN_ATTENTE) {
468
                    if (selection.get(0).getForeignID("ID_ETAT_DEVIS") == EtatDevisSQLElement.EN_ATTENTE) {
469
                        return true;
469
                        return true;
470
                    }
470
                    }
471
                }
471
                }
472
                return false;
472
                return false;
473
            }
473
            }
474
        };
474
        };
475
    }
475
    }
476
 
476
 
477
    public void transfertDevis(final List<SQLRowValues> copySelectedRows, final String destTable) {
477
    public void transfertDevis(final List<SQLRowValues> copySelectedRows, final String destTable) {
478
        SwingWorker<Boolean, Object> worker = new SwingWorker<Boolean, Object>() {
478
        SwingWorker<Boolean, Object> worker = new SwingWorker<Boolean, Object>() {
479
            @Override
479
            @Override
480
            protected Boolean doInBackground() throws Exception {
480
            protected Boolean doInBackground() throws Exception {
481
 
481
 
482
                final SQLTable tableTransfert = getTable().getTable("TR_DEVIS");
482
                final SQLTable tableTransfert = getTable().getTable("TR_DEVIS");
483
                SQLRowValues rowVals = new SQLRowValues(tableTransfert);
483
                SQLRowValues rowVals = new SQLRowValues(tableTransfert);
484
                rowVals.put("ID_DEVIS", new SQLRowValues(getTable()).put("NUMERO", null));
484
                rowVals.put("ID_DEVIS", new SQLRowValues(getTable()).put("NUMERO", null));
485
                rowVals.put("ID_" + destTable, null);
485
                rowVals.put("ID_" + destTable, null);
486
                rowVals.put("ID", null);
486
                rowVals.put("ID", null);
487
 
487
 
488
                final List<Number> lID = new ArrayList<>();
488
                final List<Number> lID = new ArrayList<>();
489
                for (SQLRowValues sqlRowValues : copySelectedRows) {
489
                for (SQLRowValues sqlRowValues : copySelectedRows) {
490
                    lID.add(sqlRowValues.getID());
490
                    lID.add(sqlRowValues.getID());
491
                }
491
                }
492
 
492
 
493
                SQLRowValuesListFetcher fetch = SQLRowValuesListFetcher.create(rowVals);
493
                SQLRowValuesListFetcher fetch = SQLRowValuesListFetcher.create(rowVals);
494
                fetch.setSelTransf(new ITransformer<SQLSelect, SQLSelect>() {
494
                fetch.setSelTransf(new ITransformer<SQLSelect, SQLSelect>() {
495
 
495
 
496
                    @Override
496
                    @Override
497
                    public SQLSelect transformChecked(SQLSelect input) {
497
                    public SQLSelect transformChecked(SQLSelect input) {
498
                        Where w = new Where(tableTransfert.getField("ID_DEVIS"), lID);
498
                        Where w = new Where(tableTransfert.getField("ID_DEVIS"), lID);
499
                        w = w.and(new Where(tableTransfert.getField("ID_" + destTable), "IS NOT", (Object) null));
499
                        w = w.and(new Where(tableTransfert.getField("ID_" + destTable), "IS NOT", (Object) null));
500
                        input.setWhere(w);
500
                        input.setWhere(w);
501
                        return input;
501
                        return input;
502
                    }
502
                    }
503
                });
503
                });
504
 
504
 
505
                List<SQLRowValues> rows = fetch.fetch();
505
                List<SQLRowValues> rows = fetch.fetch();
506
                if (rows != null && rows.size() > 0) {
506
                if (rows != null && rows.size() > 0) {
507
                    String numero = "";
507
                    String numero = "";
508
 
508
 
509
                    for (SQLRowValues sqlRow : rows) {
509
                    for (SQLRowValues sqlRow : rows) {
510
                        numero += sqlRow.getForeign("ID_DEVIS").getString("NUMERO") + " ,";
510
                        numero += sqlRow.getForeign("ID_DEVIS").getString("NUMERO") + " ,";
511
                    }
511
                    }
512
 
512
 
513
                    numero = numero.substring(0, numero.length() - 2);
513
                    numero = numero.substring(0, numero.length() - 2);
514
                    String label = "Attention ";
514
                    String label = "Attention ";
515
                    if (rows.size() > 1) {
515
                    if (rows.size() > 1) {
516
                        label += " les devis " + numero + " ont déjà été transféré!";
516
                        label += " les devis " + numero + " ont déjà été transféré!";
517
                    } else {
517
                    } else {
518
                        label += " le devis " + numero + " a déjà été transféré!";
518
                        label += " le devis " + numero + " a déjà été transféré!";
519
                    }
519
                    }
520
                    label += "\n Voulez vous continuer?";
520
                    label += "\n Voulez vous continuer?";
521
 
521
 
522
                    int ans = JOptionPane.showConfirmDialog(null, label, "Transfert devis", JOptionPane.YES_NO_OPTION);
522
                    int ans = JOptionPane.showConfirmDialog(null, label, "Transfert devis", JOptionPane.YES_NO_OPTION);
523
                    if (ans == JOptionPane.NO_OPTION) {
523
                    if (ans == JOptionPane.NO_OPTION) {
524
                        return Boolean.FALSE;
524
                        return Boolean.FALSE;
525
                    }
525
                    }
526
 
526
 
527
                }
527
                }
528
                return Boolean.TRUE;
528
                return Boolean.TRUE;
529
 
529
 
530
            }
530
            }
531
 
531
 
532
            @Override
532
            @Override
533
            protected void done() {
533
            protected void done() {
534
 
534
 
535
                try {
535
                try {
536
                    Boolean b = get();
536
                    Boolean b = get();
537
                    if (b != null && b) {
537
                    if (b != null && b) {
538
                        EditFrame frame = TransfertBaseSQLComponent.openTransfertFrame(copySelectedRows, destTable);
538
                        EditFrame frame = TransfertBaseSQLComponent.openTransfertFrame(copySelectedRows, destTable);
539
                        if (destTable.equalsIgnoreCase("BON_DE_LIVRAISON")) {
539
                        if (destTable.equalsIgnoreCase("BON_DE_LIVRAISON")) {
540
                            BonDeLivraisonSQLComponent comp = (BonDeLivraisonSQLComponent) frame.getSQLComponent();
540
                            BonDeLivraisonSQLComponent comp = (BonDeLivraisonSQLComponent) frame.getSQLComponent();
541
                            final SQLTable tableElt = comp.getElement().getTable().getTable("BON_DE_LIVRAISON_ELEMENT");
541
                            final SQLTable tableElt = comp.getElement().getTable().getTable("BON_DE_LIVRAISON_ELEMENT");
542
                            SQLRowValues rowVals = new SQLRowValues(tableElt);
542
                            SQLRowValues rowVals = new SQLRowValues(tableElt);
543
                            rowVals.put("QTE_UNITAIRE", null);
543
                            rowVals.put("QTE_UNITAIRE", null);
544
                            rowVals.put("QTE", null);
544
                            rowVals.put("QTE", null);
545
                            rowVals.put("QTE_LIVREE", null);
545
                            rowVals.put("QTE_LIVREE", null);
546
                            rowVals.put("ID_ARTICLE", null);
546
                            rowVals.put("ID_ARTICLE", null);
547
                            rowVals.put("PV_HT", null);
547
                            rowVals.put("PV_HT", null);
548
                            rowVals.put("ID_DEVIS_ELEMENT", null);
548
                            rowVals.put("ID_DEVIS_ELEMENT", null);
549
 
549
 
550
                            SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(rowVals);
550
                            SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(rowVals);
551
                            fetcher.setSelTransf(new ITransformer<SQLSelect, SQLSelect>() {
551
                            fetcher.setSelTransf(new ITransformer<SQLSelect, SQLSelect>() {
552
 
552
 
553
                                @Override
553
                                @Override
554
                                public SQLSelect transformChecked(SQLSelect input) {
554
                                public SQLSelect transformChecked(SQLSelect input) {
555
                                    List<Integer> ids = new ArrayList<>(copySelectedRows.size());
555
                                    List<Integer> ids = new ArrayList<>(copySelectedRows.size());
556
                                    for (SQLRowValues sqlRowValues : copySelectedRows) {
556
                                    for (SQLRowValues sqlRowValues : copySelectedRows) {
557
                                        ids.add(sqlRowValues.getID());
557
                                        ids.add(sqlRowValues.getID());
558
                                    }
558
                                    }
559
                                    SQLSelectJoin joinBR = input.addJoin("RIGHT", tableElt.getTable("BON_DE_LIVRAISON_ELEMENT").getField("ID_BON_DE_LIVRAISON"));
559
                                    SQLSelectJoin joinBR = input.addJoin("RIGHT", tableElt.getTable("BON_DE_LIVRAISON_ELEMENT").getField("ID_BON_DE_LIVRAISON"));
560
                                    SQLSelectJoin joinTR = input.addBackwardJoin("RIGHT", tableElt.getTable("TR_DEVIS").getField("ID_BON_DE_LIVRAISON"), joinBR.getJoinedTable().getAlias());
560
                                    SQLSelectJoin joinTR = input.addBackwardJoin("RIGHT", tableElt.getTable("TR_DEVIS").getField("ID_BON_DE_LIVRAISON"), joinBR.getJoinedTable().getAlias());
561
                                    joinTR.setWhere(new Where(joinTR.getJoinedTable().getField("ID_DEVIS"), ids));
561
                                    joinTR.setWhere(new Where(joinTR.getJoinedTable().getField("ID_DEVIS"), ids));
562
                                    System.err.println(input.asString());
562
                                    System.err.println(input.asString());
563
                                    return input;
563
                                    return input;
564
                                }
564
                                }
565
                            });
565
                            });
566
                            comp.loadQuantity(fetcher.fetch(), "DEVIS_ELEMENT");
566
                            comp.loadQuantity(fetcher.fetch(), "DEVIS_ELEMENT");
567
                        }
567
                        }
568
                    }
568
                    }
569
                } catch (Exception e) {
569
                } catch (Exception e) {
570
                    ExceptionHandler.handle("Erreur lors du transfert des devis!", e);
570
                    ExceptionHandler.handle("Erreur lors du transfert des devis!", e);
571
                }
571
                }
572
                super.done();
572
                super.done();
573
            }
573
            }
574
        };
574
        };
575
        worker.execute();
575
        worker.execute();
576
    }
576
    }
577
 
577
 
578
    public void transfertCommandeClient(final List<SQLRowValues> copySelectedRows) {
578
    public void transfertCommandeClient(final List<SQLRowValues> copySelectedRows) {
579
        transfertDevis(copySelectedRows, "COMMANDE_CLIENT");
579
        transfertDevis(copySelectedRows, "COMMANDE_CLIENT");
580
    }
580
    }
581
 
581
 
582
    @Override
582
    @Override
583
    protected List<String> getComboFields() {
583
    protected List<String> getComboFields() {
584
        List<String> l = new ArrayList<>(1);
584
        List<String> l = new ArrayList<>(1);
585
        l.add("NUMERO");
585
        l.add("NUMERO");
586
        return l;
586
        return l;
587
    }
587
    }
588
 
588
 
589
    private void transfertCommande(final SQLRow row) {
589
    private void transfertCommande(final SQLRow row) {
590
        ComptaPropsConfiguration.getInstanceCompta().getNonInteractiveSQLExecutor().execute(new Runnable() {
590
        ComptaPropsConfiguration.getInstanceCompta().getNonInteractiveSQLExecutor().execute(new Runnable() {
591
 
591
 
592
            @Override
592
            @Override
593
            public void run() {
593
            public void run() {
594
                DevisItemSQLElement elt = (DevisItemSQLElement) Configuration.getInstance().getDirectory().getElement("DEVIS_ELEMENT");
594
                DevisItemSQLElement elt = (DevisItemSQLElement) Configuration.getInstance().getDirectory().getElement("DEVIS_ELEMENT");
595
                SQLTable tableCmdElt = Configuration.getInstance().getDirectory().getElement("COMMANDE_ELEMENT").getTable();
595
                SQLTable tableCmdElt = Configuration.getInstance().getDirectory().getElement("COMMANDE_ELEMENT").getTable();
596
                SQLElement eltArticle = Configuration.getInstance().getDirectory().getElement("ARTICLE");
596
                SQLElement eltArticle = Configuration.getInstance().getDirectory().getElement("ARTICLE");
597
                List<SQLRow> rows = row.getReferentRows(elt.getTable());
597
                List<SQLRow> rows = row.getReferentRows(elt.getTable());
598
                final ListMap<SQLRow, SQLRowValues> map = new ListMap<>();
598
                final ListMap<SQLRow, SQLRowValues> map = new ListMap<>();
599
                SQLRow rowDeviseF = null;
599
                SQLRow rowDeviseF = null;
600
                for (SQLRow sqlRow : rows) {
600
                for (SQLRow sqlRow : rows) {
601
                    // on récupére l'article qui lui correspond
601
                    // on récupére l'article qui lui correspond
602
                    SQLRowValues rowArticle = new SQLRowValues(eltArticle.getTable());
602
                    SQLRowValues rowArticle = new SQLRowValues(eltArticle.getTable());
603
                    for (SQLField field : eltArticle.getTable().getFields()) {
603
                    for (SQLField field : eltArticle.getTable().getFields()) {
604
                        if (sqlRow.getTable().getFieldsName().contains(field.getName())) {
604
                        if (sqlRow.getTable().getFieldsName().contains(field.getName())) {
605
                            rowArticle.put(field.getName(), sqlRow.getObject(field.getName()));
605
                            rowArticle.put(field.getName(), sqlRow.getObject(field.getName()));
606
                        }
606
                        }
607
                    }
607
                    }
608
 
608
 
609
                    // rowArticle.loadAllSafe(rowEltFact);
609
                    // rowArticle.loadAllSafe(rowEltFact);
610
                    int idArticle = ReferenceArticleSQLElement.getIdForCNM(rowArticle, true);
610
                    int idArticle = ReferenceArticleSQLElement.getIdForCNM(rowArticle, true);
611
                    SQLRow rowArticleFind = eltArticle.getTable().getRow(idArticle);
611
                    SQLRow rowArticleFind = eltArticle.getTable().getRow(idArticle);
612
                    if (rowArticleFind != null) {
612
                    if (rowArticleFind != null) {
613
                        SQLInjector inj = SQLInjector.getInjector(rowArticle.getTable(), tableCmdElt);
613
                        SQLInjector inj = SQLInjector.getInjector(rowArticle.getTable(), tableCmdElt);
614
                        SQLRowValues rowValsElt = new SQLRowValues(inj.createRowValuesFrom(rowArticleFind));
614
                        SQLRowValues rowValsElt = new SQLRowValues(inj.createRowValuesFrom(rowArticleFind));
615
                        rowValsElt.put("ID_STYLE", sqlRow.getObject("ID_STYLE"));
615
                        rowValsElt.put("ID_STYLE", sqlRow.getObject("ID_STYLE"));
616
                        rowValsElt.put("QTE", sqlRow.getObject("QTE"));
616
                        rowValsElt.put("QTE", sqlRow.getObject("QTE"));
617
                        rowValsElt.put("T_POIDS", rowValsElt.getLong("POIDS") * rowValsElt.getInt("QTE"));
617
                        rowValsElt.put("T_POIDS", rowValsElt.getLong("POIDS") * rowValsElt.getInt("QTE"));
618
                        rowValsElt.put("T_PA_HT", ((BigDecimal) rowValsElt.getObject("PA_HT")).multiply(new BigDecimal(rowValsElt.getInt("QTE"), DecimalUtils.HIGH_PRECISION)));
618
                        rowValsElt.put("T_PA_HT", ((BigDecimal) rowValsElt.getObject("PA_HT")).multiply(new BigDecimal(rowValsElt.getInt("QTE"), DecimalUtils.HIGH_PRECISION)));
619
                        rowValsElt.put("T_PA_TTC", ((BigDecimal) rowValsElt.getObject("T_PA_HT")).multiply(BigDecimal.valueOf(rowValsElt.getForeign("ID_TAXE").getFloat("TAUX") / 100.0 + 1.0),
619
                        rowValsElt.put("T_PA_TTC", ((BigDecimal) rowValsElt.getObject("T_PA_HT")).multiply(BigDecimal.valueOf(rowValsElt.getForeign("ID_TAXE").getFloat("TAUX") / 100.0 + 1.0),
620
                                DecimalUtils.HIGH_PRECISION));
620
                                DecimalUtils.HIGH_PRECISION));
621
 
621
 
622
                        // gestion de la devise
622
                        // gestion de la devise
623
                        rowDeviseF = sqlRow.getForeignRow("ID_DEVISE");
623
                        rowDeviseF = sqlRow.getForeignRow("ID_DEVISE");
624
                        SQLRow rowDeviseHA = rowArticleFind.getForeignRow("ID_DEVISE_HA");
624
                        SQLRow rowDeviseHA = rowArticleFind.getForeignRow("ID_DEVISE_HA");
625
                        BigDecimal qte = new BigDecimal(rowValsElt.getInt("QTE"));
625
                        BigDecimal qte = new BigDecimal(rowValsElt.getInt("QTE"));
626
                        if (rowDeviseF != null && !rowDeviseF.isUndefined()) {
626
                        if (rowDeviseF != null && !rowDeviseF.isUndefined()) {
627
                            if (rowDeviseF.getID() == rowDeviseHA.getID()) {
627
                            if (rowDeviseF.getID() == rowDeviseHA.getID()) {
628
                                rowValsElt.put("PA_DEVISE", rowArticleFind.getObject("PA_DEVISE"));
628
                                rowValsElt.put("PA_DEVISE", rowArticleFind.getObject("PA_DEVISE"));
629
                                rowValsElt.put("PA_DEVISE_T", ((BigDecimal) rowArticleFind.getObject("PA_DEVISE")).multiply(qte, DecimalUtils.HIGH_PRECISION));
629
                                rowValsElt.put("PA_DEVISE_T", ((BigDecimal) rowArticleFind.getObject("PA_DEVISE")).multiply(qte, DecimalUtils.HIGH_PRECISION));
630
                                rowValsElt.put("ID_DEVISE", rowDeviseF.getID());
630
                                rowValsElt.put("ID_DEVISE", rowDeviseF.getID());
631
                            } else {
631
                            } else {
632
                                BigDecimal taux = (BigDecimal) rowDeviseF.getObject("TAUX");
632
                                BigDecimal taux = (BigDecimal) rowDeviseF.getObject("TAUX");
633
                                rowValsElt.put("PA_DEVISE", taux.multiply((BigDecimal) rowValsElt.getObject("PA_HT")));
633
                                rowValsElt.put("PA_DEVISE", taux.multiply((BigDecimal) rowValsElt.getObject("PA_HT")));
634
                                rowValsElt.put("PA_DEVISE_T", ((BigDecimal) rowValsElt.getObject("PA_DEVISE")).multiply(qte, DecimalUtils.HIGH_PRECISION));
634
                                rowValsElt.put("PA_DEVISE_T", ((BigDecimal) rowValsElt.getObject("PA_DEVISE")).multiply(qte, DecimalUtils.HIGH_PRECISION));
635
                                rowValsElt.put("ID_DEVISE", rowDeviseF.getID());
635
                                rowValsElt.put("ID_DEVISE", rowDeviseF.getID());
636
                            }
636
                            }
637
                        }
637
                        }
638
 
638
 
639
                        map.add(rowArticleFind.getForeignRow("ID_FOURNISSEUR"), rowValsElt);
639
                        map.add(rowArticleFind.getForeignRow("ID_FOURNISSEUR"), rowValsElt);
640
                    }
640
                    }
641
                }
641
                }
642
                MouvementStockSQLElement.createCommandeF(map, rowDeviseF);
642
                MouvementStockSQLElement.createCommandeF(map, rowDeviseF);
643
            }
643
            }
644
        });
644
        });
645
 
645
 
646
    }
646
    }
647
 
647
 
648
    protected List<String> getListFields() {
648
    protected List<String> getListFields() {
649
        List<String> l = new ArrayList<>();
649
        List<String> l = new ArrayList<>();
650
        l.add("NUMERO");
650
        l.add("NUMERO");
651
        l.add("DATE");
651
        l.add("DATE");
652
        l.add("ID_CLIENT");
652
        l.add("ID_CLIENT");
653
        l.add("OBJET");
653
        l.add("OBJET");
654
        l.add("ID_COMMERCIAL");
654
        l.add("ID_COMMERCIAL");
655
        if (UserRightsManager.getCurrentUserRights().haveRight(AbstractVenteArticleItemTable.SHOW_PRIX_ACHAT_CODE)) {
655
        if (UserRightsManager.getCurrentUserRights().haveRight(AbstractVenteArticleItemTable.SHOW_PRIX_ACHAT_CODE)) {
656
            l.add("T_HA");
656
            l.add("T_HA");
657
        }
657
        }
658
        l.add("T_HT");
658
        l.add("T_HT");
659
        l.add("T_TTC");
659
        l.add("T_TTC");
-
 
660
        if (getTable().contains("TRANSFORMATION")) {
-
 
661
            l.add("TRANSFORMATION");
-
 
662
        }
660
        SQLPreferences prefs = SQLPreferences.getMemCached(getTable().getDBRoot());
663
        SQLPreferences prefs = SQLPreferences.getMemCached(getTable().getDBRoot());
661
        if (prefs.getBoolean(GestionCommercialeGlobalPreferencePanel.ACOMPTE_DEVIS, false)) {
664
        if (prefs.getBoolean(GestionCommercialeGlobalPreferencePanel.ACOMPTE_DEVIS, false)) {
662
            l.add("T_ACOMPTE");
665
            l.add("T_ACOMPTE");
663
        }
666
        }
664
        l.add("INFOS");
667
        l.add("INFOS");
665
        if (getTable().contains("DUNNING_DATE")) {
668
        if (getTable().contains("DUNNING_DATE")) {
666
            l.add("DUNNING_DATE");
669
            l.add("DUNNING_DATE");
667
        }
670
        }
668
        return l;
671
        return l;
669
    }
672
    }
670
 
673
 
671
    @Override
674
    @Override
672
    protected synchronized void _initTableSource(final SQLTableModelSource table) {
675
    protected synchronized void _initTableSource(final SQLTableModelSource table) {
673
        super._initTableSource(table);
676
        super._initTableSource(table);
674
 
677
 
675
            final BaseSQLTableModelColumn colAdrLiv = new BaseSQLTableModelColumn("Adresse de livraison", String.class) {
678
            final BaseSQLTableModelColumn colAdrLiv = new BaseSQLTableModelColumn("Adresse de livraison", String.class) {
676
 
679
 
677
                @Override
680
                @Override
678
                protected Object show_(SQLRowAccessor r) {
681
                protected Object show_(SQLRowAccessor r) {
679
 
682
 
680
                    SQLRowAccessor rowAd = null;
683
                    SQLRowAccessor rowAd = null;
681
                    if (!r.isForeignEmpty("ID_ADRESSE_LIVRAISON")) {
684
                    if (!r.isForeignEmpty("ID_ADRESSE_LIVRAISON")) {
682
                        rowAd = r.getForeign("ID_ADRESSE_LIVRAISON");
685
                        rowAd = r.getForeign("ID_ADRESSE_LIVRAISON");
683
                    } else if (!r.isForeignEmpty("ID_CLIENT")) {
686
                    } else if (!r.isForeignEmpty("ID_CLIENT")) {
684
                        if (r.getForeign("ID_CLIENT").getObject("ID_ADRESSE_L") != null && !r.getForeign("ID_CLIENT").isForeignEmpty("ID_ADRESSE_L")) {
687
                        if (r.getForeign("ID_CLIENT").getObject("ID_ADRESSE_L") != null && !r.getForeign("ID_CLIENT").isForeignEmpty("ID_ADRESSE_L")) {
685
 
688
 
686
                            rowAd = r.getForeign("ID_CLIENT").getForeign("ID_ADRESSE_L");
689
                            rowAd = r.getForeign("ID_CLIENT").getForeign("ID_ADRESSE_L");
687
                        } else {
690
                        } else {
688
                            rowAd = r.getForeign("ID_CLIENT").getForeign("ID_ADRESSE");
691
                            rowAd = r.getForeign("ID_CLIENT").getForeign("ID_ADRESSE");
689
                        }
692
                        }
690
                    }
693
                    }
691
 
694
 
692
                    String lib = rowAd == null ? "" : rowAd.getString("LIBELLE") + " " + rowAd.getString("VILLE");
695
                    String lib = rowAd == null ? "" : rowAd.getString("LIBELLE") + " " + rowAd.getString("VILLE");
693
 
696
 
694
                    return lib;
697
                    return lib;
695
                }
698
                }
696
 
699
 
697
                @Override
700
                @Override
698
                public Set<FieldPath> getPaths() {
701
                public Set<FieldPath> getPaths() {
699
                    SQLTable devisTable = getTable();
702
                    SQLTable devisTable = getTable();
700
                    Path p = new Path(devisTable);
703
                    Path p = new Path(devisTable);
701
                    p = p.add(devisTable.getField("ID_CLIENT"));
704
                    p = p.add(devisTable.getField("ID_CLIENT"));
702
                    p = p.add(p.getLast().getField("ID_ADRESSE_L"));
705
                    p = p.add(p.getLast().getField("ID_ADRESSE_L"));
703
 
706
 
704
                    Path p2 = new Path(devisTable);
707
                    Path p2 = new Path(devisTable);
705
                    p2 = p2.add(devisTable.getField("ID_CLIENT"));
708
                    p2 = p2.add(devisTable.getField("ID_CLIENT"));
706
                    p2 = p2.add(p2.getLast().getField("ID_ADRESSE"));
709
                    p2 = p2.add(p2.getLast().getField("ID_ADRESSE"));
707
 
710
 
708
                    Path p3 = new Path(devisTable);
711
                    Path p3 = new Path(devisTable);
709
                    p3 = p3.add(devisTable.getField("ID_ADRESSE_LIVRAISON"));
712
                    p3 = p3.add(devisTable.getField("ID_ADRESSE_LIVRAISON"));
710
 
713
 
711
                    return CollectionUtils.createSet(new FieldPath(p, "LIBELLE"), new FieldPath(p, "VILLE"), new FieldPath(p2, "LIBELLE"), new FieldPath(p2, "VILLE"), new FieldPath(p3, "LIBELLE"),
714
                    return CollectionUtils.createSet(new FieldPath(p, "LIBELLE"), new FieldPath(p, "VILLE"), new FieldPath(p2, "LIBELLE"), new FieldPath(p2, "VILLE"), new FieldPath(p3, "LIBELLE"),
712
                            new FieldPath(p3, "VILLE"));
715
                            new FieldPath(p3, "VILLE"));
713
                }
716
                }
714
            };
717
            };
715
            table.getColumns().add(3, colAdrLiv);
718
            table.getColumns().add(3, colAdrLiv);
716
    }
719
    }
717
 
720
 
718
    @Override
721
    @Override
719
    public ListMap<String, String> getShowAs() {
722
    public ListMap<String, String> getShowAs() {
720
        return ListMap.singleton(null, "NUMERO");
723
        return ListMap.singleton(null, "NUMERO");
721
    }
724
    }
722
 
725
 
723
    @Override
726
    @Override
724
    protected void _initListRequest(ListSQLRequest req) {
727
    protected void _initListRequest(ListSQLRequest req) {
725
        super._initListRequest(req);
728
        super._initListRequest(req);
726
        req.addToGraphToFetch("ID_ETAT_DEVIS");
729
        req.addToGraphToFetch("ID_ETAT_DEVIS");
727
    }
730
    }
728
 
731
 
729
    @Override
732
    @Override
730
    protected void setupLinks(SQLElementLinksSetup links) {
733
    protected void setupLinks(SQLElementLinksSetup links) {
731
        super.setupLinks(links);
734
        super.setupLinks(links);
732
        if (getTable().contains("ID_ADRESSE")) {
735
        if (getTable().contains("ID_ADRESSE")) {
733
            links.get("ID_ADRESSE").setType(LinkType.ASSOCIATION);
736
            links.get("ID_ADRESSE").setType(LinkType.ASSOCIATION);
734
        }
737
        }
735
        if (getTable().contains("ID_ADRESSE_LIVRAISON")) {
738
        if (getTable().contains("ID_ADRESSE_LIVRAISON")) {
736
            links.get("ID_ADRESSE_LIVRAISON").setType(LinkType.ASSOCIATION);
739
            links.get("ID_ADRESSE_LIVRAISON").setType(LinkType.ASSOCIATION);
737
        }
740
        }
738
    }
741
    }
739
 
742
 
740
    /*
743
    /*
741
     * (non-Javadoc)
744
     * (non-Javadoc)
742
     * 
745
     * 
743
     * @see org.openconcerto.devis.SQLElement#getComponent()
746
     * @see org.openconcerto.devis.SQLElement#getComponent()
744
     */
747
     */
745
    public SQLComponent createComponent() {
748
    public SQLComponent createComponent() {
746
        return new DevisSQLComponent(this);
749
        return new DevisSQLComponent(this);
747
    }
750
    }
748
 
751
 
749
    /**
752
    /**
750
     * Transfert d'un devis en facture
753
     * Transfert d'un devis en facture
751
     * 
754
     * 
752
     * @param devisID
755
     * @param devisID
753
     */
756
     */
754
    public void transfertFacture(final int devisID) {
757
    public void transfertFacture(final int devisID) {
755
 
758
 
756
        SQLElement elt = Configuration.getInstance().getDirectory().getElement("SAISIE_VENTE_FACTURE");
759
        SQLElement elt = Configuration.getInstance().getDirectory().getElement("SAISIE_VENTE_FACTURE");
757
        EditFrame editFactureFrame = new EditFrame(elt);
760
        EditFrame editFactureFrame = new EditFrame(elt);
758
        editFactureFrame.setIconImage(new ImageIcon(Gestion.class.getResource("frameicon.png")).getImage());
761
        editFactureFrame.setIconImage(new ImageIcon(Gestion.class.getResource("frameicon.png")).getImage());
759
 
762
 
760
        SaisieVenteFactureSQLComponent comp = (SaisieVenteFactureSQLComponent) editFactureFrame.getSQLComponent();
763
        SaisieVenteFactureSQLComponent comp = (SaisieVenteFactureSQLComponent) editFactureFrame.getSQLComponent();
761
 
764
 
762
        comp.setDefaults();
765
        comp.setDefaults();
763
        comp.loadDevis(devisID);
766
        comp.loadDevis(devisID);
764
 
767
 
765
 
768
 
766
        editFactureFrame.pack();
769
        editFactureFrame.pack();
767
        editFactureFrame.setState(JFrame.NORMAL);
770
        editFactureFrame.setState(JFrame.NORMAL);
768
        editFactureFrame.setVisible(true);
771
        editFactureFrame.setVisible(true);
769
    }
772
    }
770
 
773
 
771
    @Override
774
    @Override
772
    public List<CustomRowEditor> getCustomRowEditors(Configuration configuration, String sessionToken) {
775
    public List<CustomRowEditor> getCustomRowEditors(Configuration configuration, String sessionToken) {
773
        List<CustomRowEditor> map = super.getCustomRowEditors(configuration, sessionToken);
776
        List<CustomRowEditor> map = super.getCustomRowEditors(configuration, sessionToken);
774
        map.add(new CustomRowEditor("sales.quote.items.list") {
777
        map.add(new CustomRowEditor("sales.quote.items.list") {
775
 
778
 
776
            @Override
779
            @Override
777
            public LightUIElement createUIElement() {
780
            public LightUIElement createUIElement() {
778
                final ColumnSpec c1 = new ColumnSpec("sales.quote.item.style", StringWithId.class, "Style", new StringWithId(2, "Normal"), true, new LightUIComboBox("sales.quote.item.style"));
781
                final ColumnSpec c1 = new ColumnSpec("sales.quote.item.style", StringWithId.class, "Style", new StringWithId(2, "Normal"), true, new LightUIComboBox("sales.quote.item.style"));
779
                final ColumnSpec c2 = new ColumnSpec("sales.quote.item.code", String.class, "Code", "", true, new LightUITextField("sales.quote.item.code"));
782
                final ColumnSpec c2 = new ColumnSpec("sales.quote.item.code", String.class, "Code", "", true, new LightUITextField("sales.quote.item.code"));
780
                final ColumnSpec c3 = new ColumnSpec("sales.quote.item.label", String.class, "Nom", "", true, new LightUITextField("sales.quote.item.name"));
783
                final ColumnSpec c3 = new ColumnSpec("sales.quote.item.label", String.class, "Nom", "", true, new LightUITextField("sales.quote.item.name"));
781
                final ColumnSpec c4 = new ColumnSpec("sales.quote.item.description", String.class, "Descriptif", "", true, new LightUITextField("sales.quote.item.description"));
784
                final ColumnSpec c4 = new ColumnSpec("sales.quote.item.description", String.class, "Descriptif", "", true, new LightUITextField("sales.quote.item.description"));
782
                final ColumnSpec c5 = new ColumnSpec("sales.quote.item.purchase.unit.price", BigDecimal.class, "P.U. Achat HT", new BigDecimal(0), true,
785
                final ColumnSpec c5 = new ColumnSpec("sales.quote.item.purchase.unit.price", BigDecimal.class, "P.U. Achat HT", new BigDecimal(0), true,
783
                        new LightUITextField("sales.quote.item.purchase.unit.price"));
786
                        new LightUITextField("sales.quote.item.purchase.unit.price"));
784
                final ColumnSpec c6 = new ColumnSpec("sales.quote.item.sales.unit.price", BigDecimal.class, "P.U. Vente HT", new BigDecimal(0), true,
787
                final ColumnSpec c6 = new ColumnSpec("sales.quote.item.sales.unit.price", BigDecimal.class, "P.U. Vente HT", new BigDecimal(0), true,
785
                        new LightUITextField("sales.quote.item.sales.unit.price"));
788
                        new LightUITextField("sales.quote.item.sales.unit.price"));
786
                final ColumnSpec c7 = new ColumnSpec("sales.quote.item.quantity", Integer.class, "Quantité", new BigDecimal(1), true, new LightUITextField("sales.quote.item.quantity"));
789
                final ColumnSpec c7 = new ColumnSpec("sales.quote.item.quantity", Integer.class, "Quantité", new BigDecimal(1), true, new LightUITextField("sales.quote.item.quantity"));
787
 
790
 
788
                final List<ColumnSpec> columnsSpec = new ArrayList<>(7);
791
                final List<ColumnSpec> columnsSpec = new ArrayList<>(7);
789
                columnsSpec.add(c1);
792
                columnsSpec.add(c1);
790
                columnsSpec.add(c2);
793
                columnsSpec.add(c2);
791
                columnsSpec.add(c3);
794
                columnsSpec.add(c3);
792
                columnsSpec.add(c4);
795
                columnsSpec.add(c4);
793
                columnsSpec.add(c5);
796
                columnsSpec.add(c5);
794
                columnsSpec.add(c6);
797
                columnsSpec.add(c6);
795
                columnsSpec.add(c7);
798
                columnsSpec.add(c7);
796
                final List<String> possibleColumnIds = new ArrayList<>(columnsSpec.size());
799
                final List<String> possibleColumnIds = new ArrayList<>(columnsSpec.size());
797
                for (ColumnSpec c : columnsSpec) {
800
                for (ColumnSpec c : columnsSpec) {
798
                    possibleColumnIds.add(c.getId());
801
                    possibleColumnIds.add(c.getId());
799
                }
802
                }
800
 
803
 
801
                final String lId = "sales.quote.items";
804
                final String lId = "sales.quote.items";
802
                final long userId = UserManager.getUserID();
805
                final long userId = UserManager.getUserID();
803
                Document columnsPrefs = null;
806
                Document columnsPrefs = null;
804
                try {
807
                try {
805
                    final DOMBuilder in = new DOMBuilder();
808
                    final DOMBuilder in = new DOMBuilder();
806
                    final org.w3c.dom.Document w3cDoc = Configuration.getInstance().getXMLConf(userId, lId);
809
                    final org.w3c.dom.Document w3cDoc = Configuration.getInstance().getXMLConf(userId, lId);
807
                    if (w3cDoc != null) {
810
                    if (w3cDoc != null) {
808
                        columnsPrefs = in.build(w3cDoc);
811
                        columnsPrefs = in.build(w3cDoc);
809
                    }
812
                    }
810
                    if (columnsPrefs == null) {
813
                    if (columnsPrefs == null) {
811
                        throw new IllegalStateException("Columns Prefs is null");
814
                        throw new IllegalStateException("Columns Prefs is null");
812
                    }
815
                    }
813
                } catch (Exception ex) {
816
                } catch (Exception ex) {
814
                    throw new IllegalArgumentException(
817
                    throw new IllegalArgumentException(
815
                            "DevisSQLElement getItemsCustomEditorProvider - Failed to get ColumnPrefs for descriptor " + lId + " and for user " + userId + "\n" + ex.getMessage());
818
                            "DevisSQLElement getItemsCustomEditorProvider - Failed to get ColumnPrefs for descriptor " + lId + " and for user " + userId + "\n" + ex.getMessage());
816
                }
819
                }
817
 
820
 
818
                final Element rootElement = columnsPrefs.getRootElement();
821
                final Element rootElement = columnsPrefs.getRootElement();
819
                if (!rootElement.getName().equals("list")) {
822
                if (!rootElement.getName().equals("list")) {
820
                    throw new IllegalArgumentException("invalid xml, roots node list expected but " + rootElement.getName() + " found");
823
                    throw new IllegalArgumentException("invalid xml, roots node list expected but " + rootElement.getName() + " found");
821
                }
824
                }
822
                final List<Element> xmlColumns = rootElement.getChildren();
825
                final List<Element> xmlColumns = rootElement.getChildren();
823
                final int columnsCount = columnsSpec.size();
826
                final int columnsCount = columnsSpec.size();
824
                if (xmlColumns.size() != columnsCount) {
827
                if (xmlColumns.size() != columnsCount) {
825
                    throw new IllegalArgumentException("incorrect columns count in xml");
828
                    throw new IllegalArgumentException("incorrect columns count in xml");
826
                }
829
                }
827
 
830
 
828
                for (int i = 0; i < columnsCount; i++) {
831
                for (int i = 0; i < columnsCount; i++) {
829
                    final ColumnSpec columnSpec = columnsSpec.get(i);
832
                    final ColumnSpec columnSpec = columnsSpec.get(i);
830
                    final String columnId = columnSpec.getId();
833
                    final String columnId = columnSpec.getId();
831
                    boolean find = false;
834
                    boolean find = false;
832
 
835
 
833
                    for (int j = 0; j < columnsCount; j++) {
836
                    for (int j = 0; j < columnsCount; j++) {
834
                        final Element xmlColumn = xmlColumns.get(j);
837
                        final Element xmlColumn = xmlColumns.get(j);
835
                        final String xmlColumnId = xmlColumn.getAttribute("id").getValue();
838
                        final String xmlColumnId = xmlColumn.getAttribute("id").getValue();
836
 
839
 
837
                        if (xmlColumnId.equals(columnId)) {
840
                        if (xmlColumnId.equals(columnId)) {
838
 
841
 
839
                            if (!xmlColumn.getName().equals("column")) {
842
                            if (!xmlColumn.getName().equals("column")) {
840
                                throw new IllegalArgumentException("ColumnSpec setPrefs - Invalid xml, element node column expected but " + xmlColumn.getName() + " found");
843
                                throw new IllegalArgumentException("ColumnSpec setPrefs - Invalid xml, element node column expected but " + xmlColumn.getName() + " found");
841
                            }
844
                            }
842
                            if (xmlColumn.getAttribute("width") == null || xmlColumn.getAttribute("min-width") == null || xmlColumn.getAttribute("max-width") == null) {
845
                            if (xmlColumn.getAttribute("width") == null || xmlColumn.getAttribute("min-width") == null || xmlColumn.getAttribute("max-width") == null) {
843
                                throw new IllegalArgumentException("ColumnSpec setPrefs - Invalid column node for " + columnId + ", it must have attribute width, min-width, max-width");
846
                                throw new IllegalArgumentException("ColumnSpec setPrefs - Invalid column node for " + columnId + ", it must have attribute width, min-width, max-width");
844
                            }
847
                            }
845
 
848
 
846
                            final int width = Integer.parseInt(xmlColumn.getAttribute("width").getValue());
849
                            final int width = Integer.parseInt(xmlColumn.getAttribute("width").getValue());
847
                            final int maxWidth = Integer.parseInt(xmlColumn.getAttribute("max-width").getValue());
850
                            final int maxWidth = Integer.parseInt(xmlColumn.getAttribute("max-width").getValue());
848
                            final int minWidth = Integer.parseInt(xmlColumn.getAttribute("min-width").getValue());
851
                            final int minWidth = Integer.parseInt(xmlColumn.getAttribute("min-width").getValue());
849
 
852
 
850
                            columnSpec.setPrefs(width, maxWidth, minWidth);
853
                            columnSpec.setPrefs(width, maxWidth, minWidth);
851
                            if (i != j) {
854
                            if (i != j) {
852
                                final ColumnSpec swap = columnsSpec.get(i);
855
                                final ColumnSpec swap = columnsSpec.get(i);
853
                                columnsSpec.set(i, columnsSpec.get(j));
856
                                columnsSpec.set(i, columnsSpec.get(j));
854
                                columnsSpec.set(j, swap);
857
                                columnsSpec.set(j, swap);
855
                            }
858
                            }
856
                            find = true;
859
                            find = true;
857
                            break;
860
                            break;
858
                        }
861
                        }
859
                    }
862
                    }
860
                    if (!find) {
863
                    if (!find) {
861
                        throw new IllegalArgumentException("xml contain unknow column: " + columnId);
864
                        throw new IllegalArgumentException("xml contain unknow column: " + columnId);
862
                    }
865
                    }
863
                }
866
                }
864
                final ColumnsSpec cSpec = new ColumnsSpec(lId, columnsSpec, possibleColumnIds, null);
867
                final ColumnsSpec cSpec = new ColumnsSpec(lId, columnsSpec, possibleColumnIds, null);
865
                cSpec.setAllowMove(true);
868
                cSpec.setAllowMove(true);
866
                cSpec.setAllowResize(true);
869
                cSpec.setAllowResize(true);
867
                final RowSelectionSpec selectionSpec = new RowSelectionSpec(getItemId());
870
                final RowSelectionSpec selectionSpec = new RowSelectionSpec(getItemId());
868
                final TableSpec tSpec = new TableSpec(getItemId(), selectionSpec, cSpec);
871
                final TableSpec tSpec = new TableSpec(getItemId(), selectionSpec, cSpec);
869
                tSpec.setColumns(cSpec);
872
                tSpec.setColumns(cSpec);
870
 
873
 
871
                String id = getItemId();
874
                String id = getItemId();
872
                final LightUITable eList = new LightUITable(id);
875
                final LightUITable eList = new LightUITable(id);
873
                eList.setTableSpec(tSpec);
876
                eList.setTableSpec(tSpec);
874
 
877
 
875
                LightUIPanel panel = new LightUIPanel("sales.quote.items.list");
878
                LightUIPanel panel = new LightUIPanel("sales.quote.items.list");
876
                panel.setGridWidth(1);
879
                panel.setGridWidth(1);
877
                panel.setFillWidth(true);
880
                panel.setFillWidth(true);
878
 
881
 
879
                LightUILine toolbarLine = new LightUILine();
882
                LightUILine toolbarLine = new LightUILine();
880
 
883
 
881
                LightUIButtonUnmanaged b1 = new LightUIButtonUnmanaged("up");
884
                LightUIButtonUnmanaged b1 = new LightUIButtonUnmanaged("up");
882
                b1.setIcon("up.png");
885
                b1.setIcon("up.png");
883
                panel.addControler(new ActivationOnSelectionControler(id, b1.getId()));
886
                panel.addControler(new ActivationOnSelectionControler(id, b1.getId()));
884
                panel.addControler(new LightController(LightController.TYPE_UP, id, b1.getId()));
887
                panel.addControler(new LightController(LightController.TYPE_UP, id, b1.getId()));
885
                toolbarLine.addChild(b1);
888
                toolbarLine.addChild(b1);
886
 
889
 
887
                final LightUIButtonUnmanaged b2 = new LightUIButtonUnmanaged("down");
890
                final LightUIButtonUnmanaged b2 = new LightUIButtonUnmanaged("down");
888
                b2.setIcon("down.png");
891
                b2.setIcon("down.png");
889
                panel.addControler(new ActivationOnSelectionControler(id, b2.getId()));
892
                panel.addControler(new ActivationOnSelectionControler(id, b2.getId()));
890
                panel.addControler(new LightController(LightController.TYPE_DOWN, id, b2.getId()));
893
                panel.addControler(new LightController(LightController.TYPE_DOWN, id, b2.getId()));
891
                toolbarLine.addChild(b2);
894
                toolbarLine.addChild(b2);
892
                // Add
895
                // Add
893
                LightUIElement addButton = new LightUIButtonUnmanaged("add", "Ajouter une ligne");
896
                LightUIElement addButton = new LightUIButtonUnmanaged("add", "Ajouter une ligne");
894
                panel.addControler(new LightController(LightController.TYPE_ADD_DEFAULT, id, addButton.getId()));
897
                panel.addControler(new LightController(LightController.TYPE_ADD_DEFAULT, id, addButton.getId()));
895
                toolbarLine.addChild(addButton);
898
                toolbarLine.addChild(addButton);
896
                // Insert
899
                // Insert
897
                LightUIElement insertButton = new LightUIButtonUnmanaged("insert", "Insérer une ligne");
900
                LightUIElement insertButton = new LightUIButtonUnmanaged("insert", "Insérer une ligne");
898
                panel.addControler(new LightController(LightController.TYPE_INSERT_DEFAULT, id, insertButton.getId()));
901
                panel.addControler(new LightController(LightController.TYPE_INSERT_DEFAULT, id, insertButton.getId()));
899
                toolbarLine.addChild(insertButton);
902
                toolbarLine.addChild(insertButton);
900
 
903
 
901
                // Copy
904
                // Copy
902
                LightUIElement copyButton = new LightUIButtonUnmanaged("copy", "Dupliquer");
905
                LightUIElement copyButton = new LightUIButtonUnmanaged("copy", "Dupliquer");
903
                panel.addControler(new ActivationOnSelectionControler(id, copyButton.getId()));
906
                panel.addControler(new ActivationOnSelectionControler(id, copyButton.getId()));
904
                panel.addControler(new LightController(LightController.TYPE_COPY, id, copyButton.getId()));
907
                panel.addControler(new LightController(LightController.TYPE_COPY, id, copyButton.getId()));
905
                toolbarLine.addChild(copyButton);
908
                toolbarLine.addChild(copyButton);
906
 
909
 
907
                // Remove
910
                // Remove
908
                LightUIElement removeButton = new LightUIButtonUnmanaged("remove", "Supprimer");
911
                LightUIElement removeButton = new LightUIButtonUnmanaged("remove", "Supprimer");
909
                panel.addControler(new ActivationOnSelectionControler(id, removeButton.getId()));
912
                panel.addControler(new ActivationOnSelectionControler(id, removeButton.getId()));
910
                panel.addControler(new LightController(LightController.TYPE_REMOVE, id, removeButton.getId()));
913
                panel.addControler(new LightController(LightController.TYPE_REMOVE, id, removeButton.getId()));
911
                toolbarLine.addChild(removeButton);
914
                toolbarLine.addChild(removeButton);
912
 
915
 
913
                panel.addChild(toolbarLine);
916
                panel.addChild(toolbarLine);
914
                final LightUILine listLine = new LightUILine();
917
                final LightUILine listLine = new LightUILine();
915
                listLine.setWeightY(1);
918
                listLine.setWeightY(1);
916
                listLine.setFillHeight(true);
919
                listLine.setFillHeight(true);
917
                listLine.addChild(eList);
920
                listLine.addChild(eList);
918
 
921
 
919
                //
922
                //
920
                panel.addChild(listLine);
923
                panel.addChild(listLine);
921
 
924
 
922
                return panel;
925
                return panel;
923
 
926
 
924
            }
927
            }
925
 
928
 
926
            @Override
929
            @Override
927
            public void fillFrom(LightUIElement uiElement, SQLRowAccessor sqlRow) {
930
            public void fillFrom(LightUIElement uiElement, SQLRowAccessor sqlRow) {
928
                LightUIPanel p = (LightUIPanel) uiElement;
931
                LightUIPanel p = (LightUIPanel) uiElement;
929
                LightUITable ltable = p.getFirstChild(LightUITable.class);
932
                LightUITable ltable = p.getFirstChild(LightUITable.class);
930
                TableSpec tSpec = ltable.getTableSpec();
933
                TableSpec tSpec = ltable.getTableSpec();
931
                ColumnsSpec columnsSpec = tSpec.getColumns();
934
                ColumnsSpec columnsSpec = tSpec.getColumns();
932
                // send: id,value
935
                // send: id,value
933
                final SQLElement elem = configuration.getDirectory().getElement("DEVIS_ELEMENT");
936
                final SQLElement elem = configuration.getDirectory().getElement("DEVIS_ELEMENT");
934
                final SQLTable table = elem.getTable();
937
                final SQLTable table = elem.getTable();
935
                final List<String> fieldsToFetch = new ArrayList<>();
938
                final List<String> fieldsToFetch = new ArrayList<>();
936
                for (ColumnSpec cs : columnsSpec.getColumns()) {
939
                for (ColumnSpec cs : columnsSpec.getColumns()) {
937
                    String colId = cs.getId();
940
                    String colId = cs.getId();
938
                    SQLField f = configuration.getFieldMapper().getSQLFieldForItem(colId);
941
                    SQLField f = configuration.getFieldMapper().getSQLFieldForItem(colId);
939
                    if (f != null) {
942
                    if (f != null) {
940
                        fieldsToFetch.add(f.getName());
943
                        fieldsToFetch.add(f.getName());
941
                    } else {
944
                    } else {
942
                        throw new IllegalStateException("No field in " + table + " for column id " + colId);
945
                        throw new IllegalStateException("No field in " + table + " for column id " + colId);
943
                    }
946
                    }
944
                }
947
                }
945
 
948
 
946
                final Where where = new Where(table.getField("ID_DEVIS"), "=", sqlRow.getID());
949
                final Where where = new Where(table.getField("ID_DEVIS"), "=", sqlRow.getID());
947
                final ListSQLRequest req = elem.createListRequest(fieldsToFetch, where, configuration.getShowAs());
950
                final ListSQLRequest req = elem.createListRequest(fieldsToFetch, where, configuration.getShowAs());
948
                List<SQLRowValues> fetchedRows = req.getValues();
951
                List<SQLRowValues> fetchedRows = req.getValues();
949
 
952
 
950
                List<Row> rows = new ArrayList<>();
953
                List<Row> rows = new ArrayList<>();
951
                for (final SQLRowValues vals : fetchedRows) {
954
                for (final SQLRowValues vals : fetchedRows) {
952
                    Row r = new Row(vals.getID(), columnsSpec.getColumns().size());
955
                    Row r = new Row(vals.getID(), columnsSpec.getColumns().size());
953
                    List<Object> values = new ArrayList<>();
956
                    List<Object> values = new ArrayList<>();
954
                    for (ColumnSpec cs : columnsSpec.getColumns()) {
957
                    for (ColumnSpec cs : columnsSpec.getColumns()) {
955
                        String colId = cs.getId();
958
                        String colId = cs.getId();
956
                        SQLField f = configuration.getFieldMapper().getSQLFieldForItem(colId);
959
                        SQLField f = configuration.getFieldMapper().getSQLFieldForItem(colId);
957
                        if (f != null) {
960
                        if (f != null) {
958
                            Object object = vals.getObject(f.getName());
961
                            Object object = vals.getObject(f.getName());
959
                            if (object instanceof SQLRowValues) {
962
                            if (object instanceof SQLRowValues) {
960
                                SQLRowValues sqlRowValues = (SQLRowValues) object;
963
                                SQLRowValues sqlRowValues = (SQLRowValues) object;
961
                                long rowId = sqlRowValues.getIDNumber().longValue();
964
                                long rowId = sqlRowValues.getIDNumber().longValue();
962
                                List<SQLField> fieldsToExpand = configuration.getShowAs().getFieldExpand(sqlRowValues.getTable());
965
                                List<SQLField> fieldsToExpand = configuration.getShowAs().getFieldExpand(sqlRowValues.getTable());
963
                                final StringBuilder b = new StringBuilder();
966
                                final StringBuilder b = new StringBuilder();
964
                                for (SQLField sqlField : fieldsToExpand) {
967
                                for (SQLField sqlField : fieldsToExpand) {
965
                                    b.append(sqlRowValues.getObject(sqlField.getName()).toString());
968
                                    b.append(sqlRowValues.getObject(sqlField.getName()).toString());
966
                                    b.append(' ');
969
                                    b.append(' ');
967
                                }
970
                                }
968
                                object = new StringWithId(rowId, b.toString().trim());
971
                                object = new StringWithId(rowId, b.toString().trim());
969
                            }
972
                            }
970
                            values.add(object);
973
                            values.add(object);
971
                        } else {
974
                        } else {
972
                            throw new IllegalStateException("No field in " + table + " for column id " + colId);
975
                            throw new IllegalStateException("No field in " + table + " for column id " + colId);
973
                        }
976
                        }
974
                    }
977
                    }
975
                    r.setValues(values);
978
                    r.setValues(values);
976
                    rows.add(r);
979
                    rows.add(r);
977
                }
980
                }
978
 
981
 
979
                TableContent tableContent = new TableContent();
982
                TableContent tableContent = new TableContent();
980
                tableContent.setRows(rows);
983
                tableContent.setRows(rows);
981
                tSpec.setContent(tableContent);
984
                tSpec.setContent(tableContent);
982
 
985
 
983
            }
986
            }
984
 
987
 
985
            @Override
988
            @Override
986
            public void store(LightUIElement uiElement, SQLRowValues row) {
989
            public void store(LightUIElement uiElement, SQLRowValues row) {
987
                // TODO Auto-generated method stub
990
                // TODO Auto-generated method stub
988
 
991
 
989
            }
992
            }
990
 
993
 
991
        });
994
        });
992
        return map;
995
        return map;
993
    }
996
    }
994
 
997
 
995
    @Override
998
    @Override
996
    protected String createCode() {
999
    protected String createCode() {
997
        return "sales.quote";
1000
        return "sales.quote";
998
    }
1001
    }
999
}
1002
}