{{-- resources/views/payroll/show.blade.php --}} @extends('layouts.app') @section('content') @php // تعريف المتغيرات العامة لاستخدامها في جميع الأقسام $components = $payroll->payrollSalaryComponents ?? collect(); $additionsTotal = 0; $deductionsTotal = 0; foreach($components as $comp) { if ($comp->value > 0) { $additionsTotal += $comp->value; } else { $deductionsTotal += abs($comp->value); } } @endphp

تفاصيل الراتب الشامل

📊 تفاصيل الراتب الشامل
✅ الإضافات (الراتب الإجمالي)
@php $components = $payroll->payrollSalaryComponents ?? collect(); $additionsTotal = 0; $deductionsTotal = 0; @endphp @foreach($components as $comp) @if($comp->value > 0) @php $label = $comp->name; if ($label === 'Overtime') { $label = 'أوفر تايم'; } elseif ($label === 'Paid Off-day Compensation') { $label = 'تعويض أيام الحضور المدفوعة'; } elseif (\Illuminate\Support\Str::contains($label ?? '', 'Underworked')) { $label = 'خصم نقصان ساعات'; } @endphp @php $additionsTotal += $comp->value; @endphp @endif @endforeach
الراتب الأساسي {{ number_format($payroll->basic_salary, 2) }} {{ $currency_name }}
الحوافز {{ number_format($payroll->incentives, 2) }} {{ $currency_name }}
{{ $label }} + {{ number_format($comp->value, 2) }} {{ $currency_name }}
إجمالي الإضافات {{ number_format($payroll->basic_salary + $payroll->incentives + $additionsTotal, 2) }} {{ $currency_name }}
❌ الخصومات
@foreach($components as $comp) @if($comp->value < 0) @php $label = $comp->name; if ($label === 'Overtime') { $label = 'أوفر تايم'; } elseif ($label === 'Paid Off-day Compensation') { $label = 'تعويض أيام الحضور المدفوعة'; } elseif (\Illuminate\Support\Str::contains($label ?? '', 'Underworked')) { $label = 'خصم نقصان ساعات'; } @endphp @php $deductionsTotal += abs($comp->value); @endphp @endif @endforeach
الخصومات النشطة - {{ number_format($payroll->active_deductions, 2) }} {{ $currency_name }}
أقساط القروض - {{ number_format($payroll->loan_installments, 2) }} {{ $currency_name }}
خصم الإجازات - {{ number_format($payroll->leave_deduction, 2) }} {{ $currency_name }}
{{ $label }} {{ number_format($comp->value, 2) }} {{ $currency_name }}
إجمالي الخصومات - {{ number_format($payroll->active_deductions + $payroll->loan_installments + $payroll->leave_deduction + $deductionsTotal, 2) }} {{ $currency_name }}
📅 أيام نقص ساعات العمل والأوفر تايم والخصم
@php $attendanceSummaryDays = $attendanceDetails ? $attendanceDetails->filter(function ($d) { return ($d['underworked_hours'] ?? 0) > 0 || ($d['overtime_hours'] ?? 0) > 0; }) : collect(); @endphp @if($attendanceSummaryDays->count() > 0)
@foreach($attendanceSummaryDays as $detail) @endforeach {{-- عرض أيام العطلات المدفوعة --}} @if(isset($paidOffAttendances) && $paidOffAttendances->count() > 0) @foreach($paidOffAttendances as $attendance) @endforeach @endif
التاريخ ساعات النقص قيمة الخصم ({{ $currency_name }}) ساعات الأوفر تايم قيمة الأوفر تايم ({{ $currency_name }}) أيام العطلات المدفوعة أجر اليوم ({{ $currency_name }})
{{ \Carbon\Carbon::parse($detail['date'])->format('Y-m-d') }} @php $uw = $detail['underworked_hours'] ?? 0; @endphp {{ $uw > 0 ? number_format($uw, 2) . ' ساعة' : '-' }} @php $uwv = $detail['underworked_value'] ?? 0; @endphp {{ $uwv > 0 ? number_format($uwv, 2) . ' ' . $currency_name : '-' }} @php $ot = $detail['overtime_hours'] ?? 0; @endphp {{ $ot > 0 ? number_format($ot, 2) . ' ساعة' : '-' }} @php $otv = $detail['overtime_value'] ?? 0; @endphp {{ $otv > 0 ? number_format($otv, 2) . ' ' . $currency_name : '-' }} - -
{{ \Carbon\Carbon::parse($attendance->date)->format('Y-m-d') }} - - - - يوم عطلة مدفوع @php // حساب أجر اليوم المدفوع $dailyRatePaidOff = 0; if (!empty($payroll->employee->default_paid_off_amount) && $payroll->employee->default_paid_off_amount > 0) { $dailyRatePaidOff = $payroll->employee->default_paid_off_amount; } elseif (!empty($dailyRate) && $dailyRate > 0) { $dailyRatePaidOff = $dailyRate; } @endphp {{ number_format($dailyRatePaidOff, 2) }} {{ $currency_name }}
@else

