OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 144 Rev 156
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
9
 * language governing permissions and limitations under the License.
10
 * 
10
 * 
11
 * When distributing the software, include this License Header Notice in each file.
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
12
 */
13
 
13
 
14
 /*
14
 /*
15
 * Créé le 18 oct. 2011
15
 * Créé le 18 oct. 2011
16
 */
16
 */
17
package org.openconcerto.erp.core.supplychain.order.element;
17
package org.openconcerto.erp.core.supplychain.order.element;
18
 
18
 
19
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
19
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
20
import org.openconcerto.erp.core.supplychain.order.component.CommandeSQLComponent;
20
import org.openconcerto.erp.core.supplychain.order.component.CommandeSQLComponent;
21
import org.openconcerto.erp.model.MouseSheetXmlListeListener;
21
import org.openconcerto.erp.model.MouseSheetXmlListeListener;
22
import org.openconcerto.sql.Configuration;
22
import org.openconcerto.sql.Configuration;
23
import org.openconcerto.sql.element.SQLComponent;
23
import org.openconcerto.sql.element.SQLComponent;
24
import org.openconcerto.sql.model.SQLInjector;
24
import org.openconcerto.sql.model.SQLInjector;
25
import org.openconcerto.sql.model.SQLRow;
25
import org.openconcerto.sql.model.SQLRow;
26
import org.openconcerto.sql.model.SQLRowAccessor;
26
import org.openconcerto.sql.model.SQLRowAccessor;
27
import org.openconcerto.sql.model.SQLRowValues;
27
import org.openconcerto.sql.model.SQLRowValues;
28
import org.openconcerto.sql.view.EditFrame;
28
import org.openconcerto.sql.view.EditFrame;
29
import org.openconcerto.sql.view.EditPanel.EditMode;
29
import org.openconcerto.sql.view.EditPanel.EditMode;
30
import org.openconcerto.sql.view.list.IListe;
30
import org.openconcerto.sql.view.list.IListe;
31
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
31
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
32
import org.openconcerto.sql.view.list.RowAction;
32
import org.openconcerto.sql.view.list.RowAction;
33
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
33
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
34
import org.openconcerto.sql.view.list.SQLTableModelSource;
34
import org.openconcerto.sql.view.list.SQLTableModelSource;
35
import org.openconcerto.utils.ListMap;
35
import org.openconcerto.utils.ListMap;
36
 
36
 
37
import java.awt.event.ActionEvent;
37
import java.awt.event.ActionEvent;
38
import java.sql.SQLException;
38
import java.sql.SQLException;
39
import java.util.ArrayList;
39
import java.util.ArrayList;
40
import java.util.List;
40
import java.util.List;
41
 
41
 
42
import javax.swing.AbstractAction;
42
import javax.swing.AbstractAction;
43
 
43
 
