<!--hr/views/leave/allocationlist-->
<!-- <section class="container" style="padding-bottom: 2rem;">
  <div class="card bg-light-transparent">
    <div class="card-body">
      <div class="card no-shadow" style="padding-top: 3rem; padding-bottom: 3rem;">
        <div class="card-body">
          <div class="row">
            Current Staff Information (<?php echo date('Y') ?>)

          </div>
        </div>
      </div>
    </div>
  </div>
</section> -->
<section class="container" style="padding-bottom: 2rem;">
  <div class="card bg-light-transparent">
    <div class="card-header bg-light">
      <div class="float-right">
        <button class="btn btn-sm btn-outline-dark" onclick="setupAllocation()"><i class="fas fa-plus"></i> New Allocation</button>
      </div>
    </div>
    <div class="card-body">
      <div class="card no-shadow">
        <div class="card-body">
          <div class="table-responsive">
            <table class="table table-bordered table-hover">
              <thead>
                <th>Year</th>
                <!-- <th>Allocated</th> -->
                <th>Unallocated</th>
                <!-- <th>Status</th> -->
                <!-- <th width="20%">Updated By</th>
                <th width="15%">Updated On</th> -->
                <!-- <th width="10%"></th> -->
              </thead>
              <tbody>
                <?php if(isset($years)): ?>
                  <?php foreach($years as $y): ?>
                    <tr>
                      <td><a href="<?php echo base_url('hr/leave/allocation/').$y['year']; ?>"><?php echo $y['year']; ?></a></td>
                      <!-- <td>123</td> -->
                      <td>
                        <?php 
                          echo count($y['unallocated_users']); 
                        ?>
                      </td>
                      <!-- <td>
                        <?php if (isset($y['unallocated_users'])){ ?>
                        <h6><b>Unallocated Staff</b></h6>
                        <ul>
                          <?php foreach ($y['unallocated_users'] as $user): ?>
                            <li><a href="<?php echo base_url('hr/leave/application/').$user['id']; ?>"><?php echo $user['name']; ?></a></li>
                          <?php endforeach; ?>
                        </ul>
                        <?php } else if ($y['year'] == date('Y')) { ?>
                          <p style="text-success">Ongoing</p>
                        <?php } else { ?>
                          <p style="text-success">Completed</p>
                        <?php } ?>
                      </td> -->
                      <!-- <td><?php echo $y['updated_by']; ?></td>
                      <td><?php echo date('d/m/Y', strtotime($y['updated_ts'])); ?></td> -->
                      <!-- <td>
                        <div class="btn-group btn-group-sm">
                          <button class="btn btn-primary"><i class="fas fa-trash"></i></button>
                          <button class="btn btn-danger"><i class="fas fa-check"></i></button>
                        </div>
                      </td> -->
                    </tr>
                  <?php endforeach; ?>
                <?php endif; ?>
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>
  </div>
</section>
<div class="modal fade" id="setupAllocationModal">
  <div class="modal-dialog modal-sm">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="allocation-modal-title">Setup Allocation</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
          <div class="form-group">
              <label for="setupYearRef">For The Year</label>
              <input id="allocationYear" type="text" class="form-control yearpicker text-right" placeholder="Choose Year">
          </div>
      </div>
      <div class="modal-footer">
          <div class="float-right">
              <button class="btn btn-primary" type="button" onclick="newAllocation()">Create Allocation</button>
          </div>
      </div>
    </div>
  </div>
</div>
<script>

  $( ".yearpicker" ).datepicker({
      uiLibrary: 'bootstrap4',
      format: 'yyyy',
      autoclose: true,
      changeYear: true,
      viewMode: "years", 
      minViewMode: "years"
  });

  function setupAllocation() {
    // clearForm('#allocationForm');

    $('#setupAllocationModal').modal('show');
  }

  function newAllocation() {
    toastConfirm('You will be redirected to another page. Are you sure you want to proceed?', () => {
      var year = $('#allocationYear').val();
      
      location.href = "<?php echo base_url('hr/leave/newAllocation/'); ?>" + year;
    });
  }

</script>