Gunawan19621
1 year ago
30 changed files with 528 additions and 76 deletions
@ -0,0 +1,142 @@
|
||||
<?php |
||||
|
||||
namespace App\Http\Controllers; |
||||
|
||||
use App\Models\Peti; |
||||
use App\Models\Customer; |
||||
use Illuminate\Http\Request; |
||||
|
||||
class RecycleDataController extends Controller |
||||
{ |
||||
/** |
||||
* Display a listing of the resource. |
||||
*/ |
||||
public function index() |
||||
{ |
||||
$peti = Peti::onlyTrashed()->get(); |
||||
$customer = Customer::onlyTrashed()->get(); |
||||
|
||||
$data = [ |
||||
'peti' => Peti::onlyTrashed()->get(), |
||||
'customer' => Customer::onlyTrashed()->get(), |
||||
'active' => 'menu-Recycle_Data', |
||||
]; |
||||
|
||||
return view('dashboard.Master_Data.Recycle_Data.index', $data); |
||||
} |
||||
|
||||
// public function pulihkanData($id) |
||||
// { |
||||
// // dd('oke'); |
||||
// $peti = Customer::withTrashed()->find($id); |
||||
|
||||
// if ($peti) { |
||||
// $peti->restore(); |
||||
// return redirect()->back()->with('success', 'Data berhasil dipulihkan.'); |
||||
// } else { |
||||
// return redirect()->back()->with('error', 'Data tidak ditemukan.'); |
||||
// } |
||||
// } |
||||
|
||||
// public function hapusPermanenData($id) |
||||
// { |
||||
// // dd('oke'); |
||||
// $peti = Peti::withTrashed()->find($id); |
||||
|
||||
// if ($peti) { |
||||
// $peti->forceDelete(); |
||||
// return redirect()->back()->with('success', 'Data berhasil dihapus permanen.'); |
||||
// } else { |
||||
// return redirect()->back()->with('error', 'Data tidak ditemukan.'); |
||||
// } |
||||
// } |
||||
|
||||
// public function pulihkanData(Request $request) |
||||
// { |
||||
// $peti = Peti::withTrashed() |
||||
// ->where('id', '=', $request->id) |
||||
// ->first(); |
||||
|
||||
// $customer = Customer::withTrashed() |
||||
// ->where('id', '=', $request->id) |
||||
// ->first(); |
||||
|
||||
// if ($peti) { |
||||
// $peti->restore(); |
||||
// return redirect()->back()->with('success', 'Data Peti berhasil dipulihkan.'); |
||||
// } elseif ($customer) { |
||||
// $customer->restore(); |
||||
// return redirect()->back()->with('success', 'Data Customer berhasil dipulihkan.'); |
||||
// } else { |
||||
// return redirect()->back()->with('error', 'Data tidak ditemukan.'); |
||||
// } |
||||
// } |
||||
|
||||
|
||||
// public function hapusPermanenData($id) |
||||
// { |
||||
// $peti = Peti::withTrashed()->find($id); |
||||
// $customer = Customer::withTrashed()->find($id); |
||||
|
||||
// if ($peti) { |
||||
// $peti->forceDelete(); |
||||
// return redirect()->back()->with('success', 'Data Peti berhasil dihapus permanen.'); |
||||
// } elseif ($customer) { |
||||
// $customer->forceDelete(); |
||||
// return redirect()->back()->with('success', 'Data Customer berhasil dihapus permanen.'); |
||||
// } else { |
||||
// return redirect()->back()->with('error', 'Data tidak ditemukan.'); |
||||
// } |
||||
// } |
||||
|
||||
|
||||
public function pulihkanData(Request $request, $model, $id) |
||||
{ |
||||
$data = null; |
||||
|
||||
switch ($model) { |
||||
case 'peti': |
||||
$data = Peti::withTrashed()->find($id); |
||||
break; |
||||
case 'customer': |
||||
$data = Customer::withTrashed()->find($id); |
||||
break; |
||||
// Add more cases for other models if needed |
||||
|
||||
default: |
||||
return redirect()->back()->with('error', 'Model tidak valid.'); |
||||
} |
||||
|
||||
if ($data) { |
||||
$data->restore(); |
||||
return redirect()->back()->with('success', "Data $model berhasil dipulihkan."); |
||||
} else { |
||||
return redirect()->back()->with('error', 'Data tidak ditemukan.'); |
||||
} |
||||
} |
||||
|
||||
public function hapusPermanenData($model, $id) |
||||
{ |
||||
$data = null; |
||||
|
||||
switch ($model) { |
||||
case 'peti': |
||||
$data = Peti::withTrashed()->find($id); |
||||
break; |
||||
case 'customer': |
||||
$data = Customer::withTrashed()->find($id); |
||||
break; |
||||
// Add more cases for other models if needed |
||||
|
||||
default: |
||||
return redirect()->back()->with('error', 'Model tidak valid.'); |
||||
} |
||||
|
||||
if ($data) { |
||||
$data->forceDelete(); |
||||
return redirect()->back()->with('success', "Data $model berhasil dihapus permanen."); |
||||
} else { |
||||
return redirect()->back()->with('error', 'Data tidak ditemukan.'); |
||||
} |
||||
} |
||||
} |
|
@ -0,0 +1,196 @@
|
||||
{{-- @extends('layouts.main') |
||||
@section('title', 'Warehouse') |
||||
@section('content') |
||||
@include('layouts.components.alert-prompt') |
||||
<div class="card shadow mb-4"> |
||||
<div class="card-header py-3"> |
||||
<div class="row"> |
||||
<div class="col-6"> |
||||
<h5 class="m-0 font-weight-bold text-primary mt-2">Recycle Data</h5> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
<div class="card-body"> |
||||
<div class="table-responsive"> |
||||
<table class="table table-bordered" id="tablebarang" width="100%" cellspacing="0"> |
||||
<thead> |
||||
<tr> |
||||
<th class="text-center" style="width: 50px;">No.</th> |
||||
<th>Kategori Data</th> |
||||
<th>Data</th> |
||||
<th>Tanggal di hapus</th> |
||||
<th class="text-center">Action</th> |
||||
</tr> |
||||
</thead> |
||||
<tbody> |
||||
@php |
||||
$norecycle = 1; |
||||
@endphp |
||||
<!-- Data Peti --> |
||||
@foreach ($peti as $data_peti) |
||||
<tr> |
||||
<td class="text-center" style="width: 50px;">{{ $norecycle++ }}</td> |
||||
<td>Data Peti</td> |
||||
<td>{{ $data_peti->fix_lot }}</td> |
||||
<td>{{ optional($data_peti->deleted_at)->format('d-m-Y') ?? '-' }}</td> |
||||
<td class="text-center"> |
||||
<form |
||||
action="{{ route('dashboard.recycle_data.pulihkanData', ['id' => $data_peti->id]) }}" |
||||
method="post"> |
||||
@csrf |
||||
@method('POST') |
||||
<button type="submit" class="btn btn-sm btn-success aksi-link" |
||||
onclick="return confirm('Apakah Anda yakin ingin memulihkan data ini?')">Pulihkan</button> |
||||
</form> |
||||
|
||||
<!-- Hapus Permanen Data --> |
||||
<form |
||||
action="{{ route('dashboard.recycle_data.hapusPermanenData', ['id' => $data_peti->id]) }}" |
||||
method="post"> |
||||
@csrf |
||||
@method('DELETE') |
||||
<button type="submit" class="btn btn-sm btn-danger aksi-link" |
||||
onclick="return confirm('Apakah Anda yakin ingin menghapus permanen data ini?')">Hapus |
||||
Permanen</button> |
||||
</form> |
||||
|
||||
</td> |
||||
</tr> |
||||
@endforeach |
||||
|
||||
<!-- Data Customer --> |
||||
@foreach ($customer as $data_items) |
||||
<tr> |
||||
<td class="text-center" style="width: 50px;">{{ $norecycle++ }}</td> |
||||
<td>Data Customer</td> |
||||
<td>{{ $data_items->name }}</td> |
||||
<td>{{ optional($data_items->deleted_at)->format('d-m-Y') ?? '-' }}</td> |
||||
<td class="text-center"> |
||||
<form |
||||
action="{{ route('dashboard.recycle_data.pulihkanData', ['id' => $data_items->id]) }}" |
||||
method="post"> |
||||
@csrf |
||||
@method('POST') |
||||
<button type="submit" class="btn btn-sm btn-success aksi-link" |
||||
onclick="return confirm('Apakah Anda yakin ingin memulihkan data ini?')">Pulihkan</button> |
||||
</form> |
||||
|
||||
<!-- Hapus Permanen Data --> |
||||
<form |
||||
action="{{ route('dashboard.recycle_data.hapusPermanenData', ['id' => $data_items->id]) }}" |
||||
method="post"> |
||||
@csrf |
||||
@method('DELETE') |
||||
<button type="submit" class="btn btn-sm btn-danger aksi-link" |
||||
onclick="return confirm('Apakah Anda yakin ingin menghapus permanen data ini?')">Hapus |
||||
Permanen</button> |
||||
</form> |
||||
|
||||
</td> |
||||
</tr> |
||||
@endforeach |
||||
</tbody> |
||||
</table> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
@endsection --}} |
||||
|
||||
|
||||
@extends('layouts.main') |
||||
@section('title', 'Warehouse') |
||||
@section('content') |
||||
@include('layouts.components.alert-prompt') |
||||
<div class="card shadow mb-4"> |
||||
<div class="card-header py-3"> |
||||
<div class="row"> |
||||
<div class="col-6"> |
||||
<h5 class="m-0 font-weight-bold text-primary mt-2">Recycle Data</h5> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
<div class="card-body"> |
||||
<div class="table-responsive"> |
||||
<table class="table table-bordered" id="tablebarang" width="100%" cellspacing="0"> |
||||
<thead> |
||||
<tr> |
||||
<th class="text-center" style="width: 50px;">No.</th> |
||||
<th>Kategori Data</th> |
||||
<th>Data</th> |
||||
<th>Tanggal di hapus</th> |
||||
<th class="text-center">Action</th> |
||||
</tr> |
||||
</thead> |
||||
<tbody> |
||||
@php |
||||
$norecycle = 1; |
||||
@endphp |
||||
<!-- Data Peti --> |
||||
@foreach ($peti as $data_peti) |
||||
<tr> |
||||
<td class="text-center" style="width: 50px;">{{ $norecycle++ }}</td> |
||||
<td>Data Peti</td> |
||||
<td>{{ $data_peti->fix_lot }}</td> |
||||
<td>{{ optional($data_peti->deleted_at)->format('d-m-Y') ?? '-' }}</td> |
||||
<td class="text-center"> |
||||
<form |
||||
action="{{ route('dashboard.recycle_data.pulihkanData', ['model' => 'peti', 'id' => $data_peti->id]) }}" |
||||
method="post"> |
||||
@csrf |
||||
@method('POST') |
||||
<button type="submit" class="btn btn-sm btn-success aksi-link" |
||||
onclick="return confirm('Apakah Anda yakin ingin memulihkan data ini?')">Pulihkan</button> |
||||
</form> |
||||
|
||||
<!-- Hapus Permanen Data --> |
||||
<form |
||||
action="{{ route('dashboard.recycle_data.hapusPermanenData', ['model' => 'peti', 'id' => $data_peti->id]) }}" |
||||
method="post"> |
||||
@csrf |
||||
@method('DELETE') |
||||
<button type="submit" class="btn btn-sm btn-danger aksi-link" |
||||
onclick="return confirm('Apakah Anda yakin ingin menghapus permanen data ini?')">Hapus |
||||
Permanen</button> |
||||
</form> |
||||
|
||||
</td> |
||||
</tr> |
||||
@endforeach |
||||
|
||||
<!-- Data Customer --> |
||||
@foreach ($customer as $data_items) |
||||
<tr> |
||||
<td class="text-center" style="width: 50px;">{{ $norecycle++ }}</td> |
||||
<td>Data Customer</td> |
||||
<td>{{ $data_items->name }}</td> |
||||
<td>{{ optional($data_items->deleted_at)->format('d-m-Y') ?? '-' }}</td> |
||||
<td class="text-center"> |
||||
<form |
||||
action="{{ route('dashboard.recycle_data.pulihkanData', ['model' => 'customer', 'id' => $data_items->id]) }}" |
||||
method="post"> |
||||
@csrf |
||||
@method('POST') |
||||
<button type="submit" class="btn btn-sm btn-success aksi-link" |
||||
onclick="return confirm('Apakah Anda yakin ingin memulihkan data ini?')">Pulihkan</button> |
||||
</form> |
||||
|
||||
<!-- Hapus Permanen Data --> |
||||
<form |
||||
action="{{ route('dashboard.recycle_data.hapusPermanenData', ['model' => 'customer', 'id' => $data_items->id]) }}" |
||||
method="post"> |
||||
@csrf |
||||
@method('DELETE') |
||||
<button type="submit" class="btn btn-sm btn-danger aksi-link" |
||||
onclick="return confirm('Apakah Anda yakin ingin menghapus permanen data ini?')">Hapus |
||||
Permanen</button> |
||||
</form> |
||||
|
||||
</td> |
||||
</tr> |
||||
@endforeach |
||||
</tbody> |
||||
</table> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
@endsection |
Loading…
Reference in new issue