<!DOCTYPE html>
<html>
<head>
    <title>Gratuity List</title>
</head>
<body>
    <div class="">
        <div class="col-6">
            <br>
      <div class="h3" style="margin-top: 0;margin-bottom: 0;">
                    <?php echo "EMPLOYEE GRATUITY 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">Date of Joining</th>
                    <th class="text-center">Service(Yrs)</th>
                    <th class="text-center">Contract Type</th>
                    <th class="text-center">Basic</th>
                    <th class="text-center">Total Salary</th>
                    <th class="text-center">Gratuity</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); 
        if(!empty($arr_employee)){   
            $n=1;
            foreach ($arr_employee as $k => $id){
                $model = Employee::model()->findbyPk($id);
		$current_date=date('Y-m-d');
                $service_period="-";
                $years="-";
                $date_join="-";		
                $service_days=0;
                $service_period_1="";
		if($model['date_join']!='0000-00-00' && $model['date_join']!=''){
                    $date_join = date("d/m/Y", strtotime($model['date_join']));
                    $d1 = strtotime($model['date_join']);
                    $d2 = strtotime($current_date);
                    $datediff = $d2 - $d1;
                    $service_days = $datediff / (60 * 60 * 24)+1;
                    $years= round($service_days/365,1);	 
                    $date1 = new DateTime($model['date_join']);
                    $date2 = new DateTime($current_date); 
                    $dd = date_diff($date1,$date2);
                    $service_period= "$dd->y Yrs $dd->m Month $dd->d Day";
                    $service_period_1="$dd->y Yrs";
                }	
                Yii::import('application.controllers.front.EosdetailsController'); 
                $gratuityamount=EosdetailsController::geteos($id);
                $total_amount=0.00;
                $model_total_salary = EmployeeSalary::model()->find(array('select'=>'sum(amount) as amount','condition' => 'employee_id="'.$model['id'].'" AND (("'.$current_date.'" BETWEEN valid_from AND valid_to) OR (valid_from <= "'.$current_date.'" AND valid_to="0000-00-00"))'));
                if($model_total_salary->amount>0){
                    $total_amount=$model_total_salary->amount;
                }
                $basic = EmployeeSalary::model()->find(array('condition' => 'employee_id="'.$model['id'].'" AND salary_type="1" AND (("'.$current_date.'" BETWEEN valid_from AND valid_to) OR (valid_from <= "'.$current_date.'" AND valid_to="0000-00-00"))'))->amount;
            ?>
                <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"); ?></td>
				  <td><?php echo $date_join;?></td>  
				  <td class="text-center"><?php echo $service_period_1;?></td>  
                                  <td class="text-center"><?php echo $model->contract->contract_type;?></td>  
                                  <td class="text-right"><?php echo Yii::app()->numberFormatter->formatCurrency($basic,"");?></td>  
                                  <td class="text-right"><?php echo Yii::app()->numberFormatter->formatCurrency($total_amount,"");?></td>  
				  <td class="text-right"><?php echo Yii::app()->numberFormatter->formatCurrency($gratuityamount,"");?></td>  
				
				 
                  </tr>
			<?php 
                        $n++;
                        } 
            }
                ?>
                </tr>			 
                    
            
            </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>
