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.

115 lines
3.1 KiB

10 months ago
<?php
namespace App\Http\Controllers;
use App\Models\Peti;
10 months ago
use App\Models\Customer;
10 months ago
use App\Models\m_warehouse;
use Illuminate\Http\Request;
10 months ago
use Illuminate\Support\Facades\Auth;
use App\Http\Requests\Disposal\ValidasiCreateDisposal;
use App\Models\Disposal;
10 months ago
class DisposalController extends Controller
{
public function index()
{
$data = [
10 months ago
'disposal' => Disposal::all(),
10 months ago
'active' => 'menu-disposal',
];
return view('dashboard.Disposal.index', $data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$data = [
'peti' => Peti::get(),
'warehouse' => m_warehouse::get(),
10 months ago
'customer' => Customer::get(),
10 months ago
'active' => 'menu-disposal',
];
return view('dashboard.Disposal.create', $data);
}
/**
* Store a newly created resource in storage.
*/
10 months ago
public function store(ValidasiCreateDisposal $request)
10 months ago
{
10 months ago
// dd($request->all());
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['created_by'] = $currentUser->fullname;
$validatedData['updated_by'] = $currentUser->fullname;
// Membuat entitas Transfer
Disposal::create($validatedData);
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');
}
10 months ago
}
/**
* Display the specified resource.
*/
10 months ago
// public function show($id)
// {
// $data = [
// 'active' => 'menu-disposal',
// ];
// return view('dashboard.Disposal.show', $data);
// }
10 months ago
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
10 months ago
$jenis_disposal = ['Pemusnaan', 'Perbaikan'];
10 months ago
$data = [
10 months ago
'disposal' => Disposal::findOrFail($id),
'peti' => Peti::get(),
'customer' => Customer::get(),
'warehouse' => m_warehouse::get(),
10 months ago
'active' => 'menu-disposal',
];
10 months ago
return view('dashboard.Disposal.edit', compact('jenis_disposal'), $data);
10 months ago
}
/**
* Update the specified resource in storage.
*/
10 months ago
// public function update($request, $id)
// {
// //
// }
10 months ago
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
10 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');
}
10 months ago
}
}