@php if (!function_exists('image_to_base64_data_uri')) { function image_to_base64_data_uri($path) { if (!file_exists($path) || !is_readable($path)) { return null; } $type = mime_content_type($path); if ($type === false) { $type = 'image/' . pathinfo($path, PATHINFO_EXTENSION); } $data = file_get_contents($path); return 'data:' . $type . ';base64,' . base64_encode($data); } } $cardsPerPage = $cols * $rows; $widthCm = data_get($cardSetting, 'card.width_cm', 8.6); $heightCm = data_get($cardSetting, 'card.height_cm', 15); $bgFilename = data_get($cardSetting, 'card.background'); $bgPath = $bgFilename ? public_path('assets/images/card/' . $bgFilename) : public_path('assets/images/card/defould.png'); $bgBase64 = image_to_base64_data_uri($bgPath); $titleStyle = data_get($cardSetting, 'title', []); $photoStyle = data_get($cardSetting, 'photo', []); $qrStyle = data_get($cardSetting, 'qr', []); $cardWidthCm = data_get($cardSetting, 'card.width_cm', 8.6); $cardWidthPx = round($cardWidthCm * 37.8); $qrSizeRatio = data_get($qrStyle, 'size_ratio'); $qrSize = $qrSizeRatio ? round($qrSizeRatio * $cardWidthPx) : data_get($qrStyle, 'size', 80); @endphp @php $paperSizes = [ 'A4' => [21.0, 29.7], 'A5' => [14.8, 21.0], 'Letter' => [21.59, 27.94] ]; [$sheetW, $sheetH] = $paperSizes[$paper] ?? $paperSizes['A4']; if (strtolower($orientation ?? '') === 'landscape') { [$sheetW, $sheetH] = [$sheetH, $sheetW]; } @endphp @php $validAnggota = collect($keanggotaan ?? []) ->filter(function($a){ return optional($a)->user !== null; }) ->values(); @endphp @foreach($validAnggota->chunk($cardsPerPage) as $pageIndex => $page)
@foreach($page as $anggota) @php $user = optional($anggota)->user; @endphp @if($user)
@php $profile = optional($user->profile); $province = optional($profile->province)->name ?? ($profile->other_province ?? null); $regency = optional($profile->regency)->name ?? ($profile->other_regency ?? null); $district = optional($profile->district)->name ?? ($profile->other_district ?? null); $photoFilename = optional($profile)->foto; $photoPath = $photoFilename ? public_path('assets/images/profilefoto/' . $photoFilename) : public_path('assets/images/profilefoto/default-profile.png'); $photoBase64 = image_to_base64_data_uri($photoPath); $imgSize = (file_exists($photoPath) && is_readable($photoPath)) ? @getimagesize($photoPath) : null; $imgAspectRatio = ($imgSize && isset($imgSize[0]) && isset($imgSize[1]) && $imgSize[0] > 0 && $imgSize[1] > 0) ? ($imgSize[0] / $imgSize[1]) : 1.22; @endphp
@if(data_get($titleStyle, 'visible', true))
{{ str_replace(["\r\n","\n"], ' ', (data_get($cardSetting, 'title.text', 'KARTU ANGGOTA'))) }}
@endif @if(data_get($cardSetting, 'name.visible', false))
{{ $user->name ?? '-' }}
@endif @if(data_get($cardSetting, 'number.visible', false))
No. Anggota: {{ $anggota->nomor_anggota ?? '-' }}
@endif @if($photoBase64 && data_get($photoStyle, 'visible', true))
@endif @if(data_get($cardSetting, 'email.visible', false))
{{ $user->email ?? '-' }}
@endif @if(data_get($cardSetting, 'no_hp.visible', false))
{{ $profile->no_hp ?? '-' }}
@endif @if(data_get($cardSetting, 'jenis_kelamin.visible', false))
{{ $profile->jenis_kelamin ?? '-' }}
@endif @if(data_get($cardSetting, 'pekerjaan.visible', false))
{{ $profile->pekerjaan ?? '-' }}
@endif @if(data_get($cardSetting, 'jabatan.visible', false))
{{ $profile->jabatan ?? '-' }}
@endif @if(data_get($cardSetting, 'alamat.visible', false))
{{ $profile->alamat ?? '-' }}
@endif @if(data_get($cardSetting, 'province.visible', false))
{{ $province ?? '-' }}
@endif @if(data_get($cardSetting, 'regency.visible', false))
{{ $regency ?? '-' }}
@endif @if(data_get($cardSetting, 'district.visible', false))
{{ $district ?? '-' }}
@endif @if(data_get($cardSetting, 'date.visible', false))
Bergabung: {{ $anggota->tanggal_bergabung ? $anggota->tanggal_bergabung->format('d/m/Y') : '-' }}
@endif @if(data_get($qrStyle, 'visible', true))
@php // Prioritaskan nomor anggota, jika tidak ada baru gunakan ID $qrData = !empty($anggota->nomor_anggota) ? $anggota->nomor_anggota : ($user->id ?? ''); $qrSvg = \SimpleSoftwareIO\QrCode\Facades\QrCode::size($qrSize)->generate($qrData); $qrBase64 = base64_encode($qrSvg); @endphp QR Code
@endif
@endif @endforeach
@endforeach