Completed
Push — master ( 137869...5c988e )
by
unknown
02:44 queued 01:25
created

MasterTarifController::createChild()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php namespace Bantenprov\MasterTarif\Http\Controllers;
2
3
use App\Http\Controllers\Controller;
4
use Illuminate\Http\Request;
5
use Bantenprov\MasterTarif\Facades\MasterTarif;
6
use Bantenprov\MasterTarif\Models\MasterTarifModel;
7
use Bantenprov\DaftarRetribusi\Models\DaftarRetribusiModel;
8
use Ramsey\Uuid\Uuid;
9
10
/**
11
 * Class MasterTarifController
12
 * @package Bantenprov\MasterTarif\Http\Controllers
13
 * @author  bantenprov <[email protected]>
14
 */
15
class MasterTarifController extends Controller
16
{
17
18
    /**
19
     * @return mixed
20
     */
21
    public function index()
22
    {
23
        $master_tarifs = MasterTarifModel::all();
24
25
        return view('master-tarif::index', compact('master_tarifs'));
26
    }
27
28
    /**
29
     * @param Request $request
30
     * @return mixed
31
     */
32
    public function create(Request $request)
33
    {
34
        $daftar_retribusies = DaftarRetribusiModel::all();
35
36
        return view('master-tarif::create', compact('daftar_retribusies'));
37
    }
38
39
    /**
40
     * @param Request $request
41
     * @return mixed
42
     */
43
    public function createChild(Request $request, $parent_id)
44
    {
45
        $master_tarif_parent = MasterTarifModel::find($parent_id);
46
47
        return view('master-tarif::create-child', compact('master_tarif_parent'));
48
    }
49
50
    /**
51
     * @param Request $request
52
     */
53
    public function store(Request $request)
54
    {
55
56
        $daftar_retribusi = DaftarRetribusiModel::find($request->daftar_retribusi_id);
57
58
        $request->validate([            
59
            'nama'                  => 'required',
60
            'dasar_hukum'           => 'required',
61
            'daftar_retribusi_id'   => 'required',
62
        ]);
63
64
        if(is_null($daftar_retribusi)){
65
            return redirect()->back()->withErrors('Error : retribusi yang dipilih tidak ditemukan');
66
        }
67
68
        // if($request->status > 1 && $request->status < 0){
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
69
        //     return redirect()->back()->withErrors('Error : status salah');
0 ignored issues
show
Unused Code Comprehensibility introduced by
69% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
70
        // }
71
72
        MasterTarifModel::create([
73
            'uuid'                  => Uuid::uuid5(Uuid::NAMESPACE_DNS, 'bantenprov.go.id'.date('YmdHis')),
74
            'nama'                  => $request->nama,
75
            'dasar_hukum'           => $request->dasar_hukum,
76
            'level'                 => 1,
77
            'daftar_retribusi_id'   => $request->daftar_retribusi_id,
78
            'daftar_retribusi_uuid' => $daftar_retribusi->uuid,
79
            'user_id'               => \Auth::user()->id,
80
            'user_update'           => \Auth::user()->id,
81
        ]);
82
83
        $request->session()->flash('message', 'Successfully add new data');
84
85
        return redirect()->route('master-tarif.index');
86
87
    }
88
89
    /**
90
     * @param Request $request
91
     */
92
    public function storeChild(Request $request, $parent_id)
93
    {
94
        $master_tarif_parent = MasterTarifModel::find($parent_id);        
95
96
        $request->validate([            
97
            'nama'                  => 'required',
98
            'status'                => 'required',
99
        ]);
100
101 View Code Duplication
        if($request->status > 1 && $request->status < 0){
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
102
            return redirect()->back()->withErrors('Error : status salah');
103
        }
104
105
        MasterTarifModel::create([
106
            'uuid'                  => Uuid::uuid5(Uuid::NAMESPACE_DNS, 'bantenprov.go.id'.date('YmdHis')),
107
            'nama'                  => $request->nama,
108
            'status'                => $request->status,            
109
            'level'                 => $master_tarif_parent->level + 1,
110
            'daftar_retribusi_id'   => $master_tarif_parent->daftar_retribusi_id,
111
            'daftar_retribusi_uuid' => $master_tarif_parent->uuid,
112
            'user_id'               => \Auth::user()->id,
113
            'user_update'           => \Auth::user()->id,
114
        ]);
115
116
        $request->session()->flash('message', 'Successfully add new data');
117
118
        return redirect()->route('master-tarif.index');
119
120
    }
121
122
    /**
123
     * @param $id
124
     * @return mixed
125
     */
126
    public function edit($id)
127
    {
128
        $daftar_retribusies = DaftarRetribusiModel::all();
129
130
        $master_tarif = MasterTarifModel::find($id);
131
132
        return view('master-tarif::edit',compact('daftar_retribusies','master_tarif'));
133
    }
134
135
    /**
136
     * @param Request $request
137
     * @param $id
138
     */
139
    public function update(Request $request, $id)
140
    {
141
        $daftar_retribusi = DaftarRetribusiModel::find($request->daftar_retribusi_id);
142
143
        $request->validate([            
144
            'nama'                  => 'required',
145
            'dasar_hukum'           => 'required',
146
            'status'                => 'required',
147
            'daftar_retribusi_id'   => 'required',
148
        ]);
149
150
        if(is_null($daftar_retribusi)){
151
            return redirect()->back()->withErrors('Error : retribusi yang dipilih tidak ditemukan');
152
        }
153
154 View Code Duplication
        if($request->status > 1 && $request->status < 0){
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
155
            return redirect()->back()->withErrors('Error : status salah');
156
        }
157
158
        MasterTarifModel::find($id)->update([            
159
            'nama'                  => $request->nama,
160
            'dasar_hukum'           => $request->dasar_hukum,
161
            'status'                => $request->status,
162
            'daftar_retribusi_id'   => $request->daftar_retribusi_id,
163
            'daftar_retribusi_uuid' => $daftar_retribusi->uuid,
164
            'user_update'           => \Auth::user()->id,
165
        ]);
166
167
        $request->session()->flash('message', 'Successfully add new data');
168
169
        return redirect()->route('master-tarif.index');
170
    }
171
172
    /**
173
     * @param $id
174
     * @return mixed
175
     */
176
    public function show($id)
177
    {
178
        $master_tarif = MasterTarifModel::find($id);
179
180
        return view('master-tarif::show', compact('master_tarif'));
181
    }
182
183
    /**
184
     * @param $id
185
     */
186
    public function destroy(Request $request, $id)
187
    {
188
        MasterTarifModel::find($id)->delete();
189
190
        $request->session()->flash('message', 'Successfully delete data');
191
192
        return redirect()->route('master-tarif.index');
193
    }
194
195
}
196