<style>
    .cursor
    {
        cursor:pointer;
    }
</style>
<div class="container-fluid mb-3">
    <div class="card bg-light-transparent">
       <div class="card-header bg-white">
            <h5>Staff Allocation List (<?php echo $year; ?>)</h5>
       </div>
       <div class="card-body">
            <div class="card no-shadow">
                <div class="card-body">
                    <div class="row">
                        <div class="col mb-3 text-right">
                            <div class="btn-group">
                                <button class="btn btn-outline-dark btn-sm" data-toggle="modal" data-target="#createAllocation" <?php echo (!empty($disable_allocation))?'disabled':''; ?> >Create allocation</button>
                                <button class="btn btn-outline-dark btn-sm" data-toggle="modal" data-target="#staffAllocation" <?php echo (!empty($disable_allocation))?'':'disabled'; ?> >Add Staff allocation</button>
                                <!-- <button class="btn btn-outline-dark btn-sm"><i class="fa fa-print"></i></button> -->
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col table-responsive">
                            <table class="table table-hover">
                                <thead>
                                    <tr>
                                        <th data-trigger="hover" data-tooltip="tooltip" title="" data-original-title="Staff Name">Staff Name</th>
                                        <th data-trigger="hover" data-tooltip="tooltip" title="" data-original-title="Current position">Position</th>
                                        <th data-trigger="hover" data-tooltip="tooltip" title="" data-original-title="Year of service">Year of Service</th>
                                        <th data-trigger="hover" data-tooltip="tooltip" title="" data-original-title="Outpatient Benefits">OP</th>
                                        <th data-trigger="hover" data-tooltip="tooltip" title="" data-original-title="Hospitalization Benefits">HP</th>
                                        <th data-trigger="hover" data-tooltip="tooltip" title="" data-original-title="Room Package">RP</th>
                                        <th data-trigger="hover" data-tooltip="tooltip" title="" data-original-title="Dental / Optical Benefits">D/O</th>
                                        <th>Action</th>
                                    </tr>
                                </thead>
                                <tbody>

                                  <?php if(!empty($allocations))foreach($allocations as $key => $row): ?>
                                    <tr>
                                        <td><?php echo (!empty($row->name))?$row->name:''; ?></td>
                                        <td><?php echo (!empty($row->position))?$row->position:'<span class="text-danger">NULL</span>'?></td>

                                        <td>
                                          <?php 
                                            if(!empty($row->date_joined))
                                            {
                                              if(strtotime($row->date_joined))
                                                {
                                                  if(date('Y') - date('Y',strtotime($row->date_joined)) >= 5)
                                                  {
                                                    echo '<span class="badge badge-success">more than 5 years</span>';
                                                  }else{
                                                    echo '<span class="badge badge-primary">less than 5 years</span>';
                                                  }
                                                }else{
                                                  echo '<span class="badge badge-danger">Invalid date</span>';
                                                }
                                            }else{
                                              echo '<span class="badge badge-danger">Unable to find date joined</span>';
                                            }
                                          ?>
                                        </td>

                                        <!-- off due to 2021 no prorate by Farid 20210304 -->
                                        <!-- <td>
                                          <?php //if(empty($row->prorate)): ?>
                                            <a class="cursor" 
                                              data-trigger="hover" data-tooltip="tooltip" 
                                              title="" data-original-title="View Outpatient Benefits" 
                                              data-toggle="modal" data-target="#outpatientAllocationModal">
                                                <i class="fas fa-times text-danger"></i>
                                            </a>
                                          <?php //else: ?>

                                            <?php
                                              // $is_outpatient_fills = true;
                                              // $not_fills = 0;

                                              // foreach ($row->prorate as $key => $prorate) 
                                              // {
                                              //   if(empty($prorate->outpatient))
                                              //   {
                                              //     $is_outpatient_fills = false;
                                              //     $not_fills++;
                                              //   }
                                              // }

                                              // if(!$is_outpatient_fills){
                                              //   if($not_fills == 12)
                                                // { //none of the months fills
                                            ?>
                                                  <a class="cursor" 
                                                    data-trigger="hover" data-tooltip="tooltip" 
                                                    title="" data-original-title="View Outpatient Benefits" 
                                                    data-toggle="modal" data-target="#outpatientAllocationModal" 
                                                    data-year="<?php //echo $row->year; ?>" 
                                                    data-modal="<?php //echo base64_encode(json_encode($row->prorate)); ?>" 
                                                    onclick="openModalOutpatient(this)" >
                                                      <i class="fas fa-times text-danger"></i>
                                                  </a>
                                            <?php
                                               // }else{
                                            ?>
                                                  <a class="cursor" 
                                                    data-trigger="hover" data-tooltip="tooltip" 
                                                    title="" data-original-title="View Outpatient Benefits" 
                                                    data-toggle="modal" data-target="#outpatientAllocationModal" 
                                                    data-year="<?php //echo $row->year; ?>" 
                                                    data-modal="<?php //echo base64_encode(json_encode($row->prorate)); ?>" 
                                                    onclick="openModalOutpatient(this)">
                                                      <i class="fas fa-hourglass-half text-warning"></i>
                                                  </a>
                                            <?php
                                               // }
                                              //}else{
                                            ?>
                                                  <a class="cursor" 
                                                    data-trigger="hover" data-tooltip="tooltip" 
                                                    title="" data-original-title="View Outpatient Benefits" 
                                                    data-toggle="modal" data-target="#outpatientAllocationModal" 
                                                    data-year="<?php //echo $row->year; ?>" 
                                                    data-modal="<?php //echo base64_encode(json_encode($row->prorate)); ?>" 
                                                    onclick="openModalOutpatient(this)">
                                                      <i class="fas fa-check text-primary"></i>
                                                  </a>
                                            <?php //} ?>
                                          <?php //endif; ?>
                                        </td> -->
                                        
                                        <td>
                                          <?php if(!empty($row->outpatient)): //echo $row->outpatient; ?>
                                            <a class="cursor" 
                                              data-trigger="hover" data-tooltip="tooltip" 
                                              title="" data-original-title="View Outpatient Benefits" 
                                              data-toggle="modal" data-target="#outpatientNoProrateAllocationModal" 
                                              data-year="<?php echo $row->year; ?>" 
                                              data-allocation="<?php echo $row->outpatient; ?>" 
                                              onclick="openModalOutpatientNoProrate(this)" >
                                              <i class="fas fa-check text-primary"></i>
                                            </a>
                                          <?php else: ?>
                                            <a class="cursor" 
                                              data-trigger="hover" data-tooltip="tooltip" 
                                              title="" data-original-title="View Outpatient Benefits" 
                                              data-toggle="modal" data-target="#outpatientNoProrateAllocationModal" 
                                              data-year="<?php echo $row->year; ?>" 
                                              data-allocation="<?php echo $row->outpatient; ?>" 
                                              onclick="openModalOutpatientNoProrate(this)" >
                                                <i class="fas fa-times text-danger"></i>
                                            </a>
                                          <?php endif; ?>
                                        </td>
                                        
                                        <td>
                                          <?php if(!empty($row->hospitalization)): ?>
                                            <a class="cursor" 
                                              data-trigger="hover" data-tooltip="tooltip" 
                                              title="" data-original-title="View Hospitalization Benefits" 
                                              data-toggle="modal" data-target="#hospitalizationAllocationModal" 
                                              data-year="<?php echo $row->year; ?>" 
                                              data-allocation="<?php echo $row->hospitalization; ?>" 
                                              onclick="openModalHospitalization(this)" >
                                                <i class="fas fa-check text-primary"></i>
                                            </a>
                                          <?php else: ?>
                                            <a class="cursor" 
                                              data-trigger="hover" data-tooltip="tooltip" 
                                              title="" data-original-title="View Hospitalization Benefits" 
                                              data-toggle="modal" data-target="#hospitalizationAllocationModal" 
                                              data-year="<?php echo $row->year; ?>" 
                                              data-allocation="<?php echo $row->hospitalization; ?>" 
                                              onclick="openModalHospitalization(this)" >
                                                <i class="fas fa-times text-danger"></i>
                                            </a>
                                          <?php endif; ?>
                                        </td>
                                        <td>
                                          <?php if(!empty($row->room_package)):?>
                                            <a class="cursor" data-trigger="hover" data-tooltip="tooltip" title="" data-original-title="View Room Package" data-toggle="modal" data-target="#roomPackageInformation" data-year="<?php echo $row->year; ?>" data-allocation="<?php echo $row->room_package; ?>" onclick="openModalRoomPackage(this)" ><i class="fas fa-check text-primary"></i></a>
                                          <?php else: ?>
                                            <a class="cursor" 
                                              data-trigger="hover" data-tooltip="tooltip" 
                                              title="" data-original-title="View Room Package" data-toggle="modal" data-target="#roomPackageInformation" data-year="<?php echo $row->year; ?>" data-allocation="<?php echo $row->room_package; ?>" onclick="openModalRoomPackage(this)" ><i class="fas fa-times text-danger"></i></a>
                                          <?php endif; ?>
                                        </td>

                                        <!-- off due to 2021 no prorate by Farid 20210304 -->
                                        <!-- <td>
                                          <?php //if(empty($row->prorate)): ?>
                                            <a class="cursor" 
                                              data-trigger="hover" data-tooltip="tooltip" 
                                              title="" data-original-title="View Dental Optical Benefits" 
                                              data-toggle="modal" data-target="#dentalOpticalAllocationModal" 
                                              data-year="<?php //echo $row->year; ?>" 
                                              data-modal="<?php //echo base64_encode(json_encode($row->prorate)); ?>" 
                                              onclick="openModalDentalOptical(this)" >
                                              <i class="fas fa-times text-danger"></i>
                                            </a>                                                
                                          <?php //else: ?>
                                          <?php
                                            // $is_dental_fills = true;
                                            // $not_fill_dental = 0;
                                            // foreach ($row->prorate as $key => $prorate) 
                                            // {
                                            //   if(empty($prorate->dental_optical))
                                            //   {
                                            //     $is_dental_fills = false;
                                            //     $not_fill_dental++;
                                            //   }
                                            // }
                                          ?>
                                            <?php //if(!$is_dental_fills): ?>
                                              <?php //if($not_fill_dental == 12): ?>
                                                <a class="cursor" 
                                                  data-trigger="hover" data-tooltip="tooltip" 
                                                  title="" data-original-title="View Dental Optical Benefits" 
                                                  data-toggle="modal" data-target="#dentalOpticalAllocationModal" 
                                                  data-year="<?php //echo $row->year; ?>" 
                                                  data-modal="<?php //echo base64_encode(json_encode($row->prorate)); ?>" 
                                                  onclick="openModalDentalOptical(this)" >
                                                  <i class="fas fa-times text-danger"></i>
                                                </a>
                                              <?php //else: ?>
                                                <a class="cursor" 
                                                  data-trigger="hover" data-tooltip="tooltip" 
                                                  title="" data-original-title="View Dental Optical Benefits" 
                                                  data-toggle="modal" data-target="#dentalOpticalAllocationModal" 
                                                  data-year="<?php //echo $row->year; ?>" 
                                                  data-modal="<?php //echo base64_encode(json_encode($row->prorate)); ?>" 
                                                  onclick="openModalDentalOptical(this)" >
                                                    <i class="fas fa-hourglass-half text-warning"></i>
                                                </a>                                            
                                              <?php //endif; ?>
                                            <?php //else: ?>
                                              <a class="cursor" 
                                                data-trigger="hover" data-tooltip="tooltip" 
                                                title="" data-original-title="View Dental Optical Benefits" 
                                                data-toggle="modal" data-target="#dentalOpticalAllocationModal" 
                                                data-year="<?php //echo $row->year; ?>" 
                                                data-modal="<?php //echo base64_encode(json_encode($row->prorate)); ?>" 
                                                onclick="openModalDentalOptical(this)" >
                                                  <i class="fas fa-check text-primary"></i>
                                              </a>
                                            <?php //endif;?>
                                          <?php //endif; ?>
                                        </td> -->
                                        
                                        <td>
                                          <?php if(!empty($row->dental_optical)): //echo $row->dental_optical; ?>
                                            <a class="cursor" 
                                              data-trigger="hover" data-tooltip="tooltip" 
                                              title="" data-original-title="View Dental / Optical Benefits" 
                                              data-toggle="modal" data-target="#dentalOpticalNoProrateAllocationModal" 
                                              data-year="<?php echo $row->year; ?>" 
                                              data-allocation="<?php echo $row->dental_optical; ?>" 
                                              onclick="openModalDentalOpticalNoProrate(this)" >
                                              <i class="fas fa-check text-primary"></i>
                                            </a>
                                          <?php else: ?>
                                            <a class="cursor" 
                                              data-trigger="hover" data-tooltip="tooltip" 
                                              title="" data-original-title="View Dental / Optical Benefits" 
                                              data-toggle="modal" data-target="#dentalOpticalNoProrateAllocationModal" 
                                              data-year="<?php echo $row->year; ?>" 
                                              data-allocation="<?php echo $row->dental_optical; ?>" 
                                              onclick="openModalDentalOpticalNoProrate(this)" >
                                                <i class="fas fa-times text-danger"></i>
                                            </a>
                                          <?php endif; ?>
                                        </td>
                                        
                                        <td>
                                          <div class="btn-group">
                                            <button class="btn btn-warning btn-sm text-white" data-toggle="modal" data-target="#change_staffAllocation" data-modal="<?php echo base64_encode(json_encode($row)); ?>" onclick="editStaffAllocation(this)" ><i class="fa fa-edit"></i></button>
                                            <button class="btn btn-danger btn-sm" data-modal="<?php echo base64_encode(json_encode($row)); ?>" onclick="removeAllocation(this)"><i class="fa fa-trash"></i></button>
                                          </div>
                                        </td>
                                    </tr>
                                  <?php endforeach; ?>

                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
       </div>
    </div>
