OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 182 Rev 185
Line 12... Line 12...
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.erp.core.supplychain.stock.element;
14
 package org.openconcerto.erp.core.supplychain.stock.element;
15
 
15
 
16
import org.openconcerto.sql.model.DBRoot;
16
import org.openconcerto.sql.model.DBRoot;
-
 
17
import org.openconcerto.sql.model.SQLInsert;
17
import org.openconcerto.sql.model.SQLRow;
18
import org.openconcerto.sql.model.SQLRow;
18
import org.openconcerto.sql.model.SQLRowAccessor;
19
import org.openconcerto.sql.model.SQLRowAccessor;
19
import org.openconcerto.sql.model.SQLRowListRSH;
20
import org.openconcerto.sql.model.SQLRowListRSH;
20
import org.openconcerto.sql.model.SQLRowValues;
21
import org.openconcerto.sql.model.SQLRowValues;
21
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
22
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
Line 26... Line 27...
26
import org.openconcerto.utils.ExceptionHandler;
27
import org.openconcerto.utils.ExceptionHandler;
27
import org.openconcerto.utils.cc.ITransformer;
28
import org.openconcerto.utils.cc.ITransformer;
28
 
29
 
29
import java.math.BigDecimal;
30
import java.math.BigDecimal;
30
import java.sql.SQLException;
31
import java.sql.SQLException;
-
 
32
import java.util.ArrayList;
-
 
33
import java.util.Arrays;
31
import java.util.Date;
34
import java.util.Date;
32
import java.util.HashMap;
35
import java.util.HashMap;
33
import java.util.List;
36
import java.util.List;
34
import java.util.Map;
37
import java.util.Map;
35
 
38
 
Line 45... Line 48...
45
        this.depot = depot;
48
        this.depot = depot;
46
        this.root = root;
49
        this.root = root;
47
        this.withAllProducts = withAllProducts;
50
        this.withAllProducts = withAllProducts;
48
    }
51
    }
49
 
52
 
50
    public void create() {
53
    public int create() {
51
        // Récupération des inventaires
54
        // Récupération des inventaires
52
        SQLTable tableEtatStock = this.root.getTable("ETAT_STOCK");
55
        SQLTable tableEtatStock = this.root.getTable("ETAT_STOCK");
53
        SQLSelect sel = new SQLSelect();
56
        SQLSelect sel = new SQLSelect();
54
        sel.addSelectStar(tableEtatStock);
57
        sel.addSelectStar(tableEtatStock);
55
        Where wEtat = new Where(tableEtatStock.getField("INVENTAIRE"), "=", Boolean.TRUE);
58
        Where wEtat = new Where(tableEtatStock.getField("INVENTAIRE"), "=", Boolean.TRUE);
Line 81... Line 84...
81
 
84
 
82
            vals.put("QTE", null);
85
            vals.put("QTE", null);
83
            if (tableMvtStock.contains("PRICE")) {
86
            if (tableMvtStock.contains("PRICE")) {
84
                vals.put("PRICE", null);
87
                vals.put("PRICE", null);
85
            }
88
            }
86
            vals.put("ID_ARTICLE", null);
89
            vals.putRowValues("ID_ARTICLE").putNulls("CODE", "NOM");
87
            vals.putRowValues("ID_STOCK").putNulls("QTE_REEL").putRowValues("ID_DEPOT_STOCK").putNulls("ID", "NOM", "CODE");
90
            vals.putRowValues("ID_STOCK").putNulls("QTE_REEL").putRowValues("ID_DEPOT_STOCK").putNulls("ID", "NOM", "CODE");
88
 
91
 
89
            // Calendar cal0116 = Calendar.getInstance();
92
            // Calendar cal0116 = Calendar.getInstance();
90
            // cal0116.set(2016, Calendar.JANUARY, 1, 0, 0, 0);
93
            // cal0116.set(2016, Calendar.JANUARY, 1, 0, 0, 0);
91
            // final Date dateDeb = cal0116.getTime();
94
            // final Date dateDeb = cal0116.getTime();
Line 209... Line 212...
209
                    }
212
                    }
