<?php 

    if(ENVIRONMENT == 'production'){
        $mgs  = "mgs/projects/job/";
    } else if(ENVIRONMENT == 'development'){
        $mgs  = "mgs.dev/projects/job/";
    }

    $mgs_link = base_url('../'.$mgs);

?>
<?php if(!empty($trainers)) foreach($trainers as $key => $value): ?>
    <tr class="border-bottom">
        <td>
            <div class="row py-1">
                <div class="col text-right">
                    <?php if($is_in_submission_range): ?>
                        <?php if($screen_mode == 'hod'){ ?>
                            <button class="btn btn-success btn-sm" 
                                data-trigger="hover" 
                                data-tooltip="tooltip" title="Approve Claim" 
                                data-original-title="Approve Claim" 
                                data-claim-id="<?php echo $value->id; ?>" 
                                data-mode="14" 
                                onclick="hodApproval(this)"
                                >
                                <i class="fas fa-thumbs-up" style="transform: scaleX(-1);"></i>    
                            </button>
                            <!-- button reject -->
                            <button class="btn btn-danger btn-sm" 
                                data-trigger="hover" 
                                data-tooltip="tooltip" 
                                title="Reject Claim" 
                                data-original-title="Reject Claim" 
                                data-id="<?php echo $value->id; ?>"
                                data-claim-id="<?php echo $value->claim_id; ?>" 
                                data-mode="14" 
                                data-toggle="modal" 
                                data-target="#rejectModal"
                                onclick="hodReject(this)"
                                >
                                <i class="fas fa-thumbs-down"></i>
                            </button>
                            <!-- button reject -->
                        <?php } else if($screen_mode == 'em'){ ?>
                            <?php if($value->lead && ($value->lead[0]->staff_id != $value->user_id)){ ?>
                                <span class="btn btn-warning btn-sm" data-tooltip="tooltip" data-original-title="You are Engagement Manager / Team Leader for this Job ID"><i class="fas fa-users"></i> EM / Team Leader</span>
                                <button class="btn btn-success btn-sm" 
                                    data-trigger="hover" 
                                    data-tooltip="tooltip" title="Approve Claim" 
                                    data-original-title="Approve Claim" 
                                    data-claim-id="<?php echo $value->id; ?>" 
                                    data-mode="14" 
                                    onclick="emApproval(this)"
                                    >
                                    <i class="fas fa-thumbs-up" style="transform: scaleX(-1);"></i>    
                                </button>
                                <!-- button reject -->
                                <button class="btn btn-danger btn-sm" 
                                    data-trigger="hover" 
                                    data-tooltip="tooltip" 
                                    title="Reject Claim" 
                                    data-original-title="Reject Claim" 
                                    data-id="<?php echo $value->id; ?>"
                                    data-claim-id="<?php echo $value->claim_id; ?>" 
                                    data-mode="14" 
                                    data-toggle="modal" data-target="#em_rejectModal"
                                    onclick="emReject(this)"
                                    >
                                    <i class="fas fa-thumbs-down"></i>
                                </button>
                                <!-- button reject -->
                            <?php } ?>
                        <?php } else { ?>
                            <?php if(empty($screen_mode)):?>
                                <button class="btn btn-danger btn-sm" 
                                    data-rqtarget="removeTrainer" 
                                    data-id="<?php echo $value->id; ?>" 
                                    onclick="deleteClaim(this)" 
                                    data-trigger="hover" 
                                    data-tooltip="tooltip" 
                                    title="" 
                                    data-original-title="Remove Claim" <?php echo ($disabled || !empty($claims->is_submit))?'disabled':''; ?>
                                >
                                    <i class="fa fa-trash-alt"></i>
                                </button>
                            <?php endif; ?>
                        <?php } ?>
                    <?php endif; ?>
                    
                    <?php if($screen_mode == 'admin'): ?>   
                        <?php if(($value->is_hod_approve == 0 || $value->is_hod_approve == 2) && ($value->is_em_approved == 0 || $value->is_em_approved == 2)): ?>
                            <div class="text-danger">claim has not been approved or rejected by EM/HOD</div>
                        <?php endif; ?>
                            <button 
                                class="btn btn-success btn-sm text-white" 
                                onclick="approveClaim(this)" 
                                data-price="<?php echo $value->amount; ?>" 
                                data-mileage=""
                                data-rqtarget="approveTrainer" 
                                data-id="<?php echo $value->id; ?>" 
                                data-status="<?php echo $value->is_admin_approve; ?>" 
                                data-allocation="status" 
                                data-balanced="balanced" 
                                data-trigger="hover" 
                                data-tooltip="tooltip" 
                                title="" 
                                data-original-title="Approve Claim">
                                <i class="fas fa-thumbs-up" style="transform: scaleX(-1);"></i>
                            </button>

                            <button 
                                class="btn btn-danger btn-sm text-white" 
                                onclick="rejectClaim(this)" 
                                data-price="<?php echo number_format($value->amount,2); ?>" 
                                data-mileage=""
                                data-rqtarget="approveTrainer" 
                                data-id="<?php echo $value->id; ?>" 
                                data-status="<?php echo $value->is_admin_approve; ?>" 
                                data-allocation="status" 
                                data-balanced="balanced" 
                                data-trigger="hover" 
                                data-tooltip="tooltip" 
                                title="" 
                                data-original-title="Approve Claim">
                                <i class="fas fa-thumbs-down"></i>
                            </button>
                    <?php endif; ?>
                </div>
            </div>

            <div class="row py-1">
                <div class="col text-primary">
                    <h4>Trainer / Facilitator</h4>
                    <?php echo date('d-F-Y',strtotime($value->date)); ?>
                </div>
            </div>
        
            <div class="row">
                <div class="col-12 col-md-10">
                    
                    <div class="row">
                        <div class="col-2">
                            <b>Job ID</b>
                        </div>
                        <div class="col">
                            <?php if($value->job){ 

                                $team_leader = $this->job_v2->get_team_leader($value->job[0]->id);

                                echo '<i class="fas fa-file-alt text-warning"></i> ';
                                echo '<b><a href="'.$mgs_link.$value->job[0]->id.'/'.$value->job[0]->departmentID.'" target="_blank"> ['.$value->job[0]->id.'] '.$value->job[0]->customerName.' - '.$value->job[0]->description.'</a></b>';
                                echo '<br><small><i> Lead by : '.$team_leader[0]->staff_name.' - '.$team_leader[0]->department_name.'['.$team_leader[0]->branch_name.']</i></small>';
                            } ?>
                        </div>
                    </div><br>

                    <div class="row">
                        <div class="col-12 col-md-12">
                            <div class="row">
                                <div class="col-md-2">
                                    <b>Status (EM)</b>
                                </div>
                                <div class="col-md-2">
                                    <?php if ($value->is_em_approved == 0): ?>
                                        <span class="badge badge-secondary">Draft</span>
                                    <?php endif ?>

                                    <?php if ($value->is_em_approved == 1): ?>
                                        <span class="badge badge-success">Approved</span>
                                    <?php endif ?>

                                    <?php if ($value->is_em_approved == 2): ?>
                                        <span class="badge badge-danger">Rejected</span>
                                    <?php endif ?>
                                </div>
                                <div class="col-md-2">
                                    <b title="HOD">Status (HOD)</b>
                                </div>
                                <div class="col-md-2">
                                    <?php if ($value->is_hod_approve == 0): ?>
                                        <span class="badge badge-secondary">Draft</span>
                                    <?php endif ?>

                                    <?php if ($value->is_hod_approve == 1): ?>
                                        <span class="badge badge-success">Approved</span>
                                    <?php endif ?>

                                    <?php if ($value->is_hod_approve == 2): ?>
                                        <span class="badge badge-danger">Rejected</span>
                                    <?php endif ?>
                                </div>
                                <div class="col-md-2">
                                    <b>Status (Admin)</b>
                                </div>
                                <div class="col-md-2">
                                    <?php if ($value->is_admin_approve == 0): ?>
                                        <span class="badge badge-secondary">Draft</span>
                                    <?php endif ?>

                                    <?php if ($value->is_admin_approve == 1): ?>
                                        <span class="badge badge-success">Approved</span>
                                    <?php endif ?>

                                    <?php if ($value->is_admin_approve == 2): ?>
                                        <span class="badge badge-danger">Rejected</span>
                                    <?php endif ?>
                                </div>
                            </div>
                        </div>
                    </div><br>

                    <div class="row">
                        <div class="col-lg-2"><b>Title</b></div>
                        <div class="col">
                            <?php echo $value->title; ?>
                        </div>
                    </div>
                
                    <div class="row">
                        <div class="col-lg-2"><b>Start At : </b></div>
                        <div class="col"><?php echo date('h:i a',strtotime($value->start_at)); ?></div>
                        <div class="cl-lg-2"><b>End At : </b></div>
                        <div class="col"><?php echo date('h:i a',strtotime($value->end_at)); ?></div>
                    </div>
                
                    <div class="row">
                        <div class="col-lg-2"><b>Type</b></div>
                        <div class="col">
                            <?php if(!empty($value->type) && $value->type == 1): ?>
                                External Training
                            <?php else: ?>
                                Inhouse Training
                            <?php endif; ?>
                        </div>
                    </div>
                
                    <div class="row">
                        <div class="col-lg-2"><b>Remarks</b></div>
                        <div class="col" style="min-height:100px;">
                            <?php if($value->is_hod_approve == 2): ?>
                                <?php if(!empty($value->hod_remarks)): ?>
                                    <b>[HOD] : </b> <?php echo $value->hod_remarks; ?>
                                <?php endif; ?>
                            <?php endif; ?>

                            <?php if($value->is_em_approved == 2): ?>
                                <?php if(!empty($value->em_remarks)): ?>
                                    <b>[EM] : </b> <?php echo $value->em_remarks; ?>
                                <?php endif; ?>
                            <?php endif; ?>

                            <?php if($value->is_admin_approve == 2): ?>
                                <?php if(!empty($value->admin_remarks)): ?>
                                    <b>[ADMIN] : </b> <?php echo $value->admin_remarks; ?>
                                <?php endif; ?>
                            <?php endif; ?>

                        </div>
                    </div>
                
                    <div class="row">
                        <div class="col-lg-2"><b>Attachments</b></div>
                        <div class="col">
                            <ol>
                                <?php foreach($value->attachments as $att_key => $att_val): ?>
                                    <li>
                                        <a href="<?php echo base_url('hr/claim/openAttachment/'.$att_val->unique_id.'/TRAINER'); ?>" target="_blanl"><?php echo $att_val->attachment_name;?></a><br>
                                        <small><?php echo $att_val->description; ?></small>
                                    </li>
                                <?php endforeach; ?>
                            </ol>
                        </div>
                    </div>

                    <?php
                        if(!empty($value->movements))
                        {
                            $staff_movements = unserialize($value->movements);
                        }
                    ?>

                    <?php if(!empty($staff_movements)): ?>
                    <div class="row">
                        <div class="col-12 col-lg-2"><b>Staff Movements</b></div>
                        <div class="col-12 col-lg-10 table-responsive">
                            <table class="table table-bordered">
                                <thead>
                                    <tr>
                                        <th>Date</th>
                                        <th>Client</th>
                                        <th>Description</th>
                                        <th>Type</th>
                                        <th>Time Out</th>
                                        <th>Time In</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php foreach($staff_movements as $key => $movement):?>
                                        <tr>
                                            <td><?php echo date('d-m-Y',strtotime($movement['movement_date'])); ?></td>
                                            <td><?php echo $movement['client'].' '.$movement['destination']; ?></td>
                                            <td><?php echo $movement['description']; ?></td>
                                            <td><?php echo $movement['movement_type']; ?></td>
                                            <td><?php echo $movement['timeOut']; ?></td>
                                            <td><?php echo $movement['timeIn']; ?></td>
                                        </tr>
                                    <?php endforeach;?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <?php endif;?>
                    
                </div>
                <div class="col-12 col-md-2">

                    <div class="row py-1 border-bottom" style="background-color:bisque;">
                        <div class="col">
                            <b>Claim (RM)</b>
                            <h1><?php echo number_format($value->amount,2); ?></h1>
                        </div>
                    </div>

                    <div class="row py-1 border-bottom" style="background-color:bisque">
                        <div class="col">
                            <b>Amount Approve (RM)</b>
                            <h1><?php echo number_format($value->amount_approved,2); ?></h1>
                        </div>
                    </div>

                </div>
            </div>
        </td>
    </tr>
<?php endforeach; ?>