case "employee_leaves" : $methodResponse = self::getEmployeeLeavesDetails($inputs); break; case "employee_apply_leaves" : $methodResponse = self::postEmployeeApplyLeave($inputs); break; case "employee_confirm_leaves" : $methodResponse = self::postEmployeeConfirmLeave($inputs); break; case "employee_update_leaves" : $methodResponse = self::postEmployeeUpdateLeave($inputs); break; public function getLeavesForEmployeeAPI($input) { try { $studentLeaves = EmployeeLeaveModel::getLeavesForEmployeeAPI($input); } catch (Exception $ex) { log . error('Exception while getting student leave data: ' . $ex); } return $studentLeaves ; } /** * Gets student leave details * @param student_id,ay_id,inst_id * @return Array [$result] */ public static function getLeavesForEmployeeAPI($inputParams) { $sqlWhereLeaveId = "" ; $sqlWhereLeaveStatus = "" ; $sqlLimitPage = "" ; $sqlWhereLeaveStatus = $sqlWhereLeaveStatus . " AND leave_status!= 'DRAFT' " ; if(isset($inputParams['emp_leave_id']) && $inputParams['emp_leave_id'] != ""){ $sqlWhereLeaveId = $sqlWhereLeaveId . " AND emp_leave_id = '" . $inputParams['emp_leave_id'] . "' " ; $sqlWhereLeaveStatus = "" ; } $sqlString="SELECT * FROM emp_leave_details WHERE emp_id=? AND ay_id=? AND inst_id=? AND is_active=1 AND is_deleted=0 $sqlWhereLeaveStatus $sqlWhereLeaveId ORDER BY leave_applied_on DESC,updated_on DESC"; $result=DB::select($sqlString, [ $inputParams['emp_id'], $inputParams['ay_id'], $inputParams['inst_id'] ]); return $result; } public function getEmployeeLeavesDetails($inputs){ Log::info("########### Inside getEmployeeLeavesDetails ###########" ); $response = array(); $employeeLeavesService = new EmployeeLeaveService(); $employeeLeaves = $employeeLeavesService->getLeavesForEmployeeAPI($inputs); $leaveTypeArray = GlobalHelper::getConfArray($inputs['inst_id'], "appldata.STUD_LEAVE_TYPE"); $leaveStatusArray = GlobalHelper::getConfArray($inputs['inst_id'], "appldata.STUD_LEAVE_STATUS"); $todayDate= \Carbon\Carbon::now()->toDateString(); foreach ($employeeLeaves AS $leaves) { $leaveStatus=''; $leaveType=''; $is_editable=true; if($leaves->leave_start_date<$todayDate AND $leaves->status == 'APPLIED'){ $leaveStatus='Leave Pending'; $is_editable=false; }elseif ($leaves->status=='APPROVED'){ $leaveStatus=$leaveStatusArray[$leaves->status]; $is_editable=false; }elseif ($leaves->status=='REJECTED'){ $leaveStatus=$leaveStatusArray[$leaves->status]; $is_editable=false; }else{ $leaveStatus=$leaveStatusArray[$leaves->status]; $is_editable=true; } $leaveType=$leaveTypeArray[$leaves->leave_type]; $data=[ 'emp_leave_id'=>$leaves->leave_id, 'employee_id'=>$leaves->employee_id, 'emp_id'=>$leaves->emp_id, 'supervisor_id'=>$leaves->supervisor_id, 'leave_type'=>$leaveType, 'leave_type_to_update'=>$leaves->leave_type, 'leave_start_date'=>$leaves->leave_start_date, 'leave_end_date'=>$leaves->leave_end_date, 'is_back_dated'=>$leaves->is_back_dated, 'leave_duration'=>$leaves->leave_duration, 'leave_applied_on'=>$leaves->leave_applied_on, 'leave_status'=>$leaveStatus, 'status_to_update'=>$leaves->status, //'status_desc'=>$leaves->status_desc, 'initiated_by'=>$leaves->initiated_by, 'initiator_comments'=>$leaves->initiator_comments, 'approved_on'=>$leaves->approved_on, 'approved_by'=>$leaves->approved_by, 'approval_type'=>$leaves->approval_type, 'approver_comments'=>$leaves->approver_comments, 'is_editable'=>$is_editable, 'todays_date'=>$todayDate ]; array_push($response,$data); } //Log::info($response); /* Final Response Data */ if(sizeof($response)>0) { $responseData = [ "label_metadata"=>$response ]; $api_response = [ "status" => self::RESPONSE_SUCCESS, "code" => self::RESPONSE_CODE_SUCCESS, "msg" => "Employee Leaves List Fetched Successfully!", "data" => $responseData, ] ; }else{ $api_response = [ "status" => self::RESPONSE_ERROR, "code" => self::RESPONSE_CODE_ERROR, "msg" => "There are no employees leaves yet!" ] ; } return $api_response ; } /** * apply leaves employee * @param Array $inputs */ public function postEmployeeApplyLeave($inputs){ Log::info("########### Inside postEmployeeApplyLeave ###########" ); $response = array(); $inputs['leave_applied_on']=\Carbon\Carbon::today()->toDateString(); $inputs['is_active']='1'; $inputs['created_by']=$inputs['emp_id']; $genericsettings = new GenericSettingsService(); $profile = $genericsettings ->all($inputs['inst_id']); $profile=$profile[0]; $weeklyHoliday=$profile->weekly_holiday; $count=0; $employeeLeavesService = new EmployeeLeaveService(); $leave_start_date=$inputs['leave_start_date']; $leave_end_date=$inputs['leave_end_date']; if ($inputs['leave_start_date']==$inputs['leave_end_date']) { $count=1; }else{ //Log::info("leave_start_date---".$inputs['leave_start_date']); //Log::info("leave_end_date---".$inputs['leave_end_date']); while($inputs['leave_start_date']<=$inputs['leave_end_date']) { //Log::info("In leave_start_date---".$inputs['leave_start_date']); $date = $inputs['leave_start_date']; $dayName = date('D', strtotime($date)); if ((stripos($weeklyHoliday, $dayName) !== false)) { $count=$count; //::error("1---".$count); }else{ $count++; //Log::info("2---".$count); } $date = \Carbon\Carbon::parse($date); $date = $date->addDays(1); $date = \Carbon\Carbon::parse($date)->toDateString(); $inputs['leave_start_date'] = $date; } } $inputs['leave_duration']=$count; $employeeLeaveList = array(); //$employeeDetails = $employeeLeavesService->getemployeeDetails($inputs); $jsonItemDtl = [ 'ay_id' => $inputs['ay_id'] . '', // Session 'inst_id' => $inputs['inst_id'] . '', // Session 'leave_id' => '', // Hard Coded 'emp_id' => $inputs['emp_id'] . '', // Hidden 'supervisor_id' => $inputs['supervisor_id'] . '', 'leave_type' => $inputs['leave_type'] . '', // Form 'leave_status' => 'DRAFT' . '', // Hard Code 'leave_applied_on' => $inputs['leave_applied_on'] . '', // todays date 'leave_start_date' => $leave_start_date . '', // Form 'leave_end_date' => $leave_end_date . '', // Form 'leave_duration' => $inputs['leave_duration'] . '', // Form (Calculated) 'is_half_day' => '0' . '', 'half_day_shift' => '0' . '', 'is_back_dated' => '0' . '', // Hidden //'initiated_by' => $inputs['employee_id'] . '', //$inputs['employee_id']; 'initiator_comments' => DbUtil::getEscapedDbStringForJson($inputs['initiator_comments']) . '',// Form 'approved_on' => '', // Hard Coded 'approved_by' => '', // Hard Coded 'approval_type' => '', // Hard Coded 'approver_comments' => '' . '', // Hard Coded 'is_active' => $inputs['is_active'] . '', // Hard Coded 'created_by' => $inputs['created_by'] . '', ]; array_push($employeeLeaveList, $jsonItemDtl); $inputs['leave_details_list'] = $employeeLeaveList; $status = $employeeLeavesService->storeNewLeave($inputs); /* Final Response Data */ if ($status->errorCode == '00000') { $response = [ "status" => self::RESPONSE_SUCCESS, "code" => self::RESPONSE_CODE_SUCCESS, "msg" => "Leave Applied Successfully!", "data" => [ "status" => $status, "leave_duration" => $inputs['leave_duration'] ], ]; } else { $response = [ "status" => self::RESPONSE_ERROR, "code" => self::RESPONSE_CODE_ERROR, "msg" => "Problem while applying leave!.. Error Code:" . $status->errorCode . ', Error Message:' . $status->errorMessage ]; } return $response ; } /** * Confirm leave * Output contains : * (1)Confirm leave * @param Array $inputs */ public function postEmployeeConfirmLeave($inputs){ Log::info("########### Inside postStudentConfirmLeave ###########" ); $response = array(); $studentLeavesService = new StudentLeavesService(); $status = $studentLeavesService->confirmLeave($inputs); if($status==true){ session()->flash('flash_message', 'Leave Applied Successfully !'); /* Send Notifications */ $notification_params = array ( array("STUDENT_LEAVE_APPLIED","LEAVE_MST_ID",$inputs['leave_id'],$inputs['ay_id']), ); $default_headers=GlobalHelper::getConfArray($inputs['inst_id'],"appldata.NOTIFICATIONS_OVERRIDE"); $notification = new NotificationEngineService(); $invokeNotif = $notification ->invoke($inputs['inst_id'],"111", $notification_params, "", "0", $default_headers); if ($invokeNotif['errorCode']=="00000") { }else{ echo "Error:".$invokeNotif['errorMessage']; } $response = [ "status" => self::RESPONSE_SUCCESS, "code" => self::RESPONSE_CODE_SUCCESS, "msg" => "Student leave confirmed successfully!", "data" => $status, ] ; }else{ $response = [ "status" => self::RESPONSE_ERROR, "code" => self::RESPONSE_CODE_ERROR, "msg" => "Problem while confirming student leave!.. Error Code:".$status->errorCode.', Error Message:'.$status->errorMessage ] ; } return $response ; } /** * update student leave * Output contains : * (1)updated student leave * @param Array $inputs */ public function postEmployeeUpdateLeave($inputs){ Log::info("########### Inside postStudentUpdateLeave ###########" ); $response = array(); $inputs['leave_applied_on']=\Carbon\Carbon::today()->toDateString(); $inputs['is_active']='1'; $inputs['created_by']=$inputs['student_id']; $studentLeavesService = new StudentLeavesService(); $genericsettings = new GenericSettingsService(); $profile = $genericsettings ->all($inputs['inst_id']); $profile=$profile[0]; $weeklyHoliday=$profile->weekly_holiday; $count=0; if ($inputs['leave_start_date']==$inputs['leave_end_date']) { $count=1; }else{ //Log::info("leave_start_date---".$inputs['leave_start_date']); //Log::info("leave_end_date---".$inputs['leave_end_date']); while($inputs['leave_start_date']<=$inputs['leave_end_date']) { //Log::info("In leave_start_date---".$inputs['leave_start_date']); $date = $inputs['leave_start_date']; $dayName = date('D', strtotime($date)); if ((stripos($weeklyHoliday, $dayName) !== false)) { $count=$count; //::error("1---".$count); }else{ $count++; //Log::info("2---".$count); } $date = \Carbon\Carbon::parse($date); $date = $date->addDays(1); $date = \Carbon\Carbon::parse($date)->toDateString(); $inputs['leave_start_date'] = $date; } } //Log::info($count); $inputs['leave_duration']=$count; $studentLeaveList = array(); $studentDetails = $studentLeavesService->getStudentDetails($inputs); if(sizeof($studentDetails)>0) { $studentDetails=$studentDetails[0]; $jsonItemDtl = [ 'ay_id' => $inputs['ay_id'] . '', // Session 'inst_id' => $inputs['inst_id'] . '', // Session 'leave_id' => $inputs['leave_id'] . '', // Hard Coded 'standard_id' => $studentDetails->standard_id . '', // Hidden 'division_id' => $studentDetails->division_id . '', // Hidden 'class_id' => $studentDetails->class_id . '', // Hidden 'student_id' => $inputs['student_id'] . '', // Hidden 'leave_type' => $inputs['leave_type'] . '', // Form 'leave_start_date' => $inputs['leave_start_date'] . '', // Form 'leave_end_date' => $inputs['leave_end_date'] . '', // Form 'is_back_dated' => '0' . '', // Hidden 'leave_duration' => $inputs['leave_duration'] . '', // Form (Calculated) 'leave_applied_on' => $inputs['leave_applied_on'] . '', // todays date 'status' => $inputs['status'] . '', // Hard Code 'status_desc' => '' . '', // Hard Code 'initiated_by' => $inputs['student_id'] . '', //$inputs['student_id']; 'initiator_comments' => DbUtil::getEscapedDbStringForJson($inputs['initiator_comments']) . '',// Form 'approved_on' => '', // Hard Coded 'approved_by' => '', // Hard Coded 'approval_type' => '', // Hard Coded 'approver_comments' => '' . '', // Hard Coded 'created_by' => $inputs['created_by'] . '', 'updated_by' => $inputs['student_id'] . '', 'is_active' => $inputs['is_active'] . '' // Hard Coded ]; array_push($studentLeaveList, $jsonItemDtl); $inputs['leave_details_list'] = $studentLeaveList; $studentLeavesService = new StudentLeavesService(); $status = $studentLeavesService->updateStudentLeave($inputs); /* Final Response Data */ if ($status->errorCode == '00000') { //::getStudentProfile($inputs); $response = [ "status" => self::RESPONSE_SUCCESS, "code" => self::RESPONSE_CODE_SUCCESS, "msg" => "Applied Leave Updated Successfully!", "data" => [ "status" => $status, "leave_duration" => $inputs['leave_duration'] ], ]; } else { $response = [ "status" => self::RESPONSE_ERROR, "code" => self::RESPONSE_CODE_ERROR, "msg" => "Problem while updating leave!.. Error Code:" . $status->errorCode . ', Error Message:' . $status->errorMessage ]; } }else{ $response = [ "status" => self::RESPONSE_ERROR, "code" => self::RESPONSE_CODE_ERROR, "msg" => "Student Not Found!" ] ; } return $response ; }