using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Exferia_EntityFramework.Script_Actualizacion
{
    class Scripts_Version_1180
    {
        public static Version G_VRS_VERSION = new Version("1.1.8.0");
        public static long G_LNG_VERSION = 1180;
        public static int G_INT_TIPO = 0;
        public static string G_STR_SCRIPT =
                                    //CREAR TABLA HPVS_Gastos
                                    " IF not exists " +
                                    " ( " +
                                        " SELECT * " +
                                        " FROM INFORMATION_SCHEMA.TABLES " +
                                        " WHERE TABLE_NAME = 'HPVS_Gastos' " +
                                    " ) " +
                                    " BEGIN " +
                                        " CREATE TABLE [HPVS_Gastos] " +
                                        " ( " +
                                            " [numeroGasto] [bigint] NOT NULL, " +
                                            " [idTerminal] [bigint] NOT NULL, " +
                                            " [fechaHora] [datetime] NOT NULL, " +
                                            " [idCamarero] [bigint] NOT NULL, " +
                                            " [idEmpresa] [bigint] NOT NULL, " +
                                            " [idTipoGasto] [bigint] NOT NULL, " +
                                            " [importe] [decimal](18, 2) NOT NULL, " +
                                            " [guid] [varchar](100) NOT NULL, " +
                                            " [tipoAccion] [varchar](1) NOT NULL, " +
                                            " [fechaBorrado] [datetime] NULL, " +
                                        " CONSTRAINT[PK_HPVS_Gastos] PRIMARY KEY CLUSTERED " +
                                        " ( " +
                                            " [numeroGasto] ASC, " +
                                            " [idTerminal] ASC, " +
                                            " [fechaHora] ASC, " +
                                            " [idCamarero] ASC, " +
                                            " [idEmpresa] ASC " +
                                        " )WITH(PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON[PRIMARY] " +
                                        " ) ON[PRIMARY] " +

                                        //relaciones
                                        " ALTER TABLE [HPVS_Gastos] WITH CHECK ADD CONSTRAINT[FK_HPVS_Gastos_HPV_Camareros] FOREIGN KEY([idCamarero]) REFERENCES [HPV_Camareros] ([id]) " +
                                        " ALTER TABLE [HPVS_Gastos] CHECK CONSTRAINT[FK_HPVS_Gastos_HPV_Camareros] " +

                                        " ALTER TABLE [HPVS_Gastos] WITH CHECK ADD CONSTRAINT[FK_HPVS_Gastos_HPV_Terminales] FOREIGN KEY([idTerminal]) REFERENCES [HPV_Terminales] ([id]) " +
                                        " ALTER TABLE [HPVS_Gastos] CHECK CONSTRAINT[FK_HPVS_Gastos_HPV_Terminales] " +

                                        " ALTER TABLE [HPVS_Gastos] WITH CHECK ADD CONSTRAINT[FK_HPVS_Gastos_MAE_TiposGastos] FOREIGN KEY([idTipoGasto]) REFERENCES [MAE_TiposGastos] ([id]) " +
                                        " ALTER TABLE [HPVS_Gastos] CHECK CONSTRAINT[FK_HPVS_Gastos_MAE_TiposGastos] " +

                                        " ALTER TABLE[HPVS_Gastos] WITH CHECK ADD CONSTRAINT[FK_HPVS_Gastos_GEN_Empresas] FOREIGN KEY([idEmpresa]) REFERENCES[GEN_Empresas] ([id]) " +
                                        " ALTER TABLE[HPVS_Gastos] CHECK CONSTRAINT[FK_HPVS_Gastos_GEN_Empresas] " +
                                    " END " +
                                    //CREAR TABLA HPVS_Liquidaciones
                                    " IF not exists " +
                                    " ( " +
                                        " SELECT * " +
                                        " FROM INFORMATION_SCHEMA.TABLES " +
                                        " WHERE TABLE_NAME = 'HPVS_Liquidaciones' " +
                                    " ) " +
                                    " BEGIN " +
                                        " CREATE TABLE [HPVS_Liquidaciones] " +
                                        " ( " +
                                            " [numeroLiquidacion] [bigint] NOT NULL, " +
                                            " [idTerminal] [bigint] NOT NULL, " +
                                            " [idEmpresa] [bigint] NOT NULL, " +
                                            " [fechaHora_Inicial] [datetime] NOT NULL, " +
                                            " [fechaHora_Final] [datetime] NULL, " +
                                            " [idCamarero_Inicial] [bigint] NOT NULL, " +
                                            " [idCamarero_Final] [bigint] NULL, " +
                                            " [arqueoInicial_001] [int] NOT NULL, " +
                                            " [arqueoInicial_002] [int] NOT NULL, " +
                                            " [arqueoInicial_005] [int] NOT NULL, " +
                                            " [arqueoInicial_010] [int] NOT NULL, " +
                                            " [arqueoInicial_020] [int] NOT NULL, " +
                                            " [arqueoInicial_050] [int] NOT NULL, " +
                                            " [arqueoInicial_1] [int] NOT NULL, " +
                                            " [arqueoInicial_2] [int] NOT NULL, " +
                                            " [arqueoInicial_5] [int] NOT NULL, " +
                                            " [arqueoInicial_10] [int] NOT NULL, " +
                                            " [arqueoInicial_20] [int] NOT NULL, " +
                                            " [arqueoInicial_50] [int] NOT NULL, " +
                                            " [arqueoInicial_100] [int] NOT NULL, " +
                                            " [arqueoInicial_200] [int] NOT NULL, " +
                                            " [arqueoInicial_500] [int] NOT NULL, " +
                                            " [sinArqueoInicial] [bit] NOT NULL, " +
                                            " [arqueoInicial_Metalico_Total] [decimal](18, 2) NOT NULL, " +
                                            " [arqueoFinal_001] [int] NULL, " +
                                            " [arqueoFinal_002] [int] NULL, " +
                                            " [arqueoFinal_005] [int] NULL, " +
                                            " [arqueoFinal_010] [int] NULL, " +
                                            " [arqueoFinal_020] [int] NULL, " +
                                            " [arqueoFinal_050] [int] NULL, " +
                                            " [arqueoFinal_1] [int] NULL, " +
                                            " [arqueoFinal_2] [int] NULL, " +
                                            " [arqueoFinal_5] [int] NULL, " +
                                            " [arqueoFinal_10] [int] NULL, " +
                                            " [arqueoFinal_20] [int] NULL, " +
                                            " [arqueoFinal_50] [int] NULL, " +
                                            " [arqueoFinal_100] [int] NULL, " +
                                            " [arqueoFinal_200] [int] NULL, " +
                                            " [arqueoFinal_500] [int] NULL, " +
                                            " [sinArqueoFinal] [bit] NOT NULL, " +
                                            " [arqueoFinal_Metalico_Total] [decimal](18, 2) NOT NULL, " +
                                            " [importeTotal_Calculado] [decimal](18, 2) NOT NULL, " +
                                            " [importeTotal_Gastos] [decimal](18, 2) NOT NULL, " +
                                            " [importeTotal_Cierre] [decimal](18, 2) NOT NULL, " +
                                            " [importeTotal_Encaja] [decimal](18, 2) NOT NULL, " +
                                            " [guid] [varchar](100) NOT NULL, " +
                                            " [tipoAccion] [varchar](1) NOT NULL, " +
                                            " [fechaBorrado] [datetime] NULL, " +
                                        " CONSTRAINT[PK_HPVS_Liquidaciones_1] PRIMARY KEY CLUSTERED " +
                                        " ( " +
                                            " [numeroLiquidacion] ASC, " +
                                            " [idTerminal] ASC, " +
                                            " [idEmpresa] ASC, " +
                                            " [fechaHora_Inicial] ASC " +
                                        " )WITH(PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON[PRIMARY] " +
                                        " ) ON[PRIMARY] " +
                                        //Relaciones
                                        " ALTER TABLE [HPVS_Liquidaciones] WITH CHECK ADD CONSTRAINT[FK_HPVS_Liquidaciones_GEN_Empresas] FOREIGN KEY([idEmpresa]) REFERENCES [GEN_Empresas] ([id]) " +
                                        " ALTER TABLE [HPVS_Liquidaciones] CHECK CONSTRAINT[FK_HPVS_Liquidaciones_GEN_Empresas] " +

                                        " ALTER TABLE [HPVS_Liquidaciones] WITH CHECK ADD CONSTRAINT[FK_HPVS_Liquidaciones_HPV_Camareros] FOREIGN KEY([idCamarero_Inicial]) REFERENCES[HPV_Camareros] ([id]) " +
                                        " ALTER TABLE [HPVS_Liquidaciones] CHECK CONSTRAINT[FK_HPVS_Liquidaciones_HPV_Camareros] " +

                                        " ALTER TABLE[HPVS_Liquidaciones] WITH CHECK ADD CONSTRAINT[FK_HPVS_Liquidaciones_HPV_Camareros_1] FOREIGN KEY([idCamarero_Final]) REFERENCES[HPV_Camareros] ([id]) " +
                                        " ALTER TABLE[HPVS_Liquidaciones] CHECK CONSTRAINT[FK_HPVS_Liquidaciones_HPV_Camareros_1] " +

                                        " ALTER TABLE [HPVS_Liquidaciones] WITH CHECK ADD CONSTRAINT[FK_HPVS_Liquidaciones_HPV_Terminales] FOREIGN KEY([idTerminal]) REFERENCES [HPV_Terminales] ([id]) " +
                                        " ALTER TABLE [HPVS_Liquidaciones] CHECK CONSTRAINT[FK_HPVS_Liquidaciones_HPV_Terminales] " +

                                    " END " +
                                    //CREAR TABLA HPVS_Liquidaciones_TiposPagos
                                    " IF not exists " +
                                    " ( " +
                                        " SELECT * " +
                                        " FROM INFORMATION_SCHEMA.TABLES " +
                                        " WHERE TABLE_NAME = 'HPVS_Liquidaciones_TiposPagos' " +
                                    " ) " +
                                    " BEGIN " +
                                        " CREATE TABLE [HPVS_Liquidaciones_TiposPagos] " +
                                        " ( " +
                                            " [numeroLiquidacion] [bigint] NOT NULL, " +
                                            " [idTerminal] [bigint] NOT NULL, " +
                                            " [idEmpresa] [bigint] NOT NULL, " +
                                            " [fechaHora_Inicial] [datetime] NOT NULL, " +
                                            " [linea] [int] NOT NULL, " +
                                            " [idTipoPago] [bigint] NOT NULL, " +
                                            " [importe_Calculado] [decimal](18, 2) NOT NULL, " +
                                            " [importe_Gastos] [decimal](18, 2) NOT NULL, " +
                                            " [importe_Cierre] [decimal](18, 2) NOT NULL, " +
                                        " CONSTRAINT[PK_HPVS_Liquidaciones_TiposPagos] PRIMARY KEY CLUSTERED " +
                                        " ( " +
                                            " [numeroLiquidacion] ASC, " +
                                            " [idTerminal] ASC, " +
                                            " [idEmpresa] ASC, " +
                                            " [fechaHora_Inicial] ASC, " +
                                            " [linea] ASC " +
                                        " )WITH(PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON[PRIMARY] " +
                                        " ) ON[PRIMARY] " +
                                        //Relaciones
                                        " ALTER TABLE [HPVS_Liquidaciones_TiposPagos] WITH CHECK ADD CONSTRAINT[FK_HPVS_Liquidaciones_TiposPagos_GEN_Empresas] FOREIGN KEY([idEmpresa]) REFERENCES[GEN_Empresas] ([id]) " +
                                        " ALTER TABLE [HPVS_Liquidaciones_TiposPagos] CHECK CONSTRAINT[FK_HPVS_Liquidaciones_TiposPagos_GEN_Empresas] " +

                                        " ALTER TABLE [HPVS_Liquidaciones_TiposPagos] WITH CHECK ADD CONSTRAINT[FK_HPVS_Liquidaciones_TiposPagos_HPV_Terminales] FOREIGN KEY([idTerminal]) REFERENCES [HPV_Terminales] ([id]) " +
                                        " ALTER TABLE [HPVS_Liquidaciones_TiposPagos] CHECK CONSTRAINT[FK_HPVS_Liquidaciones_TiposPagos_HPV_Terminales] " +

                                        " ALTER TABLE [HPVS_Liquidaciones_TiposPagos] WITH CHECK ADD CONSTRAINT[FK_HPVS_Liquidaciones_TiposPagos_HPVS_Liquidaciones] FOREIGN KEY([numeroLiquidacion], [idTerminal], [idEmpresa], [fechaHora_Inicial]) REFERENCES [HPVS_Liquidaciones] ([numeroLiquidacion], [idTerminal], [idEmpresa], [fechaHora_Inicial]) " +
                                        " ALTER TABLE [HPVS_Liquidaciones_TiposPagos] CHECK CONSTRAINT[FK_HPVS_Liquidaciones_TiposPagos_HPVS_Liquidaciones] " +

                                        " ALTER TABLE [HPVS_Liquidaciones_TiposPagos] WITH CHECK ADD CONSTRAINT[FK_HPVS_Liquidaciones_TiposPagos_MAE_TiposPagos] FOREIGN KEY([idTipoPago]) REFERENCES [MAE_TiposPagos] ([id]) " +
                                        " ALTER TABLE [HPVS_Liquidaciones_TiposPagos] CHECK CONSTRAINT[FK_HPVS_Liquidaciones_TiposPagos_MAE_TiposPagos] " +

                                    " END " +
                                    //CREAR TABLA HPVS_Tickets_Cabecera
                                    " IF not exists " +
                                    " ( " +
                                        " SELECT * " +
                                        " FROM INFORMATION_SCHEMA.TABLES " +
                                        " WHERE TABLE_NAME = 'HPVS_Tickets_Cabecera' " +
                                    " ) " +
                                    " BEGIN " +
                                        " CREATE TABLE [HPVS_Tickets_Cabecera] " +
                                        " ( " +
                                            " [numero][bigint]NOT NULL, " +
                                            " [idEmpresa] [bigint]NOT NULL, " +
                                            " [idTerminal] [bigint]NOT NULL, " +
                                            " [idSala] [bigint]NOT NULL, " +
                                            " [fechaHora] [datetime]NOT NULL, " +
                                            " [alias] [varchar](30) NULL, " +
                                            " [idCliente][bigint]NOT NULL, " +
                                            " [idImpuestoCabecera] [bigint]NOT NULL, " +
                                            " [idCamarero_Creacion] [bigint]NOT NULL, " +
                                            " [idCamarero_UltimaModificacion] [bigint]NOT NULL, " +
                                            " [idMesa] [bigint]NULL, " +
                                            " [idPuntoBarra][bigint]NULL, " +
                                            " [importeTotal][decimal](18, 2) NULL, " +
                                            " [cobrado][bit]NOT NULL, " +
                                            " [modificado] [bit]NOT NULL, " +
                                            " [guid] [varchar](100) NOT NULL, " +
                                            " [tipoAccion] [varchar](1) NOT NULL, " +
                                        " CONSTRAINT[PK_HPVS_Tickets_Cabecera] PRIMARY KEY CLUSTERED " +
                                        " ( " +
                                            " [numero] ASC, " +
                                            " [idEmpresa] ASC, " +
                                            " [idTerminal] ASC, " +
                                            " [idSala] ASC, " +
                                            " [fechaHora] ASC " +
                                        " )WITH(PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON[PRIMARY] " +
                                        " ) ON[PRIMARY] " +

                                        //Relaciones
                                        " ALTER TABLE [HPVS_Tickets_Cabecera]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Cabecera_GEN_Empresas] FOREIGN KEY([idEmpresa])REFERENCES [GEN_Empresas] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Cabecera]CHECK CONSTRAINT[FK_HPVS_Tickets_Cabecera_GEN_Empresas] " +

                                        " ALTER TABLE [HPVS_Tickets_Cabecera]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Cabecera_GEN_ImpuestosCabecera] FOREIGN KEY([idImpuestoCabecera])REFERENCES [GEN_ImpuestosCabecera] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Cabecera]CHECK CONSTRAINT[FK_HPVS_Tickets_Cabecera_GEN_ImpuestosCabecera] " +

                                        " ALTER TABLE [HPVS_Tickets_Cabecera]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Cabecera_HPV_Camareros] FOREIGN KEY([idCamarero_Creacion])REFERENCES [HPV_Camareros] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Cabecera]CHECK CONSTRAINT[FK_HPVS_Tickets_Cabecera_HPV_Camareros] " +

                                        " ALTER TABLE [HPVS_Tickets_Cabecera]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Cabecera_HPV_Camareros1] FOREIGN KEY([idCamarero_UltimaModificacion])REFERENCES [HPV_Camareros] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Cabecera]CHECK CONSTRAINT[FK_HPVS_Tickets_Cabecera_HPV_Camareros1] " +

                                        " ALTER TABLE [HPVS_Tickets_Cabecera]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Cabecera_HPV_Clientes] FOREIGN KEY([idCliente])REFERENCES [HPV_Clientes] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Cabecera]CHECK CONSTRAINT[FK_HPVS_Tickets_Cabecera_HPV_Clientes] " +

                                        " ALTER TABLE [HPVS_Tickets_Cabecera]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Cabecera_HPV_Mesas] FOREIGN KEY([idMesa])REFERENCES [HPV_Mesas] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Cabecera]CHECK CONSTRAINT[FK_HPVS_Tickets_Cabecera_HPV_Mesas] " +

                                        " ALTER TABLE [HPVS_Tickets_Cabecera]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Cabecera_HPV_PuntosBarra] FOREIGN KEY([idPuntoBarra])REFERENCES [HPV_PuntosBarra] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Cabecera]CHECK CONSTRAINT[FK_HPVS_Tickets_Cabecera_HPV_PuntosBarra] " +

                                        " ALTER TABLE [HPVS_Tickets_Cabecera]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Cabecera_HPV_Salas] FOREIGN KEY([idSala])REFERENCES [HPV_Salas] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Cabecera]CHECK CONSTRAINT[FK_HPVS_Tickets_Cabecera_HPV_Salas] " +

                                        " ALTER TABLE [HPVS_Tickets_Cabecera]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Cabecera_HPV_Terminales] FOREIGN KEY([idTerminal])REFERENCES [HPV_Terminales] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Cabecera]CHECK CONSTRAINT[FK_HPVS_Tickets_Cabecera_HPV_Terminales] " +

                                    " END " +
                                    //CREAR TABLA HPVS_Tickets_Cabecera_MesasPuntosBarra_Unidos
                                    " IF not exists " +
                                    " ( " +
                                        " SELECT * " +
                                        " FROM INFORMATION_SCHEMA.TABLES " +
                                        " WHERE TABLE_NAME = 'HPVS_Tickets_Cabecera_MesasPuntosBarra_Unidos' " +
                                    " ) " +
                                    " BEGIN " +
                                        " CREATE TABLE [HPVS_Tickets_Cabecera_MesasPuntosBarra_Unidos] " +
                                        " ( " +
                                            " [numero][bigint]NOT NULL, " +
                                            " [idEmpresa] [bigint]NOT NULL, " +
                                            " [idTerminal] [bigint]NOT NULL, " +
                                            " [idSala] [bigint]NOT NULL, " +
                                            " [fechaHora] [datetime]NOT NULL, " +
                                            " [numeroUnion] [int] NOT NULL, " +
                                            " [idMesa] [bigint]NULL, " +
                                            " [idPuntoBarra][bigint]NULL, " +
                                            " [guid][varchar](100) NOT NULL, " +
                                        " CONSTRAINT[PK_HPVS_Tickets_Cabecera_MesasPuntosBarra_Unidos] PRIMARY KEY CLUSTERED " +
                                        " ( " +
                                            " [numero] ASC, " +
                                            " [idEmpresa] ASC, " +
                                            " [idTerminal] ASC, " +
                                            " [idSala] ASC, " +
                                            " [fechaHora] ASC, " +
                                            " [numeroUnion] ASC " +
                                        " )WITH(PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON[PRIMARY] " +
                                        " ) ON[PRIMARY] " +

                                        //Relaciones
                                        " ALTER TABLE [HPVS_Tickets_Cabecera_MesasPuntosBarra_Unidos]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Cabecera_MesasPuntosBarra_Unidos_GEN_Empresas] FOREIGN KEY([idEmpresa])REFERENCES [GEN_Empresas] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Cabecera_MesasPuntosBarra_Unidos]CHECK CONSTRAINT[FK_HPVS_Tickets_Cabecera_MesasPuntosBarra_Unidos_GEN_Empresas] " +

                                        " ALTER TABLE [HPVS_Tickets_Cabecera_MesasPuntosBarra_Unidos]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Cabecera_MesasPuntosBarra_Unidos_HPV_Mesas] FOREIGN KEY([idMesa])REFERENCES [HPV_Mesas] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Cabecera_MesasPuntosBarra_Unidos]CHECK CONSTRAINT[FK_HPVS_Tickets_Cabecera_MesasPuntosBarra_Unidos_HPV_Mesas] " +

                                        " ALTER TABLE [HPVS_Tickets_Cabecera_MesasPuntosBarra_Unidos]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Cabecera_MesasPuntosBarra_Unidos_HPV_PuntosBarra] FOREIGN KEY([idPuntoBarra])REFERENCES [HPV_PuntosBarra] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Cabecera_MesasPuntosBarra_Unidos]CHECK CONSTRAINT[FK_HPVS_Tickets_Cabecera_MesasPuntosBarra_Unidos_HPV_PuntosBarra] " +

                                        " ALTER TABLE [HPVS_Tickets_Cabecera_MesasPuntosBarra_Unidos]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Cabecera_MesasPuntosBarra_Unidos_HPV_Salas] FOREIGN KEY([idSala])REFERENCES [HPV_Salas] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Cabecera_MesasPuntosBarra_Unidos]CHECK CONSTRAINT[FK_HPVS_Tickets_Cabecera_MesasPuntosBarra_Unidos_HPV_Salas] " +

                                        " ALTER TABLE [HPVS_Tickets_Cabecera_MesasPuntosBarra_Unidos]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Cabecera_MesasPuntosBarra_Unidos_HPV_Terminales] FOREIGN KEY([idTerminal])REFERENCES [HPV_Terminales] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Cabecera_MesasPuntosBarra_Unidos]CHECK CONSTRAINT[FK_HPVS_Tickets_Cabecera_MesasPuntosBarra_Unidos_HPV_Terminales] " +

                                        " ALTER TABLE [HPVS_Tickets_Cabecera_MesasPuntosBarra_Unidos]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Cabecera_MesasPuntosBarra_Unidos_HPVS_Tickets_Cabecera] FOREIGN KEY([numero], [idEmpresa], [idTerminal], [idSala], [fechaHora])REFERENCES [HPVS_Tickets_Cabecera] ([numero], [idEmpresa], [idTerminal], [idSala], [fechaHora])ON DELETE CASCADE " +
                                        " ALTER TABLE [HPVS_Tickets_Cabecera_MesasPuntosBarra_Unidos]CHECK CONSTRAINT[FK_HPVS_Tickets_Cabecera_MesasPuntosBarra_Unidos_HPVS_Tickets_Cabecera] " +

                                    " END " +
                                    //CREAR TABLA HPVS_Tickets_Cobros
                                    " IF not exists " +
                                    " ( " +
                                        " SELECT * " +
                                        " FROM INFORMATION_SCHEMA.TABLES " +
                                        " WHERE TABLE_NAME = 'HPVS_Tickets_Cobros' " +
                                    " ) " +
                                    " BEGIN " +
                                        " CREATE TABLE [HPVS_Tickets_Cobros] " +
                                        " ( " +
                                            " [numero][bigint]NOT NULL, " +
                                            " [idEmpresa] [bigint]NOT NULL, " +
                                            " [idTerminal] [bigint]NOT NULL, " +
                                            " [idSala] [bigint]NOT NULL, " +
                                            " [fechaHora] [datetime]NOT NULL, " +
                                            " [numeroCobro] [int] NOT NULL, " +
                                            " [idTipoPago] [bigint]NULL, " +
                                            " [idCamarero][bigint]NOT NULL, " +
                                            " [idTerminal_DelCobro] [bigint]NOT NULL, " +
                                            " [total] [decimal](18, 2) NOT NULL, " +
                                            " [entregado] [decimal](18, 2) NOT NULL, " +
                                            " [numeroDocumento] [varchar](50) NULL, " +
                                            " [fechaVencimiento][datetime]NULL, " +
                                            " [numeroHabitacion][varchar](10) NULL, " +
                                            " [numeroCuenta][varchar](50) NULL, " +
                                            " [guid][varchar](100) NOT NULL, " +
                                            " [invitacion] [bit]NULL, " +
                                        " CONSTRAINT[PK_HPVS_Tickets_Cobros] PRIMARY KEY CLUSTERED " +
                                        " ( " +
                                            " [numero] ASC, " +
                                            " [idEmpresa] ASC, " +
                                            " [idTerminal] ASC, " +
                                            " [idSala] ASC, " +
                                            " [fechaHora] ASC, " +
                                            " [numeroCobro] ASC " +
                                        " )WITH(PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON[PRIMARY] " +
                                        " ) ON[PRIMARY] " +

                                        //Relaciones
                                        " ALTER TABLE [HPVS_Tickets_Cobros]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Cobros_GEN_Empresas] FOREIGN KEY([idEmpresa])REFERENCES [GEN_Empresas] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Cobros]CHECK CONSTRAINT[FK_HPVS_Tickets_Cobros_GEN_Empresas] " +

                                        " ALTER TABLE [HPVS_Tickets_Cobros]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Cobros_HPV_Camareros] FOREIGN KEY([idCamarero])REFERENCES [HPV_Camareros] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Cobros]CHECK CONSTRAINT[FK_HPVS_Tickets_Cobros_HPV_Camareros] " +

                                        " ALTER TABLE [HPVS_Tickets_Cobros]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Cobros_HPV_Salas] FOREIGN KEY([idSala])REFERENCES [HPV_Salas] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Cobros]CHECK CONSTRAINT[FK_HPVS_Tickets_Cobros_HPV_Salas] " +

                                        " ALTER TABLE [HPVS_Tickets_Cobros]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Cobros_HPV_Terminales] FOREIGN KEY([idTerminal])REFERENCES [HPV_Terminales] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Cobros]CHECK CONSTRAINT[FK_HPVS_Tickets_Cobros_HPV_Terminales] " +

                                        " ALTER TABLE [HPVS_Tickets_Cobros]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Cobros_HPV_Terminales1] FOREIGN KEY([idTerminal_DelCobro])REFERENCES [HPV_Terminales] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Cobros]CHECK CONSTRAINT[FK_HPVS_Tickets_Cobros_HPV_Terminales1] " +

                                        " ALTER TABLE [HPVS_Tickets_Cobros]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Cobros_HPVS_Tickets_Cabecera] FOREIGN KEY([numero], [idEmpresa], [idTerminal], [idSala], [fechaHora])REFERENCES [HPVS_Tickets_Cabecera] ([numero], [idEmpresa], [idTerminal], [idSala], [fechaHora])ON DELETE CASCADE " +
                                        " ALTER TABLE [HPVS_Tickets_Cobros]CHECK CONSTRAINT[FK_HPVS_Tickets_Cobros_HPVS_Tickets_Cabecera] " +

                                        " ALTER TABLE [HPVS_Tickets_Cobros]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Cobros_MAE_TiposPagos] FOREIGN KEY([idTipoPago])REFERENCES [MAE_TiposPagos] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Cobros]CHECK CONSTRAINT[FK_HPVS_Tickets_Cobros_MAE_TiposPagos] " +

                                    " END " +
                                    //CREAR TABLA HPVS_Tickets_Lineas
                                    " IF not exists " +
                                    " ( " +
                                        " SELECT * " +
                                        " FROM INFORMATION_SCHEMA.TABLES " +
                                        " WHERE TABLE_NAME = 'HPVS_Tickets_Lineas' " +
                                    " ) " +
                                    " BEGIN " +
                                        " CREATE TABLE [HPVS_Tickets_Lineas] " +
                                        " ( " +
                                            " [numero][bigint]NOT NULL, " +
                                            " [idEmpresa] [bigint]NOT NULL, " +
                                            " [idTerminal] [bigint]NOT NULL, " +
                                            " [idSala] [bigint]NOT NULL, " +
                                            " [fechaHora] [datetime]NOT NULL, " +
                                            " [linea] [int] NOT NULL, " +
                                            " [idImpuestoTipo] [bigint]NOT NULL, " +
                                            " [idCamarero_Creacion] [bigint]NOT NULL, " +
                                            " [idCamarero_UltimaModificacion] [bigint]NOT NULL, " +
                                            " [idPLV] [bigint]NOT NULL, " +
                                            " [cantidad] [decimal](18, 2) NOT NULL, " +
                                            " [peso] [decimal](18, 3) NULL, " +
                                            " [precio][decimal](18, 3) NOT NULL, " +
                                            " [descuento] [decimal](18, 2) NOT NULL, " +
                                            " [importe] [decimal](18, 2) NOT NULL, " +
                                            " [observaciones] [varchar](200) NULL, " +
                                            " [guid][varchar](100) NOT NULL, " +
                                            " [invitacion] [bit]NULL, " +
                                            " [modificada][bit]NOT NULL, " +
                                        " CONSTRAINT[PK_HPVS_Tickets_Lineas] PRIMARY KEY CLUSTERED " +
                                        " ( " +
                                            " [numero] ASC, " +
                                            " [idEmpresa] ASC, " +
                                            " [idTerminal] ASC, " +
                                            " [idSala] ASC, " +
                                            " [fechaHora] ASC, " +
                                            " [linea] ASC " +
                                        " )WITH(PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON[PRIMARY] " +
                                        " ) ON[PRIMARY] " +

                                        //Relaciones
                                        " ALTER TABLE [HPVS_Tickets_Lineas]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Lineas_GEN_Empresas] FOREIGN KEY([idEmpresa])REFERENCES [GEN_Empresas] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Lineas]CHECK CONSTRAINT[FK_HPVS_Tickets_Lineas_GEN_Empresas] " +

                                        " ALTER TABLE [HPVS_Tickets_Lineas]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Lineas_GEN_ImpuestosTipos] FOREIGN KEY([idImpuestoTipo])REFERENCES [GEN_ImpuestosTipos] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Lineas]CHECK CONSTRAINT[FK_HPVS_Tickets_Lineas_GEN_ImpuestosTipos] " +

                                        " ALTER TABLE [HPVS_Tickets_Lineas]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Lineas_HPV_Camareros] FOREIGN KEY([idCamarero_Creacion])REFERENCES [HPV_Camareros] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Lineas]CHECK CONSTRAINT[FK_HPVS_Tickets_Lineas_HPV_Camareros] " +

                                        " ALTER TABLE [HPVS_Tickets_Lineas]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Lineas_HPV_Camareros1] FOREIGN KEY([idCamarero_UltimaModificacion])REFERENCES [HPV_Camareros] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Lineas]CHECK CONSTRAINT[FK_HPVS_Tickets_Lineas_HPV_Camareros1] " +

                                        " ALTER TABLE [HPVS_Tickets_Lineas]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Lineas_HPV_PLV] FOREIGN KEY([idPLV])REFERENCES [HPV_PLV] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Lineas]CHECK CONSTRAINT[FK_HPVS_Tickets_Lineas_HPV_PLV] " +

                                        " ALTER TABLE [HPVS_Tickets_Lineas]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Lineas_HPV_Salas] FOREIGN KEY([idSala])REFERENCES [HPV_Salas] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Lineas]CHECK CONSTRAINT[FK_HPVS_Tickets_Lineas_HPV_Salas] " +

                                        " ALTER TABLE [HPVS_Tickets_Lineas]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Lineas_HPV_Terminales] FOREIGN KEY([idTerminal])REFERENCES [HPV_Terminales] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Lineas]CHECK CONSTRAINT[FK_HPVS_Tickets_Lineas_HPV_Terminales] " +

                                        " ALTER TABLE [HPVS_Tickets_Lineas]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Lineas_HPVS_Tickets_Cabecera] FOREIGN KEY([numero], [idEmpresa], [idTerminal], [idSala], [fechaHora])REFERENCES [HPVS_Tickets_Cabecera] ([numero], [idEmpresa], [idTerminal], [idSala], [fechaHora])ON DELETE CASCADE " +
                                        " ALTER TABLE [HPVS_Tickets_Lineas]CHECK CONSTRAINT[FK_HPVS_Tickets_Lineas_HPVS_Tickets_Cabecera] " +

                                    " END " +
                                    //CREAR TABLA HPVS_Tickets_Lineas_Caracteristicas
                                    " IF not exists " +
                                    " ( " +
                                        " SELECT * " +
                                        " FROM INFORMATION_SCHEMA.TABLES " +
                                        " WHERE TABLE_NAME = 'HPVS_Tickets_Lineas_Caracteristicas' " +
                                    " ) " +
                                    " BEGIN " +
                                        " CREATE TABLE [HPVS_Tickets_Lineas_Caracteristicas] " +
                                        " ( " +
                                            " [numero][bigint]NOT NULL, " +
                                            " [idEmpresa] [bigint]NOT NULL, " +
                                            " [idTerminal] [bigint]NOT NULL, " +
                                            " [idSala] [bigint]NOT NULL, " +
                                            " [fechaHora] [datetime]NOT NULL, " +
                                            " [linea] [int] NOT NULL, " +
                                            " [idIngrediente] [bigint]NOT NULL, " +
                                            " [lineaCaracteristica] [int] NOT NULL, " +
                                            " [idCaracteristica] [bigint]NULL, " +
                                            " [conMasMenosSin][varchar](1) NULL, " +
                                            " [guid][varchar](100) NOT NULL, " +
                                        " CONSTRAINT[PK_HPVS_Tickets_Lineas_Caracteristicas] PRIMARY KEY CLUSTERED " +
                                        " ( " +
                                            " [numero] ASC, " +
                                            " [idEmpresa] ASC, " +
                                            " [idTerminal] ASC, " +
                                            " [idSala] ASC, " +
                                            " [fechaHora] ASC, " +
                                            " [linea] ASC, " +
                                            " [idIngrediente] ASC, " +
                                            " [lineaCaracteristica] ASC " +
                                        " )WITH(PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON[PRIMARY] " +
                                        " ) ON[PRIMARY] " +

                                        //Relaciones
                                        " ALTER TABLE [HPVS_Tickets_Lineas_Caracteristicas]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Lineas_Caracteristicas_GEN_Empresas] FOREIGN KEY([idEmpresa])REFERENCES [GEN_Empresas] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Lineas_Caracteristicas]CHECK CONSTRAINT[FK_HPVS_Tickets_Lineas_Caracteristicas_GEN_Empresas] " +

                                        " ALTER TABLE [HPVS_Tickets_Lineas_Caracteristicas]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Lineas_Caracteristicas_HPV_Caracteristicas] FOREIGN KEY([idCaracteristica])REFERENCES [HPV_Caracteristicas] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Lineas_Caracteristicas]CHECK CONSTRAINT[FK_HPVS_Tickets_Lineas_Caracteristicas_HPV_Caracteristicas] " +

                                        " ALTER TABLE [HPVS_Tickets_Lineas_Caracteristicas]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Lineas_Caracteristicas_HPV_Ingredientes] FOREIGN KEY([idIngrediente])REFERENCES [HPV_Ingredientes] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Lineas_Caracteristicas]CHECK CONSTRAINT[FK_HPVS_Tickets_Lineas_Caracteristicas_HPV_Ingredientes] " +

                                        " ALTER TABLE [HPVS_Tickets_Lineas_Caracteristicas]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Lineas_Caracteristicas_HPV_Salas] FOREIGN KEY([idSala])REFERENCES [HPV_Salas] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Lineas_Caracteristicas]CHECK CONSTRAINT[FK_HPVS_Tickets_Lineas_Caracteristicas_HPV_Salas] " +

                                        " ALTER TABLE [HPVS_Tickets_Lineas_Caracteristicas]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Lineas_Caracteristicas_HPV_Terminales] FOREIGN KEY([idTerminal])REFERENCES [HPV_Terminales] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Lineas_Caracteristicas]CHECK CONSTRAINT[FK_HPVS_Tickets_Lineas_Caracteristicas_HPV_Terminales] " +

                                        " ALTER TABLE [HPVS_Tickets_Lineas_Caracteristicas]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Lineas_Caracteristicas_HPVS_Tickets_Lineas] FOREIGN KEY([numero], [idEmpresa], [idTerminal], [idSala], [fechaHora], [linea])REFERENCES [HPVS_Tickets_Lineas] ([numero], [idEmpresa], [idTerminal], [idSala], [fechaHora], [linea])ON DELETE CASCADE " +
                                        " ALTER TABLE [HPVS_Tickets_Lineas_Caracteristicas]CHECK CONSTRAINT[FK_HPVS_Tickets_Lineas_Caracteristicas_HPVS_Tickets_Lineas] " +

                                    " END " +
                                    //CREAR TABLA HPVS_Tickets_Lineas_Escandallos
                                    " IF not exists " +
                                    " ( " +
                                        " SELECT * " +
                                        " FROM INFORMATION_SCHEMA.TABLES " +
                                        " WHERE TABLE_NAME = 'HPVS_Tickets_Lineas_Escandallos' " +
                                    " ) " +
                                    " BEGIN " +
                                        " CREATE TABLE [HPVS_Tickets_Lineas_Escandallos] " +
                                        " ( " +
                                            " [numero][bigint]NOT NULL, " +
                                            " [idEmpresa] [bigint]NOT NULL, " +
                                            " [idTerminal] [bigint]NOT NULL, " +
                                            " [idSala] [bigint]NOT NULL, " +
                                            " [fechaHora] [datetime]NOT NULL, " +
                                            " [linea] [int] NOT NULL, " +
                                            " [idSeccionMenu] [bigint]NOT NULL, " +
                                            " [idPLV_Escandallo] [bigint]NOT NULL, " +
                                            " [observaciones] [varchar](200) NULL, " +
                                            " [guid][varchar](100) NOT NULL, " +
                                        " CONSTRAINT[PK_HPVS_Tickets_Lineas_Escandallos] PRIMARY KEY CLUSTERED " +
                                        " ( " +
                                            " [numero] ASC, " +
                                            " [idEmpresa] ASC, " +
                                            " [idTerminal] ASC, " +
                                            " [idSala] ASC, " +
                                            " [fechaHora] ASC, " +
                                            " [linea] ASC, " +
                                            " [idSeccionMenu] ASC " +
                                        " )WITH(PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON[PRIMARY] " +
                                        " ) ON[PRIMARY] " +

                                        //Relaciones
                                        " ALTER TABLE [HPVS_Tickets_Lineas_Escandallos]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Lineas_Escandallos_GEN_Empresas] FOREIGN KEY([idEmpresa])REFERENCES [GEN_Empresas] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Lineas_Escandallos]CHECK CONSTRAINT[FK_HPVS_Tickets_Lineas_Escandallos_GEN_Empresas] " +

                                        " ALTER TABLE [HPVS_Tickets_Lineas_Escandallos]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Lineas_Escandallos_HPV_PLV] FOREIGN KEY([idPLV_Escandallo])REFERENCES [HPV_PLV] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Lineas_Escandallos]CHECK CONSTRAINT[FK_HPVS_Tickets_Lineas_Escandallos_HPV_PLV] " +

                                        " ALTER TABLE [HPVS_Tickets_Lineas_Escandallos]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Lineas_Escandallos_HPV_Salas] FOREIGN KEY([idSala])REFERENCES [HPV_Salas] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Lineas_Escandallos]CHECK CONSTRAINT[FK_HPVS_Tickets_Lineas_Escandallos_HPV_Salas] " +

                                        " ALTER TABLE [HPVS_Tickets_Lineas_Escandallos]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Lineas_Escandallos_HPV_SeccionesMenu] FOREIGN KEY([idSeccionMenu])REFERENCES [HPV_SeccionesMenu] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Lineas_Escandallos]CHECK CONSTRAINT[FK_HPVS_Tickets_Lineas_Escandallos_HPV_SeccionesMenu] " +

                                        " ALTER TABLE [HPVS_Tickets_Lineas_Escandallos]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Lineas_Escandallos_HPV_Terminales] FOREIGN KEY([idTerminal])REFERENCES [HPV_Terminales] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Lineas_Escandallos]CHECK CONSTRAINT[FK_HPVS_Tickets_Lineas_Escandallos_HPV_Terminales] " +

                                        " ALTER TABLE [HPVS_Tickets_Lineas_Escandallos]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Lineas_Escandallos_HPVS_Tickets_Lineas] FOREIGN KEY([numero], [idEmpresa], [idTerminal], [idSala], [fechaHora], [linea])REFERENCES [HPVS_Tickets_Lineas] ([numero], [idEmpresa], [idTerminal], [idSala], [fechaHora], [linea])ON DELETE CASCADE " +
                                        " ALTER TABLE [HPVS_Tickets_Lineas_Escandallos]CHECK CONSTRAINT[FK_HPVS_Tickets_Lineas_Escandallos_HPVS_Tickets_Lineas] " +

                                    " END " +
                                    //CREAR TABLA HPVS_Tickets_Lineas_Escandallos_Caracteristicas
                                    " IF not exists " +
                                    " ( " +
                                        " SELECT * " +
                                        " FROM INFORMATION_SCHEMA.TABLES " +
                                        " WHERE TABLE_NAME = 'HPVS_Tickets_Lineas_Escandallos_Caracteristicas' " +
                                    " ) " +
                                    " BEGIN " +
                                        " CREATE TABLE [HPVS_Tickets_Lineas_Escandallos_Caracteristicas] " +
                                        " ( " +
                                            " [numero][bigint]NOT NULL, " +
                                            " [idEmpresa] [bigint]NOT NULL, " +
                                            " [idTerminal] [bigint]NOT NULL, " +
                                            " [idSala] [bigint]NOT NULL, " +
                                            " [fechaHora] [datetime]NOT NULL, " +
                                            " [linea] [int] NOT NULL, " +
                                            " [idSeccionMenu] [bigint]NOT NULL, " +
                                            " [idIngrediente] [bigint]NOT NULL, " +
                                            " [lineaCaracteristica] [int] NOT NULL, " +
                                            " [idCaracteristica] [bigint]NULL, " +
                                            " [conMasMenosSin][varchar](1) NULL, " +
                                            " [guid][varchar](100) NOT NULL, " +
                                        " CONSTRAINT[PK_HPVS_Tickets_Lineas_Escandallos_Caracteristicas] PRIMARY KEY CLUSTERED " +
                                        " ( " +
                                            " [numero] ASC, " +
                                            " [idEmpresa] ASC, " +
                                            " [idTerminal] ASC, " +
                                            " [idSala] ASC, " +
                                            " [fechaHora] ASC, " +
                                            " [linea] ASC, " +
                                            " [idSeccionMenu] ASC, " +
                                            " [idIngrediente] ASC, " +
                                            " [lineaCaracteristica] ASC " +
                                        " )WITH(PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON[PRIMARY] " +
                                        " ) ON[PRIMARY] " +

                                        //Relaciones
                                        " ALTER TABLE [HPVS_Tickets_Lineas_Escandallos_Caracteristicas]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Lineas_Escandallos_Caracteristicas_GEN_Empresas] FOREIGN KEY([idEmpresa])REFERENCES [GEN_Empresas] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Lineas_Escandallos_Caracteristicas]CHECK CONSTRAINT[FK_HPVS_Tickets_Lineas_Escandallos_Caracteristicas_GEN_Empresas] " +

                                        " ALTER TABLE [HPVS_Tickets_Lineas_Escandallos_Caracteristicas]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Lineas_Escandallos_Caracteristicas_HPV_Caracteristicas] FOREIGN KEY([idCaracteristica])REFERENCES [HPV_Caracteristicas] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Lineas_Escandallos_Caracteristicas]CHECK CONSTRAINT[FK_HPVS_Tickets_Lineas_Escandallos_Caracteristicas_HPV_Caracteristicas] " +

                                        " ALTER TABLE [HPVS_Tickets_Lineas_Escandallos_Caracteristicas]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Lineas_Escandallos_Caracteristicas_HPV_Terminales] FOREIGN KEY([idTerminal])REFERENCES [HPV_Terminales] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Lineas_Escandallos_Caracteristicas]CHECK CONSTRAINT[FK_HPVS_Tickets_Lineas_Escandallos_Caracteristicas_HPV_Terminales] " +

                                        " ALTER TABLE [HPVS_Tickets_Lineas_Escandallos_Caracteristicas]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Lineas_Escandallos_Caracteristicas_HPV_Ingredientes] FOREIGN KEY([idIngrediente])REFERENCES [HPV_Ingredientes] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Lineas_Escandallos_Caracteristicas]CHECK CONSTRAINT[FK_HPVS_Tickets_Lineas_Escandallos_Caracteristicas_HPV_Ingredientes] " +

                                        " ALTER TABLE [HPVS_Tickets_Lineas_Escandallos_Caracteristicas]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Lineas_Escandallos_Caracteristicas_HPV_Salas] FOREIGN KEY([idSala])REFERENCES [HPV_Salas] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Lineas_Escandallos_Caracteristicas]CHECK CONSTRAINT[FK_HPVS_Tickets_Lineas_Escandallos_Caracteristicas_HPV_Salas] " +

                                        " ALTER TABLE [HPVS_Tickets_Lineas_Escandallos_Caracteristicas]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Lineas_Escandallos_Caracteristicas_HPV_SeccionesMenu] FOREIGN KEY([idSeccionMenu])REFERENCES [HPV_SeccionesMenu] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Lineas_Escandallos_Caracteristicas]CHECK CONSTRAINT[FK_HPVS_Tickets_Lineas_Escandallos_Caracteristicas_HPV_SeccionesMenu] " +

                                        " ALTER TABLE [HPVS_Tickets_Lineas_Escandallos_Caracteristicas]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Lineas_Escandallos_Caracteristicas_HPVS_Tickets_Lineas_Escandallos] FOREIGN KEY([numero], [idEmpresa], [idTerminal], [idSala], [fechaHora], [linea], [idSeccionMenu])REFERENCES [HPVS_Tickets_Lineas_Escandallos] ([numero], [idEmpresa], [idTerminal], [idSala], [fechaHora], [linea], [idSeccionMenu])ON DELETE CASCADE " +
                                        " ALTER TABLE [HPVS_Tickets_Lineas_Escandallos_Caracteristicas]CHECK CONSTRAINT[FK_HPVS_Tickets_Lineas_Escandallos_Caracteristicas_HPVS_Tickets_Lineas_Escandallos] " +

                                    " END " +
                                    //CREAR TABLA HPVS_Tickets_Resumen
                                    " IF not exists " +
                                    " ( " +
                                        " SELECT * " +
                                        " FROM INFORMATION_SCHEMA.TABLES " +
                                        " WHERE TABLE_NAME = 'HPVS_Tickets_Resumen' " +
                                    " ) " +
                                    " BEGIN " +
                                        " CREATE TABLE [HPVS_Tickets_Resumen] " +
                                        " ( " +
                                            " [numero][bigint]NOT NULL, " +
                                            " [idEmpresa] [bigint]NOT NULL, " +
                                            " [idTerminal] [bigint]NOT NULL, " +
                                            " [idSala] [bigint]NOT NULL, " +
                                            " [fechaHora] [datetime]NOT NULL, " +
                                            " [idImpuestoTipo] [bigint]NOT NULL, " +
                                            " [idImpuestoLinea] [bigint]NOT NULL, " +
                                            " [bruto] [decimal](18, 2) NOT NULL, " +
                                            " [baseImponible] [decimal](18, 2) NOT NULL, " +
                                            " [impuesto_Porcentaje] [decimal](18, 2) NOT NULL, " +
                                            " [impuesto_Valor] [decimal](18, 2) NOT NULL, " +
                                            " [recargo_Porcentaje] [decimal](18, 2) NOT NULL, " +
                                            " [recargo_Valor] [decimal](18, 2) NOT NULL, " +
                                            " [total] [decimal](18, 2) NOT NULL, " +
                                            " [guid] [varchar](100) NOT NULL, " +
                                        " CONSTRAINT[PK_HPVS_Tickets_Resumen] PRIMARY KEY CLUSTERED " +
                                        " ( " +
                                            " [numero] ASC, " +
                                            " [idEmpresa] ASC, " +
                                            " [idTerminal] ASC, " +
                                            " [idSala] ASC, " +
                                            " [fechaHora] ASC, " +
                                            " [idImpuestoTipo] ASC, " +
                                            " [idImpuestoLinea] ASC " +
                                        " )WITH(PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON[PRIMARY] " +
                                        " ) ON[PRIMARY] " +

                                        //Relaciones
                                        " ALTER TABLE [HPVS_Tickets_Resumen]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Resumen_GEN_Empresas] FOREIGN KEY([idEmpresa])REFERENCES [GEN_Empresas] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Resumen]CHECK CONSTRAINT[FK_HPVS_Tickets_Resumen_GEN_Empresas] " +

                                        " ALTER TABLE [HPVS_Tickets_Resumen]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Resumen_GEN_ImpuestosLineas] FOREIGN KEY([idImpuestoLinea])REFERENCES [GEN_ImpuestosLineas] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Resumen]CHECK CONSTRAINT[FK_HPVS_Tickets_Resumen_GEN_ImpuestosLineas] " +

                                        " ALTER TABLE [HPVS_Tickets_Resumen]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Resumen_GEN_ImpuestosTipos] FOREIGN KEY([idImpuestoTipo])REFERENCES [GEN_ImpuestosTipos] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Resumen]CHECK CONSTRAINT[FK_HPVS_Tickets_Resumen_GEN_ImpuestosTipos] " +

                                        " ALTER TABLE [HPVS_Tickets_Resumen]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Resumen_HPV_Salas] FOREIGN KEY([idSala])REFERENCES [HPV_Salas] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Resumen]CHECK CONSTRAINT[FK_HPVS_Tickets_Resumen_HPV_Salas] " +

                                        " ALTER TABLE [HPVS_Tickets_Resumen]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Resumen_HPV_Terminales] FOREIGN KEY([idTerminal])REFERENCES [HPV_Terminales] ([id]) " +
                                        " ALTER TABLE [HPVS_Tickets_Resumen]CHECK CONSTRAINT[FK_HPVS_Tickets_Resumen_HPV_Terminales] " +

                                        " ALTER TABLE [HPVS_Tickets_Resumen]WITH CHECK ADD CONSTRAINT[FK_HPVS_Tickets_Resumen_HPVS_Tickets_Cabecera] FOREIGN KEY([numero], [idEmpresa], [idTerminal], [idSala], [fechaHora])REFERENCES [HPVS_Tickets_Cabecera] ([numero], [idEmpresa], [idTerminal], [idSala], [fechaHora])ON DELETE CASCADE " +
                                        " ALTER TABLE [HPVS_Tickets_Resumen]CHECK CONSTRAINT[FK_HPVS_Tickets_Resumen_HPVS_Tickets_Cabecera] " +

                                    " END " ;

    }
}
