ok

Mini Shell

Direktori : /proc/self/root/home2/selectio/www/tnpsctestbatch.com/admin/apis/backups/
Upload File :
Current File : //proc/self/root/home2/selectio/www/tnpsctestbatch.com/admin/apis/backups/leave-request.php

<?php 
ob_start();
session_start();
include"../config/config.php";
$session_id = $_SESSION['hrm']['id'];

if(isset($_POST['type']) && $_POST['type']=='leave_request_add'){
    try{
         
        
        /*------------------------- Info G Solution Starts Here 
        
    Request Type - request_type - (1-Full Day, 2-Half Day, 3-Hours) 
    Request Status - request_status - (1-Present, 2-Requested, 3-Forward to Project Manager, 4-Forward to HR, 5-Forward to Manager, 6-Accepted, 7-Rejected)
    Type - type - (0-Absent, 1-Present, 2-Half Day, 3-Process Leave, 4-Special Present, 5-Special HalfDay, 6-Leave Requested)
        
        Info G Solution Endss Here -------------------------*/
        
        
    
        $employee = $_POST['employee'];
        $start_leave_req_date = $_POST['start_date'];
        $end_leave_req_date = $_POST['end_date'];
        $no_of_days_leave = $_POST['no_of_days_leave'];
        $reason = $_POST['reason'];
        $requset_status = $_POST['requset_status'];
    
    
    $begin_date = new DateTime("$start_leave_req_date");
    $end_date   = new DateTime("$end_leave_req_date");
    
    for($i=$begin_date; $i<=$end_date; $i->modify('+1 day'))
    {
        error_log($i->format("Y-m-d"));
        $date = $i->format("Y-m-d");
        $statement = $pdo->prepare("SELECT * FROM `tbl_attendance` WHERE `emp_id`=? and `att_date`=?");
        $statement->execute(array($employee,$date));
        $total = $statement->rowCount(); 
        $results = $statement->fetchAll(PDO::FETCH_ASSOC);
        if($total>0){
            $id = $results[0]['id'];
            $statement = $pdo->prepare("UPDATE `tbl_attendance` SET `emp_id`=?, `att_date`=?, `request_type`=?, `request_reson`=?, `type`=?, `request_status`=?, `added_by`=? WHERE id=?");
            $result = $statement->execute(array($employee,$date,1,$reason,6,2,$session_id,$id));
        }else{
            $statement = $pdo->prepare("INSERT INTO `tbl_attendance` (`emp_id`,`att_date`,`request_type`,`request_reson`,`type`,`request_status`,`added_by`) VALUES (?,?,?,?,?,?,?)");
            $result = $statement->execute(array($employee,$date,1,$reason,6,2,$session_id));
        }
        
        
    }
    
                    if($result){    
                        $return_arr['message']='Leave Request Added Successfully...';
                        $return_arr['status']=200;
                    } 
                    else{
                        $return_arr['message']='Something Went Wrong..';
                        $return_arr['status']=400;
                    }
    
    }catch(PDOException $e){
        $return_arr['message']="$e";
        $return_arr['status']=500;
        }   
    echo json_encode($return_arr);
}

if(isset($_POST['type']) && $_POST['type']=='permission_add'){
    try{
        
        
        $total_time=0;
        
        $employee = $_POST['employee'];
        $permission_date = $_POST['per_date'];
        $start_time = $_POST['start_time'];
        $reason = $_POST['reason'];
        $permission_hrs = $_POST['permission_hrs'];
        
        error_log("Start Hours: " .$start_time);
        error_log("Permission Hours: " .$permission_hrs);
        
        
        $start_Time = date($start_time);
        $end_Time = date('H:i:s',strtotime($permission_hrs,strtotime($start_Time)));
        error_log("End Hours: ".$end_Time);
    
        
        $diff_time=(strtotime(date($start_Time))-strtotime($end_Time))/60;
        error_log("Request Overall Hours: ".abs($diff_time));
        $request_overall_minutes = abs($diff_time);
        
        
        
        $statement = $pdo->prepare("SELECT * FROM `tbl_attendance` WHERE `emp_id`=? and `att_date`=?");
        $statement->execute(array($employee,$permission_date));
        $total = $statement->rowCount(); 
        $results = $statement->fetchAll(PDO::FETCH_ASSOC);
        
        if($total>0){
            $statement = $pdo->prepare("UPDATE `tbl_attendance` SET `emp_id`=?,`att_date`=?,`request_start_hrs`=?,`request_end_hrs`=?,`request_overall_minutes`=?,`permission_reason`=? WHERE `emp_id`=? and `att_date`=?");
            $result = $statement->execute(array($employee,$permission_date,$start_time,$end_Time,$employee,$permission_date,$request_overall_minutes,$reason));
        }else{
            $statement = $pdo->prepare("INSERT INTO `tbl_attendance` (`emp_id`,`att_date`,`request_start_hrs`,`request_end_hrs`,`request_overall_minutes`,`permission_reason`) VALUES (?,?,?,?,?,?)");
            $result = $statement->execute(array($employee,$permission_date,$start_time,$end_Time,$request_overall_minutes,$reason));
        }
        
        
        $statement = $pdo->prepare("INSERT INTO `tbl_permision_request`(`emp_id`,`per_date`,`start_time`, `end_time`,`total_hours`, `reason`) VALUES (?,?,?,?,?,?)");
        $result=$statement->execute(array($employee,$permission_date,$start_time,$end_Time,$total_time,$reason));
    
                    if($result){    
                        $return_arr['message']='Leave Request Added Successfully...';
                        $return_arr['status']=200;
                    } 
                    else{
                        $return_arr['message']='Something Went Wrong..';
                        $return_arr['status']=400;
                    }
    
    }catch(PDOException $e){
        $return_arr['message']="$e";
        $return_arr['status']=500;
        }   
    echo json_encode($return_arr);
}
?>

Zerion Mini Shell 1.0