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 27... Line 27...
27
import org.openconcerto.erp.core.sales.quote.element.DevisLogMailSQLElement;
27
import org.openconcerto.erp.core.sales.quote.element.DevisLogMailSQLElement;
28
import org.openconcerto.erp.core.supplychain.stock.element.ComposedItemStockUpdater;
28
import org.openconcerto.erp.core.supplychain.stock.element.ComposedItemStockUpdater;
29
import org.openconcerto.erp.core.supplychain.stock.element.DepotStockSQLElement;
29
import org.openconcerto.erp.core.supplychain.stock.element.DepotStockSQLElement;
30
import org.openconcerto.erp.core.supplychain.stock.element.StockItem;
30
import org.openconcerto.erp.core.supplychain.stock.element.StockItem;
31
import org.openconcerto.sql.changer.convert.AddMDFields;
31
import org.openconcerto.sql.changer.convert.AddMDFields;
-
 
32
import org.openconcerto.sql.changer.convert.SetFKDefault;
32
import org.openconcerto.sql.model.AliasedTable;
33
import org.openconcerto.sql.model.AliasedTable;
33
import org.openconcerto.sql.model.DBRoot;
34
import org.openconcerto.sql.model.DBRoot;
34
import org.openconcerto.sql.model.SQLField;
35
import org.openconcerto.sql.model.SQLField;
35
import org.openconcerto.sql.model.SQLField.Properties;
36
import org.openconcerto.sql.model.SQLField.Properties;
36
import org.openconcerto.sql.model.SQLName;
37
import org.openconcerto.sql.model.SQLName;
Line 39... Line 40...
39
import org.openconcerto.sql.model.SQLRowValues;
40
import org.openconcerto.sql.model.SQLRowValues;
40
import org.openconcerto.sql.model.SQLSelect;
41
import org.openconcerto.sql.model.SQLSelect;
41
import org.openconcerto.sql.model.SQLSyntax;
42
import org.openconcerto.sql.model.SQLSyntax;
42
import org.openconcerto.sql.model.SQLSystem;
43
import org.openconcerto.sql.model.SQLSystem;
43
import org.openconcerto.sql.model.SQLTable;
44
import org.openconcerto.sql.model.SQLTable;
-
 
45
import org.openconcerto.sql.model.SQLUpdate;
44
import org.openconcerto.sql.model.Where;
46
import org.openconcerto.sql.model.Where;
45
import org.openconcerto.sql.preferences.SQLPreferences;
47
import org.openconcerto.sql.preferences.SQLPreferences;
46
import org.openconcerto.sql.request.UpdateBuilder;
48
import org.openconcerto.sql.request.UpdateBuilder;
47
import org.openconcerto.sql.utils.AlterTable;
49
import org.openconcerto.sql.utils.AlterTable;
48
import org.openconcerto.sql.utils.ChangeTable;
50
import org.openconcerto.sql.utils.ChangeTable;
Line 138... Line 140...
138
            tClient.getBase().getDataSource().execute(alterClient.asString());
140
            tClient.getBase().getDataSource().execute(alterClient.asString());
139
            tClient.getSchema().updateVersion();
141
            tClient.getSchema().updateVersion();
140
            tClient.fetchFields();
142
            tClient.fetchFields();
141
        }
143
        }
142
 
144
 
-
 
145
        if (!tClient.contains("ALERTE")) {
-
 
146
            final AlterTable alterClient = new AlterTable(tClient);
-
 
147
            alterClient.addVarCharColumn("ALERTE", 4096);
-
 
148
            tClient.getBase().getDataSource().execute(alterClient.asString());
-
 
149
            tClient.getSchema().updateVersion();
-
 
150
            tClient.fetchFields();
-
 
151
        }
-
 
152
 
143
        final SQLTable tCompteClient = root.getTable("COMPTE_CLIENT_TRANSACTION");
153
        final SQLTable tCompteClient = root.getTable("COMPTE_CLIENT_TRANSACTION");
144
        if (!tCompteClient.contains("ID_MOUVEMENT")) {
154
        if (!tCompteClient.contains("ID_MOUVEMENT")) {
145
            final AlterTable alterClient = new AlterTable(tCompteClient);
155
            final AlterTable alterClient = new AlterTable(tCompteClient);
146
            alterClient.addForeignColumn("ID_MOUVEMENT", root.getTable("MOUVEMENT"));
156
            alterClient.addForeignColumn("ID_MOUVEMENT", root.getTable("MOUVEMENT"));
147
            tClient.getBase().getDataSource().execute(alterClient.asString());
157
            tClient.getBase().getDataSource().execute(alterClient.asString());
Line 815... Line 825...
815
 
825
 
816
            for (org.openconcerto.sql.model.SQLField sqlField : tableVarSal.getContentFields()) {
826
            for (org.openconcerto.sql.model.SQLField sqlField : tableVarSal.getContentFields()) {
817
 
827
 
818
                String field = sqlField.getName();
828
                String field = sqlField.getName();
819
                if (!field.equalsIgnoreCase("ID_USER_COMMON_CREATE") && !field.equalsIgnoreCase("ID_USER_COMMON_MODIFY") && !field.equalsIgnoreCase("MODIFICATION_DATE")
829
                if (!field.equalsIgnoreCase("ID_USER_COMMON_CREATE") && !field.equalsIgnoreCase("ID_USER_COMMON_MODIFY") && !field.equalsIgnoreCase("MODIFICATION_DATE")
820
                        && !field.equalsIgnoreCase("CREATION_DATE") && !field.equalsIgnoreCase("HEURE_TRAV")) {
830
                        && !field.equalsIgnoreCase("CREATION_DATE") && !field.equalsIgnoreCase("HEURE_TRAV") && !tableVarSal.contains(field + "_DEFAULT_VAL")) {
821
                    alterB.addColumn(field + "_DEFAULT_VAL", "real DEFAULT 0");
831
                    alterB.addColumn(field + "_DEFAULT_VAL", "real DEFAULT 0");
822
                }
832
                }
823
            }
833
            }
824
 
834
 
825
            root.getBase().getDataSource().execute(alterB.asString());
835
            root.getBase().getDataSource().execute(alterB.asString());
Line 857... Line 867...
857
            root.getBase().getDataSource().execute(alterB.asString());
867
            root.getBase().getDataSource().execute(alterB.asString());
858
            root.refetchTable("FICHE_PAYE");
868
            root.refetchTable("FICHE_PAYE");
859
            root.getSchema().updateVersion();
869
            root.getSchema().updateVersion();
860
        }
870
        }