</div>

<!-- outpatient prorate table -->
<div class="modal fade" id="outpatientAllocationModal" 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">Outpatient Prorate Table </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="row">
            <div class="col">
                <table class="table table-bordered table-hover" id="tbl-outpatient">
                    <thead>
                        <tr>
                            <th>Year</th>
                            <th>Month</th>
                            <th>Amount (RM)</th>
                            <th>Balanced (RM)</th>
                        </tr>
                    </thead>
                    <tbody>

                        <tr>
                            <td>2019</td>
                            <td>January</td>
                            <td>41.67</td>
                            <td>41.67</td>
                        </tr>
                        
                    </tbody>
                </table>
            </div>
        </div>
      </div>
    </div>
  </div>
</div>

<!-- outpatient no prorate table -->
<div class="modal fade" id="outpatientNoProrateAllocationModal" 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">Outpatient 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="row">
          <div class="col">
            <h4>Allocation Amount <b>RM<span id="outpatient_allocation">0.00</span></b> (<span id="outpatient_year">2010</span>)</h4>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

<!-- Hospitalization prorate table -->
<div class="modal fade" id="hospitalizationAllocationModal" 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">Hospitalization 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="row">
          <div class="col">
            <h4>Allocation Amount <b>RM<span id="hospitalization_allocation">0.00</span></b> (<span id="hospitalization_year">2010</span>)</h4>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

