-- =====================================================
-- Tabla para Cierres de Caja (Corte de Caja)
-- =====================================================
-- Ejecutar en la base de datos del ERP.

CREATE TABLE IF NOT EXISTS caja_cierres (
  id_cierre INT AUTO_INCREMENT PRIMARY KEY,
  id_empresa INT NOT NULL,
  id_usuario INT NOT NULL,
  fecha DATE NOT NULL,

  monto_apertura DECIMAL(18,2) NOT NULL DEFAULT 0.00,
  ventas_efectivo DECIMAL(18,2) NOT NULL DEFAULT 0.00,
  adiciones DECIMAL(18,2) NOT NULL DEFAULT 0.00,
  sustracciones DECIMAL(18,2) NOT NULL DEFAULT 0.00,
  gastos DECIMAL(18,2) NOT NULL DEFAULT 0.00,
  monto_esperado DECIMAL(18,2) NOT NULL DEFAULT 0.00,
  monto_cierre DECIMAL(18,2) NOT NULL DEFAULT 0.00,

  detalle_denominaciones TEXT NULL,
  notas TEXT NULL,

  creado_en DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,

  INDEX idx_empresa_fecha (id_empresa, fecha),
  INDEX idx_empresa_usuario_fecha (id_empresa, id_usuario, fecha)
) ENGINE=InnoDB;

-- Si la tabla ya existe y solo falta la columna, puedes ejecutar:
-- ALTER TABLE caja_cierres ADD COLUMN gastos DECIMAL(18,2) NOT NULL DEFAULT 0.00 AFTER sustracciones;
