OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 174 Rev 180
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
9
 * language governing permissions and limitations under the License.
10
 * 
10
 * 
11
 * When distributing the software, include this License Header Notice in each file.
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.erp.core.supplychain.order.element;
14
 package org.openconcerto.erp.core.supplychain.order.element;
15
 
15
 
16
import org.openconcerto.erp.config.Gestion;
16
import org.openconcerto.erp.config.Gestion;
17
import org.openconcerto.erp.core.common.component.TransfertBaseSQLComponent;
17
import org.openconcerto.erp.core.common.component.TransfertBaseSQLComponent;
18
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
18
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
-
 
19
import org.openconcerto.erp.core.edm.AttachmentAction;
19
import org.openconcerto.erp.core.supplychain.order.component.CommandeSQLComponent;
20
import org.openconcerto.erp.core.supplychain.order.component.CommandeSQLComponent;
20
import org.openconcerto.erp.core.supplychain.order.component.SaisieAchatSQLComponent;
21
import org.openconcerto.erp.core.supplychain.order.component.SaisieAchatSQLComponent;
21
import org.openconcerto.erp.core.supplychain.receipt.component.BonReceptionSQLComponent;
22
import org.openconcerto.erp.core.supplychain.receipt.component.BonReceptionSQLComponent;
22
import org.openconcerto.erp.generationDoc.gestcomm.CommandeXmlSheet;
23
import org.openconcerto.erp.generationDoc.gestcomm.CommandeXmlSheet;
23
import org.openconcerto.erp.model.MouseSheetXmlListeListener;
24
import org.openconcerto.erp.model.MouseSheetXmlListeListener;
24
import org.openconcerto.erp.preferences.GestionCommercialeGlobalPreferencePanel;
25
import org.openconcerto.erp.preferences.GestionCommercialeGlobalPreferencePanel;
25
import org.openconcerto.sql.Configuration;
26
import org.openconcerto.sql.Configuration;
26
import org.openconcerto.sql.element.SQLComponent;
27
import org.openconcerto.sql.element.SQLComponent;
27
import org.openconcerto.sql.element.SQLElement;
28
import org.openconcerto.sql.element.SQLElement;
28
import org.openconcerto.sql.element.TreesOfSQLRows;
29
import org.openconcerto.sql.element.TreesOfSQLRows;
29
import org.openconcerto.sql.model.SQLRow;
30
import org.openconcerto.sql.model.SQLRow;
30
import org.openconcerto.sql.model.SQLRowAccessor;
31
import org.openconcerto.sql.model.SQLRowAccessor;
31
import org.openconcerto.sql.model.SQLRowValues;
32
import org.openconcerto.sql.model.SQLRowValues;
32
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
33
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
33
import org.openconcerto.sql.model.SQLSelect;
34
import org.openconcerto.sql.model.SQLSelect;
34
import org.openconcerto.sql.model.SQLSelectJoin;
35
import org.openconcerto.sql.model.SQLSelectJoin;
35
import org.openconcerto.sql.model.SQLTable;
36
import org.openconcerto.sql.model.SQLTable;
36
import org.openconcerto.sql.model.Where;
37
import org.openconcerto.sql.model.Where;
37
import org.openconcerto.sql.preferences.SQLPreferences;
38
import org.openconcerto.sql.preferences.SQLPreferences;
38
import org.openconcerto.sql.view.EditFrame;
39
import org.openconcerto.sql.view.EditFrame;
39
import org.openconcerto.sql.view.EditPanel;
40
import org.openconcerto.sql.view.EditPanel;
40
import org.openconcerto.sql.view.list.IListe;
41
import org.openconcerto.sql.view.list.IListe;
41
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
42
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
42
import org.openconcerto.sql.view.list.RowAction;
43
import org.openconcerto.sql.view.list.RowAction;
43
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
44
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
44
import org.openconcerto.utils.ExceptionHandler;
45
import org.openconcerto.utils.ExceptionHandler;
45
import org.openconcerto.utils.cc.ITransformer;
46
import org.openconcerto.utils.cc.ITransformer;
46
 
47
 
47
import java.awt.event.ActionEvent;
48
import java.awt.event.ActionEvent;
48
import java.sql.SQLException;
49
import java.sql.SQLException;
49
import java.util.ArrayList;
50
import java.util.ArrayList;
50
import java.util.List;
51
import java.util.List;
51
 
52
 
