This commit is contained in:
Saufi
2026-06-03 08:51:22 +08:00
commit a14d43fe34
347 changed files with 38197 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
<?php
namespace App\Services\Attendance;
use App\Exports\AttendanceDetailExport;
use App\Models\ExportLog;
use App\Models\PusatMengundi;
use App\Models\StaffAssignment;
use App\Models\User;
use Illuminate\Support\Facades\Storage;
class AttendanceExportService
{
public function __construct(
private readonly AttendanceDetailExport $export,
) {}
public function exportPusat(User $actor, PusatMengundi $pusatMengundi): ExportLog
{
$assignments = StaffAssignment::query()
->with(['application', 'user', 'position', 'pusatMengundi', 'saluranMengundi', 'attendance'])
->where('pusat_mengundi_id', $pusatMengundi->id)
->where('status', 'active')
->orderBy('position_id')
->orderBy('saluran_mengundi_id')
->get();
$fileName = 'attendance-'.$pusatMengundi->code.'-'.now()->format('Ymd-His').'.xlsx';
$path = 'exports/attendance/'.$fileName;
Storage::disk('local')->makeDirectory('exports/attendance');
$absolutePath = Storage::disk('local')->path($path);
$this->export->write($assignments, $absolutePath);
$log = ExportLog::query()->create([
'election_id' => $pusatMengundi->election_id,
'generated_by_user_id' => $actor->id,
'generated_at' => now(),
'report_type' => 'attendance_detail_by_pusat',
'filter_parameters' => [
'pusat_mengundi_id' => $pusatMengundi->id,
'pusat_mengundi_code' => $pusatMengundi->code,
],
'file_name' => $fileName,
'disk' => 'local',
'path' => $path,
]);
activity('exports')
->performedOn($log)
->causedBy($actor)
->withProperties([
'report_type' => 'attendance_detail_by_pusat',
'pusat_mengundi_id' => $pusatMengundi->id,
'row_count' => $assignments->count(),
])
->log('attendance_export_generated');
return $log;
}
}