 <?php 

$atp_id = user()->user_id;
$this->db->where('user_id', $atp_id);
$atp = $this->db->get('users')->row();
 ?>

 <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <div class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1 class="m-0 text-dark">All Admitted Student</h1>
          </div><!-- /.col -->
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="<?php echo base_url() ?>admin/admin/dashboard">Dashboard</a></li>
              <li class="breadcrumb-item"><a href="#">Fees Manager</a></li>
              <li class="breadcrumb-item active">Fees Receipts</li>

            </ol>
          </div><!-- /.col -->
        </div><!-- /.row -->
      </div><!-- /.container-fluid -->
    </div>
    <!-- /.content-header -->
    <!-- Main content -->
    <section class="content">
      <div class="container-fluid">
        <div class="card card-default">
          <div class="card-header">
            <h3 class="card-title">View All Student </h3>
          </div>
            <!-- /.card-header -->
            <div class="card-body">
              <table id="example1" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>Name & Photo</th>
                  <th>Details</th>
                  <th>Course</th>
                  <th>Total Due Amt</th>
                  <th>Payment Status</th>
                  <th></th>
                </tr>
                </thead>
                <tbody>
                <?php 
                $i=1; foreach ($all_students as $student):
                    $this->db->select('a.*, b.title, b.price');
                    $this->db->from('student_course a');
                    $this->db->join('course b', 'b.id = a.st_course_course_id', 'left');
                    $this->db->where('a.st_course_student_id', $student->user_id);
                    $this->db->where('a.st_course_status > ', 0);
                    $this->db->where('st_course_batch > ', 0);
                    $all_course = $this->db->get()->result();
                  if($all_course):
                ?>
                <tr>
                  <td><?php echo $student->user_name ?>
                    <br/>
                    <img src="<?php echo check_image($student->user_photo); ?>" width="50px">
                  </td>
                  <td>
                    Reg No. : <b><?php echo $student->user_reg_id ?></b>
                    <br/>
                    Mob. : <b><?php echo $student->user_mobile ?></b>
                    <?php if($student->user_email): ?>
                      <br/>
                      Email : <b><?php echo $student->user_email ?></b>
                    <?php endif;?>
                    <br/>
                    Gender : <b><?php echo $student->user_gender ?></b>
                    <?php if($student->user_dob != '0000-00-00'): ?>
                      <br/>
                      DOB : <b><?php echo date('d-m-Y', strtotime($student->user_dob)); ?></b>
                    <?php endif; ?>
                    <?php if($student->user_qualification): ?>
                      <br/>
                      Qulification : <b><?php echo $student->user_qualification ?></b>
                    <?php endif; ?>
                    <?php if($student->user_pin_code): ?>
                      <br/>
                      Address : <b>
                      <?php echo $student->user_village ?>, <?php echo $student->user_taluka ?>, <?php echo $student->user_dist ?>, <?php echo $student->user_state ?> - <?php echo $student->user_pin_code ?></b>
                    <?php endif;?>
                  </td>
                  <td>
                    <?php 
                    $pay_amount = 0;
                    $st_course_price = 0;
                    foreach ($all_course as $course) 
                    {
                      if($course->st_course_status == 6)
                      {
                        $pay_amount += 0;
                      }
                      else
                      {
                        $pay_amount += $course->fee_student_course_due;
                      }
                      

                      $st_course_price += $course->fee_student_course_price;
                    ?>
                    <span style="font-size: 14px" class="badge badge-warning mt-2"><?php echo substr_replace($course->title, '<br>', 25, 0);?> 
                    <?php if($course->st_course_status == 6): ?>
                      <span style="font-size: 14px" class="badge badge-danger mt-2">Refund Given
                      </span>
                    <?php endif; ?></span>
                    
                  <?php }?>

                  </td>
                  <td>
                    <?php
                    $count_refund = 0;
                    foreach ($all_course as $course): 
                      if($course->st_course_status == 6)
                      {
                        echo '<span class="badge badge-success">Rs. 0</span>';
                        $count_refund += 1;
                      }
                      else
                      {
                        if($course->fee_student_course_price != 0)
                        {
                          echo '<span class="badge badge-success">Rs. ' . $course->fee_student_course_due . '</span>';
                        }
                      }

                    ?>
                    <?php endforeach; ?>
                  </td>
                  <td>
                    <?php 
                    $is_menu_show = 0;
                    foreach ($all_course as $course):
                      if($course->st_course_status == 6)
                      {
                          echo '<span class="badge badge-danger">Payment Refund</span>';
                          $is_menu_show = 1;
                      }
                      elseif($course->fee_student_course_price == 0)
                      {
                          echo '<span class="badge badge-warning">Instalment Not Setup</span>';
                          $is_menu_show = 0;
                      }
                      elseif($course->fee_student_course_due > 0)
                      {
                          echo '<span class="badge badge-info">Payment Due</span>';
                          $is_menu_show = 1;
                      }
                      else
                      {
                          echo '<span class="badge badge-success">Payment Complete</span>';
                          $is_menu_show = 1;
                      }
                    ?>
                    <?php endforeach; ?>
                  </td>
                  <td class="text-left py-0 align-middle">
                    <div class="input-group mb-3">
                      <div class="input-group-prepend">
                        <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                        Action
                        </button>
                        <div class="dropdown-menu dropdown-menu-right">
                            <a class="dropdown-item" href="<?php echo base_url() ?>/admin/fees_management/fees_instalments/<?php echo $student->user_id; ?>"><i class="fas fa-rupee-sign"></i>&nbsp;&nbsp;Fees Instalments</a>
                          <?php if($is_menu_show): ?>
                          <div class="dropdown-divider"></div>
                            <a class="dropdown-item" href="<?php echo base_url() ?>/admin/fees_management/recive_fee/<?php echo $student->user_id; ?>"><i class="fas fa-plus"></i>&nbsp;&nbsp;Receive Fees</a>
                          <div class="dropdown-divider"></div>
                            <a class="dropdown-item" href="<?php echo base_url() ?>/admin/fees_management/print_receipt/<?php echo $student->user_id; ?>"><i class="fas fa-print"></i>&nbsp;&nbsp;Print Receipt</a>
                          <div class="dropdown-divider"></div>
                            <a class="dropdown-item" href="<?php echo base_url() ?>/admin/fees_management/fees_adjustment/<?php echo $student->user_id; ?>"><i class="fas fa-minus"></i>&nbsp;&nbsp;Fees Adjustment</a>
                          <div class="dropdown-divider"></div>
                            <a class="dropdown-item" href="<?php echo base_url() ?>/admin/fees_management/refund_fees/<?php echo $student->user_id; ?>"><i class="fas fa-times"></i>&nbsp;&nbsp;Refund Fees</a>
                          <?php endif; ?>
                          <?php if($count_refund > 0): ?>
                            <div class="dropdown-divider"></div>
                              <a class="dropdown-item" href="<?php echo base_url() ?>/admin/fees_management/print_refund_receipt/<?php echo $student->user_id; ?>"><i class="fas fa-print"></i>&nbsp;&nbsp;Print Refund Receipt</a>
                          <?php endif; ?>
                        </div>
                      </div>
                    </div>
                  </td>
                </tr>
                <?php $i++; ?>
                <?php endif; endforeach; ?>
                </tbody>
              </table>
            </div>
          </div>
      </div><!--/. container-fluid -->
    </section>
    <!-- /.content -->
  </div>

<?php $a=1; foreach ($all_students as $student): ?>

<?php $a++; endforeach; ?>
<style type="text/css">
#printformdata table tr td
{
  padding:0px;
}
#printformdata table 
{
  margin-bottom: 0;
}
</style>


<script type="text/javascript">

function printtable(e)
{
  var table=document.getElementById("printformdata"+e);
  var htmltoprint=''+'<style type="text/css">table {border-spacing: 0;border-collapse: collapse; width:100%; } tbody>tr>td{padding: 8px;line-height: 1.42857143;vertical-align: top; border:1px solid #ddd;}'+ 
  'thead>tr>th{padding: 8px;line-height: 1.42857143;vertical-align: top; border:1px solid #ddd;}'+
  '</style>';
  htmltoprint+=table.outerHTML;  
  newWin=window.open("");
  newWin.document.write(htmltoprint);
  newWin.print();
  newWin.close();
}
</script>
<style type="text/css">
#printformdata, #print_btn
{
  display: none;
}
</style>