861
 
871
 
-
 
872
        if (!tableFpaye.contains("PERTE_TPT")) {
-
 
873
            final AlterTable alterB = new AlterTable(tableFpaye);
-
 
874
            alterB.addDecimalColumn("PERTE_TPT", 16, 2, BigDecimal.ZERO, false);
-
 
875
            root.getBase().getDataSource().execute(alterB.asString());
-
 
876
            root.refetchTable("FICHE_PAYE");
-
 
877
            root.getSchema().updateVersion();
-
 
878
        }
-
 
879
 
862
        SQLTable tableCpaye = root.findTable("CUMULS_PAYE");
880
        SQLTable tableCpaye = root.findTable("CUMULS_PAYE");
863
        if (!tableCpaye.contains("TAXE_CM_SAL_C")) {
881
        if (!tableCpaye.contains("TAXE_CM_SAL_C")) {
864
            final AlterTable alterB = new AlterTable(tableCpaye);
882
            final AlterTable alterB = new AlterTable(tableCpaye);
865
            alterB.addDecimalColumn("TAXE_CM_SAL_C", 16, 2, BigDecimal.ZERO, false);
883
            alterB.addDecimalColumn("TAXE_CM_SAL_C", 16, 2, BigDecimal.ZERO, false);
866
            alterB.addDecimalColumn("TAXE_CM_PAT_C", 16, 2, BigDecimal.ZERO, false);
884
            alterB.addDecimalColumn("TAXE_CM_PAT_C", 16, 2, BigDecimal.ZERO, false);
Line 932... Line 950...
932
            alterArticle.addColumn("DLC", "date");
950
            alterArticle.addColumn("DLC", "date");
933
            tableArticle.getBase().getDataSource().execute(alterArticle.asString());
951
            tableArticle.getBase().getDataSource().execute(alterArticle.asString());
934
            tableArticle.getSchema().updateVersion();
952
            tableArticle.getSchema().updateVersion();
935
            tableArticle.fetchFields();
953
            tableArticle.fetchFields();
936
        }
954
        }
-
 
955
        if (!tableArticle.contains("OPTION")) {
-
 
956
            final AlterTable alterArticle = new AlterTable(tableArticle);
-
 
957
            alterArticle.addBooleanColumn("OPTION", Boolean.FALSE, false);
-
 
958
            tableArticle.getBase().getDataSource().execute(alterArticle.asString());
-
 
959
            tableArticle.getSchema().updateVersion();
-
 
960
            tableArticle.fetchFields();
-
 
961
        }
-
 
962
 
937
        SQLTable tableFournisseur = root.getTable("FOURNISSEUR");
963
        SQLTable tableFournisseur = root.getTable("FOURNISSEUR");
938
        if (!tableFournisseur.contains("NUMERO_TVA")) {
964
        if (!tableFournisseur.contains("NUMERO_TVA")) {
939
            final AlterTable alter = new AlterTable(tableFournisseur);
965
            final AlterTable alter = new AlterTable(tableFournisseur);
940
            alter.addVarCharColumn("NUMERO_TVA", 128);
966
            alter.addVarCharColumn("NUMERO_TVA", 128);
941
            alter.addVarCharColumn("SIRET", 128);
967
            alter.addVarCharColumn("SIRET", 128);
942
            tableFournisseur.getBase().getDataSource().execute(alter.asString());
968
            tableFournisseur.getBase().getDataSource().execute(alter.asString());
943
            tableFournisseur.getSchema().updateVersion();
969
            tableFournisseur.getSchema().updateVersion();
944
            tableFournisseur.fetchFields();
970
            tableFournisseur.fetchFields();
945
        }
971
        }
-
 
972
        if (!tableFournisseur.contains("CONDITIONS_PORT")) {
-
 
973
            final AlterTable alter = new AlterTable(tableFournisseur);
-
 
974
            alter.addVarCharColumn("CONDITIONS_PORT", 128);
-
 
975
            tableFournisseur.getBase().getDataSource().execute(alter.asString());
-
 
976
            tableFournisseur.getSchema().updateVersion();
-
 
977
            tableFournisseur.fetchFields();
-
 
978
        }