<!-- room package information -->
<div class="modal fade" id="roomPackageInformation" 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">Room Package 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="row">
            <div class="col">
                <h4>Allocation Amount <b>RM<span id="room_package_allocation">0.00</span></b> (<span id="room_package_year">2010</span>)</h4>
            </div>
        </div>
      </div>
    </div>
  </div>
</div>

<!-- dental and optical prorate table -->
<div class="modal fade" id="dentalOpticalAllocationModal" 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">Dental / Optical 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="row">
            <div class="col">
                <table class="table table-bordered table-hover" id="tbl_dental_optical">
                    <thead>
                        <tr>
                            <th>Year</th>
                            <th>Month</th>
                            <th>Amount (RM)</th>
                            <th>Balanced (RM)</th>
                        </tr>
                    </thead>
                    <tbody>
                    </tbody>
                </table>
            </div>
        </div>
      </div>
    </div>
  </div>
</div>

<!-- dental and optical no prorate table -->
<div class="modal fade" id="dentalOpticalNoProrateAllocationModal" 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">Dental / Optical 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="row">
          <div class="col">
            <h4>Allocation Amount <b>RM<span id="dental_optical_allocation">0.00</span></b> (<span id="dental_optical_year">2010</span>)</h4>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

<!-- create all allocation -->
<div class="modal fade" id="createAllocation" 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">Create Allocation</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <form action="<?php echo base_url('hr/Claim/createAllocation'); ?>" method="post">
        <div class="modal-body">
            <div class="row">
                <div class="col">
                    <p>
                        <input type="checkbox" name="all_staff" checked/> Create allocation for all staff 
                        <br>
                        <input type="checkbox" name="schedule" /> Schedule allocation for every 1st of January
                    </p>
                </div>
            </div>
        </div>
        <div class="modal-footer">
            <button type="submit" class="btn btn-primary">Save changes</button>
        </div>
      </form>
    </div>
  </div>
