Files
Repuestera/docs/diagramas/plantuml/diagrama-entidad-relacion.puml

423 lines
11 KiB
Plaintext

@startuml
!theme plain
top to bottom direction
skinparam linetype ortho
skinparam packageStyle rectangle
title Diagrama Entidad-Relación (DER) - Base de Datos MySQL
package "Módulo Usuarios, Empresas y Accesos" {
entity "empresas" as empresas {
* id : bigint unsigned <<PK>>
--
nombre : varchar(120)
slug : varchar(60) <<UQ>>
cuit : varchar(11) <<UQ>>
activa : tinyint(1)
created_at : datetime(3)
updated_at : datetime(3)
deleted_at : datetime(3)
}
entity "usuarios" as usuarios {
* id : bigint unsigned <<PK>>
--
email : varchar(100) <<UQ>>
password : longtext
name : longtext
activo : tinyint(1)
debe_cambiar_password : tinyint(1)
created_at : datetime(3)
updated_at : datetime(3)
deleted_at : datetime(3)
}
entity "empresa_usuarios" as empresa_usuarios {
* usuario_id : bigint unsigned <<PK, FK>>
* empresa_id : bigint unsigned <<PK, FK>>
--
rol : varchar(20)
activo : tinyint(1)
created_at : datetime(3)
updated_at : datetime(3)
}
entity "plataforma_admins" as plataforma_admins {
* usuario_id : bigint unsigned <<PK, FK>>
--
rol : varchar(20)
activo : tinyint(1)
created_at : datetime(3)
updated_at : datetime(3)
}
entity "invitaciones_empresa" as invitaciones_empresa {
* id : bigint unsigned <<PK>>
--
empresa_id : bigint unsigned <<FK>>
email : varchar(100)
rol : varchar(20)
token_hash : varchar(64) <<UQ>>
expira_en : datetime(3)
usada_en : datetime(3)
creada_por : bigint unsigned
grupo_id : bigint unsigned
created_at : datetime(3)
}
}
package "Módulo Roles, Grupos y Permisos" {
entity "groupos" as groupos {
* id : bigint unsigned <<PK>>
--
nombre : varchar(100)
descripcion : text
imagen : varchar(500)
empresa_id : bigint unsigned
created_at : datetime(3)
updated_at : datetime(3)
deleted_at : datetime(3)
}
entity "permisos" as permisos {
* id : bigint unsigned <<PK>>
--
nombre : varchar(100) <<UQ>>
alias : varchar(100) <<UQ>>
descripcion : text
imagen : varchar(500)
created_at : datetime(3)
updated_at : datetime(3)
deleted_at : datetime(3)
}
entity "grupo_permisos" as grupo_permisos {
* grupo_id : bigint unsigned <<PK, FK>>
* permiso_id : bigint unsigned <<PK, FK>>
}
entity "grupo_grupos" as grupo_grupos {
* parent_group_id : bigint unsigned <<PK, FK>>
* child_group_id : bigint unsigned <<PK, FK>>
}
entity "usuarios_grupos" as usuarios_grupos {
* usuario_id : bigint unsigned <<PK, FK>>
* grupo_id : bigint unsigned <<PK, FK>>
}
}
package "Módulo Inventario y Almacenes" {
entity "marca" as marca {
* id : bigint unsigned <<PK>>
--
nombre : varchar(70)
empresa_id : bigint unsigned
created_at : datetime(3)
updated_at : datetime(3)
deleted_at : datetime(3)
}
entity "repuesto" as repuesto {
* id : bigint unsigned <<PK>>
--
nombre : varchar(50)
precio : decimal(10,2)
stock_minimo : bigint
descripcion : varchar(70)
marcaID : bigint unsigned <<FK>>
aliases : json
empresa_id : bigint unsigned
created_at : datetime(3)
updated_at : datetime(3)
deleted_at : datetime(3)
}
entity "almacen" as almacen {
* id : bigint unsigned <<PK>>
--
empresa_id : bigint unsigned
codigo : varchar(5)
ubicacion : varchar(40)
}
entity "stock" as stock {
* id : bigint unsigned <<PK>>
--
repuesto_id : bigint unsigned <<FK>>
almacen_id : bigint unsigned <<FK>>
cantidad : bigint unsigned
cantidad_reservada : bigint unsigned
observacion : varchar(60)
movmientos : json
empresa_id : bigint unsigned
}
entity "reservas" as reservas {
* id : bigint unsigned <<PK>>
--
repuesto_id : bigint unsigned <<FK>>
almacen_id : bigint unsigned <<FK>>
cliente_id : bigint unsigned <<FK>>
cantidad : double
estado : varchar(20)
fecha_vencimiento : datetime(3)
empresa_id : bigint unsigned
created_at : datetime(3)
updated_at : datetime(3)
deleted_at : datetime(3)
}
}
package "Módulo Ventas, Compras y Comprobantes" {
entity "clientes" as clientes {
* id : bigint unsigned <<PK>>
--
nombre : varchar(40)
cuit : varchar(11)
email : varchar(80)
empresa_id : bigint unsigned
created_at : datetime(3)
updated_at : datetime(3)
deleted_at : datetime(3)
}
entity "proveedors" as proveedors {
* id : bigint unsigned <<PK>>
--
nombre : varchar(40)
empresa_id : bigint unsigned
created_at : datetime(3)
updated_at : datetime(3)
deleted_at : datetime(3)
}
entity "orden_compra" as orden_compra {
* id : bigint unsigned <<PK>>
--
proveedorID : bigint unsigned <<FK>>
usuarioID : bigint unsigned <<FK>>
estado : varchar(20)
total : decimal(15,2)
detalles : json
empresa_id : bigint unsigned
created_at : datetime(3)
updated_at : datetime(3)
deleted_at : datetime(3)
}
entity "factura" as factura {
* id : bigint unsigned <<PK>>
--
ClienteID : bigint unsigned <<FK>>
usuarioID : bigint unsigned <<FK>>
proveedor_id : bigint unsigned <<FK>>
estado : varchar(20)
total : decimal(15,2)
se_aviso : tinyint(1)
detalles : json
empresa_id : bigint unsigned
created_at : datetime(3)
updated_at : datetime(3)
deleted_at : datetime(3)
}
entity "devolucion" as devolucion {
* id : bigint unsigned <<PK>>
--
facturaOrigenID : bigint unsigned <<FK>>
usuarioID : bigint unsigned <<FK>>
estado : varchar(20)
total : decimal(15,2)
motivo : varchar(200)
empresa_id : bigint unsigned
created_at : datetime(3)
updated_at : datetime(3)
deleted_at : datetime(3)
}
entity "nota_credito" as nota_credito {
* id : bigint unsigned <<PK>>
--
facturaID : bigint unsigned <<FK>>
usuarioID : bigint unsigned <<FK>>
estado : varchar(20)
total : decimal(15,2)
motivo : varchar(40)
empresa_id : bigint unsigned
created_at : datetime(3)
updated_at : datetime(3)
deleted_at : datetime(3)
}
entity "nota_debito" as nota_debito {
* id : bigint unsigned <<PK>>
--
facturaID : bigint unsigned <<FK>>
usuarioID : bigint unsigned <<FK>>
estado : varchar(20)
total : decimal(15,2)
motivo : varchar(40)
empresa_id : bigint unsigned
created_at : datetime(3)
updated_at : datetime(3)
deleted_at : datetime(3)
}
entity "recibo" as recibo {
* id : bigint unsigned <<PK>>
--
cliente_id : bigint unsigned <<FK>>
usuarioID : bigint unsigned <<FK>>
estado : varchar(20)
total : decimal(15,2)
empresa_id : bigint unsigned
created_at : datetime(3)
updated_at : datetime(3)
deleted_at : datetime(3)
}
entity "forma_de_pago" as forma_de_pago {
* id : bigint unsigned <<PK>>
--
descripcion : varchar(20)
empresa_id : bigint unsigned
created_at : datetime(3)
updated_at : datetime(3)
deleted_at : datetime(3)
}
entity "pago" as pago {
* id : bigint unsigned <<PK>>
--
formaDePagoID : bigint unsigned <<FK>>
recibo_id : bigint unsigned <<FK>>
importe : decimal(10,2)
empresa_id : bigint unsigned
created_at : datetime(3)
updated_at : datetime(3)
deleted_at : datetime(3)
}
entity "remitos" as remitos {
* id : bigint unsigned <<PK>>
--
almacen_origen_id : bigint unsigned <<FK>>
usuarioID : bigint unsigned <<FK>>
estado : varchar(20)
total : decimal(15,2)
fecha_emision : datetime(3)
tipo_operacion : varchar(20)
emisor_id : bigint unsigned
receptor_id : bigint unsigned
detalles : json
empresa_id : bigint unsigned
created_at : datetime(3)
updated_at : datetime(3)
deleted_at : datetime(3)
}
}
package "Módulo Contabilidad y Auditoría" {
entity "asiento_contables" as asiento_contables {
* id : bigint unsigned <<PK>>
--
comprobante_tipo : varchar(20)
comprobante_id : bigint unsigned
empresa_id : bigint unsigned
created_at : datetime(3)
updated_at : datetime(3)
deleted_at : datetime(3)
}
entity "cuenta_contables" as cuenta_contables {
* id : bigint unsigned <<PK>>
--
nombre : varchar(30)
tipo : varchar(12)
empresa_id : bigint unsigned
created_at : datetime(3)
updated_at : datetime(3)
deleted_at : datetime(3)
}
entity "movimiento_contables" as movimiento_contables {
* id : bigint unsigned <<PK>>
--
asientoID : bigint unsigned <<FK>>
cuentaID : bigint unsigned <<FK>>
debe : decimal(10,2)
haber : decimal(10,2)
descripcion : varchar(50)
empresa_id : bigint unsigned
created_at : datetime(3)
updated_at : datetime(3)
deleted_at : datetime(3)
}
entity "logs" as logs {
* id : bigint unsigned <<PK>>
--
usuario_id : bigint unsigned <<FK>>
accion : varchar(50)
detalles : json
empresa_id : bigint unsigned
created_at : datetime(3)
}
}
' Relaciones - Módulo Usuarios / Empresas
empresas ||--o{ empresa_usuarios : "posee"
usuarios ||--o{ empresa_usuarios : "pertenece"
usuarios ||--o| plataforma_admins : "es"
empresas ||--o{ invitaciones_empresa : "emite"
' Relaciones - Módulo Permisos / Grupos
groupos ||--o{ grupo_permisos : "contiene"
permisos ||--o{ grupo_permisos : "asignado"
groupos ||--o{ grupo_grupos : "padre_de"
groupos ||--o{ grupo_grupos : "hijo_de"
usuarios ||--o{ usuarios_grupos : "pertenece"
groupos ||--o{ usuarios_grupos : "asigna"
' Relaciones - Módulo Inventario / Almacenes
marca ||--o{ repuesto : "clasifica"
repuesto ||--o{ stock : "registra"
almacen ||--o{ stock : "almacena"
repuesto ||--o{ reservas : "reservado_en"
almacen ||--o{ reservas : "ubicado_en"
clientes ||--o{ reservas : "solicita"
' Relaciones - Módulo Comercial / Ventas
proveedors ||--o{ orden_compra : "destinado_a"
usuarios ||--o{ orden_compra : "gestiona"
clientes ||--o{ factura : "facturado_a"
proveedors ||--o{ factura : "facturado_por"
usuarios ||--o{ factura : "registra"
factura ||--o{ devolucion : "origen_de"
usuarios ||--o{ devolucion : "responde"
factura ||--o{ nota_credito : "aplica_a"
usuarios ||--o{ nota_credito : "registra"
factura ||--o{ nota_debito : "aplica_a"
usuarios ||--o{ nota_debito : "registra"
clientes ||--o{ recibo : "emitido_a"
usuarios ||--o{ recibo : "genera"
recibo ||--o{ pago : "recibe"
forma_de_pago ||--o{ pago : "utilizada_en"
almacen ||--o{ remitos : "sale_de"
usuarios ||--o{ remitos : "emite"
' Relaciones - Módulo Contable y Auditoría
asiento_contables ||--o{ movimiento_contables : "agrupa"
cuenta_contables ||--o{ movimiento_contables : "imputa"
usuarios ||--o{ logs : "ejecuta"
@enduml