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

START TRANSACTION;

--
-- Database: `abcoedtech_vksolar_multi`
--

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

--
-- Table structure for table `advance_payments`
--

CREATE TABLE `advance_payments` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `client_id` int(11) NOT NULL,
  `amount` decimal(12,2) NOT NULL,
  `payment_mode` varchar(50) NOT NULL,
  `payment_date` date NOT NULL,
  `remarks` text DEFAULT NULL,
  `receipt_number` varchar(50) DEFAULT NULL,
  `created_by` int(11) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `advance_payments`
--

INSERT INTO `advance_payments` (`id`, `tenant_id`, `client_id`, `amount`, `payment_mode`, `payment_date`, `remarks`, `receipt_number`, `created_by`, `created_at`) VALUES
(1, 1, 7, 10000.00, 'Cash', '2026-02-04', '', 'RV2026020400701', 2, '2026-02-04 11:46:26'),
(2, 1, 2, 10000.00, 'Cash', '2026-02-10', '', 'RV2026021000201', 2, '2026-02-10 09:58:24');

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

--
-- Table structure for table `bank_quotations`
--

CREATE TABLE `bank_quotations` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `client_id` int(11) NOT NULL,
  `quotation_number` varchar(100) NOT NULL,
  `quotation_date` date NOT NULL,
  `validity_date` date NOT NULL,
  `customer_name` varchar(255) DEFAULT NULL,
  `customer_address` text DEFAULT NULL,
  `pin_code` varchar(10) DEFAULT NULL,
  `customer_phone` varchar(20) DEFAULT NULL,
  `customer_email` varchar(100) DEFAULT NULL,
  `project_location` varchar(255) DEFAULT NULL,
  `plant_capacity` varchar(50) DEFAULT NULL,
  `system_type` varchar(50) DEFAULT NULL,
  `estimated_generation` varchar(100) DEFAULT NULL,
  `system_description` text DEFAULT NULL,
  `bank_id` int(11) NOT NULL,
  `total_amount` decimal(12,2) DEFAULT NULL,
  `subsidy` decimal(12,2) DEFAULT NULL,
  `final_amount` decimal(12,2) DEFAULT NULL,
  `status` enum('draft','final') DEFAULT 'draft',
  `created_by` int(11) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `bank_quotations`
--

INSERT INTO `bank_quotations` (`id`, `tenant_id`, `client_id`, `quotation_number`, `quotation_date`, `validity_date`, `customer_name`, `customer_address`, `pin_code`, `customer_phone`, `customer_email`, `project_location`, `plant_capacity`, `system_type`, `estimated_generation`, `system_description`, `bank_id`, `total_amount`, `subsidy`, `final_amount`, `status`, `created_by`, `created_at`, `updated_at`) VALUES
(1, 1, 1, '01', '2026-01-10', '2026-04-10', 'SHRI MANOHAR TEMBHURKAR', 'TEACHER COLONY WARD NO. 07 TALODHI NAGBHID CHANDRAPUR', '999999', '9822121061', 'temburkaranshul.maddy@gmail.com', 'TEACHER COLONY WARD NO. 07 TALODHI NAGBHID CHANDRAPUR', '3 kWp', 'On Grid', '45000', '0', 2, 200000.00, 78000.00, 122000.00, 'draft', 2, '2026-01-10 06:22:09', '2026-02-16 05:40:25'),
(2, 1, 1, '01', '2026-01-10', '2026-04-10', 'SHRI MANOHAR TEMBHURKAR', 'TEACHER COLONY WARD NO. 07 TALODHI NAGBHID CHANDRAPUR', '999999', '9822121061', 'temburkaranshul.maddy@gmail.com', 'TEACHER COLONY WARD NO. 07 TALODHI NAGBHID CHANDRAPUR', '3 kWp', 'On Grid', '45000', 'Sale of solar power generating system including supply, installation, and commissioning of 3kW On-Grid solar PV system, complete with solar panels, 3kW inverter, all other accessories, net meter and connecting cables, including elevated standard structures.', 2, 200000.00, 78000.00, 122000.00, 'draft', 2, '2026-01-10 06:24:50', '2026-02-16 05:40:25'),
(3, 1, 6, '2', '2026-01-10', '2026-04-10', 'NANDA NARAYAN LAYSE', 'p no 29 pathan layout parsodi nagpur 440022', '440022', '7972740850', 'shaileshlayase@gmail.com', 'p no 29 pathan layout parsodi nagpur 440022', ' 3 kWp', 'On Grid', '4500', 'Sale of solar power generating system including supply, installation, and commissioning of 3kW On-Grid solar PV system, complete with solar panels, 3kW inverter, all other accessories, net meter and connecting cables, including elevated standard structures.', 2, 200000.00, 78000.00, 122000.00, 'draft', 2, '2026-01-10 09:56:43', '2026-02-16 05:40:25'),
(4, 1, 6, '2', '2026-01-10', '2026-04-10', 'NANDA NARAYAN LAYSE', 'p no 29 pathan layout parsodi nagpur 440022', '440022', '7972740850', 'shaileshlayase@gmail.com', 'p no 29 pathan layout parsodi nagpur 440022', ' 3 kWp', 'On Grid', '4500', 'Sale of solar power generating system including supply, installation, and commissioning of 3kW On-Grid solar PV system, complete with solar panels, 3kW inverter, all other accessories, net meter and connecting cables, including elevated standard structures.', 2, 200000.00, 78000.00, 122000.00, 'draft', 2, '2026-01-10 10:06:10', '2026-02-16 05:40:25'),
(5, 1, 7, 'v123', '2026-01-13', '2026-04-13', 'JAYSHREE JIWAN GOURKHEDE', 'pl no 71 govt press layout dhaba nagpur 440016', '440016', '8999466479', 'abhishekgourkhede88@gmail.com', 'pl no 71 govt press layout dhaba nagpur 440016', ' kWp', 'On Grid', '4500', 'Sale of solar power generating system including supply, installation, and commissioning of 3kW On-Grid solar PV system, complete with solar panels, 3kW inverter, all other accessories, net meter and connecting cables, including elevated standard structures.', 2, 1000.00, 60.00, 940.00, 'draft', 2, '2026-01-13 11:34:44', '2026-02-16 05:40:25'),
(6, 1, 7, 'v123', '2026-01-13', '2026-04-13', 'JAYSHREE JIWAN GOURKHEDE', 'pl no 71 govt press layout dhaba nagpur 440016', '440016', '8999466479', 'abhishekgourkhede88@gmail.com', 'pl no 71 govt press layout dhaba nagpur 440016', ' kWp', 'On Grid', '4500', 'Sale of solar power generating system including supply, installation, and commissioning of 3kW On-Grid solar PV system, complete with solar panels, 3kW inverter, all other accessories, net meter and connecting cables, including elevated standard structures.', 2, 200000.00, 78000.00, 122000.00, 'draft', 2, '2026-01-16 11:52:42', '2026-02-16 05:40:25'),
(7, 1, 7, 'v123', '2026-01-13', '2026-04-13', 'JAYSHREE JIWAN GOURKHEDE', 'pl no 71 govt press layout dhaba nagpur 440016', '440016', '8999466479', 'abhishekgourkhede88@gmail.com', 'pl no 71 govt press layout dhaba nagpur 440016', ' kWp', 'On Grid', '4500', 'Sale of solar power generating system including supply, installation, and commissioning of 5kW On-Grid solar PV system, complete with solar panels, 3kW inverter, all other accessories, net meter and connecting cables, including elevated standard structures.', 2, 200000.00, 78000.00, 122000.00, 'draft', 2, '2026-01-16 11:55:01', '2026-02-16 05:40:25'),
(8, 1, 7, 'v123', '2026-01-13', '2026-04-13', 'JAYSHREE JIWAN GOURKHEDE', 'pl no 71 govt press layout dhaba nagpur 440016', '440016', '8999466479', 'abhishekgourkhede88@gmail.com', 'pl no 71 govt press layout dhaba nagpur 440016', ' kWp', 'On Grid', '4500', 'Sale of solar power generating system including supply, installation, and commissioning of 5kW On-Grid solar PV system, complete with solar panels, 3kW inverter, all other accessories, net meter and connecting cables, including elevated standard structures.', 2, 200000.00, 78000.00, 122000.00, 'draft', 2, '2026-01-16 11:58:28', '2026-02-16 05:40:25'),
(9, 1, 6, '2', '2026-01-10', '2026-04-10', 'NANDA NARAYAN LAYSE', 'p no 29 pathan layout parsodi nagpur 440022', '440022', '7972740850', 'shaileshlayase@gmail.com', 'p no 29 pathan layout parsodi nagpur 440022', ' 3 kWp', 'On Grid', '4500', 'Sale of solar power generating system including supply, installation, and commissioning of 3kW On-Grid solar PV system, complete with solar panels, 3kW inverter, all other accessories, net meter and connecting cables, including elevated standard structures.', 2, 200000.00, 78000.00, 122000.00, 'draft', 2, '2026-02-10 10:07:09', '2026-02-16 05:40:25'),
(10, 1, 7, 'v123', '2026-01-13', '2026-04-13', 'JAYSHREE JIWAN GOURKHEDE', 'pl no 71 govt press layout dhaba nagpur 440016', '440016', '8999466479', 'abhishekgourkhede88@gmail.com', 'pl no 71 govt press layout dhaba nagpur 440016', ' kWp', 'On Grid', '4500', 'Sale of solar power generating system including supply, installation, and commissioning of 5kW On-Grid solar PV system, complete with solar panels, 3kW inverter, all other accessories, net meter and connecting cables, including elevated standard structures.', 2, 200000.00, 78000.00, 122000.00, 'draft', 2, '2026-02-11 09:23:08', '2026-02-16 05:40:25');

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

--
-- Table structure for table `bank_quotation_products`
--

CREATE TABLE `bank_quotation_products` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `quotation_id` int(11) NOT NULL,
  `description` text DEFAULT NULL,
  `quantity` int(11) DEFAULT NULL,
  `unit_price` decimal(12,2) DEFAULT NULL,
  `amount` decimal(12,2) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `bank_quotation_products`
--

INSERT INTO `bank_quotation_products` (`id`, `tenant_id`, `quotation_id`, `description`, `quantity`, `unit_price`, `amount`) VALUES
(2, 1, 2, 'Sale of solar power generating system including supply, installation, and commissioning of 3kW On-Grid solar PV system', 1, 200000.00, 200000.00),
(3, 1, 1, 'Sale of solar power generating system including supply, installation, and commissioning of 3kW On-Grid solar PV system', 1, 200000.00, 200000.00),
(4, 1, 3, 'Sale of solar power generating system including supply, installation, and commissioning of 3kW On-Grid solar PV system', 1, 200000.00, 200000.00),
(5, 1, 4, 'Sale of solar power generating system including supply, installation, and commissioning of 3kW On-Grid solar PV system', 1, 200000.00, 200000.00),
(6, 1, 5, 'Sale of solar power generating system including supply, installation, and commissioning of 3kW On-Grid solar PV system', 10, 100.00, 1000.00),
(7, 1, 6, 'Sale of solar power generating system including supply, installation, and commissioning of 3kW On-Grid solar PV system', 1, 200000.00, 200000.00),
(8, 1, 7, 'Sale of solar power generating system including supply, installation, and commissioning of 5 kW On-Grid solar PV system', 1, 200000.00, 200000.00),
(9, 1, 8, 'Sale of solar power generating system including supply, installation, and commissioning of 5 kW On-Grid solar PV system', 1, 200000.00, 200000.00),
(10, 1, 9, 'Sale of solar power generating system including supply, installation, and commissioning of 3kW On-Grid solar PV system', 1, 200000.00, 200000.00),
(11, 1, 10, 'Sale of solar power generating system including supply, installation, and commissioning of 5 kW On-Grid solar PV system', 1, 200000.00, 200000.00);

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

--
-- Table structure for table `client_documents`
--

