ibnu
1 year ago
33 changed files with 690 additions and 196 deletions
@ -0,0 +1,41 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace App\Http\Requests\Disposal; |
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest; |
||||||
|
|
||||||
|
class ValidasiCreateDisposal extends FormRequest |
||||||
|
{ |
||||||
|
/** |
||||||
|
* Determine if the user is authorized to make this request. |
||||||
|
*/ |
||||||
|
public function authorize(): bool |
||||||
|
{ |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get the validation rules that apply to the request. |
||||||
|
* |
||||||
|
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string> |
||||||
|
*/ |
||||||
|
public function rules(): array |
||||||
|
{ |
||||||
|
return [ |
||||||
|
'peti_id' => 'required', |
||||||
|
'customer_id' => 'nullable', |
||||||
|
'warehouse_id' => 'nullable', |
||||||
|
'date_disposal' => 'nullable|date', |
||||||
|
'description' => 'nullable|string', |
||||||
|
'status_disposal' => 'nullable', |
||||||
|
]; |
||||||
|
} |
||||||
|
|
||||||
|
public function messages(): array |
||||||
|
{ |
||||||
|
return [ |
||||||
|
'date_disposal.date' => 'Format tanggal disposal tidak valid.', |
||||||
|
'description.string' => 'Deskripsi harus berupa teks.', |
||||||
|
]; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,41 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace App\Http\Requests\Disposal; |
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest; |
||||||
|
|
||||||
|
class ValidasiUpdateDisposal extends FormRequest |
||||||
|
{ |
||||||
|
/** |
||||||
|
* Determine if the user is authorized to make this request. |
||||||
|
*/ |
||||||
|
public function authorize(): bool |
||||||
|
{ |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get the validation rules that apply to the request. |
||||||
|
* |
||||||
|
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string> |
||||||
|
*/ |
||||||
|
public function rules(): array |
||||||
|
{ |
||||||
|
return [ |
||||||
|
'peti_id' => 'required', |
||||||
|
'customer_id' => 'nullable', |
||||||
|
'warehouse_id' => 'nullable', |
||||||
|
'date_disposal' => 'nullable|date', |
||||||
|
'description' => 'nullable|string', |
||||||
|
'status_disposal' => 'nullable', |
||||||
|
]; |
||||||
|
} |
||||||
|
|
||||||
|
public function messages(): array |
||||||
|
{ |
||||||
|
return [ |
||||||
|
'date_disposal.date' => 'Format tanggal disposal tidak valid.', |
||||||
|
'description.string' => 'Deskripsi harus berupa teks.', |
||||||
|
]; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,47 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace App\Models; |
||||||
|
|
||||||
|
use App\Traits\UUID; |
||||||
|
use Illuminate\Database\Eloquent\Model; |
||||||
|
use Illuminate\Database\Eloquent\SoftDeletes; |
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory; |
||||||
|
|
||||||
|
class Disposal extends Model |
||||||
|
{ |
||||||
|
use HasFactory, SoftDeletes, UUID; |
||||||
|
protected $table = 'disposals'; |
||||||
|
|
||||||
|
protected $fillable = [ |
||||||
|
'mobile_id', |
||||||
|
'peti_id', |
||||||
|
'customer_id', |
||||||
|
'date_disposal', |
||||||
|
'warehouse_id', |
||||||
|
'description', |
||||||
|
'status_disposal', |
||||||
|
'created_by', |
||||||
|
'updated_by', |
||||||
|
]; |
||||||
|
|
||||||
|
public function peti() |
||||||
|
{ |
||||||
|
return $this->belongsTo(Peti::class, 'peti_id')->select( |
||||||
|
'id', |
||||||
|
'tipe_peti_id', |
||||||
|
'customer_id', |
||||||
|
'warehouse_id', |
||||||
|
'date_pembuatan', |
||||||
|
'kondisipeti_id', |
||||||
|
'fix_lot', |
||||||
|
'updated_by', |
||||||
|
); |
||||||
|
} |
||||||
|
public function customer() |
||||||
|
{ |
||||||
|
return $this->belongsTo(Customer::class, 'customer_id')->select( |
||||||
|
'name', |
||||||
|
'code_customer', |
||||||
|
); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,37 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration; |
||||||
|
use Illuminate\Database\Schema\Blueprint; |
||||||
|
use Illuminate\Support\Facades\Schema; |
||||||
|
|
||||||
|
return new class extends Migration |
||||||
|
{ |
||||||
|
/** |
||||||
|
* Run the migrations. |
||||||
|
*/ |
||||||
|
public function up(): void |
||||||
|
{ |
||||||
|
Schema::create('disposals', function (Blueprint $table) { |
||||||
|
$table->uuid('id')->primary(); |
||||||
|
$table->uuid('mobile_id')->nullable(); |
||||||
|
$table->foreignUuid('peti_id')->constrained('petis'); |
||||||
|
$table->foreignUuid('customer_id')->nullable()->constrained('customers'); |
||||||
|
$table->foreignUuid('warehouse_id')->nullable()->constrained('m_warehouses'); |
||||||
|
$table->date('date_disposal'); |
||||||
|
$table->text('description')->nullable(); |
||||||
|
$table->string('status_disposal', 50); |
||||||
|
$table->timestamps(); |
||||||
|
$table->softDeletes(); |
||||||
|
$table->string('created_by', 200)->nullable(); |
||||||
|
$table->string('updated_by', 200)->nullable(); |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Reverse the migrations. |
||||||
|
*/ |
||||||
|
public function down(): void |
||||||
|
{ |
||||||
|
Schema::dropIfExists('disposals'); |
||||||
|
} |
||||||
|
}; |
@ -1,5 +1,128 @@ |
|||||||
@extends('layouts.main') |
@extends('layouts.main') |
||||||
@section('content') |
@section('content') |
||||||
@include('layouts.components.alert-prompt') |
@include('layouts.components.alert-prompt') |
||||||
<p>Halaman Edit Disposal</p> |
@include('layouts.components.alert-prompt') |
||||||
|
<div class="card shadow mb-4"> |
||||||
|
<div class="card-header py-3"> |
||||||
|
<div class="row"> |
||||||
|
<div class="col-6"> |
||||||
|
<h5 class="m-0 font-weight-bold text-primary mt-2">Edit Disposal Peti</h5> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
<div class="card-body"> |
||||||
|
<form action="{{ route('dashboard.disposal.update', $disposal->id) }}" method="POST" enctype="multipart/form-data" |
||||||
|
id="disposalForm"> |
||||||
|
@csrf |
||||||
|
@method('PUT') |
||||||
|
<div class="form-group"> |
||||||
|
<label for="peti_id" class="col-form-label">Pilih Detail Peti: <span |
||||||
|
class="text-danger">*</span></label> |
||||||
|
<select class="form-control" name="peti_id" type="text" id="peti_id" required> |
||||||
|
<option disabled selected>Pilih Detail Peti</option> |
||||||
|
@foreach ($peti as $data_peti) |
||||||
|
<option value="{{ $data_peti->id }}" data-warehouse-id="{{ $data_peti->warehouse_id }}" |
||||||
|
data-customer-name="{{ $data_peti->customer->name }}" |
||||||
|
{{ $data_peti->id == $disposal->peti_id ? 'selected' : '' }}> |
||||||
|
{{ $data_peti->fix_lot }} |
||||||
|
</option> |
||||||
|
@endforeach |
||||||
|
</select> |
||||||
|
|
||||||
|
<label for="customer_id" class="col-form-label">Customer: <span class="text-danger">*</span></label> |
||||||
|
<select class="form-control" name="customer_id" type="text" id="customer_id" required> |
||||||
|
<option disabled selected>Pilih Customer</option> |
||||||
|
@foreach ($customer as $data_customer) |
||||||
|
<option value="{{ $data_customer->id }}" |
||||||
|
{{ $data_customer->id == $disposal->customer_id ? 'selected' : '' }}> |
||||||
|
{{ $data_customer->name }} |
||||||
|
</option> |
||||||
|
@endforeach |
||||||
|
</select> |
||||||
|
|
||||||
|
<label for="date_disposal" class="col-form-label">Tanggal Disposal: <span |
||||||
|
class="text-danger">*</span></label> |
||||||
|
<input class="form-control" name="date_disposal" type="date" id="date_disposal" |
||||||
|
value="{{ $disposal->date_disposal }}"> |
||||||
|
|
||||||
|
<label for="warehouse_id" class="col-form-label">Asal Gudang: <span class="text-danger">*</span></label> |
||||||
|
<select class="form-control" name="warehouse_id" type="text" id="warehouse_id" required> |
||||||
|
<option disabled selected>Pilih Asal gudang</option> |
||||||
|
@foreach ($warehouse as $data_warehouse) |
||||||
|
<option value="{{ $data_warehouse->id }}" |
||||||
|
{{ $data_warehouse->id == $disposal->warehouse_id ? 'selected' : '' }}> |
||||||
|
{{ $data_warehouse->name }} |
||||||
|
</option> |
||||||
|
@endforeach |
||||||
|
</select> |
||||||
|
|
||||||
|
<label for="description" class="col-form-label">Alasan Disposal: <span |
||||||
|
class="text-danger">*</span></label> |
||||||
|
<textarea class="form-control" name="description" id="description" placeholder="Masukan Alasan Disposal" required>{{ $disposal->description }}</textarea> |
||||||
|
|
||||||
|
{{-- <label for="status_disposal" class="col-form-label">Status Peti: <span |
||||||
|
class="text-danger">*</span></label> |
||||||
|
<select class="form-control" name="status_disposal" id="status_disposal"> |
||||||
|
<option disabled selected>Pilih Jenis Status Peti</option> |
||||||
|
<option value="AKTIF">AKTIF</option> |
||||||
|
<option value="INAKTIF">INAKTIF</option> |
||||||
|
</select> --}} |
||||||
|
<label for="status_disposal" class="col-form-label">Status Peti: <span |
||||||
|
class="text-danger">*</span></label> |
||||||
|
<select class="form-control" name="status_disposal" id="status_disposal"> |
||||||
|
<option disabled>Pilih Jenis Status Peti</option> |
||||||
|
<option value="AKTIF" {{ $disposal->status_disposal === 'AKTIF' ? 'selected' : '' }}>AKTIF |
||||||
|
</option> |
||||||
|
<option value="INAKTIF" {{ $disposal->status_disposal === 'INAKTIF' ? 'selected' : '' }}>INAKTIF |
||||||
|
</option> |
||||||
|
</select> |
||||||
|
|
||||||
|
</div> |
||||||
|
<div class="modal-footer d-flex justify-content-center"> |
||||||
|
<a href="{{ route('dashboard.disposal.index') }}" class="btn btn-secondary">Kembali</a> |
||||||
|
<button type="submit" class="btn btn-primary" id="submitButton">Simpan</button> |
||||||
|
</div> |
||||||
|
</form> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
|
||||||
|
<!-- auto disable form pada saat sudah di simpan--> |
||||||
|
<script> |
||||||
|
document.getElementById('disposalForm').addEventListener('submit', function() { |
||||||
|
document.getElementById('submitButton').setAttribute('disabled', 'true'); |
||||||
|
}); |
||||||
|
</script> |
||||||
|
|
||||||
|
<!-- otomatis asal gudang dan Customer berdasarkan detail peti --> |
||||||
|
<script> |
||||||
|
// Mendapatkan elemen select detail peti |
||||||
|
const petiSelect = document.getElementById('peti_id'); |
||||||
|
|
||||||
|
// Mendapatkan elemen select asal gudang |
||||||
|
const warehouseSelect = document.getElementById('warehouse_id'); |
||||||
|
|
||||||
|
// Mendapatkan elemen select Customer |
||||||
|
const customerSelect = document.getElementById('customer_id'); |
||||||
|
|
||||||
|
// Menambahkan event listener ke select detail peti |
||||||
|
petiSelect.addEventListener('change', function() { |
||||||
|
// Mendapatkan data-warehouse-id dari option yang dipilih |
||||||
|
const selectedOption = this.options[this.selectedIndex]; |
||||||
|
const warehouseId = selectedOption.getAttribute('data-warehouse-id'); |
||||||
|
|
||||||
|
// Mendapatkan data-customer-name dari option yang dipilih |
||||||
|
const customerName = selectedOption.getAttribute('data-customer-name'); |
||||||
|
|
||||||
|
// Memilih asal gudang berdasarkan data-warehouse-id |
||||||
|
warehouseSelect.value = warehouseId; |
||||||
|
|
||||||
|
// Memilih customer berdasarkan data-customer-name |
||||||
|
for (let i = 0; i < customerSelect.options.length; i++) { |
||||||
|
if (customerSelect.options[i].text === customerName) { |
||||||
|
customerSelect.selectedIndex = i; |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
}); |
||||||
|
</script> |
||||||
@endsection |
@endsection |
||||||
|
Loading…
Reference in new issue