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.

156 lines
5.0 KiB

<?php
namespace App\Http\Controllers;
use App\Models\Peti;
use App\Models\Transfer;
use App\Models\m_warehouse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Http\Requests\Transfer\ValidasiCreateTransfer;
use App\Models\Customer;
class TransferController extends Controller
{
public function index()
{
$data = [
'transfer' => Transfer::all(),
'active' => 'menu-transfer',
];
return view('dashboard.Transfer.index', $data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$data = [
'customer' => Customer::get(),
'peti' => Peti::get(),
// 'warehouse' => Peti::with('warehouse_id')->get(),
'warehouse' => m_warehouse::get(),
'active' => 'menu-transfer',
];
return view('dashboard.Transfer.create', $data);
}
/**
* Store a newly created resource in storage.
*/
// public function store(ValidasiCreateTransfer $request)
// {
// try {
// $currenttype = Auth::user();
// $validatedData = $request->except('_token');
// $validatedData['created_by'] = $currenttype->fullname; // Menggunakan nama pengguna sebagai created_by
// $validatedData['updated_by'] = $currenttype->fullname; // Menggunakan nama pengguna sebagai updated_by
// // dd($validatedData);
// Transfer::create($validatedData);
// return redirect()->route('dashboard.transfer.index')->with('success', 'Data Transfer Peti berhasil ditambahkan');
// } catch (\Throwable $th) {
// // dd($th->getMessage());
// return redirect()->back()->with('error', 'Data Transfer Peti Gagal Ditambah.');
// }
// }
// public function store(ValidasiCreateTransfer $request)
// {
// try {
// $currenttype = Auth::user();
// $validatedData = $request->except('_token');
// $validatedData['created_by'] = $currenttype->fullname;
// $validatedData['updated_by'] = $currenttype->fullname;
// // Membuat entitas Transfer
// $transfer = Transfer::create($validatedData);
// // Update kolom di tabel 'petis'
// Peti::where('customer_id', $transfer->customer_id)
// ->update(['customer_id' => $transfer->customer_id]);
// Peti::where('warehouse_id', $transfer->destination_warehouse)
// ->update(['warehouse_id' => $transfer->destination_warehouse]);
// return redirect()->route('dashboard.transfer.index')->with('success', 'Data Transfer Peti berhasil ditambahkan');
// } catch (\Throwable $th) {
// return redirect()->back()->with('error', 'Data Transfer Peti Gagal Ditambah.');
// }
// }
public function store(ValidasiCreateTransfer $request)
{
try {
$currenttype = Auth::user();
$validatedData = $request->except('_token');
$validatedData['created_by'] = $currenttype->fullname;
$validatedData['updated_by'] = $currenttype->fullname;
// Membuat entitas Transfer
$transfer = Transfer::create([
'name_customer' => $request->name_customer,
'peti_id' => $request->peti_id,
'source_warehouse' => $request->source_warehouse,
'destination_warehouse' => $request->destination_warehouse,
]);
// Mengupdate warehouse_id pada model Peti
$peti = Peti::where('id', $transfer->peti_id)
->update(['warehouse_id' => $transfer->destination_warehouse]);
// dd($peti);
return redirect()->route('dashboard.transfer.index')->with('success', 'Data Transfer Peti berhasil ditambahkan');
} catch (\Throwable $th) {
return redirect()->back()->withErrors($th->getMessage());
}
}
/**
* Display the specified resource.
*/
public function show($id)
{
$data = [
'active' => 'menu-transfer',
];
return view('dashboard.Transfer.show', $data);
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$data = [
'active' => 'menu-transfer',
];
return view('dashboard.Transfer.edit', $data);
}
/**
* Update the specified resource in storage.
*/
public function update($request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
// try {
// $typepeti = Peti::findOrFail($id);
// $typepeti->delete();
// return redirect()->back()->with('success', 'Data peti berhasil dihapus');
// } catch (\Throwable $th) {
// return redirect()->back()->with('error', 'Data peti gagal dihapus');
// }
}
}