946
 
979
 
947
        // POS
980
        // POS
948
        final SQLTable caisseT = root.getTable("CAISSE");
981
        final SQLTable caisseT = root.getTable("CAISSE");
949
        final String registerLogTableName = "CAISSE_JOURNAL";
982
        final String registerLogTableName = "CAISSE_JOURNAL";
950
        if (!root.contains(registerLogTableName)) {
983
        if (!root.contains(registerLogTableName)) {
Line 1056... Line 1089...
1056
            root.getBase().getDataSource().execute(alterF.asString());
1089
            root.getBase().getDataSource().execute(alterF.asString());
1057
            root.refetchTable("SAISIE_VENTE_FACTURE");
1090
            root.refetchTable("SAISIE_VENTE_FACTURE");
1058
            root.getSchema().updateVersion();
1091
            root.getSchema().updateVersion();
1059
        }
1092
        }
1060
 
1093
 
-
 
1094
        SQLTable tableCommandeAcompte = root.getTable("COMMANDE_CLIENT");
-
 
1095
        if (!tableCommandeAcompte.contains("T_ACOMPTE")) {
-
 
1096
            final AlterTable alterB = new AlterTable(tableCommandeAcompte);
-
 
1097
            alterB.addLongColumn("T_ACOMPTE", 0L, false);
-
 
1098
            root.getBase().getDataSource().execute(alterB.asString());
-
 
1099
            root.refetchTable("COMMANDE_CLIENT");
-
 
1100
            root.getSchema().updateVersion();
-
 
1101
 
-
 
1102
            SQLTable tableEncaisse = root.getTable("ENCAISSER_MONTANT");
-
 
1103
            final AlterTable alterC = new AlterTable(tableEncaisse);
-
 
1104
            alterC.addForeignColumn("ID_COMMANDE_CLIENT", tableDevisAcompte);
-
 
1105
            root.getBase().getDataSource().execute(alterC.asString());
-
 
1106
            root.refetchTable("ENCAISSER_MONTANT");
-
 
1107
            root.getSchema().updateVersion();
-
 
1108
        }
-
 
1109
 
-
 
1110
        if (!tableDevisAcompte.contains("DATE_LIVRAISON")) {
-
 
1111
            final AlterTable alterB = new AlterTable(tableDevisAcompte);
-
 
1112
            alterB.addColumn("DATE_LIVRAISON", "date");
-
 
1113
            alterB.addVarCharColumn("TRANSFORMATION", 200);
-
 
1114
            root.getBase().getDataSource().execute(alterB.asString());
-
 
1115
            root.refetchTable("DEVIS");
-
 
1116
            root.getSchema().updateVersion();
-
 
1117
        }
-
 
1118
 
1061
        // Paye Simplifiée
1119
        // Paye Simplifiée
1062
        if (!tableFpaye.contains("ALLEGEMENT_COTISATION")) {
1120
        if (!tableFpaye.contains("ALLEGEMENT_COTISATION")) {
1063
            final AlterTable alterB = new AlterTable(tableFpaye);
1121
            final AlterTable alterB = new AlterTable(tableFpaye);
1064
            alterB.addDecimalColumn("ALLEGEMENT_COTISATION", 16, 2, BigDecimal.ZERO, false);
1122
            alterB.addDecimalColumn("ALLEGEMENT_COTISATION", 16, 2, BigDecimal.ZERO, false);
1065
            alterB.addDecimalColumn("CICE", 16, 2, BigDecimal.ZERO, false);
1123
            alterB.addDecimalColumn("CICE", 16, 2, BigDecimal.ZERO, false);
Line 1652... Line 1710...
1652
            root.refetchTable(root.getTable("ARTICLE").getName());
1710
            root.refetchTable(root.getTable("ARTICLE").getName());
1653
            root.getSchema().updateVersion();
1711
            root.getSchema().updateVersion();
1654
        }
1712
        }
1655
 
1713
 
1656
        // Gestion multidepot
1714
        // Gestion multidepot
-
 
1715
        final SQLTable userT = root.findTable("USER_COMMON");
