<!DOCTYPE html>
<html>
<head>
    <title>Leave Settlement List</title>
</head>
<body>
    <div class="">
        <div class="col-7">
            <br>
      <div class="h3" style="margin-top: 0;margin-bottom: 0;">
                    <?php echo "LEAVE SETTLEMENT LIST"; ?>
                </div>
        </div>
        <div class="col-5 offset-1" style="color:#101010;">
            <div class="text-right">
            <img src="<?php echo  'images/'.Yii::app()->user->company_logo; ?>" class="logo" style="height: 60px">
            </div>
            <br>
         </div>
    </div>
    <br>
<div class="col-md-12">
        <table id="" class="table">
            <thead>
                <tr>
                    <th class="text-center">No</th>
                    <th class="text-center">ID</th>
                    <th class="text-center">Employee Name</th>
                    <th class="text-center">Salary</th>
                    <th class="text-center">Due Days</th>
                    <th class="text-center">Amount</th>
                </tr>
            </thead>
            <tbody>
        <tr>
         <?php
        $condition ='t.isActive="Y"';
        if($branch_id>0){
            $condition.=' and branch_or_sponsor_id = "'.$branch_id.'"';
        }  
        $model_employee = Employee::model()->findAll(array('condition' =>$condition));
        $arr_employee=array();
        foreach ($model_employee as $key => $value) {
            $arr_employee[$this->ciphertext($value->first_name,"d").' '.$this->ciphertext($value->last_name,"d")]=$value->id;
        }
        ksort($arr_employee); 
        $current_date=date('Y-m-d');
        if(!empty($arr_employee)){      
            $n=1;
            foreach ($arr_employee as $k => $id){
                $model = Employee::model()->findbyPk($id);
                $salary_amount=0.00;       
                $leave_settlement_amount=0.00;
                $leave_count=0;
                $model_leave = EmployeeLeave::model()->with('leavetype')->find(array('select'=>'leave_current_balance','condition' => 't.employee_id="'.$model['id'].'" and encashable="Y" AND leave_year="'.date('Y').'"'));
                if($model_leave->leave_current_balance>0){
                    $leave_count=$model_leave->leave_current_balance;
                }
                $model_salary = EmployeeSalary::model()->find(array('select'=>'sum(amount) as amount','condition' => 'employee_id="'.$model['id'].'" AND consider_for_leave_payment="Y" AND (("'.$current_date.'" BETWEEN valid_from AND valid_to) OR (valid_from <= "'.$current_date.'" AND valid_to="0000-00-00"))'));
                if($model_salary->amount>0){
                    $salary_amount=$model_salary->amount;
                    $employee_per_day_salary = round($salary_amount/30, 2);
                    $leave_settlement_amount=$leave_count*$employee_per_day_salary;
                }   
										
            ?>
                <tr>
                    <td><?php echo $n;?></td>
                    <td><?php echo $this->ciphertext($model['employee_code'],"d"); ?></td>
                    <td><?php echo $this->ciphertext($model['first_name'],"d").' '.$this->ciphertext($model['last_name'],"d"); ?></td>				    
                    <td class="text-right"><?php echo Yii::app()->numberFormatter->formatCurrency($salary_amount,"");?></td> 
                    <td class="text-right"><?php echo $leave_count;?></td>
                    <td class="text-right"><?php echo Yii::app()->numberFormatter->formatCurrency($leave_settlement_amount,"");?></td>  
				
				 
                  </tr>
			<?php 
                        $n++;
                        
                        } 
            }
                ?>
            </tbody>
        </table>
     
    </div>
    <htmlpagefooter name="myfooter" class="newfoot">
        <div style="border-top: 1px dotted #000000; font-size: 12px; text-align: center; padding-top: 10px; background-color: #d7faeb;">
               <div style="text-align:center;width:100%;font-size:10px;"><?= Yii::app()->user->footer_autogenerated; ?>
        <?php
                  date_default_timezone_set("Asia/Dubai");
                 echo date('d/m/Y')." ".date("h:i:sa"); ?>
    </div>
<br>
            <div style="text-align:center;width:100%">
                <b><?= Yii::app()->user->footer_line_1 ?></b><br>
                <?= Yii::app()->user->footer_line_2 ?>
            </div>
            <div style="text-align:center;width:100%">Page {PAGENO} of {nb} </div>
        </div>
    </htmlpagefooter>
</body>

</html>
