|
|
|
@ -4,18 +4,20 @@ namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
use App\Models\Peti; |
|
|
|
|
use App\Models\Customer; |
|
|
|
|
use App\Models\Disposal; |
|
|
|
|
use App\Models\m_warehouse; |
|
|
|
|
use Illuminate\Http\Request; |
|
|
|
|
use Symfony\Component\Uid\Uuid; |
|
|
|
|
use Illuminate\Support\Facades\Auth; |
|
|
|
|
use App\Http\Requests\Disposal\ValidasiCreateDisposal; |
|
|
|
|
use App\Models\Disposal; |
|
|
|
|
use App\Http\Requests\Disposal\ValidasiUpdateDisposal; |
|
|
|
|
|
|
|
|
|
class DisposalController extends Controller |
|
|
|
|
{ |
|
|
|
|
public function index() |
|
|
|
|
{ |
|
|
|
|
$data = [ |
|
|
|
|
'disposal' => Disposal::all(), |
|
|
|
|
'disposal' => Disposal::orderBy('created_at', 'desc')->get(), |
|
|
|
|
'active' => 'menu-disposal', |
|
|
|
|
]; |
|
|
|
|
return view('dashboard.Disposal.index', $data); |
|
|
|
@ -42,6 +44,7 @@ class DisposalController extends Controller
|
|
|
|
|
public function store(ValidasiCreateDisposal $request) |
|
|
|
|
{ |
|
|
|
|
// dd($request->all()); |
|
|
|
|
// dd($request); |
|
|
|
|
try { |
|
|
|
|
// Mendapatkan informasi pengguna yang sedang login |
|
|
|
|
$currentUser = Auth::user(); |
|
|
|
@ -50,11 +53,18 @@ class DisposalController extends Controller
|
|
|
|
|
$validatedData = $request->validated(); |
|
|
|
|
|
|
|
|
|
// Menambahkan informasi pengguna ke dalam data yang akan disimpan |
|
|
|
|
$validatedData['mobile_id'] = Uuid::v4(); // Menambahkan ID Mobile |
|
|
|
|
$validatedData['created_by'] = $currentUser->fullname; |
|
|
|
|
$validatedData['updated_by'] = $currentUser->fullname; |
|
|
|
|
|
|
|
|
|
// Membuat entitas Transfer |
|
|
|
|
Disposal::create($validatedData); |
|
|
|
|
// Membuat entitas Disposal |
|
|
|
|
$disposal = Disposal::create($validatedData); |
|
|
|
|
|
|
|
|
|
// Mengupdate warehouse_id pada model Peti |
|
|
|
|
Peti::where('id', $disposal->peti_id) |
|
|
|
|
->update([ |
|
|
|
|
'status' => $disposal->status_disposal, |
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
return redirect()->route('dashboard.disposal.index')->with('success', 'Data Disposal Peti berhasil ditambahkan'); |
|
|
|
|
} catch (\Throwable $th) { |
|
|
|
@ -92,10 +102,40 @@ class DisposalController extends Controller
|
|
|
|
|
/** |
|
|
|
|
* Update the specified resource in storage. |
|
|
|
|
*/ |
|
|
|
|
// public function update($request, $id) |
|
|
|
|
// { |
|
|
|
|
// // |
|
|
|
|
// } |
|
|
|
|
public function update(ValidasiUpdateDisposal $request, $id) |
|
|
|
|
{ |
|
|
|
|
// dd("oke"); |
|
|
|
|
try { |
|
|
|
|
// Mendapatkan informasi pengguna yang sedang login |
|
|
|
|
$currentUser = Auth::user(); |
|
|
|
|
|
|
|
|
|
// Validasi data dari request |
|
|
|
|
$validatedData = $request->validated(); |
|
|
|
|
|
|
|
|
|
// Menambahkan informasi pengguna ke dalam data yang akan disimpan |
|
|
|
|
$validatedData['updated_by'] = $currentUser->fullname; |
|
|
|
|
|
|
|
|
|
// Mencari transfer berdasarkan ID |
|
|
|
|
$disposal = Disposal::find($id); |
|
|
|
|
|
|
|
|
|
if (!$disposal) { |
|
|
|
|
return redirect()->route('dashboard.disposal.index')->with('error', 'Data Disposal Peti tidak ditemukan'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Memperbarui data transfer |
|
|
|
|
$disposal->update($validatedData); |
|
|
|
|
|
|
|
|
|
// Mengupdate warehouse_id pada model Peti |
|
|
|
|
Peti::where('id', $disposal->peti_id) |
|
|
|
|
->update([ |
|
|
|
|
'status' => $disposal->status_disposal, |
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
return redirect()->route('dashboard.disposal.index')->with('success', 'Data Disposal Peti berhasil diperbaharui'); |
|
|
|
|
} catch (\Throwable $th) { |
|
|
|
|
return redirect()->back()->with('error', 'Data Disposal Peti gagal diperbaharui'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Remove the specified resource from storage. |
|
|
|
|