لا توجد أيام بها نقص في ساعات العمل أو أوفر تايم خلال هذا الشهر.

@endif
💰 تفاصيل الاستقطاعات
@if($actualDeductions && $actualDeductions->count() > 0)
@foreach($actualDeductions as $deduction) @endforeach
نوع الاستقطاع الوصف التاريخ التكرار المبلغ ({{ $currency_name }})
{{ $deduction->type_arabic ?? $deduction->type }} {{ $deduction->description ?? '-' }} {{ \Carbon\Carbon::parse($deduction->deduction_date)->format('Y-m-d') }} @if($deduction->frequency === 'monthly' || $deduction->is_monthly) شهري @elseif($deduction->frequency === 'yearly') سنوي @else مرة واحدة @endif {{ number_format($deduction->amount, 2) }}
إجمالي الاستقطاعات {{ number_format($actualDeductions->sum('amount'), 2) }} {{ $currency_name }}
@else

لا توجد استقطاعات نشطة لهذا الشهر.

@endif
@if($loanInstallments && $loanInstallments->count() > 0)
🏦 تفاصيل أقساط القروض
@foreach($loanInstallments as $installment) @endforeach
نوع القرض رقم القرض تاريخ الاستحقاق قيمة القسط ({{ $currency_name }})
{{ $installment->loan->loan_type_arabic ?? $installment->loan->loan_type }} {{ $installment->loan->id }} {{ \Carbon\Carbon::parse($installment->due_date)->format('Y-m-d') }} {{ number_format($installment->amount, 2) }}
إجمالي أقساط القروض {{ number_format($loanInstallments->sum('amount'), 2) }} {{ $currency_name }}
@endif
📝 تفاصيل مكونات الراتب
@php $components = $payroll->payrollSalaryComponents ?? collect(); @endphp @if($components->count() > 0)
@foreach($components as $comp) @endforeach
الوصفالمبلغ ({{ $currency_name }})التفاصيل
@php $label = $comp->name; if ($label === 'Overtime') { $label = 'أوفر تايم'; } elseif ($label === 'Paid Off-day Compensation') { $label = 'تعويض أيام الحضور المدفوعة'; } elseif (\Illuminate\Support\Str::contains($label ?? '', 'Underworked')) { $label = 'خصم نقصان ساعات'; } @endphp {{ $label }} {{ number_format($comp->value, 2) }} @if(!empty($comp->meta) && is_array($comp->meta)) @php $m = $comp->meta; @endphp @if(isset($m['type']) && $m['type'] === 'underworked') ساعات النقص: {{ ($m['hours'] ?? 0) }} ساعة × {{ number_format($m['hourly_rate'] ?? 0, 4) }} @elseif(isset($m['type']) && $m['type'] === 'overtime') ساعات الأوفر تايم: {{ ($m['hours'] ?? 0) }} ساعة × {{ number_format($m['hourly_rate'] ?? 0, 4) }} @elseif(isset($m['type']) && $m['type'] === 'paid_off_days') @php // محاولة ذكية لإظهار عدد الأيام الفعلي للحضور المدفوع $paidDays = null; $paidDaysMeta = $m['days'] ?? null; // 1) إذا كانت days في الميتا موجودة وموجبة استخدمها كما هي if ($paidDaysMeta !== null && (!is_numeric($paidDaysMeta) || (float)$paidDaysMeta > 0.0)) { $paidDays = $paidDaysMeta; } // 2) وإلا استخدم القيمة القادمة من الكنترولر إذا كانت أكبر من صفر elseif (!empty($paidOffDays) && $paidOffDays > 0) { $paidDays = $paidOffDays; } // 3) وإذا لم تتوفر أي من القيم السابقة، استنتج الأيام من مبلغ التعويض else { $amountSource = 0; if (!empty($paidOffAmount) && $paidOffAmount > 0) { $amountSource = $paidOffAmount; } elseif (!empty($payroll->paid_off_amount) && $payroll->paid_off_amount > 0) { $amountSource = $payroll->paid_off_amount; } elseif (!empty($comp->value) && $comp->value > 0) { // fallback أخير: استخدم قيمة المكوّن نفسها $amountSource = $comp->value; } if ($amountSource > 0 && !empty($dailyRate) && $dailyRate > 0) { $paidDays = round($amountSource / $dailyRate, 2); } else { $paidDays = 0; } } @endphp أيام الحضور المدفوعة: {{ $paidDays }} يوم @else {{ json_encode($m) }} @endif @else - @endif
@else