</div>

<!-- create allocation for certain people -->
<div class="modal fade" id="staffAllocation" 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">Create Staff Allocation</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>

        <form action="<?php echo base_url('hr/claim/createStaffAllocation'); ?>" method="post">
          <div class="modal-body">
            <div class="row mb-3">
                <div class="col-4">
                    Name
                </div>
                <div class="col">
                    <select name="name" class="form-control form-control-sm select" required>
                      <?php if(!empty($users)) foreach($users as $key => $row): ?>
                          <option value="<?php echo $row['id']; ?>"><?php echo $row['name']; ?></option>
                      <?php endforeach; ?>
                    </select>
                </div>
            </div>

            <div class="row mb-3">
                <div class="col-4">
                    Outpatient Benefits
                </div>
                <div class="col">
                    <select name="outpatient" class="form-control form-control-sm">
                      <?php if(!empty($allocation_types)) foreach($allocation_types as $key => $row): ?>
                        <?php if($row->claim_type_id == 1): ?>
                          <option value="<?php echo $row->id; ?>"><?php echo $row->description; ?></option>
                        <?php endif; ?>
                      <?php endforeach; ?>
                    </select>
                </div>
            </div>

            <div class="row mb-3">
                <div class="col-4">
                    Hospitalization Benefits
                </div>
                <div class="col">
                    <select name="hospitalization" class="form-control form-control-sm">
                      <?php if(!empty($allocation_types)) foreach($allocation_types as $key => $row): ?>
                        <?php if($row->claim_type_id == 2): ?>
                          <option value="<?php echo $row->id; ?>"><?php echo $row->description; ?></option>
                        <?php endif; ?>
                      <?php endforeach; ?>
                    </select>
                </div>
            </div>

            <div class="row mb-3">
                <div class="col-4">
                    Room Package
                </div>
                <div class="col">
                    <select name="room_package" class="form-control form-control-sm">
                      <?php if(!empty($allocation_types)) foreach($allocation_types as $key => $row): ?>
                        <?php if($row->claim_type_id == 3): ?>
                          <option value="<?php echo $row->id; ?>"><?php echo $row->description; ?></option>
                        <?php endif; ?>
                      <?php endforeach; ?>
                    </select>
                </div>
            </div>
            
            <div class="row mb-3">
                <div class="col-4">
                    Dental / Optical
                </div>
                <div class="col">
                    <select name="dental_optical" class="form-control form-control-sm">
                      <?php if(!empty($allocation_types)) foreach($allocation_types as $key => $row): ?>
                        <?php if($row->claim_type_id == 4): ?>
                          <option value="<?php echo $row->id; ?>"><?php echo $row->description; ?></option>
                        <?php endif; ?>
                      <?php endforeach; ?>
                    </select>
                </div>
            </div>

            <div class="row mb-3">
                <div class="col">
                    Start Month
                </div>
                <div class="col">
                    <input type="text" class="form-control form-control-sm datepicker-mm" name="start_month" required>
                </div>
                <div class="col">
                    End Month
                </div>
                <div class="col">
                    <input type="text" class="form-control form-control-sm datepicker-mm" name="end_month" required>
                </div>
            </div>

          </div>
          <div class="modal-footer">
            <button type="submit" class="btn btn-primary">Save changes</button>
          </div>
        </form>

    </div>
  </div>
