OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 156 Rev 174
Line 14... Line 14...
14
 package org.openconcerto.erp.core.supplychain.stock.element;
14
 package org.openconcerto.erp.core.supplychain.stock.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.sales.product.element.ReferenceArticleSQLElement;
18
import org.openconcerto.erp.core.sales.product.element.ReferenceArticleSQLElement;
-
 
19
import org.openconcerto.erp.core.sales.product.element.UniteVenteArticleSQLElement;
19
import org.openconcerto.erp.core.supplychain.order.component.CommandeSQLComponent;
20
import org.openconcerto.erp.core.supplychain.order.component.CommandeSQLComponent;
20
import org.openconcerto.erp.core.supplychain.order.ui.CommandeItemTable;
21
import org.openconcerto.erp.core.supplychain.order.ui.CommandeItemTable;
21
import org.openconcerto.erp.core.supplychain.supplier.component.MouvementStockSQLComponent;
22
import org.openconcerto.erp.core.supplychain.supplier.component.MouvementStockSQLComponent;
22
import org.openconcerto.erp.preferences.GestionArticleGlobalPreferencePanel;
23
import org.openconcerto.erp.preferences.GestionArticleGlobalPreferencePanel;
-
 
24
import org.openconcerto.erp.preferences.GestionCommercialeGlobalPreferencePanel;
23
import org.openconcerto.sql.Configuration;
25
import org.openconcerto.sql.Configuration;
24
import org.openconcerto.sql.element.SQLComponent;
26
import org.openconcerto.sql.element.SQLComponent;
25
import org.openconcerto.sql.element.SQLElement;
27
import org.openconcerto.sql.element.SQLElement;
26
import org.openconcerto.sql.element.TreesOfSQLRows;
28
import org.openconcerto.sql.element.TreesOfSQLRows;
27
import org.openconcerto.sql.model.SQLBackgroundTableCache;
29
import org.openconcerto.sql.model.SQLBackgroundTableCache;
Line 48... Line 50...
48
import java.util.ArrayList;
50
import java.util.ArrayList;
49
import java.util.Collection;
51
import java.util.Collection;
50
import java.util.List;
52
import java.util.List;
51
import java.util.Map.Entry;
53
import java.util.Map.Entry;
52
 
54
 
-
 
55
import javax.swing.JOptionPane;
53
import javax.swing.SwingUtilities;
56
import javax.swing.SwingUtilities;
54
 
57
 
55
public class MouvementStockSQLElement extends ComptaSQLConfElement {
58
public class MouvementStockSQLElement extends ComptaSQLConfElement {
56
 
59
 
57
    public MouvementStockSQLElement() {
60
    public MouvementStockSQLElement() {
Line 244... Line 247...
244
        }
247
        }
245
        return map;
248
        return map;
246
    }
249
    }
247
 
250
 
248
    public static void createCommandeF(final ListMap<SQLRow, SQLRowValues> col, final SQLRow rowDevise) {
251
    public static void createCommandeF(final ListMap<SQLRow, SQLRowValues> col, final SQLRow rowDevise) {
249
        createCommandeF(col, rowDevise, "", true);
252
        createCommandeF(col, rowDevise, "");
250
    }
253
    }
251
 
254
 
