<div class="container-fluid mt-5 mb-5">
    <div class="card bg-light-transparent">  
        <div class="card-header bg-white">
            <h5>Admin OT Submission Lists for <?php echo date("F Y",mktime(0,0,0, $rsOt['month'],1,$rsOt['year'])) ?>  </h5>
            <a onclick="printOTClaim()" target="_blank" class="btn btn-outline-dark btn-sm" title="Print OT Claim"><i class="fa fa-print"></i> Print</a><br>
        </div>
        <div class="tab-content">
            <div class="tab-pane fade active show" id="tableView" role="tabpanel" aria-labelledby="nav-table-tab">
                <div class="card-body">
                    <div class="card text-white bg-dark">
                        <div class="card-body">
                            <div class="row">
                                <div class="col-12 col-md-6">
                                    <div class="row">
                                        <label class="col-12 control-label" for="name" align="left">Name :</label>
                                        <div class="col-12">
                                            <input type="text" name="name" id="name" class="form-control" value="<?php echo $name ?>" readonly/>
                                            <input type="hidden" name="peopleID" id="peopleID" value="<?php echo $id ?>" data-year="<?php echo $rsOt['year'] ?>">
                                        </div>
                                    </div>
                                    <div class="row">
                                        <label class="col-6 control-label" for="dept_name" >IC No:</label>
                                        <label class="col-6 control-label" for="dept_name" >Employee ID:</label>
                                        <div class="col-6">
                                            <input type="text" name="dept_name" id="dept_name" class="form-control" value="<?php echo $ic_no ?>" readonly/>
                                        </div>
                                        <div class="col-6">
                                            <input type="text" name="dept_name" id="dept_name" class="form-control" value="<?php echo $staff_id ?>" readonly/>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-12 col-md-6">
                                    <div class="row">
                                        <label class="col-12 control-label" for="name" align="left">Department :</label>
                                        <div class="col-12">
                                            <input type="text" name="name" id="name" class="form-control" value="<?php echo $department_name ?>" readonly/>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <label class="col-12 control-label" for="dept_name" >Designation:</label>
                                        <div class="col-12">
                                            <input type="text" name="dept_name" id="dept_name" class="form-control" value="<?php echo $position_name ?>" readonly/>
                                        </div>
                                    </div>
                                </div>
                            </div>  
                        </div>
                    </div>

                    <div class="card no-shadow">
                        <div class="card-body">
                            <div class="table-responsive">
                                <table class="table table-hover table-bordered p-0 m-0" id="admin_list" style="width: 100%;">
                                    <thead>
                                        <th class="sorting" tabindex="0" aria-controls="table_contact" rowspan="1" colspan="1" aria-label="#: activate to sort column ascending" style="width: 0px;">
                                            #
                                        </th>
                                        <th class="sorting" tabindex="0" aria-controls="table_contact" rowspan="1" colspan="1" aria-label="Company Code/ Cost Centre: activate to sort column ascending" style="width: 0px;">
                                            Date
                                        </th>
                                        <th class="sorting" tabindex="0" aria-controls="table_contact" rowspan="1" colspan="1" aria-label="Salary/ Wage Month: activate to sort column ascending" style="width: 0px;">
                                            Client
                                        </th>
                                        <th class="sorting" tabindex="0" aria-controls="table_contact" rowspan="1" colspan="1" aria-label="Employee Total Upload: activate to sort column ascending" style="width: 0px;">
                                            Task
                                        </th>
                                        <th class="sorting" tabindex="0" aria-controls="table_contact" rowspan="1" colspan="1" aria-label="Employee Total Upload: activate to sort column ascending" style="width: 0px;">
                                            Start Time
                                        </th>
                                        <th class="sorting" tabindex="0" aria-controls="table_contact" rowspan="1" colspan="1" aria-label="Employee Total Upload: activate to sort column ascending" style="width: 0px;">
                                            End Time
                                        </th>
                                        <th class="sorting" tabindex="0" aria-controls="table_contact" rowspan="1" colspan="1" aria-label="Employee Total Upload: activate to sort column ascending" style="width: 0px;">
                                            Break (minutes)
                                        </th>
                                        <th class="sorting" tabindex="0" aria-controls="table_contact" rowspan="1" colspan="1" aria-label="Employee Total Upload: activate to sort column ascending" style="width: 0px;">
                                            Total Hours Applied
                                        </th>
                                        <th class="sorting" tabindex="0" aria-controls="table_contact" rowspan="1" colspan="1" aria-label="Employee Total Upload: activate to sort column ascending" style="width: 0px;">
                                            Day Type
                                        </th>
                                        <th class="sorting" tabindex="0" aria-controls="table_contact" rowspan="1" colspan="1" aria-label="Employee Total Upload: activate to sort column ascending" style="width: 0px;">
                                            Supervisor
                                        </th>
                                        <th class="sorting" tabindex="0" aria-controls="table_contact" rowspan="1" colspan="1" aria-label="Employee Total Upload: activate to sort column ascending" style="width: 0px;">
                                            Status/ Action
                                        </th>         
                                    </thead>      
                                    <tbody>
                                      
                                        <?php if (!empty($otLists)): 
                                            $totHoursApplied =0;
                                            $normalDay =0; 
                                            $restDay =0; 
                                            $publicHoliday =0; ?>
                                            <?php if(!empty($otLists)) foreach ($otLists as $key => $ot): ?>
                                                
                                            <tr>
                                                <td><?php echo $key+1;?></td>
                                                <td><?php echo date('d/m/Y',strtotime($ot['otDate'])) ?></td>
                                                <td><?php if($ot['clientID'] > 0 ){ echo $ot['clientName']; }else{ echo 'Others';};?></td>
                                                <td><?php echo $ot['task'];?></td>
                                                <td><?php echo date("g:i a", strtotime($ot['startTime'])) ?></td>
                                                <td><?php echo date("g:i a", strtotime($ot['endTime'])) ?></td>  
                                                <td><?php echo $ot['refreshment'] ?></td>  
                                                <td><?php echo $ot['totalHoursApplied'] ?></td>                     
                                                <td>
                                                    <?php 
                                                    if($ot['dayType'] == 1){
                                                        echo 'Normal Day';
                                                    }else if($ot['dayType'] == 2){
                                                        echo 'Rest Day';
                                                    }else if($ot['dayType'] == 3){
                                                        echo 'Public Holiday';
                                                    }else if($ot['dayType'] == 4){
                                                        echo 'Weekend';
                                                    }else if($ot['dayType'] == 5){
                                                        echo 'Weekdays';
                                                    }
                                                 ?>
                                                </td>
                                                <td><?php echo $ot['svName'];?> <br><small><b> - <?php echo $ot['svDeptName'];?></b></small></td>
                                                <td otDetailID="<?php echo $ot['ID']; ?>">
                                                    <?php if($ot['claim_status'] == 2){?>
                                                        <?php if($ot['status'] == 0){
                                                                echo '<button class="btn btn-sm btn-warning btn-block text-white" data-tooltip="tooltip" data-placement="bottom" data-trigger="hover" data-original-title="Change status"  data-toggle="modal" data-target="" data-json="'.base64_encode(json_encode($ot)).'" onclick="changeStatus('.$ot['ID'].')" disabled>Pending</button>';
                                                                echo '<small><i><b>*Remarks : </b>' . $ot['remarks'] .'</i></small>';
                                                            }else if($ot['status'] == 1){
                                                                echo '<button class="btn btn-sm btn-success btn-block text-white" data-toggle="modal" data-target="" data-json="'.base64_encode(json_encode($ot)).'" onclick="changeStatus('.$ot['ID'].')" disabled>Approved</button><br>';
                                                                echo '<small><i><b>*Remarks : </b>' . $ot['remarks'] .'</i></small><br>';
                                                                echo '<small><i><b>*Approved by : </b>' . $ot['status_by_name'] .'</i></small>';
                                                            }else if($ot['status'] == 2){
                                                                echo '<button class="btn btn-sm btn-danger btn-block text-white"  data-toggle="modal" data-target="" data-json="'.base64_encode(json_encode($ot)).'" onclick="changeStatus('.$ot['ID'].')" disabled>Rejected</button>';
                                                                echo '<small><i><b>*Remarks : </b>' . $ot['remarks'] .'</i></small><br>';
                                                                echo '<small><i><b>*Rejected by : </b>' . $ot['status_by_name'] .'</i></small>';
                                                            }else{
                                                                echo '<button class="btn btn-sm btn-secondary btn-block text-white"  data-toggle="modal" data-target="" data-json="'.base64_encode(json_encode($ot)).'" onclick="changeStatus('.$ot['ID'].')" disabled>Draft</button>';
                                                            }
                                                        ?>
                                                    <?php } else{ ?>
                                                        <?php if($ot['status'] == 0){
                                                                echo '<button class="btn btn-sm btn-warning btn-block text-white" data-tooltip="tooltip" data-placement="bottom" data-trigger="hover" data-original-title="Change status"  data-toggle="modal" data-target="" data-json="'.base64_encode(json_encode($ot)).'" onclick="changeStatus('.$ot['ID'].')">Pending</button>';
                                                                echo '<small><i><b>*Remarks : </b>' . $ot['remarks'] .'</i></small>';
                                                            }else if($ot['status'] == 1){
                                                                echo '<button class="btn btn-sm btn-success btn-block text-white" data-toggle="modal" data-target="" data-json="'.base64_encode(json_encode($ot)).'" onclick="changeStatus('.$ot['ID'].')">Approved</button>';
                                                                echo '<small><i><b>*Remarks : </b>' . $ot['remarks'] .'</i></small><br>';
                                                                echo '<small><i><b>*Approved by : </b>' . $ot['status_by_name'] .'</i></small>';
                                                            }else if($ot['status'] == 2){
                                                                echo '<button class="btn btn-sm btn-danger btn-block text-white"  data-toggle="modal" data-target="" data-json="'.base64_encode(json_encode($ot)).'" onclick="changeStatus('.$ot['ID'].')">Rejected</button>';
                                                                echo '<small><i><b>*Remarks : </b>' . $ot['remarks'] .'</i></small><br>';
                                                                echo '<small><i><b>*Rejected by : </b>' . $ot['status_by_name'] .'</i></small>';
                                                            }else{
                                                                echo '<button class="btn btn-sm btn-secondary btn-block text-white"  data-toggle="modal" data-target="" data-json="'.base64_encode(json_encode($ot)).'" onclick="changeStatus('.$ot['ID'].')">Draft</button>';
                                                            }
                                                        ?>
                                                    <?php } ?>
                                                </td>                                                  
                                            </tr> 
                                            <?php if($ot['totalHoursApplied']){
                                                $totHoursApplied =  $totHoursApplied + $ot['totalHoursApplied'];
                                            } 
                                                if($ot['dayType']){
                                                    if($ot['dayType'] == 1){
                                                        $normalDay++;
                                                    }else if($ot['dayType'] == 2){
                                                        $restDay++;
                                                    }else if($ot['dayType'] == 3){
                                                        $publicHoliday++;
                                                    }
                                                }
                                            ?>
                                            
                                            <?php endforeach ?>
                                        <?php endif ?>
                                    </tbody> 
                                </table>
                            </div><br>
                        </div>
                    </div>
                </div>

                <div class="card no-shadow">

                    <div class="card-body">

                        <table class="table-bordered" width="100%">
                            <h5>Claim Summary By Job for <?php echo date("F Y",mktime(0,0,0, $rsOt['month'],1,$rsOt['year'])) ?>
                            <thead>
                                <th colspan="2" class="text-center bg-light py-3">Department</th>
                                <th colspan="2" class="text-center bg-light">Details</th>
                            </thead>
                            <tbody>
                                <?php $sum = 0; ?>
                                <?php if(!empty($OTSummaryByDept)) foreach($OTSummaryByDept as $row): ?>
                                    <tr>
                                        <?php if($row['svDeptID'] !=0){ ?>
                                            <td colspan="2" class="text-center"><?php echo $row['dept']; ?></td>
                                        <?php } else { ?>
                                            <td colspan="2" class="text-center"><?php echo $department_name; ?></td>
                                        <?php }?>
                                        <td class="text-left">
                                            &nbsp;OT Applied (Hours)<br>
                                            &nbsp;OT Approved (Hours)<br> 
                                            &nbsp;OT Claim<br><hr> 
                                            <?php if($row['svDeptID'] !=0){ ?>
                                                &nbsp;<b>Total for <?php echo $row['dept']; ?></b>
                                            <?php } else { ?>
                                                &nbsp;<b>Total for <?php echo $department_name; ?></b>
                                            <?php }?>
                                            
                                        </td>
                                        <td colspan="2" class="text-center">
                                            
                                            <?php 
                                                if(!empty($row['totalHoursApproved'])){ $row['totalHoursApproved'] = $row['totalHoursApproved']; } else { $row['totalHoursApproved'] = 0; };

                                                $totalClaim = $row['totalHoursApproved']*7;

                                                $totalDept = $totalClaim;

                                                $sum+=$totalDept;

                                            ?>

                                            <?php echo $row['totalHoursApplied']; ?><br>
                                            <?php echo $row['totalHoursApproved']; ?><br>
                                            RM<?php echo number_format((float)$totalClaim, 2, '.', ''); ?><br><hr>
                                            <b>RM<?php echo number_format((float)$totalDept, 2, '.', ''); ?></b>
                                        </td>
                                    </tr>
                                <?php endforeach ?>
                            </tbody>
                            <tfoot>
                                <td colspan="3" class="text-right bg-light py-3"><b>Total Claim All : </b></td>
                                <td colspan="2" class="text-center bg-light"><b>RM<?php echo number_format((float)$sum, 2, '.', ''); ?></b></td>
                            </tfoot>
                        </table><br><br>

                        <table class="table-bordered" width="100%">
                            <h5>Claim Summary for <?php echo date("F Y",mktime(0,0,0, $rsOt['month'],1,$rsOt['year'])) ?>
                            <a onclick="printOTClaimSummary()" target="_blank" class="btn btn-outline-dark btn-sm" title="Print OT Claim"><i class="fa fa-print"></i> Print</a><br></h5>
                            <h5 class="text-right"><span class="text-danger">* </span><small>CO = Conversion Leave </small></h5>
                            <thead>
                                <th class="bg-light"></th>
                                <th colspan="2" class="text-center bg-light py-3">OT Applied (Hours)</th>
                                <th colspan="2" class="text-center bg-light py-3">OT Approved (Hours)</th>
                            </thead>
                            <tbody>
                                <tr>
                                    <td class="text-center py-3">Total OT</td>
                                    <td colspan="2" class="text-center"><input type="hidden" value="<?php echo $ot['totalHoursAppliedTotal']; ?>" id="totalOT" data-otID="<?php echo $ot['otID']; ?>"><?php echo $ot['totalHoursAppliedTotal']; ?></td>
                                    <td colspan="2" class="text-center"><input type="hidden" value="<?php echo $ot['totalHoursApproved']; ?>" id="totalApprovedOT"><?php echo $ot['totalHoursApproved']; ?></td>
                                </tr>
                                <tr>
                                    <td class="bg-light py-2"><b></b></td>
                                    <td class="text-center bg-light py-3"><b>Total Hours Approved</b></td>
                                    <td class="text-center bg-light"><b>Calculation</b></td>
                                    <td class="text-center bg-light" colspan="2"><b>Total</b></td>
                                </tr>
                            </tbody>
                            <tfoot>
                                <?php 
                                    if(!empty($ot['otID'])){ $ot['otID']             = $ot['otID']; } else { $ot['otID'] = 0; };
                                    if(!empty($ot['NormalMeal'])){ $ot['NormalMeal'] = $ot['NormalMeal']; } else { $ot['NormalMeal'] = 0; };
                                    if(!empty($ot['RestMeal'])){ $ot['RestMeal']     = $ot['RestMeal']; } else { $ot['RestMeal'] = 0; };
                                    if(!empty($ot['PublicMeal'])){ $ot['PublicMeal'] = $ot['PublicMeal']; } else { $ot['PublicMeal'] = 0; };

                                    if(!empty($ot['normal'])){ $ot['normal']     = $ot['normal']; } else { $ot['normal'] = 0; };
                                    if(!empty($ot['rest'])){ $ot['rest']         = $ot['rest']; } else { $ot['rest'] = 0; };
                                    if(!empty($ot['public'])){ $ot['public']     = $ot['public']; } else { $ot['public'] = 0; };
                                    if(!empty($ot['weekend'])){ $ot['weekend']   = $ot['weekend']; } else { $ot['weekend'] = 0; };
                                    if(!empty($ot['weekdays'])){ $ot['weekdays'] = $ot['weekdays']; } else { $ot['weekdays'] = 0; };
                                    if(!empty($ot['totalHoursAppliedTotal'])){ $ot['totalHoursAppliedTotal'] = $ot['totalHoursAppliedTotal']; } else { $ot['totalHoursAppliedTotal'] = 0; };
                                    if(!empty($ot['totalHoursApproved'])){ $ot['totalHoursApproved'] = $ot['totalHoursApproved']; } else { $ot['totalHoursApproved'] = 0; };
                                    if(!empty($ot['claim_status'])){ $ot['claim_status'] = $ot['claim_status']; } else { $ot['claim_status'] = 0; };
                        
                                    $weekendTotal2   = $ot['weekend']*7;
                                    $weekdaysTotal2  = $ot['weekdays']*7;
                                    $total2          = $weekendTotal2+$weekdaysTotal2; 

                                    $convertALHour      = intval($ot['totalHoursApproved']/8)*8;
                                    $convertALHourValue = $convertALHour*7;

                                    $total2Final        = $total2-$convertALHourValue;

                                ?>
                                <tr>
                                    <td class="text-center"> 
                                        Weekend 
                                    </td>
                                    <td class="text-center"><?php if($ot['weekend']){ echo $ot['weekend']; }else{ echo "0"; } ?></td>
                                    <td class="text-center"><?php echo $ot['weekend'].' x RM7 '; ?><br><small>(Actual Overtime x RM7.00)</small></td>
                                    <td class="text-center" colspan="2"><b>RM<?php echo number_format((float)$weekendTotal2, 2, '.', ''); ?></b></td>
                                </tr>
                                <tr>
                                    <td class="text-center"> 
                                        Weekdays
                                    </td>
                                    <td class="text-center"><?php if($ot['weekdays']){ echo $ot['weekdays']; }else{ echo "0"; } ?></td>
                                    <td class="text-center"><?php echo $ot['weekdays'].' x RM7 '; ?><br><small>(Actual Overtime x RM7.00 )</small></td>
                                    <td class="text-center" colspan="2"><b>RM<?php echo number_format((float)$weekdaysTotal2, 2, '.', ''); ?></b></td>
                                </tr>
                                <tr>
                                    <td colspan="3" class="text-right bg-light py-3"><b>Total Claim :</b></td>
                                    <td class="text-center bg-light" colspan="3"><input type="hidden" name="total2" id="total2" value="<?php echo number_format((float)$total2, 2, '.', ''); ?>"><b>RM<?php echo number_format((float)$total2, 2, '.', ''); ?></b></td>
                                </tr>

                                <?php if($basicSalary->basic_pay > 2000){ ?>
                                    <?php if($ot['claim_status'] == 2){ // verified ?> 
                                        <tr>
                                            <td class="text-center"><span class="text-danger">* </span>Convert to CO<br><small>(Completion of 8 hours)</small></td>
                                            <td colspan="3"><input type="text" value="<?php echo $ot['totalConvertToLeave']; ?>" id="totalConvertAL" class="form-control text-center" onchange="calculateALValue()" disabled></td>
                                            <td class="text-center"><input type="hidden" class="form-control text-center" name="ALValue" id="ALValue" value="<?php echo number_format((float)$ot['totalConvertToLeave']*10, 2, '.', ''); ?>"><b id="total2echo"><?php echo "(RM". number_format((float)$ot['totalConvertToLeave']*10, 2, '.', '').")" ?></b>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td colspan="4" class="text-right bg-light py-3"><b>Final Total Claim :</b></td>
                                            <td class="text-center bg-light"><input type="hidden" class="form-control text-center" name="total2Final" id="total2Final" value="<?php echo number_format((float)$ot['totalClaim'], 2, '.', ''); ?>"><b id="ALValueEcho"><?php echo "RM".number_format((float)$total2-$ot['totalConvertToLeave']*10, 2, '.', '').""; ?></b></td>
                                        </tr>
                                    <?php } else { ?>
                                        <?php if($ot['totalHoursApproved'] >= 8){ ?> 
                                            <tr>
                                                <td class="text-center"><span class="text-danger">* </span>Convert to CO<br><small>(Completion of 8 hours)</small></td>
                                                <td colspan="3"><input type="text" value="<?php echo $ot['totalConvertToLeave']; ?>" id="totalConvertAL" class="form-control text-center" onchange="calculateALValue()"></td>
                                                <td class="text-center"><input type="hidden" class="form-control text-center" name="ALValue" id="ALValue" value="<?php echo number_format((float)$ot['totalConvertToLeave']*10, 2, '.', ''); ?>"><b id="total2echo"><?php echo "(RM". number_format((float)$ot['totalConvertToLeave']*10, 2, '.', '').")" ?></b>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td colspan="4" class="text-right bg-light py-3"><b>Final Total Claim :</b></td>
                                                <td class="text-center bg-light"><input type="hidden" class="form-control text-center" name="total2Final" id="total2Final" value="<?php echo number_format((float)$ot['totalClaim'], 2, '.', ''); ?>"><b id="ALValueEcho"><?php echo "RM".number_format((float)$total2-$ot['totalConvertToLeave']*10, 2, '.', '').""; ?></b></td>
                                            </tr>
                                        <?php } else { ?>
                                            <tr>
                                                <td class="text-center"><span class="text-danger">* </span>Convert to AL<br><small>(Completion of 8 hours)</small></td>
                                                <td colspan="3"><input type="text" value="0" id="totalConvertAL" class="form-control text-center" disabled></td>
                                                <td class="text-center"><input type="hidden" class="form-control text-center" name="ALValue" id="ALValue" value="<?php echo number_format((float)$convertALHourValue, 2, '.', ''); ?>"><b id="total2echo"><?php echo "(RM". number_format((float)$convertALHourValue, 2, '.', '').")" ?></b>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td colspan="4" class="text-right bg-light py-3"><b>Final Total Claim :</b></td>
                                                <td class="text-center bg-light"><input type="hidden" class="form-control text-center" name="total2Final" id="total2Final" value="<?php echo number_format((float)$total2Final, 2, '.', ''); ?>"><b id="ALValueEcho"><?php echo "RM".number_format((float)$total2Final, 2, '.', '').""; ?></b></td>
                                            </tr>
                                        <?php } ?>
                                    <?php } ?>
                                <?php }else{ ?>

                                <?php } ?>
                            </tfoot>
                        </table>
                        
                    </div>
                    
                    <?php if($basicSalary->basic_pay <= 2000){ ?>
                        <div class="d-print-none">
                            <?php if($ot['claim_status'] == 0){ ?>
                                <button class="btn btn-success text-white btn-lg btn-block" id="verified_otClaim" style="width: 100%;" disabled>OT Claim Not Submitted Yet</button>
                            <?php } else if($ot['claim_status'] == 1){ ?>
                                <button class="btn btn-success text-white btn-lg btn-block" id="verified_otClaim" style="width: 100%;" onclick="verifyOTClaim2(<?php echo $ot['otID']; ?>)">Verify OT Claim</button>
                            <?php } else { ?>
                                <button class="btn btn-success text-white btn-lg btn-block" id="verified_otClaim" style="width: 100%;" disabled>OT Claim Verified</button>
                            <?php }?>
                        </div><br>
                    <?php } else {?>
                        <div class="d-print-none">
                            <?php if($ot['claim_status'] == 0){ ?>
                                <button class="btn btn-success text-white btn-lg btn-block" id="verified_otClaim" style="width: 100%;" disabled>OT Claim Not Submitted Yet</button>
                            <?php } else if($ot['claim_status'] == 1){ ?>
                                <button class="btn btn-success text-white btn-lg btn-block" id="verified_otClaim" style="width: 100%;" onclick="verifyOTClaim()">Verify OT Claim</button>
                            <?php } else { ?>
                                <button class="btn btn-success text-white btn-lg btn-block" id="verified_otClaim" style="width: 100%;" disabled>OT Claim Verified</button>
                            <?php }?>
                        </div><br>
                    <?php } ?>
                </div>

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

