using Exferia_Aplicacion.General;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static Exferia_Aplicacion.General.Enumerados;

namespace Exferia_EntityFramework.Script_Actualizacion
{
    public class Scripts_Version_1126
    {
        public static Version G_VRS_VERSION = new Version("1.1.2.6");
        public static long G_LNG_VERSION = 1126;
        public static int G_INT_TIPO = 0;
        public static string G_STR_SCRIPT =
                                    //MODIFICAR el campo retencion a la tabla MAE_Clientes
                                    "IF exists " +
                                      "( " +
                                      "    SELECT * " +
                                      "    FROM INFORMATION_SCHEMA.COLUMNS " +
                                      "    WHERE COLUMN_NAME='retencion' AND TABLE_NAME = 'MAE_Clientes' and DATA_TYPE='varchar'" +
                                      ") " +
                                    "BEGIN " +
                                        " UPDATE MAE_Clientes SET retencion=null where retencion<>'2'" +
                                        " UPDATE MAE_Clientes SET retencion=1 where not retencion is null " +
                                        " ALTER TABLE [MAE_Clientes] ALTER COLUMN retencion bit NULL " +
                                    "END " +
                                    //MODIFICAR el campo recargo a la tabla MAE_Clientes
                                    "IF exists " +
                                      "( " +
                                      "    SELECT * " +
                                      "    FROM INFORMATION_SCHEMA.COLUMNS " +
                                      "    WHERE COLUMN_NAME='recargo' AND TABLE_NAME = 'MAE_Clientes' and DATA_TYPE='varchar'" +
                                      ") " +
                                    "BEGIN " +
                                        " UPDATE MAE_Clientes SET recargo=null where recargo<>'2'" +
                                        " UPDATE MAE_Clientes SET recargo=1 where not recargo is null " +
                                        " ALTER TABLE [MAE_Clientes] ALTER COLUMN recargo bit NULL " +
                                    "END " +
                                    //MODIFICAR el campo permiteDepositos a la tabla MAE_Clientes
                                    "IF exists " +
                                      "( " +
                                      "    SELECT * " +
                                      "    FROM INFORMATION_SCHEMA.COLUMNS " +
                                      "    WHERE COLUMN_NAME='permiteDepositos' AND TABLE_NAME = 'MAE_Clientes' and DATA_TYPE='varchar'" +
                                      ") " +
                                    "BEGIN " +
                                        " UPDATE MAE_Clientes SET permiteDepositos=null where permiteDepositos<>'2'" +
                                        " UPDATE MAE_Clientes SET permiteDepositos=1 where not permiteDepositos is null " +
                                        " ALTER TABLE [MAE_Clientes] ALTER COLUMN permiteDepositos bit NULL " +
                                    "END " +
                                    //MODIFICAR el campo imprimirDeudaAcumulada a la tabla MAE_Clientes
                                    "IF exists " +
                                      "( " +
                                      "    SELECT * " +
                                      "    FROM INFORMATION_SCHEMA.COLUMNS " +
                                      "    WHERE COLUMN_NAME='imprimirDeudaAcumulada' AND TABLE_NAME = 'MAE_Clientes' and DATA_TYPE='varchar'" +
                                      ") " +
                                    "BEGIN " +
                                        " UPDATE MAE_Clientes SET imprimirDeudaAcumulada=null where imprimirDeudaAcumulada<>'2'" +
                                        " UPDATE MAE_Clientes SET imprimirDeudaAcumulada=1 where not imprimirDeudaAcumulada is null " +
                                        " ALTER TABLE [MAE_Clientes] ALTER COLUMN imprimirDeudaAcumulada bit NULL " +
                                    "END "+
                                    //MODIFICAR el campo imprimirDatosCadena a la tabla MAE_Clientes
                                    "IF exists " +
                                      "( " +
                                      "    SELECT * " +
                                      "    FROM INFORMATION_SCHEMA.COLUMNS " +
                                      "    WHERE COLUMN_NAME='imprimirDatosCadena' AND TABLE_NAME = 'MAE_Clientes' and DATA_TYPE='varchar'" +
                                      ") " +
                                    "BEGIN " +
                                        " UPDATE MAE_Clientes SET imprimirDatosCadena=null where imprimirDatosCadena<>'2'" +
                                        " UPDATE MAE_Clientes SET imprimirDatosCadena=1 where not imprimirDatosCadena is null " +
                                        " ALTER TABLE [MAE_Clientes] ALTER COLUMN imprimirDatosCadena bit NULL " +
                                    "END " +
                                    //MODIFICAR el campo facturarDatosCadena a la tabla MAE_Clientes
                                    "IF exists " +
                                      "( " +
                                      "    SELECT * " +
                                      "    FROM INFORMATION_SCHEMA.COLUMNS " +
                                      "    WHERE COLUMN_NAME='facturarDatosCadena' AND TABLE_NAME = 'MAE_Clientes' and DATA_TYPE='varchar'" +
                                      ") " +
                                    "BEGIN " +
                                        " UPDATE MAE_Clientes SET facturarDatosCadena=null where facturarDatosCadena<>'2'" +
                                        " UPDATE MAE_Clientes SET facturarDatosCadena=1 where not facturarDatosCadena is null " +
                                        " ALTER TABLE [MAE_Clientes] ALTER COLUMN facturarDatosCadena bit NULL " +
                                    "END " +
                                    //MODIFICAR el campo imprimir_Trazabilidad a la tabla MAE_Clientes
                                    "IF exists " +
                                      "( " +
                                      "    SELECT * " +
                                      "    FROM INFORMATION_SCHEMA.COLUMNS " +
                                      "    WHERE COLUMN_NAME='imprimir_Trazabilidad' AND TABLE_NAME = 'MAE_Clientes' and DATA_TYPE='varchar'" +
                                      ") " +
                                    "BEGIN " +
                                        " UPDATE MAE_Clientes SET imprimir_Trazabilidad=null where imprimir_Trazabilidad<>'2'" +
                                        " UPDATE MAE_Clientes SET imprimir_Trazabilidad=1 where not imprimir_Trazabilidad is null " +
                                        " ALTER TABLE [MAE_Clientes] ALTER COLUMN imprimir_Trazabilidad bit NULL " +
                                    "END " +
                                    //MODIFICAR el campo noFacturar a la tabla MAE_Clientes
                                    "IF exists " +
                                      "( " +
                                      "    SELECT * " +
                                      "    FROM INFORMATION_SCHEMA.COLUMNS " +
                                      "    WHERE COLUMN_NAME='noFacturar' AND TABLE_NAME = 'MAE_Clientes' and DATA_TYPE='varchar'" +
                                      ") " +
                                    "BEGIN " +
                                        " UPDATE MAE_Clientes SET noFacturar=null where noFacturar<>'2'" +
                                        " UPDATE MAE_Clientes SET noFacturar=1 where not noFacturar is null " +
                                        " ALTER TABLE [MAE_Clientes] ALTER COLUMN noFacturar bit NULL " +
                                    "END " +
                                    //AÑADIR el campo recargo a la tabla MAE_Proveedores
                                    "IF not exists " +
                                      "( " +
                                      "    SELECT * " +
                                      "    FROM INFORMATION_SCHEMA.COLUMNS " +
                                      "    WHERE COLUMN_NAME='recargo' AND TABLE_NAME = 'MAE_Proveedores' " +
                                      ") " +
                                    "BEGIN " +
                                        " ALTER TABLE [MAE_Proveedores]ADD[recargo] bit NULL " +
                                    "END " +
                                    //AÑADIR el campo recargo a la tabla GEN_EjerciciosActivos_Empresa
                                    "IF not exists " +
                                      "( " +
                                      "    SELECT * " +
                                      "    FROM INFORMATION_SCHEMA.COLUMNS " +
                                      "    WHERE COLUMN_NAME='recargo' AND TABLE_NAME = 'GEN_EjerciciosActivos_Empresa' " +
                                      ") " +
                                    "BEGIN " +
                                        " ALTER TABLE [GEN_EjerciciosActivos_Empresa]ADD[recargo] bit NULL " +
                                    "END " ;




    }
}
