-- https://www.phpmyadmin.net/
--

START TRANSACTION;



--
-- Database: `velvetcr_zt_mobile`
--

DELIMITER $$
--
-- Procedures
--
$$

DELIMITER ;

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

--
-- Table structure for table `audit_log`
--

CREATE TABLE `audit_log` (
  `id` bigint(20) NOT NULL,
  `user_id` int(11) NOT NULL,
  `action` varchar(40) NOT NULL,
  `entity` varchar(40) NOT NULL,
  `entity_id` bigint(20) DEFAULT NULL,
  `meta_json` text DEFAULT NULL,
  `created_at` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Table structure for table `cashbook`
--

CREATE TABLE `cashbook` (
  `id` bigint(20) NOT NULL,
  `type` enum('in','out') NOT NULL,
  `amount` decimal(12,2) NOT NULL,
  `ref_type` varchar(40) NOT NULL,
  `ref_id` bigint(20) NOT NULL,
  `note` varchar(200) DEFAULT NULL,
  `created_at` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Table structure for table `device_catalog`
--

CREATE TABLE `device_catalog` (
  `id` int(10) UNSIGNED NOT NULL,
  `brand` varchar(80) NOT NULL,
  `model` varchar(160) NOT NULL,
  `release_date` date DEFAULT NULL,
  `release_year` smallint(6) DEFAULT NULL,
  `image_url` varchar(500) DEFAULT NULL,
  `source` varchar(40) DEFAULT NULL,
  `source_id` int(10) UNSIGNED DEFAULT NULL,
  `source_key` varchar(120) DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `storage_raw` varchar(255) DEFAULT NULL,
  `ram_raw` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `device_catalog`
--

INSERT INTO `device_catalog` (`id`, `brand`, `model`, `release_date`, `release_year`, `image_url`, `source`, `source_id`, `source_key`, `created_at`, `updated_at`, `storage_raw`, `ram_raw`) VALUES
(1, 'Samsung', 'Galaxy S9', '2018-03-01', 2018, NULL, 'manual', NULL, NULL, '2026-02-02 03:14:29', '2026-02-02 03:14:29', NULL, NULL),
(2, 'Apple', 'iPhone XS', '2018-09-01', 2018, NULL, 'manual', NULL, NULL, '2026-02-02 03:14:29', '2026-02-02 03:14:29', NULL, NULL),
(3, 'Samsung', 'Galaxy A50', NULL, 2019, NULL, NULL, NULL, NULL, '2026-02-02 05:13:08', '2026-02-02 05:13:08', NULL, NULL);

--
-- Triggers `device_catalog`
--
DELIMITER $$
CREATE TRIGGER `trg_device_catalog_ai` AFTER INSERT ON `device_catalog` FOR EACH ROW BEGIN
  INSERT IGNORE INTO device_variants (device_id, storage_gb, ram_gb, notes)
  SELECT NEW.id, p.storage_gb, p.ram_gb, p.notes
  FROM device_variant_presets p
  WHERE p.is_enabled = 1
    AND (p.brand IS NULL OR p.brand = NEW.brand);
END
$$
DELIMITER ;

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

--
-- Table structure for table `device_catalog_sync_log`
--

CREATE TABLE `device_catalog_sync_log` (
  `id` int(10) UNSIGNED NOT NULL,
  `source` varchar(40) NOT NULL,
  `ran_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `status` varchar(20) NOT NULL,
  `notes` text DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Table structure for table `device_variants`
--

CREATE TABLE `device_variants` (
  `id` int(10) UNSIGNED NOT NULL,
  `device_id` int(10) UNSIGNED NOT NULL,
  `storage_gb` smallint(5) UNSIGNED NOT NULL,
  `ram_gb` smallint(5) UNSIGNED NOT NULL,
  `notes` varchar(120) DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `device_variants`
--

INSERT INTO `device_variants` (`id`, `device_id`, `storage_gb`, `ram_gb`, `notes`, `created_at`) VALUES
(1, 1, 64, 4, NULL, '2026-02-02 03:26:44'),
(2, 1, 128, 4, NULL, '2026-02-02 03:26:44'),
(3, 2, 64, 4, NULL, '2026-02-02 03:27:02'),
(4, 2, 256, 4, NULL, '2026-02-02 03:27:02'),
(6, 1, 128, 6, NULL, '2026-02-02 03:39:09'),
(8, 1, 256, 8, NULL, '2026-02-02 03:39:09'),
(13, 1, 32, 3, NULL, '2026-02-02 03:51:26'),
(15, 1, 128, 8, NULL, '2026-02-02 03:51:26'),
(17, 1, 256, 12, NULL, '2026-02-02 03:51:26'),
(19, 1, 512, 12, NULL, '2026-02-02 03:51:26'),
(31, 3, 32, 3, NULL, '2026-02-02 05:13:08'),
(32, 3, 64, 4, NULL, '2026-02-02 05:13:08'),
(33, 3, 128, 4, NULL, '2026-02-02 05:13:08'),
(34, 3, 128, 6, NULL, '2026-02-02 05:13:08'),
(35, 3, 128, 8, NULL, '2026-02-02 05:13:08'),
(36, 3, 256, 8, NULL, '2026-02-02 05:13:08'),
(37, 3, 256, 12, NULL, '2026-02-02 05:13:08'),
(38, 3, 512, 12, NULL, '2026-02-02 05:13:08'),
(56, 2, 512, 4, NULL, '2026-02-02 05:35:29');

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

--
-- Table structure for table `device_variant_presets`
--

CREATE TABLE `device_variant_presets` (
  `id` int(10) UNSIGNED NOT NULL,
  `brand` varchar(80) DEFAULT NULL,
  `storage_gb` smallint(5) UNSIGNED NOT NULL,
  `ram_gb` smallint(5) UNSIGNED NOT NULL,
  `notes` varchar(120) DEFAULT NULL,
  `is_enabled` tinyint(1) NOT NULL DEFAULT 1
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `device_variant_presets`
--

INSERT INTO `device_variant_presets` (`id`, `brand`, `storage_gb`, `ram_gb`, `notes`, `is_enabled`) VALUES
(1, NULL, 32, 3, NULL, 1),
(2, NULL, 64, 4, NULL, 1),
(3, NULL, 128, 4, NULL, 1),
(4, NULL, 128, 6, NULL, 1),
(5, NULL, 128, 8, NULL, 1),
(6, NULL, 256, 8, NULL, 1),
(7, NULL, 256, 12, NULL, 1),
(8, NULL, 512, 12, NULL, 1);

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

--
-- Table structure for table `expenses`
--

CREATE TABLE `expenses` (
  `id` bigint(20) NOT NULL,
  `expense_date` date NOT NULL,
  `head_id` int(11) NOT NULL,
  `amount` decimal(12,2) NOT NULL,
  `pay_method` enum('cash','bank','jazzcash','easypaisa') NOT NULL DEFAULT 'cash',
  `note` varchar(255) DEFAULT NULL,
  `created_by` int(11) NOT NULL,
  `created_at` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Table structure for table `expense_heads`
--

CREATE TABLE `expense_heads` (
  `id` int(11) NOT NULL,
  `name` varchar(120) NOT NULL,
  `is_fixed` tinyint(4) NOT NULL DEFAULT 0,
  `created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `expense_heads`
--

INSERT INTO `expense_heads` (`id`, `name`, `is_fixed`, `created_at`) VALUES
(1, 'Shop Rent / Shop Bill', 1, '2026-02-01 22:49:30'),
(2, 'Electricity Bill', 1, '2026-02-01 22:49:30'),
(3, 'Gas Bill', 1, '2026-02-01 22:49:30'),
(4, 'Water Bill', 1, '2026-02-01 22:49:30'),
(5, 'Internet', 1, '2026-02-01 22:49:30'),
(6, 'Mobile Load', 1, '2026-02-01 22:49:30'),
(7, 'Shop Entertainment', 1, '2026-02-01 22:49:30'),
(8, 'Salaries / Wages', 1, '2026-02-01 22:49:30'),
(9, 'Tea / Refreshment', 1, '2026-02-01 22:49:30'),
(10, 'Transport / Fuel', 1, '2026-02-01 22:49:30'),
(11, 'Repair / Parts Expense', 1, '2026-02-01 22:49:30'),
(12, 'Maintenance', 1, '2026-02-01 22:49:30'),
(13, 'Miscellaneous', 1, '2026-02-01 22:49:30');

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

--
-- Table structure for table `parties`
--

CREATE TABLE `parties` (
  `id` int(10) UNSIGNED NOT NULL,
  `party_type` enum('customer','supplier','both') NOT NULL DEFAULT 'customer',
  `name` varchar(120) NOT NULL,
  `phone` varchar(30) DEFAULT NULL,
  `cnic` varchar(25) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `parties`
--

INSERT INTO `parties` (`id`, `party_type`, `name`, `phone`, `cnic`, `created_at`, `updated_at`) VALUES
(1, 'customer', 'Test Customer', '03001234567', NULL, '2026-02-02 05:13:44', NULL),
(2, 'supplier', 'Test Supplier', '03007654321', NULL, '2026-02-02 05:14:00', NULL);

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

--
-- Table structure for table `party_ledger`
--

CREATE TABLE `party_ledger` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `party_id` int(10) UNSIGNED NOT NULL,
  `txn_date` date NOT NULL,
  `ref_type` varchar(30) NOT NULL,
  `ref_id` bigint(20) UNSIGNED DEFAULT NULL,
  `amount` decimal(12,2) NOT NULL,
  `note` varchar(255) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Table structure for table `payments`
--

CREATE TABLE `payments` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `txn_date` date NOT NULL,
  `party_id` int(10) UNSIGNED DEFAULT NULL,
  `direction` enum('in','out') NOT NULL,
  `amount` decimal(12,2) NOT NULL,
  `method` varchar(20) NOT NULL DEFAULT 'cash',
  `note` varchar(255) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Table structure for table `products`
--

CREATE TABLE `products` (
  `id` int(11) NOT NULL,
  `type` enum('accessory','new_mobile') NOT NULL DEFAULT 'accessory',
  `name` varchar(160) NOT NULL,
  `cost_price` decimal(12,2) NOT NULL DEFAULT 0.00,
  `sale_price` decimal(12,2) NOT NULL DEFAULT 0.00,
  `qty` int(11) NOT NULL DEFAULT 0,
  `low_stock` int(11) NOT NULL DEFAULT 0,
  `created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `products`
--

INSERT INTO `products` (`id`, `type`, `name`, `cost_price`, `sale_price`, `qty`, `low_stock`, `created_at`) VALUES
(1, 'accessory', 'Charger', 300.00, 500.00, 50, 10, '2026-02-01 22:49:30'),
(2, 'accessory', 'Handsfree', 250.00, 450.00, 40, 10, '2026-02-01 22:49:30'),
(3, 'accessory', 'Back Cover', 80.00, 150.00, 100, 20, '2026-02-01 22:49:30'),
(4, 'accessory', 'Screen Protector', 30.00, 80.00, 200, 30, '2026-02-01 22:49:30');

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

--
-- Table structure for table `repairs`
--

CREATE TABLE `repairs` (
  `id` bigint(20) NOT NULL,
  `customer_name` varchar(160) NOT NULL,
  `customer_phone` varchar(40) DEFAULT NULL,
  `device` varchar(160) NOT NULL,
  `issue` varchar(255) NOT NULL,
  `estimate` decimal(12,2) NOT NULL DEFAULT 0.00,
  `advance` decimal(12,2) NOT NULL DEFAULT 0.00,
  `due_date` date DEFAULT NULL,
  `status` enum('received','in_progress','ready','delivered','cancelled') NOT NULL DEFAULT 'received',
  `created_by` int(11) NOT NULL,
  `created_at` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Table structure for table `roles`
--

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

--
-- Dumping data for table `roles`
--

INSERT INTO `roles` (`id`, `name`) VALUES
(1, 'admin'),
(3, 'cashier'),
(2, 'manager'),
(4, 'viewer');

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

--
-- Table structure for table `sales`
--

CREATE TABLE `sales` (
  `id` bigint(20) NOT NULL,
  `sale_date` date NOT NULL,
  `customer_name` varchar(160) DEFAULT NULL,
  `customer_phone` varchar(40) DEFAULT NULL,
  `pay_method` enum('cash','bank','jazzcash','easypaisa') NOT NULL DEFAULT 'cash',
  `total_amount` decimal(12,2) NOT NULL,
  `total_cost` decimal(12,2) NOT NULL,
  `gross_profit` decimal(12,2) NOT NULL,
  `discount` decimal(12,2) NOT NULL DEFAULT 0.00,
  `notes` text DEFAULT NULL,
  `created_by` int(11) NOT NULL,
  `created_at` datetime NOT NULL,
  `customer_id` int(10) UNSIGNED DEFAULT NULL,
  `paid_amount` decimal(12,2) NOT NULL DEFAULT 0.00,
  `due_amount` decimal(12,2) NOT NULL DEFAULT 0.00
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Table structure for table `sales_items`
--

CREATE TABLE `sales_items` (
  `id` bigint(20) NOT NULL,
  `sale_id` bigint(20) NOT NULL,
  `item_kind` enum('product','used_mobile') NOT NULL,
  `ref_id` bigint(20) NOT NULL,
  `title` varchar(200) NOT NULL,
  `qty` int(11) NOT NULL,
  `unit_price` decimal(12,2) NOT NULL,
  `unit_cost` decimal(12,2) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Table structure for table `used_mobiles`
--

CREATE TABLE `used_mobiles` (
  `id` bigint(20) NOT NULL,
  `purchase_id` bigint(20) NOT NULL,
  `brand` varchar(80) NOT NULL,
  `model` varchar(120) NOT NULL,
  `storage` varchar(40) DEFAULT NULL,
  `color` varchar(40) DEFAULT NULL,
  `phone_condition` varchar(40) DEFAULT NULL,
  `imei1` varchar(40) NOT NULL,
  `imei2` varchar(40) DEFAULT NULL,
  `cost_price` decimal(12,2) NOT NULL,
  `status` enum('available','sold','repair') NOT NULL DEFAULT 'available',
  `sold_sale_id` bigint(20) DEFAULT NULL,
  `created_at` datetime NOT NULL,
  `device_id` int(10) UNSIGNED DEFAULT NULL,
  `variant_id` int(10) UNSIGNED DEFAULT NULL,
  `storage_gb` smallint(5) UNSIGNED DEFAULT NULL,
  `ram_gb` smallint(5) UNSIGNED DEFAULT NULL,
  `is_sold` tinyint(1) NOT NULL DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Table structure for table `used_purchases`
--

CREATE TABLE `used_purchases` (
  `id` bigint(20) NOT NULL,
  `purchase_date` date NOT NULL,
  `seller_name` varchar(160) NOT NULL,
  `seller_phone` varchar(40) DEFAULT NULL,
  `seller_cnic` varchar(30) NOT NULL,
  `brand` varchar(80) NOT NULL,
  `model` varchar(120) NOT NULL,
  `storage` varchar(40) DEFAULT NULL,
  `color` varchar(40) DEFAULT NULL,
  `phone_condition` varchar(40) DEFAULT NULL,
  `imei1` varchar(40) NOT NULL,
  `imei2` varchar(40) DEFAULT NULL,
  `purchase_price` decimal(12,2) NOT NULL,
  `notes` text DEFAULT NULL,
  `photo_file` varchar(255) DEFAULT NULL,
  `photo_thumb` varchar(255) DEFAULT NULL,
  `photo_size_kb` int(11) DEFAULT NULL,
  `photo_created_at` datetime DEFAULT NULL,
  `created_by` int(11) NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `seller_id` int(10) UNSIGNED DEFAULT NULL,
  `paid_amount` decimal(12,2) NOT NULL DEFAULT 0.00,
  `due_amount` decimal(12,2) NOT NULL DEFAULT 0.00
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `audit_log`
--
ALTER TABLE `audit_log`
  ADD PRIMARY KEY (`id`),
  ADD KEY `user_id` (`user_id`),
  ADD KEY `entity` (`entity`,`entity_id`);

--
-- Indexes for table `cashbook`
--
ALTER TABLE `cashbook`
  ADD PRIMARY KEY (`id`),
  ADD KEY `created_at` (`created_at`);

--
-- Indexes for table `device_catalog`
--
ALTER TABLE `device_catalog`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_brand_model` (`brand`,`model`),
  ADD KEY `idx_brand` (`brand`),
  ADD KEY `idx_model` (`model`),
  ADD KEY `idx_release_year` (`release_year`);
ALTER TABLE `device_catalog` ADD FULLTEXT KEY `ft_brand_model` (`brand`,`model`);

--
-- Indexes for table `device_catalog_sync_log`
--
ALTER TABLE `device_catalog_sync_log`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `device_variants`
--
ALTER TABLE `device_variants`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_variant` (`device_id`,`storage_gb`,`ram_gb`),
  ADD KEY `idx_device` (`device_id`),
  ADD KEY `idx_storage` (`storage_gb`),
  ADD KEY `idx_ram` (`ram_gb`);

--
-- Indexes for table `device_variant_presets`
--
ALTER TABLE `device_variant_presets`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_preset` (`brand`,`storage_gb`,`ram_gb`,`notes`),
  ADD KEY `idx_brand` (`brand`);

--
-- Indexes for table `expenses`
--
ALTER TABLE `expenses`
  ADD PRIMARY KEY (`id`),
  ADD KEY `expense_date` (`expense_date`),
  ADD KEY `head_id` (`head_id`),
  ADD KEY `created_by` (`created_by`);

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

--
-- Indexes for table `parties`
--
ALTER TABLE `parties`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_party_phone` (`phone`),
  ADD KEY `idx_party_name` (`name`),
  ADD KEY `idx_party_cnic` (`cnic`);

--
-- Indexes for table `party_ledger`
--
ALTER TABLE `party_ledger`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_party_date` (`party_id`,`txn_date`),
  ADD KEY `idx_ref` (`ref_type`,`ref_id`);

--
-- Indexes for table `payments`
--
ALTER TABLE `payments`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_pay_date` (`txn_date`),
  ADD KEY `idx_party_date` (`party_id`,`txn_date`);

--
-- Indexes for table `products`
--
ALTER TABLE `products`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `repairs`
--
ALTER TABLE `repairs`
  ADD PRIMARY KEY (`id`),
  ADD KEY `status` (`status`),
  ADD KEY `created_by` (`created_by`);

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

--
-- Indexes for table `sales`
--
ALTER TABLE `sales`
  ADD PRIMARY KEY (`id`),
  ADD KEY `sale_date` (`sale_date`),
  ADD KEY `created_by` (`created_by`);

--
-- Indexes for table `sales_items`
--
ALTER TABLE `sales_items`
  ADD PRIMARY KEY (`id`),
  ADD KEY `sale_id` (`sale_id`);

--
-- Indexes for table `used_mobiles`
--
ALTER TABLE `used_mobiles`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_used_imei1` (`imei1`),
  ADD KEY `status` (`status`),
  ADD KEY `purchase_id` (`purchase_id`),
  ADD KEY `idx_device_id` (`device_id`),
  ADD KEY `idx_variant_id` (`variant_id`);

--
-- Indexes for table `used_purchases`
--
ALTER TABLE `used_purchases`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_imei1` (`imei1`),
  ADD KEY `purchase_date` (`purchase_date`),
  ADD KEY `created_by` (`created_by`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `audit_log`
--
ALTER TABLE `audit_log`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `cashbook`
--
ALTER TABLE `cashbook`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT;

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

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

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

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

--
-- AUTO_INCREMENT for table `expenses`
--
ALTER TABLE `expenses`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT;

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

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

--
-- AUTO_INCREMENT for table `party_ledger`
--
ALTER TABLE `party_ledger`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `payments`
--
ALTER TABLE `payments`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

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

--
-- AUTO_INCREMENT for table `repairs`
--
ALTER TABLE `repairs`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT;

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

--
-- AUTO_INCREMENT for table `sales`
--
ALTER TABLE `sales`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `sales_items`
--
ALTER TABLE `sales_items`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `used_mobiles`
--
ALTER TABLE `used_mobiles`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `used_purchases`
--
ALTER TABLE `used_purchases`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT;

--
-- Constraints for dumped tables
--

--
-- Constraints for table `audit_log`
--
ALTER TABLE `audit_log`
  ADD CONSTRAINT `audit_log_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`);

--
-- Constraints for table `device_variants`
--
ALTER TABLE `device_variants`
  ADD CONSTRAINT `fk_variant_device` FOREIGN KEY (`device_id`) REFERENCES `device_catalog` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `expenses`
--
ALTER TABLE `expenses`
  ADD CONSTRAINT `expenses_ibfk_1` FOREIGN KEY (`head_id`) REFERENCES `expense_heads` (`id`),
  ADD CONSTRAINT `expenses_ibfk_2` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`);

--
-- Constraints for table `party_ledger`
--
ALTER TABLE `party_ledger`
  ADD CONSTRAINT `fk_party_ledger_party` FOREIGN KEY (`party_id`) REFERENCES `parties` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `payments`
--
ALTER TABLE `payments`
  ADD CONSTRAINT `fk_pay_party` FOREIGN KEY (`party_id`) REFERENCES `parties` (`id`) ON DELETE SET NULL;

--
-- Constraints for table `repairs`
--
ALTER TABLE `repairs`
  ADD CONSTRAINT `repairs_ibfk_1` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`);

--
-- Constraints for table `sales`
--
ALTER TABLE `sales`
  ADD CONSTRAINT `sales_ibfk_1` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`);

--
-- Constraints for table `sales_items`
--
ALTER TABLE `sales_items`
  ADD CONSTRAINT `sales_items_ibfk_1` FOREIGN KEY (`sale_id`) REFERENCES `sales` (`id`);

--
-- Constraints for table `used_mobiles`
--
ALTER TABLE `used_mobiles`
  ADD CONSTRAINT `used_mobiles_ibfk_1` FOREIGN KEY (`purchase_id`) REFERENCES `used_purchases` (`id`);

--
-- Constraints for table `used_purchases`
--
ALTER TABLE `used_purchases`
  ADD CONSTRAINT `used_purchases_ibfk_1` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`);
COMMIT;

