-- MySQL dump 10.13  Distrib 8.0.44, for macos12.7 (arm64)
--
-- Host: localhost    Database: tefnet_erp
-- ------------------------------------------------------
-- Server version	8.0.44

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!50503 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `agente_apuracao_periodos`
--

DROP TABLE IF EXISTS `agente_apuracao_periodos`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `agente_apuracao_periodos` (
  `id` int NOT NULL AUTO_INCREMENT,
  `cod_Representante` int NOT NULL COMMENT 'O agente (idNatureza=3)',
  `competencia` char(7) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'YYYY-MM',
  `modalidade_snap` enum('pct_parceiro','pct_cliente_final','tabela_preco') COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `pct_padrao_snap` decimal(8,4) DEFAULT NULL,
  `total_titulos_pagos` decimal(14,2) NOT NULL DEFAULT '0.00',
  `total_comissao` decimal(14,2) NOT NULL DEFAULT '0.00',
  `total_disponivel` decimal(14,2) NOT NULL DEFAULT '0.00',
  `total_em_lote` decimal(14,2) NOT NULL DEFAULT '0.00',
  `total_liquidado` decimal(14,2) NOT NULL DEFAULT '0.00',
  `status_ciclo` enum('prevista','apurada','fechada') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'prevista',
  `apurada_at` datetime DEFAULT NULL,
  `apurada_by` int DEFAULT NULL,
  `fechada_at` datetime DEFAULT NULL,
  `fechada_by` int DEFAULT NULL,
  `reaberta_at` datetime DEFAULT NULL,
  `reaberta_by` int DEFAULT NULL,
  `dirty` tinyint(1) NOT NULL DEFAULT '0',
  `dirty_em` datetime DEFAULT NULL,
  `dirty_motivo` varchar(200) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `situacao` tinyint(1) NOT NULL DEFAULT '1',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_apur_agente_competencia` (`cod_Representante`,`competencia`),
  KEY `idx_apur_status` (`status_ciclo`,`dirty`),
  KEY `idx_apur_competencia` (`competencia`)
) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `agente_apuracao_periodos`
--

LOCK TABLES `agente_apuracao_periodos` WRITE;
/*!40000 ALTER TABLE `agente_apuracao_periodos` DISABLE KEYS */;
INSERT INTO `agente_apuracao_periodos` VALUES (10,278,'2024-10','pct_parceiro',10.0000,0.00,0.00,0.00,0.00,0.00,'apurada','2026-05-09 22:12:14',0,NULL,NULL,NULL,NULL,0,NULL,NULL,1),(11,417,'2024-10','pct_cliente_final',10.0000,172.00,17.20,0.00,17.20,0.00,'fechada','2026-05-09 22:12:14',0,'2026-05-09 22:12:50',0,NULL,NULL,0,NULL,NULL,1),(12,278,'2025-12','pct_parceiro',10.0000,0.00,0.00,0.00,0.00,0.00,'apurada','2026-05-09 22:12:14',0,NULL,NULL,NULL,NULL,0,NULL,NULL,1),(13,417,'2025-12','pct_cliente_final',10.0000,1767.00,176.70,176.70,0.00,0.00,'apurada','2026-05-09 22:12:14',0,NULL,NULL,NULL,NULL,0,NULL,NULL,1),(14,278,'2026-01','pct_parceiro',10.0000,0.00,0.00,0.00,0.00,0.00,'apurada','2026-05-09 22:12:14',0,NULL,NULL,NULL,NULL,0,NULL,NULL,1),(15,417,'2026-01','pct_cliente_final',10.0000,2087.00,208.70,208.70,0.00,0.00,'apurada','2026-05-09 22:12:14',0,'2026-05-09 22:54:29',0,'2026-05-09 22:54:30',0,1,'2026-05-09 22:54:30','reabertura: restauracao spec UI#23 Onda 5',1),(16,278,'2026-02','pct_parceiro',10.0000,0.00,0.00,0.00,0.00,0.00,'apurada','2026-05-09 22:12:14',0,NULL,NULL,NULL,NULL,0,NULL,NULL,1),(17,417,'2026-02','pct_cliente_final',10.0000,3778.83,375.70,375.70,0.00,0.00,'apurada','2026-05-09 22:21:32',0,'2026-05-09 22:51:06',0,'2026-05-09 22:51:27',0,1,'2026-05-09 22:51:27','reabertura: Smoke test UI#23 Onda 5 — habilitar botão Fechar pro dono testar',1),(18,417,'2025-10','pct_cliente_final',10.0000,1287.00,128.70,128.70,0.00,0.00,'apurada','2026-05-10 12:00:06',0,NULL,NULL,NULL,NULL,0,NULL,NULL,1),(19,417,'2025-09','pct_cliente_final',10.0000,940.91,94.09,94.09,0.00,0.00,'apurada','2026-05-10 12:00:24',0,NULL,NULL,NULL,NULL,0,NULL,NULL,1),(20,417,'2025-08','pct_cliente_final',10.0000,715.19,70.40,70.40,0.00,0.00,'apurada','2026-05-10 12:23:41',0,NULL,NULL,NULL,NULL,0,NULL,NULL,1);
/*!40000 ALTER TABLE `agente_apuracao_periodos` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `agente_apuracao_itens`
--

DROP TABLE IF EXISTS `agente_apuracao_itens`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `agente_apuracao_itens` (
  `id` int NOT NULL AUTO_INCREMENT,
  `apuracao_id` int NOT NULL,
  `cod_Pedido_snap` int NOT NULL,
  `id_titulo_snap` int NOT NULL COMMENT 'tbl_Boleto.id ou tbl_Faturamento.id',
  `fonte_titulo` enum('boleto','faturamento') COLLATE utf8mb4_unicode_ci NOT NULL,
  `cod_Cliente` int NOT NULL,
  `data_pag` date NOT NULL,
  `valor_base` decimal(14,2) NOT NULL,
  `pct_aplicado` decimal(8,4) DEFAULT NULL,
  `comissao` decimal(14,2) NOT NULL,
  `regra_aplicada` varchar(160) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Texto humano-legivel da regra',
  `status_item` enum('disponivel','em_lote','liquidado','estornado') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'disponivel',
  `lote_id` int DEFAULT NULL,
  `situacao` tinyint(1) NOT NULL DEFAULT '1',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_apur_titulo` (`id_titulo_snap`,`fonte_titulo`) COMMENT 'idempotencia: 1 titulo so pode estar em 1 apuracao',
  KEY `idx_apur_item_apur` (`apuracao_id`,`status_item`),
  KEY `idx_apur_item_lote` (`lote_id`)
) ENGINE=InnoDB AUTO_INCREMENT=121 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `agente_apuracao_itens`
--

