@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
No timesheets.
@else| 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) }} |
No manual expenses.
@else| 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) }} | |
No payments.
@else| 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) }} | ||
Thank you for your work.
{{ date('Y') }} SANAULLAH MUHAMMAD TECHNICAL SERVICES L.L.C