Skip to content

Commit f7f3f43

Browse files
committed
Merge branch 'staging'
2 parents f7a099e + 19398b2 commit f7f3f43

32 files changed

Lines changed: 895 additions & 307 deletions

app/Enums/FilePath.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ enum FilePath: string
1313
case CONTRACTS = 'contracts/';
1414
case LEAVES = 'leaves/';
1515
case COE = 'uploads/employee/coe/';
16-
case DOC_TEMPLATE = 'templates/documents/';
16+
case DOC_TEMPLATE = 'templates/document/';
17+
case DEFAULT_SIGNATURE = 'templates/document/signature-placeholder.png';
1718
}

app/Http/Controllers/ApplicationDocController.php

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@ public function create($isCopy = false)
2626
return view('employee.pre-employment-copy');
2727
}
2828

29-
if(!auth()->user()->account_type == AccountType::APPLICANT->value)
29+
if (!auth()->user()->account_type == AccountType::APPLICANT->value)
3030
return redirect()->route('employee.general.documents.all');
3131

3232
return view('employee.pre-employment');
33-
3433
}
3534

3635
/* store a new resource */
@@ -54,48 +53,59 @@ public function store(Request $request)
5453

5554
$file = $request->file($prefix);
5655
$file_name = $file->getClientOriginalName();
57-
echo $file_name;
5856

5957
// Get application id
6058

6159
$doc_id = $request->input('doc_id');
62-
echo $doc_id;
6360

6461
$hashed_name = $prefix . '_' . dechex($doc_id) . '_' . $file->hashName();
65-
echo $hashed_name;
6662

6763
$user = Auth::user();
6864

6965
$user_id = $user->user_id;
7066
// dump($user);
7167

72-
$preemployed_user = User::with('account.application')->find($user_id);
68+
try {
69+
$preemployed_user = User::with('account.application')->find($user_id);
70+
71+
// dd($preemployed_user);
72+
73+
$user_folder = dechex($user_id);
74+
75+
$application_id = $preemployed_user->account->application->application_id;
7376

74-
// dd($preemployed_user);
77+
$path = $file->storeAs(FilePath::PRE_EMPLOYMENT->value . "/$user_folder", $hashed_name, 'public');
7578

76-
$first_name = $preemployed_user->account->first_name;
77-
$last_name = $preemployed_user->account->last_name;
79+
/* Needs to be updated to store in application docs instead */
7880

79-
$user_folder = $first_name . '_' . $last_name . '_' . dechex($user_id);
81+
$preemp_doc = ApplicationDoc::where('preemp_req_id', $doc_id)
82+
->where('application_id', $application_id)
83+
->first();
8084

81-
$application_id = $preemployed_user->account->application->application_id;
85+
if ($preemp_doc) {
8286

83-
$path = $file->storeAs(FilePath::PRE_EMPLOYMENT->value . "$user_folder", $hashed_name, 'public');
87+
$preemp_doc->file_path = $path;
88+
} else {
8489

85-
/* Needs to be updated to store in application docs instead */
90+
$preemp_doc = new ApplicationDoc;
91+
$preemp_doc->preemp_req_id = $doc_id;
92+
$preemp_doc->application_id = $application_id;
93+
$preemp_doc->file_path = $path;
94+
}
8695

87-
$preemp_doc = new ApplicationDoc;
88-
$preemp_doc->preemp_req_id = $doc_id;
89-
$preemp_doc->application_id = $application_id;
90-
$preemp_doc->file_path = $path;
91-
$preemp_doc->save();
96+
$preemp_doc->save();
9297

93-
/* Should be preemp_requirements name instead */
94-
$document = PreempRequirement::find($doc_id);
95-
$document_name = $document->preemp_req_name;
96-
echo $document_name;
98+
/* Should be preemp_requirements name instead */
99+
$document = PreempRequirement::find($doc_id);
100+
$document_name = $document->preemp_req_name;
101+
} catch (\Throwable $th) {
102+
report($th);
103+
if (is_null($preemployed_user->account->application)) {
104+
abort(404, 'Application not found');
105+
}
97106

98-
// return back()->with('success', '$document_name uploaded successfully!');
107+
abort(500, 'An error occurred');
108+
}
99109
}
100110
}
101111

app/Http/Controllers/FinalInterviewController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function store(Request|array $request, bool $isValidated = false)
8080
FinalInterview::create([
8181
'application_id' => $application->application_id,
8282
'final_interview_at' => $interviewStartDate . ' ' . $interviewStartTime,
83-
'final_interviewer' => auth()->user()->user_id,
83+
'final_interviewer' => auth()->user()->account->employee_id,
8484
]);
8585

