Skip to content

Commit 6911245

Browse files
authored
Merge pull request #15 from qodrorid/develop
Develop
2 parents 74e1e65 + 4e90977 commit 6911245

File tree

15 files changed

+526
-16
lines changed

15 files changed

+526
-16
lines changed

app/Http/Controllers/IzinController.php

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
namespace App\Http\Controllers;
44

5-
use App\Models\Izin;
65
use Illuminate\Http\Request;
6+
use App\Jobs\IzinJob;
7+
use App\Models\Izin;
8+
use App\Models\User;
79

810
use Auth;
911

@@ -17,6 +19,7 @@ class IzinController extends Controller
1719
*/
1820
public function index(Request $request)
1921
{
22+
$userId = Auth::user()->id;
2023
$izin = Izin::where(function($query) use ($request) {
2124
if (!is_null($request->start) and !is_null($request->end)) {
2225
$query->whereBetween('start', [$request->start, $request->end])
@@ -26,7 +29,7 @@ public function index(Request $request)
2629
$query->where('name', 'like', "%$request->keyword%")
2730
->orWhere('information', 'like', "%$request->keyword%");
2831
}
29-
})->paginate($request->showitem ?? 5);
32+
})->where('user_id', $userId)->paginate($request->showitem ?? 5);
3033

3134
$izin->appends($request->query());
3235

@@ -90,7 +93,7 @@ public function update(Request $request, Izin $izin)
9093
'end' => 'required'
9194
]);
9295

93-
if ($izin->approved) abort(400);
96+
if (!is_null($izin->approved)) abort(400);
9497

9598
try {
9699
$izin->update($request->all());
@@ -115,4 +118,71 @@ public function destroy(Izin $izin)
115118
return $this->responseQueryException($error);
116119
}
117120
}
121+
122+
public function student(Request $request)
123+
{
124+
$branchId = Auth::user()->branch_id;
125+
126+
$users = User::where(function ($query) use ($request, $branchId) {
127+
if (!is_null($branchId)) {
128+
$query->where('branch_id', $branchId);
129+
}
130+
131+
if (!is_null($request->keyword)) {
132+
$query->where('name', 'like', "%$request->keyword%")
133+
->orWhere('username', 'like', "%$request->keyword%")
134+
->orWhere('email', 'like', "%$request->keyword%");
135+
}
136+
})->where('role_id', 9)->paginate($request->showitem ?? 5);
137+
138+
$users->appends($request->query());
139+
140+
$view = $request->ajax() ? 'list-student' : 'student';
141+
142+
return view('pages.izin.' . $view, compact('users'));
143+
}
144+
145+
public function list(Request $request, User $user)
146+
{
147+
$branchId = Auth::user()->branch_id;
148+
$userId = $user->id;
149+
150+
if ((!is_null($branchId) and $branchId !== $user->branch_id) or $user->role_id !== 9) abort(403);
151+
152+
$izin = Izin::where(function($query) use ($request) {
153+
if (!is_null($request->start) and !is_null($request->end)) {
154+
$query->whereBetween('start', [$request->start, $request->end])
155+
->orWhereBetween('end', [$request->start, $request->end]);
156+
}
157+
if (!is_null($request->keyword)) {
158+
$query->where('name', 'like', "%$request->keyword%")
159+
->orWhere('information', 'like', "%$request->keyword%");
160+
}
161+
})->where('user_id', $userId)->paginate($request->showitem ?? 5);
162+
163+
$izin->appends($request->query());
164+
165+
$view = $request->ajax() ? 'izin-view-list' : 'izin-view';
166+
167+
return view('pages.izin.' . $view, compact('izin', 'userId'));
168+
}
169+
170+
public function approved(Request $request, Izin $izin)
171+
{
172+
$request->validate([
173+
'approved' => 'required'
174+
]);
175+
176+
if (!is_null($izin->approved)) abort(400);
177+
178+
$token = Auth::user()->branch->telegram;
179+
180+
try {
181+
$izin->update($request->all());
182+
if ($izin->approved == 1) IzinJob::dispatch($token, $izin);
183+
return $this->success('Successfuly update data izin!');
184+
} catch (QueryException $error) {
185+
return $this->responseQueryException($error);
186+
}
187+
}
118188
}