44
public class DemandePrixSQLElement extends ComptaSQLConfElement {
44
public class DemandePrixSQLElement extends ComptaSQLConfElement {
45
 
45
 
46
    private SQLRowValues getLivraisonAdr(SQLRowAccessor rowAffaire) {
46
    private SQLRowValues getLivraisonAdr(SQLRowAccessor rowAffaire) {
47
        SQLRowAccessor rowClient = rowAffaire.getForeign("ID_CLIENT");
47
        SQLRowAccessor rowClient = rowAffaire.getForeign("ID_CLIENT");
48
        SQLRowAccessor rowAdrL = rowClient.getForeign("ID_ADRESSE_L");
48
        SQLRowAccessor rowAdrL = rowClient.getForeign("ID_ADRESSE_L");
49
        if (rowAdrL == null || rowAdrL.isUndefined()) {
49
        if (rowAdrL == null || rowAdrL.isUndefined()) {
50
            rowAdrL = rowClient.getForeign("ID_ADRESSE");
50
            rowAdrL = rowClient.getForeign("ID_ADRESSE");
51
        }
51
        }
52
        SQLRowValues rowVals = rowAdrL.asRowValues();
52
        SQLRowValues rowVals = rowAdrL.asRowValues();
53
        rowVals.clearPrimaryKeys();
53
        rowVals.clearPrimaryKeys();
54
        return rowVals;
54
        return rowVals;
55
    }
55
    }
56
 
56
 
57
    @Override
57
    @Override
58
    protected void _initTableSource(SQLTableModelSource source) {
58
    protected void _initTableSource(SQLTableModelSource source) {
59
        super._initTableSource(source);
59
        super._initTableSource(source);
60
        // {
60
        // {
61
        // BaseSQLTableModelColumn cmd = new BaseSQLTableModelColumn("Commande associée",
61
        // BaseSQLTableModelColumn cmd = new BaseSQLTableModelColumn("Commande associée",
62
        // String.class) {
62
        // String.class) {
63
        //
63
        //
64
        // @Override
64
        // @Override
65
        // protected Object show_(SQLRowAccessor r) {
65
        // protected Object show_(SQLRowAccessor r) {
66
        // Collection<? extends SQLRowAccessor> l =
66
        // Collection<? extends SQLRowAccessor> l =
67
        // r.getReferentRows(r.getTable().getTable("COMMANDE"));
67
        // r.getReferentRows(r.getTable().getTable("COMMANDE"));
68
        // String s = "";
68
        // String s = "";
69
        // if (l != null && l.size() > 0) {
69
        // if (l != null && l.size() > 0) {
70
        // for (SQLRowAccessor sqlRowAccessor : l) {
70
        // for (SQLRowAccessor sqlRowAccessor : l) {
71
        // s += sqlRowAccessor.getString("NUMERO") + " ";
71
        // s += sqlRowAccessor.getString("NUMERO") + " ";
72
        // }
72
        // }
73
        // }
73
        // }
74
        //
74
        //
75
        // return s;
75
        // return s;
76
        // }
76
        // }
77
        //
77
        //
78
        // @Override
78
        // @Override
79
        // public Set<FieldPath> getPaths() {
79
        // public Set<FieldPath> getPaths() {
80
        // // TODO Raccord de méthode auto-généré
80
        // // TODO Raccord de méthode auto-généré
81
        // Path p = new Path(getTable());
81
        // Path p = new Path(getTable());
82
        // p = p.add(getTable().getTable("COMMANDE").getField("ID_DEMANDE_PRIX"));
82
        // p = p.add(getTable().getTable("COMMANDE").getField("ID_DEMANDE_PRIX"));
83
        //
83
        //
84
        // return CollectionUtils.createSet(new FieldPath(p, "NUMERO"));
84
        // return CollectionUtils.createSet(new FieldPath(p, "NUMERO"));
85
        // }
85
        // }
86
        // };
86
        // };
87
        // source.getColumns().add(cmd);
87
        // source.getColumns().add(cmd);
88
        // }
88
        // }
89
 
89
 
90
    }
90
    }
91
 
91
 
92
    public DemandePrixSQLElement() {
92
    public DemandePrixSQLElement() {
93
        super("DEMANDE_PRIX", "une demande de prix fournisseur", "demandes de prix fournisseur");
93
        super("DEMANDE_PRIX");
94
 
94
 
95
        MouseSheetXmlListeListener l = new MouseSheetXmlListeListener(DemandePrixSheetXML.class) {
95
        MouseSheetXmlListeListener l = new MouseSheetXmlListeListener(DemandePrixSheetXML.class) {
96
 
96
 
97
            @Override
97
            @Override
98
            protected String getMailObject(SQLRow row) {
98
            protected String getMailObject(SQLRow row) {
99
                // TODO Raccord de méthode auto-généré
99
                // TODO Raccord de méthode auto-généré
100
                return "Veuillez trouver en pièce jointe notre demande de prix.";
100
                return "Veuillez trouver en pièce jointe notre demande de prix.";
101
            }
101
            }
102
 
102
 
103
            @Override
103
            @Override
104
            public List<RowAction> addToMenu() {
104
            public List<RowAction> addToMenu() {
105
                List<RowAction> actions = new ArrayList<RowAction>();
105
                List<RowAction> actions = new ArrayList<RowAction>();
106
 
106
 
107
                PredicateRowAction action = new PredicateRowAction(new AbstractAction("Marqué comme acceptée et transférer en commande") {
107
                PredicateRowAction action = new PredicateRowAction(new AbstractAction("Marqué comme acceptée et transférer en commande") {
108
 
108
 
109
                    @Override
109
                    @Override
110
                    public void actionPerformed(ActionEvent arg0) {
110
                    public void actionPerformed(ActionEvent arg0) {
111
                        SQLRowAccessor row = IListe.get(arg0).getSelectedRow().asRow();
111
                        SQLRowAccessor row = IListe.get(arg0).getSelectedRow().asRow();
112
                        SQLRowValues rowVals = row.asRowValues();
112
                        SQLRowValues rowVals = row.asRowValues();
113
                        rowVals.put("ID_ETAT_DEMANDE_PRIX", EtatDemandePrixSQLElement.ACCEPTE);
113
                        rowVals.put("ID_ETAT_DEMANDE_PRIX", EtatDemandePrixSQLElement.ACCEPTE);
114
                        try {
114
                        try {
115
                            rowVals.update();
115
                            rowVals.update();
116
                        } catch (SQLException exn) {
116
                        } catch (SQLException exn) {
117
                            exn.printStackTrace();
117
                            exn.printStackTrace();
118
                        }
118
                        }
119
                        SQLInjector inj = SQLInjector.getInjector(row.getTable(), row.getTable().getTable("COMMANDE"));
119
                        SQLInjector inj = SQLInjector.getInjector(row.getTable(), row.getTable().getTable("COMMANDE"));
120
                        EditFrame f = new EditFrame(Configuration.getInstance().getDirectory().getElement("COMMANDE"));
120
                        EditFrame f = new EditFrame(Configuration.getInstance().getDirectory().getElement("COMMANDE"));
121
                        final CommandeSQLComponent sqlComponent = (CommandeSQLComponent) f.getPanel().getSQLComponent();
121
                        final CommandeSQLComponent sqlComponent = (CommandeSQLComponent) f.getPanel().getSQLComponent();
122
                        sqlComponent.select(inj.createRowValuesFrom(row.getID()));
122
                        sqlComponent.select(inj.createRowValuesFrom(row.getID()));
123
 
123
 
124
                        // SQLRowAccessor foreignRow = row.getForeign("ID_ADRESSE");
124
                        // SQLRowAccessor foreignRow = row.getForeign("ID_ADRESSE");
125
                        // if (foreignRow != null && !foreignRow.isUndefined()) {
125
                        // if (foreignRow != null && !foreignRow.isUndefined()) {
126
                        // ElementSQLObject obj = (ElementSQLObject)
126
                        // ElementSQLObject obj = (ElementSQLObject)
127
                        // sqlComponent.getView("ID_ADRESSE").getComp();
127
                        // sqlComponent.getView("ID_ADRESSE").getComp();
128
                        // obj.setCreated(true);
128
                        // obj.setCreated(true);
129
                        //
129
                        //
130
                        // SQLRowValues asRowValues = getLivraisonAdr(row.getForeign("ID_AFFAIRE"));
130
                        // SQLRowValues asRowValues = getLivraisonAdr(row.getForeign("ID_AFFAIRE"));
131
                        // asRowValues.clearPrimaryKeys();
131
                        // asRowValues.clearPrimaryKeys();
132
                        // obj.getSQLChild().select(asRowValues);
132
                        // obj.getSQLChild().select(asRowValues);
133
                        // }
133
                        // }
134
                        sqlComponent.loadItem(sqlComponent.getRowValuesTablePanel(), Configuration.getInstance().getDirectory().getElement("DEMANDE_PRIX"), row.getID(),
134
                        sqlComponent.loadItem(sqlComponent.getRowValuesTablePanel(), Configuration.getInstance().getDirectory().getElement("DEMANDE_PRIX"), row.getID(),
135
                                Configuration.getInstance().getDirectory().getElement("DEMANDE_PRIX_ELEMENT"));
135
                                Configuration.getInstance().getDirectory().getElement("DEMANDE_PRIX_ELEMENT"));
136
                        f.setVisible(true);
136
                        f.setVisible(true);
137
                    }
137
                    }
138
                }, false);
138
                }, false);
139
                action.setPredicate(IListeEvent.getSingleSelectionPredicate());
139
                action.setPredicate(IListeEvent.getSingleSelectionPredicate());
140
                actions.add(action);
140
                actions.add(action);
141
 
141
 
142
                PredicateRowAction actionCreate = new PredicateRowAction(new AbstractAction("Créer à partir de ...") {
142
                PredicateRowAction actionCreate = new PredicateRowAction(new AbstractAction("Créer à partir de ...") {
143
 
143
 
144
                    @Override
144
                    @Override
145
                    public void actionPerformed(ActionEvent arg0) {
145
                    public void actionPerformed(ActionEvent arg0) {
146
                        SQLRowAccessor row = IListe.get(arg0).getSelectedRow().asRow();
146
                        SQLRowAccessor row = IListe.get(arg0).getSelectedRow().asRow();
147
                        DemandePrixSQLComponent createComponent = (DemandePrixSQLComponent) createComponent();
147
                        DemandePrixSQLComponent createComponent = (DemandePrixSQLComponent) createComponent();
148
                        EditFrame frame = new EditFrame(createComponent, EditMode.CREATION);
148
                        EditFrame frame = new EditFrame(createComponent, EditMode.CREATION);
149
                        createComponent.loadDemandeExistant(row.getID());
149
                        createComponent.loadDemandeExistant(row.getID());
150
                        frame.setVisible(true);
150
                        frame.setVisible(true);
151
                    }
151
                    }
152
                }, false);
152
                }, false);
153
                actionCreate.setPredicate(IListeEvent.getSingleSelectionPredicate());
153
                actionCreate.setPredicate(IListeEvent.getSingleSelectionPredicate());
154
                actions.add(actionCreate);
154
                actions.add(actionCreate);
155
 
155
 
156
                // actions.addAll(new DemandePrixAction().getEtatAction());
156
                // actions.addAll(new DemandePrixAction().getEtatAction());
157
                return actions;
157
                return actions;
158
            }
158
            }
159
        };
159
        };
160
 
160
 
161
        getRowActions().addAll(l.getRowActions());
161
        getRowActions().addAll(l.getRowActions());
162
 
162
 
163
    }
163
    }
164
 
164
 
165
    @Override
165
    @Override
166
    protected List<String> getListFields() {
166
    protected List<String> getListFields() {
167
        final List<String> l = new ArrayList<String>();
167
        final List<String> l = new ArrayList<String>();
168
        l.add("NUMERO");
168
        l.add("NUMERO");
169
        l.add("ID_FOURNISSEUR");
169
        l.add("ID_FOURNISSEUR");
170
        l.add("DATE");
170
        l.add("DATE");
171
        l.add("ID_ETAT_DEMANDE_PRIX");
171
        l.add("ID_ETAT_DEMANDE_PRIX");
172
        return l;
172
        return l;
173
    }
173
    }
174
 
174
 
175
    @Override
175
    @Override
176
    protected List<String> getComboFields() {
176
    protected List<String> getComboFields() {
177
        final List<String> l = new ArrayList<String>();
177
        final List<String> l = new ArrayList<String>();
178
        l.add("NUMERO");
178
        l.add("NUMERO");
179
        l.add("ID_FOURNISSEUR");
179
        l.add("ID_FOURNISSEUR");
180
        return l;
180
        return l;
181
    }
181
    }
182
 
182
 
183
    @Override
183
    @Override
184
    public ListMap<String, String> getShowAs() {
184
    public ListMap<String, String> getShowAs() {
185
        return ListMap.singleton(null, "NUMERO");
185
        return ListMap.singleton(null, "NUMERO");
186
    }
186
    }
187
 
187
 
188
    @Override
188
    @Override
189
    public SQLComponent createComponent() {
189
    public SQLComponent createComponent() {
190
        return new DemandePrixSQLComponent(this);
190
        return new DemandePrixSQLComponent(this);
191
    }
191
    }
192
 
192
 
193
    @Override
193
    @Override
194
    protected String createCode() {
194
    protected String createCode() {
195
        return createCodeFromPackage() + ".demande";
195
        return createCodeOfPackage() + ".demande";
196
    }
196
    }
197
 
197
 
198
}
198
}