252
    public static void createCommandeF(final ListMap<SQLRow, SQLRowValues> col, final SQLRow rowDevise, final String ref, final boolean useCommandeEnCours) {
255
    public static void createCommandeF(final ListMap<SQLRow, SQLRowValues> col, final SQLRow rowDevise, final String ref) {
253
        if (SwingUtilities.isEventDispatchThread()) {
256
        if (SwingUtilities.isEventDispatchThread()) {
254
            throw new IllegalStateException("This method must be called outside of EDT");
257
            throw new IllegalStateException("This method must be called outside of EDT");
255
        }
258
        }
256
        if (col.size() > 0) {
259
        if (col.size() > 0) {
257
 
260
 
258
            final SQLElement commande = Configuration.getInstance().getDirectory().getElement("COMMANDE");
261
            final SQLElement commande = Configuration.getInstance().getDirectory().getElement("COMMANDE");
-
 
262
            Boolean useCommandeEnCours = SQLPreferences.getMemCached(commande.getTable().getDBRoot()).getBoolean(GestionCommercialeGlobalPreferencePanel.COMMANDE_FOURNISSEUR_EN_COURS, false);
259
            for (final Entry<SQLRow, List<SQLRowValues>> e : col.entrySet()) {
263
            for (final Entry<SQLRow, List<SQLRowValues>> e : col.entrySet()) {
260
                final SQLRow fournisseur = e.getKey();
264
                final SQLRow fournisseur = e.getKey();
261
                // On regarde si il existe une commande en cours existante
265
                // On regarde si il existe une commande en cours existante
262
                final SQLSelect sel = new SQLSelect();
266
                final SQLSelect sel = new SQLSelect();
263
                sel.addSelectStar(commande.getTable());
267
                sel.addSelectStar(commande.getTable());
Line 322... Line 326...
322
                                    index = i;
326
                                    index = i;
323
                                    break;
327
                                    break;
324
                                }
328
                                }
325
                            }
329
                            }
326
                            if (rowValsMatch != null) {
330
                            if (rowValsMatch != null) {
-
 
331
 
327
                                final int qte = rowValsMatch.getInt("QTE");
332
                                int qte = rowValsMatch.getInt("QTE");
-
 
333
                                BigDecimal qteUV = rowValsMatch.getBigDecimal("QTE_UNITAIRE");
-
 
334
 
-
 
335
                                if (rowValsMatch.getObject("ID_UNITE_VENTE") != null && rowValsMatch.getForeignID("ID_UNITE_VENTE") != UniteVenteArticleSQLElement.A_LA_PIECE) {
-
 
336
                                    qteUV = qteUV.multiply(new BigDecimal(qte));
-
 
337
                                    int qteElt = rowValsElt.getInt("QTE");
-
 
338
                                    BigDecimal qteUVElt = rowValsElt.getBigDecimal("QTE_UNITAIRE");
-
 
339
                                    qteUV = qteUV.add(qteUVElt.multiply(new BigDecimal(qteElt)));
-
 
340
                                    qte = 1;
-
 
341
                                } else {
-
 
342
                                    qte += rowValsElt.getInt("QTE");
-
 
343
                                }
-
 
344
 
328
                                model.putValue(qte + rowValsElt.getInt("QTE"), index, "QTE");
345
                                model.putValue(qte, index, "QTE");
-
 
346
                                model.putValue(qteUV, index, "QTE_UNITAIRE");
329
                            } else {
347
                            } else {
330
                                model.addRow(rowValsElt);
348
                                model.addRow(rowValsElt);
331
                                if (rowValsElt.getObject("ID_ARTICLE") != null && !rowValsElt.isForeignEmpty("ID_ARTICLE")) {
349
                                if (rowValsElt.getObject("ID_ARTICLE") != null && !rowValsElt.isForeignEmpty("ID_ARTICLE")) {
332
                                    Object o = itemTable.tarifCompletion(rowValsElt.getForeign("ID_ARTICLE").asRow(), "PRIX_METRIQUE_HA_1");
350
                                    Object o = itemTable.tarifCompletion(rowValsElt.getForeign("ID_ARTICLE").asRow(), "PRIX_METRIQUE_HA_1");
333
                                    if (o != null) {
351
                                    if (o != null) {
Line 340... Line 358...
340
                        frame.pack();
358
                        frame.pack();
341
                        FrameUtil.show(frame);
359
                        FrameUtil.show(frame);
342
 
360
 
343
                    }
361
                    }
344
                });
362
                });
-
 
363
            }
-
 
364
        } else {
-
 
365
            SwingUtilities.invokeLater(new Runnable() {
345
 
366
 
-
 
367
                @Override
-
 
368
                public void run() {
-
 
369
                    JOptionPane.showMessageDialog(null, "Aucune commande à passer", "Commande fournisseur", JOptionPane.INFORMATION_MESSAGE);
346
            }
370
                }
347
 
371
 
-
 
372
            });
348
        }
373
        }
349
 
374
 
350
    }
375
    }
351
 
376
 
352
    @Override
377
    @Override