<style>
    /* #map {height: 300px;} */
    tr:hover
    {
        cursor: pointer;
    }

    .dot
    {
        border:.5px solid #dedede;
        border-radius:25px;
        padding:5px;
        padding-top:1px;
        padding-bottom:1px;
        color:#000 !important;
        box-shadow: 0 1px 4px 0 rgba(0, 0, 0, 0.2), 0 3px 10px 0 rgba(0, 0, 0, 0.19);
    }
</style>
<?php
    $mode   = 'My Claim List';
    if(!empty($screen_mode))
    {
        if($screen_mode == 'admin')
        {
            $mode   = 'Admin Approval';
        }elseif($screen_mode == 'hod')
        {
            $mode   = 'HOD Claim Review';
        }elseif($screen_mode == 'em')
        {
            $mode   = 'Engagement Manager Claim Review';
        }
    }
?>

<section class="container" style="padding-bottom: 2rem;" id="content_section">
	<div class="card bg-light-transparent">  

        <div class="card-header bg-dark text-white">
            
            <div class="text-right">
                <?php $this->load->view('hr/claim/page/claimdetail/button'); ?>
                <h5 class="text-uppercase">
                    <?php echo $mode; ?>
                </h5>
            </div>

            <div class="row">
                <div class="col-12 col-md-3">
                    <?php
                        if(!empty($claims_user['file_location'] && $claims_user['file_name']))
                        {
                            $claim_user_img = base_url($claims_user['file_location'].$claims_user['file_name']);
                        }else{
                            if(!empty($claims_user['gender_id']))
                            {
                                $claim_user_img = base_url('assets/images/user.png');
                            }else{
                                if($claims_user['gender_id'] == '2')
                                {
                                    $claim_user_img = base_url('assets/images/user-female.png');
                                }else{
                                    $claim_user_img = base_url('assets/images/user.png');
                                }
                            }
                        }
                    ?>
                    <div class="border img-responsive rounded-circle" 
                        style=" background-image: url(<?php echo $claim_user_img; ?>);background-position:50% 50%; background-size: cover; width: 8rem; height: 8rem; margin: 0 auto;">
                    </div>
                </div>
                <div class="col-12 col-md-9">
                    <div class="row">
                        <div class="col-12 col-md-6">
                            <div class="row">
                                <div class="col-12 col-md-4 mb-3">
                                    Name
                                </div>
                                <div class="col-12 col-md-8 mb-3">
                                    <input type="text" class="form-control" value="<?php echo (!empty($claims_user))?$claims_user['name']:''; ?>" disabled/>
                                </div>
                            </div>
                        </div>
                        <div class="col-12 col-md-6">
                            <div class="row">
                                <div class="col-12 col-md-4 mb-3">
                                    Department
                                </div>
                                <div class="col-12 col-md-8 mb-3">
                                    <input type="text" class="form-control" value="<?php echo (!empty($claims_user))?$claims_user['department_name']:''; ?>" disabled/>                      
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-12 col-md-6">
                            <div class="row">
                                <div class="col-12 col-md-4 mb-3">
                                    Submission Month
                                </div>
                                <div class="col-12 col-md-8 mb-3">
                                    <input type="text" class="form-control" value="<?php echo date('F',strtotime('01-'.$month.'-'.$year))?>" disabled/>
                                </div>
                            </div>
                        </div>
                        <div class="col-12 col-md-6">
                            <div class="row">
                                <div class="col-12 col-md-4 mb-3">
                                    Submission Year
                                </div>
                                <div class="col-12 col-md-8 mb-3">
                                    <input type="text" class="form-control" value="<?php echo date('Y',strtotime('01-'.$month.'-'.$year))?>" disabled/>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <hr/>
            <div class="collapse" id="info-collapse">
                <div class="row">
                    <div class="col">
                        <h4>Prorate for submission (<?php echo date('F-Y',strtotime('01-'.$month.'-'.date('Y'))); ?>)</h4>
                    </div>
                </div>
                <div class="row">
                    <div class="col-12 col-md-3 p-3" style="border:0.5px solid #ccc;border-radius:5px;">
                        <h5>Dental / Optical</h5>
                        <p>
                            <div class="row">
                                <!-- <div class="col">
                                    <span class="text-success"><?php //echo date('F Y',strtotime('01-'.$second_month.'-'.$second_year)); ?></span> <br/>
                                    RM <?php //echo (!empty($second_prorate_dental))?number_format($second_prorate_dental,2):0.00; ?>
                                    <br>
                                    <small>Balance : RM<?php //echo (!empty($second_dental_balance))?(number_format($second_dental_balance) > 0)?number_format($second_dental_balance):0.00:0.00; ?> </small>
                                </div>
                                <div class="col">
                                    <span class="text-success"><?php //echo date('F Y',strtotime('01-'.$first_month.'-'.$first_year)); ?></span> <br>
                                    RM <?php //echo (!empty($first_prorate_dental))?number_format($first_prorate_dental,2):0.00; ?>
                                    <br>
                                    <small>Balance : RM<?php //echo (!empty($first_dental_balance))?(number_format($first_dental_balance,2) > 0)?number_format($first_dental_balance,2):0.00:0.00; ?></small>
                                </div> -->

                                <?php if($second_year != $first_year): ?>
                                <div class="col">
                                    <span class="text-success"><?php echo $second_year; ?></span> <br>
                                    RM <?php echo (!empty($first_col_prorate))?$first_col_prorate:0.00; ?>
                                    <br>
                                    <!-- <small>Balance : RM <?php //echo (!empty($first_col_balanced))?($first_col_balanced > 0)?$first_col_balanced:'0.00':'0.00'; ?></small> -->
                                    <small>Balance : RM <?php echo $first_col_balanced; ?></small>
                                </div>
                                <?php endif; ?>

                                <div class="col">
                                    <span class="text-success"><?php echo $first_year; ?></span> <br>
                                    RM <?php echo (!empty($second_col_prorate))?$second_col_prorate:0.00; ?>
                                    <br>
                                    <!-- <small>Balance : RM <?php //echo (!empty($second_col_balanced))?($second_col_balanced > 0)?$second_col_balanced:'0.00':'0.00'; ?></small> -->
                                    <small>Balance : RM <?php echo $second_col_balanced; ?></small>
                                </div>
                            </div>
                        </p>
                    </div>
                    <div class="col-12 col-md-3 p-3" style="border:0.5px solid #ccc;border-radius:5px;">
                        <h5>Hospitalization</h5>
                        <p>
                        <div class="row">

                            <?php if($second_year != $first_year): ?>
                            <div class="col">
                                <span class="text-success"><?php echo $second_year; ?></span> <br>
                                RM <?php echo (!empty($second_hospitalization_prorate))?$second_hospitalization_prorate:0.00; ?>
                                <br>
                                <small>Balance : RM <?php echo $second_hospitalization_balance; ?></small>
                            </div>
                            <?php endif; ?>

                            <div class="col">
                                <span class="text-success"><?php echo $first_year; ?></span> <br>
                                RM <?php echo (!empty($first_hospitalization_prorate))?$first_hospitalization_prorate:0.00; ?>
                                <br>
                                <small>Balance : RM <?php echo $first_hospitalization_balance; ?></small>
                            </div>

                        </div>
                        </p>
                    </div>
                    <div class="col-12 col-md-3 p-3" style="border:0.5px solid #ccc;border-radius:5px;">
                        <h5>Outpatient</h5>
                        <p>
                            <div class="row">
                                <?php if($second_year != $first_year): ?>
                                <div class="col">
                                    <span class="text-success"><?php echo $second_year; ?></span> <br>
                                    RM <?php echo (!empty($first_outpatient_prorate))?$first_outpatient_prorate:0.00; ?>
                                    <br>
                                    <!-- <small>Balance : RM <?php //echo (!empty($first_outpatient_balance))?($first_outpatient_balance > 0)?$first_outpatient_balance:'0.00':'0.00'; ?></small> -->
                                    <small>Balance : RM <?php echo $first_outpatient_balance; ?></small>
                                </div>
                                <?php endif; ?>

                                <div class="col">
                                    <span class="text-success"><?php echo $first_year; ?></span> <br>
                                    RM <?php echo (!empty($second_outpatient_prorate))?$second_outpatient_prorate:0.00; ?>
                                    <br>
                                    <!-- <small>Balance : RM <?php //echo (!empty($second_outpatient_balance))?($second_outpatient_balance > 0)?$second_outpatient_balance:'0.00':'0.00'; ?></small> -->
                                    <small>Balance : RM <?php echo $second_outpatient_balance; ?></small>
                                </div>
                            </div>
                        </p>
                    </div >
                    <div class="col-12 col-md-3 p-3" style="border:0.5px solid #ccc;border-radius:5px;">
                        <h5>Special Allowance</h5>
                        <div class="row">
                            <?php if($second_year != $first_year): ?>
                            <?php endif; ?>

                            <div class="col">Dressing<br>
                                <span class="text-success"><?php echo $first_year; ?></span><br>
                                RM <?php echo $second_dressing_prorate; ?><br>
                                <small>Balance : RM <?php echo $second_dressing_balance; ?></small>
                            </div>
                            <div class="col">Gadget<br>
                                <span class="text-success"><?php echo $current_year_gadget[0]->year;?></span><br>
                                RM <?php echo $second_gadget_prorate; ?><br>
                                <small>Balance : RM <?php echo $second_gadget_balance; ?></small>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col text-left">
                        <?php if(empty($screen_mode)){ ?>
                            <?php if($disabled): ?>
                            <span class="text-danger">*[Notes]</span> 
                            <ul>
                                <li class="text-danger">Claim submission will be disabled starting from 7th to 15th every month</li>
                                <li class="text-danger">Button submission will be disabled after submission date</li>
                            </ul>
                            <?php endif ?>
                        <?php } ?>
                    </div>
                </div>
            </div>
            <br>
            <div class="row">
                <div class="col text-right">
                    <?php 
                        if($is_in_submission_range)
                        {
                            $this->load->view('hr/claim/page/claimdetail/button2'); 
                        }else{
                            echo '<span class="text-danger">Current date is not in the date range for create and submit claim</span>';
                        }
                    ?>              
                </div>
            </div>

        </div>
    
        <div class="card-body">
            <div class="card no-shadow">
                <div class="card-body">
                    <?php 
                        $this->load->view('hr/claim/page/claimdetail/3_v2');
                    ?>
                </div>
            </div>
        </div>
        
        <!-- claim summary -->
        <div class="card-footer bg-white">
            <h5>Summary Claim for <?php echo date('F Y',strtotime('01-'.$month.'-'.$year)) ?></h5>
            <div class="table-responsive">
                <table class="table-hover table-bordered p-0 m-0" width="100%">
                    <thead>
                        <tr>
                            <th class="text-center">#</th>
                            <th class="text-center">Type</th>
                            <th class="text-center">Total Claim (RM)</th>
                            <th class="text-center">Total Approved (RM)</th>
                        </tr>
                    </thead>
                    <tbody>

                        <tr>
                            <td class="p-3">1</td> 
                            <td class="p-3">Mileage</td> 
                            <?php
                                $mileage_claim = 0;
                                $mileage_approved = 0;
                                        
                                if(!empty($travels)) foreach($travels as $key => $value)
                                {
                                    $mileage_claim += $value->mileage_amount;
                                    $mileage_approved += $value->amount_approve;
                                }
                            ?>
                            <td class="text-right p-3"><?php echo number_format($mileage_claim,2); ?></td>
                            <td class="text-right p-3"><?php echo number_format($mileage_approved,2); ?></td>
                        </tr>
                        
                        <tr>
                            <td class="p-3">2</td>
                            <td class="p-3">Petrol</td>
                            <?php
                                $petrol_claim = 0;
                                $petrol_approved = 0;
                                if(!empty($petrol)) foreach($petrol as $key => $value)
                                {
                                    $petrol_claim += $value->amount;
                                    $petrol_approved += $value->amount_approved;
                                }
                            ?>
                            <td class="text-right p-3"><?php echo number_format($petrol_claim,2); ?></td>
                            <td class="text-right p-3"><?php echo number_format($petrol_approved,2); ?></td>
                        </tr>

                        <tr>
                            <td class="p-3">3</td>
                            <td class="p-3">Accomodation</td>

                            <?php
                                $accomodation_claim = 0;
                                $accomodation_approved = 0;

                                if(!empty($accomodation)) foreach($accomodation as $key => $value)
                                {
                                    $accomodation_claim += $value->amount;
                                    $accomodation_approved += $value->amount_approved;
                                }
                            ?>
                            <td class="text-right p-3">
                                <?php echo number_format($accomodation_claim,2); ?>
                            </td>
                            <td class="text-right p-3">
                                <?php echo number_format($accomodation_approved,2); ?>
                            </td>
                        </tr>
                        
                        <?php
                            $meal_allowance = 0;
                            $meal_approved = 0;
                            
                            $outstation_allowance = 0;
                            $outstation_approved = 0;
                            
                            $travel_allowance = 0;
                            $travel_approved = 0;

                            if(!empty($subsistence)) foreach($subsistence as $key => $value)
                            {
                                if($value->allowance == 'OUTSTATION')
                                {
                                    $outstation_allowance += $value->amount;
                                    $outstation_approved += $value->amount_approved;
                                }

                                if($value->allowance == 'MEALS')
                                {
                                    $meal_allowance += $value->amount;
                                    $meal_approved += $value->amount_approved;
                                }

                                if($value->allowance == 'TRAVEL')
                                {
                                    $travel_allowance += $value->amount;
                                    $travel_approved += $value->amount_approved;
                                }
                            }
                        ?>

                        <tr>
                            <td class="p-3">4</td>
                            <td class="p-3">Subsistence Allowance - Meal</td>
                            <td class="text-right p-3"><?php echo number_format($meal_allowance,2); ?></td>
                            <td class="text-right p-3"><?php echo number_format($meal_approved,2); ?></td>
                        </tr>
                        
                        <tr>
                            <td class="p-3">5</td>
                            <td class="p-3">Subsistence Allowance - Outstation </td>
                            <td class="text-right p-3"><?php echo number_format($outstation_allowance,2); ?></td>
                            <td class="text-right p-3"><?php echo number_format($outstation_approved,2); ?></td>
                        </tr>
                                          
                        <tr>
                            <td class="p-3">6</td>
                            <td class="p-3">Subsistence Allowance - International Travel </td>
                            <td class="text-right p-3"><?php echo number_format($travel_allowance,2); ?></td>
                            <td class="text-right p-3"><?php echo number_format($travel_approved,2); ?></td>
                        </tr>
                        
                        <tr>
                            <td class="p-3">7</td>
                            <td class="p-3">Field Works - Meal Allowance </td>
                            <?php
                                $field_meal_allowance_claim = 0;
                                $field_meal_allowance_approved = 0;
                                if(!empty($meals)) foreach ($meals as $key => $value) 
                                {
                                    $field_meal_allowance_claim += $value->amount_claim;
                                    $field_meal_allowance_approved += $value->amount_approved;
                                }

                            ?>
                            <td class="text-right p-3"><?php echo number_format($field_meal_allowance_claim,2); ?></td>
                            <td class="text-right p-3"><?php echo number_format($field_meal_allowance_approved,2); ?></td>
                        </tr>

                        <tr>
                            <td class="p-3">8</td>
                            <td class="p-3">Transportation</td>
                            <?php
                                $transportation_claim = 0;
                                $transportation_approved = 0;
                                foreach($transportation as $key => $value)
                                {
                                    $transportation_claim += $value->amount;
                                    $transportation_approved += $value->amount_approved;
                                }
                            ?>
                            <td class="text-right p-3"><?php echo number_format($transportation_claim,2); ?></td>
                            <td class="text-right p-3"><?php echo number_format($transportation_approved,2); ?></td>
                        </tr>

                        <tr>
                            <td class="p-3">9</td>
                            <td class="p-3">Parking</td>
                            <?php
                                $parking_claim = 0;
                                $parking_approved = 0;
                                if(!empty($parking)) foreach($parking as $key => $value)
                                {
                                    $parking_claim += $value->amount;
                                    $parking_approved += $value->amount_approved;
                                }
                            ?>
                            <td class="text-right p-3"><?php echo number_format($parking_claim,2); ?></td>
                            <td class="text-right p-3"><?php echo number_format($parking_approved,2); ?></td>
                        </tr>
                        
                        <tr>
                            <td class="p-3">10</td>
                            <td class="p-3">Toll</td>
                            <?php
                                $toll_claim = 0;
                                $toll_approved = 0;
                                if(!empty($toll)) foreach($toll as $key => $value)
                                {
                                    $toll_claim += $value->amount;
                                    $toll_approved += $value->amount_approved;
                                }
                            ?>
                            <td class="text-right p-3"><?php echo number_format($toll_claim,2); ?></td>
                            <td class="text-right p-3"><?php echo number_format($toll_approved,2); ?></td>
                        </tr>                        

                        <tr>
                            <td class="p-3">11</td> 
                            <td class="p-3">Outpatient</td>
                            <?php 
                                $outpatient_claim   = 0;
                                $outpatient_approve = 0;
                                $medical_claim   = 0;
                                $medical_approve = 0;
                                // debug($outpatients);
                                if(!empty($outpatients)) foreach ($outpatients as $key => $outpatient) {
                                    
                                    if ($outpatient->is_medical == 0) 
                                    {
                                        $outpatient_claim   += $outpatient->amount_claim;
                                    }else
                                    {
                                        $medical_claim += $outpatient->amount_claim;
                                    }

                                    if ($outpatient->is_approve == 1 && $outpatient->is_medical == 0)
                                    {
                                        $outpatient_approve += $outpatient->amount_approved;
                                    }else
                                    {
                                        $medical_approve += $outpatient->amount_approved;
                                    }
                                    
                                }
                            ?>
                            <td class="text-right p-3"><?php echo number_format($outpatient_claim,2); ?></td> 
                            <td class="text-right p-3"><?php echo number_format($outpatient_approve,2);?></td>
                        </tr>

                        <tr>
                            <td class="p-3">12</td> 
                            <td class="p-3">Hospitalzation</td>
                            <?php 
                                $hospitalization_claim   = 0;
                                $hospitalization_approve = 0;
                                if(!empty($hospitalizations)) foreach ($hospitalizations as $key => $hospitalization) 
                                {
                                    $hospitalization_claim   += $hospitalization->amount_claim;
                                    if ($hospitalization->is_approve == 1) {
                                        $hospitalization_approve += $hospitalization->amount_approved;
                                    }
                                }
                             ?>
                            <td class="text-right p-3"><?php echo number_format($hospitalization_claim,2); ?></td> 
                            <td class="text-right p-3"><?php echo number_format($hospitalization_approve,2); ?></td>
                        </tr>

                        <tr>
                            <td class="p-3">13</td> 
                            <td class="p-3">Dental / Optical</td>
                            <?php 
                                $dental_claim   = 0;
                                $dental_approve = 0;
                                if($dentals) foreach ($dentals as $key => $dental) 
                                {
                                    $dental_claim   += $dental->amount_claim;
                                    if ($dental->is_approve == 1) {
                                        $dental_approve += $dental->amount_approved; 
                                    }
                                }
                             ?>
                            <td class="text-right p-3"><?php echo number_format($dental_claim,2); ?></td> 
                            <td class="text-right p-3"><?php echo number_format($dental_approve,2); ?></td>
                        </tr>

                        <tr>
                            <td class="p-3">14</td>
                            <td class="p-3">Special Allowance - Dressing</td>
                            <?php 
                                $dressing_claim   = 0;
                                $dressing_approve = 0;
                                if($dressing) foreach ($dressing as $key => $dressing) 
                                {
                                    $dressing_claim   += $dressing->amount_claim;
                                    if ($dressing->is_approve == 1) {
                                        $dressing_approve += $dressing->amount_approved; 
                                    }
                                }
                             ?>
                            <td class="text-right p-3"><?php echo number_format($dressing_claim,2); ?></td> 
                            <td class="text-right p-3"><?php echo number_format($dressing_approve,2); ?></td>
                        </tr>

                        <tr>
                            <td class="p-3">15</td>
                            <td class="p-3">Special Allowance - Gadget</td>
                            <?php 
                                $gadget_claim   = 0;
                                $gadget_approve = 0;
                                if($gadget) foreach ($gadget as $key => $gadget) 
                                {
                                    $gadget_claim   += $gadget->amount_claim;
                                    if ($gadget->is_approve == 1) {
                                        $gadget_approve += $gadget->amount_approved; 
                                    }
                                }
                             ?>
                            <td class="text-right p-3"><?php echo number_format($gadget_claim,2); ?></td> 
                            <td class="text-right p-3"><?php echo number_format($gadget_approve,2); ?></td>
                        </tr>
                        
                        <tr>
                            <td class="p-3">16</td>
                            <td class="p-3">Trainer / Facilitator</td>
                            <?php
                                $trainer_claim     = 0;
                                $trainer_approve   = 0;
                                if(!empty($trainers)) foreach($trainers as $key => $trainer)
                                {
                                    $trainer_claim += $trainer->amount;
                                    if($trainer->is_admin_approve == 1){
                                        $trainer_approve += $trainer->amount_approved;
                                    }
                                }
                            ?>
                            <td class="text-right p-3">
                                <?php echo number_format($trainer_claim,2); ?>
                            </td>
                            <td class="text-right p-3">
                                <?php echo number_format($trainer_approve,2); ?>
                            </td>
                        </tr>
                        
                        <tr>
                            <td class="p-3">17</td>
                            <td class="p-3">Panel</td>
                            <?php
                                $total_panel = 0;
                                if(!empty($panel_first_month)) foreach ($panel_first_month as $key => $panel) 
                                {
                                    $total_panel += $panel->amount;
                                }
                            ?>
                            <td class="text-right p-3"><?php echo number_format($total_panel,2); ?></td>
                            <td class="text-right p-3"><?php echo number_format($total_panel,2); ?></td>
                        </tr>
                        
                        <tr>
                            <td class="p-3">18</td>
                            <td class="p-3">Entertainment</td>
                            <?php
                                $total_entertainment = 0;
                                $total_entertainment_approve = 0;

                                if(!empty($entertainments)) foreach ($entertainments as $key => $entertainment) {
                                    $total_entertainment += $entertainment->amount;
                                    if($entertainment->is_approve == 1)
                                    {
                                        $total_entertainment_approve += $entertainment->amount_approved;
                                    }
                                }
                            ?>
                            <td class="text-right p-3"><?php echo number_format($total_entertainment,2); ?></td>
                            <td class="text-right p-3"><?php echo number_format($total_entertainment_approve,2); ?></td>
                        </tr>
                        
        <!-- changes made by Ariff 29/03/2021 -->
                        <?php 
                            $membership_claim = 0; 
                            $membership_approve = 0; 
                            $other_claim = 0; 
                            $other_approve = 0; 
                            if($others) foreach($others as $key => $other)
                            {
                                if($other->type == 'MEMBERSHIP')
                                {
                                    $membership_claim += $other->amount_claim;
                                    if($other->is_approve == 1)
                                    {
                                        $membership_approve += $other->amount_approved;
                                    }
                                }else
                                {
                                    $other_claim += $other->amount_claim;
                                    if($other->is_approve == 1)
                                    {
                                        $other_approve += $other->amount_approved;
                                    }
                                }
                            }
                        ?>

                        <tr>
                            <td class="p-3">19</td> 
                            <td class="p-3">Membership</td>
                            <td class="text-right p-3"><?php echo number_format($membership_claim,2); ?></td> 
                            <td class="text-right p-3"><?php echo number_format($membership_approve,2); ?></td>
                        </tr>

                        <tr>
                            <td class="p-3">20</td> 
                            <td class="p-3">Others</td>
                            <!-- <?php 
                                //$other_claim   = 0;
                                //$other_approve = 0;
                                //if($others) foreach ($others as $key => $other) {
                                    //$other_claim   += $other->amount_claim;
                                    //if ($other->is_approve == 1) {
                                        //$other_approve += $other->amount_approved; 
                                    //}
                                //}
                             ?> -->
                            <td class="text-right p-3"><?php echo number_format($other_claim,2); ?></td> 
                            <td class="text-right p-3"><?php echo number_format($other_approve,2); ?></td>
                        </tr>
                        
                    </tbody>
                    <tfoot>
                        <tr>
                            <th class="text-center">#</th>
                            <th class="text-center">Total</th>
                            <th class="text-right">
                                <?php 
                                    $total_claim = $outpatient_claim 
                                                    + $hospitalization_claim 
                                                    + $dental_claim 
                                                    + $mileage_claim 
                                                    + $other_claim 
                                                    + $membership_claim 
                                                    + $accomodation_claim 
                                                    + $transportation_claim
                                                    + $parking_claim
                                                    + $toll_claim
                                                    + $outstation_allowance
                                                    + $meal_allowance
                                                    + $travel_allowance
                                                    + $trainer_claim
                                                    + $total_panel
                                                    + $field_meal_allowance_claim
                                                    + $petrol_claim
                                                    + $total_entertainment
                                                    + $dressing_claim
                                                    + $gadget_claim;
                                    echo number_format($total_claim,2); 
                                ?>
                            </th>
                            <th class="text-right">
                                <?php 
                                    $total_approved = $outpatient_approve 
                                                        + $hospitalization_approve 
                                                        + $dental_approve 
                                                        + $other_approve 
                                                        + $membership_approve 
                                                        + $mileage_approved
                                                        + $accomodation_approved 
                                                        + $transportation_approved 
                                                        + $parking_approved
                                                        + $toll_approved
                                                        + $outstation_approved
                                                        + $meal_approved
                                                        + $travel_approved
                                                        + $trainer_approve
                                                        + $total_panel
                                                        + $field_meal_allowance_approved
                                                        + $petrol_approved
                                                        + $total_entertainment_approve
                                                        + $dressing_approve
                                                        + $gadget_approve;
                                    echo number_format($total_approved,2); 
                                ?>
                            </th>
        <!-- changes made by Ariff 29/03/2021 -->
                        </tr>
                    </tfoot>
                </table>
            </div>

        </div>
        <!-- claim summary -->
        
    </div>