1657
        {
1716
        {
1658
            // Ajout table depot
1717
            // Ajout table depot
1659
            if (!root.contains("DEPOT_STOCK")) {
1718
            if (!root.contains("DEPOT_STOCK")) {
1660
                final SQLCreateTable createTable = new SQLCreateTable(root, "DEPOT_STOCK");
1719
                final SQLCreateTable createTable = new SQLCreateTable(root, "DEPOT_STOCK");
1661
                createTable.addVarCharColumn("CODE", 25);
1720
                createTable.addVarCharColumn("CODE", 25);
1662
                createTable.addVarCharColumn("NOM", 256);
1721
                createTable.addVarCharColumn("NOM", 256);
1663
                createTable.addVarCharColumn("UI_LOCK", 256);
1722
                createTable.addVarCharColumn("UI_LOCK", 256);
1664
                createTable.addForeignColumn("ID_USER_UI_LOCK", root.findTable("USER_COMMON"));
1723
                createTable.addForeignColumn("ID_USER_UI_LOCK", userT);
1665
                // sqlRowValues.put("UI_LOCK", "ro");
1724
                // sqlRowValues.put("UI_LOCK", "ro");
1666
                // sqlRowValues.put("ID_USER_UI_LOCK", 2);
1725
                // sqlRowValues.put("ID_USER_UI_LOCK", 2);
1667
 
1726
 
1668
                try {
1727
                try {
1669
                    root.getBase().getDataSource().execute(createTable.asString());
1728
                    root.getBase().getDataSource().execute(createTable.asString());
Line 1865... Line 1924...
1865
 
1924
 
1866
            for (org.openconcerto.sql.model.SQLField sqlField : tableVarSal.getContentFields()) {
1925
            for (org.openconcerto.sql.model.SQLField sqlField : tableVarSal.getContentFields()) {
1867
 
1926
 
1868
                String field = sqlField.getName();
1927
                String field = sqlField.getName();
1869
                if (!field.equalsIgnoreCase("ID_USER_COMMON_CREATE") && !field.equalsIgnoreCase("ID_USER_COMMON_MODIFY") && !field.equalsIgnoreCase("MODIFICATION_DATE")
1928
                if (!field.equalsIgnoreCase("ID_USER_COMMON_CREATE") && !field.equalsIgnoreCase("ID_USER_COMMON_MODIFY") && !field.equalsIgnoreCase("MODIFICATION_DATE")
1870
                        && !field.equalsIgnoreCase("CREATION_DATE") && !field.endsWith("_DEFAULT_VAL")) {
1929
                        && !field.equalsIgnoreCase("CREATION_DATE") && !field.endsWith("_DEFAULT_VAL") && !tableVarSal.contains(field + "_CUMUL_VAL")) {
1871
                    alterB.addColumn(field + "_CUMUL_VAL", "real DEFAULT 0");
1930
                    alterB.addColumn(field + "_CUMUL_VAL", "real DEFAULT 0");
1872
                }
1931
                }
1873
            }
1932
            }
1874
 
1933
 
1875
            root.getBase().getDataSource().execute(alterB.asString());
1934
            root.getBase().getDataSource().execute(alterB.asString());
Line 1883... Line 1942...
1883
            root.getBase().getDataSource().execute(alterB.asString());
1942
            root.getBase().getDataSource().execute(alterB.asString());
1884
            root.refetchTable("BON_DE_LIVRAISON");
1943
            root.refetchTable("BON_DE_LIVRAISON");
1885
            root.getSchema().updateVersion();
1944
            root.getSchema().updateVersion();
1886
        }
1945
        }
1887
 
1946
 
-
 
1947
        if (!tableBL.contains("VERROU_FACTURATION")) {
-
 
1948
            final AlterTable alterB = new AlterTable(tableBL);
-
 
1949
            alterB.addBooleanColumn("VERROU_FACTURATION", Boolean.FALSE, false);
-
 
1950
            root.getBase().getDataSource().execute(alterB.asString());
-
 
1951
            root.refetchTable("BON_DE_LIVRAISON");
-
 
1952
            root.getSchema().updateVersion();
-
 
1953
        }
-
 
1954
 
1888
        // fix stock
1955
        // fix stock
1889
        {
1956
        {
1890
            SQLTable tableStock = root.getTable("STOCK");
1957
            SQLTable tableStock = root.getTable("STOCK");
1891
 
1958
 
1892
            // Doublon depot stock
1959
            // Doublon depot stock
Line 1939... Line 2006...
1939
 
2006
 
1940
                    }
2007
                    }
1941
                }
2008
                }
1942
            }
2009
            }
1943
 
2010
 
-
 
2011
            // Remove useless since 1.7.1
1944
            SQLSelect selArt = new SQLSelect();
2012
            // SQLSelect selArt = new SQLSelect();
1945
            selArt.addSelectStar(tableArt);
2013
            // selArt.addSelectStar(tableArt);
1946
            Where w = new Where(tableArt.getField("ID_STOCK"), "=", 1);
2014
            // Where w = new Where(tableArt.getField("ID_STOCK"), "=", 1);
1947
            selArt.setWhere(w);
2015
            // selArt.setWhere(w);
1948
            List<SQLRow> badStock = SQLRowListRSH.execute(selArt);
2016
            // List<SQLRow> badStock = SQLRowListRSH.execute(selArt);
1949
            for (SQLRow sqlRow : badStock) {
2017
            // for (SQLRow sqlRow : badStock) {
1950
                initStock(sqlRow);
2018
            // initStock(sqlRow);
1951
            }
2019
            // }
-
 
2020
 
1952
        }
2021
        }
1953
 
2022
 
1954
        // Tarification client par quantite
2023
        // Tarification client par quantite
1955
        if (root.getTable("TARIF_ARTICLE_CLIENT") == null) {
2024
        if (root.getTable("TARIF_ARTICLE_CLIENT") == null) {
1956
            final SQLCreateTable createTableQtyTarif = new SQLCreateTable(root, "TARIF_ARTICLE_CLIENT");
2025
            final SQLCreateTable createTableQtyTarif = new SQLCreateTable(root, "TARIF_ARTICLE_CLIENT");
Line 2094... Line 2163...
2094
            root.getSchema().updateVersion();
2163
            root.getSchema().updateVersion();
2095
        }
2164
        }
2096
        final SQLTable tableSalarie = root.getTable("SALARIE");
2165
        final SQLTable tableSalarie = root.getTable("SALARIE");