لا توجد مكونات مرتب مضافة لهذا الراتب.

@endif
صورة الموظف

{{ $payroll->employee->name }}

{{ $payroll->employee->position->name ?? 'غير محدد' }}

{{ $payroll->employee->department->name ?? 'غير محدد' }}

الرقم: {{ $payroll->employee->employee_id }} {{ $payroll->employee->email }} {{ $payroll->employee->phone ?? 'غير محدد' }}
⚠️ تحذير: الرصيد الحالي للإجازات قد يتأثر بالخصومات أو الإضافات السابقة.
📅 ملخص الإجازات
الرصيد قبل الخصم: {{ $payroll->leave_balance_before_deduction }} يوم
الأيام المستخدمة: {{ $cumulativeLeaveInfo['current_month_used'] ?? 0 }} يوم
الأيام الممنوحة: {{ $payroll->leave_granted_this_month }} يوم
الأيام الزائدة: {{ $cumulativeLeaveInfo['current_month_excess'] ?? 0 }} يوم
قيمة خصم الإجازات: {{ number_format($payroll->leave_deduction, 2) }} {{ $currency_name }}
الرصيد بعد الخصم: {{ $payroll->leave_balance_after }} يوم
🗓️ الإجازات المستخدمة
@if($usedLeaves && $usedLeaves->count() > 0)
@foreach($usedLeaves as $leave) @endforeach
نوع الإجازة تاريخ البداية تاريخ النهاية عدد الأيام الحالة
{{ $leave->leaveTypeModel->name ?? 'غير محدد' }} {{ \Carbon\Carbon::parse($leave->start_date)->format('Y-m-d') }} {{ \Carbon\Carbon::parse($leave->end_date)->format('Y-m-d') }} {{ $leave->number_of_days ?? 0 }} يوم @if($leave->status === 'approved') موافق عليها @elseif($leave->status === 'modified') معدلة @else {{ $leave->status }} @endif
@else

لا توجد إجازات مستخدمة خلال هذا الشهر

