OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 180 Rev 182
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 47... Line 47...
47
import org.openconcerto.erp.preferences.ModeReglementDefautPrefPanel;
47
import org.openconcerto.erp.preferences.ModeReglementDefautPrefPanel;
48
import org.openconcerto.sql.Configuration;
48
import org.openconcerto.sql.Configuration;
49
import org.openconcerto.sql.element.ElementSQLObject;
49
import org.openconcerto.sql.element.ElementSQLObject;
50
import org.openconcerto.sql.element.SQLComponent;
50
import org.openconcerto.sql.element.SQLComponent;
51
import org.openconcerto.sql.element.SQLElement;
51
import org.openconcerto.sql.element.SQLElement;
-
 
52
import org.openconcerto.sql.element.SQLComponent.Mode;
52
import org.openconcerto.sql.model.SQLBackgroundTableCache;
53
import org.openconcerto.sql.model.SQLBackgroundTableCache;
53
import org.openconcerto.sql.model.SQLBase;
54
import org.openconcerto.sql.model.SQLBase;
54
import org.openconcerto.sql.model.SQLInjector;
55
import org.openconcerto.sql.model.SQLInjector;
55
import org.openconcerto.sql.model.SQLRow;
56
import org.openconcerto.sql.model.SQLRow;
56
import org.openconcerto.sql.model.SQLRowAccessor;
57
import org.openconcerto.sql.model.SQLRowAccessor;
Line 62... Line 63...
62
import org.openconcerto.sql.preferences.SQLPreferences;
63
import org.openconcerto.sql.preferences.SQLPreferences;
63
import org.openconcerto.sql.sqlobject.ElementComboBox;
64
import org.openconcerto.sql.sqlobject.ElementComboBox;
64
import org.openconcerto.sql.sqlobject.JUniqueTextField;
65
import org.openconcerto.sql.sqlobject.JUniqueTextField;
65
import org.openconcerto.sql.sqlobject.SQLRequestComboBox;
66
import org.openconcerto.sql.sqlobject.SQLRequestComboBox;
66
import org.openconcerto.sql.sqlobject.SQLTextCombo;
67
import org.openconcerto.sql.sqlobject.SQLTextCombo;
-
 
68
import org.openconcerto.sql.sqlobject.itemview.SimpleRowItemView;
67
import org.openconcerto.sql.users.UserManager;
69
import org.openconcerto.sql.users.UserManager;
68
import org.openconcerto.sql.users.rights.UserRightsManager;
70
import org.openconcerto.sql.users.rights.UserRightsManager;
69
import org.openconcerto.sql.view.EditFrame;
71
import org.openconcerto.sql.view.EditFrame;
70
import org.openconcerto.sql.view.EditPanel.EditMode;
72
import org.openconcerto.sql.view.EditPanel.EditMode;
71
import org.openconcerto.sql.view.list.RowValuesTable;
73
import org.openconcerto.sql.view.list.RowValuesTable;
Line 74... Line 76...
74
import org.openconcerto.ui.FormLayouter;
76
import org.openconcerto.ui.FormLayouter;
75
import org.openconcerto.ui.JDate;
77
import org.openconcerto.ui.JDate;
76
import org.openconcerto.ui.TitledSeparator;
78
import org.openconcerto.ui.TitledSeparator;
77
import org.openconcerto.ui.component.ITextArea;
79
import org.openconcerto.ui.component.ITextArea;
78
import org.openconcerto.ui.component.InteractionMode;
80
import org.openconcerto.ui.component.InteractionMode;
-
 
81
import org.openconcerto.ui.valuewrapper.ValidatedValueWrapper;
79
import org.openconcerto.utils.ExceptionHandler;
82
import org.openconcerto.utils.ExceptionHandler;
80
import org.openconcerto.utils.GestionDevise;
83
import org.openconcerto.utils.GestionDevise;
81
import org.openconcerto.utils.cc.IFactory;
84
import org.openconcerto.utils.cc.IFactory;
-
 
85
import org.openconcerto.utils.cc.ITransformer;
-
 
86
import org.openconcerto.utils.checks.ValidState;
82
import org.openconcerto.utils.text.SimpleDocumentListener;
87
import org.openconcerto.utils.text.SimpleDocumentListener;
83
 
88
 
84
import java.awt.GridBagConstraints;
89
import java.awt.GridBagConstraints;
85
import java.awt.GridBagLayout;
90
import java.awt.GridBagLayout;
86
import java.awt.event.ActionEvent;
91
import java.awt.event.ActionEvent;
Line 358... Line 363...
358
        this.add(new JLabel(getLabelFor("ID_CLIENT"), SwingConstants.RIGHT), c);
