OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 174 Rev 185
Line 1... Line 1...
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
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
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
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.
9
 * language governing permissions and limitations under the License.
Line 23... Line 23...
23
import org.openconcerto.sql.model.SQLRowAccessor;
23
import org.openconcerto.sql.model.SQLRowAccessor;
24
import org.openconcerto.sql.model.SQLRowValues;
24
import org.openconcerto.sql.model.SQLRowValues;
25
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
25
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
26
import org.openconcerto.sql.model.SQLSelect;
26
import org.openconcerto.sql.model.SQLSelect;
27
import org.openconcerto.sql.model.SQLTable;
27
import org.openconcerto.sql.model.SQLTable;
28
import org.openconcerto.sql.model.SQLTableEvent;
-
 
29
import org.openconcerto.sql.model.SQLTableEvent.Mode;
-
 
30
import org.openconcerto.sql.model.Where;
28
import org.openconcerto.sql.model.Where;
31
import org.openconcerto.sql.utils.SQLUtils;
29
import org.openconcerto.sql.utils.SQLUtils;
32
import org.openconcerto.utils.DecimalUtils;
30
import org.openconcerto.utils.DecimalUtils;
33
import org.openconcerto.utils.ExceptionHandler;
31
import org.openconcerto.utils.ExceptionHandler;
34
import org.openconcerto.utils.ListMap;
32
import org.openconcerto.utils.ListMap;
Line 57... Line 55...
57
 
55
 
58
    private final StockLabel label;
56
    private final StockLabel label;
59
    private final List<? extends SQLRowAccessor> items;
57
    private final List<? extends SQLRowAccessor> items;
60
    private final TypeStockUpdate type;
58
    private final TypeStockUpdate type;
61
    private final boolean createMouvementStock;
59
    private final boolean createMouvementStock;
-
 
60
    private boolean clearMouvementStock;
62
    private final SQLRowAccessor rowSource;
61
    private final SQLRowAccessor rowSource;
63
    private boolean resetStockTH = false;
62
    private boolean resetStockTH = false;
64
 
63
 
65
    private boolean headless = false;
64
    private boolean headless = false;
66
 
65
 
Line 98... Line 97...
98
    public StockItemsUpdater(StockLabel label, SQLRowAccessor rowSource, List<? extends SQLRowAccessor> items, TypeStockUpdate t, boolean createMouvementStock) {
97
    public StockItemsUpdater(StockLabel label, SQLRowAccessor rowSource, List<? extends SQLRowAccessor> items, TypeStockUpdate t, boolean createMouvementStock) {
99
        this.label = label;
98
        this.label = label;
100
        this.items = items;
99
        this.items = items;
101
        this.type = t;
100
        this.type = t;
102
        this.createMouvementStock = createMouvementStock;
101
        this.createMouvementStock = createMouvementStock;
-
 
102
        this.clearMouvementStock = createMouvementStock;
103
        this.rowSource = rowSource;
103
        this.rowSource = rowSource;
104
        this.headless = GraphicsEnvironment.isHeadless();
104
        this.headless = GraphicsEnvironment.isHeadless();
105
    }
105
    }
106
 
106
 
107
    public void setHeadless(boolean headless) {
107
    public void setHeadless(boolean headless) {
Line 114... Line 114...
114
        reliquat.add(Tuple3.create(article, qte, qteUnit));
114
        reliquat.add(Tuple3.create(article, qte, qteUnit));
115
    }
115
    }
116
 
116
 
117
    List<String> requests = new ArrayList<String>();
117
    List<String> requests = new ArrayList<String>();
118
 
118
 
-
 
119
    public void setClearMouvementStock(boolean clearMouvementStock) {
-
 
120
        this.clearMouvementStock = clearMouvementStock;
-
 
121
    }
-
 
122
 
119
    public void update() throws SQLException {
123
    public void update() throws SQLException {
120
        final SQLTable stockTable = this.rowSource.getTable().getTable("STOCK");
124
        final SQLTable stockTable = this.rowSource.getTable().getTable("STOCK");
121
 
125
 
122
        if (this.createMouvementStock) {
126
        if (this.clearMouvementStock) {
123
            clearExistingMvt(this.rowSource);
127
            clearExistingMvt(this.rowSource);
124
        }
128
        }
125
 
129
 
126
        // Mise à jour des stocks des articles non composés
130
        // Mise à jour des stocks des articles non composés
127
        List<StockItem> stockItems = fetch();
131
        List<StockItem> stockItems = fetch();
128
 
132
 
129
        final ListMap<SQLRow, SQLRowValues> cmd = new ListMap<SQLRow, SQLRowValues>();
133
        final ListMap<SQLRow, SQLRowValues> cmd = new ListMap<SQLRow, SQLRowValues>();
130
 
134
 
-
 
135
        final List<Integer> updatedIDs = new ArrayList<>();
131
        for (StockItem stockItem : stockItems) {
136
        for (StockItem stockItem : stockItems) {
132
 
137
 
133
            if (stockItem.isStockInit()) {
138
            if (stockItem.isStockInit()) {
134
                requests.add(stockItem.getUpdateRequest());
139
                requests.add(stockItem.getUpdateRequest());
-
 
140
                updatedIDs.add(stockItem.getStockID());
135
            } else {
141
            } else {
136
                SQLRowValues rowVals = new SQLRowValues(stockTable);
142
                SQLRowValues rowVals = new SQLRowValues(stockTable);
137
                rowVals.put("QTE_REEL", stockItem.getRealQty());
143
                rowVals.put("QTE_REEL", stockItem.getRealQty());
138
                rowVals.put("QTE_TH", stockItem.getVirtualQty());
144
                rowVals.put("QTE_TH", stockItem.getVirtualQty());
139
                rowVals.put("QTE_LIV_ATTENTE", stockItem.getDeliverQty());
145
                rowVals.put("QTE_LIV_ATTENTE", stockItem.getDeliverQty());
Line 159... Line 165...
159
        try {
165
        try {
160
            SQLUtils.executeAtomic(stockTable.getDBSystemRoot().getDataSource(), new ConnectionHandlerNoSetup<Object, IOException>() {
166
            SQLUtils.executeAtomic(stockTable.getDBSystemRoot().getDataSource(), new ConnectionHandlerNoSetup<Object, IOException>() {
161
                @Override
167
                @Override
162
                public Object handle(SQLDataSource ds) throws SQLException, IOException {
168
                public Object handle(SQLDataSource ds) throws SQLException, IOException {
163
                    SQLUtils.executeMultiple(stockTable.getDBSystemRoot(), requests, handlers);
169
                    SQLUtils.executeMultiple(stockTable.getDBSystemRoot(), requests, handlers);
-
 
170
 
164
                    // FIXME FIRE ONLY CHANGED ROWS
171
                    if (!updatedIDs.isEmpty()) {
-
 
172
                        if (updatedIDs.size() <= 60) {
-
 
173
                            for (int idUpdated : updatedIDs) {
165
                    stockTable.fire(new SQLTableEvent(stockTable, SQLRow.NONEXISTANT_ID, Mode.ROW_UPDATED));
174
                                stockTable.fireTableModified(idUpdated);
-
 
175
                            }
-
 
176
                        } else {
-
 
177
                            stockTable.fireTableModified();
-
 
178
                        }
-
 
179
                    }
166
                    return null;
180
                    return null;
167
                }
181
                }
168
            });
182
            });
169
        } catch (IOException e) {
183
        } catch (IOException e) {
170
            ExceptionHandler.handle("Erreur de la mise à jour des stocks!", e);
184
            ExceptionHandler.handle("Erreur de la mise à jour des stocks!", e);