|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Bantenprov\Anggaran\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
/* Require */ |
|
6
|
|
|
use App\Http\Controllers\Controller; |
|
|
|
|
|
|
7
|
|
|
use Illuminate\Http\Request; |
|
8
|
|
|
use Bantenprov\BudgetAbsorption\Facades\AnggaranFacade; |
|
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
/* Models */ |
|
11
|
|
|
use Bantenprov\Anggaran\Models\Bantenprov\Anggaran\Anggaran; |
|
12
|
|
|
use Bantenprov\GroupEgovernment\Models\Bantenprov\GroupEgovernment\GroupEgovernment; |
|
|
|
|
|
|
13
|
|
|
use Bantenprov\SectorEgovernment\Models\Bantenprov\SectorEgovernment\SectorEgovernment; |
|
|
|
|
|
|
14
|
|
|
use App\User; |
|
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
/* Etc */ |
|
17
|
|
|
use Validator; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* The AnggaranController class. |
|
21
|
|
|
* |
|
22
|
|
|
* @package Bantenprov\Anggaran |
|
23
|
|
|
* @author bantenprov <[email protected]> |
|
24
|
|
|
*/ |
|
25
|
|
|
class AnggaranController extends Controller |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* Create a new controller instance. |
|
29
|
|
|
* |
|
30
|
|
|
* @return void |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $group_egovernmentModel; |
|
33
|
|
|
protected $sector_egovernment; |
|
34
|
|
|
protected $anggaran; |
|
35
|
|
|
protected $user; |
|
36
|
|
|
|
|
37
|
|
|
public function __construct(Anggaran $anggaran, GroupEgovernment $group_egovernment,SectorEgovernment $sector_egovernment, User $user) |
|
38
|
|
|
{ |
|
39
|
|
|
$this->anggaran = $anggaran; |
|
40
|
|
|
$this->group_egovernmentModel = $group_egovernment; |
|
41
|
|
|
$this->sector_egovernment = $sector_egovernment; |
|
42
|
|
|
$this->user = $user; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Display a listing of the resource. |
|
47
|
|
|
* |
|
48
|
|
|
* @return \Illuminate\Http\Response |
|
49
|
|
|
*/ |
|
50
|
|
|
public function index(Request $request) |
|
51
|
|
|
{ |
|
52
|
|
|
if (request()->has('sort')) { |
|
53
|
|
|
list($sortCol, $sortDir) = explode('|', request()->sort); |
|
54
|
|
|
|
|
55
|
|
|
$query = $this->anggaran->orderBy($sortCol, $sortDir); |
|
56
|
|
|
} else { |
|
57
|
|
|
$query = $this->anggaran->orderBy('id', 'asc'); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
if ($request->exists('filter')) { |
|
61
|
|
|
$query->where(function($q) use($request) { |
|
62
|
|
|
$value = "%{$request->filter}%"; |
|
63
|
|
|
$q->where('label', 'like', $value) |
|
64
|
|
|
->orWhere('description', 'like', $value); |
|
65
|
|
|
}); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
$perPage = request()->has('per_page') ? (int) request()->per_page : null; |
|
69
|
|
|
$response = $query->with('group_egovernment')->with('sector_egovernment')->with('user')->paginate($perPage); |
|
70
|
|
|
|
|
71
|
|
|
/*foreach($response as $group_egovernment){ |
|
72
|
|
|
array_set($response->data, 'group_egovernment', $group_egovernment->group_egovernment->label); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
foreach($response as $sector_egovernment){ |
|
76
|
|
|
array_set($response->data, 'sector_egovernment', $sector_egovernment->sector_egovernment->label); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
foreach($response as $user){ |
|
80
|
|
|
array_set($response->data, 'user', $user->user->name); |
|
81
|
|
|
}*/ |
|
82
|
|
|
|
|
83
|
|
|
return response()->json($response) |
|
|
|
|
|
|
84
|
|
|
->header('Access-Control-Allow-Origin', '*') |
|
85
|
|
|
->header('Access-Control-Allow-Methods', 'GET'); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Show the form for creating a new resource. |
|
90
|
|
|
* |
|
91
|
|
|
* @return \Illuminate\Http\Response |
|
92
|
|
|
*/ |
|
93
|
|
|
public function create() |
|
94
|
|
|
{ |
|
95
|
|
|
$group_egovernment = $this->group_egovernmentModel->all(); |
|
96
|
|
|
$sector_egovernment = $this->sector_egovernment->all(); |
|
97
|
|
|
$users = $this->user->all(); |
|
98
|
|
|
|
|
99
|
|
|
foreach($users as $user){ |
|
100
|
|
|
array_set($user, 'label', $user->name); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
$response['group_egovernment'] = $group_egovernment; |
|
|
|
|
|
|
104
|
|
|
$response['sector_egovernment'] = $sector_egovernment; |
|
105
|
|
|
$response['user'] = $users; |
|
106
|
|
|
$response['status'] = true; |
|
107
|
|
|
|
|
108
|
|
|
return response()->json($response); |
|
|
|
|
|
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Display the specified resource. |
|
113
|
|
|
* |
|
114
|
|
|
* @param \App\Anggaran $anggaran |
|
|
|
|
|
|
115
|
|
|
* @return \Illuminate\Http\Response |
|
116
|
|
|
*/ |
|
117
|
|
|
public function store(Request $request) |
|
118
|
|
|
{ |
|
119
|
|
|
$anggaran = $this->anggaran; |
|
120
|
|
|
|
|
121
|
|
|
$validator = Validator::make($request->all(), [ |
|
122
|
|
|
'group_egovernment_id' => 'required', |
|
123
|
|
|
'sector_egovernment_id' => 'required', |
|
124
|
|
|
'user_id' => 'required', |
|
125
|
|
|
'label' => 'required', |
|
126
|
|
|
'description' => 'required', |
|
127
|
|
|
]); |
|
128
|
|
|
|
|
129
|
|
|
if($validator->fails()){ |
|
130
|
|
|
$check = $anggaran->where('label',$request->label)->whereNull('deleted_at')->count(); |
|
131
|
|
|
|
|
132
|
|
|
if ($check > 0) { |
|
133
|
|
|
$response['message'] = 'Failed, label ' . $request->label . ' already exists'; |
|
|
|
|
|
|
134
|
|
|
} else { |
|
135
|
|
|
$anggaran->group_egovernment_id = $request->input('group_egovernment_id'); |
|
136
|
|
|
$anggaran->sector_egovernment_id = $request->input('sector_egovernment_id'); |
|
137
|
|
|
$anggaran->user_id = $request->input('user_id'); |
|
138
|
|
|
$anggaran->label = $request->input('label'); |
|
139
|
|
|
$anggaran->description = $request->input('description'); |
|
140
|
|
|
$anggaran->save(); |
|
141
|
|
|
|
|
142
|
|
|
$response['message'] = 'success'; |
|
143
|
|
|
} |
|
144
|
|
|
} else { |
|
145
|
|
|
$anggaran->group_egovernment_id = $request->input('group_egovernment_id'); |
|
146
|
|
|
$anggaran->sector_egovernment_id = $request->input('sector_egovernment_id'); |
|
147
|
|
|
$anggaran->user_id = $request->input('user_id'); |
|
148
|
|
|
$anggaran->label = $request->input('label'); |
|
149
|
|
|
$anggaran->description = $request->input('description'); |
|
150
|
|
|
$anggaran->save(); |
|
151
|
|
|
$response['message'] = 'success'; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
$response['status'] = true; |
|
155
|
|
|
|
|
156
|
|
|
return response()->json($response); |
|
|
|
|
|
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* Store a newly created resource in storage. |
|
161
|
|
|
* |
|
162
|
|
|
* @param \Illuminate\Http\Request $request |
|
163
|
|
|
* @return \Illuminate\Http\Response |
|
164
|
|
|
*/ |
|
165
|
|
|
public function show($id) |
|
166
|
|
|
{ |
|
167
|
|
|
$anggaran = $this->anggaran->findOrFail($id); |
|
168
|
|
|
|
|
169
|
|
|
$response['anggaran'] = $anggaran; |
|
|
|
|
|
|
170
|
|
|
$response['group_egovernment'] = $anggaran->group_egovernment; |
|
171
|
|
|
$response['sector_egovernment'] = $anggaran->sector_egovernment; |
|
172
|
|
|
$response['user'] = $anggaran->user; |
|
173
|
|
|
$response['status'] = true; |
|
174
|
|
|
|
|
175
|
|
|
return response()->json($response); |
|
|
|
|
|
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* Show the form for editing the specified resource. |
|
180
|
|
|
* |
|
181
|
|
|
* @param \App\Anggaran $anggaran |
|
182
|
|
|
* @return \Illuminate\Http\Response |
|
183
|
|
|
*/ |
|
184
|
|
|
public function edit($id) |
|
185
|
|
|
{ |
|
186
|
|
|
$anggaran = $this->anggaran->findOrFail($id); |
|
187
|
|
|
|
|
188
|
|
|
array_set($anggaran->user, 'label', $anggaran->user->name); |
|
|
|
|
|
|
189
|
|
|
|
|
190
|
|
|
$response['anggaran'] = $anggaran; |
|
|
|
|
|
|
191
|
|
|
$response['group_egovernment'] = $anggaran->group_egovernment; |
|
192
|
|
|
$response['sector_egovernment'] = $anggaran->sector_egovernment; |
|
193
|
|
|
$response['user'] = $anggaran->user; |
|
194
|
|
|
$response['status'] = true; |
|
195
|
|
|
|
|
196
|
|
|
return response()->json($response); |
|
|
|
|
|
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
/** |
|
200
|
|
|
* Update the specified resource in storage. |
|
201
|
|
|
* |
|
202
|
|
|
* @param \Illuminate\Http\Request $request |
|
203
|
|
|
* @param \App\Anggaran $anggaran |
|
204
|
|
|
* @return \Illuminate\Http\Response |
|
205
|
|
|
*/ |
|
206
|
|
|
public function update(Request $request, $id) |
|
207
|
|
|
{ |
|
208
|
|
|
$response = array(); |
|
209
|
|
|
$message = array(); |
|
210
|
|
|
|
|
211
|
|
|
$anggaran = $this->anggaran->findOrFail($id); |
|
212
|
|
|
{ |
|
213
|
|
|
$validator = Validator::make($request->all(), [ |
|
214
|
|
|
'label' => 'required', |
|
215
|
|
|
'description' => 'required', |
|
216
|
|
|
'group_egovernment_id' => 'required', |
|
217
|
|
|
'sector_egovernment_id' => 'required', |
|
218
|
|
|
'user_id' => 'required', |
|
219
|
|
|
'link' => 'required', |
|
220
|
|
|
]); |
|
221
|
|
|
|
|
222
|
|
|
if($validator->fails()){ |
|
223
|
|
|
|
|
224
|
|
|
foreach($validator->messages()->getMessages() as $key => $error){ |
|
225
|
|
|
foreach($error AS $error_get) { |
|
226
|
|
|
array_push($message, $error_get. "\n"); |
|
227
|
|
|
} |
|
228
|
|
|
} |
|
229
|
|
|
$response['message'] = $message; |
|
230
|
|
|
|
|
231
|
|
|
} else { |
|
232
|
|
|
$anggaran->label = $request->input('label'); |
|
233
|
|
|
$anggaran->description = $request->input('description'); |
|
234
|
|
|
$anggaran->link = $request->input('link'); |
|
235
|
|
|
$anggaran->group_egovernment_id = $request->input('group_egovernment_id'); |
|
236
|
|
|
$anggaran->sector_egovernment_id = $request->input('sector_egovernment_id'); |
|
237
|
|
|
$anggaran->user_id = $request->input('user_id'); |
|
238
|
|
|
$anggaran->save(); |
|
239
|
|
|
|
|
240
|
|
|
$response['message'] = 'success'; |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
$response['status'] = true; |
|
244
|
|
|
|
|
245
|
|
|
return response()->json($response); |
|
|
|
|
|
|
246
|
|
|
} |
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
|
|
/** |
|
250
|
|
|
* Remove the specified resource from storage. |
|
251
|
|
|
* |
|
252
|
|
|
* @param \App\Anggaran $anggaran |
|
253
|
|
|
* @return \Illuminate\Http\Response |
|
254
|
|
|
*/ |
|
255
|
|
|
public function destroy($id) |
|
256
|
|
|
{ |
|
257
|
|
|
$anggaran = $this->anggaran->findOrFail($id); |
|
258
|
|
|
|
|
259
|
|
|
if ($anggaran->delete()) { |
|
260
|
|
|
$response['status'] = true; |
|
|
|
|
|
|
261
|
|
|
} else { |
|
262
|
|
|
$response['status'] = false; |
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
|
|
return json_encode($response); |
|
|
|
|
|
|
266
|
|
|
} |
|
267
|
|
|
} |
|
268
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths