@extends('layouts.admin')
@section('styles')
    <link rel="stylesheet" type="text/css" href="{{ asset('assets/admin/css/vendors/datatables.css') }}">
@endsection
@section('app')
    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-12">
                @if (in_array(auth()->user()->role_id, [1, 3, 4]))
                    <div class="list-product-header">
                        <div>
                            <a class="btn btn-primary" href="{{ route('finance.payroll.create') }}">Tambah</a>
                        </div>
                    </div>
                @endif
                <div class="card">
                    <div class="card-body">
                        <div class="table-responsive">
                            <table class="display" id="datatable">
                                <thead>
                                    <tr>
                                        <th>No</th>
                                        <th>Pegawai</th>
                                        <th>Jumlah</th>
                                        <th>Insentif</th>
                                        <th>Potongan</th>
                                        <th>Hasil Mencukur</th>
                                        <th>Persentase Mencukur</th>
                                        <th>Total</th>
                                        <th>Keterangan</th>
                                        <th>Tanggal</th>
                                        @if (in_array(auth()->user()->role_id, [1, 3, 4]))
                                            <th>Aksi</th>
                                        @endif
                                    </tr>
                                </thead>
                                <tbody>
                                    @foreach ($payrolls as $payroll)
                                        <tr>
                                            <td>{{ $loop->iteration }}</td>
                                            <td>{{ $payroll->employee->biography->full_name }}</td>
                                            <td>{{ formatToRupiah($payroll->amount) }}</td>
                                            <td>{{ formatToRupiah($payroll->incetive) }}</td>
                                            <td>{{ formatToRupiah($payroll->cut) }}</td>
                                            <td>{{ formatToRupiah($payroll->shaving_result) }}</td>
                                            <td>{{ $payroll->percentage_shaving }} %</td>
                                            <td>{{ formatToRupiah($payroll->total) }}</td>
                                            <td>{{ $payroll->description }}</td>
                                            <td>{{ formatDateIndo($payroll->created_at) }}</td>
                                            @if (in_array(auth()->user()->role_id, [1, 3, 4]))
                                                <td>
                                                    <ul class="action">
                                                        <li class="edit">
                                                            <a href="{{ route('finance.payroll.edit', encryptId($payroll->id)) }}"
                                                                data-bs-toggle="tooltip" data-bs-placement="left"
                                                                data-bs-title="Edit">
                                                                <i data-feather="edit"></i>
                                                            </a>
                                                        </li>
                                                        @if (auth()->user()->role_id === 1)
                                                            <li class="delete">
                                                                <form
                                                                    action="{{ route('finance.payroll.delete', encryptId($payroll->id)) }}"
                                                                    method="post">
                                                                    @csrf
                                                                    @method('delete')
                                                                    <a href="javascript:void(0)" class="delete-data"
                                                                        data-bs-toggle="tooltip" data-bs-placement="left"
                                                                        data-bs-title="Hapus">
                                                                        <i data-feather="trash-2"></i>
                                                                    </a>
                                                                </form>
                                                            </li>
                                                        @endif
                                                    </ul>
                                                </td>
                                            @endif
                                        </tr>
                                    @endforeach
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection
@section('afterScripts')
    <script src="{{ asset('assets/admin/js/datatable/jquery.dataTables.min.js?ver=1.0.0') }}"></script>
    <script src="{{ asset('assets/admin/js/datatable/client-side.js?ver=1.0.0') }}"></script>
    <script src="{{ asset('assets/js/interactions/confirmation.js?ver=1.0.0') }}"></script>
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
@endsection