<!-- Modal change status -->

<div class="modal fade" id="modal_approve" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
    <div class="modal-dialog ">
        <div class="modal-content">
            <form class="form" id="otStat">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLongTitle">Change OT Status</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                      <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <input type="hidden" id="otID">
                <div class="modal-body">
                    <div class="row form-group">
                        <div class="col-lg-3">
                            <label for="change_status">Status</label>
                        </div>
                        <div class="col">
                            <select name="change_status" id="change_status" class="form-control">
                                <option value="0">Pending</option>
                                <option value="1">Approved</option>
                                <option value="2">Rejected</option>
                            </select>
                        </div>
                    </div>
                    <div class="row form-group">
                        <div class="col-lg-3">
                            <label for="reason">Reason</label>
                        </div>
                        <div class="col">
                            <textarea class="form-control" rows="3" id="reason"></textarea>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button onclick="updateData()" type="button" id="saveStatusButton" class="btn btn-success btn-sm" style="margin-bottom:15px; width: 200px;"><i class="fa fa-save"></i> Save</button>
                    <button type="button" class="btn btn-danger btn-sm" style="margin-bottom:15px; width: 200px;" data-dismiss="modal"><i class="fa fa-ban"></i> Cancel</button>
                </div>
            </form>
        </div>
    </div>
