<section class="container">
    <div class="row">
        
        <div class="col mb-3">
            <div class="card bg-light-transparent">
                <div class="card">
                    <div class="card-header bg white">
                        <?php echo $dept_name; ?>
                        <button id="btnShowFilters" type="button" class="btn btn-outline-dark btn-sm collapsed float-right" data-trigger="hover" title="Show Filters Box" data-toggle="collapse" data-target="#collapseFilter" aria-expanded="false">
                            <i class="fas fa-filter"></i> Show Filters
                        </button>
                    </div>
                </div>

                <div class="collapse" id="collapseFilter">
                    <div class="card-header">
                        <div class="row">
                            <div class="col">
                                <div class="card no-shadow">
                                    <div class="card-body">

                                        <div class="row">
                                            <label class="col">
                                                Year
                                            </label>                           
                                            <div class="col" >
                                                <select class="form-control" id="filter_year">
                                                   <?php
                                                    for ($i=0; $i <= 5; $i++) { 
                                                        $yr = date('Y');
                                                        $yr = $yr-$i;
                                                    ?>
                                                       <option value="<?php echo $yr; ?>" <?php echo ($year == $yr)?'selected':''; ?>><?php echo $yr; ?></option>
                                                    <?php
                                                    }
                                                   ?>
                                                </select>
                                            </div>


                                            <label class="col">Month</label>
                                            <div class="col">
                                                <select class="form-control" id="filter_month">
                                                    <option value="01" <?php echo ($month == '01')?'selected':''; ?>>January</option>
                                                    <option value="02" <?php echo ($month == '02')?'selected':''; ?>>February</option>
                                                    <option value="03" <?php echo ($month == '03')?'selected':''; ?>>March</option>
                                                    <option value="04" <?php echo ($month == '04')?'selected':''; ?>>April</option>
                                                    <option value="05" <?php echo ($month == '05')?'selected':''; ?>>May</option>
                                                    <option value="06" <?php echo ($month == '06')?'selected':''; ?>>June</option>
                                                    <option value="07" <?php echo ($month == '07')?'selected':''; ?>>July</option>
                                                    <option value="08" <?php echo ($month == '08')?'selected':''; ?>>August</option>
                                                    <option value="09" <?php echo ($month == '09')?'selected':''; ?>>September</option>
                                                    <option value="10" <?php echo ($month == '10')?'selected':''; ?>>October</option>
                                                    <option value="11" <?php echo ($month == '11')?'selected':''; ?>>November</option>
                                                    <option value="12" <?php echo ($month == '12')?'selected':''; ?>>December</option>
                                                </select>
                                            </div>
                                        </div>

                                        <div class="row">
                                            <label class="col">Department</label>
                                            <div class="col">
                                                <select class="form-control" id="filter_dept_id">
                                                    <option value="0">All</option>
                                                    <?php foreach ($departments as $key => $department) {
                                                    ?>
                                                    <option value="<?php echo $department['id']; ?>" <?php echo ($department['id'] == $dept_id)?'selected':''; ?> ><?php echo $department['name'].' ('.$department['branch_name'].') '?></option>
                                                    <?php }?>
                                                </select>
                                            </div>

                                            <label class="col">Status</label>
                                            <div class="col">
                                                <select class="form-control" id="filter_status">
                                                    <option value="0">Incomplete</option>
                                                    <option value="1">Complete</option>
                                                </select>
                                            </div>
                                        </div>

                                       
                                        <div class="row">
                                            <div class="col d-print-none">
                                                <button class="btn btn-info" id="searchBtn" onclick="filterSubmittedClaim()" >Search</button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div> 

                <div class="card-body">
                    <div class="card no-shadow">
                        <div class="card-body">
                            <h4>Submitted Claims</h4>
                            <div class="table-responsive">
                                <table class="table table-bordered">
                                    <thead>
                                        <tr>
                                            <th>Name</th>
                                            <th>Month</th>
                                            <th>Year</th>
                                            <th></th>
                                        </tr>
                                    </thead>
                                    <tbody>

                                        <?php if(!empty($claims)): ?>
                                            <?php foreach($claims as $claim): ?>
                                                <tr>
                                                    <td>
                                                        <?php echo (!empty($claim->name))?$claim->name:''; ?>
                                                    </td>
                                                    <td>
                                                        <?php echo (!empty($claim->month))?date('F ',strtotime('01-'.$claim->month.'-'.$claim->year)):''; ?>
                                                    </td>
                                                    <td>
                                                        <?php echo (!empty($claim->year))?date('Y',strtotime('01-'.$claim->month.'-'.$claim->year)):''; ?>
                                                    </td>
                                                    <td class="text-center">
                                                        <div class="btn-group">
                                                            <a class="btn btn-primary btn-sm" href="<?php echo base_url('/hr/claim_v2/adminClaimDetail/'.$claim->year.'/'.$claim->month.'/'.$claim->user_id.'/'.$claim->id.'/approval-admin'); ?>" data-trigger="hover" data-tooltip="tooltip" title="" data-original-title="View staff claim" target="_blank"><i class="fas fa-eye"></i></a>
                                                            <!-- <button class="btn btn-success btn-sm text-white" data-trigger="hover" data-tooltip="tooltip" title="" data-original-title="change status to paid" data-toggle="modal" data-target="#paidModal"><i class="far fa-money-bill-alt"></i></button> -->
                                                        </div>
                                                    </td>
                                                </tr>
                                            <?php endforeach ?>
                                        <?php endif ?>

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

                            <?php if(!empty($unsubmitted_dentals)): ?>
                                <div class="row">
                                    <div class="col-12 mt-3">
                                        <hr>
                                        <h4>Not submitted dentals and optical claims</h4>
                                        <div class="table-responsive">
                                            <table class="table table-bordered">
                                                <thead>
                                                    <tr>
                                                        <th>Name</th>
                                                        <th>Month</th>
                                                        <th>Year</th>
                                                        <th></th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    <?php foreach($unsubmitted_dentals as $key => $dental): ?>
                                                        <tr>
                                                            <td style="background-color:bisque;"><?php echo $dental->name; ?></td>
                                                            <td style="background-color:bisque;"><?php echo (date('F',strtotime('01-'.$dental->month.'-'.$dental->year)))?></td>
                                                            <td style="background-color:bisque;"><?php echo (date('Y',strtotime('01-'.$dental->month.'-'.$dental->year)))?></td>
                                                            <td class="text-center" style="background-color:bisque;">
                                                                <a 
                                                                    class="btn btn-primary btn-sm" 
                                                                    href="<?php echo base_url('/hr/claim/adminClaimDetail/'.$dental->year.'/'.$dental->month.'/'.$dental->user_id.'/'.$dental->submission_month_claim_id.'/approval-admin'); ?>" 
                                                                    data-trigger="hover" data-tooltip="tooltip" title="" data-original-title="View staff claim" target="_blank"><i class="fas fa-eye"></i></a>

                                                            </td>
                                                        </tr>
                                                    <?php endforeach; ?>
                                                </tbody>
                                            </table>
                                        </div>
                                    </div>
                                </div>
                            <?php endif; ?>

                            <?php if(!empty($unsubmitted_outpatiens)): ?>
                                <div class="row">
                                    <div class="col-12 mt-3">
                                        <hr>
                                        <h4>Not submitted outpatients claims</h4>
                                        <div class="table-responsive">
                                            <table class="table table-bordered">
                                                <thead>
                                                    <tr>
                                                        <th>Name</th>
                                                        <th>Month</th>
                                                        <th>Year</th>
                                                        <th></th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    <?php foreach($unsubmitted_outpatiens as $key => $outpatient): ?>
                                                        <tr>
                                                            <td style="background-color:bisque;"><?php echo $outpatient->name; ?></td>
                                                            <td style="background-color:bisque;"><?php echo (date('F',strtotime('01-'.$outpatient->month.'-'.$outpatient->year)))?></td>
                                                            <td style="background-color:bisque;"><?php echo (date('Y',strtotime('01-'.$outpatient->month.'-'.$outpatient->year)))?></td>
                                                            <td class="text-center" style="background-color:bisque;">
                                                                <a 
                                                                    class="btn btn-primary btn-sm" 
                                                                    href="<?php echo base_url('/hr/claim/adminClaimDetail/'.$outpatient->year.'/'.$outpatient->month.'/'.$outpatient->user_id.'/'.$outpatient->submission_month_claim_id.'/approval-admin'); ?>" 
                                                                    data-trigger="hover" data-tooltip="tooltip" title="" data-original-title="View staff claim" target="_blank"><i class="fas fa-eye"></i></a>

                                                            </td>
                                                        </tr>
                                                    <?php endforeach; ?>
                                                </tbody>
                                            </table>
                                        </div>
                                    </div>
                                </div>
                            <?php endif; ?>


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

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


