feat(dokumen-jaminan): perbaiki pengambilan custom field
- Memperbaiki pengambilan custom field pada dokumen jaminan. - Mengubah logika untuk mendapatkan custom field berdasarkan ID yang benar. - Menambahkan pengambilan custom fields yang terkait dengan jenis legalitas jaminan.
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
use Modules\Location\Models\Province;
|
use Modules\Location\Models\Province;
|
||||||
use Modules\Location\Models\Village;
|
use Modules\Location\Models\Village;
|
||||||
use Modules\Lpj\Http\Requests\DokumenJaminanRequest;
|
use Modules\Lpj\Http\Requests\DokumenJaminanRequest;
|
||||||
|
use Modules\Lpj\Models\customField;
|
||||||
use Modules\Lpj\Models\Debiture;
|
use Modules\Lpj\Models\Debiture;
|
||||||
use Modules\Lpj\Models\DetailDokumenJaminan;
|
use Modules\Lpj\Models\DetailDokumenJaminan;
|
||||||
use Modules\Lpj\Models\DokumenJaminan;
|
use Modules\Lpj\Models\DokumenJaminan;
|
||||||
@@ -88,7 +89,7 @@
|
|||||||
'jenis_legalitas_jaminan_id' => $value,
|
'jenis_legalitas_jaminan_id' => $value,
|
||||||
'name' => $request->name[$key],
|
'name' => $request->name[$key],
|
||||||
'keterangan' => $request->keterangan[$key],
|
'keterangan' => $request->keterangan[$key],
|
||||||
'details' => isset($request->custom_field[$key]) ? json_encode($request->custom_field[$key]) : ''
|
'details' => isset($request->custom_field[$value]) ? json_encode($request->custom_field[$value]) : ''
|
||||||
];
|
];
|
||||||
|
|
||||||
$dokumenJaminan = [];
|
$dokumenJaminan = [];
|
||||||
@@ -247,7 +248,7 @@
|
|||||||
'jenis_legalitas_jaminan_id' => $value,
|
'jenis_legalitas_jaminan_id' => $value,
|
||||||
'name' => $request->name[$key],
|
'name' => $request->name[$key],
|
||||||
'keterangan' => $request->keterangan[$key],
|
'keterangan' => $request->keterangan[$key],
|
||||||
'details' => isset($request->custom_field[$key]) ? json_encode($request->custom_field[$key]) : ''
|
'details' => isset($request->custom_field[$value]) ? json_encode($request->custom_field[$value]) : ''
|
||||||
];
|
];
|
||||||
|
|
||||||
$dokumenJaminan = [];
|
$dokumenJaminan = [];
|
||||||
@@ -496,6 +497,12 @@
|
|||||||
foreach ($document->detail as $detail) {
|
foreach ($document->detail as $detail) {
|
||||||
// Only include existing legalitas if its id is in the new set
|
// Only include existing legalitas if its id is in the new set
|
||||||
if (in_array($detail->jenis_legalitas_jaminan_id, $newLegalitasIds)) {
|
if (in_array($detail->jenis_legalitas_jaminan_id, $newLegalitasIds)) {
|
||||||
|
$customFields = [];
|
||||||
|
if($detail->jenisLegalitasJaminan->custom_fields) {
|
||||||
|
$customFields = CustomField::whereIn('id', $detail->jenisLegalitasJaminan->custom_fields)
|
||||||
|
->get();
|
||||||
|
}
|
||||||
|
|
||||||
$existingLegalitas[] = [
|
$existingLegalitas[] = [
|
||||||
'id' => $detail->id,
|
'id' => $detail->id,
|
||||||
'jenis_legalitas_jaminan_id' => $detail->jenis_legalitas_jaminan_id,
|
'jenis_legalitas_jaminan_id' => $detail->jenis_legalitas_jaminan_id,
|
||||||
@@ -507,6 +514,7 @@
|
|||||||
$detail->dokumen_nomor,
|
$detail->dokumen_nomor,
|
||||||
) ?? $detail->dokumen_nomor,
|
) ?? $detail->dokumen_nomor,
|
||||||
'custom_field' => $detail->jenisLegalitasJaminan->custom_field,
|
'custom_field' => $detail->jenisLegalitasJaminan->custom_field,
|
||||||
|
'custom_fields' => $customFields,
|
||||||
'custom_field_type' => $detail->jenisLegalitasJaminan->custom_field_type,
|
'custom_field_type' => $detail->jenisLegalitasJaminan->custom_field_type,
|
||||||
'details' => $detail->details,
|
'details' => $detail->details,
|
||||||
'keterangan' => $detail->keterangan,
|
'keterangan' => $detail->keterangan,
|
||||||
|
|||||||
@@ -314,38 +314,32 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
@if($detail->details)
|
@if($detail->details)
|
||||||
@if($detail->jenisLegalitasJaminan->custom_field)
|
@if($detail->jenisLegalitasJaminan->custom_fields)
|
||||||
@php $custom_field = json_decode($detail->details,true) @endphp
|
@php $custom_field = json_decode($detail->details) @endphp
|
||||||
|
{{ $custom_field->luas_tanah }}
|
||||||
|
@foreach($custom_field as $key => $value)
|
||||||
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
||||||
<label class="form-label max-w-56 capitalize">
|
<label class="form-label max-w-56 capitalize">
|
||||||
{{ str_replace('_',' ',$detail->jenisLegalitasJaminan->custom_field) }}
|
{{ getCustomField($key)->label ?? "" }}
|
||||||
</label>
|
</label>
|
||||||
<div class="flex flex-wrap items-baseline w-full">
|
<div class="flex flex-wrap items-baseline w-full">
|
||||||
<input class="input" type="text" name="custom_field[][{{$detail->jenisLegalitasJaminan->custom_field}}]" value="{{ $custom_field[$detail->jenisLegalitasJaminan->custom_field] ?? '' }}">
|
<input class="input" type="text" name="custom_field[{{$detail->jenisLegalitasJaminan->id}}][{{$key}}]" value="{{ $value ?? '' }}">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@endforeach
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@else
|
@else
|
||||||
@if($detail->jenisLegalitasJaminan->custom_field)
|
@if($detail->jenisLegalitasJaminan->custom_fields)
|
||||||
|
@foreach($detail->jenisLegalitasJaminan->custom_fields as $key)
|
||||||
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
||||||
<label class="form-label max-w-56 capitalize">
|
<label class="form-label max-w-56 capitalize">
|
||||||
{{ str_replace('_',' ',$detail->jenisLegalitasJaminan->custom_field) }}
|
{{ getCustomField($key)->label }}
|
||||||
</label>
|
</label>
|
||||||
<div class="flex flex-wrap items-baseline w-full">
|
<div class="flex flex-wrap items-baseline w-full">
|
||||||
@if($detail->jenisLegalitasJaminan->custom_field_type === "text")
|
<input class="input" type="text" name="custom_field[{{$detail->jenisLegalitasJaminan->id}}][{{getCustomField($key)->name}}]" placeholder="...">
|
||||||
<input class="input" type="text" name="custom_field[][{{$detail->jenisLegalitasJaminan->custom_field}}]" placeholder="... M2">
|
|
||||||
@elseif($detail->jenisLegalitasJaminan->custom_field_type === "number")
|
|
||||||
<input class="input" type="number" name="custom_field[][{{$detail->jenisLegalitasJaminan->custom_field}}]" placeholder="... M2">
|
|
||||||
@elseif($detail->jenisLegalitasJaminan->custom_field_type === "date")
|
|
||||||
<input class="input" type="date" name="custom_field[][{{$detail->jenisLegalitasJaminan->custom_field}}]" placeholder="... M2">
|
|
||||||
@elseif($detail->jenisLegalitasJaminan->custom_field_type === "textarea")
|
|
||||||
<textarea class="textarea" rows="3" name="custom_field[][{{$detail->jenisLegalitasJaminan->custom_field}}]" placeholder="... M2"></textarea>
|
|
||||||
@else
|
|
||||||
<input class="input" type="text" name="custom_field[][{{$detail->jenisLegalitasJaminan->custom_field}}]" placeholder="... M2">
|
|
||||||
@endif
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@endforeach
|
||||||
@endif
|
@endif
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@@ -393,25 +387,17 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@if($item->custom_field)
|
@if($item->custom_fields)
|
||||||
|
@foreach($item->custom_fields as $field)
|
||||||
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
||||||
<label class="form-label max-w-56 capitalize">
|
<label class="form-label max-w-56 capitalize">
|
||||||
{{ str_replace('_',' ',$item->custom_field) }}
|
{{ getCustomField($field)->label }}
|
||||||
</label>
|
</label>
|
||||||
<div class="flex flex-wrap items-baseline w-full">
|
<div class="flex flex-wrap items-baseline w-full">
|
||||||
@if($item->custom_field_type === "text")
|
<input class="input" type="text" name="custom_field[{{$item->id}}][{{getCustomField($field)->name}}]" placeholder="...">
|
||||||
<input class="input" type="text" name="custom_field[][{{$item->custom_field}}]" placeholder="... M2">
|
|
||||||
@elseif($item->custom_field_type === "number")
|
|
||||||
<input class="input" type="number" name="custom_field[][{{$item->custom_field}}]" placeholder="... M2">
|
|
||||||
@elseif($item->custom_field_type === "date")
|
|
||||||
<input class="input" type="date" name="custom_field[][{{$item->custom_field}}]" placeholder="... M2">
|
|
||||||
@elseif($item->custom_field_type === "textarea")
|
|
||||||
<textarea class="textarea" rows="3" name="custom_field[][{{$item->custom_field}}]" placeholder="... M2"></textarea>
|
|
||||||
@else
|
|
||||||
<input class="input" type="text" name="custom_field[][{{$item->custom_field}}]" placeholder="... M2">
|
|
||||||
@endif
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@endforeach
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
||||||
@@ -547,16 +533,16 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
${item.custom_field ? `
|
${item.custom_fields && item.custom_fields.length > 0 ? item.custom_fields.map(field => `
|
||||||
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
||||||
<label class="form-label max-w-56 capitalize">
|
<label class="form-label max-w-56 capitalize">
|
||||||
${item.custom_field.replace(/_/g, " ")}
|
${field.label}
|
||||||
</label>
|
</label>
|
||||||
<div class="flex flex-wrap items-baseline w-full">
|
<div class="flex flex-wrap items-baseline w-full">
|
||||||
${getCustomFieldInput(item.custom_field_type, item.custom_field, item.details)}
|
${getCustomFieldInput(field.type, field.name, item.details, item.id)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
` : ""}
|
`).join('') : ""}
|
||||||
|
|
||||||
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
||||||
<label class="form-label max-w-56">
|
<label class="form-label max-w-56">
|
||||||
@@ -637,19 +623,19 @@
|
|||||||
return dokumenNomor;
|
return dokumenNomor;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCustomFieldInput(type, fieldName, value) {
|
function getCustomFieldInput(type, fieldName, value, itemId) {
|
||||||
value = value ? JSON.parse(value)[fieldName] || "" : "";
|
value = value ? JSON.parse(value)[fieldName] || "" : "";
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "text":
|
case "text":
|
||||||
return `<input class="input" type="text" name="custom_field[][${fieldName}]" value="${value}">`;
|
return `<input class="input" type="text" name="custom_field[${itemId}][${fieldName}]" value="${value}">`;
|
||||||
case "number":
|
case "number":
|
||||||
return `<input class="input" type="number" name="custom_field[][${fieldName}]" value="${value}">`;
|
return `<input class="input" type="number" name="custom_field[${itemId}][${fieldName}]" value="${value}">`;
|
||||||
case "date":
|
case "date":
|
||||||
return `<input class="input" type="date" name="custom_field[][${fieldName}]" value="${value}">`;
|
return `<input class="input" type="date" name="custom_field[${itemId}][${fieldName}]" value="${value}">`;
|
||||||
case "textarea":
|
case "textarea":
|
||||||
return `<textarea class="textarea" rows="3" name="custom_field[][${fieldName}]">${value}</textarea>`;
|
return `<textarea class="textarea" rows="3" name="custom_field[${itemId}][${fieldName}]">${value}</textarea>`;
|
||||||
default:
|
default:
|
||||||
return `<input class="input" type="text" name="custom_field[][${fieldName}]" value="${value}">`;
|
return `<input class="input" type="text" name="custom_field[${itemId}][${fieldName}]" value="${value}">`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user