// Reuslt module 
<script>
/* =========================
   Tab switching + safe route mapping
   - We use Laravel route() helper rendered in blade to get exact URLs.
   - This avoids hardcoded /admin/... vs /profile_management/... mismatch.
   ========================= */

const tabs = document.querySelectorAll('.tab-btn');
const contents = document.querySelectorAll('.tab-content');
const registrationId = "{{ $registration->id }}";

// Build per-tab routes using Laravel route() so paths always match routes/web.php
const tabRoutes = {
    'attendance-tab': "{{ route('profile.student.attendance', ['registration' => $registration->id]) }}",
    'due-fees-tab': "{{ route('profile.student.due_fees', ['registration' => $registration->id]) }}",
    'paid-fees-tab': "{{ route('profile.student.paid_fees', ['registration' => $registration->id]) }}",
    'marks-sheet-tab': "{{ route('profile.student.marks_sheet', ['registration' => $registration->id]) }}",
    'class-routine-tab': "{{ route('profile.student.class_routine', ['registration' => $registration->id]) }}",
    'sms-tab': "{{ route('profile.student.sms', ['registration' => $registration->id]) }}",
    'notices-tab': "{{ route('profile.student.notices', ['registration' => $registration->id]) }}",
    'exam-tab': "{{ route('profile.student.exam', ['registration' => $registration->id]) }}",
    'documents-tab': "{{ route('profile.student.documents', ['registration' => $registration->id]) }}",
    'complains-tab': "{{ route('profile.student.complains', ['registration' => $registration->id]) }}",
    'notes-tab': "{{ route('profile.student.notes', ['registration' => $registration->id]) }}"
}

// AJAX loader with optional params
function loadTabContent(tabName, params = {}) {
    const container = document.getElementById(tabName);
    if(!container) return;
    container.innerHTML = `<div class="text-center py-2"><div class="spinner-border spinner-border-sm" role="status"></div></div>`;

    const baseUrl = tabRoutes[tabName];
    if (!baseUrl) {
        container.innerHTML = `<div class="text-muted text-center py-2">No route configured for this tab.</div>`;
        return;
    }

    // build url with params
    let url = baseUrl;
    const urlObj = new URL(baseUrl, window.location.origin);
    // append params
    Object.keys(params).forEach(k => {
        if (params[k] !== null && params[k] !== undefined && params[k] !== '') {
            urlObj.searchParams.set(k, params[k]);
        }
    });
    // cache buster to avoid potential caching issues
    urlObj.searchParams.set('_', Date.now());

    fetch(urlObj.toString(), { headers: { 'X-Requested-With': 'XMLHttpRequest' } })
        .then(res => {
            if (!res.ok) throw new Error('Network response was not ok');
            return res.text();
        })
        .then(html => {
            container.innerHTML = html;

            // If we just loaded the due-fees tab, attach the session select handler
            if (tabName === 'due-fees-tab') {
                attachDueFeesFilter(container);
            }
        })
        .catch(err => {
            console.error(err);
            container.innerHTML = `<div class="text-danger py-2 text-center">Error loading data</div>`;
        });
}

// attach change listener to the session select inside the due-fees tab
function attachDueFeesFilter(container) {
    const select = container.querySelector('#due_session_select');
    if (!select) return;

    // Avoid duplicate listeners: remove previous if any (simple method)
    select.onchange = null;

    select.addEventListener('change', function () {
        const sessionId = this.value;
        // reload due-fees tab with selected session (AJAX, no page reload)
        loadTabContent('due-fees-tab', { session_id: sessionId });
    });
}


// Tab click handling (call loadTabContent for dynamic tabs)
tabs.forEach(tab => {
    tab.addEventListener('click', () => {
        tabs.forEach(t => t.classList.remove('active'));
        contents.forEach(c => c.classList.add('d-none'));

        tab.classList.add('active');
        const targetId = tab.dataset.tab;
        const targetContent = document.getElementById(targetId);
        targetContent.classList.remove('d-none');

        if (!['profile-tab','billing-tab'].includes(targetId)){
            // load without params (controller will pick active session)
            loadTabContent(targetId);
        }
    });
});


