Browse Source

perbaikan peminjaman dan pengembalian

master
Gunawan19621 12 months ago
parent
commit
069eff5b69
  1. 7
      app/Http/Controllers/PeminjamanController.php
  2. 9
      app/Http/Controllers/PengembalianController.php
  3. 6
      app/Http/Requests/ValidasiCreatePeminjaman.php
  4. 15
      app/Http/Requests/ValidasiUpdatePengembalian.php
  5. 9
      app/Models/asset_status.php
  6. 4
      database/migrations/2023_11_06_122033_create_asset_statuses_table.php
  7. 18
      resources/views/dashboard/Peminjaman/create.blade.php
  8. 11
      resources/views/dashboard/Pengembalian/edit.blade.php
  9. 2
      resources/views/dashboard/Pengembalian/index.blade.php

7
app/Http/Controllers/PeminjamanController.php

@ -7,6 +7,7 @@ use App\Http\Requests\ValidasiUpdatePeminjaman;
use App\Models\Peti; use App\Models\Peti;
use App\Models\m_warehouse; use App\Models\m_warehouse;
use App\Models\asset_status; use App\Models\asset_status;
use App\Models\Customer;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Symfony\Component\Uid\Uuid; use Symfony\Component\Uid\Uuid;
@ -37,10 +38,10 @@ class PeminjamanController extends Controller
'peti' => Peti::all(), 'peti' => Peti::all(),
'peminjaman' => asset_status::get(), 'peminjaman' => asset_status::get(),
'warehouse' => m_warehouse::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 ->where('status', 'AKTIF') // Sesuaikan dengan nama kolom yang benar
->get(), ->get(),
'customer' => Customer::get(),
'existingPeti' => asset_status::pluck('peti_id')->toArray(), 'existingPeti' => asset_status::pluck('peti_id')->toArray(),
'active' => 'menu-peminjaman', 'active' => 'menu-peminjaman',
]; ];
@ -52,6 +53,7 @@ class PeminjamanController extends Controller
*/ */
public function store(ValidasiCreatePeminjaman $request) public function store(ValidasiCreatePeminjaman $request)
{ {
// dd($request);
try { try {
$currentUser = Auth::user(); $currentUser = Auth::user();
@ -65,6 +67,7 @@ class PeminjamanController extends Controller
asset_status::create($validatedData); asset_status::create($validatedData);
return redirect()->route('dashboard.peminjaman.index')->with('success', 'Data peminjaman berhasil ditambah.'); return redirect()->route('dashboard.peminjaman.index')->with('success', 'Data peminjaman berhasil ditambah.');
} catch (\Throwable $th) { } catch (\Throwable $th) {
dd($th->getMessage()); // Tampilkan pesan kesalahan
return redirect()->back()->with('error', 'Data peminjaman gagal ditambah.'); return redirect()->back()->with('error', 'Data peminjaman gagal ditambah.');
} }
} }

9
app/Http/Controllers/PengembalianController.php

