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.

132 lines
4.1 KiB

12 months ago
<?php
namespace App\Http\Controllers;
use App\Http\Requests\ValidasiCreateWarehouse;
use App\Http\Requests\ValidasiUpdateWarehouse;
12 months ago
use App\Models\m_warehouse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
12 months ago
class WarehouseController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
11 months ago
$data = [
'warehouses' => m_warehouse::all(),
'active' => 'menu-warehouse',
];
return view('dashboard.Master_Data.Warehouse.index', $data);
12 months ago
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
11 months ago
// return view('dashboard.Master_Data.Warehouse.create');
12 months ago
}
/**
* Store a newly created resource in storage.
*/
public function store(ValidasiCreateWarehouse $request)
12 months ago
{
try {
$currentUser = Auth::user();
// Ambil nomor urutan otomatis untuk id_incre
$latestRecord = m_warehouse::latest()->first();
$nextIdIncre = ($latestRecord) ? $latestRecord->id_incre + 1 : 1;
12 months ago
$validatedData = $request->except('_token');
$validatedData['created_by'] = $currentUser->fullname;
$validatedData['updated_by'] = $currentUser->fullname;
$validatedData['id_incre'] = $nextIdIncre;
12 months ago
m_warehouse::create($validatedData);
12 months ago
return redirect()->back()->with('success', 'Data gudang berhasil ditambah.');
} catch (\Throwable $th) {
return redirect()->back()->with('error', 'Data gudang gagal ditambah.');
}
}
// public function store(ValidasiCreateWarehouse $request)
// {
// try {
// $currentUser = Auth::user();
// // Ambil nomor urutan otomatis untuk id_incre
// $nextIdIncre = m_warehouse::max('id_incre') + 1;
// $validatedData = $request->except('_token');
// $validatedData['created_by'] = $currentUser->fullname; // Menggunakan nama pengguna sebagai created_by
// $validatedData['updated_by'] = $currentUser->fullname; // Menggunakan nama pengguna sebagai updated_by
// // Set nilai id_incre sebelum membuat entri
// $validatedData['id_incre'] = $nextIdIncre;
// m_warehouse::create($validatedData);
// return redirect()->back()->with('success', 'Data gudang berhasil ditambah.');
// } catch (\Throwable $th) {
// return redirect()->back()->with('error', 'Data gudang gagal ditambah.');
// }
// return redirect()->back()->with('success', 'Data gudang berhasil ditambah.');
// }
12 months ago
/**
* Display the specified resource.
*/
public function show($id)
{
// dd('oke');
11 months ago
// return view('dashboard.Master_Data.Warehouse.show');
12 months ago
}
/**
* Show the form for editing the specified resource.
*/
public function edit()
{
// dd('oke');
11 months ago
// return view('dashboard.Master_Data.Warehouse.edit');
12 months ago
}
/**
* Update the specified resource in storage.
*/
public function update(ValidasiUpdateWarehouse $request, $id)
12 months ago
{
try {
$warehouse = m_warehouse::findOrFail($id);
$warehouse->update($request->all());
// Menambahkan nama pengguna yang melakukan pembaruan
$userData['updated_by'] = Auth::user()->fullname;
return redirect()->back()->with('success', 'Data Gudang Berhasil Diperbaharui');
} catch (\Throwable $th) {
return redirect()->back()->with('error', 'Data Gudang Gagal Diperbaharui');
}
12 months ago
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
// dd("oke");
try {
$asset = m_warehouse::findOrFail($id);
$asset->delete();
return redirect()->back()->with('success', 'Data Gudang berhasil dihapus');
} catch (\Throwable $th) {
return redirect()->back()->with('error', 'Data Gudang gagal dihapus');
}
}
}