// initial load: profile tab already server-rendered; if you want to load billing via ajax uncomment:
// loadTabContent('billing-tab');

</script>





@extends('admin.admin_dashboard')

@section('customcss')
<!-- Datatable CSS -->
<link href="{{ asset('../asset/vendor/datatables/css/jquery.dataTables.min.css') }}" rel="stylesheet">
<!-- Nice Select CSS -->
<link href="{{ asset('../asset/vendor/jquery-nice-select/css/nice-select.css') }}" rel="stylesheet">
<style>
    /* ==================== Custom Styling ==================== */
    .card-title {
        font-weight: 600;
        font-size: 18px;
    }
    .breadcrumb {
        background: transparent;
        padding: 0;
        margin-bottom: 0;
    }
    .dataTables_wrapper .dataTables_filter input {
        border-radius: 5px;
        padding: 5px 10px;
        width: 200px;
    }
    .table th, .table td {
        vertical-align: middle;
    }
</style>
@endsection

@section('admin')
<div class="content-body">
    <div class="container-fluid">
        <!-- Page Title & Actions -->
        <div class="d-flex justify-content-between align-items-center mb-4">
            <ol class="breadcrumb mb-0">
                <li class="breadcrumb-item active"><a href="javascript:void(0)">Home</a></li>
                <li class="breadcrumb-item"><a href="javascript:void(0)">Class List</a></li>
            </ol>
            <a href="{{ route('admin.add.class') }}">
                <button class="btn btn-success">
                    <i class="fas fa-plus"></i> Add Class
                </button>
            </a>
        </div>

        <!-- Class Table Card -->
        <div class="card shadow-sm rounded-lg">
            <div class="card-header bg-white">
                <h4 class="card-title">Class List</h4>
            </div>
            <div class="card-body">
                <div class="table-responsive">
                    <table id="class-table" class="table table-striped table-bordered table-hover w-100">
                        <thead class="thead-light">
                            <tr>
                                <th>#</th>
                                <th>Class Name</th>
                                <th>Class Code</th>
                                <th>Section Count</th>
                                <th>Created At</th>
                                <th>Actions</th>
                            </tr>
                        </thead>
                        <tbody>
                            {{-- Data will be loaded via controller or AJAX --}}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

@section('customjs')
<!-- Datatable JS -->
<script src="{{ asset('../asset/vendor/datatables/js/jquery.dataTables.min.js') }}"></script>
<script src="{{ asset('../asset/js/plugins-init/datatables.init.js') }}"></script>

<!-- Nice Select JS -->
<script src="{{ asset('../asset/vendor/jquery-nice-select/js/jquery.nice-select.min.js') }}"></script>

<script>
    $(document).ready(function() {
        // Initialize DataTable
        $('#class-table').DataTable({
            processing: true,
            serverSide: true,
            ajax: "{{ route('admin.class.list.ajax') }}", // Route for AJAX fetch
            columns: [
                { data: 'id', name: 'id' },
                { data: 'name', name: 'name' },
                { data: 'class_code', name: 'class_code' },
                { data: 'sections_count', name: 'sections_count', searchable: false },
                { data: 'created_at', name: 'created_at' },
                { data: 'actions', name: 'actions', orderable: false, searchable: false },
            ],
            order: [[1, 'asc']],
            lengthMenu: [10, 25, 50, 100],
            responsive: true
        });

        // Initialize Nice Select if any dropdown
        $('select').niceSelect();
    });
</script>
@endsection









