Compare commits
4
Commits
8be0906a2e
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
013cb7b728 | ||
|
|
4ab745cfe5 | ||
|
|
c66eed56e2 | ||
|
|
bea9be8a39 |
@@ -3,6 +3,8 @@
|
||||
namespace App\Http\Controllers\Web\Dashboard;
|
||||
|
||||
use App\Enums\AksesPasar\PraktikFermentasi;
|
||||
use App\Enums\AksesPasar\SkorKesadaranPremium;
|
||||
use App\Enums\AksesPasar\SkorPengalaman;
|
||||
use App\Enums\KeparahanSerangan;
|
||||
use App\Enums\KondisiTanaman;
|
||||
use App\Enums\PenyakitTanaman;
|
||||
@@ -114,70 +116,196 @@ class SummaryController extends Controller
|
||||
'kecamatan_id',
|
||||
'desaKelurahan_id',
|
||||
'komoditas_id',
|
||||
'segmen',
|
||||
]),
|
||||
] + $filterData + $this->marketDashboardData($request));
|
||||
}
|
||||
|
||||
private function marketDashboardData(Request $request): array
|
||||
{
|
||||
if (! $request->filled('komoditas_id')) {
|
||||
return [
|
||||
'selectedKomoditas' => null,
|
||||
'priceCard' => null,
|
||||
];
|
||||
}
|
||||
|
||||
$selectedKomoditas = Komoditas::query()
|
||||
->whereKey($request->komoditas_id)
|
||||
->first(['id', 'nama']);
|
||||
|
||||
if (! $selectedKomoditas) {
|
||||
return [
|
||||
'selectedKomoditas' => null,
|
||||
'priceCard' => null,
|
||||
];
|
||||
}
|
||||
|
||||
$productCaption = $this->marketProductCaption($selectedKomoditas->nama);
|
||||
$productLabel = 'Buah segar hasil petik';
|
||||
$products = [
|
||||
['name' => 'Kakao', 'caption' => 'Harga Biji Kering', 'product' => 'Biji kering/Biji Kupas', 'variant' => 'success'],
|
||||
['name' => 'Vanili', 'caption' => 'Harga Buah Segar', 'product' => 'Buah segar hasil petik', 'variant' => 'primary'],
|
||||
['name' => 'Kopi', 'caption' => 'Harga Ceri Merah', 'product' => 'Buah segar hasil petik', 'variant' => 'warning'],
|
||||
['name' => 'Kemiri', 'caption' => 'Harga Gelondong', 'product' => 'Buah segar hasil petik', 'variant' => 'info'],
|
||||
];
|
||||
$commodities = Komoditas::query()
|
||||
->whereIn('nama', array_column($products, 'name'))
|
||||
->pluck('id', 'nama');
|
||||
|
||||
$petaniIds = $this->filteredPetaniIdsQuery($request);
|
||||
$priceQuery = DB::table('harga_jual_panen')
|
||||
$prices = DB::table('harga_jual_panen')
|
||||
->join('petani', 'petani.id', '=', 'harga_jual_panen.petani_id')
|
||||
->whereIn('harga_jual_panen.petani_id', $petaniIds)
|
||||
->whereIn('petani.komoditas_id', $commodities->values())
|
||||
->where('harga_jual_panen.harga_panen_terakhir', '>', 0)
|
||||
->where('harga_jual_panen.bentuk_produk', $productLabel);
|
||||
|
||||
$averagePrice = (float) (clone $priceQuery)->avg('harga_jual_panen.harga_panen_terakhir');
|
||||
$totalRecords = (int) (clone $priceQuery)->count();
|
||||
->whereIn('harga_jual_panen.bentuk_produk', array_unique(array_column($products, 'product')))
|
||||
->select('petani.komoditas_id', 'harga_jual_panen.bentuk_produk')
|
||||
->selectRaw('AVG(harga_jual_panen.harga_panen_terakhir) as average_price, COUNT(*) as records')
|
||||
->groupBy('petani.komoditas_id', 'harga_jual_panen.bentuk_produk')
|
||||
->get();
|
||||
|
||||
return [
|
||||
'selectedKomoditas' => $selectedKomoditas,
|
||||
'priceCard' => [
|
||||
'value' => $averagePrice > 0
|
||||
? 'Rp '.number_format($averagePrice, 0, ',', '.')
|
||||
: 'Rp 0',
|
||||
'label' => 'Harga Jual',
|
||||
'caption' => $productCaption,
|
||||
'description' => 'Harga rata-rata buah segar hasil petik di tingkat petani',
|
||||
'records' => $totalRecords,
|
||||
'unit' => '/kg',
|
||||
'variant' => 'success',
|
||||
'icon' => 'tabler-cash',
|
||||
],
|
||||
'priceCards' => collect($products)->map(function (array $product) use ($commodities, $prices) {
|
||||
$commodityId = $commodities->get($product['name']);
|
||||
$price = $commodityId === null ? null : $prices->first(fn ($row) =>
|
||||
(int) $row->komoditas_id === (int) $commodityId
|
||||
&& $row->bentuk_produk === $product['product']
|
||||
);
|
||||
|
||||
return [
|
||||
'value' => 'Rp '.number_format((float) ($price?->average_price ?? 0), 0, ',', '.'),
|
||||
'label' => $product['name'].' - '.$product['caption'],
|
||||
'description' => 'Harga rata-rata panen terakhir di tingkat petani',
|
||||
'records' => (int) ($price?->records ?? 0),
|
||||
'unit' => '/kg',
|
||||
'variant' => $product['variant'],
|
||||
'icon' => 'tabler-cash',
|
||||
];
|
||||
})->all(),
|
||||
'marketCharts' => $this->marketChannelCharts($request),
|
||||
'priceTrend' => $this->marketPriceTrend($request),
|
||||
'premiumAwareness' => $this->marketPremiumAwareness($request),
|
||||
];
|
||||
}
|
||||
|
||||
private function marketProductCaption(string $komoditasName): string
|
||||
private function marketPriceTrend(Request $request): array
|
||||
{
|
||||
$normalized = str($komoditasName)->lower()->trim()->toString();
|
||||
$products = ['Buah segar hasil petik', 'Biji basah', 'Biji kering/Biji Kupas', 'Terfermentasi (Rp/kg)'];
|
||||
$periods = [
|
||||
'harga_dua_tahun_lalu' => 'Dua Tahun Lalu',
|
||||
'harga_tahun_lalu' => 'Tahun Lalu',
|
||||
'harga_panen_terakhir' => 'Panen Terakhir',
|
||||
];
|
||||
$commodities = Komoditas::query()
|
||||
->when($request->filled('komoditas_id'), fn ($query) => $query->where('id', $request->komoditas_id))
|
||||
->orderBy('nama')
|
||||
->get(['id', 'nama']);
|
||||
|
||||
return match (true) {
|
||||
str_contains($normalized, 'kakao') => 'Harga Buah Kakao',
|
||||
str_contains($normalized, 'vanili') => 'Harga Curing',
|
||||
str_contains($normalized, 'kopi') => 'Harga Ceri Merah',
|
||||
str_contains($normalized, 'kemiri') => 'Harga Gelondong',
|
||||
default => 'Harga Buah Segar',
|
||||
};
|
||||
$query = DB::table('harga_jual_panen')
|
||||
->join('petani', 'petani.id', '=', 'harga_jual_panen.petani_id')
|
||||
->whereIn('harga_jual_panen.petani_id', $this->filteredPetaniIdsQuery($request))
|
||||
->whereIn('petani.komoditas_id', $commodities->pluck('id'))
|
||||
->whereIn('harga_jual_panen.bentuk_produk', $products)
|
||||
->select('petani.komoditas_id', 'harga_jual_panen.bentuk_produk')
|
||||
->groupBy('petani.komoditas_id', 'harga_jual_panen.bentuk_produk');
|
||||
|
||||
foreach (array_keys($periods) as $field) {
|
||||
$query->selectRaw("AVG(CASE WHEN harga_jual_panen.{$field} > 0 THEN harga_jual_panen.{$field} END) as {$field}");
|
||||
}
|
||||
|
||||
$prices = $query->get()->groupBy('komoditas_id');
|
||||
|
||||
return [
|
||||
'periods' => array_values($periods),
|
||||
'commodities' => $commodities->map(function ($commodity) use ($products, $periods, $prices) {
|
||||
$rows = $prices->get($commodity->id, collect())->keyBy('bentuk_produk');
|
||||
|
||||
return [
|
||||
'id' => $commodity->id,
|
||||
'name' => $commodity->nama,
|
||||
'series' => collect($products)->map(function ($product) use ($periods, $rows) {
|
||||
$row = $rows->get($product);
|
||||
|
||||
return [
|
||||
'name' => $product === 'Terfermentasi (Rp/kg)' ? 'Terfermentasi' : $product,
|
||||
'data' => array_map(fn ($field) => isset($row->{$field}) ? round((float) $row->{$field}, 2) : null, array_keys($periods)),
|
||||
];
|
||||
})->all(),
|
||||
];
|
||||
})->all(),
|
||||
];
|
||||
}
|
||||
|
||||
private function marketChannelCharts(Request $request): array
|
||||
{
|
||||
$rows = DB::table('akses_pasar')
|
||||
->whereNull('deleted_at')
|
||||
->whereIn('petani_id', $this->filteredPetaniIdsQuery($request))
|
||||
->orderBy('id')
|
||||
->get(['petani_id', 'tujuan_penjualan', 'sifat_hubungan_bisnis', 'frekuensi_penjualan', 'skor_pengalaman'])
|
||||
->unique('petani_id');
|
||||
|
||||
$channels = ['Tengkulak/pedagang lokal', 'Koperasi', 'BUMDes', 'Langsung ke pembeli/eksportir', 'Lainnya'];
|
||||
$relationships = [
|
||||
'Bebas, bisa pindah pembeli kapan saja' => 'Bebas pindah pembeli',
|
||||
'Langganan tetap, tapi tidak terikat' => 'Langganan tetap',
|
||||
'Berbasis hutang, harus jual ke sana karena ada pinjaman' => 'Berbasis hutang',
|
||||
'Titip jual,dibayar setelah produk terjual' => 'Titip jual',
|
||||
'Ada komitmen volume, sudah ada kesepakatan jumlah' => 'Komitmen volume',
|
||||
'Semi-kontrak, ada kesepakatan harga tertentu' => 'Semi-kontrak',
|
||||
];
|
||||
$timing = ['Langsung setelah panen', 'Ditumpuk dulu beberapa waktu', 'Saat butuh uang mendesak'];
|
||||
$experience = collect(SkorPengalaman::options())
|
||||
->mapWithKeys(fn ($option) => [$option['value'] => $option['label']])
|
||||
->all();
|
||||
|
||||
return [
|
||||
'saluranPenjualan' => $this->marketResponseChart($rows, 'tujuan_penjualan', array_combine($channels, $channels), true),
|
||||
'hubunganPembeli' => $this->marketResponseChart($rows, 'sifat_hubungan_bisnis', $relationships),
|
||||
'waktuPenjualan' => $this->marketResponseChart($rows, 'frekuensi_penjualan', array_combine($timing, $timing)),
|
||||
'aksesSaluranLain' => $this->marketResponseChart($rows, 'skor_pengalaman', $experience),
|
||||
];
|
||||
}
|
||||
|
||||
private function marketPremiumAwareness(Request $request): array
|
||||
{
|
||||
$rows = DB::table('akses_pasar')
|
||||
->whereNull('deleted_at')
|
||||
->whereIn('petani_id', $this->filteredPetaniIdsQuery($request))
|
||||
->orderBy('id')
|
||||
->get(['petani_id', 'skor_kesadaran_premium'])
|
||||
->unique('petani_id');
|
||||
$options = collect(SkorKesadaranPremium::options())
|
||||
->mapWithKeys(fn ($option) => [$option['value'] => $option['label']])
|
||||
->all();
|
||||
$chart = $this->marketResponseChart($rows, 'skor_kesadaran_premium', $options);
|
||||
$chart['fullLabels'] = [
|
||||
'Belum pernah mendengar sama sekali',
|
||||
'Pernah mendengar tapi belum paham persyaratannya',
|
||||
'Pernah mendengar dan sedikit memahami persyaratannya',
|
||||
'Sudah sangat memahami persyaratannya, tapi belum pernah mengakses pasar premium',
|
||||
'Sudah mengakses dan mendapat harga premium secara konsisten',
|
||||
];
|
||||
|
||||
return $chart;
|
||||
}
|
||||
|
||||
private function marketResponseChart($rows, string $field, array $options, bool $multiple = false): array
|
||||
{
|
||||
$counts = array_fill_keys(array_keys($options), 0);
|
||||
$respondents = 0;
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$values = $multiple ? $this->arrayValues($row->{$field}) : [$row->{$field}];
|
||||
$answers = [];
|
||||
|
||||
foreach ($values as $value) {
|
||||
if (is_string($value) || is_int($value)) {
|
||||
$value = is_string($value) ? trim($value) : $value;
|
||||
if (array_key_exists($value, $options)) {
|
||||
$answers[$value] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($answers === []) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$respondents++;
|
||||
foreach (array_keys($answers) as $answer) {
|
||||
$counts[$answer]++;
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'labels' => array_values($options),
|
||||
'fullLabels' => $field === 'skor_pengalaman' ? array_values($options) : array_keys($options),
|
||||
'series' => array_values($counts),
|
||||
'respondents' => $respondents,
|
||||
'percentages' => array_map(fn ($count) => $respondents > 0 ? round($count / $respondents * 100, 1) : 0, array_values($counts)),
|
||||
];
|
||||
}
|
||||
|
||||
private function productionDashboardData(Request $request): array
|
||||
|
||||
@@ -118,7 +118,8 @@ class AksesPasarController extends Controller
|
||||
'skorPengalamanBerhentiValues' => [
|
||||
SkorPengalaman::PERNAH_BERHENTI_TIDAK_ADA_AKSES->value,
|
||||
SkorPengalaman::PERNAH_BERHENTI_MUNGKIN_KEMBALI->value
|
||||
]
|
||||
],
|
||||
'sumberInfoLainnyaValue' => 'Lainnya',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -154,6 +155,14 @@ class AksesPasarController extends Controller
|
||||
Rule::requiredIf(fn () => in_array(SaluranTerdahulu::LAINNYA->value, $request->input('saluran_terdahulu', []), true)),
|
||||
'nullable', 'string', 'max:255'
|
||||
],
|
||||
|
||||
'tahu_harga_sebelumnya' => ['nullable', 'string', 'max:255'],
|
||||
'sumber_info_harga' => ['nullable', 'array'],
|
||||
'sumber_info_harga.*' => ['string'],
|
||||
'sumber_info_harga_lainnya' => [
|
||||
Rule::requiredIf(fn () => in_array('Lainnya', $request->input('sumber_info_harga', []), true)),
|
||||
'nullable', 'string', 'max:255'
|
||||
],
|
||||
|
||||
'praktik_fermentasi' => ['nullable', 'string', Rule::in(PraktikFermentasi::values())],
|
||||
'proses_fermentasi' => [
|
||||
@@ -216,7 +225,6 @@ class AksesPasarController extends Controller
|
||||
{
|
||||
$payload = collect($validated)->except(['harga_jual'])->all();
|
||||
|
||||
// Bersihkan input teks "Lainnya" jika checkbox Lainnya tidak dipilih
|
||||
if (!in_array('Lainnya', $payload['tujuan_penjualan'] ?? [], true)) {
|
||||
$payload['tujuan_penjualan_lainnya'] = null;
|
||||
}
|
||||
@@ -232,6 +240,10 @@ class AksesPasarController extends Controller
|
||||
$payload['saluran_terdahulu_lainnya'] = null;
|
||||
}
|
||||
|
||||
if (!in_array('Lainnya', $payload['sumber_info_harga'] ?? [], true)) {
|
||||
$payload['sumber_info_harga_lainnya'] = null;
|
||||
}
|
||||
|
||||
if (($payload['praktik_fermentasi'] ?? null) === PraktikFermentasi::BELUM_PERNAH->value) {
|
||||
$payload['proses_fermentasi'] = null;
|
||||
$payload['model_fermentasi_memungkinkan'] = null;
|
||||
@@ -274,7 +286,7 @@ class AksesPasarController extends Controller
|
||||
$data['harga_jual'][$index]['harga_tahun_lalu'] = $this->currencyDigits($item['harga_tahun_lalu']);
|
||||
}
|
||||
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']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,9 @@ class AksesPasar extends Model
|
||||
'saluran_terdahulu',
|
||||
'saluran_terdahulu_lainnya',
|
||||
'alasan_berhenti',
|
||||
'tahu_harga_sebelumnya',
|
||||
'sumber_info_harga',
|
||||
'sumber_info_harga_lainnya',
|
||||
'praktik_fermentasi',
|
||||
'proses_fermentasi',
|
||||
'model_fermentasi_memungkinkan',
|
||||
@@ -51,6 +54,7 @@ class AksesPasar extends Model
|
||||
protected $casts = [
|
||||
'tujuan_penjualan' => 'array',
|
||||
'saluran_terdahulu' => 'array',
|
||||
'sumber_info_harga' => 'array',
|
||||
];
|
||||
|
||||
protected static function booted(): void
|
||||
|
||||
@@ -61,7 +61,7 @@ return new class extends Migration
|
||||
$table->integer('harga_tahun_lalu')->nullable();
|
||||
$table->integer('harga_dua_tahun_lalu')->nullable();
|
||||
|
||||
$table ->foreignId('created_by')->nullable()->constrained('users')->onDelete('set null');
|
||||
$table ->foreignId('created_by')->nullable()->constrained('users')->onDelete('set null');
|
||||
$table ->foreignId('updated_by')->nullable()->constrained('users')->onDelete('set null');
|
||||
$table ->foreignId('deleted_by')->nullable()->constrained('users')->onDelete('set null');
|
||||
|
||||
|
||||
+28
@@ -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
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('akses_pasar', function (Blueprint $table) {
|
||||
$table->string('tahu_harga_sebelumnya')->nullable();
|
||||
$table->text('sumber_info_harga')->nullable();
|
||||
$table->string('sumber_info_harga_lainnya')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('akses_pasar', function (Blueprint $table) {
|
||||
$table->dropColumn([
|
||||
'tahu_harga_sebelumnya',
|
||||
'sumber_info_harga',
|
||||
'sumber_info_harga_lainnya',
|
||||
]);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -3,12 +3,12 @@
|
||||
@push('style')
|
||||
<style>
|
||||
.pasar-filter-card .filter-item {
|
||||
min-width: 210px;
|
||||
min-width: 190px;
|
||||
}
|
||||
|
||||
.pasar-kpi-value {
|
||||
color: var(--bs-heading-color);
|
||||
font-size: 1.85rem;
|
||||
font-size: 1.6rem;
|
||||
font-weight: 600;
|
||||
line-height: 1.2;
|
||||
overflow-wrap: anywhere;
|
||||
@@ -25,14 +25,103 @@
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.pasar-empty-state {
|
||||
min-height: 220px;
|
||||
.chart-group-header-toggle {
|
||||
cursor: pointer;
|
||||
background-color: rgba(var(--bs-primary-rgb, 115, 103, 240), 0.08);
|
||||
border-inline-start: 4px solid var(--bs-primary, #9D8EF0);
|
||||
box-shadow: none;
|
||||
transition: background-color 0.2s ease;
|
||||
}
|
||||
|
||||
.chart-group-header-toggle:hover {
|
||||
background-color: rgba(var(--bs-primary-rgb, 115, 103, 240), 0.13);
|
||||
}
|
||||
|
||||
.chart-group-header-toggle .card-body {
|
||||
padding: 12px 16px;
|
||||
}
|
||||
|
||||
.chart-group-header-toggle h5 {
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
margin-bottom: 2px;
|
||||
}
|
||||
|
||||
.chart-group-header-toggle:focus-visible {
|
||||
outline: 2px solid var(--bs-primary);
|
||||
outline-offset: 3px;
|
||||
}
|
||||
|
||||
.chart-group-icon-toggle {
|
||||
width: 34px;
|
||||
height: 34px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.chart-group-icon-toggle .icon-base {
|
||||
font-size: 24px;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
}
|
||||
|
||||
.chart-group-panel.show,
|
||||
.chart-group-panel.collapsing {
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.pasar-chart-card .card-title h5 {
|
||||
color: var(--bs-heading-color);
|
||||
font-size: 1.125rem;
|
||||
font-weight: 500;
|
||||
line-height: 1.35;
|
||||
letter-spacing: 0;
|
||||
}
|
||||
|
||||
.pasar-chart-card .card-title small,
|
||||
.chart-group-header-toggle p {
|
||||
font-size: 0.8125rem;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.pasar-chart {
|
||||
min-height: 330px;
|
||||
}
|
||||
|
||||
.pasar-chart-empty {
|
||||
min-height: 330px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: var(--bs-secondary-color);
|
||||
font-size: 0.8125rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.pasar-chart-card .apexcharts-tooltip {
|
||||
background: transparent !important;
|
||||
border: none !important;
|
||||
box-shadow: none !important;
|
||||
overflow: visible !important;
|
||||
white-space: normal;
|
||||
max-width: 260px;
|
||||
}
|
||||
|
||||
.pasar-chart-tooltip {
|
||||
border-radius: 5px;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, .15);
|
||||
padding: 8px 12px;
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
line-height: 1.25;
|
||||
}
|
||||
|
||||
.pasar-trend-tooltip-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
margin-top: 6px;
|
||||
}
|
||||
|
||||
@media (max-width: 575.98px) {
|
||||
.pasar-filter-card .filter-item {
|
||||
width: 100%;
|
||||
@@ -47,35 +136,6 @@
|
||||
<form id="form-filter" class="col-12" method="GET" action="{{ route('dashboard.pasar') }}">
|
||||
<div class="card card-border-shadow-primary pasar-filter-card">
|
||||
<div class="card-body py-3">
|
||||
<div class="d-flex align-items-center gap-2 flex-wrap">
|
||||
<div class="d-flex align-items-center me-2">
|
||||
<i class="icon-base ti tabler-adjustments-horizontal me-2"></i>
|
||||
<span class="fw-medium">Komoditas <span class="text-danger">*</span></span>
|
||||
</div>
|
||||
|
||||
<div class="filter-item">
|
||||
<select id="filter-komoditas" class="form-select form-select-sm" name="komoditas_id">
|
||||
<option value="">Pilih Komoditas</option>
|
||||
@foreach ($komoditas as $item)
|
||||
<option value="{{ $item->id }}" {{ old('komoditas_id', $komoditas_id) == $item->id ? 'selected' : '' }}>
|
||||
{{ $item->nama }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-outline-secondary btn-sm">
|
||||
<i class="icon-base ti tabler-filter me-1"></i>
|
||||
Filter
|
||||
</button>
|
||||
<button type="button" id="btn-reset-dashboard-filter" class="btn btn-outline-secondary btn-sm">
|
||||
<i class="icon-base ti tabler-refresh me-1"></i>
|
||||
Reset
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<hr class="my-3">
|
||||
|
||||
<div class="d-flex align-items-center gap-2 flex-wrap">
|
||||
<div class="d-flex align-items-center me-2">
|
||||
<i class="icon-base ti tabler-map-2 me-2"></i>
|
||||
@@ -111,39 +171,57 @@
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr class="my-3">
|
||||
|
||||
<div class="d-flex align-items-center gap-2 flex-wrap">
|
||||
<div class="d-flex align-items-center me-2">
|
||||
<i class="icon-base ti tabler-adjustments-horizontal me-2"></i>
|
||||
<span class="fw-medium">Data</span>
|
||||
</div>
|
||||
|
||||
<div class="filter-item">
|
||||
<select id="filter-komoditas" class="form-select form-select-sm" name="komoditas_id">
|
||||
<option value="">Semua Komoditas</option>
|
||||
@foreach ($komoditas as $item)
|
||||
<option value="{{ $item->id }}" {{ old('komoditas_id', $komoditas_id) == $item->id ? 'selected' : '' }}>
|
||||
{{ $item->nama }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="filter-item">
|
||||
<select id="filter-segmen" class="form-select form-select-sm" name="segmen">
|
||||
<option value="">Semua Segmen</option>
|
||||
@foreach ($segments as $segment)
|
||||
<option value="{{ $segment['name'] }}" {{ old('segmen', $segmen) == $segment['name'] ? 'selected' : '' }}>
|
||||
{{ $segment['name'] }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-outline-secondary btn-sm">
|
||||
<i class="icon-base ti tabler-filter me-1"></i>
|
||||
Filter
|
||||
</button>
|
||||
<button type="button" id="btn-reset-dashboard-filter" class="btn btn-outline-secondary btn-sm">
|
||||
<i class="icon-base ti tabler-refresh me-1"></i>
|
||||
Reset
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@if (! $selectedKomoditas)
|
||||
<div class="alert alert-primary d-flex align-items-start gap-3" role="alert">
|
||||
<i class="icon-base ti tabler-info-circle mt-1"></i>
|
||||
<div>
|
||||
<h6 class="alert-heading mb-1">Pilih komoditas terlebih dahulu</h6>
|
||||
<div>Data dashboard pasar baru akan ditampilkan setelah filter komoditas wajib diisi.</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body pasar-empty-state">
|
||||
<div>
|
||||
<div class="avatar avatar-lg mx-auto mb-3">
|
||||
<span class="avatar-initial rounded bg-label-primary">
|
||||
<i class="icon-base ti tabler-building-store icon-28px"></i>
|
||||
</span>
|
||||
</div>
|
||||
<h5 class="mb-1">Belum ada data pasar yang ditampilkan</h5>
|
||||
<p class="text-body-secondary mb-0">Gunakan filter komoditas untuk melihat harga jual rata-rata.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@else
|
||||
<div class="row g-4 mb-4">
|
||||
<div class="col-xl-4 col-md-6">
|
||||
<div class="row g-4 mb-4">
|
||||
@foreach ($priceCards as $priceCard)
|
||||
<div class="col-12 col-md-6 col-xl-3">
|
||||
<div class="card card-border-shadow-{{ $priceCard['variant'] }} h-100">
|
||||
<div class="card-body">
|
||||
<div class="d-flex align-items-center gap-4">
|
||||
<div class="d-flex flex-column align-items-start gap-3">
|
||||
<div class="avatar avatar-lg">
|
||||
<span class="avatar-initial rounded bg-label-{{ $priceCard['variant'] }}">
|
||||
<i class="icon-base ti {{ $priceCard['icon'] }} icon-28px"></i>
|
||||
@@ -161,15 +239,125 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 pt-3 border-top d-flex align-items-center justify-content-between gap-3">
|
||||
<span class="badge bg-label-success">{{ $priceCard['caption'] }}</span>
|
||||
<div class="mt-4 pt-3 border-top d-flex align-items-center justify-content-between gap-2 flex-wrap">
|
||||
<span class="badge bg-label-{{ $priceCard['variant'] }}">{{ $priceCard['records'] > 0 ? 'Rata-rata harga' : 'Belum ada data' }}</span>
|
||||
<small class="text-body-secondary">{{ number_format($priceCard['records'], 0, ',', '.') }} data harga</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
|
||||
<div class="card chart-group-header-toggle mb-4" role="button" tabindex="0"
|
||||
data-bs-toggle="collapse" data-bs-target="#saluran-harga-charts"
|
||||
aria-expanded="false" aria-controls="saluran-harga-charts" aria-label="Tampilkan chart">
|
||||
<div class="card-body d-flex justify-content-between align-items-center gap-3">
|
||||
<div>
|
||||
<h5>Saluran & Harga</h5>
|
||||
<p class="mb-0 text-body-secondary">Saluran penjualan, hubungan dengan pembeli, waktu penjualan, akses ke saluran alternatif, dan tren harga.</p>
|
||||
</div>
|
||||
<span class="btn btn-icon btn-label-secondary btn-sm chart-group-icon-toggle" aria-hidden="true">
|
||||
<i class="icon-base ti tabler-chevron-down"></i>
|
||||
</span>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
@php
|
||||
$chartDefinitions = [
|
||||
'saluranPenjualan' => ['title' => 'Saluran Penjualan Utama', 'description' => 'Kepada siapa petani biasanya menjual hasil panen?', 'variant' => 'success'],
|
||||
'hubunganPembeli' => ['title' => 'Sifat Hubungan dengan Pembeli', 'description' => 'Hubungan jual petani dengan pembeli utama saat ini.', 'variant' => 'primary'],
|
||||
'waktuPenjualan' => ['title' => 'Waktu Penjualan Hasil Panen', 'description' => 'Kapan petani biasanya menjual hasil panen?', 'variant' => 'warning'],
|
||||
'aksesSaluranLain' => ['title' => 'Pengalaman & Akses ke Saluran Lain', 'description' => 'Pengalaman menjual ke tempat lain dan akses yang masih dimiliki.', 'variant' => 'info'],
|
||||
];
|
||||
@endphp
|
||||
|
||||
<div class="collapse chart-group-panel" id="saluran-harga-charts">
|
||||
<div class="row g-4 mb-4">
|
||||
@foreach ($chartDefinitions as $key => $definition)
|
||||
<div class="col-12 col-lg-6">
|
||||
<div class="card pasar-chart-card h-100">
|
||||
<div class="card-header d-flex align-items-start justify-content-between gap-2">
|
||||
<div class="card-title mb-0">
|
||||
<h5 class="m-0 me-2" id="title-{{ $key }}">{{ $definition['title'] }}</h5>
|
||||
<small class="text-body-secondary">{{ $definition['description'] }}</small>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body d-flex flex-column">
|
||||
<div id="chart-{{ $key }}" class="pasar-chart" role="img" aria-labelledby="title-{{ $key }}" aria-describedby="summary-{{ $key }}"></div>
|
||||
<span id="summary-{{ $key }}" class="visually-hidden">
|
||||
@foreach ($marketCharts[$key]['labels'] as $index => $label)
|
||||
{{ $label }}: {{ $marketCharts[$key]['series'][$index] }} responden ({{ $marketCharts[$key]['percentages'][$index] }}%).
|
||||
@endforeach
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
@forelse ($priceTrend['commodities'] as $commodity)
|
||||
<div class="col-12 col-lg-6">
|
||||
<div class="card pasar-chart-card h-100">
|
||||
<div class="card-header">
|
||||
<div class="card-title mb-0">
|
||||
<h5 class="m-0 me-2" id="title-tren-harga-{{ $commodity['id'] }}">Tren Harga 3 Musim — {{ $commodity['name'] }}</h5>
|
||||
<small class="text-body-secondary">Rata-rata harga jual per bentuk produk selama tiga periode panen (Rp/kg).</small>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div id="chart-tren-harga-{{ $commodity['id'] }}" class="pasar-chart" role="img" aria-labelledby="title-tren-harga-{{ $commodity['id'] }}" aria-describedby="summary-tren-harga-{{ $commodity['id'] }}"></div>
|
||||
<span id="summary-tren-harga-{{ $commodity['id'] }}" class="visually-hidden"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@empty
|
||||
<div class="col-12">
|
||||
<div class="card pasar-chart-card">
|
||||
<div class="card-header">
|
||||
<div class="card-title mb-0"><h5 class="m-0">Tren Harga 3 Musim</h5></div>
|
||||
</div>
|
||||
<div class="card-body pasar-chart-empty">Belum ada komoditas untuk filter yang dipilih.</div>
|
||||
</div>
|
||||
</div>
|
||||
@endforelse
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card chart-group-header-toggle mb-4" role="button" tabindex="0"
|
||||
data-bs-toggle="collapse" data-bs-target="#kesiapan-premium-charts"
|
||||
aria-expanded="false" aria-controls="kesiapan-premium-charts" aria-label="Tampilkan chart">
|
||||
<div class="card-body d-flex justify-content-between align-items-center gap-3">
|
||||
<div>
|
||||
<h5>Kesiapan Pasar Premium</h5>
|
||||
<p class="mb-0 text-body-secondary">Kesadaran petani tentang pasar premium, persyaratan masuk, dan pengalaman mengaksesnya.</p>
|
||||
</div>
|
||||
<span class="btn btn-icon btn-label-secondary btn-sm chart-group-icon-toggle" aria-hidden="true">
|
||||
<i class="icon-base ti tabler-chevron-down"></i>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="collapse chart-group-panel" id="kesiapan-premium-charts">
|
||||
<div class="row g-4 mb-4">
|
||||
<div class="col-12">
|
||||
<div class="card pasar-chart-card">
|
||||
<div class="card-header">
|
||||
<div class="card-title mb-0">
|
||||
<h5 class="m-0 me-2" id="title-kesadaranPremium">Kesadaran Pasar Premium</h5>
|
||||
<small class="text-body-secondary">Pengetahuan tentang pasar premium dan persyaratan yang dibutuhkan untuk masuk ke pasar tersebut.</small>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div id="chart-kesadaranPremium" class="pasar-chart" role="img" aria-labelledby="title-kesadaranPremium" aria-describedby="summary-kesadaranPremium"></div>
|
||||
<span id="summary-kesadaranPremium" class="visually-hidden">
|
||||
@foreach ($premiumAwareness['fullLabels'] as $index => $label)
|
||||
{{ $label }}: {{ $premiumAwareness['series'][$index] }} responden ({{ $premiumAwareness['percentages'][$index] }}%).
|
||||
@endforeach
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@@ -177,6 +365,230 @@
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const wilayah = @json($wilayah);
|
||||
const marketCharts = @json($marketCharts);
|
||||
const chartDefinitions = @json($chartDefinitions);
|
||||
const priceTrend = @json($priceTrend);
|
||||
const premiumAwareness = @json($premiumAwareness);
|
||||
|
||||
function escapeHtml(value) {
|
||||
const element = document.createElement('span');
|
||||
element.textContent = String(value);
|
||||
return element.innerHTML;
|
||||
}
|
||||
|
||||
function formatNumber(value, digits = 0) {
|
||||
return Number(value).toLocaleString('id-ID', { maximumFractionDigits: digits });
|
||||
}
|
||||
|
||||
const compactLabels = {
|
||||
saluranPenjualan: ['Tengkulak/pedagang lokal', 'Koperasi', 'BUMDes', 'Pembeli langsung/eksportir', 'Lainnya'],
|
||||
waktuPenjualan: ['Langsung setelah panen', 'Ditumpuk beberapa waktu', 'Saat butuh uang mendesak'],
|
||||
aksesSaluranLain: ['Tidak pernah', 'Berhenti, tanpa akses', 'Berhenti, bisa kembali', 'Sesekali masih menjual', 'Akses alternatif aktif'],
|
||||
kesadaranPremium: ['Belum pernah mendengar', 'Belum paham persyaratan', 'Sedikit paham persyaratan', 'Paham, belum mengakses', 'Akses premium konsisten'],
|
||||
};
|
||||
const mobileLabels = {
|
||||
saluranPenjualan: ['Tengkulak/lokal', 'Koperasi', 'BUMDes', 'Pembeli/eksportir', 'Lainnya'],
|
||||
hubunganPembeli: ['Bebas pindah', 'Langganan tetap', 'Berbasis hutang', 'Titip jual', 'Komitmen volume', 'Semi-kontrak'],
|
||||
waktuPenjualan: ['Setelah panen', 'Ditumpuk dulu', 'Uang mendesak'],
|
||||
aksesSaluranLain: ['Tidak pernah', 'Tanpa akses', 'Bisa kembali', 'Sesekali jual', 'Akses aktif'],
|
||||
kesadaranPremium: ['Belum mendengar', 'Belum paham syarat', 'Sedikit paham', 'Paham, belum akses', 'Akses konsisten'],
|
||||
};
|
||||
|
||||
function hasTrendData(commodity) {
|
||||
return commodity && commodity.series.some(function (series) {
|
||||
return series.data.some(function (value) { return value !== null && Number(value) > 0; });
|
||||
});
|
||||
}
|
||||
|
||||
function formatPrice(value) {
|
||||
return value === null || value === undefined ? 'Belum ada data' : 'Rp ' + formatNumber(value) + '/kg';
|
||||
}
|
||||
|
||||
function renderPriceTrend(commodity) {
|
||||
const element = document.getElementById('chart-tren-harga-' + commodity.id);
|
||||
const summary = document.getElementById('summary-tren-harga-' + commodity.id);
|
||||
|
||||
if (!hasTrendData(commodity) || typeof ApexCharts === 'undefined') {
|
||||
element.classList.add('pasar-chart-empty');
|
||||
element.textContent = !hasTrendData(commodity)
|
||||
? 'Belum ada data harga untuk komoditas dan filter yang dipilih.'
|
||||
: 'Chart belum dapat dimuat. Silakan muat ulang halaman.';
|
||||
return;
|
||||
}
|
||||
|
||||
summary.textContent = commodity.name + '. ' + commodity.series.map(function (series) {
|
||||
return series.name + ': ' + series.data.map(function (value, index) {
|
||||
return priceTrend.periods[index] + ' ' + formatPrice(value);
|
||||
}).join(', ');
|
||||
}).join('. ');
|
||||
|
||||
const colors = config.chartColors.series.slice(0, 4);
|
||||
const labelStyle = { colors: config.colors.bodyColor, fontSize: '12px', fontFamily: config.fontFamily };
|
||||
new ApexCharts(element, {
|
||||
chart: { type: 'line', height: 360, fontFamily: config.fontFamily, foreColor: config.colors.bodyColor, toolbar: { show: false }, zoom: { enabled: false } },
|
||||
series: commodity.series,
|
||||
colors: colors,
|
||||
stroke: { width: 3, curve: 'straight' },
|
||||
markers: { size: 5, strokeWidth: 2, hover: { sizeOffset: 2 } },
|
||||
dataLabels: { enabled: false },
|
||||
xaxis: {
|
||||
categories: priceTrend.periods,
|
||||
tickPlacement: 'between',
|
||||
labels: { rotate: 0, style: labelStyle },
|
||||
axisBorder: { color: config.chartColors.grid },
|
||||
axisTicks: { color: config.chartColors.grid },
|
||||
},
|
||||
yaxis: {
|
||||
min: 0,
|
||||
title: { text: 'Harga (Rp/kg)', style: { color: config.colors.bodyColor, fontFamily: config.fontFamily, fontWeight: 400 } },
|
||||
labels: { style: labelStyle, formatter: function (value) { return formatNumber(value); } },
|
||||
},
|
||||
grid: { borderColor: config.chartColors.grid, strokeDashArray: 4, padding: { left: 8, right: 20 } },
|
||||
legend: { position: 'bottom', fontSize: '13px', fontFamily: config.fontFamily, labels: { colors: config.colors.bodyColor }, itemMargin: { horizontal: 12, vertical: 6 } },
|
||||
tooltip: {
|
||||
shared: true,
|
||||
intersect: false,
|
||||
custom: function ({ dataPointIndex }) {
|
||||
const rows = commodity.series.map(function (series, index) {
|
||||
return `<div class="pasar-trend-tooltip-row"><span style="color:${colors[index]}">${escapeHtml(series.name)}</span><strong>${formatPrice(series.data[dataPointIndex])}</strong></div>`;
|
||||
}).join('');
|
||||
return `<div class="pasar-chart-tooltip" style="background:${config.colors.cardColor};color:${config.colors.headingColor}"><strong>${escapeHtml(commodity.name)} — ${escapeHtml(priceTrend.periods[dataPointIndex])}</strong>${rows}</div>`;
|
||||
},
|
||||
},
|
||||
responsive: [{
|
||||
breakpoint: 576,
|
||||
options: {
|
||||
chart: { height: 420 },
|
||||
legend: { fontSize: '12px', itemMargin: { horizontal: 6, vertical: 4 } },
|
||||
xaxis: {
|
||||
labels: {
|
||||
hideOverlappingLabels: false,
|
||||
style: { fontSize: '11px' },
|
||||
formatter: function (value) {
|
||||
return { 'Dua Tahun Lalu': '2 thn lalu', 'Tahun Lalu': 'Tahun lalu', 'Panen Terakhir': 'Terakhir' }[value] || value;
|
||||
},
|
||||
},
|
||||
},
|
||||
yaxis: {
|
||||
title: { text: undefined },
|
||||
labels: { style: { fontSize: '11px' }, formatter: function (value) { return formatNumber(value); } },
|
||||
},
|
||||
},
|
||||
}],
|
||||
}).render();
|
||||
}
|
||||
|
||||
function renderResponseChart(key, data, definition) {
|
||||
const element = document.getElementById('chart-' + key);
|
||||
if (!data.respondents || typeof ApexCharts === 'undefined') {
|
||||
element.classList.add('pasar-chart-empty');
|
||||
element.textContent = !data.respondents
|
||||
? 'Belum ada data jawaban untuk filter yang dipilih.'
|
||||
: 'Chart belum dapat dimuat. Silakan muat ulang halaman.';
|
||||
return;
|
||||
}
|
||||
|
||||
const color = config.chartColors.semantic[definition.variant];
|
||||
const borderColor = config.chartColors.grid;
|
||||
const labelStyle = { colors: config.colors.bodyColor, fontSize: '12px', fontFamily: config.fontFamily };
|
||||
const maxCount = Math.max(...data.series);
|
||||
const tickCount = Math.min(4, maxCount);
|
||||
const axisMax = Math.ceil(maxCount * 1.25 / tickCount) * tickCount;
|
||||
|
||||
new ApexCharts(element, {
|
||||
chart: { type: 'bar', height: 330, fontFamily: config.fontFamily, foreColor: config.colors.bodyColor, toolbar: { show: false } },
|
||||
series: [{ name: 'Responden', data: data.series }],
|
||||
colors: [color],
|
||||
plotOptions: { bar: { horizontal: true, borderRadius: 5, barHeight: '62%', dataLabels: { position: 'top' } } },
|
||||
dataLabels: {
|
||||
enabled: true,
|
||||
textAnchor: 'start',
|
||||
offsetX: 6,
|
||||
style: { fontSize: '12px', fontFamily: config.fontFamily, fontWeight: 500, colors: [config.colors.headingColor] },
|
||||
formatter: function (value, options) {
|
||||
return `${formatNumber(value)} (${formatNumber(data.percentages[options.dataPointIndex], 1)}%)`;
|
||||
},
|
||||
},
|
||||
xaxis: {
|
||||
categories: compactLabels[key] || data.labels,
|
||||
min: 0,
|
||||
max: axisMax,
|
||||
tickAmount: tickCount,
|
||||
labels: { style: labelStyle, formatter: function (value) { return formatNumber(value); } },
|
||||
axisBorder: { color: borderColor },
|
||||
axisTicks: { color: borderColor },
|
||||
},
|
||||
yaxis: { labels: { maxWidth: 185, style: labelStyle } },
|
||||
grid: { borderColor: borderColor, strokeDashArray: 4, padding: { right: 20 } },
|
||||
legend: { show: false },
|
||||
tooltip: {
|
||||
theme: document.documentElement.getAttribute('data-bs-theme') === 'dark' ? 'dark' : 'light',
|
||||
custom: function ({ dataPointIndex }) {
|
||||
return `<div class="pasar-chart-tooltip" style="background:${color};color:${config.colors.headingColor};font-family:${config.fontFamily}">${escapeHtml(data.fullLabels[dataPointIndex])}: <strong>${formatNumber(data.series[dataPointIndex])} responden (${formatNumber(data.percentages[dataPointIndex], 1)}%)</strong></div>`;
|
||||
},
|
||||
},
|
||||
responsive: [{
|
||||
breakpoint: 576,
|
||||
options: {
|
||||
xaxis: { categories: mobileLabels[key], tickAmount: 2 },
|
||||
yaxis: { labels: { maxWidth: 125, style: { fontSize: '11px' } } },
|
||||
grid: { padding: { right: 10 } },
|
||||
dataLabels: { style: { fontSize: '11px' }, formatter: function (value) { return formatNumber(value); } },
|
||||
},
|
||||
}],
|
||||
}).render();
|
||||
}
|
||||
|
||||
function renderMarketCharts() {
|
||||
Object.entries(marketCharts).forEach(function ([key, data]) {
|
||||
renderResponseChart(key, data, chartDefinitions[key]);
|
||||
});
|
||||
priceTrend.commodities.forEach(renderPriceTrend);
|
||||
}
|
||||
|
||||
function setupChartPanel(panelId, renderCharts) {
|
||||
const chartPanel = document.getElementById(panelId);
|
||||
const chartControl = document.querySelector('.chart-group-header-toggle[aria-controls="' + chartPanel.id + '"]');
|
||||
const chartIcon = chartControl.querySelector('.chart-group-icon-toggle i');
|
||||
let rendered = false;
|
||||
|
||||
function syncChartPanelState() {
|
||||
const expanded = chartPanel.classList.contains('show');
|
||||
const label = expanded ? 'Sembunyikan chart' : 'Tampilkan chart';
|
||||
chartControl.setAttribute('aria-expanded', String(expanded));
|
||||
chartControl.setAttribute('aria-label', label);
|
||||
chartControl.title = label;
|
||||
chartIcon.classList.toggle('tabler-chevron-up', expanded);
|
||||
chartIcon.classList.toggle('tabler-chevron-down', !expanded);
|
||||
}
|
||||
|
||||
chartControl.addEventListener('keydown', function (event) {
|
||||
if (event.target !== chartControl || !['Enter', ' '].includes(event.key)) return;
|
||||
event.preventDefault();
|
||||
chartControl.click();
|
||||
});
|
||||
|
||||
chartPanel.addEventListener('shown.bs.collapse', function (event) {
|
||||
if (event.target !== chartPanel) return;
|
||||
syncChartPanelState();
|
||||
if (!rendered) {
|
||||
renderCharts();
|
||||
rendered = true;
|
||||
}
|
||||
window.dispatchEvent(new Event('resize'));
|
||||
});
|
||||
|
||||
chartPanel.addEventListener('hidden.bs.collapse', function (event) {
|
||||
if (event.target === chartPanel) syncChartPanelState();
|
||||
});
|
||||
|
||||
syncChartPanelState();
|
||||
}
|
||||
|
||||
setupChartPanel('saluran-harga-charts', renderMarketCharts);
|
||||
setupChartPanel('kesiapan-premium-charts', function () {
|
||||
renderResponseChart('kesadaranPremium', premiumAwareness, { variant: 'primary' });
|
||||
});
|
||||
|
||||
function fillSelect($select, items, placeholder) {
|
||||
$select.empty().append(new Option(placeholder, ''));
|
||||
@@ -208,7 +620,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
});
|
||||
}
|
||||
|
||||
$('#filter-provinsi, #filter-kabkota, #filter-kecamatan, #filter-desa, #filter-komoditas').select2({ width: '100%' });
|
||||
$('#filter-provinsi, #filter-kabkota, #filter-kecamatan, #filter-desa, #filter-komoditas, #filter-segmen').select2({ width: '100%' });
|
||||
|
||||
$('#filter-provinsi').on('change', function () {
|
||||
const provinsi = selectedProvinsi();
|
||||
|
||||
@@ -31,12 +31,12 @@
|
||||
<div class="card mb-6">
|
||||
<div class="card-body pt-12">
|
||||
|
||||
<h5 class="pb-3 border-bottom mb-4">Saluran Penjualan & Akses Pasar</h5>
|
||||
<h5 class="pb-4 border-bottom mb-4">Saluran Penjualan & Akses Pasar</h5>
|
||||
|
||||
<h6 class="fw-bold text-dark mb-2">Saluran Penjualan Utama</h6>
|
||||
<h5 class="mb-4 mt-4">Saluran Penjualan Utama</h5>
|
||||
<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>
|
||||
<div class="row g-2">
|
||||
<p class="form-label d-block">Kepada siapa Bapak/Ibu biasanya menjual hasil panen? (boleh pilih lebih dari satu)</p>
|
||||
<div class="row">
|
||||
@php
|
||||
$tujuanOptions = ['Tengkulak/pedagang lokal', 'Koperasi', 'BUMDes', 'Langsung ke pembeli/eksportir'];
|
||||
@endphp
|
||||
@@ -55,16 +55,16 @@
|
||||
<input class="form-check-input" type="checkbox" name="tujuan_penjualan[]" value="Lainnya" id="tujuan-lainnya" {{ in_array('Lainnya', (array) old('tujuan_penjualan', $aksesPasar?->tujuan_penjualan ?? []), true) ? 'checked' : '' }}>
|
||||
<label class="form-check-label" for="tujuan-lainnya">Lainnya:</label>
|
||||
</div>
|
||||
<input type="text" class="form-control form-control-sm w-auto flex-grow-1 max-w-400" style="max-width: 400px;" name="tujuan_penjualan_lainnya" value="{{ old('tujuan_penjualan_lainnya', $aksesPasar?->tujuan_penjualan_lainnya) }}" placeholder="Sebutkan lainnya...">
|
||||
<input type="text" class="form-control w-auto flex-grow-1 max-w-400" style="max-width: 400px;" name="tujuan_penjualan_lainnya" value="{{ old('tujuan_penjualan_lainnya', $aksesPasar?->tujuan_penjualan_lainnya) }}" placeholder="Sebutkan lainnya...">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h6 class="fw-bold text-dark mt-4 mb-2">Sifat Hubungan dengan Pembeli</h6>
|
||||
<h5 class="mb-4 mt-4">Sifat Hubungan Dengan Pembeli</h5>
|
||||
<div class="mb-4">
|
||||
<label class="form-label fw-semibold">Bagaimana sifat hubungan jual Bapak/Ibu dengan pembeli utama saat ini?</label>
|
||||
<div class="row g-2">
|
||||
<p class="form-label d-block">Bagaimana sifat hubungan jual Bapak/Ibu dengan pembeli utama saat ini?</p>
|
||||
<div class="row">
|
||||
@php
|
||||
$sifatHubunganOptions = [
|
||||
'Bebas, bisa pindah pembeli kapan saja',
|
||||
@@ -86,10 +86,10 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h6 class="fw-bold text-dark mt-4 mb-2">Bentuk Produk yang Dijual</h6>
|
||||
<h5 class="mb-4 mt-4">Bentuk Produk Yang Dijual</h5>
|
||||
<div class="mb-4">
|
||||
<label class="form-label fw-semibold">Dalam bentuk apa produk dijual?</label>
|
||||
<div class="row g-2">
|
||||
<p class="form-label d-block">Dalam bentuk apa produk dijual?</p>
|
||||
<div class="row">
|
||||
@php
|
||||
$bentukPenjualanOptions = [
|
||||
'Buah segar hasil petik (gelondongan)',
|
||||
@@ -109,10 +109,10 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h6 class="fw-bold text-dark mt-4 mb-2">Frekuensi Penjualan</h6>
|
||||
<h5 class="mb-4 mt-4">Frekuensi Penjualan</h5>
|
||||
<div class="mb-4">
|
||||
<label class="form-label fw-semibold">Kapan biasanya menjual hasil panen?</label>
|
||||
<div class="d-flex flex-column gap-2">
|
||||
<p class="form-label d-block">Kapan biasanya menjual hasil panen?</p>
|
||||
<div class="d-flex flex-column">
|
||||
@php
|
||||
$frekuensiOptions = [
|
||||
'Langsung setelah panen',
|
||||
@@ -121,20 +121,19 @@
|
||||
];
|
||||
@endphp
|
||||
@foreach($frekuensiOptions as $freq)
|
||||
<div class="form-check mb-1">
|
||||
<div class="form-check mb-2">
|
||||
<input class="form-check-input" type="radio" name="frekuensi_penjualan" value="{{ $freq }}" id="freq-{{ Str::slug($freq) }}" {{ old('frekuensi_penjualan', $aksesPasar?->frekuensi_penjualan) === $freq ? 'checked' : '' }}>
|
||||
<label class="form-check-label" for="freq-{{ Str::slug($freq) }}">{{ $freq }}</label>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
<hr class="my-4">
|
||||
|
||||
<h5 class="pb-3 border-bottom mb-4">Pengalaman Saluran Lain</h5>
|
||||
<h5 class="pb-4 border-bottom mb-4 mt-4">Pengalaman Saluran Lain</h5>
|
||||
<div class="row">
|
||||
|
||||
<div class="col-md-6 mb-4 form-control-validation">
|
||||
<label class="form-label d-block fw-bold">Pengalaman & akses ke saluran lain</label>
|
||||
<div class="col-md-12 mb-4 form-control-validation">
|
||||
<label class="form-label d-block">Apakah pernah menjual ke tempat lain sebelumnya?</label>
|
||||
@foreach($skorPengalamanOptions as $option)
|
||||
<div class="form-check mb-2">
|
||||
<input class="form-check-input @error('skor_pengalaman') is-invalid @enderror" type="radio"
|
||||
@@ -146,41 +145,67 @@
|
||||
@error('skor_pengalaman')<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="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 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>
|
||||
@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 class="col-md-6 mb-4"></div>
|
||||
|
||||
<div class="col-md-12 mb-4 form-control-validation">
|
||||
<label class="form-label d-block" for="saluran-terdahulu">Jika pernah, dulu menjual ke mana? (boleh pilih lebih dari satu)</label>
|
||||
<div class="row">
|
||||
@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 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>
|
||||
@error('saluran_terdahulu')<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>
|
||||
</div>
|
||||
|
||||
<h5 class="pb-3 border-bottom mb-4 mt-4">HARGA DI SETIAP TITIK</h5>
|
||||
<h6 class="mb-2">Harga Jual Panen Terakhir</h6>
|
||||
<p class="mb-1">Harga jual komoditas tiga musim panen terakhir:</p>
|
||||
<p class="mb-4">Dalam tiga musim panen terakhir, berapa harga jual yang Bapak/Ibu terima untuk komoditas ini sesuai dengan bentuk produk yang dijual?</p>
|
||||
<h5 class="pb-4 border-bottom mb-4 mt-4">Harga Di Setiap Titik</h5>
|
||||
<h5 class="mb-4 mt-4">Harga Jual Panen Terakhir</h5>
|
||||
<p class="form-label d-block">Harga jual komoditas tiga musim panen terakhir:</p>
|
||||
<p class="form-label d-block">Dalam tiga musim panen terakhir, berapa harga jual yang Bapak/Ibu terima untuk komoditas ini sesuai dengan bentuk produk yang dijual?</p>
|
||||
|
||||
<div class="table-responsive mb-4">
|
||||
<table class="table table-bordered align-middle">
|
||||
@@ -197,7 +222,7 @@
|
||||
<tr>
|
||||
<td>
|
||||
<input type="hidden" name="harga_jual[{{ $row['index'] }}][bentuk_produk]" value="{{ $row['bentuk'] }}">
|
||||
<strong>{{ $row['bentuk'] }}:</strong>
|
||||
{{ $row['bentuk'] }}:
|
||||
</td>
|
||||
<td>
|
||||
<div class="input-group">
|
||||
@@ -226,18 +251,87 @@
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<h5 class="pb-3 border-bottom mb-4 mt-4">PELUANG NILAI TAMBAH</h5>
|
||||
|
||||
<div class="border rounded p-4 mb-4">
|
||||
<h5 class="mb-4 mt-4">Sumber Informasi Harga</h5>
|
||||
<div class="mb-4">
|
||||
|
||||
<div class="mb-4">
|
||||
<h6 class="mb-1 text-primary">Detail Praktik Fermentasi</h6>
|
||||
<p class="text-muted small mb-0">Apakah sudah ada praktik fermentasi atau pengolahan pascapanen yang Ibu/Bapak lakukan?</p>
|
||||
<p class="form-label d-block">Sebelum menjual, apakah Bapak/Ibu sudah tahu harga yang akan diterima?</p>
|
||||
<div class="row">
|
||||
@php
|
||||
$tahuHargaOptions = [
|
||||
'Selalu tahu sebelum pergi jual',
|
||||
'Kadang tahu, kadang tidak',
|
||||
'Baru tahu saat sudah di tempat pembeli',
|
||||
'Tidak pernah tahu sebelumnya — langsung jual saja'
|
||||
];
|
||||
@endphp
|
||||
@foreach($tahuHargaOptions as $tahu)
|
||||
<div class="col-md-6">
|
||||
<div class="form-check mb-2">
|
||||
<input class="form-check-input @error('tahu_harga_sebelumnya') is-invalid @enderror" type="radio" name="tahu_harga_sebelumnya" value="{{ $tahu }}" id="tahu-{{ Str::slug($tahu) }}" {{ old('tahu_harga_sebelumnya', $aksesPasar?->tahu_harga_sebelumnya) === $tahu ? 'checked' : '' }}>
|
||||
<label class="form-check-label" for="tahu-{{ Str::slug($tahu) }}">{{ $tahu }}</label>
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
@error('tahu_harga_sebelumnya')<div class="invalid-feedback d-block">{{ $message }}</div>@enderror
|
||||
</div>
|
||||
|
||||
<div class="mb-0">
|
||||
<p class="form-label d-block">Dari mana biasanya Bapak/Ibu tahu harga hasil panen sebelum menjual? (boleh pilih lebih dari satu)</p>
|
||||
<div class="row">
|
||||
@php
|
||||
$sumberInfoHargaOptions = [
|
||||
'Tengkulak/pedagang yang datang langsung',
|
||||
'Sesama petani/tetangga',
|
||||
'PPL/petugas dinas',
|
||||
'HP/WhatsApp/internet',
|
||||
'Radio/TV',
|
||||
'Facebook',
|
||||
'Tiktok',
|
||||
'Instagram',
|
||||
'Tidak pernah cek — langsung jual saja'
|
||||
];
|
||||
$sumberInfoLainnyaValue = 'Lainnya';
|
||||
@endphp
|
||||
|
||||
@foreach($sumberInfoHargaOptions as $sumber)
|
||||
<div class="col-md-4">
|
||||
<div class="form-check mb-2">
|
||||
<input class="form-check-input @error('sumber_info_harga') is-invalid @enderror" type="checkbox" name="sumber_info_harga[]" value="{{ $sumber }}" id="sumber-{{ Str::slug($sumber) }}" {{ in_array($sumber, (array) old('sumber_info_harga', $aksesPasar?->sumber_info_harga ?? []), true) ? 'checked' : '' }}>
|
||||
<label class="form-check-label" for="sumber-{{ Str::slug($sumber) }}">{{ $sumber }}</label>
|
||||
</div>
|
||||
</div>
|
||||
@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('sumber_info_harga') is-invalid @enderror" type="checkbox" name="sumber_info_harga[]" value="{{ $sumberInfoLainnyaValue }}" id="sumber-lainnya-checkbox" {{ in_array($sumberInfoLainnyaValue, (array) old('sumber_info_harga', $aksesPasar?->sumber_info_harga ?? []), true) ? 'checked' : '' }}>
|
||||
<label class="form-check-label text-nowrap" for="sumber-lainnya-checkbox">Lainnya:</label>
|
||||
</div>
|
||||
<input type="text" class="form-control w-auto flex-grow-1 @error('sumber_info_harga_lainnya') is-invalid @enderror" style="max-width: 400px;" id="sumber-info-lainnya-input" name="sumber_info_harga_lainnya" value="{{ old('sumber_info_harga_lainnya', $aksesPasar?->sumber_info_harga_lainnya) }}" placeholder="Sebutkan sumber lainnya...">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@error('sumber_info_harga')<div class="invalid-feedback d-block">{{ $message }}</div>@enderror
|
||||
@error('sumber_info_harga_lainnya')<div class="invalid-feedback d-block">{{ $message }}</div>@enderror
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<h5 class="pb-4 border-bottom mb-4 mt-4">Peluang Nilai Tambah</h5>
|
||||
|
||||
<div class="mb-4">
|
||||
<div class="mb-4">
|
||||
<h5 class="mb-4 mt-4">Detail Praktik Fermentasi</h5>
|
||||
<p class="form-label d-block">Apakah sudah ada praktik fermentasi atau pengolahan pascapanen yang Ibu/Bapak lakukan?</p>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-4 mb-4 form-control-validation d-flex flex-column">
|
||||
<div class="mb-2 d-flex align-items-end">
|
||||
<label class="form-label mb-0" for="praktik-fermentasi">Praktik fermentasi yang dilakukan</label>
|
||||
<div class="d-flex align-items-end">
|
||||
<label class="form-label" for="praktik-fermentasi">Praktik fermentasi yang dilakukan</label>
|
||||
</div>
|
||||
<div>
|
||||
@foreach($praktikFermentasiOptions as $option)
|
||||
@@ -258,8 +352,8 @@
|
||||
</div>
|
||||
|
||||
<div class="col-md-4 mb-4 form-control-validation d-flex flex-column">
|
||||
<div class="mb-2 d-flex align-items-end">
|
||||
<label class="form-label mb-0" for="proses-fermentasi">Jika ya, bagaimana prosesnya?</label>
|
||||
<div class="d-flex align-items-end">
|
||||
<label class="form-label" for="proses-fermentasi">Jika ya, bagaimana prosesnya?</label>
|
||||
</div>
|
||||
<div>
|
||||
<textarea class="form-control @error('proses_fermentasi') is-invalid @enderror" id="proses-fermentasi" name="proses_fermentasi" rows="2" placeholder="Ceritakan prosesnya di sini...">{{ old('proses_fermentasi', $aksesPasar?->proses_fermentasi) }}</textarea>
|
||||
@@ -268,8 +362,8 @@
|
||||
</div>
|
||||
|
||||
<div class="col-md-4 mb-4 form-control-validation d-flex flex-column">
|
||||
<div class="mb-2 d-flex align-items-end">
|
||||
<label class="form-label mb-0" for="model-fermentasi">Menurut Bapak/Ibu, apa model yang paling memungkinkan?</label>
|
||||
<div class="d-flex align-items-end">
|
||||
<label class="form-label" for="model-fermentasi">Menurut Bapak/Ibu, apa model yang paling memungkinkan?</label>
|
||||
</div>
|
||||
<div>
|
||||
<textarea class="form-control @error('model_fermentasi_memungkinkan') is-invalid @enderror" id="model-fermentasi" name="model_fermentasi_memungkinkan" rows="2" placeholder="Model fermentasinya...">{{ old('model_fermentasi_memungkinkan', $aksesPasar?->model_fermentasi_memungkinkan) }}</textarea>
|
||||
@@ -279,11 +373,11 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h5 class="pb-3 border-bottom mb-4 mt-4">AKSES PASAR PREMIUM</h5>
|
||||
<h6 class="mb-3">Kesadaran Pasar Premium*</h6>
|
||||
<h5 class="pb-4 border-bottom mb-4 mt-4">Akses Pasar Premium</h5>
|
||||
<h5 class="mb-4 mt-4">Kesadaran Pasar Premium*</h5>
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-4 form-control-validation">
|
||||
<label class="form-label d-block mb-2" for="skor-premium">Pengetahuan & akses pasar premium</label>
|
||||
<label class="form-label d-block" for="skor-premium">Pengetahuan & akses pasar premium</label>
|
||||
@foreach($skorKesadaranPremiumOptions as $option)
|
||||
<div class="form-check mb-2">
|
||||
<input class="form-check-input @error('skor_kesadaran_premium') is-invalid @enderror"
|
||||
@@ -301,16 +395,16 @@
|
||||
</div>
|
||||
|
||||
<div class="col-md-6 mb-4 form-control-validation">
|
||||
<label class="form-label mb-2" for="sumber-info">Sumber informasi utama</label>
|
||||
<label class="form-label" for="sumber-info">Sumber informasi utama</label>
|
||||
<input type="text" class="form-control @error('sumber_info_premium') is-invalid @enderror" id="sumber-info" name="sumber_info_premium" value="{{ old('sumber_info_premium', $aksesPasar?->sumber_info_premium) }}">
|
||||
@error('sumber_info_premium')<div class="invalid-feedback">{{ $message }}</div>@enderror
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h5 class="pb-3 border-bottom mb-4 mt-4">KEPERCAYAAN & PERSEPSI RISIKO</h5>
|
||||
<h5 class="pb-4 border-bottom mb-4 mt-4">Kepercayaan & Persepsi Risiko</h5>
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-4 form-control-validation">
|
||||
<label class="form-label d-block mb-2" for="tingkat-kepercayaan">Seberapa percaya Bapak/Ibu untuk menjual ke pembeli atau pasar baru, di luar pembeli yang biasa?</label>
|
||||
<label class="form-label d-block" for="tingkat-kepercayaan">Seberapa percaya Bapak/Ibu untuk menjual ke pembeli atau pasar baru, di luar pembeli yang biasa?</label>
|
||||
@foreach($tingkatKepercayaanOptions as $option)
|
||||
<div class="form-check mb-2">
|
||||
<input class="form-check-input @error('tingkat_kepercayaan_pembeli_baru') is-invalid @enderror"
|
||||
@@ -328,7 +422,7 @@
|
||||
</div>
|
||||
|
||||
<div class="col-md-6 mb-4 form-control-validation">
|
||||
<label class="form-label mb-2" for="alasan-kepercayaan">Apa yang membuat Bapak/Ibu ragu atau yakin untuk mencoba pembeli baru?</label>
|
||||
<label class="form-label" for="alasan-kepercayaan">Apa yang membuat Bapak/Ibu ragu atau yakin untuk mencoba pembeli baru?</label>
|
||||
<textarea class="form-control @error('alasan_kepercayaan_pembeli_baru') is-invalid @enderror"
|
||||
id="alasan-kepercayaan"
|
||||
name="alasan_kepercayaan_pembeli_baru"
|
||||
@@ -341,7 +435,7 @@
|
||||
<div class="mt-4 text-end">
|
||||
<a href="{{ route('petani.index') }}#data-petani" class="btn btn-secondary me-2">Kembali</a>
|
||||
<button type="submit" class="btn btn-success">
|
||||
<i class="icon-base ti tabler-device-floppy me-1_5 icon-sm"></i>Simpan Akses Pasar
|
||||
<i class="icon-base ti tabler-check me-1_5 icon-sm"></i>Simpan
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -359,6 +453,8 @@
|
||||
const saluranLainnyaValue = @json($saluranLainnyaValue);
|
||||
const praktikBelumPernahValue = String(@json($praktikBelumPernahValue));
|
||||
const skorPengalamanBerhentiValues = @json($skorPengalamanBerhentiValues ?? [2,3]).map(Number);
|
||||
const skorBelumPernahValue = "1";
|
||||
const sumberInfoLainnyaValue = @json($sumberInfoLainnyaValue ?? 'Lainnya');
|
||||
|
||||
function onlyDigits(value) {
|
||||
return String(value || '').replace(/\D/g, '');
|
||||
@@ -369,6 +465,22 @@
|
||||
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() {
|
||||
const val = Number($('input[name="skor_pengalaman"]:checked').val());
|
||||
const isBerhenti = skorPengalamanBerhentiValues.includes(val);
|
||||
@@ -382,6 +494,12 @@
|
||||
if (!isLainnya) $('#saluran-lainnya').val('');
|
||||
}
|
||||
|
||||
function syncSumberInfoLainnya() {
|
||||
const isLainnya = $('input[name="sumber_info_harga[]"][value="' + sumberInfoLainnyaValue + '"]').is(':checked');
|
||||
$('#sumber-info-lainnya-input').prop('disabled', !isLainnya);
|
||||
if (!isLainnya) $('#sumber-info-lainnya-input').val('');
|
||||
}
|
||||
|
||||
function syncPraktikFermentasi() {
|
||||
const isBelumPernah = $('input[name="praktik_fermentasi"]:checked').val() === praktikBelumPernahValue;
|
||||
$('#proses-fermentasi, #model-fermentasi').prop('disabled', isBelumPernah);
|
||||
@@ -390,9 +508,15 @@
|
||||
}
|
||||
}
|
||||
|
||||
$('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="sumber_info_harga[]"]').on('change', syncSumberInfoLainnya);
|
||||
$('input[name="praktik_fermentasi"]').on('change', syncPraktikFermentasi);
|
||||
|
||||
$(document).on('input', '.rupiah-input', function () {
|
||||
const cursorAtEnd = this.selectionStart === this.value.length;
|
||||
this.value = formatRupiah(this.value);
|
||||
@@ -401,13 +525,16 @@
|
||||
this.setSelectionRange(this.value.length, this.value.length);
|
||||
}
|
||||
});
|
||||
|
||||
$('.rupiah-input').each(function () {
|
||||
this.value = formatRupiah(this.value);
|
||||
});
|
||||
|
||||
toggleSaluranLanjutan();
|
||||
syncAlasanBerhenti();
|
||||
syncSaluranLainnya();
|
||||
syncSumberInfoLainnya();
|
||||
syncPraktikFermentasi();
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
@endpush
|
||||
|
||||
@@ -0,0 +1,338 @@
|
||||
<?php
|
||||
|
||||
use App\Http\Controllers\Web\Dashboard\SummaryController;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
beforeEach(function () {
|
||||
Schema::create('master_komoditas', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('nama');
|
||||
$table->softDeletes();
|
||||
});
|
||||
foreach ([
|
||||
'master_kabupaten_kota' => 'provinsi_id',
|
||||
'master_kecamatan' => 'kabupaten_kota_id',
|
||||
'master_desa_kelurahan' => 'kecamatan_id',
|
||||
] as $name => $parent) {
|
||||
Schema::create($name, function (Blueprint $table) use ($parent) {
|
||||
$table->id();
|
||||
$table->integer($parent);
|
||||
});
|
||||
}
|
||||
Schema::create('petani', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->integer('komoditas_id');
|
||||
$table->integer('desa_kelurahan_id');
|
||||
$table->softDeletes();
|
||||
});
|
||||
Schema::create('harga_jual_panen', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->integer('petani_id');
|
||||
$table->string('bentuk_produk');
|
||||
$table->integer('harga_panen_terakhir')->nullable();
|
||||
$table->integer('harga_tahun_lalu')->nullable();
|
||||
$table->integer('harga_dua_tahun_lalu')->nullable();
|
||||
});
|
||||
Schema::create('petani_skor', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->integer('petani_id');
|
||||
$table->float('skor_kesiapan_adopsi');
|
||||
$table->softDeletes();
|
||||
});
|
||||
Schema::create('akses_pasar', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->integer('petani_id');
|
||||
$table->text('tujuan_penjualan')->nullable();
|
||||
$table->text('sifat_hubungan_bisnis')->nullable();
|
||||
$table->string('frekuensi_penjualan')->nullable();
|
||||
$table->integer('skor_pengalaman')->nullable();
|
||||
$table->integer('skor_kesadaran_premium')->nullable();
|
||||
$table->softDeletes();
|
||||
});
|
||||
|
||||
DB::table('master_komoditas')->insert([
|
||||
['id' => 1, 'nama' => 'Kakao'], ['id' => 2, 'nama' => 'Vanili'],
|
||||
['id' => 3, 'nama' => 'Kopi'], ['id' => 4, 'nama' => 'Kemiri'],
|
||||
]);
|
||||
DB::table('master_kabupaten_kota')->insert(['id' => 1, 'provinsi_id' => 1]);
|
||||
DB::table('master_kecamatan')->insert(['id' => 1, 'kabupaten_kota_id' => 1]);
|
||||
DB::table('master_desa_kelurahan')->insert([
|
||||
['id' => 1, 'kecamatan_id' => 1], ['id' => 2, 'kecamatan_id' => 1],
|
||||
]);
|
||||
DB::table('petani')->insert([
|
||||
['id' => 1, 'komoditas_id' => 1, 'desa_kelurahan_id' => 1, 'deleted_at' => null],
|
||||
['id' => 2, 'komoditas_id' => 1, 'desa_kelurahan_id' => 2, 'deleted_at' => null],
|
||||
['id' => 3, 'komoditas_id' => 2, 'desa_kelurahan_id' => 1, 'deleted_at' => null],
|
||||
['id' => 4, 'komoditas_id' => 3, 'desa_kelurahan_id' => 1, 'deleted_at' => null],
|
||||
['id' => 5, 'komoditas_id' => 4, 'desa_kelurahan_id' => 1, 'deleted_at' => null],
|
||||
['id' => 6, 'komoditas_id' => 1, 'desa_kelurahan_id' => 1, 'deleted_at' => '2026-01-01'],
|
||||
]);
|
||||
foreach ([
|
||||
[1, 'Biji kering/Biji Kupas', 10000], [2, 'Biji kering/Biji Kupas', 20000],
|
||||
[1, 'Biji kering/Biji Kupas', 0], [1, 'Biji kering/Biji Kupas', null],
|
||||
[1, 'Biji kering/Biji Kupas', -1000], [1, 'Biji basah', 90000],
|
||||
[1, 'Buah segar hasil petik', 5000],
|
||||
[3, 'Buah segar hasil petik', 30000], [3, 'Biji kering/Biji Kupas', 500000],
|
||||
[3, 'Terfermentasi (Rp/kg)', 900000], [4, 'Buah segar hasil petik', 12000],
|
||||
[5, 'Buah segar hasil petik', 8000], [5, 'Biji kering/Biji Kupas', 40000],
|
||||
[6, 'Biji kering/Biji Kupas', 1000000],
|
||||
] as [$farmer, $product, $price]) {
|
||||
DB::table('harga_jual_panen')->insert([
|
||||
'petani_id' => $farmer, 'bentuk_produk' => $product, 'harga_panen_terakhir' => $price,
|
||||
]);
|
||||
}
|
||||
DB::table('petani_skor')->insert([
|
||||
['petani_id' => 1, 'skor_kesiapan_adopsi' => 4.2, 'deleted_at' => null],
|
||||
['petani_id' => 2, 'skor_kesiapan_adopsi' => 2.5, 'deleted_at' => null],
|
||||
['petani_id' => 3, 'skor_kesiapan_adopsi' => 4.5, 'deleted_at' => '2026-01-01'],
|
||||
]);
|
||||
|
||||
$controller = app(SummaryController::class);
|
||||
$method = new ReflectionMethod($controller, 'marketDashboardData');
|
||||
$this->marketCards = fn (array $filters = []) => $method->invoke($controller, new Request($filters))['priceCards'];
|
||||
$this->marketCharts = fn (array $filters = []) => $method->invoke($controller, new Request($filters))['marketCharts'];
|
||||
$this->priceTrend = fn (array $filters = []) => $method->invoke($controller, new Request($filters))['priceTrend'];
|
||||
$this->premiumAwareness = fn (array $filters = []) => $method->invoke($controller, new Request($filters))['premiumAwareness'];
|
||||
});
|
||||
|
||||
test('market shows all four prices using the appropriate product and positive active farmer prices', function () {
|
||||
$cards = ($this->marketCards)();
|
||||
|
||||
expect(array_column($cards, 'label'))->toBe([
|
||||
'Kakao - Harga Biji Kering', 'Vanili - Harga Buah Segar',
|
||||
'Kopi - Harga Ceri Merah', 'Kemiri - Harga Gelondong',
|
||||
]);
|
||||
expect(array_column($cards, 'value'))->toBe(['Rp 15.000', 'Rp 30.000', 'Rp 12.000', 'Rp 8.000']);
|
||||
expect(array_column($cards, 'records'))->toBe([2, 1, 1, 1]);
|
||||
});
|
||||
|
||||
test('market prices respect each region level and commodity selection', function () {
|
||||
foreach (['provinsi_id', 'kabupatenKota_id', 'kecamatan_id', 'desaKelurahan_id'] as $region) {
|
||||
expect(($this->marketCards)([$region => 1])[0]['value'])
|
||||
->toBe($region === 'desaKelurahan_id' ? 'Rp 10.000' : 'Rp 15.000');
|
||||
expect(array_column(($this->marketCards)([$region => 99]), 'records'))->toBe([0, 0, 0, 0]);
|
||||
}
|
||||
|
||||
$cards = ($this->marketCards)(['komoditas_id' => 2]);
|
||||
expect(array_column($cards, 'records'))->toBe([0, 1, 0, 0]);
|
||||
expect(array_column($cards, 'value'))->toBe(['Rp 0', 'Rp 30.000', 'Rp 0', 'Rp 0']);
|
||||
});
|
||||
|
||||
test('market prices respect segment selection and ignore deleted scores', function () {
|
||||
$cards = ($this->marketCards)(['segmen' => 'Penggerak']);
|
||||
expect(array_column($cards, 'records'))->toBe([1, 0, 0, 0]);
|
||||
expect($cards[0]['value'])->toBe('Rp 10.000');
|
||||
expect(($this->marketCards)(['segmen' => 'Pemerhati'])[0]['value'])->toBe('Rp 20.000');
|
||||
});
|
||||
|
||||
test('market keeps four empty cards when no prices or active commodities are available', function () {
|
||||
DB::table('master_komoditas')->update(['deleted_at' => '2026-01-01']);
|
||||
|
||||
$cards = ($this->marketCards)();
|
||||
expect(array_column($cards, 'records'))->toBe([0, 0, 0, 0]);
|
||||
expect(array_column($cards, 'value'))->toBe(['Rp 0', 'Rp 0', 'Rp 0', 'Rp 0']);
|
||||
});
|
||||
|
||||
test('market charts count multiple channels once per respondent and use answered question denominators', function () {
|
||||
DB::table('akses_pasar')->insert([
|
||||
[
|
||||
'petani_id' => 1,
|
||||
'tujuan_penjualan' => json_encode(['Koperasi', 'BUMDes', 'Koperasi', 'Lainnya']),
|
||||
'sifat_hubungan_bisnis' => 'Bebas, bisa pindah pembeli kapan saja',
|
||||
'frekuensi_penjualan' => 'Langsung setelah panen',
|
||||
'skor_pengalaman' => 5,
|
||||
],
|
||||
[
|
||||
'petani_id' => 2,
|
||||
'tujuan_penjualan' => json_encode(['Koperasi']),
|
||||
'sifat_hubungan_bisnis' => 'Titip jual,dibayar setelah produk terjual',
|
||||
'frekuensi_penjualan' => null,
|
||||
'skor_pengalaman' => 1,
|
||||
],
|
||||
[
|
||||
'petani_id' => 3,
|
||||
'tujuan_penjualan' => '[]',
|
||||
'sifat_hubungan_bisnis' => '',
|
||||
'frekuensi_penjualan' => 'Saat butuh uang mendesak',
|
||||
'skor_pengalaman' => 3,
|
||||
],
|
||||
]);
|
||||
|
||||
$charts = ($this->marketCharts)();
|
||||
expect($charts['saluranPenjualan']['series'])->toBe([0, 2, 1, 0, 1]);
|
||||
expect($charts['saluranPenjualan']['respondents'])->toBe(2);
|
||||
expect($charts['saluranPenjualan']['percentages'])->toBe([0.0, 100.0, 50.0, 0.0, 50.0]);
|
||||
expect($charts['hubunganPembeli']['series'])->toBe([1, 0, 0, 1, 0, 0]);
|
||||
expect($charts['hubunganPembeli']['respondents'])->toBe(2);
|
||||
expect($charts['waktuPenjualan']['series'])->toBe([1, 0, 1]);
|
||||
expect($charts['waktuPenjualan']['respondents'])->toBe(2);
|
||||
expect($charts['aksesSaluranLain']['series'])->toBe([1, 0, 1, 0, 1]);
|
||||
expect($charts['aksesSaluranLain']['percentages'])->toBe([33.3, 0.0, 33.3, 0.0, 33.3]);
|
||||
});
|
||||
|
||||
test('market charts respect all dashboard filters and exclude deleted farmers and responses', function () {
|
||||
foreach ([1, 2, 3, 6] as $farmer) {
|
||||
DB::table('akses_pasar')->insert([
|
||||
'petani_id' => $farmer,
|
||||
'tujuan_penjualan' => json_encode(['Koperasi']),
|
||||
'sifat_hubungan_bisnis' => 'Langganan tetap, tapi tidak terikat',
|
||||
'frekuensi_penjualan' => 'Ditumpuk dulu beberapa waktu',
|
||||
'skor_pengalaman' => 4,
|
||||
]);
|
||||
}
|
||||
DB::table('akses_pasar')->insert([
|
||||
'petani_id' => 4, 'tujuan_penjualan' => json_encode(['BUMDes']), 'deleted_at' => '2026-01-01',
|
||||
]);
|
||||
|
||||
foreach (['provinsi_id', 'kabupatenKota_id', 'kecamatan_id', 'desaKelurahan_id'] as $region) {
|
||||
foreach (($this->marketCharts)([$region => 1]) as $chart) {
|
||||
expect($chart['respondents'])->toBe($region === 'desaKelurahan_id' ? 2 : 3);
|
||||
}
|
||||
foreach (($this->marketCharts)([$region => 99]) as $chart) {
|
||||
expect($chart['respondents'])->toBe(0);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ([['komoditas_id' => 1], ['komoditas_id' => 2], ['segmen' => 'Penggerak'], ['segmen' => 'Pemerhati']] as $filters) {
|
||||
foreach (($this->marketCharts)($filters) as $chart) {
|
||||
expect($chart['respondents'])->toBe($filters === ['komoditas_id' => 1] ? 2 : 1);
|
||||
}
|
||||
}
|
||||
foreach (($this->marketCharts)(['komoditas_id' => 2, 'segmen' => 'Penggerak']) as $chart) {
|
||||
expect($chart['respondents'])->toBe(0);
|
||||
}
|
||||
});
|
||||
|
||||
test('market charts keep ordered zero categories when answers are missing or invalid', function () {
|
||||
DB::table('akses_pasar')->insert([
|
||||
'petani_id' => 1, 'tujuan_penjualan' => '[null, {}, "Unknown"]',
|
||||
'sifat_hubungan_bisnis' => 'Unknown', 'frekuensi_penjualan' => '', 'skor_pengalaman' => 9,
|
||||
]);
|
||||
|
||||
$charts = ($this->marketCharts)();
|
||||
expect(array_map(fn ($chart) => count($chart['series']), $charts))->toBe([
|
||||
'saluranPenjualan' => 5, 'hubunganPembeli' => 6, 'waktuPenjualan' => 3, 'aksesSaluranLain' => 5,
|
||||
]);
|
||||
foreach ($charts as $chart) {
|
||||
expect($chart['respondents'])->toBe(0);
|
||||
expect(array_sum($chart['series']))->toBe(0);
|
||||
expect(array_sum($chart['percentages']))->toBe(0);
|
||||
}
|
||||
});
|
||||
|
||||
test('price trend averages each product and commodity chronologically without treating missing prices as zero', function () {
|
||||
DB::table('harga_jual_panen')->delete();
|
||||
foreach ([
|
||||
[1, 'Buah segar hasil petik', 10000, 8000, 6000],
|
||||
[2, 'Buah segar hasil petik', 20000, 12000, null],
|
||||
[3, 'Buah segar hasil petik', 30000, 20000, 10000],
|
||||
[1, 'Biji basah', 0, 7000, 4000],
|
||||
[1, 'Biji kering/Biji Kupas', -1000, null, 0],
|
||||
[1, 'Terfermentasi (Rp/kg)', null, 20000, 10000],
|
||||
[6, 'Buah segar hasil petik', 1000000, 1000000, 1000000],
|
||||
] as [$farmer, $product, $latest, $lastYear, $twoYearsAgo]) {
|
||||
DB::table('harga_jual_panen')->insert([
|
||||
'petani_id' => $farmer, 'bentuk_produk' => $product,
|
||||
'harga_panen_terakhir' => $latest, 'harga_tahun_lalu' => $lastYear, 'harga_dua_tahun_lalu' => $twoYearsAgo,
|
||||
]);
|
||||
}
|
||||
|
||||
$trend = ($this->priceTrend)();
|
||||
$commodities = array_column($trend['commodities'], null, 'id');
|
||||
expect($trend['periods'])->toBe(['Dua Tahun Lalu', 'Tahun Lalu', 'Panen Terakhir']);
|
||||
expect(array_column($commodities[1]['series'], 'name'))->toBe([
|
||||
'Buah segar hasil petik', 'Biji basah', 'Biji kering/Biji Kupas', 'Terfermentasi',
|
||||
]);
|
||||
expect(array_column($commodities[1]['series'], 'data'))->toBe([
|
||||
[6000.0, 10000.0, 15000.0], [4000.0, 7000.0, null], [null, null, null], [10000.0, 20000.0, null],
|
||||
]);
|
||||
expect($commodities[2]['series'][0]['data'])->toBe([10000.0, 20000.0, 30000.0]);
|
||||
});
|
||||
|
||||
test('price trend respects dashboard region commodity and segment filters', function () {
|
||||
// Historical prices must follow the same filters as the latest harvest.
|
||||
DB::table('harga_jual_panen')->where('harga_panen_terakhir', '>', 0)
|
||||
->update(['harga_tahun_lalu' => DB::raw('harga_panen_terakhir / 2')]);
|
||||
|
||||
foreach (['provinsi_id', 'kabupatenKota_id', 'kecamatan_id', 'desaKelurahan_id'] as $region) {
|
||||
$commodities = array_column(($this->priceTrend)([$region => 1])['commodities'], null, 'id');
|
||||
$price = $region === 'desaKelurahan_id' ? 10000.0 : 15000.0;
|
||||
expect($commodities[1]['series'][2]['data'])->toBe([null, $price / 2, $price]);
|
||||
foreach (($this->priceTrend)([$region => 99])['commodities'] as $commodity) {
|
||||
expect(array_column($commodity['series'], 'data'))->toBe(array_fill(0, 4, [null, null, null]));
|
||||
}
|
||||
}
|
||||
|
||||
$trend = ($this->priceTrend)(['komoditas_id' => 2]);
|
||||
expect(array_column($trend['commodities'], 'id'))->toBe([2]);
|
||||
expect($trend['commodities'][0]['series'][0]['data'])->toBe([null, 15000.0, 30000.0]);
|
||||
|
||||
foreach (['Penggerak' => 10000.0, 'Pemerhati' => 20000.0] as $segment => $price) {
|
||||
$commodities = array_column(($this->priceTrend)(['segmen' => $segment])['commodities'], null, 'id');
|
||||
expect($commodities[1]['series'][2]['data'])->toBe([null, $price / 2, $price]);
|
||||
expect($commodities[2]['series'][0]['data'])->toBe([null, null, null]);
|
||||
}
|
||||
});
|
||||
|
||||
test('price trend retains missing points and handles empty or deleted commodity selections', function () {
|
||||
DB::table('harga_jual_panen')->delete();
|
||||
$trend = ($this->priceTrend)();
|
||||
expect($trend['commodities'])->toHaveCount(4);
|
||||
foreach ($trend['commodities'] as $commodity) {
|
||||
expect(array_column($commodity['series'], 'data'))->toBe(array_fill(0, 4, [null, null, null]));
|
||||
}
|
||||
|
||||
expect(($this->priceTrend)(['komoditas_id' => 99])['commodities'])->toBe([]);
|
||||
DB::table('master_komoditas')->where('id', 1)->update(['deleted_at' => '2026-01-01']);
|
||||
expect(($this->priceTrend)(['komoditas_id' => 1])['commodities'])->toBe([]);
|
||||
});
|
||||
|
||||
test('premium awareness counts each active farmer once and preserves the five ordered levels', function () {
|
||||
DB::table('akses_pasar')->insert([
|
||||
'petani_id' => 4, 'skor_kesadaran_premium' => 4, 'deleted_at' => '2026-01-01',
|
||||
]);
|
||||
foreach ([1 => 1, 2 => 3, 3 => 3, 4 => 5, 5 => null, 6 => 5] as $farmer => $score) {
|
||||
DB::table('akses_pasar')->insert(['petani_id' => $farmer, 'skor_kesadaran_premium' => $score]);
|
||||
}
|
||||
DB::table('akses_pasar')->insert(['petani_id' => 1, 'skor_kesadaran_premium' => 2]);
|
||||
|
||||
$chart = ($this->premiumAwareness)();
|
||||
expect($chart['series'])->toBe([1, 0, 2, 0, 1]);
|
||||
expect($chart['percentages'])->toBe([25.0, 0.0, 50.0, 0.0, 25.0]);
|
||||
expect($chart['respondents'])->toBe(4);
|
||||
expect($chart['fullLabels'][0])->toBe('Belum pernah mendengar sama sekali');
|
||||
expect($chart['fullLabels'][4])->toBe('Sudah mengakses dan mendapat harga premium secara konsisten');
|
||||
});
|
||||
|
||||
test('premium awareness respects all dashboard region commodity and segment filters', function () {
|
||||
foreach ([1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 5] as $farmer => $score) {
|
||||
DB::table('akses_pasar')->insert(['petani_id' => $farmer, 'skor_kesadaran_premium' => $score]);
|
||||
}
|
||||
|
||||
foreach (['provinsi_id', 'kabupatenKota_id', 'kecamatan_id', 'desaKelurahan_id'] as $region) {
|
||||
$chart = ($this->premiumAwareness)([$region => 1]);
|
||||
expect($chart['respondents'])->toBe($region === 'desaKelurahan_id' ? 4 : 5);
|
||||
expect(($this->premiumAwareness)([$region => 99])['respondents'])->toBe(0);
|
||||
}
|
||||
expect(($this->premiumAwareness)(['komoditas_id' => 1])['series'])->toBe([1, 1, 0, 0, 0]);
|
||||
expect(($this->premiumAwareness)(['komoditas_id' => 2])['series'])->toBe([0, 0, 1, 0, 0]);
|
||||
expect(($this->premiumAwareness)(['segmen' => 'Penggerak'])['series'])->toBe([1, 0, 0, 0, 0]);
|
||||
expect(($this->premiumAwareness)(['segmen' => 'Pemerhati'])['series'])->toBe([0, 1, 0, 0, 0]);
|
||||
expect(($this->premiumAwareness)(['komoditas_id' => 2, 'segmen' => 'Penggerak'])['respondents'])->toBe(0);
|
||||
});
|
||||
|
||||
test('premium awareness retains empty categories and excludes missing or invalid scores', function () {
|
||||
$emptyChart = ($this->premiumAwareness)();
|
||||
foreach ([1 => 0, 2 => 6, 3 => null, 4 => -1, 5 => null] as $farmer => $score) {
|
||||
DB::table('akses_pasar')->insert(['petani_id' => $farmer, 'skor_kesadaran_premium' => $score]);
|
||||
}
|
||||
$chart = ($this->premiumAwareness)();
|
||||
expect($chart)->toBe($emptyChart);
|
||||
expect($chart['series'])->toBe([0, 0, 0, 0, 0]);
|
||||
expect($chart['respondents'])->toBe(0);
|
||||
expect($chart['labels'])->toHaveCount(5);
|
||||
expect(array_sum($chart['percentages']))->toBe(0);
|
||||
});
|
||||
Reference in New Issue
Block a user