app/Jobs/IzinJob.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace App\Jobs;
4+
5+
use Illuminate\Bus\Queueable;
6+
use Illuminate\Contracts\Queue\ShouldQueue;
7+
use Illuminate\Foundation\Bus\Dispatchable;
8+
use Illuminate\Queue\InteractsWithQueue;
9+
use Illuminate\Queue\SerializesModels;
10+
use App\Notifications\IzinNotif;
11+
use App\Models\Izin;
12+
13+
use Notification;
14+
15+
class IzinJob implements ShouldQueue
16+
{
17+
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
18+
19+
private $token;
20+
private $izin;
21+
22+
/**
23+
* Create a new job instance.
24+
*
25+
* @return void
26+
*/
27+
public function __construct(string $token, Izin $izin)
28+
{
29+
$this->token = $token;
30+
$this->izin = $izin;
31+
}
32+
33+
/**
34+
* Execute the job.
35+
*
36+
* @return void
37+
*/
38+
public function handle()
39+
{
40+
$data = (object) [
41+
'token' => $this->token,
42+
'info' => $this->izin->information,
43+
'user' => $this->izin->name
44+
];
45+
46+
Notification::send($data, new IzinNotif);
47+
}
48+
}

app/Jobs/TodoJob.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
use Illuminate\Foundation\Bus\Dispatchable;
88
use Illuminate\Queue\InteractsWithQueue;
99
use Illuminate\Queue\SerializesModels;
10-
11-
use NotificationChannels\Telegram\TelegramChannel;
1210
use App\Notifications\TodoNotif;
1311

1412
use Notification;

app/Notifications/IzinNotif.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace App\Notifications;
4+
5+
use Illuminate\Bus\Queueable;
6+
use NotificationChannels\Telegram\TelegramChannel;
7+
use NotificationChannels\Telegram\TelegramMessage;
8+
use Illuminate\Notifications\Notification;
9+
10+
class IzinNotif extends Notification
11+
{
12+
use Queueable;
13+
14+
public function via($notifiable)
15+
{
16+
return [TelegramChannel::class];
17+
}
18+
19+
public function toTelegram($notifiable)
20+
{
21+
$urlQodr = config('app.debug') ? 'https://samarinda.qodr.or.id' : config('app.url');
22+
$information = $notifiable->info;
23+
$nameUser = $notifiable->user;
24+
25+
$content = "📝 *IZIN SANTRI QODR SAMARINDA*\n";
26+
$content .= "=============================\n\n";
27+
$content .= "👤 *$nameUser*\n\n";
28+
$content .= $information . "\n\n";
29+
$content .= "Fii Amanillah. 👍";
30+
31+
return TelegramMessage::create()
32+
->to("$notifiable->token")
33+
->content($content)
34+
->button('Qodr Apps', $urlQodr);
35+
}
36+
}

app/Notifications/TodoNotif.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function via($notifiable)
2525

2626
public function toTelegram($notifiable)
2727
{
28-
$urlQodr = config('app.debug') ? 'https://samarinda.qodr.or.id/todo' : config('app.url') . '/todo';
28+
$urlQodr = config('app.debug') ? 'https://samarinda.qodr.or.id' : config('app.url');
2929
$todo = $this->todo;
3030
$todoList = json_decode($todo->todo);
3131
$nameUser = $todo->user->name;

public/js/pages/izin.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,43 @@ function deleted(id) {
8888
})
8989
}
9090

