Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Cleanups in the HR Modules #3372

Open
wants to merge 4 commits into
base: optimization/hr-modules-codebase
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use App\Models\Setting;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Response;
use Illuminate\Support\Facades\Storage;
Expand All @@ -16,8 +15,6 @@
use Modules\HR\Entities\Application;
use Modules\HR\Entities\ApplicationMeta;
use Modules\HR\Entities\ApplicationRound;
use Modules\HR\Entities\Job;
use Modules\HR\Entities\University;
use Modules\HR\Http\Requests\Recruitment\ApplicationRequest;
use Modules\HR\Http\Requests\Recruitment\CustomApplicationMailRequest;
use Modules\HR\Http\Requests\TeamInteractionRequest;
Expand Down Expand Up @@ -64,47 +61,9 @@ public function index()
*/
public function edit($id)
{
//TODO: We need to refactor the edit code and write it in the service
$application = Application::findOrFail($id);

if ($application->latestApplicationRound->hr_round_id == 1) {
$application->latestApplicationRound->scheduled_date = today()->toDateString();
$application->latestApplicationRound->scheduled_end = today()->toDateString();
$application->latestApplicationRound->scheduled_person_id = auth()->id();
$application->latestApplicationRound->save();
}

$application->load(['evaluations', 'evaluations.evaluationParameter', 'evaluations.evaluationOption', 'job', 'job.rounds', 'job.rounds.evaluationParameters', 'job.rounds.evaluationParameters.options', 'applicant', 'applicant.applications', 'applicationRounds', 'applicationRounds.evaluations', 'applicationRounds.round', 'applicationMeta', 'applicationRounds.followUps', 'tags']);
$job = $application->job;
$approveMailTemplate = Setting::getApplicationApprovedEmail();
$approveMailTemplate = str_replace('|APPLICANT NAME|', $application->applicant->name, $approveMailTemplate);
$approveMailTemplate = str_replace('|JOB TITLE|', $application->job->title, $approveMailTemplate);
$approveMailTemplate = str_replace('|LINK|', config('app.url') . '/viewForm/' . $application->applicant->id . '/' . encrypt($application->applicant->email), $approveMailTemplate);

$offerLetterTemplate = Setting::getOfferLetterTemplate();
$desiredResume = DB::table('hr_applications')->select(['hr_applications.resume'])->where('hr_applications.hr_job_id', '=', $job->id)->where('is_desired_resume', '=', 1)->get();
$attr = [
'applicant' => $application->applicant,
'application' => $application,
'timeline' => $application->applicant->timeline(),
'interviewers' => User::interviewers()->orderBy('name')->get(),
'applicantOpenApplications' => $application->applicant->openApplications(),
'applicationFormDetails' => $application->applicationMeta()->formData()->first(),
'offer_letter' => $application->offer_letter,
'approveMailTemplate' => $approveMailTemplate,
'offerLetterTemplate' => $offerLetterTemplate,
'desiredResume' => $desiredResume,
'settings' => [
'noShow' => Setting::getNoShowEmail(),
],
'type' => config("constants.hr.opportunities.{$job->type}.type"),
'universities' => University::orderBy('name')->get(),
];

if ($job->type == 'job') {
$attr['hasGraduated'] = $application->applicant->hasGraduated();
$attr['internships'] = Job::isInternship()->latest()->get();
}
$attr = $this->service->edit($application);

return view('hr.application.edit')->with($attr);
}
Expand Down
46 changes: 46 additions & 0 deletions Modules/HR/Services/ApplicationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace Modules\HR\Services;

use App\Models\Setting;
use App\Models\Tag;
use Carbon\Carbon;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Str;
use Modules\HR\Contracts\ApplicationServiceContract;
Expand Down Expand Up @@ -206,4 +208,48 @@ public function getToken()

return $accessToken;
}

public function edit($application)
{
if ($application->latestApplicationRound->hr_round_id == 1) {
$application->latestApplicationRound->scheduled_date = today()->toDateString();
$application->latestApplicationRound->scheduled_end = today()->toDateString();
$application->latestApplicationRound->scheduled_person_id = auth()->id();
$application->latestApplicationRound->save();
}

$application->load(['evaluations', 'evaluations.evaluationParameter', 'evaluations.evaluationOption', 'job', 'job.rounds', 'job.rounds.evaluationParameters', 'job.rounds.evaluationParameters.options', 'applicant', 'applicant.applications', 'applicationRounds', 'applicationRounds.evaluations', 'applicationRounds.round', 'applicationMeta', 'applicationRounds.followUps', 'tags']);
$job = $application->job;
$approveMailTemplate = Setting::getApplicationApprovedEmail();
$approveMailTemplate = str_replace('|APPLICANT NAME|', $application->applicant->name, $approveMailTemplate);
$approveMailTemplate = str_replace('|JOB TITLE|', $application->job->title, $approveMailTemplate);
$approveMailTemplate = str_replace('|LINK|', config('app.url') . '/viewForm/' . $application->applicant->id . '/' . encrypt($application->applicant->email), $approveMailTemplate);

$offerLetterTemplate = Setting::getOfferLetterTemplate();
$desiredResume = DB::table('hr_applications')->select(['hr_applications.resume'])->where('hr_applications.hr_job_id', '=', $job->id)->where('is_desired_resume', '=', 1)->get();
$attr = [
'applicant' => $application->applicant,
'application' => $application,
'timeline' => $application->applicant->timeline(),
'interviewers' => User::interviewers()->orderBy('name')->get(),
'applicantOpenApplications' => $application->applicant->openApplications(),
'applicationFormDetails' => $application->applicationMeta()->formData()->first(),
'offer_letter' => $application->offer_letter,
'approveMailTemplate' => $approveMailTemplate,
'offerLetterTemplate' => $offerLetterTemplate,
'desiredResume' => $desiredResume,
'settings' => [
'noShow' => Setting::getNoShowEmail(),
],
'type' => config("constants.hr.opportunities.{$job->type}.type"),
'universities' => University::orderBy('name')->get(),
];

if ($job->type == 'job') {
$attr['hasGraduated'] = $application->applicant->hasGraduated();
$attr['internships'] = Job::isInternship()->latest()->get();
}

return $attr;
}
}