2097
        if (!tableSalarie.contains("ID_USER_COMMON")) {
2166
        if (!tableSalarie.contains("ID_USER_COMMON")) {
2098
            final AlterTable alter = new AlterTable(tableSalarie);
2167
            final AlterTable alter = new AlterTable(tableSalarie);
2099
            alter.addForeignColumn("ID_USER_COMMON", root.findTable("USER_COMMON"));
2168
            alter.addForeignColumn("ID_USER_COMMON", userT);
2100
            exec(alter);
2169
            exec(alter);
2101
            root.refetchTable(tableSalarie.getName());
2170
            root.refetchTable(tableSalarie.getName());
2102
            root.getSchema().updateVersion();
2171
            root.getSchema().updateVersion();
2103
        }
2172
        }
2104
 
2173
 
Line 2418... Line 2487...
2418
            tableFactureF.getBase().getDataSource().execute(alter.asString());
2487
            tableFactureF.getBase().getDataSource().execute(alter.asString());
2419
            tableFactureF.getSchema().updateVersion();
2488
            tableFactureF.getSchema().updateVersion();
2420
            tableVF.fetchFields();
2489
            tableVF.fetchFields();
2421
        }
2490
        }
2422
 
2491
 
-
 
2492
        SQLTable tableNumAuto = root.getTable("NUMEROTATION_AUTO");
-
 
2493
        if (!tableNumAuto.contains("ARTICLE_FORMAT")) {
-
 
2494
 
-
 
2495
            final AlterTable alterNumero = new AlterTable(tableNumAuto);
-
 
2496
            alterNumero.addVarCharColumn("ARTICLE_FORMAT", 128);
-
 
2497
            alterNumero.addIntegerColumn("ARTICLE_START", 1);
-
 
2498
            root.getBase().getDataSource().execute(alterNumero.asString());
-
 
2499
            root.refetchTable("NUMEROTATION_AUTO");
-
 
2500
            root.getSchema().updateVersion();
-
 
2501
        }
-
 
2502
 
-
 
2503
        if (!tableArticle.contains("VIRTUEL")) {
-
 
2504
 
-
 
2505
            final SQLCreateTable createTableDeclinaisonCouleur = new SQLCreateTable(root, "ARTICLE_DECLINAISON_COULEUR");
-
 
2506
            createTableDeclinaisonCouleur.addVarCharColumn("NOM", 256);
-
 
2507
            root.getBase().getDataSource().execute(createTableDeclinaisonCouleur.asString());
-
 
2508
            InstallationPanel.insertUndef(createTableDeclinaisonCouleur);
-
 
2509
            root.refetchTable("ARTICLE_DECLINAISON_COULEUR");
-
 
2510
            root.getSchema().updateVersion();
-
 
2511
 
-
 
2512
            final SQLCreateTable createTableDeclinaisonTaille = new SQLCreateTable(root, "ARTICLE_DECLINAISON_TAILLE");
-
 
2513
            createTableDeclinaisonTaille.addVarCharColumn("NOM", 256);
-
 
2514
            root.getBase().getDataSource().execute(createTableDeclinaisonTaille.asString());
-
 
2515
            InstallationPanel.insertUndef(createTableDeclinaisonTaille);
-
 
2516
            root.refetchTable("ARTICLE_DECLINAISON_TAILLE");
-
 
2517
            root.getSchema().updateVersion();
-
 
2518
 
-
 
2519
            final AlterTable alter = new AlterTable(tableArticle);
-
 
2520
            alter.addBooleanColumn("VIRTUEL", false, false);
-
 
2521
            alter.addForeignColumn("ID_ARTICLE_VIRTUEL_PERE", tableArticle);
-
 
2522
            alter.addForeignColumn("ID_ARTICLE_DECLINAISON_TAILLE", root.getTable("ARTICLE_DECLINAISON_TAILLE"));
-
 
2523
            alter.addForeignColumn("ID_ARTICLE_DECLINAISON_COULEUR", root.getTable("ARTICLE_DECLINAISON_COULEUR"));
-
 
2524
            tableArticle.getBase().getDataSource().execute(alter.asString());
-
 
2525
            tableArticle.getSchema().updateVersion();
-
 
2526
            tableArticle.fetchFields();
-
 
2527
        }
-
 
2528
 
-
 
2529
        for (String string : achatItems) {
-
 
2530
            boolean alter = false;
-
 
2531
            SQLTable tableItems = root.getTable(string);
-
 
2532
            final AlterTable t = new AlterTable(tableItems);
-
 
2533
 
-
 
2534
            if (!tableItems.getFieldsName().contains("ID_ARTICLE_DECLINAISON_TAILLE")) {
-
 
2535
                t.addForeignColumn("ID_ARTICLE_DECLINAISON_TAILLE", root.getTable("ARTICLE_DECLINAISON_TAILLE"));
-
 
2536
                alter = true;
-
 
2537
            }
-
 
2538
            if (!tableItems.getFieldsName().contains("ID_ARTICLE_DECLINAISON_COULEUR")) {
-
 
2539
                t.addForeignColumn("ID_ARTICLE_DECLINAISON_COULEUR", root.getTable("ARTICLE_DECLINAISON_COULEUR"));
-
 
2540
                alter = true;
-
 
2541
            }
-
 
2542
 
-
 
2543
            if (alter) {
-
 
2544
                tableItems.getBase().getDataSource().execute(t.asString());
-
 
2545
                tableItems.getSchema().updateVersion();
-
 
2546
                tableItems.fetchFields();
-
 
2547
            }
-
 
2548
        }