CREATE TABLE `client_documents` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `client_id` int(11) NOT NULL,
  `document_type` enum('aadhar','electric_bill','pan_card','bank_passbook','bank_statement','it_return','other','fitting_photos','pm_documents','rts_document','meter_photo','subsidy_redeem','solar_panel_photo','inverter_photo','geotag_photo','model_agreement','dcr_certificate','salary_slip','gumasta','client_signature') NOT NULL,
  `file_path` varchar(500) NOT NULL,
  `file_name` varchar(255) DEFAULT NULL,
  `file_size` int(11) DEFAULT NULL,
  `mime_type` varchar(100) DEFAULT NULL,
  `original_filename` varchar(255) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `client_documents`
--

INSERT INTO `client_documents` (`id`, `tenant_id`, `client_id`, `document_type`, `file_path`, `file_name`, `file_size`, `mime_type`, `original_filename`, `created_at`) VALUES
(1, 1, 4, 'inverter_photo', 'uploads/clients/4/fitting_photos/inverter_photo_1768633302.jpeg', 'inverter_photo_1768633302.jpeg', NULL, NULL, 'sachin thamke inverter .jpeg', '2026-01-17 07:01:42'),
(2, 1, 4, 'geotag_photo', 'uploads/clients/4/fitting_photos/geotag_photo_1768633302.jpeg', 'geotag_photo_1768633302.jpeg', NULL, NULL, 'sachin thamke geo pic .jpeg', '2026-01-17 07:01:42'),
(3, 1, 4, 'meter_photo', 'uploads/clients/4/meter_photos/meter_photo_1768633828.jpeg', 'meter_photo_1768633828.jpeg', NULL, NULL, 'SACHIN THAMKE  METER.jpeg', '2026-01-17 07:10:28'),
(4, 1, 9, 'geotag_photo', '/admin/uploads/client_documents/9_geotag_photo_1768900930_718a1bfbcafe.jpeg', '9_geotag_photo_1768900930_718a1bfbcafe.jpeg', 205286, 'image/jpeg', 'praful site .jpeg', '2026-01-20 09:22:10');

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

--
-- Table structure for table `commissioning_certificates`
--

CREATE TABLE `commissioning_certificates` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `client_id` int(11) NOT NULL,
  `consumer_name` varchar(255) DEFAULT NULL,
  `consumer_number` varchar(100) DEFAULT NULL,
  `mobile_number` varchar(20) DEFAULT NULL,
  `email` varchar(255) DEFAULT NULL,
  `installation_address` text DEFAULT NULL,
  `re_arrangement_type` varchar(255) DEFAULT NULL,
  `re_source` varchar(255) DEFAULT NULL,
  `sanctioned_capacity` decimal(10,2) DEFAULT NULL,
  `capacity_type` varchar(100) DEFAULT NULL,
  `project_model` varchar(255) DEFAULT NULL,
  `installation_date` date DEFAULT NULL,
  `leter_no` varchar(20) NOT NULL,
  `inverter_capacity` decimal(10,2) DEFAULT NULL,
  `inverter_make` varchar(255) DEFAULT NULL,
  `number_of_modules` int(11) DEFAULT NULL,
  `module_capacity` int(11) DEFAULT NULL,
  `module_make` varchar(255) DEFAULT NULL,
  `company_name` varchar(255) DEFAULT NULL,
  `rep_name` varchar(255) DEFAULT NULL,
  `company_phone` varchar(50) DEFAULT NULL,
  `company_email` varchar(255) DEFAULT NULL,
  `created_at` datetime DEFAULT current_timestamp(),
  `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Table structure for table `company_bank_details`
--

CREATE TABLE `company_bank_details` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `bank_name` varchar(255) NOT NULL,
  `branch_name` varchar(255) NOT NULL,
  `account_number` varchar(50) NOT NULL,
  `account_type` varchar(50) DEFAULT NULL,
  `ifsc_code` varchar(20) NOT NULL,
  `bank_gst` varchar(50) DEFAULT NULL,
  `is_active` tinyint(1) DEFAULT 1,
  `created_by` int(11) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `company_bank_details`
--

INSERT INTO `company_bank_details` (`id`, `tenant_id`, `bank_name`, `branch_name`, `account_number`, `account_type`, `ifsc_code`, `bank_gst`, `is_active`, `created_by`, `created_at`, `updated_at`) VALUES
(1, 1, 'BOI', 'Godhani', 'bhu1242636633', 'Saving', '1202j3i33i3i393939', '1342627378338', 0, 1, '2026-01-09 14:36:41', '2026-02-16 05:40:25'),
(2, 1, 'STATE BANK OF INDIA', 'WADI', '44488375874', 'CURRENT', 'SBIN0012710', '', 1, 2, '2026-01-10 06:24:06', '2026-02-16 05:40:25');

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

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

CREATE TABLE `customers` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `customer_name` varchar(100) NOT NULL,
  `customer_phone` varchar(15) NOT NULL,
  `customer_email` varchar(100) DEFAULT NULL,
  `customer_address` text DEFAULT NULL,
  `property_type` enum('residential','commercial','industrial') DEFAULT NULL,
  `meter_type` enum('single_phase','three_phase','ct_meter','ip_meter') DEFAULT NULL,
  `source_quotation_id` int(11) DEFAULT NULL,
  `status` enum('active','inactive') DEFAULT 'active',
  `created_by` int(11) NOT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Table structure for table `declaration_documents`
--

CREATE TABLE `declaration_documents` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `client_id` int(11) NOT NULL,
  `company_name` varchar(255) NOT NULL,
  `system_capacity` decimal(6,2) NOT NULL,
  `consumer_name` varchar(255) NOT NULL,
  `project_address` text NOT NULL,
  `application_number` varchar(100) NOT NULL,
  `application_date` date NOT NULL,
  `discom_name` varchar(150) NOT NULL,
  `pv_module_capacity` decimal(6,2) NOT NULL,
  `pv_module_count` int(11) NOT NULL,
  `inverter_no` varchar(150) NOT NULL,
  `pv_module_make` varchar(150) NOT NULL,
  `cell_manufacturer` varchar(150) NOT NULL,
  `cell_gst_invoice` varchar(150) NOT NULL,
  `panel_serial_numbers` text NOT NULL,
  `declarant_name` varchar(150) NOT NULL,
  `declarant_designation` varchar(150) NOT NULL,
  `declarant_phone` varchar(20) NOT NULL,
  `declarant_email` varchar(150) NOT NULL,
  `declaration_date` date NOT NULL,
  `created_by` int(11) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `declaration_documents`
--

INSERT INTO `declaration_documents` (`id`, `tenant_id`, `client_id`, `company_name`, `system_capacity`, `consumer_name`, `project_address`, `application_number`, `application_date`, `discom_name`, `pv_module_capacity`, `pv_module_count`, `inverter_no`, `pv_module_make`, `cell_manufacturer`, `cell_gst_invoice`, `panel_serial_numbers`, `declarant_name`, `declarant_designation`, `declarant_phone`, `declarant_email`, `declaration_date`, `created_by`, `created_at`, `updated_at`) VALUES
(1, 1, 4, 'VK SOLAR ENERGY ', 3.00, 'SACHIN VISHWAS THAMKE', 'W.NO.4,H.NO.25/9 KAMBLE L/O WADDHAMNA NAGPUR', '71840345', '2026-02-03', 'mahadiscom', 3.00, 6, 'KN21M21230EG70316', 'kirloskar', 'venfir pvt ltd', '6543564', '13212', 'MR VILAS KALE', 'PROPRIETOR', '2423', 'vksolarenergy1989@gmail.com', '2026-02-03', 2, '2026-02-03 05:04:14', '2026-02-16 05:40:25'),
(2, 1, 7, 'VK SOLAR ENERGY ', 3.00, 'JAYSHREE JIWAN GOURKHEDE', 'pl no 71 govt press layout dhaba nagpur 440016', '156', '2026-02-05', 'maha discom', 3.00, 6, '14325', 'kir', 'dfg', 'dfg45', 'sdf435', 'MR VILAS KALE', 'PROPRIETOR', '3242', 'vksolarenergy1989@gmail.com', '2026-02-05', 2, '2026-02-05 06:36:15', '2026-02-16 05:40:25');

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

--
-- Table structure for table `employees`
--

CREATE TABLE `employees` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `employee_id` varchar(20) NOT NULL,
  `profile_picture` varchar(255) DEFAULT NULL,
  `full_name` varchar(100) NOT NULL,
  `email` varchar(100) NOT NULL,
  `phone` varchar(15) DEFAULT NULL,
  `role` enum('super_admin','admin','office_staff','sales_marketing','warehouse_staff') NOT NULL,
  `department` varchar(50) DEFAULT NULL,
  `position` varchar(50) DEFAULT NULL,
  `salary` decimal(10,2) DEFAULT NULL,
  `joining_date` date DEFAULT NULL,
  `address` text DEFAULT NULL,
  `city` varchar(50) DEFAULT NULL,
  `state` varchar(50) DEFAULT NULL,
  `pincode` varchar(10) DEFAULT NULL,
  `emergency_contact` varchar(15) DEFAULT NULL,
  `emergency_contact_name` varchar(100) DEFAULT NULL,
  `is_active` tinyint(1) DEFAULT 1,
  `created_by` int(11) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `employees`
--

INSERT INTO `employees` (`id`, `tenant_id`, `employee_id`, `profile_picture`, `full_name`, `email`, `phone`, `role`, `department`, `position`, `salary`, `joining_date`, `address`, `city`, `state`, `pincode`, `emergency_contact`, `emergency_contact_name`, `is_active`, `created_by`, `created_at`, `updated_at`) VALUES
(1, 1, 'EMP156754', NULL, 'Test User', 'test@gmail.com', '9860409222', 'warehouse_staff', 'Test', '0', 20000.00, '2026-01-09', 'Test', 'test', 'test', '887766', '78768798', 'Test', 1, 2, '2026-01-09 07:20:26', '2026-02-16 05:40:25'),
(2, 1, 'EMP060439', NULL, 'MR.SAGAR WAMAN  ZAMBARE SIR', 'vksolarenergy1989@gmail.com', '09657135476', 'warehouse_staff', 'MANGEMENT', '0', 15000.00, '2026-01-01', 'NEAR HEND PATIL ATA CHAKKI GHATPURI NAKA KHAMGAON', 'KHAMGAON', 'Maharashtra ( 27 )', '444303', '', '', 1, 2, '2026-01-16 12:06:58', '2026-02-16 05:40:25');

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

--
-- Table structure for table `invoices`
--

CREATE TABLE `invoices` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `invoice_no` varchar(50) NOT NULL,
  `invoice_type` enum('client','retailer') NOT NULL,
  `reference_id` int(11) NOT NULL,
  `invoice_date` date NOT NULL,
  `due_date` date DEFAULT NULL,
  `financial_year` varchar(9) NOT NULL,
  `warehouse_id` int(11) NOT NULL,
  `subtotal` decimal(12,2) DEFAULT 0.00,
  `cgst` decimal(12,2) DEFAULT 0.00,
  `sgst` decimal(12,2) DEFAULT 0.00,
  `igst` decimal(12,2) DEFAULT 0.00,
  `total` decimal(12,2) DEFAULT 0.00,
  `status` enum('draft','final','cancelled') DEFAULT 'draft',
  `payment_status` enum('pending','partial','paid') DEFAULT 'pending',
  `note` text DEFAULT NULL,
  `created_by` int(11) DEFAULT NULL,
  `created_at` datetime DEFAULT current_timestamp(),
  `paid_amount` decimal(12,2) DEFAULT 0.00,
  `due_amount` decimal(12,2) DEFAULT 0.00
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `invoices`
--

INSERT INTO `invoices` (`id`, `tenant_id`, `invoice_no`, `invoice_type`, `reference_id`, `invoice_date`, `due_date`, `financial_year`, `warehouse_id`, `subtotal`, `cgst`, `sgst`, `igst`, `total`, `status`, `payment_status`, `note`, `created_by`, `created_at`, `paid_amount`, `due_amount`) VALUES
(3, 1, 'VK/25-26/001', 'client', 7, '2026-01-16', NULL, '25-26', 2, 48000.00, 4320.00, 4320.00, 0.00, 56640.00, 'final', 'partial', NULL, 2, '2026-01-16 17:11:42', 0.00, 0.00),
(4, 1, 'VK/25-26/004', 'client', 7, '2026-01-17', NULL, '25-26', 2, 2000.00, 180.00, 180.00, 0.00, 2360.00, 'final', 'pending', NULL, 2, '2026-01-17 10:40:36', 0.00, 0.00),
(16, 1, 'VK/25-26/005', 'client', 7, '2026-01-30', NULL, '25-26', 1, 15000.00, 1350.00, 1350.00, 0.00, 17700.00, 'draft', 'pending', NULL, 2, '2026-01-30 15:39:12', 0.00, 0.00),
(17, 1, 'VK/25-26/017', 'client', 2, '2026-01-30', NULL, '25-26', 1, 10000.00, 900.00, 900.00, 0.00, 11800.00, 'final', 'pending', NULL, 2, '2026-01-30 15:41:06', 0.00, 0.00),
(18, 1, 'VK/25-26/018', 'client', 2, '2026-01-30', NULL, '25-26', 1, 50000.00, 4500.00, 4500.00, 0.00, 59000.00, 'final', 'pending', NULL, 2, '2026-01-30 15:50:12', 0.00, 0.00),
(19, 1, 'VK/25-26/019', 'client', 5, '2026-02-03', NULL, '25-26', 1, 180000.00, 16200.00, 16200.00, 0.00, 212400.00, 'final', 'pending', NULL, 2, '2026-02-03 10:35:56', 0.00, 0.00);

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

--
-- Table structure for table `invoice_items`
--

CREATE TABLE `invoice_items` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `invoice_id` int(11) NOT NULL,
  `product_id` int(11) NOT NULL,
  `warehouse_id` int(11) NOT NULL,
  `quantity` decimal(12,3) NOT NULL,
  `rate` decimal(12,2) NOT NULL,
  `gst_percent` decimal(5,2) DEFAULT 0.00,
  `line_total` decimal(12,2) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `invoice_items`
--

INSERT INTO `invoice_items` (`id`, `tenant_id`, `invoice_id`, `product_id`, `warehouse_id`, `quantity`, `rate`, `gst_percent`, `line_total`) VALUES
(1, 1, 3, 1, 2, 6.000, 8000.00, 18.00, 48000.00),
(2, 1, 4, 1, 2, 2.000, 1000.00, 18.00, 2000.00),
(3, 1, 16, 1, 1, 1.000, 15000.00, 18.00, 15000.00),
(4, 1, 17, 1, 1, 1.000, 10000.00, 18.00, 10000.00),
(5, 1, 18, 1, 1, 1.000, 50000.00, 18.00, 50000.00),
(6, 1, 19, 1, 1, 1.000, 180000.00, 18.00, 180000.00);

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

--
-- Table structure for table `invoice_payments`
--

CREATE TABLE `invoice_payments` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `invoice_id` int(11) NOT NULL,
  `payment_date` date NOT NULL,
  `amount` decimal(12,2) NOT NULL,
  `payment_mode` enum('cash','upi','bank','cheque','online') NOT NULL,
  `transaction_ref` varchar(255) DEFAULT NULL,
  `note` text DEFAULT NULL,
  `received_by` int(11) DEFAULT NULL,
  `created_at` datetime DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `invoice_payments`
--

INSERT INTO `invoice_payments` (`id`, `tenant_id`, `invoice_id`, `payment_date`, `amount`, `payment_mode`, `transaction_ref`, `note`, `received_by`, `created_at`) VALUES
(1, 1, 3, '2026-01-15', 10000.00, 'cash', NULL, '', NULL, '0000-00-00 00:00:00');

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

--
-- Table structure for table `login_history`
--

CREATE TABLE `login_history` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `user_id` int(11) NOT NULL,
  `login_time` timestamp NULL DEFAULT current_timestamp(),
  `ip_address` varchar(45) DEFAULT NULL,
  `user_agent` text DEFAULT NULL,
  `logout_time` timestamp NULL DEFAULT NULL,
  `session_duration` int(11) DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Table structure for table `model_agreements`
--

CREATE TABLE `model_agreements` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `client_id` int(11) NOT NULL,
  `applicant_name` varchar(255) NOT NULL,
  `consumer_number` varchar(100) NOT NULL,
  `applicant_address` text NOT NULL,
  `agreement_date` date NOT NULL,
  `vendor_name` varchar(255) NOT NULL,
  `vendor_address` text NOT NULL,
  `system_capacity` decimal(6,2) NOT NULL,
  `pv_module_make` varchar(255) NOT NULL,
  `pv_module_capacity` varchar(100) NOT NULL,
  `panel_efficiency` varchar(50) NOT NULL,
  `inverter_company_name` varchar(255) NOT NULL,
  `inverter_capacity` varchar(100) NOT NULL,
  `system_cost` decimal(12,2) NOT NULL,
  `advance_percentage` int(11) NOT NULL,
  `dispatch_percentage` int(11) NOT NULL,
  `completion_percentage` int(11) NOT NULL,
  `created_by` int(11) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `model_agreements`
--

INSERT INTO `model_agreements` (`id`, `tenant_id`, `client_id`, `applicant_name`, `consumer_number`, `applicant_address`, `agreement_date`, `vendor_name`, `vendor_address`, `system_capacity`, `pv_module_make`, `pv_module_capacity`, `panel_efficiency`, `inverter_company_name`, `inverter_capacity`, `system_cost`, `advance_percentage`, `dispatch_percentage`, `completion_percentage`, `created_by`, `created_at`, `updated_at`) VALUES
(1, 1, 5, 'PRANAY RAVINDRA KAMBLE', '411350027467', 'H NO 46,PL NO27 MIHAN KHAPRI PUNARVASAN 441108', '2026-01-22', 'VK SOLAR ENERGY', 'NAGPUR , MAHARASHTRA', 3.00, 'Kirloskar ', '454', '80', 'Polycab', '3', 180000.00, 10, 80, 10, 2, '2026-01-22 04:31:36', '2026-02-16 05:40:25'),
(2, 1, 4, 'SACHIN VISHWAS THAMKE', '410032705697', 'W.NO.4,H.NO.25/9 KAMBLE L/O WADDHAMNA NAGPUR', '2026-02-03', 'VK SOLAR ENERGY', 'NAGPUR , MAHARASHTRA', 3.00, 'kirloskar', '545', '85', 'KIRLOSKAR', '3.4', 180000.00, 10, 80, 10, 2, '2026-02-03 05:02:32', '2026-02-16 05:40:25');

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

--
-- Table structure for table `net_metering_agreements`
--

CREATE TABLE `net_metering_agreements` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `client_id` int(11) NOT NULL,
  `consumer_name` varchar(255) NOT NULL,
  `consumer_number` varchar(100) NOT NULL,
  `address` text NOT NULL,
  `location` varchar(150) NOT NULL,
  `system_capacity` decimal(6,2) NOT NULL,
  `vendor_name` varchar(255) NOT NULL,
  `agreement_date` date NOT NULL,
  `msedcl_representative` varchar(255) NOT NULL,
  `msedcl_designation` varchar(255) NOT NULL,
  `witness1_vendor` varchar(255) NOT NULL,
  `witness1_msedcl` varchar(255) NOT NULL,
  `created_by` int(11) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

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

CREATE TABLE `products` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `product_id` varchar(20) NOT NULL,
  `name` varchar(255) NOT NULL,
  `category_id` int(11) DEFAULT NULL,
  `hsn_code` varchar(50) DEFAULT NULL,
  `created_by` int(11) DEFAULT NULL,
  `created_at` datetime DEFAULT current_timestamp(),
  `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