</div>

<!-- edit allocation for certain people -->
<div class="modal fade" id="change_staffAllocation" tabindex="-1" role="dialog" aria-hidden="true">
  <div class="modal-dialog modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">Change Staff Allocation</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      
      <form action="<?php echo base_url('hr/claim/updateStaffAllocation'); ?>" method="post">
        <div class="modal-body">
          <div class="row mb-3">
              <div class="col-4">
                  Name
              </div>
              <div class="col">
                  <input type="text" class="form-control form-control-sm" disabled id="edit_allocation_name" name="name">
                  <input type="hidden" class="form-control form-control-sm" name="user_id" id="edit_user_id">
                  <input type="hidden" class="form-control form-control-sm" name="allocation_id" id="edit_allocation_id">
              </div>
          </div>

          <div class="row mb-3">
              <div class="col-4">
                  Outpatient Benefits
              </div>
              <div class="col">
                  <select name="outpatient" class="form-control form-control-sm">
                    <?php if(!empty($allocation_types)) foreach($allocation_types as $key => $row): ?>
                      <?php if($row->claim_type_id == 1): ?>
                        <option value="<?php echo $row->id; ?>"><?php echo $row->description; ?></option>
                      <?php endif; ?>
                    <?php endforeach; ?>
                  </select>
              </div>
          </div>

          <div class="row mb-3">
              <div class="col-4">
                  Hospitalization Benefits
              </div>
              <div class="col">
                  <select name="hospitalization" class="form-control form-control-sm">
                    <?php if(!empty($allocation_types)) foreach($allocation_types as $key => $row): ?>
                      <?php if($row->claim_type_id == 2): ?>
                        <option value="<?php echo $row->id; ?>"><?php echo $row->description; ?></option>
                      <?php endif; ?>
                    <?php endforeach; ?>
                  </select>
              </div>
          </div>

          <div class="row mb-3">
              <div class="col-4">
                  Room Package
              </div>
              <div class="col">
                  <select name="room_package" class="form-control form-control-sm">
                    <?php if(!empty($allocation_types)) foreach($allocation_types as $key => $row): ?>
                      <?php if($row->claim_type_id == 3): ?>
                        <option value="<?php echo $row->id; ?>"><?php echo $row->description; ?></option>
                      <?php endif; ?>
                    <?php endforeach; ?>
                  </select>
              </div>
          </div>
          
          <div class="row mb-3">
            <div class="col-4">
                Dental / Optical
            </div>
            <div class="col">
                <select name="dental_optical" class="form-control form-control-sm">
                  <?php if(!empty($allocation_types)) foreach($allocation_types as $key => $row): ?>
                    <?php if($row->claim_type_id == 4): ?>
                      <option value="<?php echo $row->id; ?>"><?php echo $row->description; ?></option>
                    <?php endif; ?>
                  <?php endforeach; ?>
                </select>
            </div>
          </div>

          <div class="row mb-3">
              <div class="col">
                  Start Month
              </div>
              <div class="col">
                  <input type="text" class="form-control form-control-sm datepicker-mm" name="start_date" required>
              </div>
              <div class="col">
                  End Month
              </div>
              <div class="col">
                  <input type="text" class="form-control form-control-sm datepicker-mm" name="end_date" required>
              </div>
          </div>

        </div>
        <div class="modal-footer">
          <button type="submit" class="btn btn-primary">Save changes</button>
        </div>
      </form>
    </div>
  </div>
