58 lines
2.0 KiB
PHP
58 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Http\Concerns\SortsQuery;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\PusatMengundi;
|
|
use App\Models\StaffAssignment;
|
|
use App\Services\Attendance\AttendanceExportService;
|
|
use App\Services\Attendance\AttendanceSummaryService;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\View\View;
|
|
use Symfony\Component\HttpFoundation\StreamedResponse;
|
|
|
|
class AttendanceController extends Controller
|
|
{
|
|
use SortsQuery;
|
|
|
|
public function index(AttendanceSummaryService $summaryService): View
|
|
{
|
|
return view('admin.attendance.index', [
|
|
'pusats' => $this->sortedQuery(
|
|
PusatMengundi::query()->with(['election.settings']),
|
|
['code', 'name'],
|
|
'name'
|
|
)->paginate(15)->withQueryString(),
|
|
'summaryService' => $summaryService,
|
|
]);
|
|
}
|
|
|
|
public function show(PusatMengundi $pusatMengundi, AttendanceSummaryService $summaryService): View
|
|
{
|
|
$assignments = StaffAssignment::query()
|
|
->with(['application', 'user', 'position', 'saluranMengundi', 'attendance.recordedBy'])
|
|
->where('pusat_mengundi_id', $pusatMengundi->id)
|
|
->where('status', 'active')
|
|
->orderBy('position_id')
|
|
->orderBy('saluran_mengundi_id')
|
|
->get();
|
|
|
|
return view('admin.attendance.show', [
|
|
'pusat' => $pusatMengundi->load('election.settings'),
|
|
'assignments' => $assignments,
|
|
'summary' => $summaryService->totalsForPusat($pusatMengundi),
|
|
'roleSummaries' => $summaryService->roleTotalsForPusat($pusatMengundi),
|
|
]);
|
|
}
|
|
|
|
public function export(PusatMengundi $pusatMengundi, Request $request, AttendanceExportService $exportService): StreamedResponse
|
|
{
|
|
$exportLog = $exportService->exportPusat($request->user(), $pusatMengundi);
|
|
|
|
return Storage::disk($exportLog->disk ?? 'local')
|
|
->download($exportLog->path, $exportLog->file_name);
|
|
}
|
|
}
|