@extends('admin.admin_dashboard')
@section('customcss')
<!-- Datatable -->
<link href="{{asset('../asset/vendor/datatables/css/jquery.dataTables.min.css')}}" rel="stylesheet">
<!-- Custom Stylesheet -->
<link href="{{asset('../asset/vendor/jquery-nice-select/css/nice-select.css"')}}" rel="stylesheet">
@endsection

@section('admin')

		<!--**********************************
            Content body start
        ***********************************-->
		<div class="content-body">
			<div class="container-fluid">
				<div class="row page-titles">
					<div class="col-md-9">
						<ol class="breadcrumb">
							<li class="breadcrumb-item active"><a href="javascript:void(0)">Home </a></li>
							<li class="breadcrumb-item"><a href="javascript:void(0)">Class list</a></li>
						</ol>
					</div>
					<div class="col-md-3 mb-0 text-right">
						<a href="{{route('admin.add.class')}}"><button class="btn btn-success"><i class="fas fa-plus"></i> Add Class</button></a>
					</div>
				</div>
				<div class="row">
					<div class="col-12">
						<div class="card">
							<div class="card-header">
								<h4 class="card-title">Class List</h4>
							</div>
							<div class="card-body">
								<div class="table-responsive">
									<table id="example" class="display" style="min-width: 845px">
										<thead>
											<tr>
												<th>ID</th>
												<th>Name</th>
												<th>Created By</th>
												<th>Status</th>
												<th>Action</th>
											</tr>
										</thead>
										<tbody>
											@foreach($getRecord as $value)
											<tr>
												<td>{{$value->id}}</td>
												<td>{{$value->name}}</td>
												<td>{{$value->created_by_name}}</td>
												@if($value->status == 1)
													<td><span class="badge light badge-success">Active</span></td>
												@else
													<td><span class="badge light badge-danger">Inactive</span></td>
												@endif
												<td>
													<div class="dropdown ms-auto text-end">
														<div class="btn-link" data-bs-toggle="dropdown">
															<svg width="24px" height="24px" viewBox="0 0 24 24" version="1.1"><g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><rect x="0" y="0" width="24" height="24"></rect><circle fill="#000000" cx="5" cy="12" r="2"></circle><circle fill="#000000" cx="12" cy="12" r="2"></circle><circle fill="#000000" cx="19" cy="12" r="2"></circle></g></svg>
														</div>
														<div class="dropdown-menu dropdown-menu-end">
															<a class="dropdown-item" href="{{route('admin.edit.class', $value->id)}}">Edit</a>
															<a class="dropdown-item" href="{{route('admin.delete.class', $value->id)}}">Delete</a>
														</div>
													</div>
												</td>
											</tr>
											@endforeach
										</tbody>
									</table>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<!--**********************************
            Content body end
        ***********************************-->
@endsection

@section('customjs')

<!-- Datatable -->
<script src="{{asset('../asset/vendor/datatables/js/jquery.dataTables.min.js')}}"></script>
<script src="{{asset('../asset/js/plugins-init/datatables.init.js')}}"></script>

<script src="{{asset('../asset/vendor/jquery-nice-select/js/jquery.nice-select.min.js')}}"></script>
@endsection






########################################
############Model and table############# 
########################################