INSERT INTO `products` (`id`, `tenant_id`, `product_id`, `name`, `category_id`, `hsn_code`, `created_by`, `created_at`, `updated_at`) VALUES
(3, 1, 'PROD001', '540 WP SOLAR PV MODULE', 2, '85414011', 2, '2026-02-10 18:32:20', '2026-02-16 11:10:25'),
(4, 1, 'PROD002', '545 WP SOLAR PV MODULE', 2, '85414011', 2, '2026-02-10 19:06:30', '2026-02-16 11:10:25'),
(5, 1, 'PROD003', '550 WP SOLAR PV MODULE', 2, '85414011', 2, '2026-02-10 19:08:42', '2026-02-16 11:10:25'),
(6, 1, 'PROD004', '570 WP SOLAR PV MODULE', 2, '85414011', 2, '2026-02-10 19:09:19', '2026-02-16 11:10:25'),
(7, 1, 'PROD005', '575 WP SOLAR PV MODULE', 2, '85414011', 2, '2026-02-10 19:10:53', '2026-02-16 11:10:25'),
(8, 1, 'PROD006', '580 WP SOLAR PV MODULE', 2, '85414011', 2, '2026-02-10 19:11:29', '2026-02-16 11:10:25'),
(9, 1, 'PROD007', '590 WP SOLAR PV MODULE', 2, '85414011', 2, '2026-02-10 19:12:06', '2026-02-16 11:10:25'),
(10, 1, 'PROD008', '595 WP SOLAR PV MODULE', 2, '85414011', 2, '2026-02-10 19:12:34', '2026-02-16 11:10:25'),
(11, 1, 'PROD009', '600 WP SOLAR PV MODULE', 2, '85414011', 2, '2026-02-10 19:13:05', '2026-02-16 11:10:25'),
(12, 1, 'PROD010', '610 WP SOLAR PV MODULE', 2, '85414011', 2, '2026-02-10 19:13:35', '2026-02-16 11:10:25'),
(13, 1, 'PROD011', '620 WP SOLAR PV MODULE', 2, '85414011', 2, '2026-02-10 19:14:11', '2026-02-16 11:10:25'),
(14, 1, 'PROD012', '630 WP SOLAR PV MODULE', 2, '85414011', 2, '2026-02-10 19:14:37', '2026-02-16 11:10:25'),
(15, 1, 'PROD013', '640 WP SOLAR PV MODULE', 2, '85414011', 2, '2026-02-10 19:14:58', '2026-02-16 11:10:25'),
(16, 1, 'PROD014', '700 WP SOLAR PV MODULE', 2, '85414011', 2, '2026-02-10 19:15:21', '2026-02-16 11:10:25'),
(17, 1, 'PROD015', '3 KW SOLAR ON GIRD INVERTER', 3, '85044090', 2, '2026-02-10 19:15:40', '2026-02-16 11:10:25'),
(18, 1, 'PROD016', '3.4 KW SOLAR ON GRID INVERTER', 3, '85044090', 2, '2026-02-10 19:15:59', '2026-02-16 11:10:25'),
(19, 1, 'PROD017', '4 KW SOLAR ON GIRD INVERTER', 3, '85044090', 2, '2026-02-10 19:16:13', '2026-02-16 11:10:25'),
(20, 1, 'PROD018', '5 KW 1 PH SOLAR ON GIRD INVERTER', 3, '85044090', 2, '2026-02-10 19:16:27', '2026-02-16 11:10:25'),
(21, 1, 'PROD019', '5 KW 3 PH SOLAR ON GRID INVERTER', 3, '85044090', 2, '2026-02-10 19:16:42', '2026-02-16 11:10:25'),
(22, 1, 'PROD020', '6 KW 1 PH SOLAR ON GIRD INVERTER', 3, '85044090', 2, '2026-02-10 19:16:55', '2026-02-16 11:10:25'),
(23, 1, 'PROD021', '8 KW 3 PH SOLAR ON GIRD INVERTER', 3, '85044090', 2, '2026-02-10 19:17:10', '2026-02-16 11:10:25'),
(24, 1, 'PROD022', '10 KW 3 PH SOLAR ON GIRD INVERTER', 3, '85044090', 2, '2026-02-10 19:17:33', '2026-02-16 11:10:25'),
(25, 1, 'PROD023', '12 KW 3 PH SOLAR ON GIRD INVERTER', 3, '85044090', 2, '2026-02-10 19:18:43', '2026-02-16 11:10:25'),
(26, 1, 'PROD024', '15 KW 3 PH SOLAR ON GIRD INVERTER', 3, '85044090', 2, '2026-02-10 19:19:17', '2026-02-16 11:10:25'),
(27, 1, 'PROD025', '20 KW 3 PH SOLAR ON GIRD INVERTER', 3, '85044090', 2, '2026-02-10 19:19:29', '2026-02-16 11:10:25'),
(28, 1, 'PROD026', '25 KW 3 PH SOLAR ON GIRD INVERTER', 3, '85044090', 2, '2026-02-10 19:19:46', '2026-02-16 11:10:25'),
(29, 1, 'PROD027', '30 KW 3 PH SOLAR ON GRID INVERTER', 3, '85044090', 2, '2026-02-10 19:20:01', '2026-02-16 11:10:25'),
(30, 1, 'PROD028', '40 KW 3 PH SOLAR ON GIRD INVERTER', 3, '85044090', 2, '2026-02-10 19:20:14', '2026-02-16 11:10:25'),
(31, 1, 'PROD029', '50 KW 3 PH SOLAR ON GRID INVERTER', 3, '85044090', 2, '2026-02-10 19:20:27', '2026-02-16 11:10:25'),
(32, 1, 'PROD030', '60 KW 3 PH SOLAR ON GIRD INVERTER', 3, '85044090', 2, '2026-02-10 19:20:44', '2026-02-16 11:10:25');

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

