{{-- Staff performance report (weekly / monthly / custom) in the house PDF style: the officer's narrative, the figures behind it, the work by location and the approval history. Every figure is the snapshot saved on the report. --}} @extends('layouts.PdfReportLayout') @php $s = $report->stats ?? []; $n = fn ($v) => number_format((float) ($v ?? 0)); $money = fn ($v) => 'TZS '.number_format((float) ($v ?? 0), fmod((float) ($v ?? 0), 1.0) == 0.0 ? 0 : 2); $paragraphs = fn ($text) => array_filter(preg_split('/\n\s*\n/', (string) $text)); $place = fn ($v) => $v ?? 'Not recorded'; // Group the location rows region -> district, with subtotals. $groups = []; foreach ($report->locations ?? [] as $row) { $groups[$row['region'] ?? ''][$row['district'] ?? ''][] = $row; } $sum = fn (array $rows, string $key) => array_sum(array_column($rows, $key)); $all = $report->locations ?? []; @endphp @section('doc_title', $docTitle) @section('doc_subtitle', $docSubtitle) @section('meta') Officer {{ $report->officer_name }} Reference {{ $report->reference ?: 'Not yet saved' }} Reporting Period {{ $report->period_label }} Status {{ $statusLabel }} Submitted {{ $report->submitted_at?->format('d M Y, H:i') ?? '-' }} Reviewed By {{ $report->reviewed_by_name ? $report->reviewed_by_name.' ('.$report->reviewed_at?->format('d M Y').')' : '-' }} @if($report->ess_reference) ESS Reference {{ $report->ess_reference }} Sent to ESS {{ $report->ess_submitted_at?->format('d M Y, H:i') }} @endif Generated {{ $generatedAt }} Figures as at {{ $report->generated_at?->format('d M Y, H:i') ?? '-' }} @endsection @section('content')
Performance Summary
@foreach($paragraphs($report->narrative) as $p)

{{ $p }}

@endforeach @if($report->other_duties)
Other Duties Performed
@foreach($paragraphs($report->other_duties) as $p)

{{ $p }}

@endforeach @endif
Challenges and Outstanding Activities
@foreach($paragraphs($report->outstanding) as $p)

{{ $p }}

@endforeach @if($report->challenges) @foreach($paragraphs($report->challenges) as $p)

{{ $p }}

@endforeach @endif @if($report->next_steps)
{{ $report->period_type === 'month' ? 'Plan for the Following Month' : 'Next Steps' }}
@foreach($paragraphs($report->next_steps) as $p)

{{ $p }}

@endforeach @endif
Key Figures
Jobs conducted{{ $n($s['jobs_conducted'] ?? 0) }} Instruments inspected{{ $n($s['instruments_inspected'] ?? 0) }}
Jobs completed{{ $n($s['jobs_completed'] ?? 0) }} Verified / rejected / condemned {{ $n($s['instruments_verified'] ?? 0) }} / {{ $n($s['instruments_rejected'] ?? 0) }} / {{ $n($s['instruments_condemned'] ?? 0) }}
Jobs pending (overdue){{ $n($s['jobs_pending'] ?? 0) }} ({{ $n($s['jobs_overdue'] ?? 0) }}) Certificates issued{{ $n($s['certificates_issued'] ?? 0) }}
Customers served (new / repeat) {{ $n($s['customers_served'] ?? 0) }} ({{ $n($s['new_customers'] ?? 0) }} / {{ $n($s['repeat_customers'] ?? 0) }}) Premises served{{ $n($s['premises_served'] ?? 0) }}
Bills generated / paid / cancelled {{ $n($s['bills_generated'] ?? 0) }} / {{ $n($s['bills_paid'] ?? 0) }} / {{ $n($s['bills_cancelled'] ?? 0) }} Amount billed{{ $money($s['amount_billed'] ?? 0) }}
Amount paid{{ $money($s['amount_paid'] ?? 0) }} Outstanding balance{{ $money($s['amount_outstanding'] ?? 0) }}
@if(! empty($s['activity_details']))
Work by Activity
@foreach($s['activity_details'] as $a) @endforeach
Activity Instruments Jobs Verified Adjusted Rejected Completed Pending
{{ $a['label'] }} {{ collect($a['instruments'])->map(fn ($i) => $i['count'].' '.$i['label'])->implode(', ') }} {{ $n($a['jobs']) }} {{ $n($a['verified']) }} {{ $n($a['adjusted']) }} {{ $n($a['rejected']) }} {{ $n($a['completed']) }} {{ $n($a['incomplete']) }}
@endif
Work by Location
@if(empty($all))

No located work was recorded in this period.

@else @foreach($groups as $region => $districts) @php $regionRows = array_merge(...array_values($districts)); @endphp @foreach($districts as $district => $rows) @foreach($rows as $row) @endforeach @if($district !== '' && count($rows) > 1) @endif @endforeach @if($region !== '' && count($groups) > 1) @endif @endforeach
Region District Ward Jobs Instruments Completed Pending
{{ $place($row['region']) }} {{ $place($row['district']) }} {{ $place($row['ward']) }} {{ $n($row['jobs_started']) }} {{ $n($row['instruments_inspected']) }} {{ $n($row['jobs_completed']) }} {{ $n($row['jobs_pending']) }}
{{ $district }} District total {{ $n($sum($rows, 'jobs_started')) }} {{ $n($sum($rows, 'instruments_inspected')) }} {{ $n($sum($rows, 'jobs_completed')) }} {{ $n($sum($rows, 'jobs_pending')) }}
{{ $region }} Region total {{ $n($sum($regionRows, 'jobs_started')) }} {{ $n($sum($regionRows, 'instruments_inspected')) }} {{ $n($sum($regionRows, 'jobs_completed')) }} {{ $n($sum($regionRows, 'jobs_pending')) }}
Grand total {{ $n($sum($all, 'jobs_started')) }} {{ $n($sum($all, 'instruments_inspected')) }} {{ $n($sum($all, 'jobs_completed')) }} {{ $n($sum($all, 'jobs_pending')) }}

Location is the region, district and ward of the customer premises the job was for, as registered in WMA-MIS. "Not recorded" means the customer has no address on record.

@endif @if($report->events->isNotEmpty())
Approval History
@foreach($report->events as $event) @endforeach
DateActionByNote
{{ $event->created_at?->format('d M Y, H:i') }} {{ ucfirst(str_replace('_', ' ', $event->action)) }} {{ $event->actor_name }} {{ $event->note }}
@endif
Officer: {{ $report->officer_name }}
Supervisor: {{ $report->reviewed_by_name ?: '' }}
@endsection