<!-- paid Modal -->
<div class="modal fade" id="paidModal" tabindex="-1" role="dialog" aria-hidden="true">
  <div class="modal-dialog modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="paidModalTitle">Change status to paid</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
        <form action="<?php echo base_url('/'); ?>" method="post">
            <div class="modal-body">
                
                <div class="row">
                    <div class="col-2">
                        <label><b>Name</b></label>
                    </div>
                    <div class="col">
                        <b>:</b> Farouq Zakwan bin Zulkifli
                    </div>
                </div>

                <div class="row">
                    <div class="col-2">
                        <label><b>Department</b></label>
                    </div>
                    <div class="col">
                        <b>:</b> IT (Corporate Center)
                    </div>
                </div>
                
                <div class="row">
                    <div class="col-2">
                        <label><b>Submission</b></label>
                    </div>
                    <div class="col">
                        <b>:</b> January 2019
                    </div>
                </div>

                <div class="row">
                    <div class="col-2">
                        <label><b>Claim (RM)</b></label>
                    </div>
                    <div class="col">
                        <b>:</b> 500.00
                    </div>
                </div>

                <div class="row">
                    <div class="col-2">
                        <label><b>Approve (RM)</b></label>
                    </div>
                    <div class="col">
                        <b>:</b> 500.00
                    </div>
                </div>

                <div class="row">
                    <div class="col-2">
                        <label><b>Paid (RM)</b></label>
                    </div>
                    <div class="col">
                        <input type="number" class="form-control" value="500.00" />
                    </div>
                </div>

            </div>
            <div class="modal-footer btn-group">
                <button type="button" class="btn btn-outline-secondary" data-dismiss="modal">cancel</button>
                <button type="submit" class="btn btn-outline-primary">Change Status</button>
            </div>
        </form>
    </div>
  </div>
</div>

<script>
    function filterSubmittedClaim() 
    {
        let year    = $('#filter_year').val();
        let month   = $('#filter_month').val();
        let dept_id = $('#filter_dept_id').val(); 
        let status  = $('#filter_status').val();

        window.location.href = '<?php echo base_url('hr/claim_v2/adminClaimList/'); ?>'+year+'/'+month+'/'+dept_id+'/'+status;
        console.log('submitted claims : '+year+' '+month+' '+dept_id+' '+status);    
    }
</script>