{{-- "Ringkasan Pengiriman" in the campaign reports: the flow Pengiriman awal (the user's input) -> Terkirim (Sukses + Gagal) -> Sukses / Gagal, with the rest "Dalam proses" while the campaign runs, or "Tidak dikirim" (filtered out: invalid, inactive or unregistered numbers) once it has ended. Shows a pie of Sukses / Gagal / rest (each slice labelled with its share), the flow table, and analytic tiles: Tingkat Terkirim, Tingkat Sukses, Rasio Sukses : Klik, and for LBA the reach of the area's potential recipients. Params: input (recipients the user submitted), success, failed, clicks (null without a short link), status (DigitalCore campaign_status); LBA only: lba (bool), estimate (the API's stored {population, min_population, max_population} or null), estimatePending (the page fetches it). Counts may be numbers or formatted strings. --}} @php $toCount = static function ($value): ?int { if (is_int($value) || is_float($value) || (is_string($value) && is_numeric($value))) { return max(0, (int) $value); } $digits = preg_replace('/\D/', '', (string) $value); // "1.234" (formatted) -> 1234 return $digits === '' ? null : (int) $digits; }; $count = static fn (int $value) => number_format($value, 0, ',', '.'); $percent = static function (?float $value): string { if ($value === null) { return '–'; } $decimals = $value > 0 && $value < 1 ? 2 : (abs($value - round($value)) < 0.05 ? 0 : 1); return number_format($value, $decimals, ',', '.').'%'; }; $share = static fn (int $part, int $whole) => $whole > 0 ? $part / $whole * 100 : null; $hint = static fn (string $text) => 'i'; $input = $toCount($input ?? null); $success = $toCount($success ?? null) ?? 0; $failed = $toCount($failed ?? null) ?? 0; $clicks = ($clicks ?? null) === null ? null : ($toCount($clicks) ?? 0); $ended = in_array(strtoupper(trim((string) ($status ?? ''))), ['FINISH', 'STOP', 'REJECT'], true); $attempted = $success + $failed; // The whole is the user's input; without one (or when DigitalCore counted more), the attempted sends. $base = $input !== null && $input >= $attempted ? $input : $attempted; $rest = $base - $attempted; $restLabel = $ended ? 'Tidak dikirim' : 'Dalam proses'; $restHint = $ended ? 'Nomor tidak aktif, tidak valid atau tidak terdaftar, sehingga tidak dikirim operator.' : 'Masih dalam antrean atau belum dilaporkan DigitalCore.'; $parts = [ ['key' => 'success', 'label' => 'Sukses', 'value' => $success], ['key' => 'failed', 'label' => 'Gagal', 'value' => $failed], ['key' => 'rest', 'label' => $restLabel, 'value' => $rest], ]; $summary = collect($parts)->map(fn ($part) => $part['label'].' '.$count($part['value']).' ('.$percent($share($part['value'], $base)).')')->implode(', '); // Pie: wedges clockwise from 12 o'clock in a 42x42 box (centre 21,21, radius 20); each wedge with // its share printed at 62% of the radius when it is big enough to hold the label (>= 6%). $point = static fn (float $turn, float $radius) => [21 + $radius * sin(2 * M_PI * $turn), 21 - $radius * cos(2 * M_PI * $turn)]; $slices = []; $start = 0.0; foreach (collect($parts)->filter(fn ($part) => $part['value'] > 0) as $part) { $turn = $part['value'] / $base; [$x0, $y0] = $point($start, 20); [$x1, $y1] = $point($start + $turn, 20); [$lx, $ly] = $point($start + $turn / 2, 12.4); $slices[] = $part + [ 'path' => $turn >= 0.9999 ? null : sprintf('M21 21L%.3f %.3fA20 20 0 %d 1 %.3f %.3fZ', $x0, $y0, $turn > 0.5 ? 1 : 0, $x1, $y1), 'text' => $turn >= 0.06 ? $percent($turn * 100) : null, 'lx' => $turn >= 0.9999 ? 21 : $lx, 'ly' => $turn >= 0.9999 ? 21 : $ly, ]; $start += $turn; } // Rasio Sukses : Klik. $clickHint = 'Click hanya dihitung jika pesan memakai Link Singkat (tombol Buat Link Singkat saat membuat iklan).'; $clickShare = $clicks === null ? null : $share($clicks, $success); $clickNote = match (true) { $clicks === null => 'Belum ada Link Singkat di iklan ini.', $success === 0 => 'Belum ada pesan sukses.', $clicks === 0 => 'Belum ada klik dari '.$count($success).' pesan sukses.', default => $percent($clickShare).' dari pesan sukses diklik · 1 klik tiap ' .number_format($success / $clicks, $success % $clicks === 0 ? 0 : 1, ',', '.').' pesan sukses', }; // LBA: Pengiriman awal against the area's potential recipients (the API's stored estimate). $lba = (bool) ($lba ?? false); $estimate = is_array($estimate ?? null) && is_numeric($estimate['population'] ?? null) ? $estimate : null; $population = $estimate ? (int) $estimate['population'] : null; $range = $estimate && is_numeric($estimate['min_population'] ?? null) && is_numeric($estimate['max_population'] ?? null) && (int) $estimate['min_population'] !== (int) $estimate['max_population'] ? $count((int) $estimate['min_population']).'–'.$count((int) $estimate['max_population']) : null; $reach = $population ? $share($base, $population) : null; @endphp {{-- Collapsible like the report's other sections (Konten Pesan Iklan, Jadwal Pengiriman, ...): the page's data-report-toggle script. --}}
@if ($base === 0)

Belum ada data pengiriman. Angka muncul setelah laporan DigitalCore tersedia.

@else
@foreach ($slices as $slice) {{ $slice['label'] }}: {{ $count($slice['value']) }} ({{ $percent($share($slice['value'], $base)) }}) @if ($slice['path']) @else @endif @endforeach @foreach ($slices as $slice) @if ($slice['text']) {{ $slice['text'] }} @endif @endforeach
{{-- The pie's legend and its numbers. --}}
TahapJumlah% pengiriman awal
Pengiriman awal{{ $count($base) }}100%
Terkirim{{ $count($attempted) }}{{ $percent($share($attempted, $base)) }}
Sukses{{ $count($success) }}{{ $percent($share($success, $base)) }}
Gagal{{ $count($failed) }}{{ $percent($share($failed, $base)) }}
{{ $restLabel }} {!! $hint($restHint) !!} {{ $count($rest) }}{{ $percent($share($rest, $base)) }}
Tingkat Terkirim{{ $percent($share($attempted, $base)) }}
{{ $count($attempted) }} dari {{ $count($base) }} pengiriman awal dikirim
Tingkat Sukses{{ $percent($share($success, $attempted)) }}
{{ $count($success) }} dari {{ $count($attempted) }} pesan terkirim berhasil diterima
Rasio Sukses : Klik{!! $clicks === null ? $hint($clickHint) : '' !!} {{ $clicks === null ? '–' : $count($success).' : '.$count($clicks) }}
{{ $clickNote }}
@if ($lba) {{-- Without a stored estimate the page fetches it (data-lba-estimate) and fills this tile (data-lba-reach). --}}
Jangkauan Area{!! $hint('Pengiriman awal dibanding estimasi penerima potensial di area lokasi iklan.') !!} {{ $population ? $percent($reach) : (($estimatePending ?? false) ? '…' : '–') }}
{{ $population ? $count($base).' dari ±'.$count($population).' orang di area'.($range ? ' ('.$range.')' : '') : (($estimatePending ?? false) ? 'Menghitung estimasi penerima potensial…' : 'Estimasi penerima potensial belum tersedia.') }}
@endif
@endif