Browse Source

update transfer jangan merubah data peti

master
Gunawan19621 1 year ago
parent
commit
d9b48c78d5
  1. 3
      app/Http/Controllers/DisposalController.php
  2. 86
      app/Http/Controllers/TransferController.php
  3. 11
      resources/views/dashboard/Transfer/edit.blade.php

3
app/Http/Controllers/DisposalController.php

@ -17,7 +17,8 @@ class DisposalController extends Controller
public function index() public function index()
{ {
$data = [ $data = [
'disposal' => Disposal::orderBy('created_at', 'desc')->get(), 'disposal' => Disposal::where('status_disposal', 'INAKTIF')->orderBy('created_at', 'desc')->get(),
// 'disposal' => Disposal::orderBy('created_at', 'desc')->get(),
'active' => 'menu-disposal', 'active' => 'menu-disposal',
]; ];
return view('dashboard.Disposal.index', $data); return view('dashboard.Disposal.index', $data);

86
app/Http/Controllers/TransferController.php

@ -64,22 +64,44 @@ class TransferController extends Controller
$validatedData['updated_by'] = $currentUser->fullname; $validatedData['updated_by'] = $currentUser->fullname;
// Membuat entitas Transfer // Membuat entitas Transfer
$transfer = Transfer::create($validatedData); 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'); return redirect()->route('dashboard.transfer.index')->with('success', 'Data Transfer Peti berhasil ditambahkan');
} catch (\Throwable $th) { } catch (\Throwable $th) {
return redirect()->back()->with('error', 'Data Transfer Peti gagal ditransfer'); 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');
// }
// }
/** /**
* Display the specified resource. * Display the specified resource.
@ -112,7 +134,7 @@ class TransferController extends Controller
*/ */
public function update(ValidasiUpdateTransfer $request, $id) public function update(ValidasiUpdateTransfer $request, $id)
{ {
// dd("oke"); // dd($request->all());
try { try {
// Mendapatkan informasi pengguna yang sedang login // Mendapatkan informasi pengguna yang sedang login
$currentUser = Auth::user(); $currentUser = Auth::user();
@ -133,18 +155,46 @@ class TransferController extends Controller
// Memperbarui data transfer // Memperbarui data transfer
$transfer->update($validatedData); $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'); return redirect()->route('dashboard.transfer.index')->with('success', 'Data Transfer Peti berhasil diperbaharui');
} catch (\Throwable $th) { } catch (\Throwable $th) {
return redirect()->back()->with('error', 'Data Transfer Peti gagal diperbaharui'); 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. * Remove the specified resource from storage.

11
resources/views/dashboard/Transfer/edit.blade.php

@ -17,7 +17,14 @@
<div class="form-group"> <div class="form-group">
<label for="peti_id" class="col-form-label">Pilih Detail Peti: <span <label for="peti_id" class="col-form-label">Pilih Detail Peti: <span
class="text-danger">*</span></label> class="text-danger">*</span></label>
<select class="form-control" name="peti_id" id="peti_id" disabled> <!-- Input tersembunyi untuk menyimpan ID -->
<input type="hidden" name="peti_id" id="peti_id" value="{{ $transfer->peti->id ?? '' }}">
<!-- Input terbaca untuk menampilkan nama -->
<input type="text" class="form-control" value="{{ $transfer->peti->fix_lot ?? '' }}" readonly>
{{-- <select class="form-control" name="peti_id" id="peti_id" disabled>
<option disabled selected>Pilih Detail Peti</option> <option disabled selected>Pilih Detail Peti</option>
@foreach ($peti as $data_peti) @foreach ($peti as $data_peti)
<option value="{{ $data_peti->id }}" <option value="{{ $data_peti->id }}"
@ -25,7 +32,7 @@
{{ $data_peti->fix_lot }} {{ $data_peti->fix_lot }}
</option> </option>
@endforeach @endforeach
</select> </select> --}}
<label for="date" class="col-form-label">Tanggal Transfer: <span <label for="date" class="col-form-label">Tanggal Transfer: <span
class="text-danger">*</span></label> class="text-danger">*</span></label>

Loading…
Cancel
Save