# PayRoll

resources / views / PayRoll /

# Index.Blade

resources / views / PayRoll / index.blade.php

@extends('layouts.master')
@section('page-title') Payroll @endsection
@section('content')
    <div class="mb-2">
        <nav aria-label="breadcrumb" class="bg-white p-2 shadow-sm rounded">
            <ol class="breadcrumb mb-0">
                <li class="breadcrumb-item active" aria-current="page">Payroll lists</li>
            </ol>
        </nav>
    </div>
    <div class="card border-0 shadow-sm rounded">
        <div class="card-body">
            <div class="row mb-3">
                <div class="col-12 col-md-4 col-lg-3">
                    <div class="">
                        <label for="name" class="text-black-50">Enter Employee Name</label>
                        <input type="text" id="name" class="form-control employee_name">
                    </div>
                </div>
                <div class="col-12 col-md-4 col-lg-3">
                    <div class="">
                        @php
                            $monthArr = ["January", "February", "March",
                                          "April", "May", "June",
                                          "July", "August", "September",
                                          "October", "November", "December"];
                        @endphp
                        <label for="month" class="text-black-50">Choose Month</label>
                        <select name="month" id="month" class="form-select select-2 select-month">
                            @foreach($monthArr as $key=>$month)
                                @php
                                    if ($key<9){
                                            $number = "0".$key+1;
                                        }else{
                                            $number = $key+1;
                                        }
                                @endphp
                                <option value="{{ $number }}" @if(now()->format('m') == $number) selected @endif>{{ $month }}</option>
                            @endforeach
                        </select>
                    </div>
                </div>
                <div class="col-12 col-md-4 col-lg-3">
                    <div class="">
                        <label for="year" class="text-black-50">Choose Year</label>
                        <select name="year" id="year" class="form-select select-2 select-year">
                            @for($i = 0; $i<5; $i++)
                                <option value="{{ now()->subYear($i)->format('Y') }}" @if(now()->format('Y') == now()->subYear($i)->format('Y') ) selected @endif>
                                    {{ now()->subYear($i)->format('Y') }}
                                </option>
                            @endfor
                        </select>
                    </div>
                </div>
                <div class="col-12 col-md-4 col-lg-3 align-items-end d-flex">
                    <button class="btn btn-primary w-100 filter-btn mt-3 mt-md-0">
                        Filter Payroll Datas
                    </button>
                </div>
            </div>
            <div class="payRollTableRender">
                {{--        Data Table Render Area        --}}
            </div>
        </div>
    </div>
@endsection
@section('js')
<script>

    $(document).ready(function (){
        $( '.select-2' ).select2( {
            theme: "bootstrap-5",
            width: $( this ).data( 'width' ) ? $( this ).data( 'width' ) : $( this ).hasClass( 'w-100' ) ? '100%' : 'style',
        } );
    });

    function payRollTableRender(){
        let employee_name = $('.employee_name').val();
        let month = $('.select-month').val();
        let year = $('.select-year').val();

        $.ajax({
            url: `/payroll/datas/payrolltable?employee_name=${employee_name}&month=${month}&year=${year}`,
            type: 'GET',
        }).done(function (res){
            $('.payRollTableRender').html(res);
        });
    }
    payRollTableRender();

    $('.filter-btn').click(function (){
        payRollTableRender();
    });

</script>
@endsection
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96

# PayRollTable.Blade

resources / views / PayRoll / payRollTable.blade.php

<div class="table-responsive">
    <table class="table table-hover table-bordered mb-0">
        <thead class="">
        <tr class="bg-primary text-white">
            <th class="text-nowrap">Employee Name</th>
            <th class="text-center">Employee ID</th>
            <th class="text-center">Role</th>
            <th class="text-center">Days Of Month</th>
            <th class="text-center">Working Day</th>
            <th class="text-center">Off Day</th>
            <th class="text-center">Attendance Day</th>
            <th class="text-center">Absence Day</th>
            <th class="text-center">Per Day (MMK)</th>
            <th class="text-center">Total (MMK)</th>
        </tr>
        </thead>
        <tbody>
        @foreach($employees as $employee)
            @php
                $attendanceDay = 0;
                $salary = collect($employee->salariesInfo)
                            ->where('month', $month)
                            ->where('year', $year)
                            ->first();
                $perDay = $salary ? $salary->amount / $workingDays : 0;
            @endphp
            @foreach($periods as $period)
                @php

                if ($period->isWeekday()){ // remove Sat and Sun

                    // sart-> 09, end->06, bs->12, be->1
                        $office_start_time = $period->format('Y-m-d').' '.$companySetting->office_start_time;
                        $office_end_time   = $period->format('Y-m-d').' '.$companySetting->office_end_time;
                        $break_start_time  = $period->format('Y-m-d').' '.$companySetting->break_start_time;
                        $break_end_time    = $period->format('Y-m-d').' '.$companySetting->break_end_time;

                        $attendance = collect($attendances)
                                        ->where('user_id', $employee->id)
                                        ->where('Indate', $period->format('Y-m-d'))
                                        ->first();
                        if ($attendance){
                            // Morning
                            if (!is_null($attendance->checkIn_time)){
                                if ($attendance->checkIn_time <= $office_start_time){
                                    $attendanceDay += 0.5;
                                }elseif ($attendance->checkIn_time > $office_start_time && $attendance->checkIn_time < $break_start_time){
                                    $attendanceDay += 0.5;
                                }else{
                                    $attendanceDay += 0;
                                }
                            }else{
                                    $attendanceDay += 0;
                            }

                            // Evening
                            if (!is_null($attendance->checkOut_time)){
                                if ($attendance->checkOut_time <= $break_end_time){
                                    $attendanceDay += 0;
                                }elseif ($attendance->checkOut_time > $break_end_time && $attendance->checkOut_time < $office_end_time){
                                    $attendanceDay += 0.5;
                                }else{
                                    $attendanceDay += 0.5;
                                }
                            }else{
                                    $attendanceDay += 0;
                            }
                        }
                }
                @endphp
            @endforeach
            @php
                $absenceDays = $workingDays - $attendanceDay;
                $total = $attendanceDay * $perDay;
            @endphp
            <tr>
                <td>{{ $employee->name }}</td>
                <td>{{ $employee->employee_id }}</td>
                <td class="text-center">{{ implode(',',$employee->roles->pluck('name')->toArray()) }}</td>
                <td class="text-center">{{ $daysInMonth }}</td>
                <td class="text-center">{{ $workingDays }}</td>
                <td class="text-center">{{ $offDays }}</td>
                <td class="text-center">{{ $attendanceDay }}</td>
                <td class="text-center">{{ $absenceDays }}</td>
                <td class="text-center">{{ number_format($perDay) }}</td>
                <td class="text-center">{{ number_format($total) }}</td>
            </tr>
        @endforeach
        </tbody>
    </table>
</div>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
Last Updated: 6/1/2022, 10:25:03 PM