OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 142 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 142 Rev 156
Line 24... Line 24...
24
import org.openconcerto.sql.element.SQLElementLinksSetup;
24
import org.openconcerto.sql.element.SQLElementLinksSetup;
25
import org.openconcerto.sql.element.TreesOfSQLRows;
25
import org.openconcerto.sql.element.TreesOfSQLRows;
26
import org.openconcerto.sql.model.AliasedTable;
26
import org.openconcerto.sql.model.AliasedTable;
27
import org.openconcerto.sql.model.SQLName;
27
import org.openconcerto.sql.model.SQLName;
28
import org.openconcerto.sql.model.SQLRow;
28
import org.openconcerto.sql.model.SQLRow;
-
 
29
import org.openconcerto.sql.model.SQLRowAccessor;
29
import org.openconcerto.sql.model.SQLSelect;
30
import org.openconcerto.sql.model.SQLSelect;
30
import org.openconcerto.sql.model.SQLTable;
31
import org.openconcerto.sql.model.SQLTable;
31
import org.openconcerto.sql.model.Where;
32
import org.openconcerto.sql.model.Where;
32
import org.openconcerto.sql.preferences.SQLPreferences;
33
import org.openconcerto.sql.preferences.SQLPreferences;
33
import org.openconcerto.sql.request.UpdateBuilder;
34
import org.openconcerto.sql.request.UpdateBuilder;
-
 
35
import org.openconcerto.sql.view.EditFrame;
-
 
36
import org.openconcerto.sql.view.EditPanel;
-
 
37
import org.openconcerto.sql.view.list.IListe;
-
 
38
import org.openconcerto.sql.view.list.RowAction;
34
import org.openconcerto.ui.preferences.DefaultProps;
39
import org.openconcerto.ui.preferences.DefaultProps;
35
import org.openconcerto.utils.ListMap;
40
import org.openconcerto.utils.ListMap;
36
 
41
 
-
 
42
import java.awt.event.ActionEvent;
37
import java.sql.SQLException;
43
import java.sql.SQLException;
38
import java.util.ArrayList;
44
import java.util.ArrayList;
39
import java.util.List;
45
import java.util.List;
40
 
46
 
-
 
47
import javax.swing.AbstractAction;
-
 
48
 
41
import org.apache.commons.dbutils.handlers.ArrayListHandler;
49
import org.apache.commons.dbutils.handlers.ArrayListHandler;
42
 
50
 
