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

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


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `lms`
--

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

--
-- Table structure for table `academic_years`
--

CREATE TABLE `academic_years` (
  `id` int(11) NOT NULL,
  `year_name` varchar(20) NOT NULL,
  `start_date` date NOT NULL,
  `end_date` date NOT NULL,
  `is_current` tinyint(1) DEFAULT 0,
  `status` tinyint(1) DEFAULT 1,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `academic_years`
--

INSERT INTO `academic_years` (`id`, `year_name`, `start_date`, `end_date`, `is_current`, `status`, `created_at`) VALUES
(1, '2024-2025', '2024-04-01', '2025-03-30', 0, 1, '2025-12-30 14:22:56'),
(2, '2025-2026', '2025-04-01', '2026-03-30', 1, 1, '2025-12-30 14:30:18');

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

--
-- Table structure for table `admin_account`
--

CREATE TABLE `admin_account` (
  `id` int(11) NOT NULL,
  `username` varchar(50) NOT NULL,
  `email` varchar(100) NOT NULL,
  `password` varchar(255) NOT NULL,
  `phone_number` varchar(15) DEFAULT NULL,
  `otp_code` varchar(6) DEFAULT NULL,
  `otp_expiry` datetime DEFAULT NULL,
  `reset_token` varchar(100) DEFAULT NULL,
  `reset_expiry` datetime DEFAULT NULL,
  `login_attempts` int(11) DEFAULT 0,
  `lockout_until` datetime DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `admin_account`
--

INSERT INTO `admin_account` (`id`, `username`, `email`, `password`, `phone_number`, `otp_code`, `otp_expiry`, `reset_token`, `reset_expiry`, `login_attempts`, `lockout_until`, `created_at`) VALUES
(1, 'Waiz', 'mushtaqueahmed178@gmail.com', '$2y$10$UnFICZIM7Fo.9Sq/Mu7a8.SFPeckHMSwbuVaM3JTFxuWN4.kErzvy', '8472083737', '873950', '2026-01-13 06:07:52', NULL, NULL, 0, NULL, '2026-01-10 15:21:27');

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

--
-- Table structure for table `chapters`
--

CREATE TABLE `chapters` (
  `id` int(11) NOT NULL,
  `subject_id` int(11) DEFAULT NULL,
  `chapter_name` varchar(200) DEFAULT NULL,
  `chapter_order` int(11) DEFAULT 1,
  `status` 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_general_ci;

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

--
-- Table structure for table `classes`
--

CREATE TABLE `classes` (
  `id` int(11) NOT NULL,
  `class_name` varchar(50) NOT NULL,
  `status` tinyint(1) NOT NULL DEFAULT 1,
  `session_year` varchar(10) DEFAULT NULL,
  `class_section` varchar(10) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `classes`
--

INSERT INTO `classes` (`id`, `class_name`, `status`, `session_year`, `class_section`) VALUES
(19, 'I', 1, NULL, NULL),
(20, 'II', 1, NULL, NULL),
(21, 'III', 1, NULL, NULL),
(22, 'IV', 1, NULL, NULL),
(23, 'V', 1, NULL, NULL);

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

--
-- Table structure for table `contact_messages`
--

CREATE TABLE `contact_messages` (
  `id` int(11) NOT NULL,
  `name` varchar(200) DEFAULT NULL,
  `email` varchar(200) DEFAULT NULL,
  `phone` varchar(50) DEFAULT NULL,
  `subject` varchar(255) DEFAULT NULL,
  `message` text DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `contact_messages`
--

INSERT INTO `contact_messages` (`id`, `name`, `email`, `phone`, `subject`, `message`, `created_at`) VALUES
(5, 'MUSHTAQUE AHMED', 'mushtaqueahmed178@gmail.com', '8472083737', 'this a message', 'this is a contact', '2025-12-18 10:50:14'),
(6, 'MUSHTAQUE AHMED', 'mushtaqueahme178@gmail.com', '08472083737', 'this a message', 'ssss', '2025-12-18 10:52:54');

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

--
-- Table structure for table `enrollments`
--

CREATE TABLE `enrollments` (
  `id` int(11) NOT NULL,
  `student_id` int(11) NOT NULL,
  `class_id` int(11) NOT NULL,
  `section_id` int(11) DEFAULT NULL,
  `medium_id` int(11) DEFAULT NULL,
  `academic_year_id` int(11) NOT NULL,
  `roll_no` varchar(20) DEFAULT NULL,
  `enrollment_date` date DEFAULT curdate(),
  `promotion_status` enum('active','promoted','failed','dropped') DEFAULT 'active'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `enrollments`
--

INSERT INTO `enrollments` (`id`, `student_id`, `class_id`, `section_id`, `medium_id`, `academic_year_id`, `roll_no`, `enrollment_date`, `promotion_status`) VALUES
(1, 34, 19, NULL, 2, 2, '42', '2026-01-28', 'active'),
(2, 35, 19, NULL, 2, 2, '65', '2026-01-28', 'active'),
(3, 36, 19, NULL, 2, 2, '74', '2026-01-28', 'active');

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

--
-- Table structure for table `exam_terms`
--

CREATE TABLE `exam_terms` (
  `id` int(11) NOT NULL,
  `term_name` varchar(100) NOT NULL,
  `status` tinyint(1) DEFAULT 1,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `max_marks` int(11) DEFAULT 100
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `exam_terms`
--

INSERT INTO `exam_terms` (`id`, `term_name`, `status`, `created_at`, `max_marks`) VALUES
(7, 'Annual', 1, '2026-01-28 12:48:18', 100);

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

--
-- Table structure for table `fee_assign`
--

CREATE TABLE `fee_assign` (
  `id` int(11) NOT NULL,
  `student_id` int(11) NOT NULL,
  `stream_id` int(11) DEFAULT NULL,
  `fee_type_id` int(11) NOT NULL,
  `total_amount` decimal(10,2) NOT NULL,
  `remaining_amount` decimal(10,2) DEFAULT 0.00,
  `due_month` varchar(30) NOT NULL,
  `due_date` date DEFAULT NULL,
  `payment_status` enum('unpaid','paid','partially_paid') DEFAULT 'unpaid',
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `fee_assign`
--

INSERT INTO `fee_assign` (`id`, `student_id`, `stream_id`, `fee_type_id`, `total_amount`, `remaining_amount`, `due_month`, `due_date`, `payment_status`, `created_at`, `updated_at`) VALUES
(60, 34, NULL, 44, 2000.00, 2000.00, 'February', '2026-02-28', 'unpaid', '2026-01-28 08:50:24', '2026-01-28 08:50:24'),
(61, 35, NULL, 44, 2000.00, 2000.00, 'February', '2026-02-28', 'unpaid', '2026-01-28 08:50:24', '2026-01-28 08:50:24'),
(62, 36, NULL, 44, 2000.00, 0.00, 'February', '2026-02-28', 'paid', '2026-01-28 08:50:24', '2026-01-28 12:34:18'),
(63, 34, NULL, 45, 500.00, 500.00, 'February', '2026-02-10', 'unpaid', '2026-01-28 08:51:04', '2026-01-28 08:51:04'),
(64, 35, NULL, 45, 500.00, 500.00, 'February', '2026-02-10', 'unpaid', '2026-01-28 08:51:04', '2026-01-28 08:51:04'),
(65, 36, NULL, 45, 500.00, 500.00, 'February', '2026-02-10', 'unpaid', '2026-01-28 08:51:04', '2026-01-28 08:51:04'),
(66, 34, NULL, 45, 500.00, 500.00, 'March', '2026-03-10', 'unpaid', '2026-01-28 11:24:46', '2026-01-28 11:24:46'),
(67, 35, NULL, 45, 500.00, 500.00, 'March', '2026-03-10', 'unpaid', '2026-01-28 11:24:46', '2026-01-28 11:24:46'),
(68, 36, NULL, 45, 500.00, 500.00, 'March', '2026-03-10', 'unpaid', '2026-01-28 11:24:46', '2026-01-28 11:24:46'),
(69, 34, NULL, 45, 500.00, 500.00, 'January', '2026-01-10', 'unpaid', '2026-01-29 10:25:39', '2026-01-29 10:25:39');

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

--
-- Table structure for table `fee_payments`
--

CREATE TABLE `fee_payments` (
  `id` int(11) NOT NULL,
  `fee_assign_id` int(11) NOT NULL,
  `student_id` int(11) NOT NULL,
  `fee_type_id` int(11) NOT NULL,
  `amount_paid` decimal(10,2) NOT NULL,
  `discount_amount` decimal(10,2) DEFAULT 0.00,
  `payment_mode` enum('Cash','UPI','Card','Cheque','Bank') NOT NULL,
  `payment_date` date NOT NULL,
  `receipt_number` varchar(50) DEFAULT NULL,
  `remarks` text DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `fee_payments`
--

INSERT INTO `fee_payments` (`id`, `fee_assign_id`, `student_id`, `fee_type_id`, `amount_paid`, `discount_amount`, `payment_mode`, `payment_date`, `receipt_number`, `remarks`, `created_at`) VALUES
(1, 62, 36, 44, 2000.00, 0.00, 'Cash', '2026-01-28', 'REC-1769603658', 'ist', '2026-01-28 12:34:18');

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

--
-- Table structure for table `fee_types`
--

CREATE TABLE `fee_types` (
  `id` int(11) NOT NULL,
  `fee_title` varchar(100) NOT NULL,
  `class_id` int(11) NOT NULL,
  `medium_id` int(11) DEFAULT NULL,
  `stream_id` int(11) DEFAULT NULL,
  `academic_year_id` int(11) DEFAULT NULL,
  `amount` decimal(10,2) NOT NULL,
  `description` text DEFAULT NULL,
  `status` tinyint(1) DEFAULT 1,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `km_range` int(11) DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `fee_types`
--

INSERT INTO `fee_types` (`id`, `fee_title`, `class_id`, `medium_id`, `stream_id`, `academic_year_id`, `amount`, `description`, `status`, `created_at`, `km_range`) VALUES
(44, 'Admission Fee', 19, 2, NULL, 2, 2000.00, '1st', 1, '2026-01-28 08:49:08', 0),
(45, 'Tuition Fee', 19, 2, NULL, 2, 500.00, 'ww', 1, '2026-01-28 08:49:30', 0);

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

--
-- Table structure for table `grading_system`
--

CREATE TABLE `grading_system` (
  `id` int(11) NOT NULL,
  `grade_name` varchar(50) NOT NULL,
  `min_percentage` int(11) NOT NULL,
  `max_percentage` int(11) NOT NULL,
  `remarks` varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `grading_system`
--

INSERT INTO `grading_system` (`id`, `grade_name`, `min_percentage`, `max_percentage`, `remarks`) VALUES
(1, 'Distinction', 85, 100, 'Outstanding'),
(2, 'Star Marks', 75, 84, 'Excellent'),
(3, '1st Divisi', 60, 74, 'First Division'),
(4, '2nd Divisi', 45, 59, 'Second Division'),
(5, '3rd Divisi', 30, 44, 'Third Division'),
(6, 'Failed', 0, 29, 'Needs Improvement');

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

--
-- Table structure for table `lessons`
--

CREATE TABLE `lessons` (
  `id` int(11) NOT NULL,
  `chapter_id` int(11) NOT NULL,
  `lesson_title` varchar(150) NOT NULL,
  `slug` varchar(150) DEFAULT NULL,
  `short_desc` text DEFAULT NULL,
  `video_url` varchar(255) DEFAULT NULL,
  `featured_image` varchar(255) DEFAULT NULL,
  `views` int(11) DEFAULT 0,
  `meta_title` varchar(160) DEFAULT NULL,
  `meta_description` varchar(255) DEFAULT NULL,
  `content` longtext DEFAULT NULL,
  `lesson_order` int(11) DEFAULT 1,
  `status` tinyint(1) DEFAULT 1,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Table structure for table `marks_entry`
--

CREATE TABLE `marks_entry` (
  `id` int(11) NOT NULL,
  `student_id` int(11) NOT NULL,
  `subject_id` int(11) NOT NULL,
  `stream_id` int(11) DEFAULT 0,
  `medium_id` int(11) DEFAULT 0,
  `exam_term_id` int(11) NOT NULL,
  `class_id` int(11) NOT NULL,
  `academic_year_id` int(11) NOT NULL,
  `theory_marks` decimal(5,2) DEFAULT 0.00,
  `practical_marks` decimal(5,2) DEFAULT 0.00,
  `total_marks` decimal(5,2) GENERATED ALWAYS AS (`theory_marks` + `practical_marks`) STORED,
  `added_by` int(11) DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `marks_entry`
--

INSERT INTO `marks_entry` (`id`, `student_id`, `subject_id`, `stream_id`, `medium_id`, `exam_term_id`, `class_id`, `academic_year_id`, `theory_marks`, `practical_marks`, `added_by`, `created_at`) VALUES
(65, 34, 29, 0, 2, 7, 19, 2, 80.00, 0.00, NULL, '2026-01-28 12:48:58'),
(66, 35, 29, 0, 2, 7, 19, 2, 70.00, 0.00, NULL, '2026-01-28 12:48:58'),
(67, 36, 29, 0, 2, 7, 19, 2, 50.00, 0.00, NULL, '2026-01-28 12:48:58'),
(68, 34, 24, 0, 2, 7, 19, 2, 80.00, 0.00, NULL, '2026-01-28 12:49:19'),
(69, 35, 24, 0, 2, 7, 19, 2, 75.00, 0.00, NULL, '2026-01-28 12:49:19'),
(70, 36, 24, 0, 2, 7, 19, 2, 60.00, 0.00, NULL, '2026-01-28 12:49:19'),
(71, 34, 27, 0, 2, 7, 19, 2, 85.00, 0.00, NULL, '2026-01-28 12:49:35'),
(72, 35, 27, 0, 2, 7, 19, 2, 70.00, 0.00, NULL, '2026-01-28 12:49:35'),
(73, 36, 27, 0, 2, 7, 19, 2, 45.00, 0.00, NULL, '2026-01-28 12:49:35'),
(74, 34, 25, 0, 2, 7, 19, 2, 90.00, 0.00, NULL, '2026-01-28 12:49:58'),
(75, 35, 25, 0, 2, 7, 19, 2, 72.00, 0.00, NULL, '2026-01-28 12:49:58'),
(76, 36, 25, 0, 2, 7, 19, 2, 52.00, 0.00, NULL, '2026-01-28 12:49:58'),
(77, 34, 26, 0, 2, 7, 19, 2, 89.00, 0.00, NULL, '2026-01-28 12:50:21'),
(78, 35, 26, 0, 2, 7, 19, 2, 59.00, 0.00, NULL, '2026-01-28 12:50:21'),
(79, 36, 26, 0, 2, 7, 19, 2, 41.00, 0.00, NULL, '2026-01-28 12:50:21'),
(80, 34, 28, 0, 2, 7, 19, 2, 90.00, 0.00, NULL, '2026-01-28 12:50:44'),
(81, 35, 28, 0, 2, 7, 19, 2, 56.00, 0.00, NULL, '2026-01-28 12:50:44'),
(82, 36, 28, 0, 2, 7, 19, 2, 52.00, 0.00, NULL, '2026-01-28 12:50:44');

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

--
-- Table structure for table `mediums`
--

CREATE TABLE `mediums` (
  `id` int(11) NOT NULL,
  `medium_name` varchar(50) NOT NULL,
  `status` tinyint(4) DEFAULT 1
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `mediums`
--

INSERT INTO `mediums` (`id`, `medium_name`, `status`) VALUES
(1, 'English', 1),
(2, 'Assamese', 1);

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

--
-- Table structure for table `school_settings`
--

CREATE TABLE `school_settings` (
  `id` int(11) NOT NULL DEFAULT 1,
  `school_name` varchar(255) NOT NULL,
  `school_logo` varchar(255) DEFAULT NULL,
  `school_address` text DEFAULT NULL,
  `phone_number` varchar(20) DEFAULT NULL,
  `email` varchar(100) DEFAULT NULL,
  `principal_signature` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `school_settings`
--

INSERT INTO `school_settings` (`id`, `school_name`, `school_logo`, `school_address`, `phone_number`, `email`, `principal_signature`) VALUES
(1, 'Al-Zabir Academy, Padupara', 'logo_1768577900_AL-ZABIR.png', 'Padupara, P.O: Ambari, PS:Dhupdhara, Dist: Goalpara, Pin No:783123 Assam', '8472083737', 'abc@gmail.com', 'sig_1767946416_signupdated.jpg');

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

--
-- Table structure for table `sections`
--

CREATE TABLE `sections` (
  `id` int(11) NOT NULL,
  `class_id` int(11) NOT NULL,
  `section_name` varchar(50) NOT NULL,
  `status` enum('active','inactive') DEFAULT 'active',
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Table structure for table `students`
--

CREATE TABLE `students` (
  `id` int(11) NOT NULL,
  `student_name` varchar(100) NOT NULL,
  `father_name` varchar(100) NOT NULL,
  `mother_name` varchar(100) DEFAULT NULL,
  `dob` date DEFAULT NULL,
  `admission_date` date DEFAULT NULL,
  `gender` enum('Male','Female','Other') NOT NULL,
  `parent_phone` varchar(20) DEFAULT NULL,
  `address` text DEFAULT NULL,
  `student_photo` varchar(255) DEFAULT NULL,
  `aadhaar_no` varchar(12) DEFAULT NULL,
  `status` tinyint(1) DEFAULT 1,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `students`
--

INSERT INTO `students` (`id`, `student_name`, `father_name`, `mother_name`, `dob`, `admission_date`, `gender`, `parent_phone`, `address`, `student_photo`, `aadhaar_no`, `status`, `created_at`) VALUES
(34, 'Irene Buck', 'Medge Blake', 'Constance Reeves', '2011-01-26', '2002-05-04', 'Male', '8135945779', 'Dolor asperiores vel', 'STD_1769589573_169.jpg', NULL, 1, '2026-01-28 08:39:34'),
(35, 'Shoshana Mullen', 'Tashya Perez', 'Kirestin Reid', '2011-07-18', '2000-03-04', 'Male', '+919916397229', 'Enim officia anim al', 'STD_1769589636_720.jpg', NULL, 1, '2026-01-28 08:40:36'),
(36, 'Xaviera Guerra', 'Germane Parrish', 'Pandora Downs', '2010-09-07', '2005-03-12', 'Female', '+917231811626', 'Dignissimos maxime o', 'STD_1769589699_882.jpg', NULL, 1, '2026-01-28 08:41:39');

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

--
-- Table structure for table `subjects`
--

CREATE TABLE `subjects` (
  `id` int(11) NOT NULL,
  `class_id` int(11) DEFAULT NULL,
  `subject_name` varchar(100) DEFAULT NULL,
  `status` tinyint(1) DEFAULT 1,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `theory_max` int(11) DEFAULT 100,
  `practical_max` int(11) DEFAULT 0,
  `pass_marks` int(11) DEFAULT 33
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `subjects`
--

INSERT INTO `subjects` (`id`, `class_id`, `subject_name`, `status`, `created_at`, `theory_max`, `practical_max`, `pass_marks`) VALUES
(24, 19, 'Assamese', 1, '2026-01-28 12:46:06', 100, 0, 30),
(25, 19, 'Maths', 1, '2026-01-28 12:46:20', 100, 0, 30),
(26, 19, 'Science', 1, '2026-01-28 12:46:46', 100, 0, 30),
(27, 19, 'English', 1, '2026-01-28 12:47:14', 100, 0, 30),
(28, 19, 'Social science', 1, '2026-01-28 12:47:37', 100, 0, 30),
(29, 19, 'Arabic', 1, '2026-01-28 12:47:52', 100, 0, 30);

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

--
-- Stand-in structure for view `view_student_fee_status`
-- (See below for the actual view)
--
CREATE TABLE `view_student_fee_status` (
);

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

--
-- Stand-in structure for view `v_pending_fees`
-- (See below for the actual view)
--
CREATE TABLE `v_pending_fees` (
`roll_no` varchar(20)
,`class_id` int(11)
,`student_id` int(11)
,`student_name` varchar(100)
,`parent_phone` varchar(20)
,`fee_type_id` int(11)
,`total_amount` decimal(10,2)
,`payment_status` enum('unpaid','paid','partially_paid')
,`due_month` varchar(30)
,`due_date` date
);

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

--
-- Structure for view `view_student_fee_status`
--
DROP TABLE IF EXISTS `view_student_fee_status`;

CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `view_student_fee_status`  AS SELECT `s`.`id` AS `student_id`, `s`.`student_name` AS `student_name`, `c`.`class_name` AS `class_name`, `fa`.`amount` AS `assigned_amount`, `fa`.`due_date` AS `due_date`, ifnull(sum(`fp`.`amount_paid`),0) AS `total_paid`, `fa`.`amount`- ifnull(sum(`fp`.`amount_paid`),0) AS `balance` FROM (((`students` `s` join `classes` `c` on(`s`.`class_id` = `c`.`id`)) join `fee_assign` `fa` on(`s`.`id` = `fa`.`student_id`)) left join `fee_payments` `fp` on(`fa`.`id` = `fp`.`fee_assign_id`)) GROUP BY `fa`.`id` ;

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

--
-- Structure for view `v_pending_fees`
--
DROP TABLE IF EXISTS `v_pending_fees`;

CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v_pending_fees`  AS SELECT `e`.`roll_no` AS `roll_no`, `e`.`class_id` AS `class_id`, `e`.`student_id` AS `student_id`, `s`.`student_name` AS `student_name`, `s`.`parent_phone` AS `parent_phone`, `fa`.`fee_type_id` AS `fee_type_id`, `fa`.`total_amount` AS `total_amount`, `fa`.`payment_status` AS `payment_status`, `fa`.`due_month` AS `due_month`, `fa`.`due_date` AS `due_date` FROM ((`fee_assign` `fa` join `enrollments` `e` on(`fa`.`student_id` = `e`.`student_id`)) join `students` `s` on(`e`.`student_id` = `s`.`id`)) ;

--
-- Indexes for dumped tables
--

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

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

--
-- Indexes for table `chapters`
--
ALTER TABLE `chapters`
  ADD PRIMARY KEY (`id`),
  ADD KEY `subject_id` (`subject_id`);

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

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

--
-- Indexes for table `enrollments`
--
ALTER TABLE `enrollments`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `unique_student_year` (`student_id`,`academic_year_id`),
  ADD KEY `class_id` (`class_id`),
  ADD KEY `academic_year_id` (`academic_year_id`);

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

--
-- Indexes for table `fee_assign`
--
ALTER TABLE `fee_assign`
  ADD PRIMARY KEY (`id`),
  ADD KEY `student_id` (`student_id`),
  ADD KEY `fee_type_id` (`fee_type_id`);

--
-- Indexes for table `fee_payments`
--
ALTER TABLE `fee_payments`
  ADD PRIMARY KEY (`id`),
  ADD KEY `student_id` (`student_id`),
  ADD KEY `fee_type_id` (`fee_type_id`),
  ADD KEY `fk_fee_assignment` (`fee_assign_id`);

--
-- Indexes for table `fee_types`
--
ALTER TABLE `fee_types`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `unique_fee_per_stream` (`fee_title`,`class_id`,`academic_year_id`,`stream_id`,`km_range`);

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

--
-- Indexes for table `lessons`
--
ALTER TABLE `lessons`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `slug` (`slug`),
  ADD UNIQUE KEY `slug_2` (`slug`),
  ADD KEY `fk_lessons_chapter` (`chapter_id`);

--
-- Indexes for table `marks_entry`
--
ALTER TABLE `marks_entry`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `unique_mark` (`student_id`,`subject_id`,`exam_term_id`,`academic_year_id`),
  ADD UNIQUE KEY `idx_marks_logic` (`student_id`,`subject_id`,`exam_term_id`,`academic_year_id`),
  ADD KEY `idx_marks_stream` (`stream_id`),
  ADD KEY `idx_marks_medium` (`medium_id`);

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

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

--
-- Indexes for table `sections`
--
ALTER TABLE `sections`
  ADD PRIMARY KEY (`id`),
  ADD KEY `fk_class_id` (`class_id`);

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

--
-- Indexes for table `subjects`
--
ALTER TABLE `subjects`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `class_id` (`class_id`,`subject_name`);

--
-- AUTO_INCREMENT for dumped tables
--

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

--
-- Constraints for dumped tables
--

--
-- Constraints for table `chapters`
--
ALTER TABLE `chapters`
  ADD CONSTRAINT `chapters_ibfk_1` FOREIGN KEY (`subject_id`) REFERENCES `subjects` (`id`);

--
-- Constraints for table `enrollments`
--
ALTER TABLE `enrollments`
  ADD CONSTRAINT `enrollments_ibfk_1` FOREIGN KEY (`student_id`) REFERENCES `students` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `enrollments_ibfk_2` FOREIGN KEY (`class_id`) REFERENCES `classes` (`id`),
  ADD CONSTRAINT `enrollments_ibfk_3` FOREIGN KEY (`academic_year_id`) REFERENCES `academic_years` (`id`);

--
-- Constraints for table `fee_assign`
--
ALTER TABLE `fee_assign`
  ADD CONSTRAINT `fee_assign_ibfk_1` FOREIGN KEY (`student_id`) REFERENCES `students` (`id`),
  ADD CONSTRAINT `fee_assign_ibfk_2` FOREIGN KEY (`fee_type_id`) REFERENCES `fee_types` (`id`);

--
-- Constraints for table `fee_payments`
--
ALTER TABLE `fee_payments`
  ADD CONSTRAINT `fee_payments_ibfk_1` FOREIGN KEY (`student_id`) REFERENCES `students` (`id`),
  ADD CONSTRAINT `fee_payments_ibfk_2` FOREIGN KEY (`fee_type_id`) REFERENCES `fee_types` (`id`),
  ADD CONSTRAINT `fk_fee_assignment` FOREIGN KEY (`fee_assign_id`) REFERENCES `fee_assign` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `lessons`
--
ALTER TABLE `lessons`
  ADD CONSTRAINT `fk_lessons_chapter` FOREIGN KEY (`chapter_id`) REFERENCES `chapters` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `lessons_ibfk_1` FOREIGN KEY (`chapter_id`) REFERENCES `chapters` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `sections`
--
ALTER TABLE `sections`
  ADD CONSTRAINT `fk_class_id` FOREIGN KEY (`class_id`) REFERENCES `classes` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Constraints for table `subjects`
--
ALTER TABLE `subjects`
  ADD CONSTRAINT `fk_subjects_class` FOREIGN KEY (`class_id`) REFERENCES `classes` (`id`) ON DELETE CASCADE;
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