@ -6,6 +6,7 @@ use App\Http\Requests\ValidasiUpdatePengembalian;
use App\Models\Peti; use App\Models\Peti;
use App\Models\m_warehouse; use App\Models\m_warehouse;
use App\Models\asset_status; use App\Models\asset_status;
use App\Models\Kondisi_Peti;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
@ -58,6 +59,7 @@ class PengembalianController extends Controller
'peti' => Peti::get(), 'peti' => Peti::get(),
'peminjaman' => asset_status::findOrFail($id), 'peminjaman' => asset_status::findOrFail($id),
'warehouse' => m_warehouse::get(), 'warehouse' => m_warehouse::get(),
'kondisiPeti' => Kondisi_Peti::get(),
'active' => 'menu-pengembalian', 'active' => 'menu-pengembalian',
]; ];
return view('dashboard.Pengembalian.edit', $data); return view('dashboard.Pengembalian.edit', $data);
@ -68,6 +70,7 @@ class PengembalianController extends Controller
*/ */
public function update(ValidasiUpdatePengembalian $request, $id) public function update(ValidasiUpdatePengembalian $request, $id)
{ {
// dd($request);
try { try {
$peminjaman = asset_status::findOrFail($id); $peminjaman = asset_status::findOrFail($id);
@ -81,9 +84,9 @@ class PengembalianController extends Controller
$peminjaman->exit_warehouse = $request->input('exit_warehouse'); $peminjaman->exit_warehouse = $request->input('exit_warehouse');
$peminjaman->enter_at = $request->input('enter_at'); $peminjaman->enter_at = $request->input('enter_at');
$peminjaman->enter_warehouse = $request->input('enter_warehouse'); $peminjaman->enter_warehouse = $request->input('enter_warehouse');
$peminjaman->kondisi_peti = $request->input('kondisi_peti'); $peminjaman->kondisi_peti_id = $request->input('kondisi_peti_id');
// Mengatur status menjadi 0 secara otomatis // Mengatur status menjadi 1 secara otomatis
$peminjaman->status = 0; $peminjaman->status = 1;
// dd($peminjaman); // dd($peminjaman);
$peminjaman->save(); $peminjaman->save();

6
app/Http/Requests/ValidasiCreatePeminjaman.php

@ -22,10 +22,10 @@ class ValidasiCreatePeminjaman extends FormRequest
public function rules(): array public function rules(): array
{ {
return [ 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', 'exit_at' => 'required|date',
'est_pengembalian' => 'required|date', // Estimasi pengembalian harus setelah exit_at '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 [ return [
'peti_id.required' => 'Bidang Detail Peti wajib diisi.', '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.required' => 'Bidang Tanggal Peminjaman wajib diisi.',
'exit_at.date' => 'Bidang Tanggal Peminjaman harus berupa tanggal.', 'exit_at.date' => 'Bidang Tanggal Peminjaman harus berupa tanggal.',
'est_pengembalian.required' => 'Bidang Estimasi Tanggal Pengembalian wajib diisi.', 'est_pengembalian.required' => 'Bidang Estimasi Tanggal Pengembalian wajib diisi.',
'est_pengembalian.date' => 'Bidang Estimasi Tanggal Pengembalian harus berupa tanggal.', 'est_pengembalian.date' => 'Bidang Estimasi Tanggal Pengembalian harus berupa tanggal.',
'exit_warehouse.required' => 'Bidang Asal Gudang wajib diisi.', 'exit_warehouse.required' => 'Bidang Asal Gudang wajib diisi.',
'exit_warehouse.integer' => 'Bidang Asal Gudang harus berupa angka.',
]; ];
} }
} }

15
app/Http/Requests/ValidasiUpdatePengembalian.php

@ -22,13 +22,13 @@ class ValidasiUpdatePengembalian extends FormRequest
public function rules(): array public function rules(): array
{ {
return [ return [
'peti_id' => 'required', 'peti_id' => 'required|integer',
'exit_at' => 'required|date', 'exit_at' => 'required|date',
'est_pengembalian' => 'required|date', 'est_pengembalian' => 'required|date',
'exit_warehouse' => 'required', 'exit_warehouse' => 'required|integer',
'enter_at' => 'required|date', 'enter_at' => 'required|date',
'enter_warehouse' => 'required', 'enter_warehouse' => 'required|integer',
'kondisi_peti' => 'required|string', 'kondisi_peti_id' => 'required|integer',
'status' => '', 'status' => '',
]; ];
} }
@ -37,16 +37,19 @@ class ValidasiUpdatePengembalian extends FormRequest
{ {
return [ return [
'peti_id.required' => 'Kolom peti_id wajib diisi.', '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.required' => 'Kolom exit_at wajib diisi.',
'exit_at.date' => 'Kolom exit_at harus berupa tanggal.', 'exit_at.date' => 'Kolom exit_at harus berupa tanggal.',
'est_pengembalian.required' => 'Kolom est_pengembalian wajib diisi.', 'est_pengembalian.required' => 'Kolom est_pengembalian wajib diisi.',
'est_pengembalian.date' => 'Kolom est_pengembalian harus berupa tanggal.', 'est_pengembalian.date' => 'Kolom est_pengembalian harus berupa tanggal.',
'exit_warehouse.required' => 'Kolom exit_warehouse wajib diisi.', '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.required' => 'Kolom enter_at wajib diisi.',
'enter_at.date' => 'Kolom enter_at harus berupa tanggal.', 'enter_at.date' => 'Kolom enter_at harus berupa tanggal.',
'enter_warehouse.required' => 'Kolom enter_warehouse wajib diisi.', 'enter_warehouse.required' => 'Kolom enter_warehouse wajib diisi.',
'kondisi_peti.required' => 'Kolom kondisi_peti wajib diisi.', 'enter_warehouse.integer' => 'Kolom enter_warehouse harus berupa angka.',
'kondisi_peti.string' => 'Kolom kondisi_peti harus berupa teks.', 'kondisi_peti_id.required' => 'Kolom kondisi_peti_id wajib diisi.',
'kondisi_peti_id.integer' => 'Kolom kondisi_peti_id harus berupa angka.',
]; ];
} }
} }

9
app/Models/asset_status.php