-
 
2549
 
-
 
2550
        for (String tableName : tableElementWithTable) {
-
 
2551
            final SQLTable tableToDecl = root.getTable(tableName);
-
 
2552
            boolean alter = false;
-
 
2553
 
-
 
2554
            final AlterTable alterDecl = new AlterTable(tableToDecl);
-
 
2555
            if (!tableToDecl.getFieldsName().contains("ID_ARTICLE_DECLINAISON_TAILLE")) {
-
 
2556
                alterDecl.addForeignColumn("ID_ARTICLE_DECLINAISON_TAILLE", root.getTable("ARTICLE_DECLINAISON_TAILLE"));
-
 
2557
                alter = true;
-
 
2558
            }
-
 
2559
            if (!tableToDecl.getFieldsName().contains("ID_ARTICLE_DECLINAISON_COULEUR")) {
-
 
2560
                alterDecl.addForeignColumn("ID_ARTICLE_DECLINAISON_COULEUR", root.getTable("ARTICLE_DECLINAISON_COULEUR"));
-
 
2561
                alter = true;
-
 
2562
            }
-
 
2563
 
-
 
2564
            if (alter) {
-
 
2565
                tableToDecl.getBase().getDataSource().execute(alterDecl.asString());
-
 
2566
                tableToDecl.getSchema().updateVersion();
-
 
2567
                tableToDecl.fetchFields();
-
 
2568
            }
-
 
2569
        }
-
 
2570
 
-
 
2571
        // Création de la table Tarif promotion
-
 
2572
        if (!root.contains("TARIF_PROMOTION")) {
-
 
2573
 
-
 
2574
            SQLCreateTable createTarif = new SQLCreateTable(root, "TARIF_PROMOTION");
-
 
2575
            createTarif.addVarCharColumn("NOM", 256);
-
 
2576
            createTarif.addColumn("START", "date");
-
 
2577
            createTarif.addColumn("END", "date");
-
 
2578
            root.getBase().getDataSource().execute(createTarif.asString());
-
 
2579
            InstallationPanel.insertUndef(createTarif);
-
 
2580
            tableDevis.getSchema().updateVersion();
-
 
2581
            root.refetchTable(createTarif.getName());
-
 
2582
        }
-
 
2583
 
-
 
2584
        // Création de la table article Tarif promotion
-
 
2585
        if (!root.contains("ARTICLE_TARIF_PROMOTION")) {
-
 
2586
 
-
 
2587
            SQLCreateTable createTarif = new SQLCreateTable(root, "ARTICLE_TARIF_PROMOTION");
-
 
2588
            createTarif.addForeignColumn("ID_DEVISE", root.findTable("DEVISE", true));
-
 
2589
            createTarif.addForeignColumn("ID_TAXE", root.findTable("TAXE", true));
-
 
2590
            createTarif.addForeignColumn("ID_TARIF_PROMOTION", root.findTable("TARIF_PROMOTION", true));
-
 
2591
            createTarif.addForeignColumn("ID_ARTICLE", root.findTable("ARTICLE", true));
-
 
2592
            createTarif.addIntegerColumn("QTE", 1);
-
 
2593
            createTarif.addDecimalColumn("PV_HT", 16, 6, BigDecimal.ZERO, false);
-
 
2594
            createTarif.addDecimalColumn("PV_TTC", 16, 6, BigDecimal.ZERO, false);
-
 
2595
            createTarif.addDecimalColumn("PRIX_METRIQUE_VT_1", 16, 6, BigDecimal.ZERO, false);
-
 
2596
            createTarif.addDecimalColumn("PRIX_METRIQUE_VT_2", 16, 6, BigDecimal.ZERO, false);
-
 
2597
            createTarif.addDecimalColumn("PRIX_METRIQUE_VT_3", 16, 6, BigDecimal.ZERO, false);
-
 
2598
            root.getBase().getDataSource().execute(createTarif.asString());
-
 
2599
            InstallationPanel.insertUndef(createTarif);
-
 
2600
            tableDevis.getSchema().updateVersion();
-
 
2601
            root.refetchTable(createTarif.getName());
-
 
2602
        }
-
 
2603
 
-
 
2604
        if (!root.contains("TAXE_CATEGORIE_COMPTABLE")) {
-
 
2605
 
-
 
2606
            final SQLCreateTable createTableTaxeCat = new SQLCreateTable(root, "TAXE_CATEGORIE_COMPTABLE");
-
 
2607
            createTableTaxeCat.addForeignColumn("ID_CATEGORIE_COMPTABLE", root.getTable("CATEGORIE_COMPTABLE"));
-
 
2608
            createTableTaxeCat.addForeignColumn("ID_TAXE", root.getTable("TAXE"));
-
 
2609
            createTableTaxeCat.addForeignColumn("ID_COMPTE_PCE_VENTE", root.getTable("COMPTE_PCE"));
-
 
2610
            createTableTaxeCat.addForeignColumn("ID_COMPTE_PCE_ACHAT", root.getTable("COMPTE_PCE"));
-
 
2611
 
-
 
2612
            try {
-
 
2613
                root.getBase().getDataSource().execute(createTableTaxeCat.asString());
-
 
2614
                InstallationPanel.insertUndef(createTableTaxeCat);
-
 
2615
                root.refetchTable("TAXE_CATEGORIE_COMPTABLE");
-
 
2616
                root.getSchema().updateVersion();
-
 
2617
            } catch (SQLException ex) {
-
 
2618
                throw new IllegalStateException("Erreur lors de la création de la table " + "TAXE_CATEGORIE_COMPTABLE", ex);
-
 
2619
            }
-
 
2620
 
-
 
2621
        }
