-- phpMyAdmin SQL Dump
-- version 5.2.1
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: May 01, 2026 at 02:38 AM
-- 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: `voucher_system`
--

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

--
-- Table structure for table `admins`
--

CREATE TABLE `admins` (
  `id` int(11) NOT NULL,
  `username` varchar(50) DEFAULT NULL,
  `password` varchar(255) DEFAULT NULL,
  `role` enum('admin','staff') NOT NULL DEFAULT 'admin'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `admins`
--

-- IMPORTANT: No default admin account is seeded here.
-- Create your admin account after import by running:
--   INSERT INTO `admins` (`username`, `password`, `role`)
--   VALUES ('your_username', '$2y$10$<hash_from_password_hash()>', 'admin');
-- Or use the admin panel's user creation feature after first login via CLI setup.

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

--
-- Table structure for table `customers`
--

CREATE TABLE `customers` (
  `id` int(10) UNSIGNED NOT NULL,
  `name` varchar(100) NOT NULL,
  `phone` varchar(20) NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `customers`
--

INSERT INTO `customers` (`id`, `name`, `phone`, `created_at`) VALUES
(1, 'abc', '99999999', '2026-04-27 14:07:02'),
(2, 'user', '0123456789', '2026-04-27 14:10:24'),
(3, 'Abc', '1111111111', '2026-04-28 08:35:52'),
(4, 'Abc', '1111111119', '2026-04-29 04:10:40'),
(5, 'Albert', '0128818810', '2026-04-29 08:56:14');

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

--
-- Table structure for table `vouchers`
--

CREATE TABLE `vouchers` (
  `id` int(10) UNSIGNED NOT NULL,
  `code` varchar(20) NOT NULL,
  `discount_type` enum('percentage','fixed') DEFAULT 'fixed',
  `discount_value` decimal(10,2) DEFAULT 0.00,
  `min_purchase` decimal(10,2) DEFAULT 0.00,
  `is_redeemed` tinyint(1) DEFAULT 0,
  `expires_at` datetime DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `event_name` varchar(100) DEFAULT NULL,
  `event_date` date DEFAULT NULL,
  `details` mediumtext DEFAULT NULL,
  `start_date` date DEFAULT NULL,
  `end_date` date DEFAULT NULL,
  `voucher_type_id` int(11) DEFAULT NULL,
  `is_public` tinyint(1) DEFAULT 0,
  `max_per_user` int(11) DEFAULT 1,
  `image` varchar(255) NOT NULL,
  `type` varchar(100) DEFAULT NULL,
  `status` varchar(20) DEFAULT 'active'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `vouchers`
--

INSERT INTO `vouchers` (`id`, `code`, `discount_type`, `discount_value`, `min_purchase`, `is_redeemed`, `expires_at`, `created_at`, `event_name`, `event_date`, `details`, `start_date`, `end_date`, `voucher_type_id`, `is_public`, `max_per_user`, `image`, `type`, `status`) VALUES
(5, 'ICE-AFCBCC68', 'fixed', 0.00, 0.00, 0, NULL, '2026-04-29 01:14:58', 'Kuching Festival Food Fair', NULL, 'RM 5 OFF FOR EVERY 5 ICE CREAM PURCHASED', '2026-04-15', '2026-05-06', NULL, 0, 1, '1777425298_95c8d43f.png', 'Ice Cream', 'active'),
(6, 'ICE-B9C793F0', 'fixed', 0.00, 0.00, 0, NULL, '2026-04-29 01:15:45', 'Kuching Festival Food Fair', NULL, '5% OFF FOR A NEW PURCHASE OF POPCORN', '2026-04-25', '2026-05-16', NULL, 1, 1, '1777425345_e0683d91.png', 'Popcorn', 'active'),
(7, 'ICE-BD996190', 'fixed', 0.00, 0.00, 0, NULL, '2026-04-29 01:16:10', 'Kuching Festival Food Fair', NULL, 'RM 3 OFF', '2026-03-11', '2026-04-07', NULL, 0, 1, '1777425370_237398dc.png', 'Ice Cream', 'active'),
(8, 'ICE-502CE9CC', 'fixed', 0.00, 0.00, 1, NULL, '2026-04-29 04:18:55', 'Free Delicious Crunchy Popcorn', NULL, 'Free Popcorn', '2026-04-08', '2026-04-30', NULL, 1, 3, '1777436335_cda17ad1.jpg', 'Popcorn', 'active');

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

--
-- Table structure for table `voucher_claims`
--

CREATE TABLE `voucher_claims` (
  `id` int(10) UNSIGNED NOT NULL,
  `customer_id` int(10) UNSIGNED NOT NULL,
  `voucher_id` int(10) UNSIGNED NOT NULL,
  `status` enum('claimed','redeemed') DEFAULT 'claimed',
  `claimed_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `redeemed_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `voucher_types`
--

CREATE TABLE `voucher_types` (
  `id` int(11) NOT NULL,
  `name` varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `voucher_types`
--

INSERT INTO `voucher_types` (`id`, `name`) VALUES
(1, 'Hokkaido Ice Cream'),
(2, 'Popcorn');

--
-- Indexes for dumped tables
--

--
-- Indexes for table `admins`
--
ALTER TABLE `admins`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `username` (`username`);

--
-- Indexes for table `customers`
--
ALTER TABLE `customers`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `phone` (`phone`),
  ADD UNIQUE KEY `phone_2` (`phone`);

--
-- Indexes for table `vouchers`
--
ALTER TABLE `vouchers`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `code` (`code`),
  ADD UNIQUE KEY `code_2` (`code`),
  ADD KEY `voucher_type_id` (`voucher_type_id`);

--
-- Indexes for table `voucher_claims`
--
ALTER TABLE `voucher_claims`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_customer_voucher` (`customer_id`,`voucher_id`),
  ADD KEY `voucher_claims_ibfk_2` (`voucher_id`);

--
-- Indexes for table `voucher_types`
--
ALTER TABLE `voucher_types`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `name` (`name`);

--
-- AUTO_INCREMENT for dumped tables
--

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

--
-- AUTO_INCREMENT for table `customers`
--
ALTER TABLE `customers`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;

--
-- AUTO_INCREMENT for table `vouchers`
--
ALTER TABLE `vouchers`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=10;

--
-- AUTO_INCREMENT for table `voucher_claims`
--
ALTER TABLE `voucher_claims`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7;

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

--
-- Constraints for dumped tables
--

--
-- Constraints for table `vouchers`
--
ALTER TABLE `vouchers`
  ADD CONSTRAINT `vouchers_ibfk_1` FOREIGN KEY (`voucher_type_id`) REFERENCES `voucher_types` (`id`);

--
-- Constraints for table `voucher_claims`
--
ALTER TABLE `voucher_claims`
  ADD CONSTRAINT `voucher_claims_ibfk_1` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `voucher_claims_ibfk_2` FOREIGN KEY (`voucher_id`) REFERENCES `vouchers` (`id`) ON DELETE 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 */;
