/*
Navicat MySQL Data Transfer

Source Server         : Server 40
Source Server Version : 50736
Source Host           : 192.200.100.40:3306
Source Database       : carnet_piku

Target Server Type    : MYSQL
Target Server Version : 50736
File Encoding         : 65001

Date: 2025-12-03 08:02:32
*/

SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------
-- Table structure for ccosto
-- ----------------------------
DROP TABLE IF EXISTS `ccosto`;
CREATE TABLE `ccosto` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `Id_ccosto` varchar(255) NOT NULL,
  `D_ccosto` varchar(255) DEFAULT NULL,
  `cargo` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;

-- ----------------------------
-- Table structure for empleados
-- ----------------------------
DROP TABLE IF EXISTS `empleados`;
CREATE TABLE `empleados` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `cedula` int(11) NOT NULL,
  `nombre` varchar(100) NOT NULL,
  `apellido` varchar(255) NOT NULL,
  `rh` varchar(5) NOT NULL,
  `ccosto` varchar(100) NOT NULL,
  `descripcion` varchar(100) NOT NULL,
  `cargo` varchar(100) NOT NULL,
  `rango` decimal(10,0) NOT NULL,
  `empresa` varchar(255) DEFAULT NULL,
  `foto` longtext,
  `fecha` date DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `cedula` (`cedula`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4;

-- ----------------------------
-- Table structure for login_attempts
-- ----------------------------
DROP TABLE IF EXISTS `login_attempts`;
CREATE TABLE `login_attempts` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `ip_address` varchar(45) NOT NULL,
  `username` varchar(100) NOT NULL,
  `attempts` int(11) DEFAULT '1',
  `last_attempt` datetime NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `idx_ip_username` (`ip_address`,`username`),
  KEY `idx_last_attempt` (`last_attempt`)
) ENGINE=MyISAM AUTO_INCREMENT=9 DEFAULT CHARSET=latin1;

-- ----------------------------
-- Table structure for registro
-- ----------------------------
DROP TABLE IF EXISTS `registro`;
CREATE TABLE `registro` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `trabajador` int(50) NOT NULL,
  `nombre` text NOT NULL,
  `ccosto` varchar(150) NOT NULL,
  `descripcion` varchar(150) NOT NULL,
  `cargo` varchar(150) NOT NULL,
  `rango` double NOT NULL,
  `fechaHora` datetime NOT NULL,
  `tipo` varchar(10) DEFAULT NULL,
  `VALOR` double DEFAULT '0',
  `SUPERVISOR` varchar(100) DEFAULT NULL,
  `ENTREGADO` varchar(50) DEFAULT 'ENTREGADO',
  `JEFE` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=548926 DEFAULT CHARSET=utf8mb4;

-- ----------------------------
-- Table structure for usuarios
-- ----------------------------
DROP TABLE IF EXISTS `usuarios`;
CREATE TABLE `usuarios` (
  `USR` varchar(10) COLLATE utf8mb4_spanish2_ci NOT NULL,
  `PAS` varchar(10) COLLATE utf8mb4_spanish2_ci NOT NULL,
  `NOMBRE` varchar(60) COLLATE utf8mb4_spanish2_ci NOT NULL,
  `EMPRESA` varchar(255) COLLATE utf8mb4_spanish2_ci NOT NULL,
  `GRADO` int(1) NOT NULL,
  PRIMARY KEY (`USR`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_spanish2_ci;
DROP TRIGGER IF EXISTS `after_delete_trigger`;
DELIMITER ;;
CREATE TRIGGER `after_delete_trigger` AFTER DELETE ON `registro` FOR EACH ROW BEGIN
    INSERT INTO auditoria_borrados (id, nombre, fecha_borrado)
    VALUES (OLD.id, OLD.nombre, NOW());
END
;;
DELIMITER ;
