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.

140 lines
4.7 KiB

1 year ago
<?php
namespace App\Http\Controllers;
use App\Http\Requests\ValidasiCreatePeminjaman;
use App\Http\Requests\ValidasiUpdatePeminjaman;
use App\Models\Peti;
use App\Models\m_warehouse;
use App\Models\asset_status;
use App\Models\Customer;
1 year ago
use Illuminate\Support\Facades\Auth;
use Symfony\Component\Uid\Uuid;
1 year ago
class PeminjamanController extends Controller
{
1 year ago
/**
* Display a listing of the resource.
*/
1 year ago
public function index()
{
$data = [
// 'peminjaman' => asset_status::get(),
'peminjaman' => asset_status::orderBy('created_at', 'desc')->get(),
'warehouse' => m_warehouse::get(),
'active' => 'menu-peminjaman',
];
return view('dashboard.Peminjaman.index', $data);
1 year ago
}
/**
* 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();
// $petiTransfer = Peti::where('id', $PetiId)
// ->leftJoin('category', 'product.category', '=', 'category.id')
// ->select('product.id','category.name')->first();
$data = [
// 'peti' => Peti::all(),
'peminjaman' => asset_status::get(),
'warehouse' => m_warehouse::get(),
'peti_block' => $petiWithStatusNotZeroOrEmptyAndActive,
// 'peti_block' => Peti::whereNotIn('id', asset_status::where('status', 0)->pluck('peti_id')->toArray())
// ->where('status', 'AKTIF') // Sesuaikan dengan nama kolom yang benar
// ->get(),
'customer' => Customer::get(),
'existingPeti' => asset_status::pluck('peti_id')->toArray(),
'active' => 'menu-peminjaman',
];
return view('dashboard.Peminjaman.create', $data);
1 year ago
}
/**
* Store a newly created resource in storage.
*/
public function store(ValidasiCreatePeminjaman $request)
1 year ago
{
// dd($request->all());
// dd($request);
1 year ago
try {
$currentUser = Auth::user();
$validatedData = $request->except('_token');
$validatedData['exit_pic'] = $currentUser->fullname; // Menambahkan ID pengguna sebagai created_by
$validatedData['mobile_id'] = Uuid::v4(); // Menambahkan ID Mobile
$validatedData['created_by'] = $currentUser->fullname; // Menambahkan ID pengguna sebagai created_by
$validatedData['updated_by'] = $currentUser->fullname; // Menambahkan ID pengguna sebagai updated_by
1 year ago
// dd($validatedData);
asset_status::create($validatedData);
return redirect()->route('dashboard.peminjaman.index')->with('success', 'Data peminjaman berhasil ditambah.');
1 year ago
} catch (\Throwable $th) {
dd($th->getMessage()); // Tampilkan pesan kesalahan
1 year ago
return redirect()->back()->with('error', 'Data peminjaman gagal ditambah.');
}
}
/**
* Display the specified resource.
*/
public function show($id)
{
// dd('oke');
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
1 year ago
{
$data = [
'peti' => Peti::all(),
'peminjaman' => asset_status::find($id),
'warehouse' => m_warehouse::get(),
'customer' => Customer::get(),
'active' => 'menu-peminjaman',
];
return view('dashboard.Peminjaman.edit', $data);
1 year ago
}
/**
* Update the specified resource in storage.
*/
public function update(ValidasiUpdatePeminjaman $request, $id)
1 year ago
{
// dd($request->all());
1 year ago
// dd($request);
try {
$peminjaman = asset_status::findOrFail($id);
$peminjaman['updated_by'] = Auth::user()->fullname; // Menambahkan ID pengguna sebagai updated_by
1 year ago
$peminjaman->update($request->all());
return redirect()->route('dashboard.peminjaman.index')->with('success', 'Data peminjaman berhasil diperbaharui');
1 year ago
} catch (\Throwable $th) {
return redirect()->back()->with('error', 'Data peminjaman gagal diperbaharui');
}
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
try {
$peminjaman = asset_status::findOrFail($id);
$peminjaman->delete();
return redirect()->back()->with('success', 'Data peminjaman berhasil dihapus');
} catch (\Throwable $th) {
return redirect()->back()->with('error', 'Data peminjaman gagal dihapus');
}
1 year ago
}
}