<div class="container-fluid mt-5 mb-5">
    <div class="card bg-light-transparent">  
        <div class="card-header bg-white">
            <div class="float-left">
                <h5>My OT Claim Details for <?php echo date("F Y",mktime(0,0,0, $rsOt['month'],1,$rsOt['year'])) ?></h5>
                <a href="<?php echo base_url('hr/overtime/otClaim')?>" class="btn btn-outline-dark btn-sm" title="Back to My OT List"  >
                    <i class="fa fa-angle-double-left"></i>Back to My OT Claim
                </a>
                <a onclick="printMyOTClaim()" target="_blank" class="btn btn-outline-dark btn-sm" title="Print My OT Claim"><i class="fa fa-print"></i> Print</a><br>
            </div>
        </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="user_id" id="user_id" value="<?php echo $_SESSION['user']['id']; ?>">
                                        </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-bordered p-0 m-0" 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;">
                                            Meal Allowance
                                        </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
                                        </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
                                        </th>       
                                    </thead>  
                                    <tbody>
                                        <?php if (!empty($otLists)): ?>
                                            <?php 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 if($ot['mealAllowance'] == 1){
                                                            echo 'Claimable (Included)';
                                                          } else if($ot['mealAllowance'] == 2){
                                                            echo 'Claimable (Not Included)';
                                                          } else {
                                                            echo 'Unclaimable';
                                                          } ?>  
                                                </td>
                                                <td><?php echo date("h:i A", strtotime($ot['startTime']));?></td>
                                                <td><?php echo date("h: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';
                                                    }
                                                 ?></td>
                                                <td><?php echo $ot['svName'];?> <br><small><b> - <?php echo $ot['svDeptName'];?></b></small></td>
                                                <td id="otID" class="" otDetailID="<?php echo $ot['ID']; ?>" otID="<?php echo $ot['otID']; ?>">
                                                    <?php if($ot['status'] == 0) { ?>
                                                        <span class="badge badge-warning text-white">Pending</span><br>
                                                        <small><i><b>*Remarks : </b><?php echo $ot['remarks'];?></i><br></small>
                                                    <?php } else if($ot['status'] == 1) { ?>
                                                        <span class="badge badge-success text-white">Approved</span><br>
                                                        <small><i><b>*Remarks : </b><?php echo $ot['remarks'];?></i><br></small>
                                                        <small><i><b>*Approved by : </b><?php echo $ot['status_by_name'];?></i><br></small>
                                                    <?php }else { ?>
                                                        <span class="badge badge-danger text-white">Rejected</span><br>
                                                        <small><i><b>*Remarks : </b><?php echo $ot['remarks'];?></i><br></small>
                                                        <small><i><b>*Rejected by : </b><?php echo $ot['status_by_name'];?></i><br></small>
                                                    <?php } ?>
                                                </td>                                                
                                            </tr> 
                                            <?php endforeach ?>
                                        <?php endif ?>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="card no-shadow">
                    <div class="card-body">
                        <?php if($basicSalary->basic_pay <= 2000 && trim(strtolower($position)) == 'trainee'){ ?> <!-- for trainee -->
                            <table class="table-bordered" width="100%">
                                <h5>My 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 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>
                                                &nbsp;Meal Allowance<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']*6; //trainee fix rate

                                                    if(!empty($row['NormalMeal'])){ $row['NormalMeal'] = $row['NormalMeal']; } else { $row['NormalMeal'] = 0; };
                                                    if(!empty($row['RestMeal'])){ $row['RestMeal']     = $row['RestMeal']; } else { $row['RestMeal'] = 0; };
                                                    if(!empty($row['PublicMeal'])){ $row['PublicMeal'] = $row['PublicMeal']; } else { $row['PublicMeal'] = 0; };

                                                    if($row['NormalMeal'] > 0){
                                                        $NormalMeal = $row['NormalMeal']*5;
                                                    }else{
                                                         $NormalMeal = 0;
                                                    }
                                                    if($row['RestMeal'] > 0){
                                                        $RestMeal = $row['RestMeal']*10;
                                                    }else{
                                                        $RestMeal = 0;
                                                    }
                                                    if($row['PublicMeal'] > 0){
                                                        $PublicMeal = $row['PublicMeal']*10;
                                                    }else{
                                                        $PublicMeal = 0;
                                                    }

                                                    $totalMeal = $NormalMeal + $RestMeal + $PublicMeal;

                                                    $totalDept = $totalClaim + $totalMeal;

                                                    $sum+=$totalDept;

                                                ?>

                                                <?php echo $row['totalHoursApplied']; ?><br>
                                                <?php echo $row['totalHoursApproved']; ?><br>
                                                RM<?php echo number_format((float)$totalClaim, 2, '.', ''); ?><br>
                                                RM<?php echo number_format((float)$totalMeal, 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>My Claim Summary for <?php echo date("F Y",mktime(0,0,0, $rsOt['month'],1,$rsOt['year'])) ?></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">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"><?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"><b></b></td>
                                        <td class="text-center bg-light py-3"><b>Total Hours Approved</b></td>
                                        <td class="text-center bg-light"><b>Meal Allowance Claimable</b></td>
                                        <td class="text-center bg-light"><b>Calculation</b></td>
                                        <td class="text-center bg-light"><b>Total</b></td>
                                    </tr>
                                </tbody>
                                <tfoot>
                                    <?php 
                                        $normalMealAllowance  = $ot['NormalMeal']*5;
                                        $restMealAllowance    = $ot['RestMeal']*10;
                                        $publicMealAllowance  = $ot['PublicMeal']*10;

                                        $normalDayTotal = 6*$ot['normal'] + $normalMealAllowance; //trainee fix rate
                                        $restDayTotal   = 6*$ot['rest'] + $restMealAllowance;
                                        $publicDayTotal = 6*$ot['public'] + $publicMealAllowance; 
                                        $total          = $normalDayTotal+$restDayTotal+$publicDayTotal; 
                                    ?>
                                    <tr>
                                        <td class="text-center"> 
                                            Normal Day 
                                        </td>
                                        <td class="text-center"><?php if($ot['normal']){ echo $ot['normal']; }else{ echo "0"; } ?></td>
                                        <td class="text-center">RM<?php if($normalMealAllowance){ echo $normalMealAllowance; }else{ echo "0"; } ?></td>
                                        <td class="text-center"><?php echo 'RM6 x '.$ot['normal'].' + RM'.$normalMealAllowance ?><br><small>(RM6 x Actual Overtime + Meal Allowance Claimable)</small></td>
                                        <td class="text-center"><b>RM<?php echo number_format((float)$normalDayTotal, 2, '.', ''); ?></b></td>
                                    </tr>
                                    <tr>
                                        <td class="text-center"> 
                                            Rest Day
                                        </td>
                                        <td class="text-center"><?php if($ot['rest']){ echo $ot['rest']; }else{ echo "0"; } ?></td>
                                        <td class="text-center">RM<?php if($restMealAllowance){ echo $restMealAllowance; }else{ echo "0"; } ?></td>
                                        <td class="text-center"><?php echo 'RM6 x '.$ot['rest'].' + RM'.$restMealAllowance ?><br><small>(RM6 x Actual Overtime + Meal Allowance Claimable)</small></td>
                                        <td class="text-center"><b>RM<?php echo number_format((float)$restDayTotal, 2, '.', ''); ?></b></td>
                                    <tr>
                                        <td class="text-center"> 
                                            Public Holiday
                                        </td>
                                        <td class="text-center"><?php if($ot['public']){ echo $ot['public']; }else{ echo "0"; } ?></td>
                                        <td class="text-center">RM<?php if($publicMealAllowance){ echo $publicMealAllowance; }else{ echo "0"; } ?></td>
                                        <td class="text-center"><?php echo 'RM6 x '.$ot['public'].' + RM'.$publicMealAllowance ?><br><small>(RM6 x Actual Overtime + Meal Allowance Claimable)</small></td>
                                        <td class="text-center"><b>RM<?php echo number_format((float)$publicDayTotal, 2, '.', ''); ?></b></td>
                                    </tr>
                                    <tr>
                                        <td colspan="4" class="text-right bg-light py-3"><b>Total Claim :</b></td>
                                        <td class="text-center bg-light"><input type="hidden" value="<?php echo number_format((float)$total, 2, '.', ''); ?>" id="totalClaim"><b>RM<?php echo number_format((float)$total, 2, '.', ''); ?></b></td>
                                    </tr>
                                </tfoot>
                            </table>
                        <?php } else if($basicSalary->basic_pay <= 2000){ ?> <!-- basic pay less then or equal to 2000 -->
                            <table class="table-bordered" width="100%">
                                <h5>My 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>
                                                &nbsp;Meal Allowance<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; };

                                                    if(!empty($row['NormalMeal'])){ $row['NormalMeal'] = $row['NormalMeal']; } else { $row['NormalMeal'] = 0; };
                                                    if(!empty($row['RestMeal'])){ $row['RestMeal']     = $row['RestMeal']; } else { $row['RestMeal'] = 0; };
                                                    if(!empty($row['PublicMeal'])){ $row['PublicMeal'] = $row['PublicMeal']; } else { $row['PublicMeal'] = 0; };

                                                    if(!empty($row['Normal'])){ $row['Normal'] = $row['Normal']; } else { $row['Normal'] = 0; };
                                                    if(!empty($row['Rest'])){ $row['Rest']     = $row['Rest']; } else { $row['Rest'] = 0; };
                                                    if(!empty($row['Public'])){ $row['Public'] = $row['Public']; } else { $row['Public'] = 0; };

                                                    if($row['NormalMeal'] > 0){
                                                        $NormalMeal = $row['NormalMeal']*5;
                                                    }else{
                                                         $NormalMeal = 0;
                                                    }
                                                    if($row['RestMeal'] > 0){
                                                        $RestMeal = $row['RestMeal']*10;
                                                    }else{
                                                        $RestMeal = 0;
                                                    }
                                                    if($row['PublicMeal'] > 0){
                                                        $PublicMeal = $row['PublicMeal']*10;
                                                    }else{
                                                        $PublicMeal = 0;
                                                    }

                                                    $totalMeal = $NormalMeal + $RestMeal + $PublicMeal;

                                                    if($row['Normal'] > 0){
                                                        $normalDayTotal = $basicSalary->basic_pay/208*1.5*$row['Normal'];
                                                    }else{
                                                        $normalDayTotal = 0;
                                                    }
                                                    if($row['Rest'] > 0){
                                                        $restDayTotal   = $basicSalary->basic_pay/208*2.0*$row['Rest'];
                                                    }else{
                                                        $restDayTotal   = 0;
                                                    }
                                                    if($row['Public'] > 0){
                                                        $publicDayTotal = $basicSalary->basic_pay/208*3.0*$row['Public'];
                                                    }else{
                                                        $publicDayTotal = 0;
                                                    }

                                                    $totalClaim = $normalDayTotal+$restDayTotal+$publicDayTotal; 

                                                    $totalDept = $totalClaim + $totalMeal;

                                                    $sum+=$totalDept;

                                                ?>

                                                <?php echo $row['totalHoursApplied']; ?><br>
                                                <?php echo $row['totalHoursApproved']; ?><br>
                                                RM<?php echo number_format((float)$totalClaim, 2, '.', ''); ?><br>
                                                RM<?php echo number_format((float)$totalMeal, 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>My Claim Summary for <?php echo date("F Y",mktime(0,0,0, $rsOt['month'],1,$rsOt['year'])) ?></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">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"><?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"><b></b></td>
                                        <td class="text-center bg-light py-3"><b>Total Hours Approved</b></td>
                                        <td class="text-center bg-light"><b>Meal Allowance Claimable</b></td>
                                        <td class="text-center bg-light"><b>Calculation</b></td>
                                        <td class="text-center bg-light"><b>Total</b></td>
                                    </tr>
                                </tbody>
                                <tfoot>
                                    <?php 
                                        $normalMealAllowance  = $ot['NormalMeal']*5;
                                        $restMealAllowance    = $ot['RestMeal']*10;
                                        $publicMealAllowance  = $ot['PublicMeal']*10;

                                        $normalDayTotal = $basicSalary->basic_pay/208*1.5*$ot['normal'] + $normalMealAllowance;
                                        $restDayTotal   = $basicSalary->basic_pay/208*2.0*$ot['rest'] + $restMealAllowance;
                                        $publicDayTotal = $basicSalary->basic_pay/208*3.0*$ot['public'] + $publicMealAllowance; 
                                        $total          = $normalDayTotal+$restDayTotal+$publicDayTotal; 
                                    ?>
                                    <tr>
                                        <td class="text-center"> 
                                            Normal Day 
                                        </td>
                                        <td class="text-center"><?php if($ot['normal']){ echo $ot['normal']; }else{ echo "0"; } ?></td>
                                        <td class="text-center">RM<?php if($normalMealAllowance){ echo $normalMealAllowance; }else{ echo "0"; } ?></td>
                                        <td class="text-center"><?php echo $basicSalary->basic_pay.'/208 x 1.5 x '.$ot['normal'].' + RM'.$normalMealAllowance ?><br><small>(Basic Salary/208 x 1.5 x Actual Overtime + Meal Allowance Claimable)</small></td>
                                        <td class="text-center"><b>RM<?php echo number_format((float)$normalDayTotal, 2, '.', ''); ?></b></td>
                                    </tr>
                                    <tr>
                                        <td class="text-center"> 
                                            Rest Day
                                        </td>
                                        <td class="text-center"><?php if($ot['rest']){ echo $ot['rest']; }else{ echo "0"; } ?></td>
                                        <td class="text-center">RM<?php if($restMealAllowance){ echo $restMealAllowance; }else{ echo "0"; } ?></td>
                                        <td class="text-center"><?php echo $basicSalary->basic_pay.'/208 x 2.0 x '.$ot['rest'].' + RM'.$restMealAllowance ?><br><small>(Basic Salary/208 x 2.0 x Actual Overtime + Meal Allowance Claimable)</small></td>
                                        <td class="text-center"><b>RM<?php echo number_format((float)$restDayTotal, 2, '.', ''); ?></b></td>
                                    <tr>
                                        <td class="text-center"> 
                                            Public Holiday
                                        </td>
                                        <td class="text-center"><?php if($ot['public']){ echo $ot['public']; }else{ echo "0"; } ?></td>
                                        <td class="text-center">RM<?php if($publicMealAllowance){ echo $publicMealAllowance; }else{ echo "0"; } ?></td>
                                        <td class="text-center"><?php echo $basicSalary->basic_pay.'/208 x 3.0 x '.$ot['public'].' + RM'.$publicMealAllowance ?><br><small>(Basic Salary/208 x 3.0 x Actual Overtime + Meal Allowance Claimable)</small></td>
                                        <td class="text-center"><b>RM<?php echo number_format((float)$publicDayTotal, 2, '.', ''); ?></b></td>
                                    </tr>
                                    <tr>
                                        <td colspan="4" class="text-right bg-light py-3"><b>Total Claim :</b></td>
                                        <td class="text-center bg-light"><input type="hidden" value="<?php echo number_format((float)$total, 2, '.', ''); ?>" id="totalClaim"><b>RM<?php echo number_format((float)$total, 2, '.', ''); ?></b></td>
                                    </tr>
                                </tfoot>
                            </table>
                        <?php } else if($basicSalary->basic_pay > 2000){ ?> <!-- basic pay more than 2000 -->
                            <table class="table-bordered" width="100%">
                                <h5>My 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 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>
                                                &nbsp;Meal Allowance<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']*10;

                                                    if(!empty($row['NormalMeal'])){ $row['NormalMeal'] = $row['NormalMeal']; } else { $row['NormalMeal'] = 0; };
                                                    if(!empty($row['RestMeal'])){ $row['RestMeal']     = $row['RestMeal']; } else { $row['RestMeal'] = 0; };
                                                    if(!empty($row['PublicMeal'])){ $row['PublicMeal'] = $row['PublicMeal']; } else { $row['PublicMeal'] = 0; };

                                                    if($row['NormalMeal'] > 0){
                                                        $NormalMeal = $row['NormalMeal']*5;
                                                    }else{
                                                         $NormalMeal = 0;
                                                    }
                                                    if($row['RestMeal'] > 0){
                                                        $RestMeal = $row['RestMeal']*10;
                                                    }else{
                                                        $RestMeal = 0;
                                                    }
                                                    if($row['PublicMeal'] > 0){
                                                        $PublicMeal = $row['PublicMeal']*10;
                                                    }else{
                                                        $PublicMeal = 0;
                                                    }

                                                    $totalMeal = $NormalMeal + $RestMeal + $PublicMeal;

                                                    $totalDept = $totalClaim + $totalMeal;

                                                    $sum+=$totalDept;

                                                ?>

                                                <?php echo $row['totalHoursApplied']; ?><br>
                                                <?php echo $row['totalHoursApproved']; ?><br>
                                                RM<?php echo number_format((float)$totalClaim, 2, '.', ''); ?><br>
                                                RM<?php echo number_format((float)$totalMeal, 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'])) ?></h5><br>
                                <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"><?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>Meal Allowance Claimable</b></td>
                                        <td class="text-center bg-light"><b>Calculation</b></td>
                                        <td class="text-center bg-light"><b>Total</b></td>
                                    </tr>
                                </tbody>
                                <tfoot>
                                    <?php 
                                        $normalMealAllowance2  = $ot['NormalMeal']*5;
                                        $restMealAllowance2    = $ot['RestMeal']*10;
                                        $publicMealAllowance2  = $ot['PublicMeal']*10;

                                        $normalDayTotal2 = $ot['normal']*10+$normalMealAllowance2;
                                        $restDayTotal2   = $ot['rest']*10+$restMealAllowance2;
                                        $publicDayTotal2 = $ot['public']*10+$publicMealAllowance2; 
                                        $total2          = $normalDayTotal2+$restDayTotal2+$publicDayTotal2; 

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

                                        $total2Final        = $total2-$convertALHourValue;
                                    ?>
                                    <tr>
                                        <td class="text-center"> 
                                            Normal Day 
                                        </td>
                                        <td class="text-center"><?php if($ot['normal']){ echo $ot['normal']; }else{ echo "0"; } ?></td>
                                        <td class="text-center">RM<?php if($normalMealAllowance2){ echo $normalMealAllowance2; }else{ echo "0"; } ?></td>
                                        <td class="text-center"><?php echo $ot['normal'].' x RM10 + RM'.$normalMealAllowance2;; ?><br><small>(Actual Overtime x RM10.00 + Meal Allowance Claimable)</small></td>
                                        <td class="text-center"><b>RM<?php echo number_format((float)$normalDayTotal2, 2, '.', ''); ?></b></td>
                                    </tr>
                                    <tr>
                                        <td class="text-center"> 
                                            Rest Day
                                        </td>
                                        <td class="text-center"><?php if($ot['rest']){ echo $ot['rest']; }else{ echo "0"; } ?></td>
                                        <td class="text-center">RM<?php if($restMealAllowance2){ echo $restMealAllowance2; }else{ echo "0"; } ?></td>
                                        <td class="text-center"><?php echo $ot['rest'].' x RM10 + RM'.$restMealAllowance2;; ?><br><small>(Actual Overtime x RM10.00 + Meal Allowance Claimable)</small></td>
                                        <td class="text-center"><b>RM<?php echo number_format((float)$restDayTotal2, 2, '.', ''); ?></b></td>
                                    <tr>
                                        <td class="text-center"> 
                                            Public Holiday
                                        </td>
                                        <td class="text-center"><?php if($ot['public']){ echo $ot['public']; }else{ echo "0"; } ?></td>
                                        <td class="text-center">RM<?php if($publicMealAllowance2){ echo $publicMealAllowance2; }else{ echo "0"; } ?></td>
                                        <td class="text-center"><?php echo $ot['public'].' x RM10 + RM'.$publicMealAllowance2; ?><br><small>(Actual Overtime x RM10.00 + Meal Allowance Claimable)</small></td>
                                        <td class="text-center"><b>RM<?php echo number_format((float)$publicDayTotal2, 2, '.', ''); ?></b></td>
                                    </tr>
                                    <tr>
                                        <td colspan="4" class="text-right bg-light py-3"><b>Total Claim :</b></td>
                                        <td class="text-center bg-light"><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($ot['claim_status']==0){ ?>
                                        <?php if($ot['totalHoursApproved'] >= 8){ ?> 
                                            <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="<?php echo $convertALHour; ?>" 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)$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 } 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 } 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="<?php echo $ot['totalConvertToLeave']; ?>" 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)$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)$ot['totalClaim'], 2, '.', '').""; ?></b></td>
                                        </tr>
                                    <?php } ?>
                                    
                                </tfoot>
                            </table>
                        <?php } ?>
                    </div>

                    <div class="d-print-none">
                        <?php if($ot['claim_status'] == 0 && (date('d') <= 7 || date('d') >= 15)){ ?> <!-- claim not submitted / open period-->
                            <?php if (!empty($otPendingDetails)) { ?> <!-- claim not submitted / details still pending-->
                                <button class="btn btn-success text-white btn-lg btn-block" id="submit_ot" style="width: 100%;" disabled title="Your OT Details still got pending.">Submit OT Claim</button>
                            <?php } else if($basicSalary->basic_pay <= 2000){ ?>
                                <button class="btn btn-success text-white btn-lg btn-block" id="submit_ot" style="width: 100%;" onclick="submitOTClaim(<?php echo $ot['otID']; ?>)">Submit OT Claim</button>
                            <?php } else {?>
                                <button class="btn btn-success text-white btn-lg btn-block" id="submit_ot" style="width: 100%;" onclick="submitOTClaim2(<?php echo $ot['otID']; ?>)">Submit OT Claim</button>
                            <?php } ?>
                        <?php } else if($ot['claim_status'] == 0 && (date('d') > 7 || date('d') < 15)){ ?> <!-- claim not submitted / closed period -->  
                            <button class="btn btn-success text-white btn-lg btn-block" id="submit_ot" style="width: 100%;" disabled>Submit OT Claim</button>
                        <?php } else if($ot['claim_status'] == 1 && (date('d') <= 7 || date('d') >= 15)){ ?> <!-- claim submitted / open period -->  
                            <button class="btn btn-success text-white btn-lg btn-block" id="submit_ot" style="width: 100%;" disabled>Claim Submitted</button>
                        <?php } else if($ot['claim_status'] == 1 && (date('d') > 7 || date('d') < 15)){ ?> <!-- claim submitted /closed period -->
                            <button class="btn btn-success text-white btn-lg btn-block" id="submit_ot" style="width: 100%;" disabled>Claim Submitted</button>
                        <?php } else { ?> <!-- others -->
                            <button class="btn btn-success text-white btn-lg btn-block" id="submit_ot" style="width: 100%;" disabled>Claim Submitted</button>
                        <?php }?>
                        <span class="text-danger float-right" style="margin-right: 20px;"> *Submit OT Claim will be disabled every 8th-15th every month.</span>
                    </div><br>
                </div>
            </div>
        </div>      
    </div>