<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class ExamType extends Model
{
    use HasFactory;

    protected $fillable = [
        'name', 'description'
    ];

    public function exams()
    {
        return $this->hasMany(Exam::class);
    }
}

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Exam extends Model
{
    use HasFactory;

    protected $fillable = [
        'exam_name',
        'exam_type_id',
        'session_id',
        'class_id',
        'start_date',
        'end_date',
        'exam_fee',
        'status',
        'is_published',
        'created_by'
    ];

    public function session()
    {
        return $this->belongsTo(AcademicSession::class, 'session_id');
    }

    public function class()
    {
        return $this->belongsTo(ClassModel::class, 'class_id');
    }

    public function type()
    {
        return $this->belongsTo(ExamType::class, 'exam_type_id');
    }

    public function components()
    {
        return $this->hasMany(ExamComponent::class, 'exam_id');
    }
}

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class ExamComponent extends Model
{
    use HasFactory;

    protected $fillable = [
        'exam_id',
        'subject_id',
        'component_name',   // CQ, MCQ, Practical, Total
        'full_mark',
        'pass_mark'
    ];

    public function exam()
    {
        return $this->belongsTo(Exam::class);
    }

    public function subject()
    {
        return $this->belongsTo(Subject::class);
    }

    public function marks()
    {
        return $this->hasMany(ExamComponentMark::class, 'component_id');
    }
}

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class ExamComponentMark extends Model
{
    use HasFactory;

    protected $fillable = [
        'exam_id',
        'student_id',
        'subject_id',
        'component_id',
        'obtained_mark',
        'is_absent',
        'remarks',
        'submitted_by'
    ];

    public function exam()
    {
        return $this->belongsTo(Exam::class);
    }

    public function component()
    {
        return $this->belongsTo(ExamComponent::class, 'component_id');
    }

    public function student()
    {
        return $this->belongsTo(StudentInfo::class, 'student_id');
    }
}


<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class ExamWeightage extends Model
{
    use HasFactory;

    protected $fillable = [
        'session_id',
        'class_id',
        'term_exam_id',
        'component_exam_type_id',   // CT / MT / Term
        'weightage_percent'
    ];

    public function session()
    {
        return $this->belongsTo(AcademicSession::class, 'session_id');
    }

    public function class()
    {
        return $this->belongsTo(ClassModel::class, 'class_id');
    }

    public function exam()
    {
        return $this->belongsTo(Exam::class, 'term_exam_id');
    }
}


<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class GradeScale extends Model
{
    use HasFactory;

    protected $fillable = [
        'grade', 'min_mark', 'max_mark', 'grade_point'
    ];
}


<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class ExamResult extends Model
{
    use HasFactory;

    protected $fillable = [
        'student_id',
        'exam_id',
        'subject_id',
        'total_obtained',
        'grade',
        'grade_point',
        'is_absent',
        'remarks'
    ];

    public function exam()
    {
        return $this->belongsTo(Exam::class);
    }

    public function student()
    {
        return $this->belongsTo(StudentInfo::class, 'student_id');
    }
}

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class MeritList extends Model
{
    use HasFactory;

    protected $fillable = [
        'exam_id',
        'student_id',
        'class_id',
        'section_id',
        'position_class',
        'position_section',
        'is_manual',
        'set_by'
    ];

    public function exam()
    {
        return $this->belongsTo(Exam::class);
    }

    public function student()
    {
        return $this->belongsTo(StudentInfo::class, 'student_id');
    }
}


        <div class="content-body">
			<div class="container-fluid">
				
			</div>
		</div>



##############################################
################## Route #####################
##############################################






###############################################
################### Controller ################
###############################################

<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\ExamType;
use App\Http\Requests\ExamTypeRequest;

class ExamTypeController extends Controller
{
    public function index()
    {
        $examTypes = ExamType::orderBy('id','desc')->get();
        return view('admin.exam_types.index', compact('examTypes'));
    }

    public function create()
    {
        return view('admin.exam_types.create');
    }

    public function store(ExamTypeRequest $request)
    {
        ExamType::create($request->validated());
        return redirect()->route('exam-types.index')->with('success','Exam Type created successfully.');
    }

    public function edit(ExamType $examType)
    {
        return view('admin.exam_types.edit', compact('examType'));
    }

    public function update(ExamTypeRequest $request, ExamType $examType)
    {
        $examType->update($request->validated());
        return redirect()->route('exam-types.index')->with('success','Exam Type updated successfully.');
    }

    public function destroy(ExamType $examType)
    {
        $examType->delete();
        return redirect()->route('exam-types.index')->with('success','Exam Type deleted successfully.');
    }
}





