Modelo ahora soporta Cajas y arqueo

This commit is contained in:
2021-05-01 00:47:20 -04:00
parent 3869f76e10
commit cc71f05a57
3 changed files with 153 additions and 53 deletions

View File

@@ -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.

View File

@@ -1,3 +1,38 @@
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,
@@ -123,6 +158,7 @@ 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,
@@ -185,12 +221,49 @@ create table canales_venta (
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,
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
@@ -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;