
/*Tabla*/
if not exists(select * FROM INFORMATION_SCHEMA.TABLES  where Table_Name='gen_localizacion')
EXEC _ini_creartabla 'gen_localizacion', 1
go
if not exists(select * FROM INFORMATION_SCHEMA.TABLES  where Table_Name='gen_localizacion_itemDocumento')
EXEC _ini_creartabla 'gen_localizacion_itemDocumento', 1
go
/*columnas*/
if not exists(select * FROM INFORMATION_SCHEMA.COLUMNS  where Table_Name='gen_localizacion' and column_name = 'id_catalogo_bodega' )
begin
alter table [gen_localizacion] add [id_catalogo_bodega] int  NOT NULL DEFAULT 0
end

if not exists(select * FROM INFORMATION_SCHEMA.COLUMNS  where Table_Name='gen_localizacion' and column_name = 'existencia' )
begin
alter table [gen_localizacion] add [existencia] int  NOT NULL DEFAULT 0
end

if not exists(select * FROM INFORMATION_SCHEMA.COLUMNS  where Table_Name='gen_localizacion' and column_name = 'existenciaMaxima' )
begin
alter table [gen_localizacion] add [existenciaMaxima] int  NOT NULL DEFAULT 0
end

/*columnas gen_localizacion_itemDocumento*/

if not exists(select * FROM INFORMATION_SCHEMA.COLUMNS  where Table_Name='gen_localizacion_itemDocumento' and column_name = 'id_localizacion' )
begin
alter table [gen_localizacion_itemDocumento] add [id_localizacion] int  NOT NULL DEFAULT 0
end

if not exists(select * FROM INFORMATION_SCHEMA.COLUMNS  where Table_Name='gen_localizacion_itemDocumento' and column_name = 'id_itemDocumento' )
begin
alter table [gen_localizacion_itemDocumento] add [id_itemDocumento] int  NOT NULL DEFAULT 0
end

if not exists(select * FROM INFORMATION_SCHEMA.COLUMNS  where Table_Name='gen_localizacion_itemDocumento' and column_name = 'cantidad' )
begin
alter table [gen_localizacion_itemDocumento] add [cantidad] int  NOT NULL DEFAULT 0
end

/*gen_bodega*/
if not exists(select * FROM INFORMATION_SCHEMA.COLUMNS  where Table_Name='gen_bodega' and column_name = 'usaLocalizacion' )
begin
alter table [gen_bodega] add [usaLocalizacion] bit  NOT NULL DEFAULT 0
end


/*tabla tablas y columnas*/


IF NOT EXISTS(SELECT * FROM [_tablas] WHERE[tabla]='gen_localizacion')
BEGIN

insert into _tablas (tabla,esMultiempresa,duplicar,eliminarIntermedias)values
('gen_localizacion',1,0,0)

END

GO

IF NOT EXISTS(SELECT * FROM [_columnas] WHERE[tabla]='gen_localizacion')
BEGIN
insert into _columnas (tabla,columna,mostrarEnGrilla,ordenGrilla,requerido,tipo,defecto,tamano )values
('gen_localizacion','localizacion',1,1,1,'varchar','',300);

insert into _columnas (tabla,columna,mostrarEnGrilla,ordenGrilla,requerido,tipo,defecto,tamano )values
('gen_localizacion','localizacion_codigo',1,1,1,'varchar','',300);

insert into _columnas (tabla,columna,mostrarEnGrilla,ordenGrilla,requerido,tipo,defecto,tamano )values
('gen_localizacion','id_catalogo_bodega',1,1,1,'int','((0))',NULL);

insert into _columnas (tabla,columna,mostrarEnGrilla,ordenGrilla,requerido,tipo,defecto,tamano )values
('gen_localizacion','existencia',1,1,1,'float','((0))',300);

insert into _columnas (tabla,columna,mostrarEnGrilla,ordenGrilla,requerido,tipo,defecto,tamano )values
('gen_localizacion','existenciaMaxima',1,1,1,'float','((0))',300);

END