</div>

<?php $this->load->view('hr/claim/page/admin/staff-allocation-special-claim'); ?>

<script>

$(document).ready(function(){
  
});

function openModalOutpatient(elem)
{
  let year = $(elem).data('year');
  let json = JSON.parse(atob($(elem).data('modal')));
  console.log(json);
  /**
   * destroy table outpatient and create a new one 
   */
  var table = $('#tbl-outpatient').DataTable();
  table.clear().page.len(50).draw();
  

  $.each(json,function(index,value){
    let outpatient = Math.floor(value.outpatient * 100)/100;
    let outpatient_balanced = Math.floor(value.outpatient_balanced * 100)/100;
    table.row.add({
        0 : year,
        1 : value.month,
        2 : accounting.formatMoney(outpatient,'RM'),
        3 : accounting.formatMoney(outpatient_balanced,'RM'), 
    }).draw();
  });
}

function openModalOutpatientNoProrate(elem)
{

    let year = $(elem).data('year'); 
    $('#outpatient_year').text(year);

    let allocation = $(elem).data('allocation');
    let allocation_value = Math.floor(allocation * 100)/100;

    $('#outpatient_allocation').text(accounting.formatMoney(allocation_value,''));

}

function openModalHospitalization(elem)
{
    let year = $(elem).data('year'); 
    $('#hospitalization_year').text(year);

    let allocation = $(elem).data('allocation');
    let allocation_value = Math.floor(allocation * 100)/100;

    $('#hospitalization_allocation').text(accounting.formatMoney(allocation_value,''));

}

