Buat Padam Kakitangan

This commit is contained in:
hafifierahman
2023-01-26 00:38:02 +08:00
parent f10abeb97a
commit c32d5ff800
3 changed files with 74 additions and 17 deletions
+18 -4
View File
@@ -214,11 +214,19 @@ class KakitanganController extends Controller
}
public function deleteKakitangan(Request $request){
// dd($request->all());
$auth_user = Auth::user();
$user = User::find($request->staff_id);
$user->delete();
// dd($user_delete);
return redirect()->route('admin.daftar.kakitangan');
// if($auth_user->roles == 'operasi'){
// // return redirect()->route('daftar.kakitangan');
// return "route('daftar.kakitangan')";
// }else if($auth_user->roles == 'admin'){
// // return redirect()->route('admin.daftar.kakitangan');
// return "route('admin.daftar.kakitangan')";
// }
return response()->json('success');
}
public function editKakitangan(Request $request){
@@ -233,6 +241,7 @@ class KakitanganController extends Controller
public function editStoreKakitangan(Request $request){
// dd($request->all());
$auth_user = Auth::user();
$user = User::find($request->user_id);
$user->name = strtoupper($request->nama);
$user->email = $request->email;
@@ -242,7 +251,12 @@ class KakitanganController extends Controller
$user->password = Hash::make($request->nokp);
$user->save();
return redirect()->route('admin.daftar.kakitangan');
if($auth_user->roles == 'operasi'){
return redirect()->route('daftar.kakitangan');
}else if($auth_user->roles == 'admin'){
return redirect()->route('admin.daftar.kakitangan');
}
}
public function resetCredentials(Request $request){
@@ -128,7 +128,7 @@
@else
@php
$cawangan_staff = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/cawangan/'. $staff->cawangan)->json();
echo ucwords($cawangan_staff['details_caw']);
echo ($cawangan_staff) ? ucwords($cawangan_staff['details_caw']) : 'test';
@endphp
@endif
</td>
@@ -136,16 +136,18 @@
@if($auth_user->roles == 'operasi')
<a href="{{ route('kakitangan.tukartaraf',['id'=>$staff->id]) }}" class="btn btn-warning" title="Tukar Taraf"><i class="material-icons">edit</i></a>
<a href="{{ route('kakitangan.tukarcawangan',['id'=>$staff->id]) }}" class="btn btn-info" title="Tukar Cawangan"><i class="material-icons">work</i></a>
<a href="{{ route('operasi.kakitangan.edit',['id'=>$staff->id]) }}" class="btn btn-success" title="Edit Maklumat"><i class="material-icons">settings</i></a>
<button type="button" class="btn btn-danger btn-delete" data-roles="{{ $auth_user->roles }}" data-staff-id="{{ $staff->id }}" data-token="{{ csrf_token() }}" title="Delete Kakitangan"><i class="material-icons">delete</i></button>
@elseif($auth_user->roles == 'admin')
<form method="post" action="{{ route('admin.kakitangan.delete') }}">
{{ @csrf_field() }}
{{-- <form method="post" action="{{ route('admin.kakitangan.delete') }}">
{{ @csrf_field() }} --}}
<input type="hidden" name="staff_id" value="{{ $staff->id }}"/>
<a href="{{ route('admin.kakitangan.tukartaraf',['id'=>$staff->id]) }}" class="btn btn-warning" title="Tukar Taraf"><i class="material-icons">edit</i></a>
<a href="{{ route('admin.kakitangan.tukarcawangan',['id'=>$staff->id]) }}" class="btn btn-info" title="Tukar Cawangan"><i class="material-icons">work</i></a>
<a href="{{ route('admin.kakitangan.edit',['id'=>$staff->id]) }}" class="btn btn-success" title="Edit Maklumat"><i class="material-icons">settings</i></a>
<a href="{{ route('admin.kakitangan.resetcredentials',['id'=>$staff->id]) }}" class="btn btn-primary" title="Reset Password"><i class="material-icons">restore</i></a>
<button type="button" class="btn btn-danger btn-delete" data-staff-id="{{ $staff->id }}" data-token="{{ csrf_token() }}" title="Delete Kakitangan"><i class="material-icons">delete</i></button>
</form>
{{-- </form> --}}
@endif
</td>
</tr>
@@ -165,20 +167,57 @@
var tablerekod = $('#rekod_kakitangan').DataTable();
$('.btn-delete').on('click', function(){
var form = $(this).closest('form');
Swal.fire(
{
title: 'Are you sure?',
text: "You won't be able to revert this!",
// var form = $(this).closest('form');
var roles = $(this).data('roles');
var staff_id = $(this).data('staff-id');
var url_redirected = (roles == 'operasi') ? "{{ route('operasi.kakitangan.delete') }}" : "{{ route('admin.kakitangan.delete') }}";
Swal.fire({
title: 'Padam Kakitangan Ini?',
text: "Anda tidak boleh mengembalikan data ini balik selepas dipadamkan!",
type: 'warning',
showCancelButton: true,
confirmButtonClass: 'btn btn-danger',
cancelButtonClass: 'btn btn-warning',
confirmButtonText: 'Yes, delete it!',
confirmButtonText: 'Padam!',
cancelButtonText: 'Batal!',
buttonsStyling: false
}
).then(function() {
form.submit();
}).then(function(result) {
if (result.isConfirmed) {
$.ajax({
method:'post',
url: url_redirected,
data: {
"_token": "{{ csrf_token() }}",
"staff_id" : staff_id
},
success:function(data){
if(data == 'success')
{
if(roles == 'operasi')
window.location.href = "{{ route('daftar.kakitangan') }}";
else
window.location.href = "{{ route('admin.daftar.kakitangan') }}";
Swal.fire({
title: 'Memuatkan...',
allowEscapeKey : false,
allowOutsideClick: false,
didOpen: function () {
Swal.showLoading();
}
});
}
},
error: function(xhr, status, error) {
var err = eval("(" + xhr.responseText + ")");
alert(xhr.responseText);
}
});
}
}).catch(swal.noop)
});
+4
View File
@@ -314,6 +314,10 @@ Route::post('kakitangan/tukar_taraf/update',['as'=>'kakitangan.tukartaraf.update
Route::get('kakitangan/tukar_cawangan',['as'=>'kakitangan.tukarcawangan','uses'=>'KakitanganController@tukarcawangan'])->middleware('auth','operasi');
Route::post('kakitangan/tukar_cawangan/update',['as'=>'kakitangan.tukarcawangan.update','uses'=>'KakitanganController@tukarcawanganUpdate'])->middleware('auth','operasi');
Route::post('operasi/komoditi/limit',['as'=>'komoditi.limit','uses'=>'KomuditiController@komoditiUpdate'])->middleware('auth','operasi');
Route::post('operasi/kakitangan/delete',['as'=>'operasi.kakitangan.delete','uses'=>'KakitanganController@deleteKakitangan'])->middleware('auth','operasi');
Route::get('operasi/kakitangan/edit',['as'=>'operasi.kakitangan.edit','uses'=>'KakitanganController@editKakitangan'])->middleware('auth','operasi');
Route::post('operasi/kakitangan/edit/store',['as'=>'operasi.kakitangan.edit.store','uses'=>'KakitanganController@editStoreKakitangan'])->middleware('auth','operasi');
Route::get('/operasi/margin',['as'=>'operasi.margin','uses'=>'OperasiController@margin'])->middleware('auth','operasi');