-
 
2622
 
-
 
2623
       
-
 
2624
        if (!root.contains("LOT_RECEPTION")) {
-
 
2625
            SQLCreateTable createLotReception = new SQLCreateTable(root, "LOT_RECEPTION");
-
 
2626
            createLotReception.addDateAndTimeColumn("DATE_RECEPTION");
-
 
2627
            createLotReception.addVarCharColumn("FOURNISSEUR", 256);
-
 
2628
            createLotReception.addVarCharColumn("ARTICLE", 256);
-
 
2629
            createLotReception.addForeignColumn("ID_ARTICLE", root.findTable("ARTICLE", true));
-
 
2630
            createLotReception.addForeignColumn("ID_DEPOT_STOCK", root.findTable("DEPOT_STOCK", true));
-
 
2631
            createLotReception.addDecimalColumn("QUANTITE", 16, 6, BigDecimal.ONE, false);
-
 
2632
            createLotReception.addVarCharColumn("NUMERO_LOT", 256);
-
 
2633
            createLotReception.addVarCharColumn("NUMERO_SERIE", 256);
-
 
2634
            createLotReception.addDateAndTimeColumn("DLC");
-
 
2635
            createLotReception.addDateAndTimeColumn("DLUO");
-
 
2636
            createLotReception.addForeignColumn("ID_BON_RECEPTION_ELEMENT", root.findTable("BON_RECEPTION_ELEMENT", true));
-
 
2637
            root.getBase().getDataSource().execute(createLotReception.asString());
-
 
2638
            InstallationPanel.insertUndef(createLotReception);
-
 
2639
 
-
 
2640
            
-
 
2641
            SQLCreateTable createLotLivraison = new SQLCreateTable(root, "LOT_LIVRAISON");
-
 
2642
            createLotLivraison.addDateAndTimeColumn("DATE_LIVRAISON");
-
 
2643
            createLotLivraison.addVarCharColumn("CLIENT", 256);
-
 
2644
            createLotLivraison.addVarCharColumn("ARTICLE", 256);
-
 
2645
            createLotLivraison.addForeignColumn("ID_ARTICLE", root.findTable("ARTICLE", true));
-
 
2646
            createLotLivraison.addForeignColumn("ID_DEPOT_STOCK", root.findTable("DEPOT_STOCK", true));
-
 
2647
            createLotLivraison.addDecimalColumn("QUANTITE", 16, 6, BigDecimal.ONE, false);
-
 
2648
            createLotLivraison.addVarCharColumn("NUMERO_LOT", 256);
-
 
2649
            createLotLivraison.addVarCharColumn("NUMERO_SERIE", 256);
-
 
2650
            createLotLivraison.addDateAndTimeColumn("DLC");
-
 
2651
            createLotLivraison.addDateAndTimeColumn("DLUO");
-
 
2652
            createLotLivraison.addForeignColumn("ID_BON_DE_LIVRAISON_ELEMENT", root.findTable("BON_DE_LIVRAISON_ELEMENT", true));
-
 
2653
            root.getBase().getDataSource().execute(createLotLivraison.asString());
-
 
2654
            InstallationPanel.insertUndef(createLotLivraison);
-
 
2655
            
-
 
2656
        }
-
 
2657
 
-
 