@endif
📊 الرواتب السابقة
@if($previousPayrolls->count() > 0)
@foreach($previousPayrolls as $prev) @php $components = $prev->relationLoaded('payrollSalaryComponents') ? $prev->payrollSalaryComponents : $prev->payrollSalaryComponents()->get(); $earningsTotal = $components->filter(fn($c) => ($c->value ?? 0) > 0)->sum('value'); $grossRaw = ($prev->basic_salary ?? 0) + ($prev->incentives ?? 0) + $earningsTotal; $overtimeTotal = $components->filter(function($c) { $meta = $c->meta ?? null; return (!empty($meta) && isset($meta['type']) && $meta['type'] === 'overtime') || (($c->name ?? '') === 'Overtime'); })->sum('value'); $attendanceAdjustment = $components->filter(function($c) { $meta = $c->meta ?? null; return (!empty($meta) && isset($meta['type']) && $meta['type'] === 'underworked') || str_contains($c->name ?? '', 'Underworked') || str_contains($c->name ?? '', 'نقصان'); })->sum('value'); $attendanceAdjustmentDisplay = $attendanceAdjustment < 0 ? -1 * $attendanceAdjustment : $attendanceAdjustment; $otherNegatives = $components->filter(function($c) { $val = $c->value ?? 0; if ($val >= 0) return false; $meta = $c->meta ?? null; if (!empty($meta) && isset($meta['type']) && $meta['type'] === 'underworked') return false; $name = $c->name ?? ''; if (str_contains($name, 'إجازة') || str_contains(strtolower($name), 'unpaid') ) return false; return true; })->sum('value'); $totalOtherDeductions = $otherNegatives < 0 ? -1 * $otherNegatives : 0; $prevLoanInstallments = $prev->loan_installments ?? 0; $leaveDeduction = $prev->leave_deduction ?? 0; $netSalary = $prev->net_salary ?? max(0, $grossRaw - ($prev->active_deductions ?? 0) - $prevLoanInstallments - $leaveDeduction - $totalOtherDeductions - $attendanceAdjustmentDisplay); @endphp @endforeach
الشهر والسنة إجمالي الراتب (الخام) حالة الدفع الإجراءات
{{ \Carbon\Carbon::create()->month($prev->month)->translatedFormat('F') }} {{ $prev->year }} {{ number_format($grossRaw, 2) }} {{ get_currency_code() }} @if($prev->paid_at) مدفوع @else قيد الدفع @endif عرض التفاصيل
@else

لا توجد رواتب سابقة

@endif
الإجراءات
@if($payroll->status == 'pending') @can('update', $payroll) تعديل
@csrf
@endcan @can('delete', $payroll)
@csrf @method('DELETE')
@endcan @endif طباعة رجوع
@push('scripts') @php $payrollTranslations = [ 'popup_blocked' => 'تم حظر نافذة الطباعة. يرجى السماح بفتح النوافذ المنبثقة.', 'print_title' => 'تفاصيل الراتب', 'income_title' => 'الإيرادات', 'deductions_title' => 'الخصومات', 'net_title' => 'الراتب الصافي', 'description_label' => 'الوصف', 'amount_label' => 'المبلغ', 'basic_salary_label' => 'الراتب الأساسي', 'incentives_label' => 'الحوافز', 'total_income_label' => 'إجمالي الإيرادات', 'total_deductions_label' => 'إجمالي الخصومات', 'net_salary_label' => 'الراتب الصافي', 'leave_deduction_label' => 'خصم الإجازات', 'days_label' => 'أيام', 'department_label' => 'القسم', 'position_label' => 'المنصب', 'month_label' => 'الشهر', ]; @endphp @endpush
💰 الراتب الصافي
@php $totalAdditions = $payroll->basic_salary + $payroll->incentives + $additionsTotal; $totalDeductions = $payroll->active_deductions + $payroll->loan_installments + $payroll->leave_deduction + $deductionsTotal; $netSalary = $totalAdditions - $totalDeductions; @endphp
إجمالي الإضافات {{ number_format($payroll->basic_salary + $payroll->incentives + $additionsTotal, 2) }} {{ $currency_name }}
إجمالي الخصومات - {{ number_format($payroll->active_deductions + $payroll->loan_installments + $payroll->leave_deduction + $deductionsTotal, 2) }} {{ $currency_name }}
الراتب الصافي المستحق{{ number_format($netSalary, 2) }} {{ $currency_name }}
@endsection