<style>
    body{background:#EAEDED;}
    a{color:black;}
a:hover{text-decoration:none;}
</style>
<div class="container-fluid mt-3 mb-3">
    <div class="row">
        <div class="col-sm-12 bg-white pt-3 pb-3">

            <ul class="breadcrumb">
            <li class="breadcrumb-item"><?php echo $this->session->userdata('ac_year'); ?></li> 
            <li class="breadcrumb-item"><a href="<?php echo base_url(); ?>Welcome">Home</a></li> 
            <li class="breadcrumb-item">All Student</li>
            <li class="breadcrumb-item"><a href="<?php echo base_url(); ?>Fee/invoices">All Invoices</a></li>
            <?php
            if($this->session->userdata('admin') ==1){
            ?>
            <li class="breadcrumb-item"><a href="<?php echo base_url();?>Fee/deleted_invoices">Deleted Invoices</a></li>
            <li class="breadcrumb-item"><a href="<?php echo base_url();?>Fee/deleted_students">Deleted Students</a></li>
            <?php
            }
            ?>
            </ul>
            <h1 class="text-success text-center" style="font-weight:600;font-size:18px;">All Students</h1><hr>
            <div class="table-responsive">
                <table class="table table-bordered table-striped" id="mytable">
                    <thead>
                        <tr>
                            <th>#</th>
                            <th>Name</th>
                            <th>Father Name</th>
                            <th>Sch. No.</th>
                            <th>Class</th>
                            <!--<th>Section</th>-->
                            <th>Profile</th>
                            <th>Edit</th>
                            <th>Fee</th>
                            <th>R.T.E.</th>
                            <th>Status</th>
                            <th>Ledger</th>
                            <?php
                            if($this->session->userdata('delete_student') ==1){
                            ?>
                            <!--<th>Course Id</th>-->
                            <th>Del</th>
                            <?php } ?>
                            <th>Documents</th>
                        </tr>
                    </thead>
                    <tbody>
                <?php
                $table="student";
                $count =0;
                $acedemic_session=$this->session->userdata('acedemic_session');
                $fetch_all_student = $this->WelcomeModel->get_students_ac_session($acedemic_session);
                if($fetch_all_student){
                    foreach($fetch_all_student as $data){ 
                        $sid=$data['sid'];
                        $get_student_data=$this->WelcomeModel->get_item_data($data['sid'],$table);
                        if($get_student_data ){
                            foreach($get_student_data as $students){


                                // $table='student';
                                // $all_students=$this->NewFeeModel->get_data($table);
                                // $count=0;
                                // if($all_students){
                                // foreach($all_students as $students){
                                $count=$count+1;
                ?>
                <tr>
                    <td><?php echo $count;?></td>
                    <td><?php echo $students['student_name'];?></td>
                    <td><?php echo $students['father_name'];?></td>
                    <td><?php echo $students['sch_no'];?></td>
                    <td><?php echo $data['class']." - ".$data['section'];?></td>
                    <!--<td><?php echo $data['section'];?></td>-->
                    <td><a href="<?php echo base_url();?>Fee/profile/<?php echo $students['id'];?>" class="btn btn-sm btn-warning" target="_blank">Profile</a></td>
                    <td>
                        <form method="post" action="<?php echo base_url();?>student/add_new_student" style="box-shadow:none; padding:0px 0px !important;">
                            <button class="btn btn-sm btn-primary edit" name="edit" value="<?php echo $students['id']; ?>" type="submit">Edit</button>
                        </form>
                    </td>
                    <td>
                        <!--<a href="<?php echo base_url();?>Fee/pay/<?php echo $students['id'];?>" class='btn btn-sm btn-success' target="_blank">Fee</a>-->
                        <a href="<?php echo base_url();?>Fee/pay_student_fee/<?php echo $students['id'];?>" class='btn btn-sm btn-success' target="_blank">Fee</a>
                    </td>
                    <td>
                        <?php 
                        $check_rte_status=$this->NewFeeModel->check_student_rte_status($sid,$acedemic_session);
                        if($check_rte_status){
                        ?>
                            <button class="btn btn-sm btn-info">
                                <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-check-lg" viewBox="0 0 16 16">
                                    <path d="M13.485 1.431a1.473 1.473 0 0 1 2.104 2.062l-7.84 9.801a1.473 1.473 0 0 1-2.12.04L.431 8.138a1.473 1.473 0 0 1 2.084-2.083l4.111 4.112 6.82-8.69a.486.486 0 0 1 .04-.045z"/>
                                </svg>
                            </button>
                        <?php
                        }else{
                        ?>
                        <a href="<?php echo base_url();?>Fee/profile/<?php echo $sid;?>" class="btn btn-sm btn-primary" target="_blank">
                            <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-plus-circle-fill" viewBox="0 0 16 16">
                                <path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM8.5 4.5a.5.5 0 0 0-1 0v3h-3a.5.5 0 0 0 0 1h3v3a.5.5 0 0 0 1 0v-3h3a.5.5 0 0 0 0-1h-3v-3z"/>
                            </svg>
                        </a>    
                        <?php
                        }
                        ?>
                    </td>
                    <td>
                        <?php
                        if($students['status'] == 0){
                        ?>
                            <button class="btn btn-sm btn-danger">Inactive</button>
                        <?php
                        }else if($students['status']==1){
                        ?>
                            <button class="btn btn-sm btn-success">Active</button>
                        <?php
                        }
                        ?>
                    </td>
                    <td><a href="<?php echo base_url();?>Ledger/student_ledger/<?php echo $students['id'];?>" class="btn btn-sm btn-warning" target="_blank">Ledger</a></td>
                    <?php
                    if($this->session->userdata('delete_student') ==1){
                    ?>
                    <!--<td><?php echo $data['course_id'];?></td>-->
                    <td>
                        <button class="btn btn-sm delete_item_btn" style="color:red;" item_id="<?php echo $students['id'];?>">
                            <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-trash-fill" viewBox="0 0 16 16">
                                <path d="M2.5 1a1 1 0 0 0-1 1v1a1 1 0 0 0 1 1H3v9a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2V4h.5a1 1 0 0 0 1-1V2a1 1 0 0 0-1-1H10a1 1 0 0 0-1-1H7a1 1 0 0 0-1 1H2.5zm3 4a.5.5 0 0 1 .5.5v7a.5.5 0 0 1-1 0v-7a.5.5 0 0 1 .5-.5zM8 5a.5.5 0 0 1 .5.5v7a.5.5 0 0 1-1 0v-7A.5.5 0 0 1 8 5zm3 .5v7a.5.5 0 0 1-1 0v-7a.5.5 0 0 1 1 0z"/>
                            </svg>
                        </button>
                    </td>
                    
                    <?php 
                    }
                    ?>
                    <td>
                        <a href="<?php echo base_url(); ?>Student/documentation/<?php echo $students['id'];?>" target="_blank" class="btn btn-outline-info">Documents</a>
                    </td>
                </tr>
            <?php
            }
        }
    }
}
?>    


                </tbody>
            </table>
        </div>


        </div>
    </div>
</div>

<script>
    $(document).ready(function(){
        $(".delete_item_btn").click(function () {
            var sid =$(this).attr("item_id");
            // alert(sid);
            $.ajax({
                url: '<?php echo base_url() ?>Fee/delete_student',
                type: 'POST', 
                data: { sid:sid},
                success: function(data){
                    alert(data);
                    // swal("Deleted Successfully");
                    location.reload(); 
                }
            });
        });
    })
</script>