-- https://www.phpmyadmin.net/
--
-- Tempo de geração: 25/08/2025 às 14:18
-- Versão do servidor: 10.4.32-MariaDB
-- Versão do PHP: 8.0.30

START TRANSACTION;



-- --------------------------------------------------------

--
-- Estrutura para tabela `client_customers`
--

CREATE TABLE `client_customers` (
  `id` int(11) NOT NULL,
  `user_id` int(11) NOT NULL,
  `name` varchar(100) NOT NULL,
  `phone` varchar(20) DEFAULT NULL,
  `cpf` varchar(20) DEFAULT NULL,
  `created_at` datetime DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Despejando dados para a tabela `client_customers`
--

INSERT INTO `client_customers` (`id`, `user_id`, `name`, `phone`, `cpf`, `created_at`) VALUES
(1, 1, 'FreeCoin', '83998533151', '', '2025-07-13 19:54:01'),
(2, 1, 'angela mayle', '83998546107', '', '2025-07-13 20:37:52'),
(3, 2, 'maria', '83998677890', '', '2025-07-13 23:56:14'),
(4, 2, 'Rauan silva', '(83) 99854-6107', '000.000.000-00', '2025-07-20 00:50:51'),
(5, 4, 'ronison fagno', '(83) 99853-3151', '', '2025-08-23 17:17:11');

-- --------------------------------------------------------

--
-- Estrutura para tabela `fiados`
--

CREATE TABLE `fiados` (
  `id` int(11) NOT NULL,
  `customer_id` int(11) NOT NULL,
  `user_id` int(11) NOT NULL,
  `description` varchar(255) DEFAULT NULL,
  `total_amount` decimal(10,2) NOT NULL,
  `created_at` datetime DEFAULT current_timestamp(),
  `valor_pago` decimal(10,2) DEFAULT 0.00,
  `saldo` decimal(10,2) DEFAULT 0.00
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Despejando dados para a tabela `fiados`
--

INSERT INTO `fiados` (`id`, `customer_id`, `user_id`, `description`, `total_amount`, `created_at`, `valor_pago`, `saldo`) VALUES
(6, 2, 1, 'valor venda teste', 150.00, '2025-07-13 22:05:04', 100.00, 50.00),
(7, 3, 2, 'peneu', 123.00, '2025-07-13 23:56:36', 61.50, 61.50),
(8, 5, 4, 'feira', 1250.00, '2025-08-23 17:17:40', 1250.00, 0.00),
(9, 5, 4, 'feira 2', 155.00, '2025-08-23 20:35:55', 155.00, 0.00);

-- --------------------------------------------------------

--
-- Estrutura para tabela `installments`
--

CREATE TABLE `installments` (
  `id` int(11) NOT NULL,
  `fiado_id` int(11) NOT NULL,
  `due_date` date NOT NULL,
  `amount` decimal(10,2) NOT NULL,
  `paid` tinyint(1) DEFAULT 0,
  `paid_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Despejando dados para a tabela `installments`
--

INSERT INTO `installments` (`id`, `fiado_id`, `due_date`, `amount`, `paid`, `paid_at`) VALUES
(12, 6, '2025-07-13', 50.00, 1, NULL),
(13, 6, '2025-08-13', 50.00, 1, NULL),
(14, 6, '2025-09-13', 50.00, 0, NULL),
(15, 7, '2025-07-13', 61.50, 1, NULL),
(16, 7, '2025-08-13', 61.50, 0, NULL),
(17, 8, '2025-09-23', 1250.00, 1, NULL),
(18, 9, '2025-09-23', 155.00, 1, NULL);

-- --------------------------------------------------------

--
-- Estrutura para tabela `payments`
--

CREATE TABLE `payments` (
  `id` int(11) NOT NULL,
  `user_id` int(11) NOT NULL,
  `reference_month` varchar(7) NOT NULL,
  `paid` tinyint(1) DEFAULT 0,
  `paid_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Estrutura para tabela `settings`
--

CREATE TABLE `settings` (
  `id` int(11) NOT NULL,
  `user_id` int(11) NOT NULL,
  `nome_empresa` varchar(100) DEFAULT NULL,
  `cnpj` varchar(25) DEFAULT NULL,
  `endereco` varchar(150) DEFAULT NULL,
  `telefone` varchar(30) DEFAULT NULL,
  `email_contato` varchar(80) DEFAULT NULL,
  `logo` varchar(200) DEFAULT NULL,
  `pix_key` varchar(120) DEFAULT NULL,
  `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Despejando dados para a tabela `settings`
--

INSERT INTO `settings` (`id`, `user_id`, `nome_empresa`, `cnpj`, `endereco`, `telefone`, `email_contato`, `logo`, `pix_key`, `updated_at`) VALUES
(1, 2, 'Lidernetwork', '00000000000', 'rua das pastilas', '8399097854', '', 'https://mir-s3-cdn-cf.behance.net/projects/404/f6044e88749841.Y3JvcCwyNDgyLDE5NDEsMCwzMjU.png', 'ronisonfagno@gmail.com', '2025-07-20 09:20:45'),
(2, 1, 'Tecnolider informatica', '00000000000', 'Rua julho carlos,160', '83998533151', '', 'https://img.cdndsgni.com/preview/10431212.jpg', 'ronisonfagno@gmail.com', '2025-07-14 13:12:44'),
(3, 4, 'Mercado Pageu', '19.501.313/0001-51', 'rua teste , 120 ,centro ,Malta-pb', '(83) 99856-2331', '', 'uploads/Red_Apple.jpg', 'mercadopageu@gmail.com', '2025-08-23 20:37:31');

--
-- Índices de tabela `client_customers`
--
ALTER TABLE `client_customers`
  ADD PRIMARY KEY (`id`),
  ADD KEY `user_id` (`user_id`);

--
-- Índices de tabela `fiados`
--
ALTER TABLE `fiados`
  ADD PRIMARY KEY (`id`),
  ADD KEY `customer_id` (`customer_id`),
  ADD KEY `user_id` (`user_id`);

--
-- Índices de tabela `installments`
--
ALTER TABLE `installments`
  ADD PRIMARY KEY (`id`),
  ADD KEY `fiado_id` (`fiado_id`);

--
-- Índices de tabela `payments`
--
ALTER TABLE `payments`
  ADD PRIMARY KEY (`id`),
  ADD KEY `user_id` (`user_id`);

--
-- Índices de tabela `settings`
--
ALTER TABLE `settings`
  ADD PRIMARY KEY (`id`),
  ADD KEY `user_id` (`user_id`);

--
-- AUTO_INCREMENT de tabela `client_customers`
--
ALTER TABLE `client_customers`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;

--
-- AUTO_INCREMENT de tabela `fiados`
--
ALTER TABLE `fiados`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=10;

--
-- AUTO_INCREMENT de tabela `installments`
--
ALTER TABLE `installments`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=19;

--
-- AUTO_INCREMENT de tabela `payments`
--
ALTER TABLE `payments`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT de tabela `settings`
--
ALTER TABLE `settings`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;

--
-- Restrições para tabelas despejadas
--

--
-- Restrições para tabelas `client_customers`
--
ALTER TABLE `client_customers`
  ADD CONSTRAINT `client_customers_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;

--
-- Restrições para tabelas `fiados`
--
ALTER TABLE `fiados`
  ADD CONSTRAINT `fiados_ibfk_1` FOREIGN KEY (`customer_id`) REFERENCES `client_customers` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fiados_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;

--
-- Restrições para tabelas `installments`
--
ALTER TABLE `installments`
  ADD CONSTRAINT `installments_ibfk_1` FOREIGN KEY (`fiado_id`) REFERENCES `fiados` (`id`) ON DELETE CASCADE;

--
-- Restrições para tabelas `payments`
--
ALTER TABLE `payments`
  ADD CONSTRAINT `payments_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;

--
-- Restrições para tabelas `settings`
--
ALTER TABLE `settings`
  ADD CONSTRAINT `settings_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;
COMMIT;