</div>

<!-- Modal Add OT -->
<div class="modal fade" id="add_claim" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLongTitle">New OT Claim</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                  <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <form method="post" action="<?php echo base_url('hr/overtime/addClaim') ?>">
                <div class="modal-body">
                    <div class="row form-group">
                        <div class="col-lg-3">
                            <label for="Date">Claim for</label>
                        </div>
                        <div class="col">
                            <input type="text" name="Date" class="datepicker form-control" id="Date" placeholder="Enter Date" autocomplete="off">
                        </div>
                    </div>  
                   
                </div>
                <div class="modal-footer">
                    <button type="submit" class="btn btn-success btn-sm" style="margin-bottom:15px; width: 200px;"><i class="fa fa-plus"></i> Add</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 Add OT -->

<script>

    $('.datepicker').datepicker({
        uiLibrary: 'bootstrap4',
        autoclose: true,
        orientation: 'bottom',
        format: "mm-yyyy",
        viewMode: "months", 
        minViewMode: "months"
    });

    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 submitOTClaim(otID) {

        validateForm("#submit_ot", "Submit this OT Claim?", function() {
            
            var postData = {
                'otID'        : otID,
                'totalClaim'  : $('#totalClaim').val()
            }

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

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

    function submitOTClaim2(otID) {

        validateForm("#submit_ot", "Submit this OT Claim?", function() {

            var postData = {
                'otID'                : otID,
                'totalConvertToLeave' : $('#totalConvertAL').val(),
                'totalClaim'          : $('#total2Final').val()
            }

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

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

    function printMyOTClaim(){

        var otID = $('#otID').attr('otID');

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


</script> 