</section> 

<?php if(empty($screen_mode)): ?>
    
    <!-- Modal claim type -->
    <div class="modal fade" id="modal_claim_type" 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">Select claim type</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <div class="row form-group">
                        <div class="col-lg-3">
                            <label for="claim_type">Claim type</label>
                        </div>
                        <div class="col">
                            <select class="form-control select" name="claim_type" id="claim_type">
                                <option value="-1" selected disabled>Select claim type</option>
                                <?php if(!empty($claimType)) foreach($claimType as $key => $row): ?>
                                    <option value="<?php echo $row['ID'] ?>" data-link="<?php echo base_url($row['form_location']); ?>"><?php echo $row['code'] ?></option>
                                <?php endforeach ?>     
                            </select>
                        </div>
                        <div class="col-lg-1">
                            <div class="btn-group float-right">
                                <a onclick="openClaimForm()" class="btn btn-info"><div class="text-white">Next</div></a>
                            </div>
                        </div>
                    </div>  
                </div>
            </div>
        </div>
    </div>
    <!-- Modal claim type -->

    <div class="modal fade" id="modal_reminder" role="dialog">
      <div class="modal-dialog modal-lg">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span>
            </button>
          </div>
          <div class="modal-body">
            <div class="row">
                <div class="col-12 col-md-2">
                    <img src="<?php echo base_url('assets/themes/web/img/reminder.png'); ?>" class="img img-fluid">
                </div>
                <div class="col-12 col-md-10">
                   <h6 class="text-uppercase text-muted"> Kindly reminder to submit your claim before <?php echo date('d-F-Y', strtotime('07-'.$month.'-'.$year)); ?></h6>
                </div>
            </div>
          </div>
        </div>
      </div>
    </div>

