 <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 Advance Salary <b><?php echo $cur_date;?></b></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="#">Payout</a></li>
              <li class="breadcrumb-item active">All Advance Salary</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">
              <?php echo form_open(base_url().'admin/payout/view_all_advane_salary'); ?>
                <div class="d-inline-block">
                  <input type="month" name="date" required class="form-control" value="<?php echo date('Y-m')?>">
                </div>
                <div class="d-inline-block">
                  <button class="btn btn-info" type="submit" name="search">Search</button>
                </div>
              <?php echo form_close(); ?>
            </h3>
            <div class="card-tools">
              <a href="javascript:void(0)" data-toggle="modal" data-target="#pay_modal" class="btn btn-success btn-sm"><i class="fa fa-plus" aria-hidden="true"></i> Add Adv. Salary</a>
            </div>
          </div>
            <!-- /.card-header -->
            <div class="card-body">
              <table id="example1" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>ID</th>
                  <th>Employee Name</th>
                  <th>Employee Role</th>
                  <th>Payment Details</th>
                  <th>Total Advance</th>
                </tr>
                </thead>
                <tbody>
                <?php $i=1; foreach ($all_salary_adv as $salary):
                $ttl_amt = 0;
                foreach ($salary->payout as $payout) 
                {
                  $ttl_amt += $payout->pay_amount;
                }
                ?>
                <tr>
                  <td><?php echo $i ?></td>
                  <td><?php echo $salary->user_name ?></td>
                  <td>
                    <span class="badge badge-success"><?php echo $salary->user_role ?></span>
                    <?php if($salary->is_instructor == 1): ?>
                      <br/>
                      <span class="badge badge-warning">Instructor</span>
                    <?php endif; ?>
                  </td>
                  <td>
                    <button data-toggle="modal" data-target="#pay_details<?php echo $salary->user_id; ?>" class="btn btn-warning btn-xs"><i class="fa fa-eye"></i> View Details</button>
                  </td>
                  <td><b>&#8377; <?php echo $ttl_amt; ?></b></td>
                </tr>
                <?php $i++; ?>
                <?php endforeach; ?>
                </tbody>
              </table>
            </div>
          </div>
      </div>
    </section>
  </div>
<?php $i=1; foreach ($all_salary_adv as $salary):?>
  <div class="modal fade" id="pay_details<?php echo $salary->user_id; ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title" id="exampleModalLabel">Payment Details</h5>
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
          </button>
        </div>
        <div class="modal-body">
          <table class="table table-bordered table-striped">
            <tr>
              <th>No</th>
              <th>Emp. Name</th>
              <th>Note</th>
              <th>Date</th>
              <th>Amount</th>
            </tr>
            <?php 
            $ttl_pay = 0;
            if($salary->payout): 
              $a =1; foreach ($salary->payout as $payout): 
              $ttl_pay += $payout->pay_amount;
              ?>
                <tr>
                  <td><?php echo $a; ?></td>
                  <td><?php echo $salary->user_name; ?></td>
                  <td width="30%"><small><?php echo $payout->pay_note; ?></small></td>
                  <td><?php echo date('d-m-Y', strtotime($payout->pay_date)); ?></td>
                  <td><b>&#8377;<?php echo $payout->pay_amount; ?></b></td>
                </tr>
              <?php $a++; endforeach ?>
              <tr>
                <th colspan="3"></th>
                <th>Total Adv.</th>
                <th>&#8377;<?php echo $ttl_pay; ?></th>
              </tr>
              <tr>
                <th colspan="3"></th>
                <th>Main Salary</th>
                <th>&#8377;<?php echo $salary->employee_pay_value; ?></th>
              </tr>
              <tr>
                <th colspan="3"></th>
                <th>Due Salary</th>
                <th>&#8377;<?php echo $salary->employee_pay_value - $ttl_pay; ?></th>
              </tr>
            <?php else: ?>
              <tr>
                <td colspan="5" class="text-center">No Data Found</td>
              </tr>
            <?php endif; ?>
          </table>
        </div>
      </div>
    </div>
  </div>
<?php endforeach; ?>


<div class="modal fade" id="pay_modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Payment Details</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <?php echo form_open(base_url().'admin/payout/add_advance_salary_details');?>
      <div class="modal-body">
        <div class="form-group">
          <label for="recipient-name" class="col-form-label">Select A Employee <span class="text-danger">*</span></label>
          <select type="text" class="form-control" id="recipient-name" required name="pay_emp_id">
            <option value="">Select</option>
            <?php foreach ($all_salary_adv as $data): ?>
              <option value="<?php echo $data->user_id; ?>"><?php echo $data->user_name; ?></option>
            <?php endforeach ?>
          </select>
        </div>
        <div class="form-group">
          <label for="message-date" class="col-form-label">Date <span class="text-danger">*</span></label>
          <input class="form-control" id="message-date" name="pay_date" required type="date" value="<?php echo date('Y-m-d')?>">
        </div>
        <div class="form-group">
          <label for="message-amount" class="col-form-label">Amount <span class="text-danger">*</span></label>
          <input class="form-control" id="message-amount" name="pay_amount" required type="number" >
        </div>
        <div class="form-group">
          <label for="message-text" class="col-form-label">Note:</label>
          <textarea class="form-control" id="message-text" placeholder="Enter Note Here" name="pay_note"></textarea>
        </div>
      </div>
      <div class="modal-footer">
        <button onclick="return confirm('Are you sure?')" type="submit" class="btn btn-primary">Save</button>
      </div>
      <?php echo form_close();?>
    </div>
  </div>
</div>