</div>

<!-- Modal change status -->

<script>
var token = "<?php echo $_SESSION['token'];?>"; 
$(document).ready(function(){

    $('#searchBtn').click(function(){
        var table = $('.table').DataTable();
        table.clear().draw();
        var frmData = new FormData();

        frmData.append('token',token); 
        frmData.append('start_date',$('#start_date').val());
        frmData.append('end_date',$('#end_date').val());
        frmData.append('dept_id',$('#dept_id').val());
        frmData.append('staff_id',$('#staff_id').val());
        frmData.append('type_id',$('#type_id').val());
        frmData.append('customer_id',$('#client_id').val());
        // console.log($('#type_id').val());
        $.ajax({
            url:"<?php echo base_url('/hr/api_movement/get'); ?>",
            type:'post',
            dataType:'json',
            data:frmData,
            processData: false,
            contentType: false,
            success:function(data){

                iziToast.success({
                    position: 'bottomRight',
                    message: 'filtering data'
                });


                if(data.table != 'no result'){
                    console.log(data.table);
                    for (var i = 0; i < data.table.length; i++) {

                        var date = new Date(data.table[i].date,);
                        var dd = date.getDate();
                        var mm = date.getMonth()+1;
                        var yy = date.getFullYear();
                        var url = "<?php echo base_url('hr/movement/edit/');?>"+data.table[i].id;
                        if(data.table[i].customerName == null){
                            data.table[i].customerName = 'Others';
                        }
                        table.row.add({
                            0   : i+1,
                            1   : data.table[i].staffName,
                            2   : data.table[i].departmentName,
                            3   : data.table[i].movementType,
                            4   : data.table[i].customerName+'<br/>'+data.table[i].destination,
                            5   : dd+'-'+mm+'-'+yy,
                            6   : timeTo12(data.table[i].timeOut),
                            7   : timeTo12(data.table[i].timeIn),
                            8   : '<a href="'+url+'"><i class="fas fa-sign-in-alt"></i></a>',
                        }).draw();
                    }
                }
                
            },
            error:function(){
                 iziToast.warning({
                    position: 'bottomRight',
                    message: '500 Internal Server Error.'
                });
            }
        });
    });
    
});

    function changeStatus(otDetail_id)
    {

        $.ajax({
            type: "POST",
            dataType:"json",
            url: "<?php echo base_url() ?>hr/overtime/getStatus",
            data: {
              id: otDetail_id
            },
            success: function(data) {

                if ($.trim(data.status) == "success")
                {
                    var detailStatusData = data.detailStatusData;

                    $("#change_status").val(detailStatusData['status']);
                    $("#reason").val(detailStatusData['remarks']);
                   
                }
            }
        });

        $('#saveStatusButton').attr('onClick', 'updateData('+ otDetail_id +')');
        $('#modal_approve').modal('show');
    }

    function fillModalStatus(elem) {
        var json = JSON.parse(atob($(elem).data('json')));
        //console.log(json.ID);
        $('#otID').val(json.ID);
        if(json.status == 0){
            $('#change_status').val(0);
        }else if(json.status == 1){
            $('#change_status').val(1);
        }else if(json.status == 2){
            $('#change_status').val(2);
        }
    }

    function fillModal(elem) {

        var json = JSON.parse(atob($(elem).data('json')));
        var [h, i] = json.startTime.split(":");
        var [H, I] = json.endTime.split(":");
        var ampm = '';
        var AMPM = '';

        if(h - 12 < 0){
            ampm = 'am';
        }else if(h - 12 == 0) {
            ampm = 'pm';
        }else if(h - 12 > 0){
            h = h - 12;
            ampm = 'pm';
        }

        if(H - 12 < 0){
            AMPM = 'am';
        }else if(H - 12 == 0){
            AMPM = 'pm';
        }else if(H - 12 > 0){
            H = H - 12;
            AMPM = 'pm';
        }

        if(json.mealAllowance == 1){
            $('#edit_meal_allowance').val(1);
        }else{
            $('#edit_meal_allowance').val(2);
        }

        if(json.dayType == 1){
            $('#edit_day_type').val(1);
        }else if(json.dayType == 2){
            $('#edit_day_type').val(2);
        }else if(json.dayType == 3){
            $('#edit_day_type').val(3);
        }

        var [yy, mm, dd] = json.otDate.split("-");
        $('#otID').val(json.ID);
        $('#edit_date').val(dd+'-'+mm+'-'+yy);
        $('#edit_client').val(json.clientID).trigger('change');
        $('#edit_task').val(json.task);
        $('#edit_start_time').val(h+ ':' + i + '' + ampm);
        $('#edit_end_time').val(H+ ':' + I + '' + AMPM);
        $('#edit_refreshment').val(json.refreshment);

        //calcTotalHour();
        calcEditTotalHour();
    }

    function updateData(otDetail_id) {
        validateForm("#otStat", "Are you sure you want to change status for this OT?", function() {
            $.ajax({
                url:'<?php echo base_url('hr/overtime/changeStatusAdmin') ?>',
                data: {
                    otID   : otDetail_id,
                    status : $('#change_status').val(),
                    reason : $('#reason').val(),
                },
                type: 'post',
                dataType: 'json',
                success: (data) => {
                    if(data.status == "Success") {
                    localStorage.setItem("status", data.status);
                    localStorage.setItem("msg", data.msg);

                    location.reload();
                    }
                }
            });
        });
    }

    function refreshBalanceFinal() {
        var totalApprovedOT   = $('#totalApprovedOT').val();
        var approvedConvertAL = $('#convertALFinal').val();
        var balanceOT         = totalApprovedOT - approvedConvertAL;

        $('#final_BalanceOT').val(balanceOT);
    }

    function calculateALValue() {
        var convertAL = $('#totalConvertAL').val();
        var total2    = $('#total2').val();

        if(convertAL % 8 > 0){
            alert("Your AL conversion hour is NOT VALID. Please insert hours in multiples of 8.");
            location.reload();
        } else {
            var ALValue     = convertAL*10;
            var total2Final = total2-ALValue;

            $('#ALValue').val(ALValue);
            $('#total2echo').html('(RM'+ALValue.toFixed(2)+')');
            $('#total2Final').val(total2Final);
            $('#ALValueEcho').html('RM'+total2Final.toFixed(2));
            
        }
        
    }

    function verifyOTClaim() {
        validateForm("#verified_otClaim", "Verify this OT Claim?", function() {

            var totalClaim  = $('#ALValueEcho').html();
            var totalClaimF = totalClaim.replace('RM','');

            var postData = {
                'otID'                  : $('#totalOT').attr('data-otID'),
                'user_id'               : $('#peopleID').val(),
                'year'                  : $('#peopleID').attr('data-year'),
                'totalHoursApproved'    : $('#totalApprovedOT').val(),
                'totalConvertToLeave'   : $('#totalConvertAL').val(),
                'totalClaim'            : totalClaimF
            }

            $.ajax({
            type: "POST",
            dataType: "json",
            url: "<?php echo base_url(); ?>hr/Overtime/verifyOTClaim",
            data: postData,
            success: function(data) {
                if ($.trim(data.status) == "success") 
                {
                    localStorage.setItem("status", data.status);
                    localStorage.setItem("msg", data.msg);

                    location.reload();
                }
            }
            });
        });

    }

    function verifyOTClaim2(otID) {
        validateForm("#verified_otClaim", "Verify this OT Claim?", function() {

            var postData = {
                'otID'                        : otID,
                'user_id'                     : $('#peopleID').val(),
                'year'                        : $('#peopleID').attr('data-year'),
                'totalHoursApproved'          : $('#totalApprovedOT').val(),
                'totalConvertToLeave'         : 0,
                'totalClaim'                  : $('#total2').val()
            }

            $.ajax({
                type: "POST",
                dataType: "json",
                url: "<?php echo base_url(); ?>hr/Overtime/verifyOTClaim",
                data: postData,
                success: function(data) {
                    if ($.trim(data.status) == "success") 
                    {
                        localStorage.setItem("status", data.status);
                        localStorage.setItem("msg", data.msg);

                        location.reload();
                    }
                }
            });
        });
    }

    function redirectLeaveEntitlement()
    {
        window.open("<?php echo base_url(); ?>hr/leave/allocation", "_blank");
    }

    function printOTClaim(){

        var otID = $('#totalOT').attr('data-otID');
        var user_id = $('#peopleID').val()

        window.open("<?php echo base_url().'hr/Overtime_report/printOTClaim/'?>" + otID + "/" + user_id, "_blank");
    }

    function printOTClaimSummary(){

        var otID = $('#totalOT').attr('data-otID');
        var user_id = $('#peopleID').val()

        window.open("<?php echo base_url().'hr/Overtime_report/printOTClaimSummary/'?>" + otID + "/" + user_id, "_blank");
    }

</script> 