<?php endif ?>

<?php if(!empty($screen_mode)): ?>
    <?php if($screen_mode == 'admin'): ?>

        <!-- modal approve -->
        <div class="modal fade" id="mdl_approve" role="dialog" aria-hidden="true">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">Approve Claim</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>

                    <form class="form" id="approveForm">
                        <div class="modal-body container"> 
                            <div class="row form-group">
                                <div class="col">
                                    <label><b>Amount Claim</b></label>
                                    <div class="input-group mb-3">
                                    <div class="input-group-prepend">
                                        <span class="input-group-text bg-light">RM</span>
                                    </div>
                                    <input type="text" name="amount_claim" id="approveAmountClaim" class="form-control bg-light" placeholder="0.00" disabled>
                                        <div class="input-group-prepend">
                                            <button type="button" id="btn-toRight" class="btn btn-success">
                                                <i class="fas fa-arrow-right"></i>
                                            </button>
                                    </div>
                                    </div>

                                </div>
                                <div class="col">
                                    <label><b>Amount Approved</b></label>
                                    <div class="input-group mb-3">
                                    <div class="input-group-prepend">
                                        <span class="input-group-text bg-light">RM</span>
                                    </div>
                                    <input type="number" name="amount_approve" id="approveAmountApprove" class="form-control currency_input" placeholder="0.00" min="0" onchange="checkProrate()" onkeyup="checkProrate()" >
                                    </div>
                                </div>
                            </div>
                            
                            <div class="row d-none form-group">
                                <div class="col-lg-6">
                                    <label><b>Status</b></label> <br>
                                    <label>Approve</label>

                                    <select class="form-control d-none" name="status" id="approveStatus">
                                        <option value="1">Approve</option>
                                    </select>

                                </div>
                                <div class="col">
                                    <input type="hidden" name="approve_id" class="form-control" id="approveId">
                                    <input type="hidden" name="reason">
                                    

                                </div>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <div class="btn-group">
                                <a href="#" class="btn btn-info" data-placement="top" title="Edit OT" data-dismiss="modal"><i class="fas fa-ban"></i> Cancel</a>
                                <button type="submit" id="btn-saveApprove" data-rqtarget="" class="btn btn-success" data-toggle="tooltip" data-placement="top" title="Approve Claim">
                                    <i class="fas fa-save"></i> Save
                                </button>
                            </div>
                        </div>
                    </form>


                </div>
            </div>
        </div>
        <!-- modal approve -->

        <div class="modal fade" id="mdl_admin_reject" role="dialod" aria-hidden="true">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <h4>Rejects claim</h4>
                    </div> 
                    <form id="admin_modal_reject" >
                        <div class="modal-body">
                            <div class="row">
                                <div class="col">
                                    <label>Reason</label>
                                    <textarea class="form-control" style="min-height:150px;" name="reason"></textarea>
                                    <input type="hidden" name="approve_id" class="form-control" id="adminRejectId">
                                    <input type="hidden" name="amount_approve" value="0">
                                    <select class="form-control d-none" name="status">
                                        <!-- <option value="0">Draft </option> -->
                                        <!-- <option value="1">Approve</option> -->
                                        <option value="2">Rejected</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        
                        <div class="modal-footer">
                            <div class="row">
                                <div class="col mb-3 float-right">
                                    <a href="#" class="btn btn-info" data-placement="top" title="" data-dismiss="modal"><i class="fas fa-ban"></i> Cancel</a>
                                    <button type="submit" id="btn-saveRejectAdmin" data-rqtarget="" class="btn btn-success" data-toggle="tooltip" data-placement="top" title="Approve Claim">
                                        <i class="fas fa-save"></i> Save
                                    </button>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>

        <!-- modal approve -->
        <div class="modal fade" id="mdl_paid" role="dialog" aria-hidden="true">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">Approve</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>

                    <form class="form" id="" action="<?php echo base_url('/hr/claim_v2/claimPaid/'); ?>" method="post">
                        <div class="modal-body container"> 
                            <div class="row form-group">
                                <div class="col">
                                    <label><b>Amount Approved</b></label>
                                    <div class="input-group mb-3">
                                        <div class="input-group-prepend">
                                            <span class="input-group-text bg-light">RM</span>
                                        </div>
                                        <?php 
                                            $approved_outpatient        = (!empty($outpatient_approve))?$outpatient_approve:0 ;
                                            $approved_hospitalization   = (!empty($hospitalization_approve))?$hospitalization_approve:0;
                                            $approved_dental            = (!empty($dental_approve))?$dental_approve:0;
                                            $approved_medical           = (!empty($medical_approve))?$medical_approve:0;
                                            $approved_mileage           = (!empty($mileage_approve))?$mileage_approve:0;
                                            $approved_travel            = (!empty($travel_approve))?$travel_approve:0;
                                            $approved_meal              = (!empty($meal_approve))?$meal_approve:0;
                                            $approved_other             = (!empty($other_approve))?$other_approve:0;

                                            $approve_amount             =  number_format($approved_outpatient+$approved_hospitalization+$approved_dental+$approved_medical+$approved_mileage+$approved_travel+$approved_meal+$approved_other,2); 
                                        
                                        ?>
                                        <input type="number" name="amount_claim" id="mdlPaid_amount_approve" class="form-control bg-light" placeholder="0.00" value="<?php echo $approve_amount; ?>" disabled>
                                        <div class="input-group-prepend">
                                            <button type="button" id="mdlPaid_transfer" class="btn btn-success">
                                                <i class="fas fa-arrow-right"></i>
                                            </button>
                                        </div>
                                    </div>
                                </div>

                                <div class="col">
                                    <label><b>Amount Paid</b></label>
                                    <div class="input-group mb-3">
                                        <div class="input-group-prepend">
                                            <span class="input-group-text bg-light">RM</span>
                                        </div>
                                        <input type="number" name="amount_paid" id="mdlPaid_amount_paid" class="form-control currency_input" placeholder="0.00" value="<?php echo $approve_amount; ?>">
                                    </div>
                                </div>
                            </div>
                            <div class="row d-none">
                                <label><b>Claim Id </b></label>
                                <div class="input-group mb-3">
                                   <input type="text" name="claim_id" class="form-control" value="<?php echo $claim_id;?>">
                                </div>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <div class="btn-group">
                                <a href="#" class="btn btn-info" data-placement="top" title="Edit OT" data-dismiss="modal"><i class="fas fa-ban"></i> Cancel</a>
                                <button type="submit" data-rqtarget="" class="btn btn-success" data-toggle="tooltip" data-placement="top" title="Approve Claim">
                                    <i class="fas fa-save"></i> Save
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <!-- modal approve -->

    <?php endif ?>

    <?php if($screen_mode == 'hod'):?>

        <!-- modal reject -->
        <div class="modal" id="rejectModal">
            <div class="modal-dialog">
                <div class="modal-content">
                <form action="<?php echo base_url('hr/claim_v2/hodReject'); ?>" method="post">

                    <!-- Modal Header -->
                    <div class="modal-header">
                        <h4 class="modal-title">Reject Claim</h4>
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                    </div>

                    <!-- Modal body -->
                    <div class="modal-body">
                        <div class="row">
                            <div class="col">
                                <!-- id -->
                                <input type="hidden" name="id" class="form-control" placeholder="id" id="hdR_id">
                                <!-- claim id -->
                                <input type="hidden" name="claim_id" class="form-control" placeholder="claim id" id="hdR_claim_id"/>
                                <!-- mode -->
                                <input type="hidden" name="mode" class="form-control" placeholder="mode" id="hdR_mode">
                                <label><b>Reason</b></label><br>
                                <textarea name="reason" id="hdR_reason" rows="10" class="form-control" placeholder="Please Specify Reason for Claim Rejection" style="resize:none;" required></textarea>
                            </div>
                        </div>
                    </div>

                    <!-- Modal footer -->
                    <div class="modal-footer btn-group">
                        <button type="submit" class="btn btn-success">Submit</button>                    
                        <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
                    </div>

                </form>
                </div>
            </div>
        </div>
        <!-- modal reject -->
    <?php endif ?>

    <?php if($screen_mode == 'em'):?>

        <!-- modal reject -->
        <div class="modal" id="em_rejectModal">
            <div class="modal-dialog">
                <div class="modal-content">
                <form action="<?php echo base_url('hr/claim_v2/emReject'); ?>" method="post">

                    <!-- Modal Header -->
                    <div class="modal-header">
                        <h4 class="modal-title">Reject Claim</h4>
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                    </div>

                    <!-- Modal body -->
                    <div class="modal-body">
                        <div class="row">
                            <div class="col">
                                <!-- id -->
                                <input type="hidden" name="em_id" class="form-control" placeholder="id" id="em_hdR_id">
                                <!-- claim id -->
                                <input type="hidden" name="em_claim_id" class="form-control" placeholder="claim id" id="em_hdR_claim_id"/>
                                <!-- mode -->
                                <input type="hidden" name="em_mode" class="form-control" placeholder="mode" id="em_hdR_mode">
                                <label><b>Reason</b></label><br>
                                <textarea name="em_reason" id="em_hdR_reason" rows="10" class="form-control" placeholder="Please Specify Reason for Claim Rejection" style="resize:none;" required></textarea>
                            </div>
                        </div>
                    </div>

                    <!-- Modal footer -->
                    <div class="modal-footer btn-group">
                        <button type="submit" class="btn btn-success">Submit</button>                    
                        <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
                    </div>

                </form>
                </div>
            </div>
        </div>
        <!-- modal reject -->
    <?php endif ?>

