penambahan fitur ekspor di hse, qma, dan pg
This commit is contained in:
@@ -5,8 +5,12 @@ namespace App\Http\Controllers\Hse;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Employee;
|
||||
use App\Models\User;
|
||||
use App\Services\SimperPdfExporter;
|
||||
use App\Services\SimpleXlsxExporter;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\View\View;
|
||||
|
||||
@@ -62,9 +66,9 @@ class EmployeeController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Tampilkan daftar master karyawan HSE & status SIMPER.
|
||||
* Helper query builder untuk memfilter master data karyawan & status SIMPER.
|
||||
*/
|
||||
public function index(Request $request): View
|
||||
private function getFilteredEmployees(Request $request): Builder
|
||||
{
|
||||
$query = Employee::query();
|
||||
|
||||
@@ -114,11 +118,171 @@ class EmployeeController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$employees = $query->orderBy('name')->paginate(20)->withQueryString();
|
||||
return $query->orderBy('name');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tampilkan daftar master karyawan HSE & status SIMPER.
|
||||
*/
|
||||
public function index(Request $request): View
|
||||
{
|
||||
$employees = $this->getFilteredEmployees($request)->paginate(20)->withQueryString();
|
||||
|
||||
return view('hse.employees_index', compact('employees'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Ekspor data master SIMPER karyawan ke format Excel (.xlsx).
|
||||
*/
|
||||
public function exportExcel(Request $request): Response
|
||||
{
|
||||
$employees = $this->getFilteredEmployees($request)->get();
|
||||
|
||||
$today = now()->translatedFormat('d F Y, H:i');
|
||||
$driverFilter = match ($request->input('driver_status')) {
|
||||
'driver' => 'Driver',
|
||||
'non_driver' => 'Bukan Driver',
|
||||
default => 'Semua Status Driver'
|
||||
};
|
||||
$simperFilter = match ($request->input('simper_status')) {
|
||||
'valid' => 'Masih Berlaku (Aktif)',
|
||||
'expiring_soon' => 'Segera Habis (≤ 30 Hari)',
|
||||
'expired' => 'Kedaluwarsa (Expired)',
|
||||
default => 'Semua Masa Berlaku'
|
||||
};
|
||||
|
||||
$metaLines = [
|
||||
'Filter: ' . $driverFilter . ' | ' . $simperFilter . ($request->filled('search') ? ' | Pencarian: "' . $request->input('search') . '"' : ''),
|
||||
'Total Data: ' . $employees->count() . ' Karyawan | Tanggal Dicetak: ' . $today . ' WIB',
|
||||
];
|
||||
|
||||
$headers = [
|
||||
'No' => 6,
|
||||
'NIK' => 16,
|
||||
'Nama Lengkap' => 30,
|
||||
'Jabatan' => 24,
|
||||
'Unit Kerja' => 20,
|
||||
'Divisi' => 20,
|
||||
'Status Driver' => 16,
|
||||
'Masa Berlaku SIMPER' => 22,
|
||||
'Status SIMPER' => 24,
|
||||
];
|
||||
|
||||
$rows = [];
|
||||
$now = now();
|
||||
$soon = now()->addDays(30);
|
||||
|
||||
foreach ($employees as $idx => $emp) {
|
||||
$isDriver = $emp->is_operator;
|
||||
$expDate = $emp->simper_expired_at ? $emp->simper_expired_at->format('d/m/Y') : '-';
|
||||
|
||||
if (! $isDriver) {
|
||||
$statusText = 'Bukan Driver';
|
||||
} elseif (! $emp->simper_expired_at) {
|
||||
$statusText = 'Belum Ada SIMPER';
|
||||
} elseif ($emp->simper_expired_at->isPast() && ! $emp->simper_expired_at->isToday()) {
|
||||
$statusText = 'Kedaluwarsa (Expired)';
|
||||
} elseif ($emp->simper_expired_at->lte($soon)) {
|
||||
$statusText = 'Segera Habis (≤ 30 Hari)';
|
||||
} else {
|
||||
$statusText = 'Masih Berlaku (Aktif)';
|
||||
}
|
||||
|
||||
$rows[] = [
|
||||
$idx + 1,
|
||||
$emp->nik,
|
||||
$emp->name,
|
||||
$emp->position ?: '-',
|
||||
$emp->unit_kerja ?: '-',
|
||||
$emp->division ?: '-',
|
||||
$isDriver ? 'Driver' : 'Bukan Driver',
|
||||
$expDate,
|
||||
$statusText,
|
||||
];
|
||||
}
|
||||
|
||||
$alignments = [
|
||||
'center', // No
|
||||
'center', // NIK
|
||||
'left', // Nama
|
||||
'left', // Jabatan
|
||||
'left', // Unit Kerja
|
||||
'left', // Divisi
|
||||
'center', // Status Driver
|
||||
'center', // Masa Berlaku
|
||||
'center', // Status SIMPER
|
||||
];
|
||||
|
||||
$fileName = 'Laporan_Data_Simper_' . now()->format('Ymd_Hi') . '.xlsx';
|
||||
$binary = SimpleXlsxExporter::create(
|
||||
'LAPORAN DATA SIMPER & STATUS DRIVER KARYAWAN - PT KERINCI MERANGIN HIDRO',
|
||||
$metaLines,
|
||||
$headers,
|
||||
$rows,
|
||||
$alignments
|
||||
);
|
||||
|
||||
return response($binary, 200, [
|
||||
'Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
'Content-Disposition' => 'attachment; filename="' . $fileName . '"',
|
||||
'Content-Length' => strlen($binary),
|
||||
'Cache-Control' => 'max-age=0, no-cache, no-store, must-revalidate',
|
||||
'Pragma' => 'public',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tampilkan laporan resmi SIMPER ke format PDF (Pratinjau PDF Asli dengan Logo PT KMH).
|
||||
*/
|
||||
public function exportPdf(Request $request): Response
|
||||
{
|
||||
$employees = $this->getFilteredEmployees($request)->get();
|
||||
|
||||
$driverFilter = match ($request->input('driver_status')) {
|
||||
'driver' => 'Driver',
|
||||
'non_driver' => 'Bukan Driver',
|
||||
default => 'Semua Status Driver'
|
||||
};
|
||||
$simperFilter = match ($request->input('simper_status')) {
|
||||
'valid' => 'Masih Berlaku (Aktif)',
|
||||
'expiring_soon' => 'Segera Habis (≤ 30 Hari)',
|
||||
'expired' => 'Kedaluwarsa (Expired)',
|
||||
default => 'Semua Masa Berlaku'
|
||||
};
|
||||
|
||||
$totalActive = $employees->filter(fn ($e) => $e->is_operator && $e->hasValidSimper())->count();
|
||||
$totalExpired = $employees->filter(fn ($e) => $e->is_operator && ! $e->hasValidSimper())->count();
|
||||
$totalNonDriver = $employees->filter(fn ($e) => ! $e->is_operator)->count();
|
||||
|
||||
$metaLeft = [
|
||||
'Kategori' => $driverFilter,
|
||||
'Tanggal Cetak' => now()->translatedFormat('d F Y, H:i') . ' WIB',
|
||||
];
|
||||
|
||||
$statusSummary = "{$totalActive} Aktif, {$totalExpired} Expired";
|
||||
if ($totalNonDriver > 0) {
|
||||
$statusSummary .= ", {$totalNonDriver} Non-Driver";
|
||||
}
|
||||
|
||||
$metaRight = [
|
||||
'Total Karyawan' => $employees->count() . ' Orang',
|
||||
'Status SIMPER' => $statusSummary,
|
||||
];
|
||||
|
||||
$subtitle = 'Data Karyawan & Driver - ' . now()->translatedFormat('d F Y');
|
||||
|
||||
$pdfBinary = SimperPdfExporter::generate($employees, $metaLeft, $metaRight, $subtitle);
|
||||
$fileName = 'Laporan_Daftar_Simper_' . now()->format('Ymd_Hi') . '.pdf';
|
||||
|
||||
return response($pdfBinary, 200, [
|
||||
'Content-Type' => 'application/pdf',
|
||||
'Content-Disposition' => 'inline; filename="' . $fileName . '"',
|
||||
'Content-Length' => strlen($pdfBinary),
|
||||
'Cache-Control' => 'private, max-age=0, must-revalidate',
|
||||
'Pragma' => 'public',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simpan data karyawan baru beserta izin SIMPER (Form modal tambah karyawan).
|
||||
*/
|
||||
|
||||
@@ -6,18 +6,21 @@ use App\Http\Controllers\Controller;
|
||||
use App\Models\Gate;
|
||||
use App\Models\SecurityGuard;
|
||||
use App\Models\User;
|
||||
use App\Services\PgTablePdfExporter;
|
||||
use App\Services\SimpleXlsxExporter;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\View\View;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class SecurityGuardController extends Controller
|
||||
{
|
||||
/**
|
||||
* Tampilkan daftar petugas Satpam beserta daftar pos gerbang.
|
||||
* Bangun query petugas Satpam berdasarkan filter request.
|
||||
*/
|
||||
public function index(Request $request): View
|
||||
protected function getGuardsQuery(Request $request)
|
||||
{
|
||||
$query = SecurityGuard::with(['gate', 'user']);
|
||||
|
||||
@@ -43,7 +46,16 @@ class SecurityGuardController extends Controller
|
||||
$query->where('gate_id', (int) $request->input('gate_id'));
|
||||
}
|
||||
|
||||
$guards = $query->orderBy('team')
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tampilkan daftar petugas Satpam beserta daftar pos gerbang.
|
||||
*/
|
||||
public function index(Request $request): View
|
||||
{
|
||||
$guards = $this->getGuardsQuery($request)
|
||||
->orderBy('team')
|
||||
->orderBy('name')
|
||||
->paginate(20)
|
||||
->withQueryString();
|
||||
@@ -53,6 +65,147 @@ class SecurityGuardController extends Controller
|
||||
return view('pg.guards_index', compact('guards', 'gates'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Ekspor data petugas Satpam ke format Excel (.xlsx).
|
||||
*/
|
||||
public function exportExcel(Request $request): Response
|
||||
{
|
||||
$guards = $this->getGuardsQuery($request)
|
||||
->orderBy('team')
|
||||
->orderBy('name')
|
||||
->get();
|
||||
|
||||
$filters = [];
|
||||
if ($request->filled('search')) {
|
||||
$filters[] = "Pencarian: \"{$request->input('search')}\"";
|
||||
}
|
||||
if ($request->filled('team')) {
|
||||
$filters[] = "Regu {$request->input('team')}";
|
||||
}
|
||||
if ($request->filled('gate_id')) {
|
||||
$gate = Gate::find($request->input('gate_id'));
|
||||
$filters[] = "Pos: " . ($gate ? $gate->name : 'ID ' . $request->input('gate_id'));
|
||||
}
|
||||
$filterDesc = empty($filters) ? 'Semua Petugas Satpam' : implode(' | ', $filters);
|
||||
|
||||
$metaLines = [
|
||||
'Sistem: Modul Private Guard (PG) - PT Kerinci Merangin Hidro',
|
||||
'Filter: ' . $filterDesc,
|
||||
'Tanggal Cetak: ' . now()->translatedFormat('d F Y H:i') . ' WIB',
|
||||
'Total Data: ' . $guards->count() . ' Personil Satpam',
|
||||
];
|
||||
|
||||
$headers = [
|
||||
'No' => 6,
|
||||
'ID Satpam' => 16,
|
||||
'Nama Lengkap' => 28,
|
||||
'Regu' => 14,
|
||||
'Penempatan Pos' => 24,
|
||||
'Status' => 14,
|
||||
'Username Akun' => 18,
|
||||
];
|
||||
|
||||
$rows = [];
|
||||
foreach ($guards as $idx => $g) {
|
||||
$badge = $g->badge_id ?? ('SEC-' . str_pad($g->id, 3, '0', STR_PAD_LEFT));
|
||||
$rows[] = [
|
||||
$idx + 1,
|
||||
$badge,
|
||||
$g->name,
|
||||
'Regu ' . $g->team,
|
||||
$g->gate ? $g->gate->name : 'Belum Ditentukan',
|
||||
$g->is_active ? 'Aktif' : 'Nonaktif',
|
||||
$g->user ? $g->user->username : ($g->badge_id ?? '-'),
|
||||
];
|
||||
}
|
||||
|
||||
$alignments = ['center', 'center', 'left', 'center', 'left', 'center', 'center'];
|
||||
$xlsxContent = SimpleXlsxExporter::create('DATA PETUGAS SATPAM - PT KMH', $metaLines, $headers, $rows, $alignments);
|
||||
|
||||
$fileName = 'data_satpam_' . date('Ymd_His') . '.xlsx';
|
||||
|
||||
return response($xlsxContent, 200, [
|
||||
'Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
'Content-Disposition' => 'attachment; filename="' . $fileName . '"',
|
||||
'Cache-Control' => 'max-age=0',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ekspor data petugas Satpam ke format PDF (preview langsung di browser).
|
||||
*/
|
||||
public function exportPdf(Request $request): Response
|
||||
{
|
||||
$guards = $this->getGuardsQuery($request)
|
||||
->orderBy('team')
|
||||
->orderBy('name')
|
||||
->get();
|
||||
|
||||
$teamDesc = $request->filled('team') ? 'Regu ' . $request->input('team') : 'Semua Regu';
|
||||
$gateDesc = 'Semua Penempatan';
|
||||
if ($request->filled('gate_id')) {
|
||||
$gate = Gate::find($request->input('gate_id'));
|
||||
$gateDesc = $gate ? $gate->name : 'ID ' . $request->input('gate_id');
|
||||
}
|
||||
|
||||
$metaLeft = [
|
||||
'Modul' => 'Data Petugas Satpam Lapangan',
|
||||
'Filter Regu' => $teamDesc,
|
||||
'Pos Gerbang' => $gateDesc,
|
||||
];
|
||||
|
||||
if ($request->filled('search')) {
|
||||
$metaLeft['Pencarian'] = '"' . $request->input('search') . '"';
|
||||
}
|
||||
|
||||
$metaRight = [
|
||||
'Tanggal Cetak' => now()->translatedFormat('d M Y, H:i') . ' WIB',
|
||||
'Total Personil' => $guards->count() . ' Orang',
|
||||
'Dicetak Oleh' => auth()->user()->name ?? 'Administrator PG',
|
||||
];
|
||||
|
||||
$columns = [
|
||||
['title' => 'NO', 'width' => 12, 'align' => 'C', 'bold' => true],
|
||||
['title' => 'ID SATPAM', 'width' => 32, 'align' => 'C', 'bold' => true],
|
||||
['title' => 'NAMA LENGKAP', 'width' => 70, 'align' => 'L', 'bold' => true, 'max_char' => 38],
|
||||
['title' => 'REGU', 'width' => 28, 'align' => 'C', 'is_status' => true],
|
||||
['title' => 'PENEMPATAN POS', 'width' => 65, 'align' => 'L', 'max_char' => 34],
|
||||
['title' => 'STATUS', 'width' => 28, 'align' => 'C', 'is_status' => true],
|
||||
['title' => 'USERNAME AKUN', 'width' => 32, 'align' => 'C'],
|
||||
];
|
||||
|
||||
$rows = [];
|
||||
foreach ($guards as $idx => $g) {
|
||||
$badge = $g->badge_id ?? ('SEC-' . str_pad($g->id, 3, '0', STR_PAD_LEFT));
|
||||
$rows[] = [
|
||||
$idx + 1,
|
||||
$badge,
|
||||
$g->name,
|
||||
'Regu ' . $g->team,
|
||||
$g->gate ? $g->gate->name : 'Belum Ditentukan',
|
||||
$g->is_active ? 'Aktif' : 'Nonaktif',
|
||||
$g->user ? $g->user->username : ($g->badge_id ?? '-'),
|
||||
];
|
||||
}
|
||||
|
||||
$pdfContent = PgTablePdfExporter::generate(
|
||||
'Laporan Data Petugas Satpam',
|
||||
'Rekapitulasi Personil Jaga & Penempatan Pos Gerbang',
|
||||
'MODUL PRIVATE GUARD (PG) - RKM-KMH',
|
||||
$metaLeft,
|
||||
$metaRight,
|
||||
$columns,
|
||||
$rows
|
||||
);
|
||||
|
||||
$fileName = 'laporan_data_satpam_' . date('Ymd_His') . '.pdf';
|
||||
|
||||
return response($pdfContent, 200, [
|
||||
'Content-Type' => 'application/pdf',
|
||||
'Content-Disposition' => 'inline; filename="' . $fileName . '"',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simpan data petugas Satpam baru dan otomatis buatkan akun login pos.
|
||||
*/
|
||||
|
||||
@@ -6,16 +6,19 @@ use App\Http\Controllers\Controller;
|
||||
use App\Models\Gate;
|
||||
use App\Models\SecurityGuard;
|
||||
use App\Models\VehicleActivity;
|
||||
use App\Services\PgTablePdfExporter;
|
||||
use App\Services\SimpleXlsxExporter;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class VerificationLogController extends Controller
|
||||
{
|
||||
/**
|
||||
* Tampilkan rekapitulasi audit dan log riwayat verifikasi gerbang oleh petugas Satpam.
|
||||
* Bangun query log verifikasi gerbang berdasarkan filter request.
|
||||
*/
|
||||
public function index(Request $request): View
|
||||
protected function getVerificationLogsQuery(Request $request)
|
||||
{
|
||||
$query = VehicleActivity::with(['vehicle', 'driver', 'gate', 'securityGuard'])
|
||||
->orderByRaw('COALESCE(validated_at, recorded_at) DESC');
|
||||
@@ -86,10 +89,229 @@ class VerificationLogController extends Controller
|
||||
});
|
||||
}
|
||||
|
||||
$activities = $query->paginate(20)->withQueryString();
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tampilkan rekapitulasi audit dan log riwayat verifikasi gerbang oleh petugas Satpam.
|
||||
*/
|
||||
public function index(Request $request): View
|
||||
{
|
||||
$activities = $this->getVerificationLogsQuery($request)->paginate(20)->withQueryString();
|
||||
$gates = Gate::where('is_active', true)->orderBy('name')->get();
|
||||
$guards = SecurityGuard::orderBy('name')->get();
|
||||
|
||||
$today = Carbon::today()->toDateString();
|
||||
$startDate = $request->input('start_date', $today);
|
||||
$endDate = $request->input('end_date', $today);
|
||||
|
||||
return view('pg.verification_logs', compact('activities', 'gates', 'guards', 'startDate', 'endDate'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Ekspor data log verifikasi gerbang ke format Excel (.xlsx).
|
||||
*/
|
||||
public function exportExcel(Request $request): Response
|
||||
{
|
||||
$activities = $this->getVerificationLogsQuery($request)->get();
|
||||
|
||||
$today = Carbon::today()->toDateString();
|
||||
$startDate = $request->input('start_date', $today);
|
||||
$endDate = $request->input('end_date', $today);
|
||||
$period = ($startDate && $endDate) ? "{$startDate} s/d {$endDate}" : ($startDate ? "Sejak {$startDate}" : 'Semua Periode');
|
||||
|
||||
$filters = ["Periode: {$period}"];
|
||||
if ($request->filled('team')) {
|
||||
$filters[] = "Regu {$request->input('team')}";
|
||||
}
|
||||
if ($request->filled('security_guard_id')) {
|
||||
$guard = SecurityGuard::find($request->input('security_guard_id'));
|
||||
$filters[] = "Satpam: " . ($guard ? $guard->name : 'ID ' . $request->input('security_guard_id'));
|
||||
}
|
||||
if ($request->filled('gate_id')) {
|
||||
$gate = Gate::find($request->input('gate_id'));
|
||||
$filters[] = "Pos: " . ($gate ? $gate->name : 'ID ' . $request->input('gate_id'));
|
||||
}
|
||||
if ($request->filled('direction')) {
|
||||
$filters[] = "Arah: " . ($request->input('direction') === 'in' ? 'Masuk' : 'Keluar');
|
||||
}
|
||||
if ($request->filled('status')) {
|
||||
$filters[] = "Status: " . ucfirst($request->input('status'));
|
||||
}
|
||||
if ($request->filled('search')) {
|
||||
$filters[] = "Pencarian: \"{$request->input('search')}\"";
|
||||
}
|
||||
|
||||
$metaLines = [
|
||||
'Sistem: Modul Private Guard (PG) - PT Kerinci Merangin Hidro',
|
||||
'Filter: ' . implode(' | ', $filters),
|
||||
'Tanggal Cetak: ' . now()->translatedFormat('d F Y H:i') . ' WIB',
|
||||
'Total Data: ' . $activities->count() . ' Riwayat Perlintasan Gerbang',
|
||||
];
|
||||
|
||||
$headers = [
|
||||
'No' => 6,
|
||||
'Waktu Verifikasi' => 20,
|
||||
'No. Transaksi' => 20,
|
||||
'Petugas Satpam' => 24,
|
||||
'Regu' => 12,
|
||||
'Pos Gerbang' => 20,
|
||||
'Plat Nomor' => 16,
|
||||
'Merek & Tipe' => 24,
|
||||
'Driver' => 24,
|
||||
'NIK Driver' => 16,
|
||||
'Arah' => 12,
|
||||
'Odometer (KM)' => 16,
|
||||
'Jarak (KM)' => 14,
|
||||
'Status' => 14,
|
||||
'Catatan Tolak' => 28,
|
||||
];
|
||||
|
||||
$rows = [];
|
||||
foreach ($activities as $idx => $item) {
|
||||
$validatedTime = $item->validated_at ?? $item->recorded_at;
|
||||
$waktu = $validatedTime ? $validatedTime->format('d/m/Y H:i') : '-';
|
||||
$satpam = $item->securityGuard ? $item->securityGuard->name : '-';
|
||||
$regu = $item->securityGuard ? 'Regu ' . $item->securityGuard->team : '-';
|
||||
$pos = $item->gate ? $item->gate->name : '-';
|
||||
$plat = $item->vehicle ? $item->vehicle->license_plate : '-';
|
||||
$merek = $item->vehicle ? ($item->vehicle->brand_type . ' (' . $item->vehicle->code . ')') : '-';
|
||||
$driver = $item->driver ? $item->driver->name : '-';
|
||||
$nik = $item->driver ? ($item->driver->nik ?? '-') : '-';
|
||||
$arah = ($item->direction === 'in') ? 'Masuk' : 'Keluar';
|
||||
$status = match($item->validation_status) {
|
||||
'approved' => 'Disetujui',
|
||||
'rejected' => 'Ditolak',
|
||||
default => 'Menunggu',
|
||||
};
|
||||
|
||||
$rows[] = [
|
||||
$idx + 1,
|
||||
$waktu,
|
||||
$item->transaction_no,
|
||||
$satpam,
|
||||
$regu,
|
||||
$pos,
|
||||
$plat,
|
||||
$merek,
|
||||
$driver,
|
||||
$nik,
|
||||
$arah,
|
||||
(int) $item->current_km,
|
||||
$item->distance > 0 ? (int) $item->distance : 0,
|
||||
$status,
|
||||
$item->rejection_note ?? '-',
|
||||
];
|
||||
}
|
||||
|
||||
$alignments = ['center', 'center', 'center', 'left', 'center', 'left', 'center', 'left', 'left', 'center', 'center', 'right', 'right', 'center', 'left'];
|
||||
$xlsxContent = SimpleXlsxExporter::create('LOG AKTIVITAS GERBANG - PT KMH', $metaLines, $headers, $rows, $alignments);
|
||||
|
||||
$fileName = 'log_aktivitas_gerbang_' . date('Ymd_His') . '.xlsx';
|
||||
|
||||
return response($xlsxContent, 200, [
|
||||
'Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
'Content-Disposition' => 'attachment; filename="' . $fileName . '"',
|
||||
'Cache-Control' => 'max-age=0',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ekspor data log verifikasi gerbang ke format PDF (preview langsung di browser).
|
||||
*/
|
||||
public function exportPdf(Request $request): Response
|
||||
{
|
||||
$activities = $this->getVerificationLogsQuery($request)->get();
|
||||
|
||||
$today = Carbon::today()->toDateString();
|
||||
$startDate = $request->input('start_date', $today);
|
||||
$endDate = $request->input('end_date', $today);
|
||||
$period = ($startDate && $endDate) ? "{$startDate} s/d {$endDate}" : ($startDate ? "Sejak {$startDate}" : 'Semua Periode');
|
||||
|
||||
$gateDesc = 'Semua Pos';
|
||||
if ($request->filled('gate_id')) {
|
||||
$gate = Gate::find($request->input('gate_id'));
|
||||
$gateDesc = $gate ? $gate->name : 'ID ' . $request->input('gate_id');
|
||||
}
|
||||
|
||||
$metaLeft = [
|
||||
'Modul' => 'Log Verifikasi Pos Gerbang',
|
||||
'Periode Tanggal' => $period,
|
||||
'Pos Gerbang' => $gateDesc,
|
||||
];
|
||||
|
||||
if ($request->filled('team')) {
|
||||
$metaLeft['Regu Satpam'] = 'Regu ' . $request->input('team');
|
||||
}
|
||||
|
||||
if ($request->filled('direction')) {
|
||||
$metaLeft['Arah Gerbang'] = ($request->input('direction') === 'in') ? 'Masuk' : 'Keluar';
|
||||
}
|
||||
|
||||
$metaRight = [
|
||||
'Tanggal Cetak' => now()->translatedFormat('d M Y, H:i') . ' WIB',
|
||||
'Total Transaksi' => $activities->count() . ' Record',
|
||||
'Dicetak Oleh' => auth()->user()->name ?? 'Administrator PG',
|
||||
];
|
||||
|
||||
$columns = [
|
||||
['title' => 'NO', 'width' => 9, 'align' => 'C', 'bold' => true],
|
||||
['title' => 'WAKTU', 'width' => 26, 'align' => 'C'],
|
||||
['title' => 'NO. TRANSAKSI', 'width' => 28, 'align' => 'C', 'bold' => true],
|
||||
['title' => 'PETUGAS SATPAM', 'width' => 34, 'align' => 'L', 'max_char' => 20],
|
||||
['title' => 'POS GERBANG', 'width' => 28, 'align' => 'L', 'max_char' => 16],
|
||||
['title' => 'KENDARAAN', 'width' => 35, 'align' => 'L', 'max_char' => 20],
|
||||
['title' => 'DRIVER / NIK', 'width' => 35, 'align' => 'L', 'max_char' => 20],
|
||||
['title' => 'ARAH', 'width' => 16, 'align' => 'C', 'is_status' => true],
|
||||
['title' => 'ODOMETER', 'width' => 22, 'align' => 'R'],
|
||||
['title' => 'STATUS', 'width' => 34, 'align' => 'C', 'is_status' => true, 'max_char' => 22],
|
||||
];
|
||||
|
||||
$rows = [];
|
||||
foreach ($activities as $idx => $item) {
|
||||
$validatedTime = $item->validated_at ?? $item->recorded_at;
|
||||
$waktu = $validatedTime ? $validatedTime->format('d/m/Y H:i') : '-';
|
||||
$satpam = $item->securityGuard ? $item->securityGuard->name : '-';
|
||||
$pos = $item->gate ? $item->gate->name : '-';
|
||||
$kendaraan = $item->vehicle ? ($item->vehicle->license_plate . ' (' . $item->vehicle->code . ')') : '-';
|
||||
$driver = $item->driver ? ($item->driver->name . ' - ' . ($item->driver->nik ?? '')) : '-';
|
||||
$arah = ($item->direction === 'in') ? 'Masuk' : 'Keluar';
|
||||
$status = match($item->validation_status) {
|
||||
'approved' => 'Disetujui',
|
||||
'rejected' => 'Ditolak' . ($item->rejection_note ? ' (' . $item->rejection_note . ')' : ''),
|
||||
default => 'Menunggu',
|
||||
};
|
||||
$odometer = number_format($item->current_km ?? 0, 0, ',', '.') . ' KM';
|
||||
|
||||
$rows[] = [
|
||||
$idx + 1,
|
||||
$waktu,
|
||||
$item->transaction_no,
|
||||
$satpam,
|
||||
$pos,
|
||||
$kendaraan,
|
||||
$driver,
|
||||
$arah,
|
||||
$odometer,
|
||||
$status,
|
||||
];
|
||||
}
|
||||
|
||||
$pdfContent = PgTablePdfExporter::generate(
|
||||
'Laporan Log Riwayat Verifikasi Gerbang',
|
||||
'Rekapitulasi Audit Lalu Lintas Kendaraan Masuk & Keluar Pos Gerbang',
|
||||
'MODUL PRIVATE GUARD (PG) - RKM-KMH',
|
||||
$metaLeft,
|
||||
$metaRight,
|
||||
$columns,
|
||||
$rows
|
||||
);
|
||||
|
||||
$fileName = 'log_verifikasi_gerbang_' . date('Ymd_His') . '.pdf';
|
||||
|
||||
return response($pdfContent, 200, [
|
||||
'Content-Type' => 'application/pdf',
|
||||
'Content-Disposition' => 'inline; filename="' . $fileName . '"',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,21 +5,25 @@ namespace App\Http\Controllers\Qma;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Gate;
|
||||
use App\Models\VehicleActivity;
|
||||
use App\Services\QmaTablePdfExporter;
|
||||
use App\Services\SimpleXlsxExporter;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class ActivityLogController extends Controller
|
||||
{
|
||||
/**
|
||||
* Tampilkan Log Aktivitas QMA 10 Kolom lengkap dengan filter tanggal dan gate.
|
||||
* Helper query builder untuk log aktivitas kendaraan dengan seluruh filter aktif.
|
||||
*/
|
||||
public function index(Request $request): View
|
||||
private function getFilteredActivityQuery(Request $request): Builder
|
||||
{
|
||||
$query = VehicleActivity::with(['vehicle', 'driver', 'gate', 'securityGuard'])
|
||||
->latest('recorded_at');
|
||||
|
||||
// Filter Rentang Tanggal (Default Hari Ini)
|
||||
// Filter Rentang Tanggal (Default Hari Ini jika tidak diisi)
|
||||
$today = Carbon::today()->toDateString();
|
||||
$startDate = $request->input('start_date', $today);
|
||||
$endDate = $request->input('end_date', $today);
|
||||
@@ -64,12 +68,225 @@ class ActivityLogController extends Controller
|
||||
$query->where('validation_status', $request->input('status'));
|
||||
}
|
||||
|
||||
$activities = $query->paginate(20)->withQueryString();
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tampilkan Log Aktivitas QMA 10 Kolom lengkap dengan filter tanggal dan gate.
|
||||
*/
|
||||
public function index(Request $request): View
|
||||
{
|
||||
$today = Carbon::today()->toDateString();
|
||||
$startDate = $request->input('start_date', $today);
|
||||
$endDate = $request->input('end_date', $today);
|
||||
|
||||
$activities = $this->getFilteredActivityQuery($request)->paginate(20)->withQueryString();
|
||||
$gates = Gate::where('is_active', true)->orderBy('name')->get();
|
||||
|
||||
return view('qma.activity_log', compact('activities', 'gates', 'startDate', 'endDate'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Ekspor Log Aktivitas Kendaraan (Timesheet LV) ke format Excel (.xlsx).
|
||||
*/
|
||||
public function exportExcel(Request $request): Response
|
||||
{
|
||||
$activities = $this->getFilteredActivityQuery($request)->get();
|
||||
|
||||
$today = Carbon::today()->toDateString();
|
||||
$startDate = $request->input('start_date', $today);
|
||||
$endDate = $request->input('end_date', $today);
|
||||
|
||||
$gateText = 'Semua Gerbang';
|
||||
if ($request->filled('gate_id')) {
|
||||
$gateObj = Gate::find($request->input('gate_id'));
|
||||
if ($gateObj) $gateText = $gateObj->name;
|
||||
}
|
||||
|
||||
$dirText = $request->filled('direction') ? ($request->input('direction') === 'in' ? 'Masuk (In)' : 'Keluar (Out)') : 'Semua Arah';
|
||||
$statusText = $request->filled('status') ? ($request->input('status') === 'approved' ? 'Disetujui PG' : 'Menunggu PG') : 'Semua Status';
|
||||
$printedAt = now()->translatedFormat('d F Y, H:i');
|
||||
|
||||
$metaLines = [
|
||||
'Periode: ' . Carbon::parse($startDate)->translatedFormat('d M Y') . ' s/d ' . Carbon::parse($endDate)->translatedFormat('d M Y') .
|
||||
' | Gerbang: ' . $gateText . ' | Arah: ' . $dirText . ' | Status: ' . $statusText,
|
||||
'Total Data: ' . $activities->count() . ' Catatan Pergerakan | Tanggal Dicetak: ' . $printedAt . ' WIB',
|
||||
];
|
||||
|
||||
$headers = [
|
||||
'No' => 6,
|
||||
'Tanggal & Waktu' => 20,
|
||||
'Kode LV' => 14,
|
||||
'Unit Kendaraan' => 28,
|
||||
'No. Polisi' => 16,
|
||||
'Penanggung Jawab' => 22,
|
||||
'Pengemudi (Driver)' => 26,
|
||||
'Pos Gerbang' => 20,
|
||||
'Arah' => 12,
|
||||
'KM Lalu' => 14,
|
||||
'KM Kini' => 14,
|
||||
'Selisih KM' => 14,
|
||||
'Aktivitas / Keperluan' => 34,
|
||||
'Status PG' => 18,
|
||||
'Petugas Security' => 22,
|
||||
];
|
||||
|
||||
$rows = [];
|
||||
foreach ($activities as $idx => $act) {
|
||||
$formattedDate = $act->recorded_at ? $act->recorded_at->translatedFormat('d/m/Y H:i') . ' WIB' : '-';
|
||||
$vehicleCode = $act->vehicle?->code ?: '-';
|
||||
$vehicleUnit = $act->vehicle?->brand_type ?: '-';
|
||||
$plat = $act->vehicle?->license_plate ?: '-';
|
||||
$dept = $act->vehicle?->department ?: ($act->vehicle?->division ?: '-');
|
||||
$driverName = $act->driver ? $act->driver->name . ' (' . $act->driver->nik . ')' : '-';
|
||||
$gateName = $act->gate?->name ?: '-';
|
||||
$direction = strtoupper($act->direction ?: '-');
|
||||
$prevKm = $act->previous_km !== null ? number_format($act->previous_km, 0, ',', '.') : '-';
|
||||
$currKm = $act->current_km !== null ? number_format($act->current_km, 0, ',', '.') : '-';
|
||||
$diffKm = $act->distance !== null ? number_format($act->distance, 0, ',', '.') : '-';
|
||||
$purpose = $act->purpose ?: '-';
|
||||
$statusPg = $act->validation_status === 'approved' ? 'Disetujui' : ($act->validation_status === 'rejected' ? 'Ditolak' : 'Menunggu PG');
|
||||
$guard = $act->securityGuard?->name ?: '-';
|
||||
|
||||
$rows[] = [
|
||||
$idx + 1,
|
||||
$formattedDate,
|
||||
$vehicleCode,
|
||||
$vehicleUnit,
|
||||
$plat,
|
||||
$dept,
|
||||
$driverName,
|
||||
$gateName,
|
||||
$direction,
|
||||
$prevKm,
|
||||
$currKm,
|
||||
$diffKm,
|
||||
$purpose,
|
||||
$statusPg,
|
||||
$guard,
|
||||
];
|
||||
}
|
||||
|
||||
$alignments = ['center', 'center', 'center', 'left', 'center', 'left', 'left', 'center', 'center', 'right', 'right', 'right', 'left', 'center', 'left'];
|
||||
$title = 'LAPORAN TIMESHEET & LOG AKTIVITAS LIGHT VEHICLE - PT KERINCI MERANGIN HIDRO';
|
||||
$fileName = 'Laporan_Timesheet_LV_' . now()->format('Ymd_Hi') . '.xlsx';
|
||||
|
||||
$binary = SimpleXlsxExporter::create($title, $metaLines, $headers, $rows, $alignments);
|
||||
|
||||
return response($binary, 200, [
|
||||
'Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
'Content-Disposition' => 'attachment; filename="' . $fileName . '"',
|
||||
'Content-Length' => strlen($binary),
|
||||
'Cache-Control' => 'max-age=0, no-cache, no-store, must-revalidate',
|
||||
'Pragma' => 'public',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ekspor Log Aktivitas Kendaraan (Timesheet LV) ke format PDF (Pratinjau Asli dengan Logo PT KMH).
|
||||
*/
|
||||
public function exportPdf(Request $request): Response
|
||||
{
|
||||
$activities = $this->getFilteredActivityQuery($request)->get();
|
||||
|
||||
$today = Carbon::today()->toDateString();
|
||||
$startDate = $request->input('start_date', $today);
|
||||
$endDate = $request->input('end_date', $today);
|
||||
|
||||
$gateText = 'Semua Gerbang';
|
||||
if ($request->filled('gate_id')) {
|
||||
$gateObj = Gate::find($request->input('gate_id'));
|
||||
if ($gateObj) $gateText = $gateObj->name;
|
||||
}
|
||||
|
||||
$dirText = $request->filled('direction') ? ($request->input('direction') === 'in' ? 'Masuk (In)' : 'Keluar (Out)') : 'Semua Arah';
|
||||
$statusText = $request->filled('status') ? ($request->input('status') === 'approved' ? 'Disetujui PG' : 'Menunggu PG') : 'Semua Status';
|
||||
$dateRangeStr = Carbon::parse($startDate)->translatedFormat('d M Y') . ' s/d ' . Carbon::parse($endDate)->translatedFormat('d M Y');
|
||||
|
||||
$totalKm = $activities->sum('distance');
|
||||
$inCount = $activities->where('direction', 'in')->count();
|
||||
$outCount = $activities->where('direction', 'out')->count();
|
||||
|
||||
$metaLeft = [
|
||||
'Periode Tanggal' => $dateRangeStr,
|
||||
'Pos Gerbang' => $gateText,
|
||||
'Arah / Status' => "Arah: {$dirText} | Status: {$statusText}",
|
||||
];
|
||||
|
||||
$metaRight = [
|
||||
'Total Catatan' => $activities->count() . ' Pergerakan Armada',
|
||||
'Total Jarak Tempuh' => number_format($totalKm, 1, ',', '.') . ' KM',
|
||||
'Rincian Arah' => "{$inCount} Masuk, {$outCount} Keluar",
|
||||
];
|
||||
|
||||
$columns = [
|
||||
['title' => 'NO', 'width' => 8, 'align' => 'C'],
|
||||
['title' => 'TANGGAL & JAM', 'width' => 25, 'align' => 'C'],
|
||||
['title' => 'KODE LV', 'width' => 16, 'align' => 'C', 'bold' => true],
|
||||
['title' => 'UNIT KENDARAAN', 'width' => 34, 'align' => 'L', 'max_char' => 22],
|
||||
['title' => 'DRIVER (PENGEMUDI)', 'width' => 30, 'align' => 'L', 'max_char' => 18],
|
||||
['title' => 'GERBANG', 'width' => 22, 'align' => 'C', 'max_char' => 14],
|
||||
['title' => 'AKSES', 'width' => 16, 'align' => 'C', 'is_status' => true],
|
||||
['title' => 'KM LALU', 'width' => 18, 'align' => 'R'],
|
||||
['title' => 'KM KINI', 'width' => 18, 'align' => 'R'],
|
||||
['title' => 'JARAK', 'width' => 16, 'align' => 'R'],
|
||||
['title' => 'AKTIVITAS / KEPERLUAN', 'width' => 42, 'align' => 'L', 'max_char' => 30],
|
||||
['title' => 'STATUS PG', 'width' => 22, 'align' => 'C', 'is_status' => true],
|
||||
];
|
||||
|
||||
$rows = [];
|
||||
foreach ($activities as $idx => $act) {
|
||||
$formattedDate = $act->recorded_at ? $act->recorded_at->translatedFormat('d/m/y H:i') : '-';
|
||||
$vehicleCode = $act->vehicle?->code ?: '-';
|
||||
$vehicleUnit = $act->vehicle?->brand_type ?: '-';
|
||||
$driverName = $act->driver?->name ?: '-';
|
||||
$gateName = $act->gate?->name ?: '-';
|
||||
$direction = strtoupper($act->direction ?: '-');
|
||||
$prevKm = $act->previous_km !== null ? number_format($act->previous_km, 0, ',', '.') : '-';
|
||||
$currKm = $act->current_km !== null ? number_format($act->current_km, 0, ',', '.') : '-';
|
||||
$diffKm = $act->distance !== null ? number_format($act->distance, 0, ',', '.') . ' KM' : '-';
|
||||
$purpose = $act->purpose ?: '-';
|
||||
$statusPg = $act->validation_status === 'approved' ? 'Disetujui' : ($act->validation_status === 'rejected' ? 'Ditolak' : 'Menunggu PG');
|
||||
|
||||
$rows[] = [
|
||||
$idx + 1,
|
||||
$formattedDate,
|
||||
$vehicleCode,
|
||||
$vehicleUnit,
|
||||
$driverName,
|
||||
$gateName,
|
||||
$direction,
|
||||
$prevKm,
|
||||
$currKm,
|
||||
$diffKm,
|
||||
$purpose,
|
||||
$statusPg,
|
||||
];
|
||||
}
|
||||
|
||||
$title = 'Laporan Timesheet & Aktivitas Light Vehicle (LV)';
|
||||
$subtitle = 'Log Pergerakan Armada Gerbang Proyek KMH - Periode: ' . $dateRangeStr;
|
||||
$pdfBinary = QmaTablePdfExporter::generate(
|
||||
$title,
|
||||
$subtitle,
|
||||
'LOG AKTIVITAS RKM-KMH',
|
||||
$metaLeft,
|
||||
$metaRight,
|
||||
$columns,
|
||||
$rows
|
||||
);
|
||||
|
||||
$fileName = 'Laporan_Timesheet_LV_' . now()->format('Ymd_Hi') . '.pdf';
|
||||
|
||||
return response($pdfBinary, 200, [
|
||||
'Content-Type' => 'application/pdf',
|
||||
'Content-Disposition' => 'inline; filename="' . $fileName . '"',
|
||||
'Content-Length' => strlen($pdfBinary),
|
||||
'Cache-Control' => 'private, max-age=0, must-revalidate',
|
||||
'Pragma' => 'public',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tampilkan Summary Aktivitas Kendaraan (Rekapitulasi Armada, Driver, Pos Gerbang & Statistik).
|
||||
*/
|
||||
@@ -173,4 +390,265 @@ class ActivityLogController extends Controller
|
||||
'gates'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Ekspor Rekapitulasi Summary Aktivitas Kendaraan ke format Excel (.xlsx).
|
||||
*/
|
||||
public function exportSummaryExcel(Request $request): Response
|
||||
{
|
||||
$today = Carbon::today()->toDateString();
|
||||
$startDate = $request->input('start_date', $today);
|
||||
$endDate = $request->input('end_date', $today);
|
||||
$type = $request->input('type');
|
||||
$gateId = $request->input('gate_id');
|
||||
|
||||
$query = VehicleActivity::query();
|
||||
|
||||
if ($startDate && $endDate) {
|
||||
$start = Carbon::parse($startDate)->startOfDay();
|
||||
$end = Carbon::parse($endDate)->endOfDay();
|
||||
$query->whereBetween('recorded_at', [$start, $end]);
|
||||
} elseif ($startDate) {
|
||||
$query->where('recorded_at', '>=', Carbon::parse($startDate)->startOfDay());
|
||||
} elseif ($endDate) {
|
||||
$query->where('recorded_at', '<=', Carbon::parse($endDate)->endOfDay());
|
||||
}
|
||||
|
||||
if ($request->filled('gate_id')) {
|
||||
$query->where('gate_id', $gateId);
|
||||
}
|
||||
|
||||
if ($request->filled('type')) {
|
||||
$type = $request->input('type');
|
||||
$query->whereHas('vehicle', function ($q) use ($type) {
|
||||
if ($type === 'lv' || $type === 'light_vehicle') {
|
||||
$q->where('category', 'light_vehicle');
|
||||
} elseif ($type === 'support' || $type === 'unit_support') {
|
||||
$q->where('category', 'unit_support');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$vehicleSummaries = (clone $query)
|
||||
->selectRaw("vehicle_id, COUNT(*) as total_trips, SUM(CASE WHEN direction = 'in' THEN 1 ELSE 0 END) as in_trips, SUM(CASE WHEN direction = 'out' THEN 1 ELSE 0 END) as out_trips, SUM(distance) as total_km")
|
||||
->groupBy('vehicle_id')
|
||||
->with('vehicle')
|
||||
->orderByDesc('total_km')
|
||||
->get();
|
||||
|
||||
if ($request->filled('search')) {
|
||||
$search = trim($request->input('search'));
|
||||
$vehicleSummaries = $vehicleSummaries->filter(function ($item) use ($search) {
|
||||
$veh = $item->vehicle;
|
||||
if (!$veh) return false;
|
||||
$haystack = strtolower(($veh->code ?? '') . ' ' . ($veh->brand_type ?? '') . ' ' . ($veh->license_plate ?? '') . ' ' . ($veh->ownership ?? '') . ' ' . ($veh->division ?? ''));
|
||||
return str_contains($haystack, strtolower($search));
|
||||
})->values();
|
||||
}
|
||||
|
||||
$gateText = 'Semua Gerbang';
|
||||
if ($request->filled('gate_id')) {
|
||||
$g = Gate::find($gateId);
|
||||
if ($g) $gateText = $g->name;
|
||||
}
|
||||
|
||||
$typeText = 'Semua Armada';
|
||||
if ($type === 'lv' || $type === 'light_vehicle') $typeText = 'Light Vehicle';
|
||||
elseif ($type === 'support' || $type === 'unit_support') $typeText = 'Unit Support';
|
||||
|
||||
$totalKmAll = $vehicleSummaries->sum('total_km');
|
||||
$totalTripsAll = $vehicleSummaries->sum('total_trips');
|
||||
$dateRangeStr = Carbon::parse($startDate)->translatedFormat('d M Y') . ' s/d ' . Carbon::parse($endDate)->translatedFormat('d M Y');
|
||||
$printedAt = now()->translatedFormat('d F Y, H:i');
|
||||
|
||||
$metaLines = [
|
||||
'Periode: ' . $dateRangeStr . ' | Kategori Armada: ' . $typeText . ' | Gerbang: ' . $gateText .
|
||||
($request->filled('search') ? ' | Pencarian: "' . $request->input('search') . '"' : ''),
|
||||
'Total: ' . $vehicleSummaries->count() . ' Unit Aktif | Akumulasi Trip: ' . number_format($totalTripsAll, 0, ',', '.') . ' Trip | Total Jarak: ' . number_format($totalKmAll, 1, ',', '.') . ' KM | Dicetak: ' . $printedAt . ' WIB',
|
||||
];
|
||||
|
||||
$headers = [
|
||||
'No' => 6,
|
||||
'Kode Unit' => 16,
|
||||
'Unit / Merek' => 30,
|
||||
'No. Polisi' => 16,
|
||||
'Kategori' => 18,
|
||||
'Penanggung Jawab' => 24,
|
||||
'Divisi' => 20,
|
||||
'Trip Masuk' => 14,
|
||||
'Trip Keluar' => 14,
|
||||
'Total Trip' => 14,
|
||||
'Total Jarak (KM)' => 18,
|
||||
'Odometer Terkini' => 18,
|
||||
];
|
||||
|
||||
$rows = [];
|
||||
foreach ($vehicleSummaries as $idx => $vs) {
|
||||
$veh = $vs->vehicle;
|
||||
$rows[] = [
|
||||
$idx + 1,
|
||||
$veh?->code ?: '-',
|
||||
$veh?->brand_type ?: '-',
|
||||
$veh?->license_plate ?: '-',
|
||||
$veh?->isLightVehicle() ? 'Light Vehicle' : 'Unit Support',
|
||||
$veh?->ownership ?: '-',
|
||||
$veh?->division ?: ($veh?->department ?: '-'),
|
||||
(int) $vs->in_trips,
|
||||
(int) $vs->out_trips,
|
||||
(int) $vs->total_trips,
|
||||
number_format($vs->total_km, 1, ',', '.'),
|
||||
$veh?->current_km !== null ? number_format($veh->current_km, 0, ',', '.') . ' KM' : '-',
|
||||
];
|
||||
}
|
||||
|
||||
$alignments = ['center', 'center', 'left', 'center', 'center', 'left', 'left', 'center', 'center', 'center', 'right', 'right'];
|
||||
$title = 'LAPORAN REKAPITULASI SUMMARY AKTIVITAS PER KENDARAAN - PT KERINCI MERANGIN HIDRO';
|
||||
$fileName = 'Laporan_Summary_Aktivitas_Kendaraan_' . now()->format('Ymd_Hi') . '.xlsx';
|
||||
|
||||
$binary = SimpleXlsxExporter::create($title, $metaLines, $headers, $rows, $alignments);
|
||||
|
||||
return response($binary, 200, [
|
||||
'Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
'Content-Disposition' => 'attachment; filename="' . $fileName . '"',
|
||||
'Content-Length' => strlen($binary),
|
||||
'Cache-Control' => 'max-age=0, no-cache, no-store, must-revalidate',
|
||||
'Pragma' => 'public',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ekspor Rekapitulasi Summary Aktivitas Kendaraan ke format PDF (Pratinjau Asli dengan Logo PT KMH).
|
||||
*/
|
||||
public function exportSummaryPdf(Request $request): Response
|
||||
{
|
||||
$today = Carbon::today()->toDateString();
|
||||
$startDate = $request->input('start_date', $today);
|
||||
$endDate = $request->input('end_date', $today);
|
||||
$type = $request->input('type');
|
||||
$gateId = $request->input('gate_id');
|
||||
|
||||
$query = VehicleActivity::query();
|
||||
|
||||
if ($startDate && $endDate) {
|
||||
$start = Carbon::parse($startDate)->startOfDay();
|
||||
$end = Carbon::parse($endDate)->endOfDay();
|
||||
$query->whereBetween('recorded_at', [$start, $end]);
|
||||
} elseif ($startDate) {
|
||||
$query->where('recorded_at', '>=', Carbon::parse($startDate)->startOfDay());
|
||||
} elseif ($endDate) {
|
||||
$query->where('recorded_at', '<=', Carbon::parse($endDate)->endOfDay());
|
||||
}
|
||||
|
||||
if ($request->filled('gate_id')) {
|
||||
$query->where('gate_id', $gateId);
|
||||
}
|
||||
|
||||
if ($request->filled('type')) {
|
||||
$type = $request->input('type');
|
||||
$query->whereHas('vehicle', function ($q) use ($type) {
|
||||
if ($type === 'lv' || $type === 'light_vehicle') {
|
||||
$q->where('category', 'light_vehicle');
|
||||
} elseif ($type === 'support' || $type === 'unit_support') {
|
||||
$q->where('category', 'unit_support');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$vehicleSummaries = (clone $query)
|
||||
->selectRaw("vehicle_id, COUNT(*) as total_trips, SUM(CASE WHEN direction = 'in' THEN 1 ELSE 0 END) as in_trips, SUM(CASE WHEN direction = 'out' THEN 1 ELSE 0 END) as out_trips, SUM(distance) as total_km")
|
||||
->groupBy('vehicle_id')
|
||||
->with('vehicle')
|
||||
->orderByDesc('total_km')
|
||||
->get();
|
||||
|
||||
if ($request->filled('search')) {
|
||||
$search = trim($request->input('search'));
|
||||
$vehicleSummaries = $vehicleSummaries->filter(function ($item) use ($search) {
|
||||
$veh = $item->vehicle;
|
||||
if (!$veh) return false;
|
||||
$haystack = strtolower(($veh->code ?? '') . ' ' . ($veh->brand_type ?? '') . ' ' . ($veh->license_plate ?? '') . ' ' . ($veh->ownership ?? '') . ' ' . ($veh->division ?? ''));
|
||||
return str_contains($haystack, strtolower($search));
|
||||
})->values();
|
||||
}
|
||||
|
||||
$gateText = 'Semua Gerbang';
|
||||
if ($request->filled('gate_id')) {
|
||||
$g = Gate::find($gateId);
|
||||
if ($g) $gateText = $g->name;
|
||||
}
|
||||
|
||||
$typeText = 'Semua Armada';
|
||||
if ($type === 'lv' || $type === 'light_vehicle') $typeText = 'Light Vehicle';
|
||||
elseif ($type === 'support' || $type === 'unit_support') $typeText = 'Unit Support';
|
||||
|
||||
$totalKmAll = $vehicleSummaries->sum('total_km');
|
||||
$totalTripsAll = $vehicleSummaries->sum('total_trips');
|
||||
$dateRangeStr = Carbon::parse($startDate)->translatedFormat('d M Y') . ' s/d ' . Carbon::parse($endDate)->translatedFormat('d M Y');
|
||||
|
||||
$metaLeft = [
|
||||
'Periode Tanggal' => $dateRangeStr,
|
||||
'Kategori Armada' => $typeText,
|
||||
'Pos Gerbang' => $gateText,
|
||||
];
|
||||
|
||||
$metaRight = [
|
||||
'Armada Beroperasi' => $vehicleSummaries->count() . ' Unit Aktif',
|
||||
'Akumulasi Trip' => number_format($totalTripsAll, 0, ',', '.') . ' Pergerakan',
|
||||
'Total Jarak Tempuh' => number_format($totalKmAll, 1, ',', '.') . ' KM',
|
||||
];
|
||||
|
||||
$columns = [
|
||||
['title' => 'NO', 'width' => 10, 'align' => 'C'],
|
||||
['title' => 'KODE UNIT', 'width' => 22, 'align' => 'C', 'bold' => true],
|
||||
['title' => 'UNIT / MEREK', 'width' => 48, 'align' => 'L', 'max_char' => 30],
|
||||
['title' => 'NO. POLISI', 'width' => 22, 'align' => 'C'],
|
||||
['title' => 'KATEGORI', 'width' => 26, 'align' => 'C'],
|
||||
['title' => 'PENANGGUNG JAWAB', 'width' => 40, 'align' => 'L', 'max_char' => 26],
|
||||
['title' => 'MASUK', 'width' => 18, 'align' => 'C'],
|
||||
['title' => 'KELUAR', 'width' => 18, 'align' => 'C'],
|
||||
['title' => 'TOTAL TRIP', 'width' => 20, 'align' => 'C', 'bold' => true],
|
||||
['title' => 'TOTAL JARAK', 'width' => 25, 'align' => 'R', 'bold' => true],
|
||||
['title' => 'ODOMETER', 'width' => 18, 'align' => 'R'],
|
||||
];
|
||||
|
||||
$rows = [];
|
||||
foreach ($vehicleSummaries as $idx => $vs) {
|
||||
$veh = $vs->vehicle;
|
||||
$rows[] = [
|
||||
$idx + 1,
|
||||
$veh?->code ?: '-',
|
||||
$veh?->brand_type ?: '-',
|
||||
$veh?->license_plate ?: '-',
|
||||
$veh?->isLightVehicle() ? 'Light Vehicle' : 'Unit Support',
|
||||
$veh?->ownership ?: '-',
|
||||
(int) $vs->in_trips,
|
||||
(int) $vs->out_trips,
|
||||
(int) $vs->total_trips,
|
||||
number_format($vs->total_km, 1, ',', '.') . ' KM',
|
||||
$veh?->current_km !== null ? number_format($veh->current_km, 0, ',', '.') : '-',
|
||||
];
|
||||
}
|
||||
|
||||
$title = 'Laporan Summary Aktivitas per Armada Kendaraan';
|
||||
$subtitle = 'Rekapitulasi Pergerakan, Frekuensi Trip, dan Jarak Tempuh - Periode: ' . $dateRangeStr;
|
||||
$pdfBinary = QmaTablePdfExporter::generate(
|
||||
$title,
|
||||
$subtitle,
|
||||
'SUMMARY AKTIVITAS RKM-KMH',
|
||||
$metaLeft,
|
||||
$metaRight,
|
||||
$columns,
|
||||
$rows
|
||||
);
|
||||
|
||||
$fileName = 'Laporan_Summary_Aktivitas_Kendaraan_' . now()->format('Ymd_Hi') . '.pdf';
|
||||
|
||||
return response($pdfBinary, 200, [
|
||||
'Content-Type' => 'application/pdf',
|
||||
'Content-Disposition' => 'inline; filename="' . $fileName . '"',
|
||||
'Content-Length' => strlen($pdfBinary),
|
||||
'Cache-Control' => 'private, max-age=0, must-revalidate',
|
||||
'Pragma' => 'public',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,18 +5,22 @@ namespace App\Http\Controllers\Qma;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\P2hRecord;
|
||||
use App\Models\Vehicle;
|
||||
use App\Services\QmaTablePdfExporter;
|
||||
use App\Services\SimpleXlsxExporter;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class P2hInspectionController extends Controller
|
||||
{
|
||||
/**
|
||||
* Tampilkan riwayat dan log pemeriksaan P2H Unit Support untuk Admin QMA.
|
||||
* Helper query builder untuk riwayat pemeriksaan P2H Unit Support dengan filter aktif.
|
||||
*/
|
||||
public function index(Request $request): View
|
||||
private function getFilteredP2hQuery(Request $request): Builder
|
||||
{
|
||||
$query = P2hRecord::with(['vehicle', 'employee', 'template', 'validator']);
|
||||
|
||||
@@ -45,7 +49,15 @@ class P2hInspectionController extends Controller
|
||||
});
|
||||
}
|
||||
|
||||
$records = $query->orderByDesc('inspected_at')->paginate(15)->withQueryString();
|
||||
return $query->orderByDesc('inspected_at');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tampilkan riwayat dan log pemeriksaan P2H Unit Support untuk Admin QMA.
|
||||
*/
|
||||
public function index(Request $request): View
|
||||
{
|
||||
$records = $this->getFilteredP2hQuery($request)->paginate(15)->withQueryString();
|
||||
|
||||
// Statistik Ringkasan P2H
|
||||
$totalP2h = P2hRecord::count();
|
||||
@@ -64,6 +76,191 @@ class P2hInspectionController extends Controller
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Ekspor Riwayat Pemeriksaan P2H Unit Support ke format Excel (.xlsx).
|
||||
*/
|
||||
public function exportExcel(Request $request): Response
|
||||
{
|
||||
$records = $this->getFilteredP2hQuery($request)->get();
|
||||
|
||||
$dateFilter = $request->filled('date') ? Carbon::parse($request->input('date'))->translatedFormat('d F Y') : 'Semua Tanggal';
|
||||
$statusFilter = $request->filled('validation_status') ?
|
||||
($request->input('validation_status') === 'approved' ? 'Disetujui QMA' :
|
||||
($request->input('validation_status') === 'rejected' ? 'Ditolak' : 'Menunggu Review')) : 'Semua Status';
|
||||
$condFilter = $request->filled('summary_condition') ?
|
||||
($request->input('summary_condition') === 'has_defect' ? 'Ada Kerusakan' : 'Normal') : 'Semua Kondisi';
|
||||
$printedAt = now()->translatedFormat('d F Y, H:i');
|
||||
|
||||
$metaLines = [
|
||||
'Filter: Tanggal: ' . $dateFilter . ' | Status QMA: ' . $statusFilter . ' | Kondisi Fisik: ' . $condFilter .
|
||||
($request->filled('search') ? ' | Pencarian: "' . $request->input('search') . '"' : ''),
|
||||
'Total Data: ' . $records->count() . ' Form Pemeriksaan P2H | Tanggal Dicetak: ' . $printedAt . ' WIB',
|
||||
];
|
||||
|
||||
$headers = [
|
||||
'No' => 6,
|
||||
'Waktu Inspeksi' => 20,
|
||||
'No. Transaksi' => 22,
|
||||
'Kode Unit' => 16,
|
||||
'Kategori & Model Alat' => 30,
|
||||
'Operator (SIMPER)' => 28,
|
||||
'NIK' => 16,
|
||||
'Shift' => 14,
|
||||
'HM Awal Operasi' => 18,
|
||||
'Kondisi Fisik' => 20,
|
||||
'Jumlah Temuan' => 16,
|
||||
'Status QMA' => 20,
|
||||
'Catatan Inspeksi / Temuan' => 36,
|
||||
'Validator QMA' => 24,
|
||||
];
|
||||
|
||||
$rows = [];
|
||||
foreach ($records as $idx => $rec) {
|
||||
$waktu = $rec->inspected_at ? $rec->inspected_at->translatedFormat('d/m/Y H:i') . ' WIB' : '-';
|
||||
$unitCode = $rec->vehicle?->code ?: '-';
|
||||
$unitModel = $rec->vehicle?->brand_type ?: ($rec->vehicle?->unit_category ?: '-');
|
||||
$opName = $rec->employee?->name ?: '-';
|
||||
$opNik = $rec->employee?->nik ?: '-';
|
||||
$shift = $rec->shift ?: '-';
|
||||
$hm = $rec->start_hm !== null ? number_format($rec->start_hm, 1, ',', '.') . ' HM' : '-';
|
||||
$kondisi = $rec->hasDefects() ? 'Ada Kerusakan (' . $rec->defect_count . ' Item)' : 'Normal (Baik)';
|
||||
$defectCount = $rec->defect_count ?: '0';
|
||||
$statusQma = $rec->isApproved() ? 'Disetujui QMA' : ($rec->isRejected() ? 'Ditolak' : 'Menunggu Review');
|
||||
$notes = $rec->general_notes ?: ($rec->validation_notes ?: '-');
|
||||
$validator = $rec->validator?->name ?: '-';
|
||||
|
||||
$rows[] = [
|
||||
$idx + 1,
|
||||
$waktu,
|
||||
$rec->transaction_no ?: '-',
|
||||
$unitCode,
|
||||
$unitModel,
|
||||
$opName,
|
||||
$opNik,
|
||||
$shift,
|
||||
$hm,
|
||||
$kondisi,
|
||||
$defectCount,
|
||||
$statusQma,
|
||||
$notes,
|
||||
$validator,
|
||||
];
|
||||
}
|
||||
|
||||
$alignments = ['center', 'center', 'center', 'center', 'left', 'left', 'center', 'center', 'right', 'center', 'center', 'center', 'left', 'left'];
|
||||
$title = 'LAPORAN PEMERIKSAAN HARIAN (P2H) ALAT BERAT & UNIT SUPPORT - PT KERINCI MERANGIN HIDRO';
|
||||
$fileName = 'Laporan_P2H_Unit_Support_' . now()->format('Ymd_Hi') . '.xlsx';
|
||||
|
||||
$binary = SimpleXlsxExporter::create($title, $metaLines, $headers, $rows, $alignments);
|
||||
|
||||
return response($binary, 200, [
|
||||
'Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
'Content-Disposition' => 'attachment; filename="' . $fileName . '"',
|
||||
'Content-Length' => strlen($binary),
|
||||
'Cache-Control' => 'max-age=0, no-cache, no-store, must-revalidate',
|
||||
'Pragma' => 'public',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ekspor Riwayat Pemeriksaan P2H Unit Support ke format PDF (Pratinjau Asli dengan Logo PT KMH).
|
||||
*/
|
||||
public function exportPdf(Request $request): Response
|
||||
{
|
||||
$records = $this->getFilteredP2hQuery($request)->get();
|
||||
|
||||
$dateFilter = $request->filled('date') ? Carbon::parse($request->input('date'))->translatedFormat('d F Y') : 'Semua Tanggal';
|
||||
$statusFilter = $request->filled('validation_status') ?
|
||||
($request->input('validation_status') === 'approved' ? 'Disetujui QMA' :
|
||||
($request->input('validation_status') === 'rejected' ? 'Ditolak' : 'Menunggu Review')) : 'Semua Status';
|
||||
$condFilter = $request->filled('summary_condition') ?
|
||||
($request->input('summary_condition') === 'has_defect' ? 'Ada Kerusakan' : 'Normal') : 'Semua Kondisi';
|
||||
|
||||
$approvedCount = $records->where('validation_status', 'approved')->count();
|
||||
$pendingCount = $records->where('validation_status', 'pending')->count();
|
||||
$rejectedCount = $records->where('validation_status', 'rejected')->count();
|
||||
$defectCount = $records->where('summary_condition', 'has_defect')->count();
|
||||
$normalCount = $records->where('summary_condition', '!=', 'has_defect')->count();
|
||||
|
||||
$metaLeft = [
|
||||
'Filter Tanggal' => $dateFilter,
|
||||
'Status Approval' => $statusFilter,
|
||||
'Kondisi Fisik' => $condFilter,
|
||||
];
|
||||
|
||||
$metaRight = [
|
||||
'Total Pemeriksaan' => $records->count() . ' Form P2H Terverifikasi',
|
||||
'Rincian Kondisi' => "{$normalCount} Normal, {$defectCount} Ada Kerusakan",
|
||||
'Rincian Status' => "{$approvedCount} Disetujui, {$pendingCount} Menunggu, {$rejectedCount} Ditolak",
|
||||
];
|
||||
|
||||
$columns = [
|
||||
['title' => 'NO', 'width' => 8, 'align' => 'C'],
|
||||
['title' => 'WAKTU', 'width' => 24, 'align' => 'C'],
|
||||
['title' => 'NO. TRANSAKSI', 'width' => 26, 'align' => 'C', 'bold' => true],
|
||||
['title' => 'KODE', 'width' => 16, 'align' => 'C', 'bold' => true],
|
||||
['title' => 'MODEL ALAT', 'width' => 34, 'align' => 'L', 'max_char' => 22],
|
||||
['title' => 'OPERATOR', 'width' => 32, 'align' => 'L', 'max_char' => 20],
|
||||
['title' => 'SHIFT', 'width' => 14, 'align' => 'C'],
|
||||
['title' => 'HM', 'width' => 18, 'align' => 'R'],
|
||||
['title' => 'KONDISI', 'width' => 28, 'align' => 'C', 'is_status' => true],
|
||||
['title' => 'STATUS QMA', 'width' => 25, 'align' => 'C', 'is_status' => true],
|
||||
['title' => 'VALIDATOR', 'width' => 22, 'align' => 'L', 'max_char' => 15],
|
||||
['title' => 'CATATAN', 'width' => 20, 'align' => 'L', 'max_char' => 14],
|
||||
];
|
||||
|
||||
$rows = [];
|
||||
foreach ($records as $idx => $rec) {
|
||||
$waktu = $rec->inspected_at ? $rec->inspected_at->translatedFormat('d/m/y H:i') : '-';
|
||||
$unitCode = $rec->vehicle?->code ?: '-';
|
||||
$unitModel = $rec->vehicle?->brand_type ?: '-';
|
||||
$opName = $rec->employee?->name ?: '-';
|
||||
$shift = $rec->shift ?: '-';
|
||||
$hm = $rec->start_hm !== null ? number_format($rec->start_hm, 1, ',', '.') : '-';
|
||||
$kondisi = $rec->hasDefects() ? 'Ada Kerusakan (' . $rec->defect_count . ')' : 'Normal (Baik)';
|
||||
$statusQma = $rec->isApproved() ? 'Disetujui QMA' : ($rec->isRejected() ? 'Ditolak' : 'Menunggu Review');
|
||||
$validator = $rec->validator?->name ?: '-';
|
||||
$notes = $rec->general_notes ?: ($rec->validation_notes ?: '-');
|
||||
|
||||
$rows[] = [
|
||||
$idx + 1,
|
||||
$waktu,
|
||||
$rec->transaction_no ?: '-',
|
||||
$unitCode,
|
||||
$unitModel,
|
||||
$opName,
|
||||
$shift,
|
||||
$hm,
|
||||
$kondisi,
|
||||
$statusQma,
|
||||
$validator,
|
||||
$notes,
|
||||
];
|
||||
}
|
||||
|
||||
$title = 'Laporan Pemeriksaan Harian (P2H) Unit Support';
|
||||
$subtitle = 'Rekapitulasi Kelaikan Alat Berat & Unit Pendukung Lapangan - PT KMH';
|
||||
$pdfBinary = QmaTablePdfExporter::generate(
|
||||
$title,
|
||||
$subtitle,
|
||||
'P2H UNIT SUPPORT RKM-KMH',
|
||||
$metaLeft,
|
||||
$metaRight,
|
||||
$columns,
|
||||
$rows
|
||||
);
|
||||
|
||||
$fileName = 'Laporan_P2H_Unit_Support_' . now()->format('Ymd_Hi') . '.pdf';
|
||||
|
||||
return response($pdfBinary, 200, [
|
||||
'Content-Type' => 'application/pdf',
|
||||
'Content-Disposition' => 'inline; filename="' . $fileName . '"',
|
||||
'Content-Length' => strlen($pdfBinary),
|
||||
'Cache-Control' => 'private, max-age=0, must-revalidate',
|
||||
'Pragma' => 'public',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tampilkan Summary Pemeriksaan P2H Unit Support (Analitik, Rekapitulasi Alat Berat & Status).
|
||||
*/
|
||||
@@ -155,6 +352,249 @@ class P2hInspectionController extends Controller
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper untuk memproses data rekapitulasi summary P2H per unit support.
|
||||
*/
|
||||
private function getP2hSummaryData(Request $request): array
|
||||
{
|
||||
$today = Carbon::today()->toDateString();
|
||||
$startDate = $request->input('start_date', Carbon::now()->startOfMonth()->toDateString());
|
||||
$endDate = $request->input('end_date', $today);
|
||||
$vehicleId = $request->input('vehicle_id');
|
||||
$validationStatus = $request->input('validation_status');
|
||||
$shift = $request->input('shift');
|
||||
$search = trim($request->input('search', ''));
|
||||
|
||||
$query = P2hRecord::with(['vehicle', 'employee', 'template']);
|
||||
|
||||
if ($startDate && $endDate) {
|
||||
$start = Carbon::parse($startDate)->startOfDay();
|
||||
$end = Carbon::parse($endDate)->endOfDay();
|
||||
$query->whereBetween('inspected_at', [$start, $end]);
|
||||
} elseif ($startDate) {
|
||||
$query->where('inspected_at', '>=', Carbon::parse($startDate)->startOfDay());
|
||||
} elseif ($endDate) {
|
||||
$query->where('inspected_at', '<=', Carbon::parse($endDate)->endOfDay());
|
||||
}
|
||||
|
||||
if ($request->filled('vehicle_id')) {
|
||||
$query->where('vehicle_id', $vehicleId);
|
||||
}
|
||||
|
||||
if ($request->filled('validation_status')) {
|
||||
$query->where('validation_status', $validationStatus);
|
||||
}
|
||||
|
||||
if ($request->filled('shift')) {
|
||||
$query->where('shift', $shift);
|
||||
}
|
||||
|
||||
if ($search !== '') {
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('transaction_no', 'like', "%{$search}%")
|
||||
->orWhereHas('vehicle', fn($v) => $v->where('code', 'like', "%{$search}%")->orWhere('brand_type', 'like', "%{$search}%"))
|
||||
->orWhereHas('employee', fn($e) => $e->where('name', 'like', "%{$search}%")->orWhere('nik', 'like', "%{$search}%"));
|
||||
});
|
||||
}
|
||||
|
||||
$records = $query->orderByDesc('inspected_at')->get();
|
||||
|
||||
$unitSummary = $records->groupBy('vehicle_id')->map(function ($group) {
|
||||
$vehicle = $group->first()->vehicle;
|
||||
return [
|
||||
'vehicle' => $vehicle,
|
||||
'total' => $group->count(),
|
||||
'approved' => $group->where('validation_status', 'approved')->count(),
|
||||
'pending' => $group->where('validation_status', 'pending')->count(),
|
||||
'rejected' => $group->where('validation_status', 'rejected')->count(),
|
||||
'has_defect' => $group->where('summary_condition', 'has_defect')->count(),
|
||||
'good' => $group->where('summary_condition', 'good')->count(),
|
||||
'latest_hm' => $group->max('start_hm'),
|
||||
'latest_inspection' => $group->max('inspected_at'),
|
||||
];
|
||||
})->sortByDesc('total');
|
||||
|
||||
return [
|
||||
'records' => $records,
|
||||
'unitSummary' => $unitSummary,
|
||||
'startDate' => $startDate,
|
||||
'endDate' => $endDate,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Ekspor Rekapitulasi Summary P2H Unit Support ke format Excel (.xlsx).
|
||||
*/
|
||||
public function exportSummaryExcel(Request $request): Response
|
||||
{
|
||||
$data = $this->getP2hSummaryData($request);
|
||||
$records = $data['records'];
|
||||
$unitSummary = $data['unitSummary'];
|
||||
$startDate = $data['startDate'];
|
||||
$endDate = $data['endDate'];
|
||||
|
||||
$dateRangeStr = Carbon::parse($startDate)->translatedFormat('d M Y') . ' s/d ' . Carbon::parse($endDate)->translatedFormat('d M Y');
|
||||
$printedAt = now()->translatedFormat('d F Y, H:i');
|
||||
|
||||
$statusFilter = $request->filled('validation_status') ?
|
||||
($request->input('validation_status') === 'approved' ? 'Disetujui QMA' :
|
||||
($request->input('validation_status') === 'rejected' ? 'Ditolak' : 'Menunggu Approval')) : 'Semua Status';
|
||||
$shiftFilter = $request->filled('shift') ? $request->input('shift') : 'Semua Shift';
|
||||
|
||||
$totalP2hAll = $records->count();
|
||||
$totalApprovedAll = $records->where('validation_status', 'approved')->count();
|
||||
$totalDefectsAll = $records->where('summary_condition', 'has_defect')->count();
|
||||
|
||||
$metaLines = [
|
||||
'Periode: ' . $dateRangeStr . ' | Status: ' . $statusFilter . ' | Shift: ' . $shiftFilter .
|
||||
($request->filled('search') ? ' | Pencarian: "' . $request->input('search') . '"' : ''),
|
||||
'Total: ' . $unitSummary->count() . ' Unit Alat Berat | Total Form: ' . $totalP2hAll . ' P2H (' . $totalApprovedAll . ' Disetujui, ' . $totalDefectsAll . ' Ada Kerusakan) | Dicetak: ' . $printedAt . ' WIB',
|
||||
];
|
||||
|
||||
$headers = [
|
||||
'No' => 6,
|
||||
'Kode Unit' => 16,
|
||||
'Model & Kategori Alat' => 32,
|
||||
'Kategori' => 20,
|
||||
'Total P2H' => 14,
|
||||
'Disetujui' => 14,
|
||||
'Menunggu' => 14,
|
||||
'Ditolak' => 14,
|
||||
'Temuan Rusak' => 16,
|
||||
'HM Terakhir' => 18,
|
||||
'Terakhir Diperiksa' => 22,
|
||||
];
|
||||
|
||||
$rows = [];
|
||||
$idx = 1;
|
||||
foreach ($unitSummary as $us) {
|
||||
$veh = $us['vehicle'];
|
||||
$latestInspection = $us['latest_inspection'] ? Carbon::parse($us['latest_inspection'])->translatedFormat('d/m/Y H:i') . ' WIB' : '-';
|
||||
$hm = $us['latest_hm'] !== null ? number_format($us['latest_hm'], 1, ',', '.') . ' HM' : '-';
|
||||
|
||||
$rows[] = [
|
||||
$idx++,
|
||||
$veh?->code ?: '-',
|
||||
$veh?->brand_type ?: '-',
|
||||
$veh?->unit_category ?: 'Alat Berat',
|
||||
(int) $us['total'],
|
||||
(int) $us['approved'],
|
||||
(int) $us['pending'],
|
||||
(int) $us['rejected'],
|
||||
(int) $us['has_defect'],
|
||||
$hm,
|
||||
$latestInspection,
|
||||
];
|
||||
}
|
||||
|
||||
$alignments = ['center', 'center', 'left', 'left', 'center', 'center', 'center', 'center', 'center', 'right', 'center'];
|
||||
$title = 'LAPORAN REKAPITULASI SUMMARY P2H UNIT SUPPORT - PT KERINCI MERANGIN HIDRO';
|
||||
$fileName = 'Laporan_Summary_P2H_Unit_Support_' . now()->format('Ymd_Hi') . '.xlsx';
|
||||
|
||||
$binary = SimpleXlsxExporter::create($title, $metaLines, $headers, $rows, $alignments);
|
||||
|
||||
return response($binary, 200, [
|
||||
'Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
'Content-Disposition' => 'attachment; filename="' . $fileName . '"',
|
||||
'Content-Length' => strlen($binary),
|
||||
'Cache-Control' => 'max-age=0, no-cache, no-store, must-revalidate',
|
||||
'Pragma' => 'public',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ekspor Rekapitulasi Summary P2H Unit Support ke format PDF (Pratinjau Asli dengan Logo PT KMH).
|
||||
*/
|
||||
public function exportSummaryPdf(Request $request): Response
|
||||
{
|
||||
$data = $this->getP2hSummaryData($request);
|
||||
$records = $data['records'];
|
||||
$unitSummary = $data['unitSummary'];
|
||||
$startDate = $data['startDate'];
|
||||
$endDate = $data['endDate'];
|
||||
|
||||
$dateRangeStr = Carbon::parse($startDate)->translatedFormat('d M Y') . ' s/d ' . Carbon::parse($endDate)->translatedFormat('d M Y');
|
||||
|
||||
$statusFilter = $request->filled('validation_status') ?
|
||||
($request->input('validation_status') === 'approved' ? 'Disetujui QMA' :
|
||||
($request->input('validation_status') === 'rejected' ? 'Ditolak' : 'Menunggu Approval')) : 'Semua Status';
|
||||
$shiftFilter = $request->filled('shift') ? $request->input('shift') : 'Semua Shift';
|
||||
|
||||
$totalApproved = $records->where('validation_status', 'approved')->count();
|
||||
$totalPending = $records->where('validation_status', 'pending')->count();
|
||||
$totalRejected = $records->where('validation_status', 'rejected')->count();
|
||||
$totalDefects = $records->where('summary_condition', 'has_defect')->count();
|
||||
|
||||
$metaLeft = [
|
||||
'Periode Tanggal' => $dateRangeStr,
|
||||
'Status Approval' => $statusFilter,
|
||||
'Filter Shift' => $shiftFilter,
|
||||
];
|
||||
|
||||
$metaRight = [
|
||||
'Unit Support Aktif' => $unitSummary->count() . ' Unit Alat Berat',
|
||||
'Total Pemeriksaan' => $records->count() . ' Form P2H Terkumpul',
|
||||
'Rincian Status' => "{$totalApproved} Disetujui, {$totalPending} Menunggu, {$totalRejected} Ditolak",
|
||||
];
|
||||
|
||||
$columns = [
|
||||
['title' => 'NO', 'width' => 10, 'align' => 'C'],
|
||||
['title' => 'KODE UNIT', 'width' => 24, 'align' => 'C', 'bold' => true],
|
||||
['title' => 'MODEL & KATEGORI ALAT', 'width' => 65, 'align' => 'L', 'max_char' => 42],
|
||||
['title' => 'TOTAL P2H', 'width' => 22, 'align' => 'C', 'bold' => true],
|
||||
['title' => 'DISETUJUI', 'width' => 22, 'align' => 'C', 'is_status' => true],
|
||||
['title' => 'MENUNGGU', 'width' => 22, 'align' => 'C', 'is_status' => true],
|
||||
['title' => 'DITOLAK', 'width' => 20, 'align' => 'C', 'is_status' => true],
|
||||
['title' => 'TEMUAN', 'width' => 24, 'align' => 'C', 'is_status' => true],
|
||||
['title' => 'HM TERAKHIR', 'width' => 26, 'align' => 'R'],
|
||||
['title' => 'TERAKHIR DIPERIKSA', 'width' => 32, 'align' => 'C'],
|
||||
];
|
||||
|
||||
$rows = [];
|
||||
$idx = 1;
|
||||
foreach ($unitSummary as $us) {
|
||||
$veh = $us['vehicle'];
|
||||
$latestInspection = $us['latest_inspection'] ? Carbon::parse($us['latest_inspection'])->translatedFormat('d/m/y H:i') : '-';
|
||||
$hm = $us['latest_hm'] !== null ? number_format($us['latest_hm'], 1, ',', '.') : '-';
|
||||
$modelCat = ($veh?->brand_type ?: '-') . ($veh?->unit_category ? ' (' . $veh->unit_category . ')' : '');
|
||||
|
||||
$rows[] = [
|
||||
$idx++,
|
||||
$veh?->code ?: '-',
|
||||
$modelCat,
|
||||
(int) $us['total'],
|
||||
(int) $us['approved'],
|
||||
(int) $us['pending'],
|
||||
(int) $us['rejected'],
|
||||
(int) $us['has_defect'],
|
||||
$hm,
|
||||
$latestInspection,
|
||||
];
|
||||
}
|
||||
|
||||
$title = 'Laporan Summary Rekapitulasi P2H Unit Support';
|
||||
$subtitle = 'Kepatuhan & Kelayakan Operasional Alat Berat Lapangan - Periode: ' . $dateRangeStr;
|
||||
$pdfBinary = QmaTablePdfExporter::generate(
|
||||
$title,
|
||||
$subtitle,
|
||||
'SUMMARY P2H RKM-KMH',
|
||||
$metaLeft,
|
||||
$metaRight,
|
||||
$columns,
|
||||
$rows
|
||||
);
|
||||
|
||||
$fileName = 'Laporan_Summary_P2H_Unit_Support_' . now()->format('Ymd_Hi') . '.pdf';
|
||||
|
||||
return response($pdfBinary, 200, [
|
||||
'Content-Type' => 'application/pdf',
|
||||
'Content-Disposition' => 'inline; filename="' . $fileName . '"',
|
||||
'Content-Length' => strlen($pdfBinary),
|
||||
'Cache-Control' => 'private, max-age=0, must-revalidate',
|
||||
'Pragma' => 'public',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tampilkan detail lembar pemeriksaan P2H (seluruh section & butir jawaban).
|
||||
*/
|
||||
|
||||
@@ -9,9 +9,13 @@ use App\Models\P2hRecord;
|
||||
use App\Models\P2hTemplate;
|
||||
use App\Models\Vehicle;
|
||||
use App\Models\VehicleActivity;
|
||||
use App\Services\SimpleXlsxExporter;
|
||||
use App\Services\VehiclePdfExporter;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\View\View;
|
||||
@@ -78,9 +82,9 @@ class VehicleController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Halaman khusus pengelolaan armada Kendaraan Ringan (Light Vehicle / LV).
|
||||
* Helper query builder untuk memfilter data Light Vehicle (LV).
|
||||
*/
|
||||
public function indexLv(Request $request): View
|
||||
private function getFilteredLvQuery(Request $request): Builder
|
||||
{
|
||||
$query = Vehicle::lightVehicles();
|
||||
|
||||
@@ -101,7 +105,15 @@ class VehicleController extends Controller
|
||||
});
|
||||
}
|
||||
|
||||
$vehicles = $query->orderBy('code')->paginate(15)->withQueryString();
|
||||
return $query->orderBy('code');
|
||||
}
|
||||
|
||||
/**
|
||||
* Halaman khusus pengelolaan armada Kendaraan Ringan (Light Vehicle / LV).
|
||||
*/
|
||||
public function indexLv(Request $request): View
|
||||
{
|
||||
$vehicles = $this->getFilteredLvQuery($request)->paginate(15)->withQueryString();
|
||||
|
||||
// Statistik Ringkasan Khusus LV
|
||||
$totalLv = Vehicle::lightVehicles()->count();
|
||||
@@ -122,6 +134,140 @@ class VehicleController extends Controller
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Ekspor data Light Vehicle ke format Excel (.xlsx).
|
||||
*/
|
||||
public function exportLvExcel(Request $request): Response
|
||||
{
|
||||
$vehicles = $this->getFilteredLvQuery($request)->get();
|
||||
|
||||
$today = now()->translatedFormat('d F Y, H:i');
|
||||
$statusFilter = $request->filled('status') ? 'Status: ' . $request->input('status') : 'Semua Status Operasional';
|
||||
$searchFilter = $request->filled('search') ? 'Pencarian: "' . $request->input('search') . '"' : '';
|
||||
|
||||
$metaLines = [
|
||||
'Filter: ' . $statusFilter . ($searchFilter ? ' | ' . $searchFilter : ''),
|
||||
'Total Data: ' . $vehicles->count() . ' Unit LV | Tanggal Dicetak: ' . $today . ' WIB',
|
||||
];
|
||||
|
||||
$headers = [
|
||||
'No' => 6,
|
||||
'Kode LV' => 16,
|
||||
'Merek & Tipe' => 32,
|
||||
'No. Polisi' => 18,
|
||||
'Divisi' => 24,
|
||||
'Kepemilikan' => 20,
|
||||
'Odometer (KM)' => 20,
|
||||
'Status Operasional' => 22,
|
||||
];
|
||||
|
||||
$rows = [];
|
||||
foreach ($vehicles as $idx => $v) {
|
||||
$odo = $v->current_km ? number_format($v->current_km, 0, ',', '.') . ' KM' : '0 KM';
|
||||
$rows[] = [
|
||||
$idx + 1,
|
||||
$v->code,
|
||||
$v->brand_type ?: '-',
|
||||
$v->license_plate ?: '-',
|
||||
$v->division ?: '-',
|
||||
$v->ownership ?: '-',
|
||||
$odo,
|
||||
$v->status ?: 'Standby',
|
||||
];
|
||||
}
|
||||
|
||||
$alignments = ['center', 'center', 'left', 'center', 'left', 'left', 'center', 'center'];
|
||||
|
||||
$fileName = 'Laporan_Data_Light_Vehicle_' . now()->format('Ymd_Hi') . '.xlsx';
|
||||
$binary = SimpleXlsxExporter::create(
|
||||
'LAPORAN DATA KENDARAAN RINGAN (LIGHT VEHICLE) - PT KERINCI MERANGIN HIDRO',
|
||||
$metaLines,
|
||||
$headers,
|
||||
$rows,
|
||||
$alignments
|
||||
);
|
||||
|
||||
return response($binary, 200, [
|
||||
'Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
'Content-Disposition' => 'attachment; filename="' . $fileName . '"',
|
||||
'Content-Length' => strlen($binary),
|
||||
'Cache-Control' => 'max-age=0, no-cache, no-store, must-revalidate',
|
||||
'Pragma' => 'public',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ekspor data Light Vehicle ke format PDF (Pratinjau Asli dengan Logo PT KMH).
|
||||
*/
|
||||
public function exportLvPdf(Request $request): Response
|
||||
{
|
||||
$vehicles = $this->getFilteredLvQuery($request)->get();
|
||||
|
||||
$today = now()->translatedFormat('d F Y, H:i');
|
||||
$statusFilter = $request->filled('status') ? $request->input('status') : 'Semua Status Operasional';
|
||||
|
||||
$totalOp = $vehicles->where('status', 'Operation')->count();
|
||||
$totalSt = $vehicles->where('status', 'Standby')->count();
|
||||
$totalBd = $vehicles->where('status', 'Breakdown')->count();
|
||||
|
||||
$metaLeft = [
|
||||
'Kategori' => 'Light Vehicle (LV)',
|
||||
'Status Operasional' => $statusFilter,
|
||||
'Tanggal Cetak' => $today . ' WIB',
|
||||
];
|
||||
|
||||
$metaRight = [
|
||||
'Total Kendaraan' => $vehicles->count() . ' Unit LV',
|
||||
'Rincian Status' => "{$totalOp} Operation, {$totalSt} Standby, {$totalBd} Breakdown",
|
||||
];
|
||||
|
||||
$columns = [
|
||||
['title' => 'NO', 'width' => 10, 'align' => 'C'],
|
||||
['title' => 'KODE LV', 'width' => 25, 'align' => 'C', 'bold' => true],
|
||||
['title' => 'MEREK & TIPE', 'width' => 64, 'align' => 'L', 'bold' => true, 'max_char' => 38],
|
||||
['title' => 'NO. POLISI', 'width' => 28, 'align' => 'C'],
|
||||
['title' => 'DIVISI', 'width' => 45, 'align' => 'L', 'max_char' => 28],
|
||||
['title' => 'KEPEMILIKAN', 'width' => 35, 'align' => 'L', 'max_char' => 22],
|
||||
['title' => 'ODOMETER', 'width' => 30, 'align' => 'C'],
|
||||
['title' => 'STATUS', 'width' => 30, 'align' => 'C', 'is_status' => true],
|
||||
];
|
||||
|
||||
$rows = [];
|
||||
foreach ($vehicles as $idx => $v) {
|
||||
$odo = $v->current_km ? number_format($v->current_km, 0, ',', '.') . ' KM' : '0 KM';
|
||||
$rows[] = [
|
||||
$idx + 1,
|
||||
$v->code,
|
||||
$v->brand_type ?: '-',
|
||||
$v->license_plate ?: '-',
|
||||
$v->division ?: '-',
|
||||
$v->ownership ?: '-',
|
||||
$odo,
|
||||
$v->status ?: 'Standby',
|
||||
];
|
||||
}
|
||||
|
||||
$subtitle = 'Armada Kendaraan Operasional Light Vehicle - ' . now()->translatedFormat('d F Y');
|
||||
$pdfBinary = VehiclePdfExporter::generate(
|
||||
'Laporan Data Light Vehicle (LV)',
|
||||
$subtitle,
|
||||
$metaLeft,
|
||||
$metaRight,
|
||||
$columns,
|
||||
$rows
|
||||
);
|
||||
|
||||
$fileName = 'Laporan_Light_Vehicle_' . now()->format('Ymd_Hi') . '.pdf';
|
||||
|
||||
return response($pdfBinary, 200, [
|
||||
'Content-Type' => 'application/pdf',
|
||||
'Content-Disposition' => 'inline; filename="' . $fileName . '"',
|
||||
'Content-Length' => strlen($pdfBinary),
|
||||
'Cache-Control' => 'private, max-age=0, must-revalidate',
|
||||
'Pragma' => 'public',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Halaman khusus pengelolaan Kategori Kendaraan Berat (Unit Support / Alat Berat).
|
||||
*/
|
||||
@@ -282,6 +428,453 @@ class VehicleController extends Controller
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper query builder untuk unit fisik alat berat (Unit Support Physical).
|
||||
*/
|
||||
private function getFilteredSupportPhysicalQuery(Request $request): Builder
|
||||
{
|
||||
$query = Vehicle::unitSupportPhysical()->with('parent');
|
||||
|
||||
if ($request->filled('status')) {
|
||||
$query->where('status', $request->input('status'));
|
||||
}
|
||||
|
||||
if ($request->filled('unit_category')) {
|
||||
$cat = $request->input('unit_category');
|
||||
$query->where(function ($q) use ($cat) {
|
||||
$q->where('unit_category', $cat)
|
||||
->orWhereHas('parent', fn ($pq) => $pq->where('unit_category', $cat));
|
||||
});
|
||||
}
|
||||
|
||||
if ($request->filled('search')) {
|
||||
$search = trim($request->input('search'));
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('code', 'like', "%{$search}%")
|
||||
->orWhere('serial_number', 'like', "%{$search}%")
|
||||
->orWhere('brand_type', 'like', "%{$search}%")
|
||||
->orWhere('unit_category', 'like', "%{$search}%")
|
||||
->orWhere('location', 'like', "%{$search}%")
|
||||
->orWhere('license_plate', 'like', "%{$search}%")
|
||||
->orWhereHas('parent', function ($pq) use ($search) {
|
||||
$pq->where('code', 'like', "%{$search}%")
|
||||
->orWhere('unit_category', 'like', "%{$search}%")
|
||||
->orWhere('brand_type', 'like', "%{$search}%");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return $query->orderBy('code');
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper query builder untuk master kategori Unit Support.
|
||||
*/
|
||||
private function getFilteredSupportCategoriesQuery(Request $request): Builder
|
||||
{
|
||||
$query = Vehicle::unitSupportCategories()->withCount('units');
|
||||
|
||||
if ($request->filled('status')) {
|
||||
$query->where('status', $request->input('status'));
|
||||
}
|
||||
|
||||
if ($request->filled('unit_category')) {
|
||||
$query->where('unit_category', $request->input('unit_category'));
|
||||
}
|
||||
|
||||
if ($request->filled('search')) {
|
||||
$search = trim($request->input('search'));
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('code', 'like', "%{$search}%")
|
||||
->orWhere('brand_type', 'like', "%{$search}%")
|
||||
->orWhere('unit_category', 'like', "%{$search}%")
|
||||
->orWhere('location', 'like', "%{$search}%")
|
||||
->orWhere('division', 'like', "%{$search}%");
|
||||
});
|
||||
}
|
||||
|
||||
return $query->orderBy('code');
|
||||
}
|
||||
|
||||
/**
|
||||
* Ekspor data Unit Support ke format Excel (.xlsx).
|
||||
*/
|
||||
public function exportSupportExcel(Request $request): Response
|
||||
{
|
||||
$hasPhysical = Vehicle::unitSupportPhysical()->exists();
|
||||
$today = now()->translatedFormat('d F Y, H:i');
|
||||
|
||||
if ($hasPhysical) {
|
||||
$units = $this->getFilteredSupportPhysicalQuery($request)->get();
|
||||
|
||||
$metaLines = [
|
||||
'Filter: ' . ($request->filled('status') ? 'Status: ' . $request->input('status') : 'Semua Status') .
|
||||
($request->filled('unit_category') ? ' | Kategori: ' . $request->input('unit_category') : '') .
|
||||
($request->filled('search') ? ' | Pencarian: "' . $request->input('search') . '"' : ''),
|
||||
'Total Data: ' . $units->count() . ' Unit Fisik Alat Berat | Tanggal Dicetak: ' . $today . ' WIB',
|
||||
];
|
||||
|
||||
$headers = [
|
||||
'No' => 6,
|
||||
'Kode Unit' => 16,
|
||||
'Kategori Alat' => 28,
|
||||
'No. Seri / Rangka' => 24,
|
||||
'Tahun' => 12,
|
||||
'No. Polisi' => 18,
|
||||
'Lokasi Kerja' => 24,
|
||||
'Odometer (HM/KM)' => 20,
|
||||
'Dokumen Izin' => 20,
|
||||
'Status Operasional' => 22,
|
||||
];
|
||||
|
||||
$rows = [];
|
||||
foreach ($units as $idx => $u) {
|
||||
$categoryName = $u->parent?->unit_category ?: ($u->parent?->brand_type ?: ($u->unit_category ?: 'Unit Support'));
|
||||
$odo = $u->current_km ? number_format($u->current_km, 0, ',', '.') . ' HM' : '0 HM';
|
||||
$docs = trim(($u->silo_document ? 'SILO ' : '') . ($u->kir_document ? 'KIR ' : '')) ?: '-';
|
||||
|
||||
$rows[] = [
|
||||
$idx + 1,
|
||||
$u->code,
|
||||
$categoryName,
|
||||
$u->serial_number ?: '-',
|
||||
$u->production_year ?: '-',
|
||||
$u->license_plate ?: '-',
|
||||
$u->location ?: '-',
|
||||
$odo,
|
||||
$docs,
|
||||
$u->status ?: 'Standby',
|
||||
];
|
||||
}
|
||||
|
||||
$alignments = ['center', 'center', 'left', 'left', 'center', 'center', 'left', 'center', 'center', 'center'];
|
||||
$title = 'LAPORAN DAFTAR UNIT FISIK ALAT BERAT (UNIT SUPPORT) - PT KERINCI MERANGIN HIDRO';
|
||||
$fileName = 'Laporan_Unit_Support_Lengkap_' . now()->format('Ymd_Hi') . '.xlsx';
|
||||
} else {
|
||||
// Fallback ke master kategori jika unit fisik belum diinput
|
||||
$categories = $this->getFilteredSupportCategoriesQuery($request)->get();
|
||||
|
||||
$metaLines = [
|
||||
'Filter: ' . ($request->filled('status') ? 'Status: ' . $request->input('status') : 'Semua Status') .
|
||||
($request->filled('unit_category') ? ' | Kategori: ' . $request->input('unit_category') : ''),
|
||||
'Total Data: ' . $categories->count() . ' Kategori Alat Berat | Tanggal Dicetak: ' . $today . ' WIB',
|
||||
];
|
||||
|
||||
$headers = [
|
||||
'No' => 6,
|
||||
'Kode Kategori' => 16,
|
||||
'Kategori Alat Berat' => 30,
|
||||
'Merek & Tipe Model' => 30,
|
||||
'Total Unit Fisik' => 18,
|
||||
'Lokasi Operasional' => 24,
|
||||
'Status Operasional' => 22,
|
||||
];
|
||||
|
||||
$rows = [];
|
||||
foreach ($categories as $idx => $cat) {
|
||||
$rows[] = [
|
||||
$idx + 1,
|
||||
$cat->code,
|
||||
$cat->unit_category ?: $cat->brand_type,
|
||||
$cat->brand_type ?: '-',
|
||||
$cat->units_count . ' Unit',
|
||||
$cat->location ?: '-',
|
||||
$cat->status ?: 'Standby',
|
||||
];
|
||||
}
|
||||
|
||||
$alignments = ['center', 'center', 'left', 'left', 'center', 'left', 'center'];
|
||||
$title = 'LAPORAN MASTER KATEGORI ALAT BERAT (UNIT SUPPORT) - PT KERINCI MERANGIN HIDRO';
|
||||
$fileName = 'Laporan_Kategori_Unit_Support_' . now()->format('Ymd_Hi') . '.xlsx';
|
||||
}
|
||||
|
||||
$binary = SimpleXlsxExporter::create($title, $metaLines, $headers, $rows, $alignments);
|
||||
|
||||
return response($binary, 200, [
|
||||
'Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
'Content-Disposition' => 'attachment; filename="' . $fileName . '"',
|
||||
'Content-Length' => strlen($binary),
|
||||
'Cache-Control' => 'max-age=0, no-cache, no-store, must-revalidate',
|
||||
'Pragma' => 'public',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ekspor data Unit Support ke format PDF (Pratinjau Asli dengan Logo PT KMH).
|
||||
*/
|
||||
public function exportSupportPdf(Request $request): Response
|
||||
{
|
||||
$hasPhysical = Vehicle::unitSupportPhysical()->exists();
|
||||
$today = now()->translatedFormat('d F Y, H:i');
|
||||
$statusFilter = $request->filled('status') ? $request->input('status') : 'Semua Status Operasional';
|
||||
|
||||
if ($hasPhysical) {
|
||||
$units = $this->getFilteredSupportPhysicalQuery($request)->get();
|
||||
|
||||
$totalOp = $units->where('status', 'Operation')->count();
|
||||
$totalSt = $units->where('status', 'Standby')->count();
|
||||
$totalBd = $units->where('status', 'Breakdown')->count();
|
||||
|
||||
$metaLeft = [
|
||||
'Kategori' => 'Unit Support (Alat Berat Fisik)',
|
||||
'Status Operasional' => $statusFilter,
|
||||
'Tanggal Cetak' => $today . ' WIB',
|
||||
];
|
||||
|
||||
$metaRight = [
|
||||
'Total Unit Fisik' => $units->count() . ' Unit Alat Berat',
|
||||
'Rincian Status' => "{$totalOp} Operation, {$totalSt} Standby, {$totalBd} Breakdown",
|
||||
];
|
||||
|
||||
$columns = [
|
||||
['title' => 'NO', 'width' => 10, 'align' => 'C'],
|
||||
['title' => 'KODE UNIT', 'width' => 24, 'align' => 'C', 'bold' => true],
|
||||
['title' => 'KATEGORI ALAT', 'width' => 45, 'align' => 'L', 'bold' => true, 'max_char' => 26],
|
||||
['title' => 'NO. SERI / RANGKA', 'width' => 42, 'align' => 'L', 'max_char' => 24],
|
||||
['title' => 'THN', 'width' => 14, 'align' => 'C'],
|
||||
['title' => 'NO. POLISI', 'width' => 24, 'align' => 'C'],
|
||||
['title' => 'LOKASI KERJA', 'width' => 50, 'align' => 'L', 'max_char' => 28],
|
||||
['title' => 'ODOMETER', 'width' => 28, 'align' => 'C'],
|
||||
['title' => 'STATUS', 'width' => 30, 'align' => 'C', 'is_status' => true],
|
||||
];
|
||||
|
||||
$rows = [];
|
||||
foreach ($units as $idx => $u) {
|
||||
$categoryName = $u->parent?->unit_category ?: ($u->parent?->brand_type ?: ($u->unit_category ?: 'Unit Support'));
|
||||
$odo = $u->current_km ? number_format($u->current_km, 0, ',', '.') . ' HM' : '0 HM';
|
||||
|
||||
$rows[] = [
|
||||
$idx + 1,
|
||||
$u->code,
|
||||
$categoryName,
|
||||
$u->serial_number ?: '-',
|
||||
$u->production_year ?: '-',
|
||||
$u->license_plate ?: '-',
|
||||
$u->location ?: '-',
|
||||
$odo,
|
||||
$u->status ?: 'Standby',
|
||||
];
|
||||
}
|
||||
|
||||
$title = 'Laporan Data Unit Support (Alat Berat)';
|
||||
$subtitle = 'Daftar Seluruh Unit Fisik Alat Berat Lapangan - ' . now()->translatedFormat('d F Y');
|
||||
$fileName = 'Laporan_Unit_Support_' . now()->format('Ymd_Hi') . '.pdf';
|
||||
} else {
|
||||
$categories = $this->getFilteredSupportCategoriesQuery($request)->get();
|
||||
|
||||
$totalOp = $categories->where('status', 'Operation')->count();
|
||||
$totalSt = $categories->where('status', 'Standby')->count();
|
||||
$totalBd = $categories->where('status', 'Breakdown')->count();
|
||||
|
||||
$metaLeft = [
|
||||
'Kategori' => 'Master Kategori Unit Support',
|
||||
'Status Operasional' => $statusFilter,
|
||||
'Tanggal Cetak' => $today . ' WIB',
|
||||
];
|
||||
|
||||
$metaRight = [
|
||||
'Total Kategori' => $categories->count() . ' Kategori Alat',
|
||||
'Rincian Status' => "{$totalOp} Operation, {$totalSt} Standby, {$totalBd} Breakdown",
|
||||
];
|
||||
|
||||
$columns = [
|
||||
['title' => 'NO', 'width' => 10, 'align' => 'C'],
|
||||
['title' => 'KODE', 'width' => 25, 'align' => 'C', 'bold' => true],
|
||||
['title' => 'KATEGORI ALAT BERAT', 'width' => 64, 'align' => 'L', 'bold' => true, 'max_char' => 38],
|
||||
['title' => 'MEREK & MODEL', 'width' => 55, 'align' => 'L', 'max_char' => 32],
|
||||
['title' => 'TOTAL UNIT', 'width' => 28, 'align' => 'C', 'bold' => true],
|
||||
['title' => 'LOKASI OPERASIONAL', 'width' => 55, 'align' => 'L', 'max_char' => 32],
|
||||
['title' => 'STATUS', 'width' => 30, 'align' => 'C', 'is_status' => true],
|
||||
];
|
||||
|
||||
$rows = [];
|
||||
foreach ($categories as $idx => $cat) {
|
||||
$rows[] = [
|
||||
$idx + 1,
|
||||
$cat->code,
|
||||
$cat->unit_category ?: $cat->brand_type,
|
||||
$cat->brand_type ?: '-',
|
||||
$cat->units_count . ' Unit',
|
||||
$cat->location ?: '-',
|
||||
$cat->status ?: 'Standby',
|
||||
];
|
||||
}
|
||||
|
||||
$title = 'Laporan Master Kategori Unit Support';
|
||||
$subtitle = 'Master 28 Kategori Alat Berat Proyek KMH - ' . now()->translatedFormat('d F Y');
|
||||
$fileName = 'Laporan_Kategori_Unit_Support_' . now()->format('Ymd_Hi') . '.pdf';
|
||||
}
|
||||
|
||||
$pdfBinary = VehiclePdfExporter::generate($title, $subtitle, $metaLeft, $metaRight, $columns, $rows);
|
||||
|
||||
return response($pdfBinary, 200, [
|
||||
'Content-Type' => 'application/pdf',
|
||||
'Content-Disposition' => 'inline; filename="' . $fileName . '"',
|
||||
'Content-Length' => strlen($pdfBinary),
|
||||
'Cache-Control' => 'private, max-age=0, must-revalidate',
|
||||
'Pragma' => 'public',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ekspor data unit fisik khusus kategori tertentu ke format Excel (.xlsx).
|
||||
*/
|
||||
public function exportSupportUnitsExcel(Request $request, int $id): Response
|
||||
{
|
||||
$category = Vehicle::unitSupportCategories()->withCount('units')->findOrFail($id);
|
||||
$query = $category->units();
|
||||
|
||||
if ($request->filled('status')) {
|
||||
$query->where('status', $request->input('status'));
|
||||
}
|
||||
|
||||
if ($request->filled('search')) {
|
||||
$search = trim($request->input('search'));
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('code', 'like', "%{$search}%")
|
||||
->orWhere('serial_number', 'like', "%{$search}%")
|
||||
->orWhere('license_plate', 'like', "%{$search}%")
|
||||
->orWhere('location', 'like', "%{$search}%");
|
||||
});
|
||||
}
|
||||
|
||||
$units = $query->orderBy('code')->get();
|
||||
$today = now()->translatedFormat('d F Y, H:i');
|
||||
|
||||
$metaLines = [
|
||||
'Kategori: ' . ($category->unit_category ?: $category->brand_type) . ' (' . $category->code . ')' .
|
||||
($request->filled('status') ? ' | Status: ' . $request->input('status') : '') .
|
||||
($request->filled('search') ? ' | Pencarian: "' . $request->input('search') . '"' : ''),
|
||||
'Total Data: ' . $units->count() . ' Unit Fisik | Tanggal Dicetak: ' . $today . ' WIB',
|
||||
];
|
||||
|
||||
$headers = [
|
||||
'No' => 6,
|
||||
'Kode Unit' => 16,
|
||||
'No. Seri / Rangka' => 24,
|
||||
'Tahun' => 12,
|
||||
'No. Polisi' => 18,
|
||||
'Lokasi Kerja' => 24,
|
||||
'Odometer (HM/KM)' => 20,
|
||||
'Dokumen Izin' => 20,
|
||||
'Status Operasional' => 22,
|
||||
];
|
||||
|
||||
$rows = [];
|
||||
foreach ($units as $idx => $u) {
|
||||
$odo = $u->current_km ? number_format($u->current_km, 0, ',', '.') . ' HM' : '0 HM';
|
||||
$docs = trim(($u->silo_document ? 'SILO ' : '') . ($u->kir_document ? 'KIR ' : '')) ?: '-';
|
||||
|
||||
$rows[] = [
|
||||
$idx + 1,
|
||||
$u->code,
|
||||
$u->serial_number ?: '-',
|
||||
$u->production_year ?: '-',
|
||||
$u->license_plate ?: '-',
|
||||
$u->location ?: '-',
|
||||
$odo,
|
||||
$docs,
|
||||
$u->status ?: 'Standby',
|
||||
];
|
||||
}
|
||||
|
||||
$alignments = ['center', 'center', 'left', 'center', 'center', 'left', 'center', 'center', 'center'];
|
||||
$title = 'LAPORAN UNIT FISIK ' . strtoupper($category->unit_category ?: $category->brand_type) . ' - PT KERINCI MERANGIN HIDRO';
|
||||
$fileName = 'Laporan_Unit_' . preg_replace('/[^A-Za-z0-9_-]/', '_', $category->code) . '_' . now()->format('Ymd_Hi') . '.xlsx';
|
||||
|
||||
$binary = SimpleXlsxExporter::create($title, $metaLines, $headers, $rows, $alignments);
|
||||
|
||||
return response($binary, 200, [
|
||||
'Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
'Content-Disposition' => 'attachment; filename="' . $fileName . '"',
|
||||
'Content-Length' => strlen($binary),
|
||||
'Cache-Control' => 'max-age=0, no-cache, no-store, must-revalidate',
|
||||
'Pragma' => 'public',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ekspor data unit fisik khusus kategori tertentu ke format PDF (Pratinjau Asli dengan Logo PT KMH).
|
||||
*/
|
||||
public function exportSupportUnitsPdf(Request $request, int $id): Response
|
||||
{
|
||||
$category = Vehicle::unitSupportCategories()->withCount('units')->findOrFail($id);
|
||||
$query = $category->units();
|
||||
|
||||
if ($request->filled('status')) {
|
||||
$query->where('status', $request->input('status'));
|
||||
}
|
||||
|
||||
if ($request->filled('search')) {
|
||||
$search = trim($request->input('search'));
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('code', 'like', "%{$search}%")
|
||||
->orWhere('serial_number', 'like', "%{$search}%")
|
||||
->orWhere('license_plate', 'like', "%{$search}%")
|
||||
->orWhere('location', 'like', "%{$search}%");
|
||||
});
|
||||
}
|
||||
|
||||
$units = $query->orderBy('code')->get();
|
||||
$today = now()->translatedFormat('d F Y, H:i');
|
||||
$statusFilter = $request->filled('status') ? $request->input('status') : 'Semua Status Operasional';
|
||||
|
||||
$totalOp = $units->where('status', 'Operation')->count();
|
||||
$totalSt = $units->where('status', 'Standby')->count();
|
||||
$totalBd = $units->where('status', 'Breakdown')->count();
|
||||
|
||||
$metaLeft = [
|
||||
'Kategori Alat' => ($category->unit_category ?: $category->brand_type) . ' (' . $category->code . ')',
|
||||
'Status Operasional' => $statusFilter,
|
||||
'Tanggal Cetak' => $today . ' WIB',
|
||||
];
|
||||
|
||||
$metaRight = [
|
||||
'Total Unit Fisik' => $units->count() . ' Unit Terdaftar',
|
||||
'Rincian Status' => "{$totalOp} Operation, {$totalSt} Standby, {$totalBd} Breakdown",
|
||||
];
|
||||
|
||||
$columns = [
|
||||
['title' => 'NO', 'width' => 10, 'align' => 'C'],
|
||||
['title' => 'KODE UNIT', 'width' => 28, 'align' => 'C', 'bold' => true],
|
||||
['title' => 'NO. SERI / RANGKA', 'width' => 50, 'align' => 'L', 'max_char' => 30],
|
||||
['title' => 'TAHUN', 'width' => 18, 'align' => 'C'],
|
||||
['title' => 'NO. POLISI', 'width' => 28, 'align' => 'C'],
|
||||
['title' => 'LOKASI KERJA', 'width' => 65, 'align' => 'L', 'max_char' => 38],
|
||||
['title' => 'ODOMETER', 'width' => 34, 'align' => 'C'],
|
||||
['title' => 'STATUS', 'width' => 34, 'align' => 'C', 'is_status' => true],
|
||||
];
|
||||
|
||||
$rows = [];
|
||||
foreach ($units as $idx => $u) {
|
||||
$odo = $u->current_km ? number_format($u->current_km, 0, ',', '.') . ' HM' : '0 HM';
|
||||
$rows[] = [
|
||||
$idx + 1,
|
||||
$u->code,
|
||||
$u->serial_number ?: '-',
|
||||
$u->production_year ?: '-',
|
||||
$u->license_plate ?: '-',
|
||||
$u->location ?: '-',
|
||||
$odo,
|
||||
$u->status ?: 'Standby',
|
||||
];
|
||||
}
|
||||
|
||||
$title = 'Laporan Unit Fisik ' . ($category->unit_category ?: $category->brand_type);
|
||||
$subtitle = 'Kategori ' . $category->code . ' - ' . now()->translatedFormat('d F Y');
|
||||
$fileName = 'Laporan_Unit_' . preg_replace('/[^A-Za-z0-9_-]/', '_', $category->code) . '_' . now()->format('Ymd_Hi') . '.pdf';
|
||||
|
||||
$pdfBinary = VehiclePdfExporter::generate($title, $subtitle, $metaLeft, $metaRight, $columns, $rows);
|
||||
|
||||
return response($pdfBinary, 200, [
|
||||
'Content-Type' => 'application/pdf',
|
||||
'Content-Disposition' => 'inline; filename="' . $fileName . '"',
|
||||
'Content-Length' => strlen($pdfBinary),
|
||||
'Cache-Control' => 'private, max-age=0, must-revalidate',
|
||||
'Pragma' => 'public',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simpan penambahan unit fisik baru di bawah kategori Unit Support tertentu.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,207 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use FPDF;
|
||||
|
||||
class PgTablePdfExporter extends FPDF
|
||||
{
|
||||
public string $reportTitle = 'Laporan Modul Private Guard';
|
||||
public string $subtitle = '';
|
||||
public string $systemTitle = 'MODUL PRIVATE GUARD (PG) - RKM-KMH';
|
||||
public array $metaLeft = [];
|
||||
public array $metaRight = [];
|
||||
public array $columns = []; // [['title' => 'NO', 'width' => 10, 'align' => 'C', 'bold' => true, 'max_char' => 20, 'is_status' => true], ...]
|
||||
public int $totalRows = 0;
|
||||
public string $logoPath = '';
|
||||
|
||||
public function Header(): void
|
||||
{
|
||||
// 1. Logo Perusahaan di Kiri Atas
|
||||
if (!empty($this->logoPath) && file_exists($this->logoPath)) {
|
||||
$this->Image($this->logoPath, 15, 10, 44);
|
||||
} else {
|
||||
$this->SetXY(15, 10);
|
||||
$this->SetFont('Arial', 'B', 14);
|
||||
$this->SetTextColor(27, 94, 32);
|
||||
$this->Cell(60, 8, 'KERINCI HYDROPOWER', 0, 0, 'L');
|
||||
}
|
||||
|
||||
// 2. Branding Sistem di Kanan Atas
|
||||
$this->SetXY(170, 10);
|
||||
$this->SetFont('Arial', 'B', 18);
|
||||
$this->SetTextColor(27, 94, 32); // #1b5e20 Green
|
||||
$this->Cell(112, 6, 'RKM-KMH', 0, 1, 'R');
|
||||
|
||||
$this->SetXY(170, 16);
|
||||
$this->SetFont('Arial', 'B', 7.5);
|
||||
$this->SetTextColor(71, 85, 105); // #475569 Slate
|
||||
$this->Cell(112, 4, 'KERINCI HYDROPOWER 350 MW', 0, 1, 'R');
|
||||
|
||||
// 3. Banner Biru Gelap Navy (#06213f)
|
||||
$this->SetY(24);
|
||||
$this->SetFillColor(6, 33, 63);
|
||||
$this->Rect(15, 24, 267, 16, 'F');
|
||||
|
||||
// Teks Judul di Kiri Banner
|
||||
$this->SetXY(18, 26);
|
||||
$this->SetFont('Arial', 'B', 13);
|
||||
$this->SetTextColor(255, 255, 255);
|
||||
$this->Cell(140, 6, $this->reportTitle, 0, 1, 'L');
|
||||
|
||||
$this->SetXY(18, 32);
|
||||
$this->SetFont('Arial', '', 8);
|
||||
$this->SetTextColor(203, 213, 225); // #cbd5e1 Slate
|
||||
$this->Cell(140, 5, $this->subtitle, 0, 1, 'L');
|
||||
|
||||
// Teks Sub-sistem di Kanan Banner
|
||||
$this->SetXY(160, 26);
|
||||
$this->SetFont('Arial', 'B', 9);
|
||||
$this->SetTextColor(255, 255, 255);
|
||||
$this->Cell(119, 6, $this->systemTitle, 0, 1, 'R');
|
||||
|
||||
$this->SetXY(160, 32);
|
||||
$this->SetFont('Arial', 'I', 7.5);
|
||||
$this->SetTextColor(203, 213, 225);
|
||||
$this->Cell(119, 5, 'Dicetak otomatis dari sistem', 0, 1, 'R');
|
||||
|
||||
// 4. Bagian Ringkasan Metadata (2 Kolom)
|
||||
$metaY = 44;
|
||||
$this->SetTextColor(51, 65, 85);
|
||||
|
||||
// Kolom Kiri
|
||||
foreach ($this->metaLeft as $k => $v) {
|
||||
$this->SetXY(15, $metaY);
|
||||
$this->SetFont('Arial', '', 8);
|
||||
$this->Cell(32, 4.5, $k, 0, 0);
|
||||
$this->Cell(5, 4.5, ':', 0, 0);
|
||||
$this->SetFont('Arial', 'B', 8);
|
||||
$this->Cell(85, 4.5, (string) $v, 0, 1);
|
||||
$metaY += 5;
|
||||
}
|
||||
|
||||
// Kolom Kanan
|
||||
$metaY2 = 44;
|
||||
foreach ($this->metaRight as $k => $v) {
|
||||
$this->SetXY(165, $metaY2);
|
||||
$this->SetFont('Arial', '', 8);
|
||||
$this->Cell(34, 4.5, $k, 0, 0);
|
||||
$this->Cell(5, 4.5, ':', 0, 0);
|
||||
$this->SetFont('Arial', 'B', 8);
|
||||
$this->Cell(78, 4.5, (string) $v, 0, 1);
|
||||
$metaY2 += 5;
|
||||
}
|
||||
|
||||
// Garis Pembatas Tipis
|
||||
$divY = max($metaY, $metaY2) + 2;
|
||||
$this->SetDrawColor(226, 232, 240);
|
||||
$this->Line(15, $divY, 282, $divY);
|
||||
|
||||
// 5. Header Tabel Solid Navy
|
||||
$tableY = $divY + 3;
|
||||
$this->SetXY(15, $tableY);
|
||||
$this->SetFillColor(6, 33, 63);
|
||||
$this->SetTextColor(255, 255, 255);
|
||||
$this->SetFont('Arial', 'B', 7.5);
|
||||
|
||||
foreach ($this->columns as $col) {
|
||||
$this->Cell($col['width'], 7.5, $col['title'], 0, 0, $col['align'] ?? 'L', true);
|
||||
}
|
||||
$this->Ln();
|
||||
}
|
||||
|
||||
public function Footer(): void
|
||||
{
|
||||
$this->SetY(-12);
|
||||
$this->SetFont('Arial', '', 7.5);
|
||||
$this->SetTextColor(148, 163, 184);
|
||||
$this->Cell(
|
||||
180,
|
||||
5,
|
||||
'Menampilkan ' . $this->totalRows . ' data - Dokumen ini digenerate secara otomatis oleh Sistem RKM-KMH pada ' . now()->translatedFormat('d F Y') . '.',
|
||||
0,
|
||||
0,
|
||||
'L'
|
||||
);
|
||||
$this->Cell(87, 5, 'Halaman ' . $this->PageNo() . ' dari {nb}', 0, 0, 'R');
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper pembuatan file PDF seragam untuk seluruh modul tabel PG.
|
||||
*/
|
||||
public static function generate(
|
||||
string $title,
|
||||
string $subtitle,
|
||||
string $systemTitle,
|
||||
array $metaLeft,
|
||||
array $metaRight,
|
||||
array $columns,
|
||||
array $rows
|
||||
): string {
|
||||
$pdf = new self('L', 'mm', 'A4');
|
||||
$pdf->AliasNbPages();
|
||||
$pdf->reportTitle = $title;
|
||||
$pdf->subtitle = $subtitle;
|
||||
$pdf->systemTitle = $systemTitle;
|
||||
$pdf->metaLeft = $metaLeft;
|
||||
$pdf->metaRight = $metaRight;
|
||||
$pdf->columns = $columns;
|
||||
$pdf->totalRows = count($rows);
|
||||
$pdf->logoPath = public_path('images/logo-kerinci.png');
|
||||
|
||||
$pdf->SetMargins(15, 10, 15);
|
||||
$pdf->AddPage();
|
||||
$pdf->SetAutoPageBreak(true, 15);
|
||||
|
||||
$fill = false;
|
||||
foreach ($rows as $r) {
|
||||
$pdf->SetFillColor(248, 250, 252);
|
||||
$pdf->SetDrawColor(241, 245, 249);
|
||||
$pdf->SetTextColor(15, 23, 42);
|
||||
|
||||
foreach ($columns as $idx => $col) {
|
||||
$val = (string) ($r[$idx] ?? '-');
|
||||
$align = $col['align'] ?? 'L';
|
||||
$width = $col['width'];
|
||||
$isBold = !empty($col['bold']);
|
||||
$isStatus = !empty($col['is_status']);
|
||||
|
||||
if ($isStatus) {
|
||||
$valLower = strtolower($val);
|
||||
if (str_contains($valLower, 'nonaktif')) {
|
||||
$pdf->SetTextColor(100, 116, 139); // Slate Gray #64748b
|
||||
} elseif (str_contains($valLower, 'disetujui') || str_contains($valLower, 'approved') || str_contains($valLower, 'aktif') || str_contains($valLower, 'masuk') || $valLower === 'in') {
|
||||
$pdf->SetTextColor(4, 120, 87); // Emerald Green #047857
|
||||
} elseif (str_contains($valLower, 'menunggu') || str_contains($valLower, 'pending') || str_contains($valLower, 'regu 2')) {
|
||||
$pdf->SetTextColor(180, 83, 9); // Amber #b45309
|
||||
} elseif (str_contains($valLower, 'ditolak') || str_contains($valLower, 'rejected')) {
|
||||
$pdf->SetTextColor(190, 18, 60); // Rose Red #be123c
|
||||
} elseif (str_contains($valLower, 'keluar') || $valLower === 'out' || str_contains($valLower, 'regu 1')) {
|
||||
$pdf->SetTextColor(29, 78, 216); // Blue #1d4ed8
|
||||
} elseif (str_contains($valLower, 'regu 3')) {
|
||||
$pdf->SetTextColor(126, 34, 206); // Purple #7e22ce
|
||||
} else {
|
||||
$pdf->SetTextColor(100, 116, 139);
|
||||
}
|
||||
$pdf->SetFont('Arial', 'B', 7.5);
|
||||
} else {
|
||||
$pdf->SetTextColor(15, 23, 42);
|
||||
$pdf->SetFont('Arial', $isBold ? 'B' : '', 7.5);
|
||||
}
|
||||
|
||||
$maxChar = !empty($col['max_char']) ? $col['max_char'] : 0;
|
||||
if ($maxChar > 0 && mb_strlen($val) > $maxChar) {
|
||||
$val = mb_strimwidth($val, 0, $maxChar, '...');
|
||||
}
|
||||
|
||||
$displayVal = ($align === 'L' && !empty($val) && $val !== '-') ? ' ' . $val : $val;
|
||||
$pdf->Cell($width, 6.5, $displayVal, 'B', 0, $align, $fill);
|
||||
}
|
||||
|
||||
$pdf->Ln();
|
||||
$fill = !$fill;
|
||||
}
|
||||
|
||||
return $pdf->Output('S');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use FPDF;
|
||||
|
||||
class QmaTablePdfExporter extends FPDF
|
||||
{
|
||||
public string $reportTitle = 'Laporan Sistem QMA';
|
||||
public string $subtitle = '';
|
||||
public string $systemTitle = 'SISTEM QMA RKM-KMH';
|
||||
public array $metaLeft = [];
|
||||
public array $metaRight = [];
|
||||
public array $columns = []; // [['title' => 'NO', 'width' => 10, 'align' => 'C', 'bold' => true, 'max_char' => 20, 'is_status' => true], ...]
|
||||
public int $totalRows = 0;
|
||||
public string $logoPath = '';
|
||||
|
||||
public function Header(): void
|
||||
{
|
||||
// 1. Logo Perusahaan di Kiri Atas
|
||||
if (!empty($this->logoPath) && file_exists($this->logoPath)) {
|
||||
$this->Image($this->logoPath, 15, 10, 44);
|
||||
} else {
|
||||
$this->SetXY(15, 10);
|
||||
$this->SetFont('Arial', 'B', 14);
|
||||
$this->SetTextColor(27, 94, 32);
|
||||
$this->Cell(60, 8, 'KERINCI HYDROPOWER', 0, 0, 'L');
|
||||
}
|
||||
|
||||
// 2. Branding Sistem di Kanan Atas
|
||||
$this->SetXY(170, 10);
|
||||
$this->SetFont('Arial', 'B', 18);
|
||||
$this->SetTextColor(27, 94, 32); // #1b5e20 Green
|
||||
$this->Cell(112, 6, 'RKM-KMH', 0, 1, 'R');
|
||||
|
||||
$this->SetXY(170, 16);
|
||||
$this->SetFont('Arial', 'B', 7.5);
|
||||
$this->SetTextColor(71, 85, 105); // #475569 Slate
|
||||
$this->Cell(112, 4, 'KERINCI HYDROPOWER 350 MW', 0, 1, 'R');
|
||||
|
||||
// 3. Banner Biru Gelap Navy
|
||||
$this->SetY(24);
|
||||
$this->SetFillColor(6, 33, 63); // #06213f Dark Navy
|
||||
$this->Rect(15, 24, 267, 16, 'F');
|
||||
|
||||
// Teks Judul di Kiri Banner
|
||||
$this->SetXY(18, 26);
|
||||
$this->SetFont('Arial', 'B', 13);
|
||||
$this->SetTextColor(255, 255, 255);
|
||||
$this->Cell(140, 6, $this->reportTitle, 0, 1, 'L');
|
||||
|
||||
$this->SetXY(18, 32);
|
||||
$this->SetFont('Arial', '', 8);
|
||||
$this->SetTextColor(203, 213, 225); // #cbd5e1 Slate
|
||||
$this->Cell(140, 5, $this->subtitle, 0, 1, 'L');
|
||||
|
||||
// Teks Sub-sistem di Kanan Banner
|
||||
$this->SetXY(160, 26);
|
||||
$this->SetFont('Arial', 'B', 9);
|
||||
$this->SetTextColor(255, 255, 255);
|
||||
$this->Cell(119, 6, $this->systemTitle, 0, 1, 'R');
|
||||
|
||||
$this->SetXY(160, 32);
|
||||
$this->SetFont('Arial', 'I', 7.5);
|
||||
$this->SetTextColor(203, 213, 225);
|
||||
$this->Cell(119, 5, 'Dicetak otomatis dari sistem', 0, 1, 'R');
|
||||
|
||||
// 4. Bagian Ringkasan Metadata (2 Kolom)
|
||||
$metaY = 44;
|
||||
$this->SetTextColor(51, 65, 85);
|
||||
|
||||
// Kolom Kiri
|
||||
foreach ($this->metaLeft as $k => $v) {
|
||||
$this->SetXY(15, $metaY);
|
||||
$this->SetFont('Arial', '', 8);
|
||||
$this->Cell(32, 4.5, $k, 0, 0);
|
||||
$this->Cell(5, 4.5, ':', 0, 0);
|
||||
$this->SetFont('Arial', 'B', 8);
|
||||
$this->Cell(85, 4.5, (string) $v, 0, 1);
|
||||
$metaY += 5;
|
||||
}
|
||||
|
||||
// Kolom Kanan
|
||||
$metaY2 = 44;
|
||||
foreach ($this->metaRight as $k => $v) {
|
||||
$this->SetXY(165, $metaY2);
|
||||
$this->SetFont('Arial', '', 8);
|
||||
$this->Cell(34, 4.5, $k, 0, 0);
|
||||
$this->Cell(5, 4.5, ':', 0, 0);
|
||||
$this->SetFont('Arial', 'B', 8);
|
||||
$this->Cell(78, 4.5, (string) $v, 0, 1);
|
||||
$metaY2 += 5;
|
||||
}
|
||||
|
||||
// Garis Pembatas Tipis
|
||||
$divY = max($metaY, $metaY2) + 2;
|
||||
$this->SetDrawColor(226, 232, 240);
|
||||
$this->Line(15, $divY, 282, $divY);
|
||||
|
||||
// 5. Header Tabel Solid Navy
|
||||
$tableY = $divY + 3;
|
||||
$this->SetXY(15, $tableY);
|
||||
$this->SetFillColor(6, 33, 63);
|
||||
$this->SetTextColor(255, 255, 255);
|
||||
$this->SetFont('Arial', 'B', 7.5);
|
||||
|
||||
foreach ($this->columns as $col) {
|
||||
$this->Cell($col['width'], 7.5, $col['title'], 0, 0, $col['align'] ?? 'L', true);
|
||||
}
|
||||
$this->Ln();
|
||||
}
|
||||
|
||||
public function Footer(): void
|
||||
{
|
||||
$this->SetY(-12);
|
||||
$this->SetFont('Arial', '', 7.5);
|
||||
$this->SetTextColor(148, 163, 184);
|
||||
$this->Cell(
|
||||
180,
|
||||
5,
|
||||
'Menampilkan ' . $this->totalRows . ' data - Dokumen ini digenerate secara otomatis oleh Sistem RKM-KMH pada ' . now()->translatedFormat('d F Y') . '.',
|
||||
0,
|
||||
0,
|
||||
'L'
|
||||
);
|
||||
$this->Cell(87, 5, 'Halaman ' . $this->PageNo() . ' dari {nb}', 0, 0, 'R');
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper pembuatan file PDF seragam untuk seluruh modul tabel QMA.
|
||||
*/
|
||||
public static function generate(
|
||||
string $title,
|
||||
string $subtitle,
|
||||
string $systemTitle,
|
||||
array $metaLeft,
|
||||
array $metaRight,
|
||||
array $columns,
|
||||
array $rows
|
||||
): string {
|
||||
$pdf = new self('L', 'mm', 'A4');
|
||||
$pdf->AliasNbPages();
|
||||
$pdf->reportTitle = $title;
|
||||
$pdf->subtitle = $subtitle;
|
||||
$pdf->systemTitle = $systemTitle;
|
||||
$pdf->metaLeft = $metaLeft;
|
||||
$pdf->metaRight = $metaRight;
|
||||
$pdf->columns = $columns;
|
||||
$pdf->totalRows = count($rows);
|
||||
$pdf->logoPath = public_path('images/logo-kerinci.png');
|
||||
|
||||
$pdf->SetMargins(15, 10, 15);
|
||||
$pdf->AddPage();
|
||||
$pdf->SetAutoPageBreak(true, 15);
|
||||
|
||||
$fill = false;
|
||||
foreach ($rows as $r) {
|
||||
$pdf->SetFillColor(248, 250, 252);
|
||||
$pdf->SetDrawColor(241, 245, 249);
|
||||
$pdf->SetTextColor(15, 23, 42);
|
||||
|
||||
foreach ($columns as $idx => $col) {
|
||||
$val = (string) ($r[$idx] ?? '-');
|
||||
$align = $col['align'] ?? 'L';
|
||||
$width = $col['width'];
|
||||
$isBold = !empty($col['bold']);
|
||||
$isStatus = !empty($col['is_status']);
|
||||
|
||||
if ($isStatus) {
|
||||
$valLower = strtolower($val);
|
||||
if (str_contains($valLower, 'disetujui') || str_contains($valLower, 'approved') || str_contains($valLower, 'operation') || str_contains($valLower, 'normal') || str_contains($valLower, 'baik')) {
|
||||
$pdf->SetTextColor(4, 120, 87); // Green #047857
|
||||
} elseif (str_contains($valLower, 'menunggu') || str_contains($valLower, 'pending') || str_contains($valLower, 'standby')) {
|
||||
$pdf->SetTextColor(180, 83, 9); // Amber #b45309
|
||||
} elseif (str_contains($valLower, 'ditolak') || str_contains($valLower, 'rejected') || str_contains($valLower, 'breakdown') || str_contains($valLower, 'rusak') || str_contains($valLower, 'defect')) {
|
||||
$pdf->SetTextColor(190, 18, 60); // Rose Red #be123c
|
||||
} elseif (str_contains($valLower, 'masuk') || $valLower === 'in') {
|
||||
$pdf->SetTextColor(4, 120, 87); // Green
|
||||
} elseif (str_contains($valLower, 'keluar') || $valLower === 'out') {
|
||||
$pdf->SetTextColor(29, 78, 216); // Blue #1d4ed8
|
||||
} elseif (str_contains($valLower, 'maintenance')) {
|
||||
$pdf->SetTextColor(2, 132, 199); // Sky blue
|
||||
} else {
|
||||
$pdf->SetTextColor(100, 116, 139);
|
||||
}
|
||||
$pdf->SetFont('Arial', 'B', 7.5);
|
||||
} else {
|
||||
$pdf->SetTextColor(15, 23, 42);
|
||||
$pdf->SetFont('Arial', $isBold ? 'B' : '', 7.5);
|
||||
}
|
||||
|
||||
$maxChar = !empty($col['max_char']) ? $col['max_char'] : 0;
|
||||
if ($maxChar > 0 && mb_strlen($val) > $maxChar) {
|
||||
$val = mb_strimwidth($val, 0, $maxChar, '...');
|
||||
}
|
||||
|
||||
$displayVal = ($align === 'L' && !empty($val) && $val !== '-') ? ' ' . $val : $val;
|
||||
$pdf->Cell($width, 6.5, $displayVal, 'B', 0, $align, $fill);
|
||||
}
|
||||
|
||||
$pdf->Ln();
|
||||
$fill = !$fill;
|
||||
}
|
||||
|
||||
return $pdf->Output('S');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,227 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use FPDF;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class SimperPdfExporter extends FPDF
|
||||
{
|
||||
public string $reportTitle = 'Laporan Data SIMPER';
|
||||
public string $subtitle = '';
|
||||
public array $metaLeft = [];
|
||||
public array $metaRight = [];
|
||||
public int $totalRows = 0;
|
||||
public string $logoPath = '';
|
||||
|
||||
public function Header(): void
|
||||
{
|
||||
// 1. Logo Perusahaan di Kiri Atas
|
||||
if (!empty($this->logoPath) && file_exists($this->logoPath)) {
|
||||
$this->Image($this->logoPath, 15, 10, 44);
|
||||
} else {
|
||||
$this->SetXY(15, 10);
|
||||
$this->SetFont('Arial', 'B', 14);
|
||||
$this->SetTextColor(27, 94, 32);
|
||||
$this->Cell(60, 8, 'KERINCI HYDROPOWER', 0, 0, 'L');
|
||||
}
|
||||
|
||||
// 2. Branding Sistem di Kanan Atas
|
||||
$this->SetXY(170, 10);
|
||||
$this->SetFont('Arial', 'B', 18);
|
||||
$this->SetTextColor(27, 94, 32); // #1b5e20 Green
|
||||
$this->Cell(112, 6, 'RKM-KMH', 0, 1, 'R');
|
||||
|
||||
$this->SetXY(170, 16);
|
||||
$this->SetFont('Arial', 'B', 7.5);
|
||||
$this->SetTextColor(71, 85, 105); // #475569 Slate
|
||||
$this->Cell(112, 4, 'KERINCI HYDROPOWER 350 MW', 0, 1, 'R');
|
||||
|
||||
// 3. Banner Biru Gelap Navy (Sesuai Referensi it.allrole.web.id)
|
||||
$this->SetY(24);
|
||||
$this->SetFillColor(6, 33, 63); // #06213f Dark Navy
|
||||
$this->Rect(15, 24, 267, 16, 'F');
|
||||
|
||||
// Teks Judul di Kiri Banner
|
||||
$this->SetXY(18, 26);
|
||||
$this->SetFont('Arial', 'B', 13);
|
||||
$this->SetTextColor(255, 255, 255);
|
||||
$this->Cell(140, 6, $this->reportTitle, 0, 1, 'L');
|
||||
|
||||
$this->SetXY(18, 32);
|
||||
$this->SetFont('Arial', '', 8);
|
||||
$this->SetTextColor(203, 213, 225); // #cbd5e1 Slate
|
||||
$this->Cell(140, 5, $this->subtitle, 0, 1, 'L');
|
||||
|
||||
// Teks Sub-sistem di Kanan Banner
|
||||
$this->SetXY(160, 26);
|
||||
$this->SetFont('Arial', 'B', 9);
|
||||
$this->SetTextColor(255, 255, 255);
|
||||
$this->Cell(119, 6, 'SISTEM KENDARAAN RKM-KMH', 0, 1, 'R');
|
||||
|
||||
$this->SetXY(160, 32);
|
||||
$this->SetFont('Arial', 'I', 7.5);
|
||||
$this->SetTextColor(203, 213, 225);
|
||||
$this->Cell(119, 5, 'Dicetak otomatis dari sistem', 0, 1, 'R');
|
||||
|
||||
// 4. Bagian Ringkasan Metadata (2 Kolom)
|
||||
$metaY = 44;
|
||||
$this->SetTextColor(51, 65, 85);
|
||||
|
||||
// Kolom Kiri
|
||||
foreach ($this->metaLeft as $k => $v) {
|
||||
$this->SetXY(15, $metaY);
|
||||
$this->SetFont('Arial', '', 8);
|
||||
$this->Cell(28, 4.5, $k, 0, 0);
|
||||
$this->Cell(5, 4.5, ':', 0, 0);
|
||||
$this->SetFont('Arial', 'B', 8);
|
||||
$this->Cell(85, 4.5, $v, 0, 1);
|
||||
$metaY += 5;
|
||||
}
|
||||
|
||||
// Kolom Kanan
|
||||
$metaY2 = 44;
|
||||
foreach ($this->metaRight as $k => $v) {
|
||||
$this->SetXY(175, $metaY2);
|
||||
$this->SetFont('Arial', '', 8);
|
||||
$this->Cell(28, 4.5, $k, 0, 0);
|
||||
$this->Cell(5, 4.5, ':', 0, 0);
|
||||
$this->SetFont('Arial', 'B', 8);
|
||||
$this->Cell(74, 4.5, $v, 0, 1);
|
||||
$metaY2 += 5;
|
||||
}
|
||||
|
||||
// Garis Pembatas Tipis
|
||||
$divY = max($metaY, $metaY2) + 2;
|
||||
$this->SetDrawColor(226, 232, 240);
|
||||
$this->Line(15, $divY, 282, $divY);
|
||||
|
||||
// 5. Header Tabel Solid Navy
|
||||
$tableY = $divY + 3;
|
||||
$this->SetXY(15, $tableY);
|
||||
$this->SetFillColor(6, 33, 63);
|
||||
$this->SetTextColor(255, 255, 255);
|
||||
$this->SetFont('Arial', 'B', 7.5);
|
||||
|
||||
$cols = [
|
||||
['NO', 10, 'C'],
|
||||
['NIK', 30, 'C'],
|
||||
['NAMA KARYAWAN', 62, 'L'],
|
||||
['JABATAN', 45, 'L'],
|
||||
['UNIT / DIVISI', 40, 'L'],
|
||||
['STATUS DRIVER', 26, 'C'],
|
||||
['MASA BERLAKU', 26, 'C'],
|
||||
['STATUS SIMPER', 28, 'C'],
|
||||
];
|
||||
|
||||
foreach ($cols as $col) {
|
||||
$this->Cell($col[1], 7.5, $col[0], 0, 0, $col[2], true);
|
||||
}
|
||||
$this->Ln();
|
||||
}
|
||||
|
||||
public function Footer(): void
|
||||
{
|
||||
$this->SetY(-12);
|
||||
$this->SetFont('Arial', '', 7.5);
|
||||
$this->SetTextColor(148, 163, 184);
|
||||
$this->Cell(
|
||||
180,
|
||||
5,
|
||||
'Menampilkan ' . $this->totalRows . ' data - Dokumen ini digenerate secara otomatis oleh Sistem RKM-KMH pada ' . now()->translatedFormat('d F Y') . '.',
|
||||
0,
|
||||
0,
|
||||
'L'
|
||||
);
|
||||
$this->Cell(87, 5, 'Halaman ' . $this->PageNo() . ' dari {nb}', 0, 0, 'R');
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate real PDF binary string.
|
||||
*/
|
||||
public static function generate(Collection $employees, array $metaLeft, array $metaRight, string $subtitle): string
|
||||
{
|
||||
$pdf = new self('L', 'mm', 'A4');
|
||||
$pdf->AliasNbPages();
|
||||
$pdf->reportTitle = 'Laporan Data SIMPER';
|
||||
$pdf->subtitle = $subtitle;
|
||||
$pdf->metaLeft = $metaLeft;
|
||||
$pdf->metaRight = $metaRight;
|
||||
$pdf->totalRows = $employees->count();
|
||||
$pdf->logoPath = public_path('images/logo-kerinci.png');
|
||||
|
||||
$pdf->SetMargins(15, 10, 15);
|
||||
$pdf->AddPage();
|
||||
$pdf->SetAutoPageBreak(true, 15);
|
||||
|
||||
$pdf->SetFont('Arial', '', 7.5);
|
||||
$fill = false;
|
||||
$soon = now()->addDays(30);
|
||||
|
||||
foreach ($employees as $idx => $emp) {
|
||||
$isDriver = $emp->is_operator;
|
||||
$expDate = $emp->simper_expired_at ? $emp->simper_expired_at->format('d/m/Y') : '-';
|
||||
|
||||
if (! $isDriver) {
|
||||
$statusText = 'Bukan Driver';
|
||||
} elseif (! $emp->simper_expired_at) {
|
||||
$statusText = 'Belum Ada SIMPER';
|
||||
} elseif ($emp->simper_expired_at->isPast() && ! $emp->simper_expired_at->isToday()) {
|
||||
$statusText = 'Kedaluwarsa';
|
||||
} elseif ($emp->simper_expired_at->lte($soon)) {
|
||||
$statusText = 'Segera Habis';
|
||||
} else {
|
||||
$statusText = 'Masih Berlaku';
|
||||
}
|
||||
|
||||
$pdf->SetFillColor(248, 250, 252);
|
||||
$pdf->SetDrawColor(241, 245, 249);
|
||||
$pdf->SetTextColor(15, 23, 42);
|
||||
|
||||
// Kolom 1: No
|
||||
$pdf->SetFont('Arial', '', 7.5);
|
||||
$pdf->Cell(10, 6.5, (string) ($idx + 1), 'B', 0, 'C', $fill);
|
||||
|
||||
// Kolom 2: NIK (Bold)
|
||||
$pdf->SetFont('Arial', 'B', 7.5);
|
||||
$pdf->Cell(30, 6.5, $emp->nik, 'B', 0, 'C', $fill);
|
||||
|
||||
// Kolom 3: Nama Lengkap (Bold, Truncate jika > 36 karakter)
|
||||
$nama = mb_strimwidth($emp->name, 0, 36, '...');
|
||||
$pdf->Cell(62, 6.5, ' ' . $nama, 'B', 0, 'L', $fill);
|
||||
|
||||
// Kolom 4: Jabatan
|
||||
$pdf->SetFont('Arial', '', 7.5);
|
||||
$jabatan = mb_strimwidth($emp->position ?: '-', 0, 26, '...');
|
||||
$pdf->Cell(45, 6.5, ' ' . $jabatan, 'B', 0, 'L', $fill);
|
||||
|
||||
// Kolom 5: Unit / Divisi
|
||||
$unit = mb_strimwidth($emp->unit_kerja ?: ($emp->division ?: '-'), 0, 24, '...');
|
||||
$pdf->Cell(40, 6.5, ' ' . $unit, 'B', 0, 'L', $fill);
|
||||
|
||||
// Kolom 6: Status Driver
|
||||
$pdf->Cell(26, 6.5, $isDriver ? 'Driver' : 'Non-Driver', 'B', 0, 'C', $fill);
|
||||
|
||||
// Kolom 7: Masa Berlaku
|
||||
$pdf->Cell(26, 6.5, $expDate, 'B', 0, 'C', $fill);
|
||||
|
||||
// Kolom 8: Status SIMPER (Berwarna)
|
||||
if ($statusText === 'Masih Berlaku') {
|
||||
$pdf->SetTextColor(4, 120, 87); // #047857 Green
|
||||
} elseif ($statusText === 'Segera Habis') {
|
||||
$pdf->SetTextColor(180, 83, 9); // #b45309 Amber
|
||||
} elseif ($statusText === 'Kedaluwarsa' || $statusText === 'Belum Ada SIMPER') {
|
||||
$pdf->SetTextColor(190, 18, 60); // #be123c Rose
|
||||
} else {
|
||||
$pdf->SetTextColor(100, 116, 139); // #64748b Slate
|
||||
}
|
||||
$pdf->SetFont('Arial', 'B', 7.5);
|
||||
$pdf->Cell(28, 6.5, $statusText, 'B', 0, 'C', $fill);
|
||||
|
||||
$pdf->Ln();
|
||||
$fill = ! $fill;
|
||||
}
|
||||
|
||||
return $pdf->Output('S');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use ZipArchive;
|
||||
|
||||
class SimpleXlsxExporter
|
||||
{
|
||||
/**
|
||||
* Generate standard OpenXML XLSX binary string.
|
||||
*
|
||||
* @param string $title
|
||||
* @param array $metaLines e.g. ['Filter: Semua', 'Tanggal Cetak: 16-10-2026 09:30']
|
||||
* @param array $headers e.g. ['No' => 6, 'NIK' => 16, 'Nama Lengkap' => 28, ...]
|
||||
* @param array $rows Array of associative or index arrays
|
||||
* @param array $alignments Optional per-column alignment: 'center' or 'left'
|
||||
* @return string Raw zip content
|
||||
*/
|
||||
public static function create(string $title, array $metaLines, array $headers, array $rows, array $alignments = []): string
|
||||
{
|
||||
$numCols = count($headers);
|
||||
$lastColLetter = self::colLetter($numCols);
|
||||
|
||||
// Build sheetData XML
|
||||
$sheetXml = '<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">';
|
||||
$sheetXml .= '<sheetPr><outlinePr summaryBelow="1" summaryRight="1" /><pageSetUpPr /></sheetPr>';
|
||||
|
||||
$totalRows = 4 + count($metaLines) + count($rows);
|
||||
$sheetXml .= '<dimension ref="A1:' . $lastColLetter . $totalRows . '" />';
|
||||
$sheetXml .= '<sheetViews><sheetView workbookViewId="0"><selection activeCell="A1" sqref="A1" /></sheetView></sheetViews>';
|
||||
$sheetXml .= '<sheetFormatPr baseColWidth="8" defaultRowHeight="16" />';
|
||||
|
||||
// Column widths
|
||||
$sheetXml .= '<cols>';
|
||||
$colIdx = 1;
|
||||
foreach ($headers as $name => $width) {
|
||||
$sheetXml .= '<col min="' . $colIdx . '" max="' . $colIdx . '" width="' . (is_numeric($width) ? $width : 15) . '" customWidth="1" />';
|
||||
$colIdx++;
|
||||
}
|
||||
$sheetXml .= '</cols>';
|
||||
|
||||
$sheetXml .= '<sheetData>';
|
||||
|
||||
// Row 1: Title
|
||||
$rowNum = 1;
|
||||
$sheetXml .= '<row r="' . $rowNum . '" ht="26" customHeight="1">';
|
||||
$sheetXml .= '<c r="A1" s="1" t="inlineStr"><is><t>' . htmlspecialchars($title, ENT_XML1) . '</t></is></c>';
|
||||
$sheetXml .= '</row>';
|
||||
|
||||
// Meta lines (Sub-titles)
|
||||
foreach ($metaLines as $meta) {
|
||||
$rowNum++;
|
||||
$sheetXml .= '<row r="' . $rowNum . '" ht="18" customHeight="1">';
|
||||
$sheetXml .= '<c r="A' . $rowNum . '" s="2" t="inlineStr"><is><t>' . htmlspecialchars($meta, ENT_XML1) . '</t></is></c>';
|
||||
$sheetXml .= '</row>';
|
||||
}
|
||||
|
||||
// Blank spacer row
|
||||
$rowNum++;
|
||||
$sheetXml .= '<row r="' . $rowNum . '" ht="10" customHeight="1"></row>';
|
||||
|
||||
// Table Header Row
|
||||
$rowNum++;
|
||||
$headerRowNum = $rowNum;
|
||||
$sheetXml .= '<row r="' . $headerRowNum . '" ht="24" customHeight="1">';
|
||||
$cIdx = 1;
|
||||
foreach ($headers as $name => $width) {
|
||||
$cellRef = self::colLetter($cIdx) . $headerRowNum;
|
||||
$sheetXml .= '<c r="' . $cellRef . '" s="3" t="inlineStr"><is><t>' . htmlspecialchars($name, ENT_XML1) . '</t></is></c>';
|
||||
$cIdx++;
|
||||
}
|
||||
$sheetXml .= '</row>';
|
||||
|
||||
// Table Data Rows
|
||||
$alignKeys = array_values($alignments);
|
||||
foreach ($rows as $rData) {
|
||||
$rowNum++;
|
||||
$sheetXml .= '<row r="' . $rowNum . '" ht="20" customHeight="1">';
|
||||
$cIdx = 1;
|
||||
$vals = is_array($rData) ? array_values($rData) : [];
|
||||
for ($i = 0; $i < $numCols; $i++) {
|
||||
$val = $vals[$i] ?? '';
|
||||
$cellRef = self::colLetter($cIdx) . $rowNum;
|
||||
$align = $alignKeys[$i] ?? ($cIdx === 1 ? 'center' : 'left');
|
||||
$styleId = ($align === 'center') ? 4 : 5;
|
||||
|
||||
if (is_numeric($val) && strlen($val) > 0 && !str_starts_with((string)$val, '0')) {
|
||||
$sheetXml .= '<c r="' . $cellRef . '" s="' . $styleId . '" t="n"><v>' . $val . '</v></c>';
|
||||
} else {
|
||||
$sheetXml .= '<c r="' . $cellRef . '" s="' . $styleId . '" t="inlineStr"><is><t>' . htmlspecialchars((string)$val, ENT_XML1) . '</t></is></c>';
|
||||
}
|
||||
$cIdx++;
|
||||
}
|
||||
$sheetXml .= '</row>';
|
||||
}
|
||||
|
||||
$sheetXml .= '</sheetData>';
|
||||
|
||||
// Merge cells for title and meta lines
|
||||
$sheetXml .= '<mergeCells count="' . (1 + count($metaLines)) . '">';
|
||||
$sheetXml .= '<mergeCell ref="A1:' . $lastColLetter . '1" />';
|
||||
for ($m = 2; $m <= 1 + count($metaLines); $m++) {
|
||||
$sheetXml .= '<mergeCell ref="A' . $m . ':' . $lastColLetter . $m . '" />';
|
||||
}
|
||||
$sheetXml .= '</mergeCells>';
|
||||
|
||||
$sheetXml .= '<pageMargins left="0.5" right="0.5" top="0.75" bottom="0.75" header="0.3" footer="0.3" />';
|
||||
$sheetXml .= '</worksheet>';
|
||||
|
||||
// Stylesheet with KMH Brand Colors (Navy / Forest Green)
|
||||
$stylesXml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
|
||||
<fonts count="4">
|
||||
<font><name val="Arial" /><sz val="10" /></font>
|
||||
<font><name val="Arial" /><sz val="14" /><b val="1" /><color rgb="FF0F172A" /></font>
|
||||
<font><name val="Arial" /><sz val="9" /><i val="1" /><color rgb="FF64748B" /></font>
|
||||
<font><name val="Arial" /><sz val="10" /><b val="1" /><color rgb="FFFFFFFF" /></font>
|
||||
</fonts>
|
||||
<fills count="3">
|
||||
<fill><patternFill patternType="none" /></fill>
|
||||
<fill><patternFill patternType="gray125" /></fill>
|
||||
<fill><patternFill patternType="solid"><fgColor rgb="FF06213F" /><bgColor rgb="FF06213F" /></patternFill></fill>
|
||||
</fills>
|
||||
<borders count="2">
|
||||
<border><left /><right /><top /><bottom /></border>
|
||||
<border>
|
||||
<left style="thin"><color rgb="FFE2E8F0" /></left>
|
||||
<right style="thin"><color rgb="FFE2E8F0" /></right>
|
||||
<top style="thin"><color rgb="FFE2E8F0" /></top>
|
||||
<bottom style="thin"><color rgb="FFE2E8F0" /></bottom>
|
||||
</border>
|
||||
</borders>
|
||||
<cellStyleXfs count="1">
|
||||
<xf numFmtId="0" fontId="0" fillId="0" borderId="0" />
|
||||
</cellStyleXfs>
|
||||
<cellXfs count="6">
|
||||
<xf numFmtId="0" fontId="0" fillId="0" borderId="0" />
|
||||
<xf numFmtId="0" fontId="1" fillId="0" borderId="0" applyAlignment="1"><alignment horizontal="center" vertical="center" /></xf>
|
||||
<xf numFmtId="0" fontId="2" fillId="0" borderId="0" applyAlignment="1"><alignment horizontal="center" vertical="center" /></xf>
|
||||
<xf numFmtId="0" fontId="3" fillId="2" borderId="1" applyAlignment="1"><alignment horizontal="center" vertical="center" wrapText="1" /></xf>
|
||||
<xf numFmtId="0" fontId="0" fillId="0" borderId="1" applyAlignment="1"><alignment horizontal="center" vertical="center" /></xf>
|
||||
<xf numFmtId="0" fontId="0" fillId="0" borderId="1" applyAlignment="1"><alignment horizontal="left" vertical="center" /></xf>
|
||||
</cellXfs>
|
||||
</styleSheet>';
|
||||
|
||||
$workbookXml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<workbook xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
|
||||
<sheets>
|
||||
<sheet name="Data SIMPER" sheetId="1" r:id="rId1" />
|
||||
</sheets>
|
||||
</workbook>';
|
||||
|
||||
$workbookRelsXml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
|
||||
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet1.xml" />
|
||||
<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml" />
|
||||
</Relationships>';
|
||||
|
||||
$relsXml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
|
||||
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml" />
|
||||
</Relationships>';
|
||||
|
||||
$contentTypesXml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
|
||||
<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml" />
|
||||
<Default Extension="xml" ContentType="application/xml" />
|
||||
<Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml" />
|
||||
<Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml" />
|
||||
<Override PartName="/xl/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml" />
|
||||
</Types>';
|
||||
|
||||
// Build ZIP
|
||||
$tmpFile = tempnam(sys_get_temp_dir(), 'xlsx_');
|
||||
$zip = new ZipArchive();
|
||||
$zip->open($tmpFile, ZipArchive::OVERWRITE);
|
||||
|
||||
$zip->addFromString('[Content_Types].xml', $contentTypesXml);
|
||||
$zip->addFromString('_rels/.rels', $relsXml);
|
||||
$zip->addFromString('xl/workbook.xml', $workbookXml);
|
||||
$zip->addFromString('xl/_rels/workbook.xml.rels', $workbookRelsXml);
|
||||
$zip->addFromString('xl/styles.xml', $stylesXml);
|
||||
$zip->addFromString('xl/worksheets/sheet1.xml', $sheetXml);
|
||||
|
||||
$zip->close();
|
||||
|
||||
$content = file_get_contents($tmpFile);
|
||||
unlink($tmpFile);
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
private static function colLetter(int $colIndex): string
|
||||
{
|
||||
$letter = '';
|
||||
while ($colIndex > 0) {
|
||||
$p = ($colIndex - 1) % 26;
|
||||
$letter = chr(65 + $p) . $letter;
|
||||
$colIndex = intval(($colIndex - $p) / 26);
|
||||
}
|
||||
return $letter ?: 'A';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use FPDF;
|
||||
|
||||
class VehiclePdfExporter extends FPDF
|
||||
{
|
||||
public string $reportTitle = 'Laporan Data Kendaraan';
|
||||
public string $subtitle = '';
|
||||
public array $metaLeft = [];
|
||||
public array $metaRight = [];
|
||||
public array $columns = []; // [['title' => 'NO', 'width' => 10, 'align' => 'C'], ...]
|
||||
public int $totalRows = 0;
|
||||
public string $logoPath = '';
|
||||
|
||||
public function Header(): void
|
||||
{
|
||||
// 1. Logo Perusahaan di Kiri Atas
|
||||
if (!empty($this->logoPath) && file_exists($this->logoPath)) {
|
||||
$this->Image($this->logoPath, 15, 10, 44);
|
||||
} else {
|
||||
$this->SetXY(15, 10);
|
||||
$this->SetFont('Arial', 'B', 14);
|
||||
$this->SetTextColor(27, 94, 32);
|
||||
$this->Cell(60, 8, 'KERINCI HYDROPOWER', 0, 0, 'L');
|
||||
}
|
||||
|
||||
// 2. Branding Sistem di Kanan Atas
|
||||
$this->SetXY(170, 10);
|
||||
$this->SetFont('Arial', 'B', 18);
|
||||
$this->SetTextColor(27, 94, 32); // #1b5e20 Green
|
||||
$this->Cell(112, 6, 'RKM-KMH', 0, 1, 'R');
|
||||
|
||||
$this->SetXY(170, 16);
|
||||
$this->SetFont('Arial', 'B', 7.5);
|
||||
$this->SetTextColor(71, 85, 105); // #475569 Slate
|
||||
$this->Cell(112, 4, 'KERINCI HYDROPOWER 350 MW', 0, 1, 'R');
|
||||
|
||||
// 3. Banner Biru Gelap Navy (Sesuai Format it.allrole.web.id)
|
||||
$this->SetY(24);
|
||||
$this->SetFillColor(6, 33, 63); // #06213f Dark Navy
|
||||
$this->Rect(15, 24, 267, 16, 'F');
|
||||
|
||||
// Teks Judul di Kiri Banner
|
||||
$this->SetXY(18, 26);
|
||||
$this->SetFont('Arial', 'B', 13);
|
||||
$this->SetTextColor(255, 255, 255);
|
||||
$this->Cell(140, 6, $this->reportTitle, 0, 1, 'L');
|
||||
|
||||
$this->SetXY(18, 32);
|
||||
$this->SetFont('Arial', '', 8);
|
||||
$this->SetTextColor(203, 213, 225); // #cbd5e1 Slate
|
||||
$this->Cell(140, 5, $this->subtitle, 0, 1, 'L');
|
||||
|
||||
// Teks Sub-sistem di Kanan Banner
|
||||
$this->SetXY(160, 26);
|
||||
$this->SetFont('Arial', 'B', 9);
|
||||
$this->SetTextColor(255, 255, 255);
|
||||
$this->Cell(119, 6, 'SISTEM KENDARAAN RKM-KMH', 0, 1, 'R');
|
||||
|
||||
$this->SetXY(160, 32);
|
||||
$this->SetFont('Arial', 'I', 7.5);
|
||||
$this->SetTextColor(203, 213, 225);
|
||||
$this->Cell(119, 5, 'Dicetak otomatis dari sistem', 0, 1, 'R');
|
||||
|
||||
// 4. Bagian Ringkasan Metadata (2 Kolom)
|
||||
$metaY = 44;
|
||||
$this->SetTextColor(51, 65, 85);
|
||||
|
||||
// Kolom Kiri
|
||||
foreach ($this->metaLeft as $k => $v) {
|
||||
$this->SetXY(15, $metaY);
|
||||
$this->SetFont('Arial', '', 8);
|
||||
$this->Cell(28, 4.5, $k, 0, 0);
|
||||
$this->Cell(5, 4.5, ':', 0, 0);
|
||||
$this->SetFont('Arial', 'B', 8);
|
||||
$this->Cell(85, 4.5, (string) $v, 0, 1);
|
||||
$metaY += 5;
|
||||
}
|
||||
|
||||
// Kolom Kanan
|
||||
$metaY2 = 44;
|
||||
foreach ($this->metaRight as $k => $v) {
|
||||
$this->SetXY(175, $metaY2);
|
||||
$this->SetFont('Arial', '', 8);
|
||||
$this->Cell(28, 4.5, $k, 0, 0);
|
||||
$this->Cell(5, 4.5, ':', 0, 0);
|
||||
$this->SetFont('Arial', 'B', 8);
|
||||
$this->Cell(74, 4.5, (string) $v, 0, 1);
|
||||
$metaY2 += 5;
|
||||
}
|
||||
|
||||
// Garis Pembatas Tipis
|
||||
$divY = max($metaY, $metaY2) + 2;
|
||||
$this->SetDrawColor(226, 232, 240);
|
||||
$this->Line(15, $divY, 282, $divY);
|
||||
|
||||
// 5. Header Tabel Solid Navy
|
||||
$tableY = $divY + 3;
|
||||
$this->SetXY(15, $tableY);
|
||||
$this->SetFillColor(6, 33, 63);
|
||||
$this->SetTextColor(255, 255, 255);
|
||||
$this->SetFont('Arial', 'B', 7.5);
|
||||
|
||||
foreach ($this->columns as $col) {
|
||||
$this->Cell($col['width'], 7.5, $col['title'], 0, 0, $col['align'] ?? 'L', true);
|
||||
}
|
||||
$this->Ln();
|
||||
}
|
||||
|
||||
public function Footer(): void
|
||||
{
|
||||
$this->SetY(-12);
|
||||
$this->SetFont('Arial', '', 7.5);
|
||||
$this->SetTextColor(148, 163, 184);
|
||||
$this->Cell(
|
||||
180,
|
||||
5,
|
||||
'Menampilkan ' . $this->totalRows . ' data - Dokumen ini digenerate secara otomatis oleh Sistem RKM-KMH pada ' . now()->translatedFormat('d F Y') . '.',
|
||||
0,
|
||||
0,
|
||||
'L'
|
||||
);
|
||||
$this->Cell(87, 5, 'Halaman ' . $this->PageNo() . ' dari {nb}', 0, 0, 'R');
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper pembuatan file PDF seragam untuk modul armada kendaraan.
|
||||
*/
|
||||
public static function generate(
|
||||
string $title,
|
||||
string $subtitle,
|
||||
array $metaLeft,
|
||||
array $metaRight,
|
||||
array $columns,
|
||||
array $rows
|
||||
): string {
|
||||
$pdf = new self('L', 'mm', 'A4');
|
||||
$pdf->AliasNbPages();
|
||||
$pdf->reportTitle = $title;
|
||||
$pdf->subtitle = $subtitle;
|
||||
$pdf->metaLeft = $metaLeft;
|
||||
$pdf->metaRight = $metaRight;
|
||||
$pdf->columns = $columns;
|
||||
$pdf->totalRows = count($rows);
|
||||
$pdf->logoPath = public_path('images/logo-kerinci.png');
|
||||
|
||||
$pdf->SetMargins(15, 10, 15);
|
||||
$pdf->AddPage();
|
||||
$pdf->SetAutoPageBreak(true, 15);
|
||||
|
||||
$fill = false;
|
||||
foreach ($rows as $r) {
|
||||
$pdf->SetFillColor(248, 250, 252);
|
||||
$pdf->SetDrawColor(241, 245, 249);
|
||||
$pdf->SetTextColor(15, 23, 42);
|
||||
|
||||
foreach ($columns as $idx => $col) {
|
||||
$val = (string) ($r[$idx] ?? '-');
|
||||
$align = $col['align'] ?? 'L';
|
||||
$width = $col['width'];
|
||||
$isBold = !empty($col['bold']);
|
||||
$isStatus = !empty($col['is_status']);
|
||||
|
||||
if ($isStatus) {
|
||||
if ($val === 'Operation') {
|
||||
$pdf->SetTextColor(4, 120, 87); // Green
|
||||
} elseif ($val === 'Standby') {
|
||||
$pdf->SetTextColor(180, 83, 9); // Amber
|
||||
} elseif ($val === 'Breakdown') {
|
||||
$pdf->SetTextColor(190, 18, 60); // Red
|
||||
} elseif ($val === 'Maintenance') {
|
||||
$pdf->SetTextColor(2, 132, 199); // Sky blue
|
||||
} else {
|
||||
$pdf->SetTextColor(100, 116, 139);
|
||||
}
|
||||
$pdf->SetFont('Arial', 'B', 7.5);
|
||||
} else {
|
||||
$pdf->SetTextColor(15, 23, 42);
|
||||
$pdf->SetFont('Arial', $isBold ? 'B' : '', 7.5);
|
||||
}
|
||||
|
||||
$maxChar = !empty($col['max_char']) ? $col['max_char'] : 0;
|
||||
if ($maxChar > 0 && mb_strlen($val) > $maxChar) {
|
||||
$val = mb_strimwidth($val, 0, $maxChar, '...');
|
||||
}
|
||||
|
||||
$displayVal = ($align === 'L' && !empty($val) && $val !== '-') ? ' ' . $val : $val;
|
||||
$pdf->Cell($width, 6.5, $displayVal, 'B', 0, $align, $fill);
|
||||
}
|
||||
|
||||
$pdf->Ln();
|
||||
$fill = !$fill;
|
||||
}
|
||||
|
||||
return $pdf->Output('S');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user