{{-- resources/views/accountancy-salaries-month.blade.php --}} @extends('layouts.mainlayout') @section('content') @php // Ha a hónap le van zárva (konyvel_ado_YEAR.generalt = 1), akkor itt true $monthClosed = !empty($taxGenerated); @endphp

Salaries — {{ $year }} / {{ str_pad($month, 2, '0', STR_PAD_LEFT) }}

@if ($monthClosed) Generate payslip @else @endif {{-- Month close gomb letiltása, ha már lezárták az adott hónapot (konyvel_ado_YEAR.generalt) --}} Close
@forelse($groups as $staffId => $items) @php // $items can be array or Collection $list = is_array($items) ? collect($items) : $items; // Try to resolve name from BRUTTO row or first row having firstname/lastname $nameRow = $list->firstWhere('what', 'BRUTTO'); if (!$nameRow) { $nameRow = $list->first(function ($r) { return !empty($r->lastname) || !empty($r->firstname); }); } $staffLabel = $staffId; if ($nameRow) { try { $lnRaw = $nameRow->lastname ?? ''; $fnRaw = $nameRow->firstname ?? ''; $ln = $lnRaw !== '' ? @base64_decode(\App\Http\Controllers\LogController::kodold_ki($lnRaw)) : ''; $fn = $fnRaw !== '' ? @base64_decode(\App\Http\Controllers\LogController::kodold_ki($fnRaw)) : ''; $lbl = trim(($ln ?: '') . ' ' . ($fn ?: '')); if ($lbl !== '') { $staffLabel = $lbl; } } catch (\Throwable $e) { } } // ====== HEADER SZÁMÍTÁS JAVÍTÁS ====== // Total income = minden income sor (BRUTTO + diurna + bármi) $incomeTotalAll = (int) $list->sum('income'); // Diurna income: a "what" nálad sokszor string ("Day Diurna ... 101"), ezért nem whereIn(101,102) $diurnaIncome = (int) $list ->filter(function ($r) { $w = (string) ($r->what ?? ''); return substr($w, -4) === ' 101' || substr($w, -4) === ' 102' || $w === '101' || $w === '102'; }) ->sum('income'); // A fejlécben kért "Income" = BRUTTO rész: // BRUTTO = TotalIncomeAll - (day+night diurna) $incomeHeader = $incomeTotalAll - $diurnaIncome; // Összes levonás (bármilyen státusz) $dedTotal = (int) $list->sum('deduction'); // Már levont (status = 6) $dedChecked = (int) $list->where('status', 6)->sum('deduction'); // Még le nem vont rész $dedOpen = $dedTotal - $dedChecked; // Payable = TOTAL (BRUTTO+diurna) - deducted $payable = $incomeHeader - $dedChecked; // piros header logika: ha payable negatív stb. $negByDiurna = $incomeHeader < 0; $negByDeduct = $incomeTotalAll - $dedChecked < 0; $makeHeaderRed = $negByDiurna || $negByDeduct; $dayCnt = (int) ($diurnaCounts[$staffId]['day'] ?? 0); $nightCnt = (int) ($diurnaCounts[$staffId]['night'] ?? 0); @endphp
{{ $staffLabel }}
Income: {{-- FONTOS: data-income a header income (BRUTTO), mert a checkbox logika ezt használja --}} {{ number_format($incomeHeader, 0, ',', ' ') }} Deduction (deducted): {{ number_format($dedChecked, 0, ',', ' ') }} @if ($dedOpen > 0) Not deducted: {{ number_format($dedOpen, 0, ',', ' ') }} @endif Payable: {{ number_format($payable, 0, ',', ' ') }}
@php $labels = [ 1 => 'Advance', 21 => 'Airplane Ticket', 22 => 'Checked-in bag + 32kg', 23 => 'Malker', 24 => 'Euro Fratello', 25 => 'Comati PSG', 26 => 'Flix Bus', 27 => 'Date Change', 28 => 'Name Change', 29 => 'Lost Airplane Ticket', 101 => 'Day Diurna', 102 => 'Night Diurna', 8 => 'Manual Adjustment', ]; @endphp @foreach ($list as $row) @php $isChecked = (int) $row->status === 6; // NORMALIZÁLÁS csak kijelzéshez: ha "Day Diurna ... 101", akkor label legyen Diurna, ne "Other:" $wRaw = (string) ($row->what ?? ''); $wKey = $row->what; if (substr($wRaw, -4) === ' 101') { $wKey = 101; } if (substr($wRaw, -4) === ' 102') { $wKey = 102; } if ($wRaw === '101') { $wKey = 101; } if ($wRaw === '102') { $wKey = 102; } $label = $labels[$wKey] ?? 'Other:'; if ((int) $wKey === 101) { $label .= ' (' . $dayCnt . ' days)'; } if ((int) $wKey === 102) { $label .= ' (' . $nightCnt . ' nights)'; } $noteText = $row->note ?? ''; @endphp @endforeach
# What Note Income Deduction Status
@if ((int) $row->income === 0) @endif {{ $row->id }} {{ $label }} {{ $wRaw }} {{ $noteText }} {{ number_format((int) $row->income, 0, ',', ' ') }} {{ number_format((int) $row->deduction, 0, ',', ' ') }} @if ((int) $row->status === 6) deducted @elseif((int) $row->status === 4) transferred @elseif((int) $row->status === 99) diurna @else open @endif
{{-- Manual credit/deduction (minimal UI) --}}
Positive = credit • Negative = deduction
@empty
No data for this month.
@endforelse
@endsection