OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 18 | Rev 25 | Go to most recent revision | 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.sales.order.element;
15
 
16
import org.openconcerto.erp.config.Gestion;
17
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
18
import org.openconcerto.erp.core.sales.invoice.component.SaisieVenteFactureSQLComponent;
19
import org.openconcerto.erp.core.sales.order.component.CommandeClientSQLComponent;
19 ilm 20
import org.openconcerto.erp.core.sales.product.element.ReferenceArticleSQLElement;
18 ilm 21
import org.openconcerto.erp.core.sales.shipment.component.BonDeLivraisonSQLComponent;
19 ilm 22
import org.openconcerto.erp.core.supplychain.order.component.CommandeSQLComponent;
23
import org.openconcerto.erp.core.supplychain.stock.element.MouvementStockSQLElement;
18 ilm 24
import org.openconcerto.sql.Configuration;
25
import org.openconcerto.sql.element.SQLComponent;
26
import org.openconcerto.sql.element.SQLElement;
19 ilm 27
import org.openconcerto.sql.model.SQLField;
28
import org.openconcerto.sql.model.SQLInjector;
29
import org.openconcerto.sql.model.SQLRow;
30
import org.openconcerto.sql.model.SQLRowValues;
31
import org.openconcerto.sql.model.SQLTable;
18 ilm 32
import org.openconcerto.sql.view.EditFrame;
19 ilm 33
import org.openconcerto.utils.CollectionMap;
18 ilm 34
 
35
import java.util.ArrayList;
36
import java.util.HashSet;
37
import java.util.List;
38
import java.util.Set;
39
 
40
import javax.swing.ImageIcon;
41
import javax.swing.JFrame;
42
 
