OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 149 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 149 Rev 156
Line 14... Line 14...
14
 package org.openconcerto.erp.core.sales.invoice.element;
14
 package org.openconcerto.erp.core.sales.invoice.element;
15
 
15
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
17
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
17
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
18
import org.openconcerto.erp.core.common.ui.AbstractVenteArticleItemTable;
18
import org.openconcerto.erp.core.common.ui.AbstractVenteArticleItemTable;
19
import org.openconcerto.erp.core.common.ui.DeviseField;
-
 
20
import org.openconcerto.erp.preferences.DefaultNXProps;
19
import org.openconcerto.erp.preferences.DefaultNXProps;
21
import org.openconcerto.erp.rights.NXRights;
20
import org.openconcerto.erp.rights.NXRights;
22
import org.openconcerto.sql.Configuration;
-
 
23
import org.openconcerto.sql.element.BaseSQLComponent;
21
import org.openconcerto.sql.element.BaseSQLComponent;
24
import org.openconcerto.sql.element.SQLComponent;
22
import org.openconcerto.sql.element.SQLComponent;
-
 
23
import org.openconcerto.sql.element.SQLElement;
-
 
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.model.SQLSelect;
28
import org.openconcerto.sql.model.SQLSelect;
-
 
29
import org.openconcerto.sql.model.SQLTable;
29
import org.openconcerto.sql.model.Where;
30
import org.openconcerto.sql.model.Where;
30
import org.openconcerto.sql.sqlobject.ElementComboBox;
31
import org.openconcerto.sql.sqlobject.ElementComboBox;
31
import org.openconcerto.sql.users.rights.UserRights;
32
import org.openconcerto.sql.users.rights.UserRights;
32
import org.openconcerto.sql.users.rights.UserRightsManager;
33
import org.openconcerto.sql.users.rights.UserRightsManager;
-
 
34
import org.openconcerto.sql.view.EditFrame;
-
 
35
import org.openconcerto.sql.view.EditPanel.EditMode;
-
 
36
import org.openconcerto.sql.view.list.IListe;
-
 
37
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
-
 
38
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
33
import org.openconcerto.sql.view.list.SQLTableModelSource;
39
import org.openconcerto.sql.view.list.SQLTableModelSource;
34
import org.openconcerto.ui.DefaultGridBagConstraints;
40
import org.openconcerto.ui.DefaultGridBagConstraints;
35
import org.openconcerto.ui.component.InteractionMode;
41
import org.openconcerto.ui.component.InteractionMode;
-
 
42
import org.openconcerto.utils.DecimalUtils;
36
import org.openconcerto.utils.cc.ITransformer;
43
import org.openconcerto.utils.cc.ITransformer;
37
 
44
 
38
import java.awt.GridBagConstraints;
45
import java.awt.GridBagConstraints;
39
import java.awt.GridBagLayout;
46
import java.awt.GridBagLayout;
-
 
47
import java.awt.event.ActionEvent;
-
 
48
import java.math.BigDecimal;
40
import java.sql.SQLException;
49
import java.sql.SQLException;
41
import java.util.ArrayList;
50
import java.util.ArrayList;
-
 
51
import java.util.HashMap;
42
import java.util.HashSet;
52
import java.util.HashSet;
43
import java.util.List;
53
import java.util.List;
-
 
54
import java.util.Map;
44
import java.util.Set;
55
import java.util.Set;
45
 
56
 
-
 
57
import javax.swing.AbstractAction;
46
import javax.swing.JLabel;
58
import javax.swing.JLabel;
47
import javax.swing.JTextField;
59
import javax.swing.JTextField;
48
 
60
 
