-- phpMyAdmin SQL Dump
-- version 5.2.1
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Feb 20, 2026 at 11:37 PM
-- Server version: 10.4.32-MariaDB
-- PHP Version: 8.2.12

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";


/*!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 */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `fuelpos`
--

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

--
-- Table structure for table `trans_creditos`
--

CREATE TABLE `trans_creditos` (
  `id` int(11) NOT NULL,
  `codigo_empresa` varchar(50) NOT NULL,
  `nombre_empresa` varchar(255) NOT NULL,
  `codigo_empleado` varchar(50) NOT NULL,
  `nombre_empleado` varchar(255) NOT NULL,
  `codigo_tarjeta` varchar(100) DEFAULT NULL,
  `sale_id` int(11) DEFAULT NULL,
  `sale_code` varchar(100) DEFAULT NULL,
  `debito` decimal(10,2) DEFAULT 0.00,
  `credito` decimal(10,2) DEFAULT 0.00,
  `balance` decimal(10,2) DEFAULT 0.00,
  `tipo_transaccion` enum('debito','credito','ajuste') DEFAULT 'debito',
  `descripcion` text DEFAULT NULL,
  `user_id` int(11) DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `trans_creditos`
--

INSERT INTO `trans_creditos` (`id`, `codigo_empresa`, `nombre_empresa`, `codigo_empleado`, `nombre_empleado`, `codigo_tarjeta`, `sale_id`, `sale_code`, `debito`, `credito`, `balance`, `tipo_transaccion`, `descripcion`, `user_id`, `created_at`, `updated_at`) VALUES
(1, 'EMP001', 'Empresa Demo S.A.', 'EMP001-001', 'Carlos Méndez', 'CARD-0001', NULL, NULL, 0.00, 5000.00, 5000.00, 'credito', 'Crédito inicial', NULL, '2026-02-20 21:33:21', '2026-02-20 21:33:21'),
(2, 'EMP001', 'Empresa Demo S.A.', 'EMP001-001', 'Carlos Méndez', 'CARD-0001', 1, 'SALE-00001', 850.50, 0.00, 4149.50, 'debito', 'Compra de combustible', NULL, '2026-02-20 21:33:21', '2026-02-20 21:33:21');

--
-- Indexes for dumped tables
--

--
-- Indexes for table `trans_creditos`
--
ALTER TABLE `trans_creditos`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_codigo_empresa` (`codigo_empresa`),
  ADD KEY `idx_codigo_empleado` (`codigo_empleado`),
  ADD KEY `idx_codigo_tarjeta` (`codigo_tarjeta`),
  ADD KEY `idx_sale_id` (`sale_id`),
  ADD KEY `idx_created_at` (`created_at`),
  ADD KEY `idx_balance_empleado` (`codigo_empleado`,`created_at`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `trans_creditos`
--
ALTER TABLE `trans_creditos`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;

--
-- Constraints for dumped tables
--

--
-- Constraints for table `trans_creditos`
--
ALTER TABLE `trans_creditos`
  ADD CONSTRAINT `fk_trans_creditos_empleado` FOREIGN KEY (`codigo_empleado`) REFERENCES `empleados` (`codigo_empleado`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_trans_creditos_empresa` FOREIGN KEY (`codigo_empresa`) REFERENCES `empresa` (`codigo`) ON DELETE CASCADE ON UPDATE CASCADE;
COMMIT;

/*!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 */;
