user-diagnosa done

This commit is contained in:
E31232303evimr 2026-03-04 01:18:14 +07:00
parent 23b28a1590
commit 36514e9123
8 changed files with 1065 additions and 126 deletions

View File

@ -8,6 +8,7 @@
use App\Models\RuleBasis;
use App\Models\RiwayatDiagnosis;
use Illuminate\Http\Request;
use Barryvdh\DomPDF\Facade\Pdf;
class DiagnosaController extends Controller
{
@ -97,14 +98,20 @@ public function hasil($id)
{
$riwayat = RiwayatDiagnosis::with('penyakit')->findOrFail($id);
// Pastikan hanya pemilik yang bisa lihat
if ($riwayat->user_id !== auth()->id()) {
abort(403);
}
$gejalaInput = MasterGejala::whereIn('id_gejala', $riwayat->gejala_input)->get();
return view('user.diagnosa.hasil', compact('riwayat', 'gejalaInput'));
// Ambil relasi gejala-penyakit dari rule_basis
$relasiGejala = RuleBasis::whereIn('id_gejala', $riwayat->gejala_input)
->whereIn('id_penyakit', collect($riwayat->hasil_diagnosa)->pluck('id_penyakit'))
->with(['penyakit', 'gejala'])
->get()
->groupBy('id_penyakit');
return view('user.diagnosa.hasil', compact('riwayat', 'gejalaInput', 'relasiGejala'));
}
public function riwayat()
@ -116,4 +123,38 @@ public function riwayat()
return view('user.diagnosa.riwayat', compact('riwayats'));
}
public function destroy($id)
{
$riwayat = RiwayatDiagnosis::findOrFail($id);
if ($riwayat->user_id !== auth()->id()) {
abort(403);
}
$riwayat->delete();
return redirect()->route('user.diagnosa.riwayat')
->with('success', 'Riwayat diagnosa berhasil dihapus!');
}
public function downloadPdf($id)
{
$riwayat = RiwayatDiagnosis::with('penyakit')->findOrFail($id);
if ($riwayat->user_id !== auth()->id()) {
abort(403);
}
$gejalaInput = MasterGejala::whereIn('id_gejala', $riwayat->gejala_input)->get();
$relasiGejala = RuleBasis::whereIn('id_gejala', $riwayat->gejala_input)
->whereIn('id_penyakit', collect($riwayat->hasil_diagnosa)->pluck('id_penyakit'))
->get()
->groupBy('id_penyakit');
$pdf = Pdf::loadView('user.diagnosa.pdf', compact('riwayat', 'gejalaInput', 'relasiGejala'));
return $pdf->download('hasil-diagnosa-' . $riwayat->id_diagnosis . '.pdf');
}
}

View File

@ -7,6 +7,7 @@
"license": "MIT",
"require": {
"php": "^8.2",
"barryvdh/laravel-dompdf": "^3.1",
"laravel/framework": "^12.0",
"laravel/tinker": "^2.10.1"
},

524
composer.lock generated
View File