--
-- Table structure for table `product_attributes`
--

CREATE TABLE `product_attributes` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `product_id` int(11) NOT NULL,
  `attr_key` varchar(120) NOT NULL,
  `attr_value` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Table structure for table `product_categories`
--

CREATE TABLE `product_categories` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `category_id` varchar(20) NOT NULL,
  `category_name` varchar(100) NOT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `product_categories`
--

INSERT INTO `product_categories` (`id`, `tenant_id`, `category_id`, `category_name`, `created_at`) VALUES
(2, 1, 'CAT001', 'SOLAR PV MODULE', '2026-02-10 05:02:37'),
(3, 1, 'CAT002', 'SOLAR INVERTERS', '2026-02-10 05:04:26'),
(4, 1, 'CAT003', 'SOLAR BATTERIES', '2026-02-10 05:04:39'),
(5, 1, 'CAT004', 'CHARGE CONTROLLERS', '2026-02-10 05:04:48'),
(6, 1, 'CAT005', 'MOUNTING & RACKING SYSTEMS', '2026-02-10 05:04:57'),
(7, 1, 'CAT006', 'ELECTRICAL PROTECTION', '2026-02-10 05:05:06'),
(8, 1, 'CAT007', 'WIRE', '2026-02-10 05:05:23'),
(9, 1, 'CAT008', 'CONNECTORS', '2026-02-10 05:05:32'),
(10, 1, 'CAT009', 'METERING', '2026-02-10 05:05:48'),
(11, 1, 'CAT010', 'THERMAL PRODUCTS', '2026-02-10 05:05:55'),
(12, 1, 'CAT011', 'LIGHTS', '2026-02-10 05:06:11'),
(13, 1, 'CAT012', 'SMALL GADGETS', '2026-02-10 05:06:20'),
(14, 1, 'CAT013', 'CABLES', '2026-02-10 05:07:21'),
(15, 1, 'CAT014', 'COMBINER BOX', '2026-02-10 05:07:34'),
(16, 1, 'CAT015', 'SURGE PROTECTION DEVICES (SPD\'S)', '2026-02-10 05:08:04');

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

--
-- Table structure for table `product_images`
--

CREATE TABLE `product_images` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `product_id` int(11) NOT NULL,
  `filename` varchar(255) NOT NULL,
  `is_primary` tinyint(1) DEFAULT 0,
  `caption` varchar(255) DEFAULT NULL,
  `created_at` datetime DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Table structure for table `product_manufacturers`
--

CREATE TABLE `product_manufacturers` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `manufacturer_id` varchar(20) NOT NULL,
  `manufacturer_name` varchar(150) NOT NULL,
  `category_id` int(11) NOT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `product_manufacturers`
--

INSERT INTO `product_manufacturers` (`id`, `tenant_id`, `manufacturer_id`, `manufacturer_name`, `category_id`, `created_at`) VALUES
(1, 1, 'MAN001', 'KIRLOSKAR', 3, '2026-02-10 07:41:37'),
(2, 1, 'MAN002', 'WAREE', 3, '2026-02-10 07:41:48'),
(3, 1, 'MAN003', 'ADANI', 3, '2026-02-10 07:42:47'),
(4, 1, 'MAN004', 'POLYCAB', 3, '2026-02-10 07:43:06'),
(5, 1, 'MAN005', 'TATA', 3, '2026-02-10 07:43:22'),
(6, 1, 'MAN006', 'K SOLAR', 3, '2026-02-10 07:43:41'),
(7, 1, 'MAN007', 'V SOLE', 3, '2026-02-10 07:43:50'),
(8, 1, 'MAN008', 'HAVELS', 3, '2026-02-10 07:44:06'),
(9, 1, 'MAN009', 'OTHER', 3, '2026-02-10 07:44:14'),
(10, 1, 'MAN010', 'KIRLOSKAR', 2, '2026-02-10 07:44:39'),
(11, 1, 'MAN011', 'WAREE', 2, '2026-02-10 07:44:56'),
(12, 1, 'MAN012', 'ADANI', 2, '2026-02-10 07:45:12'),
(13, 1, 'MAN013', 'POLYCAB', 2, '2026-02-10 07:45:22'),
(14, 1, 'MAN014', 'TATA', 2, '2026-02-10 07:45:36'),
(15, 1, 'MAN015', 'PREMIER', 2, '2026-02-10 07:45:52'),
(16, 1, 'MAN016', 'SATVIK', 2, '2026-02-10 07:46:05'),
(17, 1, 'MAN017', 'HAVELS', 2, '2026-02-10 07:46:14'),
(18, 1, 'MAN018', 'OTHER', 2, '2026-02-10 07:46:26');

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

--
-- Table structure for table `product_serials`
--

CREATE TABLE `product_serials` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `product_id` int(11) NOT NULL,
  `warehouse_id` int(11) DEFAULT NULL,
  `serial_number` varchar(255) NOT NULL,
  `status` enum('in_stock','sold','transferred','reserved','damaged','returned') NOT NULL DEFAULT 'in_stock',
  `notes` text DEFAULT NULL,
  `created_at` datetime DEFAULT current_timestamp(),
  `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Table structure for table `product_suppliers`
--

CREATE TABLE `product_suppliers` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `product_id` int(11) NOT NULL,
  `supplier_id` int(11) NOT NULL,
  `supplier_sku` varchar(150) DEFAULT NULL,
  `purchase_price` decimal(12,2) DEFAULT 0.00,
  `min_order_qty` int(11) DEFAULT 0,
  `lead_time_days` int(11) DEFAULT NULL,
  `created_at` datetime DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Table structure for table `purchase_orders`
--

CREATE TABLE `purchase_orders` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `po_number` varchar(50) NOT NULL,
  `manufacturer_id` int(11) NOT NULL,
  `warehouse_id` int(11) NOT NULL,
  `status` enum('pending','approved','rejected') DEFAULT 'pending',
  `invoice_id` int(11) DEFAULT NULL,
  `remarks` text DEFAULT NULL,
  `created_by` int(11) NOT NULL,
  `approved_by` int(11) DEFAULT NULL,
  `created_at` datetime DEFAULT current_timestamp(),
  `approved_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `purchase_orders`
--

INSERT INTO `purchase_orders` (`id`, `tenant_id`, `po_number`, `manufacturer_id`, `warehouse_id`, `status`, `invoice_id`, `remarks`, `created_by`, `approved_by`, `created_at`, `approved_at`) VALUES
(7, 1, 'PO-20260214-040119', 12, 7, 'approved', NULL, NULL, 2, 2, '2026-02-14 09:31:19', '2026-02-14 11:00:20'),
(8, 1, 'PO-20260214-055337', 8, 8, 'approved', NULL, NULL, 2, 2, '2026-02-14 11:23:37', '2026-02-14 11:26:04'),
(9, 1, 'PO-20260214-063335', 13, 7, 'approved', NULL, NULL, 2, 2, '2026-02-14 12:03:35', '2026-02-14 12:04:24'),
(10, 1, 'PO-20260214-063410', 3, 8, 'approved', NULL, NULL, 2, 2, '2026-02-14 12:04:10', '2026-02-14 12:04:56'),
(11, 1, 'PO-20260214-065038', 15, 8, 'approved', NULL, NULL, 2, 2, '2026-02-14 12:20:38', '2026-02-14 12:23:34');

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

--
-- Table structure for table `purchase_order_items`
--

CREATE TABLE `purchase_order_items` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `purchase_order_id` int(11) NOT NULL,
  `product_id` int(11) NOT NULL,
  `quantity` decimal(12,3) NOT NULL,
  `rate` decimal(12,2) NOT NULL,
  `gst_percent` decimal(5,2) DEFAULT 0.00,
  `total` decimal(12,2) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `purchase_order_items`
--

INSERT INTO `purchase_order_items` (`id`, `tenant_id`, `purchase_order_id`, `product_id`, `quantity`, `rate`, `gst_percent`, `total`) VALUES
(3, 1, 7, 3, 10.000, 100.00, 0.00, 1000.00),
(4, 1, 8, 17, 5.000, 1000.00, 0.00, 5000.00),
(5, 1, 8, 20, 5.000, 2000.00, 0.00, 10000.00),
(6, 1, 9, 3, 20.000, 7800.00, 0.00, 156000.00),
(7, 1, 10, 18, 7.000, 2000.00, 0.00, 14000.00),
(8, 1, 11, 4, 55.000, 9000.00, 0.00, 495000.00);

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

--
-- Table structure for table `quotations`
--

CREATE TABLE `quotations` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `quotation_number` varchar(50) NOT NULL,
  `customer_name` varchar(100) NOT NULL,
  `customer_phone` varchar(15) NOT NULL,
  `customer_email` varchar(100) DEFAULT NULL,
  `customer_address` text DEFAULT NULL,
  `property_type` enum('residential','commercial','industrial') NOT NULL,
  `roof_type` enum('concrete','metal','tiled','asphalt') NOT NULL,
  `meter_type` enum('single_phase','three_phase','ct_meter','ip_meter') NOT NULL,
  `roof_area` decimal(10,2) DEFAULT NULL,
  `system_size` decimal(8,2) NOT NULL,
  `panel_company` varchar(50) NOT NULL,
  `inverter_company` varchar(50) NOT NULL,
  `panel_model` varchar(20) NOT NULL,
  `system_type` enum('on-grid','off-grid','hybrid') NOT NULL,
  `monthly_bill` decimal(10,2) NOT NULL,
  `battery_backup` tinyint(1) DEFAULT 0,
  `monitoring_system` tinyint(1) DEFAULT 0,
  `maintenance_package` tinyint(1) DEFAULT 0,
  `total_cost` decimal(12,2) NOT NULL,
  `subsidy` decimal(12,2) NOT NULL,
  `final_cost` decimal(12,2) NOT NULL,
  `monthly_savings` decimal(10,2) NOT NULL,
  `yearly_savings` decimal(10,2) NOT NULL,
  `payback_period` decimal(6,2) NOT NULL,
  `status` enum('draft','sent','viewed','negotiation','accepted','rejected') DEFAULT 'draft',
  `follow_up_date` date DEFAULT NULL,
  `notes` text DEFAULT NULL,
  `created_by` int(11) NOT NULL,
  `assigned_to` int(11) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `sent_at` timestamp NULL DEFAULT NULL,
  `accepted_at` timestamp NULL DEFAULT NULL,
  `rejected_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Table structure for table `quotation_status_history`
--

CREATE TABLE `quotation_status_history` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `quotation_id` int(11) NOT NULL,
  `old_status` varchar(50) DEFAULT NULL,
  `new_status` varchar(50) NOT NULL,
  `changed_by` int(11) NOT NULL,
  `notes` text DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Table structure for table `solar_panels`
--

CREATE TABLE `solar_panels` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `client_id` int(11) NOT NULL,
  `panel_number` int(11) NOT NULL,
  `company_name` varchar(255) NOT NULL,
  `wattage` int(11) NOT NULL,
  `serial_number` varchar(255) DEFAULT NULL,
  `created_at` datetime DEFAULT current_timestamp(),
  `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Table structure for table `solar_rooftop_quotations`
