resolve aksespasar
This commit is contained in:
@@ -216,7 +216,6 @@ class AksesPasarController extends Controller
|
|||||||
{
|
{
|
||||||
$payload = collect($validated)->except(['harga_jual'])->all();
|
$payload = collect($validated)->except(['harga_jual'])->all();
|
||||||
|
|
||||||
// Bersihkan input teks "Lainnya" jika checkbox Lainnya tidak dipilih
|
|
||||||
if (!in_array('Lainnya', $payload['tujuan_penjualan'] ?? [], true)) {
|
if (!in_array('Lainnya', $payload['tujuan_penjualan'] ?? [], true)) {
|
||||||
$payload['tujuan_penjualan_lainnya'] = null;
|
$payload['tujuan_penjualan_lainnya'] = null;
|
||||||
}
|
}
|
||||||
@@ -274,7 +273,7 @@ class AksesPasarController extends Controller
|
|||||||
$data['harga_jual'][$index]['harga_tahun_lalu'] = $this->currencyDigits($item['harga_tahun_lalu']);
|
$data['harga_jual'][$index]['harga_tahun_lalu'] = $this->currencyDigits($item['harga_tahun_lalu']);
|
||||||
}
|
}
|
||||||
if (array_key_exists('harga_dua_tahun_lalu', $item)) {
|
if (array_key_exists('harga_dua_tahun_lalu', $item)) {
|
||||||
$data['harga_jual'][$index]['harga_dua_tahun_lalu'] = $this->currencyDigits($item['harga_dua_tahun_l'], 0); // fixed
|
$data['harga_jual'][$index]['harga_dua_tahun_lalu'] = $this->currencyDigits($item['harga_dua_tahun_lalu']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
|
|
||||||
<h6 class="fw-bold text-dark mb-2">Saluran Penjualan Utama</h6>
|
<h6 class="fw-bold text-dark mb-2">Saluran Penjualan Utama</h6>
|
||||||
<div class="mb-4">
|
<div class="mb-4">
|
||||||
<label class="form-label fw-semibold">144. Kepada siapa Bapak/Ibu biasanya menjual hasil panen? (boleh pilih lebih dari satu)</label>
|
<label class="form-label fw-semibold">Kepada siapa Bapak/Ibu biasanya menjual hasil panen? (boleh pilih lebih dari satu)</label>
|
||||||
<div class="row g-2">
|
<div class="row g-2">
|
||||||
@php
|
@php
|
||||||
$tujuanOptions = ['Tengkulak/pedagang lokal', 'Koperasi', 'BUMDes', 'Langsung ke pembeli/eksportir'];
|
$tujuanOptions = ['Tengkulak/pedagang lokal', 'Koperasi', 'BUMDes', 'Langsung ke pembeli/eksportir'];
|
||||||
@@ -130,52 +130,78 @@
|
|||||||
</div>
|
</div>
|
||||||
<hr class="my-4">
|
<hr class="my-4">
|
||||||
|
|
||||||
<h5 class="pb-3 border-bottom mb-4">Pengalaman Saluran Lain</h5>
|
<h5 class="pb-3 border-bottom mb-4">Pengalaman Saluran Lain</h5>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
||||||
<div class="col-md-6 mb-4 form-control-validation">
|
<div class="col-md-12 mb-4 form-control-validation">
|
||||||
<label class="form-label d-block fw-bold">Pengalaman & akses ke saluran lain</label>
|
<label class="form-label d-block fw-bold">Apakah pernah menjual ke tempat lain sebelumnya?</label>
|
||||||
@foreach($skorPengalamanOptions as $option)
|
@foreach($skorPengalamanOptions as $option)
|
||||||
<div class="form-check mb-2">
|
<div class="form-check mb-2">
|
||||||
<input class="form-check-input @error('skor_pengalaman') is-invalid @enderror" type="radio"
|
<input class="form-check-input @error('skor_pengalaman') is-invalid @enderror" type="radio"
|
||||||
id="skor-pengalaman-{{ $option['value'] }}" name="skor_pengalaman" value="{{ $option['value'] }}"
|
id="skor-pengalaman-{{ $option['value'] }}" name="skor_pengalaman" value="{{ $option['value'] }}"
|
||||||
{{ (string) old('skor_pengalaman', $aksesPasar?->skor_pengalaman) === (string) $option['value'] ? 'checked' : '' }}>
|
{{ (string) old('skor_pengalaman', $aksesPasar?->skor_pengalaman) === (string) $option['value'] ? 'checked' : '' }}>
|
||||||
<label class="form-check-label" for="skor-pengalaman-{{ $option['value'] }}">{{ $option['label'] }}</label>
|
<label class="form-check-label" for="skor-pengalaman-{{ $option['value'] }}">{{ $option['label'] }}</label>
|
||||||
|
</div>
|
||||||
|
@endforeach
|
||||||
|
@error('skor_pengalaman')<div class="invalid-feedback d-block">{{ $message }}</div>@enderror
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-12" id="blok-saluran-lanjutan">
|
||||||
|
<div class="row">
|
||||||
|
|
||||||
|
<div class="col-md-6 mb-4 form-control-validation">
|
||||||
|
<label class="form-label" for="alasan-berhenti">Alasan berhenti</label>
|
||||||
|
<input type="text" class="form-control @error('alasan_berhenti') is-invalid @enderror" id="alasan-berhenti" name="alasan_berhenti" value="{{ old('alasan_berhenti', $aksesPasar?->alasan_berhenti) }}" placeholder="Opsional (jika sudah berhenti)...">
|
||||||
|
@error('alasan_berhenti')<div class="invalid-feedback">{{ $message }}</div>@enderror
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-6 mb-4"></div>
|
||||||
|
|
||||||
|
<div class="col-md-12 mb-4 form-control-validation">
|
||||||
|
<label class="form-label d-block mb-2" for="saluran-terdahulu">Jika pernah, dulu menjual ke mana? (boleh pilih lebih dari satu)</label>
|
||||||
|
<div class="row g-2">
|
||||||
|
@foreach($saluranTerdahuluOptions as $option)
|
||||||
|
@if($option['value'] !== $saluranLainnyaValue)
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="form-check mb-2">
|
||||||
|
<input class="form-check-input @error('saluran_terdahulu') is-invalid @enderror"
|
||||||
|
type="checkbox"
|
||||||
|
id="saluran-terdahulu-{{ Str::slug($option['value']) }}"
|
||||||
|
name="saluran_terdahulu[]"
|
||||||
|
value="{{ $option['value'] }}"
|
||||||
|
{{ in_array($option['value'], (array) old('saluran_terdahulu', $aksesPasar?->saluran_terdahulu ?? []), true) ? 'checked' : '' }}>
|
||||||
|
<label class="form-check-label" for="saluran-terdahulu-{{ Str::slug($option['value']) }}">
|
||||||
|
{{ $option['label'] }}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
@endforeach
|
||||||
|
|
||||||
|
<div class="col-12 mt-2">
|
||||||
|
<div class="d-flex align-items-center gap-2 flex-wrap">
|
||||||
|
<div class="form-check mb-0">
|
||||||
|
<input class="form-check-input @error('saluran_terdahulu') is-invalid @enderror"
|
||||||
|
type="checkbox"
|
||||||
|
id="saluran-terdahulu-lainnya-checkbox"
|
||||||
|
name="saluran_terdahulu[]"
|
||||||
|
value="{{ $saluranLainnyaValue }}"
|
||||||
|
{{ in_array($saluranLainnyaValue, (array) old('saluran_terdahulu', $aksesPasar?->saluran_terdahulu ?? []), true) ? 'checked' : '' }}>
|
||||||
|
<label class="form-check-label text-nowrap" for="saluran-terdahulu-lainnya-checkbox">
|
||||||
|
Lainnya:
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<input type="text" class="form-control form-control-sm w-auto flex-grow-1 @error('saluran_terdahulu_lainnya') is-invalid @enderror" style="max-width: 400px;" id="saluran-lainnya" name="saluran_terdahulu_lainnya" value="{{ old('saluran_terdahulu_lainnya', $aksesPasar?->saluran_terdahulu_lainnya) }}" placeholder="Sebutkan saluran lainnya...">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@endforeach
|
@error('saluran_terdahulu')<div class="invalid-feedback d-block">{{ $message }}</div>@enderror
|
||||||
@error('skor_pengalaman')<div class="invalid-feedback d-block">{{ $message }}</div>@enderror
|
@error('saluran_terdahulu_lainnya')<div class="invalid-feedback d-block">{{ $message }}</div>@enderror
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-md-4 mb-4 form-control-validation">
|
|
||||||
<label class="form-label" for="alasan-berhenti">Alasan berhenti</label>
|
|
||||||
<input type="text" class="form-control @error('alasan_berhenti') is-invalid @enderror" id="alasan-berhenti" name="alasan_berhenti" value="{{ old('alasan_berhenti', $aksesPasar?->alasan_berhenti) }}" placeholder="Opsional (jika sudah berhenti)...">
|
|
||||||
@error('alasan_berhenti')<div class="invalid-feedback">{{ $message }}</div>@enderror
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="col-md-6 mb-4 form-control-validation">
|
|
||||||
<label class="form-label d-block mb-2" for="saluran-terdahulu">Dulu pernah jual ke?</label>
|
|
||||||
@foreach($saluranTerdahuluOptions as $option)
|
|
||||||
<div class="form-check mb-2">
|
|
||||||
<input class="form-check-input @error('saluran_terdahulu') is-invalid @enderror"
|
|
||||||
type="checkbox"
|
|
||||||
id="saluran-terdahulu-{{ Str::slug($option['value']) }}"
|
|
||||||
name="saluran_terdahulu[]"
|
|
||||||
value="{{ $option['value'] }}"
|
|
||||||
{{ in_array($option['value'], (array) old('saluran_terdahulu', $aksesPasar?->saluran_terdahulu ?? []), true) ? 'checked' : '' }}>
|
|
||||||
<label class="form-check-label" for="saluran-terdahulu-{{ Str::slug($option['value']) }}">
|
|
||||||
{{ $option['label'] }}
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
@endforeach
|
|
||||||
@error('saluran_terdahulu')<div class="invalid-feedback d-block">{{ $message }}</div>@enderror
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="col-md-4 mb-4 form-control-validation">
|
|
||||||
<label class="form-label" for="saluran-lainnya">Lainnya</label>
|
|
||||||
<input type="text" class="form-control @error('saluran_terdahulu_lainnya') is-invalid @enderror" id="saluran-lainnya" name="saluran_terdahulu_lainnya" value="{{ old('saluran_terdahulu_lainnya', $aksesPasar?->saluran_terdahulu_lainnya) }}" placeholder="Sebutkan saluran lainnya...">
|
|
||||||
@error('saluran_terdahulu_lainnya')<div class="invalid-feedback">{{ $message }}</div>@enderror
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<h5 class="pb-3 border-bottom mb-4 mt-4">HARGA DI SETIAP TITIK</h5>
|
<h5 class="pb-3 border-bottom mb-4 mt-4">HARGA DI SETIAP TITIK</h5>
|
||||||
<h6 class="mb-2">Harga Jual Panen Terakhir</h6>
|
<h6 class="mb-2">Harga Jual Panen Terakhir</h6>
|
||||||
@@ -358,6 +384,7 @@
|
|||||||
const saluranLainnyaValue = @json($saluranLainnyaValue);
|
const saluranLainnyaValue = @json($saluranLainnyaValue);
|
||||||
const praktikBelumPernahValue = String(@json($praktikBelumPernahValue));
|
const praktikBelumPernahValue = String(@json($praktikBelumPernahValue));
|
||||||
const skorPengalamanBerhentiValues = @json($skorPengalamanBerhentiValues ?? [2,3]).map(Number);
|
const skorPengalamanBerhentiValues = @json($skorPengalamanBerhentiValues ?? [2,3]).map(Number);
|
||||||
|
const skorBelumPernahValue = "1";
|
||||||
|
|
||||||
function onlyDigits(value) {
|
function onlyDigits(value) {
|
||||||
return String(value || '').replace(/\D/g, '');
|
return String(value || '').replace(/\D/g, '');
|
||||||
@@ -368,6 +395,22 @@
|
|||||||
return digits.replace(/\B(?=(\d{3})+(?!\d))/g, '.');
|
return digits.replace(/\B(?=(\d{3})+(?!\d))/g, '.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toggleSaluranLanjutan() {
|
||||||
|
const selectedRadio = $('input[name="skor_pengalaman"]:checked');
|
||||||
|
const val = selectedRadio.val();
|
||||||
|
const labelText = selectedRadio.parent().text().toLowerCase();
|
||||||
|
|
||||||
|
const isBelumPernah = !val || labelText.includes('belum pernah') || val === skorBelumPernahValue;
|
||||||
|
|
||||||
|
if (isBelumPernah) {
|
||||||
|
$('#blok-saluran-lanjutan').addClass('d-none');
|
||||||
|
$('#blok-saluran-lanjutan input[type="text"]').val('');
|
||||||
|
$('#blok-saluran-lanjutan input[type="checkbox"]').prop('checked', false);
|
||||||
|
} else {
|
||||||
|
$('#blok-saluran-lanjutan').removeClass('d-none');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function syncAlasanBerhenti() {
|
function syncAlasanBerhenti() {
|
||||||
const val = Number($('input[name="skor_pengalaman"]:checked').val());
|
const val = Number($('input[name="skor_pengalaman"]:checked').val());
|
||||||
const isBerhenti = skorPengalamanBerhentiValues.includes(val);
|
const isBerhenti = skorPengalamanBerhentiValues.includes(val);
|
||||||
@@ -389,9 +432,14 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$('input[name="skor_pengalaman"]').on('change', syncAlasanBerhenti);
|
$('input[name="skor_pengalaman"]').on('change', function () {
|
||||||
|
toggleSaluranLanjutan();
|
||||||
|
syncAlasanBerhenti();
|
||||||
|
});
|
||||||
|
|
||||||
$('input[name="saluran_terdahulu[]"]').on('change', syncSaluranLainnya);
|
$('input[name="saluran_terdahulu[]"]').on('change', syncSaluranLainnya);
|
||||||
$('input[name="praktik_fermentasi"]').on('change', syncPraktikFermentasi);
|
$('input[name="praktik_fermentasi"]').on('change', syncPraktikFermentasi);
|
||||||
|
|
||||||
$(document).on('input', '.rupiah-input', function () {
|
$(document).on('input', '.rupiah-input', function () {
|
||||||
const cursorAtEnd = this.selectionStart === this.value.length;
|
const cursorAtEnd = this.selectionStart === this.value.length;
|
||||||
this.value = formatRupiah(this.value);
|
this.value = formatRupiah(this.value);
|
||||||
@@ -400,10 +448,12 @@
|
|||||||
this.setSelectionRange(this.value.length, this.value.length);
|
this.setSelectionRange(this.value.length, this.value.length);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$('.rupiah-input').each(function () {
|
$('.rupiah-input').each(function () {
|
||||||
this.value = formatRupiah(this.value);
|
this.value = formatRupiah(this.value);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
toggleSaluranLanjutan();
|
||||||
syncAlasanBerhenti();
|
syncAlasanBerhenti();
|
||||||
syncSaluranLainnya();
|
syncSaluranLainnya();
|
||||||
syncPraktikFermentasi();
|
syncPraktikFermentasi();
|
||||||
|
|||||||
Reference in New Issue
Block a user