363
        this.add(new JLabel(getLabelFor("ID_CLIENT"), SwingConstants.RIGHT), c);
359
 
364
 
360
        c.gridx++;
365
        c.gridx++;
361
        c.weightx = 1;
366
        c.weightx = 1;
362
        c.fill = GridBagConstraints.NONE;
367
        c.fill = GridBagConstraints.NONE;
-
 
368
        final ValidatedValueWrapper<Integer> clientValidatedValueWrapper = ValidatedValueWrapper.add(new ElementComboBox(), new ITransformer<Integer, ValidState>() {
-
 
369
            @Override
-
 
370
            public ValidState transformChecked(Integer t) {
-
 
371
                ElementComboBox boxClient = (ElementComboBox) getView("ID_CLIENT").getComp();
-
 
372
                if (getMode() == Mode.INSERTION && boxClient != null && !boxClient.isEmpty() && boxClient.getSelectedRow().getBoolean("BLOQUE")) {
-
 
373
                    return ValidState.create(false, "Les intéractions avec ce client sont verrouillées.");
-
 
374
                } else {
-
 
375
                    return ValidState.getTrueInstance();
-
 
376
                }
-
 
377
            }
-
 
378
        });
363
        this.comboClient = new ElementComboBox();
379
        this.comboClient = (ElementComboBox) clientValidatedValueWrapper.getComp();
-
 
380
        addView(new SimpleRowItemView<Integer>(clientValidatedValueWrapper), "ID_CLIENT", REQ);
364
 
381
 
365
        this.add(this.comboClient, c);
382
        this.add(this.comboClient, c);
366
        this.addRequiredSQLObject(this.comboClient, "ID_CLIENT");
-
 
367
 
383
 
368
        if (this.displayDpt) {
384
        if (this.displayDpt) {
369
            c.gridx++;
385
            c.gridx++;
370
            c.gridwidth = 1;
386
            c.gridwidth = 1;
371
            final JLabel labelDpt = new JLabel(getLabelFor("ID_CLIENT_DEPARTEMENT"));
387
            final JLabel labelDpt = new JLabel(getLabelFor("ID_CLIENT_DEPARTEMENT"));
Line 1022... Line 1038...
1022
                            if (row.getFields().contains("ID_COMPTE_PCE_PRODUIT") && !row.isForeignEmpty("ID_COMPTE_PCE_PRODUIT")) {
1038
                            if (row.getFields().contains("ID_COMPTE_PCE_PRODUIT") && !row.isForeignEmpty("ID_COMPTE_PCE_PRODUIT")) {
1023
                                totalTTC.setDefaultCompteProduit(row.getForeign("ID_COMPTE_PCE_PRODUIT"));
1039
                                totalTTC.setDefaultCompteProduit(row.getForeign("ID_COMPTE_PCE_PRODUIT"));
1024
                            }
1040
                            }
1025
                        }
1041
                        }
