@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 <> -- nombre : varchar(120) slug : varchar(60) <> cuit : varchar(11) <> activa : tinyint(1) created_at : datetime(3) updated_at : datetime(3) deleted_at : datetime(3) } entity "usuarios" as usuarios { * id : bigint unsigned <> -- email : varchar(100) <> 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 <> * empresa_id : bigint unsigned <> -- rol : varchar(20) activo : tinyint(1) created_at : datetime(3) updated_at : datetime(3) } entity "plataforma_admins" as plataforma_admins { * usuario_id : bigint unsigned <> -- rol : varchar(20) activo : tinyint(1) created_at : datetime(3) updated_at : datetime(3) } entity "invitaciones_empresa" as invitaciones_empresa { * id : bigint unsigned <> -- empresa_id : bigint unsigned <> email : varchar(100) rol : varchar(20) token_hash : varchar(64) <> 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 <> -- 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 <> -- nombre : varchar(100) <> alias : varchar(100) <> 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 <> * permiso_id : bigint unsigned <> } entity "grupo_grupos" as grupo_grupos { * parent_group_id : bigint unsigned <> * child_group_id : bigint unsigned <> } entity "usuarios_grupos" as usuarios_grupos { * usuario_id : bigint unsigned <> * grupo_id : bigint unsigned <> } } package "Módulo Inventario y Almacenes" { entity "marca" as marca { * id : bigint unsigned <> -- 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 <> -- nombre : varchar(50) precio : decimal(10,2) stock_minimo : bigint descripcion : varchar(70) marcaID : bigint unsigned <> 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 <> -- empresa_id : bigint unsigned codigo : varchar(5) ubicacion : varchar(40) } entity "stock" as stock { * id : bigint unsigned <> -- repuesto_id : bigint unsigned <> almacen_id : bigint unsigned <> cantidad : bigint unsigned cantidad_reservada : bigint unsigned observacion : varchar(60) movmientos : json empresa_id : bigint unsigned } entity "reservas" as reservas { * id : bigint unsigned <> -- repuesto_id : bigint unsigned <> almacen_id : bigint unsigned <> cliente_id : bigint unsigned <> 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 <> -- 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 <> -- 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 <> -- proveedorID : bigint unsigned <> usuarioID : bigint unsigned <> 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 <> -- ClienteID : bigint unsigned <> usuarioID : bigint unsigned <> proveedor_id : bigint unsigned <> 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 <> -- facturaOrigenID : bigint unsigned <> usuarioID : bigint unsigned <> 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 <> -- facturaID : bigint unsigned <> usuarioID : bigint unsigned <> 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 <> -- facturaID : bigint unsigned <> usuarioID : bigint unsigned <> 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 <> -- cliente_id : bigint unsigned <> usuarioID : bigint unsigned <> 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 <> -- 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 <> -- formaDePagoID : bigint unsigned <> recibo_id : bigint unsigned <> 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 <> -- almacen_origen_id : bigint unsigned <> usuarioID : bigint unsigned <> 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 <> -- 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 <> -- 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 <> -- asientoID : bigint unsigned <> cuentaID : bigint unsigned <> 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 <> -- usuario_id : bigint unsigned <> 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