Siopas Inventory PETI for ISTW Website
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

161 lines
5.1 KiB

<?php
namespace App\Http\Controllers;
use App\Models\Peti;
12 months ago
use App\Models\Customer;
use App\Models\Disposal;
use App\Models\m_warehouse;
use Symfony\Component\Uid\Uuid;
12 months ago
use Illuminate\Support\Facades\Auth;
use App\Http\Requests\Disposal\ValidasiCreateDisposal;
use App\Http\Requests\Disposal\ValidasiUpdateDisposal;
class DisposalController extends Controller
{
public function index()
{
$data = [
'disposal' => Disposal::where('status_disposal', 'INAKTIF')->orderBy('created_at', 'desc')->get(),
// 'disposal' => Disposal::orderBy('created_at', 'desc')->get(),
'active' => 'menu-disposal',
];
return view('dashboard.Disposal.index', $data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$petiWithStatusNotZeroOrEmptyAndActive = Peti::where(function ($query) {
$query->whereHas('assetStatuses', function ($subquery) {
$subquery->where('status', '!=', 0);
})->orWhereDoesntHave('assetStatuses');
})->where('status', 'aktif')->get();
$data = [
'peti' => $petiWithStatusNotZeroOrEmptyAndActive,
'warehouse' => m_warehouse::get(),
12 months ago
'customer' => Customer::get(),
'active' => 'menu-disposal',
];
return view('dashboard.Disposal.create', $data);
}
/**
* Store a newly created resource in storage.
*/
12 months ago
public function store(ValidasiCreateDisposal $request)
{
12 months ago
// dd($request->all());
// dd($request);
12 months ago
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['mobile_id'] = Uuid::v4(); // Menambahkan ID Mobile
12 months ago
$validatedData['created_by'] = $currentUser->fullname;
$validatedData['updated_by'] = $currentUser->fullname;
// Membuat entitas Disposal
$disposal = Disposal::create($validatedData);
// Mengupdate warehouse_id pada model Peti
Peti::where('id', $disposal->peti_id)
->update([
'status' => $disposal->status_disposal,
]);
12 months ago
return redirect()->route('dashboard.disposal.index')->with('success', 'Data Disposal Peti berhasil ditambahkan');
} catch (\Throwable $th) {
return redirect()->back()->with('error', 'Data Disposal Peti gagal dimasukan ke disposal');
}
}
/**
* Display the specified resource.
*/
12 months ago
// public function show($id)
// {
// $data = [
// 'active' => 'menu-disposal',
// ];
// return view('dashboard.Disposal.show', $data);
// }
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
12 months ago
$jenis_disposal = ['Pemusnaan', 'Perbaikan'];
$data = [
12 months ago
'disposal' => Disposal::findOrFail($id),
'peti' => Peti::get(),
'customer' => Customer::get(),
'warehouse' => m_warehouse::get(),
'active' => 'menu-disposal',
];
12 months ago
return view('dashboard.Disposal.edit', compact('jenis_disposal'), $data);
}
/**
* Update the specified resource in storage.
*/
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.
*/
public function destroy($id)
{
12 months ago
// dd("oke");
try {
$disposal = Disposal::findOrFail($id);
$disposal->delete();
return redirect()->back()->with('success', 'Data disposal peti berhasil dihapus');
} catch (\Throwable $th) {
return redirect()->back()->with('error', 'Data disposal peti gagal dihapus');
}
}
}