43
public class BonDeLivraisonSQLElement extends ComptaSQLConfElement {
51
public class BonDeLivraisonSQLElement extends ComptaSQLConfElement {
44
 
52
 
45
    // TODO afficher uniquement les factures non livrees dans la combo
53
    // TODO afficher uniquement les factures non livrees dans la combo
Line 48... Line 56...
48
    public BonDeLivraisonSQLElement(String single, String plural) {
56
    public BonDeLivraisonSQLElement(String single, String plural) {
49
        super("BON_DE_LIVRAISON", single, plural);
57
        super("BON_DE_LIVRAISON", single, plural);
50
    }
58
    }
51
 
59
 
52
    public BonDeLivraisonSQLElement() {
60
    public BonDeLivraisonSQLElement() {
53
        this("un bon de livraison", "Bons de livraison");
61
        this("un bon de livraison", "bons de livraison");
54
    }
62
    }
55
 
63
 
56
    @Override
64
    @Override
57
    protected void setupLinks(SQLElementLinksSetup links) {
65
    protected void setupLinks(SQLElementLinksSetup links) {
58
        super.setupLinks(links);
66
        super.setupLinks(links);
Line 62... Line 70...
62
        if (getTable().contains("ID_ADRESSE_LIVRAISON")) {
70
        if (getTable().contains("ID_ADRESSE_LIVRAISON")) {
63
            links.get("ID_ADRESSE_LIVRAISON").setType(LinkType.ASSOCIATION);
71
            links.get("ID_ADRESSE_LIVRAISON").setType(LinkType.ASSOCIATION);
64
        }
72
        }
65
    }
73
    }
66
 
74
 
-
 
75
    @Override
67
    protected List<String> getListFields() {
76
    protected List<String> getListFields() {
68
        final List<String> l = new ArrayList<String>();
77
        final List<String> l = new ArrayList<>();
69
        l.add("NUMERO");
78
        l.add("NUMERO");
70
        l.add("DATE");
79
        l.add("DATE");
71
        l.add("ID_CLIENT");
80
        l.add("ID_CLIENT");
72
        DefaultProps props = DefaultNXProps.getInstance();
81
        DefaultProps props = DefaultNXProps.getInstance();
73
        Boolean b = props.getBooleanValue("ArticleShowPoids");
82
        Boolean b = props.getBooleanValue("ArticleShowPoids");
Line 78... Line 87...
78
        l.add("TOTAL_HT");
87
        l.add("TOTAL_HT");
79
        l.add("INFOS");
88
        l.add("INFOS");
80
        return l;
89
        return l;
81
    }
90
    }
82
 
91
 
-
 
92
    @Override
83
    protected List<String> getComboFields() {
93
    protected List<String> getComboFields() {
84
        final List<String> l = new ArrayList<String>();
94
        final List<String> l = new ArrayList<>(2);
85
        l.add("NUMERO");
95
        l.add("NUMERO");
86
        l.add("DATE");
96
        l.add("DATE");
87
        return l;
97
        return l;
88
    }
98
    }
89
 
99
 
Line 99... Line 109...
99
     */
109
     */
100
    public SQLComponent createComponent() {
110
    public SQLComponent createComponent() {
101
        return new BonDeLivraisonSQLComponent();
111
        return new BonDeLivraisonSQLComponent();
102
    }
112
    }
103
 
113
 
104
    public List<Object> getCmdClientFrom(int blOrigin) {
114
    public List<Object> getSourceTrRowsFrom(int blOrigin, String tableSourceItems, String tableSourceRoot) {
105
        SQLTable tableBLElement = getTable().getTable("BON_DE_LIVRAISON_ELEMENT");
115
        SQLTable tableBLElement = getTable().getTable("BON_DE_LIVRAISON_ELEMENT");
106
        SQLTable tableCmdElement = getTable().getTable("COMMANDE_CLIENT_ELEMENT");
116
        SQLTable tableCmdElement = getTable().getTable(tableSourceItems);
-
 
117
        String idRoot = "c2.\"" + getTable().getTable(tableSourceRoot).getKey().getFieldName() + "\"";
107
        String up = "SELECT DISTINCT c2.\"ID_COMMANDE_CLIENT\" FROm " + new SQLName(tableBLElement.getDBRoot().getName(), tableBLElement.getName()).quote() + " b2, "
118
        String up = "SELECT DISTINCT c2.\"ID_" + tableSourceRoot + "\" FROm " + new SQLName(tableBLElement.getDBRoot().getName(), tableBLElement.getName()).quote() + " b2, "
108
                + new SQLName(tableCmdElement.getDBRoot().getName(), tableCmdElement.getName()).quote() + " c2 WHERE b2.\"ID_BON_DE_LIVRAISON\"=" + blOrigin
119
                + new SQLName(tableCmdElement.getDBRoot().getName(), tableCmdElement.getName()).quote() + " c2 WHERE b2.\"ID_BON_DE_LIVRAISON\"=" + blOrigin
109
                + " AND c2.\"ARCHIVE\"=0 AND b2.\"ARCHIVE\"=0 AND c2.\"ID\">1 AND b2.\"ID\">1 AND b2.\"ID_COMMANDE_CLIENT_ELEMENT\"=c2.\"ID\"";
120
                + " AND c2.\"ARCHIVE\"=0 AND b2.\"ARCHIVE\"=0 AND " + idRoot + ">1 AND b2.\"ID\">1 AND b2.\"ID_" + tableSourceItems + "\"=" + idRoot;
110
        List<Object> cmds = getTable().getDBSystemRoot().getDataSource().executeCol(up);
121
        return getTable().getDBSystemRoot().getDataSource().executeCol(up);
111
        return cmds;
-
 
112
    }
122
    }
113
 
123
 
114
    public void updateCmdClientElement(List<Object> cmds, int idblOrigin) {
124
    public void updateQteLivree(List<Object> items, String tableItems, String tableRoot) {
-
 
125
        if (items != null && !items.isEmpty()) {
115
        SQLTable tableBLElement = getTable().getTable("BON_DE_LIVRAISON_ELEMENT");
126
            SQLTable tableBLElement = getTable().getTable("BON_DE_LIVRAISON_ELEMENT");
116
        SQLTable tableCmdElement = getTable().getTable("COMMANDE_CLIENT_ELEMENT");
127
            SQLTable tableCmdElement = getTable().getTable(tableItems);
-
 
128
            String itemsKey = "c.\"" + getTable().getTable(tableItems).getKey().getName() + "\"";
117
        UpdateBuilder build = new UpdateBuilder(tableCmdElement);
129
            UpdateBuilder build = new UpdateBuilder(tableCmdElement);
118
        build.set("QTE_LIVREE", "(SELECT SUM(b.\"QTE_LIVREE\" * b.\"QTE_UNITAIRE\") from " + new SQLName(tableBLElement.getDBRoot().getName(), tableBLElement.getName()).quote()
130
            build.set("QTE_LIVREE", "(SELECT SUM(b.\"QTE_LIVREE\" * b.\"QTE_UNITAIRE\") from " + new SQLName(tableBLElement.getDBRoot().getName(), tableBLElement.getName()).quote() + " b where "
119
                + " b where c.\"ID\"=b.\"ID_COMMANDE_CLIENT_ELEMENT\" AND c.\"ID\">1 AND c.\"ARCHIVE\"=0 AND b.\"ID\">1 AND b.\"ARCHIVE\"=0 )");
131
                    + itemsKey + "=b.\"ID_" + tableItems + "\" AND " + itemsKey + ">1 AND c.\"ARCHIVE\"=0 AND b.\"ID\">1 AND b.\"ARCHIVE\"=0 )");
120
        AliasedTable alias = new AliasedTable(tableCmdElement, "c");
132
            AliasedTable alias = new AliasedTable(tableCmdElement, "c");
121
        build.setWhere(new Where(alias.getField("ID_COMMANDE_CLIENT"), cmds));
133
            build.setWhere(new Where(alias.getField("ID_" + tableRoot), items));
122
 
134
 
123
        getTable().getDBSystemRoot().getDataSource().execute(build.asString().replaceAll(" SET", " c SET "));
135
            getTable().getDBSystemRoot().getDataSource().execute(build.asString().replaceAll(" SET", " c SET "));
124
    }
136
        }
-
 
137
    }
125
 
138
 
126
    @Override
139
    @Override
127
    protected void archive(TreesOfSQLRows trees, boolean cutLinks) throws SQLException {
140
    protected void archive(TreesOfSQLRows trees, boolean cutLinks) throws SQLException {
128
 
141
 
129
        List<Object> cmds = null;
142
        List<Object> cmds = new ArrayList<>();
-
 
143
        List<Object> devis = new ArrayList<>();
130
        List<Integer> ids = new ArrayList<Integer>();
144
        List<Integer> ids = new ArrayList<>();
131
        for (SQLRow row : trees.getRows()) {
145
        for (SQLRow row : trees.getRows()) {
132
 
146
 
133
            SQLPreferences prefs = new SQLPreferences(getTable().getDBRoot());
147
            SQLPreferences prefs = new SQLPreferences(getTable().getDBRoot());
134
 
148
 
-
 
149
            cmds.addAll(getSourceTrRowsFrom(row.getID(), "COMMANDE_CLIENT_ELEMENT", "COMMANDE_CLIENT"));
135
            cmds = getCmdClientFrom(row.getID());
150
            devis.addAll(getSourceTrRowsFrom(row.getID(), "DEVIS_ELEMENT", "DEVIS"));
136
            ids.add(row.getID());
151
            ids.add(row.getID());
137
            if (!prefs.getBoolean(GestionArticleGlobalPreferencePanel.STOCK_FACT, true)) {
152
            if (!prefs.getBoolean(GestionArticleGlobalPreferencePanel.STOCK_FACT, true)) {
138
 
153
 
139
                // Mise à jour des stocks
154
                // Mise à jour des stocks
140
                SQLElement eltMvtStock = Configuration.getInstance().getDirectory().getElement("MOUVEMENT_STOCK");
155
                SQLElement eltMvtStock = Configuration.getInstance().getDirectory().getElement("MOUVEMENT_STOCK");
Line 153... Line 168...
153
                    }
168
                    }
154
                }
169
                }
155
            }
170
            }
156
        }
171
        }