91+
/**
92+
* function delete izin
93+
* @param id
94+
* @return @void
95+
*/
96+
function approved(id, userid, approved) {
97+
var message = {}
98+
if (approved) {
99+
message = {
100+
title: 'Are you sure approved ?',
101+
text: 'students will be allowed permission',
102+
confirmButtonText: 'Approve'
103+
}
104+
} else {
105+
message = {
106+
title: 'Are you sure rejected ?',
107+
text: 'students will be banned for permission',
108+
confirmButtonText: 'Rejected'
109+
}
110+
}
111+
112+
Swal.fire({
113+
...message,
114+
type: 'warning',
115+
showCancelButton: true,
116+
confirmButtonColor: '#1ABC9C',
117+
cancelButtonColor: '#E74C3C',
118+
allowOutsideClick: false
119+
}).then((result) => {
120+
if (result.value) {
121+
$.updated(`/izin/approved/${id}`, { approved }).then(() => {
122+
$.listdata(`/izin/list/${userid}`)
123+
})
124+
}
125+
})
126+
}
127+
91128
// clear form izin
92129
$('#form-izin').on('hide.bs.modal', function () {
93130
let modal = $(this)

resources/views/pages/izin/index.blade.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
@section('content')
88

99
@include('components.page-header', [
10-
'title' => 'Izin Santri',
11-
'subtitle' => 'System Izin Santri',
10+
'title' => 'Izin Student',
11+
'subtitle' => 'System Izin Student',
1212
'breadcrumb' => [
13-
'izin santri'
13+
'izin student'
1414
]
1515
])
1616

@@ -30,9 +30,11 @@
3030
<div class="card-block">
3131
<div class="row">
3232
<div class="col-md-2">
33-
<select name="showitem" class="form-control" data-url="/izin">
34-
{!! HelperTag::showItem(request()->show ?? 5) !!}
35-
</select>
33+
<div class="form-group">
34+
<select name="showitem" class="form-control" data-url="/izin">
35+
{!! HelperTag::showItem(request()->show ?? 5) !!}
36+
</select>
37+
</div>
3638
</div>
3739
<div class="col-md-4">
3840
<div class="form-group">
@@ -48,9 +50,11 @@
4850
</div>
4951
</div>
5052
<div class="col-md-2">
51-
<button type="button" class="btn btn-primary btn-block" data-toggle="modal" data-target="#form-izin">
52-
<i class="feather icon-plus"></i> Add
53-
</button>
53+
<div class="form-group">
54+
<button type="button" class="btn btn-primary btn-block" data-toggle="modal" data-target="#form-izin">
55+
<i class="feather icon-plus"></i> Add
56+
</button>
57+
</div>
5458
</div>
5559
</div>
5660
<div class="table-responsive">
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
@php($no = $izin->perPage() * $izin->currentPage() - $izin->perPage() + 1)
2+
@foreach ($izin as $item)
3+
<tr>
4+
<td align="center">{{ $no }}</td>
5+
<td>{{ $item->information }}</td>
6+
<td align="center">{{ date('H:i | d F Y', strtotime($item->start)) }}</td>
7+
<td align="center">{{ date('H:i | d F Y', strtotime($item->end)) }}</td>
8+
<td align="center">
9+
@if ($item->approved === 1)
10+
<span class="label label-success">Approved</span>
11+
@elseif ($item->approved === 0)
12+
<span class="label label-danger">Rejected</span>
13+
@endif
14+
</td>
15+
<td class="action">
16+
@if (is_null($item->approved))
17+
<div class="dropdown-primary dropdown open btn-block">
18+
<button class="btn btn-primary btn-sm btn-block dropdown-toggle" type="button" id="action" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
19+
<i class="feather icon-cpu"></i> Action
20+
</button>
21+
<div class="dropdown-menu" aria-labelledby="action" data-dropdown-in="fadeIn" data-dropdown-out="fadeOut">
22+
<a class="dropdown-item" onclick="approved({{ $item->id }}, {{ $userId }}, 1)">
23+
<i class="feather icon-user-check"></i> Approve
24+
</a>
25+
<a class="dropdown-item" onclick="approved({{ $item->id }}, {{ $userId }}, 0)">
26+
<i class="feather icon-user-x"></i> Reject
27+
</a>
28+
</div>
29+
</div>
30+
@endif
31+
</td>
32+
</tr>
33+
@php($no = $no + 1)
34+
@endforeach
35+
36+
@if ($izin->total() < 1)
37+
<tr>
38+
<td colspan="6" align="center">Data not found</td>
39+
</tr>
40+
@endif
41+
42+
<script>
43+
(function() {
44+
@if ($izin->lastPage() > 1)
45+
$('#pagination').html(`{{ $izin->links('components.pagination.ajax') }}`)
46+
@else
47+
$('#pagination').html('')
48+
@endif
49+
})()
50+
</script>

0 commit comments

Comments
 (0)