<?php endif ?>

<script>
    var isContainer = true;

    $(document).ready(function()
    {
        <?php if(!empty($screen_mode)): ?>
            <?php if($screen_mode == 'hod' ): ?>
                $('#hodApprove').submit(function(event)
                {
                    event.preventDefault();
                    toastConfirm('Click yes to approve all claim for this submission',function(){
                        let data = 
                        {
                            year : <?php echo $this->uri->segment(4); ?>,
                            month: <?php echo $this->uri->segment(5); ?>,
                            user_id: <?php echo $this->uri->segment(6); ?>,
                            claim_id: <?php echo $this->uri->segment(7); ?>,
                            status: '1',
                        }
                        ajxRequest('<?php echo base_url('/hr/claim_v2/hodApprove/'); ?>', 'POST', data, '<?php echo current_url(); ?>');
                    });
                });
            <?php endif ?>

            <?php if($screen_mode == 'admin' ): ?>
                
                $('#btn-saveRejectAdmin').click(function(event)
                {
                    event.preventDefault();
                    var serialize = formIdToInputObject('#admin_modal_reject');
                    serialize.token = '<?php echo $_SESSION['token']; ?>';
                                
                    var locate = $(this).data('rqtarget');
                    var redirect    = '<?php echo current_url(); ?>';
                    ajxRequest(locate,'POST',serialize,redirect);
                });


                $('#btn-saveApprove').click(function(event)
                {
                    event.preventDefault();
                    var serialize = formIdToInputObject('#approveForm');
                    serialize.token = '<?php echo $_SESSION['token']; ?>';
                                
                    var locate = $(this).data('rqtarget');
                    var redirect    = '<?php echo current_url(); ?>';
                    ajxRequest(locate,'POST',serialize,redirect);
                });


                $('#btn-toRight').click(function()
                {
                    var amount_claim = $('#approveAmountClaim').val();
                    $('#approveAmountApprove').val(amount_claim);
                });

                $('#mdlPaid_transfer').click(function()
                {
                    let amount_approve = $('#mdlPaid_amount_approve').val();
                    $('#mdlPaid_amount_paid').val(amount_approve);
                });

                $('#paidClaim').submit(function(event)
                {
                    event.preventDefault();
                    toastConfirm('Are you sure you want to set this to complete',function()
                    {
                        $('#mdl_paid').modal();
                    });
                });
            <?php endif ?>
        <?php else: ?>
            <?php
                if($month == date('m') && date('d') < 8 && date('d') > 4 && $year == date('Y') && $claims->is_submit == 0):
            ?>
                $('#modal_reminder').modal({
                    show:true
                });
            <?php endif; ?>
        <?php endif ?>
    });


    <?php if($screen_mode == 'admin' ): ?>
        //admin approval claim button
        //fill up modal form
        function approveClaim(elem)
        {
            toastConfirm('You are going to approve this claim and will require to enter approved amount',function(){

                $('#approveForm').trigger("reset");
                $('#mdl_approve').modal('toggle');

                var amount_claim = $(elem).data('price');
                var mileage_claim= $(elem).data('mileage');

                $('#approveAmountApprove').val(amount_claim);

                //only for travelling situation 
                // if(!mileage_claim)
                // {
                //     mileage_claim = 0;
                // }
                
                // var amount_claim = parseFloat(amount_claim) + parseFloat(mileage_claim); //kalau 3 angka
                var url          = '<?php echo base_url('hr/api/claim_v2/');?>'+$(elem).data('rqtarget');
                var status       = $(elem).data('status');
                var id           = $(elem).data('id');

                var allocation   = $(elem).data('allocation');
                var balanced     = $(elem).data('balanced'); 

                $('#btn-saveApprove').attr('data-rqtarget',url);
                $('#approveId').val(id);
                $('#approveAmountClaim').val(amount_claim);
                // $('#approveStatus').val(status);
                
                $('#mdl-allocation').html('RM'+allocation);
                $('#mdl-prorateBalanced').html('RM'+balanced);
            });
        }

        function rejectClaim(elem) 
        {
            toastConfirm('Are you sure you want to reject this claim?',function(){
                $('#mdl_admin_reject').modal('toggle');

                var amount_claim = $(elem).data('price');
                var mileage_claim= $(elem).data('mileage');

                var url          = '<?php echo base_url('hr/api/claim_v2/');?>'+$(elem).data('rqtarget');
                var status       = $(elem).data('status');
                var id           = $(elem).data('id');

                var allocation   = $(elem).data('allocation');
                var balanced     = $(elem).data('balanced'); 

                $('#btn-saveRejectAdmin').attr('data-rqtarget',url);
                $('#adminRejectId').val(id);
                $('#rejectAmountClaim').val(0);

            });
        }
        
    <?php else: ?>
        <?php if($screen_mode == 'hod'){ ?>
            //hod approval
            function hodApproval(elem)
            {
                console.log('hod approval');
                let claim_id    = $(elem).data('claim-id');
                let mode        = $(elem).data('mode');

                let url     = '<?php echo base_url('hr/claim_v2/hodApprove/'); ?>'+mode;
                let type    = 'POST';
                let data    = 
                {
                    claim_id: claim_id,
                    mode: mode
                };
                let redirect = '<?php echo current_url(); ?>';
                ajxRequest(url, type, data, redirect);        
            }

            function hodReject(elem)
            {
                console.log('rejecting ');
                let id          = $(elem).data('id');
                let claim_id    = $(elem).data('claim-id');
                let mode        = $(elem).data('mode');

                $('#hdR_id').val(id);
                $('#hdR_claim_id').val(claim_id);
                $('#hdR_mode').val(mode);
            }

        <?php } else if($screen_mode == 'em'){ ?>
            //em approval
            function emApproval(elem)
            {
                console.log('em approval');
                let claim_id    = $(elem).data('claim-id');
                let mode        = $(elem).data('mode');

                let url     = '<?php echo base_url('hr/claim_v2/emApprove/'); ?>'+mode;
                let type    = 'POST';
                let data    = 
                {
                    claim_id: claim_id,
                    mode: mode
                };
                let redirect = '<?php echo current_url(); ?>';
                ajxRequest(url, type, data, redirect);        
            }

            function emReject(elem)
            {
                console.log('rejecting');
                let id          = $(elem).data('id');
                let claim_id    = $(elem).data('claim-id');
                let mode        = $(elem).data('mode');

                $('#em_hdR_id').val(id);
                $('#em_hdR_claim_id').val(claim_id);
                $('#em_hdR_mode').val(mode);
            }

        <?php } else { ?>
            //own claim
            function closeModal()
            {
                $('#modal_claim_travelling').modal('hide');
            }

            function openClaimForm()
            {
                var link = $('#claim_type').find(':selected').data('link');

                /* changes made by Ariff 29/03/2021 */
                var type_id = $('#claim_type').find(':selected').val();

                if(link != '<?php echo base_url(); ?>')
                {
                    if(type_id == 26)
                    {
                        window.location.href = link+'/'+'<?php echo $this->uri->segment(4); ?>'+'/'+'<?php echo $this->uri->segment(5); ?>'+'/'+'<?php echo $this->uri->segment(6); ?>'+'/'+'<?php echo $this->uri->segment(7); ?>'+'/membership';
                    }else{
                        window.location.href = link+'/'+'<?php echo $this->uri->segment(4); ?>'+'/'+'<?php echo $this->uri->segment(5); ?>'+'/'+'<?php echo $this->uri->segment(6); ?>'+'/'+'<?php echo $this->uri->segment(7); ?>';
                    }
                }
                /* changes made by Ariff 29/03/2021 */
            }

            function deleteClaim(elem)
            {
                toastConfirm('Are you sure you want to remove this claim from your list',function(){
                    var id          = $(elem).data('id');
                    var locate      = '<?php echo base_url('/hr/api/claim_v2/'); ?>'+$(elem).data('rqtarget');
                    var redirect    = '<?php echo current_url(); ?>';
                    var data        = {
                        token       : '<?php echo $_SESSION['token']; ?>',
                        id          : id,
                    }
                    ajxRequest(locate,'POST',data, redirect);
                })
            }
        <?php } ?>
    <?php endif ?>
    
</script>