OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev Author Line No. Line
18 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
 package org.openconcerto.erp.core.supplychain.order.element;
15
 
65 ilm 16
import org.openconcerto.erp.config.Gestion;
18 ilm 17
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
65 ilm 18
import org.openconcerto.erp.core.supplychain.credit.component.AvoirFournisseurSQLComponent;
18 ilm 19
import org.openconcerto.erp.core.supplychain.order.component.SaisieAchatSQLComponent;
65 ilm 20
import org.openconcerto.sql.Configuration;
18 ilm 21
import org.openconcerto.sql.element.SQLComponent;
65 ilm 22
import org.openconcerto.sql.element.SQLElement;
132 ilm 23
import org.openconcerto.sql.element.SQLElementLinksSetup;
24
import org.openconcerto.sql.element.SQLElementLink.LinkType;
65 ilm 25
import org.openconcerto.sql.model.SQLInjector;
80 ilm 26
import org.openconcerto.sql.model.SQLRow;
27
import org.openconcerto.sql.model.SQLRowValues;
65 ilm 28
import org.openconcerto.sql.view.EditFrame;
80 ilm 29
import org.openconcerto.sql.view.EditPanel;
30
import org.openconcerto.sql.view.list.IListe;
31
import org.openconcerto.sql.view.list.RowAction;
18 ilm 32
 
80 ilm 33
import java.awt.event.ActionEvent;
18 ilm 34
import java.util.ArrayList;
35
import java.util.List;
36
 
80 ilm 37
import javax.swing.AbstractAction;
65 ilm 38
import javax.swing.ImageIcon;
39
import javax.swing.JFrame;
40
 
18 ilm 41
public class SaisieAchatSQLElement extends ComptaSQLConfElement {
42
 
43
    public SaisieAchatSQLElement() {
44
        super("SAISIE_ACHAT", "une saisie d'achat", "saisies d'achats");
80 ilm 45
        this.getRowActions().add(getCloneAction());
18 ilm 46
    }
47
 
48
    protected List<String> getListFields() {
49
        final List<String> l = new ArrayList<String>();
50
        l.add("ID_MOUVEMENT");
51
        l.add("DATE");
52
        l.add("NOM");
53
        l.add("ID_FOURNISSEUR");
57 ilm 54
        l.add("MONTANT_HT");
55
        l.add("MONTANT_TTC");
18 ilm 56
        l.add("INFOS");
57
        return l;
58
    }
59
 
60
    protected List<String> getComboFields() {
61
        final List<String> l = new ArrayList<String>();
62
        l.add("DATE");
63
        l.add("MONTANT_TTC");
64
        return l;
65
    }
66
 
132 ilm 67
    @Override
68
    protected void setupLinks(SQLElementLinksSetup links) {
69
        super.setupLinks(links);
70
        links.get("ID_MOUVEMENT").setType(LinkType.ASSOCIATION);
18 ilm 71
    }
72
 
73
    /*
74
     * (non-Javadoc)
75
     *
76
     * @see org.openconcerto.devis.SQLElement#getComponent()
77
     */
78
    public SQLComponent createComponent() {
79
        return new SaisieAchatSQLComponent(this);
80
    }
81
 
57 ilm 82
    @Override
83
    protected String createCode() {
156 ilm 84
        return createCodeOfPackage() + ".purchase";
57 ilm 85
    }
65 ilm 86
 
87
    public void transfertAvoir(int idFacture) {
88
        final SQLElement elt = Configuration.getInstance().getDirectory().getElement("AVOIR_FOURNISSEUR");
89
        final EditFrame editAvoirFrame = new EditFrame(elt);
90
        editAvoirFrame.setIconImage(new ImageIcon(Gestion.class.getResource("frameicon.png")).getImage());
91
 
92
        final AvoirFournisseurSQLComponent comp = (AvoirFournisseurSQLComponent) editAvoirFrame.getSQLComponent();
93
        final SQLInjector inject = SQLInjector.getInjector(this.getTable(), elt.getTable());
94
        comp.select(inject.createRowValuesFrom(idFacture));
95
 
96
        editAvoirFrame.pack();
97
        editAvoirFrame.setState(JFrame.NORMAL);
98
        editAvoirFrame.setVisible(true);
99
 
100
    }
80 ilm 101
 
102
    public RowAction getCloneAction() {
103
        return new RowAction(new AbstractAction("Dupliquer") {
104
 
105
            public void actionPerformed(ActionEvent e) {
106
                SQLRow selectedRow = IListe.get(e).fetchSelectedRow();
107
                EditFrame editFrame = new EditFrame(SaisieAchatSQLElement.this, EditPanel.CREATION);
108
 
109
                final SQLRowValues copy = SaisieAchatSQLElement.this.createCopy(selectedRow.getID());
110
                copy.put("ID_MOUVEMENT", null);
111
                copy.put("DATE", null);
112
                editFrame.getSQLComponent().select(copy);
113
 
114
                editFrame.setVisible(true);
115
            }
116
        }, true, "purchase.clone") {
93 ilm 117
            public boolean enabledFor(java.util.List<org.openconcerto.sql.model.SQLRowValues> selection) {
80 ilm 118
                return (selection != null && selection.size() == 1);
119
            };
120
        };
121
    }
122
 
18 ilm 123
}