<!-- Extend area where template is defined -->
<?= $this->extend('templates/adminlte/generalcontent') ?>
<!-- .Extend -->

<!-- Title of the page -->
<?= $this->section('title') ?>TK Raw Log Management<?= $this->endSection() ?>
<!-- .Title -->

<!-- CSS of the page -->
<?= $this->section('css') ?>

<!-- DataTables -->
<link rel="stylesheet" href="<?= base_url() ?>adminlte/plugins/datatables-bs4/css/dataTables.bootstrap4.min.css">
<link rel="stylesheet" href="<?= base_url() ?>adminlte/plugins/datatables-responsive/css/responsive.bootstrap4.min.css">

<?= $this->endSection() ?>
<!-- .CSS -->

<!-- body attribute - class definition -->
<?= $this->section('bodyclass') ?>sidebar-mini<?= $this->endSection() ?>
<!-- .body attribute -->

<!-- Container title -->
<?= $this->section('containertitle') ?>Raw Attendance Log<?= $this->endSection() ?>
<!-- .Container title -->

<!-- Active breadcrumb -->
<?= $this->section('breadcrumbs') ?>
<li class="breadcrumb-item active">Raw Log</li>
<?= $this->endSection() ?>
<!-- .Active breadcrumb -->

<!-- Main content -->
<?= $this->section('main') ?>

<!-- Modal Add Branch -->
<div class="modal fade" id="mdlAddBranch">
  <div class="modal-dialog">
    <div class="modal-content">
      <form action="<?= url_to('payroll/addpaygroup') ?>" method="post">
        <div class="modal-header">
          <h4 class="modal-title" >New Group</h4>
          <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="row">
            <div class="col-12">
              <p class="lead">Payroll Group Information</p>
              <div class="row">
                <div class="col-12">
                  <div class="form-group">
                    <label for="txtGroupCode">Payroll Group Code</label>
                    <input class="form-control" type="text" id="txtGroupCode" name="pay_group_code" value="<?= old('pay_group_code') ?>">
                  </div>
                  <div class="form-group">
                    <label for="txtGroupName">Payroll Group Name</label>
                    <input class="form-control" type="text" id="txtGroupName" name="pay_group_name" values="<?= old('pay_group_name') ?>">
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="modal-footer">
            <button type="submit" class="btn btn-primary">Save changes</button>
            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        </div>
      </form>
    </div>
  </div>
</div>


<div class="row">
    <div class="col-12">
        <div class="card">
            <div class="card-header">
                <h3 class="card-title">List of Payroll Groups</h3>
            </div>
            <div class="card-body">
                <form action="#" method="get">
                  <div class="row">
                    <div class="col-12 col-md-6">
                      <div class="form-group">
                        <label>Select Payroll Transaction</label>
                        <select class="form-control" name="paytrans_id">
                            <?php foreach($payrollTransactions as $payrollTransaction): ?>
                            <?php
                              if(isset($selectedData))
                              $selected = ($payrollTransaction->paytrans_id == $selectedData['paytrans_id']) ? 'selected' : '';  
                            ?>
                              <option value="<?= $payrollTransaction->paytrans_id ?>" <?= (isset($selected) ? $selected : '') ?>>Payroll from <?= $payrollTransaction->payroll_from ?> to <?= $payrollTransaction->payroll_to ?> [<?= $payrollTransaction->no_of_days ?> days]</option>
                            <?php endforeach; ?>
                        </select>
                      </div>
                    </div>
                    <div class="col-12 col-md-6">
                      <div class="form-group">
                        <label>Select Group</label>
                        <div class="input-group mb-3">
                          <select class="form-control select2 rounded-0" name="pay_group_id">
                            <?php foreach($payGroups as $payGroup): ?>
                            <?php
                              if(isset($selectedData))
                              $selected = ($payGroup->pay_group_id == $selectedData['pay_group_id']) ? 'selected' : '';  
                            ?>
                              <option value="<?= $payGroup->pay_group_id ?>" <?= (isset($selected) ? $selected : '') ?>>[<?= $payGroup->pay_group_code ?>] <?= $payGroup->pay_group_name ?></option>
                            <?php endforeach; ?>
                          </select>
                          <div class="input-group-append">
                            <button class="btn btn-info btn-flat">Get Attendance Log</button>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </form>
            </div>
        </div>
    </div>
</div>

<div class="row">
  <div class="col-12">
    <?php if(isset($employeeWorkDayCount)): ?>
      <div class="card">
        <form action="/tk/attsumsave/<?= $selectedData['paytrans_id'] ?>/<?= $selectedData['pay_group_id'] ?>" method="post">
          <div class="card-header">
            <h3 class="card-title">List of Employee Work Day Count</h3>
          </div>
          <div class="card-body">
            <div class="card-body">
              <?php if(!$attendanceSummarySaved): ?>
                <p>There is no summary yet. This record is from uploaded attendance log. Click on "Save this Summary" button to save the data.</p>
              <?php endif; ?>
              <?php if($attendanceSummarySaved): ?>
                <p>Summary is saved already. If captured data is erronous, delete the saved data and recapture again.</p>
              <?php endif; ?>
              <table id="tblAttSummary" class="table table-bordered table-hover">
                <thead>
                  <tr>
                    <th>Employee ID</th>
                    <th>Name</th>
                    <th>Work Day Count</th>
                  </tr>
                </thead>
                <?php foreach($employeeWorkDayCount as $value): ?>
                  <tr>
                    <td>
                      <?= $value['dtr_emp_id'] ?>
                      <input type="hidden" name="emp_work_day_count[]" value="<?= $value['employee_id'].'|'.$value['dtr_emp_id'].'|'.$value['employee_name'].'|'.$value['att_work_days'] ?>">
                    </td>
                    <td><?= ($value['employee_name'] == '') ? 'Unkown ID' : $value['employee_name'] ?></td>
                    <td>
                      <?= $value['att_work_days'] ?>
                    </td>
                  </tr>
                <?php endforeach; ?>
              </table>
            </div>
          </div>
          <div class="card-footer">
            <?php if(!$attendanceSummarySaved): ?>
              <button type="submit" class="btn btn-primary">Save This Summary</button>
            <?php endif; ?>
            <?php if($attendanceSummarySaved): ?>
              <a class="btn btn-danger" href="/tk/attsumdel/<?= $selectedData['paytrans_id'] ?>/<?= $selectedData['pay_group_id'] ?>" onclick="return confirm('Are you sure you want to delete this summary?')">Delete This Summary</a>
            <?php endif; ?>
          </div>
        </form>
      </div>
    <?php endif; ?>
  </div>
</div>

<?= $this->endSection() ?>
<!-- .Main content -->

<!-- Javascript -->

<?= $this->section('js') ?>

<!-- DataTables  & Plugins -->
<script src="<?= base_url() ?>adminlte/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="<?= base_url() ?>adminlte/plugins/datatables-bs4/js/dataTables.bootstrap4.min.js"></script>
<script src="<?= base_url() ?>adminlte/plugins/datatables-responsive/js/dataTables.responsive.min.js"></script>
<script src="<?= base_url() ?>adminlte/plugins/datatables-responsive/js/responsive.bootstrap4.min.js"></script>


<script>
$(document).ready(function() {

  $('#tblAttSummary').DataTable({
      "paging": true,
      "lengthChange": false,
      "searching": true,
      "ordering": true,
      "info": true,
      "autoWidth": false,
      "responsive": true,
    });
    
});



</script>

<?= $this->endSection() ?>

<!-- .Javascript -->