--

CREATE TABLE `solar_rooftop_quotations` (
  `quotation_id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `quote_number` varchar(50) NOT NULL,
  `status` enum('sent','approved','declined','under_review') DEFAULT 'sent',
  `customer_id` int(11) DEFAULT NULL,
  `customer_name` varchar(150) NOT NULL,
  `customer_phone` varchar(20) DEFAULT NULL,
  `customer_email` varchar(150) DEFAULT NULL,
  `customer_address` text DEFAULT NULL,
  `prepared_by` varchar(150) DEFAULT NULL,
  `preparer_address` text DEFAULT NULL,
  `preparer_contact` varchar(50) DEFAULT NULL,
  `preparer_email` varchar(150) DEFAULT NULL,
  `roof_type` varchar(50) DEFAULT NULL,
  `roof_area_sqft` decimal(8,2) DEFAULT NULL,
  `property_type` varchar(50) DEFAULT NULL,
  `meter_type` varchar(50) DEFAULT NULL,
  `monthly_bill` decimal(12,2) DEFAULT NULL,
  `panel_wattage` int(11) DEFAULT NULL,
  `panel_count` int(11) DEFAULT NULL,
  `panel_company` varchar(100) DEFAULT NULL,
  `inverter_company` varchar(100) DEFAULT NULL,
  `inverter_capacity` varchar(50) DEFAULT NULL,
  `inverter_type` varchar(50) DEFAULT NULL,
  `inverter_count` int(11) NOT NULL,
  `system_size_kwp` decimal(6,2) DEFAULT NULL,
  `system_type` varchar(50) DEFAULT NULL,
  `total_cost` decimal(12,2) DEFAULT NULL,
  `subsidy` decimal(12,2) DEFAULT NULL,
  `final_cost` decimal(12,2) DEFAULT NULL,
  `monthly_savings` decimal(12,2) DEFAULT NULL,
  `payback_period` decimal(4,1) DEFAULT NULL,
  `created_date` datetime DEFAULT current_timestamp(),
  `updated_date` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `battery_backup` tinyint(1) DEFAULT 0,
  `smart_monitoring` tinyint(1) DEFAULT 0,
  `annual_maintenance` tinyint(1) DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `solar_rooftop_quotations`
--

INSERT INTO `solar_rooftop_quotations` (`quotation_id`, `tenant_id`, `quote_number`, `status`, `customer_id`, `customer_name`, `customer_phone`, `customer_email`, `customer_address`, `prepared_by`, `preparer_address`, `preparer_contact`, `preparer_email`, `roof_type`, `roof_area_sqft`, `property_type`, `meter_type`, `monthly_bill`, `panel_wattage`, `panel_count`, `panel_company`, `inverter_company`, `inverter_capacity`, `inverter_type`, `inverter_count`, `system_size_kwp`, `system_type`, `total_cost`, `subsidy`, `final_cost`, `monthly_savings`, `payback_period`, `created_date`, `updated_date`, `battery_backup`, `smart_monitoring`, `annual_maintenance`) VALUES
(1, 1, 'SOL-NA-2026-02-1', 'approved', 0, 'akash borikar', '1234567890', 'a@gmail.com', 'nagpur', 'aniket', 'nagpur', '987654321', 'a@gmail.com', 'flat', NULL, 'residential', 'single', 3000.00, 545, 6, 'KIRLOSKAR', 'KIRLOSKAR', '5', 'string-inverter', 1, 3.00, 'on-grid', 180000.00, 78000.00, 102000.00, 0.00, 0.0, '2026-02-10 15:41:25', '2026-02-16 11:10:25', 1, 0, 0);

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

--
-- Table structure for table `stock_movements`
--

CREATE TABLE `stock_movements` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `movement_type` enum('purchase','adjustment','transfer_out','transfer_in','sale','consume','return','other') NOT NULL,
  `product_id` int(11) NOT NULL,
  `warehouse_from` int(11) DEFAULT NULL,
  `warehouse_to` int(11) DEFAULT NULL,
  `quantity` decimal(12,3) NOT NULL,
  `unit` varchar(30) DEFAULT 'pc',
  `note` text DEFAULT NULL,
  `related_id` int(11) DEFAULT NULL,
  `created_by` int(11) DEFAULT NULL,
  `created_at` datetime DEFAULT current_timestamp(),
  `reference_type` enum('client','retailer') DEFAULT NULL,
  `reference_id` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `stock_movements`
--

INSERT INTO `stock_movements` (`id`, `tenant_id`, `movement_type`, `product_id`, `warehouse_from`, `warehouse_to`, `quantity`, `unit`, `note`, `related_id`, `created_by`, `created_at`, `reference_type`, `reference_id`) VALUES
(19, 1, 'purchase', 3, NULL, 7, 10.000, 'pc', NULL, NULL, 2, '2026-02-14 11:00:20', 'retailer', 12),
(20, 1, 'purchase', 17, NULL, 8, 5.000, 'pc', NULL, NULL, 2, '2026-02-14 11:26:04', 'retailer', 8),
(21, 1, 'purchase', 20, NULL, 8, 5.000, 'pc', NULL, NULL, 2, '2026-02-14 11:26:04', 'retailer', 8),
(22, 1, 'purchase', 3, NULL, 7, 20.000, 'pc', NULL, NULL, 2, '2026-02-14 12:04:24', 'retailer', 13),
(23, 1, 'purchase', 18, NULL, 8, 7.000, 'pc', NULL, NULL, 2, '2026-02-14 12:04:56', 'retailer', 3),
(24, 1, 'purchase', 4, NULL, 8, 55.000, 'pc', NULL, NULL, 2, '2026-02-14 12:23:34', 'retailer', 15);

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

--
-- Table structure for table `superadmin_activity_log`
--

CREATE TABLE `superadmin_activity_log` (
  `id` int(11) NOT NULL,
  `admin_user_id` int(11) NOT NULL,
  `action_type` enum('tenant_create','tenant_activate','tenant_deactivate','tenant_suspend','tenant_delete','tenant_view','user_impersonate') NOT NULL,
  `target_tenant_id` int(11) DEFAULT NULL,
  `target_user_id` int(11) DEFAULT NULL,
  `action_details` text DEFAULT NULL,
  `ip_address` varchar(45) DEFAULT NULL,
  `user_agent` text DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `superadmin_activity_log`
--

INSERT INTO `superadmin_activity_log` (`id`, `admin_user_id`, `action_type`, `target_tenant_id`, `target_user_id`, `action_details`, `ip_address`, `user_agent`, `created_at`) VALUES
(1, 2, 'tenant_deactivate', 1, NULL, 'Tenant status changed to: inactive', '::1', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36', '2026-02-16 15:55:51'),
(2, 2, 'tenant_activate', 1, NULL, 'Tenant status changed to: active', '::1', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36', '2026-02-16 15:55:53'),
(3, 2, 'tenant_view', 1, NULL, 'Viewed tenant details', '::1', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36', '2026-02-16 16:00:02'),
(4, 2, 'tenant_view', 1, NULL, 'Viewed tenant details', '::1', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36', '2026-02-16 16:00:38'),
(5, 2, 'tenant_create', 2, NULL, 'New tenant created: Test1', '::1', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36', '2026-02-16 16:07:43'),
(6, 2, 'tenant_view', 2, NULL, 'Viewed tenant details', '::1', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36', '2026-02-16 16:07:43'),
(7, 2, 'tenant_view', 2, NULL, 'Viewed tenant details', '::1', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36', '2026-02-16 16:09:56');

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

--
-- Table structure for table `suppliers`
--

CREATE TABLE `suppliers` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `contact_person` varchar(150) DEFAULT NULL,
  `phone` varchar(50) DEFAULT NULL,
  `email` varchar(150) DEFAULT NULL,
  `address` text DEFAULT NULL,
  `created_at` datetime DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Table structure for table `tenants`
--

CREATE TABLE `tenants` (
  `id` int(11) NOT NULL,
  `tenant_name` varchar(255) NOT NULL,
  `logo_path` varchar(500) DEFAULT NULL,
  `header_text` text DEFAULT NULL,
  `footer_text` text DEFAULT NULL,
  `company_name` varchar(255) NOT NULL,
  `gst_number` varchar(50) DEFAULT NULL,
  `address` text DEFAULT NULL,
  `city` varchar(100) DEFAULT NULL,
  `state` varchar(100) DEFAULT NULL,
  `pincode` varchar(20) DEFAULT NULL,
  `country` varchar(100) DEFAULT 'India',
  `contact_email` varchar(255) DEFAULT NULL,
  `contact_phone` varchar(50) DEFAULT NULL,
  `contact_mobile` varchar(50) DEFAULT NULL,
  `website` varchar(255) DEFAULT NULL,
  `invoice_prefix` varchar(20) DEFAULT 'INV',
  `quotation_prefix` varchar(20) DEFAULT 'QUO',
  `purchase_order_prefix` varchar(20) DEFAULT 'PO',
  `is_active` tinyint(1) DEFAULT 1,
  `subscription_status` enum('trial','active','suspended','cancelled') DEFAULT 'trial',
  `subscription_expires_at` datetime DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `created_by` int(11) DEFAULT NULL,
  `last_login_at` datetime DEFAULT NULL,
  `total_users` int(11) DEFAULT 0,
  `storage_used_mb` decimal(10,2) DEFAULT 0.00,
  `notes` text DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `tenants`
--

INSERT INTO `tenants` (`id`, `tenant_name`, `logo_path`, `header_text`, `footer_text`, `company_name`, `gst_number`, `address`, `city`, `state`, `pincode`, `country`, `contact_email`, `contact_phone`, `contact_mobile`, `website`, `invoice_prefix`, `quotation_prefix`, `purchase_order_prefix`, `is_active`, `subscription_status`, `subscription_expires_at`, `created_at`, `updated_at`, `created_by`, `last_login_at`, `total_users`, `storage_used_mb`, `notes`) VALUES
(1, 'VK Solar Energy', NULL, 'Leading Solar Energy Solutions Provider', 'Subject to our home Jurisdiction. Terms & Conditions Apply.', 'VK Solar Energy', '27CJXPK1402Q1ZK', 'SHAHU LAYOUT NEAR JOSHI HOSPITAL, KHADGAON ROAD WADI', 'NAGPUR', 'Maharashtra', '440023', 'India', 'vksolarenergy1989@gmail.com', '9075305275', NULL, NULL, 'VKSE', 'VKSE-Q', 'VKSE-PO', 1, 'trial', NULL, '2026-02-16 11:09:32', '2026-02-16 15:55:53', NULL, NULL, 0, 0.00, NULL),
(2, 'Test1', NULL, NULL, NULL, 'test1', '68668887', 'test', 'test', 'test', '8889988', 'India', 'test@gmail.com', '997979797', NULL, NULL, 'INV', 'QUO', 'PO', 1, 'active', '2026-03-18 00:00:00', '2026-02-16 16:07:43', '2026-02-16 16:07:43', 2, NULL, 0, 0.00, NULL);

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

--
-- Table structure for table `tenant_bank_details`
--

CREATE TABLE `tenant_bank_details` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `bank_name` varchar(255) NOT NULL,
  `branch_name` varchar(255) DEFAULT NULL,
  `account_holder_name` varchar(255) NOT NULL,
  `account_number` varchar(100) NOT NULL,
  `ifsc_code` varchar(20) DEFAULT NULL,
  `swift_code` varchar(20) DEFAULT NULL,
  `account_type` enum('savings','current') DEFAULT 'current',
  `is_primary` tinyint(1) DEFAULT 0,
  `is_active` tinyint(1) DEFAULT 1,
  `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_unicode_ci;

--
-- Dumping data for table `tenant_bank_details`
--

INSERT INTO `tenant_bank_details` (`id`, `tenant_id`, `bank_name`, `branch_name`, `account_holder_name`, `account_number`, `ifsc_code`, `swift_code`, `account_type`, `is_primary`, `is_active`, `created_at`, `updated_at`) VALUES
(1, 1, 'State Bank of India', 'Wadi Branch', 'VK SOLAR ENERGY', '1234567890', 'SBIN0001234', NULL, 'current', 1, 1, '2026-02-16 11:09:32', '2026-02-16 11:09:32');

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

--
-- Table structure for table `undertaking_documents`
--

CREATE TABLE `undertaking_documents` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `client_id` int(11) NOT NULL,
  `consumer_name` varchar(255) NOT NULL,
  `consumer_number` varchar(100) DEFAULT NULL,
  `project_address` text NOT NULL,
  `system_capacity` decimal(6,2) NOT NULL,
  `undertaking_date` date NOT NULL,
  `authorized_person` varchar(150) NOT NULL,
  `designation` varchar(150) DEFAULT NULL,
  `created_by` int(11) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Table structure for table `user_permissions`
--

CREATE TABLE `user_permissions` (
  `id` int(11) NOT NULL,
  `role` enum('super_admin','admin','office_staff','sales_marketing','warehouse_staff') NOT NULL,
  `module` varchar(50) NOT NULL,
  `can_view` tinyint(1) DEFAULT 0,
  `can_create` tinyint(1) DEFAULT 0,
  `can_edit` tinyint(1) DEFAULT 0,
  `can_delete` tinyint(1) DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `user_permissions`
--

INSERT INTO `user_permissions` (`id`, `role`, `module`, `can_view`, `can_create`, `can_edit`, `can_delete`) VALUES
(1, 'super_admin', 'dashboard', 1, 1, 1, 1),
(2, 'super_admin', 'user_management', 1, 1, 1, 1),
(3, 'super_admin', 'employee_management', 1, 1, 1, 1),
(4, 'super_admin', 'quotation_management', 1, 1, 1, 1),
(5, 'super_admin', 'customer_management', 1, 1, 1, 1),
(6, 'super_admin', 'inventory_management', 1, 1, 1, 1),
(7, 'super_admin', 'reports', 1, 1, 1, 1),
(8, 'super_admin', 'invoice_management', 1, 1, 1, 1),
(9, 'admin', 'dashboard', 1, 1, 1, 1),
(10, 'admin', 'user_management', 1, 1, 1, 0),
(11, 'admin', 'employee_management', 1, 1, 1, 1),
(12, 'admin', 'quotation_management', 1, 1, 1, 1),
(13, 'admin', 'customer_management', 1, 1, 1, 1),
(14, 'admin', 'inventory_management', 1, 1, 1, 1),
(15, 'admin', 'reports', 1, 1, 1, 1),
(16, 'admin', 'invoice_management', 1, 1, 1, 1),
(17, 'office_staff', 'dashboard', 1, 0, 0, 0),
(18, 'office_staff', 'user_management', 0, 0, 0, 0),
(19, 'office_staff', 'employee_management', 0, 0, 1, 0),
(20, 'office_staff', 'quotation_management', 1, 1, 1, 0),
(21, 'office_staff', 'customer_management', 1, 1, 1, 0),
(22, 'office_staff', 'inventory_management', 1, 0, 0, 0),
(23, 'office_staff', 'reports', 1, 1, 0, 0),
(24, 'office_staff', 'settings', 0, 0, 0, 0),
(25, 'sales_marketing', 'dashboard', 1, 0, 0, 0),
(26, 'sales_marketing', 'user_management', 0, 0, 0, 0),
(27, 'sales_marketing', 'employee_management', 0, 0, 0, 0),
(28, 'sales_marketing', 'quotation_management', 1, 1, 1, 0),
(29, 'sales_marketing', 'customer_management', 1, 1, 1, 0),
(30, 'sales_marketing', 'inventory_management', 0, 0, 0, 0),
(31, 'sales_marketing', 'reports', 0, 0, 0, 0),
(32, 'sales_marketing', 'settings', 0, 0, 0, 0),
(33, 'warehouse_staff', 'dashboard', 1, 0, 0, 0),
(34, 'warehouse_staff', 'user_management', 0, 0, 0, 0),
(35, 'warehouse_staff', 'employee_management', 0, 0, 0, 0),
(36, 'warehouse_staff', 'quotation_management', 1, 1, 1, 0),
(37, 'warehouse_staff', 'customer_management', 1, 1, 1, 0),
(38, 'warehouse_staff', 'inventory_management', 1, 1, 1, 0),
(39, 'warehouse_staff', 'reports', 0, 0, 0, 0),
(40, 'warehouse_staff', 'settings', 0, 0, 0, 0),
(41, 'super_admin', 'bank_details_management', 1, 1, 1, 1),
(42, 'admin', 'bank_details_management', 1, 1, 1, 1),
(43, 'office_staff', 'bank_details_management', 1, 0, 0, 0),
(44, 'sales_marketing', 'bank_details_management', 1, 0, 0, 0),
(45, 'warehouse_staff', 'bank_details_management', 1, 0, 0, 0),
(76, 'office_staff', 'invoice_management', 1, 1, 1, 0),
(77, 'sales_marketing', 'invoice_management', 0, 0, 0, 0),
(78, 'warehouse_staff', 'invoice_management', 1, 1, 0, 0),
(91, 'super_admin', 'settings', 1, 1, 1, 1),
(92, 'admin', 'settings', 1, 1, 1, 1),
(94, 'super_admin', 'product_management', 1, 1, 1, 1),
(95, 'admin', 'product_management', 1, 1, 1, 1),
(96, 'office_staff', 'product_management', 1, 1, 1, 0),
(97, 'sales_marketing', 'product_management', 0, 0, 0, 0),
(98, 'warehouse_staff', 'product_management', 1, 1, 0, 0),
(128, 'super_admin', 'partner_management', 1, 1, 1, 1),
(129, 'admin', 'partner_management', 1, 1, 1, 1);

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

--
-- Table structure for table `user_profiles`
--

CREATE TABLE `user_profiles` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `user_id` int(11) NOT NULL,
  `address` text DEFAULT NULL,
  `city` varchar(50) DEFAULT NULL,
  `state` varchar(50) DEFAULT NULL,
  `pincode` varchar(10) DEFAULT NULL,
  `profile_picture` varchar(255) DEFAULT NULL,
  `date_of_birth` date DEFAULT NULL,
  `joining_date` date DEFAULT NULL,
  `salary` decimal(10,2) DEFAULT NULL,
  `emergency_contact` varchar(15) DEFAULT NULL,
  `emergency_contact_name` varchar(100) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `user_profiles`
--

INSERT INTO `user_profiles` (`id`, `tenant_id`, `user_id`, `address`, `city`, `state`, `pincode`, `profile_picture`, `date_of_birth`, `joining_date`, `salary`, `emergency_contact`, `emergency_contact_name`, `created_at`, `updated_at`) VALUES
(1, 1, 1, 'VK Solar Energy Office', NULL, NULL, NULL, NULL, NULL, '2025-10-13', NULL, NULL, NULL, '2025-10-13 03:48:05', '2026-02-16 05:40:25');

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

--
-- Table structure for table `vendors_retailers`
--

CREATE TABLE `vendors_retailers` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `type` enum('vendor(Manufacturer Company)','retailer') NOT NULL,
  `company_name` varchar(150) NOT NULL,
  `contact_person` varchar(150) DEFAULT NULL,
  `mobile` varchar(20) DEFAULT NULL,
  `email` varchar(150) DEFAULT NULL,
  `address` text DEFAULT NULL,
  `gst_number` varchar(30) DEFAULT NULL,
  `is_active` tinyint(4) DEFAULT 1,
  `created_by` int(11) DEFAULT NULL,
  `created_at` datetime DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `vendors_retailers`
--

INSERT INTO `vendors_retailers` (`id`, `tenant_id`, `type`, `company_name`, `contact_person`, `mobile`, `email`, `address`, `gst_number`, `is_active`, `created_by`, `created_at`) VALUES
(15, 1, 'retailer', 'gh solar', 'abhishek', '0987654321', 'a@gmail.com', 'dsfc', '123546435', 1, 2, '2026-01-17 16:59:41'),
(16, 1, 'vendor(Manufacturer Company)', 'Adani Pvt Ltd', 'abhishek', '9087654321', 'abhi@gmail.com', 'zigabai takli', '1234', 1, 2, '2026-01-17 18:48:39');

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

--
-- Table structure for table `warehouses`
--

CREATE TABLE `warehouses` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `name` varchar(150) NOT NULL,
  `code` varchar(50) DEFAULT NULL,
  `address` text DEFAULT NULL,
  `city` varchar(100) DEFAULT NULL,
  `state` varchar(100) DEFAULT NULL,
  `pincode` varchar(12) DEFAULT NULL,
  `contact_name` varchar(100) DEFAULT NULL,
  `contact_phone` varchar(20) DEFAULT NULL,
  `image` varchar(255) DEFAULT NULL,
  `created_by` int(11) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `warehouses`
--

INSERT INTO `warehouses` (`id`, `tenant_id`, `name`, `code`, `address`, `city`, `state`, `pincode`, `contact_name`, `contact_phone`, `image`, `created_by`, `created_at`, `updated_at`) VALUES
(7, 1, 'wadi', 'ngp1', 'wadi nagpur', 'nagpur', 'maharashtra', '440030', 'vilas kale', '9807654321', 'wh_1770887078.png', 2, '2026-02-12 09:04:38', '2026-02-16 05:40:25'),
(8, 1, 'khamgaon', 'w2', 'khamgaon', 'ahilyanagar', 'maharashtra', '444532', 'kale vilas', '7865432451', 'wh_1771048292.png', 2, '2026-02-14 05:51:32', '2026-02-16 05:40:25');

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

--
-- Table structure for table `warehouse_employees`
--

CREATE TABLE `warehouse_employees` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `warehouse_id` int(11) NOT NULL,
  `employee_id` int(11) NOT NULL,
  `role` varchar(50) DEFAULT NULL,
  `assigned_at` timestamp NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `warehouse_employees`
--

INSERT INTO `warehouse_employees` (`id`, `tenant_id`, `warehouse_id`, `employee_id`, `role`, `assigned_at`) VALUES
(6, 1, 7, 2, NULL, '2026-02-12 09:04:38'),
(7, 1, 8, 1, NULL, '2026-02-14 05:51:32');

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

--
-- Table structure for table `warehouse_stock`
--

CREATE TABLE `warehouse_stock` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `warehouse_id` int(11) NOT NULL,
  `product_id` int(11) NOT NULL,
  `quantity` decimal(12,3) NOT NULL DEFAULT 0.000,
  `reserved` decimal(12,3) NOT NULL DEFAULT 0.000,
  `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `warehouse_stock`
--

INSERT INTO `warehouse_stock` (`id`, `tenant_id`, `warehouse_id`, `product_id`, `quantity`, `reserved`, `updated_at`) VALUES
(4, 1, 7, 3, 30.000, 0.000, '2026-02-16 11:10:25'),
(5, 1, 8, 17, 5.000, 0.000, '2026-02-16 11:10:25'),
(6, 1, 8, 20, 5.000, 0.000, '2026-02-16 11:10:25'),
(7, 1, 8, 18, 7.000, 0.000, '2026-02-16 11:10:25'),
(8, 1, 8, 4, 55.000, 0.000, '2026-02-16 11:10:25');

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

--
-- Table structure for table `warehouse_stock_snapshots`
--

CREATE TABLE `warehouse_stock_snapshots` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `warehouse_id` int(11) NOT NULL,
  `product_id` int(11) NOT NULL,
  `quantity` decimal(12,3) NOT NULL,
  `snapshot_at` datetime DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Table structure for table `work_completion_reports`
--

CREATE TABLE `work_completion_reports` (
  `id` int(11) NOT NULL,
  `tenant_id` int(11) NOT NULL,
  `client_id` int(11) NOT NULL,
  `name` varchar(150) DEFAULT NULL,
  `consumer_number` varchar(50) DEFAULT NULL,
  `address` text DEFAULT NULL,
  `category` varchar(50) DEFAULT NULL,
  `sanction_number` varchar(100) DEFAULT NULL,
  `sanctioned_capacity` decimal(6,2) DEFAULT NULL,
  `installed_capacity` decimal(6,2) DEFAULT NULL,
  `module_make` varchar(150) DEFAULT NULL,
  `almm_model` varchar(100) DEFAULT NULL,
  `wattage_per_module` int(11) DEFAULT NULL,
  `number_of_modules` int(11) DEFAULT NULL,
  `total_capacity` decimal(6,2) DEFAULT NULL,
  `warranty_details` text DEFAULT NULL,
  `inverter_make_model` varchar(150) DEFAULT NULL,
  `inverter_rating` varchar(100) DEFAULT NULL,
  `charge_controller` varchar(100) DEFAULT NULL,
  `inverter_capacity` varchar(100) DEFAULT NULL,
  `hpd` varchar(50) DEFAULT NULL,
  `manufacturing_year` int(11) DEFAULT NULL,
  `earthings_count` int(11) DEFAULT NULL,
  `lightening_arrester` varchar(50) DEFAULT NULL,
  `vendor_name` varchar(150) DEFAULT NULL,
  `aadhar_number` varchar(20) DEFAULT NULL,
  `report_date` date DEFAULT NULL,
  `created_at` datetime DEFAULT current_timestamp(),
  `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `advance_payments`
--
ALTER TABLE `advance_payments`
  ADD PRIMARY KEY (`id`),
  ADD KEY `client_id` (`client_id`),
  ADD KEY `idx_tenant_id` (`tenant_id`);

--
-- Indexes for table `bank_quotations`
--
ALTER TABLE `bank_quotations`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_tenant_id` (`tenant_id`);

--
-- Indexes for table `bank_quotation_products`
--
ALTER TABLE `bank_quotation_products`
  ADD PRIMARY KEY (`id`),
  ADD KEY `quotation_id` (`quotation_id`),
  ADD KEY `idx_tenant_id` (`tenant_id`);

--
-- Indexes for table `client_documents`
--
ALTER TABLE `client_documents`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_tenant_id` (`tenant_id`);

--
-- Indexes for table `commissioning_certificates`
--
ALTER TABLE `commissioning_certificates`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_tenant_client` (`tenant_id`,`client_id`),
  ADD KEY `idx_tenant_id` (`tenant_id`);

--
-- Indexes for table `company_bank_details`
--
ALTER TABLE `company_bank_details`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_tenant_id` (`tenant_id`);

--
-- Indexes for table `customers`
--
ALTER TABLE `customers`
  ADD PRIMARY KEY (`id`),
  ADD KEY `source_quotation_id` (`source_quotation_id`),
  ADD KEY `created_by` (`created_by`),
  ADD KEY `idx_tenant_id` (`tenant_id`);

--
-- Indexes for table `declaration_documents`
--
ALTER TABLE `declaration_documents`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_tenant_client_declaration` (`tenant_id`,`client_id`),
  ADD KEY `idx_tenant_id` (`tenant_id`);

--
-- Indexes for table `employees`
--
ALTER TABLE `employees`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_tenant_employee_id` (`tenant_id`,`employee_id`),
  ADD UNIQUE KEY `uniq_tenant_email` (`tenant_id`,`email`),
  ADD KEY `created_by` (`created_by`),
  ADD KEY `idx_tenant_id` (`tenant_id`);

--
-- Indexes for table `invoices`
--
ALTER TABLE `invoices`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_tenant_invoice_no` (`tenant_id`,`invoice_no`),
  ADD KEY `reference_id` (`reference_id`),
  ADD KEY `warehouse_id` (`warehouse_id`),
  ADD KEY `idx_tenant_id` (`tenant_id`),
  ADD KEY `idx_tenant_date` (`tenant_id`,`invoice_date`);

--
-- Indexes for table `invoice_items`
--
ALTER TABLE `invoice_items`
  ADD PRIMARY KEY (`id`),
  ADD KEY `invoice_id` (`invoice_id`),
  ADD KEY `product_id` (`product_id`),
  ADD KEY `idx_tenant_id` (`tenant_id`);

--
-- Indexes for table `invoice_payments`
--
ALTER TABLE `invoice_payments`
  ADD PRIMARY KEY (`id`),
  ADD KEY `invoice_id` (`invoice_id`),
  ADD KEY `idx_tenant_id` (`tenant_id`);

--
-- Indexes for table `login_history`
--
ALTER TABLE `login_history`
  ADD PRIMARY KEY (`id`),
  ADD KEY `user_id` (`user_id`),
  ADD KEY `idx_tenant_id` (`tenant_id`);

--
-- Indexes for table `model_agreements`
--
ALTER TABLE `model_agreements`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_tenant_client_agreement` (`tenant_id`,`client_id`),
  ADD KEY `idx_tenant_id` (`tenant_id`);

--
-- Indexes for table `net_metering_agreements`
--
ALTER TABLE `net_metering_agreements`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_tenant_client_metering` (`tenant_id`,`client_id`),
  ADD KEY `idx_tenant_id` (`tenant_id`);

--
-- Indexes for table `products`
--
ALTER TABLE `products`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_tenant_product_id` (`tenant_id`,`product_id`),
  ADD KEY `name` (`name`),
  ADD KEY `category_id` (`category_id`),
  ADD KEY `idx_tenant_id` (`tenant_id`),
  ADD KEY `idx_tenant_category` (`tenant_id`,`category_id`);

--
-- Indexes for table `product_attributes`
--
ALTER TABLE `product_attributes`
  ADD PRIMARY KEY (`id`),
  ADD KEY `product_id` (`product_id`),
  ADD KEY `attr_key` (`attr_key`),
  ADD KEY `idx_tenant_id` (`tenant_id`);

--
-- Indexes for table `product_categories`
--
ALTER TABLE `product_categories`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_tenant_category_id` (`tenant_id`,`category_id`),
  ADD KEY `idx_tenant_id` (`tenant_id`);

--
-- Indexes for table `product_images`
--
ALTER TABLE `product_images`
  ADD PRIMARY KEY (`id`),
  ADD KEY `product_id` (`product_id`),
  ADD KEY `idx_tenant_id` (`tenant_id`);

--
-- Indexes for table `product_manufacturers`
--
ALTER TABLE `product_manufacturers`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_tenant_manufacturer_id` (`tenant_id`,`manufacturer_id`),
  ADD KEY `category_id` (`category_id`),
  ADD KEY `idx_tenant_id` (`tenant_id`);

--
-- Indexes for table `product_serials`
--
ALTER TABLE `product_serials`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_tenant_serial_number` (`tenant_id`,`serial_number`),
  ADD KEY `product_id` (`product_id`),
  ADD KEY `warehouse_id` (`warehouse_id`),
  ADD KEY `idx_tenant_id` (`tenant_id`);

--
-- Indexes for table `product_suppliers`
--
ALTER TABLE `product_suppliers`
  ADD PRIMARY KEY (`id`),
  ADD KEY `product_id` (`product_id`),
  ADD KEY `supplier_id` (`supplier_id`),
  ADD KEY `idx_tenant_id` (`tenant_id`);

--
-- Indexes for table `purchase_orders`
--
ALTER TABLE `purchase_orders`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_tenant_po_number` (`tenant_id`,`po_number`),
  ADD KEY `warehouse_id` (`warehouse_id`),
  ADD KEY `invoice_id` (`invoice_id`),
  ADD KEY `fk_po_manufacturer` (`manufacturer_id`),
  ADD KEY `idx_tenant_id` (`tenant_id`),
  ADD KEY `idx_tenant_status` (`tenant_id`,`status`);

--
-- Indexes for table `purchase_order_items`
--
ALTER TABLE `purchase_order_items`
  ADD PRIMARY KEY (`id`),
  ADD KEY `purchase_order_id` (`purchase_order_id`),
  ADD KEY `product_id` (`product_id`),
  ADD KEY `idx_tenant_id` (`tenant_id`);

--
-- Indexes for table `quotations`
--
ALTER TABLE `quotations`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_tenant_quotation_number` (`tenant_id`,`quotation_number`),
  ADD KEY `created_by` (`created_by`),
  ADD KEY `assigned_to` (`assigned_to`),
  ADD KEY `idx_tenant_id` (`tenant_id`),
  ADD KEY `idx_tenant_status` (`tenant_id`,`status`);

--
-- Indexes for table `quotation_status_history`
--
ALTER TABLE `quotation_status_history`
  ADD PRIMARY KEY (`id`),
  ADD KEY `quotation_id` (`quotation_id`),
  ADD KEY `changed_by` (`changed_by`),
  ADD KEY `idx_tenant_id` (`tenant_id`);

--
-- Indexes for table `solar_panels`
--
ALTER TABLE `solar_panels`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_tenant_client_panel` (`tenant_id`,`client_id`,`panel_number`),
  ADD KEY `idx_serial_number` (`serial_number`),
  ADD KEY `idx_tenant_id` (`tenant_id`);

--
-- Indexes for table `solar_rooftop_quotations`
--
ALTER TABLE `solar_rooftop_quotations`
  ADD PRIMARY KEY (`quotation_id`),
  ADD UNIQUE KEY `uniq_tenant_quote_number` (`tenant_id`,`quote_number`),
  ADD KEY `customer_name` (`customer_name`),
  ADD KEY `customer_id` (`customer_id`),
  ADD KEY `idx_tenant_id` (`tenant_id`);

--
-- Indexes for table `stock_movements`
--
ALTER TABLE `stock_movements`
  ADD PRIMARY KEY (`id`),
  ADD KEY `product_id` (`product_id`),
  ADD KEY `warehouse_from` (`warehouse_from`),
  ADD KEY `warehouse_to` (`warehouse_to`),
  ADD KEY `idx_tenant_id` (`tenant_id`);

--
-- Indexes for table `superadmin_activity_log`
--
ALTER TABLE `superadmin_activity_log`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_admin` (`admin_user_id`,`created_at`),
  ADD KEY `idx_tenant` (`target_tenant_id`,`created_at`),
  ADD KEY `idx_action` (`action_type`,`created_at`);

--
-- Indexes for table `suppliers`
--
ALTER TABLE `suppliers`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_tenant_id` (`tenant_id`);

--
-- Indexes for table `tenants`
--
ALTER TABLE `tenants`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_tenant_active` (`is_active`),
  ADD KEY `idx_subscription` (`subscription_status`);

--
-- Indexes for table `tenant_bank_details`
--
ALTER TABLE `tenant_bank_details`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_tenant_bank` (`tenant_id`,`is_active`),
  ADD KEY `idx_primary_bank` (`tenant_id`,`is_primary`);

--
-- Indexes for table `undertaking_documents`
--
ALTER TABLE `undertaking_documents`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_tenant_undertaking_client` (`tenant_id`,`client_id`),
  ADD KEY `idx_tenant_id` (`tenant_id`);

--
-- Indexes for table `user_permissions`
--
ALTER TABLE `user_permissions`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `unique_role_module` (`role`,`module`);

--
-- Indexes for table `user_profiles`
--
ALTER TABLE `user_profiles`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_tenant_user_id` (`tenant_id`,`user_id`),
  ADD KEY `idx_tenant_id` (`tenant_id`);

--
-- Indexes for table `vendors_retailers`
--
ALTER TABLE `vendors_retailers`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_tenant_id` (`tenant_id`);

--
-- Indexes for table `warehouses`
--
ALTER TABLE `warehouses`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_tenant_warehouse_code` (`tenant_id`,`code`),
  ADD KEY `idx_tenant_id` (`tenant_id`);

--
-- Indexes for table `warehouse_employees`
--
ALTER TABLE `warehouse_employees`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_tenant_warehouse_employee` (`tenant_id`,`warehouse_id`,`employee_id`),
  ADD KEY `employee_id` (`employee_id`),
  ADD KEY `idx_tenant_id` (`tenant_id`);

--
-- Indexes for table `warehouse_stock`
--
ALTER TABLE `warehouse_stock`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_tenant_warehouse_product` (`tenant_id`,`warehouse_id`,`product_id`),
  ADD KEY `warehouse_id` (`warehouse_id`),
  ADD KEY `product_id` (`product_id`),
  ADD KEY `idx_tenant_id` (`tenant_id`),
  ADD KEY `idx_tenant_warehouse_product` (`tenant_id`,`warehouse_id`,`product_id`);

--
-- Indexes for table `warehouse_stock_snapshots`
--
ALTER TABLE `warehouse_stock_snapshots`
  ADD PRIMARY KEY (`id`),
  ADD KEY `warehouse_id` (`warehouse_id`),
  ADD KEY `product_id` (`product_id`),
  ADD KEY `idx_tenant_id` (`tenant_id`);

--
-- Indexes for table `work_completion_reports`
--
ALTER TABLE `work_completion_reports`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_tenant_client_report` (`tenant_id`,`client_id`),
  ADD KEY `idx_tenant_id` (`tenant_id`);

--
-- AUTO_INCREMENT for dumped tables
--

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

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

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

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

--
-- AUTO_INCREMENT for table `commissioning_certificates`
--
ALTER TABLE `commissioning_certificates`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

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

--
-- AUTO_INCREMENT for table `customers`
--
ALTER TABLE `customers`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

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

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

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

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

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

--
-- AUTO_INCREMENT for table `login_history`
--
ALTER TABLE `login_history`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

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

--
-- AUTO_INCREMENT for table `net_metering_agreements`
--
ALTER TABLE `net_metering_agreements`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

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

--
-- AUTO_INCREMENT for table `product_attributes`
--
ALTER TABLE `product_attributes`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

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

--
-- AUTO_INCREMENT for table `product_images`
--
ALTER TABLE `product_images`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

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

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

--
-- AUTO_INCREMENT for table `product_suppliers`
--
ALTER TABLE `product_suppliers`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

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

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

--
-- AUTO_INCREMENT for table `quotations`
--
ALTER TABLE `quotations`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `quotation_status_history`
--
ALTER TABLE `quotation_status_history`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `solar_panels`
--
ALTER TABLE `solar_panels`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `solar_rooftop_quotations`
--
ALTER TABLE `solar_rooftop_quotations`
  MODIFY `quotation_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

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

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

--
-- AUTO_INCREMENT for table `suppliers`
--
ALTER TABLE `suppliers`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

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

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

--
-- AUTO_INCREMENT for table `undertaking_documents`
--
ALTER TABLE `undertaking_documents`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

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

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

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

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

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

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

--
-- AUTO_INCREMENT for table `warehouse_stock_snapshots`
--
ALTER TABLE `warehouse_stock_snapshots`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `work_completion_reports`
--
ALTER TABLE `work_completion_reports`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- Constraints for dumped tables
--

--
-- Constraints for table `advance_payments`
--
ALTER TABLE `advance_payments`
  ADD CONSTRAINT `advance_payments_ibfk_1` FOREIGN KEY (`client_id`) REFERENCES `clients` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_advance_payments_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `bank_quotations`
--
ALTER TABLE `bank_quotations`
  ADD CONSTRAINT `fk_bank_quotations_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `bank_quotation_products`
--
ALTER TABLE `bank_quotation_products`
  ADD CONSTRAINT `bank_quotation_products_ibfk_1` FOREIGN KEY (`quotation_id`) REFERENCES `bank_quotations` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_bank_quotation_products_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `client_documents`
--
ALTER TABLE `client_documents`
  ADD CONSTRAINT `fk_client_documents_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `commissioning_certificates`
--
ALTER TABLE `commissioning_certificates`
  ADD CONSTRAINT `fk_commissioning_certificates_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `company_bank_details`
--
ALTER TABLE `company_bank_details`
  ADD CONSTRAINT `fk_company_bank_details_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `customers`
--
ALTER TABLE `customers`
  ADD CONSTRAINT `customers_ibfk_1` FOREIGN KEY (`source_quotation_id`) REFERENCES `quotations` (`id`),
  ADD CONSTRAINT `customers_ibfk_2` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`),
  ADD CONSTRAINT `fk_customers_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `declaration_documents`
--
ALTER TABLE `declaration_documents`
  ADD CONSTRAINT `declaration_documents_ibfk_1` FOREIGN KEY (`client_id`) REFERENCES `clients` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_declaration_documents_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `employees`
--
ALTER TABLE `employees`
  ADD CONSTRAINT `employees_ibfk_1` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`),
  ADD CONSTRAINT `fk_employees_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `invoices`
--
ALTER TABLE `invoices`
  ADD CONSTRAINT `fk_invoices_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `invoice_items`
--
ALTER TABLE `invoice_items`
  ADD CONSTRAINT `fk_invoice_items_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `invoice_items_ibfk_1` FOREIGN KEY (`invoice_id`) REFERENCES `invoices` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `invoice_payments`
--
ALTER TABLE `invoice_payments`
  ADD CONSTRAINT `fk_invoice_payments_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `invoice_payments_ibfk_1` FOREIGN KEY (`invoice_id`) REFERENCES `invoices` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `login_history`
--
ALTER TABLE `login_history`
  ADD CONSTRAINT `fk_login_history_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `login_history_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`);

--
-- Constraints for table `model_agreements`
--
ALTER TABLE `model_agreements`
  ADD CONSTRAINT `fk_model_agreements_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `net_metering_agreements`
--
ALTER TABLE `net_metering_agreements`
  ADD CONSTRAINT `fk_net_metering_agreements_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `net_metering_agreements_ibfk_1` FOREIGN KEY (`client_id`) REFERENCES `clients` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `products`
--
ALTER TABLE `products`
  ADD CONSTRAINT `fk_products_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `product_attributes`
--
ALTER TABLE `product_attributes`
  ADD CONSTRAINT `fk_product_attributes_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `product_attributes_ibfk_1` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `product_categories`
--
ALTER TABLE `product_categories`
  ADD CONSTRAINT `fk_product_categories_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `product_images`
--
ALTER TABLE `product_images`
  ADD CONSTRAINT `fk_product_images_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `product_images_ibfk_1` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `product_manufacturers`
--
ALTER TABLE `product_manufacturers`
  ADD CONSTRAINT `fk_product_manufacturers_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `product_manufacturers_ibfk_1` FOREIGN KEY (`category_id`) REFERENCES `product_categories` (`id`);

--
-- Constraints for table `product_serials`
--
ALTER TABLE `product_serials`
  ADD CONSTRAINT `fk_product_serials_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `product_serials_ibfk_1` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `product_serials_ibfk_2` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE SET NULL;

--
-- Constraints for table `product_suppliers`
--
ALTER TABLE `product_suppliers`
  ADD CONSTRAINT `fk_product_suppliers_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `product_suppliers_ibfk_1` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `product_suppliers_ibfk_2` FOREIGN KEY (`supplier_id`) REFERENCES `suppliers` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `purchase_orders`
--
ALTER TABLE `purchase_orders`
  ADD CONSTRAINT `fk_po_manufacturer` FOREIGN KEY (`manufacturer_id`) REFERENCES `product_manufacturers` (`id`),
  ADD CONSTRAINT `fk_purchase_orders_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `purchase_orders_ibfk_2` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`),
  ADD CONSTRAINT `purchase_orders_ibfk_3` FOREIGN KEY (`invoice_id`) REFERENCES `invoices` (`id`);

--
-- Constraints for table `purchase_order_items`
--
ALTER TABLE `purchase_order_items`
  ADD CONSTRAINT `fk_purchase_order_items_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `purchase_order_items_ibfk_1` FOREIGN KEY (`purchase_order_id`) REFERENCES `purchase_orders` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `purchase_order_items_ibfk_2` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`);

--
-- Constraints for table `quotations`
--
ALTER TABLE `quotations`
  ADD CONSTRAINT `fk_quotations_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `quotations_ibfk_1` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`),
  ADD CONSTRAINT `quotations_ibfk_2` FOREIGN KEY (`assigned_to`) REFERENCES `users` (`id`);

--
-- Constraints for table `quotation_status_history`
--
ALTER TABLE `quotation_status_history`
  ADD CONSTRAINT `fk_quotation_status_history_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `quotation_status_history_ibfk_1` FOREIGN KEY (`quotation_id`) REFERENCES `quotations` (`id`),
  ADD CONSTRAINT `quotation_status_history_ibfk_2` FOREIGN KEY (`changed_by`) REFERENCES `users` (`id`);

--
-- Constraints for table `solar_panels`
--
ALTER TABLE `solar_panels`
  ADD CONSTRAINT `fk_solar_panels_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `solar_panels_ibfk_1` FOREIGN KEY (`client_id`) REFERENCES `clients` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `solar_rooftop_quotations`
--
ALTER TABLE `solar_rooftop_quotations`
  ADD CONSTRAINT `fk_solar_rooftop_quotations_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `stock_movements`
--
ALTER TABLE `stock_movements`
  ADD CONSTRAINT `fk_stock_movements_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `stock_movements_ibfk_1` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `stock_movements_ibfk_2` FOREIGN KEY (`warehouse_from`) REFERENCES `warehouses` (`id`) ON DELETE SET NULL,
  ADD CONSTRAINT `stock_movements_ibfk_3` FOREIGN KEY (`warehouse_to`) REFERENCES `warehouses` (`id`) ON DELETE SET NULL;

--
-- Constraints for table `suppliers`
--
ALTER TABLE `suppliers`
  ADD CONSTRAINT `fk_suppliers_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `tenant_bank_details`
--
ALTER TABLE `tenant_bank_details`
  ADD CONSTRAINT `tenant_bank_details_ibfk_1` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `undertaking_documents`
--
ALTER TABLE `undertaking_documents`
  ADD CONSTRAINT `fk_undertaking_documents_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `undertaking_documents_ibfk_1` FOREIGN KEY (`client_id`) REFERENCES `clients` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `user_profiles`
--
ALTER TABLE `user_profiles`
  ADD CONSTRAINT `fk_user_profiles_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `user_profiles_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `vendors_retailers`
--
ALTER TABLE `vendors_retailers`
  ADD CONSTRAINT `fk_vendors_retailers_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `warehouses`
--
ALTER TABLE `warehouses`
  ADD CONSTRAINT `fk_warehouses_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `warehouse_employees`
--
ALTER TABLE `warehouse_employees`
  ADD CONSTRAINT `fk_warehouse_employees_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `warehouse_employees_ibfk_1` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `warehouse_employees_ibfk_2` FOREIGN KEY (`employee_id`) REFERENCES `employees` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `warehouse_stock`
--
ALTER TABLE `warehouse_stock`
  ADD CONSTRAINT `fk_warehouse_stock_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `warehouse_stock_ibfk_1` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `warehouse_stock_ibfk_2` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `warehouse_stock_snapshots`
--
ALTER TABLE `warehouse_stock_snapshots`
  ADD CONSTRAINT `fk_warehouse_stock_snapshots_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `warehouse_stock_snapshots_ibfk_1` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouses` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `warehouse_stock_snapshots_ibfk_2` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `work_completion_reports`
--
ALTER TABLE `work_completion_reports`
  ADD CONSTRAINT `fk_work_completion_reports_tenant` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `work_completion_reports_ibfk_1` FOREIGN KEY (`client_id`) REFERENCES `clients` (`id`) ON DELETE CASCADE;
COMMIT;
