# PayRollController
app / Http / Controllers / PayRollController.php
# payRoll
public function payRoll(){
if (!Auth::user()->can('View Payroll')){
return abort('404');
}
return view('Payroll.index');
}
1
2
3
4
5
6
2
3
4
5
6
# payRollTable
public function payRollTable(Request $request){
if (!Auth::user()->can('View Payroll')){
return abort('404');
}
$employee_name = $request->employee_name;
$month = $request->month;
$year = $request->year;
$startOfMonth = $year.'-'.$month.'-'.'01'; //2022-05-01
$endOfMonth = Carbon::parse($startOfMonth)->endOfMonth()->format('Y-m-d');
$daysInMonth = Carbon::parse($startOfMonth)->daysInMonth; //daysInMonth from Carbon
$workingDays = Carbon::parse($startOfMonth)
->diffInDaysFiltered(function (Carbon $date){
return $date->isWeekday();
},Carbon::parse($endOfMonth))->addDays(1); // parse for string
$offDays = $daysInMonth - $workingDays;
$attendances = CheckInCheckOut::whereMonth('Indate', $month)
->whereYear('Indate', $year)
->get();
$companySetting = CompanySetting::findOrfail(1);
$employees = User::orderBy('name')
->with('salariesInfo')
->where('name', 'like', "%$employee_name%")
->get();
$periods = new CarbonPeriod($startOfMonth, $endOfMonth);
return view('Payroll.payrollTable', [
'employees' => $employees,
'attendances' => $attendances,
'companySetting' => $companySetting,
'periods' => $periods,
'daysInMonth' => $daysInMonth,
'workingDays' => $workingDays,
'offDays' => $offDays,
'month' => $month,
'year' => $year
])->render(); // render for ajax
}
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
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
# Code Overview
<?php
namespace App\Http\Controllers;
use App\Models\CheckInCheckOut;
use App\Models\CompanySetting;
use App\Models\User;
use Carbon\Carbon;
use Carbon\CarbonPeriod;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class PayrollController extends Controller
{
public function payRoll(){
if (!Auth::user()->can('View Payroll')){
return abort('404');
}
return view('Payroll.index');
}
public function payRollTable(Request $request){
if (!Auth::user()->can('View Payroll')){
return abort('404');
}
$employee_name = $request->employee_name;
$month = $request->month;
$year = $request->year;
$startOfMonth = $year.'-'.$month.'-'.'01'; //2022-05-01
$endOfMonth = Carbon::parse($startOfMonth)->endOfMonth()->format('Y-m-d');
$daysInMonth = Carbon::parse($startOfMonth)->daysInMonth; //daysInMonth from Carbon
$workingDays = Carbon::parse($startOfMonth)
->diffInDaysFiltered(function (Carbon $date){
return $date->isWeekday();
},Carbon::parse($endOfMonth))->addDays(1); // parse for string
$offDays = $daysInMonth - $workingDays;
$attendances = CheckInCheckOut::whereMonth('Indate', $month)
->whereYear('Indate', $year)
->get();
$companySetting = CompanySetting::findOrfail(1);
$employees = User::orderBy('name')
->with('salariesInfo')
->where('name', 'like', "%$employee_name%")
->get();
$periods = new CarbonPeriod($startOfMonth, $endOfMonth);
return view('Payroll.payrollTable', [
'employees' => $employees,
'attendances' => $attendances,
'companySetting' => $companySetting,
'periods' => $periods,
'daysInMonth' => $daysInMonth,
'workingDays' => $workingDays,
'offDays' => $offDays,
'month' => $month,
'year' => $year
])->render(); // render for ajax
}
}
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
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