function openModalRoomPackage(elem) 
{  
    let year = $(elem).data('year');
    $('#room_package_year').text(year);

    let allocation = $(elem).data('allocation');
    let allocation_value = Math.floor(allocation * 100)/100;

    $('#room_package_allocation').text(accounting.formatMoney(allocation_value,''));
}

function openModalDentalOptical(elem) 
{
  let year = $(elem).data('year');
  let json = JSON.parse(atob($(elem).data('modal')));
  console.log(json);
  /**
   * destroy table outpatient and create a new one 
   */
  var table = $('#tbl_dental_optical').DataTable();
  table.clear().page.len(50).draw();

  $.each(json,function(index,value){
    let dental_optical = Math.floor(value.dental_optical * 100)/100;
    let dental_balanced = Math.floor(value.dental_balanced * 100)/100; 
    table.row.add({
        0 : year,
        1 : value.month,
        2 : accounting.formatMoney(dental_optical,'RM'),
        3 : accounting.formatMoney(dental_balanced,'RM'), 
    }).draw();
  })
}

function openModalDentalOpticalNoProrate(elem)
{

    let year = $(elem).data('year'); 
    $('#dental_optical_year').text(year);

    let allocation = $(elem).data('allocation');
    let allocation_value = Math.floor(allocation * 100)/100;

    $('#dental_optical_allocation').text(accounting.formatMoney(allocation_value,''));

}

function editStaffAllocation(elem) 
{
  let json = JSON.parse(atob($(elem).data('modal')));
  $('#edit_allocation_name').val(json.name);
  $('#edit_user_id').val(json.user_id);
  $('#edit_allocation_id').val(json.id);
}

function removeAllocation(elem) 
{
  let json = JSON.parse(atob($(elem).data('modal')));
  
  iziToast.question({
    timeout: 20000,
    close: false,
    overlay: true,
    displayMode: 'once',
    id: 'question',
    zindex: 999,
    title: 'Hey',
    message: 'Are you sure you want to remove allocation for '+json.name+'?',
    position: 'center',
    buttons: [
        ['<button><b>YES</b></button>', function (instance, toast) {
          ajxRemoveAllocation(json.id);
        }, true],
        ['<button>NO</button>', function (instance, toast) {
          instance.hide(toast, {
						transitionOut: 'fadeOutUp'
					});
        }],
    ]
});
}

function ajxRemoveAllocation(id) 
{
  let url       = '<?php echo base_url('hr/api/claim/removeAllocation'); ?>';
  let type      = 'POST';
  let data      = {
      token:'<?php echo $token; ?>',
      allocation_id: id,
  };
  let redirect  = '<?php echo current_url(); ?>';

  ajxRequest(url, type, data, redirect);  
}
</script>

<!-- not everything that counts can be counted 
and not everything thats counted truly counts -->