210
                }
213
                }
211
 
214
 
212
            }
215
            }
213
 
216
 
214
            SQLRowValues rowVals = new SQLRowValues(tableEtatStock);
217
            SQLInsert insertEtat = new SQLInsert();
215
            rowVals.put("DATE", d);
218
            insertEtat.add(tableEtatStock.getField("DATE"), d);
216
            rowVals.put("MONTANT_HA", totalHT);
219
            insertEtat.add(tableEtatStock.getField("MONTANT_HA"), totalHT);
217
            rowVals.put("ID_DEPOT_STOCK", depot.getID());
220
            insertEtat.add(tableEtatStock.getField("ID_DEPOT_STOCK"), depot.getID());
218
 
221
 
-
 
222
            try {
-
 
223
                int idEtat = SQLInsert.executeSimilarInserts(tableEtatStock.getDBSystemRoot(), Arrays.asList(insertEtat), true).get(0).intValue();
-
 
224
 
-
 
225
                List<SQLInsert> inserts = new ArrayList<SQLInsert>();
-
 
226
                final SQLTable tableElt = tableEtatStock.getTable("ETAT_STOCK_ELEMENT");
219
            for (EtatStock etatItem : mapStockSnap.values()) {
227
                for (EtatStock etatItem : mapStockSnap.values()) {
220
                SQLRowValues rowValsItem = new SQLRowValues(tableEtatStock.getTable("ETAT_STOCK_ELEMENT"));
228
                    SQLInsert insertItem = new SQLInsert();
221
                rowValsItem.put("ID_ETAT_STOCK", rowVals);
229
                    insertItem.add(tableElt.getField("ID_ETAT_STOCK"), idEtat);
222
                rowValsItem.put("PA", etatItem.getPa());
230
                    insertItem.add(tableElt.getField("PA"), etatItem.getPa());
223
                rowValsItem.put("PV", etatItem.getPv());
231
                    insertItem.add(tableElt.getField("PV"), etatItem.getPv());
224
                rowValsItem.put("QTE", etatItem.getQte());
232
                    insertItem.add(tableElt.getField("QTE"), etatItem.getQte());
225
                rowValsItem.put("T_PA", etatItem.getTotalPA());
233
                    insertItem.add(tableElt.getField("T_PA"), etatItem.getTotalPA());
226
                rowValsItem.put("T_PV", etatItem.getTotalPV());
234
                    insertItem.add(tableElt.getField("T_PV"), etatItem.getTotalPV());
227
                rowValsItem.put("CODE", etatItem.getArticle().getString("CODE"));
235
                    insertItem.add(tableElt.getField("CODE"), etatItem.getArticle().getString("CODE"));
228
                rowValsItem.put("NOM", etatItem.getArticle().getString("NOM"));
236
                    insertItem.add(tableElt.getField("NOM"), etatItem.getArticle().getString("NOM"));
229
                rowValsItem.put("ID_ARTICLE", etatItem.getArticle().getID());
237
                    insertItem.add(tableElt.getField("ID_ARTICLE"), etatItem.getArticle().getID());
-
 
238
                    inserts.add(insertItem);
-
 
239
                }
-
 
240
                if (!inserts.isEmpty()) {
-
 
241
                    // TODO voir avec Guillaume si il faut spliter par tranche de 1000
-
 
242
                    SQLInsert.executeSimilarInserts(tableElt.getDBSystemRoot(), inserts, false);
230
            }
243
                }
231
            try {
-
 
232
                rowVals.commit();
244
                return idEtat;
233
            } catch (SQLException e) {
245
            } catch (SQLException e) {
234
                ExceptionHandler.handle("Erreur lors de la création de l'état", e);
246
                ExceptionHandler.handle("Erreur lors de la création de l'état", e);
-
 
247
                return SQLRow.NONEXISTANT_ID;
235
            }
248
            }
236
        }
249
        }
237
    }
250
    }
238
 
251
 
239
}
252
}