<script src="<?php echo admin_css(); ?>plugins/chart.js/Chart.min.js"></script>
<div class="content-wrapper">
   <div class="content-header">
      <div class="container-fluid">
         <div class="row mb-2">
            <div class="col-sm-6 col-12">
               <h1 class="m-0">Dashboard</h1>
            </div>
         </div>
      </div>
   </div>
   
   <?php if (user()->user_role == 'Branch'): ?>
      <?php
      $date1 = date('Y-m-d');
      $date2 = user()->user_rew_date;
      $d1 = new DateTime($date1);
      $d2 = new DateTime($date2);
      $diff = $d2->diff($d1);
      if($diff->days < 30):
      ?>
         <div class="content-header">
            <div class="container-fluid">
               <div class="row ">
                  <div class="col-sm-12">
                     <div class="alert alert-danger alert-dismissible fade show" role="alert">
                        <h4 class="alert-heading"><i class="fa fa-exclamation-circle" aria-hidden="true"></i> Renewal Pending ! Only <?php echo $diff->days;?> Days Left.</h4>
                        <p>Renew your institute membership for another year of access to resources and opportunities. Pay just
                           &#x20B9;
                           <?php echo user()->user_rew_fee; ?> and stay connected to the network. <a
                              class="btn btn-success btn-xs" href="<?php echo base_url(); ?>admin/atp/pay_renewal_fee">Renew now!</a>
                        </p>
                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                           <span aria-hidden="true">&times;</span>
                        </button>
                     </div>
                  </div>
               </div>
            </div>
         </div>
      <?php endif; ?>
      <section class="content">
         <div class="container-fluid">
            <div class="row">
               <div class="col-lg-3 col-6">
                  <div class="small-box bg-success">
                     <div class="inner">
                        <h3>
                           <?php
                           $user_id = user_id();

                           $this->db->select('a.st_course_student_id, b.instalment_amount');
                           $this->db->from('student_course a');
                           $this->db->join('student_payment_instalment b', 'b.instalment_student_id = a.st_course_student_id');
                           $this->db->where('st_course_student_atp_id', $user_id);
                           $this->db->where('b.instalment_status', 1);
                           $this->db->select_sum('b.instalment_amount');
                           $all_income = $this->db->get()->result();
                           $inc_all =0;
                           foreach ($all_income as $key => $income) 
                           {
                              $inc_all += $income->instalment_amount;
                           }
                           echo $inc_all;
                           ?>
                        </h3>
                        <p>Total Income</p>
                     </div>
                     <div class="icon">
                        <i class="fa fa-inr"></i>
                     </div>
                     <a href="#" class="small-box-footer">More info <i class="fas fa-arrow-circle-right"></i></a>
                  </div>
               </div>
               <div class="col-lg-3 col-6">
                  <div class="small-box bg-danger">
                     <div class="inner">
                        <h3>
                           <?php
                           $user_id = user_id();
                           $this->db->select_sum('expense_amount');
                           $this->db->where('expense_atp_id', $user_id);
                           $expense = $this->db->get('expense_management')->row();
                           if($expense->expense_amount)
                           {
                              echo $expense->expense_amount;
                           }
                           else
                           {
                              echo 0;
                           }
                           
                           ?>
                        </h3>
                        <p>Total Expense</p>
                     </div>
                     <div class="icon">
                        <i class="fa fa-inr"></i>
                     </div>
                     <a href="<?php echo base_url() ?>/admin/expense_management/all_expense" class="small-box-footer">More
                        info <i class="fas fa-arrow-circle-right"></i></a>
                  </div>
               </div>
               <div class="col-lg-3 col-6">
                  <div class="small-box bg-info">
                     <div class="inner">
                        <h3>
                           <?php
                           $atp_id = user_id();
                           $this->db->select('user_wallet_balance');
                           $this->db->where('user_id', $atp_id);
                           $atp_details = $this->db->get('users')->row();
                           echo $atp_details->user_wallet_balance;
                           ?>
                        </h3>
                        <p>Wallet Balance</p>
                     </div>
                     <div class="icon">
                        <i class="fa fa-inr"></i>
                     </div>
                     <a href="<?php echo base_url() ?>/admin/store/wallet" class="small-box-footer">More info <i
                           class="fas fa-arrow-circle-right"></i></a>
                  </div>
               </div>
               <div class="col-lg-3 col-6">
                  <div class="small-box" style="background-color:#259585">
                     <div class="inner">
                        <h3 style="color:#fff">
                           <?php
                           $atp_id = user_id();
                           $this->db->where('user_atp', $atp_id);
                           echo $ttl_enq = $this->db->get('student_enquiry')->num_rows();
                           ?>
                        </h3>
                        <p style="color:#fff">Total Inquiries</p>
                     </div>
                     <div class="icon">
                        <i class="fa fa-question-circle"></i>
                     </div>
                     <a href="<?php echo base_url() ?>/admin/students/all_enquiry" class="small-box-footer">More info <i
                           class="fas fa-arrow-circle-right"></i></a>
                  </div>
               </div>
               <div class="col-lg-3 col-6">
                  <div class="small-box" style="background-color:#652595">
                     <div class="inner">
                        <h3 style="color:#fff">
                           <?php
                           $atp_id = user_id();
                           $this->db->where('user_atp', $atp_id);
                           $this->db->where('user_role', "Student");
                           echo $ttl_adm = $this->db->get('users')->num_rows();
                           ?>
                        </h3>
                        <p style="color:#fff">Total Admission</p>
                     </div>
                     <div class="icon">
                        <i class="fa fa-users"></i>
                     </div>
                     <a href="<?php echo base_url() ?>/admin/students/admitted_student" class="small-box-footer">More info
                        <i class="fas fa-arrow-circle-right"></i></a>
                  </div>
               </div>
               <div class="col-lg-3 col-6">
                  <div class="small-box" style="background-color:#0e4020">
                     <div class="inner">
                        <h3 style="color:#fff">
                           <?php
                           $atp_id = user_id();
                           $this->db->where('added_by', $atp_id);
                           echo $ttl_batch = $this->db->get('student_batch')->num_rows();
                           ?>
                        </h3>
                        <p style="color:#fff">Total Batches</p>
                     </div>
                     <div class="icon">
                        <i class="fa fa-book"></i>
                     </div>
                     <a href="<?php echo base_url() ?>/admin/master/all_batch" class="small-box-footer">More info <i
                           class="fas fa-arrow-circle-right"></i></a>
                  </div>
               </div>
               <div class="col-lg-3 col-6">
                  <div class="small-box" style="background-color:#9f0e86">
                     <div class="inner">
                        <h3 style="color:#fff">
                           <?php
                           $atp_id = user_id();
                           $this->db->select_sum('expense_amount');
                           $this->db->where('expense_date', date('Y-m-d'));
                           $today_exp = $this->db->get('expense_management')->row();
                           if($today_exp->expense_amount)
                           {
                              echo $today_exp->expense_amount;
                           }
                           else
                           {
                              echo 0;
                           }
                           
                           ?>
                        </h3>
                        <p style="color:#fff">Todays Expenses</p>
                     </div>
                     <div class="icon">
                        <i class="fa fa-usd"></i>
                     </div>
                     <a href="<?php echo base_url() ?>/admin/expense_management/all_expense" class="small-box-footer">More
                        info <i class="fas fa-arrow-circle-right"></i></a>
                  </div>
               </div>
               <div class="col-lg-3 col-6">
                  <div class="small-box" style="background-color:#4c0e9f">
                     <div class="inner">
                        <h3 style="color:#fff">
                           0
                        </h3>
                        <p style="color:#fff">Todays Follow-ups</p>
                     </div>
                     <div class="icon">
                        <i class="fa fa-phone"></i>
                     </div>
                     <a href="<?php echo base_url() ?>/admin/students/all_enquiry" class="small-box-footer">More info <i
                           class="fas fa-arrow-circle-right"></i></a>
                  </div>
               </div>
               <div class="col-lg-3 col-6">
                  <div class="small-box" style="background-color:#2b9f0e">
                     <div class="inner">
                        <h3 style="color:#fff">
                           0
                        </h3>
                        <p style="color:#fff">Pending Follow-ups</p>
                     </div>
                     <div class="icon">
                        <i class="fa fa-phone"></i>
                     </div>
                     <a href="<?php echo base_url() ?>/admin/students/all_enquiry" class="small-box-footer">More info <i
                           class="fas fa-arrow-circle-right"></i></a>
                  </div>
               </div>
               <div class="col-lg-3 col-6">
                  <div class="small-box" style="background-color:#0e489f">
                     <div class="inner">
                        <h3 style="color:#fff">
                           <?php
                           $this->db->select_sum('fee_student_course_due');
                           $this->db->from('student_course');
                           $this->db->where('st_course_student_atp_id', $atp_id);
                           $this->db->where('st_course_status > ', 0);
                           $all_course = $this->db->get()->row();
                           if($all_course->fee_student_course_due)
                           {
                              echo $all_course->fee_student_course_due;
                           }
                           else
                           {
                              echo 0;
                           }
                           ?>
                        </h3>
                        <p style="color:#fff">Pending Fees</p>
                     </div>
                     <div class="icon">
                        <i class="fa fa-inr"></i>
                     </div>
                     <a href="<?php echo base_url() ?>/admin/fees_management/fees_receipts" class="small-box-footer">More
                        info <i class="fas fa-arrow-circle-right"></i></a>
                  </div>
               </div>
               <div class="col-lg-3 col-6">
                  <div class="small-box" style="background-color:#3c6a68">
                     <div class="inner">
                        <h3 style="color:#fff">
                           <?php
                           $this->db->select_sum('fee_student_course_discount');
                           $this->db->from('student_course');
                           $this->db->where('st_course_student_atp_id', $atp_id);
                           $this->db->where('st_course_status > ', 0);
                           $all_course = $this->db->get()->row();
                           if($all_course->fee_student_course_discount)
                           {
                              echo $all_course->fee_student_course_discount;
                           }
                           else
                           {
                              echo 0;
                           }
                           ?>
                        </h3>
                        <p style="color:#fff">Total Discount Allow</p>
                     </div>
                     <div class="icon">
                        <i class="fa fa-inr"></i>
                     </div>
                     <a href="<?php echo base_url() ?>/admin/fees_management/fees_receipts" class="small-box-footer">More
                        info <i class="fas fa-arrow-circle-right"></i></a>
                  </div>
               </div>
               <div class="col-lg-3 col-6">
                  <div class="small-box" style="background-color:#6a3c4d">
                     <div class="inner">
                        <h3 style="color:#fff">
                           0
                        </h3>
                        <p style="color:#fff">Salary Pending</p>
                     </div>
                     <div class="icon">
                        <i class="fa fa-inr"></i>
                     </div>
                     <a href="<?php echo base_url() ?>/admin/payout/view_all_salary" class="small-box-footer">More info <i
                           class="fas fa-arrow-circle-right"></i></a>
                  </div>
               </div>
               <div class="col-lg-12 col-12">
                  <div class="card">
                     <div class="card-header border-transparent">
                        <h3 class="card-title">Inquiry Vs Admission</h3>
                     </div>
                     <div class="card-body p-3">
                        <canvas id="inq_vs_adm" height="102"></canvas>
                     </div>
                  </div>
               </div>
               <div class="col-lg-12 col-12">
                  <div class="card">
                     <div class="card-header border-transparent">
                        <h3 class="card-title">Income Vs Expenses</h3>
                     </div>
                     <div class="card-body p-3">
                        <canvas id="monthly_income" height="102"></canvas>
                     </div>
                  </div>
               </div>
            </div>
         </div>
      </section>

      <script>
         const monthly_income = document.getElementById('monthly_income').getContext('2d');
         const monthly_inc = new Chart(monthly_income, {
            type: 'line',
            data: {
               labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
               datasets: [{
                  label: 'Income ',
                  data: [<?php echo $all_income; ?>],
                  backgroundColor: ['rgba(255, 99, 132, 0.2)',],
                  borderColor: ['rgba(255, 99, 132, 1)',],
                  borderWidth: 2
               },
               {
                  label: 'Expenses ',
                  data: [<?php echo $all_expance; ?>],
                  backgroundColor: ['rgba(255, 118, 0, 1, .2)',],
                  borderColor: ['rgba(255, 118, 0, 1)',],
                  borderWidth: 2
               }
               ]
            },
            options: {
               legend: {
                  display: false,
               },
               scales: {
                  y: {
                     beginAtZero: true
                  }
               },
            }
         });

         const inq_vs_adm = document.getElementById('inq_vs_adm').getContext('2d');
         const month_sales = new Chart(inq_vs_adm, {
            type: 'line',
            data: {
               labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
               datasets: [{
                  data: [<?php echo $all_enq; ?>],
                  label: 'Inquiry ',
                  backgroundColor: ['rgba(255, 99, 132, 0.2)',],
                  borderColor: ['rgba(255, 99, 132, 1)',],
                  borderWidth: 2
               },
               {
                  data: [<?php echo $all_admission; ?>],
                  label: 'Admission ',
                  backgroundColor: ['rgba(255, 118, 0, .2)',],
                  borderColor: ['rgba(255, 118, 0, 1)',],
                  borderWidth: 2
               }
               ]
            },
            options: {
               legend: {
                  display: false,
               },
               scales: {
                  y: {
                     beginAtZero: true
                  }
               },
            }
         });

      </script>
   <?php endif; ?>
   
   <?php if (user()->user_role == 'Super Admin' || user()->user_role == 'Super Admin'): ?>
      <section class="content">
         <div class="container-fluid">
            <div class="row">
               <div class="col-lg-3 col-6">
                  <div class="small-box bg-success">
                     <div class="inner">
                        <h3>
                           <?php
                           $this->db->select('a.st_course_student_id, b.instalment_amount');
                           $this->db->from('student_course a');
                           $this->db->join('student_payment_instalment b', 'b.instalment_student_id = a.st_course_student_id');
                           // $this->db->where('st_course_student_atp_id', $user_id);
                           $this->db->where('b.instalment_status', 1);
                           $this->db->select_sum('b.instalment_amount');
                           $all_income = $this->db->get()->result();
                           $inc_all =0;
                           foreach ($all_income as $key => $income) 
                           {
                              $inc_all += $income->instalment_amount;
                           }
                           echo $inc_all;
                           ?>
                        </h3>
                        <p>Total Income</p>
                     </div>
                     <div class="icon">
                        <i class="fa fa-inr"></i>
                     </div>
                     <a href="#" class="small-box-footer">More info <i class="fas fa-arrow-circle-right"></i></a>
                  </div>
               </div>
               
              
               <div class="col-lg-3 col-6">
                  <div class="small-box" style="background-color:#259585">
                     <div class="inner">
                        <h3 style="color:#fff">
                           <?php
                           echo $ttl_enq = $this->db->get('lead_management')->num_rows();
                           ?>
                        </h3>
                        <p style="color:#fff">Total Inquiries</p>
                     </div>
                     <div class="icon">
                        <i class="fa fa-question-circle"></i>
                     </div>
                     <a href="<?php echo base_url() ?>/admin/admin/lead_management" class="small-box-footer">More info <i
                           class="fas fa-arrow-circle-right"></i></a>
                  </div>
               </div>
               <div class="col-lg-3 col-6">
                  <div class="small-box" style="background-color:#652595">
                     <div class="inner">
                        <h3 style="color:#fff">
                           <?php
                           $this->db->where('user_role', "Student");
                           echo $ttl_adm = $this->db->get('users')->num_rows();
                           ?>
                        </h3>
                        <p style="color:#fff">Total Admission</p>
                     </div>
                     <div class="icon">
                        <i class="fa fa-users"></i>
                     </div>
                     <a href="<?php echo base_url() ?>/admin/students/admitted_student" class="small-box-footer">More info
                        <i class="fas fa-arrow-circle-right"></i></a>
                  </div>
               </div>
               <div class="col-lg-3 col-6">
                  <div class="small-box" style="background-color:#0e4020">
                     <div class="inner">
                        <h3 style="color:#fff">
                           <?php
                           echo $ttl_batch = $this->db->get('student_batch')->num_rows();
                           ?>
                        </h3>
                        <p style="color:#fff">Total Batches</p>
                     </div>
                     <div class="icon">
                        <i class="fa fa-book"></i>
                     </div>
                     <a href="<?php echo base_url() ?>/admin/master/all_batch" class="small-box-footer">More info <i
                           class="fas fa-arrow-circle-right"></i></a>
                  </div>
               </div>

               <div class="col-lg-3 col-6">
                  <div class="small-box" style="background-color:#4c0e9f">
                     <div class="inner">
                        <h3 style="color:#fff">
                           0
                        </h3>
                        <p style="color:#fff">Todays Follow-ups</p>
                     </div>
                     <div class="icon">
                        <i class="fa fa-phone"></i>
                     </div>
                     <a href="<?php echo base_url() ?>/admin/students/all_enquiry" class="small-box-footer">More info <i
                           class="fas fa-arrow-circle-right"></i></a>
                  </div>
               </div>
               <div class="col-lg-3 col-6">
                  <div class="small-box" style="background-color:#2b9f0e">
                     <div class="inner">
                        <h3 style="color:#fff">
                           0
                        </h3>
                        <p style="color:#fff">Pending Follow-ups</p>
                     </div>
                     <div class="icon">
                        <i class="fa fa-phone"></i>
                     </div>
                     <a href="<?php echo base_url() ?>/admin/students/all_enquiry" class="small-box-footer">More info <i
                           class="fas fa-arrow-circle-right"></i></a>
                  </div>
               </div>
               <div class="col-lg-3 col-6">
                  <div class="small-box" style="background-color:#0e489f">
                     <div class="inner">
                        <h3 style="color:#fff">
                           <?php
                           $this->db->where('user_role', 'Branch');
                           echo $all_branch = $this->db->get('users')->num_rows();
                           
                           ?>
                        </h3>
                        <p style="color:#fff">Total Branch</p>
                     </div>
                     <div class="icon">
                        <i class="fa fa-inr"></i>
                     </div>
                     <a href="<?php echo base_url() ?>/admin/branch/view_all_branch" class="small-box-footer">More
                        info <i class="fas fa-arrow-circle-right"></i></a>
                  </div>
               </div>
               <div class="col-lg-3 col-6">
                  <div class="small-box" style="background-color:#3c6a68">
                     <div class="inner">
                        <h3 style="color:#fff">
                           4
                        </h3>
                        <p style="color:#fff">Total Lead</p>
                     </div>
                     <div class="icon">
                        <i class="fa fa-inr"></i>
                     </div>
                     <a href="<?php echo base_url() ?>admin/admin/lead_management" class="small-box-footer">More
                        info <i class="fas fa-arrow-circle-right"></i></a>
                  </div>
               </div>
               <div class="col-lg-12 col-12">
                  <div class="card">
                     <div class="card-header border-transparent">
                        <h3 class="card-title">Inquiry Vs Admission</h3>
                     </div>
                     <div class="card-body p-3">
                        <canvas id="inq_vs_adm" height="102"></canvas>
                     </div>
                  </div>
               </div>
               <div class="col-lg-12 col-12">
                  <div class="card">
                     <div class="card-header border-transparent">
                        <h3 class="card-title">Income Vs Expenses</h3>
                     </div>
                     <div class="card-body p-3">
                        <canvas id="monthly_income" height="102"></canvas>
                     </div>
                  </div>
               </div>
            </div>
         </div>
      </section>

      <script>
         const monthly_income = document.getElementById('monthly_income').getContext('2d');
         const monthly_inc = new Chart(monthly_income, {
            type: 'line',
            data: {
               labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
               datasets: [{
                  label: 'Income ',
                  data: [<?php echo $all_income; ?>],
                  backgroundColor: ['rgba(255, 99, 132, 0.2)',],
                  borderColor: ['rgba(255, 99, 132, 1)',],
                  borderWidth: 2
               },
               {
                  label: 'Expenses ',
                  data: [<?php echo $all_expance; ?>],
                  backgroundColor: ['rgba(255, 118, 0, 1, .2)',],
                  borderColor: ['rgba(255, 118, 0, 1)',],
                  borderWidth: 2
               }
               ]
            },
            options: {
               legend: {
                  display: false,
               },
               scales: {
                  y: {
                     beginAtZero: true
                  }
               },
            }
         });

         const inq_vs_adm = document.getElementById('inq_vs_adm').getContext('2d');
         const month_sales = new Chart(inq_vs_adm, {
            type: 'line',
            data: {
               labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
               datasets: [{
                  data: [<?php echo $all_enq; ?>],
                  label: 'Inquiry ',
                  backgroundColor: ['rgba(255, 99, 132, 0.2)',],
                  borderColor: ['rgba(255, 99, 132, 1)',],
                  borderWidth: 2
               },
               {
                  data: [<?php echo $all_admission; ?>],
                  label: 'Admission ',
                  backgroundColor: ['rgba(255, 118, 0, .2)',],
                  borderColor: ['rgba(255, 118, 0, 1)',],
                  borderWidth: 2
               }
               ]
            },
            options: {
               legend: {
                  display: false,
               },
               scales: {
                  y: {
                     beginAtZero: true
                  }
               },
            }
         });

      </script>
   <?php endif; ?>
</div>

      