2658
        if (!root.contains("LOT")) {
-
 
2659
            SQLCreateTable createLot = new SQLCreateTable(root, "LOT");
-
 
2660
            createLot.addForeignColumn("ID_STOCK", root.findTable("STOCK", true));
-
 
2661
            createLot.addDecimalColumn("QUANTITE", 16, 6, BigDecimal.ONE, false);
-
 
2662
            createLot.addVarCharColumn("NUMERO_LOT", 256);
-
 
2663
            createLot.addVarCharColumn("NUMERO_SERIE", 256);
-
 
2664
            createLot.addDateAndTimeColumn("DLC");
-
 
2665
            createLot.addDateAndTimeColumn("DLUO");
-
 
2666
            root.getBase().getDataSource().execute(createLot.asString());
-
 
2667
            InstallationPanel.insertUndef(createLot);
-
 
2668
 
-
 
2669
            SQLCreateTable createTransfertStock = new SQLCreateTable(root, "TRANSFERT_STOCK");
-
 
2670
            createTransfertStock.addDateAndTimeColumn("DATE");
-
 
2671
            createTransfertStock.addForeignColumn("ID_ARTICLE", root.findTable("ARTICLE", true));
-
 
2672
            createTransfertStock.addForeignColumn("ID_DEPOT_STOCK_SOURCE", root.findTable("DEPOT_STOCK", true));
-
 
2673
            createTransfertStock.addForeignColumn("ID_DEPOT_STOCK_DEST", root.findTable("DEPOT_STOCK", true));
-
 
2674
            createTransfertStock.addDecimalColumn("QUANTITE", 16, 6, BigDecimal.ONE, false);
-
 
2675
            createTransfertStock.addVarCharColumn("NUMEROS_SERIE", 50000);
-
 
2676
            createTransfertStock.addVarCharColumn("NUMEROS_LOT", 50000);
-
 
2677
            createTransfertStock.addVarCharColumn("CONTEXTE", 256);
-
 
2678
 
-
 
2679
            root.getBase().getDataSource().execute(createTransfertStock.asString());
-
 
2680
            InstallationPanel.insertUndef(createTransfertStock);
-
 
2681
 
-
 
2682
            final AlterTable alterArticle = new AlterTable(tableArticle);
-
 
2683
            alterArticle.addBooleanColumn("NUMERO_LOT_REQUIS", false, false);
-
 
2684
            alterArticle.addBooleanColumn("NUMERO_SERIE_REQUIS", false, false);
-
 
2685
            alterArticle.addBooleanColumn("DLC_REQUIS", false, false);
-
 
2686
            alterArticle.addBooleanColumn("DLUO_REQUIS", false, false);
-
 
2687
            tableArticle.getBase().getDataSource().execute(alterArticle.asString());
-
 
2688
            tableArticle.getSchema().updateVersion();
-
 
2689
            tableArticle.fetchFields();
-
 
2690
 
-
 
2691
            final AlterTable alterBonReceptionElement = new AlterTable(root.getTable("BON_RECEPTION_ELEMENT"));
-
 
2692
            alterBonReceptionElement.addForeignColumn("ID_LOT", createLot);
-
 
2693
            tableArticle.getBase().getDataSource().execute(alterBonReceptionElement.asString());
-
 
2694
 
-
 
2695
            final AlterTable alterBonLivraisonElement = new AlterTable(root.getTable("BON_DE_LIVRAISON"));
-
 
2696
            alterBonLivraisonElement.addForeignColumn("ID_LOT", createLot);
-
 
2697
            tableArticle.getBase().getDataSource().execute(alterBonLivraisonElement.asString());
-
 
2698
            tableArticle.getSchema().updateVersion();
-
 
2699
            root.refetch();
-
 
2700
        }
-
 
2701
 
-
 
2702
        SQLTable tableBR = root.getTable("BON_RECEPTION");
-
 
2703
        SQLTable tableModele = root.getTable("MODELE");
-
 
2704
        if (!tableBR.contains("ID_MODELE")) {
-
 
2705
            AlterTable a = new AlterTable(tableBR);
-
 
2706
            a.addForeignColumn("ID_MODELE", tableModele);
-
 
2707
            root.getBase().getDataSource().execute(a.asString());
-
 
2708
            tableBR.getSchema().updateVersion();
-
 
2709
            root.refetchTable(tableBR.getName());
-
 
2710
        }
-
 
2711
 
-
 
2712
        SQLTable typeModele = tableModele.getForeignTable("ID_TYPE_MODELE");
-
 
2713
        SQLSelect sel = new SQLSelect();
-
 
2714
        sel.addSelect(typeModele.getKey());
-
 
2715
        sel.setWhere(new Where(typeModele.getField("TABLE"), "=", "BON_RECEPTION"));
-
 
2716
        List<SQLRow> l = SQLRowListRSH.execute(sel);
-
 
2717
        if (l.isEmpty()) {
-
 
2718
            SQLRowValues rowVals = new SQLRowValues(typeModele);
-
 
2719
            rowVals.put("TABLE", "BON_RECEPTION");
-
 
2720
            rowVals.put("NOM", "Bon de réception");
-
 
2721
            rowVals.put("DEFAULT_MODELE", "BonReception");
-
 
2722
            rowVals.commit();
-
 
2723
        }
-
 
2724
        // Fix undefined
-
 
2725
        new SetFKDefault(root.getDBSystemRoot()).changeAll(root);
-
 
2726
        List<SQLUpdate> ups = new ArrayList<>();
-
 
2727
        if (userT.getUndefinedIDNumber() != null) {
-
 
2728
            for (SQLField userF : root.getDBSystemRoot().getGraph().getReferentKeys(userT)) {
-
 
2729
                if (userF.getTable().getDBRoot() == root) {
-
 
2730
                    SQLUpdate up = new SQLUpdate(Where.isNull(userF));
-
 
2731
                    up.add(userF, userT.getUndefinedIDNumber());
-
 
2732
                    ups.add(up);
-
 
2733
                }
-
 
2734
            }
-
 
2735
        }
-
 
2736
        if (!ups.isEmpty()) {
-
 
2737
            SQLUpdate.executeMultipleWithBatch(root.getDBSystemRoot(), ups);
-
 
2738
            System.err.println("Updater_1_5.update() fixed " + ups.size() + " error(s) on FK to USER_COMMON");
-
 
2739
        } else {
-
 
2740
            System.err.println("Updater_1_5.update() no error on FK to USER_COMMON");
-
 
2741
        }
2423
    }
2742
    }
2424
 
2743
 
2425
    public static void initStock(SQLRow rowArticle, int idDepot) {
2744
    public static void initStock(SQLRow rowArticle, int idDepot) {
2426
 
2745
 
2427
        SQLSelect selStock = new SQLSelect();
2746
        SQLSelect selStock = new SQLSelect();