Evaluation: filter date sprint-review, filter technical name, export report file
This commit is contained in:
parent
62df9728c7
commit
977728a22d
|
|
@ -0,0 +1,253 @@
|
|||
<?php
|
||||
|
||||
namespace Modules\Admin\app\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use App\Services\JiraService;
|
||||
use Carbon\Carbon;
|
||||
use Modules\Admin\app\Models\TechnicalUser;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Admin\app\Models\UserCriteria;
|
||||
use PhpOffice\PhpWord\IOFactory;
|
||||
use PhpOffice\PhpWord\PhpWord;
|
||||
|
||||
class EvaluationController extends Controller
|
||||
{
|
||||
protected $jiraService;
|
||||
|
||||
public function __construct(JiraService $jiraService)
|
||||
{
|
||||
$this->jiraService = $jiraService;
|
||||
}
|
||||
|
||||
public function sprintReview(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'userID' => 'required|exists:users,id',
|
||||
'fromDate' => 'nullable|date',
|
||||
'toDate' => 'nullable|date',
|
||||
]);
|
||||
|
||||
$userEmail = User::findOrFail($request->input('userID'))->email;
|
||||
|
||||
$projects = $this->jiraService->getAllProjects();
|
||||
|
||||
$query = UserCriteria::where('user_email', $userEmail);
|
||||
|
||||
// Date filter
|
||||
if ($request->filled('fromDate')) {
|
||||
$fromDate = Carbon::parse($request->input('fromDate'));
|
||||
$query->where('created_at', '>=', $fromDate);
|
||||
}
|
||||
|
||||
if ($request->filled('toDate')) {
|
||||
$toDate = Carbon::parse($request->input('toDate'));
|
||||
$query->where('created_at', '<=', $toDate);
|
||||
}
|
||||
|
||||
// End query
|
||||
$userCriterias = $query->with(['sprint', 'criteria'])->get();
|
||||
|
||||
$projectsData = $userCriterias->groupBy('sprint.project_id')->map(function ($userCriteriasByProject, $projectId) use ($projects) {
|
||||
$result = self::getProjectById($projects, $projectId);
|
||||
return [
|
||||
'name' => $result['name'],
|
||||
'sprints' => $userCriteriasByProject->groupBy('sprint.id')->map(function ($userCriteriasBySprint) {
|
||||
$sprint = $userCriteriasBySprint->first()->sprint;
|
||||
return [
|
||||
'name' => $sprint->name,
|
||||
'criterias' => $userCriteriasBySprint->map(function ($userCriteria) {
|
||||
$criteria = $userCriteria->criteria;
|
||||
return [
|
||||
'criteria' => $criteria->name,
|
||||
'note' => $userCriteria->note ?? '',
|
||||
'createdBy' => $userCriteria->created_by ?? '',
|
||||
'point' => $userCriteria->point ?? '',
|
||||
];
|
||||
})
|
||||
];
|
||||
})->values()
|
||||
];
|
||||
})->values();
|
||||
|
||||
return AbstractController::ResultSuccess($projectsData);
|
||||
}
|
||||
|
||||
public function getProjectById($projects, $inputId)
|
||||
{
|
||||
$filteredProjects = array_filter($projects, function ($project) use ($inputId) {
|
||||
return $project['id'] == $inputId;
|
||||
});
|
||||
return array_values($filteredProjects) ? array_values($filteredProjects)[0] : array_values($filteredProjects);
|
||||
}
|
||||
|
||||
public function technical(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'user_id' => 'required|exists:users,id',
|
||||
'keyword' => 'nullable|string'
|
||||
]);
|
||||
|
||||
$user = User::findOrFail($request->input('user_id'));
|
||||
|
||||
$query = TechnicalUser::query();
|
||||
$query = TechnicalUser::where('user_id', $user->id);
|
||||
|
||||
if ($request->filled('keyword')) {
|
||||
$keyword = '%' . $request->input('keyword') . '%';
|
||||
$query->whereHas('technical', fn($q) => $q->where('name', 'like', $keyword))
|
||||
->with('technical');
|
||||
} else {
|
||||
$query->with('technical');
|
||||
}
|
||||
|
||||
$technical_users = $query->where('point', '>', 0)->get();
|
||||
|
||||
return AbstractController::ResultSuccess(
|
||||
$technical_users
|
||||
->map(function ($user) {
|
||||
return [
|
||||
'id' => $user->id,
|
||||
'point' => $user->point,
|
||||
'updated_at' => $user->updated_at,
|
||||
'technical' => [
|
||||
'id' => $user->technical->id,
|
||||
'name' => $user->technical->name,
|
||||
'level' => $user->technical->level,
|
||||
]
|
||||
];
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
public function report(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'userID' => 'required|exists:users,id',
|
||||
'fromDate' => 'nullable|date',
|
||||
'toDate' => 'nullable|date',
|
||||
]);
|
||||
|
||||
// Query User
|
||||
$user = User::findOrFail($request->input('userID'));
|
||||
$userEmail = $user->email;
|
||||
|
||||
// Query User Criteria
|
||||
$query = UserCriteria::where('user_email', $userEmail);
|
||||
|
||||
if ($request->filled('fromDate')) {
|
||||
$fromDate = Carbon::parse($request->input('fromDate'));
|
||||
$query->where('created_at', '>=', $fromDate);
|
||||
}
|
||||
|
||||
if ($request->filled('toDate')) {
|
||||
$toDate = Carbon::parse($request->input('toDate'));
|
||||
$query->where('created_at', '<=', $toDate);
|
||||
}
|
||||
|
||||
$userCriterias = $query->with(['sprint', 'criteria'])->get();
|
||||
|
||||
|
||||
// Structure projects data
|
||||
$projects = $this->jiraService->getAllProjects();
|
||||
|
||||
$projectsData = $userCriterias->groupBy('sprint.project_id')->map(function ($userCriteriasByProject, $projectId) use ($projects) {
|
||||
$result = self::getProjectById($projects, $projectId);
|
||||
|
||||
return [
|
||||
'name' => $result['name'],
|
||||
'sprints' => $userCriteriasByProject->groupBy('sprint.id')->map(function ($userCriteriasBySprint) {
|
||||
$sprint = $userCriteriasBySprint->first()->sprint;
|
||||
return [
|
||||
'name' => $sprint->name,
|
||||
'criterias' => $userCriteriasBySprint->map(function ($userCriteria) {
|
||||
$criteria = $userCriteria->criteria;
|
||||
return [
|
||||
'criteria' => $criteria->name,
|
||||
'note' => $userCriteria->note ?? '',
|
||||
'createdBy' => $userCriteria->created_by ?? '',
|
||||
'point' => $userCriteria->point ?? '',
|
||||
];
|
||||
})
|
||||
];
|
||||
})->values()
|
||||
];
|
||||
})->values();
|
||||
|
||||
// Generate Word document
|
||||
$phpWord = new PhpWord();
|
||||
$phpWord->setDefaultFontName('Times New Roman');
|
||||
$phpWord->setDefaultFontSize(12);
|
||||
$section = $phpWord->addSection();
|
||||
|
||||
$section->addText('Staff Evaluation', [
|
||||
'bold' => true,
|
||||
'size' => 20,
|
||||
'color' => '000000',
|
||||
], [
|
||||
'align' => 'center',
|
||||
'spaceAfter' => 600,
|
||||
]);
|
||||
|
||||
if ($request->filled('fromDate')) {
|
||||
$fromDate = Carbon::parse($request->input('fromDate'));
|
||||
$section->addText("From: " . $fromDate->format('d-m-Y'), ['name' => 'Times New Roman', 'size' => 12], ['align' => 'end']);
|
||||
}
|
||||
|
||||
if ($request->filled('toDate')) {
|
||||
$toDate = Carbon::parse($request->input('toDate'));
|
||||
$section->addText("To: " . $toDate->format('d-m-Y'), ['name' => 'Times New Roman', 'size' => 12], ['align' => 'end']);
|
||||
}
|
||||
|
||||
$section->addText("{$user->name}", [
|
||||
'bold' => true,
|
||||
'size' => 14,
|
||||
'color' => '000000',
|
||||
], [
|
||||
'spaceAfter' => 400,
|
||||
]);
|
||||
|
||||
foreach ($projectsData as $project) {
|
||||
$section->addText("Project: {$project['name']}", ['bold' => true, 'size' => 14, 'color' => '000080']);
|
||||
|
||||
foreach ($project['sprints'] as $sprint) {
|
||||
$section->addText("Sprint: {$sprint['name']}", ['bold' => true, 'italic' => true, 'size' => 12, 'color' => '000000']);
|
||||
|
||||
$table = $section->addTable([
|
||||
'borderColor' => '000000',
|
||||
'borderSize' => 6,
|
||||
'cellMargin' => 80,
|
||||
]);
|
||||
|
||||
$table->addRow();
|
||||
$table->addCell(2000)->addText('Criteria', ['bold' => true]);
|
||||
$table->addCell(2000)->addText('Note', ['bold' => true]);
|
||||
$table->addCell(2000)->addText('Created By', ['bold' => true]);
|
||||
$table->addCell(2000)->addText('Points', ['bold' => true]);
|
||||
|
||||
foreach ($sprint['criterias'] as $criteria) {
|
||||
$table->addRow();
|
||||
$table->addCell(2000)->addText($criteria['criteria']);
|
||||
$table->addCell(2000)->addText($criteria['note']);
|
||||
$table->addCell(2000)->addText($criteria['createdBy']);
|
||||
$table->addCell(2000)->addText($criteria['point']);
|
||||
}
|
||||
|
||||
$section->addText(' ', [], [
|
||||
'spaceAfter' => 600,
|
||||
]);
|
||||
}
|
||||
|
||||
$section->addText(' ', [], [
|
||||
'spaceAfter' => 600,
|
||||
]);
|
||||
}
|
||||
|
||||
$tempFile = tempnam(sys_get_temp_dir(), 'word');
|
||||
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
|
||||
$objWriter->save($tempFile);
|
||||
|
||||
return response()->download($tempFile, "$user->name.docx")->deleteFileAfterSend(true);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace Modules\Admin\app\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Technical extends Model
|
||||
{
|
||||
protected $fillable = ['name', 'level'];
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace Modules\Admin\app\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class TechnicalUser extends Model
|
||||
{
|
||||
protected $table = 'technicals_users';
|
||||
protected $fillable = ['user_id', 'technical_id', 'point'];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id', 'id');
|
||||
}
|
||||
|
||||
public function technical()
|
||||
{
|
||||
return $this->belongsTo(Technical::class, 'technical_id', 'id');
|
||||
}
|
||||
}
|
||||
|
|
@ -16,6 +16,7 @@ use Modules\Admin\app\Http\Controllers\TicketController;
|
|||
use Modules\Admin\app\Http\Controllers\TimekeepingController;
|
||||
use Modules\Admin\app\Http\Controllers\TrackingController;
|
||||
use Modules\Admin\app\Http\Controllers\CriteriasController;
|
||||
use Modules\Admin\app\Http\Controllers\EvaluationController;
|
||||
use Modules\Admin\app\Http\Controllers\ProfileController;
|
||||
use Modules\Admin\app\Http\Controllers\TestCaseForSprintController;
|
||||
use Modules\Admin\app\Http\Middleware\AdminMiddleware;
|
||||
|
|
@ -173,6 +174,14 @@ Route::middleware('api')
|
|||
Route::get('/profiles-data', [ProfileController::class, 'getProfilesData'])->middleware('check.permission:admin.hr.staff.tester');
|
||||
Route::post('/profiles-data/update', [ProfileController::class, 'updateProfilesData'])->middleware('check.permission:admin.hr.staff.tester');
|
||||
});
|
||||
|
||||
Route::group([
|
||||
'prefix' => 'evaluation',
|
||||
], function () {
|
||||
Route::get('/sprint-review', [EvaluationController::class, 'sprintReview'])->middleware('check.permission:admin');
|
||||
Route::get('/technical', [EvaluationController::class, 'technical'])->middleware('check.permission:admin');
|
||||
Route::get('/report', [EvaluationController::class, 'report'])->middleware('check.permission:admin');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use App\Models\Technical;
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
use Modules\Admin\app\Models\Technical as ModelsTechnical;
|
||||
|
||||
class TechnicalsExport implements FromCollection
|
||||
{
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function collection()
|
||||
{
|
||||
return ModelsTechnical::all();
|
||||
}
|
||||
}
|
||||
|
|
@ -15,6 +15,7 @@
|
|||
"laravel/ui": "^4.3",
|
||||
"maatwebsite/excel": "^3.1",
|
||||
"nwidart/laravel-modules": "^10.0",
|
||||
"phpoffice/phpword": "^1.3",
|
||||
"pion/laravel-chunk-upload": "^1.5",
|
||||
"predis/predis": "^2.2",
|
||||
"simplesoftwareio/simple-qrcode": "^4.2",
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "6bac35902964ded629f238acceaf2c81",
|
||||
"content-hash": "3c46ab46834a4aa1178208be43c9e064",
|
||||
"packages": [
|
||||
{
|
||||
"name": "bacon/bacon-qr-code",
|
||||
|
|
@ -3389,6 +3389,58 @@
|
|||
],
|
||||
"time": "2024-01-28T10:04:15+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpoffice/math",
|
||||
"version": "0.2.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/PHPOffice/Math.git",
|
||||
"reference": "fc2eb6d1a61b058d5dac77197059db30ee3c8329"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/PHPOffice/Math/zipball/fc2eb6d1a61b058d5dac77197059db30ee3c8329",
|
||||
"reference": "fc2eb6d1a61b058d5dac77197059db30ee3c8329",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-dom": "*",
|
||||
"ext-xml": "*",
|
||||
"php": "^7.1|^8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpstan/phpstan": "^0.12.88 || ^1.0.0",
|
||||
"phpunit/phpunit": "^7.0 || ^9.0"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"PhpOffice\\Math\\": "src/Math/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Progi1984",
|
||||
"homepage": "https://lefevre.dev"
|
||||
}
|
||||
],
|
||||
"description": "Math - Manipulate Math Formula",
|
||||
"homepage": "https://phpoffice.github.io/Math/",
|
||||
"keywords": [
|
||||
"MathML",
|
||||
"officemathml",
|
||||
"php"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/PHPOffice/Math/issues",
|
||||
"source": "https://github.com/PHPOffice/Math/tree/0.2.0"
|
||||
},
|
||||
"time": "2024-08-12T07:30:45+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpoffice/phpspreadsheet",
|
||||
"version": "1.29.1",
|
||||
|
|
@ -3494,6 +3546,115 @@
|
|||
},
|
||||
"time": "2024-09-03T00:55:32+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpoffice/phpword",
|
||||
"version": "1.3.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/PHPOffice/PHPWord.git",
|
||||
"reference": "8392134ce4b5dba65130ba956231a1602b848b7f"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/PHPOffice/PHPWord/zipball/8392134ce4b5dba65130ba956231a1602b848b7f",
|
||||
"reference": "8392134ce4b5dba65130ba956231a1602b848b7f",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-dom": "*",
|
||||
"ext-json": "*",
|
||||
"ext-xml": "*",
|
||||
"php": "^7.1|^8.0",
|
||||
"phpoffice/math": "^0.2"
|
||||
},
|
||||
"require-dev": {
|
||||
"dompdf/dompdf": "^2.0",
|
||||
"ext-gd": "*",
|
||||
"ext-libxml": "*",
|
||||
"ext-zip": "*",
|
||||
"friendsofphp/php-cs-fixer": "^3.3",
|
||||
"mpdf/mpdf": "^8.1",
|
||||
"phpmd/phpmd": "^2.13",
|
||||
"phpstan/phpstan-phpunit": "@stable",
|
||||
"phpunit/phpunit": ">=7.0",
|
||||
"symfony/process": "^4.4 || ^5.0",
|
||||
"tecnickcom/tcpdf": "^6.5"
|
||||
},
|
||||
"suggest": {
|
||||
"dompdf/dompdf": "Allows writing PDF",
|
||||
"ext-gd2": "Allows adding images",
|
||||
"ext-xmlwriter": "Allows writing OOXML and ODF",
|
||||
"ext-xsl": "Allows applying XSL style sheet to headers, to main document part, and to footers of an OOXML template",
|
||||
"ext-zip": "Allows writing OOXML and ODF"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"PhpOffice\\PhpWord\\": "src/PhpWord"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"LGPL-3.0"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Mark Baker"
|
||||
},
|
||||
{
|
||||
"name": "Gabriel Bull",
|
||||
"email": "me@gabrielbull.com",
|
||||
"homepage": "http://gabrielbull.com/"
|
||||
},
|
||||
{
|
||||
"name": "Franck Lefevre",
|
||||
"homepage": "https://rootslabs.net/blog/"
|
||||
},
|
||||
{
|
||||
"name": "Ivan Lanin",
|
||||
"homepage": "http://ivan.lanin.org"
|
||||
},
|
||||
{
|
||||
"name": "Roman Syroeshko",
|
||||
"homepage": "http://ru.linkedin.com/pub/roman-syroeshko/34/a53/994/"
|
||||
},
|
||||
{
|
||||
"name": "Antoine de Troostembergh"
|
||||
}
|
||||
],
|
||||
"description": "PHPWord - A pure PHP library for reading and writing word processing documents (OOXML, ODF, RTF, HTML, PDF)",
|
||||
"homepage": "https://phpoffice.github.io/PHPWord/",
|
||||
"keywords": [
|
||||
"ISO IEC 29500",
|
||||
"OOXML",
|
||||
"Office Open XML",
|
||||
"OpenDocument",
|
||||
"OpenXML",
|
||||
"PhpOffice",
|
||||
"PhpWord",
|
||||
"Rich Text Format",
|
||||
"WordprocessingML",
|
||||
"doc",
|
||||
"docx",
|
||||
"html",
|
||||
"odf",
|
||||
"odt",
|
||||
"office",
|
||||
"pdf",
|
||||
"php",
|
||||
"reader",
|
||||
"rtf",
|
||||
"template",
|
||||
"template processor",
|
||||
"word",
|
||||
"writer"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/PHPOffice/PHPWord/issues",
|
||||
"source": "https://github.com/PHPOffice/PHPWord/tree/1.3.0"
|
||||
},
|
||||
"time": "2024-08-30T18:03:42+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpoption/phpoption",
|
||||
"version": "1.9.3",
|
||||
|
|
|
|||
Loading…
Reference in New Issue