Merge branch 'staging' of https://git.putrakuningan.com/daengdeni/lpj into tender

This commit is contained in:
2024-11-02 13:57:18 +07:00
8 changed files with 168 additions and 51 deletions

View File

@@ -63,6 +63,7 @@
public function update(PemilikJaminanRequest $request, $id, $pemilik)
{
$validate = $request->validated();
if ($validate) {
try {
$pemilik = PemilikJaminan::find($pemilik);
@@ -88,6 +89,7 @@
$districts = District::where('city_code', $pemilik->city_code)->get();
$villages = Village::where('district_code', $pemilik->district_code)->get();
$hubunganPemilik = HubunganPemilikJaminan::all();
$detailSertifikat = $pemilik->detail_sertifikat;
return view(
'lpj::pemilik_jaminan.form',
@@ -99,6 +101,7 @@
'villages',
'hubunganPemilik',
'pemilik',
'detailSertifikat'
),
);
}

View File

@@ -4,6 +4,7 @@
use Illuminate\Foundation\Http\FormRequest;
use Modules\Lpj\Rules\UniqueCifExceptZero;
use Modules\Lpj\Rules\UniqueExcept;
class DebitureRequest extends FormRequest
{

View File

@@ -26,6 +26,7 @@
'address' => 'nullable|string',
'postal_code' => 'nullable|string|max:10',
'status' => 'nullable|boolean',
'detail_sertifikat' => 'nullable|string|max:255',
];
//$rules['nomor_id'] = 'nullable|max:16|unique:pemilik_jaminan,nomor_id,debiture_id,' . $this->debiture_id;
@@ -41,4 +42,26 @@
{
return true;
}
public function prepareForValidation() {
$detailSertifikat = [];
$names = $this->input('detail_sertifikat.name', []);
$nomorIds = $this->input('detail_sertifikat.nomor_id', []);
foreach ($names as $index => $name) {
if (isset($nomorIds[$index])) {
$detailSertifikat[] = [
'name' => $name,
'nomor_id' => $nomorIds[$index]
];
}
}
$this->merge([
'detail_sertifikat' => json_encode($detailSertifikat),
]);
}
}

View File

@@ -30,7 +30,8 @@ class PemilikJaminan extends Base
'status',
'authorized_at',
'authorized_status',
'authorized_by'
'authorized_by',
'detail_sertifikat',
];
public function province()

View File