LOCK TABLES `agente_apuracao_itens` WRITE;
/*!40000 ALTER TABLE `agente_apuracao_itens` DISABLE KEYS */;
INSERT INTO `agente_apuracao_itens` VALUES (2,11,6340,78797,'faturamento',5812,'2024-11-18',172.00,10.0000,17.20,'10% sobre valor cobrado do cliente final — 10% de R$ 172,00 = R$ 17,20','em_lote',1,1),(3,13,6340,101025,'faturamento',5812,'2026-01-15',172.00,10.0000,17.20,'10% sobre valor cobrado do cliente final — 10% de R$ 172,00 = R$ 17,20','disponivel',NULL,1),(4,13,7692,101066,'faturamento',6887,'2026-01-15',335.00,10.0000,33.50,'10% sobre valor cobrado do cliente final — 10% de R$ 335,00 = R$ 33,50','disponivel',NULL,1),(5,13,7780,101069,'faturamento',7078,'2026-01-15',125.00,10.0000,12.50,'10% sobre valor cobrado do cliente final — 10% de R$ 125,00 = R$ 12,50','disponivel',NULL,1),(6,13,7867,101074,'faturamento',7146,'2026-01-15',160.00,10.0000,16.00,'10% sobre valor cobrado do cliente final — 10% de R$ 160,00 = R$ 16,00','disponivel',NULL,1),(7,13,7878,101075,'faturamento',7157,'2026-01-15',160.00,10.0000,16.00,'10% sobre valor cobrado do cliente final — 10% de R$ 160,00 = R$ 16,00','disponivel',NULL,1),(8,13,7941,101076,'faturamento',7214,'2026-01-15',335.00,10.0000,33.50,'10% sobre valor cobrado do cliente final — 10% de R$ 335,00 = R$ 33,50','disponivel',NULL,1),(9,13,8135,101086,'faturamento',7387,'2026-01-15',195.00,10.0000,19.50,'10% sobre valor cobrado do cliente final — 10% de R$ 195,00 = R$ 19,50','disponivel',NULL,1),(10,13,8246,101091,'faturamento',7487,'2026-01-15',160.00,10.0000,16.00,'10% sobre valor cobrado do cliente final — 10% de R$ 160,00 = R$ 16,00','disponivel',NULL,1),(11,13,8293,101103,'faturamento',7531,'2026-01-15',125.00,10.0000,12.50,'10% sobre valor cobrado do cliente final — 10% de R$ 125,00 = R$ 12,50','disponivel',NULL,1),(12,15,6340,102740,'faturamento',5812,'2026-02-18',172.00,10.0000,17.20,'10% sobre valor cobrado do cliente final — 10% de R$ 172,00 = R$ 17,20','disponivel',NULL,1),(13,15,7692,102780,'faturamento',6887,'2026-02-18',335.00,10.0000,33.50,'10% sobre valor cobrado do cliente final — 10% de R$ 335,00 = R$ 33,50','disponivel',NULL,1),(14,15,7780,102783,'faturamento',7078,'2026-02-18',125.00,10.0000,12.50,'10% sobre valor cobrado do cliente final — 10% de R$ 125,00 = R$ 12,50','disponivel',NULL,1),(15,15,7867,102788,'faturamento',7146,'2026-02-18',160.00,10.0000,16.00,'10% sobre valor cobrado do cliente final — 10% de R$ 160,00 = R$ 16,00','disponivel',NULL,1),(16,15,7878,102789,'faturamento',7157,'2026-02-18',160.00,10.0000,16.00,'10% sobre valor cobrado do cliente final — 10% de R$ 160,00 = R$ 16,00','disponivel',NULL,1),(17,15,7941,102790,'faturamento',7214,'2026-02-18',335.00,10.0000,33.50,'10% sobre valor cobrado do cliente final — 10% de R$ 335,00 = R$ 33,50','disponivel',NULL,1),(18,15,8135,102800,'faturamento',7387,'2026-02-18',195.00,10.0000,19.50,'10% sobre valor cobrado do cliente final — 10% de R$ 195,00 = R$ 19,50','disponivel',NULL,1),(19,15,8246,102805,'faturamento',7487,'2026-02-18',160.00,10.0000,16.00,'10% sobre valor cobrado do cliente final — 10% de R$ 160,00 = R$ 16,00','disponivel',NULL,1),(20,15,8293,102817,'faturamento',7531,'2026-02-18',125.00,10.0000,12.50,'10% sobre valor cobrado do cliente final — 10% de R$ 125,00 = R$ 12,50','disponivel',NULL,1),(21,15,8356,102824,'faturamento',7589,'2026-02-18',160.00,10.0000,16.00,'10% sobre valor cobrado do cliente final — 10% de R$ 160,00 = R$ 16,00','disponivel',NULL,1),(22,15,8377,102828,'faturamento',7610,'2026-02-18',160.00,10.0000,16.00,'10% sobre valor cobrado do cliente final — 10% de R$ 160,00 = R$ 16,00','disponivel',NULL,1),(86,17,6340,104575,'faturamento',5812,'2026-03-17',172.00,10.0000,17.20,'10% sobre valor cobrado do cliente final — 10% de R$ 172,00 = R$ 17,20','disponivel',NULL,1),(87,17,7692,104615,'faturamento',6887,'2026-03-16',335.00,10.0000,33.50,'10% sobre valor cobrado do cliente final — 10% de R$ 335,00 = R$ 33,50','disponivel',NULL,1),(88,17,7780,104618,'faturamento',7078,'2026-03-16',125.00,10.0000,12.50,'10% sobre valor cobrado do cliente final — 10% de R$ 125,00 = R$ 12,50','disponivel',NULL,1),(89,17,7867,104623,'faturamento',7146,'2026-03-16',160.00,10.0000,16.00,'10% sobre valor cobrado do cliente final — 10% de R$ 160,00 = R$ 16,00','disponivel',NULL,1),(90,17,7878,104624,'faturamento',7157,'2026-03-16',160.00,10.0000,16.00,'10% sobre valor cobrado do cliente final — 10% de R$ 160,00 = R$ 16,00','disponivel',NULL,1),(91,17,7941,104625,'faturamento',7214,'2026-03-16',335.00,10.0000,33.50,'10% sobre valor cobrado do cliente final — 10% de R$ 335,00 = R$ 33,50','disponivel',NULL,1),(92,17,8135,104635,'faturamento',7387,'2026-03-19',195.00,10.0000,19.50,'10% sobre valor cobrado do cliente final — 10% de R$ 195,00 = R$ 19,50','disponivel',NULL,1),(93,17,8246,104640,'faturamento',7487,'2026-03-16',160.00,10.0000,16.00,'10% sobre valor cobrado do cliente final — 10% de R$ 160,00 = R$ 16,00','disponivel',NULL,1),(94,17,8293,104653,'faturamento',7531,'2026-03-17',125.00,10.0000,12.50,'10% sobre valor cobrado do cliente final — 10% de R$ 125,00 = R$ 12,50','disponivel',NULL,1),(95,17,8356,104660,'faturamento',7589,'2026-03-16',160.00,10.0000,16.00,'10% sobre valor cobrado do cliente final — 10% de R$ 160,00 = R$ 16,00','disponivel',NULL,1),(96,17,8377,104664,'faturamento',7610,'2026-03-16',160.00,10.0000,16.00,'10% sobre valor cobrado do cliente final — 10% de R$ 160,00 = R$ 16,00','disponivel',NULL,1),(97,17,8414,104666,'faturamento',7647,'2026-03-16',195.00,10.0000,19.50,'10% sobre valor cobrado do cliente final — 10% de R$ 195,00 = R$ 19,50','disponivel',NULL,1),(98,17,8415,104667,'faturamento',7648,'2026-03-16',195.00,10.0000,19.50,'10% sobre valor cobrado do cliente final — 10% de R$ 195,00 = R$ 19,50','disponivel',NULL,1),(99,17,8417,104668,'faturamento',7650,'2026-03-19',195.00,10.0000,19.50,'10% sobre valor cobrado do cliente final — 10% de R$ 195,00 = R$ 19,50','disponivel',NULL,1),(100,17,8418,104669,'faturamento',7651,'2026-03-18',195.00,10.0000,19.50,'10% sobre valor cobrado do cliente final — 10% de R$ 195,00 = R$ 19,50','disponivel',NULL,1),(101,17,8419,104670,'faturamento',7652,'2026-03-16',125.00,10.0000,12.50,'10% sobre valor cobrado do cliente final — 10% de R$ 125,00 = R$ 12,50','disponivel',NULL,1),(102,17,8420,104671,'faturamento',7653,'2026-03-16',160.00,10.0000,16.00,'10% sobre valor cobrado do cliente final — 10% de R$ 160,00 = R$ 16,00','disponivel',NULL,1),(103,17,8421,104672,'faturamento',7654,'2026-03-16',125.00,10.0000,12.50,'10% sobre valor cobrado do cliente final — 10% de R$ 125,00 = R$ 12,50','disponivel',NULL,1),(104,17,8498,104676,'faturamento',7726,'2026-03-16',195.00,10.0000,19.50,'10% sobre valor cobrado do cliente final — 10% de R$ 195,00 = R$ 19,50','disponivel',NULL,1),(105,17,8499,104677,'faturamento',7728,'2026-03-16',125.00,10.0000,12.50,'10% sobre valor cobrado do cliente final — 10% de R$ 125,00 = R$ 12,50','disponivel',NULL,1),(106,17,8502,104678,'faturamento',7730,'2026-03-19',160.00,10.0000,16.00,'10% sobre valor cobrado do cliente final — 10% de R$ 160,00 = R$ 16,00','disponivel',NULL,1),(107,18,6340,97447,'faturamento',5812,'2025-11-17',172.00,10.0000,17.20,'10% sobre valor cobrado do cliente final — 10% de R$ 172,00 = R$ 17,20','disponivel',NULL,1),(108,18,7692,97488,'faturamento',6887,'2025-11-17',335.00,10.0000,33.50,'10% sobre valor cobrado do cliente final — 10% de R$ 335,00 = R$ 33,50','disponivel',NULL,1),(109,18,7780,97491,'faturamento',7078,'2025-11-17',125.00,10.0000,12.50,'10% sobre valor cobrado do cliente final — 10% de R$ 125,00 = R$ 12,50','disponivel',NULL,1),(110,18,7867,97496,'faturamento',7146,'2025-11-17',160.00,10.0000,16.00,'10% sobre valor cobrado do cliente final — 10% de R$ 160,00 = R$ 16,00','disponivel',NULL,1),(111,18,7878,97497,'faturamento',7157,'2025-11-17',160.00,10.0000,16.00,'10% sobre valor cobrado do cliente final — 10% de R$ 160,00 = R$ 16,00','disponivel',NULL,1),(112,18,7941,97498,'faturamento',7214,'2025-11-26',335.00,10.0000,33.50,'10% sobre valor cobrado do cliente final — 10% de R$ 335,00 = R$ 33,50','disponivel',NULL,1),(113,19,6340,95593,'faturamento',5812,'2025-10-15',172.00,10.0000,17.20,'10% sobre valor cobrado do cliente final — 10% de R$ 172,00 = R$ 17,20','disponivel',NULL,1),(114,19,7692,95635,'faturamento',6887,'2025-10-15',326.48,10.0000,32.65,'10% sobre valor cobrado do cliente final — 10% de R$ 326,48 = R$ 32,65','disponivel',NULL,1),(115,19,7780,95638,'faturamento',7078,'2025-10-15',122.43,10.0000,12.24,'10% sobre valor cobrado do cliente final — 10% de R$ 122,43 = R$ 12,24','disponivel',NULL,1),(116,19,7867,95643,'faturamento',7146,'2025-10-15',160.00,10.0000,16.00,'10% sobre valor cobrado do cliente final — 10% de R$ 160,00 = R$ 16,00','disponivel',NULL,1),(117,19,7878,95644,'faturamento',7157,'2025-10-15',160.00,10.0000,16.00,'10% sobre valor cobrado do cliente final — 10% de R$ 160,00 = R$ 16,00','disponivel',NULL,1),(118,20,6340,93912,'faturamento',5812,'2025-09-15',172.00,10.0000,17.20,'10% sobre valor cobrado do cliente final — 10% de R$ 172,00 = R$ 17,20','disponivel',NULL,1),(119,20,7692,93954,'faturamento',6887,'2025-09-19',407.00,10.0000,40.70,'10% sobre valor cobrado do cliente final — 10% de R$ 407,00 = R$ 40,70','disponivel',NULL,1),(120,20,7780,93958,'faturamento',7078,'2025-09-17',125.00,10.0000,12.50,'10% sobre valor cobrado do cliente final — 10% de R$ 125,00 = R$ 12,50','disponivel',NULL,1);
/*!40000 ALTER TABLE `agente_apuracao_itens` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `agente_lote_resgate`
--

DROP TABLE IF EXISTS `agente_lote_resgate`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `agente_lote_resgate` (
  `id` int NOT NULL AUTO_INCREMENT,
  `numero_humano` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'LR-YYYY-NNNN',
  `cod_Representante` int NOT NULL,
  `data_resgate` datetime NOT NULL COMMENT 'capturado no cliente',
  `total` decimal(14,2) NOT NULL,
  `status_lote` enum('aguardando_pagamento','pago','liquidado','estornado') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'aguardando_pagamento',
  `data_pag` datetime DEFAULT NULL,
  `forma_pag` enum('pix','ted','boleto','outros') COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `comprovante_hash` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'hash_temp pos-upload',
  `observacao` text COLLATE utf8mb4_unicode_ci,
  `liquidado_at` datetime DEFAULT NULL,
  `liquidado_by` int DEFAULT NULL,
  `estornado_at` datetime DEFAULT NULL,
  `estornado_by` int DEFAULT NULL,
  `estorno_motivo` varchar(240) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `situacao` tinyint(1) NOT NULL DEFAULT '1',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_lote_numero` (`numero_humano`),
  KEY `idx_lote_repr_status` (`cod_Representante`,`status_lote`),
  KEY `idx_lote_data` (`data_resgate`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `agente_lote_resgate`
--

LOCK TABLES `agente_lote_resgate` WRITE;
/*!40000 ALTER TABLE `agente_lote_resgate` DISABLE KEYS */;
INSERT INTO `agente_lote_resgate` VALUES (1,'LR-2024-0001',417,'2026-05-09 22:13:02',17.20,'aguardando_pagamento',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,1);
/*!40000 ALTER TABLE `agente_lote_resgate` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `agente_lote_item`
--

DROP TABLE IF EXISTS `agente_lote_item`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `agente_lote_item` (
  `id` int NOT NULL AUTO_INCREMENT,
  `lote_id` int NOT NULL,
  `apuracao_item_id` int NOT NULL,
  `valor_snap` decimal(14,2) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_lote_item` (`apuracao_item_id`) COMMENT '1 item de apuracao em no maximo 1 lote nao-estornado',
  KEY `idx_lote_item_lote` (`lote_id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `agente_lote_item`
--

LOCK TABLES `agente_lote_item` WRITE;
/*!40000 ALTER TABLE `agente_lote_item` DISABLE KEYS */;
INSERT INTO `agente_lote_item` VALUES (1,1,2,17.20);
/*!40000 ALTER TABLE `agente_lote_item` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `agente_critica_resgate`
--

DROP TABLE IF EXISTS `agente_critica_resgate`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `agente_critica_resgate` (
  `id` int NOT NULL AUTO_INCREMENT,
  `cod_Representante` int NOT NULL,
  `competencia` char(7) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'NULL=critica geral; preenchido=especifica',
  `motivo` varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL,
  `bloqueia_resgate` tinyint(1) NOT NULL DEFAULT '1',
  `ativa` tinyint(1) NOT NULL DEFAULT '1',
  `criado_at` datetime NOT NULL,
  `criado_by` int NOT NULL,
  `resolvido_at` datetime DEFAULT NULL,
  `resolvido_by` int DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_critica_repr` (`cod_Representante`,`ativa`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `agente_critica_resgate`
--

LOCK TABLES `agente_critica_resgate` WRITE;
/*!40000 ALTER TABLE `agente_critica_resgate` DISABLE KEYS */;
/*!40000 ALTER TABLE `agente_critica_resgate` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `agente_log_cron`
--

DROP TABLE IF EXISTS `agente_log_cron`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `agente_log_cron` (
  `id` int NOT NULL AUTO_INCREMENT,
  `iniciado_at` datetime NOT NULL,
  `finalizado_at` datetime DEFAULT NULL,
  `competencia` char(7) COLLATE utf8mb4_unicode_ci NOT NULL,
  `agentes_processados` int NOT NULL DEFAULT '0',
  `agentes_com_erro` int NOT NULL DEFAULT '0',
  `erro_msg` text COLLATE utf8mb4_unicode_ci,
  `duracao_ms` int DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_log_data` (`iniciado_at`)
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `agente_log_cron`
--

LOCK TABLES `agente_log_cron` WRITE;
/*!40000 ALTER TABLE `agente_log_cron` DISABLE KEYS */;
INSERT INTO `agente_log_cron` VALUES (1,'2026-05-06 01:11:51','2026-05-05 22:11:51','2026-04',0,0,NULL,2),(2,'2026-05-09 22:28:01','2026-05-09 19:28:01','2026-05',0,2,'agente #278: SQLSTATE[01000]: Warning: 1265 Data truncated for column \'modalidade_snap\' at row 1\nagente #417: SQLSTATE[01000]: Warning: 1265 Data truncated for column \'modalidade_snap\' at row 1',3),(3,'2026-05-09 22:28:01','2026-05-09 19:28:01','2026-04',0,2,'agente #278: SQLSTATE[01000]: Warning: 1265 Data truncated for column \'modalidade_snap\' at row 1\nagente #417: SQLSTATE[01000]: Warning: 1265 Data truncated for column \'modalidade_snap\' at row 1',1),(4,'2026-05-09 22:28:01','2026-05-09 19:28:01','2026-03',0,2,'agente #278: SQLSTATE[01000]: Warning: 1265 Data truncated for column \'modalidade_snap\' at row 1\nagente #417: SQLSTATE[01000]: Warning: 1265 Data truncated for column \'modalidade_snap\' at row 1',1),(5,'2026-05-09 22:56:19','2026-05-09 19:56:19','2024-10',0,2,'agente #278: SQLSTATE[HY000]: General error: 1525 Incorrect DATE value: \'0000-00-00\'\nagente #417: SQLSTATE[HY000]: General error: 1525 Incorrect DATE value: \'0000-00-00\'',5),(6,'2026-05-09 22:56:19','2026-05-09 19:56:19','2025-12',0,2,'agente #278: SQLSTATE[HY000]: General error: 1525 Incorrect DATE value: \'0000-00-00\'\nagente #417: SQLSTATE[HY000]: General error: 1525 Incorrect DATE value: \'0000-00-00\'',2),(7,'2026-05-09 22:56:19','2026-05-09 19:56:19','2026-01',0,2,'agente #278: SQLSTATE[HY000]: General error: 1525 Incorrect DATE value: \'0000-00-00\'\nagente #417: SQLSTATE[HY000]: General error: 1525 Incorrect DATE value: \'0000-00-00\'',2),(8,'2026-05-09 22:56:19','2026-05-09 19:56:19','2026-02',0,2,'agente #278: SQLSTATE[HY000]: General error: 1525 Incorrect DATE value: \'0000-00-00\'\nagente #417: SQLSTATE[HY000]: General error: 1525 Incorrect DATE value: \'0000-00-00\'',1),(9,'2026-05-09 22:56:50','2026-05-09 19:56:50','2024-10',2,0,NULL,5),(10,'2026-05-10 01:12:14','2026-05-09 22:12:14','2024-10',2,0,NULL,5),(11,'2026-05-10 01:12:14','2026-05-09 22:12:14','2025-12',2,0,NULL,3),(12,'2026-05-10 01:12:14','2026-05-09 22:12:14','2026-01',2,0,NULL,4),(13,'2026-05-10 01:12:14','2026-05-09 22:12:14','2026-02',2,0,NULL,4);
/*!40000 ALTER TABLE `agente_log_cron` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `agente_log_acao`
--

DROP TABLE IF EXISTS `agente_log_acao`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `agente_log_acao` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `usuario_id` int NOT NULL DEFAULT '0' COMMENT 'tbl_Usuario.id (0 quando DEV sem login)',
  `usuario_nome` varchar(120) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'snapshot do nome no momento da acao',
  `usuario_tpuser` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Tef.Net | Revenda | Agente',
  `cod_Representante` int DEFAULT NULL COMMENT 'agente alvo da acao',
  `competencia` char(7) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'AAAA-MM',
  `acao` varchar(40) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'apurar | fechar | reabrir | resgate_solicitar | lote_liquidar | lote_estornar | rollback_executar | cron_manual',
  `status_resultado` enum('OK','ERRO') COLLATE utf8mb4_unicode_ci NOT NULL,
  `mensagem` varchar(500) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `apuracao_id` bigint unsigned DEFAULT NULL,
  `lote_id` bigint unsigned DEFAULT NULL,
  `payload_resumo` text COLLATE utf8mb4_unicode_ci COMMENT 'JSON pequeno com contexto (max 500 chars)',
  `ip_address` varchar(45) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `user_agent` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `ambiente` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT 'PROD' COMMENT 'DEV | PROD (DEV quando ?dev=1)',
  PRIMARY KEY (`id`),
  KEY `idx_log_data` (`created_at`),
  KEY `idx_log_acao_data` (`acao`,`created_at`),
  KEY `idx_log_cod_comp` (`cod_Representante`,`competencia`),
  KEY `idx_log_apuracao` (`apuracao_id`),
  KEY `idx_log_lote` (`lote_id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='AUDIT#1 — log estruturado de acoes do app web/agente. Aprovado em 10/05/2026.';
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `agente_log_acao`
--

LOCK TABLES `agente_log_acao` WRITE;
/*!40000 ALTER TABLE `agente_log_acao` DISABLE KEYS */;
INSERT INTO `agente_log_acao` VALUES (1,'2026-05-10 12:00:06',999999,'DEV (sem login)','DEV',417,'2025-10','apurar','OK','Apurada: 6 titulos, comissao R$ 128,70',18,NULL,'{\"modalidade_snap\":\"pct_cliente_final\",\"total_titulos_pagos\":1287}','::1','curl/8.7.1','DEV'),(2,'2026-05-10 12:00:24',999999,'DEV (sem login)','DEV',417,'2025-09','apurar','OK','Apurada: 5 titulos, comissao R$ 94,09',19,NULL,'{\"modalidade_snap\":\"pct_cliente_final\",\"total_titulos_pagos\":940.91}','::1','curl/8.7.1','DEV'),(3,'2026-05-10 12:07:29',999999,'DEV (sem login)','DEV',NULL,NULL,'backup_criar','OK','Backup gerado: snapshot_20260510_150729.sql',NULL,NULL,'{\"arquivo\":\"snapshot_20260510_150729.sql\",\"tamanho_kb\":25,\"duracao_ms\":356,\"tabelas\":[\"agente_apuracao_periodos\",\"agente_apuracao_itens\",\"agente_lote_resgate\",\"agente_lote_item\",\"agente_critica_resgate\",\"agente_log_cron\",\"agente_log_acao\"]}','::1','curl/8.7.1','DEV'),(4,'2026-05-10 12:10:56',999999,'DEV (sem login)','DEV',NULL,NULL,'backup_criar','OK','Backup gerado: snapshot_20260510_151056.sql',NULL,NULL,'{\"arquivo\":\"snapshot_20260510_151056.sql\",\"tamanho_kb\":25,\"duracao_ms\":27,\"tabelas\":[\"agente_apuracao_periodos\",\"agente_apuracao_itens\",\"agente_lote_resgate\",\"agente_lote_item\",\"agente_critica_resgate\",\"agente_log_cron\",\"agente_log_acao\"]}','::1','curl/8.7.1','DEV'),(5,'2026-05-10 12:20:58',999999,'DEV (sem login)','DEV',417,'2024-10','resgate_solicitar','OK','Idempotente: lote LR-2024-0001 ja existia (status=aguardando_pagamento, total R$ 17,20)',11,1,'{\"codigo\":\"LOTE_JA_EXISTENTE\"}','::1','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.7727.15 Safari/537.36','DEV'),(6,'2026-05-10 12:21:00',999999,'DEV (sem login)','DEV',NULL,NULL,'backup_criar','OK','Backup gerado: snapshot_20260510_152100.sql',NULL,NULL,'{\"arquivo\":\"snapshot_20260510_152100.sql\",\"tamanho_kb\":26,\"duracao_ms\":37,\"tabelas\":[\"agente_apuracao_periodos\",\"agente_apuracao_itens\",\"agente_lote_resgate\",\"agente_lote_item\",\"agente_critica_resgate\",\"agente_log_cron\",\"agente_log_acao\"]}','::1','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.7727.15 Safari/537.36','DEV'),(7,'2026-05-10 12:23:41',999999,'DEV (sem login)','DEV',417,'2024-10','resgate_solicitar','OK','Idempotente: lote LR-2024-0001 ja existia (status=aguardando_pagamento, total R$ 17,20)',11,1,'{\"codigo\":\"LOTE_JA_EXISTENTE\"}','::1','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.7727.15 Safari/537.36','DEV'),(8,'2026-05-10 12:23:41',999999,'DEV (sem login)','DEV',417,'2025-08','apurar','OK','Apurada: 3 titulos, comissao R$ 70,40',20,NULL,'{\"modalidade_snap\":\"pct_cliente_final\",\"total_titulos_pagos\":715.19}','::1','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.7727.15 Safari/537.36','DEV');
/*!40000 ALTER TABLE `agente_log_acao` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2026-05-10 12:23:42