1026
                    if (row != null) {
1042
                    if (row != null) {
-
 
1043
                        String alerte = row.getString("ALERTE");
-
 
1044
                        if (!isFilling() && alerte != null && alerte.trim().length() > 0) {
-
 
1045
                            JOptionPane.showMessageDialog(comboClient, alerte);
-
 
1046
                        }
1027
                        if (SaisieVenteFactureSQLComponent.this.contact != null) {
1047
                        if (SaisieVenteFactureSQLComponent.this.contact != null) {
1028
                            Where w = new Where(SaisieVenteFactureSQLComponent.this.eltContact.getTable().getField("ID_CLIENT"), "=", SQLRow.NONEXISTANT_ID);
1048
                            Where w = new Where(SaisieVenteFactureSQLComponent.this.eltContact.getTable().getField("ID_CLIENT"), "=", SQLRow.NONEXISTANT_ID);
1029
                                w = w.or(new Where(SaisieVenteFactureSQLComponent.this.eltContact.getTable().getField("ID_CLIENT"), "=", id));
1049
                                w = w.or(new Where(SaisieVenteFactureSQLComponent.this.eltContact.getTable().getField("ID_CLIENT"), "=", id));
1030
                            SaisieVenteFactureSQLComponent.this.contact.getRequest().setWhere(w);
1050
                            SaisieVenteFactureSQLComponent.this.contact.getRequest().setWhere(w);
1031
                        }
1051
                        }
Line 1448... Line 1468...
1448
 
1468
 
1449
 
1469
 
1450
                int idMvt = -1;
1470
                int idMvt = -1;
1451
                if (!this.checkPrevisionnelle.isSelected()) {
1471
                if (!this.checkPrevisionnelle.isSelected()) {
1452
                    if (getMode() == Mode.MODIFICATION) {
1472
                    if (getMode() == Mode.MODIFICATION) {
-
 
1473
                        if (!rowFacture.isForeignEmpty("ID_MOUVEMENT")) {
1453
                        idMvt = rowFacture.getInt("ID_MOUVEMENT");
1474
                            idMvt = rowFacture.getInt("ID_MOUVEMENT");
1454
                        // on supprime tout ce qui est lié à la facture
1475
                            // on supprime tout ce qui est lié à la facture
1455
                        System.err.println("Archivage des fils");
1476
                            System.err.println("Archivage des fils");
1456
                        EcritureSQLElement eltEcr = (EcritureSQLElement) Configuration.getInstance().getDirectory().getElement("ECRITURE");
1477
                            EcritureSQLElement eltEcr = (EcritureSQLElement) Configuration.getInstance().getDirectory().getElement("ECRITURE");
1457
                        eltEcr.archiveMouvementProfondeur(idMvt, false);
1478
                            eltEcr.archiveMouvementProfondeur(idMvt, false);
1458
                    }
1479
                        }
-
 
1480
                    }
1459
 
1481
 
1460
                    System.err.println("Regeneration des ecritures");
1482
                    System.err.println("Regeneration des ecritures");
1461
                    if (idMvt > 1) {
1483
                    if (idMvt > 1) {
1462
                        new GenerationMvtSaisieVenteFacture(idSaisieVF, idMvt);
1484
                        new GenerationMvtSaisieVenteFacture(idSaisieVF, idMvt);
1463
                    } else {
1485
                    } else {
Line 1552... Line 1574...
1552
        // generation du document
1574
        // generation du document
1553
        final VenteFactureXmlSheet sheet = new VenteFactureXmlSheet(row);
1575
        final VenteFactureXmlSheet sheet = new VenteFactureXmlSheet(row);
1554
 
1576
 
1555
        try {
1577
        try {
1556
            sheet.createDocumentAsynchronous();
1578
            sheet.createDocumentAsynchronous();
1557
            sheet.showPrintAndExportAsynchronous(panelOO.isVisualisationSelected(), panelOO.isImpressionSelected(), true);
1579
            sheet.showPrintAndExportAsynchronous(panelOO.isVisualisationSelected(), panelOO.isImpressionSelected(), true, getElement(), row);
1558
        } catch (Exception e) {
1580
        } catch (Exception e) {
1559
            ExceptionHandler.handle("Impossible de générer la facture", e);
1581
            ExceptionHandler.handle("Impossible de générer la facture", e);
1560
        }
1582
        }
1561
    }
1583
    }
1562
 
1584
 
Line 1621... Line 1643...
1621
 
1643
 
1622
            for (SQLRow rowElt : myListItem) {
1644
            for (SQLRow rowElt : myListItem) {
1623
 
1645
 
1624
                SQLRowValues rowVals = rowElt.createUpdateRow();
1646
                SQLRowValues rowVals = rowElt.createUpdateRow();
1625
                rowVals.clearPrimaryKeys();
1647
                rowVals.clearPrimaryKeys();
1626
                this.tableFacture.getModel().addRow(rowVals);
1648
                this.tableFacture.getModel().addRow(rowVals, false);
1627
                int rowIndex = this.tableFacture.getModel().getRowCount() - 1;
1649
                int rowIndex = this.tableFacture.getModel().getRowCount() - 1;
1628
                this.tableFacture.getModel().fireTableModelModified(rowIndex);
1650
                this.tableFacture.getModel().fireTableModelModified(rowIndex);
1629
            }
1651
            }
1630
        } else {
1652
        } else {
1631
            this.tableFacture.getModel().clearRows();
1653
            this.tableFacture.getModel().clearRows();
Line 1685... Line 1707...
1685
                    rowValsCCIP.put("ID_SAISIE_VENTE_FACTURE_ELEMENT", rowVals);
1707
                    rowValsCCIP.put("ID_SAISIE_VENTE_FACTURE_ELEMENT", rowVals);
1686
                    rowValsCCIP.put("NOM", "Acompte");
1708
                    rowValsCCIP.put("NOM", "Acompte");
1687
                    rowValsCCIP.put("POURCENT", pourcentCurrentAcompte);
1709
                    rowValsCCIP.put("POURCENT", pourcentCurrentAcompte);
1688
                }
1710
                }
1689
                System.err.println(value);
1711
                System.err.println(value);
1690
                this.tableFacture.getModel().addRow(rowVals);
1712
                this.tableFacture.getModel().addRow(rowVals, false);
1691
                int rowIndex = this.tableFacture.getModel().getRowCount() - 1;
1713
                int rowIndex = this.tableFacture.getModel().getRowCount() - 1;
1692
                this.tableFacture.getModel().fireTableModelModified(rowIndex);
1714
                this.tableFacture.getModel().fireTableModelModified(rowIndex);
1693
            }
1715
            }
