Completed
Push — master ( ffc0ef...053644 )
by Nasrul Hazim
01:54
created

PayslipController::edit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers\OpenPayroll;
4
5
use App\Http\Controllers\Controller;
0 ignored issues
show
Bug introduced by
The type App\Http\Controllers\Controller was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Illuminate\Http\Request;
7
8
class PayslipController extends Controller
9
{
10
    public function __construct()
11
    {
12
        $this->middleware('auth');
13
    }
14
15
    /**
16
     * Display a listing of the resource.
17
     *
18
     * @return \Illuminate\Http\Response
19
     */
20
    public function index()
21
    {
22
    }
23
24
    /**
25
     * Show the form for creating a new resource.
26
     *
27
     * @return \Illuminate\Http\Response
28
     */
29
    public function create()
30
    {
31
        $employees = \App\Models\OpenPayroll\Employee::has('salary')->has('position')->with('salary', 'position')->get();
32
        $payrolls  = \App\Models\OpenPayroll\Payroll::whereIsLocked(false)->latest()->get();
33
34
        return view('payslip.create', compact('employees', 'payrolls'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('payslip.cre...mployees', 'payrolls')) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
35
    }
36
37
    /**
38
     * Store a newly created resource in storage.
39
     *
40
     * @param \Illuminate\Http\Request $request
41
     *
42
     * @return \Illuminate\Http\Response
43
     */
44
    public function store(Request $request)
45
    {
46
        $this->validate($request, [
47
            'payroll'   => 'required',
48
            'user_id'   => 'required',
49
            'employees' => 'required',
50
        ]);
51
52
        $payroll = \App\Models\OpenPayroll\Payroll::findByHashslugOrId($request->payroll);
53
54
        $employees = $request->employees;
55
        foreach ($employees as $hashslug) {
56
            $employee = \App\Models\OpenPayroll\Employee::hashslug($hashslug)->has('salary')->with('salary')->firstOrFail();
57
            $employee->payslips()->updateOrCreate([
58
                'payroll_id'   => $payroll->id,
0 ignored issues
show
Bug introduced by
The property id does not seem to exist on Illuminate\Database\Eloquent\Builder.
Loading history...
59
                'basic_salary' => $employee->salary->amount,
60
                'gross_salary' => $employee->salary->amount,
61
                'net_salary'   => $employee->salary->amount,
62
                'is_verified'  => false,
63
                'is_approved'  => false,
64
                'is_locked'    => false,
65
            ]);
66
        }
67
68
        swal()->success('Payslip', 'You have successfully created payslip(s).');
0 ignored issues
show
Bug introduced by
The function swal was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

68
        /** @scrutinizer ignore-call */ 
69
        swal()->success('Payslip', 'You have successfully created payslip(s).');
Loading history...
69
70
        return redirect()->route('payroll.show', $request->payroll);
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->route...ow', $request->payroll) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
71
    }
72
73
    /**
74
     * Display the specified resource.
75
     *
76
     * @param int $id
77
     *
78
     * @return \Illuminate\Http\Response
79
     */
80
    public function show($id)
81
    {
82
        $payslip = \App\Models\OpenPayroll\Payslip::whereHashslug($id)->with('payroll', 'earnings', 'earnings.type', 'deductions', 'deductions.type')->firstOrFail();
83
84
        return view('payslip.show', compact('payslip'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('payslip.show', compact('payslip')) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
85
    }
86
87
    /**
88
     * Show the form for editing the specified resource.
89
     *
90
     * @param int $id
91
     *
92
     * @return \Illuminate\Http\Response
93
     */
94
    public function edit($id)
95
    {
96
    }
97
98
    /**
99
     * Update the specified resource in storage.
100
     *
101
     * @param \Illuminate\Http\Request $request
102
     * @param int                      $id
103
     *
104
     * @return \Illuminate\Http\Response
105
     */
106
    public function update(Request $request, $id)
107
    {
108
    }
109
110
    /**
111
     * Remove the specified resource from storage.
112
     *
113
     * @param int $id
114
     *
115
     * @return \Illuminate\Http\Response
116
     */
117
    public function destroy($id)
118
    {
119
    }
120
}
121