OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 144 | Details | Compare with Previous | Last modification | View Log | RSS feed

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