52
import javax.swing.AbstractAction;
53
import javax.swing.AbstractAction;
53
import javax.swing.ImageIcon;
54
import javax.swing.ImageIcon;
54
import javax.swing.JFrame;
55
import javax.swing.JFrame;
55
import javax.swing.JOptionPane;
56
import javax.swing.JOptionPane;
56
import javax.swing.SwingWorker;
57
import javax.swing.SwingWorker;
57
 
58
 
58
import org.apache.commons.dbutils.handlers.ArrayListHandler;
59
import org.apache.commons.dbutils.handlers.ArrayListHandler;
59
 
60
 
60
public class CommandeSQLElement extends ComptaSQLConfElement {
61
public class CommandeSQLElement extends ComptaSQLConfElement {
61
 
62
 
62
    public CommandeSQLElement() {
63
    public CommandeSQLElement() {
63
        super("COMMANDE", "une commande fournisseur", "commandes fournisseur");
64
        super("COMMANDE", "une commande fournisseur", "commandes fournisseur");
64
 
65
 
-
 
66
        if (getTable().contains("ATTACHMENTS")) {
-
 
67
            PredicateRowAction actionAttachment = new PredicateRowAction(new AttachmentAction().getAction(), true);
-
 
68
            actionAttachment.setPredicate(IListeEvent.getSingleSelectionPredicate());
-
 
69
            getRowActions().add(actionAttachment);
-
 
70
        }
-
 
71
 
65
        getRowActions().addAll(new MouseSheetXmlListeListener(CommandeXmlSheet.class).getRowActions());
72
        getRowActions().addAll(new MouseSheetXmlListeListener(CommandeXmlSheet.class).getRowActions());
66
 
73
 
67
        // Transfert vers BR
74
        // Transfert vers BR
68
        PredicateRowAction bonAction = new PredicateRowAction(new AbstractAction() {
75
        PredicateRowAction bonAction = new PredicateRowAction(new AbstractAction() {
69
            public void actionPerformed(ActionEvent e) {
76
            public void actionPerformed(ActionEvent e) {
70
                final List<SQLRowValues> selectedRows = IListe.get(e).getSelectedRows();
77
                final List<SQLRowValues> selectedRows = IListe.get(e).getSelectedRows();
71
                transfertBR(selectedRows);
78
                transfertBR(selectedRows);
72
            }
79
            }
73
 
80
 
74
        }, true, "supplychain.order.create.receipt");
81
        }, true, "supplychain.order.create.receipt");
75
 
82
 
76
        bonAction.setPredicate(IListeEvent.getSingleSelectionPredicate());
83
        bonAction.setPredicate(IListeEvent.getSingleSelectionPredicate());
77
        getRowActions().add(bonAction);
84
        getRowActions().add(bonAction);
78
 
85
 
79
        PredicateRowAction actionsTRFA = new PredicateRowAction(new AbstractAction("Transfert vers facture fournisseur") {
86
        PredicateRowAction actionsTRFA = new PredicateRowAction(new AbstractAction("Transfert vers facture fournisseur") {
80
            public void actionPerformed(ActionEvent e) {
87
            public void actionPerformed(ActionEvent e) {
81
                final List<SQLRowValues> selectedRows = IListe.get(e).getSelectedRows();
88
                final List<SQLRowValues> selectedRows = IListe.get(e).getSelectedRows();
82
                SwingWorker<Boolean, Object> worker = new SwingWorker<Boolean, Object>() {
89
                SwingWorker<Boolean, Object> worker = new SwingWorker<Boolean, Object>() {
83
                    @Override
90
                    @Override
84
                    protected Boolean doInBackground() throws Exception {
91
                    protected Boolean doInBackground() throws Exception {
85
 
92
 
86
                        boolean b = TransfertBaseSQLComponent.isAlreadyAllTransfert(selectedRows, getTable(), getTable().getTable("FACTURE_FOURNISSEUR"), "T_HT", "T_HT");
93
                        boolean b = TransfertBaseSQLComponent.isAlreadyAllTransfert(selectedRows, getTable(), getTable().getTable("FACTURE_FOURNISSEUR"), "T_HT", "T_HT");
87
 
94
 
88
                        if (b) {
95
                        if (b) {
89
                            String label = "Attention ";
96
                            String label = "Attention ";
90
                            if (selectedRows.size() > 1) {
97
                            if (selectedRows.size() > 1) {
91
                                label += " les " + getPluralName() + " ont déjà été transféré!";
98
                                label += " les " + getPluralName() + " ont déjà été transféré!";
92
                            } else {
99
                            } else {
93
                                label += getSingularName() + " a déjà été transféré!";
100
                                label += getSingularName() + " a déjà été transféré!";
94
                            }
101
                            }
95
                            label += "\n Voulez vous continuer?";
102
                            label += "\n Voulez vous continuer?";
96
 
103
 
97
                            int ans = JOptionPane.showConfirmDialog(null, label, "Transfert " + getSingularName(), JOptionPane.YES_NO_OPTION);
104
                            int ans = JOptionPane.showConfirmDialog(null, label, "Transfert " + getSingularName(), JOptionPane.YES_NO_OPTION);
98
                            if (ans == JOptionPane.NO_OPTION) {
105
                            if (ans == JOptionPane.NO_OPTION) {
99
                                return Boolean.FALSE;
106
                                return Boolean.FALSE;
100
                            }
107
                            }
101
                        }
108
                        }
102
 
109
 
103
                        return Boolean.TRUE;
110
                        return Boolean.TRUE;
104
 
111
 
105
                    }
112
                    }
106
 
113
 
107
                    @Override
114
                    @Override
108
                    protected void done() {
115
                    protected void done() {
109
                        try {
116
                        try {
110
                            Boolean b = get();
117
                            Boolean b = get();
111
                            if (b) {
118
                            if (b) {
112
                                TransfertBaseSQLComponent.openTransfertFrame(selectedRows, "FACTURE_FOURNISSEUR");
119
                                TransfertBaseSQLComponent.openTransfertFrame(selectedRows, "FACTURE_FOURNISSEUR");
113
                            }
120
                            }
114
                        } catch (Exception e) {
121
                        } catch (Exception e) {
115
                            ExceptionHandler.handle("Erreur lors du transfert des " + getPluralName() + "!", e);
122
                            ExceptionHandler.handle("Erreur lors du transfert des " + getPluralName() + "!", e);
116
                        }
123
                        }
117
                    }
124
                    }
118
                };
125
                };
119
                worker.execute();
126
                worker.execute();
120
            }
127
            }
121
        }, false);
128
        }, false);
122
        actionsTRFA.setPredicate(IListeEvent.getNonEmptySelectionPredicate());
129
        actionsTRFA.setPredicate(IListeEvent.getNonEmptySelectionPredicate());
123
        getRowActions().add(actionsTRFA);
130
        getRowActions().add(actionsTRFA);
124
 
131
 
125
        // Transfert vers facture
132
        // Transfert vers facture
126
        PredicateRowAction factureAction = new PredicateRowAction(new AbstractAction() {
133
        PredicateRowAction factureAction = new PredicateRowAction(new AbstractAction() {
127
            public void actionPerformed(ActionEvent e) {
134
            public void actionPerformed(ActionEvent e) {
128
 
135
 
129
                CommandeSQLElement.this.transfertFacture(IListe.get(e).getSelectedRow().getID());
136
                CommandeSQLElement.this.transfertFacture(IListe.get(e).getSelectedRow().getID());
130
            }
137
            }
131
        }, false, "supplychain.order.create.purchase");
138
        }, false, "supplychain.order.create.purchase");
132
        factureAction.setPredicate(IListeEvent.getSingleSelectionPredicate());
139
        factureAction.setPredicate(IListeEvent.getSingleSelectionPredicate());
133
        getRowActions().add(factureAction);
140
        getRowActions().add(factureAction);
134
 
141
 
135
        getRowActions().add(getCloneAction());
142
        getRowActions().add(getCloneAction());
136
 
143
 
137
        PredicateRowAction tagValidAction = new PredicateRowAction(new AbstractAction() {
144
        PredicateRowAction tagValidAction = new PredicateRowAction(new AbstractAction() {
138
            public void actionPerformed(ActionEvent e) {
145
            public void actionPerformed(ActionEvent e) {
139
 
146
 
140
                final SQLRowValues asRowValues = IListe.get(e).getSelectedRow().asRow().createEmptyUpdateRow();
147
                final SQLRowValues asRowValues = IListe.get(e).getSelectedRow().asRow().createEmptyUpdateRow();
141
                asRowValues.put("EN_COURS", Boolean.FALSE);
148
                asRowValues.put("EN_COURS", Boolean.FALSE);
142
                try {
149
                try {
143
                    asRowValues.commit();
150
                    asRowValues.commit();
144
                } catch (SQLException e1) {
151
                } catch (SQLException e1) {
145
                    ExceptionHandler.handle("Une erreur est survenue pour notifier la commande valider", e1);
152
                    ExceptionHandler.handle("Une erreur est survenue pour notifier la commande valider", e1);
146
                }
153
                }
147
            }
154
            }
148
        }, false, "supplychain.order.valid");
155
        }, false, "supplychain.order.valid");
149
        tagValidAction.setPredicate(IListeEvent.getSingleSelectionPredicate());
156
        tagValidAction.setPredicate(IListeEvent.getSingleSelectionPredicate());
150
        getRowActions().add(tagValidAction);
157
        getRowActions().add(tagValidAction);
151
    }
158
    }
152
 
159
 
153
    @Override
160
    @Override
154
    protected List<String> getListFields() {
161
    protected List<String> getListFields() {
155
        final List<String> l = new ArrayList<>(8);
162
        final List<String> l = new ArrayList<>(8);
156
        l.add("NUMERO");
163
        l.add("NUMERO");
157
        l.add("NOM");
164
        l.add("NOM");
158
        l.add("DATE");
165
        l.add("DATE");
159
        l.add("ID_FOURNISSEUR");
166
        l.add("ID_FOURNISSEUR");
160
        l.add("ID_COMMERCIAL");
167
        l.add("ID_COMMERCIAL");
161
        l.add("T_HT");
168
        l.add("T_HT");
162
        l.add("T_TTC");
169
        l.add("T_TTC");
163
        Boolean useCommandeEnCours = SQLPreferences.getMemCached(getTable().getDBRoot()).getBoolean(GestionCommercialeGlobalPreferencePanel.COMMANDE_FOURNISSEUR_EN_COURS, false);
170
        Boolean useCommandeEnCours = SQLPreferences.getMemCached(getTable().getDBRoot()).getBoolean(GestionCommercialeGlobalPreferencePanel.COMMANDE_FOURNISSEUR_EN_COURS, false);
164
        if (useCommandeEnCours) {
171
        if (useCommandeEnCours) {
165
            l.add("EN_COURS");
172
            l.add("EN_COURS");
166
        }
173
        }
167
        l.add("INFOS");
174
        l.add("INFOS");
168
        return l;
175
        return l;
169
    }
176
    }
170
 
177
 
171
    @Override
178
    @Override
172
    protected List<String> getComboFields() {
179
    protected List<String> getComboFields() {
173
        final List<String> l = new ArrayList<>(3);
180
        final List<String> l = new ArrayList<>(3);
174
        l.add("NUMERO");
181
        l.add("NUMERO");
175
        l.add("NOM");
182
        l.add("NOM");
176
        l.add("DATE");
183
        l.add("DATE");
177
        return l;
184
        return l;
178
    }
185
    }
179
 
186
 
180
    /*
187
    /*
181
     * (non-Javadoc)
188
     * (non-Javadoc)
182
     * 
189
     * 
183
     * @see org.openconcerto.devis.SQLElement#getComponent()
190
     * @see org.openconcerto.devis.SQLElement#getComponent()
184
     */
191
     */
185
    public SQLComponent createComponent() {
192
    public SQLComponent createComponent() {
186
        return new CommandeSQLComponent();
193
        return new CommandeSQLComponent();
187
    }
194
    }
188
 
195
 
189
    public void transfertBR(final List<SQLRowValues> selectedRows) {
196
    public void transfertBR(final List<SQLRowValues> selectedRows) {
190
 
197
 
191
        EditFrame f = TransfertBaseSQLComponent.openTransfertFrame(selectedRows, "BON_RECEPTION");
198
        EditFrame f = TransfertBaseSQLComponent.openTransfertFrame(selectedRows, "BON_RECEPTION");
192
        BonReceptionSQLComponent comp = (BonReceptionSQLComponent) f.getSQLComponent();
199
        BonReceptionSQLComponent comp = (BonReceptionSQLComponent) f.getSQLComponent();
193
        final SQLTable tableElt = comp.getElement().getTable().getTable("BON_RECEPTION_ELEMENT");
200
        final SQLTable tableElt = comp.getElement().getTable().getTable("BON_RECEPTION_ELEMENT");
194
        SQLRowValues rowVals = new SQLRowValues(tableElt);
201
        SQLRowValues rowVals = new SQLRowValues(tableElt);
195
        rowVals.put("QTE_UNITAIRE", null);
202
        rowVals.put("QTE_UNITAIRE", null);
196
        rowVals.put("QTE", null);
203
        rowVals.put("QTE", null);
197
        rowVals.put("ID_ARTICLE", null);
204
        rowVals.put("ID_ARTICLE", null);
198
 
205
 
199
        SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(rowVals);
206
        SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(rowVals);
200
        fetcher.setSelTransf(new ITransformer<SQLSelect, SQLSelect>() {
207
        fetcher.setSelTransf(new ITransformer<SQLSelect, SQLSelect>() {
201
 
208
 
202
            @Override
209
            @Override
203
            public SQLSelect transformChecked(SQLSelect input) {
210
            public SQLSelect transformChecked(SQLSelect input) {
204
                final List<Integer> ids = new ArrayList<>(selectedRows.size());
211
                final List<Integer> ids = new ArrayList<>(selectedRows.size());
205
                for (SQLRowValues sqlRowValues : selectedRows) {
212
                for (SQLRowValues sqlRowValues : selectedRows) {
206
                    ids.add(sqlRowValues.getID());
213
                    ids.add(sqlRowValues.getID());
207
                }
214
                }
208
                SQLSelectJoin joinBR = input.addJoin("RIGHT", tableElt.getTable("BON_RECEPTION_ELEMENT").getField("ID_BON_RECEPTION"));
215
                SQLSelectJoin joinBR = input.addJoin("RIGHT", tableElt.getTable("BON_RECEPTION_ELEMENT").getField("ID_BON_RECEPTION"));
209
                SQLSelectJoin joinTR = input.addBackwardJoin("RIGHT", tableElt.getTable("TR_COMMANDE").getField("ID_BON_RECEPTION"), joinBR.getJoinedTable().getAlias());
216
                SQLSelectJoin joinTR = input.addBackwardJoin("RIGHT", tableElt.getTable("TR_COMMANDE").getField("ID_BON_RECEPTION"), joinBR.getJoinedTable().getAlias());
210
                joinTR.setWhere(new Where(joinTR.getJoinedTable().getField("ID_COMMANDE"), ids));
217
                joinTR.setWhere(new Where(joinTR.getJoinedTable().getField("ID_COMMANDE"), ids));
211
                return input;
218
                return input;
212
            }
219
            }
213
        });
220
        });
214
        comp.loadQuantity(fetcher.fetch());
221
        comp.loadQuantity(fetcher.fetch());
215
    }
222
    }
216
 
223
 
217
    /**
224
    /**
218
     * Transfert d'une commande en facture
225
     * Transfert d'une commande en facture
219
     * 
226
     * 
220
     * @param commandeID
227
     * @param commandeID
221
     */
228
     */
222
    public void transfertFacture(int commandeID) {
229
    public void transfertFacture(int commandeID) {
223
        SQLElement elt = Configuration.getInstance().getDirectory().getElement("SAISIE_ACHAT");
230
        SQLElement elt = Configuration.getInstance().getDirectory().getElement("SAISIE_ACHAT");
224
        EditFrame editFactureFrame = new EditFrame(elt);
231
        EditFrame editFactureFrame = new EditFrame(elt);
225
        editFactureFrame.setIconImage(new ImageIcon(Gestion.class.getResource("frameicon.png")).getImage());
232
        editFactureFrame.setIconImage(new ImageIcon(Gestion.class.getResource("frameicon.png")).getImage());
226
 
233
 
227
        SaisieAchatSQLComponent comp = (SaisieAchatSQLComponent) editFactureFrame.getSQLComponent();
234
        SaisieAchatSQLComponent comp = (SaisieAchatSQLComponent) editFactureFrame.getSQLComponent();
228
        comp.loadCommande(commandeID);
235
        comp.loadCommande(commandeID);
229
 
236
 
230
        editFactureFrame.pack();
237
        editFactureFrame.pack();
231
        editFactureFrame.setState(JFrame.NORMAL);
238
        editFactureFrame.setState(JFrame.NORMAL);
232
        editFactureFrame.setVisible(true);
239
        editFactureFrame.setVisible(true);
233
    }
240
    }
234
 
241
 
235
    public RowAction getCloneAction() {
242
    public RowAction getCloneAction() {
236
        return new RowAction(new AbstractAction() {
243
        return new RowAction(new AbstractAction() {
237
 
244
 
238
            public void actionPerformed(ActionEvent e) {
245
            public void actionPerformed(ActionEvent e) {
239
                SQLRowAccessor selectedRow = IListe.get(e).getSelectedRow();
246
                SQLRowAccessor selectedRow = IListe.get(e).getSelectedRow();
240
 
247
 
241
                SQLElement eltFact = Configuration.getInstance().getDirectory().getElement("COMMANDE");
248
                SQLElement eltFact = Configuration.getInstance().getDirectory().getElement("COMMANDE");
242
                EditFrame editFrame = new EditFrame(eltFact, EditPanel.CREATION);
249
                EditFrame editFrame = new EditFrame(eltFact, EditPanel.CREATION);
243
 
250
 
244
                ((CommandeSQLComponent) editFrame.getSQLComponent()).duplicate(selectedRow.getID());
251
                ((CommandeSQLComponent) editFrame.getSQLComponent()).duplicate(selectedRow.getID());
245
                editFrame.setVisible(true);
252
                editFrame.setVisible(true);
246
            }
253
            }
247
        }, true, "sales.quote.clone") {
254
        }, true, "sales.quote.clone") {
248
            @Override
255
            @Override
249
            public boolean enabledFor(java.util.List<org.openconcerto.sql.model.SQLRowValues> selection) {
256
            public boolean enabledFor(java.util.List<org.openconcerto.sql.model.SQLRowValues> selection) {
250
                return (selection != null && selection.size() == 1);
257
                return (selection != null && selection.size() == 1);
251
            }
258
            }
252
        };
259
        };
253
    }
260
    }
254
 
261
 
255
    @Override
262
    @Override
256
    protected void archive(TreesOfSQLRows trees, boolean cutLinks) throws SQLException {
263
    protected void archive(TreesOfSQLRows trees, boolean cutLinks) throws SQLException {
257
 
264
 
258
        for (SQLRow row : trees.getRows()) {
265
        for (SQLRow row : trees.getRows()) {
259
 
266
 
260
            // Mise à jour des stocks
267
            // Mise à jour des stocks
261
            SQLElement eltMvtStock = Configuration.getInstance().getDirectory().getElement("MOUVEMENT_STOCK");
268
            SQLElement eltMvtStock = Configuration.getInstance().getDirectory().getElement("MOUVEMENT_STOCK");
262
            SQLSelect sel = new SQLSelect();
269
            SQLSelect sel = new SQLSelect();
263
            sel.addSelect(eltMvtStock.getTable().getField("ID"));
270
            sel.addSelect(eltMvtStock.getTable().getField("ID"));
264
            Where w = new Where(eltMvtStock.getTable().getField("IDSOURCE"), "=", row.getID());
271
            Where w = new Where(eltMvtStock.getTable().getField("IDSOURCE"), "=", row.getID());
265
            Where w2 = new Where(eltMvtStock.getTable().getField("SOURCE"), "=", getTable().getName());
272
            Where w2 = new Where(eltMvtStock.getTable().getField("SOURCE"), "=", getTable().getName());
266
            sel.setWhere(w.and(w2));
273
            sel.setWhere(w.and(w2));
267
 
274
 
268
            @SuppressWarnings("rawtypes")
275
            @SuppressWarnings("rawtypes")
269
            List l = (List) eltMvtStock.getTable().getBase().getDataSource().execute(sel.asString(), new ArrayListHandler());
276
            List l = (List) eltMvtStock.getTable().getBase().getDataSource().execute(sel.asString(), new ArrayListHandler());
270
            if (l != null) {
277
            if (l != null) {
271
                for (int i = 0; i < l.size(); i++) {
278
                for (int i = 0; i < l.size(); i++) {
272
                    Object[] tmp = (Object[]) l.get(i);
279
                    Object[] tmp = (Object[]) l.get(i);
273
                    eltMvtStock.archive(((Number) tmp[0]).intValue());
280
                    eltMvtStock.archive(((Number) tmp[0]).intValue());
274
                }
281
                }
275
            }
282
            }
276
        }
283
        }
277
        super.archive(trees, cutLinks);
284
        super.archive(trees, cutLinks);
278
    }
285
    }
279
 
286
 
280
    @Override
287
    @Override
281
    protected String createCode() {
288
    protected String createCode() {
282
        return "supplychain.order";
289
        return "supplychain.order";
283
    }
290
    }
284
}
291
}