1694
            if (toAdd > 0) {
1716
            if (toAdd > 0) {
1695
                for (int i = 0; i < this.tableFacture.getModel().getRowCount() && toAdd > 0; i++) {
1717
                for (int i = 0; i < this.tableFacture.getModel().getRowCount() && toAdd > 0; i++) {
Line 1755... Line 1777...
1755
 
1777
 
1756
        loadItem(this.tableFacture, bon, rowBL.getID(), bonElt, clear);
1778
        loadItem(this.tableFacture, bon, rowBL.getID(), bonElt, clear);
1757
    }
1779
    }
1758
 
1780
 
1759
    public void addRowItem(SQLRowValues row) {
1781
    public void addRowItem(SQLRowValues row) {
1760
        this.tableFacture.getModel().addRow(row);
1782
        this.tableFacture.getModel().addRow(row, false);
1761
    }
1783
    }
1762
 
1784
 
1763
    private static final SQLElement eltModeReglement = Configuration.getInstance().getDirectory().getElement("MODE_REGLEMENT");
1785
    private static final SQLElement eltModeReglement = Configuration.getInstance().getDirectory().getElement("MODE_REGLEMENT");
1764
 
1786
 
1765
    @Override
1787
    @Override
-
 
1788
    public synchronized ValidState getValidState() {
-
 
1789
        final SQLRow clientSel = comboClient.getSelectedRow();
-
 
1790
        if (clientSel != null) {
-
 
1791
            if (getTable().getForeignTable("ID_CLIENT").contains("VERROU_COMPTA")) {
-
 
1792
                if (clientSel.getBoolean("VERROU_COMPTA")) {
-
 
1793
                    return new ValidState(false, "Le client n'a pas été vérifié par la comptabilité!");
-
 
1794
                }
-
 
1795
            }
-
 
1796
        }
-
 
1797
        return super.getValidState();
-
 
1798
    }
-
 
1799
 
-
 
1800
    @Override
1766
    protected SQLRowValues createDefaults() {
1801
    protected SQLRowValues createDefaults() {
1767
        SQLRowValues vals = new SQLRowValues(this.getTable());
1802
        SQLRowValues vals = new SQLRowValues(this.getTable());
1768
        SQLRow r;
1803
        SQLRow r;
1769
 
1804
 
1770
        try {
1805
        try {
Line 1910... Line 1945...
1910
     */
1945
     */
1911
    private void updateStock(int id) throws SQLException {
1946
    private void updateStock(int id) throws SQLException {
1912
 
1947
 
1913
        SQLPreferences prefs = SQLPreferences.getMemCached(getTable().getDBRoot());
1948
        SQLPreferences prefs = SQLPreferences.getMemCached(getTable().getDBRoot());
1914
        if (prefs.getBoolean(GestionArticleGlobalPreferencePanel.STOCK_FACT, true)) {
1949
        if (prefs.getBoolean(GestionArticleGlobalPreferencePanel.STOCK_FACT, true)) {
-
 
1950
 
1915
            SQLRow row = getTable().getRow(id);
1951
            SQLRow row = getTable().getRow(id);
1916
 
1952
 
1917
            // Check if tr from bl or cmd pour DS
1953
            // Check if tr from bl or cmd pour DS
1918
            if (getTable().getForeignTable("ID_CLIENT").contains("NOTE_2018")) {
1954
            if (getTable().getForeignTable("ID_CLIENT").contains("NOTE_2018")) {
1919
                List<SQLRow> trCmd = row.getReferentRows(getTable().getTable("TR_COMMANDE_CLIENT"));
1955
                List<SQLRow> trCmd = row.getReferentRows(getTable().getTable("TR_COMMANDE_CLIENT"));
1920
                if (!trCmd.isEmpty()) {
1956
                if (!trCmd.isEmpty()) {
1921
                    return;
1957
                    return;
1922
                }
1958
                }
-
 
1959
 
-
 
1960
                List<SQLRow> trBls = row.getReferentRows(getTable().getTable("TR_BON_DE_LIVRAISON"));
-
 
1961
                if (!trBls.isEmpty()) {
-
 
1962
                    return;
-
 
1963
                }
1923
            }
1964
            }
1924
 
1965
 
1925
            StockItemsUpdater stockUpdater = new StockItemsUpdater(new StockLabel() {
1966
            StockItemsUpdater stockUpdater = new StockItemsUpdater(new StockLabel() {
1926
 
1967
 
1927
                @Override
1968
                @Override