@extends('admin.layout.app') @section('body') @php // ---- Relations fallback ---- $expenses = $laborer->laborExpenses ?? ($laborer->expenses ?? collect()); $payments = $laborer->payments ?? collect(); $timesheets = $laborer->timesheets ?? collect(); // ---- Manual expenses total ---- $manualExpensesTotal = (float) $expenses->sum('amount'); // ---- Timesheets totals (regular + overtime) ---- $timesheetsRegularTotal = 0.0; $timesheetsOvertimeTotal = 0.0; $sumHours = 0.0; $sumOtHours = 0.0; foreach ($timesheets as $t) { $hw = (float) ($t->hours_worked ?? 0); $hr = (float) ($t->hourly_rate ?? ($laborer->hourly_wage ?? 0)); $regTotal = isset($t->total_regular) ? (float) $t->total_regular : $hw * $hr; $otH = (float) ($t->overtime_hours ?? 0); $fallbackHourly = $hr ?: ((float) ($laborer->hourly_wage ?? 0)); $computedOtRate = $fallbackHourly > 0 ? $fallbackHourly * 1.5 : 0; $otR = (float) ($t->overtime_rate ?? ($laborer->overtime_rate ?? $computedOtRate)); $otTotal = isset($t->overtime_total) ? (float) $t->overtime_total : $otH * $otR; $sumHours += $hw; $sumOtHours += $otH; $timesheetsRegularTotal += $regTotal; $timesheetsOvertimeTotal += $otTotal; } $timesheetsTotal = $timesheetsRegularTotal + $timesheetsOvertimeTotal; // ---- Payments total ---- $totalPayments = (float) $payments->sum('amount'); // ---- Grand (Net Work Cost before payments): timesheets - manual expenses ---- $grandExpenses = $timesheetsTotal - $manualExpensesTotal; // ---- Balance (positive => payable to laborer; negative => overpaid) ---- $balance = $grandExpenses - $totalPayments; @endphp
{{-- Alerts --}} @if (session('success'))
{{ session('success') }}
@endif @if (session('error'))
{{ session('error') }}
@endif {{-- Header --}}
{{-- که لوگو له بل ډومېنه راځي، CORS ته پام وکړئ --}} Company Logo

SANAULLAH MUHAMMAD TECHNICAL SERVICES L.L.C

Laborer Statement — Time Sheets, Expenses & Payments
Laborer ID: {{ $laborer->id }}

{{-- Laborer Info + Summary --}}
{{ $laborer->name }}
CNIC/Passport: {{ $laborer->cnic_passport ?? '—' }} Phone: {{ $laborer->phone ?? '—' }}
@if (!is_null($laborer->hourly_wage)) Hourly: {{ number_format($laborer->hourly_wage, 2) }} @endif @if (!is_null($laborer->overtime_rate))  •  OT Rate: {{ number_format($laborer->overtime_rate, 2) }} @endif
Created: {{ optional($laborer->created_at)->toDayDateTimeString() ?? '—' }}
Manual Expenses{{ number_format($manualExpensesTotal, 2) }}
Timesheets (Regular){{ number_format($timesheetsRegularTotal, 2) }}
Timesheets (Overtime){{ number_format($timesheetsOvertimeTotal, 2) }}

Net Work Cost{{ number_format($grandExpenses, 2) }}
Payments{{ number_format($totalPayments, 2) }}
Balance {{ number_format($balance, 2) }}
@if ($balance > 0) Payable to Laborer @elseif($balance < 0) Advance / Overpaid @else Settled (0.00) @endif
{{-- Time Sheets --}}
Time Sheets
@if (!$timesheets->isEmpty()) Total Hours: {{ number_format($sumHours, 2) }} • OT Hours: {{ number_format($sumOtHours, 2) }} • Amount: {{ number_format($timesheetsTotal, 2) }} @endif
@if ($timesheets->isEmpty())

No timesheets.

@else
@foreach ($timesheets as $t) @php $date = optional($t->work_date ?? ($t->date ?? null))->format('Y-m-d') ?? (optional($t->created_at)->format('Y-m-d') ?? '—'); $hw = (float) ($t->hours_worked ?? 0); $hr = (float) ($t->hourly_rate ?? ($laborer->hourly_wage ?? 0)); $regTotal = isset($t->total_regular) ? (float) $t->total_regular : $hw * $hr; $otH = (float) ($t->overtime_hours ?? 0); $computedOtRate = $hr > 0 ? $hr * 1.5 : 0; $otR = (float) ($t->overtime_rate ?? ($laborer->overtime_rate ?? $computedOtRate)); $otTotal = isset($t->overtime_total) ? (float) $t->overtime_total : $otH * $otR; $rowTotal = $regTotal + $otTotal; @endphp @endforeach
Date Hours Hourly Rate Regular Total OT Hours OT Rate OT Total Row Total
{{ $date }} {{ number_format($hw, 2) }} {{ number_format($hr, 2) }} {{ number_format($regTotal, 2) }} {{ number_format($otH, 2) }} {{ number_format($otR, 2) }} {{ number_format($otTotal, 2) }} {{ number_format($rowTotal, 2) }}
Totals: {{ number_format($sumHours, 2) }} {{ number_format($timesheetsRegularTotal, 2) }} {{ number_format($sumOtHours, 2) }} {{ number_format($timesheetsOvertimeTotal, 2) }} {{ number_format($timesheetsTotal, 2) }}
@endif {{-- Manual Expenses --}}
Manual Expenses
@if ($expenses->isEmpty())

No manual expenses.

@else
@foreach ($expenses as $e) @endforeach
Date Description Amount
{{ optional($e->spent_at ?? ($e->date ?? null))->format('Y-m-d') ?? '—' }} {{ $e->description ?? '—' }} {{ number_format($e->amount ?? 0, 2) }}
Manual Expenses Total {{ number_format($manualExpensesTotal, 2) }}
@endif {{-- Payments --}}
Payments
@if ($payments->isEmpty())

No payments.

@else
@foreach ($payments as $p) @endforeach
Paid At Method Amount Note/Ref
{{ optional($p->paid_at)->format('Y-m-d') ?? '—' }} {{ $p->method ?? '—' }} {{ number_format($p->amount ?? 0, 2) }} {{ $p->notes ?? ($p->reference ?? '—') }}
Payments Total {{ number_format($totalPayments, 2) }}
@endif {{-- Totals strip --}}
Work Amount: {{ number_format($timesheetsTotal, 2) }}
Manual Expenses: {{ number_format($manualExpensesTotal, 2) }}
Net Work Cost: {{ number_format($grandExpenses, 2) }}
Payments: {{ number_format($totalPayments, 2) }}
Balance: {{ number_format($balance, 2) }}
{{-- Signatures --}}
Finance Signature
Laborer Signature
{{-- Footer --}}

Thank you for your work.

{{ date('Y') }} SANAULLAH MUHAMMAD TECHNICAL SERVICES L.L.C

{{-- Print & Actions --}}
{{-- scripts --}} {{-- html2pdf.js (frontend-only PDF) --}} {{-- styles --}} @endsection