ok

Mini Shell

Direktori : /home2/selectio/public_html/tnpsctestbatch.com/admin/old/api/backups/
Upload File :
Current File : /home2/selectio/public_html/tnpsctestbatch.com/admin/old/api/backups/process-leave-api.php

<?php include"../config/config.php";

if($_POST['type']=="process_leave"){
    $ids=array();
    $year=0;
    $month=0;
    $department_id=0;
    $designation_id=0;
    $employee_id=0;
    $overall_datas=array();
    
    if(isset($_POST['filter_department']) && $_POST['filter_department']!='' && $_POST['filter_department']!=0 && $_POST['filter_department']!='all'){
        $department_id=$_POST['filter_department'];
    }
    if(isset($_POST['filter_designation']) && $_POST['filter_designation']!='' && $_POST['filter_designation']!=0 && $_POST['filter_designation']!='all'){
        $designation_id=$_POST['filter_designation'];
    }
    if(isset($_POST['filter_employee']) && $_POST['filter_employee']!='' && $_POST['filter_employee']!=0 && $_POST['filter_employee']!='all'){
        $employee_id=$_POST['filter_employee'];
    }
    if(isset($_POST['filter_year'])){
        $year=$_POST['filter_year'];
    }
    if(isset($_POST['filter_month'])){
        $month=$_POST['filter_month'];
    }
    
    $delete_ids=0;
    
    $emp_id=array();
    $date=array();
    
    $ids=$_POST['clicked_ids'];
    $response=array();
    $msg='';
    $inserted_count=0;
    
    $condition='';
    if($department_id!=0 && $department_id!=''){ 
        $condition.=' and tbl_user.department_id='.$department_id;
    }
    if($designation_id!=0 && $designation_id!=''){
        $condition.=' and tbl_user.designation_id='.$designation_id;
    }
    if($designation_id!=0 && $designation_id!=''){
        $condition.=' and tbl_user.id='.$employee_id;
    }
    
    foreach($ids as $id){
        $temp_array = explode(',', $id);
        $emp_id[]=$temp_array[0];
        $date[]=$temp_array[1];
    }
    
    $i=0;
    
    
    $sql="SELECT tbl_attendance.id FROM `tbl_attendance` inner JOIN tbl_user on tbl_attendance.emp_id=tbl_user.id WHERE MONTH(att_date) = $month AND YEAR(att_date) =$year $condition";
    error_log('del:'.$sql);
    $statement = $pdo->prepare($sql);
	$statement->execute();
	$overall_data = $statement->fetchAll(PDO::FETCH_ASSOC); 
	foreach($overall_data as $data){
	    $overall_datas[]=$data['id'];
	}
    
    //SELECT id FROM `tbl_process_leaves` where MONTH(att_date) = $month AND YEAR(att_date) =$year
    
    
    foreach($emp_id as $e){
     
    $statement = $pdo->prepare("SELECT * FROM `tbl_attendance` where emp_id=? and att_date=?");
	$statement->execute(array($e,$date[$i]));
	$o_data = $statement->fetchAll(PDO::FETCH_ASSOC);
	$count = $statement->rowCount();
	
	    if($count==0){
            
            $statement_process = $pdo->prepare("INSERT INTO `tbl_attendance` (`emp_id`, `att_date`, `type`) VALUES (?,?,?)");
            $process_wise_leaves_result = $statement_process->execute(array($e,$date[$i],4));
            
            if($process_wise_leaves_result){
                $inserted_count++;
            }
	    }else{
	        if(($key = array_search($o_data[0]['id'], $overall_datas)) !== false) {
                unset($overall_datas[$key]);
            }
	    }
        $i++;
    }
    
    $str = implode(',', $overall_datas);
    
  if($str!=''){  
    $sql="DELETE FROM `tbl_attendance` where id in ($str)";
    $statement = $pdo->prepare($sql);
    $result=$statement->execute();
  }
    
    $response['status']=1;
    $response['msg']=$inserted_count.' Record Inserted...'.count($overall_datas).' Record Deleted...';
    echo json_encode($response);
}

?>

Zerion Mini Shell 1.0