@ -11,7 +11,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
class asset_status extends Model class asset_status extends Model
{ {
use HasFactory, UUID; use HasFactory;
protected $table = 'asset_statuses'; protected $table = 'asset_statuses';
protected $fillable = [ protected $fillable = [
@ -24,7 +24,7 @@ class asset_status extends Model
'enter_at', 'enter_at',
'enter_pic', 'enter_pic',
'enter_warehouse', 'enter_warehouse',
'kondisi_peti', 'kondisi_peti_id',
'status', 'status',
'created_by', 'created_by',
'updated_by', 'updated_by',
@ -59,4 +59,9 @@ class asset_status extends Model
{ {
return $this->belongsTo(Customer::class, 'customer_id'); return $this->belongsTo(Customer::class, 'customer_id');
} }
public function kondisi_peti()
{
return $this->belongsTo(kondisi_peti::class, 'kondisi_peti_id');
}
} }

4
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->date('enter_at')->nullable();
$table->string('enter_pic', 200)->nullable(); $table->string('enter_pic', 200)->nullable();
$table->foreignId('enter_warehouse')->nullable()->constrained('m_warehouses'); $table->foreignId('enter_warehouse')->nullable()->constrained('m_warehouses');
$table->string('kondisi_peti')->nullable(); $table->foreignId('kondisi_peti_id')->nullable()->constrained('kondisi_petis');
$table->boolean('status')->default(1); $table->boolean('status')->default(0);
$table->timestamps(); $table->timestamps();
$table->softDeletes(); $table->softDeletes();
$table->string('created_by', 200)->nullable(); $table->string('created_by', 200)->nullable();

18
resources/views/dashboard/Peminjaman/create.blade.php

@ -27,9 +27,8 @@
@endforeach @endforeach
</select> </select>
<label for="name" class="col-form-label">Customer:</label> <label for="name" class="col-form-label">Customer:<span class="text-danger">*</span></label>
<input class="form-control" name="name" type="text" id="name" placeholder="Nama Customer" <input class="form-control" name="name" type="text" id="name" placeholder="Nama Customer">
readonly>
<label for="exit_at" class="col-form-label">Tanggal Peminjaman: <span <label for="exit_at" class="col-form-label">Tanggal Peminjaman: <span
class="text-danger">*</span></label> class="text-danger">*</span></label>
@ -40,10 +39,17 @@
class="text-danger">*</span></label> class="text-danger">*</span></label>
<input class="form-control" name="est_pengembalian" type="date" id="est_pengembalian" required> <input class="form-control" name="est_pengembalian" type="date" id="est_pengembalian" required>
<label for="exit_warehouse" class="col-form-label">Asal Gudang: <span <label for="warehouse" class="col-form-label">Asal Gudang:</label>
<select class="form-control" name="warehouse" type="text" id="warehouse" required>
<option disabled selected>Pilih Asal Gudang</option>
@foreach ($warehouse as $data)
<option value="{{ $data->id }}">{{ $data->name }}</option>
@endforeach
</select>
<label for="exit_warehouse" class="col-form-label">Tujuan Gudang: <span
class="text-danger">*</span></label> class="text-danger">*</span></label>
<select class="form-control" name="exit_warehouse" type="text" id="exit_warehouse" required> <select class="form-control" name="exit_warehouse" type="text" id="exit_warehouse" required>
<option disabled selected>Pilih Asal Gudang</option> <option disabled selected>Pilih Tujuan Gudang</option>
@foreach ($warehouse as $data) @foreach ($warehouse as $data)
<option value="{{ $data->id }}">{{ $data->name }}</option> <option value="{{ $data->id }}">{{ $data->name }}</option>
@endforeach @endforeach
@ -92,7 +98,7 @@
const petiSelect = document.getElementById('peti_id'); const petiSelect = document.getElementById('peti_id');
// Mendapatkan elemen select asal gudang // Mendapatkan elemen select asal gudang
const exitWarehouseSelect = document.getElementById('exit_warehouse'); const exitWarehouseSelect = document.getElementById('warehouse');
// Mendapatkan elemen input Customer // Mendapatkan elemen input Customer
const nameInput = document.getElementById('name'); const nameInput = document.getElementById('name');

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

@ -55,11 +55,14 @@
@endforeach @endforeach
</select> </select>
<label for="kondisi_peti" class="col-form-label">Kondisi Peti: <span <label for="kondisi_peti_id" class="col-form-label">Kondisi Peti: <span
class="text-danger">*</span></label> class="text-danger">*</span></label>
<input class="form-control" name="kondisi_peti" type="text" id="kondisi_peti" <select class="form-control" name="kondisi_peti_id" type="text" id="kondisi_peti_id" required>
value="{{ old('kondisi_peti', $peminjaman->kondisi_peti) }}" placeholder="Masukan kondisi peti" <option disabled selected>Pilih Kondisi Peti</option>
pattern="[^0-9]+" oninput="this.value=this.value.replace(/[0-9]/g,'');" required> @foreach ($kondisiPeti as $data_kondisiPeti)
<option value="{{ $data_kondisiPeti->id }}">{{ $data_kondisiPeti->nama_kondisi }}</option>
@endforeach
</select>
</div> </div>
<div class="modal-footer d-flex justify-content-center"> <div class="modal-footer d-flex justify-content-center">
<a href="{{ route('dashboard.peminjaman.index') }}" class="btn btn-secondary">Kembali</a> <a href="{{ route('dashboard.peminjaman.index') }}" class="btn btn-secondary">Kembali</a>

2
resources/views/dashboard/Pengembalian/index.blade.php

@ -76,7 +76,7 @@
</td> </td>
<td> <td>
@if ($data->kondisi_peti) @if ($data->kondisi_peti)
{{ $data->kondisi_peti }} {{ $data->kondisi_peti_id }}
@else @else
<p class="text-center font-weight-bold">-</p> <p class="text-center font-weight-bold">-</p>
@endif @endif

Loading…
Cancel
Save