From 069eff5b6955f6748f55fc8c19be7b64ae6318fb Mon Sep 17 00:00:00 2001 From: Gunawan19621 Date: Thu, 23 Nov 2023 22:37:08 +0700 Subject: [PATCH] perbaikan peminjaman dan pengembalian --- app/Http/Controllers/PeminjamanController.php | 7 +++++-- .../Controllers/PengembalianController.php | 9 ++++++--- app/Http/Requests/ValidasiCreatePeminjaman.php | 6 ++++-- .../Requests/ValidasiUpdatePengembalian.php | 15 +++++++++------ app/Models/asset_status.php | 9 +++++++-- ...1_06_122033_create_asset_statuses_table.php | 4 ++-- .../dashboard/Peminjaman/create.blade.php | 18 ++++++++++++------ .../dashboard/Pengembalian/edit.blade.php | 11 +++++++---- .../dashboard/Pengembalian/index.blade.php | 2 +- 9 files changed, 53 insertions(+), 28 deletions(-) diff --git a/app/Http/Controllers/PeminjamanController.php b/app/Http/Controllers/PeminjamanController.php index 1406303..04df902 100644 --- a/app/Http/Controllers/PeminjamanController.php +++ b/app/Http/Controllers/PeminjamanController.php @@ -7,6 +7,7 @@ use App\Http\Requests\ValidasiUpdatePeminjaman; use App\Models\Peti; use App\Models\m_warehouse; use App\Models\asset_status; +use App\Models\Customer; use Illuminate\Support\Facades\Auth; use Symfony\Component\Uid\Uuid; @@ -37,10 +38,10 @@ class PeminjamanController extends Controller 'peti' => Peti::all(), 'peminjaman' => asset_status::get(), 'warehouse' => m_warehouse::get(), - 'peti_block' => Peti::whereNotIn('id', asset_status::where('status', 1)->pluck('peti_id')->toArray()) + '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', ]; @@ -52,6 +53,7 @@ class PeminjamanController extends Controller */ public function store(ValidasiCreatePeminjaman $request) { + // dd($request); try { $currentUser = Auth::user(); @@ -65,6 +67,7 @@ class PeminjamanController extends Controller asset_status::create($validatedData); return redirect()->route('dashboard.peminjaman.index')->with('success', 'Data peminjaman berhasil ditambah.'); } catch (\Throwable $th) { + dd($th->getMessage()); // Tampilkan pesan kesalahan return redirect()->back()->with('error', 'Data peminjaman gagal ditambah.'); } } diff --git a/app/Http/Controllers/PengembalianController.php b/app/Http/Controllers/PengembalianController.php index 8a5c009..3ea8aaf 100644 --- a/app/Http/Controllers/PengembalianController.php +++ b/app/Http/Controllers/PengembalianController.php @@ -6,6 +6,7 @@ use App\Http\Requests\ValidasiUpdatePengembalian; use App\Models\Peti; use App\Models\m_warehouse; use App\Models\asset_status; +use App\Models\Kondisi_Peti; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; @@ -58,6 +59,7 @@ class PengembalianController extends Controller 'peti' => Peti::get(), 'peminjaman' => asset_status::findOrFail($id), 'warehouse' => m_warehouse::get(), + 'kondisiPeti' => Kondisi_Peti::get(), 'active' => 'menu-pengembalian', ]; return view('dashboard.Pengembalian.edit', $data); @@ -68,6 +70,7 @@ class PengembalianController extends Controller */ public function update(ValidasiUpdatePengembalian $request, $id) { + // dd($request); try { $peminjaman = asset_status::findOrFail($id); @@ -81,9 +84,9 @@ class PengembalianController extends Controller $peminjaman->exit_warehouse = $request->input('exit_warehouse'); $peminjaman->enter_at = $request->input('enter_at'); $peminjaman->enter_warehouse = $request->input('enter_warehouse'); - $peminjaman->kondisi_peti = $request->input('kondisi_peti'); - // Mengatur status menjadi 0 secara otomatis - $peminjaman->status = 0; + $peminjaman->kondisi_peti_id = $request->input('kondisi_peti_id'); + // Mengatur status menjadi 1 secara otomatis + $peminjaman->status = 1; // dd($peminjaman); $peminjaman->save(); diff --git a/app/Http/Requests/ValidasiCreatePeminjaman.php b/app/Http/Requests/ValidasiCreatePeminjaman.php index e461f31..42a0eee 100644 --- a/app/Http/Requests/ValidasiCreatePeminjaman.php +++ b/app/Http/Requests/ValidasiCreatePeminjaman.php @@ -22,10 +22,10 @@ class ValidasiCreatePeminjaman extends FormRequest public function rules(): array { return [ - 'peti_id' => 'required', // Pastikan peti_id ada dalam tabel petis + 'peti_id' => 'required|integer', // Pastikan peti_id ada dalam tabel petis 'exit_at' => 'required|date', 'est_pengembalian' => 'required|date', // Estimasi pengembalian harus setelah exit_at - 'exit_warehouse' => 'required', + 'exit_warehouse' => 'required|integer', ]; } @@ -33,11 +33,13 @@ class ValidasiCreatePeminjaman extends FormRequest { return [ 'peti_id.required' => 'Bidang Detail Peti wajib diisi.', + 'peti_id.integer' => 'Bidang Detail Peti harus berupa angka.', 'exit_at.required' => 'Bidang Tanggal Peminjaman wajib diisi.', 'exit_at.date' => 'Bidang Tanggal Peminjaman harus berupa tanggal.', 'est_pengembalian.required' => 'Bidang Estimasi Tanggal Pengembalian wajib diisi.', 'est_pengembalian.date' => 'Bidang Estimasi Tanggal Pengembalian harus berupa tanggal.', 'exit_warehouse.required' => 'Bidang Asal Gudang wajib diisi.', + 'exit_warehouse.integer' => 'Bidang Asal Gudang harus berupa angka.', ]; } } diff --git a/app/Http/Requests/ValidasiUpdatePengembalian.php b/app/Http/Requests/ValidasiUpdatePengembalian.php index 6183ba7..9527331 100644 --- a/app/Http/Requests/ValidasiUpdatePengembalian.php +++ b/app/Http/Requests/ValidasiUpdatePengembalian.php @@ -22,13 +22,13 @@ class ValidasiUpdatePengembalian extends FormRequest public function rules(): array { return [ - 'peti_id' => 'required', + 'peti_id' => 'required|integer', 'exit_at' => 'required|date', 'est_pengembalian' => 'required|date', - 'exit_warehouse' => 'required', + 'exit_warehouse' => 'required|integer', 'enter_at' => 'required|date', - 'enter_warehouse' => 'required', - 'kondisi_peti' => 'required|string', + 'enter_warehouse' => 'required|integer', + 'kondisi_peti_id' => 'required|integer', 'status' => '', ]; } @@ -37,16 +37,19 @@ class ValidasiUpdatePengembalian extends FormRequest { return [ 'peti_id.required' => 'Kolom peti_id wajib diisi.', + 'peti_id.integer' => 'Kolom peti_id harus berupa angka.', 'exit_at.required' => 'Kolom exit_at wajib diisi.', 'exit_at.date' => 'Kolom exit_at harus berupa tanggal.', 'est_pengembalian.required' => 'Kolom est_pengembalian wajib diisi.', 'est_pengembalian.date' => 'Kolom est_pengembalian harus berupa tanggal.', 'exit_warehouse.required' => 'Kolom exit_warehouse wajib diisi.', + 'exit_warehouse.integer' => 'Kolom exit_warehouse harus berupa angka.', 'enter_at.required' => 'Kolom enter_at wajib diisi.', 'enter_at.date' => 'Kolom enter_at harus berupa tanggal.', 'enter_warehouse.required' => 'Kolom enter_warehouse wajib diisi.', - 'kondisi_peti.required' => 'Kolom kondisi_peti wajib diisi.', - 'kondisi_peti.string' => 'Kolom kondisi_peti harus berupa teks.', + 'enter_warehouse.integer' => 'Kolom enter_warehouse harus berupa angka.', + 'kondisi_peti_id.required' => 'Kolom kondisi_peti_id wajib diisi.', + 'kondisi_peti_id.integer' => 'Kolom kondisi_peti_id harus berupa angka.', ]; } } diff --git a/app/Models/asset_status.php b/app/Models/asset_status.php index e5e5a66..ce6a187 100644 --- a/app/Models/asset_status.php +++ b/app/Models/asset_status.php @@ -11,7 +11,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; class asset_status extends Model { - use HasFactory, UUID; + use HasFactory; protected $table = 'asset_statuses'; protected $fillable = [ @@ -24,7 +24,7 @@ class asset_status extends Model 'enter_at', 'enter_pic', 'enter_warehouse', - 'kondisi_peti', + 'kondisi_peti_id', 'status', 'created_by', 'updated_by', @@ -59,4 +59,9 @@ class asset_status extends Model { return $this->belongsTo(Customer::class, 'customer_id'); } + + public function kondisi_peti() + { + return $this->belongsTo(kondisi_peti::class, 'kondisi_peti_id'); + } } diff --git a/database/migrations/2023_11_06_122033_create_asset_statuses_table.php b/database/migrations/2023_11_06_122033_create_asset_statuses_table.php index 06fb07e..ccb75cc 100644 --- a/database/migrations/2023_11_06_122033_create_asset_statuses_table.php +++ b/database/migrations/2023_11_06_122033_create_asset_statuses_table.php @@ -22,8 +22,8 @@ return new class extends Migration $table->date('enter_at')->nullable(); $table->string('enter_pic', 200)->nullable(); $table->foreignId('enter_warehouse')->nullable()->constrained('m_warehouses'); - $table->string('kondisi_peti')->nullable(); - $table->boolean('status')->default(1); + $table->foreignId('kondisi_peti_id')->nullable()->constrained('kondisi_petis'); + $table->boolean('status')->default(0); $table->timestamps(); $table->softDeletes(); $table->string('created_by', 200)->nullable(); diff --git a/resources/views/dashboard/Peminjaman/create.blade.php b/resources/views/dashboard/Peminjaman/create.blade.php index 633f94d..bc894fc 100644 --- a/resources/views/dashboard/Peminjaman/create.blade.php +++ b/resources/views/dashboard/Peminjaman/create.blade.php @@ -27,9 +27,8 @@ @endforeach - - + + @@ -40,10 +39,17 @@ class="text-danger">* - + + - - +