﻿@extends('layouts.app')

@section('title', 'تقرير التأمينات الاجتماعية')

@section('content')
<div class="container m-auto p-4 sm:p-6 lg:p-8 py-8">
    <div class="flex justify-between items-center mb-6">
        <h1 class="text-2l font-bold text-gray-900">{{ \App\Helpers\TranslationHelper::transFromDatabase('Social Insurance Report', 'تقرير التأمينات الاجتماعية') }}</h1>
        
        <div class="flex space-y-2 space-y-reverse">
            <button onclick="window.print()" class="bg-gray-600 hover:bg-gray-700 text-white font-bold py-2 p-4 rounded">
                <i class="fas fa-print ml-1"></i> {{ \App\Helpers\TranslationHelper::transFromDatabase('Print', 'طباعة') }}
            </button>
        </div>
    </div>

    <div class="bg-white shadow-md rounded-lg overflow-hidden mb-6">
        <div class="p-6 bg-gray-50 border-b border-gray-200">
            <form action="{{ route('payroll-reports.insurance') }}" method="GET" class="flex flex-wrap items-end space-y-4 space-y-reverse">
                <div class="mb-4">
                    <label for="year" class="block text-sm font-medium text-gray-700 mb-1">{{ \App\Helpers\TranslationHelper::transFromDatabase('Year', 'السنة') }}</label>
                    <select id="year" name="year" class="mt-1 block w-full py-2 p-3 border border-gray-300 bg-white rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm">
                        @for ($y = date('Y'); $y >= date('Y') - 5; $y--)
                            <option value="{{ $y }}" {{ $year == $y ? 'selected' : '' }}>{{ $y }}</option>
                        @endfor
                    </select>
                </div>
                
                <div class="mb-4">
                    <label for="month" class="block text-sm font-medium text-gray-700 mb-1">{{ \App\Helpers\TranslationHelper::transFromDatabase('Month', 'الشهر') }}</label>
                    <select id="month" name="month" class="mt-1 block w-full py-2 p-3 border border-gray-300 bg-white rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm">
                        @for ($m = 1; $m <= 12; $m++)
                            <option value="{{ $m }}" {{ $month == $m ? 'selected' : '' }}>{{ $m }}</option>
                        @endfor
                    </select>
                </div>
                
                <div class="mb-4">
                    <button type="submit" class="bg-indigo-600 hover:bg-indigo-700 text-white font-bold py-2 p-4 rounded">
                        <i class="fas fa-search ml-1"></i> {{ \App\Helpers\TranslationHelper::transFromDatabase('Show', 'عرض') }}
                    </button>
                </div>
            </form>
        </div>
    </div>

    <div class="bg-white shadow-md rounded-lg overflow-hidden">
        <div class="p-6 border-b border-gray-200">
            <div class="flex justify-between items-center mb-4">
                <h2 class="text-l font-semibold text-gray-800">{{ \App\Helpers\TranslationHelper::transFromDatabase('Social Insurance Report for Month', 'تقرير التأمينات الاجتماعية لشهر') }} {{ $month }}/{{ $year }}</h2>
            </div>
            
            @if(count($employeeInsurance) > 0)
            <table class="min-w-full divide-y divide-gray-200">
                <thead class="bg-gray-50">
                    <tr>
                        <th scope="col" class="p-6 py-3 text-right text-s font-medium text-gray-500 uppercase tracking-wider">
                            {{ \App\Helpers\TranslationHelper::transFromDatabase('Employee', 'الموظف') }}
                        </th>
                        <th scope="col" class="p-6 py-3 text-right text-s font-medium text-gray-500 uppercase tracking-wider">
                            {{ \App\Helpers\TranslationHelper::transFromDatabase('Job Number', 'الرقم الوظيفي') }}
                        </th>
                        <th scope="col" class="p-6 py-3 text-right text-s font-medium text-gray-500 uppercase tracking-wider">
                            {{ \App\Helpers\TranslationHelper::transFromDatabase('Basic Salary', 'الراتب الأساسي') }}
                        </th>
                        <th scope="col" class="p-6 py-3 text-right text-s font-medium text-gray-500 uppercase tracking-wider">
                            {{ \App\Helpers\TranslationHelper::transFromDatabase('Employee Contribution', 'مساهمة الموظف') }}
                        </th>
                        <th scope="col" class="p-6 py-3 text-right text-s font-medium text-gray-500 uppercase tracking-wider">
                            {{ \App\Helpers\TranslationHelper::transFromDatabase('Company Contribution', 'مساهمة الشركة') }}
                        </th>
                        <th scope="col" class="p-6 py-3 text-right text-s font-medium text-gray-500 uppercase tracking-wider">
                            {{ \App\Helpers\TranslationHelper::transFromDatabase('Total Contribution', 'إجمالي المساهمة') }}
                        </th>
                    </tr>
                </thead>
                <tbody class="bg-white divide-y divide-gray-200">
                    @foreach($employeeInsurance as $insurance)
                    <tr>
                        <td class="p-6 py-4 whitespace-nowrap text-sm text-gray-900">
                            {{ $insurance['employee']->full_name }}
                        </td>
                        <td class="p-6 py-4 whitespace-nowrap text-sm text-gray-900">
                            {{ $insurance['employee']->employee_number }}
                        </td>
                        <td class="p-6 py-4 whitespace-nowrap text-sm text-gray-900">
                            {{ number_format($insurance['basic_salary'], 2) }} {{ \App\Helpers\TranslationHelper::transFromDatabase('SAR', 'ريال') }}
                        </td>
                        <td class="p-6 py-4 whitespace-nowrap text-sm text-gray-900">
                            {{ number_format($insurance['employee_contribution'], 2) }} {{ \App\Helpers\TranslationHelper::transFromDatabase('SAR', 'ريال') }}
                        </td>
                        <td class="p-6 py-4 whitespace-nowrap text-sm text-gray-900">
                            {{ number_format($insurance['company_contribution'], 2) }} {{ \App\Helpers\TranslationHelper::transFromDatabase('SAR', 'ريال') }}
                        </td>
                        <td class="p-6 py-4 whitespace-nowrap text-sm text-gray-900">
                            {{ number_format($insurance['total_contribution'], 2) }} {{ \App\Helpers\TranslationHelper::transFromDatabase('SAR', 'ريال') }}
                        </td>
                    </tr>
                    @endforeach
                </tbody>
                <tfoot class="bg-gray-50">
                    <tr>
                        <td colspan="2" class="p-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">
                            {{ \App\Helpers\TranslationHelper::transFromDatabase('Total', 'الإجمالي') }}
                        </td>
                        <td class="p-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">
                            {{ number_format($totals['basic_salary'], 2) }} {{ \App\Helpers\TranslationHelper::transFromDatabase('SAR', 'ريال') }}
                        </td>
                        <td class="p-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">
                            {{ number_format($totals['employee_contribution'], 2) }} {{ \App\Helpers\TranslationHelper::transFromDatabase('SAR', 'ريال') }}
                        </td>
                        <td class="p-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">
                            {{ number_format($totals['company_contribution'], 2) }} {{ \App\Helpers\TranslationHelper::transFromDatabase('SAR', 'ريال') }}
                        </td>
                        <td class="p-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">
                            {{ number_format($totals['total_contribution'], 2) }} {{ \App\Helpers\TranslationHelper::transFromDatabase('SAR', 'ريال') }}
                        </td>
                    </tr>
                </tfoot>
            </table>
            @else
            <div class="text-center py-4 text-gray-500">
                {{ \App\Helpers\TranslationHelper::transFromDatabase('No social insurance data available for this month.', 'لا توجد بيانات للتأمينات الاجتماعية في هذا الشهر.') }}
            </div>
            @endif
        </div>
    </div>
</div>

@push('styles')
<style>
    @media print {
        body * {
            visibility: hidden;
        }
        .container, .container * {
            visibility: visible;
        }
        .container {
            position: absolute;
            left: 0;
            top: 0;
        }
        button, form {
            display: none !important;
        }
    }
</style>
@endpush
@endsection