43
public class CommandeClientSQLElement extends ComptaSQLConfElement {
44
 
45
    public CommandeClientSQLElement() {
46
        super("COMMANDE_CLIENT", "une commande client", "commandes clients");
47
    }
48
 
49
    /*
50
     * (non-Javadoc)
51
     *
52
     * @see org.openconcerto.devis.BaseSQLElement#getComboFields()
53
     */
54
    protected List<String> getComboFields() {
55
        List<String> l = new ArrayList<String>();
56
        l.add("NUMERO");
57
        return l;
58
    }
59
 
60
    /*
61
     * (non-Javadoc)
62
     *
63
     * @see org.openconcerto.devis.BaseSQLElement#getListFields()
64
     */
65
    protected List<String> getListFields() {
66
        List<String> l = new ArrayList<String>();
67
        l.add("NUMERO");
68
        l.add("DATE");
69
        l.add("ID_CLIENT");
70
        // l.add("OBJET");
71
        l.add("T_HT");
72
        l.add("T_TTC");
73
        l.add("NOM");
74
        l.add("INFOS");
75
        return l;
76
    }
77
 
78
    @Override
79
    protected Set<String> getChildren() {
80
        Set<String> set = new HashSet<String>();
81
        set.add("COMMANDE_CLIENT_ELEMENT");
82
        return set;
83
    }
84
 
85
    /*
86
     * (non-Javadoc)
87
     *
88
     * @see org.openconcerto.devis.SQLElement#getComponent()
89
     */
90
    public SQLComponent createComponent() {
91
        return new CommandeClientSQLComponent();
92
    }
93
 
94
    /**
95
     * Transfert d'un commande en BL
96
     *
97
     * @param commandeID
98
     */
99
    public void transfertBonLivraison(int commandeID) {
100
 
101
        SQLElement elt = Configuration.getInstance().getDirectory().getElement("BON_DE_LIVRAISON");
102
        EditFrame editBonFrame = new EditFrame(elt);
103
        editBonFrame.setIconImage(new ImageIcon(Gestion.class.getResource("frameicon.png")).getImage());
104
 
105
        BonDeLivraisonSQLComponent comp = (BonDeLivraisonSQLComponent) editBonFrame.getSQLComponent();
106
 
107
        // comp.setDefaults();
108
        comp.loadCommande(commandeID);
109
 
110
        editBonFrame.pack();
111
        editBonFrame.setState(JFrame.NORMAL);
112
        editBonFrame.setVisible(true);
113
    }
114
 
115
    /**
116
     * Transfert d'une commande en facture
117
     *
118
     * @param commandeID
119
     */
120
    public void transfertFacture(int commandeID) {
121
 
122
        SQLElement elt = Configuration.getInstance().getDirectory().getElement("SAISIE_VENTE_FACTURE");
123
        EditFrame editFactureFrame = new EditFrame(elt);
124
        editFactureFrame.setIconImage(new ImageIcon(Gestion.class.getResource("frameicon.png")).getImage());
125
 
126
        SaisieVenteFactureSQLComponent comp = (SaisieVenteFactureSQLComponent) editFactureFrame.getSQLComponent();
127
 
128
        // comp.setDefaults();
129
        comp.loadCommande(commandeID);
130
 
131
        editFactureFrame.pack();
132
        editFactureFrame.setState(JFrame.NORMAL);
133
        editFactureFrame.setVisible(true);
134
    }
19 ilm 135
 
136
    /**
137
     * Transfert d'une commande en commande fournisseur
138
     *
139
     * @param commandeID
140
     */
141
    public void transfertCommande(int commandeID) {
142
 
143
        // SQLElement elt = Configuration.getInstance().getDirectory().getElement("COMMANDE");
144
        // EditFrame editFactureFrame = new EditFrame(elt);
145
        // editFactureFrame.setIconImage(new
146
        // ImageIcon(Gestion.class.getResource("frameicon.png")).getImage());
147
        //
148
        // CommandeSQLComponent comp = (CommandeSQLComponent) editFactureFrame.getSQLComponent();
149
        //
150
        // // comp.setDefaults();
151
        // comp.loadCommande(commandeID);
152
        //
153
        // editFactureFrame.pack();
154
        // editFactureFrame.setState(JFrame.NORMAL);
155
        // editFactureFrame.setVisible(true);
156
        SQLElement elt = Configuration.getInstance().getDirectory().getElement("COMMANDE_CLIENT_ELEMENT");
157
        SQLTable tableCmdElt = Configuration.getInstance().getDirectory().getElement("COMMANDE_ELEMENT").getTable();
158
        SQLElement eltArticle = Configuration.getInstance().getDirectory().getElement("ARTICLE");
159
        SQLRow rowCmd = getTable().getRow(commandeID);
160
        List<SQLRow> rows = rowCmd.getReferentRows(elt.getTable());
161
        CollectionMap<SQLRow, List<SQLRowValues>> map = new CollectionMap<SQLRow, List<SQLRowValues>>();
162
        for (SQLRow sqlRow : rows) {
163
            // on récupére l'article qui lui correspond
164
            SQLRowValues rowArticle = new SQLRowValues(eltArticle.getTable());
165
            for (SQLField field : eltArticle.getTable().getFields()) {
166
                if (sqlRow.getTable().getFieldsName().contains(field.getName())) {
167
                    rowArticle.put(field.getName(), sqlRow.getObject(field.getName()));
168
                }
169
            }
170
            // rowArticle.loadAllSafe(rowEltFact);
171
            int idArticle = ReferenceArticleSQLElement.getIdForCNM(rowArticle, true);
172
            SQLRow rowArticleFind = eltArticle.getTable().getRow(idArticle);
173
            SQLInjector inj = SQLInjector.getInjector(rowArticle.getTable(), tableCmdElt);
174
            SQLRowValues rowValsElt = new SQLRowValues(inj.createRowValuesFrom(rowArticleFind));
175
 
176
            rowValsElt.put("QTE", sqlRow.getObject("QTE"));
177
            rowValsElt.put("T_POIDS", rowValsElt.getLong("POIDS") * rowValsElt.getInt("QTE"));
178
            rowValsElt.put("T_PA_HT", rowValsElt.getLong("PA_HT") * rowValsElt.getInt("QTE"));
179
            rowValsElt.put("T_PA_TTC", rowValsElt.getLong("T_PA_HT") * (rowValsElt.getForeign("ID_TAXE").getFloat("TAUX") / 100.0 + 1.0));
180
 
181
            map.put(rowArticleFind.getForeignRow("ID_FOURNISSEUR"), rowValsElt);
182
 
183
        }
184
        MouvementStockSQLElement.createCommandeF(map, rowCmd.getForeignRow("ID_TARIF").getForeignRow("ID_DEVISE"));
185
    }
18 ilm 186
}