-- phpMyAdmin SQL Dump
-- version 5.2.0
-- https://www.phpmyadmin.net/
--
-- Host: localhost:3306
-- Generation Time: Sep 21, 2025 at 03:10 PM
-- Server version: 8.0.42
-- PHP Version: 8.1.10

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: `pos`
--

-- --------------------------------------------------------

--
-- Table structure for table `expenses`
--

CREATE TABLE `expenses` (
  `id` int NOT NULL,
  `store_id` int DEFAULT NULL,
  `category` varchar(100) NOT NULL,
  `description` varchar(255) DEFAULT NULL,
  `amount` decimal(10,2) NOT NULL,
  `user_id` int NOT NULL,
  `created_at` datetime DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `expenses`
--

INSERT INTO `expenses` (`id`, `store_id`, `category`, `description`, `amount`, `user_id`, `created_at`) VALUES
(1, 1, 'Sewa alat', 'Just tes', '1000000.00', 1, '2025-09-11 11:04:16');

-- --------------------------------------------------------

--
-- Table structure for table `products`
--

CREATE TABLE `products` (
  `id` int NOT NULL,
  `product_name` varchar(255) NOT NULL,
  `sku` varchar(100) DEFAULT NULL,
  `barcode` varchar(100) DEFAULT NULL,
  `store_id` int NOT NULL,
  `description` text,
  `product_image` varchar(255) DEFAULT NULL,
  `created_at` datetime DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `products`
--

INSERT INTO `products` (`id`, `product_name`, `sku`, `barcode`, `store_id`, `description`, `product_image`, `created_at`) VALUES
(1, 'Tes', 'ffgy-ff', 'PRD000001', 1, 'tyfgh', 'uploads/products/1757519054_62aafaa9dd04a138c5fa.png', '2025-09-10 14:41:46'),
(2, 'Beng beng', 'bb', NULL, 1, '', 'uploads/products/1757520175_b2ec8c4101ca63daec92.jpg', '2025-09-10 22:54:49'),
(3, 'Susu Kotak', NULL, 'PRD000003', 1, NULL, NULL, '2025-09-12 14:04:17'),
(4, '76 Apel', 'aewr', '8991906106250', 1, '', 'uploads/products/1758460740_6470e76873a760043838.png', '2025-09-21 20:19:00'),
(5, 'WIN BErry', 'sfsfs', '8997017792276', 1, '', 'uploads/products/1758460989_f2067a7135cf56b19d5e.jpg', '2025-09-21 20:23:09');

-- --------------------------------------------------------

--
-- Table structure for table `product_units`
--

CREATE TABLE `product_units` (
  `id` int NOT NULL,
  `product_id` int NOT NULL,
  `unit_id` int NOT NULL,
  `conversion_factor` float DEFAULT '1',
  `price` decimal(10,2) NOT NULL,
  `purchase_price` decimal(10,2) NOT NULL,
  `production_cost` decimal(10,2) DEFAULT NULL,
  `warehouse_stock` int NOT NULL,
  `outlet_stock` int NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `product_units`
--

INSERT INTO `product_units` (`id`, `product_id`, `unit_id`, `conversion_factor`, `price`, `purchase_price`, `production_cost`, `warehouse_stock`, `outlet_stock`) VALUES
(2, 1, 1, 1, '50000.00', '30000.00', '0.00', 50, 20),
(3, 2, 1, 1, '2000.00', '1200.00', '0.00', 40, 0),
(4, 1, 1, 1, '51000.00', '31000.00', '0.00', 20, 0),
(5, 3, 1, 1, '5000.00', '4500.00', '0.00', 100, 47),
(6, 4, 1, 1, '15000.00', '12000.00', '0.00', 10, 10),
(7, 5, 1, 1, '12000.00', '10000.00', '0.00', 10, 10);

-- --------------------------------------------------------

--
-- Table structure for table `roles`
--

CREATE TABLE `roles` (
  `id` int NOT NULL,
  `role_name` varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `roles`
--

INSERT INTO `roles` (`id`, `role_name`) VALUES
(1, 'superadmin'),
(2, 'admin_unit'),
(3, 'kasir');

-- --------------------------------------------------------

--
-- Table structure for table `stock_transfers`
--

CREATE TABLE `stock_transfers` (
  `id` int NOT NULL,
  `product_unit_id` int NOT NULL,
  `quantity` int NOT NULL,
  `transfer_date` datetime DEFAULT CURRENT_TIMESTAMP,
  `user_id` int NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

-- --------------------------------------------------------

--
-- Table structure for table `stores`
--

CREATE TABLE `stores` (
  `id` int NOT NULL,
  `store_name` varchar(255) NOT NULL,
  `address` varchar(255) DEFAULT NULL,
  `phone` varchar(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `stores`
--

INSERT INTO `stores` (`id`, `store_name`, `address`, `phone`) VALUES
(1, 'Toko Utama', 'Jl. Raya No. 1, Kotas', ''),
(2, 'Toko Kedua', 'yr', '');

-- --------------------------------------------------------

--
-- Table structure for table `transactions`
--

CREATE TABLE `transactions` (
  `id` int NOT NULL,
  `transaction_date` datetime DEFAULT CURRENT_TIMESTAMP,
  `total_amount` decimal(10,2) NOT NULL,
  `user_id` int NOT NULL,
  `store_id` int NOT NULL,
  `payment_method` enum('tunai','qris','lainnya') NOT NULL DEFAULT 'tunai',
  `nominal_bayar` decimal(15,2) NOT NULL DEFAULT '0.00',
  `kembalian` decimal(15,2) NOT NULL DEFAULT '0.00'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `transactions`
--

INSERT INTO `transactions` (`id`, `transaction_date`, `total_amount`, `user_id`, `store_id`, `payment_method`, `nominal_bayar`, `kembalian`) VALUES
(1, '2025-09-10 16:32:54', '6000.00', 1, 1, 'tunai', '0.00', '0.00'),
(2, '2025-09-10 16:41:18', '4000.00', 1, 1, 'tunai', '0.00', '0.00'),
(3, '2025-09-10 16:42:15', '50000.00', 1, 1, 'tunai', '0.00', '0.00'),
(4, '2025-09-10 16:49:47', '4000.00', 3, 1, 'tunai', '0.00', '0.00'),
(5, '2025-09-10 23:52:22', '2000.00', 1, 1, 'tunai', '0.00', '0.00'),
(6, '2025-09-10 23:56:26', '2000.00', 3, 1, 'tunai', '0.00', '0.00'),
(7, '2025-09-11 10:19:26', '4000.00', 1, 1, 'tunai', '0.00', '0.00'),
(8, '2025-09-11 11:12:04', '18000.00', 1, 1, 'tunai', '0.00', '0.00'),
(10, '2025-09-19 18:53:29', '154000.00', 1, 1, 'tunai', '0.00', '0.00'),
(11, '2025-09-19 19:08:33', '4000.00', 1, 1, 'tunai', '0.00', '0.00'),
(12, '2025-09-19 19:09:55', '10000.00', 1, 1, 'tunai', '0.00', '0.00'),
(13, '2025-09-19 20:54:18', '5000.00', 1, 1, 'tunai', '0.00', '0.00'),
(14, '2025-09-20 15:14:51', '52000.00', 1, 1, 'tunai', '0.00', '0.00'),
(15, '2025-09-20 15:22:30', '150000.00', 3, 1, 'tunai', '0.00', '0.00'),
(16, '2025-09-20 15:25:48', '100000.00', 4, 1, 'tunai', '0.00', '0.00'),
(17, '2025-09-20 15:36:44', '2000.00', 1, 1, 'tunai', '0.00', '0.00'),
(18, '2025-09-20 15:50:42', '50000.00', 1, 1, 'tunai', '0.00', '0.00'),
(19, '2025-09-20 19:24:39', '120000.00', 1, 1, 'tunai', '0.00', '0.00'),
(20, '2025-09-20 19:29:17', '15000.00', 1, 1, 'tunai', '0.00', '5000.00'),
(21, '2025-09-20 19:30:26', '150000.00', 1, 1, 'tunai', '200000.00', '50000.00'),
(22, '2025-09-20 19:35:27', '150000.00', 1, 1, 'tunai', '200000.00', '50000.00'),
(23, '2025-09-21 22:09:23', '69000.00', 1, 1, 'qris', '69000.00', '0.00');

-- --------------------------------------------------------

--
-- Table structure for table `transaction_items`
--

CREATE TABLE `transaction_items` (
  `id` int NOT NULL,
  `transaction_id` int NOT NULL,
  `product_id` int NOT NULL,
  `product_unit_id` int NOT NULL,
  `quantity` int NOT NULL,
  `price_per_unit` decimal(10,2) NOT NULL,
  `subtotal` decimal(10,2) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `transaction_items`
--

INSERT INTO `transaction_items` (`id`, `transaction_id`, `product_id`, `product_unit_id`, `quantity`, `price_per_unit`, `subtotal`) VALUES
(1, 2, 2, 3, 2, '2000.00', '4000.00'),
(2, 3, 1, 2, 1, '50000.00', '50000.00'),
(3, 4, 2, 3, 2, '2000.00', '4000.00'),
(4, 5, 2, 3, 1, '2000.00', '2000.00'),
(5, 6, 2, 3, 1, '2000.00', '2000.00'),
(6, 7, 2, 3, 2, '2000.00', '4000.00'),
(7, 8, 2, 3, 9, '2000.00', '18000.00'),
(8, 10, 1, 2, 3, '50000.00', '150000.00'),
(9, 10, 2, 3, 2, '2000.00', '4000.00'),
(10, 11, 2, 3, 2, '2000.00', '4000.00'),
(11, 12, 3, 5, 2, '5000.00', '10000.00'),
(12, 13, 3, 5, 1, '5000.00', '5000.00'),
(13, 14, 1, 2, 1, '50000.00', '50000.00'),
(14, 14, 2, 3, 1, '2000.00', '2000.00'),
(15, 15, 1, 2, 3, '50000.00', '150000.00'),
(16, 16, 1, 2, 2, '50000.00', '100000.00'),
(17, 17, 2, 3, 1, '2000.00', '2000.00'),
(18, 18, 1, 2, 1, '50000.00', '50000.00'),
(19, 19, 1, 2, 2, '0.00', '100000.00'),
(20, 19, 3, 5, 4, '0.00', '20000.00'),
(21, 20, 3, 5, 3, '0.00', '15000.00'),
(22, 21, 1, 2, 3, '0.00', '150000.00'),
(23, 22, 1, 2, 3, '50000.00', '150000.00'),
(24, 23, 4, 6, 3, '15000.00', '45000.00'),
(25, 23, 5, 7, 2, '12000.00', '24000.00');

-- --------------------------------------------------------

--
-- Table structure for table `units`
--

CREATE TABLE `units` (
  `id` int NOT NULL,
  `unit_name` varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `units`
--

INSERT INTO `units` (`id`, `unit_name`) VALUES
(1, 'PCS'),
(2, 'PACK'),
(3, 'DUS');

-- --------------------------------------------------------

--
-- Table structure for table `users`
--

CREATE TABLE `users` (
  `id` int NOT NULL,
  `username` varchar(50) NOT NULL,
  `password` varchar(255) NOT NULL,
  `email` varchar(255) DEFAULT NULL,
  `created_at` datetime DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `store_id` int DEFAULT NULL,
  `role_id` int NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `users`
--

INSERT INTO `users` (`id`, `username`, `password`, `email`, `created_at`, `updated_at`, `store_id`, `role_id`) VALUES
(1, 'superadmin', '$2y$10$WHZATkzyS6b0wMxEGjD14O8cRAIWEHHtPC396u6I1col9OP2fKyt2', 'superadmin@example.com', '2025-09-10 05:06:07', '2025-09-10 05:06:07', NULL, 1),
(3, 'kasir_1', '$2y$10$HbNjzujl79EP6wXWlLUHGO7iltH03WGWAiD0Rc3yFGQXoI4Z9KGPu', 'kasir@1sda.com', '2025-09-10 16:49:28', '2025-09-10 16:49:28', 1, 3),
(4, 'admin_toko', '$2y$10$iBKUP80SjeZCP.YBfQFOge.7.y8wUTCOV48sUBt6KCIA9tJTdtucu', 'admin@toko.com', '2025-09-20 15:24:53', '2025-09-20 15:24:53', 1, 2);

--
-- Indexes for dumped tables
--

--
-- Indexes for table `expenses`
--
ALTER TABLE `expenses`
  ADD PRIMARY KEY (`id`),
  ADD KEY `store_id` (`store_id`),
  ADD KEY `user_id` (`user_id`);

--
-- Indexes for table `products`
--
ALTER TABLE `products`
  ADD PRIMARY KEY (`id`),
  ADD KEY `fk_products_stores` (`store_id`);

--
-- Indexes for table `product_units`
--
ALTER TABLE `product_units`
  ADD PRIMARY KEY (`id`),
  ADD KEY `product_id` (`product_id`),
  ADD KEY `unit_id` (`unit_id`);

--
-- Indexes for table `roles`
--
ALTER TABLE `roles`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `stock_transfers`
--
ALTER TABLE `stock_transfers`
  ADD PRIMARY KEY (`id`),
  ADD KEY `product_unit_id` (`product_unit_id`),
  ADD KEY `user_id` (`user_id`);

--
-- Indexes for table `stores`
--
ALTER TABLE `stores`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `transactions`
--
ALTER TABLE `transactions`
  ADD PRIMARY KEY (`id`),
  ADD KEY `user_id` (`user_id`),
  ADD KEY `store_id` (`store_id`);

--
-- Indexes for table `transaction_items`
--
ALTER TABLE `transaction_items`
  ADD PRIMARY KEY (`id`),
  ADD KEY `transaction_id` (`transaction_id`);

--
-- Indexes for table `units`
--
ALTER TABLE `units`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `users`
--
ALTER TABLE `users`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `username` (`username`),
  ADD KEY `fk_users_stores` (`store_id`),
  ADD KEY `fk_users_roles` (`role_id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `expenses`
--
ALTER TABLE `expenses`
  MODIFY `id` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

--
-- AUTO_INCREMENT for table `products`
--
ALTER TABLE `products`
  MODIFY `id` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;

--
-- AUTO_INCREMENT for table `product_units`
--
ALTER TABLE `product_units`
  MODIFY `id` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=8;

--
-- AUTO_INCREMENT for table `roles`
--
ALTER TABLE `roles`
  MODIFY `id` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;

--
-- AUTO_INCREMENT for table `stock_transfers`
--
ALTER TABLE `stock_transfers`
  MODIFY `id` int NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `stores`
--
ALTER TABLE `stores`
  MODIFY `id` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;

--
-- AUTO_INCREMENT for table `transactions`
--
ALTER TABLE `transactions`
  MODIFY `id` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=24;

--
-- AUTO_INCREMENT for table `transaction_items`
--
ALTER TABLE `transaction_items`
  MODIFY `id` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=26;

--
-- AUTO_INCREMENT for table `units`
--
ALTER TABLE `units`
  MODIFY `id` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;

--
-- AUTO_INCREMENT for table `users`
--
ALTER TABLE `users`
  MODIFY `id` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;

--
-- Constraints for dumped tables
--

--
-- Constraints for table `expenses`
--
ALTER TABLE `expenses`
  ADD CONSTRAINT `expenses_ibfk_1` FOREIGN KEY (`store_id`) REFERENCES `stores` (`id`) ON DELETE SET NULL,
  ADD CONSTRAINT `expenses_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `products`
--
ALTER TABLE `products`
  ADD CONSTRAINT `fk_products_stores` FOREIGN KEY (`store_id`) REFERENCES `stores` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `product_units`
--
ALTER TABLE `product_units`
  ADD CONSTRAINT `product_units_ibfk_1` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `product_units_ibfk_2` FOREIGN KEY (`unit_id`) REFERENCES `units` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `stock_transfers`
--
ALTER TABLE `stock_transfers`
  ADD CONSTRAINT `stock_transfers_ibfk_1` FOREIGN KEY (`product_unit_id`) REFERENCES `product_units` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `stock_transfers_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `transactions`
--
ALTER TABLE `transactions`
  ADD CONSTRAINT `fk_transactions_stores` FOREIGN KEY (`store_id`) REFERENCES `stores` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_transactions_users` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `transaction_items`
--
ALTER TABLE `transaction_items`
  ADD CONSTRAINT `transaction_items_ibfk_1` FOREIGN KEY (`transaction_id`) REFERENCES `transactions` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `users`
--
ALTER TABLE `users`
  ADD CONSTRAINT `fk_users_roles` FOREIGN KEY (`role_id`) REFERENCES `roles` (`id`) ON DELETE RESTRICT,
  ADD CONSTRAINT `fk_users_stores` FOREIGN KEY (`store_id`) REFERENCES `stores` (`id`) ON DELETE SET NULL;
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 */;
