Modelo ahora soporta Cajas y arqueo
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
start transaction;
|
||||
|
||||
-----------------------------------
|
||||
--- Inserts basicos
|
||||
-----------------------------------
|
||||
@@ -12,6 +14,11 @@ insert into tipos_canal (nombre)
|
||||
values ('Mesa'),
|
||||
('Delivery');
|
||||
|
||||
insert into medios_pago (nombre)
|
||||
values ('Efectivo'),
|
||||
('Tarjeta de Credito'),
|
||||
('Tarjeta de Debito');
|
||||
|
||||
-----------------------------------
|
||||
--- Creando restaurant de prueba
|
||||
-----------------------------------
|
||||
@@ -47,13 +54,22 @@ values ('Cocina', (select id from restaurantes where nombre = 'Todo Rico Restaur
|
||||
('Barra', (select id from restaurantes where nombre = 'Todo Rico Restaurant'));
|
||||
|
||||
insert into usuarios (auth0_id, nombre)
|
||||
values ('123456', 'Mesero');
|
||||
values ('auth0|6083af726b4de900695cb232', 'Test');
|
||||
|
||||
insert into usuarios_restaurantes (usuario_id, restaurante_id)
|
||||
values ((select id from usuarios where nombre = 'Mesero'), (select id from restaurantes where nombre = 'Todo Rico Restaurant'));
|
||||
values ((select id from usuarios where nombre = 'Test'), (select id from restaurantes where nombre = 'Todo Rico Restaurant'));
|
||||
|
||||
insert into productores (usuario_id, zona_produccion_id)
|
||||
values ((select id from usuarios where nombre = 'Mesero'), (select id from zonas_produccion where nombre = 'Cocina'));
|
||||
values ((select id from usuarios where nombre = 'Test'), (select id from zonas_produccion where nombre = 'Cocina'));
|
||||
|
||||
insert into recaudadores (usuario_id)
|
||||
values ((select id from usuarios where nombre = 'Test'));
|
||||
|
||||
insert into meseros (usuario_id)
|
||||
values ((select id from usuarios where nombre = 'Test'));
|
||||
|
||||
insert into administradores (usuario_id)
|
||||
values ((select id from usuarios where nombre = 'Test'));
|
||||
|
||||
-----------------------------------
|
||||
--- Inventando ingredientes y productos de venta
|
||||
@@ -129,9 +145,15 @@ values ('1', 500 * 20, 500 * 20 * 1.19, '2021-01-01'::date, '2021-01-30'::date,
|
||||
--- Creando ventas para descontar del inventario
|
||||
-----------------------------------
|
||||
|
||||
insert into ventas (tiempo_venta, mesero_id, canal_id, restaurante_id)
|
||||
values (current_timestamp, (select id from meseros limit 1), (select id from canales_venta where nombre = '1'),
|
||||
(select id from restaurantes where nombre = 'Todo Rico Restaurant'));
|
||||
insert into cajas (fondo, apertura, cierre) values (200000, '2021-02-01'::timestamptz, null);
|
||||
|
||||
insert into ventas (tiempo_venta, mesero_id, canal_id, restaurante_id, medio_pago_id, caja_id)
|
||||
values (current_timestamp,
|
||||
(select id from meseros limit 1),
|
||||
(select id from canales_venta where nombre = '1'),
|
||||
(select id from restaurantes where nombre = 'Todo Rico Restaurant'),
|
||||
(select id from medios_pago where nombre = 'Efectivo'),
|
||||
(select id from cajas limit 1));
|
||||
|
||||
insert into venta_productos (tiempo_entrada, tiempo_salida, venta_id, producto_id, estado_id)
|
||||
values (current_timestamp, null, (select id from ventas limit 1), (select id from productos where nombre = 'Coca-Cola'),
|
||||
@@ -146,3 +168,5 @@ values (current_timestamp, null, (select id from ventas limit 1), (select id fro
|
||||
(select id from estados_produccion where nombre = 'Enviada')),
|
||||
(current_timestamp, null, (select id from ventas limit 1), (select id from productos where nombre = 'Chuleta con Pure'),
|
||||
(select id from estados_produccion where nombre = 'Enviada'));
|
||||
|
||||
commit;
|
||||
Binary file not shown.
@@ -1,16 +1,51 @@
|
||||
start transaction;
|
||||
|
||||
drop view if exists bodega_egresos cascade;
|
||||
drop view if exists bodega_ingresos cascade;
|
||||
drop view if exists bodega_movimientos cascade;
|
||||
drop view if exists bodega_actual cascade;
|
||||
|
||||
drop table if exists usuarios_restaurantes cascade;
|
||||
drop table if exists productores cascade;
|
||||
drop table if exists recaudadores cascade;
|
||||
drop table if exists administradores cascade;
|
||||
drop table if exists recetas cascade;
|
||||
drop table if exists facturas cascade;
|
||||
drop table if exists compra_ingredientes cascade;
|
||||
drop table if exists ingredientes cascade;
|
||||
drop table if exists compras cascade;
|
||||
drop table if exists proveedores cascade;
|
||||
drop table if exists efectivos cascade;
|
||||
drop table if exists boletas_electronicas cascade;
|
||||
drop table if exists boletas_exentas cascade;
|
||||
drop table if exists venta_productos cascade;
|
||||
drop table if exists productos cascade;
|
||||
drop table if exists categorias cascade;
|
||||
drop table if exists zonas_produccion cascade;
|
||||
drop table if exists ventas cascade;
|
||||
drop table if exists meseros cascade;
|
||||
drop table if exists usuarios cascade;
|
||||
drop table if exists canales_venta cascade;
|
||||
drop table if exists sectores cascade;
|
||||
drop table if exists restaurantes cascade;
|
||||
drop table if exists tipos_canal cascade;
|
||||
drop table if exists medios_pago cascade;
|
||||
drop table if exists cajas cascade;
|
||||
drop table if exists estados_produccion cascade;
|
||||
|
||||
create table restaurantes (
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
nombre text not null,
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
nombre text not null,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp,
|
||||
deleted_at timestamptz
|
||||
updated_at timestamptz not null default current_timestamp,
|
||||
deleted_at timestamptz
|
||||
);
|
||||
|
||||
create table categorias (
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
nombre text not null,
|
||||
restaurante_id uuid references restaurantes,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp,
|
||||
deleted_at timestamptz
|
||||
);
|
||||
@@ -19,24 +54,24 @@ create table zonas_produccion (
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
nombre text not null,
|
||||
restaurante_id uuid references restaurantes,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp,
|
||||
deleted_at timestamptz
|
||||
);
|
||||
|
||||
create table usuarios (
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
auth0_id text not null,
|
||||
nombre text not null,
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
auth0_id text not null,
|
||||
nombre text not null,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp,
|
||||
deleted_at timestamptz
|
||||
updated_at timestamptz not null default current_timestamp,
|
||||
deleted_at timestamptz
|
||||
);
|
||||
|
||||
create table usuarios_restaurantes (
|
||||
usuario_id uuid references usuarios,
|
||||
restaurante_id uuid references restaurantes,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp,
|
||||
deleted_at timestamptz,
|
||||
primary key (usuario_id, restaurante_id)
|
||||
@@ -46,33 +81,33 @@ create table productores (
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
usuario_id uuid references usuarios,
|
||||
zona_produccion_id uuid references zonas_produccion,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp,
|
||||
deleted_at timestamptz
|
||||
);
|
||||
|
||||
create table recaudadores (
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
usuario_id uuid references usuarios,
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
usuario_id uuid references usuarios,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp,
|
||||
deleted_at timestamptz
|
||||
updated_at timestamptz not null default current_timestamp,
|
||||
deleted_at timestamptz
|
||||
);
|
||||
|
||||
create table meseros (
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
usuario_id uuid references usuarios,
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
usuario_id uuid references usuarios,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp,
|
||||
deleted_at timestamptz
|
||||
updated_at timestamptz not null default current_timestamp,
|
||||
deleted_at timestamptz
|
||||
);
|
||||
|
||||
create table administradores (
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
usuario_id uuid references usuarios,
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
usuario_id uuid references usuarios,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp,
|
||||
deleted_at timestamptz
|
||||
updated_at timestamptz not null default current_timestamp,
|
||||
deleted_at timestamptz
|
||||
);
|
||||
|
||||
create table ingredientes (
|
||||
@@ -80,7 +115,7 @@ create table ingredientes (
|
||||
nombre text not null,
|
||||
medida text not null,
|
||||
restaurante_id uuid references restaurantes,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp,
|
||||
deleted_at timestamptz
|
||||
);
|
||||
@@ -92,7 +127,7 @@ create table productos (
|
||||
categoria_id uuid references categorias,
|
||||
zona_produccion_id uuid references zonas_produccion,
|
||||
restaurante_id uuid references restaurantes,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp,
|
||||
deleted_at timestamptz
|
||||
);
|
||||
@@ -101,7 +136,7 @@ create table recetas (
|
||||
producto_id uuid references productos,
|
||||
ingrediente_id uuid references ingredientes,
|
||||
unidades numeric not null,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp,
|
||||
deleted_at timestamptz,
|
||||
primary key (producto_id, ingrediente_id)
|
||||
@@ -115,7 +150,7 @@ create table proveedores (
|
||||
direccion text null,
|
||||
telefono text null,
|
||||
restaurante_id uuid references restaurantes,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp,
|
||||
deleted_at timestamptz
|
||||
);
|
||||
@@ -123,9 +158,10 @@ create table proveedores (
|
||||
create table compras (
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
fecha_compra date not null,
|
||||
en_arqueo bool not null default true,
|
||||
proveedor_id uuid references proveedores,
|
||||
restaurante_id uuid references restaurantes,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp,
|
||||
deleted_at timestamptz
|
||||
);
|
||||
@@ -140,7 +176,7 @@ create table facturas (
|
||||
fecha_emision date not null,
|
||||
fecha_vencimiento date not null,
|
||||
compra_id uuid references compras,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp,
|
||||
deleted_at timestamptz
|
||||
);
|
||||
@@ -152,7 +188,7 @@ create table compra_ingredientes (
|
||||
monto_unitario_neto bigint not null,
|
||||
compra_id uuid references compras,
|
||||
ingrediente_id uuid references ingredientes,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp,
|
||||
deleted_at timestamptz
|
||||
);
|
||||
@@ -161,17 +197,17 @@ create table sectores (
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
nombre text not null,
|
||||
restaurante_id uuid references restaurantes,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp,
|
||||
deleted_at timestamptz
|
||||
);
|
||||
|
||||
create table tipos_canal (
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
nombre text not null,
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
nombre text not null,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp,
|
||||
deleted_at timestamptz
|
||||
updated_at timestamptz not null default current_timestamp,
|
||||
deleted_at timestamptz
|
||||
);
|
||||
|
||||
create table canales_venta (
|
||||
@@ -180,18 +216,55 @@ create table canales_venta (
|
||||
sector_id uuid references sectores,
|
||||
tipo_canal_id uuid references tipos_canal,
|
||||
restaurante_id uuid references restaurantes,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp,
|
||||
deleted_at timestamptz
|
||||
);
|
||||
|
||||
create table medios_pago (
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
nombre text not null,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp,
|
||||
deleted_at timestamptz
|
||||
);
|
||||
|
||||
create table cajas (
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
fondo bigint not null,
|
||||
apertura timestamptz not null,
|
||||
cierre timestamptz,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp,
|
||||
deleted_at timestamptz
|
||||
);
|
||||
|
||||
create table efectivos (
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
veinte_mil bigint not null,
|
||||
diez_mil bigint not null,
|
||||
cinco_mil bigint not null,
|
||||
dos_mil bigint not null,
|
||||
mil bigint not null,
|
||||
quinientos bigint not null,
|
||||
cien bigint not null,
|
||||
cincuenta bigint not null,
|
||||
diez bigint not null,
|
||||
caja_id uuid references cajas,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp,
|
||||
deleted_at timestamptz
|
||||
);
|
||||
|
||||
create table ventas (
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
tiempo_venta timestamptz,
|
||||
mesero_id uuid references meseros,
|
||||
canal_id uuid references canales_venta,
|
||||
restaurante_id uuid references restaurantes,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
medio_pago_id uuid references medios_pago,
|
||||
caja_id uuid references cajas,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp,
|
||||
deleted_at timestamptz
|
||||
);
|
||||
@@ -201,7 +274,7 @@ create table boletas_electronicas (
|
||||
numero_boleta text not null,
|
||||
venta_id uuid references ventas,
|
||||
restaurante_id uuid references restaurantes,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp,
|
||||
deleted_at timestamptz
|
||||
);
|
||||
@@ -210,17 +283,17 @@ create table boletas_exentas (
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
venta_id uuid references ventas,
|
||||
restaurante_id uuid references restaurantes,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp,
|
||||
deleted_at timestamptz
|
||||
);
|
||||
|
||||
create table estados_produccion (
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
nombre text not null,
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
nombre text not null,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp,
|
||||
deleted_at timestamptz
|
||||
updated_at timestamptz not null default current_timestamp,
|
||||
deleted_at timestamptz
|
||||
);
|
||||
|
||||
create table venta_productos (
|
||||
@@ -230,7 +303,7 @@ create table venta_productos (
|
||||
venta_id uuid references ventas,
|
||||
producto_id uuid references productos,
|
||||
estado_id uuid references estados_produccion,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
created_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp,
|
||||
deleted_at timestamptz
|
||||
);
|
||||
@@ -284,6 +357,7 @@ from ventas
|
||||
join venta_productos on ventas.id = venta_productos.venta_id
|
||||
join productos on venta_productos.producto_id = productos.id
|
||||
join recetas on productos.id = recetas.producto_id;
|
||||
|
||||
--- View para obtener la lista de ingresos a bodega
|
||||
create view bodega_ingresos as
|
||||
select compra_ingredientes.ingrediente_id as ingrediente_id,
|
||||
@@ -306,3 +380,5 @@ create view bodega_actual as
|
||||
select ingrediente_id as ingrediente_id, sum(unidades) as stock, restaurante_id as restaurante_id
|
||||
from bodega_movimientos
|
||||
group by bodega_movimientos.ingrediente_id, bodega_movimientos.restaurante_id;
|
||||
|
||||
commit;
|
||||
Reference in New Issue
Block a user