Browse Source

perbaikan peminjaman dan pengembalian

master
Gunawan19621 1 year 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\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.');
}
}

9
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();

6
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.',
];
}
}

15
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.',
];
}
}

9
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');
}
}

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->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();

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

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

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

@ -55,11 +55,14 @@
@endforeach
</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>
<input class="form-control" name="kondisi_peti" type="text" id="kondisi_peti"
value="{{ old('kondisi_peti', $peminjaman->kondisi_peti) }}" placeholder="Masukan kondisi peti"
pattern="[^0-9]+" oninput="this.value=this.value.replace(/[0-9]/g,'');" required>
<select class="form-control" name="kondisi_peti_id" type="text" id="kondisi_peti_id" required>
<option disabled selected>Pilih Kondisi Peti</option>
@foreach ($kondisiPeti as $data_kondisiPeti)
<option value="{{ $data_kondisiPeti->id }}">{{ $data_kondisiPeti->nama_kondisi }}</option>
@endforeach
</select>
</div>
<div class="modal-footer d-flex justify-content-center">
<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>
@if ($data->kondisi_peti)
{{ $data->kondisi_peti }}
{{ $data->kondisi_peti_id }}
@else
<p class="text-center font-weight-bold">-</p>
@endif

Loading…
Cancel
Save