157
        super.archive(trees, cutLinks);
172
        super.archive(trees, cutLinks);
158
        for (Integer id : ids) {
-
 
159
 
173
 
-
 
174
        updateQteLivree(devis, "DEVIS_ELEMENT", "DEVIS");
-
 
175
        updateQteLivree(cmds, "COMMANDE_CLIENT_ELEMENT", "COMMANDE_CLIENT");
-
 
176
 
-
 
177
    }
-
 
178
 
-
 
179
    public RowAction getCloneAction() {
-
 
180
        return new RowAction(new AbstractAction() {
-
 
181
 
-
 
182
            public void actionPerformed(ActionEvent e) {
-
 
183
                SQLRowAccessor selectedRow = IListe.get(e).getSelectedRow();
-
 
184
 
-
 
185
                EditFrame editFrame = new EditFrame(BonDeLivraisonSQLElement.this, EditPanel.CREATION);
-
 
186
 
-
 
187
                ((BonDeLivraisonSQLComponent) editFrame.getSQLComponent()).duplicate(selectedRow.getID());
160
            updateCmdClientElement(cmds, id);
188
                editFrame.setVisible(true);
-
 
189
            }
-
 
190
        }, true, "sales.quote.clone") {
-
 
191
            @Override
-
 
192
            public boolean enabledFor(java.util.List<org.openconcerto.sql.model.SQLRowValues> selection) {
-
 
193
                return (selection != null && selection.size() == 1);
161
        }
194
            }
-
 
195
        };
162
    }
196
    }
-
 
197
 
-
 
198
    @Override
-
 
199
    protected String createCodeSuffix() {
-
 
200
        return ".delivery.note";
-
 
201
    }
-
 
202
 
163
}
203
}