8686
$application->update([
@@ -123,7 +123,7 @@ public function update($request, bool $isValidated = false)
123123

124124
$data = [
125125
'final_interview_at' => $interviewStart,
126-
'final_interviewer' => auth()->user()->user_id,
126+
'final_interviewer' => auth()->user()->account->employee_id,
127127
'is_final_interview_passed' => $request['isPassed'] ?? false,
128128
];
129129

app/Http/Controllers/InitialInterviewController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function store(Request|array $request, bool $isValidated = false)
7777
InitialInterview::create([
7878
'application_id' => $application->application_id,
7979
'init_interview_at' => $interviewStartDate . ' ' . $interviewStartTime,
80-
'init_interviewer' => auth()->user()->user_id,
80+
'init_interviewer' => auth()->user()->account->employee_id,
8181
]);
8282

8383
// Insert Interview Notification Event Here
@@ -116,7 +116,7 @@ public function update($request, bool $isValidated = false)
116116

117117
$data = [
118118
'init_interview_at' => $interviewStart,
119-
'init_interviewer' => auth()->user()->user_id,
119+
'init_interviewer' => auth()->user()->account->employee_id,
120120
'is_init_interview_passed' => $request['isPassed'] ?? false,
121121
];
122122

app/Http/Controllers/Separation/CoeController.php

Lines changed: 82 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,20 @@
88
use App\Http\Helpers\RouteHelper;
99
use App\Models\CoeRequest;
1010
use App\Models\EmployeeDoc;
11-
use Barryvdh\DomPDF\Facade\Pdf;
12-
use Illuminate\Support\Facades\File;
11+
use App\Traits\NeedsWordDocToPdf;
12+
use Carbon\Carbon;
1313
use Illuminate\Http\Request;
1414
use Illuminate\Support\Facades\DB;
1515
use Illuminate\Support\Facades\Storage;
16+
use PhpOffice\PhpWord\IOFactory;
17+
use PhpOffice\PhpWord\TemplateProcessor as WordTemplateProcessor;
1618

1719
class CoeController extends Controller
1820
{
21+
use NeedsWordDocToPdf;
22+
23+
private $coeTemplatePath = FilePath::DOC_TEMPLATE->value . 'Certificate of Appreciation.docx';
24+
1925
/**
2026
* Display a listing of the resource.
2127
*/
@@ -48,6 +54,7 @@ public function show(string $coe)
4854

4955
$coe = RouteHelper::validateModel(CoeRequest::class, $coe);
5056

57+
$coe->loadMissing(['requestor.lifecycle', 'requestor.jobTitle.department']);
5158

5259
return view('employee.separation.coe.request', compact('coe'));
5360
}
@@ -59,29 +66,92 @@ public function show(string $coe)
5966
public function edit($coeRequest)
6067
{
6168

62-
// dump($coeRequest);
69+
$coeRequest->loadMissing(['requestor.lifecycle', 'requestor.jobTitle.department']);
70+
6371
$coeData = [
6472
'name' => $coeRequest->requestor->fullname,
6573
'empStart' => $coeRequest->requestor->lifecycle->start_date,
6674
'empEnd' => $coeRequest->requestor->lifecycle->separated_at,
67-
'jobTitle' => $coeRequest->requestor->jobTitle->department->department_name,
75+
'jobTitle' => $coeRequest->requestor->jobTitle->job_title,
6876
'jobDepartment' => $coeRequest->requestor->jobTitle->department->department_name,
6977
'issuedDate' => now(),
7078
'hrManager' => auth()->user()->account->fullname,
7179
'companyAddr' => 'Rowsuz Business Center, Diversin Rd',
7280
];
7381

74-
Pdf::setOption(['dpi' => 300]);
75-
$coe = Pdf::loadView('coe', $coeData);
76-
$coe->setPaper('a4', 'landscape');
77-
$coePdf = $coe->output();
82+
$relativePath = $this->generateContent($coeRequest);
83+
84+
return $relativePath;
85+
}
86+
87+
private function generateContent($coeRequest)
88+
{
89+
$reader = IOFactory::createReader('Word2007');
7890

79-
$relativePath = FilePath::COE->value . hash('sha256', time()) . '.pdf';
80-
$coePath = 'public/' . $relativePath;
8191

82-
Storage::put($coePath, $coePdf);
92+
if (Storage::disk('public')->missing($this->coeTemplatePath)) {
93+
abort(404);
94+
}
8395

84-
return $relativePath;
96+
$templateProcessor = new WordTemplateProcessor(Storage::disk('public')->path($this->coeTemplatePath));
97+
98+
$issuedDate = now();
99+
100+
$issueDay = Carbon::parse($issuedDate)->isoFormat('Do');
101+
$issueMonth = Carbon::parse($issuedDate)->format('F');
102+
$issueYear = Carbon::parse($issuedDate)->isoFormat('YYYY');
103+
104+
$values = [
105+
// Long Names isnt shrinked
106+
'EMPLOYEE_NAME' => $coeRequest->requestor->fullname,
107+
'START_DATE' => $coeRequest->requestor->lifecycle->start_date,
108+
'END_DATE' => $coeRequest->requestor->lifecycle->separated_at,
109+
'JOB_TITLE' => $coeRequest->requestor->jobTitle->job_title,
110+
'DEPT_NAME' => $coeRequest->requestor->jobTitle->department->department_name,
111+
'ORDINAL' => $issueDay,
112+
'MONTH' => $issueMonth,
113+
'YEAR' => $issueYear,
114+
'COMPANY_ADDRESS' => 'Rowsuz Business Center, Diversin Rd',
115+
'HRManager_NAME' => auth()->user()->account->fullname,
116+
];
117+
118+
$signature = null;
119+
120+
121+
if (auth()->user()->account->signature) {
122+
$signatureData = auth()->user()->account->signature;
123+
124+
if (is_string($signatureData)) {
125+
$signature = Storage::disk('public')->path($signatureData);
126+
} else {
127+
$signature = $signatureData;
128+
}
129+
}
130+
try {
131+
$templateProcessor->setImageValue('USER_SIGNATURE', $signature);
132+
} catch (\Throwable $th) {
133+
$signature = Storage::disk('public')->path(FilePath::DEFAULT_SIGNATURE->value);
134+
$templateProcessor->setImageValue('USER_SIGNATURE', $signature);
135+
report($th);
136+
}
137+
138+
$templateProcessor->setValues($values);
139+
$templateProcessor->setImageValue('USER_SIGNATURE', $signature);
140+
141+
$docxFilePath = FilePath::COE->value . hash('sha256', time()) . '.docx';
142+
$templateProcessor->saveAs(Storage::disk('public')->path($docxFilePath));
143+
144+
$disk = 'public';
145+
146+
try {
147+
$pdfFilePath = $this->convert($docxFilePath, FilePath::COE->value, $disk);
148+
Storage::disk('public')->delete($docxFilePath);
149+
150+
return $pdfFilePath;
151+
} catch (\Throwable $th) {
152+
report($th);
153+
return response()->json(['error' => $th->getMessage()], 500);
154+
}
85155
}
86156

87157
/**
@@ -110,7 +180,6 @@ public function update($coe, $coePath)
110180
'separated_at' => now(),
111181
]);
112182
});
113-
114183
}
115184

116185
/**

app/Http/Controllers/Separation/ResignationController.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,19 +125,27 @@ public function update($request, bool $validated = false)
125125
// ]);
126126
}
127127

128+
// dump(auth()->user());
129+
// dump($resignation->resignee->account);
130+
// dd(!auth()->user()->is($resignation->resignee->account));
128131
// add authorization
129-
if (!auth()->user()->is($resignation->resignee) && true) {
132+
if (!auth()->user()->is($resignation->resignee->account) && true) {
130133

131134
if (is_array($request) && $validated) {
132135
$data = [
133136
'resignation_status_id' => $request['resignation_status_id'],
134137
'initial_approver' => auth()->user()->account->employee_id,
138+
'initial_approver_signed_at' => now(),
135139
'initial_approver_comments' => $request['initial_approver_comments'],
136140
];
137141
}
138142

139143
}else{
140144
if (is_array($request) && $validated && true) {
145+
if($resignation->resignation_status_id == ResignationStatus::APPROVED->value){
146+
return response()->json(['message' => 'You cannot retract resignation'], 400);
147+
}
148+
141149
$data = [
142150
'retracted_at' => $request['retracted_at'],
143151
];
@@ -146,7 +154,7 @@ public function update($request, bool $validated = false)
146154

147155
$resignation->update($data);
148156

149-
if($request['resignation_status_id'] == ResignationStatus::APPROVED->value){
157+
if(isset($request['resignation_status_id']) && $request['resignation_status_id'] == ResignationStatus::APPROVED->value){
150158
ResignationApproved::dispatch($resignation->resignee);
151159
}
152160

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace App\Http\Helpers;
4+
5+
class FilepondHelper
6+
{
7+
public static function parseAccept($accept)
8+
{
9+
if (is_array($accept)) {
10+
$result = [];
11+
foreach ($accept as $prefix => $types) {
12+
if (is_array($types)) {
13+
foreach ($types as $type) {
14+
$result[] = "$prefix/$type";
15+
}
16+
} else {
17+
$result[] = "$prefix/$types";
18+
}
19+
}
20+
return implode(', ', $result);
21+
}
22+
return $accept;
23+
}
24+
25+
public static function transfromToFile($filePath)
26+
{
27+
try {
28+
if (file_exists($filePath)) {
29+
30+
$tempFile = new \Illuminate\Http\UploadedFile(
31+
$filePath,
32+
basename($filePath),
33+
null,
34+
null,
35+
true
36+
);
37+
38+
return $tempFile;
39+
}
40+
} catch (\Throwable $th) {
41+
report($th);
42+
}
43+
}
44+
}

app/Livewire/CoeRequestsTable.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ public function columns(): array
8989

9090
Column::make("Updated at")
9191
->label(function($row) {
92+
93+
if($row->updated_at == $row->created_at){
94+
return '--';
95+
}
9296
return $row->updated_at->format('F j, Y');
9397
})
9498
->sortable(),

0 commit comments

Comments
 (0)