49
public class SaisieVenteFactureItemSQLElement extends ComptaSQLConfElement {
61
public class SaisieVenteFactureItemSQLElement extends ComptaSQLConfElement {
50
 
62
 
-
 
63
    private final ComptaPropsConfiguration conf;
-
 
64
 
51
    public SaisieVenteFactureItemSQLElement() {
65
    public SaisieVenteFactureItemSQLElement(final ComptaPropsConfiguration conf) {
52
        super("SAISIE_VENTE_FACTURE_ELEMENT", "un article facturé", "articles facturés");
66
        super(conf.getRootSociete().getTable("SAISIE_VENTE_FACTURE_ELEMENT"));
53
    }
67
        this.conf = conf;
-
 
68
        PredicateRowAction action = new PredicateRowAction(new AbstractAction("Transfert vers commande fournisseur") {
54
 
69
 
-
 
70
            @Override
-
 
71
            public void actionPerformed(ActionEvent e) {
-
 
72
                SQLElement cmd = getDirectory().getElement("COMMANDE");
-
 
73
                EditFrame f = new EditFrame(cmd, EditMode.CREATION);
55
    public SaisieVenteFactureItemSQLElement(String tableName, String singular, String plural) {
74
                f.getSQLComponent().select(transfertCommande(IListe.get(e).getSelectedRows()));
-
 
75
                f.setVisible(true);
-
 
76
            }
-
 
77
        }, false);
-
 
78
        action.setPredicate(IListeEvent.getNonEmptySelectionPredicate());
56
        super(tableName, singular, plural);
79
        getRowActions().add(action);
57
    }
80
    }
58
 
81
 
-
 
82
    public final ComptaPropsConfiguration getConf() {
-
 
83
        return this.conf;
-
 
84
    }
-
 
85
    
59
    @Override
86
    @Override
60
    protected String getParentFFName() {
87
    protected String getParentFFName() {
61
 
88
 
62
        return "ID_SAISIE_VENTE_FACTURE";
89
        return "ID_SAISIE_VENTE_FACTURE";
63
    }
90
    }
64
 
91
 
-
 
92
    /**
-
 
93
     * Transfert d'une commande en commande fournisseur
-
 
94
     * 
-
 
95
     * @param commandeID
-
 
96
     */
-
 
97
    public SQLRowValues transfertCommande(List<SQLRowValues> factItems) {
-
 
98
        SQLTable tableCmd = getDirectory().getElement("COMMANDE").getTable();
-
 
99
        SQLTable tableCmdElt = getDirectory().getElement("COMMANDE_ELEMENT").getTable();
-
 
100
        SQLRowValues rowCmd = new SQLRowValues(tableCmd);
-
 
101
 
-
 
102
        final Map<Integer, SQLRowValues> map = new HashMap<Integer, SQLRowValues>();
-
 
103
        for (SQLRowAccessor sqlRow : factItems) {
-
 
104
            // on récupére l'article qui lui correspond
-
 
105
            SQLRow sqlRowFetch = sqlRow.asRow();
-
 
106
            sqlRowFetch.fetchValues();
-
 
107
            if (sqlRowFetch.getObject("ID_ARTICLE") != null && !sqlRowFetch.getForeign("ID_ARTICLE").isUndefined()) {
-
 
108
                int idArt = sqlRowFetch.getForeignID("ID_ARTICLE");
-
 
109
                if (map.containsKey(idArt)) {
-
 
110
                    SQLRowValues rowValsElt = map.get(idArt);
-
 
111
                    rowValsElt.put("QTE", rowValsElt.getInt("QTE") + sqlRowFetch.getInt("QTE"));
-
 
112
                } else {
-
 
113
                    SQLInjector inj = SQLInjector.getInjector(sqlRowFetch.getForeign("ID_ARTICLE").getTable(), tableCmdElt);
-
 
114
                    SQLRowValues rowValsElt = new SQLRowValues(inj.createRowValuesFrom(sqlRowFetch.getForeign("ID_ARTICLE").asRow()));
-
 
115
                    rowValsElt.put("ID_STYLE", sqlRowFetch.getObject("ID_STYLE"));
-
 
116
                    rowValsElt.put("QTE", sqlRowFetch.getObject("QTE"));
-
 
117
                    rowValsElt.put("T_POIDS", sqlRowFetch.getLong("POIDS") * rowValsElt.getInt("QTE"));
-
 
118
                    rowValsElt.put("T_PA_HT", ((BigDecimal) sqlRowFetch.getObject("PA_HT")).multiply(new BigDecimal(rowValsElt.getInt("QTE")), DecimalUtils.HIGH_PRECISION));
-
 
119
                    rowValsElt.put("T_PA_TTC",
-
 
120
                            ((BigDecimal) sqlRowFetch.getObject("T_PA_HT")).multiply(new BigDecimal((sqlRowFetch.getForeign("ID_TAXE").getFloat("TAUX") / 100.0 + 1.0)), DecimalUtils.HIGH_PRECISION));
-
 
121
                    rowValsElt.put("ID_COMMANDE", rowCmd);
-
 
122
                    map.put(idArt, rowValsElt);
-
 
123
                }
-
 
124
            }
-
 
125
 
-
 
126
        }
-
 
127
        return rowCmd;
-
 
128
    }
-
 
129
 
65
    /*
130
    /*
66
     * (non-Javadoc)
131
     * (non-Javadoc)
67
     * 
132
     * 
68
     * @see org.openconcerto.devis.BaseSQLElement#getComboFields()
133
     * @see org.openconcerto.devis.BaseSQLElement#getComboFields()
69
     */
134
     */
Line 264... Line 329...
264
        };
329
        };
265
    }
330
    }
266
 
331
 
267
    @Override
332
    @Override
268
    protected String createCode() {
333
    protected String createCode() {
269
        return createCodeFromPackage() + ".item";
334
        return createCodeOfPackage() + ".item";
270
    }
335
    }
271
}
336
}