@ -4,8 +4,85 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "bdc6d92507d397adf1c269ed49ec424d",
"content-hash": "90ba1bfa56afef0cd88d7d3c0cdcf358",
"packages": [
{
"name": "barryvdh/laravel-dompdf",
"version": "v3.1.1",
"source": {
"type": "git",
"url": "https://github.com/barryvdh/laravel-dompdf.git",
"reference": "8e71b99fc53bb8eb77f316c3c452dd74ab7cb25d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/barryvdh/laravel-dompdf/zipball/8e71b99fc53bb8eb77f316c3c452dd74ab7cb25d",
"reference": "8e71b99fc53bb8eb77f316c3c452dd74ab7cb25d",
"shasum": ""
},
"require": {
"dompdf/dompdf": "^3.0",
"illuminate/support": "^9|^10|^11|^12",
"php": "^8.1"
},
"require-dev": {
"larastan/larastan": "^2.7|^3.0",
"orchestra/testbench": "^7|^8|^9|^10",
"phpro/grumphp": "^2.5",
"squizlabs/php_codesniffer": "^3.5"
},
"type": "library",
"extra": {
"laravel": {
"aliases": {
"PDF": "Barryvdh\\DomPDF\\Facade\\Pdf",
"Pdf": "Barryvdh\\DomPDF\\Facade\\Pdf"
},
"providers": [
"Barryvdh\\DomPDF\\ServiceProvider"
]
},
"branch-alias": {
"dev-master": "3.0-dev"
}
},
"autoload": {
"psr-4": {
"Barryvdh\\DomPDF\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Barry vd. Heuvel",
"email": "barryvdh@gmail.com"
}
],
"description": "A DOMPDF Wrapper for Laravel",
"keywords": [
"dompdf",
"laravel",
"pdf"
],
"support": {
"issues": "https://github.com/barryvdh/laravel-dompdf/issues",
"source": "https://github.com/barryvdh/laravel-dompdf/tree/v3.1.1"
},
"funding": [
{
"url": "https://fruitcake.nl",
"type": "custom"
},
{
"url": "https://github.com/barryvdh",
"type": "github"
}
],
"time": "2025-02-13T15:07:54+00:00"
},
{
"name": "brick/math",
"version": "0.14.7",
@ -377,6 +454,161 @@
],
"time": "2024-02-05T11:56:58+00:00"
},
{
"name": "dompdf/dompdf",
"version": "v3.1.5",
"source": {
"type": "git",
"url": "https://github.com/dompdf/dompdf.git",
"reference": "f11ead23a8a76d0ff9bbc6c7c8fd7e05ca328496"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/dompdf/dompdf/zipball/f11ead23a8a76d0ff9bbc6c7c8fd7e05ca328496",
"reference": "f11ead23a8a76d0ff9bbc6c7c8fd7e05ca328496",
"shasum": ""
},
"require": {
"dompdf/php-font-lib": "^1.0.0",
"dompdf/php-svg-lib": "^1.0.0",
"ext-dom": "*",
"ext-mbstring": "*",
"masterminds/html5": "^2.0",
"php": "^7.1 || ^8.0"
},
"require-dev": {
"ext-gd": "*",
"ext-json": "*",
"ext-zip": "*",
"mockery/mockery": "^1.3",
"phpunit/phpunit": "^7.5 || ^8 || ^9 || ^10 || ^11",
"squizlabs/php_codesniffer": "^3.5",
"symfony/process": "^4.4 || ^5.4 || ^6.2 || ^7.0"
},
"suggest": {
"ext-gd": "Needed to process images",
"ext-gmagick": "Improves image processing performance",
"ext-imagick": "Improves image processing performance",
"ext-zlib": "Needed for pdf stream compression"
},
"type": "library",
"autoload": {
"psr-4": {
"Dompdf\\": "src/"
},
"classmap": [
"lib/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"LGPL-2.1"
],
"authors": [
{
"name": "The Dompdf Community",
"homepage": "https://github.com/dompdf/dompdf/blob/master/AUTHORS.md"
}
],
"description": "DOMPDF is a CSS 2.1 compliant HTML to PDF converter",
"homepage": "https://github.com/dompdf/dompdf",
"support": {
"issues": "https://github.com/dompdf/dompdf/issues",
"source": "https://github.com/dompdf/dompdf/tree/v3.1.5"
},
"time": "2026-03-03T13:54:37+00:00"
},
{
"name": "dompdf/php-font-lib",
"version": "1.0.2",
"source": {
"type": "git",
"url": "https://github.com/dompdf/php-font-lib.git",
"reference": "a6e9a688a2a80016ac080b97be73d3e10c444c9a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/dompdf/php-font-lib/zipball/a6e9a688a2a80016ac080b97be73d3e10c444c9a",
"reference": "a6e9a688a2a80016ac080b97be73d3e10c444c9a",
"shasum": ""
},
"require": {
"ext-mbstring": "*",
"php": "^7.1 || ^8.0"
},
"require-dev": {
"phpunit/phpunit": "^7.5 || ^8 || ^9 || ^10 || ^11 || ^12"
},
"type": "library",
"autoload": {
"psr-4": {
"FontLib\\": "src/FontLib"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"LGPL-2.1-or-later"
],
"authors": [
{
"name": "The FontLib Community",
"homepage": "https://github.com/dompdf/php-font-lib/blob/master/AUTHORS.md"
}
],
"description": "A library to read, parse, export and make subsets of different types of font files.",
"homepage": "https://github.com/dompdf/php-font-lib",
"support": {
"issues": "https://github.com/dompdf/php-font-lib/issues",
"source": "https://github.com/dompdf/php-font-lib/tree/1.0.2"
},
"time": "2026-01-20T14:10:26+00:00"
},
{
"name": "dompdf/php-svg-lib",
"version": "1.0.2",
"source": {
"type": "git",
"url": "https://github.com/dompdf/php-svg-lib.git",
"reference": "8259ffb930817e72b1ff1caef5d226501f3dfeb1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/dompdf/php-svg-lib/zipball/8259ffb930817e72b1ff1caef5d226501f3dfeb1",
"reference": "8259ffb930817e72b1ff1caef5d226501f3dfeb1",
"shasum": ""
},
"require": {
"ext-mbstring": "*",
"php": "^7.1 || ^8.0",
"sabberworm/php-css-parser": "^8.4 || ^9.0"
},
"require-dev": {
"phpunit/phpunit": "^7.5 || ^8 || ^9 || ^10 || ^11"
},
"type": "library",
"autoload": {
"psr-4": {
"Svg\\": "src/Svg"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"LGPL-3.0-or-later"
],
"authors": [
{
"name": "The SvgLib Community",
"homepage": "https://github.com/dompdf/php-svg-lib/blob/master/AUTHORS.md"
}
],
"description": "A library to read, parse and export to PDF SVG files.",
"homepage": "https://github.com/dompdf/php-svg-lib",
"support": {
"issues": "https://github.com/dompdf/php-svg-lib/issues",
"source": "https://github.com/dompdf/php-svg-lib/tree/1.0.2"
},
"time": "2026-01-02T16:01:13+00:00"
},
{
"name": "dragonmantank/cron-expression",
"version": "v3.6.0",
@ -2019,6 +2251,73 @@
],
"time": "2026-01-15T06:54:53+00:00"
},
{
"name": "masterminds/html5",
"version": "2.10.0",
"source": {
"type": "git",
"url": "https://github.com/Masterminds/html5-php.git",
"reference": "fcf91eb64359852f00d921887b219479b4f21251"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Masterminds/html5-php/zipball/fcf91eb64359852f00d921887b219479b4f21251",
"reference": "fcf91eb64359852f00d921887b219479b4f21251",
"shasum": ""
},
"require": {
"ext-dom": "*",
"php": ">=5.3.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8.35 || ^5.7.21 || ^6 || ^7 || ^8 || ^9"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.7-dev"
}
},
"autoload": {
"psr-4": {
"Masterminds\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Matt Butcher",
"email": "technosophos@gmail.com"
},
{
"name": "Matt Farina",
"email": "matt@mattfarina.com"
},
{
"name": "Asmir Mustafic",
"email": "goetas@gmail.com"
}
],
"description": "An HTML5 parser and serializer.",
"homepage": "http://masterminds.github.io/html5-php",
"keywords": [
"HTML5",
"dom",
"html",
"parser",
"querypath",
"serializer",
"xml"
],
"support": {
"issues": "https://github.com/Masterminds/html5-php/issues",
"source": "https://github.com/Masterminds/html5-php/tree/2.10.0"
},
"time": "2025-07-25T09:04:22+00:00"
},
{
"name": "monolog/monolog",
"version": "3.10.0",
@ -3290,6 +3589,86 @@
},
"time": "2025-12-14T04:43:48+00:00"
},
{
"name": "sabberworm/php-css-parser",
"version": "v9.2.0",
"source": {
"type": "git",
"url": "https://github.com/MyIntervals/PHP-CSS-Parser.git",
"reference": "59373045e11ad47b5c18fc615feee0219e42f6d3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/MyIntervals/PHP-CSS-Parser/zipball/59373045e11ad47b5c18fc615feee0219e42f6d3",
"reference": "59373045e11ad47b5c18fc615feee0219e42f6d3",
"shasum": ""
},
"require": {
"ext-iconv": "*",
"php": "^7.2.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0",
"thecodingmachine/safe": "^1.3 || ^2.5 || ^3.4"
},
"require-dev": {
"php-parallel-lint/php-parallel-lint": "1.4.0",
"phpstan/extension-installer": "1.4.3",
"phpstan/phpstan": "1.12.32 || 2.1.32",
"phpstan/phpstan-phpunit": "1.4.2 || 2.0.8",
"phpstan/phpstan-strict-rules": "1.6.2 || 2.0.7",
"phpunit/phpunit": "8.5.52",
"rawr/phpunit-data-provider": "3.3.1",
"rector/rector": "1.2.10 || 2.2.8",
"rector/type-perfect": "1.0.0 || 2.1.0",
"squizlabs/php_codesniffer": "4.0.1",
"thecodingmachine/phpstan-safe-rule": "1.2.0 || 1.4.1"
},
"suggest": {
"ext-mbstring": "for parsing UTF-8 CSS"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "9.3.x-dev"
}
},
"autoload": {
"files": [
"src/Rule/Rule.php",
"src/RuleSet/RuleContainer.php"
],
"psr-4": {
"Sabberworm\\CSS\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Raphael Schweikert"
},
{
"name": "Oliver Klee",
"email": "github@oliverklee.de"
},
{
"name": "Jake Hotson",
"email": "jake.github@qzdesign.co.uk"
}
],
"description": "Parser for CSS Files written in PHP",
"homepage": "https://www.sabberworm.com/blog/2010/6/10/php-css-parser",
"keywords": [
"css",
"parser",
"stylesheet"
],
"support": {
"issues": "https://github.com/MyIntervals/PHP-CSS-Parser/issues",
"source": "https://github.com/MyIntervals/PHP-CSS-Parser/tree/v9.2.0"
},
"time": "2026-02-21T17:12:03+00:00"
},
{
"name": "symfony/clock",
"version": "v7.4.0",
@ -5791,6 +6170,149 @@
],
"time": "2026-01-01T22:13:48+00:00"
},
{
"name": "thecodingmachine/safe",
"version": "v3.4.0",
"source": {
"type": "git",
"url": "https://github.com/thecodingmachine/safe.git",
"reference": "705683a25bacf0d4860c7dea4d7947bfd09eea19"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/thecodingmachine/safe/zipball/705683a25bacf0d4860c7dea4d7947bfd09eea19",
"reference": "705683a25bacf0d4860c7dea4d7947bfd09eea19",
"shasum": ""
},
"require": {
"php": "^8.1"
},
"require-dev": {
"php-parallel-lint/php-parallel-lint": "^1.4",
"phpstan/phpstan": "^2",
"phpunit/phpunit": "^10",
"squizlabs/php_codesniffer": "^3.2"
},
"type": "library",
"autoload": {
"files": [
"lib/special_cases.php",
"generated/apache.php",
"generated/apcu.php",
"generated/array.php",
"generated/bzip2.php",
"generated/calendar.php",
"generated/classobj.php",
"generated/com.php",
"generated/cubrid.php",
"generated/curl.php",
"generated/datetime.php",
"generated/dir.php",
"generated/eio.php",
"generated/errorfunc.php",
"generated/exec.php",
"generated/fileinfo.php",
"generated/filesystem.php",
"generated/filter.php",
"generated/fpm.php",
"generated/ftp.php",
"generated/funchand.php",
"generated/gettext.php",
"generated/gmp.php",
"generated/gnupg.php",
"generated/hash.php",
"generated/ibase.php",
"generated/ibmDb2.php",
"generated/iconv.php",
"generated/image.php",
"generated/imap.php",
"generated/info.php",
"generated/inotify.php",
"generated/json.php",
"generated/ldap.php",
"generated/libxml.php",
"generated/lzf.php",
"generated/mailparse.php",
"generated/mbstring.php",
"generated/misc.php",
"generated/mysql.php",
"generated/mysqli.php",
"generated/network.php",
"generated/oci8.php",
"generated/opcache.php",
"generated/openssl.php",
"generated/outcontrol.php",
"generated/pcntl.php",
"generated/pcre.php",
"generated/pgsql.php",
"generated/posix.php",
"generated/ps.php",
"generated/pspell.php",
"generated/readline.php",
"generated/rnp.php",
"generated/rpminfo.php",
"generated/rrd.php",
"generated/sem.php",
"generated/session.php",
"generated/shmop.php",
"generated/sockets.php",
"generated/sodium.php",
"generated/solr.php",
"generated/spl.php",
"generated/sqlsrv.php",
"generated/ssdeep.php",
"generated/ssh2.php",
"generated/stream.php",
"generated/strings.php",
"generated/swoole.php",
"generated/uodbc.php",
"generated/uopz.php",
"generated/url.php",
"generated/var.php",
"generated/xdiff.php",
"generated/xml.php",
"generated/xmlrpc.php",
"generated/yaml.php",
"generated/yaz.php",
"generated/zip.php",
"generated/zlib.php"
],
"classmap": [
"lib/DateTime.php",
"lib/DateTimeImmutable.php",
"lib/Exceptions/",
"generated/Exceptions/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "PHP core functions that throw exceptions instead of returning FALSE on error",
"support": {
"issues": "https://github.com/thecodingmachine/safe/issues",
"source": "https://github.com/thecodingmachine/safe/tree/v3.4.0"
},
"funding": [
{
"url": "https://github.com/OskarStark",
"type": "github"
},
{
"url": "https://github.com/shish",
"type": "github"
},
{
"url": "https://github.com/silasjoisten",
"type": "github"
},
{
"url": "https://github.com/staabm",
"type": "github"
}
],
"time": "2026-02-04T18:08:13+00:00"
},
{
"name": "tijsverkoyen/css-to-inline-styles",
"version": "v2.4.0",

View File

@ -1,128 +1,132 @@
@extends('layouts.user-app')
@section('page-title', '📋 Hasil Diagnosa')
@section('page-title', 'Hasil Diagnosa')
@section('page-subtitle', 'Hasil analisis penyakit tanaman kopi kamu')
@section('content')
<div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
<!-- Hasil Utama -->
<!-- Kolom Kiri -->
<div class="lg:col-span-2 space-y-6">
<!-- Penyakit Final -->
<div class="bg-white rounded-2xl shadow-lg p-6">
<div class="flex items-center mb-6">
<div class="bg-gradient-to-r from-green-500 to-green-600 rounded-xl p-3 mr-4">
<svg class="w-6 h-6 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
<div class="bg-white rounded-2xl shadow-lg overflow-hidden">
<!-- Header -->
<div style="background: linear-gradient(135deg, #16a34a, #4ade80);" class="p-6 text-white">
<div class="flex flex-wrap items-center justify-between gap-2 mb-3">
<div class="flex flex-wrap items-center gap-2">
<span class="px-3 py-1 text-xs font-bold uppercase tracking-wider rounded-full" style="background:rgba(0,0,0,0.2);">
Penyakit Terdeteksi
</span>
@if($riwayat->penyakit?->tingkat_bahaya)
<span class="px-3 py-1 text-xs font-bold rounded-full
{{ $riwayat->penyakit->tingkat_bahaya === 'Sangat Tinggi' ? 'bg-red-600 text-white' :
($riwayat->penyakit->tingkat_bahaya === 'Tinggi' ? 'bg-orange-500 text-white' :
($riwayat->penyakit->tingkat_bahaya === 'Sedang' ? 'bg-yellow-400 text-yellow-900' : 'bg-green-200 text-green-900')) }}">
⚠️ {{ $riwayat->penyakit->tingkat_bahaya }}
</span>
@endif
</div>
{{-- Tombol Download PDF --}}
<a href="{{ route('user.riwayat.pdf', $riwayat->id_diagnosis) }}"
target="_blank"
class="flex items-center gap-2 px-4 py-2 rounded-xl text-sm font-semibold transition-all duration-200 hover:scale-105 active:scale-95"
style="background:rgba(0,0,0,0.2); color:white; border: 1px solid rgba(255,255,255,0.3); backdrop-filter: blur(4px);"
onmouseover="this.style.background='rgba(0,0,0,0.35)'"
onmouseout="this.style.background='rgba(0,0,0,0.2)'">
<svg xmlns="http://www.w3.org/2000/svg" class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M12 10v6m0 0l-3-3m3 3l3-3M3 17V7a2 2 0 012-2h6l2 2h6a2 2 0 012 2v8a2 2 0 01-2 2H5a2 2 0 01-2-2z" />
</svg>
Download PDF
</a>
</div>
<h1 class="text-2xl font-bold mb-1">{{ $riwayat->penyakit->nama_penyakit ?? 'Tidak Teridentifikasi' }}</h1>
@if($riwayat->penyakit?->nama_latin)
<p class="italic text-sm mb-4" style="color:rgba(255,255,255,0.8);">{{ $riwayat->penyakit->nama_latin }}</p>
@endif
<!-- CF Progress -->
<div class="rounded-xl p-4" style="background:rgba(0,0,0,0.15);">
<div class="flex justify-between items-center mb-3">
<span class="text-sm font-semibold" style="color:rgba(255,255,255,0.9);">Tingkat Kepercayaan</span>
<span class="text-3xl font-bold text-white">{{ round($riwayat->cf_tertinggi * 100, 1) }}%</span>
</div>
<div class="w-full rounded-full h-4" style="background:rgba(0,0,0,0.25);">
<div class="h-4 rounded-full bg-white" style="width: {{ round($riwayat->cf_tertinggi * 100, 1) }}%;"></div>
</div>
<div class="flex justify-between text-xs mt-1" style="color:rgba(255,255,255,0.6);">
<span>0%</span><span>50%</span><span>100%</span>
</div>
</div>
<h3 class="text-xl font-bold text-gray-800">Hasil Diagnosa</h3>
</div>
@if($riwayat->penyakit)
<!-- Penyakit Terdeteksi -->
<div class="bg-gradient-to-r from-green-50 to-green-100 border border-green-200 rounded-xl p-5 mb-4">
<div class="flex items-start justify-between">
<div>
<p class="text-xs text-green-600 font-semibold uppercase mb-1">Penyakit Terdeteksi</p>
<h2 class="text-2xl font-bold text-green-800">{{ $riwayat->penyakit->nama_penyakit }}</h2>
@if($riwayat->penyakit->nama_latin)
<p class="text-sm text-green-600 italic mt-1">{{ $riwayat->penyakit->nama_latin }}</p>
@endif
</div>
<div class="text-right">
<p class="text-xs text-green-600 font-semibold mb-1">Tingkat Kepercayaan</p>
<p class="text-3xl font-bold text-green-700">{{ round($riwayat->cf_tertinggi * 100, 1) }}%</p>
</div>
</div>
<!-- Progress Bar CF -->
<div class="mt-4">
<div class="w-full bg-green-200 rounded-full h-3">
<div class="bg-green-600 h-3 rounded-full transition-all duration-1000"
style="width: {{ round($riwayat->cf_tertinggi * 100, 1) }}%"></div>
</div>
</div>
<!-- Badge tingkat bahaya -->
@if($riwayat->penyakit->tingkat_bahaya)
<div class="mt-3">
<span class="px-3 py-1 text-xs font-bold rounded-full
{{ $riwayat->penyakit->tingkat_bahaya === 'Sangat Tinggi' ? 'bg-red-100 text-red-700' :
($riwayat->penyakit->tingkat_bahaya === 'Tinggi' ? 'bg-orange-100 text-orange-700' :
($riwayat->penyakit->tingkat_bahaya === 'Sedang' ? 'bg-yellow-100 text-yellow-700' : 'bg-green-100 text-green-700')) }}">
⚠️ Tingkat Bahaya: {{ $riwayat->penyakit->tingkat_bahaya }}
</span>
</div>
@endif
</div>
<!-- Detail Penyakit -->
@if($riwayat->penyakit->deskripsi_singkat)
<div class="mb-4">
<h4 class="font-bold text-gray-700 mb-2">📝 Deskripsi</h4>
<p class="text-sm text-gray-600 leading-relaxed">{{ $riwayat->penyakit->deskripsi_singkat }}</p>
<!-- Body -->
<div class="p-6">
@if($riwayat->penyakit?->deskripsi_singkat)
<div class="mb-6">
<h4 class="font-bold text-gray-800 mb-2 flex items-center">
<span class="w-8 h-8 bg-blue-100 rounded-lg flex items-center justify-center mr-2 text-sm">📝</span>
Deskripsi Penyakit
</h4>
<p class="text-sm text-gray-600 leading-relaxed bg-gray-50 rounded-xl p-4">{{ $riwayat->penyakit->deskripsi_singkat }}</p>
</div>
@endif
<h4 class="font-bold text-gray-800 mb-3 flex items-center">
<span class="w-8 h-8 bg-green-100 rounded-lg flex items-center justify-center mr-2 text-sm">💊</span>
Cara Pengendalian
</h4>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
@if($riwayat->penyakit->pengendalian_pencegahan)
<div class="bg-blue-50 rounded-xl p-4">
<h4 class="font-bold text-blue-700 mb-2 text-sm">🛡️ Pencegahan</h4>
@if($riwayat->penyakit?->pengendalian_pencegahan)
<div class="bg-blue-50 border border-blue-100 rounded-xl p-4 hover:shadow-md transition">
<div class="flex items-center mb-2"><span class="text-lg mr-2">🛡️</span><h5 class="font-bold text-blue-700 text-sm">Pencegahan</h5></div>
<p class="text-xs text-blue-600 leading-relaxed">{{ $riwayat->penyakit->pengendalian_pencegahan }}</p>
</div>
@endif
@if($riwayat->penyakit->pengendalian_kimia)
<div class="bg-orange-50 rounded-xl p-4">
<h4 class="font-bold text-orange-700 mb-2 text-sm">⚗️ Pengendalian Kimia</h4>
@if($riwayat->penyakit?->pengendalian_kimia)
<div class="bg-orange-50 border border-orange-100 rounded-xl p-4 hover:shadow-md transition">
<div class="flex items-center mb-2"><span class="text-lg mr-2">⚗️</span><h5 class="font-bold text-orange-700 text-sm">Pengendalian Kimia</h5></div>
<p class="text-xs text-orange-600 leading-relaxed">{{ $riwayat->penyakit->pengendalian_kimia }}</p>
</div>
@endif
@if($riwayat->penyakit->pengendalian_organik)
<div class="bg-green-50 rounded-xl p-4">
<h4 class="font-bold text-green-700 mb-2 text-sm">🌿 Pengendalian Organik</h4>
@if($riwayat->penyakit?->pengendalian_organik)
<div class="bg-green-50 border border-green-100 rounded-xl p-4 hover:shadow-md transition">
<div class="flex items-center mb-2"><span class="text-lg mr-2">🌿</span><h5 class="font-bold text-green-700 text-sm">Pengendalian Organik</h5></div>
<p class="text-xs text-green-600 leading-relaxed">{{ $riwayat->penyakit->pengendalian_organik }}</p>
</div>
@endif
@if($riwayat->penyakit->pengendalian_budidaya)
<div class="bg-yellow-50 rounded-xl p-4">
<h4 class="font-bold text-yellow-700 mb-2 text-sm">🌱 Pengendalian Budidaya</h4>
@if($riwayat->penyakit?->pengendalian_budidaya)
<div class="bg-yellow-50 border border-yellow-100 rounded-xl p-4 hover:shadow-md transition">
<div class="flex items-center mb-2"><span class="text-lg mr-2">🌱</span><h5 class="font-bold text-yellow-700 text-sm">Pengendalian Budidaya</h5></div>
<p class="text-xs text-yellow-600 leading-relaxed">{{ $riwayat->penyakit->pengendalian_budidaya }}</p>
</div>
@endif
</div>
@else
<div class="text-center py-8 text-gray-400">
<p>Tidak ditemukan data penyakit</p>
</div>
@endif
</div>
</div>
<!-- Semua Hasil CF -->
<!-- Semua Kemungkinan -->
@if($riwayat->hasil_diagnosa && count($riwayat->hasil_diagnosa) > 1)
<div class="bg-white rounded-2xl shadow-lg p-6">
<h3 class="text-lg font-bold text-gray-800 mb-4">📊 Semua Kemungkinan Penyakit</h3>
<h3 class="text-lg font-bold text-gray-800 mb-4 flex items-center">
<span class="w-8 h-8 bg-purple-100 rounded-lg flex items-center justify-center mr-2 text-sm">📊</span>
Semua Kemungkinan Penyakit
</h3>
<div class="space-y-3">
@foreach($riwayat->hasil_diagnosa as $index => $hasil)
<div class="flex items-center justify-between p-3 rounded-xl {{ $index === 0 ? 'bg-green-50 border border-green-200' : 'bg-gray-50' }}">
<div class="flex items-center space-x-3">
<span class="w-6 h-6 rounded-full {{ $index === 0 ? 'bg-green-500' : 'bg-gray-300' }} text-white text-xs flex items-center justify-center font-bold">
{{ $index + 1 }}
</span>
<span class="text-sm font-semibold {{ $index === 0 ? 'text-green-800' : 'text-gray-700' }}">
{{ $hasil['nama_penyakit'] }}
</span>
</div>
<div class="flex items-center space-x-3">
<div class="flex items-center gap-3 p-3 rounded-xl {{ $index === 0 ? 'bg-green-50 border-2 border-green-200' : 'bg-gray-50 border border-gray-100' }}">
<span class="w-7 h-7 rounded-full {{ $index === 0 ? 'bg-green-500' : 'bg-gray-300' }} text-white text-xs flex items-center justify-center font-bold flex-shrink-0">{{ $index + 1 }}</span>
<span class="text-sm font-semibold {{ $index === 0 ? 'text-green-800' : 'text-gray-600' }} flex-1 min-w-0 truncate">
{{ $hasil['nama_penyakit'] }}
@if($index === 0)<span class="ml-2 px-2 py-0.5 bg-green-500 text-white text-xs rounded-full">Terpilih</span>@endif
</span>
<div class="flex items-center gap-2 flex-shrink-0">
<div class="w-24 bg-gray-200 rounded-full h-2">
<div class="{{ $index === 0 ? 'bg-green-500' : 'bg-gray-400' }} h-2 rounded-full"
style="width: {{ $hasil['persentase'] }}%"></div>
<div class="{{ $index === 0 ? 'bg-green-500' : 'bg-gray-400' }} h-2 rounded-full" style="width: {{ $hasil['persentase'] }}%"></div>
</div>
<span class="text-sm font-bold {{ $index === 0 ? 'text-green-700' : 'text-gray-600' }}">
{{ $hasil['persentase'] }}%
</span>
<span class="text-sm font-bold {{ $index === 0 ? 'text-green-700' : 'text-gray-500' }} w-10 text-right">{{ $hasil['persentase'] }}%</span>
</div>
</div>
@endforeach
@ -131,38 +135,99 @@
@endif
</div>
<!-- Panel Kanan -->
<!-- Tabel Relasi Gejala per Penyakit -->
@if($relasiGejala->count() > 0)
<div class="bg-white rounded-2xl shadow-lg p-6">
<h3 class="text-lg font-bold text-gray-800 mb-4 flex items-center">
<span class="w-8 h-8 bg-blue-100 rounded-lg flex items-center justify-center mr-2 text-sm">🔗</span>
Relasi Gejala & Penyakit
</h3>
<div class="overflow-x-auto rounded-xl border border-gray-200">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="px-4 py-3 text-left text-xs font-bold text-gray-600 uppercase">Gejala</th>
@foreach($riwayat->hasil_diagnosa as $hasil)
<th class="px-4 py-3 text-center text-xs font-bold text-gray-600 uppercase">
{{ $hasil['nama_penyakit'] }}
<div class="text-green-600 font-bold normal-case">{{ $hasil['persentase'] }}%</div>
</th>
@endforeach
</tr>
</thead>
<tbody class="bg-white divide-y divide-gray-200">
@foreach($gejalaInput as $gejala)
<tr class="hover:bg-gray-50">
<td class="px-4 py-3 text-xs text-gray-700 font-medium max-w-xs">{{ $gejala->nama_gejala }}</td>
@foreach($riwayat->hasil_diagnosa as $hasil)
<td class="px-4 py-3 text-center">
@if(isset($relasiGejala[$hasil['id_penyakit']]) &&
$relasiGejala[$hasil['id_penyakit']]->contains('id_gejala', $gejala->id_gejala))
<span class="inline-flex items-center justify-center w-7 h-7 bg-green-100 rounded-full">
<svg class="w-4 h-4 text-green-600" fill="currentColor" viewBox="0 0 20 20">
<path fill-rule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clip-rule="evenodd"/>
</svg>
</span>
@else
<span class="inline-flex items-center justify-center w-7 h-7 bg-gray-100 rounded-full">
<svg class="w-4 h-4 text-gray-300" fill="currentColor" viewBox="0 0 20 20">
<path fill-rule="evenodd" d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clip-rule="evenodd"/>
</svg>
</span>
@endif
</td>
@endforeach
</tr>
@endforeach
</tbody>
</table>
</div>
<p class="text-xs text-gray-400 mt-3"> = gejala terkait penyakit tersebut &nbsp;|&nbsp; = tidak terkait</p>
</div>
@endif
<!-- Kolom Kanan -->
<div class="space-y-6">
<!-- Info Diagnosa -->
<div class="bg-white rounded-2xl shadow-lg p-6">
<h3 class="text-lg font-bold text-gray-800 mb-4"> Info Diagnosa</h3>
<div class="space-y-3">
<div class="flex justify-between text-sm">
<span class="text-gray-500">Tanggal</span>
<span class="font-semibold text-gray-800">{{ $riwayat->tanggal->format('d M Y, H:i') }}</span>
<h3 class="font-bold text-gray-800 mb-4 flex items-center">
<span class="w-8 h-8 bg-blue-100 rounded-lg flex items-center justify-center mr-2 text-sm"></span>
Info Diagnosa
</h3>
<div class="space-y-2">
<div class="flex justify-between items-center py-2 border-b border-gray-100">
<span class="text-xs text-gray-500">Tanggal</span>
<span class="text-xs font-semibold text-gray-800">{{ $riwayat->tanggal->format('d M Y') }}</span>
</div>
<div class="flex justify-between text-sm">
<span class="text-gray-500">Jumlah Gejala</span>
<span class="font-semibold text-gray-800">{{ count($riwayat->gejala_input) }} gejala</span>
<div class="flex justify-between items-center py-2 border-b border-gray-100">
<span class="text-xs text-gray-500">Waktu</span>
<span class="text-xs font-semibold text-gray-800">{{ $riwayat->tanggal->format('H:i') }} WIB</span>
</div>
<div class="flex justify-between text-sm">
<span class="text-gray-500">CF Tertinggi</span>
<span class="font-semibold text-green-600">{{ round($riwayat->cf_tertinggi * 100, 1) }}%</span>
<div class="flex justify-between items-center py-2 border-b border-gray-100">
<span class="text-xs text-gray-500">Jumlah Gejala</span>
<span class="text-xs font-bold text-blue-600">{{ count($riwayat->gejala_input) }} gejala</span>
</div>
<div class="flex justify-between items-center py-2">
<span class="text-xs text-gray-500">CF Tertinggi</span>
<span class="text-xs font-bold text-green-600">{{ round($riwayat->cf_tertinggi * 100, 1) }}%</span>
</div>
</div>
</div>
<!-- Gejala yang Dipilih -->
<!-- Gejala -->
<div class="bg-white rounded-2xl shadow-lg p-6">
<h3 class="text-lg font-bold text-gray-800 mb-4">🩺 Gejala yang Dipilih</h3>
<div class="space-y-2">
<h3 class="font-bold text-gray-800 mb-4 flex items-center">
<span class="w-8 h-8 bg-green-100 rounded-lg flex items-center justify-center mr-2 text-sm">🩺</span>
Gejala Dipilih
</h3>
<div class="space-y-2 max-h-64 overflow-y-auto">
@foreach($gejalaInput as $gejala)
<div class="flex items-center space-x-2 text-sm">
<svg class="w-4 h-4 text-green-500 flex-shrink-0" fill="currentColor" viewBox="0 0 20 20">
<div class="flex items-start space-x-2 p-2 bg-green-50 rounded-lg">
<svg class="w-4 h-4 text-green-500 flex-shrink-0 mt-0.5" fill="currentColor" viewBox="0 0 20 20">
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd"/>
</svg>
<span class="text-gray-700">{{ $gejala->nama_gejala }}</span>
<span class="text-xs text-gray-700 leading-relaxed">{{ $gejala->nama_gejala }}</span>
</div>
@endforeach
</div>
@ -170,14 +235,13 @@
<!-- Aksi -->
<div class="bg-white rounded-2xl shadow-lg p-6 space-y-3">
<a href="{{ route('user.diagnosa.index') }}"
class="w-full flex items-center justify-center px-4 py-3 bg-gradient-to-r from-green-500 to-green-600 text-white font-bold rounded-xl hover:from-green-600 hover:to-green-700 transition shadow text-sm">
🔍 Diagnosa Ulang
<a href="{{ route('user.diagnosa.index') }}" class="w-full flex items-center justify-center gap-2 px-4 py-3 bg-gradient-to-r from-green-500 to-green-600 text-white font-bold rounded-xl hover:from-green-600 hover:to-green-700 transition shadow text-sm">
Diagnosa Ulang
</a>
<a href="{{ route('user.diagnosa.riwayat') }}"
class="w-full flex items-center justify-center px-4 py-3 border border-gray-300 text-gray-700 font-semibold rounded-xl hover:bg-gray-50 transition text-sm">
📋 Lihat Riwayat
<a href="{{ route('user.diagnosa.riwayat') }}" class="w-full flex items-center justify-center gap-2 px-4 py-3 border-2 border-gray-200 text-gray-700 font-semibold rounded-xl hover:bg-gray-50 transition text-sm">
Kembali ke Riwayat
</a>
</div>
</div>
</div>

View File

@ -1,6 +1,6 @@
@extends('layouts.user-app')
@section('page-title', '🔍 Diagnosa Penyakit')
@section('page-title', 'Diagnosa Penyakit')
@section('page-subtitle', 'Pilih gejala yang dialami tanaman kopi kamu')
@section('content')
@ -22,8 +22,8 @@
<!-- Daftar Gejala -->
<div class="lg:col-span-2">
<div class="bg-white rounded-2xl shadow-lg p-6">
<div class="flex items-center justify-between mb-6">
<div class="flex items-center">
<div class="mb-6">
<div class="flex items-center mb-4">
<div class="bg-gradient-to-r from-green-500 to-green-600 rounded-xl p-3 mr-4">
<svg class="w-6 h-6 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path>
@ -35,8 +35,8 @@
</div>
</div>
<!-- Search -->
<input type="text" id="search-gejala" placeholder="🔍 Cari gejala..."
class="px-4 py-2 border border-gray-300 rounded-xl text-sm focus:ring-2 focus:ring-green-500 focus:border-transparent w-48">
<input type="text" id="search-gejala" placeholder="🔍 Cari gejala yang dialami tanaman kopi kamu..."
class="w-full px-4 py-3 border border-gray-300 rounded-xl text-sm focus:ring-2 focus:ring-green-500 focus:border-transparent">
</div>
<!-- Gejala List -->
@ -74,7 +74,7 @@ class="gejala-checkbox w-5 h-5 text-green-600 rounded focus:ring-green-500 mr-4"
<!-- Gejala Terpilih -->
<div class="bg-white rounded-2xl shadow-lg p-6 sticky top-28">
<h3 class="text-lg font-bold text-gray-800 mb-4">Gejala Terpilih</h3>
<h3 class="text-lg font-bold text-gray-800 mb-4">Gejala Terpilih</h3>
<div id="selected-count" class="text-3xl font-bold text-green-600 mb-1">0</div>
<p class="text-sm text-gray-500 mb-4">gejala dipilih</p>
@ -90,7 +90,7 @@ class="w-full mb-3 px-4 py-2 border border-gray-300 text-gray-600 font-semibold
<button type="submit"
class="w-full px-4 py-3 bg-gradient-to-r from-green-500 to-green-600 text-white font-bold rounded-xl hover:from-green-600 hover:to-green-700 transition shadow-lg text-sm">
🔍 Diagnosa Sekarang
Diagnosa Sekarang
</button>
<!-- Info -->

View File

@ -0,0 +1,280 @@
<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<title>Hasil Diagnosa - {{ $riwayat->id_diagnosis }}</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'DejaVu Sans', sans-serif; font-size: 12px; color: #1f2937; background: #ffffff; line-height: 1.5; }
.header { background: #16a34a; color: white; padding: 24px 30px; }
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 9px; font-weight: bold; text-transform: uppercase; letter-spacing: 0.5px; background: #15803d; color: white; }
.badge-danger-sangat-tinggi { background: #dc2626; color: white; }
.badge-danger-tinggi { background: #f97316; color: white; }
.badge-danger-sedang { background: #facc15; color: #713f12; }
.badge-danger-rendah { background: #bbf7d0; color: #14532d; }
.nama-latin { font-style: italic; font-size: 11px; color: #bbf7d0; }
.tanggal-box { text-align: right; font-size: 10px; color: #bbf7d0; }
.cf-box { background: #15803d; border-radius: 10px; padding: 12px 16px; margin-top: 12px; }
.cf-bar-bg { background: #166534; border-radius: 999px; height: 10px; width: 100%; }
.cf-bar-fill { background: white; border-radius: 999px; height: 10px; }
.content { padding: 20px 30px; }
.section { margin-bottom: 20px; }
.section-title { font-size: 12px; font-weight: bold; color: #374151; margin-bottom: 10px; padding-bottom: 6px; border-bottom: 2px solid #d1fae5; }
.info-grid { width: 100%; border-collapse: collapse; }
.info-grid td { padding: 6px 10px; font-size: 11px; border-bottom: 1px solid #f3f4f6; }
.info-grid td:first-child { color: #6b7280; width: 35%; }
.info-grid td:last-child { font-weight: 600; color: #111827; }
.deskripsi-box { background: #f9fafb; border-radius: 8px; padding: 12px; font-size: 11px; color: #4b5563; line-height: 1.6; }
.pengendalian-grid { width: 100%; border-collapse: separate; border-spacing: 6px; }
.pengendalian-grid td { vertical-align: top; width: 50%; padding: 10px; border-radius: 8px; font-size: 10px; line-height: 1.5; }
.p-pencegahan { background: #eff6ff; color: #1d4ed8; }
.p-kimia { background: #fff7ed; color: #c2410c; }
.p-organik { background: #f0fdf4; color: #15803d; }
.p-budidaya { background: #fefce8; color: #a16207; }
.pengendalian-label { font-weight: bold; font-size: 10px; margin-bottom: 4px; }
.gejala-item { background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 6px; padding: 4px 10px; font-size: 10px; color: #166534; margin-bottom: 4px; display: block; }
.kemungkinan-table { width: 100%; border-collapse: collapse; }
.kemungkinan-table thead tr { background: #f3f4f6; }
.kemungkinan-table th { padding: 7px 10px; text-align: left; font-size: 10px; font-weight: bold; color: #6b7280; text-transform: uppercase; }
.kemungkinan-table td { padding: 8px 10px; font-size: 11px; border-bottom: 1px solid #f3f4f6; vertical-align: middle; }
.rank-badge { display: inline-block; width: 22px; height: 22px; border-radius: 50%; text-align: center; line-height: 22px; font-size: 10px; font-weight: bold; color: white; }
.rank-1 { background: #16a34a; }
.rank-other { background: #9ca3af; }
.mini-bar-bg { background: #e5e7eb; border-radius: 999px; height: 6px; width: 100%; }
.mini-bar-fill{ border-radius: 999px; height: 6px; }
.relasi-table { width: 100%; border-collapse: collapse; font-size: 10px; }
.relasi-table th { background: #f9fafb; padding: 7px 8px; font-size: 9px; font-weight: bold; color: #6b7280; border: 1px solid #e5e7eb; text-align: center; }
.relasi-table th:first-child { text-align: left; }
.relasi-table td { padding: 6px 8px; border: 1px solid #f3f4f6; text-align: center; }
.relasi-table td:first-child { text-align: left; }
.relasi-table tr:nth-child(even) { background: #f9fafb; }
.check-yes { color: #16a34a; font-weight: bold; font-size: 13px; }
.check-no { color: #d1d5db; font-size: 13px; }
.two-col { width: 100%; border-collapse: separate; border-spacing: 12px; }
.two-col td { vertical-align: top; width: 50%; }
</style>
</head>
<body>
{{-- HEADER --}}
<div class="header">
<table style="width:100%; border-collapse:collapse;">
<tr>
<td style="vertical-align:top;">
<div style="margin-bottom:8px;">
<span class="badge">&#x1F52C; Penyakit Terdeteksi</span>
@if($riwayat->penyakit?->tingkat_bahaya)
@php
$badgeClass = match($riwayat->penyakit->tingkat_bahaya) {
'Sangat Tinggi' => 'badge-danger-sangat-tinggi',
'Tinggi' => 'badge-danger-tinggi',
'Sedang' => 'badge-danger-sedang',
default => 'badge-danger-rendah',
};
@endphp
&nbsp;<span class="badge {{ $badgeClass }}">&#x26A0; {{ $riwayat->penyakit->tingkat_bahaya }}</span>
@endif
</div>
<div style="font-size:20px; font-weight:bold; color:white; margin-bottom:2px;">
{{ $riwayat->penyakit->nama_penyakit ?? 'Tidak Teridentifikasi' }}
</div>
@if($riwayat->penyakit?->nama_latin)
<div class="nama-latin">{{ $riwayat->penyakit->nama_latin }}</div>
@endif
</td>
<td style="vertical-align:top; text-align:right;">
<div class="tanggal-box">
<div>{{ $riwayat->tanggal->format('d M Y') }}</div>
<div>{{ $riwayat->tanggal->format('H:i') }} WIB</div>
<div style="margin-top:4px; font-size:9px; color:#bbf7d0;">ID: {{ $riwayat->id_diagnosis }}</div>
</div>
</td>
</tr>
</table>
<div class="cf-box">
<table style="width:100%; border-collapse:collapse; margin-bottom:6px;">
<tr>
<td style="font-size:11px; color:#bbf7d0;">Tingkat Kepercayaan</td>
<td style="font-size:22px; font-weight:bold; color:white; text-align:right;">{{ round($riwayat->cf_tertinggi * 100, 1) }}%</td>
</tr>
</table>
<div class="cf-bar-bg">
<div class="cf-bar-fill" style="width: {{ round($riwayat->cf_tertinggi * 100, 1) }}%;"></div>
</div>
<table style="width:100%; border-collapse:collapse; margin-top:3px;">
<tr>
<td style="font-size:9px; color:#bbf7d0;">0%</td>
<td style="font-size:9px; color:#bbf7d0; text-align:center;">50%</td>
<td style="font-size:9px; color:#bbf7d0; text-align:right;">100%</td>
</tr>
</table>
</div>
</div>
{{-- CONTENT --}}
<div class="content">
<table class="two-col">
<tr>
<td>
<div class="section">
<div class="section-title">Info Diagnosa</div>
<table class="info-grid">
<tr><td>Tanggal</td><td>{{ $riwayat->tanggal->format('d F Y') }}</td></tr>
<tr><td>Waktu</td><td>{{ $riwayat->tanggal->format('H:i') }} WIB</td></tr>
<tr><td>Jumlah Gejala</td><td style="color:#2563eb;">{{ count($riwayat->gejala_input) }} gejala</td></tr>
<tr><td>CF Tertinggi</td><td style="color:#16a34a;">{{ round($riwayat->cf_tertinggi * 100, 1) }}%</td></tr>
<tr><td>Tingkat Bahaya</td><td>{{ $riwayat->penyakit?->tingkat_bahaya ?? '-' }}</td></tr>
</table>
</div>
</td>
<td>
<div class="section">
<div class="section-title">Gejala Dipilih</div>
@foreach($gejalaInput as $gejala)
<span class="gejala-item">&#x2713; {{ $gejala->nama_gejala }}</span>
@endforeach
</div>
</td>
</tr>
</table>
@if($riwayat->penyakit?->deskripsi_singkat)
<div class="section">
<div class="section-title">Deskripsi Penyakit</div>
<div class="deskripsi-box">{{ $riwayat->penyakit->deskripsi_singkat }}</div>
</div>
@endif
@if($riwayat->penyakit?->pengendalian_pencegahan || $riwayat->penyakit?->pengendalian_kimia || $riwayat->penyakit?->pengendalian_organik || $riwayat->penyakit?->pengendalian_budidaya)
<div class="section">
<div class="section-title">Cara Pengendalian</div>
<table class="pengendalian-grid">
<tr>
@if($riwayat->penyakit?->pengendalian_pencegahan)
<td class="p-pencegahan">
<div class="pengendalian-label">Pencegahan</div>
{{ $riwayat->penyakit->pengendalian_pencegahan }}
</td>
@endif
@if($riwayat->penyakit?->pengendalian_kimia)
<td class="p-kimia">
<div class="pengendalian-label">Pengendalian Kimia</div>
{{ $riwayat->penyakit->pengendalian_kimia }}
</td>
@endif
</tr>
<tr>
@if($riwayat->penyakit?->pengendalian_organik)
<td class="p-organik">
<div class="pengendalian-label">Pengendalian Organik</div>
{{ $riwayat->penyakit->pengendalian_organik }}
</td>
@endif
@if($riwayat->penyakit?->pengendalian_budidaya)
<td class="p-budidaya">
<div class="pengendalian-label">Pengendalian Budidaya</div>
{{ $riwayat->penyakit->pengendalian_budidaya }}
</td>
@endif
</tr>
</table>
</div>
@endif
@if($riwayat->hasil_diagnosa && count($riwayat->hasil_diagnosa) > 1)
<div class="section">
<div class="section-title">Semua Kemungkinan Penyakit</div>
<table class="kemungkinan-table">
<thead>
<tr>
<th style="width:40px;">#</th>
<th>Nama Penyakit</th>
<th style="width:60px; text-align:right;">CF</th>
<th style="width:120px;">Grafik</th>
</tr>
</thead>
<tbody>
@foreach($riwayat->hasil_diagnosa as $index => $hasil)
<tr>
<td><span class="rank-badge {{ $index === 0 ? 'rank-1' : 'rank-other' }}">{{ $index + 1 }}</span></td>
<td style="{{ $index === 0 ? 'font-weight:bold; color:#166534;' : 'color:#374151;' }}">{{ $hasil['nama_penyakit'] }}</td>
<td style="text-align:right; font-weight:bold; color:{{ $index === 0 ? '#16a34a' : '#6b7280' }};">{{ $hasil['persentase'] }}%</td>
<td>
<div class="mini-bar-bg">
<div class="mini-bar-fill" style="width:{{ $hasil['persentase'] }}%; background:{{ $index === 0 ? '#16a34a' : '#9ca3af' }};"></div>
</div>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endif
@if($relasiGejala->count() > 0)
<div class="section">
<div class="section-title">Relasi Gejala &amp; Penyakit</div>
<table class="relasi-table">
<thead>
<tr>
<th>Gejala</th>
@foreach($riwayat->hasil_diagnosa as $hasil)
<th>
{{ $hasil['nama_penyakit'] }}<br>
<span style="color:#16a34a; text-transform:none; letter-spacing:0;">{{ $hasil['persentase'] }}%</span>
</th>
@endforeach
</tr>
</thead>
<tbody>
@foreach($gejalaInput as $gejala)
<tr>
<td>{{ $gejala->nama_gejala }}</td>
@foreach($riwayat->hasil_diagnosa as $hasil)
<td>
@if(isset($relasiGejala[$hasil['id_penyakit']]) &&
$relasiGejala[$hasil['id_penyakit']]->contains('id_gejala', $gejala->id_gejala))
<span class="check-yes">&#x2713;</span>
@else
<span class="check-no">&#x2717;</span>
@endif
</td>
@endforeach
</tr>
@endforeach
</tbody>
</table>
<p style="font-size:9px; color:#9ca3af; margin-top:6px;">&#x2713; = gejala terkait penyakit tersebut &nbsp;|&nbsp; &#x2717; = tidak terkait</p>
</div>
@endif
</div>
{{-- FOOTER --}}
<table style="width:100%; border-collapse:collapse; margin-top:24px; background:#f0fdf4; border-top:2px solid #d1fae5;">
<tr>
<td style="padding:12px 30px; font-size:9px; color:#6b7280; font-style:italic; vertical-align:middle;">
Dokumen ini digenerate otomatis oleh sistem pakar diagnosa penyakit tanaman kopi.<br>
Hasil diagnosa bersifat prediktif. Konsultasikan dengan ahli pertanian untuk penanganan lebih lanjut.
</td>
<td style="padding:12px 30px; font-size:9px; color:#16a34a; font-weight:bold; text-align:right; vertical-align:middle;">
ID: {{ $riwayat->id_diagnosis }}<br>
{{ now()->format('d/m/Y H:i') }}
</td>
</tr>
</table>
</body>
</html>

View File

@ -1,6 +1,6 @@
@extends('layouts.user-app')
@section('page-title', '📋 Riwayat Diagnosa')
@section('page-title', 'Riwayat Diagnosa')
@section('page-subtitle', 'Histori diagnosa penyakit tanaman kopi kamu')
@section('content')
@ -23,6 +23,11 @@ class="flex items-center px-5 py-3 bg-gradient-to-r from-green-500 to-green-600
</div>
<div class="overflow-x-auto rounded-xl border border-gray-200">
@if(session('success'))
<div class="mb-6 bg-green-100 border-l-4 border-green-500 text-green-700 p-4 rounded-lg">
{{ session('success') }}
</div>
@endif
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
@ -57,10 +62,34 @@ class="flex items-center px-5 py-3 bg-gradient-to-r from-green-500 to-green-600
</span>
</td>
<td class="px-6 py-4 text-center">
<a href="{{ route('user.diagnosa.hasil', $riwayat->id_diagnosis) }}"
class="inline-flex items-center px-3 py-2 bg-green-500 text-white text-xs font-semibold rounded-lg hover:bg-green-600 transition">
Lihat Detail
</a>
<div class="flex items-center justify-center space-x-2">
{{-- Lihat Detail --}}
<a href="{{ route('user.diagnosa.hasil', $riwayat->id_diagnosis) }}"
class="inline-flex items-center px-3 py-2 bg-green-500 text-white text-xs font-semibold rounded-lg hover:bg-green-600 transition">
Lihat Detail
</a>
{{-- Download PDF --}}
<a href="{{ route('user.riwayat.pdf', $riwayat->id_diagnosis) }}"
target="_blank"
class="inline-flex items-center gap-1 px-3 py-2 bg-blue-500 text-white text-xs font-semibold rounded-lg hover:bg-blue-600 transition">
<svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M12 10v6m0 0l-3-3m3 3l3-3M3 17V7a2 2 0 012-2h6l2 2h6a2 2 0 012 2v8a2 2 0 01-2 2H5a2 2 0 01-2-2z" />
</svg>
PDF
</a>
{{-- Hapus --}}
<form action="{{ route('user.diagnosa.destroy', $riwayat->id_diagnosis) }}" method="POST"
onsubmit="return confirm('Yakin ingin menghapus riwayat ini?')">
@csrf
@method('DELETE')
<button type="submit"
class="inline-flex items-center px-3 py-2 bg-red-500 text-white text-xs font-semibold rounded-lg hover:bg-red-600 transition">
Hapus
</button>
</form>
</div>
</td>
</tr>
@empty

View File

@ -38,6 +38,8 @@
Route::post('/diagnosa', [DiagnosaController::class, 'proses'])->name('diagnosa.proses');
Route::get('/diagnosa/hasil/{id}', [DiagnosaController::class, 'hasil'])->name('diagnosa.hasil');
Route::get('/diagnosa/riwayat', [DiagnosaController::class, 'riwayat'])->name('diagnosa.riwayat');
Route::get('/diagnosa/riwayat/{id}/pdf', [DiagnosaController::class, 'downloadPdf'])->name('riwayat.pdf');
Route::delete('/diagnosa/{id}', [DiagnosaController::class, 'destroy'])->name('diagnosa.destroy');
Route::get('/artikel/budidaya', [ArtikelUserController::class, 'budidaya'])->name('artikel.budidaya');
Route::get('/artikel/budidaya/{slug}', [ArtikelUserController::class, 'detailBudidaya'])->name('artikel.budidaya.detail');
Route::get('/artikel/hama-penyakit', [ArtikelUserController::class, 'hamaPenyakit'])->name('artikel.hama-penyakit');