|
|
|
@ -75,44 +75,21 @@ class TransferController extends Controller
|
|
|
|
|
$validatedData['updated_by'] = $currentUser->fullname; |
|
|
|
|
|
|
|
|
|
// Membuat entitas Transfer |
|
|
|
|
Transfer::create($validatedData); |
|
|
|
|
$transfer = Transfer::create($validatedData); |
|
|
|
|
// dd($transfer); |
|
|
|
|
// Mengupdate warehouse_id pada model Peti |
|
|
|
|
Peti::where('id', $transfer->peti_id) |
|
|
|
|
->update([ |
|
|
|
|
't_warehouse_id' => $transfer->destination_warehouse, |
|
|
|
|
'updated_by' => $currentUser->fullname, |
|
|
|
|
// 'customer_id' => $transfer->name_customer, // tambahan update customer id |
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
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 ditransfer'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//proses tambah data transfer beserta update data peti |
|
|
|
|
// public function store(ValidasiCreateTransfer $request) |
|
|
|
|
// { |
|
|
|
|
// // dd($request); |
|
|
|
|
// 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 |
|
|
|
|
// $validatedData['created_by'] = $currentUser->fullname; |
|
|
|
|
// $validatedData['updated_by'] = $currentUser->fullname; |
|
|
|
|
|
|
|
|
|
// // Membuat entitas Transfer |
|
|
|
|
// $transfer = Transfer::create($validatedData); |
|
|
|
|
// // dd($transfer); |
|
|
|
|
// // Mengupdate warehouse_id pada model Peti |
|
|
|
|
// Peti::where('id', $transfer->peti_id) |
|
|
|
|
// ->update([ |
|
|
|
|
// 'warehouse_id' => $transfer->destination_warehouse, |
|
|
|
|
// 'customer_id' => $transfer->name_customer, // tambahan update customer id |
|
|
|
|
// ]); |
|
|
|
|
|
|
|
|
|
// 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 ditransfer'); |
|
|
|
|
// } |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Show the form for editing the specified resource. |
|
|
|
@ -155,46 +132,19 @@ class TransferController extends Controller
|
|
|
|
|
// Memperbarui data transfer |
|
|
|
|
$transfer->update($validatedData); |
|
|
|
|
|
|
|
|
|
// Mengupdate warehouse_id pada model Peti |
|
|
|
|
Peti::where('id', $transfer->peti_id) |
|
|
|
|
->update([ |
|
|
|
|
't_warehouse_id' => $transfer->destination_warehouse, |
|
|
|
|
// 'customer_id' => $transfer->name_customer, |
|
|
|
|
'updated_by' => $currentUser->fullname, |
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
return redirect()->route('dashboard.transfer.index')->with('success', 'Data Transfer Peti berhasil diperbaharui'); |
|
|
|
|
} catch (\Throwable $th) { |
|
|
|
|
return redirect()->back()->with('error', 'Data Transfer Peti gagal diperbaharui'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//proses tambah data transfer beserta update data peti |
|
|
|
|
// public function update(ValidasiUpdateTransfer $request, $id) |
|
|
|
|
// { |
|
|
|
|
// 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 |
|
|
|
|
// $transfer = Transfer::find($id); |
|
|
|
|
|
|
|
|
|
// if (!$transfer) { |
|
|
|
|
// return redirect()->route('dashboard.transfer.index')->with('error', 'Data Transfer Peti tidak ditemukan'); |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
// // Memperbarui data transfer |
|
|
|
|
// $transfer->update($validatedData); |
|
|
|
|
|
|
|
|
|
// // Mengupdate warehouse_id pada model Peti |
|
|
|
|
// Peti::where('id', $transfer->peti_id) |
|
|
|
|
// ->update([ |
|
|
|
|
// 'warehouse_id' => $transfer->destination_warehouse, |
|
|
|
|
// 'customer_id' => $transfer->name_customer, |
|
|
|
|
// ]); |
|
|
|
|
|
|
|
|
|
// return redirect()->route('dashboard.transfer.index')->with('success', 'Data Transfer Peti berhasil diperbaharui'); |
|
|
|
|
// } catch (\Throwable $th) { |
|
|
|
|
// return redirect()->back()->with('error', 'Data Transfer Peti gagal diperbaharui'); |
|
|
|
|
// } |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Remove the specified resource from storage. |
|
|
|
@ -268,7 +218,7 @@ class TransferController extends Controller
|
|
|
|
|
$petiId = $request->get('peti_id'); |
|
|
|
|
|
|
|
|
|
// Fetch customer data and warehouse based on the selected peti |
|
|
|
|
$peti = Peti::with(['customer', 'warehouse']) |
|
|
|
|
$peti = Peti::with(['customer', 't_warehouse']) |
|
|
|
|
->where('id', $petiId) |
|
|
|
|
->first(); |
|
|
|
|
|
|
|
|
@ -289,16 +239,16 @@ class TransferController extends Controller
|
|
|
|
|
$selectedCustomer = $peti->customer->id; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($peti && $peti->warehouse) { |
|
|
|
|
if ($peti && $peti->t_warehouse) { |
|
|
|
|
// Extract warehouse data from the related relationship |
|
|
|
|
$warehouseData[] = [ |
|
|
|
|
'id' => $peti->warehouse->id, |
|
|
|
|
'name' => $peti->warehouse->name, |
|
|
|
|
'id' => $peti->t_warehouse->id, |
|
|
|
|
'name' => $peti->t_warehouse->name, |
|
|
|
|
// Add any other fields you want to include |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
// Set the selectedWarehouse to the warehouse id |
|
|
|
|
$selectedWarehouse = $peti->warehouse->id; |
|
|
|
|
$selectedWarehouse = $peti->t_warehouse->id; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return response()->json([ |
|
|
|
|