@@ -1,25 +1,32 @@
<?php
namespace Modules\Lpj\Rules;
namespace Modules\Lpj\Rules;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use Modules\Lpj\Models\Debiture;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use Modules\Lpj\Models\Debiture;
class UniqueCifExceptZero implements ValidationRule
{
public function __construct($id = null)
class UniqueCifExceptZero implements ValidationRule
{
$this->id = $id;
}
protected $id;
public function validate($attribute, $value, $fail): void
{
if (Debiture::where($attribute, $value)
->where('id', '!=', $this->id)
->where($attribute, '!=', '0000000000')
->exists()) {
$fail('The :attribute field must be uniquse.'.$this->id);
public function __construct($id = null)
{
$this->id = $id;
}
/**
* Run the validation rule.
*/
public function validate(string $attribute, mixed $value, Closure $fail)
: void {
if ($value !== '0000000000' && $value !== null && Debiture::query()->where($attribute, $value)->when(
$this->id,
function ($query) {
$query->where('id', '!=', $this->id);
},
)->exists()) {
$fail('The :attribute field must be unique.');
}
}
}
}

View File

@@ -0,0 +1,28 @@
<?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::table('debitures', function (Blueprint $table) {
$table->dropUnique(['cif']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('debitures', function (Blueprint $table) {
$table->string('cif')->unique()->change();
});
}
};

View File

@@ -0,0 +1,28 @@
<?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::table('pemilik_jaminan', function (Blueprint $table) {
$table->string('detail_sertifikat')->nullable()->after('name');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('pemilik_jaminan', function (Blueprint $table) {
$table->dropColumn('detail_sertifikat');
});
}
};

View File

@@ -79,7 +79,7 @@
@enderror
</div>
<div class="flex flex-wrap items-baseline w-full">
<input class="input @error('nomor_id') border-danger bg-danger-light @enderror" type="number" name="nomor_id" value="{{ $debitur->nomor_id ?? '' }}" placeholder="Nomor ID/KTP">
<input class="input @error('nomor_id') border-danger bg-danger-light @enderror" type="number" name="nomor_id" value="{{ $pemilik->nomor_id ?? '' }}" placeholder="Nomor ID/KTP">
@error('nomor_id')
<em class="alert text-danger text-sm">{{ $message }}</em>
@enderror
@@ -88,7 +88,28 @@
</div>
</div>
<div id="nama_sertifikat">
@if(isset($detailSertifikat))
@foreach(json_decode($detailSertifikat) as $sertifikat)
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5 mb-5">
<label class="form-label max-w-56">
Nama Lengkap
</label>
<div class="flex flex-wrap items-baseline w-full">
<div class="flex flex-col lg:flex-row gap-2 w-full">
<div class="flex flex-wrap items-baseline w-full">
<input class="input" type="text" id="name" name="detail_sertifikat[name][]" value="{{ $sertifikat->name }}" placeholder="Nama Pemilik Jaminan">
</div>
<div class="flex flex-wrap items-baseline w-full">
<input class="input" type="number" name="detail_sertifikat[nomor_id][]" value="{{ $sertifikat->nomor_id }}" placeholder="Nomor ID/KTP">
</div>
<button type="button" class="btn btn-danger btn-xs delete-button">Hapus</button>
</div>
</div>
</div>
@endforeach
@endif
</div>
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
<label class="form-label max-w-56">
@@ -253,41 +274,46 @@
</div>
@endsection
@push('scripts')
<script>
document.getElementById('tambah_sertifikat').addEventListener('click', function() {
const namaSertifikatDiv = document.getElementById('nama_sertifikat');
const newDiv = document.createElement('div');
newDiv.innerHTML = `
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5 mb-5">
<label class="form-label max-w-56">
Nama Lengkap
</label>
<div class="flex flex-wrap items-baseline w-full">
<div class="flex flex-col lg:flex-row gap-2 w-full">
<div class="flex flex-wrap items-baseline w-full">
<input class="input @error('name') border-danger bg-danger-light @enderror" type="text" id="name" name="name[]" value="" placeholder="Nama Pemilik Jaminan">
@error('name')
<em class="alert text-danger text-sm">{{ $message }}</em>
@enderror
</div>
<div class="flex flex-wrap items-baseline w-full">
<input class="input @error('nomor_id') border-danger bg-danger-light @enderror" type="number" name="nomor_id[]" value="" placeholder="Nomor ID/KTP">
@error('nomor_id')
<em class="alert text-danger text-sm">{{ $message }}</em>
@enderror
</div>
<button type="button" class="btn btn-danger btn-xs delete-button">Hapus</button>
</div>
</div>
</div>
`;
namaSertifikatDiv.appendChild(newDiv);
document.addEventListener("DOMContentLoaded", function() {
const namaSertifikatDiv = document.getElementById("nama_sertifikat");
// Event listener untuk tombol hapus
newDiv.querySelector('.delete-button').addEventListener('click', function() {
namaSertifikatDiv.removeChild(newDiv);
// Function to add delete event listeners to existing buttons
function addDeleteListeners() {
document.querySelectorAll(".delete-button").forEach(button => {
button.addEventListener("click", function() {
this.closest(".flex.items-baseline.flex-wrap.lg\\:flex-nowrap.gap-2\\.5.mb-5").remove();
});
});
}
// Add delete listeners to existing buttons
addDeleteListeners();
document.getElementById("tambah_sertifikat").addEventListener("click", function() {
const newDiv = document.createElement("div");
newDiv.className = "flex items-baseline flex-wrap lg:flex-nowrap gap-2.5 mb-5";
newDiv.innerHTML = `
<label class="form-label max-w-56">
Nama Lengkap
</label>
<div class="flex flex-wrap items-baseline w-full">
<div class="flex flex-col lg:flex-row gap-2 w-full">
<div class="flex flex-wrap items-baseline w-full">
<input class="input" type="text" name="detail_sertifikat[name][]" value="" placeholder="Nama Pemilik Jaminan">
</div>
<div class="flex flex-wrap items-baseline w-full">
<input class="input" type="number" name="detail_sertifikat[nomor_id][]" value="" placeholder="Nomor ID/KTP">
</div>
<button type="button" class="btn btn-danger btn-xs delete-button">Hapus</button>
</div>
</div>
`;
namaSertifikatDiv.appendChild(newDiv);
// Add delete listener to the new button
addDeleteListeners();
});
});
</script>